public function theme() { if ($theme = $this->request->get('theme')) { $this->db->query($this->db->update('table.options')->rows(array('value' => $theme))->where('name=?', 'Duoshuo_theme')); $this->response->redirect(Typecho_Common::url('extending.php?panel=Duoshuo/manage-duoshuo.php&do=manage-theme', $this->options->adminUrl)); } }
/** * 设置前缀 * * @param string $url * @access public * @return void */ public static function setPrefix($url) { self::$_prefix = md5($url); $parsed = parse_url($url); /** 在路径后面强制加上斜杠 */ self::$_path = empty($parsed['path']) ? '/' : Typecho_Common::url(NULL, $parsed['path']); }
/** * 插件实现方法 * * @access public * @return void */ public static function render($post) { $options = Helper::options(); $js = Typecho_Common::url('TinyMCE/tiny_mce/tiny_mce.js', $options->pluginUrl); $langs = Typecho_Common::url('extending.php?panel=TinyMCE/tiny_mce/langs.php', $options->adminUrl); echo "<script type=\"text/javascript\" src=\"{$js}\"></script>\n<script type=\"text/javascript\" src=\"{$langs}\"></script>\n<script type=\"text/javascript\">\n var insertImageToEditor = function (title, url, link) {\n tinyMCE.activeEditor.execCommand('mceInsertContent', false,\n '<a href=\"' + link + '\" title=\"' + title + '\"><img src=\"' + url + '\" alt=\"' + title + '\" /></a>');\n new Fx.Scroll(window).toElement(\$(document).getElement('.mceEditor'));\n };\n \n var insertLinkToEditor = function (title, url, link) {\n tinyMCE.activeEditor.execCommand('mceInsertContent', false, '<a href=\"' + url + '\" title=\"' + title + '\">' + title + '</a>');\n new Fx.Scroll(window).toElement(\$(document).getElement('.mceEditor'));\n };\n\n //自动保存\n var autoSave;\n \n tinyMCE.init({\n // General options\n mode : 'exact',\n elements : 'text',\n theme : 'advanced',\n skin : 'typecho',\n plugins : 'safari,morebreak,inlinepopups,media,coder',\n extended_valid_elements : 'code[*],pre[*],script[*],iframe[*]',\n \n init_instance_callback : function(ed) {\n \n ed.setContent(\"" . str_replace(array("\n", "\r"), array("\\n", ""), addslashes($post->content)) . "\");\n " . ($options->autoSave ? "autoSave = new Typecho.autoSave(\$('text').getParent('form').getProperty('action'), {\n time: 60,\n getContentHandle: tinyMCE.activeEditor.getContent.bind(ed),\n messageElement: 'auto-save-message',\n leaveMessage: '" . _t('您的内容尚未保存, 是否离开此页面?') . "',\n form: \$('text').getParent('form')\n });" : "") . "\n },\n \n onchange_callback: function (inst) {\n if ('undefined' != typeof(autoSave)) {\n autoSave.onContentChange();\n }\n },\n \n save_callback: function (element_id, html, body) {\n if ('undefined' != typeof(autoSave)) {\n autoSave.saveRev = autoSave.rev;\n }\n \n return html;\n },\n \n // Theme options\n theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,blockquote,|,link,unlink,image,media,|,forecolor,backcolor,|,morebreak,code',\n theme_advanced_buttons2 : '',\n theme_advanced_buttons3 : '',\n theme_advanced_toolbar_location : 'top',\n theme_advanced_toolbar_align : 'left',\n convert_urls : false,\n language : 'typecho'\n});\n</script>"; }
/** * 执行函数 * * @access public * @return void */ public function execute() { $themes = glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*'); if ($themes) { $options = $this->widget('Widget_Options'); $siteUrl = $options->siteUrl; $adminUrl = $options->adminUrl; $activated = 0; $result = array(); foreach ($themes as $key => $theme) { $themeFile = $theme . '/index.php'; if (file_exists($themeFile)) { $info = Typecho_Plugin::parseInfo($themeFile); $info['name'] = basename($theme); if ($info['activated'] = $options->theme == $info['name']) { $activated = $key; } $screen = glob($theme . '/screen*.{jpg,png,gif,bmp,jpeg,JPG,PNG,GIF,BMG,JPEG}', GLOB_BRACE); if ($screen) { $info['screen'] = Typecho_Common::url(trim(__TYPECHO_THEME_DIR__, '/') . '/' . $info['name'] . '/' . basename(current($screen)), $siteUrl); } else { $info['screen'] = Typecho_Common::url('/images/noscreen.gif', $adminUrl); } $result[$key] = $info; } } $clone = $result[$activated]; unset($result[$activated]); array_unshift($result, $clone); array_filter($result, array($this, 'push')); } }
/** * 发布文章 * * @access public * @return void */ public function writePage() { $contents = $this->request->from('text', 'template', 'allowComment', 'allowPing', 'allowFeed', 'slug', 'order'); $contents['type'] = 'page'; $contents['title'] = $this->request->get('title', _t('未命名页面')); $contents['created'] = $this->getCreated(); $contents = $this->pluginHandle()->write($contents, $this); if ($this->request->is('do=publish')) { /** 重新发布已经存在的文章 */ $this->publish($contents); /** 发送ping */ $this->widget('Widget_Service')->sendPing($this->cid); /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('页面 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title), NULL, 'success'); /** 设置高亮 */ $this->widget('Widget_Notice')->highlight($this->theId); /** 页面跳转 */ $this->response->redirect(Typecho_Common::url('manage-pages.php?', $this->options->adminUrl)); } else { /** 保存文章 */ $this->save($contents); if ($this->request->isAjax()) { $created = new Typecho_Date($this->options->gmtTime); $this->response->throwJson(array('success' => 1, 'message' => _t('文章保存于 %s', $created->format('H:i A')), 'cid' => $this->cid)); } else { /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), NULL, 'success'); /** 返回原页面 */ $this->response->redirect(Typecho_Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl)); } } }
/** * 获取插件配置面板 * * @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 * @return void */ public function execute() { $themes = $this->getThemes(); if ($themes) { $options = $this->widget('Widget_Options'); $siteUrl = $options->siteUrl; $adminUrl = $options->adminUrl; $activated = 0; $result = array(); foreach ($themes as $key => $theme) { $themeFile = $theme . '/index.php'; if (file_exists($themeFile)) { $info = Typecho_Plugin::parseInfo($themeFile); $info['name'] = $this->getTheme($theme, $key); if ($info['activated'] = $options->theme == $info['name']) { $activated = $key; } $screen = glob($theme . '/screen*.{jpg,png,gif,bmp,jpeg,JPG,PNG,GIF,BMG,JPEG}', GLOB_BRACE); if ($screen) { $info['screen'] = $options->themeUrl(basename(current($screen)), $info['name']); } else { $info['screen'] = Typecho_Common::url('noscreen.png', $options->adminStaticUrl('img')); } $result[$key] = $info; } } $clone = $result[$activated]; unset($result[$activated]); array_unshift($result, $clone); array_filter($result, array($this, 'push')); } }
private function setBody() { if (empty($this->parameter->confirm)) { throw new Typecho_Widget_Exception(_t('收件人不存在'), 404); } $this->parameter->siteTitle = $this->options->title; $this->parameter->token = strtolower(Typecho_Common::randString(8)); $this->parameter->subject = $this->_type[$this->parameter->type]; switch ($this->parameter->type) { case 'reset': $url = '/forgot'; break; case 'register': $url = '/activate'; break; default: $url = ''; break; } if (!empty($url)) { $this->parameter->url = Typecho_Common::url($url . '?token=' . $this->parameter->token, $this->options->index); } else { $this->parameter->url = $this->parameter->token; } $this->parameter->body = $this->parseBody(); return $this; }
public static function Change() { $options = Helper::options(); $cssUrl = Typecho_Common::url('LREditor/lr.css', $options->pluginUrl); $jsUrl = Typecho_Common::url('LREditor/prettify.js', $options->pluginUrl); echo '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />'; echo '<script type="text/javascript" src="' . $jsUrl . '"></script>'; ?> <script> function prettify() { $("pre").addClass("prettyprint"); prettyPrint(); } $(function() { setInterval("$('#wmd-preview').css('height', (parseInt($('#text').height()) - 5)+'px');", 500); setInterval("prettify()", 10); //Typecho.editorResize('wmd-preview', '<?php $options->index('/action/ajax?do=editorResize'); ?> '); //$('#wmd-preview').remove(); //$('textarea').after('<div id="wmd-preview"></div>'); }); </script> <?php }
/** * 插件实现方法 * * @access public * @return void */ public static function setTheme($widget) { $cookie = array('name' => '__typecho_theme', 'expire' => 86400); $options = Typecho_Widget::widget('Widget_Options'); if (isset($widget->request->theme) && $widget->request->isGet()) { if ($widget->request->theme) { $theme = $widget->request->theme; if (static::check($theme)) { Typecho_Cookie::set($cookie['name'], $widget->request->theme, $options->gmtTime + $cookie['expire'], $options->siteUrl); } else { $widget->response->redirect(Typecho_Common::url($widget->request->getPathInfo(), $options->siteUrl)); } } else { Typecho_Cookie::delete($cookie['name']); //直接提交?theme将删除cookie,恢复默认主题 return; } } else { $theme = Typecho_Cookie::get($cookie['name']); if (!$theme) { return; } if (!static::check($theme)) { Typecho_Cookie::delete($cookie['name']); return; } } /** 删除旧主题的相关设置 */ $themeRow = 'theme:' . $options->theme; if (isset($options->{$themeRow})) { $config = unserialize($options->{$themeRow}); $options->{$themeRow} = ''; foreach ($config as $row => $value) { $options->{$row} = ''; } } /** 载入新主题的相关设置 参考var/Widget/Themes/Edit.php */ $themeDir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR; $configFile = $themeDir . 'functions.php'; if (file_exists($configFile)) { require_once $configFile; if (function_exists('themeConfig')) { $form = new Typecho_Widget_Helper_Form(); themeConfig($form); $config = $form->getValues(); if ($config) { $options->{'theme:' . $theme} = serialize($config); foreach ($config as $row => $value) { $options->{$row} = $value; } } } } /** 修改$this->options->theme */ $options->theme = $theme; /** 修改$this->_themeDir */ $widget->setThemeDir($themeDir); }
/** * 插件实现方法 * * @access public * @return void */ public static function render($post) { $options = Helper::options(); $plugin_options = Typecho_Widget::widget('Widget_Options')->plugin('KEditor'); $newlineTag = $plugin_options->newlineTag; $themesTab = $plugin_options->themesTab; $editor_path = Typecho_Common::url('KEditor/editor', $options->pluginUrl); echo "\n<script type=\"text/javascript\" charset=\"utf-8\" src=\"{$editor_path}/kindeditor.js\"></script> \n<script type=\"text/javascript\">\n KE.show({\n\t\tresizeMode : 1,\n\t themesPath : '{$themesTab}',\n\t\tlangPath : 'zh_CN',\n\t newlineTag : '{$newlineTag}',\n id : 'text'\n });\n\t\$('btn-save').addEvent('mouseover', function (e) {\n\t\tKE.util.setData('text'); \n\t});\n\t\$('btn-submit').addEvent('mouseover', function (e) {\n\t\tKE.util.setData('text'); \n\t});\n function insertHtml(id, html) {\n KE.util.focus(id);\n KE.util.selection(id);\n KE.util.insertHtml(id, html);\n }\n /** 附件插入实现 */\n var insertImageToEditor = function (title, url, link) {\n insertHtml('text', '<a href=\"' + link + '\" title=\"' + title + '\"><img src=\"' + url + '\" alt=\"' + title + '\" /></a>');\n };\n var insertLinkToEditor = function (title, url, link) {\n insertHtml('text', '<a href=\"' + url + '\" title=\"' + title + '\">' + title + '</a>');\n };\n</script>"; }
/** * 执行清空缓存 * * @access public * @return void */ public function deleteFile() { $path = __TYPECHO_ROOT_DIR__ . '/usr/plugins/Avatars/cache/'; foreach (glob($path . '*') as $filename) { unlink($filename); } $this->widget('Widget_Notice')->set('读者墙头像缓存已清空!', NULL, 'success'); $this->response->redirect(Typecho_Common::url('options-plugin.php?config=Avatars', $this->options->adminUrl)); }
/** * 插件实现方法 * * @access public * @return void */ public static function render() { $options = Helper::options(); $cssUrl = Typecho_Common::url('EditorLR/lr.css', $options->pluginUrl); $jsUrl = Typecho_Common::url('EditorLR/prettify.js', $options->pluginUrl); $lrjs = Typecho_Common::url('EditorLR/lr.js', $options->pluginUrl); echo <<<HTML <link rel="stylesheet" type="text/css" href="{$cssUrl}" /> <script type="text/javascript" src="{$jsUrl}"></script> <script type="text/javascript" src="{$lrjs}"></script> HTML; }
/** * 更新相册图片 * * @access public * @return void */ public function updategallery() { if (HighSlide_Plugin::form('update')->validate()) { $this->response->goBack(); } $gallery = $this->request->from('gid', 'thumb', 'image', 'description', 'sort', 'name'); $this->db->query($this->db->update($this->prefix . 'gallery')->rows($gallery)->where('gid=?', $gallery['gid'])); //返回原页并提示信息 $this->widget('Widget_Notice')->highlight('gallery-' . $gallery['gid']); $this->widget('Widget_Notice')->set(_t('相册组%s: 图片%s 更新成功', $gallery['sort'], $gallery['name']), NULL, 'success'); $this->response->redirect(Typecho_Common::url('extending.php?panel=HighSlide%2Fmanage-gallery.php&group=' . $gallery['sort'], $this->options->adminUrl)); }
/** * 上传文件处理函数,如果需要实现自己的文件哈希或者特殊的文件系统,请在options表里把uploadHandle改成自己的函数 * * @access public * @param array $file 上传的文件 * @return mixed */ public static function uploadHandle($file) { if (empty($file['name'])) { return '请选择文件!'; } $result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasUploaded)->uploadHandle($file); if ($hasUploaded) { return $result; } $fileName = preg_split("(\\/|\\|:)", $file['name']); $file['name'] = array_pop($fileName); //获取扩展名 $ext = ''; $part = explode('.', $file['name']); if (($length = count($part)) > 1) { $ext = strtolower($part[$length - 1]); } if (!self::checkFileType($ext)) { return $ext . '类型文件不允许上传!'; } $options = Typecho_Widget::widget('Widget_Options'); $date = new Typecho_Date($options->gmtTime); $path = Typecho_Common::url(defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : parent::UPLOAD_DIR, __TYPECHO_ROOT_DIR__) . '/' . $date->year . '/' . $date->month; //创建上传目录 if (!is_dir($path)) { if (!self::makeUploadDir($path)) { return '不能创建上传目录!'; } } //获取文件名 $fileName = sprintf('%u', crc32(uniqid())) . '.' . $ext; $path = $path . '/' . $fileName; if (isset($file['tmp_name'])) { //移动上传文件 if (!move_uploaded_file($file['tmp_name'], $path)) { return '上传文件失败!'; } } else { if (isset($file['bytes'])) { //直接写入文件 if (!file_put_contents($path, $file['bytes'])) { return '上传文件失败!'; } } else { return '上传文件失败!'; } } if (!isset($file['size'])) { $file['size'] = filesize($path); } //返回相对存储路径 return array('name' => $file['name'], 'path' => (defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : self::UPLOAD_DIR) . '/' . $date->year . '/' . $date->month . '/' . $fileName, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path)); }
/** * 配置外观 * * @access public * @return void */ public function config() { $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/themes-edit?config', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD); themeConfig($form); $inputs = $form->getInputs(); if (!empty($inputs)) { foreach ($inputs as $key => $val) { $form->getInput($key)->value($this->options->{$key}); } } $form->addItem(new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('保存设置'))); 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 function deleteMember() { $mids = $this->request->filter('int')->getArray('mid'); $deleteCount = 0; if ($mids && is_array($mids)) { foreach ($mids as $mid) { if ($this->db->query($this->db->delete($this->prefix . 'hf_members')->where('mid = ?', $mid))) { $deleteCount++; } } } /** 提示信息 */ $this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('会员已经删除') : _t('没有会员被删除'), NULL, $deleteCount > 0 ? 'success' : 'notice'); /** 转向原页 */ $this->response->redirect(Typecho_Common::url('extending.php?panel=HuifengMembers%2Fmanage-members.php', $this->options->adminUrl)); }
/** * 插件实现方法 * * @access public * @return void */ public static function render($post) { $options = Helper::options(); // $plugin_options = $options->plugin('CodeMirror'); $pluginRoot = Typecho_Common::url('CodeMirror/static', $options->pluginUrl); //调用编辑器 echo <<<CODE <link rel="stylesheet" href="{$pluginRoot}/codemirror.css"> <script type="text/javascript" src="{$pluginRoot}/codemirror.js"></script> <script> var editor = CodeMirror.fromTextArea(document.getElementById('content'), { lineNumbers: true }); </script> CODE; }
public function deleteLink() { $lids = $this->request->filter('int')->lid; $deleteCount = 0; if ($lids && is_array($lids)) { foreach ($lids as $lid) { if ($this->db->query($this->db->delete($this->prefix . 'links')->where('lid = ?', $lid))) { $deleteCount++; } } } /** 提示信息 */ $this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('链接已经删除') : _t('没有链接被删除'), NULL, $deleteCount > 0 ? 'success' : 'notice'); /** 转向原页 */ $this->response->redirect(Typecho_Common::url('extending.php?panel=Links%2Fmanage-links.php', $this->options->adminUrl)); }
/** * 输出表单结构 * * @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; }
/** * 向上的返回链接 * * @access public * @return void */ public function backLink() { if (isset($this->request->parent)) { $category = $this->db->fetchRow($this->select()->where('type = ? AND mid = ?', 'category', $this->request->parent)); if (!empty($category)) { $parent = $this->db->fetchRow($this->select()->where('type = ? AND mid = ?', 'category', $category['parent'])); if ($parent) { echo '<a href="' . Typecho_Common::url('manage-categories.php?parent=' . $parent['mid'], $this->options->adminUrl) . '">'; } else { echo '<a href="' . Typecho_Common::url('manage-categories.php', $this->options->adminUrl) . '">'; } echo '« '; _e('返回父级分类'); echo '</a>'; } } }
/** * 找回密码 * * @access public * @return void */ public function doForgot() { require_once 'theme/forgot.php'; if ($this->request->isPost()) { /* 验证表单 */ if ($error = $this->forgotForm()->validate()) { $this->notice->set($error, 'error'); return false; } $db = Typecho_Db::get(); $user = $db->fetchRow($db->select()->from('table.users')->where('mail = ?', $this->request->mail)); if (empty($user)) { // 返回没有该用户 $this->notice->set(_t('该邮箱还没有注册'), 'error'); return false; } /* 生成重置密码地址 */ $hashString = $user['name'] . $user['mail'] . $user['password']; $hashValidate = Typecho_Common::hash($hashString); $token = base64_encode($user['uid'] . '.' . $hashValidate . '.' . $this->options->gmtTime); $url = Typecho_Common::url('/passport/reset?token=' . $token, $this->options->index); /* 发送重置密码地址 */ require_once 'PHPMailer/PHPMailerAutoload.php'; $phpMailer = new PHPMailer(); /* SMTP设置 */ $phpMailer->isSMTP(); $phpMailer->SMTPAuth = true; $phpMailer->Host = $this->config->host; $phpMailer->Port = $this->config->port; $phpMailer->Username = $this->config->username; $phpMailer->Password = $this->config->password; $phpMailer->isHTML(true); if ('none' != $this->config->secure) { $phpMailer->SMTPSecure = $this->config->secure; } $phpMailer->setFrom($this->config->username, $this->options->title); $phpMailer->addAddress($user['mail'], $user['name']); $phpMailer->Subject = '密码重置'; $phpMailer->Body = '<p>' . $user['name'] . ' 您好,您申请了重置登录密码</p>' . '<p>请在 1 小时内点击此链接以完成重置 <a href="' . $url . '">' . $url . '</a>'; if (!$phpMailer->send()) { $this->notice->set(_t('邮件发送失败, 请重试或联系站长'), 'error'); } else { $this->notice->set(_t('邮件已成功发送, 请注意查收'), 'success'); } } }
public static function Change() { $options = Helper::options(); $jsUrl = Typecho_Common::url('Editor/editor.js', $options->pluginUrl); $cssUrl = Typecho_Common::url('Editor/editor.css', $options->pluginUrl); ?> <link rel="stylesheet" href="<?php echo $cssUrl; ?> " /> <script type="text/javascript" src="http://lab.lepture.com/editor/marked.js"></script> <script type="text/javascript" src="<?php echo $jsUrl; ?> "></script> <script>var editor = new Editor();editor.render();</script> <?php }
/** * 删除指定的COOKIE值 * * @access public * @param string $key 指定的参数 * @return void */ public static function delete($key, $url = NULL) { if (!isset($_COOKIE[$key])) { return; } $path = '/'; if (!empty($url)) { $parsed = parse_url($url); /** 在路径后面强制加上斜杠 */ $path = empty($parsed['path']) ? '/' : Typecho_Common::url(NULL, $parsed['path']); } /** 对数组型COOKIE的删除支持 */ if (is_array($_COOKIE[$key])) { foreach ($_COOKIE[$key] as $name => $val) { setcookie("{$key}[{$name}]", '', time() - 2592000, $path); } } else { setcookie($key, '', time() - 2592000, $path); } }
public function resetPwd() { $token = $this->request->token; if (empty($token)) { throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404); } $verify = $this->widget('Util_Verify')->setParams('type=reset')->check($token); if (empty($verify) || empty($verify['uid'])) { throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404); } $validator = new Typecho_Validate(); $validator->addRule('password', 'required', _t('必须填写密码')); $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18); $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password'); $error = $validator->run($this->request->from('password', 'confirm')); /** 截获验证异常 */ if ($error) { /** 设置提示信息 */ $this->widget('Widget_Notice')->set($error, 'error'); $this->response->goBack(); } $password = $this->request->get('password'); $hasher = new PasswordHash(8, true); $password = $hasher->HashPassword($password); /** 更新数据 */ $this->update(array('password' => $password), $this->db->sql()->where('uid = ?', $verify['uid'])); /** 提示信息 */ $this->widget('Widget_Notice')->set(_t('密码已经成功修改,请重新登录'), 'success'); $this->widget('Util_Verify')->setParams('type=reset')->delete($token); if ($this->user->hasLogin()) { $this->user->logout(); } /** 转向登录页面 */ $this->response->redirect(Typecho_Common::url('login', $this->options->index)); }
/** * 插件实现方法 * * @access public * @return void */ public static function render($post) { $options = Helper::options(); $configJs = Typecho_Common::url('extending.php?panel=UEditor/ueditor/ueditor.config.js.php', $options->adminUrl); $js = Typecho_Common::url('UEditor/ueditor/ueditor.all.min.js', $options->pluginUrl); echo '<script type="text/javascript" src="' . $configJs . '"></script><script type="text/javascript" src="' . $js . '"></script>'; echo '<script type="text/javascript"> var ue1; window.onload = function() { // 渲染 ue1 = UE.getEditor("text"); } // 保存草稿时同步 document.getElementById("btn-save").onclick = function() { ue1.sync("text"); } // 提交时同步 document.getElementById("btn-submit").onclick = function() { ue1.sync("text"); } </script>'; }
/** * 插件实现方法 * * @access public * @return void */ public static function render($post) { $options = Helper::options(); $config = $options->plugin(self::$pluginName); $pluginName = self::$pluginName; $editorTheme = $config->editorTheme; $editorLang = $config->editorLang; if (!$editorLang) { $editorLang = 'zh_CN'; } $editor_default_css_url = Typecho_Common::url("{$pluginName}/editor/themes/default/default.css", $options->pluginUrl); $editor_css_url = Typecho_Common::url("{$pluginName}/editor/themes/{$editorTheme}/{$editorTheme}.css", $options->pluginUrl); $kindeditor_js_url = Typecho_Common::url("{$pluginName}/editor/kindeditor-min.js", $options->pluginUrl); $lang_js_url = Typecho_Common::url("{$pluginName}/editor/lang/{$editorLang}.js", $options->pluginUrl); $editorUploadJson = Typecho_Common::url('action/plugins-kind-upload', Typecho_Widget::widget('Widget_Options')->index); $editorUploadJson .= isset($post->cid) ? "?cid={$post->cid}" : ''; $editorNewlineTag = $config->editorNewlineTag; $editorPasteType = $config->editorPasteType; if (!in_array($editorPasteType, array('1', '2', '0'))) { $editorPasteType = 2; } if ($editorTheme == 'simple') { $items = array('fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'emoticons', 'image', 'link'); } else { if ($editorTheme == 'qq') { $items = array('bold', 'italic', 'underline', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'plug-align', 'plug-order', 'plug-indent', 'link'); } else { $items = $config->editorTools; foreach ($items as $k => $v) { if (strpos($v, '|') === 0) { $items[$k] = '|'; } } } } $items = json_encode($items); echo <<<EOF <link rel="stylesheet" href="{$editor_default_css_url}" /> <link rel="stylesheet" href="{$editor_css_url}" /> <script type="text/javascript" src="{$kindeditor_js_url}"></script> <script type="text/javascript" src="{$lang_js_url}"></script> <script type="text/javascript"> var keditor; KindEditor.ready(function(K) { keditor = K.create("textarea#text", { \tthemeType : '{$editorTheme}', \tresizeType:1, \twidth : '100%', \theight : '{$options->editorSize}px', \tlangType : '{$editorLang}', \tallowImageUpload : true, \tallowFlashUpload : true, \tallowMediaUpload : true, \tallowFileManager : false, \tuploadJson : '{$editorUploadJson}', \tnewlineTag : '{$editorNewlineTag}', \tpasteType : {$editorPasteType}, \tpagebreakHtml:'<!--more-->', \tafterBlur : function() {keditor.sync();}, \t\t\titems :{$items} }); //插入编辑器 Typecho.insertFileToEditor = function (file, url, isImage) { var html='<a href="' + url + '" title="' + file + '">' + file + '</a>'; if(isImage){ html= '<a href="' + url + '" title="' + file + '"><img src="' + url + '" alt="' + file + '" /></a>'; } keditor.insertHtml(html).hideDialog().focus(); }; }); </script> EOF; }
/** * 检测是否可以rewrite * * @access public * @param string $value 是否打开rewrite * @return void */ public function checkRewrite($value) { if ($value) { $this->user->pass('administrator'); /** 首先直接请求远程地址验证 */ $client = Typecho_Http_Client::get(); $hasWrote = false; if (!file_exists(__TYPECHO_ROOT_DIR__ . '/.htaccess') && !Typecho_Common::isAppEngine()) { if (is_writeable(__TYPECHO_ROOT_DIR__)) { $parsed = parse_url($this->options->siteUrl); $basePath = empty($parsed['path']) ? '/' : $parsed['path']; $basePath = rtrim($basePath, '/') . '/'; $hasWrote = file_put_contents(__TYPECHO_ROOT_DIR__ . '/.htaccess', "<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase {$basePath}\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.*)\$ {$basePath}index.php/\$1 [L]\n</IfModule>"); } } try { if ($client) { /** 发送一个rewrite地址请求 */ $client->setData(array('do' => 'remoteCallback'))->setHeader('User-Agent', $this->options->generator)->send(Typecho_Common::url('/action/ajax', $this->options->siteUrl)); if (200 == $client->getResponseStatus() && 'OK' == $client->getResponseBody()) { return true; } } if (false !== $hasWrote) { @unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess'); //增强兼容性,使用wordpress的redirect式rewrite规则,虽然效率有点地下,但是对fastcgi模式兼容性较好 $hasWrote = file_put_contents(__TYPECHO_ROOT_DIR__ . '/.htaccess', "<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase {$basePath}\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . {$basePath}index.php [L]\n</IfModule>"); //再次进行验证 $client = Typecho_Http_Client::get(); if ($client) { /** 发送一个rewrite地址请求 */ $client->setData(array('do' => 'remoteCallback'))->setHeader('User-Agent', $this->options->generator)->send(Typecho_Common::url('/action/ajax', $this->options->siteUrl)); if (200 == $client->getResponseStatus() && 'OK' == $client->getResponseBody()) { return true; } } unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess'); } } catch (Typecho_Http_Client_Exception $e) { if (false !== $hasWrote) { @unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess'); } return false; } return false; } else { if (file_exists(__TYPECHO_ROOT_DIR__ . '/.htaccess')) { @unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess'); } } return true; }
/** * 通用过滤器 * * @access public * @param array $value 需要过滤的行数据 * @return array */ public function filter(array $value) { /** 取出所有分类 */ $value['categories'] = $this->db->fetchAll($this->db->select()->from('table.metas')->join('table.relationships', 'table.relationships.mid = table.metas.mid')->where('table.relationships.cid = ?', $value['cid'])->where('table.metas.type = ?', 'category')->order('table.metas.order', Typecho_Db::SORT_ASC), array($this->widget('Widget_Abstract_Metas'), 'filter')); /** 取出第一个分类作为slug条件 */ $value['category'] = current(Typecho_Common::arrayFlatten($value['categories'], 'slug')); $value['date'] = new Typecho_Date($value['created']); /** 生成日期 */ $value['year'] = $value['date']->year; $value['month'] = $value['date']->month; $value['day'] = $value['date']->day; /** 生成访问权限 */ $value['hidden'] = false; /** 获取路由类型并判断此类型在路由表中是否存在 */ $type = $value['type']; $routeExists = NULL != Typecho_Router::get($type); $tmpSlug = $value['slug']; $tmpCategory = $value['category']; $value['slug'] = urlencode($value['slug']); $value['category'] = urlencode($value['category']); /** 生成静态路径 */ $value['pathinfo'] = $routeExists ? Typecho_Router::url($type, $value) : '#'; /** 生成静态链接 */ $value['permalink'] = Typecho_Common::url($value['pathinfo'], $this->options->index); /** 处理附件 */ if ('attachment' == $type) { $content = @unserialize($value['text']); //增加数据信息 $value['attachment'] = new Typecho_Config($content); $value['attachment']->isImage = in_array($content['type'], array('jpg', 'jpeg', 'gif', 'png', 'tiff', 'bmp')); $value['attachment']->url = Widget_Upload::attachmentHandle($value); if ($value['attachment']->isImage) { $value['text'] = '<img src="' . $value['attachment']->url . '" alt="' . $value['title'] . '" />'; } else { $value['text'] = '<a href="' . $value['attachment']->url . '" title="' . $value['title'] . '">' . $value['title'] . '</a>'; } } /** 处理Markdown **/ $value['isMarkdown'] = 0 === strpos($value['text'], '<!--markdown-->'); if ($value['isMarkdown']) { $value['text'] = substr($value['text'], 15); } /** 生成聚合链接 */ /** RSS 2.0 */ $value['feedUrl'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->feedUrl) : '#'; /** RSS 1.0 */ $value['feedRssUrl'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->feedRssUrl) : '#'; /** ATOM 1.0 */ $value['feedAtomUrl'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->feedAtomUrl) : '#'; $value['slug'] = $tmpSlug; $value['category'] = $tmpCategory; /** 处理密码保护流程 */ if (!empty($value['password']) && $value['password'] != $this->request->protectPassword && $value['authorId'] != $this->user->uid && !$this->user->pass('editor', true)) { $value['hidden'] = true; /** 抛出错误 */ if ($this->request->isPost() && isset($this->request->protectPassword)) { throw new Typecho_Widget_Exception(_t('对不起,您输入的密码错误'), 403); } } $value = $this->pluginHandle(__CLASS__)->filter($value, $this); /** 如果访问权限被禁止 */ if ($value['hidden']) { $value['text'] = '<form class="protected" action="' . $value['permalink'] . '" method="post">' . '<p class="word">' . _t('请输入密码访问') . '</p>' . '<p><input type="password" class="text" name="protectPassword" /> <input type="submit" class="submit" value="' . _t('提交') . '" /></p>' . '</form>'; $value['title'] = _t('此内容被密码保护'); $value['tags'] = array(); $value['commentsNum'] = 0; } return $value; }