Ejemplo n.º 1
0
 public function processAdd()
 {
     $this->checkXP();
     $language = OW::getLanguage();
     if (empty($_GET['dir']) || !file_exists(urldecode($_GET['dir']))) {
         OW::getFeedback()->error($language->text('admin', 'manage_plugins_add_ftp_move_error'));
         $this->redirectToAction('add');
     }
     $tempDir = urldecode($_GET['dir']);
     $handle = opendir($tempDir);
     if ($handle !== false) {
         while (($item = readdir($handle)) !== false) {
             if ($item === '.' || $item === '..') {
                 continue;
             }
             $innerDir = $item;
         }
         closedir($handle);
     }
     if (!empty($innerDir) && file_exists($tempDir . $innerDir . DS . 'plugin.xml')) {
         $localDir = $tempDir . $innerDir . DS;
     } else {
         OW::getFeedback()->error(OW::getLanguage()->text('admin', 'manage_plugin_add_extract_error'));
         $this->redirectToAction('index');
     }
     //get plugin.xml info
     $pluginXmlInfo = $this->pluginService->readPluginXmlInfo($tempDir . $innerDir . DS . 'plugin.xml');
     $plugin = $this->pluginService->findPluginByKey($pluginXmlInfo['key']);
     $pluginWithDevKey = $this->pluginService->findPluginByKey($pluginXmlInfo['key'], $pluginXmlInfo['developerKey']);
     if ($plugin !== null) {
         if ($pluginWithDevKey !== null) {
             $pluginDir = OW_DIR_PLUGIN . $plugin->getModule() . DS;
         } else {
             OW::getFeedback()->error(OW::getLanguage()->text('admin', 'manage_plugin_cant_add_duplicate_key_error'));
             $this->redirectToAction('index');
         }
     } else {
         $pluginDir = false;
         $itemsXmlList = BOL_PluginService::getInstance()->getPluginsXmlInfo();
         foreach ($itemsXmlList as $xmlItem) {
             if ($xmlItem["key"] == $pluginXmlInfo["key"] && $xmlItem["developerKey"] == $pluginXmlInfo['developerKey']) {
                 $pluginDir = $xmlItem["path"];
             }
         }
         if (!$pluginDir) {
             $pluginDir = OW_DIR_PLUGIN . $innerDir;
             while (file_exists($pluginDir)) {
                 $pluginDir .= rand(1, 99);
             }
         }
     }
     $ftp = $this->getFtpConnection();
     $ftp->uploadDir($localDir, $pluginDir);
     UTIL_File::removeDir($tempDir);
     OW::getFeedback()->info($language->text('base', 'manage_plugins_add_success_message'));
     $this->redirectToAction('available');
 }