コード例 #1
0
ファイル: plugins.php プロジェクト: sfsergey/knowledgetree
 function do_update()
 {
     $sTable = KTUtil::getTableName('plugins');
     $aIds = (array) KTUtil::arrayGet($_REQUEST, 'pluginids');
     // Update disabled plugins
     $sIds = implode(',', $aIds);
     $sQuery = "UPDATE {$sTable} SET disabled = 1 WHERE id NOT IN ({$sIds})";
     DBUtil::runQuery(array($sQuery));
     // Select disabled plugins that have been enabled
     $sQuery = "SELECT * FROM {$sTable} WHERE disabled = 1 AND id IN ({$sIds})";
     $res = DBUtil::getResultArray($sQuery);
     if (!PEAR::isError($res)) {
         // Enable the disabled plugins
         $sQuery = "UPDATE {$sTable} SET disabled = 0 WHERE id IN ({$sIds})";
         DBUtil::runQuery(array($sQuery));
         // run setup for each plugin
         $aEnabled = array();
         if (!empty($res)) {
             foreach ($res as $item) {
                 $aEnabled[] = $item['id'];
             }
             $sEnabled = implode(',', $aEnabled);
             $sQuery = "SELECT h.classname, h.pathname FROM {$sTable} p\n                    INNER JOIN plugin_helper h ON (p.namespace = h.plugin)\n                    WHERE classtype = 'plugin' AND p.id IN ({$sEnabled})";
             $res = DBUtil::getResultArray($sQuery);
             if (!PEAR::isError($res)) {
                 foreach ($res as $item) {
                     $classname = $item['classname'];
                     $path = $item['pathname'];
                     if (!empty($path)) {
                         require_once $path;
                     }
                     $oPlugin = new $classname($path);
                     $oPlugin->setup();
                 }
             }
         }
     }
     KTPluginEntity::clearAllCaches();
     // FIXME!!! Plugin manager needs to be updated to deal with this situation. This code should be in the plugin.
     //enabling or disabling Tag fieldset depending on whether tag cloud plugin is enabled or disabled.
     //Get tag cloud object
     $oTagClouPlugin = KTPluginEntity::getByNamespace('ktcore.tagcloud.plugin');
     if (!PEAR::isError($oTagClouPlugin) && !is_a($oTagClouPlugin, 'KTEntityNoObjects') && !is_null($oTagClouPlugin)) {
         if ($oTagClouPlugin->getDisabled() == '1') {
             //disable tag fieldset
             $aFV = array('disabled' => true);
             $aWFV = array('namespace' => 'tagcloud');
             $res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV);
         } else {
             //enable tag fieldset
             $aFV = array('disabled' => false);
             $aWFV = array('namespace' => 'tagcloud');
             $res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV);
         }
     }
     // we reregister the plugins to ensure they are in the correct order
     KTPluginUtil::registerPlugins();
     $this->successRedirectToMain(_kt('Plugins updated'));
 }
コード例 #2
0
 function setEnabled($aIds)
 {
     $sTable = KTPluginEntity::_table();
     $sIds = DBUtil::paramArray($aIds);
     $sQuery = sprintf('UPDATE %s SET disabled = 1 WHERE id NOT IN (%s)', $sTable, $sIds);
     DBUtil::runQuery(array($sQuery, $aIds));
     $sQuery = sprintf('UPDATE %s SET disabled = 0 WHERE id IN (%s)', $sTable, $sIds);
     DBUtil::runQuery(array($sQuery, $aIds));
     KTPluginEntity::clearAllCaches();
 }
コード例 #3
0
 /**
  * Read the plugins directory and register all plugins in the database.
  */
 function doPluginRegistration()
 {
     global $default;
     KTPluginUtil::_deleteSmartyFiles();
     require_once KT_LIB_DIR . '/cache/cache.inc.php';
     $oCache =& KTCache::getSingleton();
     $oCache->deleteAllCaches();
     // Remove all entries from the plugin_helper table and refresh it.
     $query = "DELETE FROM plugin_helper";
     $res = DBUtil::runQuery($query);
     $files = array();
     $plugins = array();
     KTPluginUtil::_walk(KT_DIR . '/plugins', $files);
     foreach ($files as $sFile) {
         $plugin_ending = "Plugin.php";
         if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) {
             /* Set default priority */
             $plugins[$sFile] = KTPluginUtil::getPluginPriority($sFile);
         }
     }
     /* Sort the plugins by priority */
     asort($plugins);
     /*
     Add a check to indicate that plugin registration is occuring.
     This check has been put in place to prevent the plugin being registered on every page load.
     */
     $_SESSION['plugins_registerplugins'] = true;
     foreach ($plugins as $sFile => $priority) {
         require_once $sFile;
     }
     $_SESSION['plugins_registerplugins'] = false;
     $oRegistry =& KTPluginRegistry::getSingleton();
     $aRegistryList = $oRegistry->getPlugins();
     foreach ($aRegistryList as $oPlugin) {
         $res = $oPlugin->register();
         if (PEAR::isError($res)) {
             //var_dump($res);
             $default->log->debug('Register of plugin failed: ' . $res->getMessage());
         }
     }
     $aPluginList = KTPluginEntity::getList();
     foreach ($aPluginList as $oPluginEntity) {
         $sPath = $oPluginEntity->getPath();
         if (!KTUtil::isAbsolutePath($sPath)) {
             $sPath = sprintf("%s/%s", KT_DIR, $sPath);
         }
         if (!file_exists($sPath)) {
             $oPluginEntity->setUnavailable(true);
             $oPluginEntity->setDisabled(true);
             $res = $oPluginEntity->update();
         }
     }
     KTPluginEntity::clearAllCaches();
     KTPluginUtil::_deleteSmartyFiles();
     require_once KT_LIB_DIR . '/cache/cache.inc.php';
     $oCache =& KTCache::getSingleton();
     $oCache->deleteAllCaches();
     //KTPluginUtil::removePluginCache();
 }