Exemple #1
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $comment = new Comments();
         $comment->setName($this->request->getPost('name'));
         $comment->setEmail($this->request->getPost('email'));
         $comment->setContent($this->request->getPost('comment'));
         //store comment on the comments table
         if ($comment->save() == false) {
             echo "These errors occurred: ";
             foreach ($comment->getMessages() as $msg) {
                 echo $msg;
             }
         } else {
             //store on the post_comments table
             $post_id = $this->request->getPost('id');
             $post_comment = new PostComments();
             $post_comment->setCommentId($comment->id());
             $post_comment->setPostId($post_id);
             if ($post_comment->save() == false) {
                 echo "These errors occurred: ";
                 foreach ($post_comment->getMessages() as $msg) {
                     echo $msg;
                 }
             } else {
                 return (new \Phalcon\Http\Response())->redirect('posts/post/' . $post_id);
             }
         }
     }
 }
 public function form()
 {
     Phalanx::loadClasses('public.PostComments');
     if ($this->get->id != '') {
         $post = Model::Factory('posts', false)->where("id='{$this->get->id}'")->get();
     } else {
         if ($this->get->wpid != '') {
             $post = Model::Factory('posts', false)->where("wp_posts_ID='{$this->get->wpid}'")->get();
         }
     }
     if ($post) {
         $this->views->post = $post;
         $this->views->comments = PostComments::get($post->id, false);
     }
     $this->views->pid = $this->get->id;
     $this->views->wpid = $this->get->wpid;
     $this->views->display("form-comentarios.phtml");
 }
Exemple #3
0
 public function postAction($id)
 {
     $post = Posts::findFirst($id);
     if (!$post) {
         return (new \Phalcon\Http\Response())->setStatusCode(404, "Not Found")->setContent("Not Found");
     }
     $this->view->pick('posts/post');
     $this->view->title = $post->getTitle();
     $this->view->content = $post->getContent();
     $this->view->id = $id;
     //select all comments for the post
     $comments = PostComments::find(array('conditions' => 'post_id = ?1', 'bind' => array(1 => $id)));
     $comment_array = array();
     foreach ($comments as $c) {
         $comment = Comments::findFirst($c->getCommentId());
         array_push($comment_array, array('commenter' => $comment->getName(), 'content' => $comment->getContent()));
     }
     $this->view->comments = $comment_array;
 }
 public function DisplayWordpressPost()
 {
     Phalanx::loadController('LoginController');
     $loginController = new LoginController();
     $this->isLoggedIn = $loginController->isLoggedIn();
     Phalanx::loadClasses('public.Posts', 'public.PostComments');
     $post = Posts::GetWPPostData($this->get->post_id, $this->session->user->id, true);
     $slug = mb_strtolower(preg_replace('/--+/u', '-', preg_replace('/[^\\w\\-]+/u', '-', $post->content->post_title)));
     if ($slug != $this->get->slug) {
         Request::redirect_301(HOST . "site/post/{$this->get->post_id}-{$slug}");
     }
     $v = new Views();
     $v->title = $post->content->post_title;
     $v->content = $post->content->post_content;
     $v->comments = $post->comments;
     $v->comments_array = PostComments::get($post->post_id);
     $v->replies = $post->replies;
     $v->post_id = $post->post_id;
     $v->rating = $post->rating;
     $v->when = Date::RelativeTime($post->content->post_date);
     $v->my_rating = $p->my_rating;
     $v->current_user = $this->session->user->login;
     $v->is_favorite = $p->is_favorite;
     $content = $v->render("post_body_wp.phtml");
     $template = new Template("default");
     $template->og = new stdClass();
     $template->og->title = $v->title;
     $template->og->description = substr(strip_tags($content), 0, 250);
     //$template->og->img = MEDIA_DIR . 'images/avatar/big/' . $profile_data->aditional_info->avatar;
     if (!$this->isLoggedIn) {
         $template->show_login_bar = true;
     }
     $v = new Views($template);
     $v->data = new stdClass();
     $v->data->post = $content;
     $v->display("single_post_display.phtml");
 }
 public function GetComments()
 {
     $post_id = $this->post->post_id != '' ? $this->post->post_id : false;
     $cache_time = MEMCACHE_SECONDS;
     if (!$post_id) {
         Phalanx::loadClasses('Posts');
         $post = Posts::GetWPPost($this->get->wpid);
         $post_id = $post ? $post->id : false;
         $cache_time = 180;
     }
     $comments = array('');
     header("Content-type: text/html; charset=utf-8");
     if ($post_id) {
         Phalanx::loadClasses("PostComments");
         $comments = PostComments::get($post_id, $cache_time, $this->get->sort);
         foreach ($comments as &$comment) {
             $comment->comment = preg_replace('/(?<=|(?<=[.A-Za-z0-9_-]))@([.A-Za-z0-9_-]+[.A-Za-z0-9_-]+)/', '<a class="profile-link" href="' . HOST . 'perfil/$1"e>@$1</a>', nl2br($comment->comment));
             foreach ($comment->replies as &$reply) {
                 $reply->comment = preg_replace('/(?<=|(?<=[.A-Za-z0-9_-]))@([.A-Za-z0-9_-]+[.A-Za-z0-9_-]+)/', '<a class="profile-link" href="' . HOST . 'perfil/$1"e>@$1</a>', nl2br($reply->comment));
             }
         }
     }
     if ($this->get->render) {
         Phalanx::loadController('LoginController');
         $loginController = new LoginController();
         $v = new Views();
         $v->comments = $post->comment_count;
         $v->replies = $post->reply_count;
         $v->comments_array = $comments;
         $v->post_id = $post_id;
         $v->logged_in = $loginController->isLoggedIn();
         echo $v->render('post_comments.phtml');
     } else {
         die(json_encode($comments));
     }
 }
