/** * 获取插件配置面板 * * @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) { 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); }
/** * 生成表单 * * @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) { $request = Typecho_Request::getInstance(); /** 构建表格 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/DomainTheme-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text(self::$FORM_PRE . 'name', NULL, NULL, _t('名称')); $form->addInput($name); /** 地址 */ $url = new Typecho_Widget_Helper_Form_Element_Text(self::$FORM_PRE . 'domain', NULL, "", _t('域名')); $form->addInput($url); /** 主题 */ self::$TEMP_THEME_NAME = isset($request->themename) ? $request->themename : 'default'; $themes = array_map('basename', glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*')); $themes = array_combine($themes, $themes); $theme = new DomainTheme_Element_Select(self::$FORM_PRE . 'theme', $themes, self::$TEMP_THEME_NAME, _t('主题名称'), _t('模板名称')); $form->addInput($theme); /** 模板数据 **/ $template_data = array(); /** 链接动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden(self::$FORM_PRE . 'do'); $form->addInput($do); /** 链接主键 */ $id = new Typecho_Widget_Helper_Form_Element_Hidden(self::$FORM_PRE . 'id'); $form->addInput($id); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $name->value(isset($request->name) ? $request->name : null); $url->value(isset($request->domain) ? $request->domain : null); if (isset($request->id) && 'insert' != $action) { /** 更新模式 */ $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $link = $db->fetchRow($db->select()->from($prefix . 'domaintheme')->where('id = ?', $request->id)); if (!$link) { throw new Typecho_Widget_Exception(_t('链接不存在'), 404); } $name->value(isset($request->name) ? $request->name : $link['name']); $url->value(isset($request->domain) ? $request->domain : $link['domain']); //$user->value($link['user']); $template_data = json_decode($link['user'], true); if (!isset($request->themename)) { self::$TEMP_THEME_NAME = $link['theme']; $theme->value($link['theme']); } $do->value('update'); $id->value($link['id']); $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('必须填写域名地址')); $theme->addRule('required', _t('必须填写模板名称')); } if ('update' == $action) { $id->addRule('required', _t('链接主键不存在')); } /** 自定义数据 */ //$user = new Typecho_Widget_Helper_Form_Element_Textarea('user', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展(json格式)')); //$form->addInput($user); self::configTheme($form, $template_data); $form->addItem($submit); return $form; }