예제 #1
0
 /**
  * 更换外观
  *
  * @access public
  * @param string $theme 外观名称
  * @return void
  * @throws Typecho_Widget_Exception
  */
 public function changeTheme($theme)
 {
     $theme = trim($theme, './');
     if (is_dir($this->options->themeFile($theme))) {
         /** 删除原外观设置信息 */
         $this->delete($this->db->sql()->where('name = ?', 'theme:' . $this->options->theme));
         $this->update(array('value' => $theme), $this->db->sql()->where('name = ?', 'theme'));
         /** 解除首页关联 */
         if (0 === strpos($this->options->frontPage, 'file:')) {
             $this->update(array('value' => 'recent'), $this->db->sql()->where('name = ?', 'frontPage'));
         }
         $configFile = $this->options->themeFile($theme, 'functions.php');
         if (file_exists($configFile)) {
             require_once $configFile;
             if (function_exists('themeConfig')) {
                 $form = new Typecho_Widget_Helper_Form();
                 themeConfig($form);
                 $options = $form->getValues();
                 if ($options && !$this->configHandle($options, true)) {
                     $this->insert(array('name' => 'theme:' . $theme, 'value' => serialize($options), 'user' => 0));
                 }
             }
         }
         $this->widget('Widget_Notice')->highlight('theme-' . $theme);
         $this->widget('Widget_Notice')->set(_t("外观已经改变"), 'success');
         $this->response->goBack();
     } else {
         throw new Typecho_Widget_Exception(_t('您选择的风格不存在'));
     }
 }
예제 #2
0
파일: Config.php 프로젝트: raindali/express
 /**
  * 配置外观
  *
  * @access public
  * @return void
  */
 public function config()
 {
     $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/themes-edit?config', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD);
     themeConfig($form);
     $inputs = $form->getInputs();
     if (!empty($inputs)) {
         foreach ($inputs as $key => $val) {
             $form->getInput($key)->value($this->options->{$key});
         }
     }
     $form->addItem(new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('保存设置')));
     return $form;
 }
예제 #3
0
 /**
  * 配置外观
  *
  * @access public
  * @return Typecho_Widget_Helper_Form
  */
 public function config()
 {
     $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/themes-edit?config'), Typecho_Widget_Helper_Form::POST_METHOD);
     themeConfig($form);
     $inputs = $form->getInputs();
     if (!empty($inputs)) {
         foreach ($inputs as $key => $val) {
             $form->getInput($key)->value($this->options->{$key});
         }
     }
     $submit = new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('保存设置'));
     $submit->input->setAttribute('class', 'btn primary');
     $form->addItem($submit);
     return $form;
 }
예제 #4
0
function getThemeForm($theme)
{
    global $options;
    $configFile = $options->themeFile($theme, 'functions.php');
    $haveCfg = false;
    if (file_exists($configFile)) {
        require_once $configFile;
        if (function_exists('themeConfig')) {
            $haveCfg = true;
        }
    }
    if (!$haveCfg) {
        throw new Typecho_Widget_Exception(_t('外观配置功能不存在'), 404);
    }
    $form = new Typecho_Widget_Helper_Form(Helper::url('ThemeShow/config.php') . "&cfgtheme=" . $theme, Typecho_Widget_Helper_Form::POST_METHOD);
    themeConfig($form);
    return $form;
}
예제 #5
0
 /**
  * 插件实现方法
  *
  * @access public
  * @return void
  */
 public static function setTheme($widget)
 {
     $cookie = array('name' => '__typecho_theme', 'expire' => 86400);
     $options = Typecho_Widget::widget('Widget_Options');
     if (isset($widget->request->theme) && $widget->request->isGet()) {
         if ($widget->request->theme) {
             $theme = $widget->request->theme;
             if (static::check($theme)) {
                 Typecho_Cookie::set($cookie['name'], $widget->request->theme, $options->gmtTime + $cookie['expire'], $options->siteUrl);
             } else {
                 $widget->response->redirect(Typecho_Common::url($widget->request->getPathInfo(), $options->siteUrl));
             }
         } else {
             Typecho_Cookie::delete($cookie['name']);
             //直接提交?theme将删除cookie,恢复默认主题
             return;
         }
     } else {
         $theme = Typecho_Cookie::get($cookie['name']);
         if (!$theme) {
             return;
         }
         if (!static::check($theme)) {
             Typecho_Cookie::delete($cookie['name']);
             return;
         }
     }
     /** 删除旧主题的相关设置 */
     $themeRow = 'theme:' . $options->theme;
     if (isset($options->{$themeRow})) {
         $config = unserialize($options->{$themeRow});
         $options->{$themeRow} = '';
         foreach ($config as $row => $value) {
             $options->{$row} = '';
         }
     }
     /** 载入新主题的相关设置 参考var/Widget/Themes/Edit.php */
     $themeDir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR;
     $configFile = $themeDir . 'functions.php';
     if (file_exists($configFile)) {
         require_once $configFile;
         if (function_exists('themeConfig')) {
             $form = new Typecho_Widget_Helper_Form();
             themeConfig($form);
             $config = $form->getValues();
             if ($config) {
                 $options->{'theme:' . $theme} = serialize($config);
                 foreach ($config as $row => $value) {
                     $options->{$row} = $value;
                 }
             }
         }
     }
     /** 修改$this->options->theme */
     $options->theme = $theme;
     /** 修改$this->_themeDir */
     $widget->setThemeDir($themeDir);
 }
예제 #6
0
 public static function configTheme($form, $default = array())
 {
     //$options = Typecho_Widget::widget('Widget_Options');
     //如果模板有设置函数
     if (self::isExists()) {
         themeConfig($form);
         $inputs = $form->getInputs();
         //var_dump($inputs);
         if (!empty($inputs)) {
             foreach ($inputs as $key => $val) {
                 if (isset($default[$key])) {
                     $form->getInput($key)->value($default[$key]);
                 }
             }
         }
     }
     return $form;
 }