Example #1
0
function rename_check($event, $args, $finder)
{
    $name = $args['name'];
    if (gp_restrict_uploads && !\gp\admin\Content\Uploaded::AllowedExtension($name)) {
        return false;
    }
    $args['name'] = $name;
    return $args;
}
Example #2
0
 /**
  * Add an uploaded plugin
  *
  */
 function UploadPlugin()
 {
     global $langmessage, $dataDir;
     $archive = $this->UploadedArchive();
     if (!$archive) {
         return false;
     }
     // get plugin name and check file types
     $list = $archive->ListFiles();
     $plugin_name = '';
     $remove_path = '';
     foreach ($list as $file) {
         //don't check extensions on folder
         if ($file['size'] == 0) {
             continue;
         }
         //check extension
         if (!\gp\admin\Content\Uploaded::AllowedExtension($file['name'], false)) {
             msg($langmessage['OOPS'] . ' (File type not allowed:' . htmlspecialchars($file['name']) . ')');
             return false;
         }
         //plugin name
         if (strpos($file['name'], 'plugin.js') !== false) {
             $new_plugin_name = $this->FindPluginName($archive, $file['name']);
             if (!$new_plugin_name) {
                 continue;
             }
             //use the most relevant plugin name
             $new_path = dirname($file['name']);
             if (!$plugin_name || strlen($new_path) < strlen($remove_path)) {
                 $plugin_name = $new_plugin_name;
                 $remove_path = $new_path;
             }
         }
     }
     if (!$this->CanUpload($plugin_name)) {
         return;
     }
     //extract to temporary location
     $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/' . $plugin_name);
     if (!$archive->extractTo($extract_temp)) {
         \gp\tool\Files::RmAll($extract_temp);
         msg($langmessage['OOPS'] . ' (Couldn\'t extract to temp location)');
         return false;
     }
     //move to _ckeditor folder
     $destination = $dataDir . '/data/_ckeditor/' . $plugin_name;
     $rename_from = $extract_temp . '/' . ltrim($remove_path, '/');
     if (!\gp\tool\Files::Replace($rename_from, $destination)) {
         msg($langmessage['OOPS'] . ' (Not replaced)');
         return false;
     }
     // save configuration
     if (!array_key_exists($plugin_name, $this->cke_config['plugins'])) {
         $this->cke_config['plugins'][$plugin_name] = array('installed' => time());
     }
     $this->cke_config['plugins'][$plugin_name]['updated'] = time();
     $this->SaveConfig();
     msg($langmessage['SAVED']);
 }