示例#1
0
function eme_ical_single_event($event, $title_format, $description_format) {
   global $eme_timezone;
   $title = eme_sanitize_ical (eme_replace_placeholders ( $title_format, $event, "text" ));
   $description = eme_sanitize_ical (eme_replace_placeholders ( $description_format, $event, "text" ));
   $html_description = eme_sanitize_ical (eme_replace_placeholders ( $description_format, $event, "html" ),1);

   $event_link = eme_event_url($event);
   $startstring=new ExpressiveDate($event['event_start_date']." ".$event['event_start_time'],$eme_timezone);
   $dtstartdate=$startstring->format("Ymd");
   $dtstarthour=$startstring->format("His");
   //$dtstart=$dtstartdate."T".$dtstarthour."Z";
   // we'll use localtime, so no "Z"
   $dtstart=$dtstartdate."T".$dtstarthour;
   if ($event['event_end_date'] == "")
      $event['event_end_date'] = $event['event_start_date'];
   if ($event['event_end_time'] == "")
      $event['event_end_time'] = $event['event_start_time'];
   $endstring=$event['event_end_date']." ".$event['event_end_time'];
   $endstring=new ExpressiveDate($event['event_end_date']." ".$event['event_end_time'],$eme_timezone);
   $dtenddate=$endstring->format("Ymd");
   $dtendhour=$endstring->format("His");
   //$dtend=$dtenddate."T".$dtendhour."Z";
   // we'll use localtime, so no "Z"
   $dtend=$dtenddate."T".$dtendhour;
   $tzstring = get_option('timezone_string');

   $res = "";
   $res .= "BEGIN:VEVENT\r\n";
   //DTSTAMP must be in UTC format, so adding "Z" as well
   $res .= "DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\r\n";
   if ($event['event_properties']['all_day']) {
      // ical standard for an all day event: specify only the day, meaning
      // an 'all day' event is flagged as starting at the beginning of one day and lasting until the beginning of the next
      // so it is the same as adding "T000000" as time spec to the start/end datestring
      // But since it "ends" at the beginning of the next day, we should add 24 hours, otherwise the event ends one day too soon
      $dtenddate=$endstring->addOneDay()->format('Ymd');
      $res .= "DTSTART;VALUE=DATE:$dtstartdate\r\n";
      $res .= "DTEND;VALUE=DATE:$dtenddate\r\n";
   } else {
      $res .= "DTSTART;TZID=$tzstring:$dtstart\r\n";
      $res .= "DTEND;TZID=$tzstring:$dtend\r\n";
   }
   $res .= "UID:$dtstart-$dtend-".$event['event_id']."@".$_SERVER['SERVER_NAME']."\r\n";
   $res .= "SUMMARY:$title\r\n";
   $res .= "DESCRIPTION:$description\r\n";
   $res .= "X-ALT-DESC;FMTTYPE=text/html:$html_description\r\n";
   $res .= "URL:$event_link\r\n";
   $res .= "ATTACH:$event_link\r\n";
   if ($event['event_image_id']) {
      $thumb_array = image_downsize( $event['event_image_id'], get_option('eme_thumbnail_size') );
      $thumb_url = $thumb_array[0];
      $res .= "ATTACH:$thumb_url\r\n";
   }
   if (isset($event['location_id']) && $event['location_id']) {
      $location = eme_sanitize_ical (eme_replace_placeholders ( "#_LOCATION, #_ADDRESS, #_TOWN", $event, "text" ));
      $res .= "LOCATION:$location\r\n";
   }
   $res .= "END:VEVENT\r\n";
   return $res;
}
示例#2
0
function eme_create_month_scope($count)
{
    global $eme_timezone;
    $scope = array();
    $scope[0] = __('Select Month', 'eme');
    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
    for ($i = 0; $i < $count; $i++) {
        $limit_start = $eme_date_obj->format('Y-m-01');
        $days_in_month = $eme_date_obj->getDaysInMonth();
        $limit_end = $eme_date_obj->format("Y-m-{$days_in_month}");
        $this_scope = "{$limit_start}--{$limit_end}";
        $scope_text = eme_localised_date($limit_start . " " . $eme_timezone, get_option('eme_show_period_monthly_dateformat'));
        $scope[$this_scope] = $scope_text;
        $eme_date_obj->addOneMonth();
    }
    return $scope;
}
示例#3
0
 public function testDateIsCreatedWithCustomTimeString()
 {
     $date = new ExpressiveDate('31 January 1991');
     $this->assertEquals('31/01/1991', $date->format('d/m/Y'));
     $date = new ExpressiveDate('+1 day');
     $this->assertEquals(time() + 86400, $date->getTimestamp());
     $date = new ExpressiveDate('-1 day');
     $this->assertEquals(time() - 86400, $date->getTimestamp());
 }
