/**
  * 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;
     }
 }
 /**
  * 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);
     }
 }