Beispiel #1
0
                 $userday = explode('-', $userinfo['birthday']);
                 if ($year > $userday[2] and $userday[2] != '0000' and $userinfo['showbirthday'] == 2) {
                     $age = '(' . ($year - $userday[2]) . ')';
                     $show['age'] = true;
                 } else {
                     unset($age);
                     $show['age'] = false;
                 }
                 $templater = vB_Template::create('calendar_showbirthdays');
                 $templater->register('age', $age);
                 $templater->register('userinfo', $userinfo);
                 $userbdays .= $templater->render();
                 $show['birthdays'] = true;
             }
         }
         $eventarray = cache_events_day($month, $day, $year);
     }
 }
 if (!empty($eventarray)) {
     $customcalfields = $db->query_read_slave("\n\t\t\tSELECT calendarcustomfieldid, title, options, allowentry, description\n\t\t\tFROM " . TABLE_PREFIX . "calendarcustomfield AS calendarcustomfield\n\t\t\tWHERE calendarid = {$calendarinfo['calendarid']}\n\t\t\tORDER BY calendarcustomfieldid\n\t\t");
     $customfieldssql = array();
     while ($custom = $db->fetch_array($customcalfields)) {
         $customfieldssql[] = $custom;
     }
 }
 $show['canmoveevent'] = can_moderate_calendar($calendarinfo['calendarid'], 'canmoveevents');
 $show['candeleteevent'] = can_moderate_calendar($calendarinfo['calendarid'], 'candeleteevents');
 require_once DIR . '/includes/functions_misc.php';
 // mainly for fetch_timezone
 require_once DIR . '/includes/functions_user.php';
 // to fetch user avatar
