Files
IPB/upload/sources/tasks/calendarevents.php
T
2025-12-19 00:19:56 -08:00

191 lines
5.3 KiB
PHP

<?php
/*
+--------------------------------------------------------------------------
| Invision Power Board v2.0.0
| =============================================
| by Matthew Mecham
| (c) 2001 - 2004 Invision Power Services, Inc.
| http://www.invisionpower.com
| =============================================
| Web: http://www.invisionboard.com
| Time: Tue, 21 Sep 2004 16:34:28 GMT
| Release: 150aa7a702c3c8b6f6eb90ad49305d2f
| Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
| > TASK SCRIPT: Test
| > Script written by Matt Mecham
| > Date started: 28th January 2004
|
+--------------------------------------------------------------------------
*/
//-----------------------------------------
// THIS TASKS OPERATIONS:
// Gathers birthday and calendar events for a few days and caches them
//+--------------------------------------------------------------------------
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class task_item
{
var $class = "";
var $root_path = "";
var $task = "";
var $restrict_log = 0;
/*-------------------------------------------------------------------------*/
// Our 'auto_run' function
// ADD CODE HERE
/*-------------------------------------------------------------------------*/
function run_task()
{
global $DB, $ibforums, $std;
//-----------------------------------------
// Cache calendar info
//-----------------------------------------
$calendar = array();
$birthdays = array();
$a = explode( ',', gmdate( 'Y,n,j,G,i,s', time() ) );
$day = $a[2];
$month = $a[1];
$year = $a[0];
$daysinmonth = date( 't', time() );
//-----------------------------------------
// Get 24hr before and 24hr after to make
// sure we don't break any timezones
//-----------------------------------------
$last_day = $day - 1;
$last_month = $month;
$last_year = $year;
$next_day = $day + 1;
$next_month = $month;
$next_year = $year;
//-----------------------------------------
// Calculate dates..
//-----------------------------------------
if ( $last_day == 0 )
{
$last_month -= 1;
$last_day = date( 't', time() - 86400 );
}
if ( $last_month == 0 )
{
$last_month = 12;
$last_year -= 1;
}
if ( $next_day > date( 't', time() ) )
{
$next_month += 1;
$next_day = 1;
}
if ( $next_month == 13 )
{
$next_month = 1;
$next_year += 1;
}
//-----------------------------------------
// Grab birthdays
//-----------------------------------------
$DB->simple_construct( array( 'select' => 'id, name, mgroup, bday_day, bday_month, bday_year',
'from' => 'members',
'where' => "( bday_day=$last_day AND bday_month=$last_month )
or ( bday_day=$day AND bday_month=$month )
or ( bday_day=$next_day AND bday_month=$next_month )"
) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$birthdays[ $r['id'] ] = $r;
}
//-----------------------------------------
// Grab Calendar (-24hr + 24hr)
//-----------------------------------------
if ($ibforums->vars['calendar_limit'] < 2)
{
$ibforums->vars['calendar_limit'] = 2;
}
$our_unix = time() - 86400;
$max_date = $our_unix + ( ($ibforums->vars['calendar_limit'] + 1 ) * 86400);
$DB->simple_construct( array( 'select' => 'eventid, title, read_perms, priv_event, userid, unix_stamp',
'from' => 'calendar_events',
'where' => "unix_stamp > $our_unix and unix_stamp < $max_date",
'order' => "unix_stamp"
) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$calendar[ $r['eventid'] ] = $r;
}
//-----------------------------------------
// Save...
//-----------------------------------------
$DB->simple_exec_query( array( 'delete' => 'cache_store', 'where' => "cs_key IN ('birthdays', 'calendar')" ) );
$DB->do_insert( 'cache_store', array( 'cs_array' => 1, 'cs_key' => 'birthdays', 'cs_value' => addslashes(serialize($birthdays)) ) );
$DB->do_insert( 'cache_store', array( 'cs_array' => 1, 'cs_key' => 'calendar' , 'cs_value' => addslashes(serialize($calendar)) ) );
//-----------------------------------------
// Log to log table - modify but dont delete
//-----------------------------------------
if ( ! $this->restrict_log )
{
$this->class->append_task_log( $this->task, intval(count($birthdays))." birthdays cached, ".intval(count($calendar))." events cached" );
}
}
/*-------------------------------------------------------------------------*/
// register_class
// LEAVE ALONE
/*-------------------------------------------------------------------------*/
function register_class(&$class)
{
$this->class = $class;
$this->root_path = $this->class->root_path;
}
/*-------------------------------------------------------------------------*/
// pass_task
// LEAVE ALONE
/*-------------------------------------------------------------------------*/
function pass_task( $this_task )
{
$this->task = $this_task;
}
}
?>