/** * Retrieve posts from the database * * @access private */ private function get_posts() { try { $to_read['table'] = 'post'; $to_read['columns'] = array('POST_ID'); if (VRequest::filter(false)) { if (VRequest::date('all') == 'all' && VRequest::category('all') == 'all') { switch ($this->_status) { case 'all': $to_read['condition_select_types'][':status'] = '!='; $to_read['condition_values'][':status'] = 'trash'; break; default: $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; break; } $to_read['condition_columns'][':status'] = 'post_status'; $to_read['value_types'][':status'] = 'str'; } else { if (VRequest::date('all') != 'all') { $to_read['condition_columns'][':date'] = 'post_date'; $to_read['condition_select_types'][':date'] = 'LIKE'; $to_read['condition_values'][':date'] = VRequest::date() . '%'; $to_read['value_types'][':date'] = 'str'; } if (VRequest::category('all') != 'all') { $to_read['condition_types'][':cat'] = 'AND'; $to_read['condition_columns'][':cat'] = 'post_category'; $to_read['condition_select_types'][':cat'] = 'LIKE'; $to_read['condition_values'][':cat'] = '%' . VRequest::category() . '%'; $to_read['value_types'][':cat'] = 'str'; } $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'post_status'; $to_read['value_types'][':status'] = 'str'; switch ($this->_status) { case 'all': $to_read['condition_select_types'][':status'] = '!='; $to_read['condition_values'][':status'] = 'trash'; break; default: $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; break; } } } elseif (VPost::search_button(false) || VGet::search()) { $search = '%' . $this->_search . '%'; $to_read['condition_columns'][':search'] = 'post_title'; $to_read['condition_select_types'][':search'] = 'LIKE'; $to_read['condition_values'][':search'] = $search; $to_read['value_types'][':search'] = 'str'; $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'post_status'; $to_read['value_types'][':status'] = 'str'; switch ($this->_status) { case 'all': $to_read['condition_select_types'][':status'] = '!='; $to_read['condition_values'][':status'] = 'trash'; break; default: $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; break; } } elseif (VGet::author()) { $to_read['condition_columns'][':author'] = 'post_author'; $to_read['condition_select_types'][':author'] = '='; $to_read['condition_values'][':author'] = VGet::author(1); $to_read['value_types'][':author'] = 'str'; $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'post_status'; $to_read['condition_select_types'][':status'] = '!='; $to_read['condition_values'][':status'] = 'trash'; $to_read['value_types'][':status'] = 'str'; } elseif ($this->_status != 'all') { $to_read['condition_columns'][':status'] = 'post_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } else { $to_read['condition_columns'][':status'] = 'post_status'; $to_read['condition_select_types'][':status'] = '!='; $to_read['condition_values'][':status'] = 'trash'; $to_read['value_types'][':status'] = 'str'; } //pass $to_read by parameter to have same conditions $this->get_pagination($to_read); $this->get_dates($to_read); $to_read['order'] = array('post_date', 'desc'); $to_read['limit'] = array($this->_limit_start, parent::ITEMS); $this->_content = $this->_db->read($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$value) { $id = $value['POST_ID']; $value = new Post($id); $value->_id = $id; $value->read('_title'); $value->read('_date'); $value->read('_author'); $value->read('_status'); $value->read('_category'); $value->read('_tags'); $value->read('_permalink'); } } $to_read = null; //setting the number of comments per post $to_read['table'] = 'comment'; $to_read['columns'] = array('comment_rel_id'); $comments = $this->_db->read($to_read); if (is_array($comments) && !empty($this->_content)) { foreach ($this->_content as &$article) { $count = 0; foreach ($comments as $comment) { if ($comment['comment_rel_id'] == $article->_id) { $count++; } } $article->_comment = $count; } } elseif (!empty($this->_content)) { foreach ($this->_content as &$article) { $article->_comment = 0; } } unset($comments); //end comments //setting the author username per post via its id if (!empty($this->_content)) { foreach ($this->_content as &$post) { $user = new User(); $user->_id = $post->_author; $user->read('_username'); $post->_author_name = $user->_username; } } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } }
/** * Update an existing post * * @access private */ private function update() { if ($this->check_post_data()) { try { $old = new Post(); $old->_id = $this->_post->_id; $old->read('_status'); //if post move from draft to published, creation date is updated if ($old->_status == 'draft' && $this->_post->_status == 'publish') { $this->_post->_date = date('Y-m-d H:i:s'); $this->_post->update('_date', 'str'); } $this->_post->update('_title', 'str'); $this->_post->update('_content', 'str'); $this->_post->update('_allow_comment', 'str'); $this->_post->update('_date', 'str'); $this->_post->update('_status', 'str'); $this->_post->update('_tags', 'str'); $this->_post->update('_category', 'str'); if ($this->_post->_status == 'publish') { $this->_post->_updated = 'yes'; $this->_post->_update_author = $this->_user['user_id']; $this->_post->update('_updated', 'str'); $this->_post->update('_update_author', 'int'); } $this->_action_msg = ActionMessages::post_update(true); Session::monitor_activity('updated the post "' . $this->_post->_title . '" (status: ' . $this->_post->_status . ')'); } catch (Exception $e) { $this->_action_msg = ActionMessages::post_update(ucfirst($e->getMessage())); } } $this->_action = 'to_update'; }
/** * Retrieve some recent comments pending to be approved * * @access private */ private function get_recent_comments() { if ($this->_user['comments']) { try { $to_read['table'] = 'comment'; $to_read['columns'] = array('COMMENT_ID'); $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = 'pending'; $to_read['value_types'][':status'] = 'str'; $to_read['order'] = array('comment_date', 'DESC'); $to_read['limit'] = array(0, 3); $this->_comments = $this->_db->read($to_read); if (!empty($this->_comments)) { foreach ($this->_comments as &$comment) { $comment = new Comment($comment['COMMENT_ID']); if ($comment->_rel_type == 'post') { $post = new Post(); $post->_id = $comment->_rel_id; $post->read('_title'); $post->read('_permalink'); $comment->_rel_title = $post->_title; $comment->_rel_permalink = 'ctl=posts&news=' . $post->_permalink; } elseif ($comment->_rel_type == 'media') { $media = new Media(); $media->_id = $comment->_rel_id; $media->read('_name'); $comment->_rel_title = $media->_name; $comment->_rel_permalink = 'ctl=albums&album=' . $media->_id; } } } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } }
/** * Retrieve comments from database in function of the status, the type or via a search * * @access private */ private function get_comments() { try { $to_read['table'] = 'comment'; $to_read['columns'] = array('COMMENT_ID'); if (VGet::action() == 'by_type' && VGet::id() && VGet::type() && VGet::comment_status()) { $to_read['condition_columns'][':id'] = 'comment_rel_ID'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = VGet::id(); $to_read['value_types'][':id'] = 'int'; $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } elseif (VPost::search_button(false) || VGet::search()) { $to_read['condition_columns']['group'][':content'] = 'comment_content'; $to_read['condition_select_types'][':content'] = 'LIKE'; $to_read['condition_values'][':content'] = '%' . $this->_search . '%'; $to_read['value_types'][':content'] = 'str'; $to_read['condition_types'][':name'] = 'OR'; $to_read['condition_columns']['group'][':name'] = 'comment_name'; $to_read['condition_select_types'][':name'] = 'LIKE'; $to_read['condition_values'][':name'] = '%' . $this->_search . '%'; $to_read['value_types'][':name'] = 'str'; $to_read['condition_types'][':email'] = 'OR'; $to_read['condition_columns']['group'][':email'] = 'comment_email'; $to_read['condition_select_types'][':email'] = 'LIKE'; $to_read['condition_values'][':email'] = '%' . $this->_search . '%'; $to_read['value_types'][':email'] = 'str'; $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } elseif (VGet::action() == 'edit' && VGet::comment_id()) { $to_read['condition_columns'][':id'] = 'COMMENT_ID'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = VGet::comment_id(); $to_read['value_types'][':id'] = 'int'; } else { $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } //pass $to_read by parameter to have same conditions $this->get_pagination($to_read); $to_read['order'] = array('comment_date', 'desc'); $to_read['limit'] = array($this->_limit_start, parent::ITEMS); $this->_content = $this->_db->read($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$comment) { $comment = new Comment($comment['COMMENT_ID']); if ($comment->_rel_type == 'post') { $post = new Post(); $post->_id = $comment->_rel_id; $post->read('_title'); $post->read('_permalink'); $comment->_rel_title = $post->_title; $comment->_rel_permalink = $post->_permalink; } elseif ($comment->_rel_type == 'media') { $media = new Media(); $media->_id = $comment->_rel_id; $media->read('_name'); $comment->_rel_title = $media->_name; $comment->_rel_permalink = $media->_id; } } } elseif (empty($this->_content) && VGet::action() == 'edit') { $this->_content[0] = new Comment(); throw new Exception('Invalid comment!'); } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } }