Calendar.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. /**
  3. * This file has only one real task, showing the calendar.
  4. * Original module by Aaron O'Neil - [email protected]
  5. *
  6. * Simple Machines Forum (SMF)
  7. *
  8. * @package SMF
  9. * @author Simple Machines http://www.simplemachines.org
  10. * @copyright 2014 Simple Machines and individual contributors
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version 2.1 Alpha 1
  14. */
  15. if (!defined('SMF'))
  16. die('No direct access...');
  17. /**
  18. * Show the calendar.
  19. * It loads the specified month's events, holidays, and birthdays.
  20. * It requires the calendar_view permission.
  21. * It depends on the cal_enabled setting, and many of the other cal_ settings.
  22. * It uses the calendar_start_day theme option. (Monday/Sunday)
  23. * It uses the main sub template in the Calendar template.
  24. * It goes to the month and year passed in 'month' and 'year' by get or post.
  25. * It is accessed through ?action=calendar.
  26. */
  27. function CalendarMain()
  28. {
  29. global $txt, $context, $modSettings, $scripturl, $options, $sourcedir, $user_info, $smcFunc;
  30. // Permissions, permissions, permissions.
  31. isAllowedTo('calendar_view');
  32. // Some global template resources.
  33. $context['calendar_resources'] = array(
  34. 'min_year' => $modSettings['cal_minyear'],
  35. 'max_year' => $modSettings['cal_maxyear'],
  36. );
  37. // Doing something other than calendar viewing?
  38. $subActions = array(
  39. 'ical' => 'iCalDownload',
  40. 'post' => 'CalendarPost',
  41. );
  42. if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]) && !WIRELESS)
  43. return $subActions[$_GET['sa']]();
  44. // You can't do anything if the calendar is off.
  45. if (empty($modSettings['cal_enabled']))
  46. fatal_lang_error('calendar_off', false);
  47. // This is gonna be needed...
  48. loadTemplate('Calendar');
  49. loadCSSFile('calendar.css', array('force_current' => false, 'validate' => true, 'rtl' => 'calendar.rtl.css'));
  50. // Did the specify an individual event ID? If so, let's splice the year/month in to what we would otherwise be doing.
  51. if (isset($_GET['event']))
  52. {
  53. $evid = (int) $_GET['event'];
  54. if ($evid > 0)
  55. {
  56. $request = $smcFunc['db_query']('', '
  57. SELECT start_date
  58. FROM {db_prefix}calendar
  59. WHERE id_event = {int:event_id}',
  60. array(
  61. 'event_id' => $evid,
  62. )
  63. );
  64. if ($row = $smcFunc['db_fetch_assoc']($request))
  65. {
  66. // We know the format is going to be in yyyy-mm-dd from the database, so let's run with that.
  67. list($_REQUEST['year'], $_REQUEST['month']) = explode('-', $row['start_date']);
  68. $_REQUEST['year'] = (int) $_REQUEST['year'];
  69. $_REQUEST['month'] = (int) $_REQUEST['month'];
  70. // And we definitely don't want weekly view.
  71. unset ($_GET['viewweek']);
  72. // We might use this later.
  73. $context['selected_event'] = $evid;
  74. }
  75. $smcFunc['db_free_result']($request);
  76. }
  77. unset ($_GET['event']);
  78. }
  79. // Set the page title to mention the calendar ;).
  80. $context['page_title'] = $txt['calendar'];
  81. // Is this a week view?
  82. $context['view_week'] = isset($_GET['viewweek']);
  83. // Don't let search engines index weekly calendar pages.
  84. if ($context['view_week'])
  85. $context['robot_no_index'] = true;
  86. // Get the current day of month...
  87. require_once($sourcedir . '/Subs-Calendar.php');
  88. $today = getTodayInfo();
  89. // If the month and year are not passed in, use today's date as a starting point.
  90. $curPage = array(
  91. 'day' => isset($_REQUEST['day']) ? (int) $_REQUEST['day'] : $today['day'],
  92. 'month' => isset($_REQUEST['month']) ? (int) $_REQUEST['month'] : $today['month'],
  93. 'year' => isset($_REQUEST['year']) ? (int) $_REQUEST['year'] : $today['year']
  94. );
  95. // Make sure the year and month are in valid ranges.
  96. if ($curPage['month'] < 1 || $curPage['month'] > 12)
  97. fatal_lang_error('invalid_month', false);
  98. if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
  99. fatal_lang_error('invalid_year', false);
  100. // If we have a day clean that too.
  101. if ($context['view_week'])
  102. {
  103. // Note $isValid is -1 < PHP 5.1
  104. $isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
  105. if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
  106. fatal_lang_error('invalid_day', false);
  107. }
  108. // Load all the context information needed to show the calendar grid.
  109. $calendarOptions = array(
  110. 'start_day' => !empty($options['calendar_start_day']) ? $options['calendar_start_day'] : 0,
  111. 'show_birthdays' => in_array($modSettings['cal_showbdays'], array(1, 2)),
  112. 'show_events' => in_array($modSettings['cal_showevents'], array(1, 2)),
  113. 'show_holidays' => in_array($modSettings['cal_showholidays'], array(1, 2)),
  114. 'highlight' => array(
  115. 'events' => isset($modSettings['cal_highlight_events']) ? $modSettings['cal_highlight_events'] : 0,
  116. 'holidays' => isset($modSettings['cal_highlight_holidays']) ? $modSettings['cal_highlight_holidays'] : 0,
  117. 'birthdays' => isset($modSettings['cal_highlight_birthdays']) ? $modSettings['cal_highlight_birthdays'] : 0,
  118. ),
  119. 'show_week_num' => true,
  120. 'short_day_titles' => !empty($modSettings['cal_short_days']),
  121. 'short_month_titles' => !empty($modSettings['cal_short_months']),
  122. 'show_next_prev' => !empty($modSettings['cal_prev_next_links']),
  123. 'show_week_links' => isset($modSettings['cal_week_links']) ? $modSettings['cal_week_links'] : 0,
  124. );
  125. // Load up the main view.
  126. if ($context['view_week'])
  127. $context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
  128. else
  129. $context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
  130. // Load up the previous and next months.
  131. $context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
  132. // Only show previous month if it isn't pre-January of the min-year
  133. if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
  134. $context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
  135. // Only show next month if it isn't post-December of the max-year
  136. if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
  137. $context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
  138. // Basic template stuff.
  139. $context['allow_calendar_event'] = allowedTo('calendar_post');
  140. // If you don't allow events not linked to posts and you're not an admin, we have more work to do...
  141. if ($context['allow_calendar_event'] && empty($modSettings['cal_allow_unlinked']) && !$user_info['is_admin'])
  142. {
  143. $boards_can_post = boardsAllowedTo('post_new');
  144. $context['allow_calendar_event'] &= !empty($boards_can_post);
  145. }
  146. $context['can_post'] = $context['allow_calendar_event'];
  147. $context['current_day'] = $curPage['day'];
  148. $context['current_month'] = $curPage['month'];
  149. $context['current_year'] = $curPage['year'];
  150. $context['show_all_birthdays'] = isset($_GET['showbd']);
  151. $context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0;
  152. // Set the page title to mention the month or week, too
  153. $context['page_title'] .= ' - ' . ($context['view_week'] ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
  154. // Load up the linktree!
  155. $context['linktree'][] = array(
  156. 'url' => $scripturl . '?action=calendar',
  157. 'name' => $txt['calendar']
  158. );
  159. // Add the current month to the linktree.
  160. $context['linktree'][] = array(
  161. 'url' => $scripturl . '?action=calendar;year=' . $context['current_year'] . ';month=' . $context['current_month'],
  162. 'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
  163. );
  164. // If applicable, add the current week to the linktree.
  165. if ($context['view_week'])
  166. $context['linktree'][] = array(
  167. 'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
  168. 'name' => $context['calendar_grid_main']['week_title'],
  169. );
  170. // Build the calendar button array.
  171. $context['calendar_buttons'] = array(
  172. 'post_event' => array('test' => 'can_post', 'text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'lang' => true, 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  173. );
  174. // Allow mods to add additional buttons here
  175. call_integration_hook('integrate_calendar_buttons');
  176. }
  177. /**
  178. * This function processes posting/editing/deleting a calendar event.
  179. *
  180. * - calls {@link Post.php|Post() Post()} function if event is linked to a post.
  181. * - calls {@link Subs-Calendar.php|insertEvent() insertEvent()} to insert the event if not linked to post.
  182. *
  183. * It requires the calendar_post permission to use.
  184. * It uses the event_post sub template in the Calendar template.
  185. * It is accessed with ?action=calendar;sa=post.
  186. */
  187. function CalendarPost()
  188. {
  189. global $context, $txt, $user_info, $sourcedir, $scripturl;
  190. global $modSettings, $topic, $smcFunc;
  191. // Well - can they?
  192. isAllowedTo('calendar_post');
  193. // We need this for all kinds of useful functions.
  194. require_once($sourcedir . '/Subs-Calendar.php');
  195. // Cast this for safety...
  196. if (isset($_REQUEST['eventid']))
  197. $_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
  198. // Submitting?
  199. if (isset($_POST[$context['session_var']], $_REQUEST['eventid']))
  200. {
  201. checkSession();
  202. // Validate the post...
  203. if (!isset($_POST['link_to_board']))
  204. validateEventPost();
  205. // If you're not allowed to edit any events, you have to be the poster.
  206. if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
  207. isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
  208. // New - and directing?
  209. if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
  210. {
  211. $_REQUEST['calendar'] = 1;
  212. require_once($sourcedir . '/Post.php');
  213. return Post();
  214. }
  215. // New...
  216. elseif ($_REQUEST['eventid'] == -1)
  217. {
  218. $eventOptions = array(
  219. 'board' => 0,
  220. 'topic' => 0,
  221. 'title' => $smcFunc['substr']($_REQUEST['evtitle'], 0, 100),
  222. 'member' => $user_info['id'],
  223. 'start_date' => sprintf('%04d-%02d-%02d', $_POST['year'], $_POST['month'], $_POST['day']),
  224. 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0,
  225. );
  226. insertEvent($eventOptions);
  227. }
  228. // Deleting...
  229. elseif (isset($_REQUEST['deleteevent']))
  230. removeEvent($_REQUEST['eventid']);
  231. // ... or just update it?
  232. else
  233. {
  234. // There could be already a topic you are not allowed to modify
  235. if (!allowedTo('post_new') && empty($modSettings['disableNoPostingCalendarEdits']))
  236. {
  237. $request = $smcFunc['db_query']('', '
  238. SELECT id_board, id_topic
  239. FROM {db_prefix}calendar
  240. WHERE id_event = {int:id_event}
  241. LIMIT 1',
  242. array(
  243. 'id_event' => $_REQUEST['eventid'],
  244. ));
  245. list ($id_board, $id_topic) = $smcFunc['db_fetch_row']($request);
  246. $smcFunc['db_free_result']($request);
  247. }
  248. $eventOptions = array(
  249. 'title' => $smcFunc['substr']($_REQUEST['evtitle'], 0, 100),
  250. '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),
  251. 'start_date' => strftime('%Y-%m-%d', mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year'])),
  252. );
  253. modifyEvent($_REQUEST['eventid'], $eventOptions);
  254. }
  255. updateSettings(array(
  256. 'calendar_updated' => time(),
  257. ));
  258. // No point hanging around here now...
  259. redirectexit($scripturl . '?action=calendar;month=' . $_POST['month'] . ';year=' . $_POST['year']);
  260. }
  261. // If we are not enabled... we are not enabled.
  262. if (empty($modSettings['cal_allow_unlinked']) && empty($_REQUEST['eventid']))
  263. {
  264. $_REQUEST['calendar'] = 1;
  265. require_once($sourcedir . '/Post.php');
  266. return Post();
  267. }
  268. // New?
  269. if (!isset($_REQUEST['eventid']))
  270. {
  271. $today = getdate();
  272. $context['event'] = array(
  273. 'boards' => array(),
  274. 'board' => 0,
  275. 'new' => 1,
  276. 'eventid' => -1,
  277. 'year' => isset($_REQUEST['year']) ? $_REQUEST['year'] : $today['year'],
  278. 'month' => isset($_REQUEST['month']) ? $_REQUEST['month'] : $today['mon'],
  279. 'day' => isset($_REQUEST['day']) ? $_REQUEST['day'] : $today['mday'],
  280. 'title' => '',
  281. 'span' => 1,
  282. );
  283. $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']));
  284. }
  285. else
  286. {
  287. $context['event'] = getEventProperties($_REQUEST['eventid']);
  288. if ($context['event'] === false)
  289. fatal_lang_error('no_access', false);
  290. // If it has a board, then they should be editing it within the topic.
  291. if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
  292. {
  293. // We load the board up, for a check on the board access rights...
  294. $topic = $context['event']['topic']['id'];
  295. loadBoard();
  296. }
  297. // Make sure the user is allowed to edit this event.
  298. if ($context['event']['member'] != $user_info['id'])
  299. isAllowedTo('calendar_edit_any');
  300. elseif (!allowedTo('calendar_edit_any'))
  301. isAllowedTo('calendar_edit_own');
  302. }
  303. // Get list of boards that can be posted in.
  304. $boards = boardsAllowedTo('post_new');
  305. if (empty($boards))
  306. {
  307. // You can post new events but can't link them to anything...
  308. $context['event']['categories'] = array();
  309. }
  310. else
  311. {
  312. // Load the list of boards and categories in the context.
  313. require_once($sourcedir . '/Subs-MessageIndex.php');
  314. $boardListOptions = array(
  315. 'included_boards' => in_array(0, $boards) ? null : $boards,
  316. 'not_redirection' => true,
  317. 'use_permissions' => true,
  318. 'selected_board' => $modSettings['cal_defaultboard'],
  319. );
  320. $context['event']['categories'] = getBoardList($boardListOptions);
  321. }
  322. // Template, sub template, etc.
  323. loadTemplate('Calendar');
  324. $context['sub_template'] = 'event_post';
  325. $context['page_title'] = isset($_REQUEST['eventid']) ? $txt['calendar_edit'] : $txt['calendar_post_event'];
  326. $context['linktree'][] = array(
  327. 'name' => $context['page_title'],
  328. );
  329. }
  330. /**
  331. * This function offers up a download of an event in iCal 2.0 format.
  332. *
  333. * follows the conventions in RFC5546 http://tools.ietf.org/html/rfc5546
  334. * sets events as all day events since we don't have hourly events
  335. * will honor and set multi day events
  336. * sets a sequence number if the event has been modified
  337. *
  338. * @todo .... allow for week or month export files as well?
  339. */
  340. function iCalDownload()
  341. {
  342. global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
  343. // You can't export if the calendar export feature is off.
  344. if (empty($modSettings['cal_export']))
  345. fatal_lang_error('calendar_export_off', false);
  346. // Goes without saying that this is required.
  347. if (!isset($_REQUEST['eventid']))
  348. fatal_lang_error('no_access', false);
  349. // This is kinda wanted.
  350. require_once($sourcedir . '/Subs-Calendar.php');
  351. // Load up the event in question and check it exists.
  352. $event = getEventProperties($_REQUEST['eventid']);
  353. if ($event === false)
  354. fatal_lang_error('no_access', false);
  355. // Check the title isn't too long - iCal requires some formatting if so.
  356. $title = str_split($event['title'], 30);
  357. foreach ($title as $id => $line)
  358. {
  359. if ($id != 0)
  360. $title[$id] = ' ' . $title[$id];
  361. $title[$id] .= "\n";
  362. }
  363. // Format the dates.
  364. $datestamp = date('Ymd\THis\Z', time());
  365. $datestart = $event['year'] . ($event['month'] < 10 ? '0' . $event['month'] : $event['month']) . ($event['day'] < 10 ? '0' . $event['day'] : $event['day']);
  366. // Do we have a event that spans several days?
  367. if ($event['span'] > 1)
  368. {
  369. $dateend = strtotime($event['year'] . '-' . ($event['month'] < 10 ? '0' . $event['month'] : $event['month']) . '-' . ($event['day'] < 10 ? '0' . $event['day'] : $event['day']));
  370. $dateend += ($event['span'] - 1) * 86400;
  371. $dateend = date('Ymd', $dateend);
  372. }
  373. // This is what we will be sending later
  374. $filecontents = '';
  375. $filecontents .= 'BEGIN:VCALENDAR' . "\n";
  376. $filecontents .= 'METHOD:PUBLISH' . "\n";
  377. $filecontents .= 'PRODID:-//SimpleMachines//SMF ' . (empty($forum_version) ? 2.0 : strtr($forum_version, array('SMF ' => ''))) . '//EN' . "\n";
  378. $filecontents .= 'VERSION:2.0' . "\n";
  379. $filecontents .= 'BEGIN:VEVENT' . "\n";
  380. // @TODO - Should be the members email who created the event rather than $webmaster_email.
  381. $filecontents .= 'ORGANIZER;CN="' . $event['realname'] . '":MAILTO:' . $webmaster_email . "\n";
  382. $filecontents .= 'DTSTAMP:' . $datestamp . "\n";
  383. $filecontents .= 'DTSTART;VALUE=DATE:' . $datestart . "\n";
  384. // more than one day
  385. if ($event['span'] > 1)
  386. $filecontents .= 'DTEND;VALUE=DATE:' . $dateend . "\n";
  387. // event has changed? advance the sequence for this UID
  388. if ($event['sequence'] > 0)
  389. $filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
  390. $filecontents .= 'SUMMARY:' . implode('', $title);
  391. $filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
  392. $filecontents .= 'END:VEVENT' . "\n";
  393. $filecontents .= 'END:VCALENDAR';
  394. // Send some standard headers.
  395. ob_end_clean();
  396. if (!empty($modSettings['enableCompressedOutput']))
  397. @ob_start('ob_gzhandler');
  398. else
  399. ob_start();
  400. // Send the file headers
  401. header('Pragma: ');
  402. header('Cache-Control: no-cache');
  403. if (!isBrowser('gecko'))
  404. header('Content-Transfer-Encoding: binary');
  405. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
  406. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
  407. header('Accept-Ranges: bytes');
  408. header('Connection: close');
  409. header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
  410. if (empty($modSettings['enableCompressedOutput']))
  411. header('Content-Length: ' . $smcFunc['strlen']($filecontents));
  412. // This is a calendar item!
  413. header('Content-Type: text/calendar');
  414. // Chuck out the card.
  415. echo $filecontents;
  416. // Off we pop - lovely!
  417. obExit(false);
  418. }
  419. /**
  420. * Nothing to see here. Move along.
  421. */
  422. function clock()
  423. {
  424. global $settings, $context, $scripturl;
  425. $context['onimg'] = $settings['images_url'] . '/bbc/bbc_bg.png';
  426. $context['offimg'] = $settings['images_url'] . '/bbc/bbc_hoverbg.png';
  427. $context['page_title'] = 'Anyone know what time it is?';
  428. $context['linktree'][] = array(
  429. 'url' => $scripturl . '?action=clock',
  430. 'name' => 'Clock',
  431. );
  432. $context['robot_no_index'] = true;
  433. $omfg = isset($_REQUEST['omfg']);
  434. $bcd = !isset($_REQUEST['rb']) && !isset($_REQUEST['omfg']) && !isset($_REQUEST['time']);
  435. loadTemplate('Calendar');
  436. if ($bcd)
  437. {
  438. $context['sub_template'] = 'bcd';
  439. $context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
  440. $context['clockicons'] = unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
  441. }
  442. elseif (!$omfg && !isset($_REQUEST['time']))
  443. {
  444. $context['sub_template'] = 'hms';
  445. $context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
  446. $context['clockicons'] = unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
  447. }
  448. elseif ($omfg)
  449. {
  450. $context['sub_template'] = 'omfg';
  451. $context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
  452. $context['clockicons'] = unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
  453. }
  454. elseif (isset($_REQUEST['time']))
  455. {
  456. $context['sub_template'] = 'thetime';
  457. $time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
  458. $year = $time['year'] % 100;
  459. $month = $time['mon'];
  460. $day = $time['mday'];
  461. $hour = $time['hours'];
  462. $min = $time['minutes'];
  463. $sec = $time['seconds'];
  464. $context['linktree'][] = array('url' => $scripturl . '?action=clock;time=' . $_REQUEST['time'], 'name' => 'Requested Time');
  465. $context['clockicons'] = array(
  466. 'year' => array(
  467. 64 => false,
  468. 32 => false,
  469. 16 => false,
  470. 8 => false,
  471. 4 => false,
  472. 2 => false,
  473. 1 => false
  474. ),
  475. 'month' => array(
  476. 8 => false,
  477. 4 => false,
  478. 2 => false,
  479. 1 => false
  480. ),
  481. 'day' => array(
  482. 16 => false,
  483. 4 => false,
  484. 8 => false,
  485. 2 => false,
  486. 1 => false
  487. ),
  488. 'hour' => array(
  489. 32 => false,
  490. 16 => false,
  491. 8 => false,
  492. 4 => false,
  493. 2 => false,
  494. 1 => false
  495. ),
  496. 'min' => array(
  497. 32 => false,
  498. 16 => false,
  499. 8 => false,
  500. 4 => false,
  501. 2 => false,
  502. 1 => false
  503. ),
  504. 'sec' => array(
  505. 32 => false,
  506. 16 => false,
  507. 8 => false,
  508. 4 => false,
  509. 2 => false,
  510. 1 => false
  511. ),
  512. );
  513. foreach ($context['clockicons'] as $t => $vs)
  514. foreach ($vs as $v => $dumb)
  515. {
  516. if ($$t >= $v)
  517. {
  518. $$t -= $v;
  519. $context['clockicons'][$t][$v] = true;
  520. }
  521. }
  522. }
  523. }
  524. ?>