示例#1
0
 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));
     }
 }
示例#2
0
 /**
  * 获取插件配置面板
  * 
  * @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);
 }
示例#3
0
文件: Edit.php 项目: raindali/express
 /**
  * 发布文章
  *
  * @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));
         }
     }
 }
示例#4
0
 /**
  * 返回所有的文章
  * news:
  *      count:
  *      articles:
  *             [
  *                  author:
  *                  title:
  *                  time:
  *                  excerp:
  *              ]
  * @return {}
  */
 public function getPosts()
 {
     $_cats = $this->db->fetchAll($this->db->select('slug, name, mid, count, description')->from('table.metas')->where('type = ?', 'category'));
     $_cat_item = array();
     $res = array();
     foreach ($_cats as $key => $value) {
         $_articles_db = $this->db->fetchAll($this->db->select('table.contents.slug, table.contents.cid, table.contents.text, table.contents.title, table.contents.created, table.users.screenName')->from('table.contents')->join('table.relationships', 'table.relationships.cid = table.contents.cid')->join('table.users', 'table.users.uid = table.contents.authorId')->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', 'post')->where('table.relationships.mid = ?', $value['mid']));
         //$_articles = array();
         foreach ($_articles_db as $key => $_value_article) {
             //$_value_article['slug'] = $_value_article[];
             //$_value_article['title'] = $_value_article[];
             $_value_article['author'] = $_value_article['screenName'];
             unset($_value_article['screenName']);
             $_value_article['excerp'] = Typecho_Common::subStr(strip_tags($_value_article['text']), 0, 100, '...');
             unset($_value_article['text']);
             $_value_article['time'] = $_value_article['created'];
             unset($_value_article['created']);
             /* 最好在上面内联选择出来 */
             $_value_article['banner'] = self::getBanner($_value_article['cid']);
             $_articles_db[$key] = $_value_article;
             //$_articles[] = $_value_article;
         }
         $_cat_item['articles'] = $_articles_db;
         $_cat_item['count'] = $value['count'];
         $_cat_item['name'] = $value['name'];
         $_cat_item['description'] = $value['description'];
         $res[$value['slug']] = $_cat_item;
     }
     return $res;
 }
示例#5
0
 /**
  * 插件实现方法
  * 
  * @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>";
 }
示例#6
0
文件: Verify.php 项目: dccecc/typecho
 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;
 }
示例#7
0
 /**
  * Normalize reference label
  *
  * This enables case-insensitive label matching
  *
  * @param string $string
  *
  * @return string
  */
 public static function normalizeReference($string)
 {
     // Collapse internal whitespace to single space and remove
     // leading/trailing whitespace
     $string = preg_replace('/\\s+/', '', trim($string));
     return Typecho_Common::strToUpper($string, 'UTF-8');
 }
示例#8
0
 /**
  * 执行函数
  *
  * @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'));
     }
 }
示例#9
0
文件: List.php 项目: raindali/express
 /**
  * 执行函数
  *
  * @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'));
     }
 }
示例#10
0
文件: Action.php 项目: dccecc/typecho
 public function avatar()
 {
     $uid = $this->request->get('uid');
     $size = $this->request->get('s');
     if (!is_numeric($uid)) {
         Typecho_Common::error(404);
         exit;
     }
     $path = __TYPECHO_ROOT_DIR__ . Widget_Common::getAvatarPath($uid);
     $path .= $uid . '.jpg';
     if (!is_file($path)) {
         $path = __TYPECHO_ROOT_DIR__ . '/usr/avatar/default.jpg';
     }
     require_once __TYPECHO_ROOT_DIR__ . '/var/Util/Image.php';
     $image = new Image();
     $image->open($path);
     $type = $image->type();
     if (is_numeric($size)) {
         $image->thumb($size, $size);
     }
     header('Content-Type:image/' . $type . ';');
     //输出图像
     if ('jpeg' == $type || 'jpg' == $type) {
         // 采用jpeg方式输出
         imagejpeg($image->showImg());
     } elseif ('gif' == $type) {
         imagegif($image->showImg());
     } else {
         $fun = 'image' . $type;
         $fun($image->showImg());
     }
 }
示例#11
0
文件: Do.php 项目: dccecc/typecho
 /**
  * 入口函数,初始化路由器
  *
  * @access public
  * @return void
  * @throws Typecho_Widget_Exception
  */
 public function execute()
 {
     /** 验证路由地址 **/
     $action = $this->request->action;
     //兼容老版本
     if (empty($action)) {
         $widget = trim($this->request->widget, '/');
         $objectName = 'Widget_' . str_replace('/', '_', $widget);
         if (Typecho_Common::isAvailableClass($objectName)) {
             $widgetName = $objectName;
         }
     } else {
         /** 判断是否为plugin */
         $actionTable = array_merge($this->_map, unserialize($this->widget('Widget_Options')->actionTable));
         if (isset($actionTable[$action])) {
             $widgetName = $actionTable[$action];
         }
     }
     if (isset($widgetName) && class_exists($widgetName)) {
         $reflectionWidget = new ReflectionClass($widgetName);
         if ($reflectionWidget->implementsInterface('Widget_Interface_Do')) {
             $this->widget($widgetName)->action();
             return;
         }
     }
     throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404);
 }
