diff options
-rw-r--r-- | crontab.example | 22 | ||||
-rw-r--r-- | engine/handlers/cron_handler.php | 8 | ||||
-rw-r--r-- | engine/lib/cron.php | 59 | ||||
-rw-r--r-- | htaccess_dist | 2 | ||||
-rw-r--r-- | languages/en.php | 2 |
5 files changed, 89 insertions, 4 deletions
diff --git a/crontab.example b/crontab.example new file mode 100644 index 000000000..cb2223d3b --- /dev/null +++ b/crontab.example @@ -0,0 +1,22 @@ +# Crontab example. +# +# This file is an example of triggering Elgg cron events. Modify and register events +# as appropriate. +# +# See crontab (5) for more information. +# +# @author Marcus Povey + +# Location of GET +GET='/usr/bin/GET' + +# Location of your site +ELGG='http://www.example.com/' + +# The crontab +@reboot $GET ${ELGG}pg/cron/reboot/ +@hourly $GET ${ELGG}pg/cron/hourly/ +@daily $GET ${ELGG}pg/cron/daily/ +@weekly $GET ${ELGG}pg/cron/weekly/ +@monthly $GET ${ELGG}pg/cron/monthly/ +@yearly $GET ${ELGG}pg/cron/yearly/ diff --git a/engine/handlers/cron_handler.php b/engine/handlers/cron_handler.php index dd58b5266..acc24541c 100644 --- a/engine/handlers/cron_handler.php +++ b/engine/handlers/cron_handler.php @@ -14,16 +14,20 @@ require_once("../start.php"); global $CONFIG; + // Get basic parameters + $period = get_input('period'); + if (!$period) throw new CronException(sprintf(elgg_echo('CronException:unknownperiod'), $period)); + // Get a list of parameters $params = array(); $params['time'] = time(); - foreach ($_REQUEST[] as $k => $v) + foreach ($CONFIG->input as $k => $v) $params[$k] = $v; // Trigger hack $std_out = ""; // Data to return to - $std_out = trigger_plugin_hook('system', 'cron', $params, $std_out); + $std_out = trigger_plugin_hook('cron', $period, $params, $std_out); // Return event echo $std_out; diff --git a/engine/lib/cron.php b/engine/lib/cron.php new file mode 100644 index 000000000..f488bab0f --- /dev/null +++ b/engine/lib/cron.php @@ -0,0 +1,59 @@ +<?php + /** + * Elgg cron library. + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + /** The cron exception. */ + class CronException extends Exception {} + + /** + * Initialisation + * + */ + function cron_init() + { + // Register a pagehandler for cron + register_page_handler('cron','cron_page_handler'); + } + + /** + * Cron handler for redirecting pages. + * + * @param unknown_type $page + */ + function cron_page_handler($page) + { + global $CONFIG; + + if ($page[0]) + { + switch (strtolower($page[0])) + { + case 'hourly' : + case 'daily' : + case 'weekly' : + case 'monthly': + case 'yearly' : + case 'reboot' : set_input('period', $page[0]); break; + default : throw new CronException(sprintf(elgg_echo('CronException:unknownperiod'), $page[0])); + } + + // Include cron handler + include($CONFIG->path . "engine/handlers/cron_handler.php"); + } + else + include($CONFIG->pluginspath . "ss_sms/index.php"); + } + + + // Register a startup event + register_elgg_event_handler('init','system','cron_init'); + +?>
\ No newline at end of file diff --git a/htaccess_dist b/htaccess_dist index 9148ad2f5..90fcb40c8 100644 --- a/htaccess_dist +++ b/htaccess_dist @@ -67,8 +67,6 @@ RewriteEngine on #
#RewriteBase /
-RewriteRule ^cron\/$ engine/handlers/cron_handler.php
-
RewriteRule ^action\/([A-Za-z\_\-\/]+)$ engine/handlers/action_handler.php?action=$1
RewriteRule ^actions\/([A-Za-z\_\-\/]+)$ engine/handlers/action_handler.php?action=$1
diff --git a/languages/en.php b/languages/en.php index cdcd51636..c23a9fa2f 100644 --- a/languages/en.php +++ b/languages/en.php @@ -156,6 +156,8 @@ 'InstallationException:DatarootBlank' => "You have not specified a data directory.", 'SecurityException:authenticationfailed' => "User could not be authenticated", + + 'CronException:unknownperiod' => '%s is not a recognised period.', /** * API */ |