diff --git a/objects/functions.php b/objects/functions.php index e2dcfcd751..0c1b4b13c5 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -18,15 +18,16 @@ if (!isset($global) || !is_array($global)) { */ if (!function_exists('str_starts_with')) { - function str_starts_with(string $Haystack, string $Needle): bool { + function str_starts_with(string $Haystack, string $Needle): bool + { return substr($Haystack, 0, strlen($Needle)) === $Needle; } - } if (!function_exists('xss_esc')) { - function xss_esc($text) { + function xss_esc($text) + { if (empty($text)) { return ""; } @@ -45,33 +46,34 @@ if (!function_exists('xss_esc')) { $result = str_replace(['&amp;'], ['&'], $result); return $result; } - } -function xss_esc_back($text) { +function xss_esc_back($text) +{ $text = htmlspecialchars_decode($text, ENT_QUOTES); $text = str_replace(['&', ''', "#039;"], [" ", "`", "`"], $text); return $text; } // Make sure SecureVideosDirectory will be the first -function cmpPlugin($a, $b) { +function cmpPlugin($a, $b) +{ if ( - $a['name'] === 'SecureVideosDirectory' || - $a['name'] === 'GoogleAds_IMA' || - $a['name'] === 'Subscription' || - $a['name'] === 'PayPerView' || - $a['name'] === 'FansSubscriptions' + $a['name'] === 'SecureVideosDirectory' || + $a['name'] === 'GoogleAds_IMA' || + $a['name'] === 'Subscription' || + $a['name'] === 'PayPerView' || + $a['name'] === 'FansSubscriptions' ) { return -1; } elseif ($a['name'] === 'PlayerSkins') { return 1; } elseif ( - $b['name'] === 'SecureVideosDirectory' || - $b['name'] === 'GoogleAds_IMA' || - $b['name'] === 'Subscription' || - $b['name'] === 'PayPerView' || - $b['name'] === 'FansSubscriptions' + $b['name'] === 'SecureVideosDirectory' || + $b['name'] === 'GoogleAds_IMA' || + $b['name'] === 'Subscription' || + $b['name'] === 'PayPerView' || + $b['name'] === 'FansSubscriptions' ) { return 1; } elseif ($b['name'] === 'PlayerSkins') { @@ -82,7 +84,8 @@ function cmpPlugin($a, $b) { // Returns a file size limit in bytes based on the PHP upload_max_filesize // and post_max_size -function file_upload_max_size() { +function file_upload_max_size() +{ static $max_size = -1; if ($max_size < 0) { @@ -99,7 +102,8 @@ function file_upload_max_size() { return $max_size; } -function parse_size($size) { +function parse_size($size) +{ $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size. if ($unit) { @@ -110,7 +114,8 @@ function parse_size($size) { } } -function humanFileSize($size, $unit = "") { +function humanFileSize($size, $unit = "") +{ if ((!$unit && $size >= 1 << 30) || $unit == "GB") { return number_format($size / (1 << 30), 2) . "GB"; } @@ -126,11 +131,13 @@ function humanFileSize($size, $unit = "") { return number_format($size) . " bytes"; } -function get_max_file_size() { +function get_max_file_size() +{ return humanFileSize(file_upload_max_size()); } -function humanTiming($time, $precision = 0, $useDatabaseTime = true, $addAgo = false) { +function humanTiming($time, $precision = 0, $useDatabaseTime = true, $addAgo = false) +{ $time = secondsIntervalFromNow($time, $useDatabaseTime); if ($addAgo) { @@ -147,7 +154,8 @@ function humanTiming($time, $precision = 0, $useDatabaseTime = true, $addAgo = f * @param string $useDatabaseTime good if you are checking the created time * @return string */ -function humanTimingAgo($time, $precision = 0, $useDatabaseTime = true) { +function humanTimingAgo($time, $precision = 0, $useDatabaseTime = true) +{ $time = secondsIntervalFromNow($time, $useDatabaseTime); if (empty($time)) { return __("Now"); @@ -155,7 +163,8 @@ function humanTimingAgo($time, $precision = 0, $useDatabaseTime = true) { return sprintf(__('%s ago'), secondsToHumanTiming($time, $precision)); } -function humanTimingAfterwards($time, $precision = 0, $useDatabaseTime = true) { +function humanTimingAfterwards($time, $precision = 0, $useDatabaseTime = true) +{ if (!is_numeric($time)) { $time = strtotime($time); } @@ -168,7 +177,8 @@ function humanTimingAfterwards($time, $precision = 0, $useDatabaseTime = true) { return __('Coming in') . ' ' . secondsToHumanTiming($time, $precision); } -function secondsToHumanTiming($time, $precision = 0, $addAgo = false) { +function secondsToHumanTiming($time, $precision = 0, $addAgo = false) +{ if (empty($time)) { return __("Now"); } @@ -231,7 +241,8 @@ function secondsToHumanTiming($time, $precision = 0, $addAgo = false) { } } -function checkVideosDir() { +function checkVideosDir() +{ $dir = "../videos"; if (file_exists($dir)) { return is_writable($dir); @@ -239,15 +250,18 @@ function checkVideosDir() { return mkdir($dir); } -function isApache() { +function isApache() +{ return (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false); } -function isPHP($version = "'7.3.0'") { +function isPHP($version = "'7.3.0'") +{ return (version_compare(PHP_VERSION, $version) >= 0); } -function modEnabled($mod_name) { +function modEnabled($mod_name) +{ if (!function_exists('apache_get_modules')) { _ob_start(); phpinfo(INFO_MODULES); @@ -258,77 +272,91 @@ function modEnabled($mod_name) { return in_array('mod_' . $mod_name, apache_get_modules()); } -function modRewriteEnabled() { +function modRewriteEnabled() +{ return modEnabled("rewrite"); } -function modAliasEnabled() { +function modAliasEnabled() +{ return modEnabled("alias"); } -function isFFMPEG() { +function isFFMPEG() +{ return trim(shell_exec('which ffmpeg')); } -function isUnzip() { +function isUnzip() +{ return trim(shell_exec('which unzip')); } -function isExifToo() { +function isExifToo() +{ return trim(shell_exec('which exiftool')); } -function isAPPInstalled($appName) { +function isAPPInstalled($appName) +{ $appName = preg_replace('/[^a-z0-9_-]/i', '', $appName); return trim(shell_exec("which {$appName}")); } -function getPathToApplication() { +function getPathToApplication() +{ return str_replace("install/index.php", "", $_SERVER["SCRIPT_FILENAME"]); } -function getURLToApplication() { +function getURLToApplication() +{ $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $url = explode("install/index.php", $url); return $url[0]; } //max_execution_time = 7200 -function check_max_execution_time() { +function check_max_execution_time() +{ $max_size = ini_get('max_execution_time'); $recomended_size = 7200; return ($recomended_size <= $max_size); } //post_max_size = 100M -function check_post_max_size() { +function check_post_max_size() +{ $max_size = parse_size(ini_get('post_max_size')); $recomended_size = parse_size('100M'); return ($recomended_size <= $max_size); } //upload_max_filesize = 100M -function check_upload_max_filesize() { +function check_upload_max_filesize() +{ $max_size = parse_size(ini_get('upload_max_filesize')); $recomended_size = parse_size('100M'); return ($recomended_size <= $max_size); } //memory_limit = 100M -function check_memory_limit() { +function check_memory_limit() +{ $max_size = parse_size(ini_get('memory_limit')); $recomended_size = parse_size('512M'); return ($recomended_size <= $max_size); } -function base64DataToImage($imgBase64) { +function base64DataToImage($imgBase64) +{ $img = $imgBase64; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); return base64_decode($img); } -function getRealIpAddr() { +function getRealIpAddr() +{ if (isCommandLineInterface()) { $ip = "127.0.0.1"; } else if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet @@ -343,7 +371,8 @@ function getRealIpAddr() { return $ip; } -function cleanString($text) { +function cleanString($text) +{ $utf8 = [ '/[áaâaaäą]/u' => 'a', '/[ÁAÂAÄĄ]/u' => 'A', @@ -389,7 +418,8 @@ function cleanString($text) { return preg_replace(array_keys($utf8), array_values($utf8), $text); } -function safeString($text, $strict = false) { +function safeString($text, $strict = false) +{ $text = strip_tags($text); $text = str_replace(array('&', '<', '>'), array('', '', ''), $text); $text = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '', $text); @@ -403,7 +433,8 @@ function safeString($text, $strict = false) { return $text; } -function cleanURLName($name, $replaceChar = '-') { +function cleanURLName($name, $replaceChar = '-') +{ $name = preg_replace('/[!#$&\'()*+,\\/:;=?@[\\]%"\/\\\\ ]+/', $replaceChar, trim(mb_strtolower(cleanString($name)))); return trim(preg_replace('/[\x00-\x1F\x7F\xD7\xE0]/u', $replaceChar, $name), $replaceChar); } @@ -413,7 +444,8 @@ function cleanURLName($name, $replaceChar = '-') { * if is set $_GET['ignoreCommandLineInterface'] will return false * @return boolean */ -function isCommandLineInterface() { +function isCommandLineInterface() +{ return (empty($_GET['ignoreCommandLineInterface']) && php_sapi_name() === 'cli'); } @@ -423,15 +455,16 @@ function isCommandLineInterface() { * @param array $statusarray associative array with type/message pairs * @return string */ -function status($statusarray) { +function status($statusarray) +{ if (isCommandLineInterface()) { foreach ($statusarray as $status => $message) { echo $status . ":" . $message . "\n"; } } else { echo json_encode(array_map(function ($text) { - return nl2br($text); - }, $statusarray)); + return nl2br($text); + }, $statusarray)); } } @@ -440,12 +473,14 @@ function status($statusarray) { * * @param array $statusarray associative array with type/message pairs */ -function croak($statusarray) { +function croak($statusarray) +{ status($statusarray); die; } -function getSecondsTotalVideosLength() { +function getSecondsTotalVideosLength() +{ $configFile = dirname(__FILE__) . '/../videos/configuration.php'; require_once $configFile; global $global; @@ -473,12 +508,14 @@ function getSecondsTotalVideosLength() { return $seconds; } -function getMinutesTotalVideosLength() { +function getMinutesTotalVideosLength() +{ $seconds = getSecondsTotalVideosLength(); return floor($seconds / 60); } -function secondsToVideoTime($seconds) { +function secondsToVideoTime($seconds) +{ if (!is_numeric($seconds)) { return $seconds; } @@ -489,11 +526,13 @@ function secondsToVideoTime($seconds) { return sprintf('%02d:%02d:%02d', $hours, $mins, $secs); } -function parseSecondsToDuration($seconds) { +function parseSecondsToDuration($seconds) +{ return secondsToVideoTime($seconds); } -function parseDurationToSeconds($str) { +function parseDurationToSeconds($str) +{ if ($str == "00:00:00") { return 0; } @@ -511,11 +550,13 @@ function parseDurationToSeconds($str) { return intval($durationParts[2]) + ($minutes * 60); } -function durationToSeconds($str) { +function durationToSeconds($str) +{ return parseDurationToSeconds($str); } -function secondsToDuration($seconds) { +function secondsToDuration($seconds) +{ return parseSecondsToDuration($seconds); } @@ -525,7 +566,8 @@ function secondsToDuration($seconds) { * @param string $mail * call it before send mail to let AVideo decide the method */ -function setSiteSendMessage(\PHPMailer\PHPMailer\PHPMailer &$mail) { +function setSiteSendMessage(\PHPMailer\PHPMailer\PHPMailer &$mail) +{ global $global; if (empty($mail)) { $mail = new \PHPMailer\PHPMailer\PHPMailer(); @@ -570,11 +612,13 @@ function setSiteSendMessage(\PHPMailer\PHPMailer\PHPMailer &$mail) { session_write_close(); } -function array_iunique($array) { +function array_iunique($array) +{ return array_intersect_key($array, array_unique(array_map("mb_strtolower", $array))); } -function partition(array $list, $totalItens) { +function partition(array $list, $totalItens) +{ $listlen = count($list); _error_log("partition: listlen={$listlen} totalItens={$totalItens}"); $p = ceil($listlen / $totalItens); @@ -590,7 +634,8 @@ function partition(array $list, $totalItens) { return $partition; } -function sendSiteEmail($to, $subject, $message, $fromEmail = '', $fromName = '') { +function sendSiteEmail($to, $subject, $message, $fromEmail = '', $fromName = '') +{ global $advancedCustom; $resp = false; if (empty($to)) { @@ -689,7 +734,8 @@ function sendSiteEmail($to, $subject, $message, $fromEmail = '', $fromName = '') return $resp; } -function sendSiteEmailAsync($to, $subject, $message) { +function sendSiteEmailAsync($to, $subject, $message) +{ global $global; $content = ['to' => $to, 'subject' => $subject, 'message' => $message]; $tmpFile = getTmpFile(); @@ -703,7 +749,8 @@ function sendSiteEmailAsync($to, $subject, $message) { return $pid; } -function createEmailMessageFromTemplate($message) { +function createEmailMessageFromTemplate($message) +{ //check if the message already have a HTML body if (preg_match("/html>/i", $message)) { @@ -721,7 +768,8 @@ function createEmailMessageFromTemplate($message) { return str_replace($replace, $words, $text); } -function sendEmailToSiteOwner($subject, $message) { +function sendEmailToSiteOwner($subject, $message) +{ global $advancedCustom, $global; $subject = UTF8encode($subject); $message = UTF8encode($message); @@ -749,12 +797,13 @@ function sendEmailToSiteOwner($subject, $message) { } } -function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $showinfo = 0, $controls = 1, $time = 0, $objectFit = "") { +function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $showinfo = 0, $controls = 1, $time = 0, $objectFit = "") +{ global $global; //_error_log("parseVideos: $videoString"); if (strpos($videoString, 'youtube.com/embed') !== false) { return $videoString . (parse_url($videoString, PHP_URL_QUERY) ? '&' : '?') . 'modestbranding=1&showinfo=' - . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&t=$time&objectFit=$objectFit"; + . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&t=$time&objectFit=$objectFit"; } if (strpos($videoString, 'iframe') !== false) { // retrieve the video url @@ -770,12 +819,12 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ if (stripos($link, 'embed') !== false) { return $link . (parse_url($link, PHP_URL_QUERY) ? '&' : '?') . 'modestbranding=1&showinfo=' - . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&t=$time&objectFit=$objectFit"; + . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&t=$time&objectFit=$objectFit"; } elseif (strpos($link, 'youtube.com') !== false) { preg_match( - '/[\\?\\&]v=([^\\?\\&]+)/', - $link, - $matches + '/[\\?\\&]v=([^\\?\\&]+)/', + $link, + $matches ); //the ID of the YouTube URL: x6qe_kVaBpg if (empty($matches[1])) { @@ -783,18 +832,18 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ } $id = $matches[1]; return '//www.youtube.com/embed/' . $id . '?modestbranding=1&showinfo=' - . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&te=$time&objectFit=$objectFit"; + . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&te=$time&objectFit=$objectFit"; } elseif (strpos($link, 'youtu.be') !== false) { //https://youtu.be/9XXOBSsPoMU preg_match( - '/youtu.be\/([a-zA-Z0-9_]+)($|\/)/', - $link, - $matches + '/youtu.be\/([a-zA-Z0-9_]+)($|\/)/', + $link, + $matches ); //the ID of the YouTube URL: x6qe_kVaBpg $id = $matches[1]; return '//www.youtube.com/embed/' . $id . '?modestbranding=1&showinfo=' - . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&te=$time&objectFit=$objectFit"; + . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&te=$time&objectFit=$objectFit"; } elseif (strpos($link, 'player.vimeo.com') !== false) { // works on: // http://player.vimeo.com/video/37985580?title=0&byline=0&portrait=0 @@ -805,9 +854,9 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ } elseif (strpos($link, 'vimeo.com/channels') !== false) { //extract the ID preg_match( - '/\/\/(www\.)?vimeo.com\/channels\/[a-z0-9-]+\/(\d+)($|\/)/i', - $link, - $matches + '/\/\/(www\.)?vimeo.com\/channels\/[a-z0-9-]+\/(\d+)($|\/)/i', + $link, + $matches ); //the ID of the Vimeo URL: 71673549 @@ -816,9 +865,9 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ } elseif (strpos($link, 'vimeo.com') !== false) { //extract the ID preg_match( - '/\/\/(www\.)?vimeo.com\/(\d+)($|\/)/', - $link, - $matches + '/\/\/(www\.)?vimeo.com\/(\d+)($|\/)/', + $link, + $matches ); //the ID of the Vimeo URL: 71673549 @@ -827,9 +876,9 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ } elseif (strpos($link, 'dailymotion.com') !== false) { //extract the ID preg_match( - '/\/\/(www\.)?dailymotion.com\/video\/([a-zA-Z0-9_]+)($|\/)/', - $link, - $matches + '/\/\/(www\.)?dailymotion.com\/video\/([a-zA-Z0-9_]+)($|\/)/', + $link, + $matches ); //the ID of the Vimeo URL: 71673549 @@ -838,18 +887,18 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ } elseif (strpos($link, 'metacafe.com') !== false) { //extract the ID preg_match( - '/\/\/(www\.)?metacafe.com\/watch\/([a-zA-Z0-9_\/-]+)$/', - $link, - $matches + '/\/\/(www\.)?metacafe.com\/watch\/([a-zA-Z0-9_\/-]+)$/', + $link, + $matches ); $id = $matches[2]; return '//www.metacafe.com/embed/' . $id; } elseif (strpos($link, 'vid.me') !== false) { //extract the ID preg_match( - '/\/\/(www\.)?vid.me\/([a-zA-Z0-9_-]+)$/', - $link, - $matches + '/\/\/(www\.)?vid.me\/([a-zA-Z0-9_-]+)$/', + $link, + $matches ); $id = $matches[2]; @@ -934,7 +983,7 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ parse_str($url_parsed['query'], $new_qs_parsed); // Here's the other query string $other_query_string = 'modestbranding=1&showinfo=' - . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&t=$time"; + . $showinfo . "&autoplay={$autoplay}&controls=$controls&loop=$loop&mute=$mute&t=$time"; $other_qs_parsed = []; parse_str($other_query_string, $other_qs_parsed); // Stitch the two query strings together @@ -947,11 +996,11 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ $scheme = "{$url_parsed['scheme']}:"; } $new_url = $scheme - . '//' - . $url_parsed['host'] - . $url_parsed['path'] - . '?' - . $final_query_string; + . '//' + . $url_parsed['host'] + . $url_parsed['path'] + . '?' + . $final_query_string; return $new_url; // return data @@ -959,7 +1008,8 @@ function parseVideos($videoString = null, $autoplay = 0, $loop = 0, $mute = 0, $ $canUseCDN = []; -function canUseCDN($videos_id) { +function canUseCDN($videos_id) +{ if (empty($videos_id)) { return false; } @@ -981,7 +1031,8 @@ function canUseCDN($videos_id) { return $canUseCDN[$videos_id]; } -function clearVideosURL($fileName = "") { +function clearVideosURL($fileName = "") +{ global $global; $path = getCacheDir() . "getVideosURL/"; if (empty($path)) { @@ -992,7 +1043,8 @@ function clearVideosURL($fileName = "") { } } -function maxLifetime() { +function maxLifetime() +{ global $maxLifetime; if (!isset($maxLifetime)) { $aws_s3 = AVideoPlugin::getObjectDataIfEnabled('AWS_S3'); @@ -1017,7 +1069,8 @@ function maxLifetime() { $cacheExpirationTime = false; -function cacheExpirationTime() { +function cacheExpirationTime() +{ if (isBot()) { return 604800; // 1 week } @@ -1029,7 +1082,8 @@ function cacheExpirationTime() { return intval($cacheExpirationTime); } -function _getImagesURL($fileName, $type) { +function _getImagesURL($fileName, $type) +{ global $global; $files = []; $source = Video::getSourceFile($fileName, ".jpg"); @@ -1074,7 +1128,8 @@ function _getImagesURL($fileName, $type) { return $files; } -function getVideosURLPDF($fileName) { +function getVideosURLPDF($fileName) +{ global $global; if (empty($fileName)) { return []; @@ -1102,7 +1157,8 @@ function getVideosURLPDF($fileName) { return $files; } -function getVideosURLIMAGE($fileName) { +function getVideosURLIMAGE($fileName) +{ global $global; if (empty($fileName)) { return []; @@ -1138,7 +1194,8 @@ function getVideosURLIMAGE($fileName) { return $files; } -function getVideosURLZIP($fileName) { +function getVideosURLZIP($fileName) +{ global $global; if (empty($fileName)) { return []; @@ -1174,7 +1231,8 @@ function getVideosURLZIP($fileName) { return $files; } -function getVideosURLArticle($fileName) { +function getVideosURLArticle($fileName) +{ global $global; if (empty($fileName)) { return []; @@ -1194,7 +1252,8 @@ function getVideosURLArticle($fileName) { return $files; } -function getVideosURLAudio($fileName, $fileNameisThePath = false) { +function getVideosURLAudio($fileName, $fileNameisThePath = false) +{ global $global; if (empty($fileName)) { return []; @@ -1247,11 +1306,13 @@ function getVideosURLAudio($fileName, $fileNameisThePath = false) { return $files; } -function getVideosURL($fileName, $cache = true) { +function getVideosURL($fileName, $cache = true) +{ return getVideosURL_V2($fileName); // disable this function soon } -function getVideosURLMP4Only($fileName) { +function getVideosURLMP4Only($fileName) +{ $allFiles = getVideosURL_V2($fileName); if (is_array($allFiles)) { foreach ($allFiles as $key => $value) { @@ -1265,7 +1326,8 @@ function getVideosURLMP4Only($fileName) { return []; } -function getVideosURLMP3Only($fileName) { +function getVideosURLMP3Only($fileName) +{ $allFiles = getVideosURL_V2($fileName); if (is_array($allFiles)) { foreach ($allFiles as $key => $value) { @@ -1279,7 +1341,8 @@ function getVideosURLMP3Only($fileName) { return []; } -function getVideosURLWEBMOnly($fileName) { +function getVideosURLWEBMOnly($fileName) +{ $allFiles = getVideosURL_V2($fileName); // disable this function soon if (is_array($allFiles)) { foreach ($allFiles as $key => $value) { @@ -1293,15 +1356,18 @@ function getVideosURLWEBMOnly($fileName) { return []; } -function getVideosURLMP4WEBMOnly($fileName) { +function getVideosURLMP4WEBMOnly($fileName) +{ return array_merge(getVideosURLMP4Only($fileName), getVideosURLWEBMOnly($fileName)); } -function getVideosURLMP4WEBMMP3Only($fileName) { +function getVideosURLMP4WEBMMP3Only($fileName) +{ return array_merge(getVideosURLMP4Only($fileName), getVideosURLWEBMOnly($fileName), getVideosURLMP3Only($fileName)); } -function getVideosURLOnly($fileName, $includeOffline = true) { +function getVideosURLOnly($fileName, $includeOffline = true) +{ $allFiles = getVideosURL_V2($fileName); // disable this function soon foreach ($allFiles as $key => $value) { if ($value['type'] !== 'video' || (!$includeOffline && preg_match('/offline/i', $key))) { @@ -1311,7 +1377,8 @@ function getVideosURLOnly($fileName, $includeOffline = true) { return $allFiles; } -function getAudioURLOnly($fileName) { +function getAudioURLOnly($fileName) +{ $allFiles = getVideosURL_V2($fileName); // disable this function soon foreach ($allFiles as $key => $value) { if ($value['type'] !== 'audio') { @@ -1321,7 +1388,8 @@ function getAudioURLOnly($fileName) { return $allFiles; } -function getAudioOrVideoURLOnly($fileName) { +function getAudioOrVideoURLOnly($fileName) +{ $allFiles = getVideosURL_V2($fileName); // disable this function soon foreach ($allFiles as $key => $value) { if ($value['type'] !== 'video' && $value['type'] !== 'audio') { @@ -1331,13 +1399,15 @@ function getAudioOrVideoURLOnly($fileName) { return $allFiles; } -function getVideosDir() { +function getVideosDir() +{ return Video::getStoragePath(); } $getVideosURL_V2Array = []; -function getVideosURL_V2($fileName, $recreateCache = false) { +function getVideosURL_V2($fileName, $recreateCache = false) +{ global $global, $getVideosURL_V2Array; if (empty($fileName)) { return []; @@ -1378,9 +1448,9 @@ function getVideosURL_V2($fileName, $recreateCache = false) { // check if is a dummy file and the URL still wrong $pathFilesize = filesize($value['path']); if ( - $value['type'] === 'video' && // is a video - preg_match("/^{$preg_match_url}/", $value['url']) && // the URL is the same as the main domain - $pathFilesize < 20 + $value['type'] === 'video' && // is a video + preg_match("/^{$preg_match_url}/", $value['url']) && // the URL is the same as the main domain + $pathFilesize < 20 ) { // file size is small _error_log("getVideosURL_V2:: dummy file found, fix cache " . json_encode(["/^{$preg_match_url}/", $value['url'], preg_match("/^{$preg_match_url}video/", $value['url']), $pathFilesize, $value])); unset($files); @@ -1480,7 +1550,9 @@ function getVideosURL_V2($fileName, $recreateCache = false) { $files[$key] = AVideoPlugin::modifyURL($_file); } TimeLogEnd($timeName, __LINE__); - $files = array_merge($extraFiles, $files); + if (is_array($extraFiles)) { + $files = array_merge($extraFiles, $files); + } ObjectYPT::setCache($cacheName, $files); } if (is_array($files)) { @@ -1493,7 +1565,8 @@ function getVideosURL_V2($fileName, $recreateCache = false) { } //Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. -function sortVideosURL($a, $b) { +function sortVideosURL($a, $b) +{ if ($a['type'] == 'video') { $aRes = getResolutionFromFilename($a['filename']); $bRes = getResolutionFromFilename($b['filename']); @@ -1503,7 +1576,8 @@ function sortVideosURL($a, $b) { return 0; } -function getResolutionFromFilename($filename) { +function getResolutionFromFilename($filename) +{ global $getResolutionFromFilenameArray; if (!isset($getResolutionFromFilenameArray)) { @@ -1533,7 +1607,8 @@ function getResolutionFromFilename($filename) { return $res; } -function getSources($fileName, $returnArray = false, $try = 0) { +function getSources($fileName, $returnArray = false, $try = 0) +{ if ($returnArray) { $videoSources = $audioTracks = $subtitleTracks = []; } else { @@ -1604,7 +1679,8 @@ function getSources($fileName, $returnArray = false, $try = 0) { * @param string $file_src * @return array get image size with cache */ -function getimgsize($file_src) { +function getimgsize($file_src) +{ global $_getimagesize; if (empty($file_src) || !file_exists($file_src)) { return [0, 0]; @@ -1644,7 +1720,8 @@ function getimgsize($file_src) { return $size; } -function getImageFormat($file) { +function getImageFormat($file) +{ $size = getimgsize($file); if ($size === false) { return false; @@ -1682,7 +1759,8 @@ function getImageFormat($file) { return array('format' => $format, 'extension' => $extension); } -function im_resize($file_src, $file_dest, $wd, $hd, $q = 80) { +function im_resize($file_src, $file_dest, $wd, $hd, $q = 80) +{ if (empty($file_dest)) { return false; } @@ -1790,7 +1868,8 @@ function im_resize($file_src, $file_dest, $wd, $hd, $q = 80) { return true; } -function im_resizeV2($file_src, $file_dest, $wd, $hd, $q = 80) { +function im_resizeV2($file_src, $file_dest, $wd, $hd, $q = 80) +{ //_error_log("im_resizeV2: $file_src, $file_dest, $wd, $hd, $q"); $newImage = im_resize($file_src, $file_dest, $wd, $hd, 100); @@ -1828,7 +1907,8 @@ function im_resizeV2($file_src, $file_dest, $wd, $hd, $q = 80) { return $saved; } -function scaleUpAndMantainAspectRatioFinalSizes($new_w, $old_w, $new_h, $old_h) { +function scaleUpAndMantainAspectRatioFinalSizes($new_w, $old_w, $new_h, $old_h) +{ if ($new_w < $new_h) { $aspectRatio = $new_w / $old_w; @@ -1849,7 +1929,8 @@ function scaleUpAndMantainAspectRatioFinalSizes($new_w, $old_w, $new_h, $old_h) return array('w' => $thumb_w, 'h' => $thumb_h); } -function scaleUpImage($file_src, $file_dest, $wd, $hd) { +function scaleUpImage($file_src, $file_dest, $wd, $hd) +{ if (!file_exists($file_src)) { return false; @@ -1924,7 +2005,8 @@ function scaleUpImage($file_src, $file_dest, $wd, $hd) { return $result; } -function im_resizePNG($file_src, $file_dest, $wd, $hd) { +function im_resizePNG($file_src, $file_dest, $wd, $hd) +{ $srcImage = imagecreatefrompng($file_src); $ws = imagesx($srcImage); $hs = imagesy($srcImage); @@ -1934,16 +2016,16 @@ function im_resizePNG($file_src, $file_dest, $wd, $hd) { imagesavealpha($targetImage, true); imagecopyresampled( - $targetImage, - $srcImage, - 0, - 0, - 0, - 0, - $wd, - $hd, - $ws, - $hs + $targetImage, + $srcImage, + 0, + 0, + 0, + 0, + $wd, + $hd, + $ws, + $hs ); $saved = imagepng($targetImage, $file_dest); @@ -1951,7 +2033,8 @@ function im_resizePNG($file_src, $file_dest, $wd, $hd) { return $saved; } -function im_resizeV3($file_src, $file_dest, $wd, $hd) { +function im_resizeV3($file_src, $file_dest, $wd, $hd) +{ return im_resizeV2($file_src, $file_dest, $wd, $hd); // ffmpeg disabled _error_log("im_resizeV3: $file_src, $file_dest, $wd, $hd"); @@ -1964,47 +2047,51 @@ function im_resizeV3($file_src, $file_dest, $wd, $hd) { if (false) { - class Imagick { + class Imagick + { const FILTER_BOX = 1; - function getImageFormat() { + function getImageFormat() + { return ''; } - function coalesceImages() { + function coalesceImages() + { return new Imagick(); } - function nextImage() { + function nextImage() + { return true; } - function resizeImage() { - + function resizeImage() + { } - function deconstructImages() { + function deconstructImages() + { return new Imagick(); } - function clear() { - + function clear() + { } - function destroy() { - + function destroy() + { } - function writeImages() { - + function writeImages() + { } - } - } -function im_resize_gif($file_src, $file_dest, $max_width, $max_height) { +function im_resize_gif($file_src, $file_dest, $max_width, $max_height) +{ if (class_exists('Imagick')) { $imagick = new Imagick($file_src); @@ -2025,7 +2112,8 @@ function im_resize_gif($file_src, $file_dest, $max_width, $max_height) { } } -function im_resize_max_size($file_src, $file_dest, $max_width, $max_height) { +function im_resize_max_size($file_src, $file_dest, $max_width, $max_height) +{ $fn = $file_src; $extension = mb_strtolower(pathinfo($file_dest, PATHINFO_EXTENSION)); @@ -2094,7 +2182,8 @@ function im_resize_max_size($file_src, $file_dest, $max_width, $max_height) { @unlink($tmpFile); } -function convertImage($originalImage, $outputImage, $quality) { +function convertImage($originalImage, $outputImage, $quality) +{ $imagetype = 0; if (function_exists('exif_imagetype')) { $imagetype = exif_imagetype($originalImage); @@ -2168,7 +2257,8 @@ function convertImage($originalImage, $outputImage, $quality) { return $response; } -function decideMoveUploadedToVideos($tmp_name, $filename, $type = "video") { +function decideMoveUploadedToVideos($tmp_name, $filename, $type = "video") +{ if ($filename == '.zip') { return false; } @@ -2231,7 +2321,8 @@ function decideMoveUploadedToVideos($tmp_name, $filename, $type = "video") { return $destinationFile; } -function unzipDirectory($filename, $destination) { +function unzipDirectory($filename, $destination) +{ global $global; // Wait a couple of seconds to make sure the file has completed transfer sleep(2); @@ -2280,7 +2371,8 @@ function unzipDirectory($filename, $destination) { @unlink($filename); } -function make_path($path) { +function make_path($path) +{ $created = false; if (substr($path, -1) !== DIRECTORY_SEPARATOR) { $path = pathinfo($path, PATHINFO_DIRNAME); @@ -2312,7 +2404,8 @@ function make_path($path) { * @param string $allowedExtensions * @return string */ -function cleanDirectory($dir, $allowedExtensions = ['key', 'm3u8', 'ts', 'vtt', 'jpg', 'gif', 'mp3', 'webm', 'webp']) { +function cleanDirectory($dir, $allowedExtensions = ['key', 'm3u8', 'ts', 'vtt', 'jpg', 'gif', 'mp3', 'webm', 'webp']) +{ $ffs = scandir($dir); unset($ffs[array_search('.', $ffs, true)]); @@ -2335,7 +2428,8 @@ function cleanDirectory($dir, $allowedExtensions = ['key', 'm3u8', 'ts', 'vtt', } } -function isAnyStorageEnabled() { +function isAnyStorageEnabled() +{ if ($yptStorage = AVideoPlugin::loadPluginIfEnabled("YPTStorage")) { return true; } elseif ($aws_s3 = AVideoPlugin::loadPluginIfEnabled("AWS_S3")) { @@ -2350,13 +2444,14 @@ function isAnyStorageEnabled() { if (!function_exists('mime_content_type')) { - function mime_content_type($filename) { + function mime_content_type($filename) + { return mime_content_type_per_filename($filename); } - } -function fontAwesomeClassName($filename) { +function fontAwesomeClassName($filename) +{ $mime_type = mime_content_type_per_filename($filename); // List of official MIME Types: http://www.iana.org/assignments/media-types/media-types.xhtml $icon_classes = [ @@ -2391,7 +2486,8 @@ function fontAwesomeClassName($filename) { return 'fas fa-file'; } -function mime_content_type_per_filename($filename) { +function mime_content_type_per_filename($filename) +{ $mime_types = [ 'txt' => 'text/plain', 'htm' => 'text/html', @@ -2485,7 +2581,8 @@ function mime_content_type_per_filename($filename) { } } -function combineFiles($filesArray, $extension = "js") { +function combineFiles($filesArray, $extension = "js") +{ global $global, $advancedCustom; if ($extension == 'js' && isBot()) { @@ -2551,7 +2648,8 @@ function combineFiles($filesArray, $extension = "js") { return getURL($relativeDir . $md5FileName); } -function combineFilesHTML($filesArray, $extension = "js", $doNotCombine = false) { +function combineFilesHTML($filesArray, $extension = "js", $doNotCombine = false) +{ if (empty($doNotCombine)) { $jsURL = combineFiles($filesArray, $extension); } @@ -2580,7 +2678,8 @@ function combineFilesHTML($filesArray, $extension = "js", $doNotCombine = false) } } -function getTagIfExists($relativePath) { +function getTagIfExists($relativePath) +{ global $global; $relativePath = str_replace('\\', '/', $relativePath); $file = "{$global['systemRootPath']}{$relativePath}"; @@ -2601,7 +2700,8 @@ function getTagIfExists($relativePath) { } } -function getImageTagIfExists($relativePath, $title = '', $id = '', $style = '', $class = 'img img-responsive', $lazyLoad = false, $preloadImage = false) { +function getImageTagIfExists($relativePath, $title = '', $id = '', $style = '', $class = 'img img-responsive', $lazyLoad = false, $preloadImage = false) +{ global $global; $relativePathOriginal = $relativePath; $relativePath = getRelativePath($relativePath); @@ -2648,7 +2748,8 @@ function getImageTagIfExists($relativePath, $title = '', $id = '', $style = '', return $img; } -function createWebPIfNotExists($path) { +function createWebPIfNotExists($path) +{ if (version_compare(PHP_VERSION, '8.0.0') < 0 || !file_exists($path)) { return $path; } @@ -2664,7 +2765,8 @@ function createWebPIfNotExists($path) { return $nextGenPath; } -function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation = '', $title = '', $preloadImage = false, $doNotUseAnimatedGif = false) { +function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation = '', $title = '', $preloadImage = false, $doNotUseAnimatedGif = false) +{ $id = uniqid(); //getImageTagIfExists($relativePath, $title = '', $id = '', $style = '', $class = 'img img-responsive', $lazyLoad = false, $preloadImage=false) $img = getImageTagIfExists($relativePath, $title, "thumbsJPG{$id}", '', 'thumbsJPG img img-responsive', false, true) . PHP_EOL; @@ -2674,7 +2776,8 @@ function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimat return '
' . $img . '
'; } -function getRelativePath($path) { +function getRelativePath($path) +{ global $global; $relativePath = ''; $parts = explode('view/img/', $path); @@ -2698,7 +2801,8 @@ function getRelativePath($path) { return $parts2[0]; } -function local_get_contents($path) { +function local_get_contents($path) +{ if (function_exists('fopen')) { $myfile = fopen($path, "r") or die("Unable to open file! [{$path}]"); $text = fread($myfile, filesize($path)); @@ -2707,14 +2811,16 @@ function local_get_contents($path) { } } -function getSelfUserAgent() { +function getSelfUserAgent() +{ global $global, $AVideoStreamer_UA; $agent = $AVideoStreamer_UA . "_"; $agent .= md5($global['salt']); return $agent; } -function isValidM3U8Link($url, $timeout = 3) { +function isValidM3U8Link($url, $timeout = 3) +{ if (!isValidURL($url)) { return false; } @@ -2727,7 +2833,8 @@ function isValidM3U8Link($url, $timeout = 3) { return false; } -function copy_remotefile_if_local_is_smaller($url, $destination) { +function copy_remotefile_if_local_is_smaller($url, $destination) +{ if (file_exists($destination)) { $size = filesize($destination); $remote_size = getUsageFromURL($url); @@ -2741,7 +2848,8 @@ function copy_remotefile_if_local_is_smaller($url, $destination) { return file_put_contents($destination, $content); } -function url_get_contents($url, $ctx = "", $timeout = 0, $debug = false) { +function url_get_contents($url, $ctx = "", $timeout = 0, $debug = false) +{ global $global, $mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase, $mysqlPort; if (!isValidURLOrPath($url)) { _error_log('url_get_contents Cannot download ' . $url); @@ -2838,7 +2946,8 @@ function url_get_contents($url, $ctx = "", $timeout = 0, $debug = false) { return false; } -function getUpdatesFilesArray() { +function getUpdatesFilesArray() +{ global $config, $global; if (!class_exists('User') || !User::isAdmin()) { return []; @@ -2859,7 +2968,8 @@ function getUpdatesFilesArray() { return $updateFiles; } -function thereIsAnyUpdate() { +function thereIsAnyUpdate() +{ if (!User::isAdmin()) { return false; } @@ -2874,7 +2984,8 @@ function thereIsAnyUpdate() { return @$_SESSION['sessionCache'][$name]; } -function thereIsAnyRemoteUpdate() { +function thereIsAnyRemoteUpdate() +{ if (!User::isAdmin()) { return false; } @@ -2906,7 +3017,8 @@ function thereIsAnyRemoteUpdate() { return $_SESSION['sessionCache'][$name]; } -function UTF8encode($data) { +function UTF8encode($data) +{ if (emptyHTML($data)) { return $data; } @@ -2932,7 +3044,8 @@ function UTF8encode($data) { } //detect search engine bots -function isBot() { +function isBot() +{ global $_isBot; if (empty($_SERVER['HTTP_USER_AGENT'])) { return true; @@ -2980,7 +3093,8 @@ function isBot() { * @param string $adaptive * @return boolean */ -function tail($filepath, $lines = 1, $adaptive = true, $returnArray = false) { +function tail($filepath, $lines = 1, $adaptive = true, $returnArray = false) +{ if (!function_exists('mb_strlen')) { $msg = "AVideoLog::ERROR you need to install the mb_strlen function to make it work, please the command 'sudo apt install php-mbstring'"; if ($returnArray) { @@ -3048,7 +3162,8 @@ function tail($filepath, $lines = 1, $adaptive = true, $returnArray = false) { } } -function encryptPassword($password, $noSalt = false) { +function encryptPassword($password, $noSalt = false) +{ global $advancedCustom, $global, $advancedCustomUser; if (!empty($advancedCustomUser->encryptPasswordsWithSalt) && !empty($global['salt']) && empty($noSalt)) { $password .= $global['salt']; @@ -3057,7 +3172,8 @@ function encryptPassword($password, $noSalt = false) { return md5(hash("whirlpool", sha1($password))); } -function encryptPasswordVerify($password, $hash, $encodedPass = false) { +function encryptPasswordVerify($password, $hash, $encodedPass = false) +{ global $advancedCustom, $global; if (!$encodedPass || $encodedPass === 'false') { //_error_log("encryptPasswordVerify: encrypt"); @@ -3087,7 +3203,8 @@ function encryptPasswordVerify($password, $hash, $encodedPass = false) { return $isValid; } -function isMobile($userAgent = null, $httpHeaders = null) { +function isMobile($userAgent = null, $httpHeaders = null) +{ if (empty($userAgent) && empty($_SERVER["HTTP_USER_AGENT"])) { return false; } @@ -3098,7 +3215,8 @@ function isMobile($userAgent = null, $httpHeaders = null) { return $detect->isMobile($userAgent, $httpHeaders); } -function isAndroid() { +function isAndroid() +{ global $global; require_once $global['systemRootPath'] . 'objects/Mobile_Detect.php'; $detect = new Mobile_Detect(); @@ -3106,11 +3224,13 @@ function isAndroid() { return $detect->is('AndroidOS'); } -function isChannelPage() { +function isChannelPage() +{ return strpos($_SERVER["SCRIPT_NAME"], 'view/channel.php') !== false; } -function isAVideoMobileApp($user_agent = "") { +function isAVideoMobileApp($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -3128,7 +3248,8 @@ function isAVideoMobileApp($user_agent = "") { return false; } -function isAVideoEncoder($user_agent = "") { +function isAVideoEncoder($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -3146,21 +3267,24 @@ function isAVideoEncoder($user_agent = "") { return false; } -function isCDN() { +function isCDN() +{ if (empty($_SERVER['HTTP_CDN_HOST'])) { return false; } return isFromCDN($_SERVER['HTTP_CDN_HOST']); } -function isFromCDN($url) { +function isFromCDN($url) +{ if (preg_match('/cdn.ypt.me/i', $url)) { return true; } return false; } -function isAVideo($user_agent = "") { +function isAVideo($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -3178,7 +3302,8 @@ function isAVideo($user_agent = "") { return false; } -function isAVideoEncoderOnSameDomain() { +function isAVideoEncoderOnSameDomain() +{ $url = isAVideoEncoder(); if (empty($url)) { return false; @@ -3187,7 +3312,8 @@ function isAVideoEncoderOnSameDomain() { return isSameDomainAsMyAVideo($url); } -function isSameDomainAsMyAVideo($url) { +function isSameDomainAsMyAVideo($url) +{ global $global; if (empty($url)) { return false; @@ -3195,7 +3321,8 @@ function isSameDomainAsMyAVideo($url) { return isSameDomain($url, $global['webSiteRootURL']) || isSameDomain($url, getCDN()); } -function getRefferOrOrigin() { +function getRefferOrOrigin() +{ $url = ''; if (!empty($_SERVER['HTTP_REFERER'])) { $url = $_SERVER['HTTP_REFERER']; @@ -3205,7 +3332,8 @@ function getRefferOrOrigin() { return $url; } -function requestComesFromSameDomainAsMyAVideo() { +function requestComesFromSameDomainAsMyAVideo() +{ global $global; $url = getRefferOrOrigin(); //var_dump($_SERVER);exit; @@ -3213,14 +3341,16 @@ function requestComesFromSameDomainAsMyAVideo() { return isSameDomain($url, $global['webSiteRootURL']) || isSameDomain($url, getCDN()) || isFromCDN($url); } -function forbidIfIsUntrustedRequest($logMsg = '', $approveAVideoUserAgent = true) { +function forbidIfIsUntrustedRequest($logMsg = '', $approveAVideoUserAgent = true) +{ global $global; if (isUntrustedRequest($logMsg, $approveAVideoUserAgent)) { forbiddenPage('Invalid Request ' . getRealIpAddr(), true); } } -function isUntrustedRequest($logMsg = '', $approveAVideoUserAgent = true) { +function isUntrustedRequest($logMsg = '', $approveAVideoUserAgent = true) +{ global $global; if (!empty($global['bypassSameDomainCheck']) || isCommandLineInterface()) { return false; @@ -3236,14 +3366,16 @@ function isUntrustedRequest($logMsg = '', $approveAVideoUserAgent = true) { return false; } -function forbidIfItIsNotMyUsersId($users_id, $logMsg = '') { +function forbidIfItIsNotMyUsersId($users_id, $logMsg = '') +{ if (itIsNotMyUsersId($users_id)) { _error_log("forbidIfItIsNotMyUsersId: [{$users_id}]!=[" . User::getId() . "] {$logMsg}"); forbiddenPage('It is not your user ' . getRealIpAddr(), true); } } -function itIsNotMyUsersId($users_id) { +function itIsNotMyUsersId($users_id) +{ $users_id = intval($users_id); if (empty($users_id)) { return false; @@ -3254,11 +3386,13 @@ function itIsNotMyUsersId($users_id) { return User::getId() != $users_id; } -function requestComesFromSafePlace() { +function requestComesFromSafePlace() +{ return (requestComesFromSameDomainAsMyAVideo() || isAVideo()); } -function addGlobalTokenIfSameDomain($url) { +function addGlobalTokenIfSameDomain($url) +{ if (!filter_var($url, FILTER_VALIDATE_URL) || (empty($_GET['livelink']) || !preg_match("/^http.*/i", $_GET['livelink']))) { return $url; } @@ -3268,7 +3402,8 @@ function addGlobalTokenIfSameDomain($url) { return addQueryStringParameter($url, 'globalToken', getToken(60)); } -function isGlobalTokenValid() { +function isGlobalTokenValid() +{ if (empty($_REQUEST['globalToken'])) { return false; } @@ -3283,7 +3418,8 @@ function isGlobalTokenValid() { * * @return string */ -function removeQueryStringParameter($url, $varname) { +function removeQueryStringParameter($url, $varname) +{ $parsedUrl = parse_url($url); $query = []; @@ -3311,7 +3447,8 @@ function removeQueryStringParameter($url, $varname) { * * @return string */ -function addQueryStringParameter($url, $varname, $value) { +function addQueryStringParameter($url, $varname, $value) +{ if ($value === null || $value === '') { return removeQueryStringParameter($url, $varname); } @@ -3342,14 +3479,16 @@ function addQueryStringParameter($url, $varname, $value) { return $scheme . '//' . $parsedUrl['host'] . $port . $path . $query; } -function isSameDomain($url1, $url2) { +function isSameDomain($url1, $url2) +{ if (empty($url1) || empty($url2)) { return false; } return (get_domain($url1) === get_domain($url2)); } -function isAVideoStreamer($user_agent = "") { +function isAVideoStreamer($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -3364,7 +3503,8 @@ function isAVideoStreamer($user_agent = "") { return false; } -function isAVideoUserAgent($user_agent = "") { +function isAVideoUserAgent($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -3386,7 +3526,8 @@ function isAVideoUserAgent($user_agent = "") { return false; } -function isAVideoStorage($user_agent = "") { +function isAVideoStorage($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -3404,7 +3545,8 @@ function isAVideoStorage($user_agent = "") { return false; } -function get_domain($url, $ifEmptyReturnSameString = false) { +function get_domain($url, $ifEmptyReturnSameString = false) +{ $pieces = parse_url($url); $domain = $pieces['host'] ?? ''; if (empty($domain)) { @@ -3421,7 +3563,8 @@ function get_domain($url, $ifEmptyReturnSameString = false) { return false; } -function verify($url) { +function verify($url) +{ global $global; ini_set('default_socket_timeout', 5); $cacheFile = sys_get_temp_dir() . '/' . md5($url) . "_verify.log"; @@ -3455,7 +3598,8 @@ function verify($url) { return json_decode($result); } -function isVerified($url) { +function isVerified($url) +{ $resultV = verify($url); if (!empty($resultV) && !$resultV->verified) { error_log("Error on Login not verified"); @@ -3464,7 +3608,8 @@ function isVerified($url) { return true; } -function siteMap() { +function siteMap() +{ _error_log("siteMap: start"); ini_set('memory_limit', '-1'); ini_set('max_execution_time', 0); @@ -3660,7 +3805,8 @@ function siteMap() { return $newXML5; } -function object_to_array($obj) { +function object_to_array($obj) +{ //only process if it's an object or array being passed to the function if (is_object($obj) || is_array($obj)) { $ret = (array) $obj; @@ -3676,7 +3822,8 @@ function object_to_array($obj) { } } -function allowOrigin() { +function allowOrigin() +{ global $global; cleanUpAccessControlHeader(); $HTTP_ORIGIN = empty($_SERVER['HTTP_ORIGIN']) ? @$_SERVER['HTTP_REFERER'] : $_SERVER['HTTP_ORIGIN']; @@ -3693,7 +3840,8 @@ function allowOrigin() { header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); } -function cleanUpAccessControlHeader() { +function cleanUpAccessControlHeader() +{ if (!headers_sent()) { foreach (headers_list() as $header) { if (preg_match('/Access-Control-Allow-Origin/i', $header)) { @@ -3704,7 +3852,8 @@ function cleanUpAccessControlHeader() { } } -function rrmdir($dir) { +function rrmdir($dir) +{ //if(preg_match('/cache/i', $dir)){_error_log("rrmdir($dir) ". json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));exit;} $dir = str_replace(['//', '\\\\'], DIRECTORY_SEPARATOR, $dir); @@ -3751,7 +3900,8 @@ function rrmdir($dir) { } } -function rrmdirCommandLine($dir, $async = false) { +function rrmdirCommandLine($dir, $async = false) +{ if (is_dir($dir)) { $dir = escapeshellarg($dir); if (isWindows()) { @@ -3772,7 +3922,8 @@ function rrmdirCommandLine($dir, $async = false) { * You can now configure it on the configuration.php * @return boolean */ -function ddosProtection() { +function ddosProtection() +{ global $global; $maxCon = empty($global['ddosMaxConnections']) ? 40 : $global['ddosMaxConnections']; $secondTimeout = empty($global['ddosSecondTimeout']) ? 5 : $global['ddosSecondTimeout']; @@ -3821,7 +3972,8 @@ function ddosProtection() { return true; } -function getAdsLeaderBoardBigVideo() { +function getAdsLeaderBoardBigVideo() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3830,7 +3982,8 @@ function getAdsLeaderBoardBigVideo() { return $adCode; } -function getAdsLeaderBoardTop() { +function getAdsLeaderBoardTop() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3839,7 +3992,8 @@ function getAdsLeaderBoardTop() { return $adCode; } -function getAdsChannelLeaderBoardTop() { +function getAdsChannelLeaderBoardTop() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3848,7 +4002,8 @@ function getAdsChannelLeaderBoardTop() { return $adCode; } -function getAdsLeaderBoardTop2() { +function getAdsLeaderBoardTop2() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3857,7 +4012,8 @@ function getAdsLeaderBoardTop2() { return $adCode; } -function getAdsLeaderBoardMiddle() { +function getAdsLeaderBoardMiddle() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3866,7 +4022,8 @@ function getAdsLeaderBoardMiddle() { return $adCode; } -function getAdsLeaderBoardFooter() { +function getAdsLeaderBoardFooter() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3875,7 +4032,8 @@ function getAdsLeaderBoardFooter() { return $adCode; } -function getAdsSideRectangle() { +function getAdsSideRectangle() +{ $ad = AVideoPlugin::getObjectDataIfEnabled('ADs'); $adCode = ''; if (!empty($ad)) { @@ -3884,7 +4042,8 @@ function getAdsSideRectangle() { return $adCode; } -function isToHidePrivateVideos() { +function isToHidePrivateVideos() +{ $obj = AVideoPlugin::getObjectDataIfEnabled("Gallery"); if (!empty($obj)) { return $obj->hidePrivateVideos; @@ -3900,7 +4059,8 @@ function isToHidePrivateVideos() { return false; } -function convertImageToOG($source, $destination) { +function convertImageToOG($source, $destination) +{ if (!file_exists($destination)) { $w = 200; $h = 200; @@ -3916,11 +4076,13 @@ function convertImageToOG($source, $destination) { return $destination; } -function convertImageToRoku($source, $destination) { +function convertImageToRoku($source, $destination) +{ return convertImageIfNotExists($source, $destination, 1280, 720, true); } -function convertImageIfNotExists($source, $destination, $width, $height, $scaleUp = true) { +function convertImageIfNotExists($source, $destination, $width, $height, $scaleUp = true) +{ if (empty($source)) { _error_log("convertImageToRoku: source image is empty"); return false; @@ -3955,17 +4117,20 @@ function convertImageIfNotExists($source, $destination, $width, $height, $scaleU return $destination; } -function ogSite() { +function ogSite() +{ global $global, $config; include $global['systemRootPath'] . 'objects/functionogSite.php'; } -function getOpenGraph($videos_id) { +function getOpenGraph($videos_id) +{ global $global, $config, $advancedCustom; include $global['systemRootPath'] . 'objects/functiongetOpenGraph.php'; } -function getLdJson($videos_id) { +function getLdJson($videos_id) +{ $cache = ObjectYPT::getCache("getLdJson{$videos_id}", 0); if (empty($cache)) { echo $cache; @@ -4035,7 +4200,8 @@ function getLdJson($videos_id) { echo $output; } -function getItemprop($videos_id) { +function getItemprop($videos_id) +{ $cache = ObjectYPT::getCache("getItemprop{$videos_id}", 0); if (empty($cache)) { echo $cache; @@ -4077,7 +4243,8 @@ function getItemprop($videos_id) { echo $output; } -function getOS($user_agent = "") { +function getOS($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -4119,7 +4286,8 @@ function getOS($user_agent = "") { return $os_platform; } -function get_browser_name($user_agent = "") { +function get_browser_name($user_agent = "") +{ if (empty($user_agent)) { $user_agent = @$_SERVER['HTTP_USER_AGENT']; } @@ -4202,10 +4370,10 @@ function get_browser_name($user_agent = "") { // Check for strings commonly used in bot user agents elseif ( - strpos($t, 'crawler') || strpos($t, 'api') || - strpos($t, 'spider') || strpos($t, 'http') || - strpos($t, 'bot') || strpos($t, 'archive') || - strpos($t, 'info') || strpos($t, 'data') + strpos($t, 'crawler') || strpos($t, 'api') || + strpos($t, 'spider') || strpos($t, 'http') || + strpos($t, 'bot') || strpos($t, 'archive') || + strpos($t, 'info') || strpos($t, 'data') ) { return '[Bot] Other'; } @@ -4218,7 +4386,8 @@ function get_browser_name($user_agent = "") { * we need to detect the chrome browser and load an older version * */ -function isOldChromeVersion() { +function isOldChromeVersion() +{ global $global; if (empty($_SERVER['HTTP_USER_AGENT'])) { return false; @@ -4232,7 +4401,8 @@ function isOldChromeVersion() { return false; } -function TimeLogStart($name) { +function TimeLogStart($name) +{ global $global; if (!empty($global['noDebug'])) { return false; @@ -4247,7 +4417,8 @@ function TimeLogStart($name) { return $name; } -function TimeLogEnd($name, $line, $TimeLogLimit = 0.7) { +function TimeLogEnd($name, $line, $TimeLogLimit = 0.7) +{ global $global; if (!empty($global['noDebug']) || empty($global['start'][$name])) { return false; @@ -4266,17 +4437,18 @@ function TimeLogEnd($name, $line, $TimeLogLimit = 0.7) { TimeLogStart($name); } -class AVideoLog { +class AVideoLog +{ public static $DEBUG = 0; public static $WARNING = 1; public static $ERROR = 2; public static $SECURITY = 3; public static $SOCKET = 4; - } -function _error_log_debug($message, $show_args = false) { +function _error_log_debug($message, $show_args = false) +{ $array = debug_backtrace(); $message .= PHP_EOL; foreach ($array as $value) { @@ -4288,7 +4460,8 @@ function _error_log_debug($message, $show_args = false) { _error_log(PHP_EOL . '***' . PHP_EOL . $message . '***'); } -function _error_log($message, $type = 0, $doNotRepeat = false) { +function _error_log($message, $type = 0, $doNotRepeat = false) +{ if (empty($doNotRepeat)) { // do not log it too many times when you are using HLS format, other wise it will fill the log file with the same error $doNotRepeat = preg_match("/hls.php$/", $_SERVER['SCRIPT_NAME']); @@ -4328,7 +4501,8 @@ function _error_log($message, $type = 0, $doNotRepeat = false) { error_log($str); } -function postVariables($url, $array, $httpcodeOnly = true, $timeout = 10) { +function postVariables($url, $array, $httpcodeOnly = true, $timeout = 10) +{ if (!$url || !is_string($url) || !preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url)) { return false; } @@ -4364,7 +4538,8 @@ function postVariables($url, $array, $httpcodeOnly = true, $timeout = 10) { } } -function _session_start(array $options = []) { +function _session_start(array $options = []) +{ try { if (!_empty($_GET['PHPSESSID'])) { if (!User::isLogged()) { @@ -4403,7 +4578,8 @@ function _session_start(array $options = []) { * this is necessary because of the signup from the iframe pages * @return boolean */ -function blackListRegenerateSession() { +function blackListRegenerateSession() +{ if (!requestComesFromSafePlace()) { return false; } @@ -4420,7 +4596,8 @@ function blackListRegenerateSession() { return false; } -function _mysql_connect($persistent = false) { +function _mysql_connect($persistent = false) +{ global $global, $mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase, $mysqlPort, $mysql_connect_was_closed; $checkValues = array('mysqlHost', 'mysqlUser', 'mysqlPass', 'mysqlDatabase'); @@ -4457,7 +4634,8 @@ function _mysql_connect($persistent = false) { } } -function _mysql_commit() { +function _mysql_commit() +{ global $global; if (_mysql_is_open()) { try { @@ -4468,13 +4646,13 @@ function _mysql_commit() { */ @$global['mysqli']->commit(); } catch (Exception $exc) { - } //$global['mysqli'] = false; } } -function _mysql_close() { +function _mysql_close() +{ global $global, $mysql_connect_was_closed; if (_mysql_is_open()) { //_error_log('MySQL Closed '. json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); @@ -4487,13 +4665,13 @@ function _mysql_close() { */ @$global['mysqli']->close(); } catch (Exception $exc) { - } //$global['mysqli'] = false; } } -function _mysql_is_open() { +function _mysql_is_open() +{ global $global, $mysql_connect_was_closed; try { @@ -4507,7 +4685,8 @@ function _mysql_is_open() { return false; } -function remove_utf8_bom($text) { +function remove_utf8_bom($text) +{ if (strlen($text) > 1000000) { return $text; } @@ -4517,7 +4696,8 @@ function remove_utf8_bom($text) { return $text; } -function getCacheDir() { +function getCacheDir() +{ $p = AVideoPlugin::loadPlugin("Cache"); if (empty($p)) { return addLastSlash(sys_get_temp_dir()); @@ -4525,7 +4705,8 @@ function getCacheDir() { return $p->getCacheDir(); } -function clearCache($firstPageOnly = false) { +function clearCache($firstPageOnly = false) +{ global $global; $lockFile = getVideosDir() . '.clearCache.lock'; if (file_exists($lockFile) && filectime($lockFile) > strtotime('-5 minutes')) { @@ -4559,15 +4740,18 @@ function clearCache($firstPageOnly = false) { return true; } -function clearAllUsersSessionCache() { +function clearAllUsersSessionCache() +{ sendSocketMessageToAll(time(), 'socketClearSessionCache'); } -function clearFirstPageCache() { +function clearFirstPageCache() +{ return clearCache(true); } -function getUsageFromFilename($filename, $dir = "") { +function getUsageFromFilename($filename, $dir = "") +{ global $global; if (!empty($global['getUsageFromFilename'])) { // manually add this variable in your configuration.php file to not scan your video usage @@ -4724,7 +4908,8 @@ function getUsageFromFilename($filename, $dir = "") { * return The size of the file referenced by $url, or false if the size * could not be determined. */ -function getUsageFromURL($url) { +function getUsageFromURL($url) +{ global $global; if (!empty($global['doNotGetUsageFromURL'])) { // manually add this variable in your configuration.php file to not scan your video usage @@ -4779,7 +4964,8 @@ function getUsageFromURL($url) { return (int) $result; } -function getDirSize($dir, $forceNew = false) { +function getDirSize($dir, $forceNew = false) +{ global $_getDirSize; if (!isset($_getDirSize)) { @@ -4822,7 +5008,8 @@ function getDirSize($dir, $forceNew = false) { } } -function foldersize($path) { +function foldersize($path) +{ $total_size = 0; $files = scandir($path); $cleanPath = rtrim($path, '/') . '/'; @@ -4843,7 +5030,8 @@ function foldersize($path) { return $total_size; } -function getDiskUsage() { +function getDiskUsage() +{ global $global; $dir = getVideosDir() . ""; $obj = new stdClass(); @@ -4865,11 +5053,13 @@ function getDiskUsage() { return $obj; } -function unsetSearch() { +function unsetSearch() +{ unset($_GET['searchPhrase'], $_POST['searchPhrase'], $_GET['search'], $_GET['q']); } -function encrypt_decrypt($string, $action) { +function encrypt_decrypt($string, $action) +{ global $global; $output = false; @@ -4898,32 +5088,37 @@ function encrypt_decrypt($string, $action) { return $output; } -function compressString($string) { +function compressString($string) +{ if (function_exists("gzdeflate")) { $string = gzdeflate($string, 9); } return $string; } -function decompressString($string) { +function decompressString($string) +{ if (function_exists("gzinflate")) { $string = gzinflate($string); } return $string; } -function encryptString($string) { +function encryptString($string) +{ if (is_object($string) || is_array($string)) { $string = json_encode($string); } return encrypt_decrypt($string, 'encrypt'); } -function decryptString($string) { +function decryptString($string) +{ return encrypt_decrypt($string, 'decrypt'); } -function getToken($timeout = 0, $salt = "") { +function getToken($timeout = 0, $salt = "") +{ global $global; $obj = new stdClass(); $obj->salt = $global['salt'] . $salt; @@ -4943,11 +5138,13 @@ function getToken($timeout = 0, $salt = "") { return encryptString($strObj); } -function isTokenValid($token, $salt = "") { +function isTokenValid($token, $salt = "") +{ return verifyToken($token, $salt); } -function verifyToken($token, $salt = "") { +function verifyToken($token, $salt = "") +{ global $global; $obj = _json_decode(decryptString($token)); if (empty($obj)) { @@ -4969,7 +5166,8 @@ function verifyToken($token, $salt = "") { return true; } -class YPTvideoObject { +class YPTvideoObject +{ public $id; public $title; @@ -4978,7 +5176,8 @@ class YPTvideoObject { public $channelTitle; public $videoLink; - public function __construct($id, $title, $description, $thumbnails, $channelTitle, $videoLink) { + public function __construct($id, $title, $description, $thumbnails, $channelTitle, $videoLink) + { $this->id = $id; $this->title = $title; $this->description = $description; @@ -4986,10 +5185,10 @@ class YPTvideoObject { $this->channelTitle = $channelTitle; $this->videoLink = $videoLink; } - } -function isToShowDuration($type) { +function isToShowDuration($type) +{ $notShowTo = ['pdf', 'article', 'serie', 'zip', 'image', 'live', 'livelinks']; if (in_array($type, $notShowTo)) { return false; @@ -4998,25 +5197,29 @@ function isToShowDuration($type) { } } -function _dieAndLogObject($obj, $prefix = "") { +function _dieAndLogObject($obj, $prefix = "") +{ $objString = json_encode($obj); _error_log($prefix . $objString); die($objString); } -function isAVideoPlayer() { +function isAVideoPlayer() +{ if (isVideo() || isSerie()) { return true; } return false; } -function isFirstPage() { +function isFirstPage() +{ global $isFirstPage, $global; return !empty($isFirstPage) || getSelfURI() === "{$global['webSiteRootURL']}view/"; } -function isVideo() { +function isVideo() +{ global $isModeYouTube, $global; if (!empty($global['doNotLoadPlayer'])) { return false; @@ -5024,12 +5227,14 @@ function isVideo() { return !empty($isModeYouTube) || isPlayList() || isEmbed() || isLive(); } -function isOffline() { +function isOffline() +{ global $_isOffline; return !empty($_isOffline); } -function isVideoTypeEmbed() { +function isVideoTypeEmbed() +{ global $isVideoTypeEmbed; if (isVideo() && !empty($isVideoTypeEmbed) && $videos_id = getVideos_id()) { @@ -5039,21 +5244,25 @@ function isVideoTypeEmbed() { return false; } -function isAudio() { +function isAudio() +{ global $isAudio; return !empty($isAudio); } -function isSerie() { +function isSerie() +{ return isPlayList(); } -function isPlayList() { +function isPlayList() +{ global $isPlayList, $isSerie; return !empty($isSerie) || !empty($isPlayList); } -function isChannel() { +function isChannel() +{ global $isChannel; if (!empty($isChannel) && !isVideo()) { $user_id = 0; @@ -5077,7 +5286,8 @@ function isChannel() { return false; } -function isEmbed() { +function isEmbed() +{ global $isEmbed, $global; if (!empty($global['doNotLoadPlayer'])) { return false; @@ -5085,7 +5295,8 @@ function isEmbed() { return !empty($isEmbed); } -function isWebRTC() { +function isWebRTC() +{ global $isWebRTC, $global; if (!empty($global['doNotLoadPlayer'])) { return false; @@ -5093,7 +5304,8 @@ function isWebRTC() { return !empty($isWebRTC); } -function isLive() { +function isLive() +{ global $isLive, $global; if (!empty($global['doNotLoadPlayer'])) { return false; @@ -5117,7 +5329,8 @@ function isLive() { } } -function isLiveLink() { +function isLiveLink() +{ global $isLiveLink; if (!empty($isLiveLink)) { return $isLiveLink; @@ -5126,7 +5339,8 @@ function isLiveLink() { } } -function getLiveKey() { +function getLiveKey() +{ global $getLiveKey; if (empty($getLiveKey)) { return false; @@ -5134,7 +5348,8 @@ function getLiveKey() { return $getLiveKey; } -function setLiveKey($key, $live_servers_id, $live_index = '') { +function setLiveKey($key, $live_servers_id, $live_index = '') +{ global $getLiveKey; $parameters = Live::getLiveParametersFromKey($key); $key = $parameters['key']; @@ -5155,7 +5370,8 @@ function setLiveKey($key, $live_servers_id, $live_index = '') { return $getLiveKey; } -function isVideoPlayerHasProgressBar() { +function isVideoPlayerHasProgressBar() +{ if (isWebRTC()) { return false; } @@ -5170,7 +5386,8 @@ function isVideoPlayerHasProgressBar() { return false; } -function isHLS() { +function isHLS() +{ global $video, $global; if (isLive()) { return true; @@ -5180,7 +5397,8 @@ function isHLS() { return false; } -function getRedirectUri($returnThisIfRedirectUriIsNotSet = false) { +function getRedirectUri($returnThisIfRedirectUriIsNotSet = false) +{ if (isValidURL(@$_GET['redirectUri'])) { return $_GET['redirectUri']; } @@ -5200,12 +5418,14 @@ function getRedirectUri($returnThisIfRedirectUriIsNotSet = false) { } } -function setRedirectUri($redirectUri) { +function setRedirectUri($redirectUri) +{ _session_start(); $_SESSION['redirectUri'] = $redirectUri; } -function redirectIfRedirectUriIsSet() { +function redirectIfRedirectUriIsSet() +{ $redirectUri = false; if (!empty($_GET['redirectUri'])) { if (isSameDomainAsMyAVideo($_GET['redirectUri'])) { @@ -5226,7 +5446,8 @@ function redirectIfRedirectUriIsSet() { } } -function getRedirectToVideo($videos_id) { +function getRedirectToVideo($videos_id) +{ $redirectUri = getRedirectUri(); $isEmbed = 0; if (stripos($redirectUri, "embed") !== false) { @@ -5239,14 +5460,16 @@ function getRedirectToVideo($videos_id) { return Video::getLink($videos_id, $video['clean_title'], $isEmbed); } -function getRequestURI() { +function getRequestURI() +{ if (empty($_SERVER['REQUEST_URI'])) { return ""; } return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; } -function getSelfURI() { +function getSelfURI() +{ if (empty($_SERVER['PHP_SELF']) || empty($_SERVER['HTTP_HOST'])) { return ""; } @@ -5264,11 +5487,13 @@ function getSelfURI() { return $url; } -function isSameVideoAsSelfURI($url) { +function isSameVideoAsSelfURI($url) +{ return URLsAreSameVideo($url, getSelfURI()); } -function URLsAreSameVideo($url1, $url2) { +function URLsAreSameVideo($url1, $url2) +{ $videos_id1 = getVideoIDFromURL($url1); $videos_id2 = getVideoIDFromURL($url2); if (empty($videos_id1) || empty($videos_id2)) { @@ -5277,7 +5502,8 @@ function URLsAreSameVideo($url1, $url2) { return $videos_id1 === $videos_id2; } -function getVideos_id($returnPlaylistVideosIDIfIsSerie = false) { +function getVideos_id($returnPlaylistVideosIDIfIsSerie = false) +{ global $_getVideos_id; $videos_id = false; if (isset($_getVideos_id) && is_int($_getVideos_id)) { @@ -5320,7 +5546,8 @@ function getVideos_id($returnPlaylistVideosIDIfIsSerie = false) { return $videos_id; } -function getPlayListIndex() { +function getPlayListIndex() +{ global $__playlistIndex; if (empty($__playlistIndex) && !empty($_REQUEST['playlist_index'])) { $__playlistIndex = intval($_REQUEST['playlist_index']); @@ -5328,7 +5555,8 @@ function getPlayListIndex() { return intval($__playlistIndex); } -function getPlayListData() { +function getPlayListData() +{ global $playListData; if (empty($playListData)) { $playListData = array(); @@ -5336,7 +5564,8 @@ function getPlayListData() { return $playListData; } -function getPlayListDataVideosId() { +function getPlayListDataVideosId() +{ $playListData_videos_id = array(); foreach (getPlayListData() as $value) { $playListData_videos_id[] = $value->getVideos_id(); @@ -5344,7 +5573,8 @@ function getPlayListDataVideosId() { return $playListData_videos_id; } -function getPlayListCurrentVideo($setVideos_id = true) { +function getPlayListCurrentVideo($setVideos_id = true) +{ $videos_id = getPlayListCurrentVideosId($setVideos_id); if (empty($videos_id)) { return false; @@ -5353,7 +5583,8 @@ function getPlayListCurrentVideo($setVideos_id = true) { return $video; } -function getPlayListCurrentVideosId($setVideos_id = true) { +function getPlayListCurrentVideosId($setVideos_id = true) +{ $playListData = getPlayListData(); $playlist_index = getPlayListIndex(); if (empty($playListData[$playlist_index])) { @@ -5367,17 +5598,20 @@ function getPlayListCurrentVideosId($setVideos_id = true) { return $videos_id; } -function setPlayListIndex($index) { +function setPlayListIndex($index) +{ global $__playlistIndex; $__playlistIndex = intval($index); } -function setVideos_id($videos_id) { +function setVideos_id($videos_id) +{ global $_getVideos_id; $_getVideos_id = $videos_id; } -function getPlaylists_id() { +function getPlaylists_id() +{ global $_isPlayList; if (!isset($_isPlayList)) { $_isPlayList = false; @@ -5401,7 +5635,8 @@ function getPlaylists_id() { return $_isPlayList; } -function isVideoOrAudioNotEmbed() { +function isVideoOrAudioNotEmbed() +{ if (!isVideo()) { return false; } @@ -5420,7 +5655,8 @@ function isVideoOrAudioNotEmbed() { return false; } -function getVideoIDFromURL($url) { +function getVideoIDFromURL($url) +{ if (preg_match("/v=([0-9]+)/", $url, $matches)) { return intval($matches[1]); } @@ -5449,7 +5685,8 @@ function getVideoIDFromURL($url) { return false; } -function getBackURL() { +function getBackURL() +{ global $global; $backURL = getRedirectUri(); if (empty($backURL)) { @@ -5461,7 +5698,8 @@ function getBackURL() { return $backURL; } -function getHomeURL() { +function getHomeURL() +{ global $global, $advancedCustomUser, $advancedCustom; if (isValidURL($advancedCustomUser->afterLoginGoToURL)) { return $advancedCustomUser->afterLoginGoToURL; @@ -5471,7 +5709,8 @@ function getHomeURL() { return $global['webSiteRootURL']; } -function isValidURL($url) { +function isValidURL($url) +{ //var_dump(empty($url), !is_string($url), preg_match("/^http.*/", $url), filter_var($url, FILTER_VALIDATE_URL)); if (empty($url) || !is_string($url)) { return false; @@ -5482,7 +5721,8 @@ function isValidURL($url) { return false; } -function isValidURLOrPath($str, $insideCacheOrTmpDirOnly = true) { +function isValidURLOrPath($str, $insideCacheOrTmpDirOnly = true) +{ global $global; //var_dump(empty($url), !is_string($url), preg_match("/^http.*/", $url), filter_var($url, FILTER_VALIDATE_URL)); if (empty($str) || !is_string($str)) { @@ -5509,11 +5749,11 @@ function isValidURLOrPath($str, $insideCacheOrTmpDirOnly = true) { foreach ($pathsToCheck as $value) { if ( - str_starts_with($value, $absolutePathTmp) || - str_starts_with($value, '/var/www/') || - str_starts_with($value, $absolutePathCache) || - str_starts_with($value, $global['systemRootPath']) || - str_starts_with($value, getVideosDir()) + str_starts_with($value, $absolutePathTmp) || + str_starts_with($value, '/var/www/') || + str_starts_with($value, $absolutePathCache) || + str_starts_with($value, $global['systemRootPath']) || + str_starts_with($value, getVideosDir()) ) { return true; } @@ -5529,19 +5769,23 @@ function isValidURLOrPath($str, $insideCacheOrTmpDirOnly = true) { return false; } -function hasLastSlash($word) { +function hasLastSlash($word) +{ return substr($word, -1) === '/'; } -function addLastSlash($word) { +function addLastSlash($word) +{ return $word . (hasLastSlash($word) ? "" : "/"); } -function URLHasLastSlash() { +function URLHasLastSlash() +{ return hasLastSlash($_SERVER["REQUEST_URI"]); } -function ucname($str) { +function ucname($str) +{ $str = ucwords(mb_strtolower($str)); foreach (['\'', '-'] as $delim) { @@ -5552,15 +5796,18 @@ function ucname($str) { return $str; } -function sanitize_input($input) { +function sanitize_input($input) +{ return htmlentities(strip_tags($input)); } -function sanitize_array_item(&$item, $key) { +function sanitize_array_item(&$item, $key) +{ $item = sanitize_input($item); } -function getSEOComplement($parameters = []) { +function getSEOComplement($parameters = []) +{ global $config; $allowedTypes = $parameters["allowedTypes"] ?? null; @@ -5608,7 +5855,8 @@ function getSEOComplement($parameters = []) { return $txt; } -function doNOTOrganizeHTMLIfIsPagination() { +function doNOTOrganizeHTMLIfIsPagination() +{ global $global; $page = getCurrentPage(); if ($page > 1) { @@ -5616,7 +5864,8 @@ function doNOTOrganizeHTMLIfIsPagination() { } } -function getCurrentPage() { +function getCurrentPage() +{ if (!empty($_REQUEST['current'])) { return intval($_REQUEST['current']); } elseif (!empty($_POST['current'])) { @@ -5635,7 +5884,8 @@ function getCurrentPage() { return 1; } -function getTrendingLimit() { +function getTrendingLimit() +{ global $advancedCustom; if (empty($advancedCustom)) { $advancedCustom = AVideoPlugin::getObjectData("CustomizeAdvanced"); @@ -5644,17 +5894,20 @@ function getTrendingLimit() { return $daysLimit; } -function getTrendingLimitDate() { +function getTrendingLimitDate() +{ $daysLimit = getTrendingLimit(); $dateDaysLimit = date('Y-m-d H:i:s', strtotime("-{$daysLimit} days")); return $dateDaysLimit; } -function setCurrentPage($current) { +function setCurrentPage($current) +{ $_REQUEST['current'] = intval($current); } -function getRowCount($default = 1000) { +function getRowCount($default = 1000) +{ global $global; if (!empty($_REQUEST['rowCount'])) { $defaultN = intval($_REQUEST['rowCount']); @@ -5674,17 +5927,19 @@ function getRowCount($default = 1000) { return (!empty($defaultN) && $defaultN > 0) ? $defaultN : $default; } -function setRowCount($rowCount) { +function setRowCount($rowCount) +{ $_REQUEST['rowCount'] = intval($rowCount); } -function getSearchVar() { +function getSearchVar() +{ $search = ''; if (!empty($_REQUEST['search'])) { $search = $_REQUEST['search']; } elseif (!empty($_REQUEST['q'])) { $search = $_REQUEST['q']; - }else if (!empty($_REQUEST['searchPhrase'])) { + } else if (!empty($_REQUEST['searchPhrase'])) { $search = $_REQUEST['searchPhrase']; } else if (!empty($_REQUEST['search']['value'])) { $search = $_REQUEST['search']['value']; @@ -5694,7 +5949,8 @@ function getSearchVar() { $cleanSearchHistory = ''; -function cleanSearchVar() { +function cleanSearchVar() +{ global $cleanSearchHistory; $search = getSearchVar(); if (!empty($search)) { @@ -5706,7 +5962,8 @@ function cleanSearchVar() { } } -function reloadSearchVar() { +function reloadSearchVar() +{ global $cleanSearchHistory; $_REQUEST['search'] = $cleanSearchHistory; if (empty($_GET['search'])) { @@ -5717,7 +5974,8 @@ function reloadSearchVar() { } } -function wget($url, $filename, $debug = false) { +function wget($url, $filename, $debug = false) +{ if (empty($url) || $url == "php://input" || !isValidURL($url)) { return false; } @@ -5764,7 +6022,8 @@ function wget($url, $filename, $debug = false) { * @param $infile The full URL to the remote file * @param $outfile The path where to save the file */ -function copyfile_chunked($infile, $outfile) { +function copyfile_chunked($infile, $outfile) +{ $chunksize = 10 * (1024 * 1024); // 10 Megs /** @@ -5845,16 +6104,19 @@ function copyfile_chunked($infile, $outfile) { return $cnt; } -function wgetLockFile($url) { +function wgetLockFile($url) +{ return getTmpDir("YPTWget") . md5($url) . ".lock"; } -function wgetLock($url) { +function wgetLock($url) +{ $file = wgetLockFile($url); return file_put_contents($file, time() . PHP_EOL, FILE_APPEND | LOCK_EX); } -function wgetRemoveLock($url) { +function wgetRemoveLock($url) +{ $filename = wgetLockFile($url); if (!file_exists($filename)) { return false; @@ -5862,16 +6124,19 @@ function wgetRemoveLock($url) { return unlink($filename); } -function getLockFile($name) { +function getLockFile($name) +{ return getTmpDir("YPTLockFile") . md5($name) . ".lock"; } -function setLock($name) { +function setLock($name) +{ $file = getLockFile($name); return file_put_contents($file, time()); } -function isLock($name, $timeout = 60) { +function isLock($name, $timeout = 60) +{ $file = getLockFile($name); if (file_exists($file)) { $time = intval(file_get_contents($file)); @@ -5881,7 +6146,8 @@ function isLock($name, $timeout = 60) { } } -function removeLock($name) { +function removeLock($name) +{ $filename = getLockFile($name); if (!file_exists($filename)) { return false; @@ -5889,7 +6155,8 @@ function removeLock($name) { return unlink($filename); } -function wgetIsLocked($url) { +function wgetIsLocked($url) +{ $filename = wgetLockFile($url); if (!file_exists($filename)) { return false; @@ -5903,7 +6170,8 @@ function wgetIsLocked($url) { } // due the some OS gives a fake is_writable response -function isWritable($dir) { +function isWritable($dir) +{ $dir = rtrim($dir, '/') . '/'; $file = $dir . uniqid(); $result = false; @@ -5919,7 +6187,8 @@ function isWritable($dir) { return $result; } -function _isWritable($dir) { +function _isWritable($dir) +{ if (!isWritable($dir)) { return false; } @@ -5929,7 +6198,8 @@ function _isWritable($dir) { return !empty($bytes); } -function getTmpDir($subdir = "") { +function getTmpDir($subdir = "") +{ global $global; if (empty($_SESSION['getTmpDir'])) { $_SESSION['getTmpDir'] = []; @@ -5957,11 +6227,13 @@ function getTmpDir($subdir = "") { return $tmpDir; } -function getTmpFile() { +function getTmpFile() +{ return getTmpDir("tmpFiles") . uniqid(); } -function getMySQLDate() { +function getMySQLDate() +{ global $global; $sql = "SELECT now() as time FROM configurations LIMIT 1"; // I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/AVideo/about @@ -5976,7 +6248,8 @@ function getMySQLDate() { return $row; } -function _file_put_contents($filename, $data, $flags = 0, $context = null) { +function _file_put_contents($filename, $data, $flags = 0, $context = null) +{ make_path($filename); if (!is_string($data)) { $data = _json_encode($data); @@ -5984,7 +6257,8 @@ function _file_put_contents($filename, $data, $flags = 0, $context = null) { return file_put_contents($filename, $data, $flags, $context); } -function html2plainText($html) { +function html2plainText($html) +{ if (!is_string($html)) { return ''; } @@ -5993,19 +6267,20 @@ function html2plainText($html) { return $text; } -function getInputPassword($id, $attributes = 'class="form-control"', $paceholder = '') { +function getInputPassword($id, $attributes = 'class="form-control"', $paceholder = '') +{ if (empty($paceholder)) { $paceholder = __("Password"); } - ?> +?>
> - +
- +?>
> - +
- +?> - " . PHP_EOL; @@ -6164,7 +6443,8 @@ function examineJSONError($object) { return false; } -function _json_encode_utf8($object) { +function _json_encode_utf8($object) +{ $object = object_to_array($object); if (!is_array($object)) { return false; @@ -6179,7 +6459,8 @@ function _json_encode_utf8($object) { return $json; } -function _json_encode($object) { +function _json_encode($object) +{ global $_json_encode_force_utf8; if (empty($object)) { return false; @@ -6234,7 +6515,8 @@ function _json_encode($object) { return $json; } -function _json_decode($object) { +function _json_decode($object) +{ global $global; if (empty($object)) { return false; @@ -6258,7 +6540,8 @@ function _json_decode($object) { } // this will make sure the strring will fits in the database field -function _substr($string, $start, $length = null) { +function _substr($string, $start, $length = null) +{ // make sure the name is not chunked in case of multibyte string if (function_exists("mb_strcut")) { return mb_strcut($string, $start, $length, "UTF-8"); @@ -6267,7 +6550,8 @@ function _substr($string, $start, $length = null) { } } -function _strlen($string) { +function _strlen($string) +{ // make sure the name is not chunked in case of multibyte string if (function_exists("mb_strlen")) { return mb_strlen($string, "UTF-8"); @@ -6276,7 +6560,8 @@ function _strlen($string) { } } -function getSEODescription($text, $maxChars = 320) { +function getSEODescription($text, $maxChars = 320) +{ $removeChars = ['|', '"']; $replaceChars = ['-', '']; $newText = trim(str_replace($removeChars, $replaceChars, html2plainText($text))); @@ -6287,7 +6572,8 @@ function getSEODescription($text, $maxChars = 320) { } } -function getSEOTitle($text, $maxChars = 60) { +function getSEOTitle($text, $maxChars = 60) +{ $removeChars = ['|', '"']; $replaceChars = ['-', '']; $newText = trim(str_replace($removeChars, $replaceChars, safeString($text))); @@ -6298,7 +6584,8 @@ function getSEOTitle($text, $maxChars = 60) { } } -function getPagination($total, $page = 0, $link = "", $maxVisible = 10, $infinityScrollGetFromSelector = "", $infinityScrollAppendIntoSelector = "") { +function getPagination($total, $page = 0, $link = "", $maxVisible = 10, $infinityScrollGetFromSelector = "", $infinityScrollAppendIntoSelector = "") +{ global $global, $advancedCustom; if ($total < 2) { return ''; @@ -6338,8 +6625,8 @@ function getPagination($total, $page = 0, $link = "", $maxVisible = 10, $infinit } return ""; + . ""; } $pag = '