/** * 初始化函数 * * @access public * @return void */ public function execute() { /** 设置参数默认值 */ $this->parameter->setDefault('format=Y-m&type=month&limit=0'); $resource = $this->db->query($this->db->select('created')->from('table.contents')->where('type = ?', 'post')->where('table.contents.status = ?', 'publish')->where('table.contents.created < ?', $this->options->gmtTime)->order('table.contents.created', Typecho_Db::SORT_DESC)); $offset = $this->options->timezone - $this->options->serverTimezone; $result = array(); while ($post = $this->db->fetchRow($resource)) { $timeStamp = $post['created'] + $offset; $date = date($this->parameter->format, $timeStamp); if (isset($result[$date])) { $result[$date]['count']++; } else { $result[$date]['year'] = date('Y', $timeStamp); $result[$date]['month'] = date('m', $timeStamp); $result[$date]['day'] = date('d', $timeStamp); $result[$date]['date'] = $date; $result[$date]['count'] = 1; } } if ($this->parameter->limit > 0) { $result = array_slice($result, 0, $this->parameter->limit); } foreach ($result as $row) { $row['permalink'] = Typecho_Router::url('archive_' . $this->parameter->type, $row, $this->widget('Widget_Options')->index); $this->push($row); } }
/** * 执行函数 * * @access public * @return void */ public function execute() { if ($this->hasLogin()) { $rows = $this->db->fetchAll($this->db->select()->from('table.options')->where('user = ?', $this->_user['uid'])); $this->push($this->_user); foreach ($rows as $row) { $this->options->__set($row['name'], $row['value']); } //更新最后活动时间 $this->db->query($this->db->update('table.users')->rows(array('activated' => $this->options->gmtTime))->where('uid = ?', $this->_user['uid'])); } }
function links($slug) { $db = Typecho_Db::get(); $Contents = Typecho_Widget::widget('Widget_Abstract_Contents'); $value = $db->fetchRow($db->select()->from('table.contents')->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', 'page')->where('table.contents.slug = ?', $slug)->where('table.contents.password IS NULL')->limit(1)); $value = $Contents->filter($value); if (0 === strpos($value['text'], '<!--markdown-->')) { $value['isMarkdown'] = 0; } else { $value['isMarkdown'] = 1; } if ($value['isMarkdown'] == 1) { $text = substr($value['text'], 15); $text = $Contents->markdown($text); } else { $text = $Contents->autoP($value['text']); } $search = '/<ul>(.*?)<\\/ul>/is'; preg_match_all($search, $text, $matches); $result = ''; foreach ($matches[1] as $v) { $result .= $v; } $result = str_replace('<li>', '', $result); $result = str_replace('</li>', '<br/>', $result); $result = rtrim($result, '<br/>'); echo $result; }
function SB_tagcloud($param) { $db = Typecho_Db::get(); $text = '<aside class="widget widget-simpletags clearfix"><h3 class="widget-title"><span>标签云</span></h3><div class="st-tag-cloud">'; $sql = $db->fetchAll($db->select()->from("table.metas")->where('type = ?', 'tag')->order('count', Typecho_Db::SORT_DESC)->limit(intval($param['max']) ? intval($param['max']) : 30)); if (!empty($sql)) { $largest = 22; $smallest = 8; $scale_min = 1; $scale_max = 10; $minout = max($scale_min, 0); $maxout = max($scale_max, $minout); $maxval = 0; $minval = $sql[0]['count']; foreach ($sql as $tag) { if ($tag['count'] > $maxval) { $maxval = $tag['count']; } if ($minval > $tag['count']) { $minval = $tag['count']; } } $scale = $maxval > $minval ? ($maxout - $minout) / ($maxval - $minval) : 0; $obj = Typecho_Widget::widget("Widget_Abstract_Metas"); foreach ($sql as $tag) { $tag = $obj->filter($tag); $scale_result = ceil(($tag['count'] - $minval) * $scale + $minout); $text .= "<a href=\"" . $tag['permalink'] . "\" title=\"" . $tag['count'] . " 个主题\" style=\"font-size:" . round(($scale_result - $scale_min) * ($largest - $smallest) / ($scale_max - $scale_min) + $smallest) . "px;color:" . get_color_by_scale(round(($scale_result - $scale_min) / ($scale_max - $scale_min) * 100) / 100, "#cccccc", "#666666") . "\">" . $tag['name'] . "</a>\n"; } } return $text . '</div></aside>'; }
public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); /* 获取数据库对象、配置及用户 */ $this->_db = Typecho_Db::get(); $this->_options = Typecho_Widget::widget('Widget_Options'); }
public static function info() { $options = Typecho_Widget::widget('Widget_Options'); $Ukagaka = $options->plugin('Ukagaka'); $wcc['notice'] = stripslashes($Ukagaka->notice); $db = Typecho_Db::get(); $select = $db->select()->from('table.options')->where('name = ?', 'Ukagaka_starttime'); $lifetime = $db->fetchAll($select); $lifetime = self::get_wcc_lifetime($lifetime[0]['value']); $name = Typecho_Widget::widget('Widget_Options')->title; $wcc['showlifetime'] = '我已经与主人 ' . $name . ' 一起生存了 <font color="red">' . $lifetime["day"] . '</font> 天 <font color="red">' . $lifetime["hours"] . '</font> 小时 <font color="red">' . $lifetime["minutes"] . '</font> 分钟 <font color="red">' . $lifetime["seconds"] . '</font> 秒的快乐时光啦~*^_^*'; $foods = explode("\r\n", $Ukagaka->foods); foreach ($foods as $key => $value) { $xx = explode("//", $value); $wcc['foods'][] = $xx[0]; $wcc['eatsay'][] = $xx[1]; } if ($Ukagaka->contact) { $contact = explode("\r\n", $Ukagaka->contact); foreach ($contact as $key => $value) { $xx = explode("//", $value); $wcc['ques'][] = $xx[0]; $wcc['ans'][] = $xx[1]; } } else { $wcc['contactapi'] = '1'; } $wcc = json_encode($wcc); echo $wcc; }
public function __construct() { $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->table = $this->prefix . 'access'; $this->config = Typecho_Widget::widget('Widget_Options')->plugin('Access'); $this->request = Typecho_Request::getInstance(); $this->pageSize = $this->config->pageSize; $this->isDrop = $this->config->isDrop; if ($this->pageSize == null || $this->isDrop == null) { throw new Typecho_Plugin_Exception('请先设置插件!'); } switch ($this->request->get('action')) { case 'logs': default: $this->action = 'logs'; $this->title = '访问日志'; $this->parseLogs(); break; case 'overview': $this->action = 'overview'; $this->title = '访问概览'; $this->parseOverview(); break; } }
public function action() { $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->options = Typecho_Widget::widget('Widget_Options'); $cid = $this->request->cid; if (!$cid) { $this->response->throwJson(array('status' => 0, 'msg' => '请选择喜欢的文章!')); } $likes = Typecho_Cookie::get('__post_likes'); if (empty($likes)) { $likes = array(); } else { $likes = explode(',', $likes); } if (!in_array($cid, $likes)) { $row = $this->db->fetchRow($this->db->select('likesNum')->from('table.contents')->where('cid = ?', $cid)->limit(1)); $this->db->query($this->db->update('table.contents')->rows(array('likesNum' => (int) $row['likesNum'] + 1))->where('cid = ?', $cid)); array_push($likes, $cid); $likes = implode(',', $likes); Typecho_Cookie::set('__post_likes', $likes); //记录查看cookie $this->response->throwJson(array('status' => 1, 'msg' => '成功点赞!')); } $this->response->throwJson(array('status' => 0, 'msg' => '你已经点赞过了!')); }
public function favorite() { $user = $this->widget('Widget_User'); if (!$user->hasLogin()) { $this->response->throwJson(array('status' => 0, 'msg' => _t('还未登录不能进行此操作!'))); } $favorites = $this->widget('Widget_Users_Favorites'); if (!empty($this->request->fid)) { $db = Typecho_Db::get(); $favorites->deleteFavorite($this->request->fid); $this->response->throwJson(array('status' => 1, 'msg' => _t('已取消收藏!'))); } //数据是否存在 if ($favorites->dataExists()) { $this->response->throwJson(array('status' => 0, 'msg' => _t('收藏的内容不存在!'))); } //是否已经收藏 if ($favorites->favoriteExists($favorites->parameter->type, $favorites->getSrcId())) { $this->response->throwJson(array('status' => 0, 'msg' => _t($favorites->getTitle() . '已收藏!'))); } $fid = $favorites->addFavorite(); if ($fid) { $this->response->throwJson(array('status' => 1, 'fid' => $fid, 'msg' => _t($favorites->getTitle() . '已成功收藏!'))); } else { $this->response->throwJson(array('status' => 0, 'msg' => _t('收藏出错!'))); } }
/** * 执行函数 * * @access public * @return void */ public function execute() { $this->db->fetchAll($this->db->select()->from('table.options')->where('user = 0'), array($this, 'push')); /** 支持皮肤变量重载 */ if (!empty($this->row['theme:' . $this->row['theme']])) { $themeOptions = NULL; /** 解析变量 */ if ($themeOptions = unserialize($this->row['theme:' . $this->row['theme']])) { /** 覆盖变量 */ $this->row = array_merge($this->row, $themeOptions); } } $this->stack[] =& $this->row; /** 初始化站点信息 */ $this->siteUrl = Typecho_Common::url(NULL, $this->siteUrl); $this->plugins = unserialize($this->plugins); /** 增加对SSL连接的支持 */ if ($this->request->isSecure() && 0 === strpos($this->siteUrl, 'http://')) { $this->siteUrl = substr_replace($this->siteUrl, 'https', 0, 4); } /** 自动初始化路由表 */ $this->routingTable = unserialize($this->routingTable); if (!isset($this->routingTable[0])) { /** 解析路由并缓存 */ $parser = new Typecho_Router_Parser($this->routingTable); $parsedRoutingTable = $parser->parse(); $this->routingTable = array_merge(array($parsedRoutingTable), $this->routingTable); $this->db->query($this->db->update('table.options')->rows(array('value' => serialize($this->routingTable)))->where('name = ?', 'routingTable')); } }
public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); $this->db = Typecho_Db::get(); $this->options = Helper::options(); //$this->pluginRootUrl = Typecho_Common::url('Api/', $this->options->pluginUrl); require_once 'Twig/Autoloader.php'; Twig_Autoloader::register(); }
public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); $this->_db = Typecho_Db::get(); $this->_dir = '.' . __TYPECHO_PLUGIN_DIR__ . '/CommentToMail/'; $this->_set = Helper::options()->plugin('CommentToMail'); require_once $this->_dir . 'class.phpmailer.php'; $this->mail = new PHPMailer(); }
public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); /** 初始化数据库 */ $this->db = Typecho_Db::get(); /** 初始化常用组件 */ $this->options = $this->widget('Widget_Options'); $this->_time = new Typecho_Date($this->options->gmtTime); }
/** * 构造函数,初始化组件 * * @access public * @param mixed $request request对象 * @param mixed $response response对象 * @param mixed $params 参数列表 * @return void */ public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); /** 初始化数据库 */ $this->db = Typecho_Db::get(); /** 初始化常用组件 */ $this->options = $this->widget('Widget_Options'); $this->user = $this->widget('Widget_User'); }
public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); $this->_db = Typecho_Db::get(); $this->_options = Helper::options()->plugin('WeChatHelper'); $this->_textTpl = "<xml>\n <ToUserName><![CDATA[%s]]></ToUserName>\n <FromUserName><![CDATA[%s]]></FromUserName>\n <CreateTime>%s</CreateTime>\n <MsgType><![CDATA[text]]></MsgType>\n <Content><![CDATA[%s]]></Content>\n <FuncFlag>0</FuncFlag>\n </xml>"; $this->_imageTpl = "<xml>\n <ToUserName><![CDATA[%s]]></ToUserName>\n <FromUserName><![CDATA[%s]]></FromUserName>\n <CreateTime>%s</CreateTime>\n <MsgType><![CDATA[news]]></MsgType>\n <ArticleCount>%s</ArticleCount>\n <Articles>%s</Articles>\n <FuncFlag>1</FuncFlag>\n </xml>"; $this->_itemTpl = "<item>\n <Title><![CDATA[%s]]></Title> \n <Description><![CDATA[%s]]></Description>\n <PicUrl><![CDATA[%s]]></PicUrl>\n <Url><![CDATA[%s]]></Url>\n </item>"; }
/** *Action入口 *@return redirect */ public function action() { $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->options = Typecho_Widget::widget('Widget_Options'); $this->on($this->request->is('do=clearAll'))->clearAll(); $this->on($this->request->is('do=deleteLog'))->deleteLog(); $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'javascript:history.back(-1);'; $this->response->redirect($referer); }
public function action() { $this->db = Typecho_Db::get(); $this->options = Typecho_Widget::widget('Widget_Options'); $this->on($this->request->is('do=insert'))->insertLink(); $this->on($this->request->is('do=update'))->updateLink(); $this->on($this->request->is('do=delete'))->deleteLink(); $this->on($this->request->is('do=sort'))->sortLink(); $this->response->redirect($this->options->adminUrl); }
public function optimize() { $db = Typecho_Db::get(); $config = $db->getConfig(); $tables = $db->fetchAll("SHOW TABLE STATUS FROM " . $config[0]->database); foreach ($tables as $row) { $result = $db->fetchAll('OPTIMIZE TABLE ' . $row['Name']); } $this->widget('Widget_Notice')->set(_t('数据库优化完成!'), 'success'); $this->response->goBack(); }
function topcategory($category) { $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $rs = $db->fetchRow($db->select()->from($prefix . 'metas')->where('slug = ?', $category)->limit(1)); if (isset($rs['parent']) && $rs['parent'] == 0) { return $rs['slug']; } elseif (isset($rs['parent'])) { $rs2 = $db->fetchRow($db->select()->from($prefix . 'metas')->where('mid = ?', $rs['parent'])->limit(1)); return $rs2['slug']; } }
public function action() { $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->options = Typecho_Widget::widget('Widget_Options'); $this->on($this->request->is('do=insert'))->insertLink(); $this->on($this->request->is('do=addhanson'))->addHanSonBlog(); $this->on($this->request->is('do=update'))->updateLink(); $this->on($this->request->is('do=delete'))->deleteLink(); $this->on($this->request->is('do=sort'))->sortLink(); $this->response->redirect($this->options->adminUrl); }
/** * 显示上一篇 * * @access public * @param string $default 如果没有上一篇, 显示的默认文字 * @return void */ function thePrev($widget, $word = '上一篇', $default = NULL) { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents')->where('table.contents.created < ?', $widget->created)->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', $widget->type)->where('table.contents.password IS NULL')->order('table.contents.created', Typecho_Db::SORT_DESC)->limit(1); $content = $db->fetchRow($sql); if ($content) { $content = $widget->filter($content); $link = '<a href="' . $content['permalink'] . '" id="article-nav-older" class="article-nav-link-wrap" title="' . $content['title'] . '">' . '<div class="article-nav-title">' . $content['title'] . '</div><strong class="article-nav-caption">></strong>' . '</a>'; echo $link; } else { echo $default; } }
public function init($option) { $this->db = Typecho_Db::get(); $prefix = $this->db->getPrefix(); $table_name = $prefix . 'cache'; $sql_detect = "SHOW TABLES LIKE '%" . $table_name . "%'"; if (count($this->db->fetchAll($sql_detect)) == 0) { $this->install_db(); } else { // 用访问触发缓存过期 $this->db->query($this->db->delete('table.cache')->where('time <= ?', time() - $this->expire)); } }
/** * 显示上一篇 * * @access public * @param string $default 如果没有下一篇,显示的默认文字 * @return void */ function thePrev($widget, $default = NULL) { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents')->where('table.contents.created < ?', $widget->created)->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', $widget->type)->where('table.contents.password IS NULL')->order('table.contents.created', Typecho_Db::SORT_DESC)->limit(1); $content = $db->fetchRow($sql); if ($content) { $content = $widget->filter($content); $link = '<a href="' . $content['permalink'] . '" title="' . $content['title'] . '">← 上一篇文章</a>'; echo $link; } else { echo $default; } }
public static function duoshuoInstall() { $installDb = Typecho_Db::get(); $scripts = file_get_contents('usr/plugins/Duoshuo/install.sql'); $scripts = str_replace(array('%charset%', 'typecho_'), array('utf8', $installDb->getPrefix()), $scripts); $scripts = explode(';', $scripts); foreach ($scripts as $script) { $script = trim($script); if ($script) { $installDb->query($script, Typecho_Db::WRITE); } } }
/** * 插件实现方法 * * @access public * @return void */ public static function webtotal() { $config = Typecho_Widget::widget('Widget_Options')->plugin('WebTotal'); $num = $config->total ? $config->total : '未设置'; if (is_numeric($num)) { $db = Typecho_Db::get(); $num++; $total = array('total' => $num); $db->query($db->update('table.options')->rows(array('value' => serialize($total)))->where('name = ?', 'plugin:WebTotal')); echo '<div style="text-align: center;">您是第<span style="color:red;"> ' . $num . ' </span> 位访客</div>'; } else { echo $num; } }
public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); $this->db = Typecho_Db::get(); $this->options = $this->widget('Widget_Options'); $this->bakpath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->bakdir . DIRECTORY_SEPARATOR; $baknum = intval(Typecho_Widget::widget('Widget_Options')->plugin('TEDbBak')->baknum); if ($baknum > 0) { $this->limit = $baknum; } if (!is_dir($this->bakpath)) { mkdir($this->bakpath); } }
/** * 显示上一个内容的标题链接 * * @access public * @param string $default 如果没有下一篇,显示的默认文字 * @return void */ function thePrev($widget, $default = "This is the oldest Post") { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents')->where('table.contents.created < ?', $widget->created)->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', $widget->type)->where('table.contents.password IS NULL')->order('table.contents.created', Typecho_Db::SORT_DESC)->limit(1); $content = $db->fetchRow($sql); if ($content) { $content = $widget->filter($content); $link = '<a style="cursor:default" class="older-posts" href="' . $content['permalink'] . '" title="' . $content['title'] . '">Old Post →</a>'; echo $link; } else { $link = '<a style="cursor:default" class="older-posts" href="#" >' . $default . '</a>'; echo $link; } }
public function action() { $this->widget('Widget_User')->pass('administrator'); $this->db = Typecho_Db::get(); $this->options = Typecho_Widget::widget('Widget_Options'); $this->fileload(); $this->plugin = Duoshuo_Typecho::getInstance(); $this->on($this->request->is('do=theme'))->theme(); $this->on($this->request->is('do=fireExport'))->fireExport(); $this->on($this->request->is('do=Duoshuo_sync_log'))->Duoshuo_sync_log(); $this->on($this->request->is('do=Duoshuo_reset'))->Duoshuo_reset(); $this->on($this->request->is('do=delete_comments'))->delete_comments(); $this->on($this->request->is('do=exportjson'))->exportjson(); $this->on($this->request->is('do=writecomments'))->writecomments(); //$this->on($this->request->is('do=setting'))->Setting(); //暂停功能,完善再发 }
/** * 构造函数,初始化组件 * * @access public * @param mixed $request request对象 * @param mixed $response response对象 * @param mixed $params 参数列表 */ public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); /** 初始化数据库 */ $this->db = Typecho_Db::get(); /** 初始化常用组件 */ $this->options = $this->widget('Widget_Options'); $this->user = $this->widget('Widget_User'); $this->security = $this->widget('Widget_Security'); $this->_themeDir = rtrim($this->options->themeFile($this->options->theme), '/') . '/'; /** 加载皮肤函数 */ $functionsFile = $this->_themeDir . 'functions.php'; if (!$this->_invokeFromOutside && file_exists($functionsFile)) { require_once $functionsFile; } }
/** * 激活插件方法,如果激活失败,直接抛出异常 * * @access public * @return void * @throws Typecho_Plugin_Exception */ public static function activate() { $db = Typecho_Db::get(); $golinks = $db->getPrefix() . 'golinks'; $adapter = $db->getAdapterName(); if ("Pdo_SQLite" === $adapter || "SQLite" === $adapter) { $db->query(" CREATE TABLE IF NOT EXISTS " . $golinks . " (\n id INTEGER PRIMARY KEY, \n key TEXT,\n target TEXT,\n count NUMERIC)"); } if ("Pdo_Mysql" === $adapter || "Mysql" === $adapter) { $db->query("CREATE TABLE IF NOT EXISTS " . $golinks . " (\n `id` int(8) NOT NULL AUTO_INCREMENT,\n `key` varchar(32) NOT NULL,\n `target` varchar(10000) NOT NULL,\n `count` int(8) DEFAULT '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"); } Helper::addAction('golinks', 'GoLinks_Action'); Helper::addRoute('go', '/go/[key]/', 'GoLinks_Action', 'golink'); Helper::addPanel(2, 'GoLinks/panel.php', '链接转换', '链接转换管理', 'administrator'); return '数据表 ' . $golinks . ' 创建成功, 插件已经成功激活!'; }