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