Beispiel #1
0
 /**
  * 执行函数
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     $themes = $this->getThemes();
     if ($themes) {
         $options = $this->widget('Widget_Options');
         $siteUrl = $options->siteUrl;
         $adminUrl = $options->adminUrl;
         $activated = 0;
         $result = array();
         foreach ($themes as $key => $theme) {
             $themeFile = $theme . '/index.php';
             if (file_exists($themeFile)) {
                 $info = Typecho_Plugin::parseInfo($themeFile);
                 $info['name'] = $this->getTheme($theme, $key);
                 if ($info['activated'] = $options->theme == $info['name']) {
                     $activated = $key;
                 }
                 $screen = glob($theme . '/screen*.{jpg,png,gif,bmp,jpeg,JPG,PNG,GIF,BMG,JPEG}', GLOB_BRACE);
                 if ($screen) {
                     $info['screen'] = $options->themeUrl(basename(current($screen)), $info['name']);
                 } else {
                     $info['screen'] = Typecho_Common::url('noscreen.png', $options->adminStaticUrl('img'));
                 }
                 $result[$key] = $info;
             }
         }
         $clone = $result[$activated];
         unset($result[$activated]);
         array_unshift($result, $clone);
         array_filter($result, array($this, 'push'));
     }
 }
Beispiel #2
0
 /**
  * 执行函数
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     $themes = glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*');
     if ($themes) {
         $options = $this->widget('Widget_Options');
         $siteUrl = $options->siteUrl;
         $adminUrl = $options->adminUrl;
         $activated = 0;
         $result = array();
         foreach ($themes as $key => $theme) {
             $themeFile = $theme . '/index.php';
             if (file_exists($themeFile)) {
                 $info = Typecho_Plugin::parseInfo($themeFile);
                 $info['name'] = basename($theme);
                 if ($info['activated'] = $options->theme == $info['name']) {
                     $activated = $key;
                 }
                 $screen = glob($theme . '/screen*.{jpg,png,gif,bmp,jpeg,JPG,PNG,GIF,BMG,JPEG}', GLOB_BRACE);
                 if ($screen) {
                     $info['screen'] = Typecho_Common::url(trim(__TYPECHO_THEME_DIR__, '/') . '/' . $info['name'] . '/' . basename(current($screen)), $siteUrl);
                 } else {
                     $info['screen'] = Typecho_Common::url('/images/noscreen.gif', $adminUrl);
                 }
                 $result[$key] = $info;
             }
         }
         $clone = $result[$activated];
         unset($result[$activated]);
         array_unshift($result, $clone);
         array_filter($result, array($this, 'push'));
     }
 }
Beispiel #3
0
 /**
  * 应用商店主页
  *
  */
 public function market()
 {
     //获取插件列表
     $result = json_decode(http_get($this->server . 'packages.json'));
     if ($result) {
         //导出已激活插件
         $activatedPlugins = Typecho_Plugin::export();
         foreach ($result->packages as &$_package) {
             $pluginPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/' . $_package->name . '/';
             $pluginEntry = $pluginPath . 'Plugin.php';
             $_package->existed = 0;
             if (file_exists($pluginEntry)) {
                 $_package->existed = 1;
                 $pluginMeta = Typecho_Plugin::parseInfo($pluginEntry);
                 foreach ($_package->versions as &$_version) {
                     $_version->activated = 0;
                     $_version->description = strip_tags($_version->description);
                     $_version->author = strip_tags($_version->author);
                     if ($_version->version == $pluginMeta['version'] and isset($activatedPlugins['activated'][$_package->name])) {
                         $_version->activated = 1;
                     }
                 }
             } else {
                 foreach ($_package->versions as &$_version) {
                     $_version->description = strip_tags($_version->description);
                     $_version->author = strip_tags($_version->author);
                     $_version->activated = 0;
                 }
             }
         }
     }
     include 'views/market.php';
 }
Beispiel #4
0
 /**
  * 绑定动作
  *
  * @access public
  * @return unknown
  */
 public function execute()
 {
     $this->user->pass('administrator');
     if (!isset($this->request->config)) {
         throw new Typecho_Widget_Exception(_t('插件不存在'), 404);
     }
     /** 获取插件入口 */
     list($this->_pluginFileName, $this->_className) = Typecho_Plugin::portal($this->request->config, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
     $this->info = Typecho_Plugin::parseInfo($this->_pluginFileName);
 }
Beispiel #5
0
 /**
  * 绑定动作
  *
  * @access public
  */
 public function execute()
 {
     $this->user->pass('administrator');
     $config = $this->request->filter('slug')->config;
     if (empty($config)) {
         throw new Typecho_Widget_Exception(_t('插件不存在'), 404);
     }
     /** 获取插件入口 */
     list($this->_pluginFileName, $this->_className) = Typecho_Plugin::portal($config, $this->options->pluginDir($config));
     $this->info = Typecho_Plugin::parseInfo($this->_pluginFileName);
 }
Beispiel #6
0
 /**
  * 激活插件
  *
  * @access public
  * @return void
  */
 public function activate($pluginName)
 {
     /** 获取插件入口 */
     list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
     $info = Typecho_Plugin::parseInfo($pluginFileName);
     /** 检测依赖信息 */
     list($version, $build) = explode('/', Typecho_Common::VERSION);
     if (Typecho_Plugin::checkDependence($build, $info['dependence'])) {
         /** 获取已激活插件 */
         $plugins = Typecho_Plugin::export();
         $activatedPlugins = $plugins['activated'];
         /** 载入插件 */
         require_once $pluginFileName;
         /** 判断实例化是否成功 */
         if (isset($activatedPlugins[$pluginName]) || !class_exists($className) || !method_exists($className, 'activate')) {
             throw new Typecho_Widget_Exception(_t('无法激活插件'), 500);
         }
         try {
             $result = call_user_func(array($className, 'activate'));
             Typecho_Plugin::activate($pluginName);
             $this->update(array('value' => serialize(Typecho_Plugin::export())), $this->db->sql()->where('name = ?', 'plugins'));
         } catch (Typecho_Plugin_Exception $e) {
             /** 截获异常 */
             $this->widget('Widget_Notice')->set($e->getMessage(), NULL, 'error');
             $this->response->goBack();
         }
         $form = new Typecho_Widget_Helper_Form();
         call_user_func(array($className, 'config'), $form);
         $personalForm = new Typecho_Widget_Helper_Form();
         call_user_func(array($className, 'personalConfig'), $personalForm);
         $options = $form->getValues();
         $personalOptions = $personalForm->getValues();
         if ($options && !$this->configHandle($pluginName, $options, true)) {
             self::configPlugin($pluginName, $options);
         }
         if ($personalOptions && !$this->personalConfigHandle($className, $personalOptions)) {
             self::configPlugin($pluginName, $personalOptions, true);
         }
     } else {
         $result = _t('<a href="%s">%s</a> 无法在此版本的typecho下正常工作', $info['link'], $info['title']);
     }
     /** 设置高亮 */
     $this->widget('Widget_Notice')->highlight('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();
 }
Beispiel #7
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);
                 }
             }
         }
     }
 }
Beispiel #8
0
 /**
  * 获取当前所有自定义模板
  *
  * @access public
  * @return array
  */
 public function getTemplates()
 {
     $files = glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/*.php');
     $result = array();
     foreach ($files as $file) {
         $info = Typecho_Plugin::parseInfo($file);
         $file = basename($file);
         if ('index.php' != $file && 'custom' == $info['title']) {
             $result[$file] = $info['description'];
         }
     }
     return $result;
 }
Beispiel #9
0
 /**
  * 获取当前所有自定义模板
  *
  * @access public
  * @return array
  */
 public function getTemplates()
 {
     $files = glob($this->options->themeFile($this->options->theme . '/category', '*.php'));
     $result = array();
     foreach ($files as $file) {
         $info = Typecho_Plugin::parseInfo($file);
         $file = basename($file);
         if ('index.php' != $file && 'custom' == $info['title']) {
             $result[$file] = $info['description'];
         }
     }
     return $result;
 }
Beispiel #10
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));
 }
Beispiel #11
0
    /**
     * 输出表单结构
     *
     * @access public
     * @return Typecho_Widget_Helper_Form
     */
    public function form()
    {
        /** 构建表格 */
        $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/options-reading'), Typecho_Widget_Helper_Form::POST_METHOD);
        /** 文章日期格式 */
        $postDateFormat = new Typecho_Widget_Helper_Form_Element_Text('postDateFormat', NULL, $this->options->postDateFormat, _t('文章日期格式'), _t('此格式用于指定显示在文章归档中的日期默认显示格式.') . '<br />' . _t('在某些主题中这个格式可能不会生效, 因为主题作者可以自定义日期格式.') . '<br />' . _t('请参考 <a href="http://www.php.net/manual/zh/function.date.php">PHP 日期格式写法</a>.'));
        $postDateFormat->input->setAttribute('class', 'w-40 mono');
        $form->addInput($postDateFormat->addRule('xssCheck', _t('请不要在日期格式中使用特殊字符')));
        //首页显示
        $frontPageParts = explode(':', $this->options->frontPage);
        $frontPageType = $frontPageParts[0];
        $frontPageValue = count($frontPageParts) > 1 ? $frontPageParts[1] : '';
        $frontPageOptions = array('recent' => _t('显示最新发布的文章'));
        $frontPattern = '</label></span><span class="multiline front-archive%class%">' . '<input type="checkbox" id="frontArchive" name="frontArchive" value="1"' . ($this->options->frontArchive && 'recent' != $frontPageType ? ' checked' : '') . ' />
<label for="frontArchive">' . _t('同时将文章列表页路径更改为 %s', '<input type="text" name="archivePattern" class="w-20 mono" value="' . htmlspecialchars($this->decodeRule($this->options->routingTable['archive']['url'])) . '" />') . '</label>';
        // 页面列表
        $pages = $this->db->fetchAll($this->db->select('cid', 'title')->from('table.contents')->where('type = ?', 'page')->where('status = ?', 'publish')->where('created < ?', $this->options->gmtTime));
        if (!empty($pages)) {
            $pagesSelect = '<select name="frontPagePage" id="frontPage-frontPagePage">';
            foreach ($pages as $page) {
                $selected = '';
                if ('page' == $frontPageType && $page['cid'] == $frontPageValue) {
                    $selected = ' selected="true"';
                }
                $pagesSelect .= '<option value="' . $page['cid'] . '"' . $selected . '>' . $page['title'] . '</option>';
            }
            $pagesSelect .= '</select>';
            $frontPageOptions['page'] = _t('使用 %s 页面作为首页', '</label>' . $pagesSelect . '<label for="frontPage-frontPagePage">');
            $selectedFrontPageType = 'page';
        }
        // 自定义文件列表
        $files = glob($this->options->themeFile($this->options->theme, '*.php'));
        $filesSelect = '';
        foreach ($files as $file) {
            $info = Typecho_Plugin::parseInfo($file);
            $file = basename($file);
            if ('index.php' != $file && 'index' == $info['title']) {
                $selected = '';
                if ('file' == $frontPageType && $file == $frontPageValue) {
                    $selected = ' selected="true"';
                }
                $filesSelect .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
            }
        }
        if (!empty($filesSelect)) {
            $frontPageOptions['file'] = _t('直接调用 %s 模板文件', '</label><select name="frontPageFile" id="frontPage-frontPageFile">' . $filesSelect . '</select><label for="frontPage-frontPageFile">');
            $selectedFrontPageType = 'file';
        }
        if (isset($frontPageOptions[$frontPageType]) && 'recent' != $frontPageType && isset($selectedFrontPageType)) {
            $selectedFrontPageType = $frontPageType;
            $frontPattern = str_replace('%class%', '', $frontPattern);
        }
        if (isset($selectedFrontPageType)) {
            $frontPattern = str_replace('%class%', ' hidden', $frontPattern);
            $frontPageOptions[$selectedFrontPageType] .= $frontPattern;
        }
        $frontPage = new Typecho_Widget_Helper_Form_Element_Radio('frontPage', $frontPageOptions, $frontPageType, _t('站点首页'));
        $form->addInput($frontPage->multiMode());
        /** 文章列表数目 */
        $postsListSize = new Typecho_Widget_Helper_Form_Element_Text('postsListSize', NULL, $this->options->postsListSize, _t('文章列表数目'), _t('此数目用于指定显示在侧边栏中的文章列表数目.'));
        $postsListSize->input->setAttribute('class', 'w-20');
        $form->addInput($postsListSize->addRule('isInteger', _t('请填入一个数字')));
        /** 每页文章数目 */
        $pageSize = new Typecho_Widget_Helper_Form_Element_Text('pageSize', NULL, $this->options->pageSize, _t('每页文章数目'), _t('此数目用于指定文章归档输出时每页显示的文章数目.'));
        $pageSize->input->setAttribute('class', 'w-20');
        $form->addInput($pageSize->addRule('isInteger', _t('请填入一个数字')));
        /** FEED全文输出 */
        $feedFullText = new Typecho_Widget_Helper_Form_Element_Radio('feedFullText', array('0' => _t('仅输出摘要'), '1' => _t('全文输出')), $this->options->feedFullText, _t('聚合全文输出'), _t('如果你不希望在聚合中输出文章全文,请使用仅输出摘要选项.') . '<br />' . _t('摘要的文字取决于你在文章中使用分隔符的位置.'));
        $form->addInput($feedFullText);
        /** 提交按钮 */
        $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置'));
        $submit->input->setAttribute('class', 'btn primary');
        $form->addItem($submit);
        return $form;
    }
Beispiel #12
0
 /**
  * 输出表单结构
  *
  * @access public
  * @return Typecho_Widget_Helper_Form
  */
 public function form()
 {
     /** 构建表格 */
     $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/options-reading', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD);
     /** 文章日期格式 */
     $postDateFormat = new Typecho_Widget_Helper_Form_Element_Text('postDateFormat', NULL, $this->options->postDateFormat, _t('文章日期格式'), _t('此格式用于指定显示在文章归档中的日期默认显示格式.<br />
     在某些主题中这个格式可能不会生效, 因为主题作者可以自定义日期格式.<br />
     请参考<a href="http://cn.php.net/manual/zh/function.date.php">PHP日期格式写法</a>.'));
     $form->addInput($postDateFormat);
     //首页显示
     $frontPageParts = explode(':', $this->options->frontPage);
     $frontPageType = $frontPageParts[0];
     $frontPageValue = count($frontPageParts) > 1 ? $frontPageParts[1] : '';
     $frontPageOptions = array('recent' => _t('显示最新发布的文章'));
     // 页面列表
     $pages = $this->db->fetchAll($this->db->select('cid', 'title')->from('table.contents')->where('type = ?', 'page')->where('status = ?', 'publish')->where('created < ?', $this->options->gmtTime));
     if (!empty($pages)) {
         $pagesSelect = '<select name="frontPagePage" id="frontPage-frontPagePage">';
         foreach ($pages as $page) {
             $selected = '';
             if ('page' == $frontPageType && $page['cid'] == $frontPageValue) {
                 $selected = ' selected="true"';
             }
             $pagesSelect .= '<option value="' . $page['cid'] . '"' . $selected . '>' . $page['title'] . '</option>';
         }
         $pagesSelect .= '</select>';
         $frontPageOptions['page'] = _t('使用 %s 页面作为首页', '</label>' . $pagesSelect . '<label for="frontPage-frontPagePage">');
     }
     // 自定义文件列表
     $files = glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/*.php');
     $filesSelect = '';
     foreach ($files as $file) {
         $info = Typecho_Plugin::parseInfo($file);
         $file = basename($file);
         if ('index.php' != $file && 'index' == $info['title']) {
             $selected = '';
             if ('file' == $frontPageType && $file == $frontPageValue) {
                 $selected = ' selected="true"';
             }
             $filesSelect .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
         }
     }
     if (!empty($filesSelect)) {
         $frontPageOptions['file'] = _t('直接调用 %s 模板文件', '</label><select name="frontPageFile" id="frontPage-frontPageFile">' . $filesSelect . '</select><label for="frontPage-frontPageFile">');
     }
     $frontPage = new Typecho_Widget_Helper_Form_Element_Radio('frontPage', $frontPageOptions, $frontPageType, _t('站点首页'));
     $form->addInput($frontPage->multiMode());
     /** 文章列表数目 */
     $postsListSize = new Typecho_Widget_Helper_Form_Element_Text('postsListSize', NULL, $this->options->postsListSize, _t('文章列表数目'), _t('此数目用于指定显示在侧边拦中的文章列表数目.'));
     $postsListSize->input->setAttribute('class', 'mini');
     $form->addInput($postsListSize->addRule('isInteger', _t('请填入一个数字')));
     /** 每页文章数目 */
     $pageSize = new Typecho_Widget_Helper_Form_Element_Text('pageSize', NULL, $this->options->pageSize, _t('每页文章数目'), _t('此数目用于指定文章归档输出时每页显示的文章数目.'));
     $pageSize->input->setAttribute('class', 'mini');
     $form->addInput($pageSize->addRule('isInteger', _t('请填入一个数字')));
     /** FEED全文输出 */
     $feedFullText = new Typecho_Widget_Helper_Form_Element_Radio('feedFullText', array('0' => _t('仅输出摘要'), '1' => _t('全文输出')), $this->options->feedFullText, _t('聚合全文输出'), _t('如果你不希望在聚合中输出文章全文,请使用仅输出摘要选项.<br />
     摘要的文字取决于你在文章中使用分隔符的位置.'));
     $form->addInput($feedFullText);
     /** 提交按钮 */
     $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置'));
     $form->addItem($submit);
     return $form;
 }
Beispiel #13
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);
                 }
             }
         }
     }
 }