Exemplo n.º 1
0
 public function updateLink()
 {
     $this->checkLogin();
     if (DomainTheme_Plugin::form('update')->validate()) {
         $this->response->goBack();
     }
     /** 取出数据 */
     //$form_data = $this->request->from(array_keys($_POST));
     $form_data = $_POST;
     $data['id'] = $this->get_data_once($form_data, DomainTheme_Plugin::$FORM_PRE . 'id');
     $data['name'] = $this->get_data_once($form_data, DomainTheme_Plugin::$FORM_PRE . 'name');
     $data['domain'] = $this->get_data_once($form_data, DomainTheme_Plugin::$FORM_PRE . 'domain');
     $data['theme'] = $this->get_data_once($form_data, DomainTheme_Plugin::$FORM_PRE . 'theme');
     unset($form_data[DomainTheme_Plugin::$FORM_PRE . 'do']);
     $data['user'] = json_encode($form_data);
     /** 更新数据 */
     $this->db->query($this->db->update($this->prefix . 'domaintheme')->rows($data)->where('id = ?', $data['id']));
     /** 设置高亮 */
     $this->widget('Widget_Notice')->highlight('link-' . $data['id']);
     /** 提示信息 */
     $this->widget('Widget_Notice')->set(_t('"%s" => %s 已经被更新', $data['domain'], $data['theme']), NULL, 'success');
     /** 转向原页 */
     $this->response->redirect(Typecho_Common::url('extending.php?panel=DomainTheme%2Fmanage-domaintheme.php', $this->options->adminUrl));
 }
Exemplo n.º 2
0
                                    <td colspan="5"><h6 class="typecho-list-table-title"><?php 
    _e('没有任何链接');
    ?>
</h6></td>
                                </tr>
                                <?php 
}
?>
                            </tbody>
                        </table>
                    </div>
                    </form>
				</div>
                <div class="col-mb-12 col-tb-4" role="form">
                    <?php 
DomainTheme_Plugin::form()->render();
?>
                </div>
        </div>
    </div>
</div>

<?php 
include 'copyright.php';
include 'common-js.php';
?>

<script type="text/javascript">
(function () {
    $(document).ready(function () {
        var table = $('.typecho-list-table').tableDnD({
Exemplo n.º 3
0
 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;
 }