示例#12
0
 /**
  * 设置前缀 
  * 
  * @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']);
 }
示例#13
0
文件: Init.php 项目: raindali/express
 /**
  * 入口函数,初始化路由器
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 对变量赋值 */
     $options = $this->widget('Widget_Options');
     /** 开始会话 */
     @session_start();
     /** 初始化charset */
     Typecho_Common::$charset = $options->charset;
     /** 初始化exception */
     Typecho_Common::$exceptionHandle = 'Widget_ExceptionHandle';
     /** 设置路径 */
     if (defined('__TYPECHO_PATHINFO_ENCODING__')) {
         $pathInfo = $this->request->getPathInfo(__TYPECHO_PATHINFO_ENCODING__, $options->charset);
     } else {
         $pathInfo = $this->request->getPathInfo();
     }
     Typecho_Router::setPathInfo($pathInfo);
     /** 初始化路由器 */
     Typecho_Router::setRoutes($options->routingTable);
     /** 初始化插件 */
     Typecho_Plugin::init($options->plugins);
     /** 初始化回执 */
     $this->response->setCharset($options->charset);
     $this->response->setContentType($options->contentType);
     /** 默认时区 */
     if (!ini_get("date.timezone") && function_exists("date_default_timezone_set")) {
         @date_default_timezone_set('UTC');
     }
     /** 初始化时区 */
     Typecho_Date::setTimezoneOffset($options->timezone);
     /** 监听缓冲区 */
     ob_start();
 }
示例#14
0
 /**
  * 获取插件配置面板
  *
  * @access public
  * @param Typecho_Widget_Helper_Form $form 配置面板
  * @return void
  */
 public static function config(Typecho_Widget_Helper_Form $form)
 {
     $mode = new Typecho_Widget_Helper_Form_Element_Radio('mode', array('smtp' => 'smtp', 'mail' => 'mail()', 'sendmail' => 'sendmail()'), 'smtp', '发信方式');
     $form->addInput($mode);
     $host = new Typecho_Widget_Helper_Form_Element_Text('host', NULL, 'smtp.', _t('SMTP地址'), _t('请填写 SMTP 服务器地址'));
     $form->addInput($host->addRule('required', _t('必须填写一个SMTP服务器地址')));
     $port = new Typecho_Widget_Helper_Form_Element_Text('port', NULL, '25', _t('SMTP端口'), _t('SMTP服务端口,一般为25。'));
     $port->input->setAttribute('class', 'mini');
     $form->addInput($port->addRule('required', _t('必须填写SMTP服务端口'))->addRule('isInteger', _t('端口号必须是纯数字')));
     $user = new Typecho_Widget_Helper_Form_Element_Text('user', NULL, NULL, _t('SMTP用户'), _t('SMTP服务验证用户名,一般为邮箱名如:youname@domain.com'));
     $form->addInput($user->addRule('required', _t('SMTP服务验证用户名')));
     $pass = new Typecho_Widget_Helper_Form_Element_Password('pass', NULL, NULL, _t('SMTP密码'));
     $form->addInput($pass->addRule('required', _t('SMTP服务验证密码')));
     $validate = new Typecho_Widget_Helper_Form_Element_Checkbox('validate', array('validate' => '服务器需要验证', 'ssl' => 'ssl加密'), array('validate'), 'SMTP验证');
     $form->addInput($validate);
     $token = new Typecho_Widget_Helper_Form_Element_Password('token', NULL, Typecho_Common::randString(7), _t('Token'), _t('请勿泄露'));
     $form->addInput($token);
     $fromName = new Typecho_Widget_Helper_Form_Element_Text('fromName', NULL, NULL, _t('发件人名称'), _t('发件人名称,留空则使用博客标题'));
     $form->addInput($fromName);
     $mail = new Typecho_Widget_Helper_Form_Element_Text('mail', NULL, NULL, _t('接收邮件的地址'), _t('接收邮件的地址,如为空则使用文章作者个人设置中的邮件地址!'));
     $form->addInput($mail->addRule('email', _t('请填写正确的邮件地址!')));
     $contactme = new Typecho_Widget_Helper_Form_Element_Text('contactme', NULL, NULL, _t('模板中“联系我”的邮件地址'), _t('联系我用的邮件地址,如为空则使用文章作者个人设置中的邮件地址!'));
     $form->addInput($contactme->addRule('email', _t('请填写正确的邮件地址!')));
     $status = new Typecho_Widget_Helper_Form_Element_Checkbox('status', array('approved' => '提醒已通过评论', 'waiting' => '提醒待审核评论', 'spam' => '提醒垃圾评论'), array('approved', 'waiting'), '提醒设置', _t('该选项仅针对博主,访客只发送已通过的评论。'));
     $form->addInput($status);
     $other = new Typecho_Widget_Helper_Form_Element_Checkbox('other', array('to_owner' => '有评论及回复时,发邮件通知博主。', 'to_guest' => '评论被回复时,发邮件通知评论者。', 'to_me' => '自己回复自己的评论时,发邮件通知。(同时针对博主和访客)', 'to_log' => '记录邮件发送日志。'), array('to_owner', 'to_guest'), '其他设置', _t('选中该选项插件会在log/mailer_log.txt 文件中记录发送日志,需要本地可以写入文件。'));
     $form->addInput($other->multiMode());
     $titleForOwner = new Typecho_Widget_Helper_Form_Element_Text('titleForOwner', null, "[{title}] 一文有新的评论", _t('博主接收邮件标题'));
     $form->addInput($titleForOwner->addRule('required', _t('博主接收邮件标题 不能为空')));
     $titleForGuest = new Typecho_Widget_Helper_Form_Element_Text('titleForGuest', null, "您在 [{title}] 的评论有了回复", _t('访客接收邮件标题'));
     $form->addInput($titleForGuest->addRule('required', _t('访客接收邮件标题 不能为空')));
 }
