예제 #1
0
 /**
  * 强行删除某个插件
  *
  * @access public
  * @param string $pluginName 插件名称
  * @return void
  */
 public static function removePlugin($pluginName)
 {
     try {
         /** 获取插件入口 */
         list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
         /** 获取已启用插件 */
         $plugins = Typecho_Plugin::export();
         $activatedPlugins = $plugins['activated'];
         /** 载入插件 */
         require_once $pluginFileName;
         /** 判断实例化是否成功 */
         if (!isset($activatedPlugins[$pluginName]) || !class_exists($className) || !method_exists($className, 'deactivate')) {
             throw new Typecho_Widget_Exception(_t('无法禁用插件'), 500);
         }
         $result = call_user_func(array($className, 'deactivate'));
     } catch (Exception $e) {
         //nothing to do
     }
     $db = Typecho_Db::get();
     try {
         Typecho_Plugin::deactivate($pluginName);
         $db->query($db->update('table.options')->rows(array('value' => serialize(Typecho_Plugin::export())))->where('name = ?', 'plugins'));
     } catch (Typecho_Plugin_Exception $e) {
         //nothing to do
     }
     $db->query($db->delete('table.options')->where('name = ?', 'plugin:' . $pluginName));
 }
예제 #2
0
파일: Edit.php 프로젝트: raindali/express
 /**
  * 禁用插件
  *
  * @access public
  * @return void
  */
 public function deactivate($pluginName)
 {
     /** 获取已激活插件 */
     $plugins = Typecho_Plugin::export();
     $activatedPlugins = $plugins['activated'];
     $pluginFileExist = true;
     try {
         /** 获取插件入口 */
         list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
     } catch (Typecho_Plugin_Exception $e) {
         $pluginFileExist = false;
         if (!isset($activatedPlugins[$pluginName])) {
             throw $e;
         }
     }
     /** 判断实例化是否成功 */
     if (!isset($activatedPlugins[$pluginName])) {
         throw new Typecho_Widget_Exception(_t('无法禁用插件'), 500);
     }
     if ($pluginFileExist) {
         /** 载入插件 */
         require_once $pluginFileName;
         /** 判断实例化是否成功 */
         if (!isset($activatedPlugins[$pluginName]) || !class_exists($className) || !method_exists($className, 'deactivate')) {
             throw new Typecho_Widget_Exception(_t('无法禁用插件'), 500);
         }
         try {
             $result = call_user_func(array($className, 'deactivate'));
         } catch (Typecho_Plugin_Exception $e) {
             /** 截获异常 */
             $this->widget('Widget_Notice')->set($e->getMessage(), NULL, 'error');
             $this->response->goBack();
         }
         /** 设置高亮 */
         $this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
     }
     Typecho_Plugin::deactivate($pluginName);
     $this->update(array('value' => serialize(Typecho_Plugin::export())), $this->db->sql()->where('name = ?', 'plugins'));
     $this->delete($this->db->sql()->where('name = ?', 'plugin:' . $pluginName));
     $this->delete($this->db->sql()->where('name = ?', '_plugin:' . $pluginName));
     if (isset($result) && is_string($result)) {
         $this->widget('Widget_Notice')->set($result, NULL, 'notice');
     } else {
         $this->widget('Widget_Notice')->set(_t('插件已经被禁用'), NULL, 'success');
     }
     $this->response->goBack();
 }