Пример #1
0
 /**
  * 创建表单标题
  *
  * @access public
  * @param string $value 标题字符串
  * @return Typecho_Widget_Helper_Form_Element
  */
 public function label($value)
 {
     /** 创建标题元素 */
     if (empty($this->label)) {
         $this->label = new Typecho_Widget_Helper_Layout('label', array('class' => 'typecho-label'));
         $this->container($this->label);
     }
     $this->label->html($value);
     return $this;
 }
Пример #2
0
    /**
     * 获取插件配置面板
     * 
     * @access public
     * @param Typecho_Widget_Helper_Form $form 配置面板
     * @return void
     */
    public static function config(Typecho_Widget_Helper_Form $form)
    {
        $introduce = new Typecho_Widget_Helper_Layout("div");
        $introduce->html(<<<EOI
<p>在 Typecho 正式显示 404 之前,此插件会遍历列表并作出跳转。</p>
<p>规则列表一行一个,格式为: Pattern   Rewrite结果  [flags]</p>
<p>比如【 <code class="success">^\\/(\\d+)\\/?\$  /archives/\$1   T</code> 】可以把 /12 以302重定向跳转到 /archivers/12 </p>
<p><a href="https://github.com/laobubu/Typecho_rewriterule">详细说明看这里</a></p>
EOI
);
        $rules = new Typecho_Widget_Helper_Form_Element_Textarea('rules', NULL, '不符合书写规范的行可以当注释哦', _t('规则列表'));
        $form->addInput($rules);
        $form->addItem($introduce);
    }
Пример #3
0
 public static function config(Typecho_Widget_Helper_Form $form)
 {
     $help = new Typecho_Widget_Helper_Layout('div', array('style' => 'color: #999; background-color: #eee; border-radius: 10px; padding: 10px;'));
     $help->html("<strong>使用方法</strong><pre><small>```c#\nConsole.Write(\"Hello World!\");\n```\n或行内代码\n`js console.log(\"Hi!\");`</small></pre>");
     $form->addItem($help);
     $themes = array_map('basename', glob(dirname(__FILE__) . '/themes/*.css'));
     $themes = array_combine($themes, $themes);
     $theme = new Typecho_Widget_Helper_Form_Element_Select('theme', $themes, 'prism-coy.css', _t('代码样式'));
     $form->addInput($theme->addRule('enum', _t('必须选择样式'), $themes));
     $showLineNumber = new Typecho_Widget_Helper_Form_Element_Checkbox('showln', array('showln' => _t('显示行号')), array('showln'), _t('是否在大段代码左侧显示行号'));
     $form->addInput($showLineNumber);
     $forceWrap = new Typecho_Widget_Helper_Form_Element_Checkbox('forceWrap', array('forceWrap' => _t('强制换行')), array('forceWrap'), _t('是否强制换行'));
     $form->addInput($forceWrap);
     $showLang = new Typecho_Widget_Helper_Form_Element_Checkbox('showlang', array('showlang' => _t('显示语言标签')), array('showlang'), _t('是否在大段代码右上角显示语言'));
     $form->addInput($showLang);
 }
Пример #4
0
 /**
  * 生成表单
  *
  * @access public
  * @param string $action 表单动作
  * @return Typecho_Widget_Helper_Form_Element
  */
 public function form($action = NULL)
 {
     /** 构建表格 */
     $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/contents-attachment-edit', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD);
     /** 文件名称 */
     $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, $this->title, _t('标题 *'));
     $form->addInput($name);
     /** 文件缩略名 */
     $slug = new Typecho_Widget_Helper_Form_Element_Text('slug', NULL, $this->slug, _t('缩略名'), _t('文件缩略名用于创建友好的链接形式,建议使用字母,数字,下划线和横杠.'));
     $form->addInput($slug);
     /** 文件描述 */
     $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, $this->attachment->description, _t('描述'), _t('此文字用于描述文件,在有的主题中它会被显示.'));
     $form->addInput($description);
     /** 分类动作 */
     $do = new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'update');
     $form->addInput($do);
     /** 分类主键 */
     $cid = new Typecho_Widget_Helper_Form_Element_Hidden('cid', NULL, $this->cid);
     $form->addInput($cid);
     /** 提交按钮 */
     $submit = new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('提交修改'));
     $submit->input->setAttribute('class', 'primary');
     $delete = new Typecho_Widget_Helper_Layout('a', array('href' => Typecho_Common::url('/action/contents-attachment-edit?do=delete&cid=' . $this->cid, $this->options->index), 'class' => 'operate-delete', 'lang' => _t('你确认删除文件 %s 吗?', $this->attachment->name)));
     $submit->container($delete->html(_t('删除文件')));
     $form->addItem($submit);
     $name->addRule('required', _t('必须填写文件标题'));
     $name->addRule(array($this, 'nameToSlug'), _t('文件标题无法被转换为缩略名'));
     $slug->addRule(array($this, 'slugExists'), _t('缩略名已经存在'));
     return $form;
 }
Пример #5
0
 /**
  * 双因素认证表单
  *
  * @access public
  * @return Typecho_Widget_Helper_Form
  */
 public function twoFactorAuthForm()
 {
     /** 构建表格 */
     $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/users-profile'), Typecho_Widget_Helper_Form::POST_METHOD);
     if ($this->user->twoFactorAuthKey) {
         /** 验证码确认 */
         $confirm = new Typecho_Widget_Helper_Form_Element_Text('confirm', NULL, NULL, _t('验证码'), _t('请输入验证码以停用双因素认证.'));
         $confirm->input->setAttribute('class', 'w-60');
         $confirm->addRule('required', _t('请输入验证码'));
         $form->addInput($confirm);
         $form->addItem(new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'twoFactorAuth'));
         $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('停用双因素认证'));
         $submit->input->setAttribute('class', 'btn primary');
         $form->addItem($submit);
     } else {
         /** 生成密钥 */
         $secret = $this->widget('Widget_GoogleAuthenticator')->createSecret();
         $qrlink = $this->widget('Widget_GoogleAuthenticator')->getQRCodeGoogleUrl('Typecho Blog', $secret);
         $text = new Typecho_Widget_Helper_Layout('p', array());
         $text->html(_t('请在手机上添加密钥 %s,并在下方输入手机上显示的验证码.<br><a href="%s" target="_blank">扫描二维码</a>', $secret, $qrlink));
         $form->addItem($text);
         /** 确认 */
         $confirm = new Typecho_Widget_Helper_Form_Element_Text('confirm', NULL, NULL, _t('验证码'), NULL);
         $confirm->input->setAttribute('class', 'w-60');
         $confirm->addRule('required', _t('请输入验证码以确保双因素认证正确配置'));
         $form->addInput($confirm);
         $form->addItem(new Typecho_Widget_Helper_Form_Element_Hidden('secret', NULL, $secret));
         $form->addItem(new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'twoFactorAuth'));
         $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('启用双因素认证'));
         $submit->input->setAttribute('class', 'btn primary');
         $form->addItem($submit);
     }
     return $form;
 }