-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodule.php
117 lines (104 loc) · 3.19 KB
/
module.php
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
<?php
/*
+ ------------------------------------------------------------------------------ +
| PHP File Downloader
|
| Copyright (C) 2012 Hashem Qolami
|
| This program is free software: you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation, either version 3 of the License, or
| any later version.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| Released under the terms and conditions of the
| GNU General Public License (http://www.gnu.org/licenses/gpl.html).
|
| $URL: https://github.com/qolami/PHP-File-Downloader $
| $Version: 1.3 $
| $Author: Hashem Qolami $
+ ------------------------------------------------------------------------------ +
*/
defined("CORE_INIT") or die("Access Denied!");
function multi_array_search($obj, $parent_arr){
foreach($parent_arr as $key => $val){
if(is_array($val)) {
if(in_array($obj, $val)) return $key;
}else{
if($val == $obj) return $key;
}
}
return 'not found!';
}
function release_array($directory, $vFileTyp){
is_dir($directory) or die('folder not found!');
$dir = @opendir($directory);
$i = 0;
while(($file = @readdir($dir)) !== false){
$filetype = strtolower(substr(strrchr($file, '.'), 1)); // strtolower(array_pop(explode('.', $file)));
if(array_key_exists($filetype, $vFileTyp)) {
$files[$i][] = $directory.'/'.$file;
$files[$i][] = filemtime($files[$i][0]);
$i++;
}
}
@closedir($dir);
return $files;
}
function get_release_address($arr, $ver, $ver_separator=NULL){
isset($ver_separator) or $ver_separator = '_';
if($ver == 'latest'){
for($i=0; $i<count($arr); $i++){
$modtime[] = $arr[$i][1];
}
return $arr[multi_array_search(max($modtime), $arr)][0];
}else{
for($i=0; $i<count($arr); $i++){
if(preg_match("#^(.+)".$ver_separator.$ver."[^0-9]*(\.[a-z7]{2,})$#i", basename($arr[$i][0]))) return $arr[$i][0];
}
return false;
}
}
function get_referrer(){
return isset($_SERVER['HTTP_REFERER'])?strtolower($_SERVER['HTTP_REFERER']):NULL;
}
function get_ip(){
return isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'];
}
function check_referrer($ref, $refs){
if(!isset($ref) || strlen($ref)<1) return false;
foreach($refs as $val){
if(preg_match("#".trim($val)."#i", $ref)) return 1;
}
return false;
}
function log_download_info($log_file, $arr){
if($handler = @fopen($log_file, 'a+')){
@fputs($handler, implode(" ", $arr)."\n");
@fclose($handler);
}
}
function check_url_valid($hash, $duration){
$current_time = time();
$arr = @json_decode(file_get_contents(TMP_ADDRS_FILE), true);
if(!array_key_exists($hash, $arr)) return false;
if(($current_time - floatval($arr[$hash]['mktime'])) < $duration) return 1;
return false;
}
function update_temp_file($arr, $duration){
if(!is_array($arr)) $arr = array();
$current_time = time();
if(!array_key_exists('creation', $arr)){
$arr['creation'] = $current_time;
}else{
if(($current_time - floatval($arr['creation'])) > $duration){
unset($arr);
$arr = array();
}
}
return $arr;
}
?>