-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
513 lines (469 loc) · 16.1 KB
/
Copy pathfunctions.php
File metadata and controls
513 lines (469 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<?php
function local_get_contents($path) {
if (function_exists('fopen')) {
$myfile = fopen($path, "r") or die("Unable to open file!");
$text = fread($myfile, filesize($path));
fclose($myfile);
return $text;
}
return @file_get_contents($path);
}
function url_get_contents($Url, $ctx = "") {
if (empty($ctx)) {
$opts = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
);
$context = stream_context_create($opts);
} else {
$context = $ctx;
}
// some times the path has special chars
if (!filter_var($Url, FILTER_VALIDATE_URL)) {
if (!file_exists($Url)) {
$Url = utf8_decode($Url);
}
}
if (ini_get('allow_url_fopen')) {
try {
$tmp = @file_get_contents($Url, false, $context);
if ($tmp != false) {
return $tmp;
}
} catch (ErrorException $e) {
error_log("Error on get Content");
}
} else if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
return @file_get_contents($Url, false, $context);
}
// Returns a file size limit in bytes based on the PHP upload_max_filesize
// and post_max_size
function file_upload_max_size() {
static $max_size = -1;
if ($max_size < 0) {
// Start with post_max_size.
$max_size = parse_size(ini_get('post_max_size'));
// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = parse_size(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size = $upload_max;
}
}
return $max_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) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
} else {
return round($size);
}
}
function humanFileSize($size, $unit = "") {
if ((!$unit && $size >= 1 << 30) || $unit == "GB")
return number_format($size / (1 << 30), 2) . "GB";
if ((!$unit && $size >= 1 << 20) || $unit == "MB")
return number_format($size / (1 << 20), 2) . "MB";
if ((!$unit && $size >= 1 << 10) || $unit == "KB")
return number_format($size / (1 << 10), 2) . "KB";
return number_format($size) . " bytes";
}
function get_max_file_size() {
return humanFileSize(file_upload_max_size());
}
function humanTiming($time) {
$time = time() - $time; // to get the time since that moment
$time = ($time < 1) ? 1 : $time;
$tokens = array(
31536000 => __('year'),
2592000 => __('month'),
604800 => __('week'),
86400 => __('day'),
3600 => __('hour'),
60 => __('minute'),
1 => __('second')
);
foreach ($tokens as $unit => $text) {
if ($time < $unit)
continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : '');
}
}
function checkVideosDir() {
$dir = "../videos";
if (file_exists($dir)) {
if (is_writable($dir)) {
return true;
} else {
return false;
}
} else {
return mkdir($dir);
}
}
function isApache() {
if (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false)
return true;
else
return false;
}
function isPHP($version = "'7.0.0'") {
if (version_compare(PHP_VERSION, $version) >= 0) {
return true;
} else {
return false;
}
}
function modRewriteEnabled() {
if (!function_exists('apache_get_modules')) {
ob_start();
phpinfo(INFO_MODULES);
$contents = ob_get_contents();
ob_end_clean();
return (strpos($contents, 'mod_rewrite') !== false);
} else {
return in_array('mod_rewrite', apache_get_modules());
}
}
function isFFMPEG() {
return trim(shell_exec('which ffmpeg'));
}
function isExifToo() {
return trim(shell_exec('which exiftool'));
}
function getPathToApplication() {
return str_replace("install/index.php", "", $_SERVER["SCRIPT_FILENAME"]);
}
function getURLToApplication() {
$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = explode("install/index.php", $url);
$url = $url[0];
return $url;
}
//max_execution_time = 7200
function check_max_execution_time() {
$max_size = ini_get('max_execution_time');
$recomended_size = 7200;
if ($recomended_size > $max_size) {
return false;
} else {
return true;
}
}
//post_max_size = 100M
function check_post_max_size() {
$max_size = parse_size(ini_get('post_max_size'));
$recomended_size = parse_size('100M');
if ($recomended_size > $max_size) {
return false;
} else {
return true;
}
}
//upload_max_filesize = 100M
function check_upload_max_filesize() {
$max_size = parse_size(ini_get('upload_max_filesize'));
$recomended_size = parse_size('100M');
if ($recomended_size > $max_size) {
return false;
} else {
return true;
}
}
//memory_limit = 100M
function check_memory_limit() {
$max_size = parse_size(ini_get('memory_limit'));
$recomended_size = parse_size('512M');
if ($recomended_size > $max_size) {
return false;
} else {
return true;
}
}
function check_mysqlnd() {
return function_exists('mysqli_fetch_all');
}
function base64DataToImage($imgBase64) {
$img = $imgBase64;
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
return base64_decode($img);
}
function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function cleanString($text) {
$utf8 = array(
'/[áàâãªä]/u' => 'a',
'/[ÁÀÂÃÄ]/u' => 'A',
'/[ÍÌÎÏ]/u' => 'I',
'/[íìîï]/u' => 'i',
'/[éèêë]/u' => 'e',
'/[ÉÈÊË]/u' => 'E',
'/[óòôõºö]/u' => 'o',
'/[ÓÒÔÕÖ]/u' => 'O',
'/[úùûü]/u' => 'u',
'/[ÚÙÛÜ]/u' => 'U',
'/ç/' => 'c',
'/Ç/' => 'C',
'/ñ/' => 'n',
'/Ñ/' => 'N',
'/–/' => '-', // UTF-8 hyphen to "normal" hyphen
'/[’‘‹›‚]/u' => ' ', // Literally a single quote
'/[“”«»„]/u' => ' ', // Double quote
'/ /' => ' ', // nonbreaking space (equiv. to 0x160)
);
return preg_replace(array_keys($utf8), array_values($utf8), $text);
}
/**
* @brief return true if running in CLI, false otherwise
* if is set $_GET['ignoreCommandLineInterface'] will return false
* @return boolean
*/
function isCommandLineInterface() {
return (empty($_GET['ignoreCommandLineInterface']) && php_sapi_name() === 'cli');
}
/**
* @brief show status message as text (CLI) or JSON-encoded array (web)
*
* @param array $statusarray associative array with type/message pairs
* @return string
*/
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));
}
}
/**
* @brief show status message and die
*
* @param array $statusarray associative array with type/message pairs
*/
function croak($statusarray) {
status($statusarray);
die;
}
function getSecondsTotalVideosLength() {
$configFile = dirname(__FILE__) . '/../videos/configuration.php';
require_once $configFile;
global $global;
$sql = "SELECT * FROM videos v ";
$res = $global['mysqli']->query($sql);
$seconds = 0;
while ($row = $res->fetch_assoc()) {
$seconds += parseDurationToSeconds($row['duration']);
}
return $seconds;
}
function getMinutesTotalVideosLength() {
$seconds = getSecondsTotalVideosLength();
return floor($seconds / 60);
}
function parseDurationToSeconds($str) {
$durationParts = explode(":", $str);
if (empty($durationParts[1]))
return 0;
$minutes = intval(($durationParts[0]) * 60) + intval($durationParts[1]);
return intval($durationParts[2]) + ($minutes * 60);
}
/**
*
* @global type $global
* @param type $mail
* call it before send mail to let YouPHPTube decide the method
*/
function setSiteSendMessage(&$mail) {
global $global;
require_once $global['systemRootPath'] . 'objects/configuration.php';
$config = new Configuration();
if ($config->getSmtp()) {
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // 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();
} else {
$mail->isSendmail();
}
}
function decideFromPlugin() {
$json_file = file_get_contents(Login::getStreamerURL() . "plugin/CustomizeAdvanced/advancedCustom.json.php");
// convert the string to a json object
$advancedCustom = json_decode($json_file);
if (
empty($advancedCustom->doNotShowEncoderResolutionLow) && empty($advancedCustom->doNotShowEncoderResolutionSD) && empty($advancedCustom->doNotShowEncoderResolutionHD)) {
return array("mp4" => 80, "webm" => 87);
}
if (
empty($advancedCustom->doNotShowEncoderResolutionLow) && empty($advancedCustom->doNotShowEncoderResolutionSD)) {
return array("mp4" => 77, "webm" => 84);
}
if (
empty($advancedCustom->doNotShowEncoderResolutionLow) && empty($advancedCustom->doNotShowEncoderResolutionHD)) {
return array("mp4" => 79, "webm" => 86);
}
if (
empty($advancedCustom->doNotShowEncoderResolutionSD) && empty($advancedCustom->doNotShowEncoderResolutionHD)) {
return array("mp4" => 78, "webm" => 85);
}
if (empty($advancedCustom->doNotShowEncoderResolutionLow)) {
return array("mp4" => 74, "webm" => 81);
}
if (empty($advancedCustom->doNotShowEncoderResolutionSD)) {
return array("mp4" => 75, "webm" => 82);
}
if (empty($advancedCustom->doNotShowEncoderResolutionHD)) {
return array("mp4" => 76, "webm" => 83);
}
return array("mp4" => 80, "webm" => 87);
}
function decideFormatOrder() {
if (empty($_POST['webm']) || $_POST['webm'] === 'false') {
// mp4 only
if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false' &&
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false' &&
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) { // all resolutions
error_log("MP4 All");
return (80);
} else if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false' &&
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) {
error_log("MP4 Low - HD");
return (79);
} else if (
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false' &&
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) {
error_log("MP4 SD - HD");
return (78);
} else if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false' &&
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false'
) {
error_log("MP4 Low SD");
return (77);
} else if (
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) {
error_log("MP4 HD");
return (76);
} else if (
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false'
) {
error_log("MP4 SD");
return (75);
} else if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false'
) {
error_log("MP4 LOW");
return (74);
} else {
$decide = decideFromPlugin();
return $decide['mp4'];
}
} else {
// mp4 and webm
if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false' &&
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false' &&
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) { // all resolutions
return (87);
} else if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false' &&
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) {
return (86);
} else if (
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false' &&
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) {
return (85);
} else if (
!empty($_POST['inputLow']) && $_POST['inputLow'] !== 'false' &&
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false'
) {
return (84);
} else if (
!empty($_POST['inputHD']) && $_POST['inputHD'] !== 'false'
) {
return (83);
} else if (
!empty($_POST['inputSD']) && $_POST['inputSD'] !== 'false'
) {
return (82);
} else {
$decide = decideFromPlugin();
return $decide['webm'];
}
}
return 1;
}
function getUpdatesFiles() {
global $config, $global;
$files1 = scandir($global['systemRootPath'] . "update");
$updateFiles = array();
foreach ($files1 as $value) {
preg_match("/updateDb.v([0-9.]*).sql/", $value, $match);
if (!empty($match)) {
if ($config->currentVersionLowerThen($match[1])) {
$updateFiles[] = array('filename' => $match[0], 'version' => $match[1]);
}
}
}
return $updateFiles;
}
function ip_is_private($ip) {
$pri_addrs = array(
'10.0.0.0|10.255.255.255', // single class A network
'172.16.0.0|172.31.255.255', // 16 contiguous class B network
'192.168.0.0|192.168.255.255', // 256 contiguous class C network
'169.254.0.0|169.254.255.255', // Link-local address also refered to as Automatic Private IP Addressing
'127.0.0.0|127.255.255.255' // localhost
);
$long_ip = ip2long($ip);
if ($long_ip != -1) {
foreach ($pri_addrs AS $pri_addr) {
list ($start, $end) = explode('|', $pri_addr);
// IF IS PRIVATE
if ($long_ip >= ip2long($start) && $long_ip <= ip2long($end)) {
return true;
}
}
}
return false;
}