示例#15
0
    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 
    }
示例#16
0
 /**
  * 执行函数,初始化数据
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     $this->parameter->setDefault('limit=5');
     if ($this->parameter->tags) {
         $tagsGroup = implode(',', Typecho_Common::arrayFlatten($this->parameter->tags, 'mid'));
         $this->db->fetchAll($this->select()->join('table.relationships', 'table.contents.cid = table.relationships.cid')->where('table.relationships.mid IN (' . $tagsGroup . ')')->where('table.contents.cid <> ?', $this->parameter->cid)->where('table.contents.status = ?', 'publish')->where('table.contents.password IS NULL')->where('table.contents.created < ?', $this->options->gmtTime)->where('table.contents.type = ?', $this->parameter->type)->order('table.contents.created', Typecho_Db::SORT_DESC)->limit($this->parameter->limit), array($this, 'push'));
     }
 }
示例#17
0
 /**
  * 插件实现方法
  *
  * @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);
 }
示例#18
0
 /**
  * 插件实现方法
  * 
  * @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>";
 }
示例#19
0
 /**
  * 执行清空缓存
  *
  * @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));
 }
示例#20
0
 private function parseFileName($fileName, $repositoryPath)
 {
     $result = array('do' => 'publish', 'allowComment' => $this->options->defaultAllowComment, 'allowPing' => $this->options->defaultAllowPing, 'allowFeed' => $this->options->defaultAllowFeed);
     $basePath = Helper::options()->plugin('GoogleCodeSVN')->basePath;
     $basePath = '/' . trim($basePath, '/') . '/';
     if (0 !== strpos($fileName, $basePath)) {
         return false;
     }
     $path = substr($fileName, strlen($basePath));
     $part = explode('/', $path);
     if (2 != count($part)) {
         return false;
     }
     list($categoryName, $baseName) = $part;
     list($slug) = explode('.', $baseName);
     $result['slug'] = $slug;
     $post = $this->db->fetchRow($this->db->select()->from('table.contents')->where('slug = ?', $slug)->limit(1));
     if (!empty($post)) {
         if ('post' != $post['type']) {
             return false;
         } else {
             $result['cid'] = $post['cid'];
         }
     }
     /** 将目录作为分类缩略名处理 */
     $categorySlug = Typecho_Common::slugName($categoryName);
     $category = $this->db->fetchRow($this->db->select()->from('table.metas')->where('slug = ? OR name = ?', $categorySlug, $categoryName)->where('type = ?', 'category')->limit(1));
     /** 如果分类不存在则直接重建分类 */
     if (empty($category)) {
         $input['name'] = $categoryName;
         $input['slug'] = $categorySlug;
         $input['type'] = 'category';
         $input['description'] = $categoryName;
         $input['do'] = 'insert';
         $this->widget('Widget_Metas_Category_Edit', NULL, $input, false)->action();
         $result['category'] = array($this->widget('Widget_Notice')->getHighlightId());
     } else {
         $result['category'] = array($category['mid']);
     }
     $url = rtrim($repositoryPath, '/') . $fileName;
     $client = Typecho_Http_Client::get('Curl', 'Socket');
     if (false == $client) {
         return false;
     }
     $client->send($url);
     $result['text'] = '';
     $result['title'] = '';
     if (200 == $client->getResponseStatus() || 304 == $client->getResponseStatus()) {
         $response = trim($client->getResponseBody());
         list($title, $text) = explode("\n", $response, 2);
         $result['title'] = $title;
         $result['text'] = $text;
     }
     return $result;
 }
