public static function get_adopted($page = 0) { $range = $page * 30; //$mdl = Model::ExecuteQuery("SELECT sql_cache c.name, c.quantity, c.status, c.picture, a.id AS adopted_id FROM cats c RIGHT JOIN cats_adopted a ON c.id = a.cat_id WHERE c.status!=0 AND c.inactive=0 group by c.id ORDER BY c.status desc, adopted_id asc limit $range, 30"); //$mdl = Model::ExecuteQuery("SELECT c.*, a.id AS adopted_id FROM cats c LEFT JOIN cats_adopted a ON c.id = a.cat_id WHERE c.status!=0 AND c.inactive=0 ORDER BY adopted_id desc, c.status asc limit $range, 30"); //$mdl = Model::ExecuteQuery("SELECT sql_cache c.name, c.quantity, c.status, c.picture, a.id AS adopted_id FROM cats c right JOIN cats_adopted a ON c.id = a.cat_id WHERE c.status!=0 AND c.inactive=0 ORDER BY adopted_id desc, c.status asc limit $range, 30"); $mdl = Model::ExecuteQuery("SELECT sql_cache c.name, c.quantity, c.status as status, c.picture, a.id AS adopted_id FROM cats c LEFT JOIN cats_adopted a ON c.id = a.cat_id WHERE c.status!=0 AND c.inactive=0 group by c.id ORDER BY status asc, adopted_id desc, c.id desc limit {$range}, 30"); $mdl_count = Model::ExecuteQuery("SELECT sql_cache count(c.id) as total FROM cats c LEFT JOIN cats_adopted a ON c.id = a.cat_id WHERE c.status!=0 AND c.inactive=0"); //$mdl = Model::ExecuteQuery("SELECT sql_cache c.name, c.quantity, c.status as status, c.picture, a.id AS adopted_id FROM cats c right outer JOIN cats_adopted a ON c.id = a.cat_id WHERE c.status!=0 AND c.inactive=0 group by c.id ORDER BY c.status desc, adopted_id desc limit $range, 30"); $result = $mdl; $result_count = $mdl_count; $response = array(); $a = 0; $b = $result_count[0]->total - $range; for ($i = 0; $i < count($result); $i++) { $response[$i] = $result[$i]; $response[$i]->cod = $b; if ($result[$i]->quantity == "2" && $result[$i]->status == "2") { $response[$i + 1] = null; $response[$i]->cod = $b . " / " . ($b - 1); $b--; $a++; } if ($response[$i]->name == $response[$i - 1]->name) { //unset($response[$i]); } $b--; $a++; } //krsort($response); //$response = array_slice($response, $range, 30); return $response; }
public function rate() { $o = new stdClass(); $nerdtrackID = $this->get->nerdtrackID; switch ($this->get->action) { case "rate": $m = Model::Factory('rating'); $m->nerdtrack_id = $nerdtrackID; $m->user_id = $this->session->user->id; $m->rating = $this->get->rating; $m->date = date('Y-m-d H:i:s'); $o->status = $m->insert(); if ($o->status) { $field = $this->get->rating == '1' ? 'like_count' : 'dislike_count'; Model::ExecuteQuery("UPDATE nerdtrack SET {$field}={$field}+1 WHERE id='{$nerdtrackID}' AND {$field}>0"); } break; case "unrate": $m = Model::Factory('rating'); $m->where("nerdtrack_id='{$nerdtrackID}' AND user_id='{$this->session->user->id}'"); $o->status = (bool) $m->delete(); if ($o->status) { $field = $this->get->currentRate == '1' ? 'like_count' : 'dislike_count'; $where = ''; if ($this->get->currentRate != '1') { $where = ' AND {$field} > 0'; } Model::ExecuteQuery("UPDATE nerdtrack SET {$field}={$field}-1 WHERE id='{$nerdtrackID}' {$where}"); } break; case "change_rate": $m = Model::Factory('rating'); $m->rating = $this->get->currentRate == 1 ? '-1' : '1'; $m->date = date('Y-m-d H:i:s'); $m->where("nerdtrack_id='{$nerdtrackID}' AND user_id='{$this->session->user->id}'"); $o->status = (bool) $m->update(); if ($o->status) { if ($this->get->currentRate == '1') { Model::ExecuteQuery("UPDATE nerdtrack SET like_count=like_count-1 WHERE id='{$nerdtrackID}' AND like_count>0"); Model::ExecuteQuery("UPDATE nerdtrack SET dislike_count=dislike_count+1 WHERE id='{$nerdtrackID}'"); } elseif ($this->get->currentRate == '-1') { Model::ExecuteQuery("UPDATE nerdtrack SET like_count=like_count+1 WHERE id='{$nerdtrackID}'"); Model::ExecuteQuery("UPDATE nerdtrack SET dislike_count=dislike_count-1 WHERE id='{$nerdtrackID}' AND dislike_count>0"); } } break; } header("Content-type:text/plain;charset=utf-8"); $data = json_encode($o); if (isset($this->get->callback)) { die("{$this->get->callback}({$data});"); } else { die($data); } }
public function delete_cat() { $m = Model::Factory('cats'); $m->inactive = 1; $m->where("id=" . $this->get->cat_id); $m->update(); $a = Model::Factory("cats_adopted"); $a->fields("id"); $a->order("id DESC"); $increment = $a->get()->id + 1; $b = Model::ExecuteQuery("ALTER TABLE cats_adopted AUTO_INCREMENT = {$increment};"); Request::redirect(HOST . 'adm/gatos/all'); }
public static function build($uid, stdClass $config) { Phalanx::loadClasses('Friendship', 'Posts', 'PostComments', 'PostCategory', 'Favorites', 'Profile'); $friends_ids = Friendship::get_friend_array($uid); $friends_ids = implode(', ', $friends_ids); $limit = NUMBER_OF_POSTS_LOADED_PER_TIME; $where = ""; $whereRTs = ""; if (property_exists($config, 'min')) { $where .= " AND p.id < '{$config->min}'"; $whereRTs .= " AND p.original_posts_id < '{$config->min}'"; } if (property_exists($config, 'max')) { $where .= " AND p.id < '{$config->max}'"; $whereRTs .= " AND p.original_posts_id < '{$config->max}'"; } if (!property_exists($config, 'min') and !property_exists($config, 'max')) { $where = "AND p.date > DATE_SUB(NOW(), INTERVAL 2 WEEK)"; } $sql = "SELECT * FROM (\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\tSELECT \tp.id \t\t\t\t\t\tAS id,\r\n\t\t\t\t\t\t\t\tp.original_posts_id \t\tAS original_id,\r\n\t\t\t\t\t\t\t\t1\t\t\t\t\t\t\tAS reblog_count,\r\n\t\t\t\t\t\t\t\tp.user_id \t\t\t\t\tAS user_id,\r\n\t\t\t\t\t\t\t\tp.content \t\t\t\t\tAS content,\r\n\t\t\t\t\t\t\t\tp.date \t\t\t\t\t\tAS date,\r\n\t\t\t\t\t\t\t\tp.title\t\t\t\t\t\tAS title,\r\n\t\t\t\t\t\t\t\tp.like_count\t\t\t\tAS likes,\r\n\t\t\t\t\t\t\t\tp.dislike_count\t\t\t\tAS dislikes,\r\n\t\t\t\t\t\t\t\tp.comment_count\t\t\t\tAS comments,\r\n\t\t\t\t\t\t\t\tp.reply_count\t\t\t\tAS replies,\r\n\t\t\t\t\t\t\t\tp.reblog_count\t\t\t\tAS reblogs,\r\n\t\t\t\t\t\t\t\tp.promoted\t\t\t\t\tAS promoted,\r\n\t\t\t\t\t\t\t\tu.name\t \t\t\t\t\tAS name,\r\n\t\t\t\t\t\t\t\tu.login\t\t\t\t\t\tAS user,\r\n\t\t\t\t\t\t\t\tud.avatar \t\t\t\t\tAS avatar\r\n\t\t\t\t\t\tFROM\tposts p\r\n\t\t\t\t\t\tINNER JOIN user u\r\n\t\t\t\t\t\t\t\tON u.id = p.user_id\r\n\t\t\t\t\t\tINNER JOIN user_data ud\r\n\t\t\t\t\t\t\t\tON ud.user_id = p.user_id\r\n\t\t\t\t\t\tWHERE \tp.user_id IN({$friends_ids})\r\n\t\t\t\t\t\t{$where}\r\n\t\t\t\t\t\tAND u.banned IS NULL\r\n\t\t\t\t\t\tAND p.status=1\r\n\t\t\t\t\t\tAND p.original_posts_id IS NULL\r\n\t\t\t\t\t\tORDER BY\tp.id DESC\r\n\t\t\t\t\t\tLIMIT\t{$limit}\r\n\t\t\t\t\t) UNION (\r\n\t\t\t\t\t\tSELECT \tp.id \t\t\t\t\t\tAS id,\r\n\t\t\t\t\t\t\t\tp.original_posts_id \t\tAS original_id,\r\n\t\t\t\t\t\t\t\tCOUNT(p.original_posts_id)\tAS reblog_count,\r\n\t\t\t\t\t\t\t\tp.user_id \t\t\t\t\tAS user_id,\r\n\t\t\t\t\t\t\t\tp.content \t\t\t\t\tAS content,\r\n\t\t\t\t\t\t\t\tp.date \t\t\t\t\t\tAS date,\r\n\t\t\t\t\t\t\t\tp.title\t\t\t\t\t\tAS title,\r\n\t\t\t\t\t\t\t\tp.like_count\t\t\tAS likes,\r\n\t\t\t\t\t\t\t\tp.dislike_count\t\t\tAS dislikes,\r\n\t\t\t\t\t\t\t\tp.comment_count\t\t\tAS comments,\r\n\t\t\t\t\t\t\t\tp.reply_count\t\t\tAS replies,\r\n\t\t\t\t\t\t\t\tp.reblog_count\t\t\tAS reblogs,\r\n\t\t\t\t\t\t\t\tp.promoted\t\t\tAS promoted,\r\n\t\t\t\t\t\t\t\tu.name\t \t\t\tAS name,\r\n\t\t\t\t\t\t\t\tu.login\t\t\t\tAS user,\r\n\t\t\t\t\t\t\t\tud.avatar \t\t\tAS avatar\r\n\t\t\t\t\t\tFROM\tposts p\r\n\t\t\t\t\t\tINNER JOIN user u\r\n\t\t\t\t\t\t\t\tON u.id = p.user_id\r\n\t\t\t\t\t\tINNER JOIN user_data ud\r\n\t\t\t\t\t\t\t\tON ud.user_id = p.user_id\r\n\t\t\t\t\t\tWHERE \tp.user_id IN({$friends_ids})\r\n\t\t\t\t\t\t{$where}\r\n\t\t\t\t\t\t-- {$whereRTs}\r\n\t\t\t\t\t\tAND u.banned IS NULL\r\n\t\t\t\t\t\tAND p.status=1\r\n\t\t\t\t\t\tAND p.original_posts_id IS NOT NULL\r\n\t\t\t\t\t\tGROUP BY\tp.original_posts_id\r\n\t\t\t\t\t\tORDER BY\tp.id DESC\r\n\t\t\t\t\t\tLIMIT\t{$limit}\r\n\t\t\t\t\t)\t\r\n\t\t\t\t) posts\r\n\t\t\t\tORDER BY id DESC\r\n\t\t\t\tLIMIT 10"; $data = Model::ExecuteQuery($sql); $ret = array(); foreach ($data as $v) { $o = new stdClass(); $o->date = Date::RelativeTime($v->date); $o->id = $v->id; $o->original_id = $v->original_id; $o->reblog_count = $v->reblog_count; $o->name = $v->name; $o->title = $v->title; $o->avatar = $v->avatar; $o->user_id = $v->user_id; $o->rating = new stdClass(); $o->rating->megaboga = (int) abs($v->likes); $o->rating->whatever = (int) abs($v->dislikes); $o->rating->reblog_count = (int) abs($v->reblogs); $o->my_rating = Posts::userRating($uid, $v->id); $o->is_reblogged = Posts::userHasReblogged($v->id, $uid); $o->content = trim($v->content); $o->comments = $v->comments; $o->replies = $v->replies; $o->user = $v->user; $o->categories = PostCategory::from_post($v->id); $o->is_favorite = Favorites::is_favorite($uid, $v->id); $o->user_points = Profile::experience($v->user_id); $o->promoted = (bool) $v->promoted; if (!empty($o->original_id)) { //Se o post for um reblog, então o conteúdo dele deve ser o do reblogado, mostrando as ações $originalPost = Posts::from_user(false, $o->original_id); $originalPost = reset($originalPost); $o->content = $originalPost->content; $o->title = $originalPost->title; $o->reblogged_from = $originalPost->user; $o->original_date = $originalPost->date; $o->rating->reblog_count = $originalPost->rating->reblog_count; $o->categories = PostCategory::from_post($originalPost->id); $o->is_reblogged = Posts::userHasReblogged($originalPost->id, $uid); } $ret[] = $o; } return $ret; }
public static function remove($uid, $fid) { Model::ExecuteQuery("UPDATE user_data SET friend_count=friend_count-1 WHERE user_id='{$uid}' OR user_id='{$fid}'"); $m = Model::Factory('friendship'); $m->where("(user_id='{$uid}' AND friend_id='{$fid}') OR (user_id='{$fid}' AND friend_id='{$uid}')"); return $m->delete(); }
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; }
public function DeleteComment() { if (!$this->isLoggedIn) { return; } #Goodbye, XSS if ($this->session->accept_token != REQUEST_TOKEN) { Request::redirect(HOST . 'login'); return; } $cm = Model::Factory('comment', true, 3600); $cm->where("id='{$this->post->comment_id}'"); $comment = $cm->get(); if ($comment->in_reply_to != '') { Model::ExecuteQuery("UPDATE posts SET comment_count = comment_count-1 WHERE id='{$comment->posts_id}'"); } else { Model::ExecuteQuery("UPDATE posts SET reply_count = reply_count-1 WHERE id='{$comment->posts_id}'"); } header("Content-type: text/html; charset=utf-8"); $m = Model::Factory('comment')->where("id='{$this->post->comment_id}' AND user_id='{$this->session->user->id}'"); $m->status = 0; $m->delete_date = date('Y-m-d H:i:s'); $m->deleted_by_uid = $this->session->user->id; $s = $m->update(); if ($s) { $m = Model::Factory('comment')->where("in_reply_to='{$this->post->comment_id}'"); $m->status = 0; $m->delete_date = date('Y-m-d H:i:s'); $m->deleted_by_uid = $this->session->user->id; $m->update(); echo 'SUCCESS'; } else { echo 'FAIL'; } }
public static function Unblog($postID, $userID) { $reblogged = self::userHasReblogged($postID, $userID); if (!$reblogged) { return false; } $m = Model::Factory('posts')->where("original_posts_id='{$postID}' AND user_id='{$userID}'")->delete(); Model::ExecuteQuery("UPDATE posts SET reblog_count=reblog_count-1 WHERE id='{$postID}'"); return true; }
public function Rate() { Phalanx::loadClasses('Notification'); if (!$this->isLoggedIn) { return; } #Goodbye, XSS if ($this->session->accept_token != REQUEST_TOKEN) { Request::redirect(HOST . 'login'); return; } $m = Model::Factory('rating'); switch ($this->post->action) { case 'rate': $m->date = date('Y-m-d H:i:s'); $m->ip = REQUEST_IP; $m->user_id = $this->session->user->id; $m->rating = $this->post->rating; if ($this->post->comment_id) { $m->comment_id = $this->post->comment_id; } elseif ($this->post->post_id) { $m->posts_id = $this->post->post_id; } $status = $m->insert(); if ($status) { if ($this->post->comment_id) { if ($this->post->rating == 1) { $n = new Notification(Notification::LIKED_COMMENT, $this->session->user->id, $this->post->comment_id); Model::ExecuteQuery("UPDATE comment SET like_count = like_count+1 WHERE id='{$this->post->comment_id}'"); } else { $n = new Notification(Notification::DISLIKED_COMMENT, $this->session->user->id, $this->post->comment_id); Model::ExecuteQuery("UPDATE comment SET dislike_count = dislike_count+1 WHERE id='{$this->post->comment_id}'"); } } else { if ($this->post->rating == 1) { $n = new Notification(Notification::LIKED_POST, $this->session->user->id, $this->post->post_id); Model::ExecuteQuery("UPDATE posts SET like_count = like_count+1 WHERE id='{$this->post->post_id}'"); } else { $n = new Notification(Notification::DISLIKED_POST, $this->session->user->id, $this->post->post_id); Model::ExecuteQuery("UPDATE posts SET dislike_count = dislike_count+1 WHERE id='{$this->post->post_id}'"); } } } break; case 'unrate': if ($this->post->comment_id) { $m->where("comment_id='{$this->post->comment_id}' AND user_id='{$this->session->user->id}'"); if ($this->post->current_vote == '1') { Model::ExecuteQuery("UPDATE comment SET like_count = like_count-1 WHERE id='{$this->post->comment_id}' AND like_count>0"); } else { Model::ExecuteQuery("UPDATE comment SET dislike_count = dislike_count-1 WHERE id='{$this->post->comment_id}' AND dislike_count>0"); } } elseif ($this->post->post_id) { $m->where("posts_id='{$this->post->post_id}' AND user_id='{$this->session->user->id}'"); if ($this->post->current_vote == '1') { Model::ExecuteQuery("UPDATE posts SET like_count = like_count-1 WHERE id='{$this->post->post_id}' AND like_count>0"); } else { Model::ExecuteQuery("UPDATE posts SET dislike_count = dislike_count-1 WHERE id='{$this->post->post_id}' AND dislike_count>0"); } } $status = $m->delete(); break; case 'change_rate': if (!$this->post->current_vote or $this->post->current_vote == '') { return; } $m->rating = $this->post->rating; if ($this->post->comment_id) { $m->where("comment_id='{$this->post->comment_id}' AND user_id='{$this->session->user->id}'"); } else { $m->where("posts_id='{$this->post->post_id}' AND user_id='{$this->session->user->id}'"); } $status = $m->update(); if ($status) { if ($this->post->comment_id) { $m->where("comment_id='{$this->post->comment_id}' AND user_id='{$this->session->user->id}'"); if ($this->post->current_vote == '1') { Model::ExecuteQuery("UPDATE comment SET like_count=like_count-1, dislike_count=dislike_count+1 WHERE id='{$this->post->comment_id}' AND like_count>0"); } else { Model::ExecuteQuery("UPDATE comment SET dislike_count=dislike_count-1, like_count=like_count+1 WHERE id='{$this->post->comment_id}' AND dislike_count>0"); } } else { $m->where("posts_id='{$this->post->post_id}' AND user_id='{$this->session->user->id}'"); if ($this->post->current_vote == '1') { Model::ExecuteQuery("UPDATE posts SET dislike_count=dislike_count+1 WHERE id='{$this->post->post_id}'"); Model::ExecuteQuery("UPDATE posts SET like_count=like_count-1 WHERE id='{$this->post->post_id}' AND like_count>0"); } else { Model::ExecuteQuery("UPDATE posts SET like_count=like_count+1 WHERE id='{$this->post->post_id}'"); Model::ExecuteQuery("UPDATE posts SET dislike_count=dislike_count-1 WHERE id='{$this->post->post_id}' AND dislike_count>0"); } } } break; } #Faz a contagem dos likes e dislikes if ($this->post->comment_id) { $m = Model::Factory('comment', false, false); $m->fields("like_count", "dislike_count"); $m->where("id='{$this->post->comment_id}'"); $data = $m->get(); } else { $m = Model::Factory('posts', false, false); $m->fields("like_count", "dislike_count"); $m->where("id='{$this->post->post_id}'"); $data = $m->get(); } header("Content-type: text/html; charset=utf-8"); $o = new stdClass(); $o->status = $status; $o->quantity = new stdClass(); $o->quantity->whatever = $data->dislike_count; $o->quantity->megaboga = $data->like_count; die(json_encode($o)); }