public function form()
 {
     Phalanx::loadClasses('Profile', 'PostCategory', 'Lists', 'GamerTags', 'NotificationSettings');
     $this->views->data = Profile::get_profile($this->session->user->login, 1, 0, 1, 0, 0, 1, 1);
     $this->views->categories = PostCategory::get();
     $this->views->lists = Lists::from_user($this->session->user->id);
     $this->views->notification_settings = NotificationSettings::from_user($this->session->user->id);
     $this->views->message = $this->session->message;
     $this->session->message = '';
     $this->views->display("settings_form.phtml");
 }
示例#2
0
 /**
  * Not only a getter for the notifications attribute, it always tries
  * to make sure that this attribute always has the latest notification
  * handlers, even if they have not been configured/seen by the user b4.
  */
 public function getNotifications()
 {
     $baseline = array();
     foreach ($this->_notifications as $handler) {
         $baseline[] = get_class($handler);
     }
     $availableHandlers = NotificationSettings::getHandlers();
     // If new handlers are not available here, create them.
     foreach ($availableHandlers as $handler) {
         if (!in_array($handler, $baseline)) {
             // Create an empty notification instance
             $notification = new $handler();
             $this->_notifications[$handler] = $notification;
         }
     }
     // If existing handlers are not available anymore, remove them
     foreach ($this->_notifications as $handler => $_) {
         if (!in_array($handler, $availableHandlers)) {
             unset($this->_notifications[$handler]);
         }
     }
     return $this->_notifications;
 }
