############################################################## 
## MOD Title:		Topic Calendar - upgrade from beta 1.5 to v 1.0.0
## MOD Author:		Ptirhiik < ptirhiik@clanmckeen.com > (Pierre) http://rpgnet.clanmckeen.com
## MOD Description:
##			Upgrade Topic Calendar from beta 1.5 to v 1.0.0
## MOD Version:		1.0.0
## 
## Installation Level:	Easy
## Installation Time:	15 Minutes
## Files To Edit:
##			calendar_scheduler.php
##			posting.php
##			includes/functions.php
##			includes/functions_calendar.php
##			includes/page_header.php
##			language/lang_english/lang_admin.php
##			language/lang_english/lang_main.php
##			templates/subSilver/calendar_box.tpl
##
## Included Files:
##			lang_extend_topic_calendar.php
##			mod-lang_settings/lang_extend_mac.php
##			mod-mods_settings/lang_extend_mods_settings.php
##
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes: 
## 
############################################################## 
## MOD History: 
## 
##   2003-10-30 - Version 1.0.0
##      - fix a bug on DST date change in scheduler
##	- fix the -1 issue in preview post
##	- cut off softer the message in the overview event window
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################
#
#-----[ COPY ]------------------------------------------------
#
copy lang_extend_topic_calendar.php to language/lang_english/lang_extend_mods_settings.php
copy mod-mods_settings/lang_extend_mods_settings.php to language/lang_english/lang_extend_mods_settings.php
copy mod-lang_settings/lang_extend_mac.php to includes/lang_extend_mac.php
#
#-----[ OPEN ]------------------------------------------------
#
calendar_scheduler.php
#
#-----[ FIND ]------------------------------------------------
#
 *	version				: 1.0.3 - 14/09/2003
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
 *	version				: 1.0.4 - 30/10/2003
#
#-----[ FIND ]------------------------------------------------
#
		$offset = $offset + 86400;
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
		$off_tab = explode('/', date('m/d/Y', $offset));
		$offset = mktime( 0, 0, 0, $off_tab[0], $off_tab[1]+1, $off_tab[2] );
#
#-----[ OPEN ]------------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------------
#
	$topic_calendar_duration = intval($d_day) * 86400 + intval($d_hour) * 3600 + intval($d_min) * 60 -1;
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
	$topic_calendar_duration = intval($d_day) * 86400 + intval($d_hour) * 3600 + intval($d_min) * 60;
#
#-----[ FIND ]------------------------------------------------
#
			$topic_calendar_duration = ( $topic_calendar_duration != $post_data['topic_calendar_duration'] && !$is_auth['auth_cal']) ? $post_data['topic_calendar_duration'] : $topic_calendar_duration;
#
#-----[ AFTER, ADD ]------------------------------------------
#
			if ( !empty($topic_calendar_duration) )
			{
				$topic_calendar_duration--;
			}
#
#-----[ FIND ]------------------------------------------------
#
			$preview_subject .= get_calendar_title($topic_calendar_time, $topic_calendar_duration);
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
			$topic_calendar_duration_preview = $topic_calendar_duration-1;
			if ($topic_calendar_duration_preview < 0)
			{
				$topic_calendar_duration_preview = 0;
			}
			$preview_subject .= get_calendar_title($topic_calendar_time, $topic_calendar_duration_preview);
#
#-----[ OPEN ]------------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : language settings -----------------------------------------------------------------------
//-- mod : mods settings ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	if ( $userdata['user_id'] != ANONYMOUS )
	{
		if ( !empty($userdata['user_lang']))
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : mods settings ---------------------------------------------------------------------------
//-- add
	global $db, $mods, $list_yes_no, $userdata;

	//	get all the mods settings
	$dir = @opendir($phpbb_root_path . 'includes/mods_settings');
	while( $file = @readdir($dir) )
	{
		if( preg_match("/^mod_.*?\." . $phpEx . "$/", $file) )
		{
			include_once($phpbb_root_path . 'includes/mods_settings/' . $file);
		}
	}
	@closedir($dir);
//-- fin mod : mods settings -----------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	//
	// Set up style
	//
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : language settings -----------------------------------------------------------------------
//-- add
	include($phpbb_root_path . './includes/lang_extend_mac.' . $phpEx);
//-- fin mod : language settings -------------------------------------------------------------------

#
#-----[ FIND ]------------------------------------------------
#
		}

		if ( empty($template) )
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : language settings -----------------------------------------------------------------------
//-- add
			include($phpbb_root_path . './includes/lang_extend_mac.' . $phpEx);
