/**
  * Class constructor
  *
  * @access	public
  */
 public function __construct()
 {
     parent::__construct();
     if (VGet::action() == 'edit' && VGet::id()) {
         $this->_view_type = 'edit';
         $this->_title = 'Edit Link';
     } else {
         $this->_view_type = 'new';
         $this->_title = 'New Link';
     }
     if ($this->_user['settings']) {
         $this->get_link();
         if (VPost::new_link(false)) {
             $this->create();
         } elseif (VPost::update_link(false)) {
             $this->update();
         }
     }
 }
 /**
  * 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();
     }
 }
 /**
  * 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();
     }
 }
 /**
  * Display page content
  *
  * @access	public
  */
 public function display_content()
 {
     if (VGet::action() == 'check') {
         echo '{"lynxpress":"true"}';
     } else {
         echo json_encode($this->_content);
     }
 }
 /**
  * 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());
         }
     }
 }
 /**
  * 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();
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
             }
         }
     }
 }
 /**
  * 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();
     }
 }
 /**
  * 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();
     }
 }
 /**
  * Delete a role
  *
  * @access	private
  */
 private function delete()
 {
     if (VGet::action(false) == 'delete' && !in_array(VGet::role(), array('administrator', 'editor', 'author')) && $this->_user['delete_content']) {
         try {
             $to_read['table'] = 'user';
             $to_read['columns'] = array('USER_ID');
             $to_read['condition_columns'][':r'] = 'user_role';
             $to_read['condition_select_types'][':r'] = '=';
             $to_read['condition_values'][':r'] = VGet::role();
             $to_read['value_types'][':r'] = 'str';
             $users = $this->_db->read($to_read);
             if (!empty($users)) {
                 throw new Exception('Can\'t delete the role "' . ucfirst(VGet::role()) . '" because a user is using it!');
             }
             $to_read = null;
             $to_read['table'] = 'setting';
             $to_read['columns'] = array('SETTING_ID');
             $to_read['condition_columns'][':t'] = 'setting_type';
             $to_read['condition_select_types'][':t'] = '=';
             $to_read['condition_values'][':t'] = 'role';
             $to_read['value_types'][':t'] = 'str';
             $to_read['condition_types'][':n'] = 'AND';
             $to_read['condition_columns'][':n'] = 'setting_name';
             $to_read['condition_select_types'][':n'] = '=';
             $to_read['condition_values'][':n'] = VGet::role();
             $to_read['value_types'][':n'] = 'str';
             $role = $this->_db->read($to_read);
             $role = new Setting($role[0]['SETTING_ID']);
             $role->delete();
             $to_read = null;
             $to_read['table'] = 'setting';
             $to_read['columns'] = array('SETTING_ID');
             $to_read['condition_columns'][':t'] = 'setting_type';
             $to_read['condition_select_types'][':t'] = '=';
             $to_read['condition_values'][':t'] = 'all_roles';
             $to_read['value_types'][':t'] = 'str';
             $roles = $this->_db->read($to_read);
             $roles = new Setting($roles[0]['SETTING_ID']);
             $array = json_decode($roles->_data, true);
             foreach ($array as $key => $value) {
                 if ($value == VGet::role()) {
                     unset($array[$key]);
                 }
             }
             $roles->_data = json_encode($array);
             $roles->update('_data', 'str');
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::deleted($result);
     } elseif (VGet::action(false) == 'delete' && !$this->_user['delete_content']) {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }