mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Update
This commit is contained in:
parent
3c385d4dd7
commit
b813f528ba
19 changed files with 3024 additions and 2990 deletions
|
@ -96,6 +96,11 @@ class Category
|
||||||
$this->parentId = $parentId;
|
$this->parentId = $parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParentId()
|
||||||
|
{
|
||||||
|
return $this->parentId;
|
||||||
|
}
|
||||||
|
|
||||||
public function setDescription($description)
|
public function setDescription($description)
|
||||||
{
|
{
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
214
objects/functionsAVideo.php
Normal file
214
objects/functionsAVideo.php
Normal file
|
@ -0,0 +1,214 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$AVideoMobileAPPLivestreamer_UA = "AVideoMobileAppLiveStreamer";
|
||||||
|
$AVideoMobileAPP_UA = "AVideoMobileApp";
|
||||||
|
$AVideoEncoder_UA = "AVideoEncoder";
|
||||||
|
$AVideoEncoderNetwork_UA = "AVideoEncoderNetwork";
|
||||||
|
$AVideoStreamer_UA = "AVideoStreamer";
|
||||||
|
$AVideoStorage_UA = "AVideoStorage";
|
||||||
|
|
||||||
|
function isAVideoMobileApp($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $AVideoMobileAPP_UA;
|
||||||
|
if (preg_match("/{$AVideoMobileAPP_UA}(.*)/", $_SERVER["HTTP_USER_AGENT"], $match)) {
|
||||||
|
$url = trim($match[1]);
|
||||||
|
if (!empty($url)) {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAVideoEncoder($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $AVideoEncoder_UA;
|
||||||
|
if (preg_match("/{$AVideoEncoder_UA}(.*)/", $user_agent, $match)) {
|
||||||
|
$url = trim($match[1]);
|
||||||
|
if (!empty($url)) {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCDN()
|
||||||
|
{
|
||||||
|
if (empty($_SERVER['HTTP_CDN_HOST'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isFromCDN($_SERVER['HTTP_CDN_HOST']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isFromCDN($url)
|
||||||
|
{
|
||||||
|
if (preg_match('/cdn.ypt.me/i', $url)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAVideo($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $AVideoEncoder_UA;
|
||||||
|
if (preg_match("/AVideo(.*)/", $_SERVER["HTTP_USER_AGENT"], $match)) {
|
||||||
|
$url = trim($match[1]);
|
||||||
|
if (!empty($url)) {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAVideoEncoderOnSameDomain()
|
||||||
|
{
|
||||||
|
$url = isAVideoEncoder();
|
||||||
|
if (empty($url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$url = "http://{$url}";
|
||||||
|
return isSameDomainAsMyAVideo($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSameDomainAsMyAVideo($url)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
if (empty($url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isSameDomain($url, $global['webSiteRootURL']) || isSameDomain($url, getCDN());
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAVideoStreamer($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $AVideoStreamer_UA, $global;
|
||||||
|
$md5 = md5($global['salt']);
|
||||||
|
if (preg_match("/{$AVideoStreamer_UA}_{$md5}/", $_SERVER["HTTP_USER_AGENT"])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAVideoUserAgent($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $AVideoMobileAPP_UA, $AVideoEncoder_UA, $AVideoEncoderNetwork_UA, $AVideoStreamer_UA, $AVideoStorage_UA, $global;
|
||||||
|
|
||||||
|
// Lavf = ffmpeg
|
||||||
|
//$agents = [$AVideoMobileAPP_UA, $AVideoEncoder_UA, $AVideoEncoderNetwork_UA, $AVideoStreamer_UA, $AVideoStorage_UA, 'Lavf'];
|
||||||
|
$agents = [$AVideoMobileAPP_UA, $AVideoEncoder_UA, $AVideoEncoderNetwork_UA, $AVideoStreamer_UA, $AVideoStorage_UA];
|
||||||
|
|
||||||
|
foreach ($agents as $value) {
|
||||||
|
if (preg_match("/{$value}/", $user_agent)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAVideoStorage($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $AVideoStorage_UA;
|
||||||
|
if (preg_match("/{$AVideoStorage_UA}(.*)/", $_SERVER["HTTP_USER_AGENT"], $match)) {
|
||||||
|
$url = trim($match[1]);
|
||||||
|
if (!empty($url)) {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getSelfUserAgent()
|
||||||
|
{
|
||||||
|
global $global, $AVideoStreamer_UA;
|
||||||
|
$agent = $AVideoStreamer_UA . "_";
|
||||||
|
$agent .= md5($global['salt']);
|
||||||
|
return $agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestComesFromSameDomainAsMyAVideo()
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
$url = getRefferOrOrigin();
|
||||||
|
//var_dump($_SERVER);exit;
|
||||||
|
//_error_log("requestComesFromSameDomainAsMyAVideo: ({$url}) == ({$global['webSiteRootURL']})");
|
||||||
|
return isSameDomain($url, $global['webSiteRootURL']) || isSameDomain($url, getCDN()) || isFromCDN($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
define('E_FATAL', E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR |
|
||||||
|
E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
|
||||||
|
if (!isCommandLineInterface() && !isAVideoEncoder()) {
|
||||||
|
register_shutdown_function('avideoShutdown');
|
||||||
|
}
|
||||||
|
|
||||||
|
function avideoShutdown()
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
$error = error_get_last();
|
||||||
|
if ($error && ($error['type'] & E_FATAL)) {
|
||||||
|
var_dump($error);
|
||||||
|
_error_log($error, AVideoLog::$ERROR);
|
||||||
|
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
|
||||||
|
if (!User::isAdmin()) {
|
||||||
|
if (!preg_match('/json\.php$/i', $_SERVER['PHP_SELF'])) {
|
||||||
|
echo '<!-- This page means an error 500 Internal Server Error, check your log file -->' . PHP_EOL;
|
||||||
|
include $global['systemRootPath'] . 'view/maintanance.html';
|
||||||
|
} else {
|
||||||
|
$o = new stdClass();
|
||||||
|
$o->error = true;
|
||||||
|
$o->msg = ('Under Maintanance');
|
||||||
|
echo json_encode($o);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '<pre>';
|
||||||
|
var_dump($error);
|
||||||
|
var_dump(debug_backtrace());
|
||||||
|
echo '</pre>';
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}else{
|
||||||
|
if(class_exists('Cache')){
|
||||||
|
Cache::saveCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
308
objects/functionsBrowser.php
Normal file
308
objects/functionsBrowser.php
Normal file
|
@ -0,0 +1,308 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function isSafari()
|
||||||
|
{
|
||||||
|
global $global, $_isSafari;
|
||||||
|
if (!isset($_isSafari)) {
|
||||||
|
$_isSafari = false;
|
||||||
|
$os = getOS();
|
||||||
|
if (preg_match('/Mac|iPhone|iPod|iPad/i', $os)) {
|
||||||
|
require_once $global['systemRootPath'] . 'objects/Mobile_Detect.php';
|
||||||
|
$detect = new Mobile_Detect();
|
||||||
|
$_isSafari = $detect->is('Safari');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $_isSafari;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fixQuotesIfSafari($str)
|
||||||
|
{
|
||||||
|
if (!isSafari()) {
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
return fixQuotes($str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getLanguageFromBrowser()
|
||||||
|
{
|
||||||
|
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$parts = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
return str_replace('-', '_', $parts[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deviceIdToObject($deviceID)
|
||||||
|
{
|
||||||
|
$parts = explode('-', $deviceID);
|
||||||
|
$obj = new stdClass();
|
||||||
|
$obj->browser = '';
|
||||||
|
$obj->os = '';
|
||||||
|
$obj->ip = '';
|
||||||
|
$obj->user_agent = '';
|
||||||
|
$obj->users_id = 0;
|
||||||
|
|
||||||
|
foreach ($parts as $key => $value) {
|
||||||
|
$parts[$key] = str_replace('_', ' ', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($parts[0]) {
|
||||||
|
case 'ypt':
|
||||||
|
$obj->browser = $parts[1];
|
||||||
|
$obj->os = $parts[2];
|
||||||
|
$obj->ip = $parts[3];
|
||||||
|
$obj->user_agent = $parts[4];
|
||||||
|
$obj->users_id = $parts[5];
|
||||||
|
break;
|
||||||
|
case 'unknowDevice':
|
||||||
|
$obj->browser = $parts[0];
|
||||||
|
$obj->os = 'unknow OS';
|
||||||
|
$obj->ip = $parts[1];
|
||||||
|
$obj->user_agent = 'unknow UA';
|
||||||
|
$obj->users_id = $parts[2];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It's separated by time, version, clock_seq_hi, clock_seq_lo, node, as indicated in the followoing rfc.
|
||||||
|
*
|
||||||
|
* From the IETF RFC4122:
|
||||||
|
* 8-4-4-4-12
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getDeviceID($useRandomString = true)
|
||||||
|
{
|
||||||
|
$ip = md5(getRealIpAddr());
|
||||||
|
$pattern = "/[^0-9a-z_.-]/i";
|
||||||
|
if (empty($_SERVER['HTTP_USER_AGENT'])) {
|
||||||
|
$device = "unknowDevice-{$ip}";
|
||||||
|
$device .= '-' . intval(User::getId());
|
||||||
|
return preg_replace($pattern, '-', $device);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($useRandomString)) {
|
||||||
|
$device = 'ypt-' . get_browser_name() . '-' . getOS() . '-' . $ip . '-' . md5($_SERVER['HTTP_USER_AGENT']);
|
||||||
|
$device = str_replace(
|
||||||
|
['[', ']', ' '],
|
||||||
|
['', '', '_'],
|
||||||
|
$device
|
||||||
|
);
|
||||||
|
$device .= '-' . intval(User::getId());
|
||||||
|
return preg_replace($pattern, '-', $device);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cookieName = "yptDeviceID";
|
||||||
|
if (empty($_COOKIE[$cookieName])) {
|
||||||
|
if (empty($_GET[$cookieName])) {
|
||||||
|
$id = uniqidV4();
|
||||||
|
$_GET[$cookieName] = $id;
|
||||||
|
}
|
||||||
|
if (empty($_SESSION[$cookieName])) {
|
||||||
|
_session_start();
|
||||||
|
$_SESSION[$cookieName] = $_GET[$cookieName];
|
||||||
|
} else {
|
||||||
|
$_GET[$cookieName] = $_SESSION[$cookieName];
|
||||||
|
}
|
||||||
|
if (!_setcookie($cookieName, $_GET[$cookieName], strtotime("+ 1 year"))) {
|
||||||
|
return "getDeviceIDError";
|
||||||
|
}
|
||||||
|
$_COOKIE[$cookieName] = $_GET[$cookieName];
|
||||||
|
}
|
||||||
|
return preg_replace($pattern, '-', $_COOKIE[$cookieName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fakeBrowser($url)
|
||||||
|
{
|
||||||
|
// create curl resource
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
// set url
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
|
||||||
|
//return the transfer as a string
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
|
||||||
|
|
||||||
|
// $output contains the output string
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
|
||||||
|
// close curl resource to free up system resources
|
||||||
|
curl_close($ch);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_browser_name($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
return 'Unknow';
|
||||||
|
}
|
||||||
|
// Make case insensitive.
|
||||||
|
$t = mb_strtolower($user_agent);
|
||||||
|
|
||||||
|
// If the string *starts* with the string, strpos returns 0 (i.e., FALSE). Do a ghetto hack and start with a space.
|
||||||
|
// "[strpos()] may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE."
|
||||||
|
// http://php.net/manual/en/function.strpos.php
|
||||||
|
$t = " " . $t;
|
||||||
|
|
||||||
|
// Humans / Regular Users
|
||||||
|
if (isAVideoStreamer($t)) {
|
||||||
|
return 'AVideo Mobile App';
|
||||||
|
} elseif ($url = isAVideoEncoder($t)) {
|
||||||
|
return 'AVideo Encoder ' . $url;
|
||||||
|
} elseif ($url = isAVideoStreamer($t)) {
|
||||||
|
return 'AVideo Streamer ' . $url;
|
||||||
|
} elseif (strpos($t, 'crkey')) {
|
||||||
|
return 'Chromecast';
|
||||||
|
} elseif (strpos($t, 'opera') || strpos($t, 'opr/')) {
|
||||||
|
return 'Opera';
|
||||||
|
} elseif (strpos($t, 'edge')) {
|
||||||
|
return 'Edge';
|
||||||
|
} elseif (strpos($t, 'chrome')) {
|
||||||
|
return 'Chrome';
|
||||||
|
} elseif (strpos($t, 'safari')) {
|
||||||
|
return 'Safari';
|
||||||
|
} elseif (strpos($t, 'firefox')) {
|
||||||
|
return 'Firefox';
|
||||||
|
} elseif (strpos($t, 'msie') || strpos($t, 'trident/7')) {
|
||||||
|
return 'Internet Explorer';
|
||||||
|
} elseif (strpos($t, 'applecoremedia')) {
|
||||||
|
return 'Native Apple Player';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search Engines
|
||||||
|
elseif (strpos($t, 'google')) {
|
||||||
|
return '[Bot] Googlebot';
|
||||||
|
} elseif (strpos($t, 'bing')) {
|
||||||
|
return '[Bot] Bingbot';
|
||||||
|
} elseif (strpos($t, 'slurp')) {
|
||||||
|
return '[Bot] Yahoo! Slurp';
|
||||||
|
} elseif (strpos($t, 'duckduckgo')) {
|
||||||
|
return '[Bot] DuckDuckBot';
|
||||||
|
} elseif (strpos($t, 'baidu')) {
|
||||||
|
return '[Bot] Baidu';
|
||||||
|
} elseif (strpos($t, 'yandex')) {
|
||||||
|
return '[Bot] Yandex';
|
||||||
|
} elseif (strpos($t, 'sogou')) {
|
||||||
|
return '[Bot] Sogou';
|
||||||
|
} elseif (strpos($t, 'exabot')) {
|
||||||
|
return '[Bot] Exabot';
|
||||||
|
} elseif (strpos($t, 'msn')) {
|
||||||
|
return '[Bot] MSN';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Common Tools and Bots
|
||||||
|
elseif (strpos($t, 'mj12bot')) {
|
||||||
|
return '[Bot] Majestic';
|
||||||
|
} elseif (strpos($t, 'ahrefs')) {
|
||||||
|
return '[Bot] Ahrefs';
|
||||||
|
} elseif (strpos($t, 'semrush')) {
|
||||||
|
return '[Bot] SEMRush';
|
||||||
|
} elseif (strpos($t, 'rogerbot') || strpos($t, 'dotbot')) {
|
||||||
|
return '[Bot] Moz or OpenSiteExplorer';
|
||||||
|
} elseif (strpos($t, 'frog') || strpos($t, 'screaming')) {
|
||||||
|
return '[Bot] Screaming Frog';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Miscellaneous
|
||||||
|
elseif (strpos($t, 'facebook')) {
|
||||||
|
return '[Bot] Facebook';
|
||||||
|
} elseif (strpos($t, 'pinterest')) {
|
||||||
|
return '[Bot] Pinterest';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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')
|
||||||
|
) {
|
||||||
|
return '[Bot] Other';
|
||||||
|
}
|
||||||
|
//_error_log("Unknow user agent ($t) IP=" . getRealIpAddr() . " URI=" . getRequestURI());
|
||||||
|
return 'Other (Unknown)';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Due some error on old chrome browsers (version < 70) on decrypt HLS keys with the videojs versions greater then 7.9.7
|
||||||
|
* we need to detect the chrome browser and load an older version
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function isOldChromeVersion()
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
if (empty($_SERVER['HTTP_USER_AGENT'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($global['forceOldChrome'])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (preg_match('/Chrome\/([0-9.]+)/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
|
||||||
|
return version_compare($matches[1], '80', '<=');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOS($user_agent = "")
|
||||||
|
{
|
||||||
|
if (empty($user_agent)) {
|
||||||
|
$user_agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$os_platform = "Unknown OS Platform";
|
||||||
|
|
||||||
|
if (!empty($user_agent)) {
|
||||||
|
$os_array = [
|
||||||
|
'/windows nt 10/i' => 'Windows 10',
|
||||||
|
'/windows nt 6.3/i' => 'Windows 8.1',
|
||||||
|
'/windows nt 6.2/i' => 'Windows 8',
|
||||||
|
'/windows nt 6.1/i' => 'Windows 7',
|
||||||
|
'/windows nt 6.0/i' => 'Windows Vista',
|
||||||
|
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
|
||||||
|
'/windows nt 5.1/i' => 'Windows XP',
|
||||||
|
'/windows xp/i' => 'Windows XP',
|
||||||
|
'/windows nt 5.0/i' => 'Windows 2000',
|
||||||
|
'/windows me/i' => 'Windows ME',
|
||||||
|
'/win98/i' => 'Windows 98',
|
||||||
|
'/win95/i' => 'Windows 95',
|
||||||
|
'/win16/i' => 'Windows 3.11',
|
||||||
|
'/macintosh|mac os x/i' => 'Mac OS X',
|
||||||
|
'/mac_powerpc/i' => 'Mac OS 9',
|
||||||
|
'/linux/i' => 'Linux',
|
||||||
|
'/ubuntu/i' => 'Ubuntu',
|
||||||
|
'/iphone/i' => 'iPhone',
|
||||||
|
'/ipod/i' => 'iPod',
|
||||||
|
'/ipad/i' => 'iPad',
|
||||||
|
'/android/i' => 'Android',
|
||||||
|
'/blackberry/i' => 'BlackBerry',
|
||||||
|
'/webos/i' => 'Mobile',
|
||||||
|
// Additional TV devices and mobile devices
|
||||||
|
'/roku/i' => 'Roku',
|
||||||
|
'/android tv/i' => 'Android TV',
|
||||||
|
'/apple tv/i' => 'Apple TV',
|
||||||
|
'/fire tv|firestick|fire stick/i' => 'Amazon Fire TV',
|
||||||
|
'/windows phone/i' => 'Windows Phone',
|
||||||
|
'/symbian/i' => 'Symbian',
|
||||||
|
'/tizen/i' => 'Tizen',
|
||||||
|
'/webos tv/i' => 'WebOS TV'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($os_array as $regex => $value) {
|
||||||
|
if (preg_match($regex, $user_agent)) {
|
||||||
|
$os_platform = $value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $os_platform;
|
||||||
|
}
|
|
@ -71,7 +71,6 @@ function cutVideoWithFFmpeg($inputFile, $startTimeInSeconds, $endTimeInSeconds,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getDurationFromFile($file)
|
function getDurationFromFile($file)
|
||||||
{
|
{
|
||||||
global $config, $getDurationFromFile;
|
global $config, $getDurationFromFile;
|
||||||
|
@ -430,3 +429,60 @@ function killProcess($pid)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function canExecutePgrep() {
|
||||||
|
// Check if we can successfully pgrep the init or systemd process
|
||||||
|
$test = shell_exec('pgrep -f init || pgrep -f systemd');
|
||||||
|
return !empty($test); // Return true if we can execute pgrep, false otherwise
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProcessPids($processName) {
|
||||||
|
if (!canExecutePgrep()) {
|
||||||
|
return null; // If we can't execute pgrep, return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using pgrep with -a to get both PID and the full command line
|
||||||
|
$output = shell_exec('pgrep -af ' . escapeshellarg($processName));
|
||||||
|
|
||||||
|
if (empty($output)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the string into an array based on newline and filter out any empty values
|
||||||
|
$lines = array_filter(explode("\n", $output));
|
||||||
|
|
||||||
|
$pids = [];
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
// Skip the line containing sh -c pgrep
|
||||||
|
if (strpos($line, 'pgrep') !== false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//_error_log("getProcessPids($processName) $line");
|
||||||
|
// Extract PID from the start of the line
|
||||||
|
list($pid, ) = explode(' ', trim($line), 2);
|
||||||
|
$pids[] = $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCommandByPid($pid) {
|
||||||
|
$cmdlineFile = "/proc/{$pid}/cmdline";
|
||||||
|
|
||||||
|
// Check if the cmdline file exists for the given PID
|
||||||
|
if (!file_exists($cmdlineFile)) {
|
||||||
|
return false; // or return an error message or throw an exception
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the content and break it into an array using null characters as the delimiter
|
||||||
|
$cmd = file_get_contents($cmdlineFile);
|
||||||
|
$cmdArray = explode("\0", $cmd);
|
||||||
|
|
||||||
|
// Remove any empty elements from the array
|
||||||
|
$cmdArray = array_filter($cmdArray, function($value) {
|
||||||
|
return $value !== '';
|
||||||
|
});
|
||||||
|
|
||||||
|
return $cmdArray;
|
||||||
|
}
|
235
objects/functionsFFMPEG.php
Normal file
235
objects/functionsFFMPEG.php
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function get_ffmpeg($ignoreGPU = false)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
$complement = ' -user_agent "' . getSelfUserAgent() . '" ';
|
||||||
|
//return 'ffmpeg -headers "User-Agent: '.getSelfUserAgent("FFMPEG").'" ';
|
||||||
|
$ffmpeg = 'ffmpeg ';
|
||||||
|
if (empty($ignoreGPU) && !empty($global['ffmpegGPU'])) {
|
||||||
|
$ffmpeg .= ' --enable-nvenc ';
|
||||||
|
}
|
||||||
|
if (!empty($global['ffmpeg'])) {
|
||||||
|
_error_log('get_ffmpeg $global[ffmpeg] detected ' . $global['ffmpeg']);
|
||||||
|
$ffmpeg = "{$global['ffmpeg']}{$ffmpeg}";
|
||||||
|
} else {
|
||||||
|
_error_log('get_ffmpeg default ' . $ffmpeg . $complement);
|
||||||
|
}
|
||||||
|
return $ffmpeg . $complement;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_ffprobe() {
|
||||||
|
global $global;
|
||||||
|
$complement = ' -user_agent "' . getSelfUserAgent() . '" ';
|
||||||
|
//return 'ffmpeg -user_agent "'.getSelfUserAgent("FFMPEG").'" ';
|
||||||
|
//return 'ffmpeg -headers "User-Agent: '.getSelfUserAgent("FFMPEG").'" ';
|
||||||
|
$ffprobe = 'ffprobe ';
|
||||||
|
if (!empty($global['ffprobe'])) {
|
||||||
|
|
||||||
|
$dir = dirname($global['ffprobe']);
|
||||||
|
|
||||||
|
$ffprobe = "{$dir}/{$ffprobe}";
|
||||||
|
}
|
||||||
|
return $ffprobe.$complement;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertVideoToMP3FileIfNotExists($videos_id)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
if (!empty($global['disableMP3'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$video = Video::getVideoLight($videos_id);
|
||||||
|
if (empty($video)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$types = ['video', 'audio'];
|
||||||
|
if (!in_array($video['type'], $types)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$paths = Video::getPaths($video['filename']);
|
||||||
|
$mp3File = "{$paths['path']}{$video['filename']}.mp3";
|
||||||
|
if (file_exists($mp3File) && filesize($mp3File)<100) {
|
||||||
|
unlink($mp3File);
|
||||||
|
}
|
||||||
|
if (!file_exists($mp3File)) {
|
||||||
|
$sources = getVideosURLOnly($video['filename'], false);
|
||||||
|
|
||||||
|
if (!empty($sources)) {
|
||||||
|
$source = end($sources);
|
||||||
|
convertVideoFileWithFFMPEG($source['url'], $mp3File);
|
||||||
|
if (file_exists($mp3File)) {
|
||||||
|
return Video::getSourceFile($video['filename'], ".mp3", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Video::getSourceFile($video['filename'], ".mp3", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function m3u8ToMP4($input)
|
||||||
|
{
|
||||||
|
$videosDir = getVideosDir();
|
||||||
|
$outputfilename = str_replace($videosDir, "", $input);
|
||||||
|
$parts = explode("/", $outputfilename);
|
||||||
|
$resolution = Video::getResolutionFromFilename($input);
|
||||||
|
$outputfilename = $parts[0] . "_{$resolution}_.mp4";
|
||||||
|
$outputpath = "{$videosDir}cache/downloads/{$outputfilename}";
|
||||||
|
$msg = '';
|
||||||
|
$error = true;
|
||||||
|
if (empty($outputfilename)) {
|
||||||
|
$msg = "downloadHLS: empty outputfilename {$outputfilename}";
|
||||||
|
_error_log($msg);
|
||||||
|
return ['error' => $error, 'msg' => $msg];
|
||||||
|
}
|
||||||
|
_error_log("downloadHLS: m3u8ToMP4($input)");
|
||||||
|
//var_dump(!preg_match('/^http/i', $input), filesize($input), preg_match('/.m3u8$/i', $input));
|
||||||
|
$ism3u8 = preg_match('/.m3u8$/i', $input);
|
||||||
|
if (!preg_match('/^http/i', $input) && (filesize($input) <= 10 || $ism3u8)) { // dummy file
|
||||||
|
$filepath = pathToRemoteURL($input, true, true);
|
||||||
|
if ($ism3u8 && !preg_match('/.m3u8$/i', $filepath)) {
|
||||||
|
$filepath = addLastSlash($filepath) . 'index.m3u8';
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = getToken(60);
|
||||||
|
$filepath = addQueryStringParameter($filepath, 'globalToken', $token);
|
||||||
|
} else {
|
||||||
|
$filepath = escapeshellcmd($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($filepath)) {
|
||||||
|
$filepath = addLastSlash($filepath) . 'index.m3u8';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($outputpath)) {
|
||||||
|
//var_dump('m3u8ToMP4 !file_exists', $filepath, $outputpath);
|
||||||
|
//exit;
|
||||||
|
$return = convertVideoFileWithFFMPEG($filepath, $outputpath);
|
||||||
|
//var_dump($return);
|
||||||
|
//exit;
|
||||||
|
if (empty($return)) {
|
||||||
|
$msg3 = "downloadHLS: ERROR 2 ";
|
||||||
|
$finalMsg = $msg . PHP_EOL . $msg3;
|
||||||
|
_error_log($msg3);
|
||||||
|
return ['error' => $error, 'msg' => $finalMsg];
|
||||||
|
} else {
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$msg = "downloadHLS: outputpath already exists ({$outputpath})";
|
||||||
|
_error_log($msg);
|
||||||
|
}
|
||||||
|
$error = false;
|
||||||
|
return ['error' => $error, 'msg' => $msg, 'path' => $outputpath, 'filename' => $outputfilename];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConvertVideoFileWithFFMPEGProgressFilename($toFileLocation)
|
||||||
|
{
|
||||||
|
$progressFile = $toFileLocation . '.log';
|
||||||
|
return $progressFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertVideoToDownlaodProgress($toFileLocation)
|
||||||
|
{
|
||||||
|
$progressFile = getConvertVideoFileWithFFMPEGProgressFilename($toFileLocation);
|
||||||
|
return parseFFMPEGProgress($progressFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseFFMPEGProgress($progressFilename)
|
||||||
|
{
|
||||||
|
//get duration of source
|
||||||
|
$obj = new stdClass();
|
||||||
|
|
||||||
|
$obj->duration = 0;
|
||||||
|
$obj->currentTime = 0;
|
||||||
|
$obj->progress = 0;
|
||||||
|
$obj->from = '';
|
||||||
|
$obj->to = '';
|
||||||
|
if (!file_exists($progressFilename)) {
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
$obj->filemtime = filemtime($progressFilename);
|
||||||
|
$obj->secondsOld = time() - $obj->filemtime;
|
||||||
|
|
||||||
|
$content = url_get_contents($progressFilename);
|
||||||
|
if (empty($content)) {
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
//var_dump($content);exit;
|
||||||
|
preg_match("/Duration: (.*?), start:/", $content, $matches);
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
$rawDuration = $matches[1];
|
||||||
|
|
||||||
|
//rawDuration is in 00:00:00.00 format. This converts it to seconds.
|
||||||
|
$ar = array_reverse(explode(":", $rawDuration));
|
||||||
|
$duration = floatval($ar[0]);
|
||||||
|
if (!empty($ar[1])) {
|
||||||
|
$duration += intval($ar[1]) * 60;
|
||||||
|
}
|
||||||
|
if (!empty($ar[2])) {
|
||||||
|
$duration += intval($ar[2]) * 60 * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
//get the time in the file that is already encoded
|
||||||
|
preg_match_all("/time=(.*?) bitrate/", $content, $matches);
|
||||||
|
|
||||||
|
$rawTime = array_pop($matches);
|
||||||
|
|
||||||
|
//this is needed if there is more than one match
|
||||||
|
if (is_array($rawTime)) {
|
||||||
|
$rawTime = array_pop($rawTime);
|
||||||
|
}
|
||||||
|
if (empty($rawTime)) {
|
||||||
|
$rawTime = '00:00:00.00';
|
||||||
|
}
|
||||||
|
//rawTime is in 00:00:00.00 format. This converts it to seconds.
|
||||||
|
$ar = array_reverse(explode(":", $rawTime));
|
||||||
|
$time = floatval($ar[0]);
|
||||||
|
if (!empty($ar[1])) {
|
||||||
|
$time += intval($ar[1]) * 60;
|
||||||
|
}
|
||||||
|
if (!empty($ar[2])) {
|
||||||
|
$time += intval($ar[2]) * 60 * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($duration)) {
|
||||||
|
//calculate the progress
|
||||||
|
$progress = round(($time / $duration) * 100);
|
||||||
|
} else {
|
||||||
|
$progress = 'undefined';
|
||||||
|
}
|
||||||
|
$obj->duration = $duration;
|
||||||
|
$obj->currentTime = $time;
|
||||||
|
$obj->remainTime = ($obj->duration - $time);
|
||||||
|
$obj->remainTimeHuman = secondsToVideoTime($obj->remainTime);
|
||||||
|
$obj->progress = $progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match("/Input[a-z0-9 #,]+from '([^']+)':/", $content, $matches);
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
$path_parts = pathinfo($matches[1]);
|
||||||
|
$partsExtension = explode('?', $path_parts['extension']);
|
||||||
|
$obj->from = $partsExtension[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match("/Output[a-z0-9 #,]+to '([^']+)':/", $content, $matches);
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
$path_parts = pathinfo($matches[1]);
|
||||||
|
$partsExtension = explode('?', $path_parts['extension']);
|
||||||
|
$obj->to = $partsExtension[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function removeUserAgentIfNotURL($cmd){
|
||||||
|
if (!preg_match('/ -i [\'"]?https?:/i', $cmd) && !preg_match('/ffprobe.*[\'"]?https?:/i', $cmd)) {
|
||||||
|
$cmd = preg_replace('/-user_agent "[^"]+"/', '', $cmd);
|
||||||
|
}
|
||||||
|
return $cmd;
|
||||||
|
}
|
1042
objects/functionsFile.php
Normal file
1042
objects/functionsFile.php
Normal file
File diff suppressed because it is too large
Load diff
210
objects/functionsHuman.php
Normal file
210
objects/functionsHuman.php
Normal file
|
@ -0,0 +1,210 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function humanTiming($time, $precision = 0, $useDatabaseTime = true, $addAgo = false)
|
||||||
|
{
|
||||||
|
if (empty($time)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$time = secondsIntervalFromNow($time, $useDatabaseTime);
|
||||||
|
|
||||||
|
if ($addAgo) {
|
||||||
|
$addAgo = $time - time();
|
||||||
|
}
|
||||||
|
|
||||||
|
return secondsToHumanTiming($time, $precision, $addAgo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $time
|
||||||
|
* @param string $precision
|
||||||
|
* @param string $useDatabaseTime good if you are checking the created time
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function humanTimingAgo($time, $precision = 0, $useDatabaseTime = true)
|
||||||
|
{
|
||||||
|
$time = secondsIntervalFromNow($time, $useDatabaseTime);
|
||||||
|
if (empty($time)) {
|
||||||
|
return __("Now");
|
||||||
|
}
|
||||||
|
return sprintf(__('%s ago'), secondsToHumanTiming($time, $precision));
|
||||||
|
}
|
||||||
|
|
||||||
|
function humanTimingAfterwards($time, $precision = 0, $useDatabaseTime = true)
|
||||||
|
{
|
||||||
|
if (!is_numeric($time)) {
|
||||||
|
$time = strtotime($time);
|
||||||
|
}
|
||||||
|
$time = secondsIntervalFromNow($time, $useDatabaseTime);
|
||||||
|
if (empty($time)) {
|
||||||
|
return __("Now");
|
||||||
|
} elseif ($time > 0) {
|
||||||
|
return sprintf(__('%s Ago'), secondsToHumanTiming($time, $precision));
|
||||||
|
}
|
||||||
|
return __('Coming in') . ' ' . secondsToHumanTiming($time, $precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
function secondsToHumanTiming($time, $precision = 0, $addAgo = false)
|
||||||
|
{
|
||||||
|
if (empty($time)) {
|
||||||
|
return __("Now");
|
||||||
|
}
|
||||||
|
$time = ($time < 0) ? $time * -1 : $time;
|
||||||
|
$time = ($time < 1) ? 1 : $time;
|
||||||
|
$tokens = [
|
||||||
|
31536000 => 'year',
|
||||||
|
2592000 => 'month',
|
||||||
|
604800 => 'week',
|
||||||
|
86400 => 'day',
|
||||||
|
3600 => 'hour',
|
||||||
|
60 => 'minute',
|
||||||
|
1 => 'second',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For detection purposes only
|
||||||
|
*/
|
||||||
|
__('year');
|
||||||
|
__('month');
|
||||||
|
__('week');
|
||||||
|
__('day');
|
||||||
|
__('hour');
|
||||||
|
__('minute');
|
||||||
|
__('second');
|
||||||
|
__('years');
|
||||||
|
__('months');
|
||||||
|
__('weeks');
|
||||||
|
__('days');
|
||||||
|
__('hours');
|
||||||
|
__('minutes');
|
||||||
|
__('seconds');
|
||||||
|
|
||||||
|
foreach ($tokens as $unit => $text) {
|
||||||
|
if ($time < $unit) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$numberOfUnits = floor($time / $unit);
|
||||||
|
if ($numberOfUnits > 1) {
|
||||||
|
$text = __($text . "s");
|
||||||
|
} else {
|
||||||
|
$text = __($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($precision) {
|
||||||
|
$rest = $time % $unit;
|
||||||
|
if ($rest) {
|
||||||
|
$text .= ' ' . secondsToHumanTiming($rest, $precision - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$return = $numberOfUnits . ' ' . $text;
|
||||||
|
|
||||||
|
if (!empty($addAgo) && $addAgo < 0) {
|
||||||
|
$return = sprintf(__('%s Ago'), $return);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function seconds2human($ss)
|
||||||
|
{
|
||||||
|
$s = $ss % 60;
|
||||||
|
$m = floor(($ss % 3600) / 60);
|
||||||
|
$h = floor(($ss % 86400) / 3600);
|
||||||
|
$d = floor(($ss % 2592000) / 86400);
|
||||||
|
$M = floor($ss / 2592000);
|
||||||
|
|
||||||
|
$times = [];
|
||||||
|
|
||||||
|
if (!empty($M)) {
|
||||||
|
$times[] = "$M " . __('m');
|
||||||
|
}
|
||||||
|
if (!empty($d)) {
|
||||||
|
$times[] = "$d " . __('d');
|
||||||
|
}
|
||||||
|
if (!empty($h)) {
|
||||||
|
$times[] = "$h " . __('h');
|
||||||
|
}
|
||||||
|
if (!empty($m)) {
|
||||||
|
$times[] = "$m " . __('min');
|
||||||
|
}
|
||||||
|
if (!empty($s)) {
|
||||||
|
$times[] = "$s " . __('sec');
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(', ', $times);
|
||||||
|
}
|
||||||
|
|
||||||
|
function secondsIntervalHuman($time, $useDatabaseTime = true)
|
||||||
|
{
|
||||||
|
$dif = secondsIntervalFromNow($time, $useDatabaseTime);
|
||||||
|
if ($dif < 0) {
|
||||||
|
return humanTimingAfterwards($time, 0, $useDatabaseTime);
|
||||||
|
} else {
|
||||||
|
return humanTimingAgo($time, 0, $useDatabaseTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function secondsToTime($seconds, $precision = '%06.3f') {
|
||||||
|
$hours = floor($seconds / 3600);
|
||||||
|
$mins = intval(floor($seconds / 60) % 60);
|
||||||
|
$secs = ($seconds % 60); // 1
|
||||||
|
$decimal = fmod($seconds, 1); //0.25
|
||||||
|
return sprintf("%02d:%02d:{$precision}", $hours, $mins, $secs + $decimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
function timeToSecondsInt($hms) {
|
||||||
|
$a = explode(":", $hms); // split it at the colons
|
||||||
|
// minutes are worth 60 seconds. Hours are worth 60 minutes.
|
||||||
|
|
||||||
|
for ($i = 0; $i < 3; $i++) {
|
||||||
|
$a[$i] = @intval($a[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$seconds = round((+$a[0]) * 60 * 60 + (+$a[1]) * 60 + (+$a[2]));
|
||||||
|
return ($seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
function secondsInterval($time1, $time2)
|
||||||
|
{
|
||||||
|
if (!isset($time1) || !isset($time2)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!is_numeric($time1)) {
|
||||||
|
$time1 = strtotime($time1);
|
||||||
|
}
|
||||||
|
if (!is_numeric($time2)) {
|
||||||
|
$time2 = strtotime($time2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $time1 - $time2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTimeForFuture($time, $useDatabaseTime = true)
|
||||||
|
{
|
||||||
|
$dif = secondsIntervalFromNow($time, $useDatabaseTime);
|
||||||
|
if ($dif < 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function secondsIntervalFromNow($time, $useDatabaseTimeOrTimezoneString = true)
|
||||||
|
{
|
||||||
|
$timeNow = time();
|
||||||
|
//var_dump($time, $useDatabaseTimeOrTimezoneString);
|
||||||
|
if (!empty($useDatabaseTimeOrTimezoneString)) {
|
||||||
|
if (is_numeric($useDatabaseTimeOrTimezoneString) || is_bool($useDatabaseTimeOrTimezoneString)) {
|
||||||
|
//echo $time . '-' . __LINE__ . '=>';
|
||||||
|
$timeNow = getDatabaseTime();
|
||||||
|
} elseif (is_string($useDatabaseTimeOrTimezoneString)) {
|
||||||
|
//echo '-' . __LINE__ . PHP_EOL . PHP_EOL;
|
||||||
|
$timeNow = getTimeInTimezone($timeNow, $useDatabaseTimeOrTimezoneString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return secondsInterval($timeNow, $time);
|
||||||
|
}
|
|
@ -1008,4 +1008,79 @@ function convertImage($originalImage, $outputImage, $quality, $useExif = false)
|
||||||
imagedestroy($imageTmp);
|
imagedestroy($imageTmp);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function base64DataToImage($imgBase64)
|
||||||
|
{
|
||||||
|
$img = $imgBase64;
|
||||||
|
$img = str_replace('data:image/png;base64,', '', $img);
|
||||||
|
$img = str_replace(' ', '+', $img);
|
||||||
|
return base64_decode($img);
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveBase64DataToPNGImage($imgBase64, $filePath)
|
||||||
|
{
|
||||||
|
$fileData = base64DataToImage($imgBase64);
|
||||||
|
if (empty($fileData)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return _file_put_contents($filePath, $fileData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function createWebPIfNotExists($path)
|
||||||
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '8.0.0') < 0 || !file_exists($path)) {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
$extension = pathinfo($path, PATHINFO_EXTENSION);
|
||||||
|
if ($extension !== 'jpg') {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
$nextGenPath = str_replace('.jpg', '_jpg.webp', $path);
|
||||||
|
|
||||||
|
if (!file_exists($nextGenPath)) {
|
||||||
|
convertImage($path, $nextGenPath, 90);
|
||||||
|
}
|
||||||
|
return $nextGenPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getCroppie(
|
||||||
|
$buttonTitle,
|
||||||
|
$callBackJSFunction,
|
||||||
|
$resultWidth = 0,
|
||||||
|
$resultHeight = 0,
|
||||||
|
$viewportWidth = 0,
|
||||||
|
$boundary = 25,
|
||||||
|
$viewportHeight = 0,
|
||||||
|
$enforceBoundary = true
|
||||||
|
) {
|
||||||
|
global $global;
|
||||||
|
require_once $global['systemRootPath'] . 'objects/functionCroppie.php';
|
||||||
|
return getCroppieElement(
|
||||||
|
$buttonTitle,
|
||||||
|
$callBackJSFunction,
|
||||||
|
$resultWidth ,
|
||||||
|
$resultHeight ,
|
||||||
|
$viewportWidth,
|
||||||
|
$boundary ,
|
||||||
|
$viewportHeight,
|
||||||
|
$enforceBoundary );
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveCroppieImage($destination, $postIndex = "imgBase64")
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
require_once $global['systemRootPath'] . 'objects/functionCroppie.php';
|
||||||
|
return saveCroppieImageElement($destination, $postIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isImageNotFound($imgURL){
|
||||||
|
if(empty($imgURL)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImagesPlaceHolders::isDefaultImage($imgURL);
|
||||||
|
}
|
|
@ -129,4 +129,12 @@ function _error_log($message, $type = 0, $doNotRepeat = false)
|
||||||
|
|
||||||
function isSchedulerRun(){
|
function isSchedulerRun(){
|
||||||
return preg_match('/Scheduler\/run\.php$/', $_SERVER['SCRIPT_NAME']);
|
return preg_match('/Scheduler\/run\.php$/', $_SERVER['SCRIPT_NAME']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _dieAndLogObject($obj, $prefix = "")
|
||||||
|
{
|
||||||
|
$objString = json_encode($obj);
|
||||||
|
_error_log($prefix . $objString);
|
||||||
|
die($objString);
|
||||||
}
|
}
|
340
objects/functionsMail.php
Normal file
340
objects/functionsMail.php
Normal file
|
@ -0,0 +1,340 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global array $global
|
||||||
|
* @param string $mail
|
||||||
|
* call it before send mail to let AVideo decide the method
|
||||||
|
*/
|
||||||
|
function setSiteSendMessage(\PHPMailer\PHPMailer\PHPMailer &$mail)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
if (empty($mail)) {
|
||||||
|
$mail = new \PHPMailer\PHPMailer\PHPMailer();
|
||||||
|
}
|
||||||
|
if (empty($_POST["comment"])) {
|
||||||
|
$_POST["comment"] = '';
|
||||||
|
}
|
||||||
|
require_once $global['systemRootPath'] . 'objects/configuration.php';
|
||||||
|
$config = new AVideoConf();
|
||||||
|
$mail->CharSet = 'UTF-8';
|
||||||
|
if ($config->getSmtp()) {
|
||||||
|
_error_log("Sending SMTP Email");
|
||||||
|
$mail->CharSet = 'UTF-8';
|
||||||
|
$mail->isSMTP(); // enable SMTP
|
||||||
|
if (!empty($_POST) && !empty($_REQUEST['isTest']) && User::isAdmin()) {
|
||||||
|
$mail->SMTPDebug = 3;
|
||||||
|
$mail->Debugoutput = function ($str, $level) {
|
||||||
|
_error_log("SMTP ERROR $level; message: $str", AVideoLog::$ERROR);
|
||||||
|
};
|
||||||
|
|
||||||
|
_error_log("Debug enable on the SMTP Email");
|
||||||
|
} else {
|
||||||
|
_error_log("Debug disabled on the SMTP Email");
|
||||||
|
}
|
||||||
|
$mail->SMTPOptions = [
|
||||||
|
'ssl' => [
|
||||||
|
'verify_peer' => false,
|
||||||
|
'verify_peer_name' => false,
|
||||||
|
'allow_self_signed' => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$mail->SMTPAuth = $config->getSmtpAuth(); // authentication enabled
|
||||||
|
$mail->SMTPSecure = $config->getSmtpSecure(); // secure transfer enabled REQUIRED for Gmail
|
||||||
|
$mail->Host = $config->getSmtpHost();
|
||||||
|
$mail->Port = $config->getSmtpPort();
|
||||||
|
$mail->Username = $config->getSmtpUsername();
|
||||||
|
$mail->Password = $config->getSmtpPassword();
|
||||||
|
//_error_log(print_r($config, true));
|
||||||
|
} else {
|
||||||
|
_error_log("Sending SendMail Email");
|
||||||
|
$mail->isSendmail();
|
||||||
|
}
|
||||||
|
// do not let the system hang on email send
|
||||||
|
_session_write_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function sendSiteEmail($to, $subject, $message, $fromEmail = '', $fromName = '')
|
||||||
|
{
|
||||||
|
global $advancedCustom, $config, $global;
|
||||||
|
$resp = false;
|
||||||
|
if (empty($to)) {
|
||||||
|
_error_log('sendSiteEmail: ERROR: to is empty');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_object($to)) {
|
||||||
|
$to = object_to_array($to);
|
||||||
|
}
|
||||||
|
if (!is_array($to)) {
|
||||||
|
$to = [$to];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($advancedCustom)) {
|
||||||
|
$advancedCustom = AVideoPlugin::loadPlugin("CustomizeAdvanced");
|
||||||
|
}
|
||||||
|
|
||||||
|
$subject = UTF8encode($subject);
|
||||||
|
$message = UTF8encode($message);
|
||||||
|
$message = createEmailMessageFromTemplate($message);
|
||||||
|
|
||||||
|
$total = count($to);
|
||||||
|
if ($total == 1) {
|
||||||
|
$debug = $to[0];
|
||||||
|
} else {
|
||||||
|
$debug = "count={$total}";
|
||||||
|
}
|
||||||
|
|
||||||
|
_error_log("sendSiteEmail [{$debug}] {$subject}");
|
||||||
|
//require_once $global['systemRootPath'] . 'objects/include_phpmailer.php';
|
||||||
|
if (empty($fromEmail)) {
|
||||||
|
$fromEmail = $config->getContactEmail();
|
||||||
|
}
|
||||||
|
if (empty($fromName)) {
|
||||||
|
$fromName = $config->getWebSiteTitle();
|
||||||
|
}
|
||||||
|
_error_log("sendSiteEmail: to=" . json_encode($to) . " from={$fromEmail} subject={$subject}");
|
||||||
|
$webSiteTitle = $config->getWebSiteTitle();
|
||||||
|
if (!is_array($to)) {
|
||||||
|
$to = array($to);
|
||||||
|
}
|
||||||
|
foreach ($to as $key => $value) {
|
||||||
|
if (!isValidEmail($value)) {
|
||||||
|
_error_log("sendSiteEmail invalid email {$value}");
|
||||||
|
unset($to[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$size = intval(@$advancedCustom->splitBulkEmailSend);
|
||||||
|
if (empty($size)) {
|
||||||
|
$size = 90;
|
||||||
|
}
|
||||||
|
$to = array_iunique($to);
|
||||||
|
$pieces = partition($to, $size);
|
||||||
|
$totalEmails = count($to);
|
||||||
|
$totalCount = 0;
|
||||||
|
_error_log("sendSiteEmail::sending totalEmails=[{$totalEmails}]");
|
||||||
|
foreach ($pieces as $piece) {
|
||||||
|
$mail = new \PHPMailer\PHPMailer\PHPMailer();
|
||||||
|
setSiteSendMessage($mail);
|
||||||
|
$mail->setFrom($fromEmail, $fromName);
|
||||||
|
$mail->Subject = $subject . " - " . $webSiteTitle;
|
||||||
|
$mail->msgHTML($message);
|
||||||
|
$count = 0;
|
||||||
|
foreach ($piece as $value) {
|
||||||
|
$totalCount++;
|
||||||
|
$count++;
|
||||||
|
//_error_log("sendSiteEmail::addBCC [{$count}] {$value}");
|
||||||
|
$mail->addBCC($value);
|
||||||
|
}
|
||||||
|
//_error_log("sendSiteEmail::sending now count=[{$count}] [{$totalCount}/{$totalEmails}]");
|
||||||
|
|
||||||
|
$resp = $mail->send();
|
||||||
|
if (!$resp) {
|
||||||
|
_error_log("sendSiteEmail Error Info: {$mail->ErrorInfo} count=[{$count}] [{$totalCount}/{$totalEmails}]");
|
||||||
|
} else {
|
||||||
|
_error_log("sendSiteEmail Success Info: count=[{$count}] [{$totalCount}/{$totalEmails}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Set the subject line
|
||||||
|
return $resp;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
_error_log($e->getMessage()); //Boring error messages from anything else!
|
||||||
|
}
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendSiteEmailAsync($to, $subject, $message)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
// If $to is not an array, make it one
|
||||||
|
if (!is_array($to)) {
|
||||||
|
$to = array($to);
|
||||||
|
}
|
||||||
|
// Make sure the emails in $to are unique
|
||||||
|
$to = array_unique($to);
|
||||||
|
$content = ['to' => $to, 'subject' => $subject, 'message' => $message];
|
||||||
|
//$tmpFile = getTmpFile();
|
||||||
|
$tmpFile = "{$global['systemRootPath']}videos/emails_" . uniqid() . '.log';
|
||||||
|
$bytes = file_put_contents($tmpFile, _json_encode($content));
|
||||||
|
//outputAndContinueInBackground();
|
||||||
|
$command = "php {$global['systemRootPath']}objects/sendSiteEmailAsync.php '$tmpFile' && rm '$tmpFile'";
|
||||||
|
$totalEmails = count($to);
|
||||||
|
_error_log("sendSiteEmailAsync start [bytes=$bytes] [totalEmails={$totalEmails}] ($command) file_exists=" . file_exists($tmpFile));
|
||||||
|
$pid = execAsync($command);
|
||||||
|
_error_log("sendSiteEmailAsync end {$pid}");
|
||||||
|
return $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendBulkEmail($users_id_array, $emails_array, $subject, $message)
|
||||||
|
{
|
||||||
|
|
||||||
|
$obj = AVideoPlugin::getDataObjectIfEnabled('Scheduler');
|
||||||
|
if (!empty($users_id_array) && $obj->sendEmails) {
|
||||||
|
_error_log("sendBulkEmail Scheduler");
|
||||||
|
$Emails_messages = Emails_messages::setOrCreate($message, $subject);
|
||||||
|
//var_dump($Emails_messages->getId());
|
||||||
|
$count = 0;
|
||||||
|
foreach ($users_id_array as $users_id) {
|
||||||
|
if (empty($users_id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$Email_to_user = new Email_to_user(0);
|
||||||
|
$Email_to_user->setEmails_messages_id($Emails_messages->getId());
|
||||||
|
$Email_to_user->setUsers_id($users_id);
|
||||||
|
if ($Email_to_user->save()) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_error_log("sendBulkEmail Scheduler done total={$count}");
|
||||||
|
} else {
|
||||||
|
_error_log("sendBulkEmail sendSiteEmailAsync");
|
||||||
|
if (empty($emails_array)) {
|
||||||
|
$to = array();
|
||||||
|
$sql = "SELECT email FROM users WHERE id IN (" . implode(', ', $users_id_array) . ") ";
|
||||||
|
$res = sqlDAL::readSql($sql);
|
||||||
|
$fullData = sqlDAL::fetchAllAssoc($res);
|
||||||
|
sqlDAL::close($res);
|
||||||
|
if ($res != false) {
|
||||||
|
foreach ($fullData as $row) {
|
||||||
|
if (empty($row['email'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$to[] = $row['email'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$to = $emails_array;
|
||||||
|
}
|
||||||
|
// Make sure the emails in $to are unique
|
||||||
|
$to = array_unique($to);
|
||||||
|
sendSiteEmailAsync($to, $subject, $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createEmailMessageFromTemplate($message)
|
||||||
|
{
|
||||||
|
//check if the message already have a HTML body
|
||||||
|
if (preg_match("/html>/i", $message)) {
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $global, $config;
|
||||||
|
$text = file_get_contents("{$global['systemRootPath']}view/include/emailTemplate.html");
|
||||||
|
$siteTitle = $config->getWebSiteTitle();
|
||||||
|
$logo = "<img src=\"" . getURL($config->getLogo()) . "\" alt=\"{$siteTitle}\"/>";
|
||||||
|
|
||||||
|
$words = [$logo, $message, $siteTitle];
|
||||||
|
$replace = ['{logo}', '{message}', '{siteTitle}'];
|
||||||
|
|
||||||
|
return str_replace($replace, $words, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendEmailToSiteOwner($subject, $message)
|
||||||
|
{
|
||||||
|
global $advancedCustom, $global;
|
||||||
|
$subject = UTF8encode($subject);
|
||||||
|
$message = UTF8encode($message);
|
||||||
|
_error_log("sendEmailToSiteOwner {$subject}");
|
||||||
|
global $config, $global;
|
||||||
|
//require_once $global['systemRootPath'] . 'objects/include_phpmailer.php';
|
||||||
|
$contactEmail = $config->getContactEmail();
|
||||||
|
$webSiteTitle = $config->getWebSiteTitle();
|
||||||
|
try {
|
||||||
|
$mail = new \PHPMailer\PHPMailer\PHPMailer();
|
||||||
|
setSiteSendMessage($mail);
|
||||||
|
$mail->setFrom($contactEmail, $webSiteTitle);
|
||||||
|
$mail->Subject = $subject . " - " . $webSiteTitle;
|
||||||
|
$mail->msgHTML($message);
|
||||||
|
$mail->addAddress($contactEmail);
|
||||||
|
$resp = $mail->send();
|
||||||
|
if (!$resp) {
|
||||||
|
_error_log("sendEmailToSiteOwner Error Info: {$mail->ErrorInfo}");
|
||||||
|
} else {
|
||||||
|
_error_log("sendEmailToSiteOwner Success Info: $subject ");
|
||||||
|
}
|
||||||
|
return $resp;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
_error_log($e->getMessage()); //Boring error messages from anything else!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isValidEmail($email, $checkHost = false)
|
||||||
|
{
|
||||||
|
global $_email_hosts_checked;
|
||||||
|
if (empty($email)) {
|
||||||
|
_error_log("isValidEmail email is empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
_error_log("isValidEmail not FILTER_VALIDATE_EMAIL {$email}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (preg_match('/@teste?\./i', $email)) {
|
||||||
|
_error_log("isValidEmail wrong domain {$email}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (preg_match('/@yourDomain?\./i', $email)) {
|
||||||
|
_error_log("isValidEmail wrong domain {$email}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isset($_email_hosts_checked)) {
|
||||||
|
$_email_hosts_checked = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($checkHost)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get host name from email and check if it is valid
|
||||||
|
$email_host = array_slice(explode("@", $email), -1)[0];
|
||||||
|
|
||||||
|
if (isset($_email_hosts_checked[$email_host])) {
|
||||||
|
return $_email_hosts_checked[$email_host];
|
||||||
|
}
|
||||||
|
|
||||||
|
$_email_hosts_checked[$email_host] = true;
|
||||||
|
// Check if valid IP (v4 or v6). If it is we can't do a DNS lookup
|
||||||
|
if (!filter_var($email_host, FILTER_VALIDATE_IP, [
|
||||||
|
'flags' => FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE,
|
||||||
|
])) {
|
||||||
|
//Add a dot to the end of the host name to make a fully qualified domain name
|
||||||
|
// and get last array element because an escaped @ is allowed in the local part (RFC 5322)
|
||||||
|
// Then convert to ascii (http://us.php.net/manual/en/function.idn-to-ascii.php)
|
||||||
|
$email_host = idn_to_ascii($email_host . '.');
|
||||||
|
|
||||||
|
//Check for MX pointers in DNS (if there are no MX pointers the domain cannot receive emails)
|
||||||
|
if (!checkdnsrr($email_host, "MX")) {
|
||||||
|
$_email_hosts_checked[$email_host] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_email_hosts_checked[$email_host];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $strOrArray
|
||||||
|
* @return string return an array with the valid emails.
|
||||||
|
*/
|
||||||
|
function is_email($strOrArray)
|
||||||
|
{
|
||||||
|
if (empty($strOrArray)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (!is_array($strOrArray)) {
|
||||||
|
$strOrArray = [$strOrArray];
|
||||||
|
}
|
||||||
|
$valid_emails = [];
|
||||||
|
foreach ($strOrArray as $email) {
|
||||||
|
if (is_numeric($email)) {
|
||||||
|
$email = User::getEmailDb($email);
|
||||||
|
}
|
||||||
|
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$valid_emails[] = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $valid_emails;
|
||||||
|
}
|
393
objects/functionsPHP.php
Normal file
393
objects/functionsPHP.php
Normal file
|
@ -0,0 +1,393 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It return true in case the $html_string is a string 'false' (good for post/get variables check)
|
||||||
|
* It also return true in case it is an empty HTML
|
||||||
|
* @param string $html_string
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function _empty($html_string)
|
||||||
|
{
|
||||||
|
if (empty($html_string)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (is_string($html_string)) {
|
||||||
|
if (mb_strtolower($html_string) == 'false') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (mb_strtolower($html_string) == 'null') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emptyHTML($html_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _intval($string)
|
||||||
|
{
|
||||||
|
if (is_string($string)) {
|
||||||
|
if (mb_strtolower($string) == 'true') {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return intval($string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _strtotime($datetime)
|
||||||
|
{
|
||||||
|
return is_int($datetime) ? $datetime : strtotime($datetime);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @link https://github.com/php/php-src/issues/8218#issuecomment-1072439915
|
||||||
|
*/
|
||||||
|
function _ob_end_clean()
|
||||||
|
{
|
||||||
|
@ob_end_clean();
|
||||||
|
header_remove('Content-Encoding');
|
||||||
|
}
|
||||||
|
|
||||||
|
function _ob_clean()
|
||||||
|
{
|
||||||
|
@ob_clean();
|
||||||
|
header_remove('Content-Encoding');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function _ob_start($force = false)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
if (!isset($global['ob_start_callback'])) {
|
||||||
|
$global['ob_start_callback'] = 'ob_gzhandler';
|
||||||
|
} else {
|
||||||
|
if (empty($global['ob_start_callback'])) {
|
||||||
|
$global['ob_start_callback'] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($global['ob_start_callback']) && empty($force) && ob_get_level()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ob_start($global['ob_start_callback']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
clear return send stop
|
||||||
|
ob_clean x
|
||||||
|
ob_end_clean x x
|
||||||
|
ob_end_flush x x
|
||||||
|
ob_flush x
|
||||||
|
ob_get_clean x x x // should be called ob_get_end_clean
|
||||||
|
ob_get_contents x
|
||||||
|
ob_get_flush x x
|
||||||
|
*/
|
||||||
|
function _ob_get_clean()
|
||||||
|
{
|
||||||
|
$content = ob_get_contents();
|
||||||
|
_ob_end_clean();
|
||||||
|
_ob_start();
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _setcookie($cookieName, $value, $expires = 0)
|
||||||
|
{
|
||||||
|
global $config, $global;
|
||||||
|
if (empty($expires)) {
|
||||||
|
if (empty($config) || !is_object($config)) {
|
||||||
|
require_once $global['systemRootPath'] . 'objects/configuration.php';
|
||||||
|
if (class_exists('AVideoConf')) {
|
||||||
|
$config = new AVideoConf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($config) && is_object($config)) {
|
||||||
|
$expires = time() + $config->getSession_timeout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$domain = getDomain();
|
||||||
|
if (version_compare(phpversion(), '7.3', '>=')) {
|
||||||
|
$cookie_options = [
|
||||||
|
'expires' => $expires,
|
||||||
|
'path' => '/',
|
||||||
|
'domain' => $domain,
|
||||||
|
'secure' => true,
|
||||||
|
'httponly' => true,
|
||||||
|
'samesite' => 'None'
|
||||||
|
];
|
||||||
|
setcookie($cookieName, $value, $cookie_options);
|
||||||
|
$cookie_options['domain'] = 'www.' . $domain;
|
||||||
|
setcookie($cookieName, $value, $cookie_options);
|
||||||
|
} else {
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", $domain);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", 'www.' . $domain);
|
||||||
|
}
|
||||||
|
$_COOKIE[$cookieName]=$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _unsetcookie($cookieName)
|
||||||
|
{
|
||||||
|
$domain = getDomain();
|
||||||
|
$expires = strtotime("-10 years");
|
||||||
|
$value = '';
|
||||||
|
_setcookie($cookieName, $value, $expires);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/") && setcookie($cookieName, $value, (int) $expires);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", str_replace("www", "", $domain));
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", "www." . $domain);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", ".www." . $domain);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", "." . $domain);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/", $domain);
|
||||||
|
setcookie($cookieName, $value, (int) $expires, "/");
|
||||||
|
setcookie($cookieName, $value, (int) $expires);
|
||||||
|
unset($_COOKIE[$cookieName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _resetcookie($cookieName, $value)
|
||||||
|
{
|
||||||
|
_unsetcookie($cookieName);
|
||||||
|
_setcookie($cookieName, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this will make sure the strring will fits in the database field
|
||||||
|
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");
|
||||||
|
} else {
|
||||||
|
return substr($string, $start, $length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
} else {
|
||||||
|
return strlen($string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_utf8($string)
|
||||||
|
{
|
||||||
|
return preg_match('//u', $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _utf8_encode_recursive($object)
|
||||||
|
{
|
||||||
|
if (is_string($object)) {
|
||||||
|
return is_utf8($object) ? $object : utf8_encode($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($object)) {
|
||||||
|
foreach ($object as $key => $value) {
|
||||||
|
$object[$key] = _utf8_encode_recursive($value);
|
||||||
|
}
|
||||||
|
} elseif (is_object($object)) {
|
||||||
|
foreach ($object as $key => $value) {
|
||||||
|
$object->$key = _utf8_encode_recursive($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _json_encode($object)
|
||||||
|
{
|
||||||
|
if (is_string($object)) {
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
if (empty($object)) {
|
||||||
|
return json_encode($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that all strings within the object are UTF-8 encoded
|
||||||
|
$utf8_encoded_object = _utf8_encode_recursive($object);
|
||||||
|
|
||||||
|
// Encode the object as JSON
|
||||||
|
$json = json_encode($utf8_encoded_object);
|
||||||
|
|
||||||
|
// If there's a JSON encoding error, log the error message and debug backtrace
|
||||||
|
if (empty($json) && json_last_error()) {
|
||||||
|
$errors[] = "_json_encode: Error Found: " . json_last_error_msg();
|
||||||
|
foreach ($errors as $value) {
|
||||||
|
_error_log($value);
|
||||||
|
}
|
||||||
|
_error_log(json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _json_decode($object)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
if (empty($object)) {
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
if (!is_string($object)) {
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
if (isValidURLOrPath($object)) {
|
||||||
|
$content = file_get_contents($object);
|
||||||
|
if (!empty($content)) {
|
||||||
|
$object = $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$json = json_decode($object);
|
||||||
|
if ($json === null) {
|
||||||
|
$object = str_replace(["\r", "\n"], ['\r', '\n'], $object);
|
||||||
|
return json_decode($object);
|
||||||
|
} else {
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _session_write_close(){
|
||||||
|
if (isSessionStarted()) {
|
||||||
|
//_error_log(json_encode(debug_backtrace()));
|
||||||
|
@session_write_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSessionStarted() {
|
||||||
|
global $customSessionHandle;
|
||||||
|
|
||||||
|
if(session_status() == PHP_SESSION_NONE){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(session_status() == PHP_SESSION_ACTIVE){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Check if a session variable exists in Memcached
|
||||||
|
if (!empty($customSessionHandle) && $customSessionHandle->get(session_id()) !== false) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function session_start_preload(){
|
||||||
|
global $_session_start_preload, $global;
|
||||||
|
if(empty($global['systemRootPath'])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!class_exists('AVideoConf')){
|
||||||
|
require $global['systemRootPath'] . 'objects/configuration.php';
|
||||||
|
}
|
||||||
|
if(!isset($_session_start_preload)){
|
||||||
|
$_session_start_preload = 1;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = new AVideoConf();
|
||||||
|
|
||||||
|
// server should keep session data for AT LEAST 1 hour
|
||||||
|
ini_set('session.gc_maxlifetime', $config->getSession_timeout());
|
||||||
|
|
||||||
|
// each client should remember their session id for EXACTLY 1 hour
|
||||||
|
session_set_cookie_params($config->getSession_timeout());
|
||||||
|
|
||||||
|
//Fix “set SameSite cookie to none” warning
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
|
||||||
|
setcookie('key', 'value', ['samesite' => 'None', 'secure' => true]);
|
||||||
|
} else {
|
||||||
|
header('Set-Cookie: cross-site-cookie=name; SameSite=None; Secure');
|
||||||
|
setcookie('key', 'value', time() + $config->getSession_timeout(), '/; SameSite=None; Secure');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _session_start(array $options = [])
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
session_start_preload();
|
||||||
|
if (isset($_GET['PHPSESSID']) && !_empty($_GET['PHPSESSID'])) {
|
||||||
|
$PHPSESSID = $_GET['PHPSESSID'];
|
||||||
|
unset($_GET['PHPSESSID']);
|
||||||
|
if (!User::isLogged()) {
|
||||||
|
if ($PHPSESSID !== session_id()) {
|
||||||
|
_session_write_close();
|
||||||
|
session_id($PHPSESSID);
|
||||||
|
//_error_log("captcha: session_id changed to {$PHPSESSID}");
|
||||||
|
}
|
||||||
|
//memcachedSession();
|
||||||
|
$session = @session_start($options);
|
||||||
|
|
||||||
|
if (preg_match('/objects\/getCaptcha\.php/i', $_SERVER['SCRIPT_NAME'])) {
|
||||||
|
$regenerateSessionId = false;
|
||||||
|
}
|
||||||
|
if (!blackListRegenerateSession()) {
|
||||||
|
_error_log("captcha: session_id regenerated new session_id=" . session_id());
|
||||||
|
_session_regenerate_id();
|
||||||
|
}
|
||||||
|
return $session;
|
||||||
|
} else {
|
||||||
|
//_error_log("captcha: user logged we will not change the session ID PHPSESSID={$PHPSESSID} session_id=" . session_id());
|
||||||
|
}
|
||||||
|
} elseif (!isSessionStarted()) {
|
||||||
|
//_error_log(json_encode(debug_backtrace()));
|
||||||
|
$start = microtime(true);
|
||||||
|
//_error_log('session_start 1');
|
||||||
|
$session = @session_start($options);
|
||||||
|
//_error_log('session_start 2');
|
||||||
|
$takes = microtime(true) - $start;
|
||||||
|
if($takes > 1){
|
||||||
|
_error_log('session_start takes '.$takes.' seconds to open');
|
||||||
|
_error_log(json_encode(debug_backtrace()));
|
||||||
|
//exit;
|
||||||
|
}
|
||||||
|
return $session;
|
||||||
|
}
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
_error_log("_session_start: " . $exc->getTraceAsString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _session_regenerate_id()
|
||||||
|
{
|
||||||
|
session_regenerate_id(true);
|
||||||
|
_resetcookie('PHPSESSID', session_id());
|
||||||
|
_resetcookie(session_name(), session_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
function uniqidV4()
|
||||||
|
{
|
||||||
|
$randomString = openssl_random_pseudo_bytes(16);
|
||||||
|
$time_low = bin2hex(substr($randomString, 0, 4));
|
||||||
|
$time_mid = bin2hex(substr($randomString, 4, 2));
|
||||||
|
$time_hi_and_version = bin2hex(substr($randomString, 6, 2));
|
||||||
|
$clock_seq_hi_and_reserved = bin2hex(substr($randomString, 8, 2));
|
||||||
|
$node = bin2hex(substr($randomString, 10, 6));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the four most significant bits (bits 12 through 15) of the
|
||||||
|
* time_hi_and_version field to the 4-bit version number from
|
||||||
|
* Section 4.1.3.
|
||||||
|
* @see http://tools.ietf.org/html/rfc4122#section-4.1.3
|
||||||
|
*/
|
||||||
|
$time_hi_and_version = hexdec($time_hi_and_version);
|
||||||
|
$time_hi_and_version = $time_hi_and_version >> 4;
|
||||||
|
$time_hi_and_version = $time_hi_and_version | 0x4000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the two most significant bits (bits 6 and 7) of the
|
||||||
|
* clock_seq_hi_and_reserved to zero and one, respectively.
|
||||||
|
*/
|
||||||
|
$clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved);
|
||||||
|
$clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2;
|
||||||
|
$clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000;
|
||||||
|
|
||||||
|
return sprintf('%08s-%04s-%04x-%04x-%012s', $time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @link https://github.com/php/php-src/issues/8218
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function doesPHPVersioHasOBBug()
|
||||||
|
{
|
||||||
|
return (version_compare(phpversion(), '8.1.4', '==') || version_compare(phpversion(), '8.0.17', '=='));
|
||||||
|
}
|
115
objects/functionsSocket.php
Normal file
115
objects/functionsSocket.php
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $users_id="" or 0 means send messages to all users
|
||||||
|
* $users_id="-1" means send to no one
|
||||||
|
*/
|
||||||
|
|
||||||
|
function sendSocketMessage($msg, $callbackJSFunction = "", $users_id = "-1", $send_to_uri_pattern = "", $try = 0)
|
||||||
|
{
|
||||||
|
if (AVideoPlugin::isEnabledByName('YPTSocket')) {
|
||||||
|
if (!is_string($msg)) {
|
||||||
|
$msg = json_encode($msg);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$obj = YPTSocket::send($msg, $callbackJSFunction, $users_id, $send_to_uri_pattern);
|
||||||
|
//_error_log("sendSocketMessage YPTSocket::send ");
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
if ($try < 3) {
|
||||||
|
sleep(1);
|
||||||
|
_error_log("sendSocketMessage try agaion [$try]" . $exc->getMessage());
|
||||||
|
$obj = sendSocketMessage($msg, $callbackJSFunction, $users_id, $send_to_uri_pattern, $try + 1);
|
||||||
|
} else {
|
||||||
|
$obj = new stdClass();
|
||||||
|
$obj->error = true;
|
||||||
|
$obj->msg = $exc->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($obj->error && !empty($obj->msg)) {
|
||||||
|
_error_log("sendSocketMessage " . $obj->msg);
|
||||||
|
}
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendSocketMessageToUsers_id($msg, $users_id, $callbackJSFunction = "")
|
||||||
|
{
|
||||||
|
if (empty($users_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_error_log("sendSocketMessageToUsers_id start " . json_encode($users_id));
|
||||||
|
if (!is_array($users_id)) {
|
||||||
|
$users_id = [$users_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
$resp = [];
|
||||||
|
foreach ($users_id as $value) {
|
||||||
|
$resp[] = sendSocketMessage($msg, $callbackJSFunction, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendSocketErrorMessageToUsers_id($msg, $users_id, $callbackJSFunction = "avideoResponse")
|
||||||
|
{
|
||||||
|
$newMessage = new stdClass();
|
||||||
|
$newMessage->error = true;
|
||||||
|
$newMessage->msg = $msg;
|
||||||
|
return sendSocketMessageToUsers_id($newMessage, $users_id, $callbackJSFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendSocketSuccessMessageToUsers_id($msg, $users_id, $callbackJSFunction = "avideoResponse")
|
||||||
|
{
|
||||||
|
$newMessage = new stdClass();
|
||||||
|
$newMessage->error = false;
|
||||||
|
$newMessage->msg = $msg;
|
||||||
|
return sendSocketMessageToUsers_id($newMessage, $users_id, $callbackJSFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendSocketMessageToAll($msg, $callbackJSFunction = "", $send_to_uri_pattern = "")
|
||||||
|
{
|
||||||
|
return sendSocketMessage($msg, $callbackJSFunction, "", $send_to_uri_pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendSocketMessageToNone($msg, $callbackJSFunction = "")
|
||||||
|
{
|
||||||
|
return sendSocketMessage($msg, $callbackJSFunction, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSocketConnectionLabel()
|
||||||
|
{
|
||||||
|
$html = '<span class="socketStatus">
|
||||||
|
<span class="socket_icon socket_loading_icon">
|
||||||
|
<i class="fas fa-sync fa-spin"></i>
|
||||||
|
</span>
|
||||||
|
<span class="socket_icon socket_not_loading socket_disconnected_icon">
|
||||||
|
<span class="fa-stack">
|
||||||
|
<i class="fas fa-slash fa-stack-1x"></i>
|
||||||
|
<i class="fas fa-plug fa-stack-1x"></i>
|
||||||
|
</span> ' . __('Disconnected') . '
|
||||||
|
</span>
|
||||||
|
<span class="socket_icon socket_not_loading socket_connected_icon">
|
||||||
|
<span class="fa-stack">
|
||||||
|
<i class="fas fa-plug fa-stack-1x"></i>
|
||||||
|
</span> ' . __('Connected') . '
|
||||||
|
</span>
|
||||||
|
</span>';
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSocketVideoClassName($videos_id)
|
||||||
|
{
|
||||||
|
return 'total_on_videos_id_' . $videos_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSocketLiveClassName($key, $live_servers_id)
|
||||||
|
{
|
||||||
|
return 'total_on_live_' . $key . '_' . intval($live_servers_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSocketLiveLinksClassName($live_links_id)
|
||||||
|
{
|
||||||
|
return 'total_on_live_links_id_' . $live_links_id;
|
||||||
|
}
|
|
@ -239,7 +239,8 @@ $groups = UserGroups::getAllUsersGroups();
|
||||||
<label for="text">text:</label>
|
<label for="text">text:</label>
|
||||||
<textarea type="text" class="form-control" id="pageText"></textarea>
|
<textarea type="text" class="form-control" id="pageText"></textarea>
|
||||||
<?php
|
<?php
|
||||||
echo getTinyMCE("pageText");
|
//getTinyMCE($id, $simpleMode = false, $allowAttributes = false, $allowCSS = false, $allowAllTags = false)
|
||||||
|
echo getTinyMCE("pageText", false, true, true, true);
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,6 +24,9 @@ class IP2Location extends ObjectYPT {
|
||||||
// japan 2.16.40.123
|
// japan 2.16.40.123
|
||||||
// USA 2.16.13.123
|
// USA 2.16.13.123
|
||||||
//$ip = '2.16.40.123';
|
//$ip = '2.16.40.123';
|
||||||
|
if(!isset($_SESSION['IP2Location']) || !is_array($_SESSION['IP2Location'])){
|
||||||
|
$_SESSION['IP2Location'] = array();
|
||||||
|
}
|
||||||
if (empty($_SESSION['IP2Location'][$ip]['country_code'])) {
|
if (empty($_SESSION['IP2Location'][$ip]['country_code'])) {
|
||||||
$_SESSION['IP2Location'][$ip] = false;
|
$_SESSION['IP2Location'][$ip] = false;
|
||||||
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||||
|
|
|
@ -8,8 +8,9 @@ if (empty($_REQUEST['users_id'])) {
|
||||||
header('Content-Type: image/jpeg');
|
header('Content-Type: image/jpeg');
|
||||||
$img = 'img/placeholders/user.png';
|
$img = 'img/placeholders/user.png';
|
||||||
} else {
|
} else {
|
||||||
|
$users_id = intval($_REQUEST['users_id']);
|
||||||
header('Content-Type: image/png');
|
header('Content-Type: image/png');
|
||||||
$img = "../videos/userPhoto/photo{$_REQUEST['users_id']}.png";
|
$img = "../videos/userPhoto/photo{$users_id}.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($img)) {
|
if (!file_exists($img)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue