/**
  * Retrieve the template list from lynxpress.org
  *
  * @access	private
  */
 private function get_templates()
 {
     try {
         $url = 'http://lynxpress.org/admin/index.php?ns=rpc&action=get_templates';
         if (VPost::search_button(false) && VPost::search(false)) {
             $url .= '&search=' . VPost::search();
         } else {
             $url .= '&limit=10';
         }
         $curl = new Curl($url);
         $this->_templates = json_decode($curl->_content, true);
         if (isset($this->_templates['message'])) {
             throw new Exception($this->_templates['message']);
         }
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         $this->_templates = array();
     }
 }
 /**
  * Display an html table with all retrieved posts
  *
  * @access	private
  */
 private function display_table()
 {
     Html::table('o');
     if (!empty($this->_content)) {
         foreach ($this->_content as $post) {
             $draft_y = null;
             if (($this->_status == 'all' || $this->_status == 'trash') && $post->_status == 'draft') {
                 $draft_y = ' - <span class="bold">Draft</span>';
             }
             $preview = null;
             if ($post->_status == 'draft') {
                 $preview = 'preview=true&';
             }
             if ($this->_status == 'trash') {
                 $actions = Html::mp_restore_link($post->_id);
                 $actions .= Html::mp_delete_link($post->_id);
             } else {
                 $actions = Html::mp_edit_link($post->_id);
                 $actions .= Html::mp_trash_link($post->_id, $this->_status);
                 $actions .= Html::mp_view_link($preview, $post->_permalink, $post->_title);
             }
             $key_cats = explode(',', $post->_category);
             $cats = array();
             foreach ($key_cats as $key) {
                 array_push($cats, ucfirst($this->_categories[$key]));
             }
             $cats = implode(', ', $cats);
             Html::table_row($post->_id, $post->_title, $draft_y, $actions, $post->_author, $post->_author_name, $cats, $post->_tags, $post->_comment, $post->_date);
         }
     } else {
         if (VPost::search_button(false)) {
             $no_post = '<tr><td colspan="7">No post found';
             if ($this->_status == 'trash') {
                 $no_post .= ' in Trash';
             }
             echo $no_post . '</td></tr>';
         } else {
             if (VRequest::post_status() == 'trash') {
                 echo '<tr><td colspan="7">No post in Trash</td></tr>';
             } else {
                 echo '<tr><td colspan="7">There is no post yet.</td></tr>';
             }
         }
     }
     Html::table('c');
 }
 /**
  * Method that display the page
  *
  * @access	public
  */
 public function display_content()
 {
     $this->display_menu();
     if ($this->_user['comments']) {
         echo $this->_action_msg . '<div id="list_wrapper">';
         Html::form('o', 'post', 'index.php?ns=comments&ctl=manage');
         if (VGet::action() == 'edit') {
             $this->display_edit();
         } elseif (VGet::action() == 'reply') {
             $this->display_reply();
         } else {
             $this->display_comment_status();
             if (!empty($this->_content)) {
                 $this->display_actions('top');
                 $this->display_table();
                 $this->display_actions('butt');
                 $this->display_pagination();
             } else {
                 Html::table('o');
                 if (VPost::search_button(false)) {
                     $no_post = '<tr><td colspan="4">No comments found';
                     if ($this->_status == 'trash') {
                         $no_post .= ' in Trash';
                     }
                     echo $no_post . '</td></tr>';
                 } else {
                     echo '<tr><td colspan="4">There is no comments yet.</td></tr>';
                 }
                 Html::table('c');
             }
         }
         echo Helper::datalist('names', $this->_content, '_name');
         Html::form('c');
         echo '</div>';
     } else {
         echo ActionMessages::part_no_perm();
     }
 }
 /**
  * Display a html table with retrieved links
  *
  * @access	private
  */
 private function display_table()
 {
     Html::table('o');
     if (!empty($this->_content)) {
         foreach ($this->_content as $link) {
             Html::table_row($link->_id, $link->_name, $link->_link, $link->_rss_link, $link->_notes, $this->_levels[$link->_priority]);
         }
     } else {
         if (VPost::search_button(false)) {
             echo '<tr><td colspan="6">No link found</td></tr>';
         }
     }
     Html::table('c');
 }
 /**
  * Display an html table with retrieved medias
  *
  * @access	private
  */
 private function display_table()
 {
     Html::mm_table('o');
     if (!empty($this->_medias)) {
         foreach ($this->_medias as $item) {
             switch ($this->_view_type) {
                 case 'image':
                     $fname = basename($item->_permalink);
                     $dirname = dirname($item->_permalink) . '/';
                     $path = $dirname . '150-' . $fname;
                     $links = Html::mm_image_links($dirname, $fname);
                     break;
                 case 'video':
                     $path = 'images/thumb_video.png';
                     $links = Html::mm_video_link($item->_permalink);
                     break;
                 case 'alien':
                     $path = 'images/thumb_alien.png';
                     $links = Html::mm_alien_link($item->_embed_code);
                     break;
             }
             Html::mm_table_row($item->_id, $path, $item->_name, $item->_type, $this->_view_type, $item->_author, $item->_author_name, $item->_date, $links, $this->_view_type);
         }
     } else {
         if (VPost::search_button(false)) {
             echo '<tr><td colspan="4">No media found</td></tr>';
         } else {
             echo '<tr><td colspan="7">There is no media yet.</td></tr>';
         }
     }
     Html::mm_table('c');
 }
 /**
  * Retrieve albums from the database
  *
  * @access	private
  */
 private function get_albums()
 {
     try {
         $to_read['table'] = 'media';
         $to_read['columns'] = array('MEDIA_ID');
         $to_read['condition_columns'][':t'] = 'media_type';
         $to_read['condition_select_types'][':t'] = '=';
         $to_read['condition_values'][':t'] = 'album';
         $to_read['value_types'][':t'] = 'str';
         $to_read['order'] = array('media_date', 'DESC');
         if (VRequest::filter(false)) {
             if (VRequest::date() != 'all') {
                 $to_read['condition_types'][':d'] = 'AND';
                 $to_read['condition_columns'][':d'] = 'media_date';
                 $to_read['condition_select_types'][':d'] = 'LIKE';
                 $to_read['condition_values'][':d'] = VRequest::date('1970-01') . '%';
                 $to_read['value_types'][':d'] = 'str';
             }
             if (VRequest::category() != 'all') {
                 $to_read['condition_types'][':c'] = 'AND';
                 $to_read['condition_columns'][':c'] = 'media_category';
                 $to_read['condition_select_types'][':c'] = 'LIKE';
                 $to_read['condition_values'][':c'] = '%' . VRequest::category() . '%';
                 $to_read['value_types'][':c'] = 'str';
             }
         } elseif (VPost::search_button(false) || VGet::search()) {
             $to_read['condition_types'][':n'] = 'AND';
             $to_read['condition_columns'][':n'] = 'media_name';
             $to_read['condition_select_types'][':n'] = 'LIKE';
             $to_read['condition_values'][':n'] = '%' . $this->_search . '%';
             $to_read['value_types'][':n'] = 'str';
         } elseif ((VGet::action() == 'edit' || VGet::action() == 'upload' || VGet::action() == 'edit_image') && VGet::id()) {
             $to_read['condition_types'][':id'] = 'AND';
             $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';
             if (VGet::action() == 'edit') {
                 $this->get_pictures();
             } elseif (VGet::action() == 'edit_image' && VGet::pid()) {
                 $this->get_picture();
             }
         }
         //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->_albums = $this->_db->read($to_read);
         if (!empty($this->_albums)) {
             foreach ($this->_albums as &$album) {
                 $album = new Media($album['MEDIA_ID']);
                 $user = new User();
                 $user->_id = $album->_author;
                 $user->read('_username');
                 $album->_author_name = $user->_username;
             }
         } elseif (empty($this->_content) && (VGet::action() == 'edit' || VGet::action() == 'upload')) {
             $this->_albums[0] = new Media();
             throw new Exception('Invalid album!');
         }
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }