예제 #1
0
파일: ajax-load.php 프로젝트: juslee/e27
<?php

require_once "../../../wp-config.php";
if (isset($_GET['showMonth'])) {
    $options = get_option(ADMIN_OPTIONS_NAME);
    //$_GET;
    //$icsOptions = WPICSImporter::getAdminOptions();
    $options['ics_file_default'] = $_GET['calendar'];
    echo icsCalDisplay::showCalendar($options, $_GET['showMonth'], '', '', $_GET['cuid']);
    exit;
}
if (isset($_GET['widgetPage'])) {
    $widget = WPICSImporter::getWidgetOptions();
    $options = WPICSImporter::getAdminOptions();
    $options = WPICSImporter::prepareWidgetOptions($widget, $options);
    $options['events_page'] = (int) $_GET['widgetPage'];
    $output = ICalEvents::custom_display_events($options, true);
    echo $output['output'];
    if ($output['count'] < $options['event_limit']) {
        echo '<script>jQuery("#ics-calendar-widget-next").hide();</script>';
    }
    exit;
}
if (isset($_GET['eventsPage']) && isset($_GET['eventsStart']) && isset($_GET['eventsEnd']) && isset($_GET['eventsFile'])) {
    $icsOptions = WPICSImporter::getAdminOptions();
    $gmt_start = $_GET['eventsStart'];
    $gmt_end = $_GET['eventsEnd'];
    if ($icsOptions['limit_type'] == 'days') {
        $gmt_start += (int) $icsOptions['event_limit'] * 24 * 3600 * (int) $_GET['eventsPage'];
        $gmt_end += (int) $icsOptions['event_limit'] * 24 * 3600 * (int) $_GET['eventsPage'];
        $icsOptions['event_limit'] = 0;
예제 #2
0
파일: ics-import.php 프로젝트: juslee/e27
 function placePageCalendar($content)
 {
     // Get the options...
     $icsOptions = $this->getAdminOptions();
     // SET LOCALE FOR EVERY PAGE/EVENT
     if (!empty($icsOptions['date_language'])) {
         $fixed_locales = preg_replace('/ +/', '', $icsOptions['date_language']);
         $locales = explode(',', $fixed_locales);
         if (!setlocale(LC_ALL, $locales)) {
             //return "Locale Error";
             exit;
         }
     }
     // Only do this if this is a page and it has the appropriate custom field
     if (is_page()) {
         $savedLimit = $icsOptions['event_limit'];
         $savedDefault = $icsOptions['ics_file_default'];
         if (isset($_GET['ics-perm'])) {
             $icsArray = unserialize($icsOptions['ics_files']);
             $output = '<a style="float:right;" href="' . preg_replace('/ics-perm=([^&?]*)(&|\\?)?/i', '', $_SERVER['REQUEST_URI']) . '">' . __('Return to Calendar', 'WPICSImporter') . '</a>' . '<br style="clear:both;" />';
             return $output . ICalEvents::display_one_event($icsArray, $_GET['ics-perm']);
         }
         if (preg_match('/\\[' . $this->showEvents . '=?([0-9]*)?( +cal=)?([0-9,]{1,})?\\]/i', $content, $args)) {
             define('ICAL_EVENTS_CACHE_TTL', $icsOptions['cache_time']);
             preg_match_all('/\\[' . $this->showEvents . '=?([0-9]*)?( +cal=)?([0-9,]{1,})?\\]/i', $content, $args);
             foreach ($args[1] as $k => $arg) {
                 $more = '';
                 if (!empty($arg)) {
                     $icsOptions['event_limit'] = $arg;
                     $more .= '=' . $arg;
                 } else {
                     $icsOptions['event_limit'] = $savedLimit;
                 }
                 if (!empty($args[3][$k])) {
                     $icsOptions['ics_file_default'] = $args[3][$k];
                     $more .= ' +cal=' . $args[3][$k];
                 } else {
                     $icsOptions['ics_file_default'] = $savedDefault;
                 }
                 if ($icsOptions['use_custom_format'] == 'true') {
                     $eventsContent = ICalEvents::custom_display_events($icsOptions);
                 } else {
                     if ($icsOptions['gmt_start_now'] == 'true') {
                         $gmt_start = time();
                         $gmt_end = NULL;
                         if ($icsOptions['limit_type'] == 'days') {
                             $gmt_end = time() + (int) $icsOptions['event_limit'] * 24 * 3600;
                             $icsOptions['event_limit'] = 0;
                         }
                     } else {
                         if ($icsOptions['gmt_start'] != '') {
                             $gmt_start = strtotime($icsOptions['gmt_start'], time());
                         }
                         if ($icsOptions['gmt_end'] != '') {
                             $gmt_end = strtotime($icsOptions['gmt_end'], time());
                         }
                     }
                     $icsArray = unserialize($icsOptions['ics_files']);
                     if ($icsOptions['ics_file_default'] == 'combine') {
                         $icsFile = $icsArray;
                     } elseif (strstr($icsOptions['ics_file_default'], ',')) {
                         $cals = explode(',', $icsOptions['ics_file_default']);
                         foreach ($cals as $calid) {
                             $icsFile[] = $icsArray[trim($calid)];
                         }
                     } elseif (!empty($icsArray[$icsOptions['ics_file_default']])) {
                         $icsFile = $icsArray[$icsOptions['ics_file_default']];
                     } else {
                         $icsFile = array_shift($icsArray);
                     }
                     $eventsContent = ICalEvents::display_events($icsFile, $gmt_start, $gmt_end, $icsOptions['event_limit']);
                 }
                 $content = preg_replace('/\\[' . $this->showEvents . $more . '\\]/i', $eventsContent, $content);
             }
         }
         if (preg_match('/\\[' . $this->showCalendar . '( +cal=)?([0-9,]{1,})?\\]/i', $content)) {
             $cssAdd = '<style type="text/css" media="screen">@import "' . (empty($icsOptions['cal_css_file']) ? ICSCALENDAR_URLPATH . 'library/ics-calendar.css' : $icsOptions['cal_css_file']) . '";</style>' . "\n";
             $eventid = '';
             if (!empty($_GET['icsevent'])) {
                 $eventid = $_GET['icsevent'];
             }
             if (!empty($_GET['icsdate'])) {
                 $eventdate = $_GET['icsdate'];
             }
             $icsArray = unserialize($icsOptions['ics_files']);
             preg_match_all('/\\[' . $this->showCalendar . '( +cal=)?([0-9,]{1,})?\\]/i', $content, $finds);
             foreach ($finds[2] as $find) {
                 if (!empty($find)) {
                     $icsOptions['ics_file_default'] = $find;
                     $more = ' +cal=' . $find;
                 } else {
                     $icsOptions['ics_file_default'] = $savedDefault;
                     $more = '';
                 }
                 $calDisplay = $cssAdd . icsCalDisplay::initCalendar($icsOptions, $eventid, $eventdate);
                 $content = preg_replace('/\\[' . $this->showCalendar . $more . '\\]/i', $calDisplay, $content);
             }
         }
     }
     return $content;
 }
예제 #3
0
        function showCalendar($options, $selected_date = NULL, $eventid = '', $eventdate = '', $cuid = '')
        {
            if ($selected_date != NULL) {
                $today = getdate(strtotime($selected_date));
            } elseif (!empty($eventid)) {
                //$selectedEvent = ICalEvents::get_event($options['ics_file'], $eventid, $eventdate);
                //$pretoday = getdate($selectedEvent['StartTime']);
                //$today = getdate( mktime(0,0,0,$pretoday['mon'],1,$pretoday['year']) );
                $today = getdate($eventdate);
            } else {
                $today = getdate();
            }
            $fixed_locales = preg_replace('/ +/', '', $options['date_language']);
            $locales = explode(',', $fixed_locales);
            if (!setlocale(LC_ALL, $locales)) {
                //return "Locale Error";
                exit;
            }
            $calArray = icsCalDisplay::getCalendarArray($today, $options);
            $icsArray = unserialize($options['ics_files']);
            if ($options['ics_file_default'] == 'combine') {
                $icsFile = $icsArray;
            } elseif (strstr($options['ics_file_default'], ',')) {
                $cals = explode(',', $options['ics_file_default']);
                foreach ($cals as $calid) {
                    $icsFile[] = $icsArray[trim($calid)];
                }
            } elseif (!empty($icsArray[$options['ics_file_default']])) {
                $icsFile = $icsArray[$options['ics_file_default']];
            } else {
                $icsFile = array_shift($icsArray);
            }
            $events = ICalEvents::get_events($icsFile, $calArray[0], end($calArray) + 24 * 3600 + 1, NULL);
            if (is_array($events)) {
                foreach ($events as $event) {
                    if ($options['cal_show_multiday'] == '1') {
                        $days = ceil(($event['EndTime'] - $event['StartTime']) / (3600 * 24));
                    } else {
                        $days = 1;
                    }
                    for ($i = 0; $i < $days; $i++) {
                        $calEvents[date('Y-n-j', $event['StartTime'] + $i * 3600 * 24)][] = $event;
                    }
                }
            }
            $calContent = '<table class="ics-calendar-table" cellspacing="1" cellpadding="1" width="100%">';
            $calContent .= '<tr class="ics-calendar-days">' . "\n";
            $calContentWeekdays = array();
            for ($d = 1; $d <= 7; $d++) {
                $calContentWeekdays[] = strftime('%a', strtotime('2009-3-' . $d));
            }
            //$calContentWeekdays = array('Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat');
            $dayHolder = array_splice($calContentWeekdays, $options['cal_startday']);
            $calContentWeekdays = array_merge($dayHolder, $calContentWeekdays);
            $calContent .= '<td>' . implode('</td><td>', $calContentWeekdays) . '</td></tr>' . "\n";
            //foreach($calArray as $day){
            //	echo date('m-d-Y',$day)."<br>";
            //}
            // Display the first calendar row with correct positioning
            //Get how many complete weeks are in the actual month
            $fullWeeks = floor(count($calArray) / 7);
            $lineWeeks = $options['cal_shrink'] == '1' ? ceil(count($calArray) / 7) : 6;
            $x = 0;
            for ($i = 0; $i < $lineWeeks; $i++) {
                $calContent .= '<tr>';
                for ($j = 0; $j < 7; $j++) {
                    $currDate = getdate($calArray[$x]);
                    $x++;
                    #increase to the next item in the array.
                    $calContent .= "<td>";
                    //$calContent .= '<div id="ics-cell-'.$currDate['mon'].'-'.$currDate['mday'].'" class="ics-calendar-cell">';
                    $calContent .= '<div class="';
                    if ($currDate['mon'] == $today['mon']) {
                        $calContent .= 'date-holder';
                    } else {
                        $calContent .= 'old-date-holder';
                    }
                    ##Current selected month, or outside the month.
                    if ($currDate['mday'] == date('j', time()) && $currDate['year'] == date('Y', time()) && $currDate['mon'] == date('n', time())) {
                        $calContent .= ' ics-calendar-today';
                    }
                    #select the actual day.
                    $calContent .= '">';
                    $eventsKey = $currDate['year'] . '-' . $currDate['mon'] . '-' . $currDate['mday'];
                    /*------------>*/
                    $CAL_NUM_DISPLAY = $options['cal_events_per_day'];
                    if (isset($calEvents) && array_key_exists($eventsKey, $calEvents)) {
                        if (!function_exists('sortEvents')) {
                            function sortEvents($a, $b)
                            {
                                if ($a['StartTime'] == $b['StartTime']) {
                                    return 0;
                                }
                                return $a['StartTime'] < $b['StartTime'] ? -1 : 1;
                            }
                        }
                        usort($calEvents[$eventsKey], 'sortEvents');
                        //print_r($calEvents[$eventsKey]);
                        if (count($calEvents[$eventsKey]) > $CAL_NUM_DISPLAY) {
                            ### MORE button if there are too many events
                            $calContent .= '<a class="ics-more-button" href="javascript:void(0);" tag="ics-cell-' . $currDate['mon'] . '-' . $currDate['mday'] . '">&laquo; ' . __('more', 'WPICSImporter') . '</a>';
                            ### Get events and place them in an enlarged box.
                            $calContent .= '<div id="ics-cell-' . $currDate['mon'] . '-' . $currDate['mday'] . '" class="ics-calendar-more-box">';
                            $calContent .= '<div style="width:100%; text-align:right; "><span style="float:left; "><small><a href="javascript:void(0);" onclick="jQuery(\'#ics-cell-' . $currDate['mon'] . '-' . $currDate['mday'] . '\').hide()">&laquo; ' . __('close', 'WPICSImporter') . '</a></small></span> <strong>' . $currDate['mday'] . '</strong></div>';
                            foreach ($calEvents[$eventsKey] as $event) {
                                $eventUID = 'ics_' . md5($event['UID']);
                                $calContent .= '<div class="ics-calendar-event" icstag="' . $eventUID . $eventsKey . $cuid . '">';
                                $calContent .= $options['cal_popups'] == 'mouse-over' && !empty($event['attach']) ? '<a href="' . $event['attach'] . '" target="_blank">' . $event['Summary'] . '</a>' : $event['Summary'];
                                $calContent .= '</div>';
                            }
                            $calContent .= '</div>';
                        }
                        $calContent .= '<strong>' . $currDate['mday'] . '</strong></div>';
                        $e = 0;
                        //print '<pre>';
                        //print_r($calEvents);
                        foreach ($calEvents[$eventsKey] as $key => $event) {
                            if (!isset($event['SkipBox'])) {
                                $eventUID = 'ics_' . md5($event['UID']);
                                $showBoxNow = $eventid == $event['UID'] ? ' style="margin-top: 20px; display: block;"' : '';
                                $calContent .= '<div class="ics-calendar-event-box" id="' . $eventUID . $eventsKey . $cuid . '"' . $showBoxNow . '>';
                                $icsRequestURI = !empty($_GET['realPath']) ? base64_decode($_GET['realPath']) : $_SERVER['REQUEST_URI'];
                                $icsRequestURI = preg_replace('/(\\?|&)?(icsevent|icsdate)=([^?=&]*)/i', '', $icsRequestURI);
                                if ($options['cal_event_download'] == 1) {
                                    $icsEventLink = ICSCALENDAR_URLPATH . 'ajax-load.php?';
                                    $icsEventLink .= 'downloadEvent=' . $event['UID'] . '';
                                    $icsEventLink .= '&calendarID=' . $event['calID'] . '';
                                    $calContent .= '<div class="ics-calendar-permalink"><a href="' . $icsEventLink . '">' . __('Download', 'WPICSImporter') . '</a></div>  ';
                                }
                                if ($options['cal_permalinks'] == 1) {
                                    $icsPermalink = $icsRequestURI;
                                    $icsPermalink .= preg_match('/\\?/', $icsPermalink) ? '&' : '?';
                                    //$icsPermalink .= 'icsevent='.$event['UID'].'';
                                    //$icsPermalink .= '&icsdate='.$event['StartTime'].'';
                                    $icsPermalink .= 'ics-perm=' . $event['UID'] . '';
                                    $calContent .= '<div class="ics-calendar-permalink"><a href="' . $icsPermalink . '">' . __('Permalink', 'WPICSImporter') . '</a></div>';
                                }
                                $calContent .= '<div>' . __('Event:', 'WPICSImporter') . ' <strong>' . ($options['cal_popups'] == 'click' && !empty($event['attach']) ? '<a href="' . $event['attach'] . '" target="_blank">' . $event['Summary'] . '</a>' : $event['Summary']) . '</strong><br />';
                                if (ICalEvents::is_all_day($event['StartTime'], $event['EndTime']) || isset($options['hide_time']) && $options['hide_time'] == 'true') {
                                    $formated_date = ICalEvents::fdate($options['date_format'], $event['StartTime']);
                                } else {
                                    $formated_date = ICalEvents::format_date_range($event['StartTime'], $event['EndTime'], $event['Untimed'], $options['date_format'], $options['time_format']);
                                }
                                $calContent .= __('When:', 'WPICSImporter') . ' ' . $formated_date . '<br />';
                                if (!empty($event['Description'])) {
                                    $calContent .= __('Description:', 'WPICSImporter') . ' ' . $event['Description'] . '<br />';
                                }
                                if (!empty($event['Location'])) {
                                    $calContent .= __('Location:', 'WPICSImporter') . ' ' . $event['Location'] . '<br />';
                                }
                                $calContent .= '</div></div>';
                            }
                            $e++;
                        }
                        for ($f = 0; $f < $CAL_NUM_DISPLAY; $f++) {
                            $fevent = $calEvents[$eventsKey][$f];
                            if ($fevent['Summary'] != '') {
                                $eventUID = 'ics_' . md5($fevent['UID']);
                                $calContent .= '<div class="ics-calendar-event" icstag="' . $eventUID . $eventsKey . $cuid . '">';
                                $calContent .= $options['cal_popups'] == 'mouse-over' && !empty($fevent['attach']) ? '<a href="' . $fevent['attach'] . '" target="_blank">' . $fevent['Summary'] . '</a>' : $fevent['Summary'];
                                $calContent .= '</div>';
                            }
                        }
                    } elseif ($x <= count($calArray)) {
                        $calContent .= $currDate['mday'] . '</div>';
                    } else {
                        $calContent .= '</div>';
                    }
                    //$calContent .= '</div>';
                    $calContent .= "</td>" . "\n";
                }
                $calContent .= '</tr>' . "\n";
            }
            $calContent .= '</table>';
            $calContent .= '<script type="text/javascript">
								jQuery("#ics-prev-button' . $cuid . '").attr("month","' . date('Y-m-d', mktime(0, 0, 0, $today['mon'] - 1, 1, $today['year'])) . '");
								jQuery("#ics-next-button' . $cuid . '").attr("month","' . date('Y-m-d', mktime(0, 0, 0, $today['mon'] + 1, 1, $today['year'])) . '");
								jQuery("#ics-calendar-header-text' . $cuid . '").html("' . strftime("%B", mktime(0, 0, 0, $today['mon'], 1, $today['year'])) . ' ' . $today['year'] . ' ");
								';
            if ($options['cal_popups'] == 'mouse-over') {
                $calContent .= '	jQuery().mousemove(function(e){
										if(e.pageX > (jQuery(window).width()/2) ) {
											jQuery(".ics-calendar-event-box").css("left",e.pageX + 5 - jQuery(".ics-calendar-event-box").width());
										} else {
											jQuery(".ics-calendar-event-box").css("left",e.pageX + 5);
										}
										jQuery(".ics-calendar-event-box").css("top",e.pageY + 5);
									});';
                $calContent .= '	jQuery("div.ics-calendar-event").hover(
										function () {
											jQuery("#" + jQuery(this).attr("icstag")).show();
										}, 
										function () {
											jQuery("#" + jQuery(this).attr("icstag")).hide();
										}
									);';
            } elseif ($options['cal_popups'] == 'click') {
                $calContent .= '	jQuery("div.ics-calendar-event").click(
										function (e) {
											var $jObject = jQuery("#" + jQuery(this).attr("icstag"));
											var css = {};								
											css.marginTop = 20;
											if(jQuery(this).offset().left > (jQuery(window).width()/2) ) {
												css.marginLeft = -$jObject.width()
											} else {
												css.marginLeft = 0;
											}
											jQuery(".ics-calendar-event-box").hide();
											$jObject.css(css).show();
											e.stopPropagation();
										}
									);';
                $calContent .= '	jQuery(".ics-calendar-event-box").click(function(e) {
											e.stopPropagation();
										}
									);
									';
                $calContent .= '	jQuery(document).click(function(e){
										jQuery(".ics-calendar-event-box").hide();
									});';
            }
            $calContent .= '	jQuery("a.ics-more-button").click(function() { jQuery(".ics-calendar-more-box").hide(); jQuery("#"+jQuery(this).attr("tag")).show(); });';
            //jQuery(".ics-calendar-more-box").mouseout(function() { jQuery(this).hide(); });
            $calContent .= '</script>';
            $calContent .= '';
            return $calContent;
        }