Manage Settings Page and Manage Widget */ class amr_ical_widget extends WP_Widget { /** constructor */ public function __construct() { $widget_ops = array ('description'=>__('Upcoming Events', 'amr-ical-events-list' ),'classname'=>'events'); parent::__construct('amr-ical-upe' , __('Upcoming Events List', 'amr-ical-events-list' ) , $widget_ops); } /* ============================================================================================== */ function widget ($args /* the title etc */, $instance /* the params */) { /* 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, /* used to give each ical widget a unique id on a page */ $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 '
ical list widget:'.$amr_listtype.'
'.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 = ''.__($title,'amr-ical-events-list') .''; 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 update($new_instance, $old_instance) { /* this does the update / save */ $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['moreurl'] = strip_tags($new_instance['moreurl']); $instance['moreurl'] = amr_make_sticky_url($instance['moreurl'] ); $instance['doeventsummarylink']= strip_tags($new_instance['doeventsummarylink']); $instance['externalicalonly'] = strip_tags($new_instance['externalicalonly']); $instance['shortcode_urls'] = strip_tags($new_instance['shortcode_urls']); if (get_option('amr-ical-widget') ) delete_option('amr-ical-widget'); /* if it exists - leave code for a while for conversion */ return $instance; } /* ============================================================================================== */ function form($instance) { /* this does the display form */ global $amrW; $instance = wp_parse_args( (array) $instance, array( 'title' => __('Upcoming Events','amr-ical-events-list') , 'moreurl' => '', 'doeventsummarylink' => true, 'externalicalonly' => false, 'shortcode_urls' => '' ) ); $title = $instance['title']; $moreurl = $instance['moreurl']; $doeventsummarylink= $instance['doeventsummarylink']; $externalicalonly = $instance['externalicalonly']; $shortcode_urls = $instance['shortcode_urls']; if ($opt = get_option('amr-ical-widget')) { /* delete the old option in the save */ if (isset ($opt['urls']) ) $shortcode_urls = str_replace(',', ' ',$opt['urls']); /* in case anyone had multiple urls separate by commas - change to spaces*/ if (isset ($opt['moreurl']) ) $moreurl = $opt['moreurl']; if (isset ($opt['title']) ) $title = $opt['title']; if (isset ($opt['listtype']) and (!($opt['listtype']===4))) $shortcode_urls = 'listtype='.$opt['listtype'].' '.$shortcode_urls; if (isset ($opt['limit']) and (!($opt['limit']==='5'))) $shortcode_urls = 'events='.$opt['limit'].' '.$shortcode_urls; } $seemore = __('See plugin website for more details','amr-ical-events-list'); // ?>

?

__('Upcoming Events', 'amr-ical-events-list' ), 'classname'=>'widget_calendar'); parent::__construct(false, __('Upcoming Events Calendar', 'amr-ical-events-list' ), $widget_ops); } /* ============================================================================================== */ function widget ($args, $instance) { /* this is the piece that actualy does the widget display */ global $amrW; global $amr_options; global $amr_limits; global $amr_listtype; global $change_view_allowed; global $widget_icalno; /* used to give each ical widget a unique id on a page */ global $amr_calendar_url, $amr_been_here; // don't check becuase it checks in the shortcode function we call // 20140209 redundant - done in the shortcode function too $criteria = amr_get_params ($args); /* this may update listtype, limits etc */ 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_listtype = '8'; /* default only, can be overwitten in shortcode or query string */ extract ($args, EXTR_SKIP); /* this is for the before / after widget etc*/ unset($args); extract ($instance, EXTR_SKIP); /* the widget form fields */ if (isset ($moreurl) ) $moreurl = trim($moreurl," "); $amr_calendar_url = (empty($moreurl)) ? null : $moreurl ; if (!empty ($shortcode_urls)) // from the instance $atts = shortcode_parse_atts($shortcode_urls); if (!empty ($externalicalonly) and $externalicalonly) $atts['eventpoststoo'] = '0'; else $atts['eventpoststoo'] = '1'; $atts['show_views'] = '0'; $atts['ignore_query'] = 1; $atts['show_month_nav'] = 1; // if (!(isset($widget_icalno))) $widget_icalno = 0; else $widget_icalno= $widget_icalno + 1; $amrW = 'w'; /* to maintain consistency with previous version */ $content = amr_do_smallcal_shortcode($atts); // thsi will check query params etc //output... if (!empty($before_widget)) echo $before_widget; if (!empty($before_title)) echo $before_title; if (!empty($title)) echo apply_filters('widget_title',__($title,'amr-ical-events-list') ); if (!empty($after_title)) echo $after_title; echo $content; if (!empty($after_widget)) echo $after_widget; if (isset ($savedays)) $amr_limits['days'] = $savedays; /* we made it out the other end without looping ?*/ $amr_been_here = false; } /* ============================================================================================== */ function update($new_instance, $old_instance) { /* this does the update / save */ $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); // if (!empty($instance['externalicalonly'])) // was causing it not to svae - why? $instance['externalicalonly'] = ($new_instance['externalicalonly']); $instance['shortcode_urls'] = strip_tags($new_instance['shortcode_urls']); $instance['moreurl'] = strip_tags($new_instance['moreurl']); $instance['moreurl'] = amr_make_sticky_url($instance['moreurl'] ); return $instance; } /* ============================================================================================== */ function form($instance) { /* this does the display form */ $instance = wp_parse_args( (array) $instance, array( 'title' => __('Upcoming Events','amr-ical-events-list'), 'externalicalonly' => false, 'moreurl' => '', 'shortcode_urls' => 'ignore_query=1' ) ); $title = $instance['title']; $moreurl = $instance['moreurl']; $externalicalonly = $instance['externalicalonly']; $shortcode_urls = $instance['shortcode_urls']; $seemore = __('See more','amr-ical-events-list'); ?>

?