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; }
/** * 通用过滤器 * * @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; }
/** * 通用过滤器 * * @access public * @param array $value 需要过滤的行数据 * @return array */ public function filter(array $value) { //生成静态链接 $type = $value['type']; $routeExists = NULL != Typecho_Router::get($type); $tmpSlug = $value['slug']; $value['slug'] = urlencode($value['slug']); $value['permalink'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->index) : '#'; /** 生成聚合链接 */ /** 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 = $this->pluginHandle(__CLASS__)->filter($value, $this); return $value; }
/** * 准备数据 * @param $contents 文章内容 * @param $class 调用接口的类 * @throws Typecho_Plugin_Exception */ public static function send($contents, $class) { //如果文章属性为隐藏或滞后发布 if ('publish' != $contents['visibility'] || $contents['created'] > time()) { return; } //获取系统配置 $options = Helper::options(); //判断是否配置好API if (is_null($options->plugin('BaiduSubmit')->api)) { throw new Typecho_Plugin_Exception(_t('api未配置')); } //获取文章类型 $type = $contents['type']; //获取路由信息 $routeExists = NULL != Typecho_Router::get($type); if (!is_null($routeExists)) { $db = Typecho_Db::get(); $contents['cid'] = $class->cid; $contents['categories'] = $db->fetchAll($db->select()->from('table.metas')->join('table.relationships', 'table.relationships.mid = table.metas.mid')->where('table.relationships.cid = ?', $contents['cid'])->where('table.metas.type = ?', 'category')->order('table.metas.order', Typecho_Db::SORT_ASC)); $contents['category'] = urlencode(current(Typecho_Common::arrayFlatten($contents['categories'], 'slug'))); $contents['slug'] = urlencode($contents['slug']); $contents['date'] = new Typecho_Date($contents['created']); $contents['year'] = $contents['date']->year; $contents['month'] = $contents['date']->month; $contents['day'] = $contents['date']->day; } //生成永久连接 $path_info = $routeExists ? Typecho_Router::url($type, $contents) : '#'; $permalink = Typecho_Common::url($path_info, $options->index); //调用post方法 self::post($permalink); }
/** * 通用过滤器 * * @access public * @param array $value 需要过滤的行数据 * @return array */ public function filter(array $value) { //生成静态链接 $routeExists = NULL != Typecho_Router::get('author'); $value['permalink'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->index) : '#'; /** 生成聚合链接 */ /** RSS 2.0 */ $value['feedUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedUrl) : '#'; /** RSS 1.0 */ $value['feedRssUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedRssUrl) : '#'; /** ATOM 1.0 */ $value['feedAtomUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedAtomUrl) : '#'; // modified_by_jiangmuzi 2015.09.22 $avatar = Forum_Common::parseUserAvatar($value['uid']); $value = array_merge($value, $avatar); $value['ucenter'] = $this->options->someUrl('ucenter', array('u' => $value['name']), false); // end modified $value = $this->pluginHandle(__CLASS__)->filter($value, $this); return $value; }
/** * 通用过滤器 * * @access public * @param array $value 需要过滤的行数据 * @return array */ public function filter(array $value) { //生成静态链接 $routeExists = NULL != Typecho_Router::get('author'); $value['permalink'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->index) : '#'; /** 生成聚合链接 */ /** RSS 2.0 */ $value['feedUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedUrl) : '#'; /** RSS 1.0 */ $value['feedRssUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedRssUrl) : '#'; /** ATOM 1.0 */ $value['feedAtomUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedAtomUrl) : '#'; $value = $this->pluginHandle(__CLASS__)->filter($value, $this); return $value; }
<div class="typecho-option-tabs"> <ul class="typecho-option-tabs clearfix"> <li class="current"> <form action="<?php $options->index('/action/golinks?add'); ?> " method="post" > KEY:<input name="key" id="key" type="text" value="" /> 目标:<input name="target" id="target" type="text" value="http://" /> <input type="submit" class="btn-s primary" value="添加" /> </form> </li> <li class="right current"> <?php $ro = Typecho_Router::get('go'); ?> 自定义链接:<input id="links" name="links" value="<?php echo $ro['url']; ?> " type="text"> <button id="qlinks" type="button">修改</button> </li> </ul> </div> <div class="typecho-table-wrap"> <table class="typecho-list-table"> <colgroup> <col width="15%"/> <col width="25%"/> <col width="47%"/>
/** * Grab all posts and filter them into an array * */ public static function GetPosts() { $options = Typecho_Widget::widget('Widget_Options'); /** * 获取数据库实例化对象 * 用静态变量存储实例化的数据库对象,可以保证数据连接仅进行一次 */ $db = Typecho_Db::get(); $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 = $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 return $posts; }
/** * 编辑文章后更新缓存 * @param $contents * @param $class */ public static function post_update($contents, $class) { if ('publish' != $contents['visibility'] || $contents['created'] > time()) { return; } //获取系统配置 $options = Helper::options(); if (!$options->plugin('TpCache')->cache_driver) { return; } //获取文章类型 $type = $contents['type']; //获取路由信息 $routeExists = NULL != Typecho_Router::get($type); if (!is_null($routeExists)) { $db = Typecho_Db::get(); $contents['cid'] = $class->cid; $contents['categories'] = $db->fetchAll($db->select()->from('table.metas')->join('table.relationships', 'table.relationships.mid = table.metas.mid')->where('table.relationships.cid = ?', $contents['cid'])->where('table.metas.type = ?', 'category')->order('table.metas.order', Typecho_Db::SORT_ASC)); $contents['category'] = urlencode(current(Typecho_Common::arrayFlatten($contents['categories'], 'slug'))); $contents['slug'] = urlencode($contents['slug']); $contents['date'] = new Typecho_Date($contents['created']); $contents['year'] = $contents['date']->year; $contents['month'] = $contents['date']->month; $contents['day'] = $contents['date']->day; } //生成永久连接 $path_info = $routeExists ? Typecho_Router::url($type, $contents) : '#'; self::init(); if (self::needCache($path_info)) { self::delete(self::$path); } }
/** * 通用过滤器 * * @access public * @param array $value 需要过滤的行数据 * @return array */ public function filter(array $value) { //生成静态链接 $routeExists = NULL != Typecho_Router::get('author'); $value['permalink'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->index) : '#'; /** 生成聚合链接 */ /** RSS 2.0 */ $value['feedUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedUrl) : '#'; /** RSS 1.0 */ $value['feedRssUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedRssUrl) : '#'; /** ATOM 1.0 */ $value['feedAtomUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedAtomUrl) : '#'; // modified_by_jiangmuzi 2015.09.22 if (!empty($value['extend'])) { $value['extend'] = unserialize($value['extend']); } $value['ucenter'] = $this->options->someUrl('ucenter', array('u' => $value['name']), false); // end modified $value = $this->pluginHandle(__CLASS__)->filter($value, $this); return $value; }