mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-31 02:10:37 +02:00
Monstra Library: basic core improvments
This commit is contained in:
@@ -1,162 +1,163 @@
|
||||
<?php
|
||||
|
||||
// Add plugin navigation link
|
||||
Navigation::add(__('Files', 'filesmanager'), 'content', 'filesmanager', 3);
|
||||
// Add plugin navigation link
|
||||
Navigation::add(__('Files', 'filesmanager'), 'content', 'filesmanager', 3);
|
||||
|
||||
/**
|
||||
* Filesmanager Admin Class
|
||||
*/
|
||||
class FilesmanagerAdmin extends Backend
|
||||
{
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static function main()
|
||||
{
|
||||
// Array of forbidden types
|
||||
$forbidden_types = array('html', 'htm', 'js', 'jsb', 'mhtml', 'mht',
|
||||
'php', 'phtml', 'php3', 'php4', 'php5', 'phps',
|
||||
'shtml', 'jhtml', 'pl', 'py', 'cgi', 'sh', 'ksh', 'bsh', 'c', 'htaccess', 'htpasswd',
|
||||
'exe', 'scr', 'dll', 'msi', 'vbs', 'bat', 'com', 'pif', 'cmd', 'vxd', 'cpl');
|
||||
|
||||
// Array of image types
|
||||
$image_types = array('jpg', 'png', 'bmp', 'gif', 'tif');
|
||||
|
||||
// Get Site url
|
||||
$site_url = Option::get('siteurl');
|
||||
|
||||
// Init vars
|
||||
if (Request::get('path')) $path = Request::get('path'); else $path = 'uploads/';
|
||||
|
||||
// Add slash if not exists
|
||||
if (substr($path, -1, 1) != '/') {
|
||||
$path .= '/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
// Upload corectly!
|
||||
if ($path == 'uploads' || $path == 'uploads//') {
|
||||
$path = 'uploads/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
// Only 'uploads' folder!
|
||||
if (strpos($path, 'uploads') === false) {
|
||||
$path = 'uploads/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
// Set default path value if path is empty
|
||||
if ($path == '') {
|
||||
$path = 'uploads/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
$files_path = ROOT . DS . 'public' . DS . $path;
|
||||
$files_list = array();
|
||||
|
||||
$current = explode('/', $path);
|
||||
|
||||
// Get information about current path
|
||||
$_list = FilesmanagerAdmin::fdir($files_path);
|
||||
|
||||
$files_list = array();
|
||||
|
||||
// Get files
|
||||
if (isset($_list['files'])) {
|
||||
foreach ($_list['files'] as $files) {
|
||||
$files_list[] = $files;
|
||||
}
|
||||
}
|
||||
|
||||
$dir_list = array();
|
||||
|
||||
// Get dirs
|
||||
if (isset($_list['dirs'])) {
|
||||
foreach ($_list['dirs'] as $dirs) {
|
||||
if (strpos($dirs, '.') === false) $dir_list[] = $dirs;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete file
|
||||
// -------------------------------------
|
||||
if (Request::get('id') == 'filesmanager' && Request::get('delete_file')) {
|
||||
|
||||
if (Security::check(Request::get('token'))) {
|
||||
|
||||
File::delete($files_path.Request::get('delete_file'));
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
// Delete dir
|
||||
// -------------------------------------
|
||||
if (Request::get('id') == 'filesmanager' && Request::get('delete_dir')) {
|
||||
|
||||
if (Security::check(Request::get('token'))) {
|
||||
|
||||
Dir::delete($files_path.Request::get('delete_dir'));
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
// Upload file
|
||||
// -------------------------------------
|
||||
if (Request::post('upload_file')) {
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
if ($_FILES['file']) {
|
||||
if ( ! in_array(File::ext($_FILES['file']['name']), $forbidden_types)) {
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']));
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
}
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
// Display view
|
||||
View::factory('box/filesmanager/views/backend/index')
|
||||
->assign('path', $path)
|
||||
->assign('current', $current)
|
||||
->assign('files_list', $files_list)
|
||||
->assign('dir_list', $dir_list)
|
||||
->assign('forbidden_types', $forbidden_types)
|
||||
->assign('image_types', $image_types)
|
||||
->assign('site_url', $site_url)
|
||||
->assign('files_path', $files_path)
|
||||
->display();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filesmanager Admin Class
|
||||
* Get directories and files in current path
|
||||
*/
|
||||
class FilesmanagerAdmin extends Backend {
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static function main() {
|
||||
|
||||
// Array of forbidden types
|
||||
$forbidden_types = array('html', 'htm', 'js', 'jsb', 'mhtml', 'mht',
|
||||
'php', 'phtml', 'php3', 'php4', 'php5', 'phps',
|
||||
'shtml', 'jhtml', 'pl', 'py', 'cgi', 'sh', 'ksh', 'bsh', 'c', 'htaccess', 'htpasswd',
|
||||
'exe', 'scr', 'dll', 'msi', 'vbs', 'bat', 'com', 'pif', 'cmd', 'vxd', 'cpl');
|
||||
|
||||
// Array of image types
|
||||
$image_types = array('jpg', 'png', 'bmp', 'gif', 'tif');
|
||||
|
||||
// Get Site url
|
||||
$site_url = Option::get('siteurl');
|
||||
|
||||
// Init vars
|
||||
if (Request::get('path')) $path = Request::get('path'); else $path = 'uploads/';
|
||||
|
||||
// Add slash if not exists
|
||||
if (substr($path, -1, 1) != '/') {
|
||||
$path .= '/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
// Upload corectly!
|
||||
if ($path == 'uploads' || $path == 'uploads//') {
|
||||
$path = 'uploads/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
// Only 'uploads' folder!
|
||||
if (strpos($path, 'uploads') === false) {
|
||||
$path = 'uploads/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
// Set default path value if path is empty
|
||||
if ($path == '') {
|
||||
$path = 'uploads/';
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
$files_path = ROOT . DS . 'public' . DS . $path;
|
||||
$files_list = array();
|
||||
|
||||
$current = explode('/', $path);
|
||||
|
||||
// Get information about current path
|
||||
$_list = FilesmanagerAdmin::fdir($files_path);
|
||||
|
||||
$files_list = array();
|
||||
|
||||
// Get files
|
||||
if (isset($_list['files'])) {
|
||||
foreach ($_list['files'] as $files) {
|
||||
$files_list[] = $files;
|
||||
}
|
||||
}
|
||||
|
||||
$dir_list = array();
|
||||
|
||||
// Get dirs
|
||||
if (isset($_list['dirs'])) {
|
||||
foreach ($_list['dirs'] as $dirs) {
|
||||
if (strpos($dirs, '.') === false) $dir_list[] = $dirs;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete file
|
||||
// -------------------------------------
|
||||
if (Request::get('id') == 'filesmanager' && Request::get('delete_file')) {
|
||||
|
||||
if (Security::check(Request::get('token'))) {
|
||||
|
||||
File::delete($files_path.Request::get('delete_file'));
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
// Delete dir
|
||||
// -------------------------------------
|
||||
if (Request::get('id') == 'filesmanager' && Request::get('delete_dir')) {
|
||||
|
||||
if (Security::check(Request::get('token'))) {
|
||||
|
||||
Dir::delete($files_path.Request::get('delete_dir'));
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
// Upload file
|
||||
// -------------------------------------
|
||||
if (Request::post('upload_file')) {
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
if ($_FILES['file']) {
|
||||
if ( ! in_array(File::ext($_FILES['file']['name']), $forbidden_types)) {
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']));
|
||||
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
}
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
// Display view
|
||||
View::factory('box/filesmanager/views/backend/index')
|
||||
->assign('path', $path)
|
||||
->assign('current', $current)
|
||||
->assign('files_list', $files_list)
|
||||
->assign('dir_list', $dir_list)
|
||||
->assign('forbidden_types', $forbidden_types)
|
||||
->assign('image_types', $image_types)
|
||||
->assign('site_url', $site_url)
|
||||
->assign('files_path', $files_path)
|
||||
->display();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get directories and files in current path
|
||||
*/
|
||||
protected static function fdir($dir, $type = null) {
|
||||
$files = array();
|
||||
$c = 0;
|
||||
$_dir = $dir;
|
||||
if (is_dir($dir)) {
|
||||
$dir = opendir ($dir);
|
||||
while (false !== ($file = readdir($dir))) {
|
||||
if (($file !=".") && ($file !="..")) {
|
||||
$c++;
|
||||
if (is_dir($_dir.$file)) {
|
||||
$files['dirs'][$c] = $file;
|
||||
} else {
|
||||
$files['files'][$c] = $file;
|
||||
}
|
||||
protected static function fdir($dir, $type = null)
|
||||
{
|
||||
$files = array();
|
||||
$c = 0;
|
||||
$_dir = $dir;
|
||||
if (is_dir($dir)) {
|
||||
$dir = opendir ($dir);
|
||||
while (false !== ($file = readdir($dir))) {
|
||||
if (($file !=".") && ($file !="..")) {
|
||||
$c++;
|
||||
if (is_dir($_dir.$file)) {
|
||||
$files['dirs'][$c] = $file;
|
||||
} else {
|
||||
$files['files'][$c] = $file;
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
return $files;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
return $files;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,34 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Files manager plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Files manager plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('Files manager', 'filesmanager'),
|
||||
__('Files manager', 'filesmanager'),
|
||||
'1.0.0',
|
||||
'Awilum',
|
||||
'http://monstra.org/',
|
||||
null,
|
||||
'box');
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('Files manager', 'filesmanager'),
|
||||
__('Files manager', 'filesmanager'),
|
||||
'1.0.0',
|
||||
'Awilum',
|
||||
'http://monstra.org/',
|
||||
null,
|
||||
'box');
|
||||
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
|
||||
|
||||
// Include Admin
|
||||
Plugin::admin('filesmanager', 'box');
|
||||
|
||||
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
|
||||
}
|
||||
|
||||
// Include Admin
|
||||
Plugin::admin('filesmanager', 'box');
|
||||
|
||||
}
|
||||
|
||||
// Add Plugin Javascript
|
||||
Javascript::add('plugins/box/filesmanager/js/filesmanager.js', 'backend');
|
||||
// Add Plugin Javascript
|
||||
Javascript::add('plugins/box/filesmanager/js/filesmanager.js', 'backend');
|
||||
|
@@ -8,4 +8,4 @@
|
||||
<plugin_version>1.0.0</plugin_version>
|
||||
<plugin_author>Awilum</plugin_author>
|
||||
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
|
||||
</root>
|
||||
</root>
|
||||
|
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'filesmanager' => array(
|
||||
'Files' => 'Dateien',
|
||||
'Files manager' => 'Datei-Manager',
|
||||
'Name' => 'Name',
|
||||
'Actions' => 'Aktionen',
|
||||
'Delete' => 'Löschen',
|
||||
'Upload' => 'Hochladen',
|
||||
'directory' => 'Ordner',
|
||||
'Delete directory: :dir' => 'Lösche Ordner: :dir',
|
||||
'Delete file: :file' => 'Lösche Datei: file',
|
||||
'Extension' => 'Dateiendung',
|
||||
'Size' => 'Größe',
|
||||
)
|
||||
);
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'filesmanager' => array(
|
||||
'Files' => 'Dateien',
|
||||
'Files manager' => 'Datei-Manager',
|
||||
'Name' => 'Name',
|
||||
'Actions' => 'Aktionen',
|
||||
'Delete' => 'Löschen',
|
||||
'Upload' => 'Hochladen',
|
||||
'directory' => 'Ordner',
|
||||
'Delete directory: :dir' => 'Lösche Ordner: :dir',
|
||||
'Delete file: :file' => 'Lösche Datei: file',
|
||||
'Extension' => 'Dateiendung',
|
||||
'Size' => 'Größe',
|
||||
)
|
||||
);
|
||||
|
@@ -4,14 +4,14 @@
|
||||
'filesmanager' => array(
|
||||
'Files' => 'Files',
|
||||
'Files manager' => 'Files manager',
|
||||
'Name' => 'Name',
|
||||
'Name' => 'Name',
|
||||
'Actions' => 'Actions',
|
||||
'Delete' => 'Delete',
|
||||
'Upload' => 'Upload',
|
||||
'directory' => 'directory',
|
||||
'Delete directory: :dir' => 'Delete directory: :dir',
|
||||
'Delete directory: :dir' => 'Delete directory: :dir',
|
||||
'Delete file: :file' => 'Delete file :file',
|
||||
'Extension' => 'Extension',
|
||||
'Size' => 'Size',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
return array(
|
||||
'filesmanager' => array(
|
||||
'Files' => 'File',
|
||||
'Files manager' => 'Gestione file',
|
||||
'Files manager' => 'Gestione file',
|
||||
'Name' => 'Nome',
|
||||
'Actions' => 'Azioni',
|
||||
'Delete' => 'Elimina',
|
||||
@@ -14,4 +14,4 @@
|
||||
'Extension' => 'Estensione',
|
||||
'Size' => 'Dimensione',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -4,14 +4,14 @@
|
||||
'filesmanager' => array(
|
||||
'Files' => 'Bylos',
|
||||
'Files manager' => 'Bylų tvarkyklė',
|
||||
'Name' => 'Pavadinimas',
|
||||
'Name' => 'Pavadinimas',
|
||||
'Actions' => 'Veiksmai',
|
||||
'Delete' => 'Ištrinti',
|
||||
'Upload' => 'Įkelti',
|
||||
'directory' => 'aplankas',
|
||||
'Delete directory: :dir' => 'Ištrinti aplanką: :dir',
|
||||
'Delete directory: :dir' => 'Ištrinti aplanką: :dir',
|
||||
'Delete file: :file' => 'Ištrinti bylą :file',
|
||||
'Extension' => 'Plėtinys',
|
||||
'Size' => 'Dydis',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -9,9 +9,9 @@
|
||||
'Delete' => 'Deletar',
|
||||
'Upload' => 'Upload',
|
||||
'directory' => 'directory',
|
||||
'Delete directory: :dir' => 'Deletar o diretório: :dir',
|
||||
'Delete directory: :dir' => 'Deletar o diretório: :dir',
|
||||
'Delete file: :file' => 'Deletar o arquivo :file',
|
||||
'Extension' => 'Extensão',
|
||||
'Size' => 'Tamanho',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
return array(
|
||||
'filesmanager' => array(
|
||||
'Files' => 'Файлы',
|
||||
'Files manager' => 'Менеджер файлов',
|
||||
'Files manager' => 'Менеджер файлов',
|
||||
'Name' => 'Название',
|
||||
'Actions' => 'Действия',
|
||||
'Delete' => 'Удалить',
|
||||
@@ -14,4 +14,4 @@
|
||||
'Extension' => 'Расширение',
|
||||
'Size' => 'Размер',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
return array(
|
||||
'filesmanager' => array(
|
||||
'Files' => 'Файли',
|
||||
'Files manager' => 'Менеджер файлів',
|
||||
'Files manager' => 'Менеджер файлів',
|
||||
'Name' => 'Назва',
|
||||
'Actions' => 'Дії',
|
||||
'Delete' => 'Видалити',
|
||||
@@ -14,4 +14,4 @@
|
||||
'Extension' => 'Розширення',
|
||||
'Size' => 'Розмір',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -26,12 +26,12 @@
|
||||
}
|
||||
|
||||
$s = '';
|
||||
|
||||
|
||||
foreach ($path_parts as $p) {
|
||||
$s .= $p.'/';
|
||||
if($p == $current[count($current)-2]) $active = ' class="active"'; else $active = '';
|
||||
echo '<li'.$active.'><a href="index.php?id=filesmanager&path='.$s.'">'.$p.'</a> <span class="divider">/</span></li>';
|
||||
}
|
||||
if($p == $current[count($current)-2]) $active = ' class="active"'; else $active = '';
|
||||
echo '<li'.$active.'><a href="index.php?id=filesmanager&path='.$s.'">'.$p.'</a> <span class="divider">/</span></li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<!-- /Filesmanger_path -->
|
||||
@@ -47,12 +47,12 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (isset($dir_list)) foreach ($dir_list as $dir) { ?>
|
||||
<tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b><?php echo Html::anchor($dir, 'index.php?id=filesmanager&path='.$path.$dir.'/'); ?></b>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<?php echo Number::byteFormat(Dir::size(UPLOADS . DS . $dir)); ?>
|
||||
@@ -66,10 +66,10 @@
|
||||
<div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php if (isset($files_list)) foreach ($files_list as $file) { $ext = File::ext($file); ?>
|
||||
<?php if ( ! in_array($ext, $forbidden_types)) { ?>
|
||||
<tr>
|
||||
<tr>
|
||||
<td<?php if (isset(File::$mime_types[$ext]) && preg_match('/image/', File::$mime_types[$ext])) echo ' class="image"'?>>
|
||||
<?php echo Html::anchor(File::name($file), $site_url.'public/' . $path.$file, array('target'=>'_blank'));?>
|
||||
</td>
|
||||
@@ -84,11 +84,11 @@
|
||||
<?php echo Html::anchor(__('Delete', 'filesmanager'),
|
||||
'index.php?id=filesmanager&delete_file='.$file.'&path='.$path.'&token='.Security::token(),
|
||||
array('class' => 'btn btn-small', 'onclick' => "return confirmDelete('".__('Delete file: :file', 'filesmanager', array(':file' => $file))."')"));
|
||||
?>
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } } ?>
|
||||
</tr>
|
||||
<?php } } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -100,4 +100,4 @@
|
||||
<div class="modal-body">
|
||||
<p align="center"><img /></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user