Пример #1
0
 function scanPlugins()
 {
     $plugins = array();
     $dir = ROOT . "/plugins";
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if (is_dir($dir . "/" . $file) && $file != "." && $file != "..") {
                 if (file_exists($dir . "/" . $file . "/info.php")) {
                     $plugin_info = (include_once $dir . "/" . $file . "/info.php");
                     array_push($plugins, $plugin_info);
                 }
             }
         }
         closedir($dh);
     }
     usort($plugins, 'plugin_sort');
     foreach ($plugins as $plg) {
         if (!Plugins::instance()->findOne(array("conditions" => "name = '" . $plg['name'] . "'"))) {
             $plugin = new Plugin();
             //if ( isset($plg["id"]) && is_numeric($plg["id"]) ) {
             //$plugin->setId($plg['id']);
             //}
             $plugin->setName($plg["name"]);
             $plugin->setIsActivated(0);
             $plugin->setIsInstalled(0);
             $plugin->setVersion(array_var($plg, 'version'));
             $plugin->save();
         }
     }
 }
Пример #2
0
 protected function body()
 {
     if (!$this->userHasPrivileges(User::pluginsAdd)) {
         return false;
     }
     $inputs = array('name' => array('isName', 'isNotEmpty'));
     if (!$this->isInputValid($inputs)) {
         return false;
     }
     $name = $this->getParams('name');
     $existingPluginsWithSameName = Repositories::getRepository(Repositories::Plugin)->findBy(['name' => $name]);
     if (count($existingPluginsWithSameName) > 0) {
         return $this->death(StringID::PluginNameAlreadyExists);
     }
     $pluginFile = $this->getUploadedFile('plugin');
     if (!$pluginFile) {
         return false;
     }
     $pluginFolder = Config::get('paths', 'plugins') . $name;
     if (file_exists($pluginFolder)) {
         return $this->death(StringID::PluginFolderAlreadyExists);
     }
     if (!Filesystem::createDir($pluginFolder)) {
         return $this->death(StringID::FileSystemError);
     }
     if (!Compression::unzip($pluginFile, $pluginFolder)) {
         $this->death(StringID::UnzipUnsuccessful);
         goto cleanup_error;
     }
     $manifestFile = $pluginFolder . DIRECTORY_SEPARATOR . 'manifest.xml';
     $manifest = null;
     if (!($manifest = $this->parsePluginManifest($manifestFile))) {
         $this->death(StringID::BadlyFormedPlugin);
         goto cleanup_error;
     }
     if (!file_exists($pluginFolder . DIRECTORY_SEPARATOR . $manifest['mainFile'])) {
         $this->death(StringID::BadlyFormedPlugin);
         goto cleanup_error;
     }
     $plugin = new \Plugin();
     $plugin->setIdentifier($manifest['identifier']);
     $plugin->setDescription($manifest['description']);
     $plugin->setConfig($manifest['arguments']);
     $plugin->setMainfile($name . '/' . $manifest['mainFile']);
     $plugin->setName($name);
     $plugin->setType($manifest['type']);
     Repositories::persistAndFlush($plugin);
     Filesystem::removeFile($pluginFile);
     return true;
     cleanup_error:
     Filesystem::removeDir($pluginFolder);
     Filesystem::removeFile($pluginFile);
     return false;
 }
Пример #3
0
 public function register($plugin, $name = null)
 {
     if (!$plugin instanceof Plugin) {
         if (!$name) {
             throw new \Exception(t('You must specify a plugin key and name.'));
         } else {
             $p = new Plugin();
             $p->setKey($plugin);
             $p->setName($name);
             $key = $plugin;
         }
     } else {
         $p = $plugin;
         $key = $plugin->getKey();
     }
     $this->plugins[$key] = $p;
 }
