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());
     }
 }
 /**
  * Retrieve user preferences
  *
  * @access	private
  */
 private function get_prefs()
 {
     try {
         $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'] = 'user_' . VSession::user_id();
         $to_read['value_types'][':t'] = 'str';
         $pref = $this->_db->read($to_read);
         $this->_prefs = new Setting($pref[0]['SETTING_ID']);
         $this->_prefs->_data = json_decode($this->_prefs->_data, true);
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Retrieve all plugins installed
  *
  * @access	private
  */
 private function get_plugins()
 {
     try {
         $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'] = 'plugin';
         $to_read['value_types'][':t'] = 'str';
         $this->_plugins = $this->_db->read($to_read);
         if (!empty($this->_plugins)) {
             foreach ($this->_plugins as &$plg) {
                 $plg = new Setting($plg['SETTING_ID']);
                 $plg->_data = json_decode($plg->_data, true);
             }
         }
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Retrieve all categories from the database for a specific type
  *
  * @static
  * @access	public
  * @param	array [$array] Array to populate with categories (passed by reference)
  * @param	string [$msg] Attribute to return a message to if error raisen (passed by reference)
  * @param	string [$type] Category type that has to be retrieved
  */
 public static function get_categories(&$array, &$msg, $type)
 {
     try {
         $db =& Database::load();
         $to_read['table'] = 'category';
         $to_read['columns'] = array('CATEGORY_ID', 'category_name');
         $to_read['condition_columns'][':t'] = 'category_type';
         $to_read['condition_select_types'][':t'] = '=';
         $to_read['condition_values'][':t'] = $type;
         $to_read['value_types'][':t'] = 'str';
         $cats = $db->read($to_read);
         if (is_array($cats)) {
             foreach ($cats as $cat) {
                 $array[$cat['CATEGORY_ID']] = $cat['category_name'];
             }
         }
     } catch (Exception $e) {
         $msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * 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());
     }
 }
 /**
  * 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());
         }
     }
 }
 /**
  * Retrieve post settings
  *
  * @access	private
  */
 private function get_setting()
 {
     try {
         $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'] = 'post';
         $to_read['value_types'][':t'] = 'str';
         $this->_setting = $this->_db->read($to_read);
         if (empty($this->_setting)) {
             $this->_setting = new Setting();
             $this->_setting->_name = 'Post';
             $this->_setting->_type = 'post';
             $this->_setting->_data = json_encode(array('media' => false));
             $this->_setting->create();
             $this->_setting->_data = json_decode($this->_setting->_data, true);
         } else {
             $this->_setting = new Setting($this->_setting[0]['SETTING_ID']);
             $this->_setting->_data = json_decode($this->_setting->_data, true);
         }
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Move uploaded files to the right place and insert metadata in the database
  *
  * @access	private
  */
 private function create()
 {
     if (VPost::upload(false)) {
         try {
             $path = 'content/' . date('Y/m/');
             $img = new HandleMedia();
             $img->load_upload('file');
             $name = Helper::remove_accent($img->_name);
             $mime = $img->_mime;
             if (file_exists(PATH . $path . $name)) {
                 throw new Exception('The file "' . $name . '" already exists');
             }
             $img->save(PATH . $path . $name);
             if (substr($mime, 0, 5) == 'image') {
                 $img->thumb(150, 0);
                 $img->thumb(300, 0);
                 $img->thumb(1000, 0);
                 $this->_media->_status = 'draft';
             } elseif (substr($mime, 0, 5) == 'video') {
                 $this->_media->_status = 'publish';
             }
             $this->_media->_name = $name;
             $this->_media->_type = $mime;
             $this->_media->_author = $this->_user['user_id'];
             $this->_media->_allow_comment = 'closed';
             $this->_media->_permalink = $path . $name;
             $this->_media->_album = 0;
             $this->_media->create();
             Session::monitor_activity('has uploaded a file named: ' . $this->_media->_name);
             if (substr($mime, 0, 5) == 'video') {
                 header('Location: index.php?ns=media&ctl=manage&type=video');
             } else {
                 header('Location: index.php?ns=media&ctl=manage');
             }
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     } elseif (VPost::create_album(false) && $this->_user['album_photo']) {
         if (!VPost::name()) {
             $this->_action_msg = ActionMessages::custom_wrong('Album name missing');
         } else {
             try {
                 $name = VPost::name();
                 $path = 'content/albums/' . Helper::slug($name) . '/';
                 if (file_exists(PATH . $path)) {
                     throw new Exception('The album "' . $name . '" already exists');
                 }
                 $this->_media->_name = $name;
                 $this->_media->_type = 'album';
                 $this->_media->_author = $this->_user['user_id'];
                 $this->_media->_status = 'draft';
                 $this->_media->_permalink = $path;
                 $this->_media->_description = stripslashes(VPost::description());
                 $this->_media->_category = implode(',', VPost::cat(array()));
                 $this->_media->_allow_comment = VPost::allow_comment('closed');
                 $this->_media->_album = 0;
                 $img = new HandleMedia();
                 $img->load_upload('cover');
                 $img->save(PATH . $path . 'cover.png');
                 $img->thumb(150, 0);
                 $img->thumb(300, 0);
                 $img->thumb(1000, 0);
                 $this->_media->create();
                 Session::monitor_activity('created an album named: ' . $this->_media->_name);
                 header('Location: index.php?ns=media&ctl=albums&action=edit&id=' . $this->_media->_id);
             } catch (Exception $e) {
                 $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
             }
         }
     } elseif (VPost::link_alien(false)) {
         if (!VPost::name() || !VPost::embed_code()) {
             $this->_action_msg = ActionMessages::custom_wrong('There\'s missing informations');
         } else {
             try {
                 $this->_media->_name = VPost::name();
                 $this->_media->_type = 'alien';
                 $this->_media->_author = $this->_user['user_id'];
                 $this->_media->_status = 'draft';
                 $this->_media->_allow_comment = 'closed';
                 $this->_media->_permalink = Helper::slug(VPost::name());
                 $this->_media->_embed_code = VPost::embed_code();
                 $this->_media->_album = 0;
                 $this->_media->create();
                 Session::monitor_activity('linked a new video named: ' . $this->_media->_name);
                 header('Location: index.php?ns=media&ctl=manage&type=video');
             } catch (Exception $e) {
                 $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
             }
         }
     } elseif (VPost::register_video(false)) {
         try {
             if (!file_exists(PATH . VPost::url())) {
                 throw new Exception('Video not found');
             }
             if (!VPost::mime()) {
                 throw new Exception('Video mime type missing');
             }
             $this->_media->_name = VPost::name();
             $this->_media->_type = VPost::mime();
             $this->_media->_author = $this->_user['user_id'];
             $this->_media->_status = 'publish';
             $this->_media->_allow_comment = 'closed';
             $this->_media->_permalink = VPost::url();
             $this->_media->_album = 0;
             $this->_media->create();
             Session::monitor_activity('registered a new video named: ' . $this->_media->_name);
             header('Location: index.php?ns=media&ctl=manage&action=edit&type=video&id=' . $this->_media->_id);
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     }
 }
 /**
  * Set data in user object and returns errors if data doesn't fit
  *
  * @access	private
  * @return	boolean
  */
 private function check_post_data()
 {
     $results = array();
     $errors = array();
     array_push($results, $this->_profile->__set('_firstname', VPost::firstname()));
     array_push($results, $this->_profile->__set('_lastname', VPost::lastname()));
     array_push($results, $this->_profile->__set('_nickname', VPost::nickname()));
     array_push($results, $this->_profile->__set('_publicname', VPost::public_name()));
     if (VPost::role(false)) {
         //don't set when update own profile
         array_push($results, $this->_profile->__set('_role', VPost::role()));
     }
     array_push($results, $this->_profile->__set('_email', VPost::email()));
     array_push($results, $this->_profile->__set('_website', VPost::website()));
     array_push($results, $this->_profile->__set('_msn', VPost::msn()));
     array_push($results, $this->_profile->__set('_twitter', VPost::twitter()));
     array_push($results, $this->_profile->__set('_facebook', VPost::fb()));
     array_push($results, $this->_profile->__set('_google', VPost::google()));
     array_push($results, $this->_profile->__set('_avatar', VPost::avatar()));
     array_push($results, $this->_profile->__set('_bio', VPost::bio()));
     if (VPost::new_pwd(false) && VPost::new_pwd() == VPost::re_new_pwd()) {
         array_push($results, $this->_profile->__set('_password', Helper::make_password($this->_profile->_username, VPost::new_pwd())));
     } elseif (VPost::new_pwd(false) && VPost::new_pwd() != VPost::re_new_pwd()) {
         array_push($results, 'Passwords does\'t match');
     }
     foreach ($results as $result) {
         if ($result !== true) {
             //so it contains an error message
             array_push($errors, '<li>- ' . $result . '<li>');
         }
     }
     if (!empty($errors)) {
         $error_msg = 'Check your informations:<br/><ul>' . implode('', $errors) . '</ul>';
         $this->_action_msg = ActionMessages::custom_wrong($error_msg);
         return false;
     } else {
         return true;
     }
 }
 /**
  * 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 a specific image of an album
  *
  * @access	private
  */
 private function get_picture()
 {
     try {
         $this->_pictures[0] = new Media(VGet::pid());
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Create a new user
  *
  * @access	private
  */
 private function create()
 {
     if ($this->check_post_data()) {
         try {
             $to_read['table'] = 'user';
             $to_read['columns'] = array('USER_ID');
             $to_read['condition_columns'][':u'] = 'user_username';
             $to_read['condition_select_types'][':u'] = 'LIKE';
             $to_read['condition_values'][':u'] = $this->_new_user->_username;
             $to_read['value_types'][':u'] = 'str';
             $user = $this->_db->read($to_read);
             if (!empty($user)) {
                 throw new Exception('Username already used!');
             }
             $this->_new_user->create();
             Session::monitor_activity('added a new member: ' . $this->_new_user->_username);
             if ($this->_new_user->_result_action === true && VPost::send_pwd(false)) {
                 $to = $this->_new_user->_email;
                 $subject = 'Your password for ' . WS_NAME;
                 $message = 'This is your password: '******'Location: index.php?ns=users&ctl=manage');
             } elseif ($this->_new_user->_result_action === true) {
                 header('Location: index.php?ns=users&ctl=manage');
             }
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     }
 }
 /**
  * Get pagination informations
  *
  * @access	private
  * @param	array [$to_read]
  */
 private function get_pagination($to_read)
 {
     try {
         list($this->_page, $this->_limit_start) = Helper::pagination(parent::ITEMS);
         $to_read['columns'] = array('COUNT(COMMENT_ID) as count');
         $count = $this->_db->read($to_read);
         $this->_max = ceil($count[0]['count'] / parent::ITEMS);
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * 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);
             }
         }
     }
 }
 /**
  * Retrieve published videos
  *
  * @access	private
  */
 private function get_video()
 {
     try {
         $this->_content = array();
         $all = new Media();
         $all->_name = 'All';
         $all->_id = 'all';
         array_unshift($this->_content, $all);
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * 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();
     }
 }
 /**
  * Retrieve posts dates
  *
  * @access	private
  * @param	array [$to_read]
  */
 private function get_dates($to_read)
 {
     try {
         $to_read['columns'] = array('distinct substr(media_date, 1, 7) as date');
         $to_read['order'] = array('media_date', 'DESC');
         if (VRequest::date('all') != 'all') {
             unset($to_read['condition_columns'][':date']);
             unset($to_read['condition_select_types'][':date']);
             unset($to_read['condition_values'][':date']);
             unset($to_read['value_types'][':date']);
         }
         $this->_dates = $this->_db->read($to_read);
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Update link object
  *
  * @access	private
  */
 private function update()
 {
     if ($this->_user['settings']) {
         if ($this->check_post_data()) {
             try {
                 $this->_link->update('_name', 'str');
                 $this->_link->update('_link', 'str');
                 $this->_link->update('_rss_link', 'str');
                 $this->_link->update('_notes', 'str');
                 $this->_link->update('_priority', 'int');
                 header('Location: index.php?ns=links&ctl=manage');
             } catch (Exception $e) {
                 $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
             }
         }
     } else {
         $this->_action_msg = ActionMessages::action_no_perm();
     }
 }
 /**
  * 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());
     }
 }
 /**
  * Retrieve some drafted post
  *
  * @access	private
  */
 private function get_draft()
 {
     if ($this->_user['post']) {
         try {
             $to_read['table'] = 'post';
             $to_read['columns'] = array('POST_ID', 'post_title', 'post_content', 'post_date');
             $to_read['condition_columns'][':status'] = 'post_status';
             $to_read['condition_select_types'][':status'] = '=';
             $to_read['condition_values'][':status'] = 'draft';
             $to_read['value_types'][':status'] = 'str';
             $this->_drafts = $this->_db->read($to_read);
             if (!empty($this->_drafts)) {
                 foreach ($this->_drafts as &$post) {
                     $post = new Post($post['POST_ID']);
                 }
             }
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     }
 }
 /**
  * Upload and move into place a new template
  *
  * @access	private
  */
 private function create()
 {
     if (VPost::upload(false)) {
         try {
             $tpl = VFiles::tpl();
             if ($tpl['error'] != 0) {
                 throw new Exception('No file uploaded');
             }
             $tmp = 'tmp/tpl_' . md5_file($tpl['tmp_name']) . '/';
             File::unzip($tpl['tmp_name'], $tmp);
             $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();
             header('Location: index.php?ns=templates&ctl=manage');
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     }
 }
 /**
  * Set data from the form into the object
  *
  * If errors detected in the object it's returned into an array
  *
  * @access	private
  * @return	boolean
  */
 private function check_post_data()
 {
     $results = array();
     $errors = array();
     array_push($results, $this->_post->__set('_title', VPost::title()));
     array_push($results, $this->_post->__set('_content', VPost::content()));
     array_push($results, $this->_post->__set('_allow_comment', VPost::allow_comment('closed')));
     if (VPost::publish(false)) {
         array_push($results, $this->_post->__set('_status', 'publish'));
     } else {
         array_push($results, $this->_post->__set('_status', 'draft'));
     }
     array_push($results, $this->_post->__set('_category', implode(',', VPost::categories(array()))));
     //insertion of an empty aarray to return error message defined in the object
     array_push($results, $this->_post->__set('_tags', VPost::tags('divers')));
     if ($this->_action == 'to_insert') {
         array_push($results, $this->_post->__set('_permalink', Helper::slug($this->_post->__get('_title'))));
     }
     //we should make it in create method, but we need to handle the error
     foreach ($results as $result) {
         if ($result !== true) {
             array_push($errors, '<li>- ' . $result . '</li>');
         }
     }
     if (!empty($errors)) {
         $error_msg = 'Check your informations:<br/><ul>' . implode('', $errors) . '</ul>';
         $this->_action_msg = ActionMessages::custom_wrong($error_msg);
         return false;
     } else {
         return true;
     }
 }
 /**
  * Add a new Plugin
  *
  * @access	private
  */
 private function create()
 {
     if (VPost::upload(false)) {
         try {
             $plg = VFiles::plg();
             if ($plg['error'] != 0) {
                 throw new Exception('No file uploaded');
             }
             $tmp = 'tmp/plg_' . md5_file($plg['tmp_name']) . '/';
             File::unzip($plg['tmp_name'], $tmp);
             $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();
             header('Location: index.php?ns=plugins&ctl=manage');
         } catch (Exception $e) {
             $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
         }
     }
 }
 /**
  * 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();
     }
 }
 /**
  * Retrieve current template setting
  *
  * @access	private
  */
 private function get_setting()
 {
     try {
         $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'] = 'current_template';
         $to_read['value_types'][':t'] = 'str';
         $this->_setting = $this->_db->read($to_read);
         if (!empty($this->_setting)) {
             $this->_setting = new Setting($this->_setting[0]['SETTING_ID']);
         } else {
             throw new Exception('Current template setting doesn\'t exist');
         }
     } catch (Exception $e) {
         $this->_action_msg = ActionMessages::custom_wrong($e->getMessage());
     }
 }
 /**
  * Method that permits to create a new category
  *
  * @access	private
  */
 private function create()
 {
     if (VPost::add_cat(false) && VPost::name() && VPost::type() != 'no') {
         try {
             $cat = new Category();
             $cat->_name = VPost::name();
             $cat->_type = VPost::type();
             $cat->create();
             Session::monitor_activity('created a new category: ' . $cat->_name);
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::created($result);
     } elseif (VPost::add_cat(false) && (!VPost::name() || VPost::type() == 'no')) {
         $this->_action_msg = ActionMessages::custom_wrong('Make sure you\'ve filled all inputs!');
     }
 }
 /**
  * Check posted data
  *
  * @access	private
  * @return	boolean
  */
 private function check_post_data()
 {
     $errors = array();
     if (str_word_count(VPost::role()) != 1) {
         array_push($errors, '<li>- The role can contain only one word</li>');
     }
     if (!empty($errors)) {
         $error_msg = 'Check your informations:<br/><ul>' . implode('', $errors) . '</ul>';
         $this->_action_msg = ActionMessages::custom_wrong($error_msg);
         return false;
     } else {
         return true;
     }
 }