Ejemplo n.º 1
0
Archivo: ignore.php Proyecto: anqh/core
 /**
  * Find ids of users the user has ignored.
  *
  * @static
  * @param   integer  $user_id
  * @return  array
  */
 public static function find_by_user($user_id)
 {
     $user_id = (int) $user_id;
     $ckey = 'ignores_' . $user_id;
     // Try static cache
     $ignores = Anqh::cache_get($ckey);
     if (is_null($ignores)) {
         // Load from DB
         $ignores = (array) DB::select('ignore_id')->from('ignores')->where('user_id', '=', $user_id)->execute()->as_array(null, 'ignore_id');
         Anqh::cache_set($ckey, $ignores, Date::HOUR);
     }
     return $ignores;
 }
Ejemplo n.º 2
0
 /**
  * Load Foursquare data
  *
  * @return  array
  */
 public function foursquare()
 {
     if ($this->foursquare_id) {
         // Use cache to avoid flooding Foursquare
         $foursquare = Anqh::cache_get('foursquare_venue_' . $this->foursquare_id);
         if (!$foursquare) {
             // Store the original request
             $request = $_REQUEST;
             $_REQUEST = array('method' => 'venue', 'vid' => $this->foursquare_id);
             $response = Request::factory(Route::url('api_venues', array('action' => 'foursquare', 'format' => 'json')))->execute()->body();
             // Restore the original request
             $_REQUEST = $request;
             $foursquare = Arr::path(json_decode($response, true), 'venue.venue');
             // Cache results for 15 minutes
             Anqh::cache_set('foursquare_venue_' . $this->foursquare_id, $foursquare, 60 * 15);
         }
         return $foursquare;
     }
 }
Ejemplo n.º 3
0
Archivo: user.php Proyecto: anqh/anqh
 /**
  * Get user id from data
  *
  * @static
  * @param   mixed  $user
  * @return  integer
  */
 public static function user_id($user)
 {
     if (is_int($user) || is_numeric($user)) {
         // Already got id
         return (int) $user;
     } else {
         if (is_array($user)) {
             // Got user array
             return (int) Arr::get($user, 'id');
         } else {
             if ($user instanceof Model_User) {
                 // Got user model
                 return $user->id;
             } else {
                 if (is_string($user)) {
                     // Got user name
                     $username = Text::clean($user);
                     if (!($id = (int) Anqh::cache_get('user_uid_' . $username))) {
                         if ($user = Model_User::find_user($user)) {
                             $id = $user->id;
                             Anqh::cache_set('user_uid_' . $username, $id, Date::DAY);
                         }
                     }
                     return $id;
                 }
             }
         }
     }
     return 0;
 }