diff --git a/objects/functions.php b/objects/functions.php index 411a1e6527..e1dc133abe 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -616,7 +616,15 @@ function getimgsize($file_src){ $name = "getimgsize_". md5($file_src); $cached = ObjectYPT::getCache($name, 86400);//one day if(!empty($cached)){ - return (Array) $cached; + $c = (Array) $cached; + $size = array(); + foreach ($c as $key => $value) { + if(preg_match("/^[0-9]+$/", $key)){ + $key = intval($key); + } + $size[$key] = $value; + } + return $size; } $size = @getimagesize($file_src); @@ -701,4 +709,30 @@ function im_resize($file_src, $file_dest, $wd, $hd) { @chmod($file_dest, 0666); return true; +} + +function decideMoveUploadedToVideos($tmp_name, $filename){ + global $global; + $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); + if (!empty($aws_s3)) { + $aws_s3->move_uploaded_file($tmp_name, $filename); + } else { + if (!move_uploaded_file($tmp_name, "{$global['systemRootPath']}videos/{$filename}")) { + $obj->msg = "Error on move_uploaded_file({$tmp_name}, {$global['systemRootPath']}videos/{$filename})"; + die(json_encode($obj)); + } + } +} + +function decideFile_put_contentsToVideos($tmp_name, $filename){ + global $global; + $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); + if (!empty($aws_s3)) { + $aws_s3->move_uploaded_file($tmp_name, $filename); + } else { + if (!move_uploaded_file($tmp_name, "{$global['systemRootPath']}videos/{$filename}")) { + $obj->msg = "Error on move_uploaded_file({$tmp_name}, {$global['systemRootPath']}videos/{$filename})"; + die(json_encode($obj)); + } + } } \ No newline at end of file diff --git a/objects/video.php b/objects/video.php index 8ce141800c..e684f8ea32 100644 --- a/objects/video.php +++ b/objects/video.php @@ -668,23 +668,39 @@ class Video { if (empty($resp)) { die('Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } else { - $path = self::getStoragePath(); - foreach (self::$types as $value) { - $file = "{$path}original_{$video['filename']}"; - if (file_exists($file)) { - @unlink($file); - } - // Streamlined for less coding space. - $files = glob("{$path}{$video['filename']}.*"); - foreach ($files as $file) { - if (file_exists($file)) { - @unlink($file); - } - } + $this->removeFiles($video['filename']); + $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); + if(!empty($aws_s3)){ + $aws_s3->removeFiles($video['filename']); } } return $resp; } + + private function removeFiles($filename){ + if(empty($filename)){ + return false; + } + global $global; + $file = "{$global['systemRootPath']}videos/original_{$filename}"; + $this->removeFilePath($file); + + $files = "{$global['systemRootPath']}videos/{$filename}"; + $this->removeFilePath($files); + } + + private function removeFilePath($filePath){ + if(empty($filePath)){ + return false; + } + // Streamlined for less coding space. + $files = glob("{$filePath}.*"); + foreach ($files as $file) { + if (file_exists($file)) { + @unlink($file); + } + } + } function setDescription($description) { $this->description = $description; @@ -752,12 +768,12 @@ class Video { $getID3 = new getID3; // Analyze file and store returned data in $ThisFileInfo $ThisFileInfo = $getID3->analyze($file); - return static::getCleanDuration($ThisFileInfo['playtime_string']); + return static::getCleanDuration(@$ThisFileInfo['playtime_string']); } function updateDurationIfNeed($fileExtension = ".mp4") { global $global; - $source = self::getSourceFile($this->filename, $fileExtension); + $source = self::getSourceFile($this->filename, $fileExtension, true); $file = $source['path']; if (!empty($this->id) && $this->duration == "EE:EE:EE" && file_exists($file)) { @@ -1193,7 +1209,7 @@ class Video { * @param type $type * @return type .jpg .gif _thumbs.jpg _Low.mp4 _SD.mp4 _HD.mp4 */ - static function getSourceFile($filename, $type=".jpg") { + static function getSourceFile($filename, $type=".jpg", $includeS3 = false) { global $global; $name = "getSourceFile_{$filename}{$type}_"; $cached = ObjectYPT::getCache($name, 86400);//one day @@ -1203,10 +1219,13 @@ class Video { $source = array(); $source['path'] = "{$global['systemRootPath']}videos/{$filename}{$type}"; $source['url'] = "{$global['webSiteRootURL']}videos/{$filename}{$type}"; - if (!file_exists($source['path']) || filesize($source['path']) < 1024) { - $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); - if (!empty($aws_s3)) { - $source = $aws_s3->getAddress("{$filename}{$type}"); + /* need it because getDurationFromFile*/ + if($includeS3){ + if (!file_exists($source['path']) || filesize($source['path']) < 1024) { + $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); + if (!empty($aws_s3)) { + $source = $aws_s3->getAddress("{$filename}{$type}"); + } } } ObjectYPT::setCache($name, $source); @@ -1234,18 +1253,18 @@ class Video { $gifSource = self::getSourceFile($filename, ".gif"); $jpegSource = self::getSourceFile($filename, ".jpg"); $thumbsSource = self::getSourceFile($filename, "_thumbs.jpg"); - $obj->poster = ""; - $obj->thumbsGif = ""; - $obj->thumbsJpg = ""; + $obj->poster = $jpegSource['url']; + $obj->thumbsGif = $gifSource['url']; + $obj->thumbsJpg = $thumbsSource['url']; if ($type !== "audio") { if (file_exists($gifSource['path'])) { $obj->thumbsGif = $gifSource['url']; } - if (file_exists($jpegSource['path']) && filesize($jpegSource['path']) > 1024) { + if (file_exists($jpegSource['path'])) { $obj->poster = $jpegSource['url']; $obj->thumbsJpg = $thumbsSource['url']; // create thumbs - if (!file_exists($thumbsSource['path'])) { + if (!file_exists($thumbsSource['path']) && filesize($jpegSource['path']) > 1024) { im_resize($jpegSource['path'], $thumbsSource['path'], 250, 140); } } else { diff --git a/objects/youPHPTubeEncoder.json.php b/objects/youPHPTubeEncoder.json.php index 9204e41ddc..b512c7ccc5 100644 --- a/objects/youPHPTubeEncoder.json.php +++ b/objects/youPHPTubeEncoder.json.php @@ -66,53 +66,30 @@ if (empty($videoFileName)) { $destination_local = "{$global['systemRootPath']}videos/{$videoFileName}"; // get video file from encoder -$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); -if(empty($aws_s3)){ - $destination = $destination_local; - error_log("Using Local Storage: {$destination}"); -}else{ - $address = $aws_s3->getAddress($filename); - $destination = "{$address['path']}"; - error_log("Using AWS Storage: {$destination}"); -} - if (!empty($_FILES['video']['tmp_name'])) { $resolution = ""; if (!empty($_POST['resolution'])) { $resolution = "_{$_POST['resolution']}"; } - $destination_resolution_file = "{$destination}{$resolution}.{$_POST['format']}"; - if (!move_uploaded_file($_FILES['video']['tmp_name'], $destination_resolution_file)) { - $obj->msg = print_r(sprintf(__("Could not move video file [%s] => [%s %s %s]"), $_FILES['video']['tmp_name'], $destination, $_POST['format'], $resolution), true); - error_log($obj->msg); - die(json_encode($obj)); - } - if(!empty($aws_s3)){ - file_put_contents( "{$destination_local}{$resolution}.{$_POST['format']}" , "Dummy File for $destination_resolution_file " ); - } + $filename = "{$videoFileName}{$resolution}.{$_POST['format']}"; + decideMoveUploadedToVideos($_FILES['video']['tmp_name'], $filename); } else { // set encoding $video->setStatus('e'); } -if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination}.jpg")) { - if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination}.jpg")) { - $obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination), true); - error_log($obj->msg); - die(json_encode($obj)); - } - if(!empty($aws_s3)){ - file_put_contents( "{$destination_local}.jpg" , "Dummy File" ); - } -} -if (!empty($_FILES['gifimage']['tmp_name']) && !file_exists("{$destination}.gif")) { - if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], "{$destination}.gif")) { - $obj->msg = print_r(sprintf(__("Could not move gif image file [%s.gif]"), $destination), true); +if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) { + if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination_local}.jpg")) { + $obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination_local), true); + error_log($obj->msg); + die(json_encode($obj)); + } +} +if (!empty($_FILES['gifimage']['tmp_name']) && !file_exists("{$destination_local}.gif")) { + if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], "{$destination_local}.gif")) { + $obj->msg = print_r(sprintf(__("Could not move gif image file [%s.gif]"), $destination_local), true); error_log($obj->msg); die(json_encode($obj)); } - if(!empty($aws_s3)){ - file_put_contents( "{$destination_local}.gif" , "Dummy File" ); - } } $video_id = $video->save(); $video->updateDurationIfNeed(); diff --git a/plugin/YouPHPTubePlugin.php b/plugin/YouPHPTubePlugin.php index d56657e08b..4d073c8c7f 100644 --- a/plugin/YouPHPTubePlugin.php +++ b/plugin/YouPHPTubePlugin.php @@ -162,6 +162,11 @@ class YouPHPTubePlugin{ return !empty(Plugin::getEnabled($uuid)); } + static function isEnabledByName($name){ + $p = static::loadPluginIfEnabled($name); + return !empty($p); + } + static function getLogin(){ $plugins = Plugin::getAllEnabled(); $logins = array(); diff --git a/view/mini-upload-form/upload.php b/view/mini-upload-form/upload.php index bb5a61f1d9..4ef960e6d0 100644 --- a/view/mini-upload-form/upload.php +++ b/view/mini-upload-form/upload.php @@ -1,4 +1,5 @@ msg = "File extension error [{$_FILES['upl']['name']}], we allow only (". implode(",", $allowed) . ")"; + $obj->msg = "File extension error [{$_FILES['upl']['name']}], we allow only (" . implode(",", $allowed) . ")"; die(json_encode($obj)); } //var_dump($extension, $type);exit; @@ -26,37 +27,29 @@ if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0) { $path_parts = pathinfo($_FILES['upl']['name']); $mainName = preg_replace("/[^A-Za-z0-9]/", "", cleanString($path_parts['filename'])); $filename = uniqid($mainName . "_", true); - $video = new Video(substr(preg_replace("/_+/", " ", $_FILES['upl']['name']),0,-4), $filename, @$_FILES['upl']['videoId']); + $video = new Video(substr(preg_replace("/_+/", " ", $_FILES['upl']['name']), 0, -4), $filename, @$_FILES['upl']['videoId']); $video->setDuration($duration); $video->setType("video"); $video->setStatus('a'); $id = $video->save(); - + /** * This is when is using in a non uploaded movie */ - - $path = Video::getStoragePath(); - - if (!move_uploaded_file($_FILES['upl']['tmp_name'], $path . $filename.".mp4")) { - $obj->msg = "Error on move_uploaded_file(" . $_FILES['upl']['tmp_name'] . ", " . $path . $filename.".mp4)"; - die(json_encode($obj)); - } - $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); - if(!empty($aws_s3)){ - file_put_contents( "{$global['systemRootPath']}videos/{$filename}.mp4" , "Dummy File" ); - } - - + $tmp_name = $_FILES['upl']['tmp_name']; + $filenameMP4 = $filename . ".mp4"; + decideMoveUploadedToVideos($tmp_name, $filenameMP4); + + if (YouPHPTubePlugin::isEnabled("996c9afb-b90e-40ca-90cb-934856180bb9")) { require_once $global['systemRootPath'] . 'plugin/MP4ThumbsAndGif/MP4ThumbsAndGif.php'; $videoFileName = $video->getFilename(); MP4ThumbsAndGif::getImage($videoFileName, 'jpg'); MP4ThumbsAndGif::getImage($videoFileName, 'gif'); } - - + + $obj->error = false; $obj->filename = $filename; $obj->duration = $duration;