示例#4
0
function eme_client_clock_callback() {
   // Set php clock values in an array
   $phptime_obj = new ExpressiveDate(null,$eme_timezone);
   // if clock data not set
   if (!isset($_SESSION['eme_client_unixtime'])) {
      // Preset php clock values in client session variables for fall-back if valid client clock data isn't received.
      $_SESSION['eme_client_clock_valid'] = false; // Will be set true if all client clock data passes sanity tests
      $_SESSION['eme_client_php_difference'] = 0; // Client-php clock difference integer seconds
      $_SESSION['eme_client_unixtime'] = (int) $phptime_obj->format('U'); // Integer seconds since 1/1/1970 @ 12:00 AM
      $_SESSION['eme_client_seconds'] = (int) $phptime_obj->format('s'); // Integer second this minute (0-59)
      $_SESSION['eme_client_minutes'] = (int) $phptime_obj->format('i'); // Integer minute this hour (0-59)
      $_SESSION['eme_client_hours'] = (int) $phptime_obj->format('h'); // Integer hour this day (0-23)
      $_SESSION['eme_client_wday'] = (int) $phptime_obj->format('w'); // Integer day this week (0-6), 0 = Sunday, ... , 6 = Saturday
      $_SESSION['eme_client_mday'] = (int) $phptime_obj->format('j'); // Integer day this month 1-31)
      $_SESSION['eme_client_month'] = (int) $phptime_obj->format('n'); // Integer month this year (1-12)
      $_SESSION['eme_client_fullyear'] = (int) $phptime_obj->format('Y'); // Integer year (1970-9999)
      $ret = '1'; // reload from server
   } else {
      $ret = '0';
   }
   
   // Cast client clock values as integers to avoid mathematical errors and set in temporary local variables.
   $client_unixtime = (int) $_POST['client_unixtime'];
   $client_seconds = (int) $_POST['client_seconds'];
   $client_minutes = (int) $_POST['client_minutes'];
   $client_hours = (int) $_POST['client_hours'];
   $client_wday = (int) $_POST['client_wday'];
   $client_mday = (int) $_POST['client_mday'];
   $client_month = (int) $_POST['client_month'];
   $client_fullyear = (int) $_POST['client_fullyear'];
   
   // Client clock sanity tests
   $valid = true;
   if (abs($client_unixtime - $_SESSION['eme_client_unixtime']) > 300) $valid = false; // allow +/-5 min difference
   if (abs($client_seconds - 30) > 30) $valid = false; // Seconds <0 or >60
   if (abs($client_minutes - 30) > 30) $valid = false; // Minutes <0 or >60
   if (abs($client_hours - 12) > 12) $valid = false; // Hours <0 or >24
   if (abs($client_wday - 3) > 3) $valid = false; // Weekday <0 or >6
   if (abs($client_mday - $_SESSION['eme_client_mday']) > 30) $valid = false; // >30 day difference
   if (abs($client_month - $_SESSION['eme_client_month']) > 11) $valid = false; // >11 month difference
   if (abs($client_fullyear - $_SESSION['eme_client_fullyear']) > 1) $valid = false; // >1 year difference

   // To insure mutual consistency, don't use any client values unless they all passed the tests.
   if ($valid) {
      $_SESSION['eme_client_unixtime'] = $client_unixtime;
      $_SESSION['eme_client_seconds'] = $client_seconds;
      $_SESSION['eme_client_minutes'] = $client_minutes;
      $_SESSION['eme_client_hours'] = $client_hours;
      $_SESSION['eme_client_wday'] = $client_wday;
      $_SESSION['eme_client_mday'] = $client_mday;
      $_SESSION['eme_client_month'] = $client_month;
      $_SESSION['eme_client_fullyear'] = $client_fullyear;
      $_SESSION['eme_client_clock_valid'] = true;
      // Set  date & time clock strings
      $client_clock_str = "$client_fullyear-$client_month-$client_mday $client_hours:$client_minutes:$client_seconds";
      $client_clock_obj = new ExpressiveDate($client_clock_str,$eme_timezone);
      $_SESSION['eme_client_php_difference'] = (int) $client_clock_obj->getDifferenceInSeconds($phptime_obj);
   }
   
   // it is an ajax instance: echo the result
   echo $ret;
}
示例#5
0
function eme_get_recurrence_eventids($recurrence_id, $future_only = 0)
{
    global $wpdb;
    $events_table = $wpdb->prefix . EVENTS_TBNAME;
    if ($future_only) {
        $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
        $today = $eme_date_obj->format('Y-m-d');
        $sql = $wpdb->prepare("SELECT event_id FROM {$events_table} WHERE recurrence_id = %d AND event_start_date > %s ORDER BY event_start_date ASC, event_start_time ASC", $recurrence_id, $today);
    } else {
        $sql = $wpdb->prepare("SELECT event_id FROM {$events_table} WHERE recurrence_id = %d ORDER BY event_start_date ASC, event_start_time ASC", $recurrence_id);
    }
    return $wpdb->get_col($sql);
}
示例#6
0
 /**
  * Generate the Monthly Project Report for Selected User
  * @return View
  */
 public function postUserProjectReport()
 {
     //Get the selected UserId
     $userId = \Input::get('userprojectreportid');
     //Get Details of User
     $user = \User::find($userId);
     $firstName = $user->first_name;
     $lastName = $user->last_name;
     //Get selected Project Id
     $projectId = \Input::get('projectmonth');
     //Get the selected Date for the month
     $selectedMonth = \Input::get('userprojectdate_submit');
     //Generate Month from the date
     $daysArray = \DateAndTime::getMonthDates($selectedMonth);
     //Get Data
     $data = $this->report->generateWeeklyProjectReport($daysArray, $projectId, $userId);
     //Manipulation for View
     $tempDates = array();
     foreach ($daysArray as $day) {
         $tempDay = new \ExpressiveDate($day);
         $tempDates[] = $tempDay->format('jS F, Y');
     }
     //Manipulation for Charts
     $chartWeek = json_encode($tempDates);
     $tempDate = new \ExpressiveDate($selectedMonth);
     $year = $tempDate->getYear();
     $month = $tempDate->getMonth();
     $totalNoOfDays = (int) $tempDate->getDaysInMonth();
     $allmonths = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
     $chartWeekData = json_encode($data['dayTime'], JSON_NUMERIC_CHECK);
     return \View::make('dashboard.reports.monthlyproject')->with('data', $data)->with('name', $firstName . $lastName)->with('totalDays', $totalNoOfDays)->with('dates', $daysArray)->with('year', (int) $year)->with('month', $allmonths[(int) $month])->with('chartWeek', $chartWeek)->with('chartWeekData', $chartWeekData);
 }
示例#7
0
function eme_fdgg_notification()
{
    $store_name = get_option('eme_fdgg_store_name');
    $shared_secret = get_option('eme_fdgg_shared_secret');
    require_once 'payment_gateways/fdgg/fdgg-util_sha2.php';
    $payment_id = intval($_POST['invoicenumber']);
    $charge_total = $_POST['charge_total'];
    $approval_code = $_POST['approval_code'];
    $response_hash = $_POST['response_hash'];
    $response_status = $_POST['status'];
    //$cur=$event['currency'];
    // First Data only allows USD
    $cur = "USD";
    $payment = eme_get_payment($payment_id);
    $timezone_short = "GMT";
    $eme_date_obj = new ExpressiveDate($payment['creation_date_gmt'], $timezone_short);
    $datetime = $eme_date_obj->format("Y:m:d-H:i:s");
    $calc_hash = fdgg_createHash($shared_secret . $approval_code . $charge_total . $cur . $datetime . $store_name);
    if ($response_hash != $calc_hash) {
        die('Hash Incorrect');
    }
    // TODO: do some extra checks, like the price payed and such
    #$price=eme_get_total_booking_price($event,$booking);
    if (strtolower($response_status) == 'approved') {
        eme_update_payment_payed($payment_id);
    }
}
示例#8
0
 public function widget($args, $instance)
 {
     global $wp_query, $eme_timezone;
     //extract($args);
     //$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Calendar','eme' ) : $instance['title'], $instance, $this->id_base);
     //$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     $title = apply_filters('widget_title', $instance['title']);
     $long_events = isset($instance['long_events']) ? $instance['long_events'] : false;
     $category = empty($instance['category']) ? '' : $instance['category'];
     $notcategory = empty($instance['notcategory']) ? '' : $instance['notcategory'];
     if ($instance['authorid'] == -1) {
         $author = '';
     } else {
         $authinfo = get_userdata($instance['authorid']);
         $author = $authinfo->user_login;
     }
     if (is_array($category)) {
         $category = implode(',', $category);
     }
     if (is_array($notcategory)) {
         $notcategory = implode(',', $notcategory);
     }
     $options = array();
     $options['title'] = $title;
     $options['long_events'] = $long_events;
     $options['category'] = $category;
     $options['notcategory'] = $notcategory;
     // the month shown depends on the calendar day clicked
     if (get_query_var('calendar_day')) {
         $eme_date_obj = new ExpressiveDate(get_query_var('calendar_day'), $eme_timezone);
     } else {
         $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
     }
     $options['month'] = $eme_date_obj->format('m');
     $options['year'] = $eme_date_obj->format('Y');
     $options['author'] = $author;
     echo $args['before_widget'];
     if ($title) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     eme_get_calendar($options);
     echo $args['after_widget'];
 }
示例#9
0
 public function makeTasks($tasks)
 {
     try {
         $data = array();
         foreach ($tasks as $task) {
             if ($task['status'] == 'delayed') {
                 $today = new ExpressiveDate();
                 $enddate = new ExpressiveDate($task['end_date']);
                 $task['num_status'] = (int) $today->getDifferenceInDays($enddate);
                 if ($task['num_status'] > 0) {
                     $task['status'] = 'active';
                     $tempTask = \Task::find($task['id']);
                     $tempTask->status = 'active';
                     $tempTask->save();
                 } else {
                     $task['status_desc'] = abs($task['num_status']) . ' days passed since End date';
                 }
             } elseif ($task['status'] == 'active') {
                 if ($task['end_date'] != null) {
                     $today = new ExpressiveDate();
                     $enddate = new ExpressiveDate($task['end_date']);
                     $task['num_status'] = (int) $today->getDifferenceInDays($enddate);
                     if ((int) $task['num_status'] < 0) {
                         $tempTask = \Task::find($task['id']);
                         $tempTask->status = 'delayed';
                         $tempTask->update();
                         $task['status_desc'] = abs($task['num_status']) . ' days passed since End date';
                         $task['num_status'] = 'Delayed';
                         $task['status'] = 'delayed';
                     }
                 } else {
                     $task['num_status'] = 'Active';
                 }
             }
             if ($task['project_id'] == null) {
                 $task['project_name'] = null;
             } else {
                 $project = \Project::find($task['project_id']);
                 $task['project_name'] = $project->project_name;
             }
             $tempUpdatedAt = new ExpressiveDate($task['updated_at']);
             $task['updated_at'] = $tempUpdatedAt->format('jS F, Y \\a\\t g:ia');
             $task['totalsubtasks'] = $subtasks = \Task::find($task['id'])->subtasks()->get()->count();
             if ($task['totalsubtasks'] == 0) {
                 $task['rem_subtasks'] = 0;
                 $task['subTaskPercentage'] = 0;
             } else {
                 $task['rem_subtasks'] = $subtasks = \Task::find($task['id'])->subtasks()->where('status', '=', 'active')->orWhere('status', '=', 'delayed')->get()->count();
                 $task['subTaskPercentage'] = (int) (($task['totalsubtasks'] - $task['rem_subtasks']) * 100) / $task['totalsubtasks'];
             }
             $task['users'] = \Task::find($task['id'])->users()->orderBy('first_name')->get()->toArray();
             $task['files'] = \Fileref::where('parent_id', '=', $task['id'])->where('parent_type', '=', 'task')->get()->count();
             $data[] = $task;
         }
         return $data;
     } catch (Exception $e) {
         \Log::error('Something went wrong in Task Repository - makeTasks():' . $e->getMessage());
         throw new \SomeThingWentWrongException();
     }
 }
示例#10
0
function eme_get_bookings_by_person_id($person_id, $future, $approval_status = 0)
{
    global $wpdb;
    $events_table = $wpdb->prefix . EVENTS_TBNAME;
    $bookings_table = $wpdb->prefix . BOOKINGS_TBNAME;
    if ($future) {
        $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
        $this_time = $eme_date_obj->format('Y-m-d H:i:00');
        if ($approval_status == 1) {
            $extra_condition = "bookings.approved=1 AND ";
        } elseif ($approval_status == 2) {
            $extra_condition = "bookings.approved=0 AND ";
        } else {
            $extra_condition = "";
        }
        $sql = $wpdb->prepare("select bookings.* from {$bookings_table} as bookings,{$events_table} as events where {$extra_condition} person_id = %d AND bookings.event_id=events.event_id AND CONCAT(events.event_start_date,' ',events.event_start_time)>'{$this_time}'", $person_id);
    } else {
        $sql = $wpdb->prepare("SELECT * FROM {$bookings_table} WHERE person_id = %d", $person_id);
    }
    $result = $wpdb->get_results($sql, ARRAY_A);
    return $result;
}
示例#11
0
 public function getUpdatedAtAttribute($value)
 {
     $tempUpdatedAt = new ExpressiveDate($value);
     return $tempUpdatedAt->format('jS F, Y \\a\\t g:ia');
 }
示例#12
0
function eme_rss()
{
    global $eme_timezone;
    if (isset($_GET['limit'])) {
        $limit = intval($_GET['limit']);
    } else {
        $limit = get_option('eme_event_list_number_items');
    }
    if (isset($_GET['author'])) {
        $author = $_GET['author'];
    } else {
        $author = "";
    }
    if (isset($_GET['contact_person'])) {
        $contact_person = $_GET['contact_person'];
    } else {
        $contact_person = "";
    }
    if (isset($_GET['order'])) {
        $order = $_GET['order'];
    } else {
        $order = "ASC";
    }
    if (isset($_GET['category'])) {
        $category = $_GET['category'];
    } else {
        $category = 0;
    }
    if (isset($_GET['location_id'])) {
        $location_id = $_GET['location_id'];
    } else {
        $location_id = '';
    }
    if (isset($_GET['scope'])) {
        $scope = $_GET['scope'];
    } else {
        $scope = "future";
    }
    if (isset($_GET['title'])) {
        $main_title = $_GET['title'];
    } else {
        $main_title = get_option('eme_rss_main_title');
    }
    echo "<?xml version='1.0'?>\n";
    ?>
<rss version="2.0">
<channel>
<title><?php 
    echo eme_sanitize_rss($main_title);
    ?>
</title>
<link><?php 
    $events_page_link = eme_get_events_page(true, false);
    echo eme_sanitize_rss($events_page_link);
    ?>
</link>
<description><?php 
    echo eme_sanitize_rss(get_option('eme_rss_main_description'));
    ?>
</description>
<docs>
http://blogs.law.harvard.edu/tech/rss
</docs>
<generator>
Weblog Editor 2.0
</generator>
<?php 
    $title_format = get_option('eme_rss_title_format');
    $description_format = get_option('eme_rss_description_format');
    $events = eme_get_events($limit, $scope, $order, 0, $location_id, $category, $author, $contact_person);
    # some RSS readers don't like it when an empty feed without items is returned, so we add a dummy item then
    if (empty($events)) {
        echo "<item>\n";
        echo "<title></title>\n";
        echo "<link></link>\n";
        echo "</item>\n";
    } else {
        foreach ($events as $event) {
            $title = eme_sanitize_rss(eme_replace_placeholders($title_format, $event, "rss"));
            $description = eme_sanitize_rss(eme_replace_placeholders($description_format, $event, "rss"));
            $event_link = eme_sanitize_rss(eme_event_url($event));
            echo "<item>\n";
            echo "<title>{$title}</title>\n";
            echo "<link>{$event_link}</link>\n";
            if (get_option('eme_rss_show_pubdate')) {
                if (get_option('eme_rss_pubdate_startdate')) {
                    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
                    $timezoneoffset = $eme_date_obj->format('O');
                    echo "<pubDate>" . eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone, 'D, d M Y H:i:s $timezoneoffset') . "</pubDate>\n";
                } else {
                    echo "<pubDate>" . eme_localised_date($event['modif_date_gmt'], 'D, d M Y H:i:s +0000') . "</pubDate>\n";
                }
            }
            echo "<description>{$description}</description>\n";
            if (get_option('eme_categories_enabled')) {
                $categories = eme_sanitize_rss(eme_replace_placeholders("#_CATEGORIES", $event, "rss"));
                echo "<category>{$categories}</category>\n";
            }
            echo "</item>\n";
        }
    }
    ?>

</channel>
</rss>

