/**
  * Class constructor
  *
  * @access	public
  */
 public function __construct()
 {
     parent::__construct();
     $this->_key = VGet::website();
     $this->_slug = VGet::slug();
     $this->get_prefs();
     $this->get_post();
     $this->build_title();
     $this->create();
 }
 /**
  * Display a pagination, for listings controllers
  *
  * @static
  * @access	public
  * @param	integer [$p] Current page
  * @param	integer [$max] Maximum pages available
  * @param	string [$link] Additional GET parameter, if in a search
  * @param	string [$text] Text to display after older/newest
  */
 public static function pagination($p, $max, $link, $text)
 {
     echo '<nav id="pagination">';
     if ($p < $max) {
         echo '<a class="a_button" href="index.php?ns=' . VGet::ns() . '&ctl=' . VGet::ctl('manage') . $link . '&p=' . ($p + 1) . '">Older ' . $text . '</a>';
     }
     if ($p > 1) {
         echo '<a class="a_button" href="index.php?ns=' . VGet::ns() . '&ctl=' . VGet::ctl('manage') . $link . '&p=' . ($p - 1) . '">Newest ' . $text . '</a>';
     }
     echo '</nav>';
 }
 /**
  * Retrieve content depending of xml type wanted
  *
  * @access	private
  */
 private function get_content()
 {
     if ($this->_type == 'rss') {
         $to_read['table'] = 'post';
         $to_read['columns'] = array('POST_ID AS guid', 'post_title AS title', 'post_content AS description', 'post_date AS pubDate', 'post_author AS author', 'post_permalink AS link');
         $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 (VGet::cat()) {
             $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'] = '%' . VGet::cat() . '%';
             $to_read['value_types'][':cat'] = 'str';
         }
         $this->_content = $this->_db->read($to_read);
         if (!empty($this->_content)) {
             foreach ($this->_content as &$value) {
                 $user = new User($value['author']);
                 $value['author'] = $user->_publicname;
                 $value['title'] = htmlspecialchars($value['title']);
                 $value['description'] = htmlspecialchars(substr($value['description'], 0, 200));
             }
         }
     } elseif ($this->_type == 'sitemap') {
         $to_read['table'] = 'post';
         $to_read['columns'] = array('post_permalink AS SPLink', 'post_date AS SPPubDate');
         $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';
         $this->_content = $this->_db->read($to_read);
         $to_read = null;
         $to_read['table'] = 'media';
         $to_read['columns'] = array('MEDIA_ID AS SMLink', 'media_date AS SMPubDate');
         $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['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';
         $media = $this->_db->read($to_read);
         if (!empty($media)) {
             foreach ($media as $value) {
                 array_push($this->_content, $value);
             }
         }
     }
 }
 /**
  * Create a link object if in edit mode, else create an empty link object
  *
  * @access	private
  */
 private function get_link()
 {
     if ($this->_view_type == 'edit') {
         try {
             $this->_link = new Link(VGet::id());
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
             $this->_link = new Link();
         }
     } else {
         $this->_link = new Link();
     }
 }
 public function __construct()
 {
     $this->_display_html = false;
     if (VGet::loggedout()) {
         $this->_msg = ActionMessages::custom_good('You\'ve been logged out');
     }
     try {
         $this->_session = new Session();
         if (VPost::login(false)) {
             $this->_session->login();
         }
     } catch (Exception $e) {
         $this->_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Class constructor
  *
  * @access	public
  */
 public function __construct()
 {
     parent::__construct();
     if (VGet::view() && in_array(VGet::view(), array('upload', 'linkage', 'album', 'video'))) {
         $this->_view_type = VGet::view();
     } else {
         $this->_view_type = 'upload';
     }
     if ($this->_view_type == 'album') {
         Helper::get_categories($this->_categories, $this->_action_msg, 'album');
     }
     $this->build_title();
     $this->_media = new Media();
     if ($this->_user['media']) {
         $this->create();
     }
 }
 /**
  * Class constructor
  *
  * @access	public
  */
 public function __construct()
 {
     parent::__construct();
     try {
         $this->_slug = VGet::slug();
         if (empty($this->_slug)) {
             throw new Exception('No permalink found!');
         }
         $this->_url = 'cache/post/' . $this->_slug . '.json';
         if ($this->check_cache() === false) {
             $this->get_content();
             $cache = new File();
             $cache->_content = json_encode($this->_content);
             $cache->save($this->_url);
         } else {
             $cache = File::read($this->_url);
             $this->_content = json_decode($cache->_content, true);
         }
     } catch (Exception $e) {
         $this->_content = array('message' => $e->getMessage());
     }
 }
 /**
  * Method to build the complement link for navigation
  *
  * @access	protected
  * @return	string
  */
 protected function link_navigation()
 {
     switch ($this->_pid) {
         case 'posts':
             $link = 'ctl=posts&';
             break;
         case 'search':
             if (VGet::tag()) {
                 $link = 'ctl=search&tag=' . VGet::tag() . '&';
             } elseif (VGet::cat()) {
                 $link = 'ctl=search&cat=' . VGet::cat() . '&';
             } else {
                 $link = 'ctl=search&q=' . VGet::q() . '&';
             }
             break;
         default:
             $link = 'ctl=' . $this->_pid . '&';
             break;
     }
     return $link;
 }
 /**
  * Retrieve all user data
  *
  * If the user is not a valid one, an empty user object is created
  *
  * to avoid problems calling html elements
  *
  * @access	private
  */
 private function get_user()
 {
     try {
         if (VGet::id() && $this->_user['settings']) {
             $this->_profile = new User(VGet::id());
         } else {
             $this->_profile = new User($this->_user['user_id']);
         }
         $this->build_avatar();
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         $this->_profile = new User();
         $this->_profile->_id = $this->_user['user_id'];
     }
 }
 /**
  * Display page content
  *
  * @access	public
  */
 public function display_content()
 {
     if (!empty($this->_album) && VGet::comments(false) !== false) {
         $this->display_comments();
     } elseif (!empty($this->_album)) {
         $this->display_album();
     } else {
         $this->display_albums();
     }
 }
 /**
  * Delete medias from database and on hard drive
  *
  * @access	private
  */
 private function delete()
 {
     if ($this->_user['delete_content'] && VPost::delete(false) && VPost::media_id()) {
         $results = array();
         $global_result = true;
         foreach (VPost::media_id() as $id) {
             try {
                 $media = new Media();
                 $media->_id = $id;
                 $media->read('_permalink');
                 $path = $media->_permalink;
                 $media->delete();
                 unset($media);
                 HandleMedia::delete(PATH . $path);
                 $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $id . ' AND comment_rel_type = "media"');
                 if (VPost::type() == 'alien') {
                     $to_update['table'] = 'media';
                     $to_update['columns'] = array(':attach' => 'media_attachment');
                     $to_update['condition_columns'] = array(':ca' => 'media_attachment');
                     $to_update['column_values'] = array(':attach' => null, ':ca' => $id);
                     $to_update['value_types'] = array(':attach' => 'null', ':ca' => 'int');
                     $this->_db->update($to_update);
                 }
                 array_push($results, true);
             } catch (Exception $e) {
                 array_push($results, false);
             }
         }
         foreach ($results as $result) {
             if ($result !== true) {
                 $global_result = false;
             }
         }
         Session::monitor_activity('deleted ' . count(VPost::media_id()) . ' file(s)');
         $this->_action_msg = ActionMessages::deleted($global_result);
     } elseif ($this->_user['delete_content'] && VGet::action() == 'delete' && VGet::id()) {
         try {
             $media = new Media();
             $media->_id = VGet::id();
             $media->read('_permalink');
             $path = $media->_permalink;
             $media->delete();
             unset($media);
             HandleMedia::delete(PATH . $path);
             $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . VGet::id() . ' AND comment_rel_type = "media"');
             if (VGet::type() == 'alien') {
                 $to_update['table'] = 'media';
                 $to_update['columns'] = array(':attach' => 'media_attachment');
                 $to_update['condition_columns'] = array(':ca' => 'media_attachment');
                 $to_update['column_values'] = array(':attach' => null, ':ca' => VGet::id());
                 $to_update['value_types'] = array(':attach' => 'null', ':ca' => 'int');
                 $this->_db->update($to_update);
             }
             Session::monitor_activity('deleted a file');
             $result = true;
         } catch (Exception $e) {
             error_log($e->getMessage(), 0);
             $result = false;
         }
         $this->_action_msg = ActionMessages::deleted($result);
     } elseif (!$this->_user['delete_content'] && (VPost::delete(false) || VGet::action() == 'delete')) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 /**
  * Delete files on hard drive and metadata in database
  *
  * @access	private
  */
 private function delete()
 {
     if (VPost::apply_action(false) && VPost::action() == 'delete' && $this->_user['delete_content']) {
         if (VPost::album_id()) {
             try {
                 foreach (VPost::album_id() as $id) {
                     $album = new Media();
                     $album->_id = $id;
                     $album->read('_permalink');
                     $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'] = $id;
                     $to_read['value_types'][':id'] = 'int';
                     $ids = $this->_db->read($to_read);
                     if (!empty($ids)) {
                         foreach ($ids as $pid) {
                             $pic = new Media();
                             $pic->_id = $pid['MEDIA_ID'];
                             $pic->read('_permalink');
                             $permalink = $pic->_permalink;
                             HandleMedia::delete(PATH . $permalink);
                             $pic->delete();
                         }
                     }
                     $permalink = $album->_permalink;
                     HandleMedia::delete(PATH . $permalink . 'cover.png');
                     @rmdir(PATH . $permalink);
                     $album->delete();
                     $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $id . ' AND comment_rel_type = "media"');
                 }
                 Session::monitor_activity('deleted ' . count(VPost::album_id()) . ' album(s)');
                 $result = true;
             } catch (Exception $e) {
                 $result = $e->getMessage();
             }
             $this->_action_msg = ActionMessages::deleted($result);
         }
     } elseif (VGet::action() == 'delete' && VGet::id() && $this->_user['delete_content']) {
         try {
             $pic = new Media();
             $pic->_id = VGet::id();
             $pic->read('_permalink');
             $permalink = $pic->_permalink;
             HandleMedia::delete(PATH . $permalink);
             $pic->delete();
             $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . VGet::id() . ' AND comment_rel_type = "media"');
             Session::monitor_activity('deleted a picture of an album');
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::deleted($result);
     } elseif (VPost::delete_pics(false)) {
         if (VPost::picture_id()) {
             try {
                 foreach (VPost::picture_id() as $id) {
                     $pic = new Media();
                     $pic->_id = $id;
                     $pic->read('_permalink');
                     $permalink = $pic->_permalink;
                     HandleMedia::delete(PATH . $permalink);
                     $pic->delete();
                 }
                 Session::monitor_activity('deleted ' . count(VPost::picture_id(array())) . ' picture(s) of an album');
                 $result = true;
             } catch (Exception $e) {
                 $result = $e->getMessage();
             }
         }
     } elseif ((VPost::apply_action(false) && VPost::action() == 'delete' || VGet::action() == 'delete' || VPost::delete_pics(false)) && !$this->_user['delete_content']) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 /**
  * Check if current controller can display an archive list
  *
  * @static
  * @access	public
  * @return	boolean
  */
 public static function check_pub_dates()
 {
     if (in_array(VGet::ctl(), array('posts', 'search'))) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Method to determine page number and associated limit for sql queries
  *
  * @static
  * @access	public
  * @param	integer [$items] Items number per page
  * @return	array
  */
 public static function pagination($items)
 {
     if (!VGet::p()) {
         $limit_start = 0;
         $page = 1;
     } else {
         if (VGet::p() < 1) {
             $page = 1;
         } else {
             $page = VGet::p();
         }
         $limit_start = ($page - 1) * $items;
     }
     return array($page, $limit_start);
 }
 /**
  * Retrieve the timeline of a website
  *
  * @access	private
  */
 private function get_timeline()
 {
     try {
         $site = VGet::website();
         if (!empty($site) || $site === 0) {
             $this->_key = VGet::website();
         } else {
             $data = $this->_prefs->_data['timeline'];
             reset($data);
             $this->_key = key($data);
         }
         if (empty($this->_prefs->_data['timeline'])) {
             throw new Exception('No website in your preferences!');
         }
         if (!isset($this->_prefs->_data['timeline'][$this->_key])) {
             throw new Exception('Requested website not found!');
         }
         $url = $this->_prefs->_data['timeline'][$this->_key]['url'] . 'admin/index.php?ns=rpc&ctl=timeline&since=' . $this->_since;
         $curl = new Curl($url);
         $this->_timeline = json_decode($curl->_content, true);
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Build cache
  *
  * Exceptions of the exist method continue here
  * So cache generation is stopped if its not a landing page or
  * when we are on an album comments page and also when a form
  * has been submitted
  *
  * @access	public
  * @param	string [$action] Can be "s" or "e" (meaning start or end)
  */
 public function build($action)
 {
     if (self::ACTIVATED === false) {
         return false;
     }
     if ((!empty($this->_post) || count($this->_get) > 1) && !in_array(VGet::ctl(), array('search', 'albums'))) {
         return true;
     } elseif (VGet::ctl() == 'albums' && VGet::comments()) {
         return true;
     }
     if ($action == 's') {
         ob_start();
     } elseif ($action == 'e') {
         $content = ob_get_contents();
         ob_end_flush();
         $cache = new File();
         $cache->_content = $content;
         $cache->save($this->_url);
     } else {
         throw new Exception('Unknown cache command');
     }
 }
 /**
  * Display page content
  *
  * @access	public
  */
 public function display_content()
 {
     Html::header_authors(VGet::author());
     if (!empty($this->_content)) {
         if (!VSession::html5()) {
             echo '<ul id="authors">';
         }
         foreach ($this->_content as $user) {
             Html::author($user->_publicname, $user->_email, $user->_website, $user->_msn, $user->_twitter, $user->_facebook, $user->_google, $user->_avatar, $user->_bio);
         }
         if (!VSession::html5()) {
             echo '</ul>';
         }
     } else {
         Html::no_content('Wanted user doesn\'t exist');
     }
 }
 /**
  * Extract wanted words and set them in associated attributes
  *
  * @access	private
  */
 private function build_search()
 {
     if (substr(VGet::q(), 0, 4) == 'date') {
         $this->_by_date = trim(substr(VGet::q(), 5));
     } elseif (VGet::q()) {
         $this->_words_to_find = array_unique(explode(' ', trim(VGet::q())));
         $this->_search = implode(' ', $this->_words_to_find);
     } elseif (VGet::tag()) {
         $this->_tag = VGet::tag();
     } elseif (VGet::cat()) {
         $this->_cat = VGet::cat();
     } else {
         header('Location: 404.php');
     }
 }
 /**
  * Method that permits to delete one or more comments at a time
  *
  * @access	private
  */
 private function delete()
 {
     if ((isset($_POST['empty']) || VRequest::action() == 'delete') && $this->_user['delete_content']) {
         if (isset($_POST['empty']) && VPost::comment_status() && in_array(VPost::comment_status(), array('spam', 'trash'))) {
             $to_delete['table'] = 'comment';
             $to_delete['condition_columns'][':status'] = 'comment_status';
             $to_delete['condition_values'][':status'] = VPost::comment_status();
             $to_delete['value_types'][':status'] = 'str';
             $global_result = $this->_db->delete($to_delete);
         } elseif (VPost::action() == 'delete' && VPost::comment_id()) {
             $results = array();
             $global_result = true;
             foreach (VPost::comment_id() as $id) {
                 try {
                     $comment = new Comment();
                     $comment->_id = $id;
                     $comment->delete();
                     unset($comment);
                     array_push($results, true);
                 } catch (Exception $e) {
                     array_push($results, false);
                 }
             }
             foreach ($results as $result) {
                 if ($result !== true) {
                     $global_result = false;
                 }
             }
         } elseif (VGet::action() == 'delete' && VGet::comment_id()) {
             try {
                 $comment = new Comment();
                 $comment->_id = VGet::comment_id();
                 $comment->delete();
                 $global_result = true;
             } catch (Exception $e) {
                 $global_result = false;
             }
         }
         if (isset($global_result)) {
             $this->_action_msg = ActionMessages::deleted($global_result);
         }
     } elseif ((isset($POST['empty']) || VRequest::action() == 'delete') && $this->_user['delete_content'] === false) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 /**
  * Install a plugin from github
  *
  * @access	private
  */
 private function create()
 {
     if (VGet::action() == 'install' && VGet::user() && VGet::repo() && VGet::download()) {
         try {
             $curl = new Curl('https://api.github.com/repos/' . VGet::user() . '/' . VGet::repo() . '/downloads');
             $downloads = json_decode($curl->_content, true);
             if (empty($downloads)) {
                 throw new Exception('Archive doesn\'t exist on Github');
             }
             if (isset($downloads['message'])) {
                 throw new Exception($downloads['message']);
             }
             $url = null;
             foreach ($downloads as $download) {
                 if ($download['name'] == VGet::download()) {
                     if ($download['content_type'] != 'application/zip') {
                         throw new Exception('Invalid archive type! (.zip only)');
                     } else {
                         $url = $download['html_url'];
                     }
                 }
             }
             unset($curl);
             $curl = new Curl($url);
             $zip = new File();
             $zip->_content = $curl->_content;
             $zip->save('tmp/plugin.zip');
             $tmp = 'tmp/plg_' . md5_file('tmp/plugin.zip') . '/';
             File::unzip('tmp/plugin.zip', $tmp);
             File::delete('tmp/plugin.zip');
             $json = File::read($tmp . 'manifest.json');
             $conf = json_decode($json->_content, true);
             //check if manifest is complete
             if (!isset($conf['name']) || !isset($conf['namespace']) || !isset($conf['entry_point']) || !isset($conf['author']) || !isset($conf['url']) || !isset($conf['admin']) || !isset($conf['site']) || !isset($conf['library']) || !isset($conf['queries']) || !isset($conf['uninstall'])) {
                 throw new Exception('Invalid manifest');
             }
             if (is_dir('includes/' . $conf['namespace']) || is_dir('library/' . $conf['namespace'])) {
                 throw new Exception('The namespace "' . $conf['namespace'] . '" is already taken');
             }
             //if one of files doesn't exists, an exception will be raised
             foreach ($conf['admin'] as $file) {
                 File::read($tmp . 'admin/' . $file);
             }
             //if one of files doesn't exists, an exception will be raised
             foreach ($conf['site'] as $file) {
                 if (file_exists(PATH . 'includes/' . $file)) {
                     throw new Exception('The file "' . $file . '" already exists in site directory');
                 }
                 File::read($tmp . 'site/' . $file);
             }
             //if one of files doesn't exists, an exception will be raised
             foreach ($conf['library'] as $file) {
                 File::read($tmp . 'library/' . $file);
             }
             foreach ($conf['admin'] as $file) {
                 File::move($tmp . 'admin/' . $file, 'includes/' . $conf['namespace'] . '/' . $file);
                 File::delete($tmp . 'admin/' . $file);
             }
             foreach ($conf['site'] as $file) {
                 File::move($tmp . 'site/' . $file, PATH . 'includes/' . $file);
                 File::delete($tmp . 'site/' . $file);
             }
             foreach ($conf['library'] as $file) {
                 File::move($tmp . 'library/' . $file, 'library/' . $conf['namespace'] . '/' . $file);
                 File::delete($tmp . 'library/' . $file);
             }
             if (isset($conf['css'])) {
                 foreach ($conf['css'] as $file) {
                     File::move($tmp . 'css/' . $file, PATH . 'css/' . $conf['namespace'] . '.css');
                     File::delete($tmp . 'css/' . $file);
                 }
             }
             foreach ($conf['queries'] as $query) {
                 $this->_db->query(str_replace('{{prefix}}', DB_PREFIX, $query));
             }
             File::delete($tmp . 'manifest.json');
             $setting = new Setting();
             $setting->_name = $conf['name'];
             $setting->_type = 'plugin';
             $setting->_data = json_encode($conf);
             $setting->create();
             $this->_action_msg = ActionMessages::custom_good('Plugin "' . $setting->_name . '" installed');
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
             //remove files
             foreach ($conf['admin'] as $file) {
                 File::delete($tmp . 'admin/' . $file, false);
             }
             foreach ($conf['site'] as $file) {
                 File::delete($tmp . 'site/' . $file, false);
             }
             foreach ($conf['library'] as $file) {
                 File::delete($tmp . 'library/' . $file, false);
             }
         }
     }
 }
 /**
  * Build link for comments permalink
  *
  * @access	private
  * @return	string
  */
 private function build_link()
 {
     switch ($this->_pid) {
         case 'posts':
             $link = 'ctl=posts&news=' . VGet::news();
             break;
         case 'albums':
             $link = 'ctl=albums&&album=' . VGet::album();
             break;
     }
     return $link;
 }
 /**
  * Delete links
  *
  * @access	private
  */
 private function delete()
 {
     if (VPost::delete(false) && VPost::link_id() && $this->_user['delete_content']) {
         try {
             foreach (VPost::link_id() as $id) {
                 $link = new Link();
                 $link->_id = $id;
                 $link->delete();
                 $this->_action_msg = ActionMessages::deleted($link->_result_action);
             }
             Session::monitor_activity('deleted ' . count(VPost::link_id()) . ' link(s)');
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     } elseif (VGet::action() == 'delete' && VGet::id() && $this->_user['delete_content']) {
         try {
             $link = new Link();
             $link->_id = Vget::id();
             $link->delete();
             Session::monitor_activity('deleted a link');
             $this->_action_msg = ActionMessages::deleted($link->_result_action);
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     } elseif ((VPost::delete(false) || VGet::action() == 'delete') && $this->_user['delete_content'] === false) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 /**
  * Install a template from github
  *
  * @access	private
  */
 private function create()
 {
     if (VGet::action() == 'install' && VGet::user() && VGet::repo() && VGet::download()) {
         try {
             $curl = new Curl('https://api.github.com/repos/' . VGet::user() . '/' . VGet::repo() . '/downloads');
             $downloads = json_decode($curl->_content, true);
             if (empty($downloads)) {
                 throw new Exception('Archive doesn\'t exist on Github');
             }
             if (isset($downloads['message'])) {
                 throw new Exception($downloads['message']);
             }
             $url = null;
             foreach ($downloads as $download) {
                 if ($download['name'] == VGet::download()) {
                     if ($download['content_type'] != 'application/zip') {
                         throw new Exception('Invalid archive type! (.zip only)');
                     } else {
                         $url = $download['html_url'];
                     }
                 }
             }
             unset($curl);
             $curl = new Curl($url);
             $zip = new File();
             $zip->_content = $curl->_content;
             $zip->save('tmp/template.zip');
             $tmp = 'tmp/tpl_' . md5_file('tmp/template.zip') . '/';
             File::unzip('tmp/template.zip', $tmp);
             File::delete('tmp/template.zip');
             $json = File::read($tmp . 'manifest.json');
             $conf = json_decode($json->_content, true);
             //check if the manifest is complete
             if (!isset($conf['name']) || !isset($conf['author']) || !isset($conf['url']) || !isset($conf['namespace']) || !isset($conf['files'])) {
                 throw new Exception('Invalid manifest!');
             }
             if (is_dir(PATH . 'includes/templates/' . $conf['namespace'] . '/')) {
                 throw new Exception('Template already exist');
             }
             //if one of files doesn't exists, an exception will be raised
             foreach ($conf['files'] as $file) {
                 File::read($tmp . $file);
             }
             foreach ($conf['files'] as $file) {
                 File::move($tmp . $file, PATH . 'includes/templates/' . $conf['namespace'] . '/' . $file);
                 File::delete($tmp . $file);
             }
             File::delete($tmp . 'manifest.json');
             $setting = new Setting();
             $setting->_name = $conf['name'];
             $setting->_type = 'template';
             $setting->_data = json_encode($conf);
             $setting->create();
             $this->_action_msg = ActionMessages::custom_good('Template "' . $setting->_name . '" installed');
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     }
 }
 /**
  * Determine maximum pages number
  *
  * @access	private
  */
 private function get_nb_pages()
 {
     $to_read['table'] = $this->_sql_table;
     $to_read['columns'] = array('COUNT(POST_ID) AS 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';
     }
     $nb = $this->_db->read($to_read);
     $this->_nb_pages = ceil($nb[0]['id'] / parent::ITEMS_PAGE);
 }
use Library\Variable\Get as VGet;
use Exception;
define('PATH', '');
define('ADMIN', 'admin/');
define('INC', 'includes/');
try {
    require_once INC . 'class.install.inc.php';
    //If the config file doesn't exist or the database install is not made, redirect to install.php
    if (!file_exists('config.php') || file_exists('config.php') && !\Install\Install::check_installed()) {
        header('Location: install.php');
    }
    require_once 'config.php';
    require_once INC . 'class.loader.inc.php';
    Loader::load();
    $controller = '\\Site\\' . ucfirst(VGet::ctl('defaultpage'));
    //forbidden classes
    if ($controller::CONTROLLER === false) {
        throw new Exception('Unknown controllers');
    }
    new Session();
    $page = new $controller();
    $cache = new Cache();
    if ($cache->_exist === false) {
        $cache->build('s');
        $title = $page->_title;
        $menu = $page->_menu;
        require_once Html::header();
        $page->display_content();
        require_once Html::footer();
        $cache->build('e');
 /**
  * Remove one website from the timeline
  *
  * @access	private
  */
 private function delete()
 {
     if (VGet::action() == 'remove' && VGet::id(false) !== false) {
         try {
             $data = $this->_prefs->_data;
             unset($data['timeline'][VGet::id()]);
             $this->_prefs->_data = json_encode($data);
             $this->_prefs->update('_data', 'str');
             $this->_prefs->_data = json_decode($this->_prefs->_data, true);
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::pref_updated($result);
     }
 }
 /**
  * Delete selected posts
  *
  * @access	private
  */
 private function delete()
 {
     if ((VRequest::action() == 'delete' && VRequest::id() || VPost::delete(false) || VPost::empty_trash(false)) && $this->_user['delete_content']) {
         try {
             $post = new Post();
             if (VGet::action() == 'delete' && VGet::id()) {
                 $post->_id = VGet::id();
                 $post->delete();
                 $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . VGet::id() . ' AND comment_rel_type = "post"');
                 $result = $post->_result_action;
             } elseif (VPost::delete(false)) {
                 foreach (VPost::post_id() as $id) {
                     $post->_id = $id;
                     $post->delete();
                     $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $id . ' AND comment_rel_type = "post"');
                 }
                 $result = $post->_result_action;
             } elseif (VPost::empty_trash(false)) {
                 $to_read['table'] = 'post';
                 $to_read['columns'] = array('POST_ID');
                 $to_read['condition_columns'][':s'] = 'post_status';
                 $to_read['condition_select_types'][':s'] = '=';
                 $to_read['condition_values'][':s'] = 'trash';
                 $to_read['value_types'][':s'] = 'str';
                 $posts = $this->_db->read($to_read);
                 foreach ($posts as $post) {
                     $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $post['POST_ID'] . ' AND comment_rel_type = "post"');
                 }
                 $to_delete['table'] = 'post';
                 $to_delete['condition_columns'][':status'] = 'post_status';
                 $to_delete['condition_values'][':status'] = 'trash';
                 $to_delete['value_types'][':status'] = 'str';
                 $result = $this->_db->delete($to_delete);
             }
             Session::monitor_activity('deleted post(s)');
             $this->_action_msg = ActionMessages::deleted($result);
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     } elseif ((VRequest::action() == 'delete' && VRequest::id() || VPost::delete(false) || VPost::empty_trash(false)) && $this->_user['delete_content'] === false) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 *
 * This file is part of Lynxpress.
 *
 *   Lynxpress is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Lynxpress is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Lynxpress.  If not, see http://www.gnu.org/licenses/.
 */
require_once 'needed.php';
use Library\Variable\Get as VGet;
try {
    $controller = '\\Admin\\' . ucfirst(VGet::ns('timeline')) . '\\' . ucfirst(VGet::ctl('manage'));
    $page = new $controller();
    if ($page->html === true) {
        require_once INC . 'html/header.php';
    }
    $page->display_content();
    if ($page->html === true) {
        require_once INC . 'html/footer.html';
    }
} catch (Exception $e) {
    die('<h1>' . $e->getMessage() . '</h1>');
}
 /**
  * Method that permits to delete one or more categories
  *
  * @access	private
  */
 private function delete()
 {
     if (VPost::delete(false) && $this->_user['delete_content']) {
         if (VPost::category_id()) {
             try {
                 foreach (VPost::category_id() as $id) {
                     $cat = new Category();
                     $cat->_id = $id;
                     $cat->read('_name');
                     $cat->read('_type');
                     $type = $cat->_type;
                     if ($this->check_usage($id, $type)) {
                         throw new Exception('Can\'t delete ' . $cat->_name . ' because it\'s used!');
                     }
                     $cat->delete();
                     $this->check_empty($type);
                 }
                 Session::monitor_activity('deleted ' . count(VPost::category_id()) . ' category(ies)');
                 $result = true;
             } catch (Exception $e) {
                 $result = $e->getMessage();
             }
             $this->_action_msg = ActionMessages::deleted($result);
         }
     } elseif (VGet::action() == 'delete' && VGet::id()) {
         try {
             $cat = new Category();
             $cat->_id = VGet::id();
             $cat->read('_name');
             $cat->read('_type');
             $type = $cat->_type;
             if ($this->check_usage(VGet::id(), $type)) {
                 throw new Exception('Can\'t delete ' . ucwords($cat->_name) . ' because it\'s used!');
             }
             $cat->delete();
             $this->check_empty($type);
             Session::monitor_activity('deleted a category');
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::deleted($result);
     } elseif ((VPost::delete(false) || VGet::action() == 'delete' && VGet::id()) && !$this->_user['delete_content']) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 /**
  * Display page content
  *
  * @access	public
  */
 public function display_content()
 {
     if (VGet::action() == 'check') {
         echo '{"lynxpress":"true"}';
     } else {
         echo json_encode($this->_content);
     }
 }