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