|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
function file_update_ago($filepath) |
|
4
|
|
|
{ |
|
5
|
|
|
$filemtime = filemtime($filepath); |
|
6
|
|
|
$now = time(); |
|
7
|
|
|
$diff = $now - $filemtime; |
|
8
|
|
|
return $diff; |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
// This file only include other files to have only 1 entry in your crontabs. |
|
13
|
|
|
// ------------------------------------------------------------------------ |
|
14
|
|
|
|
|
15
|
|
|
$filePath = dirname(__FILE__); |
|
16
|
|
|
$config_file = $filePath.'/../../config.php'; |
|
17
|
|
|
|
|
18
|
|
|
include_once($config_file); |
|
19
|
|
|
|
|
20
|
|
|
// Load variables.json |
|
21
|
|
|
$variables = $filePath.'/../json/variables.json'; |
|
22
|
|
|
$config = json_decode(file_get_contents($variables)); |
|
23
|
|
|
// force english language for all cron stuff |
|
24
|
|
|
$config->system->forced_lang = 'en'; |
|
25
|
|
|
|
|
26
|
|
|
// Manage Time Interval |
|
27
|
|
|
// ##################### |
|
28
|
|
|
|
|
29
|
|
|
include_once($filePath.'/../process/timezone.loader.php'); |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
# MySQL |
|
33
|
|
|
$mysqli = new mysqli(SYS_DB_HOST, SYS_DB_USER, SYS_DB_PSWD, SYS_DB_NAME, SYS_DB_PORT); |
|
34
|
|
|
|
|
35
|
|
|
if ($mysqli->connect_error != '') { |
|
36
|
|
|
die('MySQL connect error'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
// Update dashboard data |
|
41
|
|
|
// the following files are updated every run |
|
42
|
|
|
$gym_file = SYS_PATH.'/core/json/gym.stats.json'; |
|
43
|
|
|
$pokestop_file = SYS_PATH.'/core/json/pokestop.stats.json'; |
|
44
|
|
|
$pokemonstats_file = SYS_PATH.'/core/json/pokemon.stats.json'; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
if (is_file($gym_file)) { |
|
48
|
|
|
$gymsdatas = json_decode(file_get_contents($gym_file), true); |
|
49
|
|
|
} |
|
50
|
|
|
if (is_file($pokestop_file)) { |
|
51
|
|
|
$stopdatas = json_decode(file_get_contents($pokestop_file), true); |
|
52
|
|
|
} |
|
53
|
|
|
if (is_file($pokemonstats_file)) { |
|
54
|
|
|
$pokedatas = json_decode(file_get_contents($pokemonstats_file), true); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$timestamp = time(); |
|
58
|
|
|
|
|
59
|
|
|
include_once(SYS_PATH.'/core/cron/gym.cron.php'); |
|
60
|
|
|
include_once(SYS_PATH.'/core/cron/pokemon.cron.php'); |
|
61
|
|
|
include_once(SYS_PATH.'/core/cron/pokestop.cron.php'); |
|
62
|
|
|
if ($config->system->captcha_support) { |
|
63
|
|
|
include_once(SYS_PATH.'/core/cron/captcha.cron.php'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// The following files are updated every 24h only because the queries are quite expensive |
|
67
|
|
|
// and they don't need a fast update interval |
|
68
|
|
|
$update_delay = 86400; |
|
69
|
|
|
$pokedex_rarity_file = SYS_PATH.'/core/json/pokedex.rarity.json'; |
|
70
|
|
|
$nests_file = SYS_PATH.'/core/json/nests.stats.json'; |
|
71
|
|
|
|
|
72
|
|
|
// Do not update both files at the same time to lower cpu load |
|
73
|
|
|
if (file_update_ago($pokedex_rarity_file) > $update_delay) { |
|
74
|
|
|
// set file mtime to now before executing long running queries |
|
75
|
|
|
// so we don't try to update the file twice |
|
76
|
|
|
touch($pokedex_rarity_file); |
|
77
|
|
|
// update pokedex rarity |
|
78
|
|
|
include_once(SYS_PATH.'/core/cron/pokedex.rarity.php'); |
|
79
|
|
|
} elseif (file_update_ago($nests_file) > $update_delay) { |
|
80
|
|
|
// set file mtime to now before executing long running queries |
|
81
|
|
|
// so we don't try to update the file twice |
|
82
|
|
|
touch($nests_file); |
|
83
|
|
|
// update nests |
|
84
|
|
|
include_once(SYS_PATH.'/core/cron/nests.cron.php'); |
|
85
|
|
|
} |
|
86
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.