示例#21
0
function gravatar_url($mail, $size, $echo = true)
{
    $rating = Helper::options()->commentsAvatarRating;
    $Request = new Typecho_Request();
    $default = null;
    $url = Typecho_Common::gravatarUrl($mail, $size, $rating, $default, $Request->isSecure());
    if ($echo) {
        echo $url;
    } else {
        return $url;
    }
}
示例#22
0
 /**
  * 更新相册图片
  *
  * @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));
 }
示例#23
0
    /**
     * 插件实现方法
     * 
     * @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;
    }
示例#24
0
 /**
  * 配置外观
  *
  * @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;
 }
示例#25
0
 /**
  * 执行函数
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     $this->parameter->setDefault('pageSize=20');
     $select = $this->select();
     $this->_currentPage = $this->request->get('page', 1);
     /** 过滤标题 */
     if (NULL != ($keywords = $this->request->keywords)) {
         $select->where('name LIKE ? OR screenName LIKE ?', '%' . Typecho_Common::filterSearchQuery($keywords) . '%', '%' . Typecho_Common::filterSearchQuery($keywords) . '%');
     }
     $this->_countSql = clone $select;
     $select->order('table.users.uid', Typecho_Db::SORT_ASC)->page($this->_currentPage, $this->parameter->pageSize);
     $this->db->fetchAll($select, array($this, 'push'));
 }
示例#26
0
 /**
  * 添加新的链接转换
  * 
  */
 public function add()
 {
     $key = $this->request->key;
     $key = $key ? $key : Typecho_Common::randString(8);
     $target = $this->request->target;
     if ($target === "" || $target === "http://") {
         $this->widget('Widget_Notice')->set(_t('请输入目标链接。'), NULL, 'error');
     } elseif ($this->getTarget($key)) {
         $this->widget('Widget_Notice')->set(_t('该key已被使用,请更换key值。'), NULL, 'error');
     } else {
         $links = array('key' => $key, 'target' => $this->request->target, 'count' => 0);
         $insertId = $this->db->query($this->db->insert('table.golinks')->rows($links));
     }
 }
示例#27
0
 /**
  * 初始化函数
  *
  * @access public
  * @return void
  */
 public function action()
 {
     // protect
     $this->security->protect();
     /** 如果已经登录 */
     if ($this->user->hasLogin() || !$this->options->allowRegister) {
         /** 直接返回 */
         $this->response->redirect($this->options->index);
     }
     /** 初始化验证类 */
     $validator = new Typecho_Validate();
     $validator->addRule('name', 'required', _t('必须填写用户名称'));
     $validator->addRule('name', 'minLength', _t('用户名至少包含2个字符'), 2);
     $validator->addRule('name', 'maxLength', _t('用户名最多包含32个字符'), 32);
     $validator->addRule('name', 'xssCheck', _t('请不要在用户名中使用特殊字符'));
     $validator->addRule('name', array($this, 'nameExists'), _t('用户名已经存在'));
     $validator->addRule('mail', 'required', _t('必须填写电子邮箱'));
     $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在'));
     $validator->addRule('mail', 'email', _t('电子邮箱格式错误'));
     $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200);
     /** 如果请求中有password */
     if (array_key_exists('password', $_REQUEST)) {
         $validator->addRule('password', 'required', _t('必须填写密码'));
         $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6);
         $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18);
         $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password');
     }
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('name', 'password', 'mail', 'confirm'))) {
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         Typecho_Cookie::set('__typecho_remember_mail', $this->request->mail);
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error);
         $this->response->goBack();
     }
     $hasher = new PasswordHash(8, true);
     $generatedPassword = Typecho_Common::randString(7);
     $dataStruct = array('name' => $this->request->name, 'mail' => $this->request->mail, 'screenName' => $this->request->name, 'password' => $hasher->HashPassword($generatedPassword), 'created' => $this->options->gmtTime, 'group' => 'subscriber');
     $dataStruct = $this->pluginHandle()->register($dataStruct);
     $insertId = $this->insert($dataStruct);
     $this->db->fetchRow($this->select()->where('uid = ?', $insertId)->limit(1), array($this, 'push'));
     $this->pluginHandle()->finishRegister($this);
     $this->user->login($this->request->name, $generatedPassword);
     Typecho_Cookie::delete('__typecho_first_run');
     Typecho_Cookie::delete('__typecho_remember_name');
     Typecho_Cookie::delete('__typecho_remember_mail');
     $this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success');
     $this->response->redirect($this->options->adminUrl);
 }
