コード例 #1
0
 /**
  * Archive shortcode handler.
  */
 function process_archive_shortcode($args = array(), $content = false)
 {
     $args = $this->_preparse_arguments($args, array('network' => false, 'date' => false, 'relative_date' => false, 'lookahead' => false, 'weeks' => false, 'category' => false, 'categories' => false, 'limit' => false, 'order' => false, 'paged' => false, 'page' => 1, 'class' => false, 'template' => 'get_shortcode_archive_output', 'override_styles' => false, 'override_scripts' => false));
     if ($args['paged']) {
         $requested_page = get_query_var('page');
         $requested_page = $requested_page ? $requested_page : get_query_var('paged');
         $args['page'] = $requested_page ? $requested_page : $args['page'];
     }
     $events = array();
     if (is_multisite() && $args['network']) {
         $events = Eab_Network::get_upcoming_events(30);
     } else {
         $query = $this->_to_query_args($args);
         $order_method = $args['order'] ? create_function('', 'return "' . $args['order'] . '";') : false;
         if ($order_method) {
             add_filter('eab-collection-date_ordering_direction', $order_method);
         }
         // Lookahead - depending on presence, use regular upcoming query, or poll week count
         if ($args['lookahead']) {
             $method = $args['weeks'] ? create_function('', 'return ' . $args['weeks'] . ';') : false;
             if ($method) {
                 add_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
             $events = Eab_CollectionFactory::get_upcoming_weeks_events($args['date'], $query);
             if ($method) {
                 remove_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
         } else {
             // No lookahead, get the full month only
             $events = Eab_CollectionFactory::get_upcoming_events($args['date'], $query);
         }
         if ($order_method) {
             remove_filter('eab-collection-date_ordering_direction', $order_method);
         }
     }
     $output = Eab_Template::util_apply_shortcode_template($events, $args);
     if ($output) {
         if ($args['paged'] && !(is_multisite() && $args['network'])) {
             if ($method) {
                 add_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
             $events_query = $args['lookahead'] ? Eab_CollectionFactory::get_upcoming_weeks($args['date'], $query) : Eab_CollectionFactory::get_upcoming($args['date'], $query);
             if ($method) {
                 remove_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
             $output .= eab_call_template('get_shortcode_paging', $events_query, $args);
         }
     } else {
         $output = $content;
     }
     if (!$args['override_styles']) {
         wp_enqueue_style('eab_front');
     }
     if (!$args['override_scripts']) {
         wp_enqueue_script('eab_event_js');
         do_action('eab-javascript-do_enqueue_api_scripts');
     }
     return $output;
 }
コード例 #2
0
 public function get_weekly_calendar($timestamp = false, $id = '', $class = '')
 {
     $options = Eab_Options::get_instance();
     if (!is_object($options)) {
         $options = new Eab_Options();
     }
     $timestamp = $timestamp ? $timestamp : $this->get_local_time();
     $year = date("Y", $timestamp);
     $month = date("m", $timestamp);
     //$query = Eab_CollectionFactory::get_upcoming(strtotime("{$year}-{$month}-01 00:00"));
     $query = Eab_CollectionFactory::get_upcoming_weeks(strtotime("{$year}-{$month}-01 00:00"));
     $this->_events = $query->posts;
     $date = $timestamp ? $timestamp : $this->get_local_time();
     $sunday = $this->sunday($date);
     // Timestamp of first Sunday of any date
     if (!($start = $this->_data->get_option('weekly_calendar_start')) or $start > 23) {
         $start = 10;
     }
     // Set a default working time start
     $first = $start * 3600 + $sunday;
     // Timestamp of the first cell of first Sunday
     if (!($end = $this->_data->get_option('weekly_calendar_end')) or $end < 1) {
         $end = 24;
     }
     // Set a default working time end
     $last = $end * 3600 + $sunday;
     // Timestamp of the last cell of first Sunday
     if (!($interval = $this->_data->get_option('weekly_calendar_interval')) or $interval < 10 or $interval > 60 * 12) {
         $interval = 120;
     }
     // Set a default interval in minutes
     $step = $interval * 60;
     // Timestamp increase interval to one cell below
     $days = $this->arrange(array(0, 1, 2, 3, 4, 5, 6), -1);
     // Arrange days acc. to start of week
     $post_info = array();
     foreach ($this->_events as $event) {
         $post_info[] = $this->_get_item_data($event);
     }
     $tbl_id = $id;
     $tbl_id = $tbl_id ? "id='{$tbl_id}'" : '';
     $tbl_class = $class;
     $tbl_class = $tbl_class ? "class='{$tbl_class}'" : '';
     $ret = '';
     $ret .= "<table width='100%' {$tbl_id} {$tbl_class}>";
     $ret .= $this->_get_table_meta_row('thead');
     $ret .= '<tbody>';
     $ret .= $this->_get_first_row();
     $todays_no = date("w", $this->get_local_time());
     // Number of today
     for ($t = $first; $t < $last; $t = $t + $step) {
         foreach ($days as $key => $i) {
             // Not sure if it's current fix, but it works!
             if ($i == 0) {
                 $i = 7;
             }
             if ($i == -1) {
                 $from = $this->secs2hours($t - $sunday);
                 $to = $this->secs2hours($t - $sunday + $step);
                 $ret .= "<td class='wpmudevevents-weekly-calendar-hours-mins'>" . $from . " - " . $to . "</td>";
             } else {
                 $current_cell_start = $t + $i * 86400;
                 $current_cell_end = $current_cell_start + $step;
                 $this->reset_event_info_storage();
                 foreach ($post_info as $ipost) {
                     $count = count($ipost['event_starts']);
                     for ($k = 0; $k < $count; $k++) {
                         $start = strtotime($ipost['event_starts'][$k]);
                         $end = strtotime($ipost['event_ends'][$k]);
                         if ($start < $current_cell_end && $end > $current_cell_start) {
                             if ($options->get_option('weekly_calendar_display')) {
                                 $this->set_event_info_author(array('start' => $start, 'end' => $end), array('start' => $current_cell_start, 'end' => $current_cell_end), $ipost);
                             } else {
                                 $this->set_event_info(array('start' => $start, 'end' => $end), array('start' => $current_cell_start, 'end' => $current_cell_end), $ipost);
                             }
                         }
                     }
                 }
                 $activity = $this->get_event_info_as_string($i);
                 $now = $todays_no == $i ? 'class="today"' : '';
                 if ($this->get_local_time() < $current_cell_end && $this->get_local_time() > $current_cell_start) {
                     $now = 'class="now"';
                 }
                 $ret .= "<td {$now}>{$activity}</td>";
             }
         }
         $ret .= '</tr><tr>';
         // Close the last day of the week
     }
     $ret .= $this->_get_last_row();
     $ret .= '</tbody>';
     $ret .= $this->_get_table_meta_row('tfoot');
     $ret .= '</table>';
     return $ret;
 }