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
|
<?php
/**
* Elgg cron library.
*
* @package Elgg
* @subpackage Core
*/
/**
* Cron initialization
*
* @return void
* @access private
*/
function cron_init() {
// Register a pagehandler for cron
elgg_register_page_handler('cron', 'cron_page_handler');
// register a hook for Walled Garden public pages
elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'cron_public_pages');
}
/**
* Cron handler
*
* @param array $page Pages
*
* @return bool
* @throws CronException
* @access private
*/
function cron_page_handler($page) {
if (!isset($page[0])) {
forward();
}
$period = strtolower($page[0]);
$allowed_periods = array(
'minute', 'fiveminute', 'fifteenmin', 'halfhour', 'hourly',
'daily', 'weekly', 'monthly', 'yearly', 'reboot'
);
if (!in_array($period, $allowed_periods)) {
throw new CronException(elgg_echo('CronException:unknownperiod', array($period)));
}
// Get a list of parameters
$params = array();
$params['time'] = time();
// Data to return to
$old_stdout = "";
ob_start();
$old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout);
$std_out = ob_get_clean();
echo $std_out . $old_stdout;
return true;
}
/**
* Register cron's pages as public in case we're in Walled Garden mode
*
* @param string $hook public_pages
* @param string $type system
* @param array $return_value Array of pages to allow
* @param mixed $params Params
*
* @return array
* @access private
*/
function cron_public_pages($hook, $type, $return_value, $params) {
$return_value[] = 'cron/minute';
$return_value[] = 'cron/fiveminute';
$return_value[] = 'cron/fifteenmin';
$return_value[] = 'cron/halfhour';
$return_value[] = 'cron/hourly';
$return_value[] = 'cron/daily';
$return_value[] = 'cron/weekly';
$return_value[] = 'cron/monthly';
$return_value[] = 'cron/yearly';
$return_value[] = 'cron/reboot';
return $return_value;
}
elgg_register_event_handler('init', 'system', 'cron_init');
|