From bcac217db3395b262cf5721edc93b16961aed89f Mon Sep 17 00:00:00 2001 From: metal_gvc Date: Sun, 9 Feb 2014 21:09:40 +0200 Subject: [PATCH] Uploading new plugins via the admin panel #215 --- libraries/Gelato/FileSystem/Dir.php | 22 ++++++ plugins/box/plugins/plugins.admin.php | 67 +++++++++++++++++++ .../box/plugins/views/backend/index.view.php | 30 +++++++++ 3 files changed, 119 insertions(+) diff --git a/libraries/Gelato/FileSystem/Dir.php b/libraries/Gelato/FileSystem/Dir.php index 76a5883..423ff7c 100644 --- a/libraries/Gelato/FileSystem/Dir.php +++ b/libraries/Gelato/FileSystem/Dir.php @@ -203,4 +203,26 @@ class Dir return $total_size; } + /** + * Copy directory. + * + * Dir::copy('source_folder_path', 'destination_folder_path); + * + * @param $src + * @param $dst + */ + public static function copy($src, $dst) { + $dir = opendir($src); + @mkdir($dst); + while(false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' )) { + if ( is_dir($src .'/'. $file) ) { + self::copy($src .'/'. $file, $dst .'/'. $file); + } else { + copy($src .'/'. $file,$dst .'/'. $file); + } + } + } + closedir($dir); + } } diff --git a/plugins/box/plugins/plugins.admin.php b/plugins/box/plugins/plugins.admin.php index 96da4df..33e3602 100755 --- a/plugins/box/plugins/plugins.admin.php +++ b/plugins/box/plugins/plugins.admin.php @@ -1,5 +1,8 @@ extract($_FILES['file']['tmp_name'], $tmp_dir); + if (!empty($file_locations)) { + + $manifest = ''; + foreach ($file_locations as $filepath) { + if (substr($filepath, -strlen('.manifest.xml')) === '.manifest.xml') { + $manifest = $filepath; + break; + } + } + + if (!empty($manifest) && basename(dirname($manifest)) === 'install') { + $manifest_file = pathinfo($manifest, PATHINFO_BASENAME); + $plugin_name = str_replace('.manifest.xml', '', $manifest_file); + + if (Dir::create(PLUGINS . DS . $plugin_name)) { + $tmp_plugin_dir = dirname(dirname($manifest)); + Dir::copy($tmp_plugin_dir, PLUGINS . DS . $plugin_name); + Notification::set('success', __('Plugin was uploaded', 'plugins')); + $error = false; + } + } + } + } else { + $error = 'System error'; + } + } else { + $error = 'Forbidden plugin file type'; + } + } else { + $error = 'Plugin was not uploaded'; + } + + if ($error) { + Notification::set('error', __($error, 'plugins')); + } + + if (Request::post('dragndrop')) { + Request::shutdown(); + } else { + Request::redirect($site_url.'/admin/index.php?id=plugins'); + } + } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } + } + // Installed plugins $plugins_installed = array(); @@ -149,6 +211,11 @@ class PluginsAdmin extends Backend ->assign('installed_plugins', $installed_plugins) ->assign('plugins_to_intall', $plugins_to_intall) ->assign('_users_plugins', $_users_plugins) + ->assign('fileuploader', array( + 'uploadUrl' => $site_url.'/admin/index.php?id=plugins', + 'csrf' => Security::token(), + 'errorMsg' => __('Upload server error', 'filesmanager') + )) ->display(); } } diff --git a/plugins/box/plugins/views/backend/index.view.php b/plugins/box/plugins/views/backend/index.view.php index 0c8465b..bf18da9 100755 --- a/plugins/box/plugins/views/backend/index.view.php +++ b/plugins/box/plugins/views/backend/index.view.php @@ -1,6 +1,8 @@


+ +
@@ -93,6 +95,34 @@ + +
+
+ 'multipart/form-data', 'class' => 'form-inline')). + Form::hidden('csrf', Security::token()) + ); + ?> +
+ + 'btn btn-primary')). + Form::close() + ); + ?> + + +
+
+
+
+
+
+
+
+