コード例 #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
 /**
  * Load the plugins for the current page
  *
  * @param unknown_type $sType
  */
 static function loadPlugins($sType)
 {
     // Check the current page - can be extended.
     // Currently we only distinguish between the dashboard and everything else.
     if ($sType != 'dashboard') {
         $sType = 'general';
     }
     $aPlugins = array();
     $aPluginHelpers = array();
     $aDisabled = array();
     // Get the list of enabled plugins
     $query = "SELECT h.classname, h.pathname, h.plugin FROM plugin_helper h\n            INNER JOIN plugins p ON (p.namespace = h.plugin)\n           WHERE p.disabled = 0 AND h.classtype='plugin' ORDER BY p.orderby";
     $aPluginHelpers = DBUtil::getResultArray($query);
     if (PEAR::isError($aPluginHelpers)) {
         global $default;
         $default->log->debug('Error in pluginutil: ' . $aPluginHelpers->getMessage());
         return false;
     }
     // Check that there are plugins and if not, register them
     if (empty($aPluginHelpers) || isset($_POST['_force_plugin_truncate'])) {
         DBUtil::startTransaction();
         KTPluginUtil::registerPlugins();
         DBUtil::commit();
         $query = "SELECT h.classname, h.pathname, h.plugin FROM plugin_helper h\n        \t   INNER JOIN plugins p ON (p.namespace = h.plugin)\n        \t   WHERE p.disabled = 0 AND h.classtype='plugin' ORDER BY p.orderby";
         $aPluginHelpers = DBUtil::getResultArray($query);
     }
     // Create plugin objects
     foreach ($aPluginHelpers as $aItem) {
         $classname = $aItem['classname'];
         $path = $aItem['pathname'];
         if (!empty($path)) {
             $path = KT_DIR . '/' . $path;
             require_once $path;
             $oPlugin = new $classname($path);
             if ($oPlugin->load()) {
                 $aPlugins[] = $oPlugin;
             } else {
                 $aDisabled[] = "'{$aItem['plugin']}'";
             }
         }
     }
     $sDisabled = implode(',', $aDisabled);
     // load plugin helpers into global space
     $query = 'SELECT h.* FROM plugin_helper h
         INNER JOIN plugins p ON (p.namespace = h.plugin)
     	WHERE p.disabled = 0 ';
     //WHERE viewtype='{$sType}'";
     if (!empty($sDisabled)) {
         $query .= " AND h.plugin NOT IN ({$sDisabled}) ";
     }
     $query .= ' ORDER BY p.orderby';
     $aPluginList = DBUtil::getResultArray($query);
     KTPluginUtil::load($aPluginList);
     // Load the template locations - ignore disabled plugins
     // Allow for templates that don't correctly link to the plugin
     $query = "SELECT * FROM plugin_helper h\n            LEFT JOIN plugins p ON (p.namespace = h.plugin)\n            WHERE h.classtype='locations' AND (disabled = 0 OR disabled IS NULL) AND unavailable = 0";
     $aLocations = DBUtil::getResultArray($query);
     if (!empty($aLocations)) {
         $oTemplating =& KTTemplating::getSingleton();
         foreach ($aLocations as $location) {
             $aParams = explode('|', $location['object']);
             call_user_func_array(array(&$oTemplating, 'addLocation2'), $aParams);
         }
     }
     return true;
 }