public static function Run() { chdir(realpath(dirname(__FILE__) . '/../')); require_once 'includes/global.php'; $doc_root = Config::Get('document_root'); $DB = GetDB(); self::Log('Starting...'); self::MarkRunning(); while (true) { // See if we were requested to stop if (self::ShouldStop()) { self::Log('User requested stop...'); break; } self::Ping(); $DB->Connect(); $queue_item = $DB->Row('SELECT *,`tbx_conversion_queue`.`video_id` AS `video_id`,`tbx_conversion_queue`.`queued` AS `queued` FROM `tbx_conversion_queue` LEFT JOIN ' . '`tbx_thumb_queue` USING (`video_id`) WHERE `tbx_thumb_queue`.`video_id` IS NULL ORDER BY `tbx_conversion_queue`.`queued` LIMIT 1'); if (!empty($queue_item)) { $video = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($queue_item['video_id'])); if (!empty($video)) { $DB->Update('UPDATE `tbx_video` SET `conversion_failed`=0 WHERE `video_id`=?', array($video['video_id'])); $DB->Update('UPDATE `tbx_conversion_queue` SET `date_started`=? WHERE `video_id`=?', array(Database_MySQL::Now(), $video['video_id'])); $clips = $DB->FetchAll('SELECT * FROM `tbx_video_clip` WHERE `video_id`=? ORDER BY `clip_id`', array($queue_item['video_id'])); $dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id'])); Video_Converter::SetLogFile($dir->GetBaseDir() . '/convert.log'); $convert_start = time(); $conversion_failed = false; foreach ($clips as $clip) { $clip_path = null; $old_path = null; try { // Stored locally, move to originals directory if ($clip['clip'][0] == '/') { $old_path = $doc_root . $clip['clip']; $clip_path = $dir->AddOriginalFromFile($old_path); } else { $http = new HTTP(); if ($http->Get($clip['clip'], $clip['clip'])) { $clip_path = $dir->AddOriginalFromVar($http->body, File::Extension($clip['clip'])); } else { throw new BaseException('Could not download clip for conversion: ' . $http->error); } } $output_file = Video_Converter::Convert($clip_path, $dir->GetProcessingDir(), Config::Get('video_format'), Config::Get('video_bitrate'), Config::Get('audio_bitrate'), Config::Get('video_size'), array('ConversionQueue', 'Ping')); $converted_video = $dir->AddClipFromFile($output_file); $DB->Disconnect(); $DB->Connect(); $DB->Update('UPDATE `tbx_video_clip` SET `clip`=?,`filesize`=? WHERE `clip_id`=?', array(str_replace($doc_root, '', $converted_video), filesize($converted_video), $clip['clip_id'])); } catch (Exception $e) { if (!empty($old_path) && !empty($clip_path)) { rename($clip_path, $old_path); } Video_Converter::Log($e->getMessage() . (strtolower(get_class($e)) == 'baseexception' ? $e->getExtras() : '') . "\n" . $e->getTraceAsString()); $conversion_failed = true; } } $convert_end = time(); $dir->ClearProcessing(); $dir->ClearTemp(); $DB->Connect(); $DB->Update('DELETE FROM `tbx_conversion_queue` WHERE `video_id`=?', array($queue_item['video_id'])); if ($conversion_failed) { self::UpdateStatsProcessed($convert_start, $convert_end, $queue_item['queued'], true); $DB->Update('UPDATE `tbx_video` SET `conversion_failed`=1 WHERE `video_id`=?', array($video['video_id'])); } else { // Update stats self::UpdateStatsProcessed($convert_start, $convert_end, $queue_item['queued']); $status = empty($video['next_status']) ? STATUS_ACTIVE : $video['next_status']; // Set video status $DB->Update('UPDATE `tbx_video` SET `status`=? WHERE `video_id`=?', array($status, $video['video_id'])); if ($video['status'] != $status && $status == STATUS_ACTIVE && !$video['is_private']) { Tags::AddToFrequency($video['tags']); } UpdateCategoryStats($video['category_id']); } } } else { break; } } self::MarkStopped(); self::Log('Exiting...'); }
public static function Run() { chdir(realpath(dirname(__FILE__) . '/../')); require_once 'includes/global.php'; $doc_root = Config::Get('document_root'); $DB = GetDB(); self::Log('Starting...'); self::MarkRunning(); while (true) { // See if we were requested to stop if (self::ShouldStop()) { self::Log('User requested stop...'); break; } self::Ping(); $DB->Connect(); $queue_item = $DB->Row('SELECT * FROM `tbx_thumb_queue` ORDER BY `queued` LIMIT 1'); if (!empty($queue_item)) { $video = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($queue_item['video_id'])); if (!empty($video)) { $DB->Update('UPDATE `tbx_thumb_queue` SET `date_started`=? WHERE `video_id`=?', array(Database_MySQL::Now(), $video['video_id'])); $clips = $DB->FetchAll('SELECT * FROM `tbx_video_clip` WHERE `video_id`=? AND `type`!=? ORDER BY `clip_id`', array($queue_item['video_id'], 'Embed')); $dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id'])); Video_FrameGrabber::SetLogFile($dir->GetBaseDir() . '/thumbnailer.log'); $thumb_start = time(); try { if (!empty($clips)) { $thumbs = array(); $duration = 0; // Number of thumbs to create per clip $amount = round(Config::Get('thumb_amount') / count($clips)); // Move existing thumbnails $dir->MoveFiles($dir->GetThumbsDir(), $dir->GetTempDir(), JPG_EXTENSION); // Process each clip foreach ($clips as $clip) { self::Ping(); // Remote video if (preg_match('~https?://~i', $clip['clip'])) { $http = new HTTP(); if ($http->Get($clip['clip'], $clip['clip'])) { $video_file = $dir->AddOriginalFromVar($http->body, File::Extension($clip['clip'])); $vi = new Video_Info($video_file); $vi->Extract(); $duration += $vi->length; $temp_thumbs = Video_FrameGrabber::Grab($video_file, $dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'), $vi); // Move generated thumbs from the processing directory foreach ($temp_thumbs as $temp_thumb) { $thumbs[] = $dir->AddThumbFromFile($temp_thumb); } @unlink($video_file); } } else { $temp_thumbs = Video_FrameGrabber::Grab($doc_root . '/' . $clip['clip'], $dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size')); // Move generated thumbs from the processing directory foreach ($temp_thumbs as $temp_thumb) { $thumbs[] = $dir->AddThumbFromFile($temp_thumb); } } } // Get the relative URL for each thumb and add to database $thumb_ids = array(); foreach ($thumbs as $thumb) { $thumb = str_replace($doc_root, '', $thumb); $thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => $thumb)); } // Determine number of thumbnails and select random display thumbnail $num_thumbnails = count($thumbs); $display_thumbnail = null; if ($num_thumbnails > 0) { // Select display thumbnail randomly from the first 40% $display_thumbnail = $thumb_ids[rand(0, floor(0.4 * $num_thumbnails))]; } $update = array('video_id' => $video['video_id'], 'num_thumbnails' => $num_thumbnails, 'display_thumbnail' => $display_thumbnail); if (empty($video['duration']) && !empty($duration)) { $update['duration'] = $duration; } DatabaseUpdate('tbx_video', $update); // Remove old thumbnails $DB->Update('DELETE FROM `tbx_video_thumbnail` WHERE `video_id`=?' . (!empty($thumb_ids) ? ' AND`thumbnail_id` NOT IN (' . join(',', $thumb_ids) . ')' : ''), array($video['video_id'])); $dir->ClearTemp(); } } catch (Exception $e) { // Restore old thumbnails $dir->MoveFiles($dir->GetTempDir(), $dir->GetThumbsDir(), JPG_EXTENSION); Video_FrameGrabber::Log($e->getMessage() . (strtolower(get_class($e)) == 'baseexception' ? $e->getExtras() : '') . "\n" . $e->getTraceAsString()); self::UpdateStatsProcessed($thumb_start, $thumb_end, $queue_item['queued'], true); } $thumb_end = time(); $DB->Update('DELETE FROM `tbx_thumb_queue` WHERE `video_id`=?', array($queue_item['video_id'])); self::UpdateStatsProcessed($thumb_start, $thumb_end, $queue_item['queued']); } } else { break; } } self::MarkStopped(); self::Log('Exiting...'); }
public function PreProcess() { $this->video_dir = new Video_Dir(null, 0700); Request::FixFiles(); if (!isset($_FILES[Video_Source::FIELD_UPLOADS])) { throw new BaseException('No files were uploaded'); } foreach ($_FILES[Video_Source::FIELD_UPLOADS] as $upload) { // No file uploaded in this field if ($upload['error'] == UPLOAD_ERR_NO_FILE) { continue; } // Check for other errors if ($upload['error'] != UPLOAD_ERR_OK) { throw new BaseException(Uploads::CodeToMessage($upload['error'])); } $thumbs = array(); $will_grab = Video_Info::CanExtract() && Video_FrameGrabber::CanGrab(); switch (File::Type($upload['name'])) { case File::TYPE_ZIP: foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_JPEG) as $name => $data) { $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION); } foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_VIDEO) as $name => $data) { $this->clips[] = $this->video_dir->AddClipFromVar($data, File::Extension($name)); } break; case File::TYPE_JPEG: $thumbs[] = $this->video_dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION); break; case File::TYPE_VIDEO: $this->clips[] = $this->video_dir->AddClipFromFile($upload['tmp_name'], File::Extension($upload['name'])); break; } } // Make sure at least one video clip was uploaded if (empty($this->clips)) { throw new BaseException('No video files were uploaded'); } // Try to grab frames from video files if ($will_grab) { $amount = round(Config::Get('thumb_amount') / count($this->clips)); foreach ($this->clips as $clip) { $vi = new Video_Info($clip); $vi->Extract(); $this->duration += $vi->length; $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size')); // Move generated thumbs from the processing directory foreach ($temp_thumbs as $temp_thumb) { $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb); } $this->video_dir->ClearProcessing(); } } else { $this->duration = $this->source[Video_Source::FIELD_DURATION]; } // Use uploaded images if none could be generated if (empty($this->thumbs) && !empty($thumbs)) { if (Video_Thumbnail::CanResize()) { $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality')); } else { $this->thumbs = $this->video_dir->MoveFiles(Video_Dir::TEMP, Video_Dir::THUMBS, JPG_EXTENSION); } } // Cleanup temp and processing dirs $this->video_dir->ClearTemp(); $this->video_dir->ClearProcessing(); }
function tbxUploadStepTwo() { global $t; $upload = $_FILES['video_file']; $v = Validator::Create(); $DB = GetDB(); $v->Register(sha1($_REQUEST['step_one_data'] . Config::Get('random_value')) == $_REQUEST['step_one_sig'], Validator_Type::IS_TRUE, _T('Validation:Video Data Altered')); $v->Register($upload['error'] == UPLOAD_ERR_OK, Validator_Type::IS_TRUE, Uploads::CodeToMessage($upload['error'])); if (is_uploaded_file($upload['tmp_name'])) { $max_filesize = Format::StringToBytes(Config::Get('max_upload_size')); $max_duration = Format::DurationToSeconds(Config::Get('max_upload_duration')); $extensions = str_replace(',', '|', Config::Get('upload_extensions')); $v->Register($upload['size'], Validator_Type::IS_BETWEEN, _T('Validation:Video size too large'), '1,' . $max_filesize); $v->Register(File::Extension($upload['name']), Validator_Type::REGEX_MATCH, _T('Validation:Video file extension not allowed'), '~^(' . $extensions . ')$~'); try { $vi = new Video_Info($upload['tmp_name']); $vi->Extract(); $v->Register($vi->length, Validator_Type::LESS_EQ, _T('Validation:Video duration too long'), $max_duration); } catch (Exception $e) { $v->Register(false, Validator_Type::IS_TRUE, $e->getMessage()); } $md5 = md5_file($upload['tmp_name']); if (Config::Get('flag_upload_reject_duplicates')) { $v->Register($DB->QueryCount('SELECT COUNT(*) FROM `tbx_video_md5sum` WHERE `md5`=?', array($md5)), Validator_Type::IS_ZERO, _T('Validation:Duplicate video')); } } // Validate input if (!$v->Validate()) { $t->Assign('g_errors', $v->GetErrors()); $t->AssignByRef('g_form', $_REQUEST); if (isset($_REQUEST['flash'])) { $t->Display('upload-flash-errors.tpl'); } else { $t->Assign('g_file_types', '*.' . str_replace(',', ';*.', Config::Get('upload_extensions'))); $t->Assign('g_cookie', $_COOKIE[LOGIN_COOKIE]); $t->Display('upload-step-two.tpl'); } return; } $_REQUEST = array_merge($_REQUEST, unserialize(base64_decode($_REQUEST['step_one_data']))); Form_Prepare::Standard('tbx_video'); Form_Prepare::Standard('tbx_video_stat'); Form_Prepare::Custom('tbx_video_custom_schema', 'on_submit'); $_REQUEST['duration'] = $vi->length; $_REQUEST['date_added'] = Database_MySQL::Now(); $_REQUEST['username'] = AuthenticateUser::GetUsername(); $_REQUEST['is_private'] = Config::Get('flag_upload_allow_private') ? intval($_REQUEST['is_private']) : 0; $_REQUEST['allow_ratings'] = intval($_REQUEST['allow_ratings']); $_REQUEST['allow_embedding'] = intval($_REQUEST['allow_embedding']); $_REQUEST['allow_comments'] = intval($_REQUEST['allow_comments']) ? 'Yes - Add Immediately' : 'No'; $_REQUEST['is_user_submitted'] = 1; if ($_REQUEST['recorded_day'] && $_REQUEST['recorded_month'] && $_REQUEST['recorded_year']) { $_REQUEST['date_recorded'] = $_REQUEST['recorded_year'] . '-' . $_REQUEST['recorded_month'] . '-' . $_REQUEST['recorded_day']; } // Strip HTML tags if (Config::Get('flag_video_strip_tags')) { $_REQUEST = String::StripTags($_REQUEST); } // Configure status $_REQUEST['status'] = STATUS_ACTIVE; if (Config::Get('flag_upload_convert')) { $_REQUEST['status'] = STATUS_QUEUED; $_REQUEST['next_status'] = Config::Get('flag_upload_review') ? STATUS_PENDING : STATUS_ACTIVE; } else { if (Config::Get('flag_upload_review')) { $_REQUEST['status'] = STATUS_PENDING; } } // Add to database $_REQUEST['video_id'] = DatabaseAdd('tbx_video', $_REQUEST); DatabaseAdd('tbx_video_custom', $_REQUEST); DatabaseAdd('tbx_video_stat', $_REQUEST); if ($_REQUEST['status'] == STATUS_ACTIVE && !$_REQUEST['is_private']) { Tags::AddToFrequency($_REQUEST['tags']); } else { if ($_REQUEST['status'] == STATUS_QUEUED) { DatabaseAdd('tbx_conversion_queue', array('video_id' => $_REQUEST['video_id'], 'queued' => time())); } } // Mark as private if ($_REQUEST['is_private']) { $_REQUEST['private_id'] = sha1(uniqid(rand(), true)); DatabaseAdd('tbx_video_private', $_REQUEST); } // Setup video files and generate thumbnails $directory = Video_Dir::DirNameFromId($_REQUEST['video_id']); $vd = new Video_Dir($directory); $clip = $vd->AddClipFromFile($upload['tmp_name'], File::Extension($upload['name'])); if (Video_FrameGrabber::CanGrab()) { Video_FrameGrabber::Grab($clip, $vd->GetThumbsDir(), Config::Get('thumb_amount'), Config::Get('thumb_quality'), Config::Get('thumb_size'), $vi); } foreach ($vd->GetClipURIs() as $clip) { $_REQUEST['clip'] = $clip; $_REQUEST['filesize'] = filesize(Config::Get('document_root') . $clip); DatabaseAdd('tbx_video_clip', $_REQUEST); } $thumb_ids = array(); foreach ($vd->GetThumbURIs() as $thumb) { $_REQUEST['thumbnail'] = $thumb; $thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', $_REQUEST); } // Select the display thumbnail $num_thumbnails = count($thumb_ids); $display_thumbnail = null; if ($num_thumbnails > 0) { $display_thumbnail = $thumb_ids[rand(0, floor(0.4 * $num_thumbnails))]; } DatabaseUpdate('tbx_video', array('video_id' => $_REQUEST['video_id'], 'num_thumbnails' => $num_thumbnails, 'display_thumbnail' => $display_thumbnail)); // Add MD5 sum for prevention of duplicates $DB->Update('REPLACE INTO `tbx_video_md5sum` VALUES (?)', array($md5)); // Update user stats StatsRollover(); $DB->Update('UPDATE `tbx_user_stat` SET ' . '`today_videos_uploaded`=`today_videos_uploaded`+1,' . '`week_videos_uploaded`=`week_videos_uploaded`+1,' . '`month_videos_uploaded`=`month_videos_uploaded`+1,' . '`total_videos_uploaded`=`total_videos_uploaded`+1 ' . 'WHERE `username`=?', array($_REQUEST['username'])); $t->AssignByRef('g_form', $_REQUEST); $t->AssignByRef('g_video', $_REQUEST); $t->Display(isset($_REQUEST['flash']) ? 'upload-flash-complete.tpl' : 'upload-complete.tpl'); UpdateCategoryStats($_REQUEST['category_id']); if (!Config::Get('flag_using_cron') && $_REQUEST['status'] == STATUS_QUEUED) { ConversionQueue::Start(); } }
function tbxVideoEdit() { Privileges::Check(Privileges::VIDEOS); $DB = GetDB(); $schema = GetDBSchema(); $v = Validator::Create(); $v->RegisterFromXml($schema->el('//table[name="tbx_video"]')); $v->RegisterFromXml($schema->el('//table[name="tbx_video_custom"]')); if (!String::IsEmpty($_REQUEST['username'])) { $v->Register($DB->QueryCount('SELECT COUNT(*) FROM `tbx_user` WHERE `username`=?', array($_REQUEST['username'])) > 0, Validator_Type::IS_TRUE, 'The Username entered does not exist'); } if (!$v->Validate()) { return JSON::Failure(array('message' => 'Video could not be updated; please fix the following items', 'errors' => $v->GetErrors())); } $_REQUEST['display_thumbnail'] = empty($_REQUEST['display_thumbnail']) ? null : $_REQUEST['display_thumbnail']; $_REQUEST['date_recorded'] = String::Nullify($_REQUEST['date_recorded']); $_REQUEST['tags'] = Tags::Format($_REQUEST['tags']); $_REQUEST['username'] = String::Nullify(Request::Get('username')); $_REQUEST['duration'] = Format::DurationToSeconds($_REQUEST['duration']); $original = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($_REQUEST['video_id'])); // Handle uploaded thumbs, if any $dir = new Video_Dir(Video_Dir::DirNameFromId($original['video_id'])); $thumbs_added = 0; $thumb_ids = array(); Request::FixFiles(); if (isset($_FILES['thumb_uploads'])) { foreach ($_FILES['thumb_uploads'] as $upload) { if (File::Extension($upload['name']) == JPG_EXTENSION && ($imgsize = getimagesize($upload['tmp_name'])) !== false) { $temp_file = $dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION); if (Video_Thumbnail::CanResize()) { $temp_file = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $dir->GetTempDir()); } $thumb = $dir->AddThumbFromFile($temp_file); $thumbs_added++; $thumb = str_replace(Config::Get('document_root'), '', $thumb); $thumb_ids[] = array('uri' => $thumb, 'id' => DatabaseAdd('tbx_video_thumbnail', array('video_id' => $original['video_id'], 'thumbnail' => $thumb))); } } if ($thumbs_added > 0) { $dir->ClearTemp(); $_REQUEST['num_thumbnails'] = $original['num_thumbnails'] + $thumbs_added; } } // Update base database tables $video = DatabaseUpdate('tbx_video', $_REQUEST); DatabaseUpdate('tbx_video_custom', $_REQUEST); // Handle changes to video clips foreach ($_REQUEST['clips'] as $clip_id => $clip) { DatabaseUpdate('tbx_video_clip', array('video_id' => $video['video_id'], 'clip_id' => $clip_id, 'clip' => $clip['clip'])); } if ($_REQUEST['is_private'] && !$original['is_private']) { $_REQUEST['private_id'] = sha1(uniqid(mt_rand(), true)); DatabaseAdd('tbx_video_private', $_REQUEST); if ($original['status'] == STATUS_ACTIVE) { Tags::RemoveFromFrequency($original['tags']); } } else { if (!$_REQUEST['is_private']) { if ($original['status'] == STATUS_ACTIVE) { if ($original['is_private']) { Tags::AddToFrequency($_REQUEST['tags']); } else { Tags::UpdateFrequency($original['tags'], $_REQUEST['tags']); } } $DB->Update('DELETE FROM `tbx_video_private` WHERE `video_id`=?', array($_REQUEST['video_id'])); } } if ($original['status'] == STATUS_ACTIVE) { $t = new Template(); $t->ClearCache('categories.tpl'); } UpdateCategoryStats($original['category_id'], $video['category_id']); UpdateSponsorStats($original['sponsor_id'], $_REQUEST['sponsor_id']); $output = array('id' => $video['video_id'], 'message' => 'Video has been successfully updated', 'html' => SearchItemHtml('video', $video), 'thumbs' => $thumb_ids); JSON::Success($output); }
/** * Read the settings in the files. * If a settings file is missing, raise an exception. * * @param string $config_file (for testing purpose only) * @return void * @author Thibaud Rohmer */ public static function init($forced = false, $config_file = NULL) { /// Settings already created if (Settings::$photos_dir !== NULL && !$forced) { return; } if (!isset($config)) { $config = (object) array(); } /// Set default values for $config $config->timezone = "Europe/Paris"; /// Load config.php file if (!isset($config_file)) { $config_file = realpath(dirname(__FILE__) . "/../../config.php"); } if (!(include $config_file)) { throw new Exception("You need to create a configuration file."); } /// Setup variables Settings::$photos_dir = $config->photos_dir; Settings::$thumbs_dir = $config->ps_generated . "/Thumbs/"; Settings::$conf_dir = $config->ps_generated . "/Conf/"; Settings::$admin_settings_file = $config->ps_generated . "/Conf/admin_settings.ini"; if (isset($config->imagemagick_path) && is_file($config->imagemagick_path)) { Settings::$imagemagick_path = $config->imagemagick_path; } if (isset($config->quality_small) && $config->quality_small >= 0 && $config->quality_small <= 100) { Settings::$quality_small = $config->quality_small; } if (isset($config->quality_mini) && $config->quality_mini >= 0 && $config->quality_mini <= 100) { Settings::$quality_mini = $config->quality_mini; } /// Set TimeZone date_default_timezone_set($config->timezone); // Now, check that this stuff exists. if (!file_exists(Settings::$photos_dir)) { if (!@mkdir(Settings::$photos_dir, 0750, true)) { throw new Exception("PHOTOS dir '" . Settings::$photos_dir . "' doesn't exist and couldn't be created !"); } } if (!file_exists(Settings::$thumbs_dir)) { if (!@mkdir(Settings::$thumbs_dir, 0750, true)) { throw new Exception("PS_GENERATED dir '" . Settings::$thumbs_dir . "' doesn't exist or doesn't have the good rights."); } } if (!file_exists(Settings::$conf_dir)) { if (!@mkdir(Settings::$conf_dir, 0750, true)) { throw new Exception("PS_GENERATED dir '" . Settings::$conf_dir . "' doesn't exist or doesn't have the good rights."); } } // Get Admin Settings if (file_exists(Settings::$admin_settings_file)) { $admin_settings = parse_ini_file(Settings::$admin_settings_file); if (isset($admin_settings['name'])) { Settings::$name = stripslashes($admin_settings['name']); } if (isset($admin_settings['fbappid'])) { Settings::$fbappid = $admin_settings['fbappid']; } if ($admin_settings['site_address']) { Settings::$site_address = $admin_settings['site_address']; } else { Settings::$site_address = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; } // Formatting the address so we can directly append "?t=..." to it without worry if (!preg_match("/ndex.php\$/", Settings::$site_address) && !preg_match("/.*\\/\$/", Settings::$site_address)) { Settings::$site_address = Settings::$site_address . "/"; } Settings::$like = isset($admin_settings['like']); Settings::$plusone = isset($admin_settings['plusone']); Settings::$noregister = isset($admin_settings['noregister']); Settings::$forcehttps = isset($admin_settings['forcehttps']); Settings::$nocomments = isset($admin_settings['nocomments']); Settings::$nodownload = isset($admin_settings['nodownload']); Settings::$l33t = isset($admin_settings['l33t']); Settings::$reverse_menu = isset($admin_settings['reverse_menu']); Settings::$rss = isset($admin_settings['rss']); if (isset($admin_settings['max_comments'])) { Settings::$max_comments = $admin_settings['max_comments'] + 0; } if (isset($admin_settings['thumbs_size'])) { Settings::$thumbs_size = $admin_settings['thumbs_size'] + 0; } if (isset($admin_settings['loc'])) { Settings::$loc = $admin_settings['loc']; } if (isset($admin_settings['user_theme'])) { Settings::$user_theme = $admin_settings['user_theme']; } /*** Video ***/ Settings::$encode_video = isset($admin_settings['encode_video']); if (isset($admin_settings['ffmpeg_path'])) { Settings::$ffmpeg_path = $admin_settings['ffmpeg_path']; } if (isset($admin_settings['ffmpeg_option'])) { Settings::$ffmpeg_option = $admin_settings['ffmpeg_option']; } } // Localization files path Settings::$locpath = dirname(dirname(dirname(__FILE__))) . "/inc/loc/"; // Get Localization array if (is_file(Settings::$locpath . "/" . Settings::$loc)) { Settings::$loc_chosen = parse_ini_file(Settings::$locpath . "/" . Settings::$loc, true); } Settings::$loc_default = parse_ini_file(Settings::$locpath . "/default.ini", true); // Localization files available Settings::$ava_loc = array(); $a = scandir(Settings::$locpath); foreach ($a as $f) { if (File::Extension($f) == "ini") { Settings::$ava_loc[] = $f; } } Settings::$themespath = dirname(dirname(dirname(__FILE__))) . "/user/themes/"; // Themes available Settings::$ava_themes = array(); $a = scandir(Settings::$themespath); foreach ($a as $f) { if ($f[0] != '.') { Settings::$ava_themes[] = $f; } } }
public function PreProcess() { $this->video_dir = new Video_Dir(null, 0700); $thumbs = array(); $clips = array(); foreach ($this->source[Video_Source::FIELD_URLS] as $url) { $url_path = parse_url($url, PHP_URL_PATH); switch (File::Type($url_path)) { case File::TYPE_ZIP: $http = new HTTP(); if ($http->Get($url, $url)) { $zip = $this->video_dir->AddTempFromVar($http->body, ZIP_EXTENSION); foreach (Zip::ExtractEntries($zip, File::TYPE_JPEG) as $name => $data) { $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION); } foreach (Zip::ExtractEntries($zip, File::TYPE_VIDEO) as $name => $data) { $this->clips[] = $this->video_dir->AddClipFromVar($data, File::Extension($name)); } } break; case File::TYPE_JPEG: $http = new HTTP(); if ($http->Get($url, $url)) { $thumbs[] = $this->video_dir->AddTempFromVar($http->body, JPG_EXTENSION); } break; case File::TYPE_VIDEO: if ($this->source[Video_Source::FLAG_HOTLINK]) { $clips[] = $url; $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]); } else { $http = new HTTP(); if ($http->Get($url, $url)) { $this->clips[] = $this->video_dir->AddClipFromVar($http->body, File::Extension($http->url)); } } break; } } if (empty($clips)) { if (!empty($this->clips) && Video_Info::CanExtract() && Video_FrameGrabber::CanGrab()) { $amount = round(Config::Get('thumb_amount') / count($this->clips)); foreach ($this->clips as $clip) { $vi = new Video_Info($clip); $vi->Extract(); $this->duration += $vi->length; $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size')); // Move generated thumbs from the processing directory foreach ($temp_thumbs as $temp_thumb) { $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb); } $this->video_dir->ClearProcessing(); } } } else { $this->clips = $clips; } if (empty($this->clips)) { throw new BaseException('No valid video URLs were submitted'); } // Use images from supplied URLs if none could be generated if (empty($this->thumbs) && !empty($thumbs)) { if (Video_Thumbnail::CanResize()) { $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality')); } else { $this->thumbs = $this->video_dir->MoveFiles($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), JPG_EXTENSION); } } // Cleanup temp and processing dirs $this->video_dir->ClearTemp(); $this->video_dir->ClearProcessing(); }
/** * Read the settings in the files. * If a settings file is missing, raise an exception. * * @return void * @author Thibaud Rohmer */ public static function init($forced = false) { /// Settings already created if (Settings::$photos_dir !== NULL && !$forced) { return; } /// Set default values for $config $config->timezone = "Europe/Paris"; /// Load config.php file $config_file = realpath(dirname(__FILE__) . "/../../config.php"); if (!(include $config_file)) { throw new Exception("You need to create a configuration file."); } /// Setup variables Settings::$photos_dir = $config->photos_dir; Settings::$thumbs_dir = $config->ps_generated . "/Thumbs/"; Settings::$conf_dir = $config->ps_generated . "/Conf/"; Settings::$admin_settings_file = $config->ps_generated . "/Conf/admin_settings.ini"; /// Set TimeZone date_default_timezone_set($config->timezone); // Now, check that this stuff exists. if (!file_exists(Settings::$photos_dir)) { if (!@mkdir(Settings::$photos_dir, 0750, true)) { throw new Exception("PHOTOS dir '" . Settings::$photos_dir . "' doesn't exist and couldn't be created !"); } } if (!file_exists(Settings::$thumbs_dir)) { if (!@mkdir(Settings::$thumbs_dir, 0750, true)) { throw new Exception("PS_GENERATED dir '" . Settings::$thumbs_dir . "' doesn't exist or doesn't have the good rights."); } } if (!file_exists(Settings::$conf_dir)) { if (!@mkdir(Settings::$conf_dir, 0750, true)) { throw new Exception("PS_GENERATED dir '" . Settings::$conf_dir . "' doesn't exist or doesn't have the good rights."); } } // Get Admin Settings if (file_exists(Settings::$admin_settings_file)) { $admin_settings = parse_ini_file(Settings::$admin_settings_file); if (isset($admin_settings['name'])) { Settings::$name = stripslashes($admin_settings['name']); } if (isset($admin_settings['fbappid'])) { Settings::$fbappid = $admin_settings['fbappid']; } if ($admin_settings['site_address']) { Settings::$site_address = $admin_settings['site_address']; } else { Settings::$site_address = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; } Settings::$like = isset($admin_settings['like']); Settings::$plusone = isset($admin_settings['plusone']); Settings::$noregister = isset($admin_settings['noregister']); Settings::$forcehttps = isset($admin_settings['forcehttps']); Settings::$nocomments = isset($admin_settings['nocomments']); Settings::$nodownload = isset($admin_settings['nodownload']); Settings::$l33t = isset($admin_settings['l33t']); Settings::$reverse_menu = isset($admin_settings['reverse_menu']); Settings::$hide_menu = isset($admin_settings['hide_menu']); Settings::$hide_infos = isset($admin_settings['hide_infos']); if (isset($admin_settings['max_comments'])) { Settings::$max_comments = $admin_settings['max_comments'] + 0; } if (isset($admin_settings['max_comments'])) { Settings::$max_comments = $admin_settings['max_comments'] + 0; } if (isset($admin_settings['max_img_dir'])) { Settings::$max_img_dir = $admin_settings['max_img_dir'] + 0; } if (isset($admin_settings['loc'])) { Settings::$loc = $admin_settings['loc']; } /*** Video ***/ Settings::$encode_video = isset($admin_settings['encode_video']); if (isset($admin_settings['ffmpeg_path'])) { Settings::$ffmpeg_path = $admin_settings['ffmpeg_path']; } if (isset($admin_settings['ffmpeg_option'])) { Settings::$ffmpeg_option = $admin_settings['ffmpeg_option']; } } // Localization files path Settings::$locpath = dirname(dirname(dirname(__FILE__))) . "/inc/loc/"; // Get Localization array if (is_file(Settings::$locpath . "/" . Settings::$loc)) { Settings::$loc_chosen = parse_ini_file(Settings::$locpath . "/" . Settings::$loc, true); } Settings::$loc_default = parse_ini_file(Settings::$locpath . "/default.ini", true); // Localization files available Settings::$ava_loc = array(); $a = scandir(Settings::$locpath); foreach ($a as $f) { if (File::Extension($f) == "ini") { Settings::$ava_loc[] = $f; } } }
public function PreProcess() { $this->video_dir = new Video_Dir(null, 0700); $http = new HTTP(); if (!$http->Get($this->source[Video_Source::FIELD_GALLERY])) { throw new BaseException('Could not access gallery: ' . $http->error); } list($thumbs, $clips) = self::ExtractUrls($http->url, $http->body); if (empty($clips)) { throw new BaseException('No video files could be located on this gallery'); } // Hotlinking video from gallery if ($this->source[Video_Source::FLAG_HOTLINK]) { $this->clips = $clips; $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]); } else { // Download clips $amount = round(Config::Get('thumb_amount') / count($clips)); foreach ($clips as $clip) { $chttp = new HTTP(); if ($chttp->Get($clip, $http->url)) { $clip = $this->video_dir->AddClipFromVar($chttp->body, File::Extension($chttp->url)); $this->clips[] = $clip; $vi = new Video_Info($clip); $vi->Extract(); $this->duration += $vi->length; $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size')); // Move generated thumbs from the processing directory foreach ($temp_thumbs as $temp_thumb) { $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb); } $this->video_dir->ClearProcessing(); } } } // Download thumbs from gallery if none could be created from the video files // or video files are being hotlinked if (empty($this->thumbs)) { foreach ($thumbs as $thumb) { $coords = null; if (preg_match('~^\\[(.*?)\\](.*)~', $thumb, $matches)) { $coords = $matches[1]; $thumb = $matches[2]; } $thttp = new HTTP(); if ($thttp->Get($thumb, $http->url)) { $temp_file = $this->video_dir->AddTempFromVar($thttp->body, JPG_EXTENSION); $imgsize = @getimagesize($temp_file); $aspect = $imgsize !== false ? $imgsize[0] / $imgsize[1] : 0; if ($imgsize !== false && $aspect >= self::MIN_ASPECT && $aspect <= self::MAX_ASPECT) { if (Video_Thumbnail::CanResize()) { $this->thumbs[] = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $this->video_dir->GetThumbsDir(), $coords); } else { $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_file, JPG_EXTENSION); } } else { unlink($temp_file); } } } } // Cleanup temp and processing dirs $this->video_dir->ClearTemp(); $this->video_dir->ClearProcessing(); }