示例#1
0
 /**
  * 执行函数
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 列出插件目录 */
     $pluginDirs = $this->getPlugins();
     $this->parameter->setDefault(array('activated' => NULL));
     /** 获取已启用插件 */
     $plugins = Typecho_Plugin::export();
     $this->activatedPlugins = $plugins['activated'];
     if (!empty($pluginDirs)) {
         foreach ($pluginDirs as $key => $pluginDir) {
             $parts = $this->getPlugin($pluginDir, $key);
             if (empty($parts)) {
                 continue;
             }
             list($pluginName, $pluginFileName) = $parts;
             if (file_exists($pluginFileName)) {
                 $info = Typecho_Plugin::parseInfo($pluginFileName);
                 $info['name'] = $pluginName;
                 list($version, $build) = explode('/', Typecho_Common::VERSION);
                 $info['dependence'] = Typecho_Plugin::checkDependence($build, $info['dependence']);
                 /** 默认即插即用 */
                 $info['activated'] = true;
                 if ($info['activate'] || $info['deactivate'] || $info['config'] || $info['personalConfig']) {
                     $info['activated'] = isset($this->activatedPlugins[$pluginName]);
                     if (isset($this->activatedPlugins[$pluginName])) {
                         unset($this->activatedPlugins[$pluginName]);
                     }
                 }
                 if ($info['activated'] == $this->parameter->activated) {
                     $this->push($info);
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * 配置插件
  *
  * @access public
  * @return Typecho_Widget_Helper_Form
  * @throws Typecho_Widget_Exception
  */
 public function config()
 {
     /** 获取插件名称 */
     $pluginName = $this->request->filter('slug')->config;
     /** 获取已启用插件 */
     $plugins = Typecho_Plugin::export();
     $activatedPlugins = $plugins['activated'];
     /** 判断实例化是否成功 */
     if (!$this->info['config'] || !isset($activatedPlugins[$pluginName])) {
         throw new Typecho_Widget_Exception(_t('无法配置插件'), 500);
     }
     /** 载入插件 */
     require_once $this->_pluginFileName;
     $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/plugins-edit?config=' . $pluginName), Typecho_Widget_Helper_Form::POST_METHOD);
     call_user_func(array($this->_className, 'config'), $form);
     $options = $this->options->plugin($pluginName);
     if (!empty($options)) {
         foreach ($options as $key => $val) {
             $form->getInput($key)->value($val);
         }
     }
     $submit = new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('保存设置'));
     $submit->input->setAttribute('class', 'btn primary');
     $form->addItem($submit);
     return $form;
 }
示例#3
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));
 }
示例#4
0
/**
 * 判断插件是否启用
 *
 * @param string $pluginName
 * @return bool
 */
function pluginExists($pluginName)
{
    static $_plugins;
    if (is_null($_plugins)) {
        $_plugins = Typecho_Plugin::export();
    }
    return isset($_plugins['activated'][$pluginName]);
}
示例#5
0
 /**
  * 执行函数
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 列出插件目录 */
     $pluginDirs = glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ . '/*');
     $this->parameter->setDefault(array('activated' => NULL));
     /** 获取已启用插件 */
     $plugins = Typecho_Plugin::export();
     $this->activatedPlugins = $plugins['activated'];
     if (!empty($pluginDirs)) {
         foreach ($pluginDirs as $pluginDir) {
             if (is_dir($pluginDir)) {
                 /** 获取插件名称 */
                 $pluginName = basename($pluginDir);
                 /** 获取插件主文件 */
                 $pluginFileName = $pluginDir . '/Plugin.php';
             } else {
                 if (file_exists($pluginDir) && 'index.php' != basename($pluginDir)) {
                     $pluginFileName = $pluginDir;
                     $part = explode('.', basename($pluginDir));
                     if (2 == count($part) && 'php' == $part[1]) {
                         $pluginName = $part[0];
                     } else {
                         continue;
                     }
                 } else {
                     continue;
                 }
             }
             if (file_exists($pluginFileName)) {
                 $info = Typecho_Plugin::parseInfo($pluginFileName);
                 $info['name'] = $pluginName;
                 list($version, $build) = explode('/', Typecho_Common::VERSION);
                 $info['dependence'] = Typecho_Plugin::checkDependence($build, $info['dependence']);
                 /** 默认即插即用 */
                 $info['activated'] = true;
                 if ($info['activate'] || $info['deactivate'] || $info['config'] || $info['personalConfig']) {
                     $info['activated'] = isset($this->activatedPlugins[$pluginName]);
                     if (isset($this->activatedPlugins[$pluginName])) {
                         unset($this->activatedPlugins[$pluginName]);
                     }
                 }
                 if (!is_bool($this->parameter->activated) || $info['activated'] == $this->parameter->activated) {
                     $this->push($info);
                 }
             }
         }
     }
 }
示例#6
0
    <section class="widget">
		<h3 class="widget-title"><?php 
    _e('归档');
    ?>
</h3>
        <ul class="widget-list">
            <?php 
    $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')->parse('<li><a href="{permalink}">{date}</a></li>');
    ?>
        </ul>
	</section>
    <?php 
}
?>
    <?php 
$all_plugins = Typecho_Plugin::export();
?>
    <?php 
