当前位置: 首页>>代码示例>>PHP>>正文


PHP Visitor::instance方法代码示例

本文整理汇总了PHP中Visitor::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Visitor::instance方法的具体用法?PHP Visitor::instance怎么用?PHP Visitor::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Visitor的用法示例。


在下文中一共展示了Visitor::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getInstance

 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
开发者ID:kapai69,项目名称:fl-ru-damp,代码行数:7,代码来源:class.visitor.php

示例2: before

 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     if (!Visitor::instance()->logged_in('admin')) {
         throw new Permission_Exception(new Model_Role());
     }
 }
开发者ID:netbiel,项目名称:core,代码行数:10,代码来源:roles.php

示例3: getInstance

 static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new Visitor();
     }
     return self::$instance;
 }
开发者ID:notUserDeveloper,项目名称:fl-ru-damp,代码行数:7,代码来源:class.visitor.php

示例4: before

 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     if (!Visitor::instance()->logged_in('admin')) {
         throw new Permission_Exception(new Model_Tag());
     }
     $this->page_title = __('Tags');
 }
开发者ID:netbiel,项目名称:core,代码行数:11,代码来源:tags.php

示例5: before

 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     if (!Visitor::instance()->logged_in('admin')) {
         throw new Permission_Exception(new Model_Tag());
     }
     $this->view = View_Page::factory(__('Tags'));
 }
开发者ID:anqh,项目名称:anqh,代码行数:11,代码来源:tags.php

示例6: text

 /**
  * Get a single line of text representing the exception:
  *
  * Error [ Code ]: Message ~ File [ Line ] (#id: username, ip: IP, uri: URI)
  *
  * @param   Exception   $e
  * @return  string
  */
 public static function text(Exception $e)
 {
     if ($user = Visitor::instance()->get_user()) {
         $user_id = $user->id;
         $username = Text::clean($user->username);
     } else {
         $user_id = 0;
         $username = '';
     }
     return sprintf('%s [ %s ]: %s ~ %s [ %d ] (#%d: %s, ip: %s, uri: %s)', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine(), $user_id, $username, Request::$client_ip, Text::clean(Request::current_uri()));
 }
开发者ID:anqh,项目名称:anqh,代码行数:19,代码来源:exception.php

示例7: login

 /**
  * Show invite only page if enabled
  */
 public function login()
 {
     $uri = new URI();
     // Redirect to invite page if not logged or signing in
     if (!in_array($uri->string(), array('invite', 'sign/in')) && strpos($uri->string(), 'sign/up') !== 0 && !Visitor::instance()->logged_in()) {
         // Stop execution if ajax, ie. expired session and trying to do ajax call
         if (request::is_ajax()) {
             exit;
         }
         url::redirect('invite');
     }
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:15,代码来源:invite_hook.php

示例8: before

 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     Cache::$default = 'default';
     // Check if this was an interna request or direct
     $this->internal = $this->request !== Request::instance();
     // Ajax request?
     $this->ajax = Request::$is_ajax;
     // Load current user, null if none
     if (self::$user === false) {
         self::$user = Visitor::instance()->get_user();
     }
 }
开发者ID:netbiel,项目名称:core,代码行数:16,代码来源:controller.php

