-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron.php
executable file
·121 lines (92 loc) · 2.98 KB
/
cron.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
#!/usr/bin/env php
<?php
/*
* Jappix Me - Your public profile, anywhere
* CRON service
*
* License: AGPL
* Author: Valérian Saliou
*/
// Change current working dir
chdir(dirname(__FILE__));
// Initialize
include('./php/config.php');
include('./php/functions.php');
// Disable PHP error reporting
if(getConfig('app', 'mode') != 'development') {
ini_set('display_errors', 'off');
ini_set('error_reporting', 0);
}
// Don't allow non-CLI requests
if(sourceClient() != 'cli')
exit('Command-Line CRON Service. Please call me from your shell.');
// Greet the shell user
print('[cron] Welcome, master!'."\n");
print('[cron] Scanning users...'."\n");
print("\n");
// Regenerate updated user data
$count_update = 0;
$available_users = scandir('./cache');
foreach($available_users as $current_user) {
// Not a XID?
if(!strpos($current_user, '@'))
continue;
// Check for fresh raw data
$exists_vcard = file_exists('./cache/'.$current_user.'/raw/vcard');
$exists_microblog = file_exists('./cache/'.$current_user.'/raw/microblog');
$exists_geoloc = file_exists('./cache/'.$current_user.'/raw/geoloc');
// Check a raw file is available
if($exists_vcard && $exists_microblog && $exists_geoloc) {
print('[cron] Regenerating storage for '.$current_user.'...'."\n");
$count_update++;
// Regenerate user XMPP data
$current_data = requestXMPPData($current_user);
// Any avatar for this user?
$exists_avatar = false;
$current_user_vcard = $current_data['vcard'];
if(isset($current_user_vcard['vcard'])) {
$current_vcard_arr = $current_user_vcard['vcard'][0]['sub'];
if(isset($current_vcard_arr['photo'])) {
$current_vcard_photo = $current_vcard_arr['photo'][0]['sub'];
// Get avatar data
$current_avatar_binval = isset($current_vcard_photo['binval']) ? $current_vcard_photo['binval'][0]['sub'] : null;
$current_avatar_type = isset($current_vcard_photo['type']) ? substr(strrchr($current_vcard_photo['type'][0]['sub'], '/'), 1) : null;
// Default avatar type
if(!$current_avatar_type)
$current_avatar_type = 'png';
// JPEG files must have .jpg extension
if($current_avatar_type == 'jpeg')
$current_avatar_type = 'jpg';
// Avatar exists?
if($current_avatar_binval && preg_match('/^(png|jpg|gif)$/', $current_avatar_type))
$exists_avatar = true;
// Free some memory
unset($current_vcard_photo);
unset($current_avatar_binval);
unset($current_avatar_type);
}
// Free some memory
unset($current_vcard_arr);
}
if($exists_avatar)
writeCache($current_user, 'avatar', 'exists', '');
else
writeCache($current_user, 'avatar', 'not_exists', '');
// Free some memory
unset($current_data);
unset($exists_avatar);
unset($current_user_vcard);
}
// Free some memory
unset($exists_vcard);
unset($exists_microblog);
unset($exists_geoloc);
}
// Nobody updated?
if($count_update == 0)
print('[cron] Nothing to do.'."\n");
// All done!
print("\n");
print('[cron] Done.'."\n");
print('[cron] Bye Bye!'."\n");
exit;