cron.php
changeset 193 ebe99e82a59a
parent 191 3dbe848431b0
child 317 f8356d9c3481
equal deleted inserted replaced
187:9dbbec5e6096 193:ebe99e82a59a
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
       
     5  * Version 1.0.2 (Coblynau)
       
     6  * Copyright (C) 2006-2007 Dan Fuhry
       
     7  *
       
     8  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
       
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
       
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
       
    13  */
       
    14 
       
    15 //
       
    16 // cron.php - Maintenance tasks that should be run periodically
       
    17 //
       
    18 
       
    19 // The cron script is triggered by way of an image. This is a 1x1px transparent GIF.
       
    20 define('ENANO_GIF_SPACER', base64_decode('R0lGODlhAQABAIAAAP///////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgABACwAAAAAAQABAAACAkwBADs='));
       
    21 
       
    22 // Don't need a page to load, all we should need is the Enano API
       
    23 $_GET['title'] = 'Enano:Cron';
       
    24 require('includes/common.php');
       
    25 
       
    26 global $db, $session, $paths, $template, $plugins; // Common objects
       
    27 
       
    28 // Hope now that plugins are loaded :-)
       
    29 $last_run = ( $x = getConfig('cron_last_run') ) ? $x : 0;
       
    30 $time = strval(time());
       
    31 setConfig('cron_last_run', $time);
       
    32 
       
    33 global $cron_tasks;
       
    34 
       
    35 foreach ( $cron_tasks as $interval => $tasks )
       
    36 {
       
    37   $last_run_threshold = time() - ( $interval * 3600 );
       
    38   if ( $last_run_threshold >= $last_run )
       
    39   {
       
    40     foreach ( $tasks as $task )
       
    41     {
       
    42       @call_user_func($task);
       
    43     }
       
    44   }
       
    45 }
       
    46 
       
    47 header('Pragma: no-cache');
       
    48 header('Cache-control: no-cache');
       
    49 header('Expires: Thu, 1 Jan 1970 00:00:01 GMT');
       
    50 header('Content-type: image/gif');
       
    51 
       
    52 echo ENANO_GIF_SPACER;
       
    53 
       
    54 ?>