本文整理匯總了PHP中Typecho_Db類的典型用法代碼示例。如果您正苦於以下問題:PHP Typecho_Db類的具體用法?PHP Typecho_Db怎麽用?PHP Typecho_Db使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Typecho_Db類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
/**
* 初始化函數
*
* @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);
}
}
示例2: links
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;
}
示例3: SB_tagcloud
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>';
}
示例4: __construct
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
/* 獲取數據庫對象、配置及用戶 */
$this->_db = Typecho_Db::get();
$this->_options = Typecho_Widget::widget('Widget_Options');
}
示例5: info
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;
}
示例6: __construct
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;
}
}
示例7: action
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' => '你已經點讚過了!'));
}
示例8: favorite
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('收藏出錯!')));
}
}
示例9: __construct
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();
}
示例10: __construct
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();
}
示例11: __construct
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);
}
示例12: __construct
/**
* 構造函數,初始化組件
*
* @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');
}
示例13: __construct
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>";
}
示例14: action
/**
*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);
}
示例15: action
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);
}