/** * 获取插件配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ public static function config(Typecho_Widget_Helper_Form $form) { $editorThemeOptions = array('default' => '默认风格', 'simple' => '简洁风格', 'qq' => 'QQ风格'); $editorTheme = new Typecho_Widget_Helper_Form_Element_Select('editorTheme', $editorThemeOptions, 'default', _t('皮肤')); $editorLangOptions = array('zh_CN' => '中文简体', 'en' => 'English'); $editorLang = new Typecho_Widget_Helper_Form_Element_Select('editorLang', $editorLangOptions, 'zh_CN', '语言'); $line = new Typecho_Widget_Helper_Layout('hr'); $editorNewlineTagOptions = array('br' => '新开始行', 'p' => '新开始段落'); $editorNewlineTag = new Typecho_Widget_Helper_Form_Element_Radio('editorNewlineTag', $editorNewlineTagOptions, 'p', _t('回车处理')); $editorPasteTypeOptions = array('0' => '禁止', '1' => '纯文本', '2' => 'HTML'); $editorPasteType = new Typecho_Widget_Helper_Form_Element_Radio('editorPasteType', $editorPasteTypeOptions, '2', _t('粘贴类型')); $editorToolsOptions = array('source' => 'HTML代码', '|' => '分隔', 'undo' => '后退', 'redo' => '前进', '|1' => '分隔', 'preview' => '预览', 'wordpaste' => '从Word粘贴', 'print' => '打印', 'template' => '插入模板', 'code' => '插入程序代码', 'cut' => '剪切', 'copy' => ' 复制', 'paste' => '粘贴', 'plainpaste' => '粘贴为无格式文本', '|2' => '分隔', 'selectall' => '全选', 'justifyleft' => '左对齐', 'justifycenter' => '居中', 'justifyright' => '右对齐', 'justifyfull' => '两端对齐', 'insertorderedlist' => '编号', 'insertunorderedlist' => '项目符号', 'indent' => '增加缩进', 'outdent' => '减少缩进', 'subscript' => '下标', 'superscript' => '上标', 'removeformat' => '删除格式', 'quickformat' => '一键排版', '|3' => '分隔', 'formatblock' => '段落', 'fontname' => '字体', 'fontsize' => '文字大小', '|3' => '分隔', 'forecolor' => '文字颜色', 'hilitecolor' => '文字背景', 'bold' => '粗体', 'italic' => '斜体', 'underline' => '下划线', 'strikethrough' => '删除线', '|5' => '分隔', 'image' => '图片', 'flash' => 'Flash', 'media' => '视音频', 'table' => '表格', 'hr' => '插入横线', 'emoticons' => '插入表情', 'link' => '超级链接', 'unlink' => '取消超级链接', 'fullscreen' => '全屏显示', 'map' => 'Google地图', 'baidumap' => '百度地图', 'lineheight' => '行距', 'clearhtml' => '清理HTML代码', 'pagebreak' => ' 插入分页符', 'anchor' => '插入锚点', 'insertfile' => '插入文件', '|6' => '分隔', 'about' => '关于'); $editorToolsDescription = _t('仅在默认风格有效!'); $editorTools = new Typecho_Widget_Helper_Form_Element_Checkbox('editorTools', $editorToolsOptions, array('fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'emoticons', 'image', 'link'), _t('工具栏'), $editorToolsDescription); $form->addInput($editorTheme); $form->addInput($editorLang); $form->addItem($line); $form->addInput($editorNewlineTag); $form->addInput($editorPasteType); $form->addItem($line); $form->addInput($editorTools); $form->addItem($line); echo <<<EOF <style> #typecho-option-item-editorTools-4 span{width:24%;display:inline-block;margin-right:0;} </style> EOF; }
/** * 获取插件配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ public static function config(Typecho_Widget_Helper_Form $form) { if (isset($_GET['action']) && $_GET['action'] == 'deletefile') { self::deletefile(); } $listexpire = new Typecho_Widget_Helper_Form_Element_Text('listexpire', null, '43200', _t('歌单更新周期'), _t('设置歌单的缓存时间(单位:秒),超过设定时间后歌单将自动更新')); $form->addInput($listexpire); $maintheme = new Typecho_Widget_Helper_Form_Element_Text('maintheme', null, '#e6d0b2', _t('默认主题颜色'), _t('播放器默认的主题颜色,如 #372e21、#75c、red、blue,该设定会被[player]标签中的theme属性覆盖,默认为 #e6d0b2')); $form->addInput($maintheme); $nolyric = new Typecho_Widget_Helper_Form_Element_Text('nolyric', null, '找不到歌词', _t('找不到歌词时显示的文字'), _t('找不到歌词时显示的文字')); $form->addInput($nolyric); $mutex = new Typecho_Widget_Helper_Form_Element_Radio('mutex', array('false' => _t('是'), 'true' => _t('否')), 'true', _t('是否允许在一个页面中多个播放器同时播放'), _t('若选择否,当页面中存在多个播放器时,点击其中一个播放器的播放按钮,其它播放器将自动暂停')); $form->addInput($mutex); $preload = new Typecho_Widget_Helper_Form_Element_Radio('preload', array('false' => _t('自动'), 'none' => _t('none'), 'metadata' => _t('metadata'), 'auto' => _t('auto')), 'false', _t('音频预加载(preload)属性'), '自动:移动端为none,桌面端为metadata; none:页面加载后不预加载音频; metadata:当页面加载后仅加载音频的元数据; auto:一旦页面加载,则开始加载音频。'); $form->addInput($preload); $cache = new Typecho_Widget_Helper_Form_Element_Radio('cache', array('false' => _t('否')), 'false', _t('清空缓存'), _t('清空插件生成的缓存文件,必要时可以使用')); $form->addInput($cache); $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->value(_t('清空歌词,专辑图片链接,在线歌曲缓存')); $submit->setAttribute('style', 'position:relative;'); $submit->input->setAttribute('style', 'position:absolute;bottom:37px;'); $submit->input->setAttribute('class', 'btn btn-s btn-warn btn-operate'); $submit->input->setAttribute('formaction', Typecho_Common::url('/options-plugin.php?config=APlayer&action=deletefile', Helper::options()->adminUrl)); $form->addItem($submit); }
/** * 获取插件配置面板 * * @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); }
public function form() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/options-forum'), Typecho_Widget_Helper_Form::POST_METHOD); $siteIcp = new Typecho_Widget_Helper_Form_Element_Text('siteIcp', NULL, $this->options->siteIcp, _t('网站备案号'), _t('在这里填入网站备案号')); $siteIcp->input->setAttribute('class', 'w-60'); $form->addInput($siteIcp); $siteStat = new Typecho_Widget_Helper_Form_Element_Textarea('siteStat', NULL, $this->options->siteStat, _t('统计代码'), _t('在这里填入网站统计代码')); $form->addInput($siteStat); $smtp_host = new Typecho_Widget_Helper_Form_Element_Text('smtpHost', NULL, $this->options->smtpHost, _t('SMTP地址'), _t('请填写 SMTP 服务器地址')); $smtp_host->input->setAttribute('class', 'w-60'); $form->addInput($smtp_host); $smtp_port = new Typecho_Widget_Helper_Form_Element_Text('smtpPort', NULL, $this->options->smtpPort, _t('SMTP端口'), _t('SMTP服务端口,一般为25。')); $smtp_port->input->setAttribute('class', 'w-60'); $form->addInput($smtp_port); $smtp_user = new Typecho_Widget_Helper_Form_Element_Text('smtpUser', NULL, $this->options->smtpUser, _t('SMTP用户'), _t('SMTP服务验证用户名,一般为邮箱名如:youname@domain.com')); $smtp_user->input->setAttribute('class', 'w-60'); $form->addInput($smtp_user); $smtp_pass = new Typecho_Widget_Helper_Form_Element_Password('smtpPass', NULL, $this->options->smtpPass, _t('SMTP密码')); $smtp_pass->input->setAttribute('class', 'w-60'); $form->addInput($smtp_pass); $from_mail = new Typecho_Widget_Helper_Form_Element_Text('smtpMail', NULL, $this->options->smtpMail, _t('发件人EMAIL')); $from_mail->input->setAttribute('class', 'w-60'); $form->addInput($from_mail->addRule('email', _t('电子邮箱格式错误'))); $from_name = new Typecho_Widget_Helper_Form_Element_Text('smtpName', NULL, $this->options->smtpName, _t('发件人名称')); $from_name->input->setAttribute('class', 'w-60'); $form->addInput($from_name); //用户积分 $credits_register = new Typecho_Widget_Helper_Form_Element_Text('creditsRegister', NULL, $this->options->creditsRegister, _t('注册积分'), _t('用户注册后默认的积分')); $credits_register->input->setAttribute('class', 'w-60'); $form->addInput($credits_register); $credits_login = new Typecho_Widget_Helper_Form_Element_Text('creditsLogin', NULL, $this->options->creditsLogin, _t('登录积分'), _t('每日登录获取的积分')); $credits_login->input->setAttribute('class', 'w-60'); $form->addInput($credits_login); $credits_publish = new Typecho_Widget_Helper_Form_Element_Text('creditsPublish', NULL, $this->options->creditsPublish, _t('发布主题'), _t('用户发布主题加上或减少的积分')); $credits_publish->input->setAttribute('class', 'w-60'); $form->addInput($credits_publish); $credits_reply = new Typecho_Widget_Helper_Form_Element_Text('creditsReply', NULL, $this->options->creditsReply, _t('发表回复'), _t('用户发表回复加上或减少的积分')); $credits_reply->input->setAttribute('class', 'w-60'); $form->addInput($credits_reply); $credits_invite = new Typecho_Widget_Helper_Form_Element_Text('creditsInvite', NULL, $this->options->creditsInvite, _t('邀请注册'), _t('邀请者和被邀请者所奖励的积分')); $credits_invite->input->setAttribute('class', 'w-60'); $form->addInput($credits_invite); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); return $form; }
/** * 获取插件配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ public static function config(Typecho_Widget_Helper_Form $form) { if (isset($_GET['action']) && $_GET['action'] == 'deletefile') { self::deletefile(); } $cache = new Typecho_Widget_Helper_Form_Element_Radio('cache', array('false' => _t('否')), 'false', _t('清空缓存'), _t('必要时可以使用')); $form->addInput($cache); $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->value(_t('清空歌词缓存')); $submit->setAttribute('style', 'position:relative;'); $submit->input->setAttribute('style', 'position:absolute;bottom:37px;'); $submit->input->setAttribute('class', 'btn btn-s btn-warn btn-operate'); $submit->input->setAttribute('formaction', Typecho_Common::url('/options-plugin.php?config=cPlayer&action=deletefile', Helper::options()->adminUrl)); $form->addItem($submit); }
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); }
/** * 输出表单结构 * * @access public * @return Typecho_Widget_Helper_Form */ public function form() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/options-general', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 站点名称 */ $title = new Typecho_Widget_Helper_Form_Element_Text('title', NULL, $this->options->title, _t('站点名称'), _t('站点的名称将显示在网页的标题处.')); $form->addInput($title); /** 站点描述 */ $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, $this->options->description, _t('站点描述'), _t('站点描述将显示在网页代码的头部.')); $form->addInput($description); /** 关键词 */ $keywords = new Typecho_Widget_Helper_Form_Element_Text('keywords', NULL, $this->options->keywords, _t('关键词'), _t('请以半角逗号 "," 分割多个关键字.')); $form->addInput($keywords); /** 注册 */ $allowRegister = new Typecho_Widget_Helper_Form_Element_Radio('allowRegister', array('0' => _t('不允许'), '1' => _t('允许')), $this->options->allowRegister, _t('是否允许注册'), _t('允许访问者注册到你的网站, 默认的注册用户不享有任何写入权限.')); $form->addInput($allowRegister); /** 时区 */ $timezoneList = array("0" => _t('格林威治(子午线)标准时间 (GMT)'), "3600" => _t('中欧标准时间 阿姆斯特丹,荷兰,法国 (GMT +1)'), "7200" => _t('东欧标准时间 布加勒斯特,塞浦路斯,希腊 (GMT +2)'), "10800" => _t('莫斯科时间 伊拉克,埃塞俄比亚,马达加斯加 (GMT +3)'), "14400" => _t('第比利斯时间 阿曼,毛里塔尼亚,留尼汪岛 (GMT +4)'), "18000" => _t('新德里时间 巴基斯坦,马尔代夫 (GMT +5)'), "21600" => _t('科伦坡时间 孟加拉 (GMT +6)'), "25200" => _t('曼谷雅加达 柬埔寨,苏门答腊,老挝 (GMT +7)'), "28800" => _t('北京时间 香港,新加坡,越南 (GMT +8)'), "32400" => _t('东京平壤时间 西伊里安,摩鹿加群岛 (GMT +9)'), "36000" => _t('悉尼关岛时间 塔斯马尼亚岛,新几内亚 (GMT +10)'), "39600" => _t('所罗门群岛 库页岛 (GMT +11)'), "43200" => _t('惠灵顿时间 新西兰,斐济群岛 (GMT +12)'), "-3600" => _t('佛德尔群岛 亚速尔群岛,葡属几内亚 (GMT -1)'), "-7200" => _t('大西洋中部时间 格陵兰 (GMT -2)'), "-10800" => _t('布宜诺斯艾利斯 乌拉圭,法属圭亚那 (GMT -3)'), "-14400" => _t('智利巴西 委内瑞拉,玻利维亚 (GMT -4)'), "-18000" => _t('纽约渥太华 古巴,哥伦比亚,牙买加 (GMT -5)'), "-21600" => _t('墨西哥城时间 洪都拉斯,危地马拉,哥斯达黎加 (GMT -6)'), "-25200" => _t('美国丹佛时间 (GMT -7)'), "-28800" => _t('美国旧金山时间 (GMT -8)'), "-32400" => _t('阿拉斯加时间 (GMT -9)'), "-36000" => _t('夏威夷群岛 (GMT -10)'), "-39600" => _t('东萨摩亚群岛 (GMT -11)'), "-43200" => _t('艾尼威托克岛 (GMT -12)')); $timezone = new Typecho_Widget_Helper_Form_Element_Select('timezone', $timezoneList, $this->options->timezone, _t('时区')); $form->addInput($timezone); /** 扩展名 */ $attachmentTypesOptionsResult = NULL != trim($this->options->attachmentTypes) ? array_map('trim', explode(',', $this->options->attachmentTypes)) : array(); $attachmentTypesOptionsValue = array(); if (in_array('@image@', $attachmentTypesOptionsResult)) { $attachmentTypesOptionsValue[] = '@image@'; } if (in_array('@media@', $attachmentTypesOptionsResult)) { $attachmentTypesOptionsValue[] = '@media@'; } if (in_array('@doc@', $attachmentTypesOptionsResult)) { $attachmentTypesOptionsValue[] = '@doc@'; } $attachmentTypesOther = array_diff($attachmentTypesOptionsResult, $attachmentTypesOptionsValue); $attachmentTypesOtherValue = ''; if (!empty($attachmentTypesOther)) { $attachmentTypesOptionsValue[] = '@other@'; $attachmentTypesOtherValue = implode(',', $attachmentTypesOther); } $attachmentTypesOptions = array('@image@' => _t('图片文件') . ' <code>(gif jpg png tiff bmp)</code>', '@media@' => _t('多媒体文件') . ' <code>(mp3 wmv wma rmvb rm avi flv)</code>', '@doc@' => _t('常用档案文件') . ' <code>(txt doc docx xls xlsx ppt pptx zip rar pdf)</code>', '@other@' => _t('其他格式 %s', ' <input type="text" class="w-50 text-s mono" name="attachmentTypesOther" value="' . htmlspecialchars($attachmentTypesOtherValue) . '" />')); $attachmentTypes = new Typecho_Widget_Helper_Form_Element_Checkbox('attachmentTypes', $attachmentTypesOptions, $attachmentTypesOptionsValue, _t('允许上传的文件类型'), _t('用逗号 "," 将后缀名隔开, 例如: <code>cpp, h, mak</code>')); $form->addInput($attachmentTypes->multiMode()); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置')); $submit->input->setAttribute('class', 'primary'); $form->addItem($submit); return $form; }
public static function form($action = NULL) { /** 构建表格 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/links-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 链接名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('链接名称*')); $form->addInput($name); /** 链接地址 */ $url = new Typecho_Widget_Helper_Form_Element_Text('url', NULL, "http://", _t('链接地址*')); $form->addInput($url); /** 链接分类 */ $sort = new Typecho_Widget_Helper_Form_Element_Text('sort', NULL, NULL, _t('链接分类'), _t('建议以英文字母开头,只包含字母与数字')); $form->addInput($sort); /** 链接图片 */ $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL, NULL, _t('链接图片'), _t('需要以http://开头,留空表示没有链接图片')); $form->addInput($image); /** 链接描述 */ $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('链接描述')); $form->addInput($description); /** 自定义数据 */ $user = new Typecho_Widget_Helper_Form_Element_Text('user', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展')); $form->addInput($user); /** 链接动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 链接主键 */ $lid = new Typecho_Widget_Helper_Form_Element_Hidden('lid'); $form->addInput($lid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $form->addItem($submit); $request = Typecho_Request::getInstance(); if (isset($request->lid) && 'insert' != $action) { /** 更新模式 */ $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $link = $db->fetchRow($db->select()->from($prefix . 'links')->where('lid = ?', $request->lid)); if (!$link) { throw new Typecho_Widget_Exception(_t('链接不存在'), 404); } $name->value($link['name']); $url->value($link['url']); $sort->value($link['sort']); $image->value($link['image']); $description->value($link['description']); $user->value($link['user']); $do->value('update'); $lid->value($link['lid']); $submit->value(_t('编辑链接')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加链接')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写链接名称')); $url->addRule('required', _t('必须填写链接地址')); $url->addRule('url', _t('不是一个合法的链接地址')); $image->addRule('url', _t('不是一个合法的图片地址')); } if ('update' == $action) { $lid->addRule('required', _t('链接主键不存在')); $lid->addRule(array(new Links_Plugin(), 'LinkExists'), _t('链接不存在')); } return $form; }
/** * 生成表单 * * @access public * @param string $action 表单动作 * @return Typecho_Widget_Helper_Form */ public function form($action = NULL) { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/metas-tag-edit'), Typecho_Widget_Helper_Form::POST_METHOD); /** 标签名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('标签名称 *'), _t('这是标签在站点中显示的名称.可以使用中文,如 "地球".')); $form->addInput($name); /** 标签缩略名 */ $slug = new Typecho_Widget_Helper_Form_Element_Text('slug', NULL, NULL, _t('标签缩略名'), _t('标签缩略名用于创建友好的链接形式, 如果留空则默认使用标签名称.')); $form->addInput($slug); // modified_by_jiangmuzi 2015.09.25 /** 父级分类 */ $options = array(0 => _t('不选择')); $parents = $this->widget('Widget_Metas_Category_List@options', isset($this->request->mid) ? 'ignore=' . $this->request->mid : ''); while ($parents->next()) { $options[$parents->mid] = str_repeat(' ', $parents->levels) . $parents->name; } $parent = new Typecho_Widget_Helper_Form_Element_Select('parent', $options, $this->request->parent, _t('父级分类'), _t('此标签将归档在您选择的父级分类下.')); $form->addInput($parent); /** 标签描述 */ $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('标签描述'), _t('此文字用于描述标签, 在有的主题中它会被显示.')); $form->addInput($description); // end modified /** 标签动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 标签主键 */ $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid'); $form->addInput($mid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); if (isset($this->request->mid) && 'insert' != $action) { /** 更新模式 */ $meta = $this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid)->where('type = ?', 'tag')->limit(1)); if (!$meta) { $this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl)); } $name->value($meta['name']); $slug->value($meta['slug']); $do->value('update'); $mid->value($meta['mid']); $submit->value(_t('编辑标签')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加标签')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写标签名称')); $name->addRule(array($this, 'nameExists'), _t('标签名称已经存在')); $name->addRule(array($this, 'nameToSlug'), _t('标签名称无法被转换为缩略名')); $name->addRule('xssCheck', _t('请不要标签名称中使用特殊字符')); $slug->addRule(array($this, 'slugExists'), _t('缩略名已经存在')); $slug->addRule('xssCheck', _t('请不要在缩略名中使用特殊字符')); } if ('update' == $action) { $mid->addRule('required', _t('标签主键不存在')); $mid->addRule(array($this, 'tagExists'), _t('标签不存在')); } return $form; }
/** * 生成表单 * * @access public * @return Typecho_Widget_Helper_Form */ public function passwordForm() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/users-profile', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 用户密码 */ $password = new Typecho_Widget_Helper_Form_Element_Password('password', NULL, NULL, _t('用户密码'), _t('为此用户分配一个密码.<br /> 建议使用特殊字符与字母的混编样式,以增加系统安全性.')); $form->addInput($password); /** 用户密码确认 */ $confirm = new Typecho_Widget_Helper_Form_Element_Password('confirm', NULL, NULL, _t('用户密码确认'), _t('请确认你的密码, 与上面输入的密码保持一致.')); $form->addInput($confirm); /** 用户动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'password'); $form->addInput($do); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('更新密码')); $form->addItem($submit); $password->addRule('required', _t('必须填写密码')); $password->addRule('minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $confirm->addRule('confirm', _t('两次输入的密码不一致'), 'password'); return $form; }
/** * 输出表单结构 * * @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; }
/** * 生成表单 * * @access public * @return Typecho_Widget_Helper_Form */ public function passwordForm() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/users-profile'), Typecho_Widget_Helper_Form::POST_METHOD); /** 用户密码 */ $password = new Typecho_Widget_Helper_Form_Element_Password('password', NULL, NULL, _t('用户密码'), _t('为此用户分配一个密码.') . '<br />' . _t('建议使用特殊字符与字母、数字的混编样式,以增加系统安全性.')); $password->input->setAttribute('class', 'w-60'); $form->addInput($password); /** 用户密码确认 */ $confirm = new Typecho_Widget_Helper_Form_Element_Password('confirm', NULL, NULL, _t('用户密码确认'), _t('请确认你的密码, 与上面输入的密码保持一致.')); $confirm->input->setAttribute('class', 'w-60'); $form->addInput($confirm); /** 用户动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'password'); $form->addInput($do); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('更新密码')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); $password->addRule('required', _t('必须填写密码')); $password->addRule('minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $confirm->addRule('confirm', _t('两次输入的密码不一致'), 'password'); return $form; }
/** * 生成重置密码表单 * * @access public * @return Typecho_Widget_Helper_Form */ public function resetForm() { $form = new Typecho_Widget_Helper_Form(NULL, Typecho_Widget_Helper_Form::POST_METHOD); /** 新密码 */ $password = new Typecho_Widget_Helper_Form_Element_Password('password', NULL, NULL, _t('新密码'), _t('建议使用特殊字符与字母、数字的混编样式,以增加系统安全性.')); $password->input->setAttribute('class', 'w-100'); $form->addInput($password); /** 新密码确认 */ $confirm = new Typecho_Widget_Helper_Form_Element_Password('confirm', NULL, NULL, _t('密码确认'), _t('请确认你的密码, 与上面输入的密码保持一致.')); $confirm->input->setAttribute('class', 'w-100'); $form->addInput($confirm); /** 用户动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'password'); $form->addInput($do); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('更新密码')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); $password->addRule('required', _t('必须填写密码')); $password->addRule('minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $confirm->addRule('confirm', _t('两次输入的密码不一致'), 'password'); return $form; }
} } $submit = new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('保存设置')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); $form->render(); } else { $form = new Typecho_Widget_Helper_Form(Helper::url('ThemeShow/config.php'), Typecho_Widget_Helper_Form::POST_METHOD); Typecho_Widget::widget('Widget_Themes_List')->to($themes); $availableThemes = array(); while ($themes->next()) { $availableThemes[$themes->name] = $themes->title; } $themeSel = new Typecho_Widget_Helper_Form_Element_Select('theme', $availableThemes, $options->theme, '主题名称'); $form->addInput($themeSel); $submit = new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('配置此主题')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); $form->render(); } ?> </div> </div> </div> </div> <?php include 'copyright.php'; include 'common-js.php'; include 'form-js.php'; include 'footer.php';
/** * 输出表单结构 * * @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; }
/** * 生成表单 * * @access public * @param string $action 表单动作 * @return Typecho_Widget_Helper_Form_Element */ public function form($action = NULL) { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/metas-category-edit'), Typecho_Widget_Helper_Form::POST_METHOD); /** 分类名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('分类名称 *')); $form->addInput($name); /** 分类缩略名 */ $slug = new Typecho_Widget_Helper_Form_Element_Text('slug', NULL, NULL, _t('分类缩略名'), _t('分类缩略名用于创建友好的链接形式, 建议使用字母, 数字, 下划线和横杠.')); $form->addInput($slug); /** 父级分类 */ $options = array(0 => _t('不选择')); $parents = $this->widget('Widget_Metas_Category_List@options', isset($this->request->mid) ? 'ignore=' . $this->request->mid : ''); while ($parents->next()) { $options[$parents->mid] = str_repeat(' ', $parents->levels) . $parents->name; } $parent = new Typecho_Widget_Helper_Form_Element_Select('parent', $options, $this->request->parent, _t('父级分类'), _t('此分类将归档在您选择的父级分类下.')); $form->addInput($parent); /** 分类模板 */ $options = $this->getTemplates(); array_unshift($options, _t('不选择')); $template = new Typecho_Widget_Helper_Form_Element_Select('template', $options, $this->request->template, _t('分类渲染模板'), _t('该分类的文章将按照高模板渲染.')); $form->addInput($template); /** 分类关键词 */ $keywords = new Typecho_Widget_Helper_Form_Element_Text('keywords', NULL, NULL, _t('关键词(SEO)')); $form->addInput($keywords); /** 分类描述 */ $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('分类描述'), _t('此文字用于描述分类, 在有的主题中它会被显示.')); $form->addInput($description); /** 分类动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 分类主键 */ $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid'); $form->addInput($mid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); if (isset($this->request->mid) && 'insert' != $action) { /** 更新模式 */ $meta = $this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid)->where('type = ?', 'category')->limit(1)); if (!$meta) { $this->response->redirect(Typecho_Common::url('manage-categories.php', $this->options->adminUrl)); } $name->value($meta['name']); $slug->value($meta['slug']); $parent->value($meta['parent']); $keywords->value($meta['keywords']); $template->value($meta['template']); $description->value($meta['description']); $do->value('update'); $mid->value($meta['mid']); $submit->value(_t('编辑分类')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加分类')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写分类名称')); $name->addRule(array($this, 'nameExists'), _t('分类名称已经存在')); $name->addRule(array($this, 'nameToSlug'), _t('分类名称无法被转换为缩略名')); $name->addRule('xssCheck', _t('请不要在分类名称中使用特殊字符')); $slug->addRule(array($this, 'slugExists'), _t('缩略名已经存在')); $slug->addRule('xssCheck', _t('请不要在缩略名中使用特殊字符')); } if ('update' == $action) { $mid->addRule('required', _t('分类主键不存在')); $mid->addRule(array($this, 'categoryExists'), _t('分类不存在')); } return $form; }
/** * 生成表单 * * @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; }
public static function form($action = NULL) { /** 构建表格 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/huifeng-members-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); $form->setAttribute('enctype', 'multipart/form-data'); // 表示可以上传数据 /* 添加隐藏域限制上传大小 */ $maxfilesize = new Typecho_Widget_Helper_Form_Element_Hidden('MAX_FILE_SIZE', NULL, '1000000', NULL, NULL); $form->addInput($maxfilesize); // 限制大小的隐藏域应在上传标签之前 /** 头像 */ $image_upload = new Typecho_Widget_Helper_Form_Element_Text('image_upload', NULL, NULL, _t('上传头像'), NULL); // 用于头像图片上传 $image_upload->input->setAttribute('type', 'file'); $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL, NULL, _t('头像'), NULL); // 获取数据库里的头像地址 $img_show = new Typecho_Widget_Helper_Layout('img', NULL); $img_src = '/usr/plugins/HuifengMembers/nopic.jpg'; if ($image->getAttribute('src' != '')) { $img_src = $image->getAttribute('src'); } $img_show->setAttribute('src', $img_src); $img_show->setAttribute('height', '180'); $img_show->setAttribute('style', 'margin-top: 4em;max-width: 180px;max-height: 180px;'); $form->addItem($img_show); $form->addInput($image_upload); $form->addInput($image); /** 会员名称 */ // Typecho_Widget_Helper_Form_Element_Text ($name=NULL, array $options=NULL, $value=NULL, $label=NULL, $categories=NULL) $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('会员名称*'), _t('请填写真实姓名')); $form->addInput($name); /** 所在部门 */ $position = new Typecho_Widget_Helper_Form_Element_Text('position', NULL, NULL, _t('所在部门*'), _t('请正确填写所在部门科室')); $form->addInput($position); /** 联系电话 */ $tel = new Typecho_Widget_Helper_Form_Element_Text('tel', NULL, NULL, _t('联系电话'), NULL); $form->addInput($tel); /** 分类 */ $categories = new Typecho_Widget_Helper_Form_Element_Text('categories', NULL, NULL, _t('分类')); $form->addInput($categories); /** 是否值班 */ $is_onduty = new Typecho_Widget_Helper_Form_Element_Radio('is_onduty', array('否' => _t('否'), '是' => _t('是')), '否', _t('是否值班')); $form->addInput($is_onduty); /** 自定义数据 */ $field = new Typecho_Widget_Helper_Form_Element_Text('field', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展')); $form->addInput($field); /** 会员动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 会员主键 */ $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid'); $form->addInput($mid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); $request = Typecho_Request::getInstance(); if (isset($request->mid) && 'insert' != $action) { /** 更新模式 */ $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $member = $db->fetchRow($db->select()->from($prefix . 'hf_members')->where('mid = ?', $request->mid)); if (!$member) { throw new Typecho_Widget_Exception(_t('会员不存在'), 404); } $name->value($member['name']); $position->value($member['position']); $tel->value($member['tel']); $image->value($member['image']); $categories->value($member['categories']); $is_onduty->value($member['is_onduty']); $field->value($member['field']); $do->value('update'); $mid->value($member['mid']); $submit->value(_t('编辑会员')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加会员')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写会员名称')); $name->addRule('xssCheck', _t('请勿在会员名称栏输入特殊字符')); $position->addRule('required', _t('必须填写所在部门')); $position->addRule('xssCheck', _t('请勿在所在部门栏输入特殊字符')); // $position->addRule('url', _t('不是一个合法的url')); // $image->addRule('image', _t('不是一个合法的图片地址')); $tel->addRule('required', _t('必须填写联系电话')); $tel->addRule('isInteger', _t('电话号码必须是无符号整数')); $tel->addRule('minLength', _t('电话号码不得小于6位'), 6); $tel->addRule('maxLength', _t('电话号码不得大于11位'), 12); // $image->addRule('required', _t('必须上传头像图片')); } if ('update' == $action) { $mid->addRule('required', _t('会员主键不存在')); $mid->addRule(array(new HuifengMembers_Plugin(), 'HuifengMembersExists'), _t('会员不存在')); } return $form; }
/** * 构建相册表单 * * @access public * @param string $action,$render * @return Typecho_Widget_Helper_Form */ public static function form($action = NULL, $render = '1') { $options = Helper::options(); $settings = $options->plugin('HighSlide'); //图片编辑表单 $form1 = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/gallery-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL, "http://", _t('原图地址*')); $form1->addInput($image); $thumb = new Typecho_Widget_Helper_Form_Element_Text('thumb', NULL, "http://", _t('缩略图地址*')); $form1->addInput($thumb); $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('图片名称')); $name->input->setAttribute('class', 'mini'); $form1->addInput($name); $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('图片描述'), _t('推荐填写, 用于展示相册中图片的文字说明效果')); $form1->addInput($description); $sort = new Typecho_Widget_Helper_Form_Element_Text('sort', NULL, "1", _t('相册组*'), _t('输入数字, 对应写入[GALLERY-数字]在页面调用')); $sort->input->setAttribute('class', 'w-10'); $form1->addInput($sort); $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form1->addInput($do); $gid = new Typecho_Widget_Helper_Form_Element_Hidden('gid'); $form1->addInput($gid); $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn'); $form1->addItem($submit); //相册设置表单 $form2 = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/gallery-edit?do=sync', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); $gallery = new Typecho_Widget_Helper_Form_Element_Select('gallery', array('gallery-horizontal-strip' => _t('连环画册'), 'gallery-thumbstrip-above' => _t('黑色影夹'), 'gallery-vertical-strip' => _t('时光胶带'), 'gallery-in-box' => _t('纯白记忆'), 'gallery-floating-thumbs' => _t('往事片段'), 'gallery-floating-caption' => _t('沉默注脚'), 'gallery-controls-in-heading' => _t('岁月名片'), 'gallery-in-page' => _t('幻影橱窗(单相册)')), $settings->gallery, _t('相册风格'), _t('套装效果, 不受插件通用设置影响')); $form2->addInput($gallery); $thumboptions = array('fixedwidth' => _t('固定宽度 %s', ' <input type="text" class="w-10 text-s mono" name="fixedwidth" value="' . $settings->fixedwidth . '" />'), 'fixedheight' => _t('固定高度 %s', ' <input type="text" class="w-10 text-s mono" name="fixedheight" value="' . $settings->fixedheight . '" />'), 'fixedratio' => _t('固定比例 %s', ' <input type="text" class="w-10 text-s mono" name="fixedratio" value="' . $settings->fixedratio . '" />')); $thumbfix = new Typecho_Widget_Helper_Form_Element_Radio('thumbfix', $thumboptions, $settings->thumbfix, _t('缩略图规格'), _t('宽高单位px(无需填写), 比例注意使用半角冒号')); $form2->addInput($thumbfix->multiMode()); $storage = new Typecho_Widget_Helper_Form_Element_Radio('storage', array('local' => _t('本地'), 'qiniu' => _t('七牛'), 'upyun' => _t('又拍云'), 'bcs' => _t('百度BCS')), $settings->storage, _t('储存位置')); $form2->addInput($storage); $local = new Typecho_Widget_Helper_Form_Element_Text('local', NULL, $settings->local, _t('本地路径'), _t('确保首层目录可写, 结尾带/号')); $form2->addInput($local); $qiniubucket = new Typecho_Widget_Helper_Form_Element_Text('qiniubucket', NULL, $settings->qiniubucket, _t('空间名称')); $form2->addInput($qiniubucket); $qiniudomain = new Typecho_Widget_Helper_Form_Element_Text('qiniudomain', NULL, $settings->qiniudomain, _t('空间域名')); $form2->addInput($qiniudomain); $qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Text('qiniuaccesskey', NULL, $settings->qiniuaccesskey, _t('AccessKey')); $form2->addInput($qiniuaccesskey); $qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Text('qiniusecretkey', NULL, $settings->qiniusecretkey, _t('SecretKey')); $form2->addInput($qiniusecretkey); $qiniuprefix = new Typecho_Widget_Helper_Form_Element_Text('qiniuprefix', NULL, $settings->qiniuprefix, _t('路径前缀'), _t('注意开头不要加/号')); $form2->addInput($qiniuprefix); $upyunbucket = new Typecho_Widget_Helper_Form_Element_Text('upyunbucket', NULL, $settings->upyunbucket, _t('空间名称')); $form2->addInput($upyunbucket); $upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', NULL, $settings->upyundomain, _t('绑定域名')); $form2->addInput($upyundomain); $upyunuser = new Typecho_Widget_Helper_Form_Element_Text('upyunuser', NULL, $settings->upyunuser, _t('操作员')); $form2->addInput($upyunuser); $upyunpwd = new Typecho_Widget_Helper_Form_Element_Text('upyunpwd', NULL, $settings->upyunpwd, _t('密码')); $form2->addInput($upyunpwd); $upyunkey = new Typecho_Widget_Helper_Form_Element_Text('upyunkey', NULL, $settings->upyunkey, _t('密匙')); $form2->addInput($upyunkey); $upyunprefix = new Typecho_Widget_Helper_Form_Element_Text('upyunprefix', NULL, $settings->upyunprefix, _t('路径前缀')); $form2->addInput($upyunprefix); $bcsbucket = new Typecho_Widget_Helper_Form_Element_Text('bcsbucket', NULL, $settings->bcsbucket, _t('空间名称')); $form2->addInput($bcsbucket); $bcsapikey = new Typecho_Widget_Helper_Form_Element_Text('bcsapikey', NULL, $settings->bcsapikey, _t('APIKey')); $form2->addInput($bcsapikey); $bcssecretkey = new Typecho_Widget_Helper_Form_Element_Text('bcssecretkey', NULL, $settings->bcssecretkey, _t('SecretKey')); $form2->addInput($bcssecretkey); $bcsprefix = new Typecho_Widget_Helper_Form_Element_Text('bcsprefix', NULL, $settings->bcsprefix, _t('路径前缀')); $form2->addInput($bcsprefix); $form2->addItem($submit); //隐藏模式 switch ($settings->storage) { case 'local': $qiniubucket->setAttribute('style', 'display:none;'); $qiniudomain->setAttribute('style', 'display:none;'); $qiniuaccesskey->setAttribute('style', 'display:none;'); $qiniusecretkey->setAttribute('style', 'display:none;'); $qiniuprefix->setAttribute('style', 'display:none;'); $upyunbucket->setAttribute('style', 'display:none;'); $upyundomain->setAttribute('style', 'display:none;'); $upyunuser->setAttribute('style', 'display:none;'); $upyunpwd->setAttribute('style', 'display:none;'); $upyunkey->setAttribute('style', 'display:none;'); $upyunprefix->setAttribute('style', 'display:none;'); $bcsbucket->setAttribute('style', 'display:none;'); $bcsapikey->setAttribute('style', 'display:none;'); $bcssecretkey->setAttribute('style', 'display:none;'); $bcsprefix->setAttribute('style', 'display:none;'); break; case 'qiniu': $local->setAttribute('style', 'display:none;'); $upyunbucket->setAttribute('style', 'display:none;'); $upyundomain->setAttribute('style', 'display:none;'); $upyunuser->setAttribute('style', 'display:none;'); $upyunpwd->setAttribute('style', 'display:none;'); $upyunkey->setAttribute('style', 'display:none;'); $upyunprefix->setAttribute('style', 'display:none;'); $bcsbucket->setAttribute('style', 'display:none;'); $bcsapikey->setAttribute('style', 'display:none;'); $bcssecretkey->setAttribute('style', 'display:none;'); $bcsprefix->setAttribute('style', 'display:none;'); break; case 'upyun': $local->setAttribute('style', 'display:none;'); $qiniubucket->setAttribute('style', 'display:none;'); $qiniudomain->setAttribute('style', 'display:none;'); $qiniuaccesskey->setAttribute('style', 'display:none;'); $qiniusecretkey->setAttribute('style', 'display:none;'); $qiniuprefix->setAttribute('style', 'display:none;'); $bcsbucket->setAttribute('style', 'display:none;'); $bcsapikey->setAttribute('style', 'display:none;'); $bcssecretkey->setAttribute('style', 'display:none;'); $bcsprefix->setAttribute('style', 'display:none;'); break; case 'bcs': $local->setAttribute('style', 'display:none;'); $qiniubucket->setAttribute('style', 'display:none;'); $qiniudomain->setAttribute('style', 'display:none;'); $qiniuaccesskey->setAttribute('style', 'display:none;'); $qiniusecretkey->setAttribute('style', 'display:none;'); $qiniuprefix->setAttribute('style', 'display:none;'); $upyunbucket->setAttribute('style', 'display:none;'); $upyundomain->setAttribute('style', 'display:none;'); $upyunuser->setAttribute('style', 'display:none;'); $upyunpwd->setAttribute('style', 'display:none;'); $upyunkey->setAttribute('style', 'display:none;'); $upyunprefix->setAttribute('style', 'display:none;'); break; } //更新模式 $request = Typecho_Request::getInstance(); if (isset($request->gid) && $action !== 'insert') { $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $gallery = $db->fetchRow($db->select()->from($prefix . 'gallery')->where('gid=?', $request->gid)); if (!$gallery) { throw new Typecho_Widget_Exception(_t('图片不存在'), 404); } $thumb->value($gallery['thumb']); $image->value($gallery['image']); $sort->value($gallery['sort']); $name->value($gallery['name']); $description->value($gallery['description']); $do->value('update'); $gid->value($gallery['gid']); $submit->value(_t('修改图片')); $_action = 'update'; } elseif ($action == 'sync' && $render == '2') { $submit->value(_t('保存设置')); $_action = 'sync'; } else { $do->value('insert'); $submit->value(_t('添加图片')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } //验证规则 if ($action == 'insert' || $action == 'update') { $thumb->addRule('required', _t('缩略图地址不能为空')); $image->addRule('required', _t('原图地址不能为空')); $sort->addRule('required', _t('相册组不能为空')); $thumb->addRule('url', _t('请输入合法的图片地址')); $image->addRule('url', _t('请输入合法的图片地址')); $sort->addRule('isInteger', _t('请输入一个整数数字')); } if ($action == 'update') { $gid->addRule('required', _t('图片主键不存在')); $gid->addRule(array(new HighSlide_Plugin(), 'galleryexists'), _t('图片不存在')); } $form = $render == '1' ? $form1 : $form2; return $form; }
/** * 生成表单 * * @access public * @param string $action 表单动作 * @return Typecho_Widget_Helper_Form */ public function form($action = NULL) { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/metas-tag-edit'), Typecho_Widget_Helper_Form::POST_METHOD); /** 标签名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('标签名称 *'), _t('这是标签在站点中显示的名称.可以使用中文,如 "地球".')); $form->addInput($name); /** 标签缩略名 */ $slug = new Typecho_Widget_Helper_Form_Element_Text('slug', NULL, NULL, _t('标签缩略名'), _t('标签缩略名用于创建友好的链接形式, 如果留空则默认使用标签名称.')); $form->addInput($slug); /** 标签动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 标签主键 */ $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid'); $form->addInput($mid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); if (isset($this->request->mid) && 'insert' != $action) { /** 更新模式 */ $meta = $this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid)->where('type = ?', 'tag')->limit(1)); if (!$meta) { $this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl)); } $name->value($meta['name']); $slug->value($meta['slug']); $do->value('update'); $mid->value($meta['mid']); $submit->value(_t('编辑标签')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加标签')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写标签名称')); $name->addRule(array($this, 'nameExists'), _t('标签名称已经存在')); $name->addRule(array($this, 'nameToSlug'), _t('标签名称无法被转换为缩略名')); $name->addRule('xssCheck', _t('请不要标签名称中使用特殊字符')); $slug->addRule(array($this, 'slugExists'), _t('缩略名已经存在')); $slug->addRule('xssCheck', _t('请不要在缩略名中使用特殊字符')); } if ('update' == $action) { $mid->addRule('required', _t('标签主键不存在')); $mid->addRule(array($this, 'tagExists'), _t('标签不存在')); } return $form; }
/** * 清空缓存功能表单 * * @access public * @return Typecho_Widget_Helper_Form */ public static function form($action = NULL) { $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/avatars-delete', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn btn-s btn-warn btn-operate'); $form->addItem($submit); $do->value('delete'); $submit->value('清空缓存'); $_action = 'delete'; if (empty($action)) { $action = $_action; } return $form; }
/** * 邮件测试表单 * @return Typecho_Widget_Helper_Form */ public function testMailForm() { /** 构建表单 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/' . CommentToMail_Plugin::$action, $options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 收件人名称 */ $toName = new Typecho_Widget_Helper_Form_Element_Text('toName', NULL, NULL, _t('收件人名称'), _t('为空则使用博主昵称')); $form->addInput($toName); /** 收件人邮箱 */ $to = new Typecho_Widget_Helper_Form_Element_Text('to', NULL, NULL, _t('收件人邮箱'), _t('为空则使用博主邮箱')); $form->addInput($to); /** 邮件标题 */ $title = new Typecho_Widget_Helper_Form_Element_Text('title', NULL, NULL, _t('邮件标题 *')); $form->addInput($title); /** 邮件内容 */ $content = new Typecho_Widget_Helper_Form_Element_Textarea('content', NULL, NULL, _t('邮件内容 *')); $content->input->setAttribute('class', 'w-100 mono'); $form->addInput($content); /** 动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); /** 设置值 */ $do->value('testMail'); $submit->value('发送邮件'); /** 添加规则 */ $to->addRule('email', _t('邮箱地址不正确')); $title->addRule('required', _t('必须填写邮件标题')); $content->addRule('required', _t('必须填写邮件内容')); return $form; }
/** * 输出表单结构 * * @access public * @return Typecho_Widget_Helper_Form */ public function form() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/options-discussion'), Typecho_Widget_Helper_Form::POST_METHOD); /** 评论日期格式 */ $commentDateFormat = new Typecho_Widget_Helper_Form_Element_Text('commentDateFormat', NULL, $this->options->commentDateFormat, _t('评论日期格式'), _t('这是一个默认的格式,当你在模板中调用显示评论日期方法时, 如果没有指定日期格式, 将按照此格式输出.') . '<br />' . _t('具体写法请参考 <a href="http://www.php.net/manual/zh/function.date.php">PHP 日期格式写法</a>.')); $commentDateFormat->input->setAttribute('class', 'w-40 mono'); $form->addInput($commentDateFormat); /** 评论列表数目 */ $commentsListSize = new Typecho_Widget_Helper_Form_Element_Text('commentsListSize', NULL, $this->options->commentsListSize, _t('评论列表数目'), _t('此数目用于指定显示在侧边栏中的评论列表数目.')); $commentsListSize->input->setAttribute('class', 'w-20'); $form->addInput($commentsListSize->addRule('isInteger', _t('请填入一个数字'))); $commentsShowOptions = array('commentsShowCommentOnly' => _t('仅显示评论, 不显示 Pingback 和 Trackback'), 'commentsMarkdown' => _t('在评论中使用Markdown语法'), 'commentsShowUrl' => _t('评论者名称显示时自动加上其个人主页链接'), 'commentsUrlNofollow' => _t('对评论者个人主页链接使用 <a href="http://en.wikipedia.org/wiki/Nofollow">nofollow 属性</a>'), 'commentsAvatar' => _t('启用 <a href="http://gravatar.com">Gravatar</a> 头像服务, 最高显示评级为 %s 的头像', '</label><select id="commentsShow-commentsAvatarRating" name="commentsAvatarRating"> <option value="G"' . ('G' == $this->options->commentsAvatarRating ? ' selected="true"' : '') . '>G - 普通</option> <option value="PG"' . ('PG' == $this->options->commentsAvatarRating ? ' selected="true"' : '') . '>PG - 13岁以上</option> <option value="R"' . ('R' == $this->options->commentsAvatarRating ? ' selected="true"' : '') . '>R - 17岁以上成人</option> <option value="X"' . ('X' == $this->options->commentsAvatarRating ? ' selected="true"' : '') . '>X - 限制级</option></select> <label for="commentsShow-commentsAvatarRating">'), 'commentsPageBreak' => _t('启用分页, 并且每页显示 %s 篇评论, 在列出时将 %s 作为默认显示', '</label><input type="text" value="' . $this->options->commentsPageSize . '" class="text num text-s" id="commentsShow-commentsPageSize" name="commentsPageSize" /><label for="commentsShow-commentsPageSize">', '</label><select id="commentsShow-commentsPageDisplay" name="commentsPageDisplay"> <option value="first"' . ('first' == $this->options->commentsPageDisplay ? ' selected="true"' : '') . '>' . _t('第一页') . '</option> <option value="last"' . ('last' == $this->options->commentsPageDisplay ? ' selected="true"' : '') . '>' . _t('最后一页') . '</option></select>' . '<label for="commentsShow-commentsPageDisplay">'), 'commentsThreaded' => _t('启用评论回复, 以 %s 层作为每个评论最多的回复层数', '</label><input name="commentsMaxNestingLevels" type="text" class="text num text-s" value="' . $this->options->commentsMaxNestingLevels . '" id="commentsShow-commentsMaxNestingLevels" /> <label for="commentsShow-commentsMaxNestingLevels">') . '</label></span><span class="multiline">' . _t('将 %s 的评论显示在前面', '<select id="commentsShow-commentsOrder" name="commentsOrder"> <option value="DESC"' . ('DESC' == $this->options->commentsOrder ? ' selected="true"' : '') . '>' . _t('较新的') . '</option> <option value="ASC"' . ('ASC' == $this->options->commentsOrder ? ' selected="true"' : '') . '>' . _t('较旧的') . '</option></select><label for="commentsShow-commentsOrder">')); $commentsShowOptionsValue = array(); if ($this->options->commentsShowCommentOnly) { $commentsShowOptionsValue[] = 'commentsShowCommentOnly'; } if ($this->options->commentsMarkdown) { $commentsShowOptionsValue[] = 'commentsMarkdown'; } if ($this->options->commentsShowUrl) { $commentsShowOptionsValue[] = 'commentsShowUrl'; } if ($this->options->commentsUrlNofollow) { $commentsShowOptionsValue[] = 'commentsUrlNofollow'; } if ($this->options->commentsAvatar) { $commentsShowOptionsValue[] = 'commentsAvatar'; } if ($this->options->commentsPageBreak) { $commentsShowOptionsValue[] = 'commentsPageBreak'; } if ($this->options->commentsThreaded) { $commentsShowOptionsValue[] = 'commentsThreaded'; } $commentsShow = new Typecho_Widget_Helper_Form_Element_Checkbox('commentsShow', $commentsShowOptions, $commentsShowOptionsValue, _t('评论显示')); $form->addInput($commentsShow->multiMode()); /** 评论提交 */ $commentsPostOptions = array('commentsRequireModeration' => _t('所有评论必须经过审核'), 'commentsWhitelist' => _t('评论者之前须有评论通过了审核'), 'commentsRequireMail' => _t('必须填写邮箱'), 'commentsRequireURL' => _t('必须填写网址'), 'commentsCheckReferer' => _t('检查评论来源页 URL 是否与文章链接一致'), 'commentsAntiSpam' => _t('开启反垃圾保护'), 'commentsAutoClose' => _t('在文章发布 %s 天以后自动关闭评论', '</label><input name="commentsPostTimeout" type="text" class="text num text-s" value="' . intval($this->options->commentsPostTimeout / (24 * 3600)) . '" id="commentsPost-commentsPostTimeout" /> <label for="commentsPost-commentsPostTimeout">'), 'commentsPostIntervalEnable' => _t('同一 IP 发布评论的时间间隔限制为 %s 分钟', '</label><input name="commentsPostInterval" type="text" class="text num text-s" value="' . round($this->options->commentsPostInterval / 60, 1) . '" id="commentsPost-commentsPostInterval" /> <label for="commentsPost-commentsPostInterval">')); $commentsPostOptionsValue = array(); if ($this->options->commentsRequireModeration) { $commentsPostOptionsValue[] = 'commentsRequireModeration'; } if ($this->options->commentsWhitelist) { $commentsPostOptionsValue[] = 'commentsWhitelist'; } if ($this->options->commentsRequireMail) { $commentsPostOptionsValue[] = 'commentsRequireMail'; } if ($this->options->commentsRequireURL) { $commentsPostOptionsValue[] = 'commentsRequireURL'; } if ($this->options->commentsCheckReferer) { $commentsPostOptionsValue[] = 'commentsCheckReferer'; } if ($this->options->commentsAntiSpam) { $commentsPostOptionsValue[] = 'commentsAntiSpam'; } if ($this->options->commentsAutoClose) { $commentsPostOptionsValue[] = 'commentsAutoClose'; } if ($this->options->commentsPostIntervalEnable) { $commentsPostOptionsValue[] = 'commentsPostIntervalEnable'; } $commentsPost = new Typecho_Widget_Helper_Form_Element_Checkbox('commentsPost', $commentsPostOptions, $commentsPostOptionsValue, _t('评论提交')); $form->addInput($commentsPost->multiMode()); /** 允许使用的HTML标签和属性 */ $commentsHTMLTagAllowed = new Typecho_Widget_Helper_Form_Element_Textarea('commentsHTMLTagAllowed', NULL, $this->options->commentsHTMLTagAllowed, _t('允许使用的HTML标签和属性'), _t('默认的用户评论不允许填写任何的HTML标签, 你可以在这里填写允许使用的HTML标签.') . '<br />' . _t('比如: %s', ': <code><a href=""> <img src=""> <blockquote></code>')); $commentsHTMLTagAllowed->input->setAttribute('class', 'mono'); $form->addInput($commentsHTMLTagAllowed); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); return $form; }
/** * 输出表单结构 * * @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; }
/** * 生成表单 * * @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/metas-category-edit', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 分类名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('分类名称 *')); $form->addInput($name); /** 分类缩略名 */ $slug = new Typecho_Widget_Helper_Form_Element_Text('slug', NULL, NULL, _t('分类缩略名'), _t('分类缩略名用于创建友好的链接形式,建议使用字母,数字,下划线和横杠.')); $form->addInput($slug); /** 分类描述 */ $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('分类描述'), _t('此文字用于描述分类,在有的主题中它会被显示.')); $form->addInput($description); /** 分类动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 分类主键 */ $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid'); $form->addInput($mid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'primary'); $form->addItem($submit); if (isset($this->request->mid) && 'insert' != $action) { /** 更新模式 */ $meta = $this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid)->where('type = ?', 'category')->limit(1)); if (!$meta) { $this->response->redirect(Typecho_Common::url('manage-metas.php', $this->options->adminUrl)); } $name->value($meta['name']); $slug->value($meta['slug']); $description->value($meta['description']); $do->value('update'); $mid->value($meta['mid']); $submit->value(_t('编辑分类')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加分类')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写分类名称')); $name->addRule(array($this, 'nameExists'), _t('分类名称已经存在')); $name->addRule(array($this, 'nameToSlug'), _t('分类名称无法被转换为缩略名')); $slug->addRule(array($this, 'slugExists'), _t('缩略名已经存在')); } if ('update' == $action) { $mid->addRule('required', _t('分类主键不存在')); $mid->addRule(array($this, 'categoryExists'), _t('分类不存在')); } return $form; }
/** * 输出表单结构 * * @access public * @return Typecho_Widget_Helper_Form */ public function form() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/options-discussion'), Typecho_Widget_Helper_Form::POST_METHOD); /** 评论日期格式 */ $commentDateFormat = new Typecho_Widget_Helper_Form_Element_Text('commentDateFormat', NULL, $this->options->commentDateFormat, _t('回复日期格式'), _t('这是一个默认的格式,当你在模板中调用显示回复日期方法时, 如果没有指定日期格式, 将按照此格式输出.') . '<br />' . _t('具体写法请参考 <a href="http://www.php.net/manual/zh/function.date.php">PHP 日期格式写法</a>.')); $commentDateFormat->input->setAttribute('class', 'w-40 mono'); $form->addInput($commentDateFormat); /** 评论列表数目 */ $commentsListSize = new Typecho_Widget_Helper_Form_Element_Text('commentsListSize', NULL, $this->options->commentsListSize, _t('回复列表数目'), _t('此数目用于指定显示在侧边栏中的评论列表数目.')); $commentsListSize->input->setAttribute('class', 'w-20'); $form->addInput($commentsListSize->addRule('isInteger', _t('请填入一个数字'))); $commentsShowOptions = array('commentsMarkdown' => _t('在评论中使用 Markdown 语法'), 'commentsAvatar' => _t('评论列表显示头像'), 'commentsPageBreak' => _t('启用分页, 并且每页显示 %s 篇评论 %s 作为默认显示', '</label><input type="text" value="' . $this->options->commentsPageSize . '" class="text num text-s" id="commentsShow-commentsPageSize" name="commentsPageSize" /><label for="commentsShow-commentsPageSize">', '</label><select id="commentsShow-commentsOrder" name="commentsOrder"> <option value="DESC"' . ('DESC' == $this->options->commentsOrder ? ' selected="true"' : '') . '>' . _t('较新的') . '</option> <option value="ASC"' . ('ASC' == $this->options->commentsOrder ? ' selected="true"' : '') . '>' . _t('较旧的') . '</option></select><label for="commentsShow-commentsOrder">')); $commentsShowOptionsValue = array(); if ($this->options->commentsMarkdown) { $commentsShowOptionsValue[] = 'commentsMarkdown'; } if ($this->options->commentsAvatar) { $commentsShowOptionsValue[] = 'commentsAvatar'; } if ($this->options->commentsPageBreak) { $commentsShowOptionsValue[] = 'commentsPageBreak'; } if ($this->options->commentsThreaded) { $commentsShowOptionsValue[] = 'commentsThreaded'; } $commentsShow = new Typecho_Widget_Helper_Form_Element_Checkbox('commentsShow', $commentsShowOptions, $commentsShowOptionsValue, _t('评论显示')); $form->addInput($commentsShow->multiMode()); /** 评论提交 */ $commentsPostOptions = array('commentsRequireModeration' => _t('所有评论必须经过审核'), 'commentsWhitelist' => _t('评论者之前须有评论通过了审核'), 'commentsCheckReferer' => _t('检查评论来源页 URL 是否与文章链接一致'), 'commentsAntiSpam' => _t('开启反垃圾保护'), 'commentsAutoClose' => _t('在主题发布 %s 天以后自动关闭评论', '</label><input name="commentsPostTimeout" type="text" class="text num text-s" value="' . intval($this->options->commentsPostTimeout / (24 * 3600)) . '" id="commentsPost-commentsPostTimeout" /> <label for="commentsPost-commentsPostTimeout">'), 'commentsPostIntervalEnable' => _t('同一 IP 发布评论的时间间隔限制为 %s 分钟', '</label><input name="commentsPostInterval" type="text" class="text num text-s" value="' . round($this->options->commentsPostInterval / 60, 1) . '" id="commentsPost-commentsPostInterval" /> <label for="commentsPost-commentsPostInterval">')); $commentsPostOptionsValue = array(); if ($this->options->commentsRequireModeration) { $commentsPostOptionsValue[] = 'commentsRequireModeration'; } if ($this->options->commentsWhitelist) { $commentsPostOptionsValue[] = 'commentsWhitelist'; } if ($this->options->commentsCheckReferer) { $commentsPostOptionsValue[] = 'commentsCheckReferer'; } if ($this->options->commentsAntiSpam) { $commentsPostOptionsValue[] = 'commentsAntiSpam'; } if ($this->options->commentsAutoClose) { $commentsPostOptionsValue[] = 'commentsAutoClose'; } if ($this->options->commentsPostIntervalEnable) { $commentsPostOptionsValue[] = 'commentsPostIntervalEnable'; } $commentsPost = new Typecho_Widget_Helper_Form_Element_Checkbox('commentsPost', $commentsPostOptions, $commentsPostOptionsValue, _t('评论提交')); $form->addInput($commentsPost->multiMode()); /** 允许使用的HTML标签和属性 */ $commentsHTMLTagAllowed = new Typecho_Widget_Helper_Form_Element_Textarea('commentsHTMLTagAllowed', NULL, $this->options->commentsHTMLTagAllowed, _t('允许使用的HTML标签和属性'), _t('默认的用户评论不允许填写任何的HTML标签, 你可以在这里填写允许使用的HTML标签.') . '<br />' . _t('比如: %s', ': <code><a href=""> <img src=""> <blockquote></code>')); $commentsHTMLTagAllowed->input->setAttribute('class', 'mono'); $form->addInput($commentsHTMLTagAllowed); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); return $form; }
/** * 生成表单 * * @access public * @param string $action 表单动作 * @return Typecho_Widget_Helper_Form */ public function form($action = NULL) { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/users-edit'), Typecho_Widget_Helper_Form::POST_METHOD); /** 用户名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('用户名 *'), _t('此用户名将作为用户登录时所用的名称.') . '<br />' . _t('请不要与系统中现有的用户名重复.')); $form->addInput($name); /** 电子邮箱地址 */ $mail = new Typecho_Widget_Helper_Form_Element_Text('mail', NULL, NULL, _t('电子邮箱地址 *'), _t('电子邮箱地址将作为此用户的主要联系方式.') . '<br />' . _t('请不要与系统中现有的电子邮箱地址重复.')); $form->addInput($mail); /** 用户昵称 */ $screenName = new Typecho_Widget_Helper_Form_Element_Text('screenName', NULL, NULL, _t('用户昵称'), _t('用户昵称可以与用户名不同, 用于前台显示.') . '<br />' . _t('如果你将此项留空, 将默认使用用户名.')); $form->addInput($screenName); /** 用户密码 */ $password = new Typecho_Widget_Helper_Form_Element_Password('password', NULL, NULL, _t('用户密码'), _t('为此用户分配一个密码.') . '<br />' . _t('建议使用特殊字符与字母、数字的混编样式,以增加系统安全性.')); $password->input->setAttribute('class', 'w-60'); $form->addInput($password); /** 用户密码确认 */ $confirm = new Typecho_Widget_Helper_Form_Element_Password('confirm', NULL, NULL, _t('用户密码确认'), _t('请确认你的密码, 与上面输入的密码保持一致.')); $confirm->input->setAttribute('class', 'w-60'); $form->addInput($confirm); /** 个人主页地址 */ $url = new Typecho_Widget_Helper_Form_Element_Text('url', NULL, NULL, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>http://</code> 开头.')); $form->addInput($url); /** 用户组 */ $group = new Typecho_Widget_Helper_Form_Element_Select('group', array('subscriber' => _t('关注者'), 'contributor' => _t('贡献者'), 'editor' => _t('编辑'), 'administrator' => _t('管理员')), NULL, _t('用户组'), _t('不同的用户组拥有不同的权限.') . '<br />' . _t('具体的权限分配表请<a href="http://docs.typecho.org/develop/acl">参考这里</a>.')); $form->addInput($group); /** 用户动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 用户主键 */ $uid = new Typecho_Widget_Helper_Form_Element_Hidden('uid'); $form->addInput($uid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); if (NULL != $this->request->uid) { $submit->value(_t('编辑用户')); $name->value($this->name); $screenName->value($this->screenName); $url->value($this->url); $mail->value($this->mail); $group->value($this->group); $do->value('update'); $uid->value($this->uid); $_action = 'update'; } else { $submit->value(_t('增加用户')); $do->value('insert'); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $screenName->addRule(array($this, 'screenNameExists'), _t('昵称已经存在')); $screenName->addRule('xssCheck', _t('请不要在昵称中使用特殊字符')); $url->addRule('url', _t('个人主页地址格式错误')); $mail->addRule('required', _t('必须填写电子邮箱')); $mail->addRule(array($this, 'mailExists'), _t('电子邮箱地址已经存在')); $mail->addRule('email', _t('电子邮箱格式错误')); $password->addRule('minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $confirm->addRule('confirm', _t('两次输入的密码不一致'), 'password'); } if ('insert' == $action) { $name->addRule('required', _t('必须填写用户名称')); $name->addRule('xssCheck', _t('请不要在用户名中使用特殊字符')); $name->addRule(array($this, 'nameExists'), _t('用户名已经存在')); $password->label(_t('用户密码 *')); $confirm->label(_t('用户密码确认 *')); $password->addRule('required', _t('必须填写密码')); } if ('update' == $action) { $name->input->setAttribute('disabled', 'disabled'); $uid->addRule('required', _t('用户主键不存在')); $uid->addRule(array($this, 'userExists'), _t('用户不存在')); } return $form; }
/** * 输出表单结构 * * @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; }
/** * 输出表单结构 * * @access public * @return Typecho_Widget_Helper_Form */ public function form() { /** 构建表格 */ $form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/options-general'), Typecho_Widget_Helper_Form::POST_METHOD); /** 站点名称 */ $title = new Typecho_Widget_Helper_Form_Element_Text('title', NULL, $this->options->title, _t('站点名称'), _t('站点的名称将显示在网页的标题处.')); $title->input->setAttribute('class', 'w-100'); $form->addInput($title->addRule('required', _t('请填写站点名称'))->addRule('xssCheck', _t('请不要在站点名称中使用特殊字符'))); /** 站点地址 */ if (!defined('__TYPECHO_SITE_URL__')) { $siteUrl = new Typecho_Widget_Helper_Form_Element_Text('siteUrl', NULL, $this->options->originalSiteUrl, _t('站点地址'), _t('站点地址主要用于生成内容的永久链接.') . ($this->options->originalSiteUrl == $this->options->rootUrl ? '' : '</p><p class="message notice mono">' . _t('当前地址 <strong>%s</strong> 与上述设定值不一致', $this->options->rootUrl))); $siteUrl->input->setAttribute('class', 'w-100 mono'); $form->addInput($siteUrl->addRule('required', _t('请填写站点地址'))->addRule('url', _t('请填写一个合法的URL地址'))); } /** 站点描述 */ $description = new Typecho_Widget_Helper_Form_Element_Text('description', NULL, $this->options->description, _t('站点描述'), _t('站点描述将显示在网页代码的头部.')); $form->addInput($description->addRule('xssCheck', _t('请不要在站点描述中使用特殊字符'))); /** 关键词 */ $keywords = new Typecho_Widget_Helper_Form_Element_Text('keywords', NULL, $this->options->keywords, _t('关键词'), _t('请以半角逗号 "," 分割多个关键字.')); $form->addInput($keywords->addRule('xssCheck', _t('请不要在关键词中使用特殊字符'))); /** 注册 */ $allowRegister = new Typecho_Widget_Helper_Form_Element_Radio('allowRegister', array('0' => _t('不允许'), '1' => _t('允许')), $this->options->allowRegister, _t('是否允许注册'), _t('允许访问者注册到你的网站, 默认的注册用户不享有任何写入权限.')); $form->addInput($allowRegister); /** 语言项 */ // hack 语言扫描 _t('lang'); $langs = self::getLangs(); if (count($langs) > 1) { $lang = new Typecho_Widget_Helper_Form_Element_Select('lang', $langs, $this->options->lang, _t('语言')); $form->addInput($lang->addRule(array($this, 'checkLang'), _t('所选择的语言包不存在'))); } /** 时区 */ $timezoneList = array("0" => _t('格林威治(子午线)标准时间 (GMT)'), "3600" => _t('中欧标准时间 阿姆斯特丹,荷兰,法国 (GMT +1)'), "7200" => _t('东欧标准时间 布加勒斯特,塞浦路斯,希腊 (GMT +2)'), "10800" => _t('莫斯科时间 伊拉克,埃塞俄比亚,马达加斯加 (GMT +3)'), "14400" => _t('第比利斯时间 阿曼,毛里塔尼亚,留尼汪岛 (GMT +4)'), "18000" => _t('新德里时间 巴基斯坦,马尔代夫 (GMT +5)'), "21600" => _t('科伦坡时间 孟加拉 (GMT +6)'), "25200" => _t('曼谷雅加达 柬埔寨,苏门答腊,老挝 (GMT +7)'), "28800" => _t('北京时间 香港,新加坡,越南 (GMT +8)'), "32400" => _t('东京平壤时间 西伊里安,摩鹿加群岛 (GMT +9)'), "36000" => _t('悉尼关岛时间 塔斯马尼亚岛,新几内亚 (GMT +10)'), "39600" => _t('所罗门群岛 库页岛 (GMT +11)'), "43200" => _t('惠灵顿时间 新西兰,斐济群岛 (GMT +12)'), "-3600" => _t('佛德尔群岛 亚速尔群岛,葡属几内亚 (GMT -1)'), "-7200" => _t('大西洋中部时间 格陵兰 (GMT -2)'), "-10800" => _t('布宜诺斯艾利斯 乌拉圭,法属圭亚那 (GMT -3)'), "-14400" => _t('智利巴西 委内瑞拉,玻利维亚 (GMT -4)'), "-18000" => _t('纽约渥太华 古巴,哥伦比亚,牙买加 (GMT -5)'), "-21600" => _t('墨西哥城时间 洪都拉斯,危地马拉,哥斯达黎加 (GMT -6)'), "-25200" => _t('美国丹佛时间 (GMT -7)'), "-28800" => _t('美国旧金山时间 (GMT -8)'), "-32400" => _t('阿拉斯加时间 (GMT -9)'), "-36000" => _t('夏威夷群岛 (GMT -10)'), "-39600" => _t('东萨摩亚群岛 (GMT -11)'), "-43200" => _t('艾尼威托克岛 (GMT -12)')); $timezone = new Typecho_Widget_Helper_Form_Element_Select('timezone', $timezoneList, $this->options->timezone, _t('时区')); $form->addInput($timezone); /** 扩展名 */ $attachmentTypesOptionsResult = NULL != trim($this->options->attachmentTypes) ? array_map('trim', explode(',', $this->options->attachmentTypes)) : array(); $attachmentTypesOptionsValue = array(); if (in_array('@image@', $attachmentTypesOptionsResult)) { $attachmentTypesOptionsValue[] = '@image@'; } if (in_array('@media@', $attachmentTypesOptionsResult)) { $attachmentTypesOptionsValue[] = '@media@'; } if (in_array('@doc@', $attachmentTypesOptionsResult)) { $attachmentTypesOptionsValue[] = '@doc@'; } $attachmentTypesOther = array_diff($attachmentTypesOptionsResult, $attachmentTypesOptionsValue); $attachmentTypesOtherValue = ''; if (!empty($attachmentTypesOther)) { $attachmentTypesOptionsValue[] = '@other@'; $attachmentTypesOtherValue = implode(',', $attachmentTypesOther); } $attachmentTypesOptions = array('@image@' => _t('图片文件') . ' <code>(gif jpg jpeg png tiff bmp)</code>', '@media@' => _t('多媒体文件') . ' <code>(mp3 wmv wma rmvb rm avi flv)</code>', '@doc@' => _t('常用档案文件') . ' <code>(txt doc docx xls xlsx ppt pptx zip rar pdf)</code>', '@other@' => _t('其他格式 %s', ' <input type="text" class="w-50 text-s mono" name="attachmentTypesOther" value="' . htmlspecialchars($attachmentTypesOtherValue) . '" />')); $attachmentTypes = new Typecho_Widget_Helper_Form_Element_Checkbox('attachmentTypes', $attachmentTypesOptions, $attachmentTypesOptionsValue, _t('允许上传的文件类型'), _t('用逗号 "," 将后缀名隔开, 例如: %s', '<code>cpp, h, mak</code>')); $form->addInput($attachmentTypes->multiMode()); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置')); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); return $form; }
/** * 双因素认证表单 * * @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; }