Esempio n. 1
0
 /**
  * 输出表单结构
  *
  * @access public
  * @return Typecho_Widget_Helper_Form
  */
 public function form()
 {
     /** 构建表格 */
     $form = new Typecho_Widget_Helper_Form($this->security->getRootUrl('index.php/action/options-permalink'), Typecho_Widget_Helper_Form::POST_METHOD);
     if (!defined('__TYPECHO_REWRITE__')) {
         /** 是否使用地址重写功能 */
         $rewrite = new Typecho_Widget_Helper_Form_Element_Radio('rewrite', array('0' => _t('不启用'), '1' => _t('启用')), $this->options->rewrite, _t('是否使用地址重写功能'), _t('地址重写即 rewrite 功能是某些服务器软件提供的优化内部连接的功能.') . '<br />' . _t('打开此功能可以让你的链接看上去完全是静态地址.'));
         // disable rewrite check when rewrite opened
         if (!$this->options->rewrite && !$this->request->is('enableRewriteAnyway=1')) {
             $errorStr = _t('重写功能检测失败, 请检查你的服务器设置');
             /** 如果是apache服务器, 可能存在无法写入.htaccess文件的现象 */
             if ((isset($_SERVER['SERVER_SOFTWARE']) && false !== strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') || function_exists('apache_get_version')) && !file_exists(__TYPECHO_ROOT_DIR__ . '/.htaccess') && !is_writeable(__TYPECHO_ROOT_DIR__)) {
                 $errorStr .= '<br /><strong>' . _t('我们检测到你使用了apache服务器, 但是程序无法在根目录创建.htaccess文件, 这可能是产生这个错误的原因.') . _t('请调整你的目录权限, 或者手动创建一个.htaccess文件.') . '</strong>';
             }
             $errorStr .= '<br /><input type="checkbox" name="enableRewriteAnyway" id="enableRewriteAnyway" value="1" />' . ' <label for="enableRewriteAnyway">' . _t('如果你仍然想启用此功能, 请勾选这里') . '</label>';
             $rewrite->addRule(array($this, 'checkRewrite'), $errorStr);
         }
         $form->addInput($rewrite);
     }
     $patterns = array('/archives/[cid:digital]/' => _t('默认风格') . ' <code>/archives/{cid}/</code>', '/archives/[slug].html' => _t('wordpress风格') . ' <code>/archives/{slug}.html</code>', '/[year:digital:4]/[month:digital:2]/[day:digital:2]/[slug].html' => _t('按日期归档') . ' <code>/archives/{year}/{month}/{day}/{slug}.html</code>', '/[category]/[slug].html' => _t('按分类归档') . ' <code>/{category}/{slug}.html</code>');
     /** 自定义文章路径 */
     $postPatternValue = $this->options->routingTable['post']['url'];
     /** 增加个性化路径 */
     $customPatternValue = NULL;
     if (isset($this->request->__typecho_form_item_postPattern)) {
         $customPatternValue = $this->request->__typecho_form_item_postPattern;
         Typecho_Cookie::delete('__typecho_form_item_postPattern');
     } else {
         if (!isset($patterns[$postPatternValue])) {
             $customPatternValue = $this->decodeRule($postPatternValue);
         }
     }
     $patterns['custom'] = _t('个性化定义') . ' <input type="text" class="w-50 text-s mono" name="customPattern" value="' . $customPatternValue . '" />';
     $postPattern = new Typecho_Widget_Helper_Form_Element_Radio('postPattern', $patterns, $postPatternValue, _t('自定义文章路径'), _t('可用参数: <code>{cid}</code> 日志 ID, <code>{slug}</code> 日志缩略名, <code>{category}</code> 分类, <code>{directory}</code> 多级分类, <code>{year}</code> 年, <code>{month}</code> 月, <code>{day}</code> 日') . '<br />' . _t('选择一种合适的文章静态路径风格, 使得你的网站链接更加友好.') . '<br />' . _t('一旦你选择了某种链接风格请不要轻易修改它.'));
     if ($customPatternValue) {
         $postPattern->value('custom');
     }
     $form->addInput($postPattern->multiMode());
     /** 独立页面后缀名 */
     $pagePattern = new Typecho_Widget_Helper_Form_Element_Text('pagePattern', NULL, $this->decodeRule($this->options->routingTable['page']['url']), _t('独立页面路径'), _t('可用参数: <code>{cid}</code> 页面 ID, <code>{slug}</code> 页面缩略名') . '<br />' . _t('请在路径中至少包含上述的一项参数.'));
     $pagePattern->input->setAttribute('class', 'mono w-60');
     $form->addInput($pagePattern->addRule(array($this, 'checkPagePattern'), _t('独立页面路径中没有包含 {cid} 或者 {slug} ')));
     /** 分类页面 */
     $categoryPattern = new Typecho_Widget_Helper_Form_Element_Text('categoryPattern', NULL, $this->decodeRule($this->options->routingTable['category']['url']), _t('分类路径'), _t('可用参数: <code>{mid}</code> 分类 ID, <code>{slug}</code> 分类缩略名, <code>{directory}</code> 多级分类') . '<br />' . _t('请在路径中至少包含上述的一项参数.'));
     $categoryPattern->input->setAttribute('class', 'mono w-60');
     $form->addInput($categoryPattern->addRule(array($this, 'checkCategoryPattern'), _t('分类路径中没有包含 {mid} 或者 {slug} ')));
     /** 提交按钮 */
     $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置'));
     $submit->input->setAttribute('class', 'btn primary');
     $form->addItem($submit);
     return $form;
 }
Esempio n. 2
0
 /**
  * 输出表单结构
  *
  * @access public
  * @return Typecho_Widget_Helper_Form
  */
 public function form()
 {
     /** 构建表格 */
     $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('index.php/action/options-permalink', $this->options->siteUrl), Typecho_Widget_Helper_Form::POST_METHOD);
     /** 是否使用地址重写功能 */
     $rewrite = new Typecho_Widget_Helper_Form_Element_Radio('rewrite', array('0' => _t('不启用'), '1' => _t('启用')), $this->options->rewrite, _t('是否使用地址重写功能'), _t('地址重写即rewrite功能是某些服务器软件提供的优化内部连接的功能.<br />
     打开此功能可以让你的链接看上去完全是静态地址.'));
     $errorStr = _t('重写功能检测失败, 请检查你的服务器设置');
     /** 如果是apache服务器, 可能存在无法写入.htaccess文件的现象 */
     if ((isset($_SERVER['SERVER_SOFTWARE']) && false !== strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') || function_exists('apache_get_version')) && !file_exists(__TYPECHO_ROOT_DIR__ . '/.htaccess') && !is_writeable(__TYPECHO_ROOT_DIR__)) {
         $errorStr .= '<br /><strong>' . _t('我们检测到你使用了apache服务器, 但是程序无法在根目录创建.htaccess文件, 这可能是产生这个错误的原因.
         请调整你的目录权限, 或者手动创建一个.htaccess文件.') . '</strong>';
     }
     $errorStr .= _t('<br />如果你仍然想启用此功能, <a href="%s">请点击这里</a>', Typecho_Common::url('index.php/action/options-permalink?do=enableRewriteAnyway', $this->options->siteUrl));
     $form->addInput($rewrite->addRule(array($this, 'checkRewrite'), $errorStr));
     $patterns = array('/archives/[cid:digital]/' => _t('默认风格') . ' <strong><small>/archives/{cid}/</small></strong>', '/archives/[slug].html' => _t('wordpress风格') . ' <strong><small>/archives/{slug}.html</small></strong>', '/[year:digital:4]/[month:digital:2]/[day:digital:2]/[slug].html' => _t('按日期归档') . ' <strong><small>/archives/{year}/{month}/{day}/{slug}.html</small></strong>', '/[category]/[slug].html' => _t('按分类归档') . ' <strong><small>/{category}/{slug}.html</small></strong>');
     /** 自定义文章路径 */
     $postPatternValue = $this->options->routingTable['post']['url'];
     /** 增加个性化路径 */
     $customPatternValue = NULL;
     if (isset($this->request->__typecho_form_item_postPattern)) {
         $customPatternValue = $this->request->__typecho_form_item_postPattern;
         Typecho_Cookie::delete('__typecho_form_item_postPattern');
     } else {
         if (!isset($patterns[$postPatternValue])) {
             $customPatternValue = $this->decodeRule($postPatternValue);
         }
     }
     $patterns['custom'] = _t('个性化定义') . ' <input type="text" style="width: 250px;" name="customPattern" value="' . $customPatternValue . '" />';
     $postPattern = new Typecho_Widget_Helper_Form_Element_Radio('postPattern', $patterns, $postPatternValue, _t('自定义文章路径'), _t('可用参数:{cid} 日志ID、{slug} 日志缩略名、{category} 分类、{year} 年、{month} 月、{day} 日<br />选择一种合适的文章静态路径风格, 使得你的网站链接更加友好.<br />
     一旦你选择了某种链接风格请不要轻易修改它.'));
     if ($customPatternValue) {
         $postPattern->value('custom');
     }
     $form->addInput($postPattern->multiMode());
     /** 独立页面后缀名 */
     $pageSuffixValue = false !== ($pos = strrpos($this->options->routingTable['page']['url'], '.')) ? substr($this->options->routingTable['page']['url'], $pos) : '/';
     $pageSuffix = new Typecho_Widget_Helper_Form_Element_Radio('pageSuffix', array('/' => '<strong>' . _t('无') . '</strong>', '.html' => '<strong>html</strong>', '.htm' => '<strong>htm</strong>', '.php' => '<strong>php</strong>'), $pageSuffixValue, _t('独立页面后缀名'), _t('给独立页面设置一种文件后缀名, 使得它看起来像
     <br /><strong>%s</strong>', Typecho_Common::url('example.html', $this->options->index)));
     $form->addInput($pageSuffix);
     /** 提交按钮 */
     $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置'));
     $form->addItem($submit);
     return $form;
 }