示例#28
0
 public static function hasLogin()
 {
     $cookieUid = Typecho_Cookie::get('__typecho_uid');
     if (null !== $cookieUid) {
         $db = Typecho_Db::get();
         $user = $db->fetchRow($db->select()->from('table.users')->where('uid = ?', intval($cookieUid))->limit(1));
         $cookieAuthCode = Typecho_Cookie::get('__typecho_authCode');
         if ($user && Typecho_Common::hashValidate($user['authCode'], $cookieAuthCode)) {
             return true;
         }
         Typecho_Cookie::delete('__typecho_uid');
         Typecho_Cookie::delete('__typecho_authCode');
     }
     return false;
 }
 /**
  * 获取插件配置面板
  * 
  * @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);
 }
示例#30
0
function OutputArchives($db, $options)
{
    $select = $db->select('cid', 'title', 'slug', 'created', 'allowComment', 'commentsNum')->from('table.contents')->where('status = ?', 'publish')->where('type = ?', 'post');
    $rawposts = $db->fetchAll($select);
    $posts = array();
    // Loop through each post and sort it into a structured array
    foreach ($rawposts as $post) {
        /** 取出所有分类 */
        $categories = $isTypechoEX ? Cache_Plugin::meta_get($post['cid'], "category") : $db->fetchAll($db->select('slug')->from('table.metas')->join('table.relationships', 'table.metas.mid = table.relationships.mid')->where('table.relationships.cid = ?', $post['cid'])->where('table.metas.type = ?', 'category')->order('table.metas.order', Typecho_Db::SORT_ASC));
        /** 取出第一个分类作为slug条件 */
        $post['category'] = current(Typecho_Common::arrayFlatten($categories, 'slug'));
        $date = new Typecho_Date($post['created']);
        $post['year'] = $date->year;
        $post['month'] = $date->month;
        $post['day'] = $date->day;
        $type = 'post';
        //$p['type'];
        $routeExists = NULL != Typecho_Router::get($type);
        $permalink = $routeExists ? Typecho_Router::url($type, $post, $options->index) : '#';
        $post['permalink'] = $permalink;
        $posts[$post['year'] . '.' . $post['month']][] = $post;
    }
    $rawposts = null;
    // More memory cleanup
    // Sort the months based on $atts
    krsort($posts);
    // Sort the posts within each month based on $atts
    foreach ($posts as $key => $month) {
        $sorter = array();
        foreach ($month as $post) {
            $sorter[] = $post['created'];
        }
        array_multisort($sorter, SORT_DESC, $month);
        $posts[$key] = $month;
        unset($month);
    }
    // Generate the HTML
    $html = "";
    foreach ($posts as $yearmonth => $posts) {
        list($year, $month) = explode('.', $yearmonth);
        $html .= "<li><b><a href=\"" . Typecho_Router::url('archive_month', array('year' => $year, 'month' => $month), $options->index) . "\">" . $year . "年" . $month . "月</a></b> <span>(" . number_format(count($posts)) . " 篇文章)</span><ul>";
        foreach ($posts as $post) {
            $html .= "<li>" . $post['day'] . ": <a href=\"" . $post['permalink'] . "\">" . $post['title'] . "</a> <span>(" . number_format($post['commentsNum']) . ")</span></li>";
        }
        $html .= "</ul></li>";
    }
    return $html;
}