//-- fin mod : language settings -------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------------
#
includes/functions_calendar.php
#
#-----[ FIND ]------------------------------------------------
#
 *	version			: 1.1.7 - 15/09/2003
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
 *
 *	version			: 1.1.8 - 30/10/2003
#
#-----[ FIND ]------------------------------------------------
#
// function select
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
// calendar_shorten_text()
function calendar_shorten_text($text, $uid, $max_size)
{
	$wtext = $text;

	// remove [img]*[/img] && [url*]*[/url]
	$wtext = preg_replace("/\[img:$uid\][^\[]*\[\/img:$uid\]/", ' ', $wtext);
	$wtext = preg_replace("/\[url[^\]]*\]/", "[url:$uid]", $wtext);
	$wtext = preg_replace("/\[\/url[^\]]*\]/", "[/url:$uid]", $wtext);
	$wtext = preg_replace("/\[url:$uid\]([^\[]*)\[\/url:$uid\]/", ' \\1 ', $wtext);

	// remove all bbcodes
	$wtext = preg_replace("/\[[^\]]*:$uid\]/", ' ', $wtext);

	// cut the text
	$res = '';
	$offset = 0;
	$cut = false;
	if ( strlen($wtext) > $max_size )
	{
		$cut = true;
		$wtext = substr($wtext, 0, $max_size);
	}
	for ( $i=0; $i < strlen($wtext); $i++ )
	{
		$done = false;
		$tag = substr($text, $offset, 4);
		if ( in_array( $tag, array('[img', '[url') ) || ($text[$offset] == '[') )
		{
			// are we on a bbcode ?
			$close_tag = ":$uid]";
			if ( $tag == '[img' )
			{
				$close_tag = "[/img:$uid]";
			}
			else if ( $tag == '[url' )
			{
				$close_tag = "[/url:$uid]";
				$close_pos = strpos($text, $close_tag, $offset);
				if ( !$close_pos )
				{
					$close_tag = '[/url]';
				}
			}
			$close_pos = strpos($text, $close_tag, $offset);

			$supposed = substr($text, $offset, $close_pos - $offset + strlen($close_tag) );

			// bbcode confirmed
			if ( (strpos($supposed, ":$uid") != 0) || ($close_tag == '[/url]') )
			{
				$res .= $supposed;
				$offset += strlen($supposed);
				$done = true;
			}
		}

		// not a bbCode
		if ( !$done )
		{
			$res .= $text[$offset];
			$offset++;
		}
	}

	// find all bbCode openers
	$openers = array();
	preg_match_all("|(\[[^\/\]].*:$uid\])|U", $res, $openers );

	// find all bbCode closers
	$closers = array();
	preg_match_all("|(\[\/[^\]].*:$uid\])|U", $res, $closers );

	// get the non closed bbcode
	$push = array();
	for ($i = 0; $i < count($openers[1]); $i++)
	{
		$parms = explode('=', $openers[1][$i] );
		if ( count($parms) > 1 )
		{
			$close = '[/' . substr( $parms[0], 1);
			if ( strpos( $parms[ count($parms) - 1 ], $uid ) !== false )
			{
				$close .= ':' . $uid . ']';
			}
		}
		else
		{
			$close = '[/' . substr($openers[1][$i], 1);
		}
		$found = false;
		for ( $j = 0; $j < count($closers[1]); $j++ )
		{
			$found = ($close == $closers[1][$j]);
			if ( $found )
			{
				$closers[1][$i] = '';
				break;
			}
		}
		if ( !$found )
		{
			$push[] = $close;
		}
	}

	// re-add closers in reverse order
	for ( $i = ( count($push)-1 ); $i >= 0; $i-- )
	{
		$res .= $push[$i];
	}

	if ( $cut )
	{
		$res .= '...';
	}

	return $res;
}
#
#-----[ FIND ]------------------------------------------------
#
		$message = substr($message, 0, $topic_text_length);
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
		$message = calendar_shorten_text($message, $row['bbcode_uid'], $topic_text_length);
