本文整理汇总了PHP中user::logged方法的典型用法代码示例。如果您正苦于以下问题:PHP user::logged方法的具体用法?PHP user::logged怎么用?PHP user::logged使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user
的用法示例。
在下文中一共展示了user::logged方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_delete
public function action_delete()
{
if (!user::logged('admin')) {
ajax::error(__('You must be logged in to delete content'));
}
if ($_POST) {
$delete = arr::get($_POST, 'delete', false);
if ($delete) {
try {
if (is_array($delete)) {
foreach ($delete as $id) {
$content = ORM::factory('Content', $id);
if ($content->loaded()) {
$content->delete();
}
}
} else {
$content = ORM::factory('Content', $delete);
if ($content->loaded()) {
$content->delete();
}
}
ajax::success(__('The content has been deleted'));
} catch (exception $e) {
ajax::error(__('An error occurred and the content couldn\'t be deleted: :errormessage', array(':errormessage' => $e->getMessage())));
}
}
ajax::error(__('No data recieved'));
}
}
示例2: action_twittercallback
public function action_twittercallback()
{
if (arr::get($_GET, 'denied', false)) {
notes::error('Seems like you didn\'t want to log in with Twitter anyway. Feel free to try again if it was a mistake!');
site::redirect();
}
$token = arr::get($_GET, 'oauth_token', false);
$verifier = arr::get($_GET, 'oauth_verifier', false);
if (!$token || !$verifier) {
notes::error('Something went wrong in the process, and we didn\'t get the expected data back from Twitter. Please try again');
site::redirect();
}
$connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret'), Session::instance()->get_once('twitter_oauth_token'), Session::instance()->get_once('twitter_oauth_token_secret'));
$token = $connection->getAccessToken($verifier);
$oauth_token = arr::get($token, 'oauth_token', '');
$oauth_token_secret = arr::get($token, 'oauth_token_secret', '');
$user_id = arr::get($token, 'user_id', '');
$screen_name = arr::get($token, 'screen_name', '');
$oauth = ORM::factory('Oauth')->where('type', '=', 'twitter')->where('token', '=', $oauth_token)->find();
if ($oauth->loaded()) {
try {
$user = $oauth->user;
user::force_login($user);
} catch (exception $e) {
if ($user->loaded()) {
if (user::logged()) {
// Random error, but user got logged in. We don't care, YOLO!
} else {
notes::error('Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.');
Kohana::$log->add(Log::ERROR, '1. Couldnt log user in: ' . $e->getMessage());
}
}
}
site::redirect('write');
} else {
try {
$user = ORM::factory('User');
$user->username = $screen_name;
$user->validation_required(false)->save();
$user->add_role('login');
$oauth = ORM::factory('Oauth');
$oauth->user_id = $user->id;
$oauth->type = 'twitter';
$oauth->token = $oauth_token;
$oauth->token_secret = $oauth_token_secret;
$oauth->service_id = $user_id;
$oauth->screen_name = $screen_name;
$oauth->save();
user::force_login($user);
} catch (exception $e) {
Kohana::$log->add(Log::ERROR, '2. Couldnt create user: ' . $e->getMessage());
notes::error('Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.');
}
site::redirect('/write');
}
}
示例3: action_write
public function action_write()
{
$errors = false;
$page = false;
if (user::logged()) {
$page = $this->request->param('page');
if ($_POST && strlen(arr::get($_POST, 'content', '')) > 0) {
$content = arr::get($_POST, 'content', '');
if ($page->type == 'page') {
$raw = $page->rawcontent();
if ($raw != "") {
$content = $raw . "\n" . $content;
}
} else {
if ($page->type == 'autosave') {
$page->type = 'page';
}
}
try {
$page->wordcount = site::count_words($content);
$page->content = $content;
if ($page->wordcount >= 750 && !(bool) $page->counted) {
user::update_stats($page);
$page->counted = 1;
}
$page->duration = $page->duration + (time() - arr::get($_POST, 'start', 999));
$page->update();
$oldsaves = ORM::factory('Page')->where('type', '=', 'autosave')->where('user_id', '=', user::get()->id)->find_all();
if ((bool) $oldsaves->count()) {
foreach ($oldsaves as $old) {
$old->delete();
}
}
achievement::check_all(user::get());
notes::success('Your page has been saved!');
//site::redirect('write/'.$page->day);
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
}
}
} else {
if ($_POST) {
notes::error('You must be logged in to save your page. Please log in and submit again.');
}
}
$this->bind('errors', $errors);
$this->bind('page', $page);
$this->template->daystamp = $this->request->param('daystamp');
$this->template->page = $page;
seo::instance()->title("Write Your Morning Pages");
seo::instance()->description("Morning Pages is about writing three pages of stream of consciousness thought every day. Become a better person by using MorninPages.net");
}
示例4: action_getautosave
public function action_getautosave()
{
if (!user::logged()) {
ajax::error('You must be logged in');
}
$user = user::get();
$autosave = ORM::factory('Page')->where('user_id', '=', $user->id)->where('type', '=', 'autosave')->find();
$content = '';
if ($autosave->loaded() && $autosave->content != '') {
$content = $autosave->decode($autosave->content);
$autosave->delete();
}
ajax::success('', array('content' => $content, 'md5' => md5($content)));
}
示例5: require_login
public function require_login($msg = true, $redirect = false)
{
if ($msg === true) {
$msg = 'You must be logged in to see this page';
}
if (!user::logged()) {
if ($msg) {
notes::error($msg);
}
if ($redirect) {
site::redirect($redirect);
} else {
user::redirect('login');
}
}
}
示例6: update_stats
public static function update_stats($page)
{
if (!user::logged()) {
return;
}
$user = self::get();
$yesterdayslug = site::day_slug(strtotime('-1 day', $user->timestamp()));
$yesterday = ORM::factory('Page')->where('user_id', '=', $user->id)->where('day', '=', $yesterdayslug)->where('type', '=', 'page')->find();
if ($yesterday->loaded()) {
$user->current_streak += 1;
if ($user->doing_challenge()) {
$challenge = $user->challenge;
$challenge->progress += 1;
if ($challenge->progress >= 30) {
if ($user->option('completedchallenge') == 0) {
notes::success('You have completed the 30 day challenge and have been added to our ' . HTML::anchor('challenge/wall-of-fame', 'wall of fame') . '! Congratulations!');
$options = $user->option;
$options->completedchallenge = $user->timestamp();
$options->save();
} else {
notes::success('You have completed the 30 day challenge! Congratulations!');
}
user::award_points(100, 'Completed the 30 day challenge! (+100 points)', $user);
$challenge->delete();
} else {
$challenge->save();
}
}
if ($user->current_streak > $user->longest_streak) {
$user->longest_streak = $user->current_streak;
}
} else {
$user->current_streak = 1;
if ($user->doing_challenge()) {
$challenge = $user->challenge;
$challenge->progress = 1;
$challenge->save();
}
}
$user->all_time_words += $page->wordcount;
if ($page->wordcount > $user->most_words) {
notes::success('You have written more today than you ever have before! Good job!');
$user->most_words = $page->wordcount;
}
$user->save();
}
示例7: before
public function before()
{
if (!user::logged('admin') && $this->request->action() !== 'media') {
site::redirect();
}
if ($this->request->action() === 'media' || $this->request->action() === 'uploads') {
// Do not template media files
$this->auto_render = FALSE;
} else {
parent::before();
$this->template->controller = str_replace('cms_', '', $this->request->controller());
$this->template->action = $this->request->action();
$file = $this->template->controller . '/' . $this->template->action;
$file = str_replace('_', '/', $file);
if (file_exists(Kohana::find_file('views', $file))) {
$this->template->view = View::factory($file);
}
}
}
示例8: save_update_current
public static function save_update_current()
{
if (true || !user::logged('admin')) {
$session = Session::instance();
$visitor = ORM::factory('Visitor', $session->get('active_visitor'));
$base = request::detect_uri();
$queries = isset($_GET) && !empty($_GET) ? '?' . http_build_query($_GET) : '';
$uri = request::detect_uri() . $queries;
//substr($base, 1, strlen($base))
if ($visitor->loaded() && $uri == $visitor->page) {
// This is just a reload of the current page.
return;
}
if (!$visitor->loaded()) {
$numvisits = cookie::get('numvisits');
if (!$numvisits) {
$numvisits = 0;
}
cookie::set('numvisits', $numvisits + 1);
$visitor->numvisits = $numvisits + 1;
$visitor->start = time();
$visitor->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$visitor->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$visitor->geolocation = 'todo';
}
if (empty($visitor->client)) {
$visitor->client = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
$visitor->page = $uri;
if (user::logged()) {
$visitor->user_id = user::get()->id;
}
$history = json_decode($visitor->history);
if (!is_array($history)) {
$history = array();
}
$history[] = $uri;
$visitor->history = json_encode($history);
$visitor->time = time();
$visitor->save();
$session->set('active_visitor', $visitor->id);
}
}
示例9: action_info
public function action_info()
{
maintenance::delete_inactive_visitors();
$messages = 0;
if (user::logged()) {
$user = user::get();
$messages += $user->messages->where('read', '=', '0')->count_all();
$roles = $user->roles->find_all();
$roleids = array();
if ((bool) $roles->count()) {
foreach ($roles as $role) {
$roleids[] = $role->id;
}
}
if ((bool) count($roleids)) {
$messages += ORM::factory('Message')->where('role_id', 'in', $roleids)->where('read', '=', '0')->where('user_id', '!=', $user->id)->count_all();
}
}
ajax::success('', array('current_visitors' => $visitors = ORM::factory('Visitor')->count_all(), 'unread_messages' => $messages));
}
示例10: action_takechallenge
public function action_takechallenge()
{
if (!user::logged()) {
ajax::error('You must be logged in to sign up for the challenge!');
}
$user = user::get();
if ($user->doing_challenge()) {
ajax::error('You are already doing the challenge! Complete it first, then sign up again.');
}
$challenge = ORM::factory('User_Challenge');
$challenge->user_id = $user->id;
$challenge->start = $user->timestamp();
$challenge->progress = 0;
if ($user->wrote_today()) {
$challenge->progress = 1;
}
$challenge->save();
$user->add_event('Signed up for the 30 day challenge!');
ajax::success('Awesome! You have signed up for the challenge! Good luck!', array('progress' => $challenge->progress));
}
示例11: action_xml
public function action_xml()
{
if (!user::logged()) {
ajax::error('You must be logged in to use this feature');
}
$user = user::get();
$pages = $user->pages->where('type', '=', 'page')->find_all();
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<channel>';
$namelen = strlen($user->username);
$possessive = $user->username . "'s";
if (substr($user->username, $namelen - 1, $namelen) == 's') {
$possessive = $user->username . "'";
}
$xml .= '<title>' . $possessive . ' morning pages</title>';
$xml .= '<language>en-US</language>';
$xml .= '<author>' . $user->username . '</author>';
$xml .= '<pages>';
if ((bool) $pages->count()) {
foreach ($pages as $page) {
$xml .= '<page>';
$xml .= '<published>';
$xml .= '<date>' . $page->daystamp() . '</date>';
$xml .= '<timestamp>' . $page->created . '</timestamp>';
$xml .= '</published>';
$xml .= '<content><![CDATA[' . $page->rawcontent() . ']]></content>';
$xml .= '<wordcount>' . $page->wordcount . '</wordcount>';
$xml .= '</page>';
}
}
$xml .= '</pages>';
$xml .= '</channel>';
$this->response->headers('Content-Type', 'text/xml');
$this->response->body($xml);
$this->response->send_file(true, 'pages.xml');
}
示例12: action_savesetting
public function action_savesetting()
{
if (!user::logged()) {
ajax::error('You must be logged in');
}
$user = user::get();
$option = $user->option;
$setting = arr::get($_POST, 'setting', false);
$value = arr::get($_POST, 'value', false);
if (!$setting || $value === false) {
ajax::error('Something wen\'t wrong and your setting couldn\'t be saved. I received no data!');
}
$update_timestamp = false;
switch ($setting) {
case 'reminder':
$option->reminder = $value;
$update_timestamp = true;
break;
case 'reminder_hour':
$option->reminder_hour = $value;
$update_timestamp = true;
break;
case 'reminder_minute':
$option->reminder_minute = $value;
$update_timestamp = true;
break;
case 'reminder_meridiem':
$option->reminder_meridiem = $value;
$update_timestamp = true;
break;
case 'timezone_id':
$option->timezone_id = $value;
$update_timestamp = true;
break;
case 'privacymode':
$option->privacymode = $value;
break;
case 'privacymode_minutes':
$option->privacymode_minutes = $value;
break;
case 'hemingwaymode':
$option->hemingwaymode = $value;
break;
case 'public':
$option->public = $value;
break;
case 'rtl':
$option->rtl = $value;
break;
case 'language':
$option->language = (int) $value;
break;
default:
ajax::error('Something wen\'t wrong and your setting couldn\'t be saved. I received no data!');
break;
}
try {
if ($update_timestamp) {
$option->next_reminder = $user->get_next_reminder($user);
}
$option->save();
ajax::success('Saved');
} catch (ORM_Validation_Exception $e) {
ajax::error('An error occurred and your setting couldn\'t be saved.', array('errors' => $e->errors()));
}
}
示例13: action_talk
public function action_talk()
{
$tag = $this->request->param('tag');
$talk = $this->request->param('talk');
if (user::logged()) {
// Iterate views
if ($talk->user_id != user::get()->id) {
$talk->views = $talk->views + 1;
try {
$talk->save();
} catch (ORM_Validation_Exception $e) {
//var_dump($e->errors());
}
}
// Set when the user last saw the topic
$user = user::get();
$viewed = $user->talkviews->where('talk_id', '=', $talk->id)->find();
if (!$viewed->loaded()) {
$viewed->user_id = $user->id;
$viewed->talk_id = $talk->id;
}
$viewed->last = time();
$viewed->save();
}
$replies = $talk->replies->where('op', '!=', 1);
$counter = $talk->replies->where('op', '!=', 1);
$limit = Kohana::$config->load('talk')->get('pagination_limit');
$numreplies = $counter->count_all();
$numpages = ceil($numreplies / $limit);
$page = (int) arr::get($_GET, 'page', 0);
if ($_POST) {
$this->require_login();
$reply = ORM::factory('Talkreply');
$reply->values($_POST);
$reply->user_id = user::get()->id;
$reply->talk_id = $talk->id;
try {
$reply->save();
$page = $numpages;
$talk->last_reply = time();
$talk->save();
$subscriptions = $talk->subscriptions->find_all();
if ((bool) $subscriptions->count()) {
foreach ($subscriptions as $subscription) {
if ($subscription->user_id != $reply->user_id) {
mail::create('talkreplyposted')->to($subscription->user->email)->tokenize(array('username' => $subscription->user->username, 'sendername' => $reply->user->username, 'title' => $talk->title, 'reply' => $reply->content, 'link' => HTML::anchor(URL::site($talk->url() . '?page=' . $page . '#comment-' . $reply->id, 'http'), $talk->title)))->send();
}
}
}
$vote = ORM::factory('User_Talkvote');
$vote->type = 'talkreply';
$vote->user_id = user::get()->id;
$vote->object_id = $reply->id;
$vote->save();
notes::success('Your reply has been posted.');
site::redirect($talk->url() . '?page=' . $page . '#comment-' . $reply->id);
} catch (ORM_Validation_Exception $e) {
notes::error('Whoops! Your submission contained errors. Please review it and submit again');
$errors = $e->errors();
}
}
if ($page < 1) {
$page = 1;
}
if ($page > $numpages) {
$page = $numpages;
}
$replies = $replies->limit($limit);
if ($page - 1 > 0) {
$replies = $replies->offset($limit * ($page - 1));
}
$replies = $replies->find_all();
$this->bind('tag', $tag);
$this->bind('talk', $talk);
$this->bind('replies', $replies);
$this->bind('tags', ORM::factory('Talktag')->find_all());
$this->bind('numpages', $numpages);
$this->bind('currentpage', $page);
seo::instance()->title($talk->title);
seo::instance()->description("Talk About Morning Pages, or anything else you might find interesting. Use this area to ask questions, make friends, or find out information about Morning Pages.");
}
示例14: array
</ul>
</li>
</ul>
</nav>
</div>
</header>
<?php
if (false) {
?>
<section id="user-options" class="hidden-menu">
<div class="container">
<ul>
<?php
if (user::logged()) {
?>
<li><a href="<?php
echo URL::site('user/options');
?>
">User options</a></li>
<!-- <li>Current streak: echo user::get()->current_streak </li> -->
<li>
<select data-bind="goToPreviousPage:true" id="pastposts">
<option value="0">Previous pages</option>
<option value="/">Today</option>
<?php
$pages = user::get()->pages->where('type', '=', 'page')->order_by('created', 'DESC')->find_all();
$years = array();
if ((bool) $pages->count()) {
foreach ($pages as $p) {
示例15: function
" type="text/javascript"></script>
<script src="<?php
echo URL::site('media/js/config.js');
?>
" type="text/javascript"></script>
<script>
<?php
$filename = 'media/js/viewModels/' . $controller . '/' . $action . '.js';
$include_viewmodel = false;
if (file_exists($filename)) {
$include_viewmodel = true;
}
?>
require(['project'], function(project){
project.init(<?php
echo (user::logged() ? 'true' : 'false') . ', ' . site::notes();
?>
).then(function(){
<?php
if ($include_viewmodel) {
?>
require(['viewModels/<?php
echo $controller . '/' . $action;
?>
']);
<?php
}
?>
});
});
</script>