/**
  * 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!');
     }
 }
 /**
  * Method to insert form data in the object
  *
  * and loads error messages if data doesn't fit
  *
  * @access	private
  * @return	boolean
  */
 private function check_post_data()
 {
     $results = array();
     $errors = array();
     array_push($results, $this->_link->__set('_name', VPost::name()));
     array_push($results, $this->_link->__set('_link', VPost::url()));
     array_push($results, $this->_link->__set('_rss_link', VPost::rss()));
     array_push($results, $this->_link->__set('_notes', VPost::notes()));
     array_push($results, $this->_link->__set('_priority', VPost::lvl()));
     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;
     }
 }
 /**
  * Update medias metadata, and also file manipulation when requested
  *
  * @access	private
  */
 private function update()
 {
     if (VPost::update_image(false)) {
         try {
             $media = new Media();
             $media->_id = VPost::id();
             $media->_name = VPost::name();
             $media->_description = VPost::description();
             $media->update('_name', 'str');
             $media->update('_description', 'str');
             if (VPost::rotate() != 'no') {
                 $media->read('_permalink');
                 $media->read('_type');
                 $path = $media->_permalink;
                 $fname = basename($path);
                 $dirname = dirname($path) . '/';
                 $img = new HandleMedia();
                 $img->_mime = $media->_type;
                 $img->load(PATH . $path);
                 $img->rotate(VPost::rotate());
                 $img->load(PATH . $dirname . '1000-' . $fname);
                 $img->rotate(VPost::rotate());
                 $img->load(PATH . $dirname . '300-' . $fname);
                 $img->rotate(VPost::rotate());
                 $img->load(PATH . $dirname . '150-' . $fname);
                 $img->rotate(VPost::rotate());
             }
             if (VPost::flip() != 'no') {
                 $media->read('_permalink');
                 $media->read('_type');
                 $path = $media->_permalink;
                 $fname = basename($path);
                 $dirname = dirname($path) . '/';
                 $img = new HandleMedia();
                 $img->_mime = $media->_type;
                 $img->load(PATH . $path);
                 $img->flip(VPost::flip());
                 $img->load(PATH . $dirname . '1000-' . $fname);
                 $img->flip(VPost::flip());
                 $img->load(PATH . $dirname . '300-' . $fname);
                 $img->flip(VPost::flip());
                 $img->load(PATH . $dirname . '150-' . $fname);
                 $img->flip(VPost::flip());
             }
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     } elseif (VPost::update_video(false)) {
         try {
             $media = new Media();
             $media->_id = VPost::id();
             $media->_name = VPost::name();
             $media->_description = VPost::description();
             $media->_category = implode(',', VPost::cat(array()));
             $media->update('_name', 'str');
             $media->update('_description', 'str');
             $media->update('_category', 'str');
             if (VPost::attach() != 'no') {
                 $media->_attachment = VPost::attach();
                 $media->update('_attachment', 'int');
             } else {
                 $media->_attachment = null;
                 $media->update('_attachment', 'null');
             }
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     } elseif (VPost::update_alien(false)) {
         try {
             $media = new Media();
             $media->_id = VPost::id();
             $media->_name = VPost::name();
             $media->_description = VPost::description();
             $media->_embed_code = VPost::embed();
             $media->update('_name', 'str');
             $media->update('_description', 'str');
             $media->update('_embed_code', 'str');
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     }
 }
 /**
  * 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());
         }
     }
 }
 /**
  * Update album and pictures metadatas
  *
  * @access	private
  */
 private function update()
 {
     if (VPost::apply_action(false) && in_array(VPost::action(), array('publish', 'unpublish'))) {
         switch (VPost::action()) {
             case 'publish':
                 $status = 'publish';
                 break;
             case 'unpublish':
                 $status = 'draft';
                 break;
         }
         if (VPost::album_id()) {
             try {
                 foreach (VPost::album_id() as $id) {
                     $album = new Media();
                     $album->_id = $id;
                     $album->_status = $status;
                     $album->update('_status', 'str');
                 }
                 $result = true;
             } catch (Exception $e) {
                 $result = $e->getMessage();
             }
             $this->_action_msg = ActionMessages::updated($result);
         }
     } elseif (VPost::save(false)) {
         try {
             $album = new Media();
             $album->_id = VPost::album_id();
             $album->_name = VPost::name();
             $album->_description = VPost::description();
             $album->_allow_comment = VPost::allow_comment('closed');
             $album->_category = implode(',', VPost::cat(array()));
             $album->update('_name', 'str');
             $album->update('_description', 'str');
             $album->update('_allow_comment', 'str');
             $album->update('_category', 'str');
             foreach ($_POST as $key => $value) {
                 $pic = substr($key, 0, 3);
                 if ($pic == 'pic') {
                     $id = substr($key, 3);
                     $picture = new Media();
                     $picture->_id = $id;
                     $picture->_name = VPost::$key();
                     $picture->update('_name', 'str');
                 }
             }
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     } elseif (VPost::publish(false)) {
         try {
             $album = new Media();
             $album->_id = VPost::album_id();
             $album->_status = 'publish';
             $album->_name = VPost::name();
             $album->_description = VPost::description();
             $album->_allow_comment = VPost::allow_comment('closed');
             $album->_category = implode(',', VPost::cat(array()));
             $album->update('_name', 'str');
             $album->update('_description', 'str');
             $album->update('_allow_comment', 'str');
             $album->update('_category', 'str');
             $album->update('_status', 'str');
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     } elseif (VPost::unpublish(false)) {
         try {
             $album = new Media();
             $album->_id = VPost::album_id();
             $album->_status = 'draft';
             $album->update('_status', 'str');
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     } elseif (VPost::update_image(false)) {
         try {
             $media = new Media();
             $media->_id = VPost::pid();
             $media->_name = VPost::name();
             $media->_description = VPost::description();
             $media->update('_name', 'str');
             $media->update('_description', 'str');
             if (VPost::rotate() != 'no') {
                 $media->read('_permalink');
                 $media->read('_type');
                 $path = $media->_permalink;
                 $fname = basename($path);
                 $dirname = dirname($path) . '/';
                 $img = new HandleMedia();
                 $img->_mime = $media->_type;
                 $img->load(PATH . $path);
                 $img->rotate(VPost::rotate());
                 $img->load(PATH . $dirname . '1000-' . $fname);
                 $img->rotate(VPost::rotate());
                 $img->load(PATH . $dirname . '300-' . $fname);
                 $img->rotate(VPost::rotate());
                 $img->load(PATH . $dirname . '150-' . $fname);
                 $img->rotate(VPost::rotate());
             }
             if (VPost::flip() != 'no') {
                 $media->read('_permalink');
                 $media->read('_type');
                 $path = $media->_permalink;
                 $fname = basename($path);
                 $dirname = dirname($path) . '/';
                 $img = new HandleMedia();
                 $img->_mime = $media->_type;
                 $img->load(PATH . $path);
                 $img->flip(VPost::flip());
                 $img->load(PATH . $dirname . '1000-' . $fname);
                 $img->flip(VPost::flip());
                 $img->load(PATH . $dirname . '300-' . $fname);
                 $img->flip(VPost::flip());
                 $img->load(PATH . $dirname . '150-' . $fname);
                 $img->flip(VPost::flip());
             }
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::updated($result);
     }
 }