示例#1
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;
 }