<?php 
}
示例#13
0
function eme_get_calendar($args = "")
{
    global $wp_locale;
    global $wpdb, $eme_timezone;
    // the calendar is being used, so we need the jquery for the calendar
    global $eme_need_calendar_js;
    $eme_need_calendar_js = 1;
    $defaults = array('category' => 0, 'notcategory' => 0, 'full' => 0, 'month' => '', 'year' => '', 'echo' => 1, 'long_events' => 0, 'author' => '', 'contact_person' => '', 'location_id' => '', 'template_id' => 0);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $echo = $echo === "true" || $echo === "1" ? true : $echo;
    $full = $full === "true" || $full === "1" ? true : $full;
    $long_events = $long_events === "true" || $long_events === "1" ? true : $long_events;
    $echo = $echo === "false" || $echo === "0" ? false : $echo;
    $full = $full === "false" || $full === "0" ? false : $full;
    $long_events = $long_events === "false" || $long_events === "0" ? false : $long_events;
    // this comes from global wordpress preferences
    $start_of_week = get_option('start_of_week');
    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
    if (get_option('eme_use_client_clock') && isset($_SESSION['eme_client_mday']) && isset($_SESSION['eme_client_month']) && isset($_SESSION['eme_client_fullyear'])) {
        // these come from client unless their clock is wrong
        $iNowDay = sprintf("%02d", $_SESSION['eme_client_mday']);
        $iNowMonth = sprintf("%02d", $_SESSION['eme_client_month']);
        $iNowYear = sprintf("%04d", $_SESSION['eme_client_fullyear']);
    } else {
        // Get current year, month and day
        list($iNowYear, $iNowMonth, $iNowDay) = explode('-', $eme_date_obj->getDate());
    }
    $iSelectedYear = $year;
    $iSelectedMonth = $month;
    if ($iSelectedMonth == '') {
        $iSelectedMonth = $iNowMonth;
    }
    if ($iSelectedYear == '') {
        $iSelectedYear = $iNowYear;
    }
    $iSelectedMonth = sprintf("%02d", $iSelectedMonth);
    // Get name and number of days of specified month
    $eme_date_obj->setDay(1);
    $eme_date_obj->setMonth($iSelectedMonth);
    $eme_date_obj->setYear($iSelectedYear);
    // Get friendly month name, but since DateTime::format doesn't respect the locale, we need eme_localised_date
    if ($full) {
        list($sMonthName, $iDaysInMonth) = explode('-', eme_localised_date($eme_date_obj->getDate(), 'F-t'));
    } else {
        list($sMonthName, $iDaysInMonth) = explode('-', eme_localised_date($eme_date_obj->getDate(), 'M-t'));
    }
    // take into account some locale info: some always best show full month name, some show month after year, some have a year suffix
    $locale_code = substr(get_locale(), 0, 2);
    $showMonthAfterYear = 0;
    $yearSuffix = "";
    switch ($locale_code) {
        case "hu":
            $showMonthAfterYear = 1;
            break;
        case "ja":
            $showMonthAfterYear = 1;
            $sMonthName = eme_localised_date($eme_date_obj->getDate(), 'F');
            $yearSuffix = "年";
            break;
        case "ko":
            $showMonthAfterYear = 1;
            $sMonthName = eme_localised_date($eme_date_obj->getDate(), 'F');
            $yearSuffix = "년";
            break;
        case "zh":
            $showMonthAfterYear = 1;
            $sMonthName = eme_localised_date($eme_date_obj->getDate(), 'F');
            $yearSuffix = "年";
            break;
    }
    if ($showMonthAfterYear) {
        $cal_datestring = "{$iSelectedYear}{$yearSuffix} {$sMonthName}";
    } else {
        $cal_datestring = "{$sMonthName} {$iSelectedYear}{$yearSuffix}";
    }
    // Get previous year and month
    $iPrevYear = $iSelectedYear;
    $iPrevMonth = $iSelectedMonth - 1;
    if ($iPrevMonth <= 0) {
        $iPrevYear--;
        $iPrevMonth = 12;
        // set to December
    }
    $iPrevMonth = sprintf("%02d", $iPrevMonth);
    // Get next year and month
    $iNextYear = $iSelectedYear;
    $iNextMonth = $iSelectedMonth + 1;
    if ($iNextMonth > 12) {
        $iNextYear++;
        $iNextMonth = 1;
    }
    $iNextMonth = sprintf("%02d", $iNextMonth);
    // Get number of days of previous month
    $eme_date_obj2 = new ExpressiveDate(null, $eme_timezone);
    $eme_date_obj2->setDay(1);
    $eme_date_obj2->setMonth($iPrevMonth);
    $eme_date_obj2->setYear($iPrevYear);
    $iPrevDaysInMonth = (int) $eme_date_obj2->getDaysInMonth();
    // Get numeric representation of the day of the week of the first day of specified (current) month
    // remember: first day of week is a Sunday
    // if you want the day of the week to begin on Monday: start_of_week=1, Tuesday: start_of_week=2, etc ...
    // So, if e.g. the month starts on a Sunday and start_of_week=1 (Monday), then $iFirstDayDow is 6
    $iFirstDayDow = (int) $eme_date_obj->getDayOfWeekAsNumeric() - $start_of_week;
    if ($iFirstDayDow < 0) {
        $iFirstDayDow += 7;
    }
    // On what day the previous month begins
    $iPrevShowFrom = $iPrevDaysInMonth - $iFirstDayDow + 1;
    // we'll look for events in the requested month and 7 days before and after
    $calbegin = "{$iPrevYear}-{$iPrevMonth}-{$iPrevShowFrom}";
    $calend = "{$iNextYear}-{$iNextMonth}-07";
    $events = eme_get_events(0, "{$calbegin}--{$calend}", "ASC", 0, $location_id, $category, $author, $contact_person, 1, $notcategory);
    $eventful_days = array();
    if ($events) {
        //Go through the events and slot them into the right d-m index
        foreach ($events as $event) {
            if ($event['event_status'] == STATUS_PRIVATE && !is_user_logged_in()) {
                continue;
            }
            $eme_date_obj_end = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $eme_date_obj_now = new ExpressiveDate(null, $eme_timezone);
            if (get_option('eme_cal_hide_past_events') && $eme_date_obj_end->lessThan($eme_date_obj_now)) {
                continue;
            }
            if ($long_events) {
                //If $long_events is set then show a date as eventful if there is an multi-day event which runs during that day
                $eme_date_obj_tmp = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                if ($eme_date_obj_end->lessThan($eme_date_obj_tmp)) {
                    $eme_date_obj_end = $eme_date_obj_tmp->copy();
                }
                $day_count = 0;
                while ($eme_date_obj_tmp->lessOrEqualTo($eme_date_obj_end)) {
                    $event_eventful_date = $eme_date_obj_tmp->getDate();
                    //Only show events on the day that they start
                    if (isset($eventful_days[$event_eventful_date]) && is_array($eventful_days[$event_eventful_date])) {
                        $eventful_days[$event_eventful_date][] = $event;
                    } else {
                        $eventful_days[$event_eventful_date] = array($event);
                    }
                    $eme_date_obj_tmp->addOneDay();
                }
            } else {
                //Only show events on the day that they start
                if (isset($eventful_days[$event['event_start_date']]) && is_array($eventful_days[$event['event_start_date']])) {
                    $eventful_days[$event['event_start_date']][] = $event;
                } else {
                    $eventful_days[$event['event_start_date']] = array($event);
                }
            }
        }
    }
    // we found all the events for the wanted days, now get them in the correct format with a good link
    if ($template_id) {
        $event_format = eme_get_template_format($template_id);
    } else {
        $event_format = get_option('eme_full_calendar_event_format');
    }
    $event_title_format = get_option('eme_small_calendar_event_title_format');
    $event_title_separator_format = get_option('eme_small_calendar_event_title_separator');
    $cells = array();
    foreach ($eventful_days as $day_key => $events) {
        // Set the date into the key
        $events_titles = array();
        foreach ($events as $event) {
            $events_titles[] = eme_replace_placeholders($event_title_format, $event, "text");
        }
        $link_title = implode($event_title_separator_format, $events_titles);
        $cal_day_link = eme_calendar_day_url($day_key);
        // Let's add the possible options
        // template_id is not being used per event
        if (!empty($location_id)) {
            $cal_day_link = add_query_arg(array('location_id' => $location_id), $cal_day_link);
        }
        if (!empty($category)) {
            $cal_day_link = add_query_arg(array('category' => $category), $cal_day_link);
        }
        if (!empty($notcategory)) {
            $cal_day_link = add_query_arg(array('notcategory' => $scope), $cal_day_link);
        }
        if (!empty($author)) {
            $cal_day_link = add_query_arg(array('author' => $author), $cal_day_link);
        }
        if (!empty($contact_person)) {
            $cal_day_link = add_query_arg(array('contact_person' => $contact_person), $cal_day_link);
        }
        $event_date = explode('-', $day_key);
        $event_day = ltrim($event_date[2], '0');
        $cells[$day_key] = "<a title='{$link_title}' href='{$cal_day_link}'>{$event_day}</a>";
        if ($full) {
            $cells[$day_key] .= "<ul class='eme-calendar-day-event'>";
            foreach ($events as $event) {
                $cells[$day_key] .= eme_replace_placeholders($event_format, $event);
            }
            $cells[$day_key] .= "</ul>";
        }
    }
    // If previous month
    $isPreviousMonth = $iFirstDayDow > 0;
    // Initial day on the calendar
    $iCalendarDay = $isPreviousMonth ? $iPrevShowFrom : 1;
    $isNextMonth = false;
    $sCalTblRows = '';
    // Generate rows for the calendar
    for ($i = 0; $i < 6; $i++) {
        // 6-weeks range
        if ($isNextMonth) {
            continue;
        }
        $sCalTblRows .= "<tr>";
        for ($j = 0; $j < 7; $j++) {
            // 7 days a week
            // we need the calendar day with 2 digits for the planned events
            $iCalendarDay_padded = sprintf("%02d", $iCalendarDay);
            if ($isPreviousMonth) {
                $calstring = "{$iPrevYear}-{$iPrevMonth}-{$iCalendarDay_padded}";
            } elseif ($isNextMonth) {
                $calstring = "{$iNextYear}-{$iNextMonth}-{$iCalendarDay_padded}";
            } else {
                $calstring = "{$iSelectedYear}-{$iSelectedMonth}-{$iCalendarDay_padded}";
            }
            // each day in the calendar has the name of the day as a class by default
            $eme_date_obj = new ExpressiveDate($calstring, $eme_timezone);
            $sClass = $eme_date_obj->format('D');
            if (isset($cells[$calstring])) {
                if ($isPreviousMonth) {
                    $sClass .= " eventful-pre event-day-{$iCalendarDay}";
                } elseif ($isNextMonth) {
                    $sClass .= " eventful-post event-day-{$iCalendarDay}";
                } elseif ($calstring == "{$iNowYear}-{$iNowMonth}-{$iNowDay}") {
                    $sClass .= " eventful-today event-day-{$iCalendarDay}";
                } else {
                    $sClass .= " eventful event-day-{$iCalendarDay}";
                }
                $sCalTblRows .= '<td class="' . $sClass . '">' . $cells[$calstring] . "</td>\n";
            } else {
                if ($isPreviousMonth) {
                    $sClass .= " eventless-pre";
                } elseif ($isNextMonth) {
                    $sClass .= " eventless-post";
                } elseif ($calstring == "{$iNowYear}-{$iNowMonth}-{$iNowDay}") {
                    $sClass .= " eventless-today";
                } else {
                    $sClass .= " eventless";
                }
                $sCalTblRows .= '<td class="' . $sClass . '">' . $iCalendarDay . "</td>\n";
            }
            // Next day
            $iCalendarDay++;
            if ($isPreviousMonth && $iCalendarDay > $iPrevDaysInMonth) {
                $isPreviousMonth = false;
                $iCalendarDay = 1;
            }
            if (!$isPreviousMonth && !$isNextMonth && $iCalendarDay > $iDaysInMonth) {
                $isNextMonth = true;
                $iCalendarDay = 1;
            }
        }
        $sCalTblRows .= "</tr>\n";
    }
    $weekdays = array(__('Sunday'), __('Monday'), __('Tuesday'), __('Wednesday'), __('Thursday'), __('Friday'), __('Saturday'));
    $sCalDayNames = "";
    // respect the beginning of the week offset
    for ($i = $start_of_week; $i < $start_of_week + 7; $i++) {
        $j = $i;
        if ($j == 7) {
            $j -= 7;
        }
        if ($full) {
            $sCalDayNames .= "<td>" . $wp_locale->get_weekday_abbrev($weekdays[$j]) . "</td>";
        } else {
            $sCalDayNames .= "<td>" . $wp_locale->get_weekday_initial($weekdays[$j]) . "</td>";
        }
    }
    // the real links are created via jquery when clicking on the prev-month or next-month class-links
    $previous_link = "<a class='prev-month' href=\"#\">&lt;&lt;</a>";
    $next_link = "<a class='next-month' href=\"#\">&gt;&gt;</a>";
    $random = rand(100, 200);
    $full ? $class = 'eme-calendar-full' : ($class = 'eme-calendar');
    $calendar = "<div class='{$class}' id='eme-calendar-{$random}'>";
    if ($full) {
        $fullclass = 'fullcalendar';
        $head = "<td class='month_name' colspan='7'>{$previous_link} {$next_link} {$cal_datestring}</td>\n";
    } else {
        $fullclass = '';
        $head = "<td>{$previous_link}</td><td class='month_name' colspan='5'>{$cal_datestring}</td><td>{$next_link}</td>\n";
    }
    // Build the heading portion of the calendar table
    $calendar .= "<table class='eme-calendar-table {$fullclass}'>\n" . "<thead>\n<tr>\n" . $head . "</tr>\n</thead>\n" . "<tr class='days-names'>\n" . $sCalDayNames . "</tr>\n";
    $calendar .= $sCalTblRows;
    $calendar .= "</table>\n</div>";
    // we generate the onclick javascript per calendar div
    // this is important if more than one calendar exists on the page
    $calendar .= "<script type='text/javascript'>\n         jQuery('#eme-calendar-" . $random . " a.prev-month').click(function(e){\n            e.preventDefault();\n            tableDiv = jQuery('#eme-calendar-" . $random . "');\n            loadCalendar(tableDiv, '{$full}', '{$long_events}','{$iPrevMonth}','{$iPrevYear}','{$category}','{$author}','{$contact_person}','{$location_id}','{$notcategory}','{$template_id}');\n         } );\n         jQuery('#eme-calendar-" . $random . " a.next-month').click(function(e){\n            e.preventDefault();\n            tableDiv = jQuery('#eme-calendar-" . $random . "');\n            loadCalendar(tableDiv, '{$full}', '{$long_events}','{$iNextMonth}','{$iNextYear}','{$category}','{$author}','{$contact_person}','{$location_id}','{$notcategory}','{$template_id}');\n         } );\n         </script>";
    $output = $calendar;
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
示例#14
0
function eme_get_category_eventids($category_id,$future=0) {
   // similar to eme_get_recurrence_eventids
   global $wpdb;
   $events_table = $wpdb->prefix.EVENTS_TBNAME;
   if ($future_only) {
      $eme_date_obj=new ExpressiveDate(null,$eme_timezone);
      $today = $eme_date_obj->format('Y-m-d');
      $sql = $wpdb->prepare("SELECT event_id FROM $events_table WHERE FIND_IN_SET(%d,event_category_ids) AND event_start_date > %s ORDER BY event_start_date ASC, event_start_time ASC",$category_id,$today);
   } else {
      $sql = $wpdb->prepare("SELECT event_id FROM $events_table WHERE FIND_IN_SET(%d,event_category_ids) ORDER BY event_start_date ASC, event_start_time ASC",$category_id);
   }
   return $wpdb->get_col($sql);
}