示例9: handle

 /**
  * Handle exception
  *
  * @param  Exception  $e
  */
 public static function handle(Exception $e)
 {
     if ($e instanceof Kohana_404_Exception) {
         if (Kohana::config('site.inviteonly') && !Visitor::instance()->get_user()) {
             // Redirect to invite login if invite only and not logged in
             url::redirect('invite');
         } else {
             if (!headers_sent()) {
                 $e->sendHeaders();
             }
             $page = new Error_Controller();
             $page->_404();
         }
     } else {
         return parent::handle($e);
     }
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:22,代码来源:MY_Kohana_Exception.php

示例10: online

 /**
  * Save current user to online cache
  */
 public function online()
 {
     // Skip when signing in/out to avoid strange Fatal error
     if (strpos(URI::instance()->string(), 'sign') === 0) {
         return;
     }
     $user = Visitor::instance()->get_user();
     $online = new Online_User_Model($_SESSION['session_id']);
     if (!$online->loaded()) {
         $online->session_id = $_SESSION['session_id'];
     }
     $online->last_activity = $_SESSION['last_activity'];
     $online->user_id = $user ? $user->id : null;
     try {
         $online->save();
     } catch (ORM_Validation_Exception $e) {
     }
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:21,代码来源:online_hook.php

示例11: __construct

 /**
  * Create new View class.
  */
 public function __construct()
 {
     // Initialize static variables
     if (!self::$_initialized) {
         // Request type
         if (Request::current()->is_ajax()) {
             self::$_request_type = Controller::REQUEST_AJAX;
         } else {
             if (!Request::current()->is_initial()) {
                 self::$_request_type = Controller::REQUEST_INTERNAL;
             }
         }
         // Viewing user
         if (self::$_user = Visitor::instance()->get_user()) {
             self::$_user_id = self::$_user->id;
         }
         self::$_initialized = true;
     }
 }
开发者ID:anqh,项目名称:core,代码行数:22,代码来源:base.php

示例12: user

 /**
  * Get URL for user
  *
  * @param   mixed   $user   true for session user
  * @param   string  $action
  * @return  string
  */
 public static function user($user, $action = null)
 {
     static $_visitor;
     if (is_numeric($user) && (int) $user > 0) {
         // User id given
         if ($user = Model_User::find_user($user)) {
             $user = $user->username;
         }
     } else {
         if ($user instanceof Model_User) {
             // Model_User given
             $user = $user->username;
         } else {
             if (is_array($user) && isset($user['username'])) {
                 // Light user array given
                 $user = $user['username'];
             } else {
                 if ($user === true) {
                     // Use session user
                     if ($_visitor === null) {
                         if ($user = Visitor::instance()->get_user()) {
                             $_visitor = $user->username;
                         } else {
                             // No session user available
                             $_visitor = false;
                         }
                     }
                     $user = $_visitor;
                 }
             }
         }
     }
     // Username available
     if (is_string($user)) {
         return Route::url('user', array('username' => urlencode($user), 'action' => $action));
     }
     return null;
 }
开发者ID:anqh,项目名称:anqh,代码行数:45,代码来源:url.php

示例13: find_user

 /**
  * Load one user.
  *
  * @param   mixed  $user  user_id, username, email, User_Model or false for current session
  * @return  User_Model
  */
 public function find_user($id = false)
 {
     static $session = false;
     $user = null;
     $cache = false;
     // Try user models first (User_Model, session)
     if ($id instanceof User_Model) {
         // User_Model
         $user = $id;
     } else {
         if ($id === false) {
             // Current session, fetch only once
             if ($session === false) {
                 $session = Visitor::instance()->get_user();
             }
             $user = $session;
         }
     }
     // Then try others (user_id, email, username_clean)
     if (!$user && $id !== true && !empty($id)) {
         if (is_numeric($id) || empty($id)) {
             $id = (int) $id;
         } else {
             if (valid::email($id)) {
                 $id = mb_strtolower($id);
             } else {
                 $id = utf8::clean($id);
             }
         }
         if (isset(self::$users[$id])) {
             // Found from static cache
             return self::$users[$id];
         } else {
             if ($user = $this->cache->get($this->cache->key('user', $id))) {
                 // Found from cache
                 $user = unserialize($user);
             } else {
                 // Not found from caches, try db
                 if (is_int($id)) {
                     $user = $this->find($id);
                 } else {
                     $user = $this->where(valid::email($id) ? 'email' : 'username_clean', '=', $id)->find();
                 }
                 $cache = true;
             }
         }
     }
     // If user found, add to cache(s)
     if ($user && $user->loaded()) {
         self::$users[$user->id] = self::$users[utf8::clean($user->username)] = self::$users[mb_strtolower($user->email)] = $user;
         if ($cache) {
             $this->cache->set($this->cache->key('user', $user->id), serialize($user), null, self::$cache_max_age);
         }
     }
     return $user;
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:62,代码来源:user.php

示例14: user

 /**
  * Returns user link
  *
  * @param   mixed   $user
  * @param   string  $nick
  * @param   array   $attributes
  * @param   string  $url         override url
  * @return  string
  */
 public static function user($user, $nick = null, array $attributes = null, $url = null)
 {
     static $viewer = true;
     // Load current user for friend styling
     if ($viewer === true) {
         $viewer = Visitor::instance()->get_user();
     }
     $class = array('user', 'hoverable');
     if (is_array($user) || $user && ($user = Model_User::find_user_light($user))) {
         if ($user) {
             $nick = $user['username'];
             if ($viewer && $viewer->is_friend($user)) {
                 $class[] = 'friend ';
             }
             switch ($user['gender']) {
                 case 'f':
                     $class[] = 'female';
                     break;
                 case 'm':
                     $class[] = 'male';
                     break;
             }
         }
     }
     $class[] = Arr::get($attributes, 'class');
     $attributes['class'] = trim(implode(' ', $class));
     return empty($nick) ? __('Unknown') : HTML::anchor($url ? $url : URL::user($nick), $nick, $attributes);
 }
开发者ID:anqh,项目名称:anqh,代码行数:37,代码来源:html.php

示例15: _join

 /**
  * Register with code
  *
  * @param  Model_Invitation  $invitation
  * @param  array             $external
  * @param  string            $provider
  */
 public function _join(Model_Invitation $invitation = null, array $external = null, $provider = null)
 {
     $user = new Model_User();
     if ($invitation) {
         $user->email = $invitation->email;
     } else {
         if ($external) {
             $user->email = Arr::get($external, 'email');
             $user->name = Arr::get($external, 'name');
             $user->username = Arr::get($external, 'username', $user->name);
             $user->avatar_url = 'https://graph.facebook.com/' . $external['id'] . '/picture';
             $user->picture = 'https://graph.facebook.com/' . $external['id'] . '/picture?type=large';
             if ($location = Arr::get($external, 'location')) {
                 $user->location = $location->name;
                 $user->city_name = $location->name;
             }
             if ($gender = Arr::get($external, 'gender')) {
                 switch ($gender) {
                     case 'male':
                         $user->gender = 'm';
                         break;
                     case 'female':
                         $user->gender = 'f';
                         break;
                 }
             }
             if ($birthday = Arr::get($external, 'birthday')) {
                 $user->dob = $birthday;
             }
         }
     }
     // Handle post
     $errors = array();
     if ($_POST && !Arr::get($_POST, 'signup')) {
         $post = Arr::extract($_POST, array('username', 'password', 'password_confirm'));
         try {
             $user->username = $post['username'];
             $user->password_kohana = $post['password'];
             $user->created = time();
             $user->save();
             // Delete used invitation
             if ($invitation) {
                 $invitation->delete();
             }
             // Connect accounts
             if ($external && $provider) {
                 $consumer = new OAuth2_Consumer($provider);
                 $token = $consumer->get_token();
                 $external_user_id = $external['id'];
                 if ($token && $external_user_id) {
                     $external = new Model_User_External();
                     $external->set_fields(array('token' => $token['access_token'], 'user_id' => $user->id, 'external_user_id' => $external_user_id, 'created' => time(), 'expires' => time() + (int) $token['expires'], 'provider' => $provider));
                     $external->save();
                 }
             }
             // Login user
             $user->add_role('login');
             Visitor::instance()->login($user, $_POST['password']);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $user->password_kohana = $user->password_confirm = null;
             $errors = $e->array->errors('validation');
         }
     }
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_register($user, $errors, $invitation->code));
 }
开发者ID:anqh,项目名称:anqh,代码行数:73,代码来源:sign.php


注:本文中的Visitor::instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。