/** * Add an uploaded plugin * */ function UploadPlugin() { global $langmessage, $dataDir; includeFile('admin/admin_uploaded.php'); $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 (!admin_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)) { gpFiles::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 (!gpFiles::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']); }
/** * Write Archive * */ private function ExtractArchive($archive_path) { global $langmessage, $dataDir; $archive = new \gp\tool\Archive($archive_path); $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon'); if (!$archive->extractTo($extract_temp)) { $this->message($langmessage['download_failed'] . ' (Package not extracted)'); return false; } //get archive root $archive_root = $archive->GetRoot(); if (is_null($archive_root)) { $this->message($langmessage['download_failed'] . ' (Root not found)'); return false; } //rename to source folder $rename_from = $extract_temp . '/' . ltrim($archive_root, '/'); if (!gpFiles::Replace($rename_from, $this->source)) { $this->message($langmessage['download_failed'] . ' (Not replaced)'); return false; } return true; }