-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom.php
126 lines (109 loc) · 3.29 KB
/
custom.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
118
119
120
121
122
123
124
125
126
<?php
if(!isset($_GET['cmd'])) return;
include "common.php";
$url = urldecode($_SERVER['REQUEST_URI']);
$APP_PATH = substr($url, 0, strpos($url, 'custom.php'));
$DIR_PATH = str_replace('\\', '/', dirname(__FILE__));
if($DIR_PATH[-1] != '/')$DIR_PATH .= '/';
$DAT_PATH = $DIR_PATH.'datasets/documents/';
$CFG_PATH = $DAT_PATH.'homepage/config/';
$cmd = Strtoupper($_GET['cmd']);
// get random image
function random_image($mode) {
global $CFG_PATH;
$image_list = getImagelist($CFG_PATH.'images/');
if(count($image_list)==0) return;
if ($mode == 0)
return $image_list[rand(0, count($image_list)-1)];
else
return $image_list[randint_day()%count($image_list)];
}
function get_bing_today_imageurl() {
$str = file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if (preg_match("/<url>(.+?)<\/url>/", $str, $matches)) {
$imgurl = 'https://cn.bing.com'.$matches[1];
return $imgurl;
}
}
function random_js($mode) {
global $CFG_PATH;
$js_list = glob($CFG_PATH.'javascript/*.js');
if(count($js_list)==0) return;
foreach ($js_list as &$v){
$v = substr($v, strlen($CFG_PATH.'javascript/'));
}
if ($mode == 0)
return $js_list[rand(0, count($js_list)-1)];
else
return $js_list[randint_day()%count($js_list)];
}
/*
custom.php?cmd=xxx&
cmd:
IMAGE_OF_BING
IMAGE_OF_RANDOM
IMAGE_OF_DAY
IMAGE_LIBRARY
JS_OF_DAY
JS_OF_RANDOM
*/
switch($cmd) {
case "IMAGE_OF_DAY":
echo random_image(1);
return;
case "IMAGE_OF_RANDOM":
echo random_image(0);
return;
case "IMAGE_OF_BING":
case "IMAGE_OF_BING_AUTOSAVE":
if(file_exists($CFG_PATH.'images/BING_OF_DAY.txt')){
$d = file_get_contents($CFG_PATH.'images/BING_OF_DAY.txt');
$t = explode("|", $d);
if(($t[0]==intdiv(time()+8*3600,24*3600))&&(file_exists($t[1]))) {
echo basename($t[1]);
return;
}
}
for($i=0; $i<3; $i++) {
$url = get_bing_today_imageurl();
if($url != "") break;
}
$v1 = parse_url($url);
parse_str($v1['query'], $v2);
$imgfile = $CFG_PATH.'images/'.$v2['id'];
if (file_exists($imgfile) && (filesize($imgfile)>30000) ){
echo $v2['id'];
return;
}
else {
if ($cmd == "IMAGE_OF_BING_AUTOSAVE") {
$bG = false;
for($i=0; $i<3; $i++) {
// get image and save to file
$image_data = file_get_contents($url);
if(strlen($image_data)>50000){
$bG = true;
break;
}
}
if($bG) {
file_put_contents($imgfile, $image_data, LOCK_EX);
$v = intdiv(time()+8*3600,24*3600);
file_put_contents($CFG_PATH.'images/BING_OF_DAY.txt', $v.'|'.$imgfile, LOCK_EX);
}
}
echo $url;
}
return;
case "IMAGE_LIBRARY":
echo json_encode(getImagelist($CFG_PATH.'images/'));
return;
case "JS_OF_DAY":
echo random_js(1);
return;
case "JS_OF_RANDOM":
echo random_js(0);
return;
default: return;
}
?>