function amr_events_as_calendar($liststyle, $events, $id, $class = '', $initial = true) { /* startingpoint was wp calendar */ global $amr_options, $amr_listtype, $amr_limits, $amrW; global $amr_globaltz; global $change_view_allowed; global $wpdb, $wp_locale; global $amr_calendar_url; global $amr_event_columns; //20151018 $empty = ' '; $link = amr_get_day_link_stem(); // get the daylink stem // --- Note that if months set, then events will have started from beg of month */ $months = 1; $weeks = 2; // as default if (isset($amr_limits['months'])) { $months = $amr_limits['months']; //may need later on if we are going to show multiple boxes on one page $weeks = 0; } else { if (isset($amr_limits['weeks'])) { $weeks = $amr_limits['weeks']; $months = 0; } } // testing //$weeks = 2; // need weeks =2 else miss early ones // Let's figure out when we are $start = amr_newDateTime(); $today_day = $start->format('j'); $today_month = $start->format('m'); $today_year = $start->format('Y'); $start = clone $amr_limits['start']; $thismonth = $start->format('m'); $thisyear = $start->format('Y'); if (!($liststyle === 'weekscalendar')) { $start->setDate($thisyear, $thismonth, 1); } else { $start->setDate($thisyear, $thismonth, $start->format('j')); } // what was asked for in url (in case using small calendar as a selector ) if (!empty($_GET['start']) and is_numeric($_GET['start'])) { $selected_day = substr($_GET['start'], 6, 2); $selected_month = substr($_GET['start'], 4, 2); $selected_year = substr($_GET['start'], 0, 4); } else { $selected_day = $today_day; $selected_month = $today_month; $selected_year = $today_year; } $events = amr_check_for_multiday_events($events); // now have dummy multi day events added and field dummyYMD to use if (!($liststyle === 'weekscalendar')) { $bunchesofevents = amr_get_events_in_months_format($events, $months, $start); } else { $bunchesofevents = amr_get_events_in_weeks_format($events, $weeks, $start); } if ($liststyle === 'weekscalendar') { if (!empty($amr_options['listtypes'][$amr_listtype]['format']['Day'])) { $caption_format = $amr_options['listtypes'][$amr_listtype]['format']['Day']; } else { $caption_format = 'j M'; } } else { if (!empty($amr_options['listtypes'][$amr_listtype]['format']['Month'])) { $caption_format = $amr_options['listtypes'][$amr_listtype]['format']['Month']; } else { $caption_format = 'F,Y'; } } // if ( isset($_GET['w']) ) $w = ''.intval($_GET['w']); /* what sthis for ?*/ // week_begins = 0 stands for Sunday $week_begins = intval(get_option('start_of_week')); if ($liststyle == 'smallcalendar') { // for compatibility with wordpress default $class = ' widget_calendar '; } if (empty($class)) { $class = $liststyle; } else { $class = $class . ' ' . $liststyle . ' '; } if (!empty($amr_limits['show_views']) and $change_view_allowed) { $views = amrical_calendar_views(); } else { $views = ''; } $html = $views; $calendar_output = ''; $multi_output = ''; if (empty($amr_limits['show_month_nav'])) { $navigation = ''; $tfoot = ''; } else { $navigation = amr_calendar_navigation($start, $months, $weeks, $liststyle); // include month year dropdown with links if ($liststyle == 'smallcalendar' and $months < 2) { $tfoot = '<tfoot><tr><td class="calendar_navigation" colspan="7">' . $navigation . '</td></tr></tfoot>'; } else { $tfoot = ''; $html .= '<div class="calendar_navigation">' . $navigation . '</div>'; } } $columns = $amr_event_columns; // 20151018 add so we can use easily//prepare_order_and_sequence ($amr_options['listtypes'][$amr_listtype]['compprop']); //var_dump($columns); if (empty($columns)) { return; } // now do for each month or week------------------------------------------------------------------------------------------------------- if (isset($_GET['debugwks'])) { echo '<br />Bunches of events = ' . count($bunchesofevents) . '<br />'; } foreach ($bunchesofevents as $ym => $bunchevents) { //also for weeks $thismonth = substr($ym, 4, 2); $thisyear = substr($ym, 0, 4); if (!($liststyle === 'weekscalendar')) { $start->setDate($thisyear, $thismonth, 1); } else { $start->setDate($thisyear, $thismonth, $start->format('j')); } if (ICAL_EVENTS_DEBUG) { echo '<br />' . $ym; } if (isset($_GET['debugwks'])) { echo '<br />weeks = ' . $weeks . ' ' . $start->format('c'); } $dayheaders = '<tr class="dayheaders">' . amr_calendar_colheaders($liststyle, $start) . '</tr>'; if ($liststyle === 'weekscalendar') { // then cannot use thead as can only have one thead per table- else is data $calendar_caption = apply_filters('amr_events_table_caption', amr_weeks_caption($start)); if (!empty($calendar_caption)) { $calendar_caption = '<tr class="caption"><th colspan="7">' . $calendar_caption . '</th></tr>'; } $calendar_output .= '<tbody>'; $calendar_output .= $dayheaders; } else { $calendar_caption = apply_filters('amr_events_table_caption', amr_date_i18n($caption_format, $start)); if (!empty($calendar_caption)) { $calendar_caption = '<caption>' . $calendar_caption . '</caption>'; } $calendar_output .= '<table ' . $id . ' class="' . $class . '" >' . $calendar_caption; $calendar_output .= '<thead>' . $dayheaders . '</thead>' . $tfoot . '<tbody>'; } // Get days with events $titles = array(); $eventsfortheday = array(); $dayswithevents = array(); if (ICAL_EVENTS_DEBUG) { echo '<br />Bunch events count=' . count($bunchevents); } if (!empty($bunchevents)) { // NOTE SINGULAR month // get the titles and events for each day $bunchevents = amr_sort_by_two_cols('dummytime', 'MultiDay', $bunchevents); //20140805 foreach ($bunchevents as $event) { // convert eventdate to display timezone now for day of month assignment, other dates will be // converted to display timezone at display time. if (empty($event['EventDate'])) { continue; } // if no date, we cannot display anywhere if (isset($event['dummyYMD'])) { //$month = $event['EventDate']->format('m'); //$month = substr($event['dummyYMD'],4,2); // quicker? //if (isset($_GET['debugwks'])) {echo '<br />Do we need monts=thismonth check?'.$month.' '.$thismonth;} //if ($month == $thismonth) { // this allows to have agenda with more months and events cached //$day = $event['dummyYMD']->format('j'); $day = ltrim(substr($event['dummyYMD'], 6, 2), '0'); // quicker? $dayswithevents[] = $day; // replace with listtype format $title = ''; if (isset($event['SUMMARY'])) { $title = $event['SUMMARY']; } if (is_array($title)) { $title = implode($title); } $titles[$day][] = $title; // $eventsfortheday[$day][] = $event; // } } } } if (isset($dayswithevents)) { $dayswithevents = array_unique($dayswithevents); } if (!($liststyle === 'smallcalendar') or !function_exists('amr_events_customisable_small_calendar_daytitles')) { $daytitles = amr_prepare_day_titles($titles, $liststyle); } // for large hover? unset($titles); //----------------------------------------------------------------------------------- if (!empty($eventsfortheday)) { if (ICAL_EVENTS_DEBUG) { echo ' we have ' . count($eventsfortheday) . ' days of events'; } foreach ($eventsfortheday as $day => $devents) { if (ICAL_EVENTS_DEBUG) { echo '<br />Day =' . $day . ' with ' . count($devents) . ' events '; } $dayhtml[$day] = amr_list_one_days_events($devents, $columns); if (function_exists('amr_events_customisable_small_calendar_daytitles') and $liststyle === 'smallcalendar') { $daytitles[$day] = amr_events_customisable_small_calendar_daytitles($devents, $columns); } //if (isset($_GET['debugwks'])) echo '<br />Day: '.$day.' '.$dayhtml[$day]; } } unset($eventsfortheday); // else echo 'EMPTY events forday'; /* ------See how much we should pad in the beginning */ $week = 1; $calendar_output .= "\n\t" . '<tr class="week week1">'; //----------------------------------------------------------------------------------- if ($liststyle === 'weekscalendar') { //if (isset ($weeks)) { $day1 = $start->format('j'); // set to start of week //The day of the month without leading zeros (1 to 31) //$daysinbunch = $day1+6; $daysinbunch = 7; } else { $pad = calendar_week_mod($start->format('w') - $week_begins); if (0 != $pad) { $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr($pad) . '" class="pad">' . $empty . '</td>'; } $day1 = 1; $daysinbunch = $start->format('t'); //The number of days in the given month } if (isset($_GET['debugwks'])) { echo '<br />Day 1= ' . $day1; } $newrow = false; $nextdate = new Datetime(); //if cloning dont need tz $nextdate = clone $start; // for ( $day = $day1; $day <= $daysinbunch; ++$day ) { for ($i = 1; $i <= $daysinbunch; $i += 1) { if (isset($_GET['debugwks'])) { echo '<br />i = ' . $i; } // $calendar_output .= amr_handle_each_day ($thisyear, $thismonth, $day, $daytitles, $dayswithevents,$dayhtml); if (isset($newrow) && $newrow) { if ($week > 1) { // then we need to end the previous row $calendar_output .= AMR_NL . '</tr>'; $calendar_output .= AMR_NL . '<tr class="week week' . $week . '">' . AMR_NL; } //else echo 'new row but $week = '.$week; } $newrow = false; $lastinrow = ''; // check if after this we need a new row eg if month calendar// // if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) { if (6 == calendar_week_mod($nextdate->format('w') - $week_begins)) { $newrow = true; $lastinrow = ' endweek'; $week = $week + 1; // helps to balance out the multi month view } /* wp code - can't we do better ? */ //$datestring = $day.'-'.$thismonth.'-'.$thisyear; // must use hyphens for uk english dates, else it goes US //$dow = date('N',strtotime($datestring)); // does not like dates earlier than 1902 $dow = $nextdate->format('N'); $thisyear = $nextdate->format('Y'); $thismonth = $nextdate->format('m'); $day = $nextdate->format('j'); $hasevents = ''; if (!empty($amr_limits['day_links']) and $amr_limits['day_links'] and !empty($daytitles[$day])) { // then we have events for that day, so can link to it $hasevents = ' hasevents '; $daylink = '<a class="daylink" href="' . htmlentities(amr_get_day_link($thisyear, $thismonth, $day, $link)) . '" title="' . $daytitles[$day] . '">' . $day . '</a>'; } else { $daylink = $day; } if ($day == $today_day && $thismonth == $today_month && $thisyear == $today_year) { $today = ' today '; } else { $today = ''; } if ($day == $selected_day && $thismonth == $selected_month && $thisyear == $selected_year) { $selected = ' selected '; } else { $selected = ''; } $calendar_output .= '<td class="day' . $dow . $today . $selected . $hasevents . $lastinrow . '">'; if (!($liststyle === 'weekscalendar')) { $calendar_output .= '<div class="day">' . $daylink . '</div>'; } if (!empty($dayswithevents) and in_array($day, $dayswithevents)) { // any posts today? if (isset($_GET['debugwks'])) { echo '<br />Day=' . $day; } // if (($liststyle == 'largecalendar') if (in_array($liststyle, array('largecalendar', 'weekscalendar')) and !empty($dayhtml[$day])) { $calendar_output .= AMR_NL . $dayhtml[$day]; } } else { $calendar_output .= $empty; //' '; } $calendar_output .= '</td>'; date_modify($nextdate, '+1 day'); } // now check if we need to pad to the end of the week // $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); $pad = 6 - calendar_week_mod($dow - $week_begins); if ($pad != 0 && $pad != 7) { $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr($pad) . '"> ' . '</td>'; } else { $week = $week - 1; } if ($months > 1 and $liststyle == 'smallcalendar') { // pad so that they will all line up nicely in the multiview for ($w = $week; $week <= 5; ++$week) { $calendar_output .= "\n\t" . '</tr><tr><td class="pad" colspan="7" > </td>' . "\n\t"; } } if ($liststyle === 'weekscalendar') { $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t"; } else { $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; } $multi_output .= $calendar_output; $calendar_output = ''; if (isset($weeks)) { date_modify($start, '+7 days'); } else { date_modify($start, '+1 month'); } } // for each bunch (eg month?) if ($liststyle === 'weekscalendar') { // if we are doing weekly, we want only one table so all will line up $multi_output = '<table ' . $id . ' class="' . $class . '" >' . $multi_output . '</table><!-- end weekly table -->'; } $html .= $multi_output; return $html; }
function amr_format_date($format, $datestamp) { /* want a integer timestamp or a date object */ global $amr_options, $amr_globaltz; //if (is_string($datestamp)) $datestamp = date_create($datestamp, $amr_globaltz); if (isset($amr_options['date_localise'])) { $method = $amr_options['date_localise']; } else { $method = 'wp'; } // v4.0.9 was none date_timezone_set($datestamp, $amr_globaltz); /* Converting here, but then some derivations wrong eg: unsetting of end date */ if (isset($_GET['tzdebug'])) { echo '<br />' . $datestamp->format('c'); } if ($method === 'wp') { return amr_wp_format_date($format, $datestamp, false); } else { if ($method === 'wpgmt') { return amr_wp_format_date($format, $datestamp, true); } else { if ($method === 'amr') { return amr_date_i18n($format, $datestamp); } else { if (stristr($format, '%')) { return strftime($format, $datestamp->format('U')); } else { return $datestamp->format($format); } } } } }
function amr_ical_general_form() { global $amr_csize, $amr_calprop, $amr_formats, $amr_limits, $amr_compprop, $amr_groupings, $amr_components, $amr_options, $amr_globaltz; $amr_options = amr_getset_options(false); $amr_ical_image_settings = get_option('amr-ical-images-to-use'); if (empty($amr_ical_image_settings['images_size'])) { $imagesize = '16'; } else { $imagesize = (int) $amr_ical_image_settings['images_size']; } $gentext = __('General Options', 'amr-ical-events-list'); $styletext = __('Styling and Images', 'amr-ical-events-list'); $advtext = __('Advanced', 'amr-ical-events-list'); $managetext = __('Manage Event List Types', 'amr-ical-events-list'); echo '<div> <a title="' . $gentext . '" href="#amrglobal">' . $gentext . '</a> | ' . '<a title="' . $styletext . '" href="#amrstyle">' . $styletext . '</a> | ' . '<a title="' . $advtext . '" href="#amradvanced">' . $advtext . '</a> | ' . '<a title="' . $managetext . '" href="' . admin_url('admin.php?page=manage_event_listing') . '">' . $managetext . '</a> <fieldset id="amrglobal"><h3>' . $gentext . '</h3>'; echo '<div class="postbox" style="padding:1em 2em; width: 600px;"> <label for="noeventsmessage">'; _e('Message if no events found: ', 'amr-ical-events-list'); ?> </label><br /> <input class="wide regular-text" type="text" id="noeventsmessage" name="noeventsmessage" <?php if (isset($amr_options['noeventsmessage']) and $amr_options['noeventsmessage']) { echo 'value="' . $amr_options['noeventsmessage'] . '"'; } ?> /> <br /> <label for="lookmoresmessage"> <?php _e('Look for more events message: ', 'amr-ical-events-list'); ?> </label><br /> <input class="wide regular-text" type="text" id="lookmoremessage" name="lookmoremessage" <?php if (isset($amr_options['lookmoremessage']) and $amr_options['lookmoremessage']) { echo 'value="' . $amr_options['lookmoremessage'] . '"'; } ?> /> <br /> <label for="lookprevmessage"> <?php _e('Look for previous events message: ', 'amr-ical-events-list'); ?> </label><br /> <input class="wide regular-text" type="text" id="lookprevmessage" name="lookprevmessage" <?php if (isset($amr_options['lookprevmessage']) and $amr_options['lookprevmessage']) { echo 'value="' . $amr_options['lookprevmessage'] . '"'; } ?> /> <br /> <label for="resetmessage"> <?php _e('Reset events message: ', 'amr-ical-events-list'); ?> </label><br /> <input class="wide regular-text" type="text" id="resetmessage" name="resetmessage" <?php if (isset($amr_options['resetmessage']) and $amr_options['resetmessage']) { echo 'value="' . $amr_options['resetmessage'] . '"'; } ?> /> <br /> <label for="freebusymessage"> <?php _e('Free busy text: ', 'amr-ical-events-list'); _e(' - replaces the summary text (Busy)in a VFREEBUSY component.', 'amr-ical-events-list'); ?> </label><br /> <input class="wide regular-text" type="text" id="freebusymessage" name="freebusymessage" <?php if (isset($amr_options['freebusymessage']) and $amr_options['freebusymessage']) { echo 'value="' . $amr_options['freebusymessage'] . '"'; } ?> /> <br /> <label for="usehumantime"> <input type="checkbox" id="usehumantime" name="usehumantime" value="usehumantime" <?php if (isset($amr_options['usehumantime']) and $amr_options['usehumantime']) { echo 'checked="checked"'; } ?> /> <?php _e('Use human time like midday, midnight', 'amr-ical-events-list'); ?> </label> <label for="ngiyabonga"> <input type="checkbox" id="ngiyabonga" name="ngiyabonga" value="ngiyabonga" <?php if (isset($amr_options['ngiyabonga']) and $amr_options['ngiyabonga']) { echo 'checked="checked"'; } ?> /> <?php _e('Do not give credit to the author', 'amr-ical-events-list'); ?> </label> </div> </fieldset> <fieldset id="amrstyle"><h3><?php echo $styletext; ?> </h3> <div class="postbox" style="padding:1em 2em; width: 600px;"> <label for="do_groupingjs"> <input type="checkbox" id="do_grouping_js" name="do_grouping_js" value="do_grouping_js" <?php if (!empty($amr_options['do_grouping_js']) and $amr_options['do_grouping_js']) { echo 'checked="checked"'; } ?> /> <?php _e('Use javascript to collapse event groupings', 'amr-ical-events-list'); ?> </label> <br /> <label for="own_css"> <input type="checkbox" id="own_css" name="own_css" value="own_css" <?php if (isset($amr_options['own_css']) and $amr_options['own_css']) { echo 'checked="checked"'; } ?> /> <?php _e('Use my theme css, not plugin css', 'amr-ical-events-list'); $files = amr_get_css_url_choices(); ?> </label> <br /> <label for="no_images"> <input type="checkbox" id="no_images" name="no_images" value="true" <?php if (isset($amr_options['no_images']) and $amr_options['no_images']) { echo 'checked="checked"'; } ?> /><?php _e(' No images (tick for text only)', 'amr-ical-events-list'); ?> </label> <br /> <br /> <label for="images_size16"> <?php _e('Image icon size:', 'amr-ical-events-list'); ?> <input type="radio" id="images_size16" name="images_size" value="16" <?php if ($imagesize == '16') { echo 'checked="checked"'; } ?> /><?php _e('16', 'amr-ical-events-list'); ?> </label> <label for="images_size32"> <input type="radio" id="images_size32" name="images_size" value="32" <?php if ($imagesize == '32') { echo 'checked="checked"'; } ?> /><?php _e('32', 'amr-ical-events-list'); ?> </label> <p><em><?php _e('The css provided works with the default twenty-ten theme and similar themes. Your theme may be different.', 'amr-ical-events-list'); echo ' '; _e('To edit the file, download the custom one added to your uploads folder: uploads/css.', 'amr-ical-events-list'); echo ' '; _e('Edit it and then re-upload to that same folder. Then select it in the box below.', 'amr-ical-events-list'); echo ' '; _e('This file will not be overwritten when the plugin is upgraded or when your theme is upgraded. ', 'amr-ical-events-list'); ?> </em> <a href="http://icalevents.com/?s=css"><?php _e('More info', 'amr-ical-events-list'); ?> </a></p> <p> <a href="<?php echo ICALLISTPLUGINURL . 'css/icallist.css'; ?> "><?php _e('Download the latest provided css file for editing', 'amr-ical-events-list'); ?> </a><?php echo ' '; _e('(optional)', 'amr-ical-events-list'); ?> </p> <label for="cssfile"><?php _e('Choose plugin default css or choose a custom css and edit it.', 'amr-ical-events-list'); ?> </label> <select id="cssfile" name="cssfile" ><?php if (empty($files)) { echo AMR_NL . ' <option value="">' . __('No css files found in css directory ', 'amr-ical-events-list') . $dir . ' ' . $files . '</option>'; } else { foreach ($files as $ifile => $file) { echo AMR_NL . ' <option value="' . $file . '"'; if (isset($amr_options['cssfile']) and $amr_options['cssfile'] == $file) { echo ' selected="selected" '; } echo '>' . $file . '</option>'; } } ?> </select> </div></fieldset> <fieldset id="amradvanced"> <h3><?php _e('Advanced:', 'amr-ical-events-list'); ?> </h3><div class="postbox" style="padding:1em 2em; width: 600px;"> <?php printf(__('Your php version is: %s', 'amr-ical-events-list'), phpversion()); ?> <br /><?php if (version_compare('5.3', PHP_VERSION, '>')) { echo '<b>' . __('Minimum Php version 5.3 required for events cacheing. ', 'amr-ical-events-list') . '</b>'; _e('Cacheing of generated events for re-use on same page (eg: widget plus list) will not be attempted. ', 'amr-ical-events-list'); _e('Apparently objects do not serialise correctly in php < 5.3.', 'amr-ical-events-list'); echo '<br /><br />'; } amr_check_timezonesettings(); $now = date_create('now', $amr_globaltz); ?> <br /><br /><?php _e('Choose date localisation method:', 'amr-ical-events-list'); ?> <a href="http://icalevents.com/2044-date-and-time-localisation-in-wordpress/"><b>?</b></a><br /> <br /><label for="no_localise"><input type="radio" id="no_localise" name="date_localise" value="none" <?php if ($amr_options['date_localise'] === "none") { echo ' checked="checked" '; } ?> /> <?php _e('none', 'amr-ical-events-list'); echo ' - ' . amr_format_date('r', $now); ?> </label> <br /><label for="am_localise"><input type="radio" id="am_localise" name="date_localise" value="amr" <?php if ($amr_options['date_localise'] === "amr") { echo ' checked="checked" '; } ?> /> <?php _e('amr', 'amr-ical-events-list'); echo ' - ' . amr_date_i18n('r', $now); ?> </label> <br /><label for="wp_localise"><input type="radio" id="wp_localise" name="date_localise" value="wp" <?php if ($amr_options['date_localise'] === "wp") { echo ' checked="checked" '; } ?> /> <?php _e('wp', 'amr-ical-events-list'); echo ' - ' . amr_wp_format_date('r', $now, false); ?> </label> <br /><label for="wpg_localise"><input type="radio" id="wpg_localise" name="date_localise" value="wpgmt" <?php if ($amr_options['date_localise'] === "wpgmt") { echo ' checked="checked" '; } ?> /> <?php _e('wpgmt', 'amr-ical-events-list'); echo ' - ' . amr_wp_format_date('r', $now, true); ?> </label> <br /><br /><br /> <?php // _e('Http timeout for external ics files:', 'amr-ical-events-list'); $options = array('5', '8', '10', '20', '30', '1'); if (!isset($amr_options['timeout'])) { $amr_options['timeout'] = 5; } ?> <br /><br /> <label for="timeout"><?php _e('Choose seconds before timeout for each ics file fetch', 'amr-ical-events-list'); ?> </label> <select id="timeout" name="timeout" ><?php foreach ($options as $i => $sec) { echo '<option value="' . $sec . '"'; if (isset($amr_options['timeout']) and $amr_options['timeout'] == $sec) { echo ' selected="selected" '; } echo '>' . $sec . '</option>'; } ?> </select><br /> <em><?php _e('Warning - 30 seconds is a long time! Let it use cache rather if things are slow', 'amr-ical-events-list'); ?> </em> </div> </fieldset> </div> <?php }