Пример #4
0
 private static function getObject($pluginFile)
 {
     $plugin = new Plugin();
     $fileLines = file_get_contents($pluginFile);
     if (preg_match("#@author\\s(.+)\\s\\<#", $fileLines, $match)) {
         $plugin->setAuthor(trim($match[1]));
     }
     if (preg_match("#@author\\s(.+)\\s\\<([a-z\\@\\.A-Z\\s\\-]+)\\>#", $fileLines, $match)) {
         $plugin->setMail(strtolower($match[2]));
     }
     if (preg_match("#@name\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setName($match[1]);
     }
     if (preg_match("#@licence\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setLicence($match[1]);
     }
     if (preg_match("#@version\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setVersion($match[1]);
     }
     if (preg_match("#@link\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setLink(trim($match[1]));
     }
     if (preg_match("#@type\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setType(trim($match[1]));
     }
     if (preg_match("#@description\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setDescription(trim($match[1]));
     }
     if (Plugin::loadState($pluginFile) || $plugin->getType() == 'component') {
         $plugin->setState(1);
     } else {
         $plugin->setState(0);
     }
     $plugin->setPath($pluginFile);
     return $plugin;
 }
Пример #5
0
/**
 * Resolve a plugin object from a row
 *
 * @param $row
 * @return Plugin
 */
function resolvePlugin($row)
{
    $plugin = new Plugin();
    $plugin->setID($row['ID']);
    $plugin->setParent($row['Parent']);
    $plugin->setName($row['Name']);
    $plugin->setAuthors($row['Author']);
    $plugin->setHidden($row['Hidden']);
    $plugin->setGlobalHits($row['GlobalHits']);
    $plugin->setCreated($row['Created']);
    $plugin->setLastUpdated($row['LastUpdated']);
    $plugin->setRank($row['Rank']);
    $plugin->setLastRank($row['LastRank']);
    $plugin->setLastRankChange($row['LastRankChange']);
    $plugin->setServerCount($row['ServerCount30']);
    return $plugin;
}
 function update_plugins()
 {
     trace(__FILE__, 'update_plugins()');
     $plugins = array_var($_POST, 'plugins');
     //$plugins = array('invoices' => '1');
     if (is_null($plugins)) {
         $this->redirectTo('administration', 'plugins');
     }
     $reference = Plugins::getAllPlugins();
     trace(__FILE__, 'update_plugins() - getAllPlugins done');
     $errors = array();
     foreach ($plugins as $name => $yes_no) {
         //If it is not a plugin continue
         $plugin_file_path = APPLICATION_PATH . '/plugins/' . $name . '/init.php';
         trace(__FILE__, "update_plugins() - plugin_file_path=[{$plugin_file_path}]");
         if (!file_exists($plugin_file_path)) {
             continue;
         }
         trace(__FILE__, "update_plugins() - plugin_file_path=[{$plugin_file_path}] exists");
         // get existing id
         $id = $reference[$name];
         $nicename = ucwords(str_replace('_', ' ', $name));
         trace(__FILE__, "update_plugins() - id={$id} name={$name} nicename={$nicename}");
         if ($yes_no && '-' == $id) {
             trace(__FILE__, "update_plugins() - activating [{$name}]");
             try {
                 // Check if plugin exists in database
                 $plugin = Plugins::findOne(array('conditions' => array('`name` = ?', $name)));
                 trace(__FILE__, "update_plugins() - findOne");
                 if ($plugin == NULL) {
                     $plugin = new Plugin();
                 }
                 trace(__FILE__, "update_plugins() - setName");
                 $plugin->setName($name);
                 trace(__FILE__, "update_plugins() - setInstalled");
                 $plugin->setInstalled(true);
                 DB::beginWork();
                 trace(__FILE__, "update_plugins() - including [{$plugin_file_path}]");
                 // get the file loaded here
                 include $plugin_file_path;
                 // get activation routine ready
                 trace(__FILE__, "update_plugins() - activate: {$name}");
                 $activate = $name . '_activate';
                 if (function_exists($activate)) {
                     trace(__FILE__, "update_plugins() - calling: {$activate}");
                     $activate();
                 }
                 // save to db now
                 $plugin->save();
                 DB::commit();
             } catch (Exception $e) {
                 trace(__FILE__, 'update_plugins() - ' . $e->getMessage());
                 DB::rollback();
                 $errors[] = $nicename . ' (' . $e->getMessage() . ')';
             }
         } elseif (!$yes_no && '-' != $id) {
             try {
                 trace(__FILE__, "update_plugins() - deactivating [{$name}]");
                 $plugin = Plugins::findById($id);
                 DB::beginWork();
                 $deactivate = $name . '_deactivate';
                 if (function_exists($deactivate)) {
                     trace(__FILE__, "update_plugins() - calling {$deactivate}");
                     //Check if user choose to purge data
                     if ($plugins[$name . "_data"] == "0") {
                         trace(__FILE__, "update_plugins() - calling {$deactivate}(true)");
                         $deactivate(true);
                     } else {
                         $deactivate();
                     }
                 }
                 $plugin->setInstalled(false);
                 $plugin->save();
                 DB::commit();
             } catch (Exception $e) {
                 DB::rollback();
                 $errors[] = $nicename . ' (' . $e->getMessage() . ')';
             }
         }
     }
     if (count($errors)) {
         flash_error(lang('plugin activation failed', implode(", ", $errors)));
     } else {
         flash_success(lang('plugins updated'));
     }
     $this->redirectTo('administration', 'plugins');
 }
 function getPluginList($adminGroup)
 {
     $sql = "SELECT plugin, name, description FROM gban_plugin WHERE plugin IN (\n              SELECT DISTINCT gp.plugin FROM gban_plugin gp, gban_plugin_flag pf, gban_admin_group_flag agf\n              WHERE admin_group_id = '" . $adminGroup . "' AND pf.plugin_flag_id = agf.plugin_flag_id\n              AND gp.plugin = pf.plugin\n            )\n            ORDER BY plugin ASC";
     $this->db->sql_query($sql);
     $plugins = $this->db->get_array();
     $pluginList = array();
     for ($i = 0; $i < count($plugins); $i++) {
         $plugin = new Plugin();
         $plugin->setId($plugins[$i]['plugin']);
         $plugin->setName(stripslashes($plugins[$i]['name']));
         $plugin->setDescription(stripslashes($plugins[$i]['description']));
         array_push($pluginList, $plugin);
     }
     return $pluginList;
 }
Пример #8
0
 private static function getObject($pluginFile)
 {
     $plugin = new Plugin();
     $fileLines = file_get_contents($pluginFile);
     if (preg_match_all("#@author\\s(.+)\\s\\<(.*)\\>#", $fileLines, $matches)) {
         foreach ($matches[1] as $match) {
             $authors[] = trim($match);
         }
         $plugin->setAuthor($authors);
         foreach ($matches[2] as $match) {
             $address[] = strtolower($match);
         }
         $plugin->setAddress($address);
     }
     if (preg_match("#@name\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setName($match[1]);
     }
     if (preg_match("#@licence\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setLicence($match[1]);
     }
     if (preg_match("#@version\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setVersion($match[1]);
     }
     if (preg_match("#@link\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setLink(trim($match[1]));
     }
     if (preg_match("#@type\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setType(trim($match[1]));
     }
     if (preg_match("#@description\\s(.+)[\r\n]#", $fileLines, $match)) {
         $plugin->setDescription(trim($match[1]));
     }
     if (Plugin::loadState($pluginFile) || $plugin->getType() == 'component') {
         $plugin->setState(1);
     } else {
         $plugin->setState(0);
     }
     $plugin->setPath($pluginFile);
     return $plugin;
 }