Exemple #6
0
 public static function exportFromUser($uid)
 {
     Phalanx::loadClasses('PostCategory', 'PostComments', 'Favorites');
     $m = Model::Factory('posts p', 0);
     $m->fields('p.id 					AS id', 'p.original_posts_id	AS original_id', 'p.title		AS title', 'p.user_id 		AS user_id', 'p.content 		AS content', 'p.date 		AS date', 'p.public		AS privacy', 'p.like_count		AS likes', 'p.dislike_count	AS dislikes', 'p.reblog_count		AS reblogs', 'p.comment_count	AS comments', 'p.reply_count		AS replies', 'p.promoted			AS promoted', 'u.name 		AS name', 'u.login		AS user', 'ud.avatar 		AS avatar');
     $m->innerJoin('user u', 'u.id = p.user_id');
     $m->innerJoin('user_data ud', 'ud.user_id = p.user_id');
     $m->order('p.id DESC');
     $where = array();
     $where[] = "p.status=1";
     $where[] = "p.original_posts_id IS NULL";
     if ($uid) {
         $where[] = "p.user_id = '{$uid}'";
     }
     $where = implode(" AND ", $where);
     $m->where($where);
     $data = $m->all();
     $ret = array();
     $Session = new Session();
     foreach ($data as $v) {
         $o = new stdClass();
         $o->date = Date::RelativeTime($v->date);
         $o->id = $v->id;
         $o->original_id = $v->original_id;
         $o->title = $v->title;
         $o->user = $v->user;
         $o->name = $v->name;
         $o->avatar = $v->avatar;
         $o->user_id = $v->user_id;
         $o->content = trim($v->content);
         $o->rating = new stdClass();
         $o->rating->whatever = (int) abs($v->dislikes);
         $o->rating->megaboga = (int) abs($v->likes);
         $o->rating->reblog_count = (int) abs($v->reblogs);
         $o->my_rating = self::userRating($Session->user->id, $v->id);
         $o->is_reblogged = self::userHasReblogged($o->original_id, $Session->user->id);
         $o->categories = PostCategory::from_post($v->id);
         $o->comments = $v->comments;
         $o->comments_array = PostComments::get($v->id);
         $o->replies = $v->replies;
         $o->privacy = $v->privacy;
         $o->promoted = $v->promoted;
         $o->is_favorite = Favorites::is_favorite($uid, $v->id);
         $o->user_points = Profile::experience($v->user_id);
         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 = self::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;
         }
         $ret[] = $o;
     }
     return $ret;
 }