function amr_handle_no_events() { global $amr_options, $amr_limits; $thecal = ''; if (!empty($amr_options['noeventsmessage'])) { $thecal .= '<a class="noeventsmessage" style="cursor:help;" href="" title="' . amr_echo_parameters() . '"> ' . __($amr_options['noeventsmessage'], 'amr-ical-events-list') . '</a>'; if (isset($amr_limits['show_look_more']) and $amr_limits['show_look_more']) { $thecal .= amr_show_look_more(); } if (isset($amr_limits['pagination']) and $amr_limits['pagination']) { $thecal .= amr_semi_paginate(); } } return $thecal; }
function widget($args, $instance) { /* this is the piece that actualy does the widget display */ global $amrW, $amr_options, $amr_limits, $amr_listtype, $amr_calendar_url, $amr_ical_am_doing, $change_view_allowed, $widget_icalno, $amr_been_here; /* used to detect if we are looping somehow - reset at the end of each widget or shortcode. */ // if (amr_a_nested_event_shortcode()) { return false; } //someone entered an event shortcode into event content - causing a loop of events lists inside event lists amr_ical_load_text(); // do we have to reload all over theplace ? wp does not always seem to have the translations $change_view_allowed = false; $amr_ical_am_doing = 'listwidget'; extract($args, EXTR_SKIP); /* this is for the before / after widget etc*/ unset($args); //nb do not delete this else mucks up the args later extract($instance, EXTR_SKIP); /* this is for the params etc*/ if (!empty($shortcode_urls)) { // get any args stored in the widget settings $args = shortcode_parse_atts($shortcode_urls); } if (empty($args['listtype'])) { $args['listtype'] = '4'; } $amr_listtype = (int) $args['listtype']; // if (!empty($externalicalonly) and $externalicalonly) { $args['eventpoststoo'] = '0'; } else { $args['eventpoststoo'] = '1'; } // $args['show_month_nav'] = '0'; // comment out, otherwise cannot have at all if requetsed? $args['headings'] = '1'; $args['show_views'] = '0'; $amrW = 'w'; /* to maintain consistency with previous version and prevent certain actions */ $criteria = amr_get_params($args); /* this may update listtype, limits etc */ // what was this for ?? if (isset($criteria['event'])) { unset($criteria['event']); } //*** later may need to check for other custo posttypes if (ICAL_EVENTS_DEBUG) { echo '<hr>ical list widget:' . $amr_listtype . ' <br />' . amr_echo_parameters(); } if (isset($doeventsummarylink) and !$doeventsummarylink) { $amrW = 'w_no_url'; } $moreurl = trim($moreurl, " "); $moreurl = empty($moreurl) ? null : $moreurl; $amr_calendar_url = esc_url($moreurl); if (ICAL_EVENTS_DEBUG) { echo 'Calendar url = ' . $amr_calendar_url; } if (isset($_REQUEST['lang'])) { $moreurl = add_query_arg('lang', $_REQUEST['lang'], $moreurl); } // wp 3.3.1 doesn't like html in titles anymore - why ? // if (!empty ($moreurl)) // $title = '<a title="'.__('Look for more','amr-ical-events-list').'" href= "'.$moreurl.'">'.__($title,'amr-ical-events-list') .'</a>'; if (!isset($widget_icalno)) { $widget_icalno = 0; } else { $widget_icalno = $widget_icalno + 1; } $content = amr_process_icalspec($criteria, $amr_limits['start'], $amr_limits['end'], $amr_limits['events'], $widget_icalno); //output... //var_dump($criteria); echo $before_widget; // if (!empty($criteria['headings'])) echo $before_title . apply_filters('widget_title', __($title, 'amr-ical-events-list')) . $after_title; echo $content; echo $after_widget; /* we made it out the other end without looping ?*/ $amr_been_here = false; }
function amr_GET_params($attributes = array()) { /* We are passed the widget or shortcode attributes, check them, get what we can there, then check for passed parameters (form or query string ) Anything unset we will get from the default settings for that listtype. The defaults list type is 1. then set the amr_limits (note the calendar options may overwrite these) */ global $amr_limits, $amr_listtype, $amr_liststyle, $amr_options, $amr_groupings, $amr_fields_needed, $amr_event_columns, $amr_formats, $amr_globaltz, $change_view_allowed, $amr_calendar_url, $amrW; // indicates if widget, $amr_options = amr_GETset_options(); // $defaults = array('listtype' => $amr_listtype, 'startoffset' => '', 'hoursoffset' => '', 'monthsoffset' => '', 'daysoffset' => '', 'start' => '', 'days' => '', 'events' => '', 'months' => '', 'hours' => '', 'weeks' => '', 'tz' => '', 'eventpoststoo' => '1', 'agenda' => '', 'calendar' => '', 'eventmap' => '0', 'show_views' => '1', 'show_month_nav' => '0', 'show_look_more' => '0', 'day_links' => '1', 'month_year_dropdown' => '0', 'month_prev_next' => '0', 'calendar_properties' => '1', 'pagination' => '1', 'headings' => '1', 'ignore_query' => '', 'grouping' => '', 'more_url' => '', 'no_filters' => '0', 'sort_later_events_first' => '0', 'exclude_in_progress' => '0'); $shortcode_params = shortcode_atts($defaults, $attributes); // if (!empty($attributes)) { // if there is stuff left - must be urls foreach ($attributes as $i => $v) { if (is_numeric($i) or $i == 'ics') { // ie if it is a value passed with no name, we expect only urls like that if (substr($v, 0, 1) == ':') { /* attempt to maintain old filter compatibity */ $shortcode_params['urls'][$i] = substr($v, 1); } $v2 = str_ireplace('webcal://', 'http://', $v); //keep the webcal if (function_exists('filter_var') and !filter_var($v2, FILTER_VALIDATE_URL)) { /* rejecting a valid URL on php 5.2.14 */ echo '<h2>' . sprintf(__('Invalid Ical URL %s', 'amr-ical-events-list'), $v2) . '</h2>'; if (current_user_can('administrator')) { echo '<p>Notes to admin only (does not show if not logged in as admin): <ul> <li>If you have put [ical in the widget - take it out! </li> <li>the php validation functon does not cope with internationalised domain, please contact the developer if this affects you.</li> </ul></p>'; } } else { $shortcode_params['urls'][$i] = esc_url_raw($v); } unset($attributes[$i]); } } // end foreach } //end if // handle taxonomies we do not even know about yet /* get the parameters we want out of the attributes, supplying defaults for anything missing */ /* but now we may have missed taxonomies etc as the defaults do not know about them, so get the diff */ if (!empty($attributes)) { //var_dump($attributes); //var_dump($shortcode_params); // - this could be multi-d array due to urls so array diff will throw a notice in php 5.4 // maybe extract somehow ourselves? or use array_diff_key instead /**** $taxo_selection = array_diff_key($attributes, $shortcode_params); } // if we had some taxos, marge them into shortcode selection if (!empty($taxo_selection)) { $shortcode_params = array_merge($shortcode_params, $taxo_selection); } $allow_query = (!isset($shortcode_params['ignore_query']) or !$shortcode_params['ignore_query']); $ignore_query_all = (isset($shortcode_params['ignore_query']) and $shortcode_params['ignore_query'] == 'all'); unset($shortcode_params['ignore_query']); if ($allow_query) { // parse_str($_SERVER['QUERY_STRING'], $queryargs); /* Get anything passed in the query string that will override shortcodes */ // check for posted values to get around that pesky problem if (isset($_GET['start'])) { $queryargs['start'] = $_GET['start']; } foreach ($queryargs as $i => $arg) { $queryargs[$i] = filter_var($arg, FILTER_SANITIZE_STRING); //Strip tags, } if ($change_view_allowed) { // for upcoming events widget, may want to allow query of days etc, but not the listtype change if (isset($queryargs['calendar'])) { $queryargs['listtype'] = $queryargs['calendar']; } if (isset($queryargs['agenda'])) { $queryargs['listtype'] = $queryargs['agenda']; } } unset($queryargs['page_id']); unset($queryargs['debug']); if (isset($_GET['debugq'])) { echo '<hr> Query allowed, attributes/args to consider adding:<br />'; var_dump($queryargs); } $shortcode_params = array_merge($shortcode_params, $queryargs); /* If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended. */ // if (ICAL_EVENTS_DEBUG) {echo '<hr>After merge with query args<br />'; var_dump($shortcode_params); } //unset($queryargs['listtype']); } else { if (isset($_GET['debugq'])) { echo '<hr>Ignoring most query parameters '; } } // // save the global list type first if (!empty($shortcode_params['listtype'])) { $amr_listtype = $shortcode_params['listtype']; unset($shortcode_params['listtype']); } // unset($attributes['listtype']); if ($change_view_allowed and $allow_query) { // then we will NOT ignore these query parameters as that will break our navigation //if (ICAL_EVENTS_DEBUG) {echo '<br />Allowed to change views';} if (isset($_GET['listtype'])) { $amr_listtype = intval($_GET['listtype']); } if (isset($_GET['eventmap'])) { $amr_listtype = 'eventmap'; } // havent figured this out yet } // check the listtype here ? if (empty($amr_options['listtypes'][$amr_listtype])) { if (current_user_can('administrator')) { echo sprintf(__('System error - event list type %s missing - please inform administrator.', 'amr-ical-events-list'), $amr_listtype); _e('Now using an available list type to list events', 'amr-ical-events-list'); } $amr_listtype = amr_first_available_listtype(); } $amr_liststyle = isset($amr_options['listtypes'][$amr_listtype]['general']['ListHTMLStyle']) ? $amr_options['listtypes'][$amr_listtype]['general']['ListHTMLStyle'] : ($amr_liststyle = 'table'); //; 'list' if (!empty($shortcode_params['more_url'])) { $amr_calendar_url = esc_url($shortcode_params['more_url']); unset($shortcode_params['more_url']); } // always respond to start // if (in_array ($amr_liststyle, array('smallcalendar','largecalendar', 'weekscalendar'))) { // then query args overeride even if we have ignore query if (!$ignore_query_all) { if (isset($_GET['start'])) { $queryargs['start'] = $_GET['start']; } //need here too if (!empty($queryargs['start'])) { $shortcode_params['start'] = abs((int) $queryargs['start']); if (ICAL_EVENTS_DEBUG) { echo '<br />START = ' . $shortcode_params['start']; } // $shortcode_params['start'] = (substr((string) $shortcode_params['start'],0,6).'01'); //set to month start - done in month shortcdoe? } if (!empty($queryargs['months'])) { $shortcode_params['months'] = abs((int) $queryargs['months']); } if (!empty($queryargs['tz'])) { $shortcode_params['tz'] = filter_var($queryargs['tz'], FILTER_SANITIZE_STRING); } } else { if (isset($_GET['debugall'])) { echo '<br/>** Ignoring all query parameters'; } } //----------------------------------------------------------------------------------------------------------------- now do thelimits array // then get the limits for that list type $amr_limits = $amr_options['listtypes'][$amr_listtype]['limit']; /* get the default limits */ if ($amr_liststyle === 'weekscalendar') { $amr_limits['weeks'] = 2; // default for horizontal calendar } if ($amr_liststyle === 'largecalendar' or $amr_liststyle === 'smallcalendar') { if (empty($amr_limits['months'])) { $amr_limits['months'] = 1; } // default for horizontal calendar } // now check groupings $gg = ''; if (!empty($shortcode_params['grouping'])) { $gg = ucwords($shortcode_params['grouping']); } unset($shortcode_params['grouping']); if (!empty($_GET['grouping'])) { $gg = ucwords($_GET['grouping']); } if (!($gg == '')) { unset($amr_options['listtypes'][$amr_listtype]['grouping']); if (array_key_exists($gg, $amr_groupings)) { // if it is a valid grouping $amr_options['listtypes'][$amr_listtype]['grouping'][$gg] = true; unset($shortcode_params['grouping']); } } if (!empty($shortcode_params)) { foreach ($shortcode_params as $i => $v) { // must be atts not limits as atts may hold more then limits - limits just has initial limits if (in_array($i, array('headings', 'show_views', 'agenda', 'eventmap', 'calendar', 'eventpoststoo', 'pagination', 'calendar_properties', 'no_filters', 'show_month_nav', 'show_look_more', 'day_links', 'more_url', 'month_year_dropdown', 'month_prev_next'))) { $amr_limits[$i] = abs(intval($v)); unset($shortcode_params[$i]); // only unset if empty what??? - else will lose others } else { if (in_array($i, array('days', 'events', 'months', 'listtype', 'hours', 'weeks', 'daysoffset', 'startoffset', 'hoursoffset', 'monthsoffset'))) { if (!empty($v)) { $amr_limits[$i] = (int) $v; } // can be negative, so no abs unset($shortcode_params[$i]); } } } if (!empty($amr_limits['listtype'])) { $amr_listtype = $amr_limits['listtype']; if (ICAL_EVENTS_DEBUG) { echo '<br />listtype set to: '; } } } // else might be a taxonomy or categeory etc ... pass through - not if we have filtered string /* ----check if we want to overwrite the wordpress timezone */ if (!empty($shortcode_params['tz'])) { // allows one to overwrite the timezone $amr_globaltz = timezone_open($shortcode_params['tz']); } unset($shortcode_params['preview']); //clear it out so we do not pass to wp query unset($shortcode_params['tz']); //clear it out so we do not pass to wp query if (isset($_GET['tzdebug'])) { echo '<p>Plugin/Wordpress Timezone:' . timezone_name_GET($amr_globaltz); echo ', current offset is ' . $amr_globaltz->getOffset(date_create('now', $amr_globaltz)) / (60 * 60) . '</p>'; } //------------------------------- $pos_int_options = array("options" => array("min_range" => 1, "max_range" => 1000)); $neg_int_options = array("options" => array("min_range" => -1000, "max_range" => 1000)); /* check non url parameters */ if (empty($shortcode_params['start'])) { $amr_limits['start'] = date_create('now', $amr_globaltz); } else { $amr_limits['start'] = abs((int) $shortcode_params['start']); } unset($shortcode_params['start']); // clear it out so we do not pass it to wp query // work out whether we are doing a calendar or not. calendars must still respond to at least the month navigation foreach ($amr_limits as $i => $a) { // create our date objects if ($i === 'start' or $i === 'end') { if (!is_object($a)) { $dateok = checkdate(substr($a, 4, 2), substr($a, 6, 2), substr($a, 0, 4)); /* year */ if ($dateok) { $amr_limits[$i] = date_create($a, $amr_globaltz); if (!is_object($amr_limits[$i])) { amr_tell_error($i . ' ' . __('Date could not be converted to date object.', 'amr-ical-events-list') . __('Check date and global timezone.', 'amr-ical-events-list')); var_dump($amr_limits[$i]); var_dump($amr_globaltz); } } else { _e('Invalid Start Date', 'amr-ical-events-list'); echo '<br />' . $i . ' ' . $a; $amr_limits[$i] = date_create('now', $amr_globaltz); } } /* else all is okay - we have default date of now */ } } if (!empty($shortcode_params['daysoffset'])) { /* keeping startoffset for old version compatibility, but allowing for daysoffset for compatibility with other offsets */ $amr_limits['startoffset'] = (int) $shortcode_params['daysoffset']; // can be negative } /* ---- check for urls that are either passed by query or form, or are in the shortcode with a number or not ie: not ics = */ //set up global for easier access $amr_formats = $amr_options['listtypes'][$amr_listtype]['format']; // now adjust our start dta if necessary if (!empty($amr_limits['startoffset'])) { $daysoffset = (int) $amr_limits['startoffset']; if ($daysoffset > 0) { $daysoffset = '+' . (string) $daysoffset . ' days'; } else { $daysoffset = (string) $daysoffset . ' days'; } date_modify($amr_limits['start'], $daysoffset); } // if (!empty($amr_limits['hoursoffset'])) { $hrsoffset = (int) $amr_limits['hoursoffset']; if ($hrsoffset > 0) { $hrsoffset = '+' . (string) $hrsoffset . ' hours'; } else { $hrsoffset = (string) $hrsoffset . ' hours'; } date_modify($amr_limits['start'], $hrsoffset); /*** as per request from jd */ } // if (!empty($amr_limits['monthsoffset'])) { $mthsoffset = (int) $amr_limits['monthsoffset']; if ($mthsoffset >= 0) { $mthsoffset = '+' . (string) $mthsoffset . ' months'; } else { $mthsoffset = (string) $mthsoffset . ' months'; } date_modify($amr_limits['start'], $mthsoffset); } // if (!empty($amr_limits['hours'])) { /* then set the time to the beginning of the day , and get rid of months and days */ date_time_set($amr_limits['start'], $amr_limits['start']->format('G'), 0, 0); /* set the time to beginning of the hour */ unset($amr_limits['days']); unset($amr_limits['months']); } if (!empty($amr_limits['months'])) { /* then set the date to the beginning of the month and get rid of days */ $days = (int) $amr_limits['start']->format('d'); if ($days > 1) { $amr_limits['start']->modify('-' . ($days - 1) . ' days'); } date_time_set($amr_limits['start'], 0, 0, 0); unset($amr_limits['days']); } // if (empty($amr_limits['hours'])) { /* else use the days and then set the time to the beginning of the day */ date_time_set($amr_limits['start'], 0, 0, 0); } $wkst = ical_GET_weekstart(); // get the wp start of week if (isset($_GET['debugwks'])) { echo '<br/>wkst = ' . $wkst; } if (!empty($amr_limits['weeks'])) { // weeks overrides all else $amr_limits['start'] = amr_GET_human_start_of_week($amr_limits['start'], $wkst); /* set to start of week */ $amr_limits['days'] = $amr_limits['weeks'] * 7; unset($amr_limits['hours']); if (isset($_GET['debugwks'])) { echo '<br />Start set to = ' . $amr_limits['start']->format('c'); } } // now find our end date - may get overridden if calendar if (is_object($amr_limits['start'])) { $amr_limits['end'] = new Datetime(); //if cloning dont need tz $amr_limits['end'] = clone $amr_limits['start']; } else { // something horribly wrong here amr_tell_eror(__('Error: Start data of range is not a date object. Please advise administrator', 'amr-ical-events-list')); var_dump($amr_limits['start']); } if (!empty($amr_limits['months'])) { date_modify($amr_limits['end'], '+' . $amr_limits['months'] . ' months'); } if (!empty($amr_limits['days'])) { date_modify($amr_limits['end'], '+' . $amr_limits['days'] . ' days'); } if (!empty($amr_limits['hours'])) { date_modify($amr_limits['end'], '+' . $amr_limits['hours'] . ' hours'); } else { date_modify($amr_limits['end'], '-1 second'); } /* so that we do not include events starting in the next time period */ if (isset($_GET['debug'])) { echo '<br/>end = ' . $amr_limits['end']->format('c'); } // date_time_set ($amr_limits['end'],23,59,59); // if we have this, do we need the -1 second below? if (isset($_GET['debugq'])) { echo '<hr> Before passing others <br />'; var_dump($shortcode_params); echo amr_echo_parameters(); } $amr_event_columns = prepare_order_and_sequence($amr_options['listtypes'][$amr_listtype]['compprop']); //do once earlier $amr_fields_needed = amr_extract_fields($amr_event_columns); // setup global return $shortcode_params; // only return params needed for wp query ? }