/** * 构造函数,初始化组件 * * @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'); }
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; }
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; } }
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 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('收藏出错!'))); } }
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; }
/** * 构造函数,初始化组件 * * @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->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(); //$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 = 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)); } }
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 * @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 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; } }
/** * 插件实现方法 * * @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; } }
/** * 激活插件方法,如果激活失败,直接抛出异常 * * @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 . ' 创建成功, 插件已经成功激活!'; }
/** * 构造函数,初始化组件 * * @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; } }
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(); //暂停功能,完善再发 }
function rand_posts() { $num = 2; $db = Typecho_Db::get(); $rs = $db->fetchRow($db->select(['COUNT(cid)' => 'total'])->from('table.contents')->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', 'post')); $total = $rs['total']; srand((double) microtime() * 10000000); $ary = range(0, $total - 1); if ($num > $total) { $num = $total; } $rand = array_rand($ary, $num); $render = []; foreach ($rand as $index) { $result = $db->fetchRow($db->select()->from('table.contents')->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', 'post')->offset($index)->limit(1)); $render[] = ['title' => $result['title'], 'content' => mb_substr($result['text'], 0, 119, 'utf-8'), 'created' => date("Y-m-d", $result['created']), 'comments' => $result['commentsNum'], 'url' => '/' . $result['slug'] . '.html']; } return $render; }
public static function install() { $installDb = Typecho_Db::get(); $prefix = $installDb->getPrefix(); $oauthTable = $prefix . self::$tableName; try { $installDb->query("CREATE TABLE `{$oauthTable}` (\n `moid` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `plateform` varchar(45) NOT NULL DEFAULT 'sina',\n `uid` int(10) unsigned NOT NULL,\n `openid` varchar(80) NOT NULL,\n `bind_time` int(10) unsigned NOT NULL,\n `expires_in` int(10) unsigned DEFAULT NULL,\n `refresh_token` varchar(300) DEFAULT NULL,\n PRIMARY KEY (`moid`),\n KEY `uid` (`uid`),\n KEY `plateform` (`plateform`),\n KEY `openid` (`openid`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8"); return '表创建成功, 插件已经被激活!'; } catch (Typecho_Db_Exception $e) { $code = $e->getCode(); if ('Mysql' == $type && 1050 == $code) { $script = 'SELECT `moid` from `' . $oauthTable . '`'; $installDb->query($script, Typecho_Db::READ); return '数据表已存在,插件启用成功'; } else { throw new Typecho_Plugin_Exception('数据表' . $oauthTable . '建立失败,插件启用失败。错误号:' . $code); } } }
function img_postthumb($cid) { $db = Typecho_Db::get(); $rs = $db->fetchRow($db->select('table.contents.text')->from('table.contents')->where('table.contents.cid=?', $cid)->order('table.contents.cid', Typecho_Db::SORT_ASC)->limit(1)); preg_match_all("/\\<img.*?src\\=\"(.*?)\"[^>]*>/i", $rs['text'], $thumbUrl); //通过正则式获取图片地址 $img_src = $thumbUrl[1][0]; //将赋值给img_src $img_counter = count($thumbUrl[0]); //一个src地址的计数器 switch ($img_counter > 0) { case $allPics = 1: echo $img_src; //当找到一个src地址的时候,输出缩略图 break; default: echo ""; //没找到(默认情况下),不输出任何内容 } }