Chris@76: 'iCalDownload', Chris@76: 'post' => 'CalendarPost', Chris@76: ); Chris@76: Chris@76: if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]) && !WIRELESS) Chris@76: return $subActions[$_GET['sa']](); Chris@76: Chris@76: // This is gonna be needed... Chris@76: loadTemplate('Calendar'); Chris@76: Chris@76: // You can't do anything if the calendar is off. Chris@76: if (empty($modSettings['cal_enabled'])) Chris@76: fatal_lang_error('calendar_off', false); Chris@76: Chris@76: // Set the page title to mention the calendar ;). Chris@76: $context['page_title'] = $txt['calendar']; Chris@76: Chris@76: // Is this a week view? Chris@76: $context['view_week'] = isset($_GET['viewweek']); Chris@76: Chris@76: // Don't let search engines index weekly calendar pages. Chris@76: if ($context['view_week']) Chris@76: $context['robot_no_index'] = true; Chris@76: Chris@76: // Get the current day of month... Chris@76: require_once($sourcedir . '/Subs-Calendar.php'); Chris@76: $today = getTodayInfo(); Chris@76: Chris@76: // If the month and year are not passed in, use today's date as a starting point. Chris@76: $curPage = array( Chris@76: 'day' => isset($_REQUEST['day']) ? (int) $_REQUEST['day'] : $today['day'], Chris@76: 'month' => isset($_REQUEST['month']) ? (int) $_REQUEST['month'] : $today['month'], Chris@76: 'year' => isset($_REQUEST['year']) ? (int) $_REQUEST['year'] : $today['year'] Chris@76: ); Chris@76: Chris@76: // Make sure the year and month are in valid ranges. Chris@76: if ($curPage['month'] < 1 || $curPage['month'] > 12) Chris@76: fatal_lang_error('invalid_month', false); Chris@76: if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) Chris@76: fatal_lang_error('invalid_year', false); Chris@76: // If we have a day clean that too. Chris@76: if ($context['view_week']) Chris@76: { Chris@76: // Note $isValid is -1 < PHP 5.1 Chris@76: $isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']); Chris@76: if ($curPage['day'] > 31 || !$isValid || $isValid == -1) Chris@76: fatal_lang_error('invalid_day', false); Chris@76: } Chris@76: Chris@76: // Load all the context information needed to show the calendar grid. Chris@76: $calendarOptions = array( Chris@76: 'start_day' => !empty($options['calendar_start_day']) ? $options['calendar_start_day'] : 0, Chris@76: 'show_birthdays' => in_array($modSettings['cal_showbdays'], array(1, 2)), Chris@76: 'show_events' => in_array($modSettings['cal_showevents'], array(1, 2)), Chris@76: 'show_holidays' => in_array($modSettings['cal_showholidays'], array(1, 2)), Chris@76: 'show_week_num' => true, Chris@76: 'short_day_titles' => false, Chris@76: 'show_next_prev' => true, Chris@76: 'show_week_links' => true, Chris@76: 'size' => 'large', Chris@76: ); Chris@76: Chris@76: // Load up the main view. Chris@76: if ($context['view_week']) Chris@76: $context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions); Chris@76: else Chris@76: $context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); Chris@76: Chris@76: // Load up the previous and next months. Chris@76: $calendarOptions['show_birthdays'] = $calendarOptions['show_events'] = $calendarOptions['show_holidays'] = false; Chris@76: $calendarOptions['short_day_titles'] = true; Chris@76: $calendarOptions['show_next_prev'] = false; Chris@76: $calendarOptions['show_week_links'] = false; Chris@76: $calendarOptions['size'] = 'small'; Chris@76: $context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); Chris@76: // Only show previous month if it isn't pre-January of the min-year Chris@76: if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) Chris@76: $context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions); Chris@76: // Only show next month if it isn't post-December of the max-year Chris@76: if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) Chris@76: $context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions); Chris@76: Chris@76: // Basic template stuff. Chris@76: $context['can_post'] = allowedTo('calendar_post'); Chris@76: $context['current_day'] = $curPage['day']; Chris@76: $context['current_month'] = $curPage['month']; Chris@76: $context['current_year'] = $curPage['year']; Chris@76: $context['show_all_birthdays'] = isset($_GET['showbd']); Chris@76: Chris@76: // Set the page title to mention the month or week, too Chris@76: $context['page_title'] .= ' - ' . ($context['view_week'] ? sprintf($txt['calendar_week_title'], $context['calendar_grid_main']['week_number'], ($context['calendar_grid_main']['week_number'] == 53 ? $context['current_year'] - 1 : $context['current_year'])) : $txt['months'][$context['current_month']] . ' ' . $context['current_year']); Chris@76: Chris@76: // Load up the linktree! Chris@76: $context['linktree'][] = array( Chris@76: 'url' => $scripturl . '?action=calendar', Chris@76: 'name' => $txt['calendar'] Chris@76: ); Chris@76: // Add the current month to the linktree. Chris@76: $context['linktree'][] = array( Chris@76: 'url' => $scripturl . '?action=calendar;year=' . $context['current_year'] . ';month=' . $context['current_month'], Chris@76: 'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year'] Chris@76: ); Chris@76: // If applicable, add the current week to the linktree. Chris@76: if ($context['view_week']) Chris@76: $context['linktree'][] = array( Chris@76: 'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'], Chris@76: 'name' => $txt['calendar_week'] . ' ' . $context['calendar_grid_main']['week_number'] Chris@76: ); Chris@76: } Chris@76: Chris@76: function CalendarPost() Chris@76: { Chris@76: global $context, $txt, $user_info, $sourcedir, $scripturl; Chris@76: global $modSettings, $topic, $smcFunc; Chris@76: Chris@76: // Well - can they? Chris@76: isAllowedTo('calendar_post'); Chris@76: Chris@76: // We need this for all kinds of useful functions. Chris@76: require_once($sourcedir . '/Subs-Calendar.php'); Chris@76: Chris@76: // Cast this for safety... Chris@76: if (isset($_REQUEST['eventid'])) Chris@76: $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; Chris@76: Chris@76: // Submitting? Chris@76: if (isset($_POST[$context['session_var']], $_REQUEST['eventid'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Validate the post... Chris@76: if (!isset($_POST['link_to_board'])) Chris@76: validateEventPost(); Chris@76: Chris@76: // If you're not allowed to edit any events, you have to be the poster. Chris@76: if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) Chris@76: isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any')); Chris@76: Chris@76: // New - and directing? Chris@76: if ($_REQUEST['eventid'] == -1 && isset($_POST['link_to_board'])) Chris@76: { Chris@76: $_REQUEST['calendar'] = 1; Chris@76: require_once($sourcedir . '/Post.php'); Chris@76: return Post(); Chris@76: } Chris@76: // New... Chris@76: elseif ($_REQUEST['eventid'] == -1) Chris@76: { Chris@76: $eventOptions = array( Chris@76: 'board' => 0, Chris@76: 'topic' => 0, Chris@76: 'title' => substr($_REQUEST['evtitle'], 0, 60), Chris@76: 'member' => $user_info['id'], Chris@76: 'start_date' => sprintf('%04d-%02d-%02d', $_POST['year'], $_POST['month'], $_POST['day']), Chris@76: 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0, Chris@76: ); Chris@76: insertEvent($eventOptions); Chris@76: } Chris@76: Chris@76: // Deleting... Chris@76: elseif (isset($_REQUEST['deleteevent'])) Chris@76: removeEvent($_REQUEST['eventid']); Chris@76: Chris@76: // ... or just update it? Chris@76: else Chris@76: { Chris@76: $eventOptions = array( Chris@76: 'title' => substr($_REQUEST['evtitle'], 0, 60), Chris@76: 'span' => empty($modSettings['cal_allowspan']) || empty($_POST['span']) || $_POST['span'] == 1 || empty($modSettings['cal_maxspan']) || $_POST['span'] > $modSettings['cal_maxspan'] ? 0 : min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1), Chris@76: 'start_date' => strftime('%Y-%m-%d', mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year'])), Chris@76: ); Chris@76: Chris@76: modifyEvent($_REQUEST['eventid'], $eventOptions); Chris@76: } Chris@76: Chris@76: updateSettings(array( Chris@76: 'calendar_updated' => time(), Chris@76: )); Chris@76: Chris@76: // No point hanging around here now... Chris@76: redirectexit($scripturl . '?action=calendar;month=' . $_POST['month'] . ';year=' . $_POST['year']); Chris@76: } Chris@76: Chris@76: // If we are not enabled... we are not enabled. Chris@76: if (empty($modSettings['cal_allow_unlinked']) && empty($_REQUEST['eventid'])) Chris@76: { Chris@76: $_REQUEST['calendar'] = 1; Chris@76: require_once($sourcedir . '/Post.php'); Chris@76: return Post(); Chris@76: } Chris@76: Chris@76: // New? Chris@76: if (!isset($_REQUEST['eventid'])) Chris@76: { Chris@76: $today = getdate(); Chris@76: Chris@76: $context['event'] = array( Chris@76: 'boards' => array(), Chris@76: 'board' => 0, Chris@76: 'new' => 1, Chris@76: 'eventid' => -1, Chris@76: 'year' => isset($_REQUEST['year']) ? $_REQUEST['year'] : $today['year'], Chris@76: 'month' => isset($_REQUEST['month']) ? $_REQUEST['month'] : $today['mon'], Chris@76: 'day' => isset($_REQUEST['day']) ? $_REQUEST['day'] : $today['mday'], Chris@76: 'title' => '', Chris@76: 'span' => 1, Chris@76: ); Chris@76: $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year'])); Chris@76: Chris@76: // Get list of boards that can be posted in. Chris@76: $boards = boardsAllowedTo('post_new'); Chris@76: if (empty($boards)) Chris@76: fatal_lang_error('cannot_post_new', 'permission'); Chris@76: Chris@76: // Load the list of boards and categories in the context. Chris@76: require_once($sourcedir . '/Subs-MessageIndex.php'); Chris@76: $boardListOptions = array( Chris@76: 'included_boards' => in_array(0, $boards) ? null : $boards, Chris@76: 'not_redirection' => true, Chris@76: 'use_permissions' => true, Chris@76: 'selected_board' => $modSettings['cal_defaultboard'], Chris@76: ); Chris@76: $context['event']['categories'] = getBoardList($boardListOptions); Chris@76: } Chris@76: else Chris@76: { Chris@76: $context['event'] = getEventProperties($_REQUEST['eventid']); Chris@76: Chris@76: if ($context['event'] === false) Chris@76: fatal_lang_error('no_access', false); Chris@76: Chris@76: // If it has a board, then they should be editing it within the topic. Chris@76: if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg'])) Chris@76: { Chris@76: // We load the board up, for a check on the board access rights... Chris@76: $topic = $context['event']['topic']['id']; Chris@76: loadBoard(); Chris@76: } Chris@76: Chris@76: // Make sure the user is allowed to edit this event. Chris@76: if ($context['event']['member'] != $user_info['id']) Chris@76: isAllowedTo('calendar_edit_any'); Chris@76: elseif (!allowedTo('calendar_edit_any')) Chris@76: isAllowedTo('calendar_edit_own'); Chris@76: } Chris@76: Chris@76: // Template, sub template, etc. Chris@76: loadTemplate('Calendar'); Chris@76: $context['sub_template'] = 'event_post'; Chris@76: Chris@76: $context['page_title'] = isset($_REQUEST['eventid']) ? $txt['calendar_edit'] : $txt['calendar_post_event']; Chris@76: $context['linktree'][] = array( Chris@76: 'name' => $context['page_title'], Chris@76: ); Chris@76: } Chris@76: Chris@76: function iCalDownload() Chris@76: { Chris@76: global $smcFunc, $sourcedir, $forum_version, $context, $modSettings; Chris@76: Chris@76: // Goes without saying that this is required. Chris@76: if (!isset($_REQUEST['eventid'])) Chris@76: fatal_lang_error('no_access', false); Chris@76: Chris@76: // This is kinda wanted. Chris@76: require_once($sourcedir . '/Subs-Calendar.php'); Chris@76: Chris@76: // Load up the event in question and check it exists. Chris@76: $event = getEventProperties($_REQUEST['eventid']); Chris@76: Chris@76: if ($event === false) Chris@76: fatal_lang_error('no_access', false); Chris@76: Chris@76: // Check the title isn't too long - iCal requires some formatting if so. Chris@76: $title = str_split($event['title'], 30); Chris@76: foreach ($title as $id => $line) Chris@76: { Chris@76: if ($id != 0) Chris@76: $title[$id] = ' ' . $title[$id]; Chris@76: $title[$id] .= "\n"; Chris@76: } Chris@76: Chris@76: // Format the date. Chris@76: $date = $event['year'] . '-' . ($event['month'] < 10 ? '0' . $event['month'] : $event['month']) . '-' . ($event['day'] < 10 ? '0' . $event['day'] : $event['day']) . 'T'; Chris@76: $date .= '1200:00:00Z'; Chris@76: Chris@76: // This is what we will be sending later. Chris@76: $filecontents = ''; Chris@76: $filecontents .= 'BEGIN:VCALENDAR' . "\n"; Chris@76: $filecontents .= 'VERSION:2.0' . "\n"; Chris@76: $filecontents .= 'PRODID:-//SimpleMachines//SMF ' . (empty($forum_version) ? 1.0 : strtr($forum_version, array('SMF ' => ''))) . '//EN' . "\n"; Chris@76: $filecontents .= 'BEGIN:VEVENT' . "\n"; Chris@76: $filecontents .= 'DTSTART:' . $date . "\n"; Chris@76: $filecontents .= 'DTEND:' . $date . "\n"; Chris@76: $filecontents .= 'SUMMARY:' . implode('', $title); Chris@76: $filecontents .= 'END:VEVENT' . "\n"; Chris@76: $filecontents .= 'END:VCALENDAR'; Chris@76: Chris@76: // Send some standard headers. Chris@76: ob_end_clean(); Chris@76: if (!empty($modSettings['enableCompressedOutput'])) Chris@76: @ob_start('ob_gzhandler'); Chris@76: else Chris@76: ob_start(); Chris@76: Chris@76: // Send the file headers Chris@76: header('Pragma: '); Chris@76: header('Cache-Control: no-cache'); Chris@76: if (!$context['browser']['is_gecko']) Chris@76: header('Content-Transfer-Encoding: binary'); Chris@76: header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); Chris@76: header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT'); Chris@76: header('Accept-Ranges: bytes'); Chris@76: header('Connection: close'); Chris@76: header('Content-Disposition: attachment; filename=' . $event['title'] . '.ics'); Chris@76: Chris@76: // How big is it? Chris@76: if (empty($modSettings['enableCompressedOutput'])) Chris@76: header('Content-Length: ' . $smcFunc['strlen']($filecontents)); Chris@76: Chris@76: // This is a calendar item! Chris@76: header('Content-Type: text/calendar'); Chris@76: Chris@76: // Chuck out the card. Chris@76: echo $filecontents; Chris@76: Chris@76: // Off we pop - lovely! Chris@76: obExit(false); Chris@76: } Chris@76: Chris@76: // This is not the code you are looking for. Chris@76: function clock() Chris@76: { Chris@76: global $settings, $context; Chris@76: $context['onimg'] = $settings['images_url'] . '/bbc/bbc_bg.gif'; Chris@76: $context['offimg'] = $settings['images_url'] . '/bbc/bbc_hoverbg.gif'; Chris@76: Chris@76: $context['page_title'] = 'Anyone know what time it is?'; Chris@76: $context['robot_no_index'] = true; Chris@76: Chris@76: $omfg = isset($_REQUEST['omfg']); Chris@76: $bcd = !isset($_REQUEST['rb']) && !isset($_REQUEST['omfg']) && !isset($_REQUEST['time']); Chris@76: Chris@76: loadTemplate('Calendar'); Chris@76: Chris@76: if ($bcd && !$omfg) Chris@76: { Chris@76: $context['sub_template'] = 'bcd'; Chris@76: $context['clockicons'] = unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ==')); Chris@76: } Chris@76: elseif (!$omfg && !isset($_REQUEST['time'])) Chris@76: { Chris@76: $context['sub_template'] = 'hms'; Chris@76: $context['clockicons'] = unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319')); Chris@76: } Chris@76: elseif ($omfg) Chris@76: { Chris@76: $context['sub_template'] = 'omfg'; Chris@76: $context['clockicons'] = unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ==')); Chris@76: } Chris@76: elseif (isset($_REQUEST['time'])) Chris@76: { Chris@76: $context['sub_template'] = 'thetime'; Chris@76: $time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']); Chris@76: Chris@76: $context['clockicons'] = array( Chris@76: 'year' => array( Chris@76: 64 => false, Chris@76: 32 => false, Chris@76: 16 => false, Chris@76: 8 => false, Chris@76: 4 => false, Chris@76: 2 => false, Chris@76: 1 => false Chris@76: ), Chris@76: 'month' => array( Chris@76: 8 => false, Chris@76: 4 => false, Chris@76: 2 => false, Chris@76: 1 => false Chris@76: ), Chris@76: 'day' => array( Chris@76: 16 => false, Chris@76: 4 => false, Chris@76: 8 => false, Chris@76: 2 => false, Chris@76: 1 => false Chris@76: ), Chris@76: 'hour' => array( Chris@76: 32 => false, Chris@76: 16 => false, Chris@76: 8 => false, Chris@76: 4 => false, Chris@76: 2 => false, Chris@76: 1 => false Chris@76: ), Chris@76: 'min' => array( Chris@76: 32 => false, Chris@76: 16 => false, Chris@76: 8 => false, Chris@76: 4 => false, Chris@76: 2 => false, Chris@76: 1 => false Chris@76: ), Chris@76: 'sec' => array( Chris@76: 32 => false, Chris@76: 16 => false, Chris@76: 8 => false, Chris@76: 4 => false, Chris@76: 2 => false, Chris@76: 1 => false Chris@76: ), Chris@76: ); Chris@76: Chris@76: $year = $time['year'] % 100; Chris@76: $month = $time['mon']; Chris@76: $day = $time['mday']; Chris@76: $hour = $time['hours']; Chris@76: $min = $time['minutes']; Chris@76: $sec = $time['seconds']; Chris@76: Chris@76: foreach ($context['clockicons'] as $t => $vs) Chris@76: foreach ($vs as $v => $dumb) Chris@76: { Chris@76: if ($$t >= $v) Chris@76: { Chris@76: $$t -= $v; Chris@76: $context['clockicons'][$t][$v] = true; Chris@76: } Chris@76: } Chris@76: } Chris@76: } Chris@76: ?>