/~enabled/smd_calendar.php
PHP | 3258 lines | 2916 code | 178 blank | 164 comment | 400 complexity | 9765c280f80ce3fb85716ea8c1d6be92 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- // This is a PLUGIN TEMPLATE for Textpattern CMS.
- // Copy this file to a new name like abc_myplugin.php. Edit the code, then
- // run this file at the command line to produce a plugin for distribution:
- // $ php abc_myplugin.php > abc_myplugin-0.1.txt
- // Plugin name is optional. If unset, it will be extracted from the current
- // file name. Plugin names should start with a three letter prefix which is
- // unique and reserved for each plugin author ("abc" is just an example).
- // Uncomment and edit this line to override:
- $plugin['name'] = 'smd_calendar';
- // Allow raw HTML help, as opposed to Textile.
- // 0 = Plugin help is in Textile format, no raw HTML allowed (default).
- // 1 = Plugin help is in raw HTML. Not recommended.
- # $plugin['allow_html_help'] = 1;
- $plugin['version'] = '0.54';
- $plugin['author'] = 'Stef Dawson';
- $plugin['author_uri'] = 'http://stefdawson.com/';
- $plugin['description'] = 'Calendar / event / schedule system with events as Textpattern articles';
- // Plugin load order:
- // The default value of 5 would fit most plugins, while for instance comment
- // spam evaluators or URL redirectors would probably want to run earlier
- // (1...4) to prepare the environment for everything else that follows.
- // Values 6...9 should be considered for plugins which would work late.
- // This order is user-overrideable.
- $plugin['order'] = '5';
- // Plugin 'type' defines where the plugin is loaded
- // 0 = public : only on the public side of the website (default)
- // 1 = public+admin : on both the public and admin side
- // 2 = library : only when include_plugin() or require_plugin() is called
- // 3 = admin : only on the admin side (no AJAX)
- // 4 = admin+ajax : only on the admin side (AJAX supported)
- // 5 = public+admin+ajax : on both the public and admin side (AJAX supported)
- $plugin['type'] = '0';
- // Plugin "flags" signal the presence of optional capabilities to the core plugin loader.
- // Use an appropriately OR-ed combination of these flags.
- // The four high-order bits 0xf000 are available for this plugin's private use
- if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
- if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
- $plugin['flags'] = '0';
- // Plugin 'textpack' is optional. It provides i18n strings to be used in conjunction with gTxt().
- // Syntax:
- // ## arbitrary comment
- // #@event
- // #@language ISO-LANGUAGE-CODE
- // abc_string_name => Localized String
- /** Uncomment me, if you need a textpack
- $plugin['textpack'] = <<< EOT
- #@admin
- #@language en-gb
- abc_sample_string => Sample String
- abc_one_more => One more
- #@language de-de
- abc_sample_string => Beispieltext
- abc_one_more => Noch einer
- EOT;
- **/
- // End of textpack
- if (!defined('txpinterface'))
- @include_once('zem_tpl.php');
- # --- BEGIN PLUGIN CODE ---
- /**
- * smd_calendar
- *
- * A Textpattern CMS plugin for complete monthly event and calendar management
- * -> Originally based on mdp_calendar - thanks Marshall!
- * -> Full-size / mini calendar by month, with ISO week support
- * -> Txp articles are events. Future, past, and today's events are supported. Multi-day (spanned) events are based on article expiry
- * -> Next/prev month/year select list with customisable start/end years
- * -> Filter events by cat / section / author / status / time / expiry
- * -> Specify event frequency in custom field (1 week / 10 days / 3 months / etc)
- * -> Optionally (re)schedule / cancel / omit event dates
- * -> Customisable output for events and cells using multiple forms/container and classes
- * -> Conditional tags for building custom logic
- *
- * @author Stef Dawson
- * @link http://stefdawson.com/
- */
- // TODO:
- // * allow table header to be removed / restyled completely (the month/week dropdown & nav icons)
- // -- a form (navform?) for the header row with access to all vars such as which month is being displayed?
- // -- tools to allow the header to be generated from components and laid out in any manner?
- // * allow URL vars to be passed as POST (to bypass gbp_permlinks)
- // * add custom rows to the table (header, footer) -- header could be used to replace the current nav/dropdowns
- // * div-based calendar layout?
- // TOFIX:
- // * Expiry dates on extra+ allspanned dates in smd_article_event (and calendar?). They currently 'creep' a day for every day of a spanned event
- // * Ranges in stepfields (http://forum.textpattern.com/viewtopic.php?pid=254395#p254395 and http://forum.textpattern.com/viewtopic.php?pid=255617#p255617)
- if( $date = gps('date') ) {
- $_GET['month'] = $date;
- }
- function smd_calendar($atts, $thing='') {
- global $pretext, $thisarticle, $variable, $prefs, $smd_cal_flag, $smd_date, $smd_calinfo, $smd_cal_ucls;
- extract(lAtts(array(
- 'time' => 'any',
- 'size' => 'large',
- 'expired' => '',
- 'category' => null,
- 'subcats' => '',
- 'section' => '',
- 'author' => '',
- 'realname' => '',
- 'status' => 'live',
- 'showall' => '0',
- 'static' => '',
- 'form' => '',
- 'spanform' => 'SMD_SAME',
- 'recurform' => 'SMD_SAME',
- 'cellform' => '',
- 'headerform' => '',
- 'stepfield' => '',
- 'skipfield' => '',
- 'omitfield' => '',
- 'extrafield' => '',
- 'extrastrict' => '0',
- 'datefields' => '',
- 'showskipped' => '0',
- 'showspanned' => '1',
- 'holidays' => '',
- 'holidayflags' => 'standard',
- 'classlevels' => 'cell, event',
- 'linkposted' => 'recur, multi, multiprev, multilast',
- 'classprefixes' => 'smd_cal_, smd_cal_ev_',
- 'class' => '',
- 'rowclass' => '',
- 'cellclass' => '',
- 'emptyclass' => 'empty',
- 'isoweekclass' => 'week',
- 'navclass' => 'navprev, navnext',
- 'navarrow' => '<, >',
- 'navid' => '',
- 'eventclasses' => 'category',
- 'eventwraptag' => 'span',
- 'select' => '',
- 'selectbtn' => '',
- 'myclass' => '',
- 'mywraptag' => '',
- 'caption' => '',
- 'summary' => '',
- 'id' => '',
- 'week' => '',
- 'month' => '',
- 'year' => '',
- 'remap' => '',
- 'yearwidth' => '0',
- 'isoweeks' => '',
- 'dayformat' => 'ABBR',
- 'monthformat' => 'FULL',
- 'firstday' => 0,
- 'maintain' => 'calid',
- 'nameval' => '',
- 'event_delim' => ',',
- 'gmt' => 0,
- 'lang' => '',
- 'debug' => 0,
- ), $atts));
- $size = (in_array($size, array('small', 'large'))) ? $size : 'large';
- $status = ($status) ? $status : 'live'; // in case status is empty
- $firstday = ($isoweeks == '') ? $firstday : 1;
- $spanform = ($spanform == 'SMD_SAME') ? $form : $spanform;
- $recurform = ($recurform == 'SMD_SAME') ? $form : $recurform;
- $cellform = (empty($cellform)) ? '' : fetch_form($cellform);
- $headerform = (empty($headerform)) ? '' : fetch_form($headerform);
- $frontpage = ($section=='' && $pretext['s']=='default') ? true : false;
- // Set up the class prefixes
- $clevs = do_list($classlevels);
- $cls = do_list($classprefixes);
- $cls_pfx = $evc_pfx = $cls[0];
- if (count($cls) > 1){
- $evc_pfx = $cls[1];
- }
- // Set up the nav class(es)
- $maintain = do_list($maintain);
- $navarrow = do_list($navarrow);
- $navparr = $navarrow[0];
- $navnarr = (count($navarrow) > 1) ? $navarrow[1] : $navarrow[0];
- $navclass = do_list($navclass);
- $navpclass = $navclass[0];
- $navnclass = (count($navclass) > 1) ? $navclass[1] : $navclass[0];
- // Filters
- $fopts = array();
- $catSQL = $secSQL = $authSQL = $fpSQL = '';
- if($category !== null) {
- $uncats = false;
- $allcats = do_list($category);
- if (($pos = array_search('SMD_UNCAT', $allcats)) !== false) {
- $uncats = true;
- unset($allcats[$pos]);
- $category = join(',', $allcats);
- }
- $fopts['c'] = $category; // TODO: Can fopts take a list? Should it include subcats?
- $subcats = (empty($subcats)) ? 0 : ((strtolower($subcats)=="all") ? 99999 : intval($subcats));
- if ($subcats) {
- $outcats = array();
- foreach ($allcats as $cat) {
- $cats = getTree(doslash($cat), 'article');
- foreach ($cats as $jdx => $val) {
- if ($cats[$jdx]['level'] <= $subcats) {
- $outcats[] = $cats[$jdx]['name'];
- }
- }
- }
- $allcats = $outcats;
- }
- $catSQL = doQuote(join("','", doSlash($allcats)));
- $catSQL = ($uncats ? " AND (Category1 = '' AND Category2 = '')" : '') .
- ($uncats && $allcats ? " OR " : ($allcats ? " AND " : '')) .
- ($allcats ? "( Category1 IN (".$catSQL.") OR Category2 IN (".$catSQL.") ) " : '');
- }
- if($section) {
- $secs = do_list($section);
- $smd_calinfo['s'] = $secs[0];
- $secSQL = doQuote(join("','", doSlash($secs)));
- $secSQL = " AND Section IN (".$secSQL.") ";
- }
- if($realname) {
- $authors = safe_column('name', 'txp_users', 'RealName IN ('. doQuote(join("','", doArray(do_list($realname), 'urldecode'))) .')' );
- $author = join(',', $authors);
- }
- if($author) {
- $fopts['author'] = htmlentities(gps('author'));
- $authSQL = doQuote(join("','", doSlash(do_list($author))));
- $authSQL = " AND AuthorID IN (".$authSQL.") ";
- }
- if ($frontpage && !$showall) {
- $fpSQL = filterFrontPage();
- }
- $smd_calinfo['artid'] = $thisarticle['thisid'];
- $smd_calinfo['artitle'] = $thisarticle['url_title'];
- $nameval = do_list($nameval);
- foreach ($nameval as $nv) {
- $nv = explode("=", $nv);
- if ($nv[0]) {
- $fopts[$nv[0]] = ((isset($nv[1])) ? $nv[1] : '');
- }
- }
- $status = do_list($status);
- $stati = array();
- foreach ($status as $stat) {
- if (empty($stat)) {
- continue;
- } else if (is_numeric($stat)) {
- $stati[] = $stat;
- } else {
- $stati[] = getStatusNum($stat);
- }
- }
- $stati = " Status IN (".join(',', $stati).")";
- $expired = ($expired) ? $expired : $prefs['publish_expired_articles'];
- $expired = (($expired) ? '' : ' AND (now() <= Expires OR Expires = '.NULLDATETIME.')');
- $eventclasses = do_list($eventclasses);
- $holidayflags = do_list($holidayflags);
- $linkposted = do_list($linkposted);
- $datefields = do_list($datefields);
- // Work out the first and last posts to determine the year range - probably a better way of doing this than 3 queries
- $filt = $stati . (($category !== null) ? $catSQL : '') . (($section) ? $secSQL : '') . (($author) ? $authSQL : '') . $fpSQL;
- $earliest = safe_field('unix_timestamp(Posted) AS uPosted', 'textpattern', $filt .' ORDER BY Posted ASC LIMIT 0, 1', $debug);
- $lp = safe_field('unix_timestamp(Posted) AS uPosted', 'textpattern', $filt .' ORDER BY Posted DESC LIMIT 0, 1', $debug);
- $lm = safe_field('unix_timestamp(LastMod) AS uLastMod', 'textpattern', $filt .' ORDER BY LastMod DESC LIMIT 0, 1', $debug);
- $latest = ($time=="past") ? time() : (($lp > $lm) ? $lp : $lm);
- $yearwidth = do_list($yearwidth);
- $yearwidth[0] = (empty($yearwidth[0])) ? 0 : $yearwidth[0];
- if (count($yearwidth) == 1) {
- $yearwidth[1] = $yearwidth[0];
- }
- $usenow = array(false,false);
- foreach ($yearwidth as $yridx => $yritem) {
- if (strpos($yritem,"c") !== false) {
- $yearwidth[$yridx] = intval($yritem);
- $usenow[$yridx] = true;
- }
- }
- // Remap w/m/y to other vars if required
- $remap = do_list($remap);
- $dmap = array("y" => "y", "m" => "m", "w" => "w");
- foreach ($remap as $dpair) {
- $dpair = do_list($dpair, ':');
- $dmap[$dpair[0]] = (isset($dpair[1])) ? $dpair[1] : $dpair[0];
- }
- $earliest = date("Y", strtotime("-".$yearwidth[0]." year", ( (empty($earliest) || $usenow[0]==true) ? time() : $earliest) ) );
- $latest = date("Y", strtotime("+".$yearwidth[1]." year", ( (empty($latest) || $usenow[1]==true) ? time() : $latest) ) );
- // Check the URL for current date and calendar target info
- $in_calid = gps('calid');
- $in_year = (gps($dmap["y"]) and is_numeric(gps($dmap["y"]))) ? (int)gps($dmap["y"]) : '';
- $in_month = (gps($dmap["m"]) and is_numeric(gps($dmap["m"]))) ? (int)gps($dmap["m"]) : '';
- $in_week = (gps($dmap["w"]) and is_numeric(gps($dmap["w"]))) ? (int)gps($dmap["w"]) : '';
- if($static) { // if we're static w/o any supplied vars, use the current date
- if(!$year) { $year = safe_strftime('%Y'); }
- if(!$month) { $month = safe_strftime('%m'); }
- } else { // otherwise use current date only if there's nothing else
- if( $id == $in_calid ) { // use incoming
- $year = ($in_year) ? $in_year : (($year) ? $year : safe_strftime('%Y'));
- $month = ($in_month) ? $in_month : (($month) ? $month : safe_strftime('%m'));
- // If week is used, adjust month so it encompasses the given week
- $week = $in_week;
- if ($week) {
- $month = safe_strftime("%m", strtotime($year."W".str_pad($week, 2, '0', STR_PAD_LEFT))); // Get the month from the week
- }
- } else { // use current
- if(!$year) { $year = safe_strftime('%Y'); }
- if(!$month) { $month = safe_strftime('%m'); }
- if($week) { $month = safe_strftime("%m", strtotime($year."W".str_pad($week, 2, '0', STR_PAD_LEFT))); }
- }
- }
- $smd_calinfo['id'] = ($in_calid) ? $in_calid : $id;
- $smd_date['y'] = $year; $smd_date['m'] = $month; // $week/day/isoyear are set per event later
- $ts_first = mktime(0, 0, 0, $month, 1, $year);
- $ts_last = mktime(23, 59, 59, $month, date('t',$ts_first), $year);
- $ts_lastoff = $ts_last - tz_offset($ts_last);
- if ($debug) {
- echo "++ THIS MONTH'S CALENDAR [ start stamp // end date // end stamp // end date // tz offset (end) ] ++";
- dmp($ts_first, date('Y-m-d H:i:s', $ts_first), $ts_last, date('Y-m-d H:i:s', $ts_last), $ts_lastoff);
- }
- $extrasql = $catSQL . $secSQL . $authSQL . $fpSQL;
- switch($time) {
- case "any" : break;
- case "future" : $extrasql .= " AND Posted > now()"; break;
- default : $extrasql .= " AND Posted < now()"; break; // The past
- }
- // Holidays are global 'exclusions', either defined directly or in a txp:variable
- $holidays = do_list($holidays);
- $txphols = do_list($holidays[0], ":");
- if ($txphols[0] == "txpvar") {
- $holidays = do_list($variable[$txphols[1]]);
- }
- // Force each holiday to a known format. Holidays without years use current year
- foreach ($holidays as $key => $val) {
- if (empty($val)) continue;
- $numparts = preg_match('/^([\d\w]+).?([\d\w]+).?([\d\w]+)?$/', $val, $parts);
- if ($numparts) {
- if (count($parts) == 3) {
- $parts[3] = $year;
- }
- $val = str_pad($parts[1], 2, '0', STR_PAD_LEFT).'-'.str_pad($parts[2], 2, '0', STR_PAD_LEFT).'-'.$parts[3];
- }
- $holidays[$key] = date("d-M-Y", safe_strtotime($val));
- }
- if ($debug > 0 && !empty($holidays) && $holidays[0] != '') {
- echo "++ HOLIDAYS ++ ";
- dmp($holidays);
- }
- // Get all matching articles in (and before) this month
- $events = array();
- $uposted_field = (empty($datefields[0])) ? 'uPosted' : "UNIX_TIMESTAMP($datefields[0])";
- $sql2 = $stati . " HAVING $uposted_field <= ".$ts_lastoff. $expired . $extrasql ." ORDER BY Posted ASC";
- $grabCols = '*, unix_timestamp(Posted) as uPosted, unix_timestamp(LastMod) as uLastMod, unix_timestamp(Expires) as uExpires';
- $evlist = safe_rows($grabCols, 'textpattern', $sql2, $debug);
- article_push();
- // If any events recur and fall within the current month, add those as well
- // If any dates are to be excluded, the entry is skipped UNLESS showskipped indicates otherwise
- foreach ($evlist as $row) {
- $idx = 0; // In case the 1st day of the month is a continuation of an event from the end of the previous month
- $start = (!empty($datefields[0]) && !empty($row[$datefields[0]]) && ($stdt = strtotime($row[$datefields[0]])) !== false) ? $stdt : $row['uPosted'] + tz_offset($row['uPosted']);
- $start_date = date("Y-m-d", $start); // For recurring/spanned events on a minical, this is the event the cell links to
- $real_end = (isset($datefields[1]) && !empty($row[$datefields[1]]) && ($endt = strtotime($row[$datefields[1]])) !== false) ? $endt : (($row['uExpires']==0) ? 0 : $row['uExpires'] + tz_offset($row['uExpires']));
- // If end < start the user-specified dates cannot be trusted
- if ($real_end != 0 && $real_end <= $start) {
- $start = $row['uPosted'] + tz_offset($row['uPosted']);
- $real_end = $row['uExpires'] + tz_offset($row['uExpires']);
- trigger_error('Expiry cannot be before start date in "'.$row['Title'].'": ignored', E_USER_WARNING);
- }
- $end = ($real_end != 0 && $real_end < $ts_last) ? $real_end : $ts_last;
- $real_diff = ($real_end==0) ? 0 : $real_end - $start;
- $real_end_month = ($real_end==0) ? 0 : date('m', $real_end);
- $real_end_year = ($real_end==0) ? 0 : date('Y', $real_end);
- $fake_diff = strtotime(date("Y-M-d", $real_end) . " 23:59:59");
- $diff = ($real_end==0) ? 0 : $fake_diff - $start;
- $smd_cal_flag = array();
- $smd_cal_ucls = array();
- $ev_month = date('m', $start);
- $ev_year = date('Y', $start);
- $ev_hr = date('H', $start);
- $ev_mn = date('i', $start);
- $ev_sc = date('s', $start);
- if ($debug > 1) {
- echo '++ EVENT START // END // (if non-zero) REAL END ++';
- dmp(date('d-M-Y H:i:s', $start) .' // '. date('d-M-Y H:i:s', $end) .' // '. ( ($real_end == 0) ? '' : date('d-M-Y H:i:s', $real_end) ));
- dmp($row['Title']);
- if ($debug > 2) {
- dmp($row);
- }
- }
- $multi = (($end > $start) && ($real_end > $start) && ($real_end > $ts_first) && (date("d-m-Y", $real_end) != date("d-m-Y", $start))) ? true : false;
- $recur = (empty($row[$stepfield])) ? false : true;
- $hol_hit = in_array(date("d-M-Y", $start), $holidays);
- $evclasses = array();
- foreach ($eventclasses as $evcls) {
- switch ($evcls) {
- case "":
- break;
- case "gcat":
- if (isset($pretext['c']) && !empty($pretext['c'])) {
- $evclasses[] = $evc_pfx.$pretext['c'];
- }
- break;
- case "category":
- if (isset($row['Category1']) && !empty($row['Category1'])) {
- $evclasses[] = $evc_pfx.$row['Category1'];
- }
- if (isset($row['Category2']) && !empty($row['Category2'])) {
- $evclasses[] = $evc_pfx.$row['Category2'];
- }
- break;
- case "section":
- if (isset($pretext['s']) && !empty($pretext['s'])) {
- $evclasses[] = $evc_pfx.$pretext['s'];
- }
- break;
- case "author":
- if (isset($pretext['author']) && !empty($pretext['author'])) {
- $evclasses[] = $evc_pfx.$pretext['author'];
- }
- break;
- default:
- if (isset($row[$evcls]) && !empty($row[$evcls])) {
- $evclasses[] = $evc_pfx.$row[$evcls];
- }
- break;
- }
- }
- $ignore = array();
- $omit = array();
- $cflag = array();
- if ($debug > 1 && $evclasses) {
- echo '++ EVENT CLASSES ++';
- dmp($evclasses);
- }
- // Events that start or are added this month
- if (($start < $end) && ($start > $ts_first)) {
- populateArticleData($row);
- // a standard event or start of a multi
- if ($showspanned && $multi && !$recur) {
- $smd_cal_flag[] = 'multifirst';
- }
- if ($recur) {
- $smd_cal_flag[] = 'recurfirst';
- }
- if (!$smd_cal_flag) {
- $smd_cal_flag[] = 'standard';
- }
- if ( ( $hol_hit && !in_array('multi',$holidayflags) && in_array('multifirst',$smd_cal_flag) ) || ( $hol_hit && !in_array('standard',$holidayflags) && in_array('standard',$smd_cal_flag) ) ) {
- $smd_cal_flag[] = 'cancel';
- }
- foreach ($smd_cal_flag as $item) {
- $cflag[] = $cls_pfx.$item;
- }
- $idx = $smd_date['d'] = (int)strftime('%d', $start);
- $smd_date['w'] = strftime(smd_cal_reformat_win('%V', $start), $start);
- $smd_date['iy'] = strftime(smd_cal_reformat_win('%G', $start), $start);
- $use_posted = in_array('standard', $linkposted);
- $op = ($thing) ? parse($thing) : (($form) ? parse_form($form) : (($size=="small") ? smd_cal_minilink($row, $idx, $month, $year, $use_posted) : href($row['Title'], permlinkurl($row), ' title="'.$row['Title'].'"')) );
- $events[$idx][] = array('ev' => $op, 'evid' => $row['ID'], 'flag' => $smd_cal_flag, 'classes' => array_merge($cflag, $smd_cal_ucls, $evclasses), 'posted' => $start_date);
- $smd_cal_flag = array();
- $cflag = array();
- $smd_cal_ucls = array();
- $use_posted = '';
- }
- // Generate a skip array for this event
- if ($skipfield && $row[$skipfield] != '') {
- $ignores = do_list($row[$skipfield]);
- foreach ($ignores as $val) {
- $igrng = smd_expand_daterange($val, $start, $end);
- foreach ($igrng as $theval) {
- $ignore[] = date("d-M-Y", $theval); // Force each date to a known format
- }
- }
- }
- // Generate an omit array for this event
- if ($omitfield && $row[$omitfield] != '') {
- $omits = do_list($row[$omitfield]);
- foreach ($omits as $val) {
- $omrng = smd_expand_daterange($val, $start, $end);
- foreach ($omrng as $theval) {
- $omit[] = date("d-M-Y", $theval);
- }
- }
- }
- if ($debug > 1 && ($ignore || $omit)) {
- echo '++ OMITTED DATES ++';
- dmp($omit);
- echo '++ CANCELLED DATES ++';
- dmp($ignore);
- }
- // Calculate the date offsets and check recurring events that fall within the month of interest
- if ($stepfield && $row[$stepfield] != '') {
- $freq = do_list($row[$stepfield]);
- $stampoff = (int)(3600*$ev_hr) + (int)(60*$ev_mn) + (int)$ev_sc;
- foreach ($freq as $interval) {
- $max_loop = 99999; // Yuk, but practically limitless
- $origerval = $interval;
- $interval = str_replace("?month", date('F', mktime(0,0,0,$month,1)), $interval);
- $interval = str_replace("?year", $year, $interval);
- if (strpos($interval, "last") === 0) {
- $interval = date("l, F jS Y", strtotime( $interval, mktime(12, 0, 0, date("n", mktime(0,0,0,$month,1,$year))+1, 1, $year) ));
- $max_loop = 1;
- } else if (strpos($interval, "first") === 0) {
- $interval = date("l, F jS Y", strtotime( $interval, mktime(12, 0, 0, (($month>1) ? $month-1 : 12), date("t", mktime(0,0,0,$month-1,1,(($month==1) ? $year-1: $year))), (($month==1) ? $year-1: $year)) ));
- $max_loop = 1;
- } else if (strpos($interval, "this") === 0) {
- $max_loop = 1;
- }
- $ts_loop = 0;
- $ts_curr = $start;
- if (strpos($origerval, "?month") || strpos($origerval, "?year")) {
- $max_loop = 1;
- }
- // $rng = smd_expand_daterange($interval);
- //dmp($interval, $rng);
- while ($ts_curr < $end && $ts_loop < $max_loop) {
- if ($max_loop == 1) {
- $ts_curr = strtotime($interval);
- $ts_curr = ($ts_curr < $start || $ts_curr > $end) ? $start : $ts_curr;
- } else {
- $ts_curr = strtotime($interval, $ts_curr);
- }
- if ($ts_curr === false) {
- $ts_loop++;
- break;
- } else {
- if ($debug > 1) {
- dmp("INTERVAL: ". date('d-M-Y H:i:s', $ts_curr+$stampoff));
- }
- if ($ts_curr < $end && $ts_curr >= $ts_first && $ts_curr != $start) {
- // A recurring event. Check it isn't a holiday or to be ignored
- populateArticleData($row);
- $op = '';
- $idx = (int)strftime('%d', $ts_curr);
- $smd_cal_flag[] = 'recur';
- $thisdate = date("d-M-Y", $ts_curr);
- $omit_me = in_array($thisdate, $omit);
- $show_me = !in_array($thisdate, $ignore);
- $hol_hit = in_array($thisdate, $holidays);
- $show_hol = ($hol_hit && !in_array('recur',$holidayflags) ) ? false : true;
- $use_posted = smd_cal_in_array(array('recur', 'recurfirst'), $linkposted);
- if ( $omit_me ) {
- $smd_cal_flag[] = 'omit';
- }
- if ( (!$show_me || !$show_hol) && !$omit_me ) {
- $smd_cal_flag[] = 'cancel';
- }
- foreach ($smd_cal_flag as $item) {
- $cflag[] = $cls_pfx.$item;
- }
- // Create the events that appear in the cell but only if they've not appeared before, or are to be ignored/omitted
- if (!$omit_me) {
- if (($show_me && $show_hol) || $showskipped) {
- $smd_date['d'] = $idx;
- $smd_date['w'] = strftime(smd_cal_reformat_win('%V', $ts_curr), $ts_curr);
- $smd_date['iy'] = strftime(smd_cal_reformat_win('%G', $ts_curr), $ts_curr);
- $op = ($recurform) ? parse_form($recurform) : (($thing) ? parse($thing) : (($size=="small") ? smd_cal_minilink($row, $idx, $month, $year, $use_posted) : href($row['Title'], permlinkurl($row), ' title="'.$row['Title'].'"')) );
- }
- }
- $used = array();
- if (isset($events[$idx]) && $events[$idx] != NULL) {
- foreach ($events[$idx] as $ev) {
- $used[] = $ev['ev'];
- }
- }
- if (isset($events[$idx]) && $events[$idx] == NULL || !in_array($op, $used)) {
- $events[$idx][] = array('ev' => $op, 'evid' => $row['ID'], 'flag' => $smd_cal_flag, 'classes' => array_merge($cflag, $smd_cal_ucls, $evclasses), 'posted' => $start_date);
- }
- $smd_cal_flag = array();
- $cflag = array();
- $smd_cal_ucls = array();
- $use_posted = '';
- }
- $ts_loop++;
- }
- }
- }
- } else if ($showspanned && $multi) {
- // Non-recurring events may span more than one date but they must still respect ignored dates and holidays
- populateArticleData($row);
- $lastday = (int)strftime('%d', $end);
- $real_lastday = (int)strftime('%d', $real_end);
- while (++$idx <= $lastday) {
- $op = '';
- $multiflag = (($year==$real_end_year) && ($month==$real_end_month) && ($idx==$real_lastday)) ? 'multilast' : (($idx==1) ? 'multiprev' : 'multi');
- $smd_cal_flag[] = $multiflag;
- $thistime = mktime(0, 0, 0, $month, $idx, $year);
- $thisdate = date("d-M-Y", $thistime);
- $omit_me = in_array($thisdate, $omit);
- $show_me = !in_array($thisdate, $ignore);
- $hol_hit = in_array($thisdate, $holidays);
- $show_hol = ($hol_hit && !in_array('multi',$holidayflags) ) ? false : true;
- $use_posted = smd_cal_in_array(array('multi', 'multifirst', 'multilast', 'multiprev'), $linkposted);
- if ( $omit_me ) {
- $smd_cal_flag[] = 'omit';
- }
- if ( (!$show_me || !$show_hol) && !$omit_me ) {
- $smd_cal_flag[] = 'cancel';
- }
- foreach ($smd_cal_flag as $item) {
- $cflag[] = $cls_pfx.$item;
- }
- // Create the spanned event that appears in the cell
- if (!$omit_me) {
- if ( ($show_me && $show_hol) || $showskipped) {
- $smd_date['d'] = $idx;
- $smd_date['w'] = strftime(smd_cal_reformat_win('%V', $thistime), $thistime);
- $smd_date['iy'] = strftime(smd_cal_reformat_win('%G', $thistime), $thistime);
- $op = ($spanform) ? parse_form($spanform) : (($thing) ? parse($thing) : (($size=="small") ? smd_cal_minilink($row, $idx, $month, $year, $use_posted) : href('→', permlinkurl($row), ' title="'.$row['Title'].'"')) );
- }
- }
- $events[$idx][] = array('ev' => $op, 'evid' => $row['ID'], 'flag' => $smd_cal_flag, 'classes' => array_merge($cflag, $smd_cal_ucls, $evclasses), 'posted' => $start_date);
- $smd_cal_flag = array();
- $cflag = array();
- $smd_cal_ucls = array();
- $use_posted = '';
- }
- }
- // Add any extra dates for this event that are within the current month
- if ($extrafield && $row[$extrafield] != '') {
- $xtra = do_list($row[$extrafield]);
- $ev_hr = date('H', $start);
- $ev_mn = date('i', $start);
- $ev_sc = date('s', $start);
- $stampoff = (int)(3600*$ev_hr) + (int)(60*$ev_mn) + (int)$ev_sc;
- foreach ($xtra as $val) {
- if (strpos($val, "+") === false) {
- $exrng = smd_expand_daterange($val);
- $val = date("Y-m-d", $exrng[0]);
- $spidth = count($exrng);
- $spex = 0;
- } else {
- $chk = $showspanned && !$recur;
- $spidth = $chk ? ceil($diff / (60*60*24)) : 1; // days between dates
- $val = rtrim($val, '+');
- $spex = $chk ? 1 : 0;
- }
- for ($jdx = 1; $jdx <= $spidth; $jdx++) {
- $tm = safe_strtotime($val . (($jdx==1) ? '' : '+'.($jdx-1).' days'));
- if ($diff > 0 && $jdx == 1) {
- $expstamp = $tm+$stampoff+$real_diff;
- }
- $idx = $smd_date['d'] = (int)strftime('%d', $tm);
- $dt = date("Y-m-d", $tm);
- $lst = ($extrastrict) ? $end : $ts_last;
- if ($tm < $lst && $tm >= $ts_first) {
- $fakerow = $row;
- $fakerow['Posted'] = date("Y-m-d H:i:s", $tm+$stampoff);
- $fakerow['uPosted'] = $tm+$stampoff;
- if ($diff>0) {
- $fakerow['Expires'] = date("Y-m-d H:i:s", $expstamp);
- $fakerow['uExpires'] = $expstamp;
- }
- populateArticleData($fakerow);
- $smd_cal_flag[] = 'extra';
- $cflag[] = $cls_pfx.'extra';
- $omit_me = false;
- $show_me = $show_hol = true;
- if ($spex) {
- $multiflag = ($jdx==1) ? 'multifirst' : (($jdx==$spidth) ? 'multilast' : (($idx==1) ? 'multiprev' : 'multi'));
- $thisdate = date("d-M-Y", $tm);
- $omit_me = in_array($thisdate, $omit);
- $show_me = !in_array($thisdate, $ignore);
- $hol_hit = in_array($thisdate, $holidays);
- $show_hol = ($hol_hit && !in_array('multi',$holidayflags) ) ? false : true;
- $use_posted = in_array('extra', $linkposted);
- if ($omit_me) {
- $smd_cal_flag[] = 'omit';
- }
- if ( (!$show_me || !$show_hol) && !$omit_me ) {
- $smd_cal_flag[] = 'cancel';
- }
- $smd_cal_flag[] = $multiflag;
- $cflag[] = $cls_pfx.$multiflag;
- }
- if (!$omit_me) {
- if ( ($show_me && $show_hol) || $showskipped) {
- $smd_date['w'] = strftime(smd_cal_reformat_win('%V', $tm), $tm);
- $smd_date['iy'] = strftime(smd_cal_reformat_win('%G', $tm), $tm);
- $op = ($spex && $spanform) ? parse_form($spanform) : (($thing) ? parse($thing) : (($form) ? parse_form($form) : (($size=="small") ? smd_cal_minilink($row, $idx, $month, $year, $use_posted) : href((($spex && $jdx>1) ? '→' : $row['Title']), permlinkurl($row), ' title="'.$row['Title'].'"')) ));
- $events[$idx][] = array('ev' => $op, 'evid' => $row['ID'], 'flag' => $smd_cal_flag, 'classes' => array_merge($cflag, $smd_cal_ucls, $evclasses), 'posted' => $dt);
- $smd_cal_flag = array();
- $cflag = array();
- $smd_cal_ucls = array();
- $use_posted = '';
- }
- }
- }
- }
- }
- }
- }
- article_pop();
- if ($debug > 1 && $events) {
- echo '++ ALL EVENTS ++';
- dmp($events);
- }
- // Generate the calendar
- $calendar = new SMD_Calendar($size, $year, $month, $events, $section, $category, $debug);
- $calendar->setWeek($week);
- $calendar->setFirstDayOfWeek($firstday);
- $calendar->setGMT($gmt);
- $calendar->setLang($lang);
- $calendar->setClassLevels($clevs);
- $calendar->setClassPrefix($cls_pfx);
- $calendar->setEventWraptag($eventwraptag);
- $calendar->setCellForm($cellform);
- $calendar->setHdrForm($headerform);
- $calendar->setMYWraptag($mywraptag);
- $calendar->setSummary($summary);
- $calendar->setCaption($caption);
- $calendar->setTableID($id);
- $calendar->setTableClass($class);
- $calendar->setRowClass($rowclass);
- $calendar->setCellClass($cellclass);
- $calendar->setEmptyClass($emptyclass);
- $calendar->setISOWeekClass($isoweekclass);
- $calendar->setNavInfo($navpclass,$navnclass,$navparr,$navnarr,$navid);
- $calendar->setNavKeep($maintain);
- $calendar->setMYClass($myclass);
- $calendar->setNameFormat($dayformat, "d");
- $calendar->setNameFormat($monthformat, "m");
- $calendar->setRemap($dmap);
- $calendar->setShowISOWeek($isoweeks);
- $calendar->setEYear($earliest);
- $calendar->setLYear($latest);
- $calendar->setFilterOpts($fopts);
- $calendar->setDelim($event_delim);
- $calendar->setHolidays($holidays);
- $calendar->setSelectors(do_list($select), $selectbtn);
- return $calendar->display($static);
- }
- class SMD_Calendar extends SMD_Raw_Calendar {
- // Override Constructor
- // Permits multiple events to show per day
- var $section = '';
- var $category = '';
- var $size = '';
- var $debug = 0;
- var $events = array();
- function SMD_Calendar($size,$year,$month,$events,$section,$category, $debug=0) {
- $this->debug = $debug;
- $this->section = $section;
- $this->category = $category;
- $this->events = $events;
- $this->size = $size;
- $this->smd_Raw_Calendar($year,$month,$debug);
- }
- // Override dspDayCell to display stuff right
- function dspDayCell($theday) {
- global $smd_cal_flag, $smd_calinfo, $smd_cal_ucls, $smd_date, $permlink_mode;
- $smd_cal_flag = array();
- $smd_cal_ucls = array();
- $tdclass = array();
- $hasarticle = isset($this->events[$theday]);
- $now = time() + tz_offset();
- $thedate = mktime(0, 0, 0, $this->month, $theday, $this->year);
- $hol_hit = in_array(date("d-M-Y", $thedate), $this->holidays);
- if ($hasarticle) {
- $smd_cal_flag[] = 'event';
- }
- if ($hol_hit) {
- $smd_cal_flag[] = 'hols';
- }
- $cflag = array();
- foreach ($smd_cal_flag as $item) {
- $cflag[] = $this->cls_pfx.$item;
- }
- if ($this->cellclass) {
- $tdclass[] = $this->cellclass;
- }
- $tdclass = array_merge($tdclass, $cflag);
- $runningclass = (in_array("cell", $this->cls_lev) || in_array("cellplus", $this->cls_lev)) ? $tdclass : array();
- if($this->year == date('Y',$now) and $this->month == date('n',$now) and $theday == date('j',$now) ) {
- $smd_cal_flag[] = 'today';
- $runningclass[] = $this->cls_pfx.'today';
- }
- $out = array();
- $flags = array();
- $evid = array();
- $fout = array('standard'=>array(),'recur'=>array(),'recurfirst'=>array(),'multifirst'=>array(),'multi'=>array(),'multiprev'=>array(),'multilast'=>array(),'cancel'=>array(),'extra'=>array());
- if (empty($this->cellform) && $this->size == 'large') {
- $out[] = hed($theday,4);
- }
- $evcnt = 0;
- if( isset($this->events[$theday]) ) {
- $days_events = $this->events[$theday];
- foreach($days_events as $ev) {
- $evclass = $ev['classes'];
- $evid[] = $ev['evid'];
- $flags = array_merge($flags, $ev['flag']);
- if (in_array("cellplus", $this->cls_lev)) {
- $runningclass = array_merge($runningclass, $evclass);
- }
- $cls = ($evclass && in_array("event", $this->cls_lev)) ? ' class="'.join(' ', $evclass).'"' : '';
- $op = ($this->evwraptag) ? tag($ev['ev'], $this->evwraptag, $cls) : $ev['ev'];
- foreach ($ev['flag'] as $flev) {
- $fout[$flev][] = $op;
- }
- $out[] = $op;
- $evcnt++;
- if ($this->size == 'small' && $evcnt == 1) {
- break;
- }
- }
- } elseif ($this->size == 'small') {
- $out[] = hed($theday,4);
- }
- // Amalgamate the event-level classes and cell-level classes if required
- $runningclass = array_unique($runningclass);
- if (in_array("cellplus", $this->cls_lev)) {
- $smd_cal_flag = array_merge($smd_cal_flag, $flags);
- }
- if ($this->cellform) {
- $thistime = mktime(0, 0, 0, $this->month, $theday, $this->year);
- $smd_calinfo['id'] = $this->tableID;
- $smd_date['y'] = $this->year;
- $smd_date['m'] = $this->month;
- $smd_date['w'] = strftime(smd_cal_reformat_win('%V', $thistime), $thistime);
- $smd_date['iy'] = strftime(smd_cal_reformat_win('%G', $thistime), $thistime);
- $smd_date['d'] = $theday;
- $reps = array(
- '{evid}' => join($this->event_delim, $evid),
- '{standard}' => join('',$fout['standard']),
- '{recur}' => join('',$fout['recur']),
- '{recurfirst}' => join('',$fout['recurfirst']),
- '{allrecur}' => join('',array_merge($fout['recur'], $fout['recurfirst'])),
- '{multifirst}' => join('',$fout['multifirst']),
- '{multiprev}' => join('',$fout['multiprev']),
- '{multi}' => join('',$fout['multilast']),
- '{multilast}' => join('',$fout['multilast']),
- '{allmulti}' => join('',array_merge($fout['multifirst'],$fout['multi'],$fout['multiprev'],$fout['multilast'])),
- '{cancel}' => join('',$fout['cancel']),
- '{extra}' => join('',$fout['extra']),
- '{events}' => join('',$out),
- '{numevents}' => $evcnt,
- '{day}' => $theday,
- '{dayzeros}' => str_pad($theday, 2, '0', STR_PAD_LEFT),
- '{weekday}' => ((is_array($this->dayNameFmt)) ? $this->dayNames[date('w',$thistime)] : strftime($this->dayNameFmt, $thistime)),
- '{weekdayabbr}' => strftime('%a', $thistime),
- '{weekdayfull}' => strftime('%A', $thistime),
- '{week}' => $smd_date['w'],
- '{month}' => $this->month,
- '{monthzeros}' => str_pad($this->month, 2, '0', STR_PAD_LEFT),
- '{monthname}' => ((is_array($this->mthNameFmt)) ? $this->mthNames[date('n',$thistime)] : strftime($this->mthNameFmt, $thistime)),
- '{monthnameabbr}' => strftime('%b', $thistime),
- '{monthnamefull}' => strftime('%B', $thistime),
- '{year}' => $this->year,
- '{shortyear}' => strftime('%y', $thistime),
- '{isoyear}' => $smd_date['iy'],
- '{shortisoyear}' => strftime(smd_cal_reformat_win('%g', $thistime), $thistime),
- );
- $cellout = parse(strtr($this->cellform, $reps));
- $carray = array_merge($runningclass, $smd_cal_ucls);
- $smd_cal_ucls = array();
- return doTag($cellout,'td',join(' ',$carray));
- } else {
- return doTag(join('',$out),'td',join(' ',$runningclass));
- }
- }
- function display($static=false) {
- $sum = ($this->tblSummary) ? ' summary="'.$this->tblSummary.'"' : '';
- $id = ($this->tableID) ? ' id="'.$this->tableID.'"' : '';
- $c[] = ($this->tblCaption) ? '<caption>'.$this->tblCaption.'</caption>' : '';
- $c[] = '<thead>';
- $c[] = $this->dspHeader($static);
- $c[] = $this->dspDayNames();
- $c[] = '</thead>';
- $c[] = $this->dspDayCells();
- return doTag(join('',$c),'table',$this->tableclass,$sum.$id);
- }
- function dspHeader($static) {
- global $pretext, $smd_calinfo, $permlink_mode;
- $currmo = $this->month;
- $curryr = $this->year;
- $navpclass = $this->getNavInfo("pc");
- $navnclass = $this->getNavInfo("nc");
- $navparrow = $this->getNavInfo("pa");
- $navnarrow = $this->getNavInfo("na");
- $navid = $this->getNavInfo("id");
- $navpclass = ($navpclass) ? ' class="'.$navpclass.'"' : '';
- $navnclass = ($navnclass) ? ' class="'.$navnclass.'"' : '';
- $fopts = $this->fopts;
- $sec = (isset($smd_calinfo['s']) && !empty($smd_calinfo['s'])) ? $smd_calinfo['s'] : '';
- foreach ($this->maintain as $col) {
- switch ($col) {
- case "section":
- if ($pretext['s'] && $permlink_mode != 'year_month_day_title') {
- $fopts = array('s' => $pretext['s']) + $fopts;
- }
- break;
- case "article":
- if ($pretext['id']) {
- $fopts = array('id' => $pretext['id']) + $fopts;
- }
- break;
- case "category":
- if ($pretext['c']) {
- $fopts = array('c' => $pretext['c']) + $fopts;
- }
- break;
- case "author":
- if (gps('author')) {
- $fopts = array('author' => gps('author')) + $fopts;
- }
- break;
- case "date":
- if (gps('date')) {
- $fopts = array('date' => gps('date')) + $fopts;
- }
- break;
- case "pg":
- if ($pretext['pg']) {
- $fopts = array('pg' => $pretext['pg']) + $fopts;
- }
- break;
- case "calid":
- if ($this->tableID) {
- $fopts = array('calid' => $this->tableID) + $fopts;
- }
- break;
- default:
- if (gps($col)) {
- $fopts = array($col => gps($col)) + $fopts;
- }
- break;
- }
- }
- $fopts = array_unique($fopts);
- $filters = array();
- $filterHid = array();
- if (!$static) {
- foreach($fopts as $key => $val) {
- $filters[] = $key.'='.$val;
- $filterHid[] = hInput($key, $val);
- }
- }
- // Week select list
- if ($this->useSelector('week') && !$static) {
- $currwk = ($this->week) ? $this->week : date('W', safe_strtotime($curryr."-".$currmo."-1 12:00"));
- for ( $idx = 1; $idx <= 53; $idx++ ) {
- $tagatts = ' value="'.$idx.'"';
- if ( $idx == $currwk ) $tagatts .= ' selected="selected"';
- $optiontags[] = doTag($this->selpfx['week'].str_pad($idx, 2, '0', STR_PAD_LEFT).$this->selsfx['week'], 'option', '', $tagatts);
- }
- $selector[] = doTag(join(n, $optiontags), 'select', (($this->mywraptag) ? '' : $this->myclass), ' name="'.$this->remap['w'].'"'.(($this->selbtn) ? '' : ' onchange="this.form.submit()"'), '')
- . (($this->useSelector('year')) ? '' : hInput($this->remap['y'], $curryr));
- $optiontags = array(); // Blank out
- }
- // Month select list - note mktime has the day forced to 1. If not you get
- // bizarre repeated month names on the 31st of some months :-\
- if (!$this->useSelector('week')) {
- if ($this->useSelector('month') && !$static) {
- for ( $idx = 1; $idx <= 12; $idx++ ) {
- $tagatts = ' value="'.$idx.'"';
- if ( $idx == $currmo ) $tagatts .= ' selected="selected"';
- $optiontags[] = doTag($this->selpfx['month'].((is_array($this->mthNameFmt)) ? $this->mthNames[date('n',mktime(12,0,0,$idx,1))] : safe_strftime($this->mthNameFmt, mktime(12,0,0,$idx,1) )).$this->selsfx['month'], 'option', '', $tagatts);
- }
- $selector[] = doTag(join(n, $optiontags), 'select', (($this->mywraptag) ? '' : $this->myclass), ' name="'.$this->remap['m'].'"'.(($this->selbtn) ? '' : ' onchange="this.form.submit()"'), '')
- . (($this->useSelector('year')) ? '' : hInput($this->remap['y'], $curryr));
- $optiontags = array(); // Blank out
- } else {
- $selector[] = doTag($this->getMonthName(), 'span', (($this->mywraptag) ? '' : $this->myclass));
- }
- }
- // Year select list
- $y0 = $this->eyr;
- $y1 = $this->lyr;
- if ($this->useSelector('year') && ($y0 != $y1) && !$static) {
- for ( $idx = $y0; $idx <= $y1; $idx++ ) {
- $tagatts = ' value="'.$idx.'"';
- if ( $idx == $curryr ) $tagatts .= ' selected="selected"';
- $optiontags[] = doTag($this->selpfx['year'].$idx.$this->selsfx['year'], 'option', '', $tagatts);
- }
- $selector[] = doTag(join(n, $optiontags), 'select', (($this->mywraptag) ? '' : $this->myclass), ' name="'.$this->remap['y'].'"'.(($this->selbtn) ? '' : ' onchange="this.form.submit()"'), '')
- . (($this->useSelector('month') || $this->useSelector('week')) ? '' : hInput($this->remap['m'], $currmo));
- } else {
- $selector[] = doTag($curryr, 'span', (($this->mywraptag) ? '' : $this->myclass));
- }
- $request = serverSet('REQUEST_URI');
- $redirect = serverSet('REDIRECT_URL');
- if (!empty($redirect) && ($request != $redirect) && is_callable('_l10n_set_browse_language')) {
- // MLP in da house: use the redirect URL instead
- $request = $redirect;
- }
- $urlp = parse_url($request);
- $action = $urlp['path'];
- if ($permlink_mode == 'messy') {
- $out = makeOut('id','s','c','q','pg','p','month');
- foreach($out as $key => $val) {
- if ($val) {
- $filters[] = $key.'='.$val;
- $filterHid[] = hInput($key, $val);
- }
- }
- }
- $filterHid = array_unique($filterHid);
- $filters = array_unique($filters);
- $extras = '';
- if (!$static && ( $this->useSelector('month') || $this->useSelector('year') )) {
- if ($this->selbtn) {
- $extras .= doTag('', 'input', 'smd_cal_input', ' type="submit" value="'.$this->selbtn.'"');
- }
- $extras .= join(n, $filterHid);
- }
- $selector = '<form action="'.$action.'" method="get"'.(($navid) ? ' id="'.$navid.'"' : '').'>'.doTag(join(sp, $selector).$extras, $this->mywraptag, $this->myclass).'</form>';
- $nav_back_link = $this->navigation($curryr, $currmo, '-', $filters, $urlp['path']);
- $nav_fwd_link = $this->navigation($curryr, $currmo, '+', $filters, $urlp['path']);
- $nav_back = (!$static && $nav_back_link) ? '<a href="'.$nav_back_link.'"'.$navpclass.'>'.$navparrow.'</a>' : ' ';
- $nav_fwd = (!$static && $nav_fwd_link) ? '<a href="'.$nav_fwd_link.'"'.$navnclass.'>'.$navnarrow.'</a>' : ' ';
- $c[] = doTag($nav_back,'th');
- $c[] = '<th colspan="'.(($this->showISOWeek) ? 6 : 5).'">'.$selector.'</th>';
- $c[] = doTag($nav_fwd,'th');
- return doTag(join('',$c),'tr', 'smd_cal_navrow');
- }
- function navigation($year,$month,$direction,$flt,$url='') {
- global $permlink_mode;
- if($direction == '-') {
- if($month - 1 < 1) {
- $month = 12;
- $year -= 1;
- } else {
- $month -= 1;
- }
- } else {
- if($month + 1 > 12) {
- $month = 1;
- $year += 1;
- } else {
- $month += 1;
- }
- }
- // Abort if we're about to go out of range
- if ($year < $this->eyr || $year > $this->lyr) {
- return '';
- }
- $flt[] = $this->remap['m']."=$month";
- $flt[] = $this->remap['y']."=$year";
- return $url . "?" . join(a, $flt);
- }
- }
- /**
- * Basic Calendar data and display
- * http://www.oscarm.org/static/pg/calendarClass/
- * @author Oscar Merida
- * @created Jan 18 2004
- */
- class SMD_Raw_Calendar {
- var $gmt = 1, $lang, $debug = 0;
- var $year, $eyr, $lyr, $month, $week;
- var $dayNameFmt, $mthNameFmt, $dayNames, $mthNames, $startDay, $endDay, $firstDayOfWeek = 0, $startOffset = 0;
- var $selectors, $selbtn, $selpfx, $selsfx;
- var $showISOWeek, $ISOWeekHead, $ISOWeekCell;
- var $cls_lev, $cls_pfx, $fopts;
- var $evwraptag, $mywraptag;
- var $rowclass, $cellclass, $emptyclass, $isoclass, $myclass, $tableID, $tblSummary, $tblCaption;
- var $navpclass, $navnclass, $navparrow, $navnarrow, $navid;
- var $holidays, $cellform, $hdrform, $maintain, $remap;
- var $event_delim;
- /**
- * Constructor
- *
- * @param integer, year
- * @param integer, month
- * @return object
- * @public
- */
- function SMD_Raw_Calendar ($yr, $mo, $debug=0) {
- $this->setDebug($debug);
- $this->setYear($yr);
- $this->setMonth($mo);
- $this->setClassPrefix('smd_cal_');
- $this->startTime = strtotime( "$yr-$mo-01 00:00" );
- $this->startDay = date( 'D', $this->startTime );
- $this->endDay = date( 't', $this->startTime );
- $this->endTime = strtotime( "$yr-$mo-".$this->endDay." 23:59:59" );
- if ($this->debug) {
- echo "++ THIS MONTH'S RENDERED CALENDAR [ start stamp // end date // start day // end stamp // end date // end day number ] ++";
- dmp($this->startTime, date('Y-m-d H:i:s', $this->startTime), $this->startDay, $this->endTime, date('Y-m-d H:i:s', $this->endTime), $this->endDay);
- }
- $this->setNameFormat('%a', 'd');
- $this->setNameFormat('%B', 'm');
- $this->setFirstDayOfWeek(0);
- $this->setShowISOWeek('');
- $this->setTableID('');
- $this->setTableClass('');
- }
- // === end Calendar ===
- // Getters
- function useSelector($val) { return in_array($val, $this->selectors); }
- function getDayName($day) { return ($this->dayNames[$day%7]); }
- function getMonthName() {
- if (is_array($this->mthNameFmt)) {
- return $this->mthNames[date('n',$this->startTime)];
- } else {
- return strftime($this->mthNameFmt, $this->startTime);
- }
- }
- function getNavInfo($type) {
- $r = '';
- switch ($type) {
- case "id": $r = $this->navid; break;
- case "pc": $r = $this->navpclass; break;
- case "nc": $r = $this->navnclass; break;
- case "pa": $r = $this->navparrow; break;
- case "na": $r = $this->navnarrow; break;
- }
- return $r;
- }
- // Setters
- function setDebug($d){ $this->debug = $d; }
- function setGMT($b){ $this->gmt = $b; }
- function setLang($code){ $this->lang = $code; }
- function setSummary($txt){ $this->tblSummary = $txt; }
- function setCaption($txt){ $this->tblCaption = $txt; }
- function setCellForm($frm){ $this->cellform = $frm; }
- function setHdrForm($frm){ $this->hdrform = $frm; }
- function setTableID($id){ $this->tableID = $id; }
- function setYear($yr){ $this->year = $yr; }
- function setEYear($yr){ $this->eyr = $yr; }
- function setLYear($yr){ $this->lyr = $yr; }
- function setMonth($mth){ $this->month = (int)$mth; }
- function setWeek($wk){
- if ($wk) {
- $wk = str_pad($wk, 2, '0', STR_PAD_LEFT);
- $this->week = $wk;
- $this->month = safe_strftime("%m", strtotime($this->year."W".$wk));
- }
- }
- function setNavKeep($ar){ $this->maintain = $ar; }
- function setShowISOWeek($val) {
- $this->showISOWeek = ($val) ? true : false;
- if ($val) {
- $val = do_list($val);
- $this->ISOWeekHead = $val[0];
- $this->ISOWeekCell = (isset($val[1])) ? $val[1] : '{week}';
- }
- }
- function setRemap($map){ $this->remap = $map; }
- function setClassLevels($cls){ $this->cls_lev = $cls; }
- function setClassPrefix($cls){ $this->cls_pfx = $cls; }
- function setEventWraptag($wrap){ $this->evwraptag = $wrap; }
- function setMYWraptag($wrap){ $this->mywraptag = $wrap; }
- function setTableClass($cls) { $this->tableclass = ($cls) ? $this->cls_pfx.$cls : ''; }
- function setRowClass($cls){ $this->rowclass = ($cls) ? $this->cls_pfx.$cls : ''; }
- function setCellClass($cls){ $this->cellclass = ($cls) ? $this->cls_pfx.$cls : ''; }
- function setEmptyClass($cls){ $this->emptyclass = ($cls) ? $this->cls_pfx.$cls : ''; }
- function setISOWeekClass($cls){ $this->isoclass = ($cls) ? $this->cls_pfx.$cls : ''; }
- function setDelim($dlm){ $this->event_delim = $dlm; }
- function setNavInfo($clsp, $clsn, $arrp, $arrn, $nid){
- $this->navpclass = ($clsp) ? $this->cls_pfx.$clsp : '';
- $this->navnclass = ($clsn) ? $this->cls_pfx.$clsn : '';
- $this->navparrow = ($arrp) ? $arrp : '';
- $this->navnarrow = ($arrn) ? $arrn : '';
- $this->navid = ($nid) ? $this->cls_pfx.$nid : '';
- }
- function setMYClass($cls){ $this->myclass = ($cls) ? $this->cls_pfx.$cls : ''; }
- function setFilterOpts($f) { $this->fopts = $f; }
- function setHolidays($hols) { $this->holidays = $hols; }
- function setSelectors($sel, $btn) {
- foreach ($sel as $idx => $item) {
- $selparts = explode(":", $item);
- $sel[$idx] = $selparts[0];
- $this->selpfx[$selparts[0]] = (isset($selparts[1])) ? $selparts[1] : '';
- $this->selsfx[$selparts[0]] = (isset($selparts[2])) ? $selparts[2] : '';
- }
- $this->selectors = $sel;
- $this->selbtn = $btn;
- }
- function setFirstDayOfWeek($d) {
- $this->firstDayOfWeek = ((int)$d <= 6 and (int)$d >= 0) ? (int)$d : 0;
- $this->startOffset = date('w', $this->startTime) - $this->firstDayOfWeek;
- if ( $this->startOffset < 0 ) {
- $this->startOffset = 7 - abs($this->startOffset);
- }
- }
- /**
- * frm: any valid PHP strftime() string or ABBR/FULL
- * typ: d to set day, m to set month format
- */
- function setNameFormat($frm, $typ="d") {
- switch ($frm) {
- case "full":
- case "FULL":
- $fmt = ($typ == 'd') ? "%A" : "%B";
- break;
- case "abbr":
- case "ABBR":
- $fmt = ($typ == 'd') ? "%a" : "%b";
- break;
- default:
- if (strpos($frm, '%') === 0) {
- $fmt = $frm;
- } else {
- $frm = trim($frm, '{}');
- $frm = do_list($frm);
- $fmt = $frm;
- }
- break;
- }
- if ($typ == "d") {
- $this->dayNameFmt = $fmt;
- $this->dayNames = array();
- // This is done to make sure Sunday is always the first day of our array
- $start = 0;
- $end = $start + 7;
- $sunday = strtotime('1970-Jan-04 12:00:00');
- for($i=$start; $i<$end; $i++) {
- if (is_array($fmt)) {
- $this->dayNames[] = $fmt[$i-$start];
- } else {
- $this->dayNames[] = ucfirst(strftime($fmt, ($sunday + (86400*$i))));
- }
- }
- } else {
- $this->mthNameFmt = $fmt;
- $this->mthNames = array();
- for ($i=0; $i<12; $i++) {
- if (is_array($fmt)) {
- $this->mthNames[$i+1] = $fmt[$i];
- }
- }
- }
- }
- /**
- * Return markup for displaying the calendar.
- * @return
- * @public
- */
- function display ( ) {
- $id = ($this->tableID) ? ' id="'.$this->tableID.'"' : '';
- $c[] = '<table'.$id.'>';
- $c[] = '<thead>' . $this->dspDayNames() . '</thead>';
- $c[] = $this->dspDayCells();
- $c[] = '</table>';
- return join('',$c);
- }
- /…
Large files files are truncated, but you can click here to view the full file