/**
  * Move uploaded files in the associated album directory and insert metadata in the database
  *
  * @access	private
  */
 private function create()
 {
     if (VPost::upload(false) && !empty($_FILES)) {
         try {
             $album = new Media();
             $album->_id = VPost::album_id();
             $album->read('_name');
             $album->read('_permalink');
             $path = $album->_permalink;
             foreach (VFiles::all() as $key => $img) {
                 if (empty($img['name'])) {
                     continue;
                 }
                 $pic = new HandleMedia();
                 $pic->load_upload($key);
                 $name = Helper::remove_accent($pic->_name);
                 $mime = $pic->_mime;
                 if (substr($mime, 0, 5) == 'image') {
                     if (file_exists(PATH . $path . $name)) {
                         throw new Exception('The file "' . $name . '" already exists');
                     }
                     $pic->save(PATH . $path . $name);
                     $pic->thumb(150, 0);
                     $pic->thumb(300, 0);
                     $pic->thumb(1000, 0);
                     $picture = new Media();
                     $picture->_name = $name;
                     $picture->_type = $mime;
                     $picture->_author = $this->_user['user_id'];
                     $picture->_album = $album->_id;
                     $picture->_allow_comment = 'closed';
                     $picture->_permalink = $path . $name;
                     $picture->_status = 'publish';
                     $picture->create();
                 }
             }
             Session::monitor_activity('added new photos to ' . $album->_name);
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::created($result);
     } elseif (VPost::upload_zip() && !empty($_FILES)) {
         try {
             $album = new Media();
             $album->_id = VPost::album_id();
             $album->read('_name');
             $album->read('_permalink');
             $path = $album->_permalink;
             $tmp = 'tmp/albums/';
             if (empty($_FILES['zip']['tmp_name'])) {
                 throw new Exception('No archive uploaded!');
             }
             File::unzip($_FILES['zip']['tmp_name'], $tmp);
             $files = @scandir($tmp);
             if (empty($files)) {
                 throw new Exception('Your archive is empty!');
             }
             foreach ($files as $file) {
                 $finfo = new finfo(FILEINFO_MIME_TYPE);
                 $mime = $finfo->file($tmp . $file);
                 if ($mime == 'directory') {
                     continue;
                 }
                 $pic = new HandleMedia();
                 $pic->_mime = $mime;
                 $pic->load($tmp . $file);
                 $name = Helper::remove_accent($pic->_name);
                 if (substr($mime, 0, 5) == 'image') {
                     if (file_exists(PATH . $path . $name)) {
                         throw new Exception('The file "' . $name . '" already exists');
                     }
                     File::read($tmp . $file)->save(PATH . $path . $name);
                     $pic->_file = PATH . $path . $name;
                     $pic->thumb(150, 0);
                     $pic->thumb(300, 0);
                     $pic->thumb(1000, 0);
                     $picture = new Media();
                     $picture->_name = $name;
                     $picture->_type = $mime;
                     $picture->_author = $this->_user['user_id'];
                     $picture->_album = $album->_id;
                     $picture->_allow_comment = 'closed';
                     $picture->_permalink = $path . $name;
                     $picture->_status = 'publish';
                     $picture->create();
                     File::delete($tmp . $file);
                 }
             }
             Session::monitor_activity('added new photos to ' . $album->_name);
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::created($result);
     }
 }
 /**
  * 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!');
     }
 }
 /**
  * Create a new role
  *
  * @access	private
  */
 private function create()
 {
     if (VPost::add_role(false) && $this->check_post_data()) {
         try {
             $new_role = new Setting();
             $new_role->_name = strtolower(VPost::role());
             $new_role->_type = 'role';
             $new_role->_data = json_encode(array('dashboard' => false, 'post' => false, 'media' => false, 'album_photo' => false, 'comments' => false, 'delete_content' => false, 'settings' => false));
             $new_role->create();
             //update array containing all roles name
             $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';
             $all_roles = $this->_db->read($to_read);
             //if the setting does't exist, we create it with the new role
             if (empty($all_roles)) {
                 $all_roles = new Setting();
                 $all_roles->_name = 'All roles';
                 $all_roles->_type = 'all_roles';
                 $all_roles->_data = json_encode(array(strtolower(VPost::role())));
                 $all_roles->create();
             } else {
                 $all_roles = new Setting($all_roles[0]['SETTING_ID']);
                 $roles = json_decode($all_roles->_data, true);
                 array_push($roles, strtolower(VPost::role()));
                 $all_roles->_data = json_encode($roles);
                 $all_roles->update('_data', 'str');
             }
             //end update
             $result = true;
         } catch (Exception $e) {
             $result = $e->getMessage();
         }
         $this->_action_msg = ActionMessages::created($result);
     }
 }