#
#-----[ OPEN ]------------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]------------------------------------------------
#
include_once($phpbb_root_path . 'includes/mods_settings/mod_calendar.' . $phpEx);

if (!defined('IN_CALENDAR'))
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
if (!defined('IN_CALENDAR'))
#
#-----[ OPEN ]------------------------------------------------
#
# Here we step back to the original file
#
language/lang_english/lang_admin.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
//-- mod : mods settings ---------------------------------------------------------------------------
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
<?php
#
#-----[ FIND ]------------------------------------------------
#
//-- mod : mods settings ---------------------------------------------------------------------------
//-- add
$lang['Configuration_extend']	= 'Configuration +';
$lang['Override_user_choices']	= 'Override user choices';
//-- fin mod : mods settings -----------------------------------------------------------------------
//
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
//
#
#-----[ OPEN ]------------------------------------------------
#
# Here we step back to the original file
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
//-- mod : mods settings ---------------------------------------------------------------------------
//-- mod : calendar --------------------------------------------------------------------------------
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
<?php
#
#-----[ FIND ]------------------------------------------------
#
//-- mod : calendar --------------------------------------------------------------------------------
//-- add
$lang['Calendar']				= 'Calendar';
$lang['Calendar_scheduler']		= 'Scheduler';
$lang['Calendar_event']			= 'Calendar event';
$lang['Calendar_from_to']		= 'From %s to %s (included)';
$lang['Calendar_time']			= '%s';
$lang['Calendar_duration']		= 'During';

$lang['Calendar_settings']		= 'Calendar settings';
$lang['Calendar_week_start']	= 'First day of the week';
$lang['Calendar_header_cells']	= 'Number of cells to display on the board header (0 for no display)';
$lang['Calendar_title_length']	= 'Length of the title displayed in the calendar cells';
$lang['Calendar_text_length']	= 'Length of the text displayed in the overview windows';
$lang['Calendar_display_open']	= 'Display the calendar row on the board header opened';
$lang['Calendar_nb_row']		= 'Number of row per day on the board header';
$lang['Calendar_birthday']		= 'Display birthday in the calendar';
$lang['Calendar_forum']			= 'Display the forum name under the topic title in the scheduler';

$lang['Sorry_auth_cal']			= 'Sorry, but only %s can post calendar events in this forum.';
$lang['Date_error']				= 'day %d, month %d, year %d is not a valid date';

$lang['Event_time']				= 'Event time';
$lang['Minutes']				= 'Minutes';
$lang['Today']					= 'Today';
$lang['All_events']				= 'All events';