if (array_key_exists('Links', $all_plugins['activated'])) {
    ?>
    <section class="widget">
        <h3 class="widget-title">Links</h3>
        <ul class="widget-list">
        <?php 
    Links_Plugin::output("SHOW_TEXT", 10);
    ?>
        </ul>
    </section>
    <?php 
}
?>
示例#7
0
 private function getActivePlugins()
 {
     $activatedPlugins = Typecho_Plugin::export();
     return array_keys($activatedPlugins['activated']);
 }
示例#8
0
 /**
  * 更新个人设置
  *
  * @access public
  * @return void
  */
 public function updatePersonal()
 {
     /** 获取插件名称 */
     $pluginName = $this->request->plugin;
     /** 获取已激活插件 */
     $plugins = Typecho_Plugin::export();
     $activatedPlugins = $plugins['activated'];
     /** 获取插件入口 */
     list($pluginFileName, $className) = Typecho_Plugin::portal($this->request->plugin, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
     $info = Typecho_Plugin::parseInfo($pluginFileName);
     if (!$info['personalConfig'] || !isset($activatedPlugins[$pluginName])) {
         throw new Typecho_Widget_Exception(_t('无法配置插件'), 500);
     }
     $form = $this->personalForm($pluginName, $className, $pluginFileName, $group);
     $this->user->pass($group);
     /** 验证表单 */
     if ($form->validate()) {
         $this->response->goBack();
     }
     $settings = $form->getAllRequest();
     unset($settings['do'], $settings['plugin']);
     $name = '_plugin:' . $pluginName;
     if (!$this->personalConfigHandle($className, $settings)) {
         if ($this->db->fetchObject($this->db->select(array('COUNT(*)' => 'num'))->from('table.options')->where('name = ? AND user = ?', $name, $this->user->uid))->num > 0) {
             $this->widget('Widget_Abstract_Options')->update(array('value' => serialize($settings)), $this->db->sql()->where('name = ? AND user = ?', $name, $this->user->uid));
         } else {
             $this->widget('Widget_Abstract_Options')->insert(array('name' => $name, 'value' => serialize($settings), 'user' => $this->user->uid));
         }
     }
     /** 提示信息 */
     $this->widget('Widget_Notice')->set(_t("%s 设置已经保存", $info['title']), NULL, 'success');
     /** 转向原页 */
     $this->response->redirect(Typecho_Common::url('profile.php', $this->options->adminUrl));
 }
示例#9
0
 public function install()
 {
     $version = $this->request->get('version');
     $plugin = $this->request->get('plugin');
     $require = $this->request->get('require');
     $require === '*' and $require = '';
     $pluginPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/' . $plugin . '/';
     $pluginBackupPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/_' . $plugin . '/';
     $activatedPlugins = Typecho_Plugin::export();
     $existed = false;
     $activated = false;
     $tempFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/.app_store/' . $plugin . '-' . $version . '.zip';
     try {
         //检查版本
         list(, $buildVersion) = explode('/', Typecho_Common::VERSION);
         if (!Typecho_Plugin::checkDependence($buildVersion, $require)) {
             throw new VersionNotMatchException('版本不匹配,无法安装.');
         }
         //查看插件是否已经存在
         //查看插件是否已经激活
         if (file_exists($pluginPath)) {
             $existed = true;
             if (file_exists($pluginPath . 'Plugin.php') and isset($activatedPlugins['activated'][$plugin])) {
                 $activated = true;
             }
         }
         //插件如果存在,则需要备份下,后面出错可以进行回滚
         if ($existed or $activated) {
             file_exists($pluginBackupPath) and delete_files($pluginBackupPath) and @rmdir($pluginBackupPath);
             @rename($pluginPath, $pluginBackupPath);
         }
         //下载新插件zip包
         $archive = http_get($this->server . 'archive/' . $plugin . '/' . str_replace(' ', '%20', $version));
         if (!$archive) {
             throw new DownloadErrorException('下载插件包出错!');
         }
         //保存文件
         $fp = fopen($tempFile, 'w');
         fwrite($fp, $archive);
         fclose($fp);
         //解压缩文件
         $unzip = new Unzip();
         //创建文件夹
         @mkdir($pluginPath);
         $extractedFiles = $unzip->extract($tempFile, $pluginPath);
         if ($extractedFiles === false) {
             throw new UnzipErrorException('解压缩出错!');
         }
         //OK,解压缩成功了
         //删除备份文件
         file_exists($pluginBackupPath) and delete_files($pluginBackupPath) and @rmdir($pluginBackupPath);
         //删除临时文件
         @unlink($tempFile);
         //报告首长, 安装顺利完成
         echo json_encode(array('status' => true, 'activated' => $activated));
     } catch (VersionNotMatchException $e) {
         $e->responseJson();
     } catch (DownloadErrorException $e) {
         //如果存在备份包,则进行回滚
         file_exists($pluginBackupPath) and @rename($pluginBackupPath, $pluginPath);
         $e->responseJson();
     } catch (UnzipErrorException $e) {
         //清理解锁压缩的废弃文件
         file_exists($pluginPath) and delete_files($pluginPath) and @rmdir($pluginPath);
         //如果存在备份包,则进行回滚
         file_exists($pluginBackupPath) and @rename($pluginBackupPath, $pluginPath);
         //删除临时文件
         @unlink($tempFile);
         $e->responseJson();
     } catch (Exception $e) {
         $error = new JsonableException($e->getMessage());
         $error->responseJson();
     }
 }
示例#10
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();
 }