function construct_calendar_output($today, $usertoday, $calendarinfo, $fullcalendar = 0, $weekrange = '')
{
    global $birthdaycache, $eventcache, $vbulletin, $vbphrase, $stylevar, $show, $colspan, $days, $months;
    $calendarid = $calendarinfo['calendarid'];
    $month = $usertoday['month'];
    $year = $usertoday['year'];
    $calendardaybits = '';
    $calendarweekbits = '';
    if ($calendarinfo['showweekends']) {
        $weeklength = 7;
        $colspan = 8;
        $daywidth = '14%';
        $linkwidth = '2%';
    } else {
        $weeklength = 5;
        $colspan = 6;
        $daywidth = '19%';
        $linkwidth = '5%';
    }
    // set up the controls for this month
    $displaymonth['starttime'] = gmmktime(12, 0, 0, $month, 1, $year);
    $displaymonth['numdays'] = gmdate('t', $displaymonth['starttime']);
    $displaymonth['month'] = gmdate('n', $displaymonth['starttime']);
    $displaymonth['year'] = gmdate('Y', $displaymonth['starttime']);
    $todaylink = "{$today['year']}-{$today['mon']}-{$today['mday']}";
    // get an array of days starting with the user's chosen week start
    static $userweek;
    if (!is_array($userweek)) {
        $userweek = array();
        $curday = $vbulletin->userinfo['startofweek'];
        while (sizeof($userweek) < $weeklength) {
            if (!$calendarinfo['showweekends'] and ($curday == 1 or $curday == 7)) {
                $curday++;
            } else {
                $userweek[] = $curday++;
            }
            if ($curday > 7) {
                $curday = 1;
            }
        }
    }
    // wind back the start day so we have the days preceeding the current month that will be displayed
    $startday = 1;
    while ($null++ < 31) {
        if (gmdate('w', gmmktime(0, 0, 0, $displaymonth['month'], $startday, $displaymonth['year'])) + 1 == $userweek[0]) {
            break;
        } else {
            $startday--;
        }
    }
    if ($fullcalendar) {
        $template = array('day' => 'calendar_monthly_day', 'day_other' => 'calendar_monthly_day_other', 'week' => 'calendar_monthly_week', 'header' => 'calendar_monthly_header');
    } else {
        if ($startday == 1 and $show['yearlyview']) {
            // wind back the start day by a week so we always end up with 6 rows for neatness
            $startday -= 7;
        }
        $template = array('day' => 'calendar_smallmonth_day', 'day_other' => 'calendar_smallmonth_day_other', 'week' => 'calendar_smallmonth_week', 'header' => 'calendar_smallmonth_header');
    }
    // fetch special holiday events
    $eastercache = fetch_easter_array($usertoday['year']);
    if (!$fullcalendar) {
        // set up which days will be shown
        for ($i = 0; $i < 7; $i++) {
            $dayvarname = 'day' . ($i + 1);
            if ($userweek["{$i}"]) {
                ${$dayvarname} = $vbphrase[$days[$userweek[$i]] . '_short'];
                $show["{$dayvarname}"] = true;
            } else {
                $show["{$dayvarname}"] = false;
            }
        }
    }
    // now start creating the week rows
    $rows = 0;
    while (++$rows <= 6) {
        if (!$show['yearlyview'] and $startday > $displaymonth['numdays']) {
            break;
        }
        // run through the user's week days
        $calendardaybits = '';
        foreach ($userweek as $daycount => $curday) {
            $datestamp = gmmktime(0, 0, 0, $displaymonth['month'], $startday++, $displaymonth['year']);
            $dayname = $vbphrase["{$days[$curday]}_abbr"];
            $year = gmdate('Y', $datestamp);
            $month = gmdate('n', $datestamp);
            $day = gmdate('j', $datestamp);
            $daylink = "{$year}-{$month}-{$day}";
            if (!$daycount) {
                $firstweek = gmmktime(0, 0, 0, $month, $day, $year);
            }
            // is this day today?
            $show['highlighttoday'] = iif($daylink == $todaylink, true, false);
            // is this day in our desired month?
            if ($month != $displaymonth['month']) {
                $daytemplatename =& $template['day_other'];
            } else {
                $daytemplatename =& $template['day'];
                // is this day in our desired week?
                if (!$fullcalendar) {
                    if (is_array($weekrange) and $datestamp >= $weekrange['start'] and $datestamp <= $weekrange['end']) {
                        $show['highlightweek'] = true;
                    } else {
                        $show['highlightweek'] = false;
                    }
                }
                $show['birthdaylink'] = false;
                $show['daylink'] = false;
                $show['holiday'] = false;
                $showholiday = false;
                $show['eventlink'] = false;
                $userbdays = '';
                $userevents = '';
                $eventdesc = '';
                $eventtotal = 0;
                // get this day's birthdays
                if ($calendarinfo['showbirthdays'] and $fullcalendar and is_array($birthdaycache["{$month}"]["{$day}"])) {
                    unset($userday);
                    unset($age);
                    unset($birthdaydesc);
                    $bdaycount = 0;
                    foreach ($birthdaycache["{$month}"]["{$day}"] as $index => $value) {
                        $userday = explode('-', $value['birthday']);
                        $bdaycount++;
                        $username = $value['username'];
                        $userid = $value['userid'];
                        if ($year > $userday[2] and $userday[2] != '0000' and $value['showbirthday'] == 2) {
                            $age = '(' . ($year - $userday[2]) . ')';
                        } else {
                            unset($age);
                        }
                        $birthdaydesc .= iif($birthdaydesc, ', ') . $value['username'];
                        eval('$userbdays .= "' . fetch_template('calendar_monthly_birthday') . '";');
                    }
                    if ($bdaycount > $calendarinfo['birthdaycount']) {
                        $show['birthdaylink'] = true;
                    }
                }
                // get this day's holidays
                if (!empty($eastercache["{$month}-{$day}-{$year}"])) {
                    $eventtotal++;
                    $event['title'] =& $eastercache["{$month}-{$day}-{$year}"]['title'];
                    $event['preview'] = htmlspecialchars_uni(fetch_trimmed_title($eastercache["{$month}-{$day}-{$year}"]['event'], 300));
                    $show['daylink'] = true;
                    $eventdesc .= iif($eventdesc, "\r\n") . $event['title'];
                    if ($fullcalendar) {
                        $show['holiday'] = true;
                        $showholiday = true;
                        ($hook = vBulletinHook::fetch_hook('calendar_displaymonth_event')) ? eval($hook) : false;
                        eval('$userevents .= "' . fetch_template('calendar_monthly_event') . '";');
                    }
                }
                // get this day's events
                if (is_array($eventcache)) {
                    $eventarray = cache_events_day($month, $day, $year);
                    foreach ($eventarray as $index => $event) {
                        $eventtotal++;
                        $show['daylink'] = true;
                        $eventdesc .= iif($eventdesc, "\r\n") . htmlspecialchars_uni($event['title']);
                        if ($fullcalendar) {
                            $eventid = $event['eventid'];
                            $show['holiday'] = iif($event['holidayid'], true, false);
                            if ($show['holiday']) {
                                $showholiday = true;
                            }
                            $show['subscribed'] = iif($event['subscribed'], true, false);
                            if ($calendarinfo['cutoff'] and strlen($event['title']) > $calendarinfo['cutoff'] and !$event['holidayid']) {
                                $event['title'] = substr($event['title'], 0, $calendarinfo['cutoff']) . ' (...)';
                            }
                            $event['title'] = htmlspecialchars_uni($event['title']);
                            ($hook = vBulletinHook::fetch_hook('calendar_displaymonth_event')) ? eval($hook) : false;
                            eval('$userevents .= "' . fetch_template('calendar_monthly_event') . '";');
                        }
                    }
                    if ($eventtotal > $calendarinfo['eventcount']) {
                        $show['eventlink'] = true;
                    }
                }
            }
            $show['holiday'] = $showholiday;
            ($hook = vBulletinHook::fetch_hook('calendar_displaymonth_daybit')) ? eval($hook) : false;
            eval('$calendardaybits .= "' . fetch_template($daytemplatename) . '";');
            // if no weekends, bump on the counter to compensate
            if (!$calendarinfo['showweekends'] and $daycount >= 4) {
                $startday += 2;
            }
        }
        ($hook = vBulletinHook::fetch_hook('calendar_displaymonth_weekbit')) ? eval($hook) : false;
        eval('$calendarrowbits .= "' . fetch_template($template['week']) . '";');
    }
    $year = $displaymonth['year'];
    $month = $displaymonth['month'];
    $monthname = $vbphrase["{$months[$month]}"];
    ($hook = vBulletinHook::fetch_hook('calendar_displaymonth_month')) ? eval($hook) : false;
    eval('$calendarrowbits = "' . fetch_template($template['header']) . '";');
    return $calendarrowbits;
}
Beispiel #3
0
function construct_calendar_output($today, $usertoday, $calendarinfo, $fullcalendar = 0,
		$weekrange = '', $thismonth_only = false)
{
	global $birthdaycache, $eventcache, $vbulletin, $vbphrase, $show, $colspan, $days, $months;

	$calendarid = $calendarinfo['calendarid'];
	$month = $usertoday['month'];
	$year = $usertoday['year'];

	$calendardaybits = '';
	$calendarweekbits = '';

	if ($calendarinfo['showweekends'])
	{
		$weeklength = 7;
		$colspan = 8;
		$daywidth = '14%';
		$linkwidth = '2%';
	}
	else
	{
		$weeklength = 5;
		$colspan = 6;
		$daywidth = '19%';
		$linkwidth = '5%';
	}

	// set up the controls for this month
	$displaymonth['starttime'] = gmmktime(12, 0, 0, $month, 1, $year);
	$displaymonth['numdays'] = gmdate('t', $displaymonth['starttime']);
	$displaymonth['month'] = gmdate('n', $displaymonth['starttime']);
	$displaymonth['year'] = gmdate('Y', $displaymonth['starttime']);
	$todaylink = "$today[year]-$today[mon]-$today[mday]";
	// get an array of days starting with the user's chosen week start
	static $userweek;
	if (!is_array($userweek))
	{
		$userweek = array();
		$curday = $vbulletin->userinfo['startofweek'];
		while (sizeof($userweek) < $weeklength)
		{
			if (!$calendarinfo['showweekends'] AND ($curday == 1 OR $curday == 7))
			{
				$curday++;
			}
			else
			{
				$userweek[] = $curday++;
			}
			if ($curday > 7)
			{
				$curday = 1;
			}
		}
	}

	// wind back the start day so we have the days preceeding the current month that will be displayed
	$startday = 1;
	while ($null++ < 31)
	{
		if ((gmdate('w', gmmktime(0, 0, 0, $displaymonth['month'], $startday, $displaymonth['year'])) + 1) == $userweek[0])
		{
			break;
		}
		else
		{
			$startday--;
		}
	}

	if ($fullcalendar)
	{
		$template = array(
			'day'       => 'calendar_monthly_day',
			'day_other' => 'calendar_monthly_day_other',
			'week'      => 'calendar_monthly_week',
			'header'    => 'calendar_monthly_header'
		);
	}
	else
	{
		if ($startday == 1 AND $show['yearlyview'])
		{
			// wind back the start day by a week so we always end up with 6 rows for neatness
			$startday -= 7;
		}
		$template = array(
			'day'       => 'calendar_smallmonth_day',
			'day_other' => 'calendar_smallmonth_day_other',
			'week'      => 'calendar_smallmonth_week',
			'header'    => 'calendar_smallmonth_header'
		);
	}

	// fetch special holiday events
	$eastercache = fetch_easter_array($usertoday['year']);

	// set up which days will be shown
	for ($i = 0; $i < 7; $i++)
	{
		$dayvarname = 'day' . ($i + 1);
		if ($userweek["$i"])
		{
			${$dayvarname} = array(
				'full'  => $vbphrase[ $days [ $userweek[$i] ] ],
				'short' => $vbphrase[ $days[ $userweek[$i] ] . '_short']
			);
			$show["$dayvarname"] = true;
		}
		else
		{
			$show["$dayvarname"] = false;
		}
	}


	// now start creating the week rows
	$rows = 0;
	while (++$rows <= 6)
	{
		if (!$show['yearlyview'] AND $startday > $displaymonth['numdays'])
		{
			break;
		}

		// run through the user's week days
		$calendardaybits = '';
		foreach ($userweek AS $daycount => $curday)
		{
				
			$datestamp = gmmktime(0, 0, 0, $displaymonth['month'], $startday++, $displaymonth['year']);
			$dayname = $vbphrase["$days[$curday]_abbr"];
			$year = gmdate('Y', $datestamp);
			$month = gmdate('n', $datestamp);
			$day = gmdate('j', $datestamp);
			$daylink = "$year-$month-$day";
			

			if (!$daycount)
			{
				$firstweek = gmmktime(0, 0, 0, $month, $day, $year);
			}

			// is this day today?
			$show['highlighttoday'] = iif($daylink == $todaylink, true, false);

			// is this day in our desired month?
			if ($month != $displaymonth['month'])
			{
				$daytemplatename =& $template['day_other'];
			}
			else
			{
				$daytemplatename =& $template['day'];

				// is this day in our desired week?
				if (!$fullcalendar)
				{
					if (is_array($weekrange) AND $datestamp >= $weekrange['start'] AND $datestamp <= $weekrange['end'])
					{
						$show['highlightweek'] = true;
					}
					else
					{
						$show['highlightweek'] = false;
					}
				}

				$show['birthdaylink'] = false;
				$show['daylink'] = false;
				$show['holiday'] = false;
				$showholiday = false;
				$show['eventlink'] = false;
				$userbdays = '';
				$userevents = '';
				$eventdesc = '';
				$eventtotal = 0;

				// get this day's birthdays
				if ($calendarinfo['showbirthdays'] AND $fullcalendar AND is_array($birthdaycache["$month"]["$day"]))
				{
					unset($userday);
					unset($age);
					unset($birthdaydesc);
					$bdaycount = 0;
					foreach ($birthdaycache["$month"]["$day"] AS $index => $userinfo)
					{
						$userday = explode('-', $userinfo['birthday']);
						$bdaycount++;
						if ($year > $userday[2] AND $userday[2] != '0000' AND $userinfo['showbirthday'] == 2)
						{
							$age = '(' . ($year - $userday[2]) . ')';
						}
						else
						{
							unset($age);
						}
						$birthdaydesc .= iif($birthdaydesc, ', ') . $userinfo['username'];
						$templater = vB_Template::create('calendar_monthly_birthday');
							$templater->register('age', $age);
							$templater->register('userinfo', $userinfo);
						$userbdays .= $templater->render();
					}
					if ($bdaycount > $calendarinfo['birthdaycount'])
					{
						$show['birthdaylink'] = true;
					}
				}

				// get this day's holidays
				if (!empty($eastercache["$month-$day-$year"]))
				{
					$eventtotal++;
					$event['title'] =& $eastercache["$month-$day-$year"]['title'];
					$event['preview'] = htmlspecialchars_uni(fetch_trimmed_title($eastercache["$month-$day-$year"]['event'], 300));
					$show['daylink'] = true;

					$eventdesc .= iif($eventdesc, "\r\n") .	$event['title'];
					if ($fullcalendar)
					{
						$show['holiday'] = true;
						$showholiday = true;

						($hook = vBulletinHook::fetch_hook('calendar_displaymonth_event')) ? eval($hook) : false;

						$templater = vB_Template::create('calendar_monthly_event');
							$templater->register('calendarid', $calendarid);
							$templater->register('day', $day);
							$templater->register('event', $event);
							$templater->register('month', $month);
							$templater->register('year', $year);
						$userevents .= $templater->render();
					}
				}

				// get this day's events
				if (is_array($eventcache))
				{
					$eventarray = cache_events_day($month, $day, $year);

					foreach($eventarray AS $index => $event)
					{
						$eventtotal++;
						$show['daylink'] = true;
						$eventdesc .= iif($eventdesc, "\r\n") .	htmlspecialchars_uni($event['title']);
						if ($fullcalendar)
						{
							$eventid = $event['eventid'];
							$show['holiday'] = iif($event['holidayid'], true, false);
							if ($show['holiday'])
							{
								$showholiday = true;
							}
							$show['subscribed'] = iif($event['subscribed'], true, false);
							if ($calendarinfo['cutoff'] AND strlen($event['title']) > $calendarinfo['cutoff'] AND !$event['holidayid'])
							{
								$event['title'] = substr($event['title'], 0, $calendarinfo['cutoff']) . ' (...)';
							}
							$event['title'] =  htmlspecialchars_uni($event['title']);

							($hook = vBulletinHook::fetch_hook('calendar_displaymonth_event')) ? eval($hook) : false;

							$templater = vB_Template::create('calendar_monthly_event');
								$templater->register('calendarid', $calendarid);
								$templater->register('day', $day);
								$templater->register('event', $event);
								$templater->register('month', $month);
								$templater->register('year', $year);
							$userevents .= $templater->render();
						}
					}
					if ($eventtotal > $calendarinfo['eventcount'])
					{
						$show['eventlink'] = true;
					}
				}
			}

			$show['holiday'] = $showholiday;
			$show['weeklink'] = ($daycount == 0);
			($hook = vBulletinHook::fetch_hook('calendar_displaymonth_daybit')) ? eval($hook) : false;

			//Hide this if set to only show links for this month
			if ($thismonth_only AND ($month !=  $usertoday['month']))
			{
				$show['daylink'] = false;
				$daytemplatename = $template['day'];
			}

			
			$templater = vB_Template::create($daytemplatename);
				$templater->register('bdaycount', $bdaycount);
				$templater->register('birthdaydesc', $birthdaydesc);
				$templater->register('calendarid', $calendarid);
				$templater->register('day', $day);
				$templater->register('dayname', $dayname);
				$templater->register('daywidth', $daywidth);
				$templater->register('eventdesc', $eventdesc);
				$templater->register('eventtotal', $eventtotal);
				$templater->register('month', $month);
				$templater->register('otherday', $otherday);
				$templater->register('otherdayname', $otherdayname);
				$templater->register('userbdays', $userbdays);
				$templater->register('userevents', $userevents);
				$templater->register('year', $year);
				$templater->register('firstweek', $firstweek);
			$calendardaybits .= $templater->render();

			// if no weekends, bump on the counter to compensate
			if (!$calendarinfo['showweekends'] AND $daycount >= 4)
			{
				$startday += 2;
			}
		}

		($hook = vBulletinHook::fetch_hook('calendar_displaymonth_weekbit')) ? eval($hook) : false;

		$templater = vB_Template::create($template['week']);
			$templater->register('calendardaybits', $calendardaybits);
			$templater->register('calendarid', $calendarid);
			$templater->register('firstweek', $firstweek);
			$templater->register('linkwidth', $linkwidth);
			$templater->register('month', $month);
		$calendarrowbits .= $templater->render();
	}

	$year = $displaymonth['year'];
	$month = $displaymonth['month'];
	$monthname = $vbphrase["$months[$month]"];

	($hook = vBulletinHook::fetch_hook('calendar_displaymonth_month')) ? eval($hook) : false;

	$templater = vB_Template::create($template['header']);
		$templater->register('calendarid', $calendarid);
		$templater->register('calendarrowbits', $calendarrowbits);
		$templater->register('colspan', $colspan);
		$templater->register('day1', $day1);
		$templater->register('day2', $day2);
		$templater->register('day3', $day3);
		$templater->register('day4', $day4);
		$templater->register('day5', $day5);
		$templater->register('day6', $day6);
		$templater->register('day7', $day7);
		$templater->register('month', $month);
		$templater->register('monthname', $monthname);
		$templater->register('year', $year);
	return $templater->render();
}