示例#3
0
 public static function from_user($uid, $limit = 15)
 {
     if ($uid == '') {
         return;
     }
     Phalanx::loadClasses('NotificationSettings');
     $action_ids = NotificationSettings::from_user($uid);
     if ($action_ids) {
         $action_ids = implode(", ", $action_ids);
         $where = " AND action_type IN ({$action_ids})";
     }
     $query = "SELECT\td1.*,\n\t\t\t\t\t\t\t\tu.login,\n\t\t\t\t\t\t\t\tud.avatar\n\t\t\t\t\t\tFROM\t(\n\t\t\t\t\t\t\tSELECT\t@took_by_uid:=(\n\t\t\t\t\t\t\t\tSELECT\ttook_by_user_id\n\t\t\t\t\t\t\t\tFROM\tnotifications NI USE INDEX (fk_notifications_user1, idx_notifications_uid_date)\n\t\t\t\t\t\t\t\tWHERE\tNI.notify_user_id = {$uid}\n\t\t\t\t\t\t\t\tAND\t\tNI.action_type = n.action_type\n\t\t\t\t\t\t\t\tAND\t\tNI.action_id = n.action_id\n\t\t\t\t\t\t\t\tORDER BY id DESC\n\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t  )\tAS\ttook_by_user_id,\n\t\t\t\t\t\t\t\tCOUNT(took_by_user_id) AS qtty,\n\t\t\t\t\t\t\t\taction_id,\n\t\t\t\t\t\t\t\taction_type,\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\tSELECT\tdate\n\t\t\t\t\t\t\t\t\tFROM\tnotifications NI USE INDEX (fk_notifications_user1, idx_notifications_uid_date)\n\t\t\t\t\t\t\t\t\tWHERE\tNI.notify_user_id = {$uid}\n\t\t\t\t\t\t\t\t\tAND\t\tNI.action_type = n.action_type\n\t\t\t\t\t\t\t\t\tAND\t\tNI.action_id = n.action_id\n\t\t\t\t\t\t\t\t\tORDER BY id DESC\n\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t)\tAS\tdate,\n\t\t\t\t\t\t\t\treaded,\n\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\tFROM\tnotifications n USE INDEX (fk_notifications_user1, idx_notifications_uid_date)\n\t\t\t\t\t\t\tWHERE\tnotify_user_id = {$uid}\n\t\t\t\t\t\t\tAND\t\tdate > DATE_SUB(NOW(), INTERVAL 2 WEEK)\n\t\t\t\t\t\t\t{$where}\n\t\t\t\t\t\t\tGROUP BY action_id, action_type\n\t\t\t\t\t\t\tORDER BY n.id DESC LIMIT {$limit}\n\t\t\t\t\t\t) d1\n\t\t\t\t\t\tINNER JOIN\tuser u\n\t\t\t\t\t\t\t\tON\tu.id = d1.took_by_user_id\n\t\t\t\t\t\tINNER JOIN\tuser_data ud USE INDEX (fk_user_data_user1)\n\t\t\t\t\t\t\t\tON\tud.user_id = u.id\n\t\t\t\t\t\tORDER BY\tdate DESC";
     $data = Model::ExecuteQuery($query);
     $return = array();
     $Session = new Session();
     Phalanx::loadClasses('Profile');
     foreach ($data as $each) {
         $o = new stdClass();
         $o->id = $each->id;
         $o->readed = $each->readed;
         $o->when = Date::RelativeTime($each->date);
         $o->image = AVATAR_DIR . 'square/' . $each->avatar;
         $o->classname = '';
         switch ($each->action_type) {
             case Notification::WON_A_BADGE:
                 $b = Model::Factory('badge')->where("id='{$each->action_id}'")->get();
                 $o->description = "Parabéns! Você ganhou o badge <b>" . $b->name . "</b>";
                 $o->image = MEDIA_DIR . 'images/badges/' . $b->icon_url;
                 $o->link = 'meu-perfil/badges';
                 $o->classname = 'badge';
                 break;
             case Notification::LIKED_POST:
             case Notification::DISLIKED_POST:
                 $post_title = Model::Factory('posts')->where("id='{$each->action_id}'")->get()->title;
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post_title)));
                 if ($each->qtty > 1) {
                     $quantity = $each->qtty - 1;
                     $quantity = $quantity == 1 ? "e outro nerd marcaram" : "e outros {$quantity} nerds marcaram";
                     if ($each->action_type == Notification::LIKED_POST) {
                         $o->description = "<b>{$each->login}</b> {$quantity} seu post como MEGABOGA";
                     } else {
                         if ($each->action_type == Notification::DISLIKED_POST) {
                             $o->description = "<b>{$each->login}</b> {$quantity} seu post como WHATEVER";
                         }
                     }
                 } else {
                     if ($each->action_type == Notification::LIKED_POST) {
                         $o->description = "<b>{$each->login}</b> marcou seu post como MEGABOGA";
                     } else {
                         if ($each->action_type == Notification::DISLIKED_POST) {
                             $o->description = "<b>{$each->login}</b> marcou seu post como WHATEVER";
                         }
                     }
                 }
                 $o->link = 'perfil/' . $Session->user->login . '/post/' . $each->action_id . '-' . $safe_url;
                 break;
             case Notification::REBLOGGED_POST:
                 $post_title = Model::Factory('posts')->where("id='{$each->action_id}'")->get()->title;
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post_title)));
                 if ($each->qtty > 1) {
                     $quantity = $each->qtty - 1;
                     $o->description = $quantity == 1 ? "e outro nerd reblogaram seu post" : "e outros {$quantity} nerds reblogaram seu post";
                 } else {
                     $o->description = "<b>{$each->login}</b> reblogou seu post";
                 }
                 $o->link = 'perfil/' . $Session->user->login . '/post/' . $each->action_id . '-' . $safe_url;
                 break;
             case Notification::FAVORITED_A_POST:
                 $post_title = Model::Factory('posts')->where("id='{$each->action_id}'")->get()->title;
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post_title)));
                 if ($each->qtty > 1) {
                     $quantity = $each->qtty - 1;
                     $quantity = $quantity == 1 ? "e outro nerd FAVORITARAM" : "e outros {$quantity} nerds FAVORITARAM";
                 } else {
                     $quantity = " FAVORITOU";
                 }
                 $o->description = "<b>{$each->login}</b> {$quantity} seu post";
                 $o->link = 'perfil/' . $Session->user->login . '/post/' . $each->action_id . '-' . $safe_url;
                 break;
             case Notification::DISLIKED_COMMENT:
             case Notification::LIKED_COMMENT:
                 $comment = Model::Factory('comment', true, 3600)->where("id='{$each->action_id}'")->get();
                 $post = Model::Factory('posts', true, 3600)->where("id='{$comment->posts_id}'")->get();
                 $post_owner = Model::Factory('user u', true, 3600)->where("u.id='{$post->user_id}'")->get();
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post->title)));
                 if ($each->qtty > 1) {
                     $quantity = $each->qtty - 1;
                     $quantity = $quantity == 1 ? "e outro nerd marcaram" : "e outros {$quantity} nerds marcaram";
                     if ($each->action_type == Notification::LIKED_COMMENT) {
                         $o->description = "<b>{$each->login}</b> {$quantity} seu comentário como MEGABOGA";
                     } else {
                         if ($each->action_type == Notification::DISLIKED_COMMENT) {
                             $o->description = "<b>{$each->login}</b> {$quantity} seu comentário como WHATEVER";
                         }
                     }
                 } else {
                     if ($each->action_type == Notification::LIKED_COMMENT) {
                         $o->description = "<b>{$each->login}</b> marcou seu comentário como MEGABOGA";
                     } else {
                         if ($each->action_type == Notification::DISLIKED_COMMENT) {
                             $o->description = "<b>{$each->login}</b> marcou seu comentário como WHATEVER";
                         }
                     }
                 }
                 if ($post_owner->id == 0) {
                     $o->link = "site/post/{$post->wp_posts_ID}-";
                 } else {
                     $o->link = 'perfil/' . $post_owner->login . '/post/' . $post->id . '-' . $safe_url;
                 }
                 break;
             case Notification::COMMENTED_POST:
                 $post = Model::Factory('posts')->where("id='{$each->action_id}'")->get();
                 $post_title = $post->title;
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post->title)));
                 if ($each->qtty > 1) {
                     $quantity = $each->qtty - 1;
                     if ($quantity == 1) {
                         $o->description = "<b>{$each->login}</b> e outro nerd comentaram seu post";
                     } else {
                         $o->description = "<b>{$each->login}</b> e outros {$quantity} nerds comentaram seu post";
                     }
                 } else {
                     $o->description = "<b>{$each->login}</b> comentou seu post";
                 }
                 $o->link = 'perfil/' . $Session->user->login . '/post/' . $each->action_id . '-' . $safe_url;
                 break;
             case Notification::REPLYED_COMMENT:
                 $comment = Model::Factory('comment')->where("id='{$each->action_id}'")->get();
                 $post = Model::Factory('posts')->where("id='{$comment->posts_id}'")->get();
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post->title)));
                 $m = Model::Factory('user');
                 $m->where("id='{$post->user_id}'");
                 $post_owner = $m->get();
                 if ($each->qtty > 1) {
                     $quantity = $each->qtty - 1;
                     if ($quantity == 1) {
                         $o->description = "<b>{$each->login}</b> e outro nerd  responderam seu comentário";
                     } else {
                         $o->description = "<b>{$each->login}</b> e outros {$quantity} nerds responderam seu comentário";
                     }
                 } else {
                     $o->description = "<b>{$each->login}</b> respondeu seu comentário";
                 }
                 if ($post_owner->login != $Session->user->login) {
                     if ($post_owner->login == $each->login) {
                         $o->description .= " no post dele";
                     } else {
                         if ($post_owner->id != 0) {
                             $o->description .= " no post de <b>{$post_owner->login}</b>";
                         }
                     }
                 }
                 if ($post_owner->id == 0) {
                     $o->link = "site/post/{$post->wp_posts_ID}-";
                 } else {
                     $o->link = 'perfil/' . $post_owner->login . '/post/' . $comment->posts_id . '-' . $safe_url;
                 }
                 break;
             case Notification::LEVELED_UP:
                 $o->description = "Parabéns <b>{$Session->user->login}</b>, agora você está no <b>Level {$each->action_id}</b>!";
                 $o->link = "meu-perfil";
                 $o->image = '';
                 break;
             case Notification::CHANGED_AVATAR:
                 $m = Model::Factory('user');
                 $m->where("id='{$each->took_by_user_id}'");
                 $user = $m->get();
                 $o->description = '' . $user->login . " trocou o avatar";
                 $o->link = 'perfil/' . $user->login;
                 break;
             case Notification::BEFRIENDED:
                 $u = Model::Factory('user')->where("id='{$each->took_by_user_id}'")->get();
                 $o->description = "<b>{$u->login}</b> aceitou seu pedido de amizade";
                 $o->link = 'perfil/' . $u->login;
                 break;
             case Notification::TAGGED_IN_A_POST:
                 $u = Model::Factory('user')->where("id='{$each->took_by_user_id}'")->get();
                 $od = Profile::other_data($each->took_by_user_id);
                 $p = Model::Factory('posts')->where("id='{$each->action_id}'")->get();
                 $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $p->title)));
                 $o->description = "<b>{$u->login}</b> te citou em um post";
                 $o->image = AVATAR_DIR . 'square/' . $od->avatar;
                 $o->link = 'perfil/' . $u->login . '/post/' . $each->action_id . '-' . $safe_url;
                 break;
             case Notification::TAGGED_IN_A_COMMENT:
                 $u = Model::Factory('user')->where("id='{$each->took_by_user_id}'")->get();
                 $p = Model::Factory('posts')->where("id='{$each->action_id}'")->get();
                 if ($p->user_id != 0) {
                     $post_owner = Model::Factory('user')->where("id='{$p->user_id}'")->get();
                     $safe_url = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $p->title)));
                     $o->link = 'perfil/' . $post_owner->login . '/post/' . $each->action_id . '-' . $safe_url;
                 } else {
                     $o->link = "site/post/{$p->wp_posts_ID}-";
                 }
                 $o->description = "<b>{$u->login}</b> te citou em um comentário";
                 break;
         }
         $return[] = $o;
     }
     return $return;
 }