$lang['Rules_calendar_can']		= 'You <b>can</b> post calendar events in this forum';
$lang['Rules_calendar_cannot']	= 'You <b>cannot</b> post calendar events in this forum';
//-- fin mod : calendar ----------------------------------------------------------------------------
//
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
//
#
#-----[ OPEN ]------------------------------------------------
#
# Here we replaced the blank char with tabulation, and rework very slightly the javascript code
#
templates/subSilver/calendar_box.tpl
#
#-----[ FIND ]------------------------------------------------
#
function createTitle(which, string, x, y) 
{
    // record the original first child (protection when deleting)
    if (typeof(originalFirstChild) == 'undefined') 
	{
        originalFirstChild = document.body.firstChild;
    }

    x = document.all ? (event.clientX + document.body.scrollLeft) : x;
    y = document.all ? (event.clientY + document.body.scrollTop) : y;
    element = document.createElement('div');
    element.style.position = 'absolute';
    element.style.zIndex = 1000;
    element.style.visibility = 'hidden';
    if (document.all) 
	{
        element.style.width = '200px';
        excessWidth = 50;
        excessHeight = 20;
    }
    else 
	{
        excessWidth = 0; 
        excessHeight = 20;
    }
    element.innerHTML = '<div class="bodyline"><table width="300" cellspacing="0" cellpadding="0" border="0"><tr><td><table width="100%"><tr><td><span class="gen">' + string + '</span></td></tr></table></td></tr></table></div>';
    renderedElement = document.body.insertBefore(element, document.body.firstChild);
    renderedWidth = renderedElement.offsetWidth;
    renderedHeight = renderedElement.offsetHeight;
    // fix overflowing off the right side of the screen
    overFlowX = x + renderedWidth + excessWidth - document.body.offsetWidth;
    x = overFlowX > 0 ? x - overFlowX : x;
    // fix overflowing off the bottom of the screen
    overFlowY = y + renderedHeight + excessHeight - window.innerHeight - window.pageYOffset;
    y = overFlowY > 0 ? y - overFlowY : y;
    renderedElement.style.top = (y + 15) + 'px';
    renderedElement.style.left = (x + 15) + 'px';
    // windows versions of mozilla are like too fast here...we have to slow it down
    if (agt.indexOf('gecko') != -1 && agt.indexOf('win') != -1) 
	{
        setTimeout("renderedElement.style.visibility = 'visible'", 1);
    }
    else 
	{
        renderedElement.style.visibility = 'visible';
    }
}

function destroyTitle() 
{
    // make sure we don't delete the actual page contents (javascript can get out of alignment)
    if (document.body.firstChild != originalFirstChild) 
	{
        document.body.removeChild(document.body.firstChild);
    }
}
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
function createTitle(which, string, x, y) 
{
	// record the original first child (protection when deleting)
	if (typeof(originalFirstChild) == 'undefined') 
	{
		originalFirstChild = document.body.firstChild;
	}

	x = document.all ? (event.clientX + document.body.scrollLeft) : x;
	y = document.all ? (event.clientY + document.body.scrollTop) : y;
	element = document.createElement('div');
	element.style.position = 'absolute';
	element.style.zIndex = 1000;
	element.style.visibility = 'hidden';
	excessWidth = 0;
	if (document.all) 
	{
		excessWidth = 50;
	}
	excessHeight = 20;
	element.innerHTML = '<div class="bodyline"><table width="300" cellspacing="0" cellpadding="0" border="0"><tr><td><table width="100%"><tr><td><span class="gen">' + string + '</span></td></tr></table></td></tr></table></div>';
	renderedElement = document.body.insertBefore(element, document.body.firstChild);
	renderedWidth = renderedElement.offsetWidth;
	renderedHeight = renderedElement.offsetHeight;

	// fix overflowing off the right side of the screen
	overFlowX = x + renderedWidth + excessWidth - document.body.offsetWidth;
	x = overFlowX > 0 ? x - overFlowX : x;

	// fix overflowing off the bottom of the screen
	overFlowY = y + renderedHeight + excessHeight - window.innerHeight - window.pageYOffset;
	y = overFlowY > 0 ? y - overFlowY : y;

	renderedElement.style.top = (y + 15) + 'px';
	renderedElement.style.left = (x + 15) + 'px';

	// windows versions of mozilla are like too fast here...we have to slow it down
	if (agt.indexOf('gecko') != -1 && agt.indexOf('win') != -1) 
	{
		setTimeout("renderedElement.style.visibility = 'visible'", 1);
	}
	else 
	{
		renderedElement.style.visibility = 'visible';
	}
}

function destroyTitle() 
{
	// make sure we don't delete the actual page contents (javascript can get out of alignment)
	if (document.body.firstChild != originalFirstChild) 
	{
		document.body.removeChild(document.body.firstChild);
	}
}
#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------------
#
# EoM