本文整理匯總了PHP中Typecho_Cookie::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP Typecho_Cookie::set方法的具體用法?PHP Typecho_Cookie::set怎麽用?PHP Typecho_Cookie::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Typecho_Cookie
的用法示例。
在下文中一共展示了Typecho_Cookie::set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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' => '你已經點讚過了!'));
}
示例2: setTheme
/**
* 插件實現方法
*
* @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);
}
示例3: set
/**
* 設定堆棧每一行的值
*
* @param string $value 值對應的鍵值
* @param string $type 提示類型
* @param string $typeFix 兼容老插件
* @return array
*/
public function set($value, $type = 'notice', $typeFix = 'notice')
{
$notice = is_array($value) ? array_values($value) : array($value);
if (empty($type) && $typeFix) {
$type = $typeFix;
}
Typecho_Cookie::set('__typecho_notice', json_encode($notice), $this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400, $this->widget('Widget_Options')->siteUrl);
Typecho_Cookie::set('__typecho_notice_type', $type, $this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400, $this->widget('Widget_Options')->siteUrl);
}
示例4: action
/**
* 初始化函數
*
* @access public
* @return void
*/
public function action()
{
// protect
$this->security->protect();
/** 如果已經登錄 */
if ($this->user->hasLogin()) {
/** 直接返回 */
$this->response->redirect($this->options->index);
}
/** 初始化驗證類 */
$validator = new Typecho_Validate();
$validator->addRule('name', 'required', _t('請輸入用戶名'));
$validator->addRule('password', 'required', _t('請輸入密碼'));
/** 截獲驗證異常 */
if ($error = $validator->run($this->request->from('name', 'password'))) {
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
/** 設置提示信息 */
$this->widget('Widget_Notice')->set($error);
$this->response->goBack();
}
/** 先驗證動態密碼 **/
$user = $this->db->fetchRow($this->select()->where('name = ?', $this->request->name)->limit(1));
if ($user['twoFactorAuthKey']) {
if ($this->request->twoFactAuth) {
if (!$this->widget('Widget_GoogleAuthenticator')->verifyCode($user['twoFactorAuthKey'], $this->request->twoFactAuth, 2)) {
$this->widget('Widget_Notice')->set(_t('動態密碼不正確'));
$this->response->goBack();
}
} else {
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
$this->response->redirect($this->options->adminUrl . 'login.php?requireTwoFactAuth=yes');
}
}
/** 開始驗證用戶 **/
$valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0);
/** 比對密碼 */
if (!$valid) {
/** 防止窮舉,休眠3秒 */
sleep(3);
$this->pluginHandle()->loginFail($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
$this->widget('Widget_Notice')->set(_t('用戶名或密碼無效'), 'error');
$this->response->goBack('?referer=' . urlencode($this->request->referer));
}
$this->pluginHandle()->loginSucceed($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
/** 跳轉驗證後地址 */
if (NULL != $this->request->referer) {
$this->response->redirect($this->request->referer);
} else {
if (!$this->user->pass('contributor', true)) {
/** 不允許普通用戶直接跳轉後台 */
$this->response->redirect($this->options->profileUrl);
} else {
$this->response->redirect($this->options->adminUrl);
}
}
}
示例5: comment
/**
* 評論處理函數
*
* @throws Typecho_Widget_Exception
* @throws Exception
* @throws Typecho_Exception
*/
private function comment()
{
// modified_by_jiangmuzi 2015.09.23
// 必須登錄後才可以回複
if (!$this->user->hasLogin()) {
$this->widget('Widget_Notice')->set(_t('請先<a href="%s">登錄</a>', $this->options->someUrl('login', null, false) . '?redir=' . $this->request->getRequestUrl()), NULL, 'success');
$this->response->goBack();
}
// end modified
// 使用安全模塊保護
$this->security->protect();
$comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved');
//檢驗格式
$validator = new Typecho_Validate();
$validator->addRule('text', 'required', _t('必須填寫評論內容'));
$comment['text'] = $this->request->text;
/** 記錄登錄用戶的id */
$comment['authorId'] = $this->user->uid;
if ($error = $validator->run($comment)) {
/** 記錄文字 */
Typecho_Cookie::set('__some_remember_text', $comment['text']);
throw new Typecho_Widget_Exception(implode("\n", $error));
}
/** 生成過濾器 */
try {
$comment = $this->pluginHandle()->comment($comment, $this->_content);
} catch (Typecho_Exception $e) {
Typecho_Cookie::set('__some_remember_text', $comment['text']);
throw $e;
}
// modified_by_jiangmuzi 2015.09.23
// 解析@數據
$atArr = $this->searchAt($comment);
// end modified
/** 添加評論 */
$commentId = $this->insert($comment);
Typecho_Cookie::delete('__some_remember_text');
$this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push'));
//更新最後評論人及時間
$this->db->query($this->db->update('table.contents')->rows(array('lastUid' => $this->authorId, 'lastComment' => $this->created))->where('cid = ?', $this->cid));
//提醒主題作者
if ($comment['authorId'] != $comment['ownerId']) {
$atArr[] = array('uid' => $comment['ownerId'], 'type' => 'comment');
}
if (!empty($atArr)) {
foreach ($atArr as $v) {
$this->widget('Widget_Users_Messages')->addMessage($v['uid'], $commentId, $v['type']);
}
}
//觸發評論積分規則
Widget_Common::credits('reply', null, $commentId);
/** 評論完成接口 */
$this->pluginHandle()->finishComment($this);
$this->response->goBack('#' . $this->theId);
}
示例6: action
/**
* 初始化函數
*
* @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);
}
示例7: action
/**
* 初始化函數
*
* @access public
* @return void
*/
public function action()
{
/** 如果已經登錄 */
if ($this->user->hasLogin()) {
/** 直接返回 */
$this->response->redirect($this->options->index);
}
/** 初始化驗證類 */
$validator = new Typecho_Validate();
$validator->addRule('name', 'required', _t('請輸入用戶名'));
$validator->addRule('password', 'required', _t('請輸入密碼'));
/** 截獲驗證異常 */
if ($error = $validator->run($this->request->from('name', 'password'))) {
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
/** 設置提示信息 */
$this->widget('Widget_Notice')->set($error);
$this->response->goBack();
}
/** 開始驗證用戶 **/
$valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0);
/** 比對密碼 */
if (!$valid) {
/** 防止窮舉,休眠3秒 */
sleep(3);
$this->pluginHandle()->loginFail($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
$this->widget('Widget_Notice')->set(_t('用戶名或密碼無效'), 'error');
$this->response->goBack('?referer=' . urlencode($this->request->referer));
}
$this->pluginHandle()->loginSucceed($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
/** 跳轉驗證後地址 */
if (NULL != $this->request->referer) {
$this->response->redirect($this->request->referer);
} else {
if (!$this->user->pass('contributor', true)) {
/** 不允許普通用戶直接跳轉後台 */
$this->response->redirect($this->options->siteUrl);
} else {
$this->response->redirect($this->options->adminUrl);
}
}
}
示例8: doLogin
protected function doLogin()
{
// protect
$this->security->protect();
/** 如果已經登錄 */
if ($this->user->hasLogin()) {
/** 直接返回 */
$this->response->redirect($this->options->index);
}
/** 初始化驗證類 */
$validator = new Typecho_Validate();
$validator->addRule('name', 'required', _t('請輸入用戶名'));
$validator->addRule('password', 'required', _t('請輸入密碼'));
/** 截獲驗證異常 */
if ($error = $validator->run($this->request->from('name', 'password'))) {
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
/** 設置提示信息 */
$this->widget('Widget_Notice')->set($error);
$this->response->goBack();
}
/** 開始驗證用戶 **/
$valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0);
/** 比對密碼 */
if (!$valid) {
/** 防止窮舉,休眠3秒 */
sleep(3);
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
$this->widget('Widget_Notice')->set(_t('用戶名或密碼無效'), 'error');
$this->response->goBack('?referer=' . urlencode($this->request->referer));
}
$this->widget('Widget_Notice')->set('已成功登錄!', 'notice');
//登錄積分
Forum_Common::credits('login');
/** 跳轉驗證後地址 */
$this->response->redirect($this->request->get('redir', $this->options->index));
}
示例9: like
protected function like()
{
$cid = $this->request->cid;
if (!$cid) {
$this->response->throwJson(array('status' => 0, 'msg' => '請選擇喜歡的文章!'));
}
$likes = Typecho_Cookie::get('__sis_pls');
if (empty($likes)) {
$likes = array();
} else {
$likes = explode(',', $likes);
}
if (!in_array($cid, $likes)) {
$db = Typecho_Db::get();
$row = $db->fetchRow($db->select('likesNum')->from('table.contents')->where('cid = ?', $cid)->limit(1));
$db->query($db->update('table.contents')->rows(array('likesNum' => (int) $row['likesNum'] + 1))->where('cid = ?', $cid));
array_push($likes, $cid);
$likes = implode(',', $likes);
Typecho_Cookie::set('__sis_pls', $likes);
//記錄查看cookie
$this->response->throwJson(array('status' => 1, 'msg' => '成功點讚!'));
}
$this->response->throwJson(array('status' => 0, 'msg' => '你已經點讚過了!'));
}
示例10: feed
/**
* 遠程請求代理
*
* @access public
* @return void
*/
public function feed()
{
$this->user->pass('subscriber');
$client = Typecho_Http_Client::get();
if ($client) {
$client->setHeader('User-Agent', $this->options->generator)->send('http://typecho.org/feed/');
/** 匹配內容體 */
$response = $client->getResponseBody();
preg_match_all("/<item>\\s*<title>([^>]*)<\\/title>\\s*<link>([^>]*)<\\/link>\\s*<guid>[^>]*<\\/guid>\\s*<pubDate>([^>]*)<\\/pubDate>/is", $response, $matches);
$data = array();
if ($matches) {
foreach ($matches[0] as $key => $val) {
$data[] = array('title' => $matches[1][$key], 'link' => $matches[2][$key], 'date' => Typecho_I18n::dateWord(strtotime($matches[3][$key]), $this->options->gmtTime + $this->options->timezone));
if ($key > 3) {
break;
}
}
}
if (!empty($data)) {
Typecho_Cookie::set('__typecho_feed', Typecho_Json::encode($data));
}
$this->response->throwJson($data);
return;
}
throw new Typecho_Widget_Exception(_t('禁止訪問'), 403);
}
示例11: comment
/**
* 評論處理函數
*
* @throws Typecho_Widget_Exception
* @throws Exception
* @throws Typecho_Exception
*/
private function comment()
{
// modified_by_jiangmuzi 2015.09.23
// 必須登錄後才可以回複
if (!$this->user->hasLogin()) {
$this->widget('Widget_Notice')->set(_t('請先<a href="%s">登錄</a>', $this->options->someUrl('login', null, false) . '?redir=' . $this->request->getRequestUrl()), NULL, 'success');
$this->response->goBack();
}
// end modified
// 使用安全模塊保護
$this->security->protect();
$comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved');
/** 判斷父節點 */
/*
if ($parentId = $this->request->filter('int')->get('parent')) {
if ($this->options->commentsThreaded && ($parent = $this->db->fetchRow($this->db->select('coid', 'cid')->from('table.comments')
->where('coid = ?', $parentId))) && $this->_content->cid == $parent['cid']) {
$comment['parent'] = $parentId;
} else {
throw new Typecho_Widget_Exception(_t('父級評論不存在'));
}
}*/
//檢驗格式
$validator = new Typecho_Validate();
$validator->addRule('text', 'required', _t('必須填寫評論內容'));
$comment['text'] = $this->request->text;
/** 記錄登錄用戶的id */
$comment['authorId'] = $this->user->uid;
if ($error = $validator->run($comment)) {
/** 記錄文字 */
Typecho_Cookie::set('__some_remember_text', $comment['text']);
throw new Typecho_Widget_Exception(implode("\n", $error));
}
/** 生成過濾器 */
try {
$comment = $this->pluginHandle()->comment($comment, $this->_content);
} catch (Typecho_Exception $e) {
Typecho_Cookie::set('__some_remember_text', $comment['text']);
throw $e;
}
// modified_by_jiangmuzi 2015.09.23
// 解析@數據
$search = $replace = $atMsg = array();
$pattern = "/@([^@^\\s^:]{1,})([\\s\\:\\,\\;]{0,1})/";
preg_match_all($pattern, $comment['text'], $matches);
if (!empty($matches[1])) {
$matches[1] = array_unique($matches[1]);
foreach ($matches[1] as $name) {
if (empty($name)) {
continue;
}
$atUser = $this->widget('Widget_Users_Query@name_' . $name, array('name' => $name));
if (!$atUser->have()) {
continue;
}
$search[] = '@' . $name;
$replace[] = '<a href="' . $atUser->ucenter . '" target="_blank">@' . $name . '</a>';
//提醒at用戶
if ($comment['authorId'] != $atUser->uid && $atUser->uid != $comment['ownerId']) {
$atMsg[] = array('uid' => $atUser->uid, 'type' => 'at');
}
}
if (!empty($search)) {
$comment['text'] = str_replace(@$search, @$replace, $comment['text']);
}
}
// end modified
/** 添加評論 */
$commentId = $this->insert($comment);
Typecho_Cookie::delete('__some_remember_text');
$this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push'));
//更新最後評論人及時間
$this->db->query($this->db->update('table.contents')->rows(array('lastUid' => $this->authorId, 'lastComment' => $this->created))->where('cid = ?', $this->cid));
//提醒主題作者
if ($comment['authorId'] != $comment['ownerId']) {
$atMsg[] = array('uid' => $comment['ownerId'], 'type' => 'comment');
}
if (!empty($atMsg)) {
foreach ($atMsg as $v) {
$this->widget('Widget_Users_Messages')->addMessage($v['uid'], $commentId, $v['type']);
}
}
//觸發評論積分規則
Widget_Common::credits('reply');
/** 評論完成接口 */
$this->pluginHandle()->finishComment($this);
$this->response->goBack('#' . $this->theId);
}
示例12: singleHandle
/**
* 獨立頁處理
*
* @access private
* @param Typecho_Db_Query $select 查詢對象
* @param boolean $hasPushed 是否已經壓入隊列
* @return void
* @throws Typecho_Widget_Exception
*/
private function singleHandle(Typecho_Db_Query $select, &$hasPushed)
{
if ('comment_page' == $this->parameter->type) {
$params = array();
$matched = Typecho_Router::match($this->request->permalink);
if ($matched && $matched instanceof Widget_Archive && $matched->is('single')) {
$this->import($matched);
$hasPushed = true;
return;
}
}
/** 將這兩個設置提前是為了保證在調用query的plugin時可以在插件中使用is判斷初步歸檔類型 */
/** 如果需要更細判斷,則可以使用singleHandle來實現 */
$this->_archiveSingle = true;
/** 默認歸檔類型 */
$this->_archiveType = 'single';
/** 匹配類型 */
if ('single' != $this->parameter->type) {
$select->where('table.contents.type = ?', $this->parameter->type);
}
/** 如果是單篇文章或獨立頁麵 */
if (isset($this->request->cid)) {
$select->where('table.contents.cid = ?', $this->request->filter('int')->cid);
}
/** 匹配縮略名 */
if (isset($this->request->slug)) {
$select->where('table.contents.slug = ?', $this->request->slug);
}
/** 匹配時間 */
if (isset($this->request->year)) {
$year = $this->request->filter('int')->year;
$fromMonth = 1;
$toMonth = 12;
$fromDay = 1;
$toDay = 31;
if (isset($this->request->month)) {
$fromMonth = $this->request->filter('int')->month;
$toMonth = $fromMonth;
$fromDay = 1;
$toDay = date('t', mktime(0, 0, 0, $toMonth, 1, $year));
if (isset($this->request->day)) {
$fromDay = $this->request->filter('int')->day;
$toDay = $fromDay;
}
}
/** 獲取起始GMT時間的unix時間戳 */
$from = mktime(0, 0, 0, $fromMonth, $fromDay, $year) - $this->options->timezone + $this->options->serverTimezone;
$to = mktime(23, 59, 59, $toMonth, $toDay, $year) - $this->options->timezone + $this->options->serverTimezone;
$select->where('table.contents.created > ? AND table.contents.created < ?', $from, $to);
}
/** 保存密碼至cookie */
if ($this->request->isPost() && isset($this->request->protectPassword)) {
$this->security->protect();
Typecho_Cookie::set('protectPassword', $this->request->protectPassword, 0);
}
/** 匹配類型 */
$select->limit(1);
$this->query($select);
if (!$this->have() || isset($this->request->category) && $this->category != $this->request->category || isset($this->request->directory) && $this->request->directory != implode('/', $this->directory)) {
if (!$this->_invokeFromOutside) {
/** 對沒有索引情況下的判斷 */
throw new Typecho_Widget_Exception(_t('請求的地址不存在'), 404);
} else {
$hasPushed = true;
return;
}
}
/** 設置模板 */
if ($this->template) {
/** 應用自定義模板 */
$this->_themeFile = $this->template;
}
/** 設置頭部feed */
/** RSS 2.0 */
//對自定義首頁使用全局變量
if (!$this->_makeSinglePageAsFrontPage) {
$this->_feedUrl = $this->feedUrl;
/** RSS 1.0 */
$this->_feedRssUrl = $this->feedRssUrl;
/** ATOM 1.0 */
$this->_feedAtomUrl = $this->feedAtomUrl;
/** 設置標題 */
$this->_archiveTitle = $this->title;
/** 設置關鍵詞 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));
/** 設置描述 */
$this->_description = $this->description;
}
/** 設置歸檔類型 */
$this->_archiveType = $this->type;
/** 設置歸檔縮略名 */
//.........這裏部分代碼省略.........
示例13: execute
/**
* 執行函數
*
* @access public
* @return void
*/
public function execute()
{
$select = $this->select();
$this->parameter->setDefault('pageSize=20');
$this->_currentPage = $this->request->get('page', 1);
/** 過濾標題 */
if (NULL != ($keywords = $this->request->filter('search')->keywords)) {
$select->where('table.comments.text LIKE ?', '%' . $keywords . '%');
}
/** 如果具有貢獻者以上權限,可以查看所有評論,反之隻能查看自己的評論 */
if (!$this->user->pass('editor', true)) {
$select->where('table.comments.ownerId = ?', $this->user->uid);
} else {
if (!isset($this->request->cid)) {
if ('on' == $this->request->__some_all_comments) {
Typecho_Cookie::set('__some_all_comments', 'on');
} else {
if ('off' == $this->request->__some_all_comments) {
Typecho_Cookie::set('__some_all_comments', 'off');
}
if ('on' != Typecho_Cookie::get('__some_all_comments')) {
$select->where('table.comments.ownerId = ?', $this->user->uid);
}
}
}
}
if (in_array($this->request->status, array('approved', 'waiting', 'spam'))) {
$select->where('table.comments.status = ?', $this->request->status);
} else {
if ('hold' == $this->request->status) {
$select->where('table.comments.status <> ?', 'approved');
} else {
$select->where('table.comments.status = ?', 'approved');
}
}
//增加按文章歸檔功能
if (isset($this->request->cid)) {
$select->where('table.comments.cid = ?', $this->request->filter('int')->cid);
}
$this->_countSql = clone $select;
$select->order('table.comments.coid', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize);
$this->db->fetchAll($select, array($this, 'push'));
}
示例14: list
Typecho_Widget::widget('Widget_User')->to($user);
Typecho_Widget::widget('Widget_Security')->to($security);
Typecho_Widget::widget('Widget_Menu')->to($menu);
/** 初始化上下文 */
$request = $options->request;
$response = $options->response;
/** 檢測是否是第一次登錄 */
$currentMenu = $menu->getCurrentMenu();
list($prefixVersion, $suffixVersion) = explode('/', $options->version);
$params = parse_url($currentMenu[2]);
$adminFile = basename($params['path']);
if (!$user->logged && !Typecho_Cookie::get('__some_first_run') && !empty($currentMenu)) {
if ('welcome.php' != $adminFile) {
$response->redirect(Typecho_Common::url('welcome.php', $options->adminUrl));
} else {
Typecho_Cookie::set('__some_first_run', 1);
}
} else {
/** 檢測版本是否升級 */
if ($user->pass('administrator', true) && !empty($currentMenu)) {
$mustUpgrade = !defined('Typecho_Common::VERSION') || version_compare(str_replace('/', '.', Typecho_Common::VERSION), str_replace('/', '.', $options->version), '>');
if ($mustUpgrade && 'upgrade.php' != $adminFile) {
$response->redirect(Typecho_Common::url('upgrade.php', $options->adminUrl));
} else {
if (!$mustUpgrade && 'upgrade.php' == $adminFile) {
$response->redirect($options->adminUrl);
} else {
if (!$mustUpgrade && 'welcome.php' == $adminFile && $user->logged) {
$response->redirect($options->adminUrl);
}
}
示例15: viewCounter
/**
* 增加瀏覽量
* @params Widget_Archive $archive
* @return void
*/
public static function viewCounter($archive)
{
if ($archive->is('single')) {
$cid = $archive->cid;
$views = Typecho_Cookie::get('__post_views');
if (empty($views)) {
$views = array();
} else {
$views = explode(',', $views);
}
if (!in_array($cid, $views)) {
$db = Typecho_Db::get();
$db->query($db->update('table.contents')->rows(array('viewsNum' => (int) $archive->viewsNum + 1))->where('cid = ?', $cid));
array_push($views, $cid);
$views = implode(',', $views);
Typecho_Cookie::set('__post_views', $views);
//記錄查看cookie
}
}
}