コード例 #1
0
ファイル: amr-pluggable.php プロジェクト: greg3560/plailly
 function amr_list_events($events, $tid, $class, $show_views = true)
 {
     global $wp_locale, $locale, $amr_options, $amr_limits, $amr_listtype, $amr_liststyle, $amr_current_event, $amrW, $amrtotalevents, $amr_globaltz, $amr_groupings, $amr_event_columns, $change_view_allowed;
     if (ICAL_EVENTS_DEBUG) {
         echo '<br />Peak Memory So far :' . amr_memory_convert(memory_get_usage(true));
         echo '<br />Now Listing, and locale = ' . $locale . ' and list type = ' . $amr_listtype . '</h2>';
     }
     if (!defined('AMR_NL')) {
         define('AMR_NL', 'PHP_EOL');
     }
     /* we want to maybe be able to replace the table html for alternate styling - may need to  keep the li items though */
     $amrconstrainedevents = count($events);
     $html = '';
     if (in_array($amr_liststyle, array('smallcalendar', 'largecalendar', 'weekscalendar'))) {
         /* is it a calendar box we want - handle separately */
         $html = amr_events_as_calendar($amr_liststyle, $events, $tid, $class);
         return $html;
     }
     $columns = $amr_event_columns;
     // 20151018 add so we can use easily//prepare_order_and_sequence ($amr_options['listtypes'][$amr_listtype]['compprop']);
     if (!$columns) {
         return;
     } else {
         $no_cols = count($columns);
     }
     /* --- setup the html tags ---------------------------------------------- */
     $htm = amr_get_html_structure($amr_liststyle, $no_cols);
     /* -- show view options or not  ------------------------------------------*/
     if (isset($amr_limits['show_views']) and $amr_limits['show_views'] and $change_view_allowed) {
         $views = amrical_calendar_views();
     } else {
         $views = '';
     }
     /* -- show month year nav options or not  ----------------NOT IN USE - need to lift code out for reuse --------------------------*/
     $start = amr_newDateTime('now');
     if (!empty($amr_limits['start'])) {
         //$start = amr_newDateTime('now');
         //else
         $start = clone $amr_limits['start'];
     }
     $navigation = '';
     if (isset($amr_limits['show_month_nav']) and $amr_limits['show_month_nav']) {
         if (isset($amr_limits['months'])) {
             $months = $amr_limits['months'];
         } else {
             $months = 1;
         }
         //		$start    = new Datetime('now',$amr_globaltz);
         //		$start    = clone $amr_limits['start'];
         $navigation = amr_calendar_navigation($start, $months, 0, $amr_liststyle);
         // include month year dropdown	with links
         $navigation = '<div class="calendar_navigation">' . $navigation . '</div>';
     } else {
         if (isset($amr_limits['month_prev_next']) and $amr_limits['month_prev_next'] and function_exists('amr_do_month_prev_next_shortcode')) {
             $navigation .= amr_do_month_prev_next_shortcode();
         }
         if (isset($amr_limits['month_year_dropdown']) and $amr_limits['month_year_dropdown'] and function_exists('amr_month_year_navigation')) {
             $navigation .= amr_month_year_navigation($start);
         }
     }
     /* -- heading and footers code ------------------------------------------*/
     if (isset($amr_limits['headings'])) {
         $doheadings = $amr_limits['headings'];
     } else {
         $doheadings = true;
     }
     if (isset($amr_limits['pagination'])) {
         $dopagination = $amr_limits['pagination'];
     } else {
         $dopagination = true;
     }
     $headhtml = '';
     if ($doheadings) {
         $docolheading = false;
         if (ICAL_EVENTS_DEBUG) {
             echo '<br />Headings? ';
             var_dump($amr_options['listtypes'][$amr_listtype]['heading']);
         }
         foreach ($amr_options['listtypes'][$amr_listtype]['heading'] as $i => $h) {
             if (!empty($h)) {
                 $docolheading = true;
             }
         }
         if ($docolheading) {
             foreach ($columns as $i => $col) {
                 if (isset($amr_options['listtypes'][$amr_listtype]['heading'][$i])) {
                     $colhead = __($amr_options['listtypes'][$amr_listtype]['heading'][$i], 'amr-ical-events-list');
                 } else {
                     $colhead = '&nbsp;';
                 }
                 $headhtml .= amr_do_a_headercell_html($htm, $i, $colhead);
             }
             $html .= amr_do_column_header_html($htm, $i, $headhtml);
         }
     }
     /* ***** with thechange in list types, we have to rethink how we do the footers .... for tables we say the footers up front, but for others not. */
     $fhtml = '';
     if (isset($amr_options['ngiyabonga']) and $amr_options['ngiyabonga']) {
         $fhtml .= amr_ngiyabonga();
     } else {
         $fhtml .= '<!-- event calendar by anmari.com.  See it at icalevents.com -->';
     }
     if (isset($amr_limits['show_look_more']) and $amr_limits['show_look_more']) {
         $fhtml .= amr_show_look_more();
     }
     if (!empty($amr_limits) and $amrtotalevents > $amrconstrainedevents) {
         if ($dopagination and function_exists('amr_semi_paginate')) {
             $fhtml .= amr_semi_paginate();
         }
         if (function_exists('amr_ical_edit')) {
             $fhtml .= amr_add_new_event_link();
         }
     }
     $alt = false;
     /* -- body code ------------------------------------------*/
     /* ----------- check for groupings and compress these to requested groupings only */
     $groupings = amr_get_groupings_requested();
     $groupedevents = amr_assign_events_to_groupings($groupings, $events);
     // will just return if no grouping
     $html .= amr_list_events_in_groupings($htm, '', $columns, $groupedevents, $events);
     if (!empty($tid)) {
         $tid = ' id="' . $tid . '" ';
     }
     $html = (!empty($htm['box']) ? $htm['box'] . $tid . ' class="' . $class . '">' : '') . $html . $htm['boxc'] . $fhtml;
     $html = $views . AMR_NL . $navigation . AMR_NL . $html . AMR_NL;
     return $html;
 }
コード例 #2
0
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 = '&nbsp;';
    $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;
                //'&nbsp;';
            }
            $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) . '">&nbsp;' . '</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" >&nbsp;</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;
}