/** * Retrieve all activity saved in database * * @access private */ private function get_content() { try { $to_read['table'] = 'activity'; $to_read['columns'] = array('*'); $to_read['order'] = array('date', 'DESC'); $this->_activity = $this->_db->read($to_read); if (!empty($this->_activity)) { foreach ($this->_activity as &$value) { $user = new User(); $user->_id = $value['USER_ID']; $user->read('_username'); $user->read('_email'); $value['username'] = $user->_username; $value['email'] = $user->_email; } } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } }
/** * Retrieve Albums from the database * * @access private */ private function get_content() { try { $to_read['table'] = $this->_sql_table; $to_read['columns'] = array('MEDIA_ID'); if (VGet::album()) { $to_read['condition_columns'][':album'] = 'media_album'; $to_read['condition_select_types'][':album'] = '='; $to_read['condition_values'][':album'] = VGet::album(); $to_read['value_types'][':album'] = 'str'; $to_read['order'] = array('media_name', 'ASC'); $this->_album = new Media(VGet::album()); $user = new User(); $user->_id = $this->_album->_author; $user->read('_publicname'); $this->_album->_author_name = $user->_publicname; } elseif (VGet::cat()) { $to_read['condition_columns'][':cat'] = 'media_category'; $to_read['condition_select_types'][':cat'] = 'LIKE'; $to_read['condition_values'][':cat'] = '%' . VGet::cat() . '%'; $to_read['value_types'][':cat'] = 'str'; $to_read['condition_types'][':type'] = 'AND'; $to_read['condition_columns'][':type'] = 'media_type'; $to_read['condition_select_types'][':type'] = '='; $to_read['condition_values'][':type'] = 'album'; $to_read['value_types'][':type'] = 'str'; $to_read['order'] = array('media_date', 'DESC'); } else { $to_read['condition_columns'][':type'] = 'media_type'; $to_read['condition_select_types'][':type'] = '='; $to_read['condition_values'][':type'] = 'album'; $to_read['value_types'][':type'] = 'str'; $to_read['order'] = array('media_date', 'DESC'); } $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'media_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = 'publish'; $to_read['value_types'][':status'] = 'str'; $this->_content = $this->_db->read($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$element) { $element = new Media($element['MEDIA_ID']); } } elseif (empty($this->_content) && VGet::album()) { header('Location: 404.php'); } } catch (Exception $e) { @error_log($e->getMessage() . ' file: ' . __FILE__ . '; line: ' . __LINE__, 1, WS_EMAIL); header('Location: 404.php'); } }
/** * 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()); } }
/** * Retrieve admin side logged activity * * @access private */ private function get_activity() { if ($this->_user['settings']) { try { $to_read['table'] = 'activity'; $to_read['columns'] = array('USER_ID', 'data', 'date'); $to_read['limit'] = array(0, 10); $to_read['order'] = array('date', 'desc'); $this->_activity = $this->_db->read($to_read); if (!empty($this->_activity)) { foreach ($this->_activity as &$act) { $user = new User(); $user->_id = $act['USER_ID']; $user->read('_username'); $act['name'] = $user->_username; } } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } }
/** * Create a comment on a distant website * * @access private */ private function create() { if (VPost::submit(false) && VPost::content(false)) { try { $user = new User(); $user->_id = $this->_user['user_id']; $user->read('_publicname'); $user->read('_email'); $data = array('name' => $user->_publicname, 'email' => $user->_email, 'content' => VPost::content(), 'id' => $this->_content['post']['POST_ID'], 'type' => 'post'); $url = $this->_prefs->_data['timeline'][$this->_key]['url'] . 'admin/index.php?ns=rpc&ctl=comment'; $curl = new Curl(); $curl->_post = true; $curl->_data = $data; $curl->_url = $url; $curl->connect(); $msg = json_decode($curl->_content, true); if ($msg['message'] !== true) { throw new Exception('Error on distant website! ' . $this->_prefs->_data['timeline'][$this->_key]['title'] . ' says "' . $msg['message'] . '"'); } $this->_action_msg = ActionMessages::custom_good('Comment submitted'); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } }
/** * Retrieve wanted posts * * @access private */ private function get_content() { try { $to_read['table'] = $this->_sql_table; $to_read['columns'] = array('POST_ID'); $to_read['condition_columns'][':s'] = 'post_status'; $to_read['condition_select_types'][':s'] = '='; $to_read['condition_values'][':s'] = 'publish'; $to_read['value_types'][':s'] = 'str'; if ($this->_view_type == 'news') { $to_read['condition_types'][':p'] = 'AND'; $to_read['condition_columns'][':p'] = 'post_permalink'; $to_read['condition_select_types'][':p'] = '='; $to_read['condition_values'][':p'] = VGet::news(); $to_read['value_types'][':p'] = 'str'; } if (VGet::preview()) { $to_read['condition_values'][':s'] = 'draft'; } $to_read['order'] = array('post_date', 'DESC'); $to_read['limit'] = array($this->_limit_start, parent::ITEMS_PAGE); $this->_content = $this->_db->read($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$post) { $post = new Post($post['POST_ID']); $user = new User(); $user->_id = $post->_author; $user->read('_publicname'); $post->_author_name = $user->_publicname; $updated = $post->_updated; if ($updated == 'yes') { $user->_id = $post->_update_author; $user->read('_publicname'); $post->_update_author_name = $user->_publicname; } } } elseif (empty($this->_content) && $this->_view_type == 'news' && !VGet::preview()) { header('Location: 404.php'); } } catch (Exception $e) { @error_log($e->getMessage() . ' file: ' . __FILE__ . '; line: ' . __LINE__, 1, WS_EMAIL); header('Location: 404.php'); } }
/** * Retrieve a post from a given permalink, and with associated comments * * @access private */ private function get_content() { try { $to_read['table'] = 'post'; $to_read['columns'] = array('POST_ID', 'post_title', 'post_content', 'post_allow_comment', 'post_date', 'post_author'); $to_read['condition_columns'][':p'] = 'post_permalink'; $to_read['condition_select_types'][':p'] = '='; $to_read['condition_values'][':p'] = $this->_slug; $to_read['value_types'][':p'] = 'str'; $to_read['condition_types'][':s'] = 'AND'; $to_read['condition_columns'][':s'] = 'post_status'; $to_read['condition_select_types'][':s'] = '='; $to_read['condition_values'][':s'] = 'publish'; $to_read['value_types'][':s'] = 'str'; $post = $this->_db->read($to_read); if (empty($post)) { throw new Exception('No post found!'); } $user = new User(); $user->_id = $post[0]['post_author']; $user->read('_publicname'); $post[0]['post_author'] = $user->_publicname; $this->_content['post'] = $post[0]; if ($post[0]['post_allow_comment'] == 'open') { $to_read = null; $to_read['table'] = 'comment'; $to_read['columns'] = array('comment_name', 'comment_content', 'comment_date'); $to_read['condition_columns'][':r'] = 'comment_rel_id'; $to_read['condition_select_types'][':r'] = '='; $to_read['condition_values'][':r'] = $post[0]['POST_ID']; $to_read['value_types'][':r'] = 'int'; $to_read['condition_types'][':t'] = 'AND'; $to_read['condition_columns'][':t'] = 'comment_rel_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'post'; $to_read['value_types'][':t'] = 'str'; $to_read['condition_types'][':s'] = 'AND'; $to_read['condition_columns'][':s'] = 'comment_status'; $to_read['condition_select_types'][':s'] = '='; $to_read['condition_values'][':s'] = 'approved'; $to_read['value_types'][':s'] = 'str'; $to_read['order'] = array('comment_date', 'DESC'); $this->_content['comments'] = $this->_db->read($to_read); } else { $this->_content['comments'] = array(); } } catch (Exception $e) { $this->_content = array('message' => $e->getMessage()); } }
/** * Retrieve wanted posts from the database * * @access private */ private function get_content() { try { $to_read['table'] = $this->_sql_table; $to_read['columns'] = array('POST_ID'); if (!empty($this->_search)) { foreach ($this->_words_to_find as $key => $word) { $search = '%' . $word . '%'; $to_read['condition_types'][":title{$key}"] = 'OR'; $to_read['condition_columns']['group'][":title{$key}"] = 'post_title'; $to_read['condition_select_types'][":title{$key}"] = 'LIKE'; $to_read['condition_values'][":title{$key}"] = $search; $to_read['value_types'][":title{$key}"] = 'str'; $to_read['condition_types'][":content{$key}"] = 'OR'; $to_read['condition_columns']['group'][":content{$key}"] = 'post_content'; $to_read['condition_select_types'][":content{$key}"] = 'LIKE'; $to_read['condition_values'][":content{$key}"] = $search; $to_read['value_types'][":content{$key}"] = 'str'; } } elseif (!empty($this->_tag)) { $to_read['condition_columns'][':tag'] = 'post_tags'; $to_read['condition_select_types'][':tag'] = 'LIKE'; $to_read['condition_values'][':tag'] = '%' . $this->_tag . '%'; $to_read['value_types'][':tag'] = 'str'; } elseif (!empty($this->_cat)) { $to_read['condition_columns'][':cat'] = 'post_category'; $to_read['condition_select_types'][':cat'] = 'LIKE'; $to_read['condition_values'][':cat'] = '%' . $this->_cat . '%'; $to_read['value_types'][':cat'] = 'str'; } elseif (!empty($this->_by_date)) { $to_read['condition_columns'][':date'] = 'post_date'; $to_read['condition_select_types'][':date'] = 'LIKE'; $to_read['condition_values'][':date'] = $this->_by_date . '%'; $to_read['value_types'][':date'] = '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'] = 'publish'; $to_read['value_types'][':status'] = 'str'; $to_read['limit'] = array($this->_limit_start, parent::ITEMS_PAGE); $to_read['order'] = array('post_date', 'DESC'); $this->_content = $this->_db->read($to_read); $this->get_nb_pages($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$post) { $post = new Post($post['POST_ID']); $user = new User(); $user->_id = $post->_author; $user->read('_publicname'); $post->_author_name = $user->_publicname; $updated = $post->__get('_updated'); if ($updated == 'yes') { $user->_id = $post->_update_author; $user->read('_publicname'); $post->_update_author_name = $user->_publicname; } } } } catch (Exception $e) { @error_log($e->getMessage() . ' file: ' . __FILE__ . '; line: ' . __LINE__, 1, WS_EMAIL); header('Location: 404.php'); } }
/** * Retrieve wanted medias metadata from the database * * @access private */ private function get_medias() { try { $to_read['table'] = 'media'; $to_read['columns'] = array('MEDIA_ID'); if (VPost::search_button(false) || VGet::search()) { $to_read['condition_columns'][':name'] = 'media_name'; $to_read['condition_select_types'][':name'] = 'LIKE'; $to_read['condition_values'][':name'] = '%' . $this->_search . '%'; $to_read['value_types'][':name'] = 'str'; } elseif (VRequest::filter(false)) { if (VRequest::date('all') !== 'all') { $to_read['condition_columns'][':date'] = 'media_date'; $to_read['condition_select_types'][':date'] = 'LIKE'; $to_read['condition_values'][':date'] = VRequest::date('1970-01') . '%'; $to_read['value_types'][':date'] = 'str'; } if (VRequest::category('all') !== 'all') { $to_read['condition_types'][':cat'] = 'AND'; $to_read['condition_columns'][':cat'] = 'media_category'; $to_read['condition_select_types'][':cat'] = 'LIKE'; $to_read['condition_values'][':cat'] = '%' . VRequest::category() . '%'; $to_read['value_types'][':cat'] = 'str'; } } elseif (VGet::action() == 'edit' && VGet::id()) { $to_read['condition_columns'][':id'] = 'MEDIA_ID'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = VGet::id(); $to_read['value_types'][':id'] = 'int'; } elseif (VGet::author()) { $to_read['condition_columns'][':author'] = 'media_author'; $to_read['condition_select_types'][':author'] = '='; $to_read['condition_values'][':author'] = VGet::author(); $to_read['value_types'][':author'] = 'int'; } $to_read['condition_types'][':type'] = 'AND'; $to_read['condition_columns'][':type'] = 'media_type'; $to_read['condition_select_types'][':type'] = 'LIKE'; $to_read['condition_values'][':type'] = $this->_view_type . '%'; $to_read['value_types'][':type'] = 'str'; $to_read['condition_types'][':album'] = 'AND'; $to_read['condition_columns'][':album'] = 'media_album'; $to_read['condition_select_types'][':album'] = '='; $to_read['condition_values'][':album'] = '0'; $to_read['value_types'][':album'] = 'int'; //pass $to_read by parameter to have same conditions $this->get_pagination($to_read); $this->get_dates($to_read); $to_read['order'] = array('media_date', 'desc'); $to_read['limit'] = array($this->_limit_start, parent::ITEMS); $this->_medias = $this->_db->read($to_read); if (!empty($this->_medias)) { foreach ($this->_medias as &$item) { $item = new Media($item['MEDIA_ID']); $user = new User(); $user->_id = $item->_author; $user->read('_username'); $item->_author_name = $user->_username; } } elseif (empty($this->_medias) && VGet::action() == 'edit') { throw new Exception('Invalid media!'); } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); $this->_medias = null; $this->_medias[0] = new Media(); } }
/** * Retrieve all pictures attached to an album when you're in album edit view * * @access private */ private function get_pictures() { try { $to_read['table'] = 'media'; $to_read['columns'] = array('MEDIA_ID'); $to_read['condition_columns'][':id'] = 'media_album'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = VGet::id(); $to_read['value_types'][':id'] = 'int'; $to_read['order'] = array('media_name', 'ASC'); $this->_pictures = $this->_db->read($to_read); if (!empty($this->_pictures)) { foreach ($this->_pictures as &$pic) { $pic = new Media($pic['MEDIA_ID']); $user = new User(); $user->_id = $pic->_author; $user->read('_username'); $pic->_author_name = $user->_username; } } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } }
/** * Retrieve video metadatas from database * * @access private */ private function get_content() { try { $to_read['table'] = $this->_sql_table; $to_read['columns'] = array('MEDIA_ID'); $to_read['condition_columns'][':t'] = 'media_type'; $to_read['condition_select_types'][':t'] = 'LIKE'; $to_read['condition_values'][':t'] = 'video%'; $to_read['value_types'][':t'] = 'str'; $to_read['condition_types'][':s'] = 'AND'; $to_read['condition_columns'][':s'] = 'media_status'; $to_read['condition_select_types'][':s'] = '='; $to_read['condition_values'][':s'] = 'publish'; $to_read['value_types'][':s'] = 'str'; if (VGet::cat(false)) { $to_read['condition_types'][':cat'] = 'AND'; $to_read['condition_columns'][':cat'] = 'media_category'; $to_read['condition_select_types'][':cat'] = 'LIKE'; $to_read['condition_values'][':cat'] = '%' . VGet::cat() . '%'; $to_read['value_types'][':cat'] = 'str'; } $this->_content = $this->_db->read($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$media) { $media = new Media($media['MEDIA_ID']); //retrieve user public name $user = new User(); $user->_id = $media->_author; $user->read('_publicname'); $media->_author_publicname = $user->_publicname; $attached = $media->_attachment; if (!empty($attached)) { $attach = new Media(); $attach->_id = $media->_attachment; $attach->read('_embed_code'); $media->_embed_code = $attach->_embed_code; } } } } catch (Exception $e) { @error_log($e->getMessage() . ' file: ' . __FILE__ . '; line: ' . __LINE__, 1, WS_EMAIL); header('Location: 404.php'); } }