Ejemplo n.º 1
0
function eme_ical_single_event($event, $title_format, $description_format)
{
    $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 = $event['event_start_date'] . " " . $event['event_start_time'];
    $dtstartdate = eme_localised_date($startstring, "Ymd");
    $dtstarthour = eme_localised_date($startstring, "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'];
    $dtenddate = eme_localised_date($endstring, "Ymd");
    $dtendhour = eme_localised_date($endstring, "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 = eme_localised_date(eme_date_calc("+1 day", $endstring), "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;
}
Ejemplo n.º 2
0
function eme_create_year_scope($count)
{
    $day_offset = date('j') - 1;
    $scope = array();
    $scope[0] = __('Select Year', 'eme');
    for ($i = 0; $i < $count; $i++) {
        $year = date('Y', strtotime("{$i} year -{$day_offset} days"));
        $limit_start = "{$year}-01-01";
        $limit_end = "{$year}-12-31";
        $this_scope = "{$limit_start}--{$limit_end}";
        $scope_text = eme_localised_date($limit_start, get_option('eme_show_period_yearly_dateformat'));
        $scope[$this_scope] = $scope_text;
    }
    return $scope;
}
Ejemplo n.º 3
0
function eme_create_year_scope($count)
{
    global $eme_timezone;
    $scope = array();
    $scope[0] = __('Select Year', 'eme');
    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
    for ($i = 0; $i < $count; $i++) {
        $year = $eme_date_obj->getYear();
        $limit_start = "{$year}-01-01";
        $limit_end = "{$year}-12-31";
        $this_scope = "{$limit_start}--{$limit_end}";
        $scope_text = eme_localised_date($limit_start . " " . $eme_timezone, get_option('eme_show_period_yearly_dateformat'));
        $scope[$this_scope] = $scope_text;
        $eme_date_obj->addOneYear();
    }
    return $scope;
}
Ejemplo n.º 4
0
function eme_printable_booking_report($event_id) {
   global $eme_timezone;
   $event = eme_get_event($event_id);
   $current_userid=get_current_user_id();
   if (!(current_user_can( get_option('eme_cap_edit_events')) || current_user_can( get_option('eme_cap_list_events')) ||
        (current_user_can( get_option('eme_cap_author_event')) && ($event['event_author']==$current_userid || $event['event_contactperson_id']==$current_userid)))) {
        echo "No access";
        die;
   }

   $is_multiprice = eme_is_multi($event['price']);
   $is_multiseat = eme_is_multi($event['event_seats']);
   $bookings = eme_get_bookings_for($event_id);
   $answer_columns = eme_get_answercolumns(eme_get_bookingids_for($event_id));
   $available_seats = eme_get_available_seats($event_id);
   $booked_seats = eme_get_booked_seats($event_id);
   $pending_seats = eme_get_pending_seats($event_id);
   if ($is_multiseat) {
      $available_seats_ms=eme_convert_array2multi(eme_get_available_multiseats($event_id));
      $booked_seats_ms=eme_convert_array2multi(eme_get_booked_multiseats($event_id));
      $pending_seats_ms=eme_convert_array2multi(eme_get_pending_multiseats($event_id));
   }

   $stylesheet = EME_PLUGIN_URL."events_manager.css";
   foreach($answer_columns as $col) {
      $formfield[$col["field_name"]]=eme_get_formfield_id_byname($col["field_name"]);
   }
   ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html>
      <head>
         <meta http-equiv="Content-type" content="text/html; charset=utf-8">
         <title>Bookings for <?php echo eme_trans_sanitize_html($event['event_name']);?></title>
          <link rel="stylesheet" href="<?php echo $stylesheet; ?>" type="text/css" media="screen" />
          <?php
            $file_name= get_stylesheet_directory()."/eme.css";
            if (file_exists($file_name))
               echo "<link rel='stylesheet' href='".get_stylesheet_directory_uri()."/eme.css' type='text/css' media='screen' />\n";
            $file_name= get_stylesheet_directory()."/eme_print.css";
            if (file_exists($file_name))
               echo "<link rel='stylesheet' href='".get_stylesheet_directory_uri()."/eme_print.css' type='text/css' media='print' />\n";
          ?>
      </head>
      <body id="eme_printable_body">
         <div id="eme_printable_container">
         <h1>Bookings for <?php echo eme_trans_sanitize_html($event['event_name']);?></h1> 
         <p><?php echo eme_localised_date($event['event_start_date']." ".$event['event_start_time']." ".$eme_timezone); ?></p>
         <p><?php if ($event['location_id']) echo eme_replace_placeholders("#_LOCATIONNAME, #_ADDRESS, #_TOWN", $event); ?></p>
         <?php if ($event['price']) ?>
            <p><?php _e ( 'Price: ','eme' ); echo eme_replace_placeholders("#_CURRENCY #_PRICE", $event)?></p>
         <h1><?php _e('Bookings data', 'eme');?></h1>
         <table id="eme_printable_table">
            <tr>
               <th scope='col' class='eme_print_id'><?php _e('ID', 'eme')?></th>
               <th scope='col' class='eme_print_name'><?php _e('Last Name', 'eme')?></th>
               <th scope='col' class='eme_print_name'><?php _e('First Name', 'eme')?></th>
               <th scope='col' class='eme_print_email'><?php _e('E-mail', 'eme')?></th>
               <th scope='col' class='eme_print_phone'><?php _e('Phone number', 'eme')?></th> 
               <th scope='col' class='eme_print_seats'><?php if ($is_multiprice) _e('Seats (Multiprice)', 'eme'); else _e('Seats', 'eme'); ?></th>
               <th scope='col' class='eme_print_paid'><?php _e('Paid', 'eme')?></th>
               <th scope='col' class='eme_print_booking_date'><?php _e('Booking date', 'eme')?></th>
               <th scope='col' class='eme_print_total_price'><?php _e('Total price', 'eme')?></th>
               <th scope='col' class='eme_print_unique_nbr'><?php _e('Unique nbr', 'eme')?></th>
               <th scope='col' class='eme_print_comment'><?php _e('Comment', 'eme')?></th> 
            <?php
            $nbr_columns=11;
            foreach($answer_columns as $col) {
               $class="eme_print_formfield".$formfield[$col['field_name']];
               print "<th scope='col' class='$class'>".$col['field_name']."</th>";
               $nbr_columns++;
            }
            ?>
            </tr>
            <?php
            foreach($bookings as $booking) {
               $localised_booking_date = eme_localised_date($booking['creation_date']." ".$eme_timezone);
               $localised_booking_time = eme_localised_time($booking['creation_date']." ".$eme_timezone);
               $person = eme_get_person ($booking['person_id']);
               $pending_string="";
               if (eme_event_needs_approval($event_id) && !$booking['booking_approved']) {
                  $pending_string=__('(pending)','eme');
               }
                ?>
            <tr>
               <td class='eme_print_id'><?php echo $booking['booking_id']?></td> 
               <td class='eme_print_name'><?php echo $person['lastname']?></td> 
               <td class='eme_print_name'><?php echo $person['firstname']?></td> 
               <td class='eme_print_email'><?php echo $person['email']?></td>
               <td class='eme_print_phone'><?php echo $person['phone']?></td>
               <td class='eme_print_seats' class='seats-number'><?php 
               if ($is_multiprice) {
                  // in cases where the event switched to multiprice, but somebody already registered while it was still single price: booking_seats_mp is then empty
                  if ($booking['booking_seats_mp'] == "")
                     $booking['booking_seats_mp']=$booking['booking_seats'];
                  echo $booking['booking_seats']." (".$booking['booking_seats_mp'].") ".$pending_string;
               } else {
                  echo $booking['booking_seats']." ".$pending_string;
               }
               ?>
               </td>
               <td class='eme_print_paid'><?php if ($booking['booking_payed']) _e('Yes'); else _e('No'); ?></td>
               <td class='eme_print_booking_date'><?php echo $localised_booking_date." ".$localised_booking_time; ?></td>
               <td class='eme_print_total_price'><?php echo eme_get_total_booking_price($event,$booking); ?></td>
               <td class='eme_print_unique_nbr'><?php echo $booking['transfer_nbr_be97']; ?></td>
               <td class='eme_print_comment'><?=$booking['booking_comment'] ?></td> 
               <?php
                  $answers = eme_get_answers($booking['booking_id']);
                  foreach($answer_columns as $col) {
                     $found=0;
                     foreach ($answers as $answer) {
                        $class="eme_print_formfield".$formfield[$col['field_name']];
                        if ($answer['field_name'] == $col['field_name']) {
                           print "<td class='$class'>".eme_sanitize_html(eme_convert_answer2tag($answer))."</td>";
                           $found=1;
                           break;
                        }
                     }
                     # to make sure the number of columns are correct, we add an empty answer if none was found
                     if (!$found)
                        print "<td class='$class'>&nbsp;</td>";
                  }
               ?>
            </tr>
               <?php } ?>
            <tr id='eme_printable_booked-seats'>
               <td colspan='<?php echo $nbr_columns-4;?>'>&nbsp;</td>
               <td class='total-label'><?php _e('Booked', 'eme')?>:</td>
               <td colspan='3' class='seats-number'><?php
               print $booked_seats;
               if ($is_multiseat) print " ($booked_seats_ms)";
			      if ($pending_seats>0) {
                  if ($is_multiseat)
                     print " ".sprintf( __('(%s pending)','eme'), $pending_seats . " ($pending_seats_ms)");
                  else
                     print " ".sprintf( __('(%s pending)','eme'), $pending_seats);
               }
               ?>
            </td>
            </tr>
            <tr id='eme_printable_available-seats'>
               <td colspan='<?php echo $nbr_columns-4;?>'>&nbsp;</td>
               <td class='total-label'><?php _e('Available', 'eme')?>:</td>
               <td colspan='3' class='seats-number'><?php print $available_seats; if ($is_multiseat) print " ($available_seats_ms)"; ?></td>
            </tr>
         </table>
         </div>
      </body>
      </html>
      <?php
      die();
} 
Ejemplo n.º 5
0
function eme_localised_time($mydate) {
   global $eme_time_format;
   $result = eme_localised_date($mydate,$eme_time_format);
   if (get_option('eme_time_remove_leading_zeros')) {
      $result = str_replace(":00","",$result);
      $result = str_replace(":0",":",$result);
   }
   return $result;
}
Ejemplo n.º 6
0
function eme_get_recurrence_desc($recurrence_id)
{
    global $wpdb, $eme_timezone;
    $events_table = $wpdb->prefix . EVENTS_TBNAME;
    $recurrence_table = $wpdb->prefix . RECURRENCE_TBNAME;
    $sql = $wpdb->prepare("SELECT * FROM {$recurrence_table} WHERE recurrence_id = %d", $recurrence_id);
    $recurrence = $wpdb->get_row($sql, ARRAY_A);
    $weekdays_name = array(__('Monday'), __('Tuesday'), __('Wednesday'), __('Thursday'), __('Friday'), __('Saturday'), __('Sunday'));
    $monthweek_name = array('1' => __('the first %s of the month', 'eme'), '2' => __('the second %s of the month', 'eme'), '3' => __('the third %s of the month', 'eme'), '4' => __('the fourth %s of the month', 'eme'), '5' => __('the fifth %s of the month', 'eme'), '-1' => __('the last %s of the month', 'eme'));
    $output = sprintf(__('From %1$s to %2$s', 'eme'), eme_localised_date($recurrence['recurrence_start_date'] . " " . $eme_timezone), eme_localised_date($recurrence['recurrence_end_date'] . " " . $eme_timezone)) . ", ";
    if ($recurrence['recurrence_freq'] == 'daily') {
        $freq_desc = __('everyday', 'eme');
        if ($recurrence['recurrence_interval'] > 1) {
            $freq_desc = sprintf(__("every %s days", 'eme'), $recurrence['recurrence_interval']);
        }
    } elseif ($recurrence['recurrence_freq'] == 'weekly') {
        if (!$recurrence['recurrence_byday']) {
            # no weekdays given for the recurrence, so we use the
            # day of the week of the startdate as reference
            $recurrence['recurrence_byday'] = eme_localised_date($recurrence['recurrence_start_date'] . " " . $eme_timezone, 'w');
            # Sunday is 7, not 0
            if ($recurrence['recurrence_byday'] == 0) {
                $recurrence['recurrence_byday'] = 7;
            }
        }
        $weekday_array = explode(",", $recurrence['recurrence_byday']);
        $natural_days = array();
        foreach ($weekday_array as $day) {
            array_push($natural_days, $weekdays_name[$day - 1]);
        }
        $and_string = __(" and ", 'eme');
        $output .= implode($and_string, $natural_days);
        $freq_desc = ", " . __('every week', 'eme');
        if ($recurrence['recurrence_interval'] > 1) {
            $freq_desc = ", " . sprintf(__("every %s weeks", 'eme'), $recurrence['recurrence_interval']);
        }
    } elseif ($recurrence['recurrence_freq'] == 'monthly') {
        if (!$recurrence['recurrence_byday']) {
            # no monthday given for the recurrence, so we use the
            # day of the month of the startdate as reference
            $recurrence['recurrence_byday'] = eme_localised_date($recurrence['recurrence_start_date'] . " " . $eme_timezone, 'e');
        }
        $weekday_array = explode(",", $recurrence['recurrence_byday']);
        $natural_days = array();
        foreach ($weekday_array as $day) {
            array_push($natural_days, $weekdays_name[$day - 1]);
        }
        $and_string = __(" and ", 'eme');
        $freq_desc = sprintf($monthweek_name[$recurrence['recurrence_byweekno']], implode($and_string, $natural_days));
        $freq_desc = ", " . __('every month', 'eme');
        if ($recurrence['recurrence_interval'] > 1) {
            $freq_desc .= ", " . sprintf(__("every %s months", 'eme'), $recurrence['recurrence_interval']);
        }
    } elseif ($recurrence['recurrence_freq'] == 'specific') {
        return __("Specific days", 'eme');
    } else {
        $freq_desc = "";
    }
    $output .= $freq_desc;
    return $output;
}
Ejemplo n.º 7
0
function eme_replace_placeholders($format, $event, $target = "html", $do_shortcode = 1, $lang = '')
{
    global $eme_need_gmap_js, $eme_timezone;
    // an initial filter for the format, in case people want to change anything before the placeholders get replaced
    if (has_filter('eme_events_format_prefilter')) {
        $format = apply_filters('eme_events_format_prefilter', $format, $event);
    }
    // some variables we'll use further down more than once
    $current_userid = get_current_user_id();
    $person_id = eme_get_person_id_by_wp_id($current_userid);
    $eme_enable_notes_placeholders = get_option('eme_enable_notes_placeholders');
    if (isset($event['location_id']) && $event['location_id']) {
        $location = eme_get_location($event['location_id']);
    } else {
        $location = eme_new_location();
    }
    // first replace the notes sections, since these can contain other placeholders
    if ($eme_enable_notes_placeholders) {
        $format = eme_replace_notes_placeholders($format, $event, $target);
    }
    // then we do the custom attributes, since these can contain other placeholders
    preg_match_all("/#(ESC|URL)?_ATT\\{.+?\\}(\\{.+?\\})?/", $format, $results);
    foreach ($results[0] as $resultKey => $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = "";
        //Strip string of placeholder and just leave the reference
        $attRef = substr(substr($result, 0, strpos($result, '}')), 6);
        if (isset($event['event_attributes'][$attRef])) {
            $replacement = $event['event_attributes'][$attRef];
        }
        if (trim($replacement) == '' && isset($results[2][$resultKey]) && $results[2][$resultKey] != '') {
            //Check to see if we have a second set of braces;
            $replacement = substr($results[2][$resultKey], 1, strlen(trim($results[2][$resultKey])) - 2);
        }
        if ($need_escape) {
            $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
        }
        if ($need_urlencode) {
            $replacement = rawurlencode($replacement);
        }
        $format = str_replace($orig_result, $replacement, $format);
    }
    // and now all the other placeholders
    $legacy = get_option('eme_legacy');
    $deprecated = get_option('eme_deprecated');
    if ($legacy) {
        preg_match_all("/#(ESC|URL)?@?_?[A-Za-z0-9_]+(\\[.*\\])?(\\[.*\\])?/", $format, $placeholders);
    } else {
        preg_match_all("/#(ESC|URL)?@?_?[A-Za-z0-9_]+(\\{.*?\\})?(\\{.*?\\})?/", $format, $placeholders);
    }
    // make sure we set the largest matched placeholders first, otherwise if you found e.g.
    // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ...
    usort($placeholders[0], 'sort_stringlenth');
    // if the add and remove booking form appear on the same page, we need to decide which form shows the "message" upon booking
    // the first one wins
    $a1 = strpos($format, "ADDBOOKINGFORM");
    $a2 = strpos($format, "REMOVEBOOKINGFORM");
    $show_message_on_add = 1;
    $show_message_on_remove = 1;
    if ($a1 !== false && $a2 !== false) {
        if ($a1 < $a2) {
            $show_message_on_remove = 0;
        } else {
            $show_message_on_add = 0;
        }
    }
    $eme_date_obj_now = new ExpressiveDate(null, $eme_timezone);
    foreach ($placeholders[0] as $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        $found = 1;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = "";
        // matches all fields placeholder
        if ($event && preg_match('/#_EDITEVENTLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = "<a href=' " . admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event['event_id']) . "'>" . __('Edit') . "</a>";
            }
        } elseif ($event && preg_match('/#_EDITEVENTURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_EVENTPRINTBOOKINGSLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = "<a href=' " . admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']) . "'>" . __('Printable view of bookings', 'eme') . "</a>";
            }
        } elseif ($event && preg_match('/#_EVENTPRINTBOOKINGSURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_EVENTCSVBOOKINGSLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = "<a href=' " . admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']) . "'>" . __('Printable view of bookings', 'eme') . "</a>";
            }
        } elseif ($event && preg_match('/#_EVENTCSVBOOKINGSURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
                $replacement = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_STARTDATE/', $result)) {
            $replacement = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_STARTTIME/', $result)) {
            $replacement = eme_localised_time($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_ENDDATE/', $result)) {
            $replacement = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_ENDTIME/', $result)) {
            $replacement = eme_localised_time($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_24HSTARTTIME/', $result)) {
            $replacement = substr($event['event_start_time'], 0, 5);
        } elseif ($event && preg_match('/#_24HENDTIME$/', $result)) {
            $replacement = substr($event['event_end_time'], 0, 5);
        } elseif ($event && preg_match('/#_PAST_FUTURE_CLASS/', $result)) {
            $eme_start_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $eme_end_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            if ($eme_start_obj->greaterThan($eme_date_obj_now)) {
                $replacement = "eme-future-event";
            } elseif ($eme_start_obj->lessOrEqualTo($eme_date_obj_now) && $eme_end_obj->greaterOrEqualTo($eme_date_obj_now)) {
                $replacement = "eme-ongoing-event";
            } else {
                $replacement = "eme-past-event";
            }
        } elseif ($event && preg_match('/#_12HSTARTTIME$/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone)->format('h:i A');
        } elseif ($event && preg_match('/#_12HENDTIME$/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone)->format('h:i A');
        } elseif ($event && preg_match('/#_12HSTARTTIME_NOLEADINGZERO/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone)->format('g:i A');
            if (get_option('eme_time_remove_leading_zeros')) {
                $replacement = str_replace(":00", "", $replacement);
                $replacement = str_replace(":0", ":", $replacement);
            }
        } elseif ($event && preg_match('/#_12HENDTIME_NOLEADINGZERO/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone)->format('g:i A');
            if (get_option('eme_time_remove_leading_zeros')) {
                $replacement = str_replace(":00", "", $replacement);
                $replacement = str_replace(":0", ":", $replacement);
            }
        } elseif ($event && preg_match('/#_MAP/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } elseif (isset($event['location_id']) && $event['location_id']) {
                $replacement = eme_single_location_map($location);
            }
        } elseif ($event && preg_match('/#_DIRECTIONS/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } elseif (isset($event['location_id']) && $event['location_id']) {
                $replacement = eme_add_directions_form($location);
            }
        } elseif ($event && preg_match('/#_EVENTS_FILTERFORM/', $result)) {
            if ($target == "rss" || $target == "text" || eme_is_single_event_page()) {
                $replacement = "";
            } else {
                $replacement = eme_filter_form();
            }
        } elseif ($event && preg_match('/#_ADDBOOKINGFORM$/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } else {
                $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add);
            }
        } elseif ($event && preg_match('/#_ADDBOOKINGFORM_IF_NOT_REGISTERED/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } else {
                $not_registered_only = 1;
                $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add, $not_registered_only);
            }
        } elseif ($event && preg_match('/#_REMOVEBOOKINGFORM$/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } else {
                // when the booking just happened and the user needs to pay, we don't show the remove booking form
                if ($booking_id_done && eme_event_can_pay_online($event)) {
                    $replacement = "";
                } else {
                    $replacement = eme_delete_booking_form($event['event_id'], $show_message_on_remove);
                }
            }
        } elseif ($event && preg_match('/#_REMOVEBOOKINGFORM_IF_REGISTERED/', $result)) {
            if ($target == "rss" || $target == "text") {
                $replacement = "";
            } elseif (is_user_logged_in()) {
                // when the booking just happened and the user needs to pay, we don't show the remove booking form
                if ($booking_id_done && eme_event_can_pay_online($event)) {
                    $replacement = "";
                } elseif (eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) {
                    $replacement = eme_delete_booking_form($event['event_id'], $show_message_on_remove);
                }
            }
        } elseif ($event && preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)$/', $result)) {
            $replacement = eme_get_available_seats($event['event_id']);
        } elseif ($deprecated && preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)(\\d+)/', $result, $matches) || preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_available_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(TOTALSPACES|TOTALSEATS)$/', $result)) {
            $replacement = $event['event_seats'];
        } elseif ($deprecated && preg_match('/#_(TOTALSPACES|TOTALSEATS)(\\d+)/', $result, $matches) || preg_match('/#_(TOTALSPACES|TOTALSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_convert_multi2array($event['event_seats']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)$/', $result)) {
            $replacement = eme_get_booked_seats($event['event_id']);
        } elseif ($deprecated && preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)(\\d+)/', $result, $matches) || preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_booked_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(PENDINGSPACES|PENDINGSEATS)$/', $result)) {
            $replacement = eme_get_pending_seats($event['event_id']);
        } elseif ($event && preg_match('/#_(PENDINGSPACES|PENDINGSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_pending_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_(APPROVEDSPACES|APPROVEDSEATS)$/', $result)) {
            $replacement = eme_get_approved_seats($event['event_id']);
        } elseif ($event && preg_match('/#_(APPROVEDSPACES|APPROVEDSEATS)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]) - 1;
            $replacement = 0;
            if (eme_is_multi($event['event_seats'])) {
                $seats = eme_get_approved_multiseats($event['event_id']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif ($event && preg_match('/#_USER_(RESERVEDSPACES|BOOKEDSEATS)$/', $result)) {
            if (is_user_logged_in()) {
                $replacement = eme_get_booked_seats_by_wp_event_id($current_userid, $event['event_id']);
            }
        } elseif ($event && preg_match('/#_LINKEDNAME/', $result)) {
            $event_link = eme_event_url($event, $lang);
            if ($target == "html") {
                $replacement = "<a href='{$event_link}' title='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'>" . eme_trans_sanitize_html($event['event_name'], $lang) . "</a>";
            } else {
                $replacement = eme_translate($event['event_name'], $lang);
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_ICALLINK/', $result)) {
            $url = site_url("/?eme_ical=public_single&amp;event_id=" . $event['event_id']);
            $replacement = "<a href='{$url}'>ICAL</a>";
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_ICALURL/', $result)) {
            $replacement = site_url("/?eme_ical=public_single&amp;event_id=" . $event['event_id']);
        } elseif ($event && preg_match('/#_EVENTIMAGE$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $event['event_image_url'] = wp_get_attachment_url($event['event_image_id']);
            }
            if ($event['event_image_url'] != '') {
                $replacement = "<img src='" . $event['event_image_url'] . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_EVENTIMAGEURL$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $event['event_image_url'] = wp_get_attachment_url($event['event_image_id']);
            }
            if ($event['event_image_url'] != '') {
                $replacement = $event['event_image_url'];
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMB$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], get_option('eme_thumbnail_size'));
                $thumb_url = $thumb_array[0];
                $thumb_width = $thumb_array[1];
                $thumb_height = $thumb_array[2];
                $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMBURL$/', $result)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], get_option('eme_thumbnail_size'));
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMB\\{(.+)\\}/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $thumb_width = $thumb_array[1];
                $thumb_height = $thumb_array[2];
                $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($legacy && $event && preg_match('/#_EVENTIMAGETHUMB\\[(.+)\\]/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $thumb_width = $thumb_array[1];
                $thumb_height = $thumb_array[2];
                $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>";
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_EVENTIMAGETHUMBURL\\{(.+)\\}/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
            }
        } elseif ($legacy && $event && preg_match('/#_EVENTIMAGETHUMBURL\\[(.+)\\]/', $result, $matches)) {
            if (!empty($event['event_image_id'])) {
                $thumb_array = image_downsize($event['event_image_id'], $matches[1]);
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
            }
        } elseif ($event && preg_match('/#_EVENTATT\\{(.+)\\}\\{(.+)\\}/', $result, $matches)) {
            $tmp_event_id = intval($matches[1]);
            $tmp_event_attkey = $matches[2];
            $tmp_event = eme_get_event($tmp_event_id);
            if (isset($tmp_event['event_attributes'][$tmp_event_attkey])) {
                $replacement = $tmp_event['event_attributes'][$tmp_event_attkey];
            }
        } elseif ($event && preg_match('/#_MYLOCATIONATT\\{(.+)\\}/', $result, $matches)) {
            $tmp_attkey = $matches[1];
            if (isset($location['location_attributes'][$tmp_attkey])) {
                $replacement = $location['location_attributes'][$tmp_attkey];
            }
        } elseif ($event && preg_match('/#_EVENTPAGEURL\\{(.+)\\}/', $result, $matches)) {
            $events_page_link = eme_get_events_page(true, false);
            $replacement = add_query_arg(array('event_id' => intval($matches[1])), $events_page_link);
            if (!empty($lang)) {
                $replacement = add_query_arg(array('lang' => $lang), $replacement);
            }
        } elseif ($legacy && $event && preg_match('/#_EVENTPAGEURL\\[(.+)\\]/', $result, $matches)) {
            $events_page_link = eme_get_events_page(true, false);
            $replacement = add_query_arg(array('event_id' => intval($matches[1])), $events_page_link);
            if (!empty($lang)) {
                $replacement = add_query_arg(array('lang' => $lang), $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTPAGEURL$/', $result)) {
            $replacement = eme_event_url($event, $lang);
        } elseif ($event && preg_match('/#_(NAME|EVENTNAME)$/', $result)) {
            $field = "event_name";
            if (isset($event[$field])) {
                $replacement = $event[$field];
            }
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html($replacement, $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate($replacement, $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate($replacement, $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTID/', $result)) {
            $field = "event_id";
            $replacement = intval($event[$field]);
        } elseif ($event && preg_match('/#_SINGLE_EVENTPAGE_EVENTID/', $result)) {
            // returns the event id of the single event page currently shown
            if (eme_is_single_event_page()) {
                $replacement = intval(get_query_var('event_id'));
            }
        } elseif ($event && preg_match('/#_DAYS_TILL_START/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $replacement = $eme_date_obj_now->getDifferenceInDays($eme_date_obj);
        } elseif ($event && preg_match('/#_DAYS_TILL_END/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $replacement = $eme_date_obj_now->getDifferenceInDays($eme_date_obj);
        } elseif ($event && preg_match('/#_HOURS_TILL_START/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $replacement = round($eme_date_obj_now->getDifferenceInHours($eme_date_obj));
        } elseif ($event && preg_match('/#_HOURS_TILL_END/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $replacement = round($eme_date_obj_now->getDifferenceInHours($eme_date_obj));
        } elseif ($event && preg_match('/#_EVENTPRICE$|#_PRICE$/', $result)) {
            $field = "price";
            if ($event[$field]) {
                $replacement = $event[$field];
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($deprecated && $event && preg_match('/#_(EVENT)?PRICE(\\d+)/', $result, $matches) || $event && preg_match('/#_(EVENT)?PRICE\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2] - 1);
            if ($event["price"] && eme_is_multi($event["price"])) {
                $prices = eme_convert_multi2array($event["price"]);
                if (is_array($prices) && array_key_exists($field_id, $prices)) {
                    $replacement = $prices[$field_id];
                    if ($target == "html") {
                        $replacement = apply_filters('eme_general', $replacement);
                    } elseif ($target == "rss") {
                        $replacement = apply_filters('eme_general_rss', $replacement);
                    } else {
                        $replacement = apply_filters('eme_text', $replacement);
                    }
                }
            }
        } elseif ($event && preg_match('/#_CURRENCY/', $result)) {
            $field = "currency";
            // currency is only important if the price is not empty as well
            if ($event['price']) {
                $replacement = $event[$field];
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_ATTENDEES/', $result)) {
            $replacement = eme_get_attendees_list_for($event);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_BOOKINGS/', $result)) {
            $replacement = eme_get_bookings_list_for_event($event);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_(CONTACTNAME|CONTACTPERSON)/', $result)) {
            $contact = eme_get_contact($event);
            if ($contact) {
                $replacement = $contact->display_name;
            }
            $replacement = eme_trans_sanitize_html($replacement, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_(CONTACTEMAIL|PLAIN_CONTACTEMAIL)/', $result)) {
            $contact = eme_get_contact($event);
            if ($contact) {
                $replacement = $contact->user_email;
                if ($target == "html") {
                    // ascii encode for primitive harvesting protection ...
                    $replacement = eme_ascii_encode($replacement);
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_CONTACTPHONE/', $result)) {
            $contact = eme_get_contact($event);
            if ($contact) {
                $phone = eme_get_user_phone($contact->ID);
                // ascii encode for primitive harvesting protection ...
                $replacement = eme_ascii_encode($phone);
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_AUTHORNAME/', $result)) {
            $author = eme_get_author($event);
            if ($author) {
                $replacement = $author->display_name;
            }
            $replacement = eme_trans_sanitize_html($replacement, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_AUTHOREMAIL/', $result)) {
            $author = eme_get_author($event);
            if ($author) {
                $replacement = $author->user_email;
                if ($target == "html") {
                    // ascii encode for primitive harvesting protection ...
                    $replacement = eme_ascii_encode($replacement);
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_AUTHORPHONE/', $result)) {
            $author = eme_get_author($event);
            if ($author) {
                $phone = eme_get_user_phone($author->ID);
                // ascii encode for primitive harvesting protection ...
                $replacement = eme_ascii_encode($phone);
            }
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif (preg_match('/#_EVENTCREATIONDATE/', $result)) {
            $replacement = eme_localised_date($event['creation_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTMODIFDATE/', $result)) {
            $replacement = eme_localised_date($event['modif_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTCREATIONTIME/', $result)) {
            $replacement = eme_localised_time($event['creation_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTMODIFTIME/', $result)) {
            $replacement = eme_localised_time($event['modif_date'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#[A-Za-z]$/', $result)) {
            // matches all PHP date placeholders for startdate-time
            $replacement = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone, ltrim($result, "#"));
            if (get_option('eme_time_remove_leading_zeros') && $result == "#i") {
                $replacement = ltrim($replacement, "0");
            }
        } elseif ($event && preg_match('/#@[A-Za-z]$/', $result)) {
            // matches all PHP time placeholders for enddate-time
            $replacement = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone, ltrim($result, "#@"));
            if (get_option('eme_time_remove_leading_zeros') && $result == "#@i") {
                $replacement = ltrim($replacement, "0");
            }
        } elseif ($event && preg_match('/#_EVENTCATEGORYIDS$/', $result) && get_option('eme_categories_enabled')) {
            $categories = $event['event_category_ids'];
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html($categories, $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_trans_sanitize_html($categories, $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_trans_sanitize_html($categories, $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_(EVENT)?CATEGORIES$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_category_names($event['event_id']);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTCATEGORIES_CSS$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_category_names($event['event_id']);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_EVENTCATEGORYDESCRIPTIONS$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_category_descriptions($event['event_id']);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_LINKED(EVENT)?CATEGORIES$/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_event_categories($event['event_id']);
            $cat_links = array();
            foreach ($categories as $category) {
                $cat_link = eme_category_url($category);
                $cat_name = $category['category_name'];
                if ($target == "html") {
                    array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>");
                } else {
                    array_push($cat_links, eme_translate($cat_name, $lang));
                }
            }
            $replacement = join(", ", $cat_links);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/^#_(EVENT)?CATEGORIES\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_category_names($event['event_id'], $extra_conditions);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/^#_EVENTCATEGORIES_CSS\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[1];
            $exclude_cats = $matches[2];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_category_names($event['event_id'], $extra_conditions);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(" ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($legacy && $event && preg_match('/^#_(EVENT)?CATEGORIES\\[(.*?)\\]\\[(.*?)\\]/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_category_names($event['event_id'], $extra_conditions);
            if ($target == "html") {
                $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $categories), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_LINKED(EVENT)?CATEGORIES\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_categories($event['event_id'], $extra_conditions);
            $cat_links = array();
            foreach ($categories as $category) {
                $cat_link = eme_category_url($category);
                $cat_name = $category['category_name'];
                if ($target == "html") {
                    array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>");
                } else {
                    array_push($cat_links, eme_translate($cat_name, $lang));
                }
            }
            $replacement = join(", ", $cat_links);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($legacy && $event && preg_match('/#_LINKED(EVENT)?CATEGORIES\\[(.*?)\\]\\[(.*?)\\]/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[2];
            $exclude_cats = $matches[3];
            $extra_conditions_arr = array();
            if (!empty($include_cats)) {
                array_push($extra_conditions_arr, "category_id IN ({$include_cats})");
            }
            if (!empty($exclude_cats)) {
                array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})");
            }
            $extra_conditions = join(" AND ", $extra_conditions_arr);
            $categories = eme_get_event_categories($event['event_id'], $extra_conditions);
            $cat_links = array();
            foreach ($categories as $category) {
                $cat_link = eme_category_url($category);
                $cat_name = $category['category_name'];
                if ($target == "html") {
                    array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>");
                } else {
                    array_push($cat_links, eme_translate($cat_name, $lang));
                }
            }
            $replacement = join(", ", $cat_links);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = eme_translate(join(", ", $cat_links), $lang);
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif (preg_match('/#_CALENDAR_DAY/', $result)) {
            $day_key = get_query_var('calendar_day');
            $replacement = eme_localised_date($day_key . " " . $eme_timezone);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif ($event && preg_match('/#_RECURRENCE_DESC|#_RECURRENCEDESC/', $result)) {
            if ($event['recurrence_id']) {
                $replacement = eme_get_recurrence_desc($event['recurrence_id']);
                if ($target == "html") {
                    $replacement = apply_filters('eme_general', $replacement);
                } elseif ($target == "rss") {
                    $replacement = apply_filters('eme_general_rss', $replacement);
                } else {
                    $replacement = apply_filters('eme_text', $replacement);
                }
            }
        } elseif ($event && preg_match('/#_RECURRENCE_NBR/', $result)) {
            // returns the sequence number of an event in a recurrence series
            if ($event['recurrence_id']) {
                $events = eme_get_recurrence_eventids($event['recurrence_id']);
                $nbr = array_search($event['event_id'], $events);
                if ($nbr !== false) {
                    $replacement = $nbr + 1;
                }
            }
        } elseif ($event && preg_match('/#_RSVPEND/', $result)) {
            // show the end date+time for which a user can rsvp for an event
            if (eme_is_event_rsvp($event)) {
                $rsvp_number_days = $event['rsvp_number_days'];
                $rsvp_number_hours = $event['rsvp_number_hours'];
                $rsvp_end_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                $rsvp_end_obj->minusDays($rsvp_number_days);
                $rsvp_end_obj->minusHours($rsvp_number_hours);
                $rsvp_end_date = eme_localised_date($rsvp_end_obj->getDateTime() . " " . $eme_timezone);
                $rsvp_end_time = eme_localised_time($rsvp_end_obj->getDateTime() . " " . $eme_timezone);
                $replacement = $rsvp_end_date . " " . $rsvp_end_time;
            }
        } elseif ($event && preg_match('/#_IS_RSVP_ENDED/', $result)) {
            if (eme_is_event_rsvp($event)) {
                $rsvp_number_days = $event['rsvp_number_days'];
                $rsvp_number_hours = $event['rsvp_number_hours'];
                $rsvp_end_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                $rsvp_end_obj->minusDays($rsvp_number_days);
                $rsvp_end_obj->minusHours($rsvp_number_hours);
                if ($rsvp_end_obj->lessThan($eme_date_obj_now)) {
                    $replacement = 1;
                } else {
                    $replacement = 0;
                }
            }
        } elseif ($event && preg_match('/#_EVENT_EXTERNAL_REF/', $result)) {
            $replacement = $event['event_external_ref'];
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } elseif ($target == "rss") {
                $replacement = apply_filters('eme_general_rss', $replacement);
            } else {
                $replacement = apply_filters('eme_text', $replacement);
            }
        } elseif (preg_match('/#_IS_SINGLE_DAY/', $result)) {
            if (eme_is_single_day_page()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif (preg_match('/#_IS_SINGLE_EVENT/', $result)) {
            if (eme_is_single_event_page()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif (preg_match('/#_IS_LOGGED_IN/', $result)) {
            if (is_user_logged_in()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif (preg_match('/#_IS_ADMIN_PAGE/', $result)) {
            if (is_admin()) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_RSVP_ENABLED/', $result)) {
            if (eme_is_event_rsvp($event)) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_PRIVATE_EVENT/', $result)) {
            if ($event['event_status'] == STATUS_PRIVATE) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_RECURRENT_EVENT/', $result)) {
            if ($event['recurrence_id']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_ONGOING_EVENT/', $result)) {
            $eme_start_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $eme_end_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            if ($eme_start_obj->lessOrEqualTo($eme_date_obj_now) && $eme_end_obj->greaterOrEqualTo($eme_date_obj_now)) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_REGISTERED/', $result)) {
            if (is_user_logged_in() && eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_MULTIPRICE/', $result)) {
            if (eme_is_multi($event['price'])) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_MULTISEAT/', $result)) {
            if (eme_is_multi($event['event_seats'])) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_ALLDAY/', $result)) {
            if ($event['event_properties']['all_day']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_ATTENDANCE/', $result)) {
            if ($event['event_properties']['take_attendance']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_AUTHOR$/', $result)) {
            if ($event['event_author'] == $current_userid) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_CONTACTPERSON/', $result)) {
            if ($event['event_contactperson_id'] == $current_userid) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_AUTHOR_OR_CONTACTPERSON/', $result)) {
            if ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_MULTIDAY/', $result)) {
            if ($event['event_start_date'] != $event['event_end_date']) {
                $replacement = 1;
            } else {
                $replacement = 0;
            }
        } elseif ($event && preg_match('/#_IS_FIRST_RECURRENCE/', $result)) {
            // returns 1 if the event is the first event in a recurrence series
            if ($event['recurrence_id']) {
                $events = eme_get_recurrence_eventids($event['recurrence_id']);
                $nbr = array_search($event['event_id'], $events);
                if ($nbr !== false && $nbr == 0) {
                    $replacement = 1;
                }
            }
        } elseif ($event && preg_match('/#_IS_LAST_RECURRENCE/', $result)) {
            // returns 1 if the event is the last event in a recurrence series
            if ($event['recurrence_id']) {
                $events = eme_get_recurrence_eventids($event['recurrence_id']);
                $nbr = array_search($event['event_id'], $events);
                $last_index = count($events) - 1;
                if ($nbr !== false && $nbr == $last_index) {
                    $replacement = 1;
                }
            }
        } elseif (preg_match('/#_LOCALE/', $result)) {
            $replacement = get_locale();
        } else {
            $found = 0;
        }
        if ($found) {
            if ($need_escape) {
                $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
            }
            if ($need_urlencode) {
                $replacement = rawurlencode($replacement);
            }
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    # now handle all possible location placeholders
    # but the eme_replace_locations_placeholders can't do "do_shortcode" at the end, because
    # this would cause [eme_if] tags to be replaced here already, while some placeholders of the
    # event haven't been replaced yet (like time placeholders, and event details)
    $format = eme_replace_locations_placeholders($format, $location, $target, 0, $lang);
    // for extra date formatting, eg. #_{d/m/Y}
    preg_match_all("/#(ESC|URL)?@?_\\{.*?\\}/", $format, $results);
    // make sure we set the largest matched placeholders first, otherwise if you found e.g.
    // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ...
    usort($results[0], 'sort_stringlenth');
    foreach ($results[0] as $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = '';
        if (substr($result, 0, 3) == "#@_") {
            $my_date = "event_end_date";
            $my_time = "event_end_time";
            $offset = 4;
        } else {
            $my_date = "event_start_date";
            $my_time = "event_start_time";
            $offset = 3;
        }
        $replacement = eme_localised_date($event[$my_date] . " " . $event[$my_time] . " " . $eme_timezone, substr($result, $offset, strlen($result) - ($offset + 1)));
        if ($need_escape) {
            $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
        }
        if ($need_urlencode) {
            $replacement = rawurlencode($replacement);
        }
        $format = str_replace($orig_result, $replacement, $format);
    }
    # we handle NOTES the last, this used to be the default behavior
    # so no placeholder replacement happened accidentaly in possible shortcodes inside #_NOTES
    # but since we have templates to aid in all that ...
    if (!$eme_enable_notes_placeholders) {
        $format = eme_replace_notes_placeholders($format, $event, $target);
    }
    // now, replace any language tags found in the format itself
    $format = eme_translate($format, $lang);
    if ($do_shortcode) {
        return do_shortcode($format);
    } else {
        return $format;
    }
}
Ejemplo n.º 8
0
function eme_global_map($atts)
{
    global $eme_need_gmap_js;
    if (get_option('eme_gmap_is_active') == '1') {
        // the locations shortcode has been deteced, so we indicate
        // that we want the javascript in the footer as well
        $eme_need_gmap_js = 1;
        extract(shortcode_atts(array('show_locations' => true, 'show_events' => false, 'eventful' => false, 'scope' => 'all', 'paging' => 0, 'category' => '', 'width' => 450, 'height' => 300, 'list_location' => 'after'), $atts));
        $eventful = $eventful === "true" || $eventful === "1" ? true : $eventful;
        $show_events = $show_events === "true" || $show_events === "1" ? true : $show_events;
        $show_locations = $show_locations === "true" || $show_locations === "1" ? true : $show_locations;
        $eventful = $eventful === "false" || $eventful === "0" ? false : $eventful;
        $show_events = $show_events === "false" || $show_events === "0" ? false : $show_events;
        $show_locations = $show_locations === "false" || $show_locations === "0" ? false : $show_locations;
        $events_page_link = eme_get_events_page(true, false);
        $prev_text = "";
        $next_text = "";
        $scope_offset = 0;
        // for browsing: if paging=1 and only for this_week,this_month or today
        if ($eventful && $paging == 1) {
            if (isset($_GET['eme_offset'])) {
                $scope_offset = $_GET['eme_offset'];
            }
            $prev_offset = $scope_offset - 1;
            $next_offset = $scope_offset + 1;
            if ($scope == "this_week") {
                $start_of_week = get_option('start_of_week');
                $day_offset = date('w') - $start_of_week;
                if ($day_offset < 0) {
                    $day_offset += 7;
                }
                $limit_start = eme_date_calc("-{$day_offset} days +{$scope_offset} week");
                $limit_end = eme_date_calc("+6 days", $start_day);
                $scope = "{$limit_start}--{$limit_end}";
                $scope_text = eme_localised_date($limit_start) . " -- " . eme_localised_date($limit_end);
                $prev_text = __('Previous week', 'eme');
                $next_text = __('Next week', 'eme');
            } elseif ($scope == "this_month") {
                $limit_start = eme_date_calc("first day of {$scope_offset} month");
                $limit_end = eme_date_calc("last day of {$scope_offset} month");
                $scope = "{$limit_start}--{$limit_end}";
                $scope_text = eme_localised_date($limit_start, get_option('eme_show_period_monthly_dateformat'));
                $prev_text = __('Previous month', 'eme');
                $next_text = __('Next month', 'eme');
            } elseif ($scope == "this_year") {
                $year = date('Y') + $scope_offset;
                $limit_start = "{$year}-01-01";
                $limit_end = "{$year}-12-31";
                $scope = "{$limit_start}--{$limit_end}";
                $scope = "{$limit_start}--{$limit_end}";
                $scope_text = eme_localised_date($limit_start, get_option('eme_show_period_yearly_dateformat'));
                $prev_text = __('Previous year', 'eme');
                $next_text = __('Next year', 'eme');
            } elseif ($scope == "today") {
                $scope = date('Y-m-d', strtotime("{$scope_offset} days"));
                $limit_start = $scope;
                $limit_end = $scope;
                $scope_text = eme_localised_date($limit_start);
                $prev_text = __('Previous day', 'eme');
                $next_text = __('Next day', 'eme');
            } elseif ($scope == "tomorrow") {
                $scope_offset++;
                $scope = date('Y-m-d', strtotime("{$scope_offset} days"));
                $limit_start = $scope;
                $limit_end = $scope;
                $scope_text = eme_localised_date($limit_start);
                $prev_text = __('Previous day', 'eme');
                $next_text = __('Next day', 'eme');
            }
            // to prevent going on indefinitely and thus allowing search bots to go on for ever,
            // we stop providing links if there are no more events left
            $older_events = eme_get_events(1, "--" . $limit_start, "ASC", 0, $location['location_id'], $category);
            $newer_events = eme_get_events(1, "++" . $limit_end, "ASC", 0, $location['location_id'], $category);
            if (count($older_events) == 0) {
                $prev_text = "";
            }
            if (count($newer_events) == 0) {
                $next_text = "";
            }
        }
        $id_base = preg_replace("/\\D/", "_", microtime(1));
        $id_base = rand() . "_" . $id_base;
        if (!preg_match('/\\%$|px$/', $width)) {
            $width = $width . "px";
        }
        if (!preg_match('/\\%$|px$/', $height)) {
            $height = $height . "px";
        }
        $result = "<div id='eme_global_map_{$id_base}' class='eme_global_map' style='width: {$width}; height: {$height}'>map</div>";
        // get the paging output ready
        if ($paging == 1) {
            $pagination_top = "<div id='locations-pagination-top'> ";
            $this_page_url = $_SERVER['REQUEST_URI'];
            // remove the offset info
            $this_page_url = remove_query_arg('eme_offset', $this_page_url);
            if ($prev_text != "") {
                $pagination_top .= "<a class='eme_nav_left' href='" . add_query_arg(array('eme_offset' => $prev_offset), $this_page_url) . "'>&lt;&lt; {$prev_text}</a>";
            }
            if ($next_text != "") {
                $pagination_top .= "<a class='eme_nav_right' href='" . add_query_arg(array('eme_offset' => $next_offset), $this_page_url) . "'>{$next_text} &gt;&gt;</a>";
            }
            $pagination_top .= "<span class='eme_nav_center'>{$scope_text}</span>";
            $pagination_top .= "</div>";
            $pagination_bottom = str_replace("locations-pagination-top", "locations-pagination-bottom", $pagination_top);
            $result = $pagination_top . $result . $pagination_bottom;
        }
        $eventful_string = "eventful_" . $id_base;
        $scope_string = "scope_" . $id_base;
        $category_string = "category_" . $id_base;
        $result .= "<script type='text/javascript'>\n         <!--// \n      {$eventful_string} = '{$eventful}';\n      {$scope_string} = '{$scope}';\n      {$category_string} = '{$category}';\n      events_page_link = '{$events_page_link}';\n         //-->\n         </script>";
        // we add the list if wanted (only for "before" or "after")
        $locations = eme_get_locations((bool) $eventful, $scope, $category, $scope_offset);
        $loc_list = "<div id='eme_div_locations_list_{$id_base}' class='eme_div_locations_list'><ol id='eme_locations_list_{$id_base}' class='eme_locations_list'>";
        $firstletter = "A";
        foreach ($locations as $location) {
            if ($show_locations) {
                $loc_list .= "<li id='location-" . $location['location_id'] . "_{$id_base}" . "' style='list-style-type: upper-alpha'><a>" . eme_trans_sanitize_html($location['location_name']) . "</a></li>";
            }
            if ($show_events) {
                $events = eme_get_events(0, $scope, "ASC", $scope_offset, $location['location_id'], $category);
                $loc_list .= "<ol id='eme_events_list'>";
                foreach ($events as $event) {
                    if ($show_locations) {
                        $loc_list .= "<li id='location-" . $location['location_id'] . "_{$id_base}" . "' style='list-style-type: none'>- <a>" . eme_trans_sanitize_html($event['event_name']) . "</a></li>";
                    } else {
                        $loc_list .= "<li id='location-" . $location['location_id'] . "_{$id_base}" . "' style='list-style-type: none'>{$firstletter}. <a>" . eme_trans_sanitize_html($event['event_name']) . "</a></li>";
                    }
                }
                $loc_list .= "</ol>";
            }
            // cool: we can increment strings in php, so we can mimic the CSS "style='list-style-type: upper-alpha'" thingie
            // usefull when we show events (more than one event per location)
            $firstletter++;
        }
        $loc_list .= "</ol></div>";
        if ($list_location == "before") {
            $result = $loc_list . $result;
        } elseif ($list_location == "after") {
            $result .= $loc_list;
        }
    } else {
        $result = "";
    }
    return $result;
}
Ejemplo n.º 9
0
function eme_send_mail_form($event_id = 0)
{
    ?>
<div class="wrap">
<div id="icon-events" class="icon32"><br />
</div>
<h2><?php 
    _e('Send Mails to attendees or bookings for a event', 'eme');
    ?>
</h2>
<?php 
    admin_show_warnings();
    ?>
   <div id='message' class='updated'><p>
<?php 
    _e('Warning: using this functionality to send mails to attendees can result in a php timeout, so not everybody will receive the mail then. This depends on the number of attendees, the load on the server, ... . If this happens, use the CSV export link to get the list of all attendees and use mass mailing tools (like OpenOffice) for your mailing.', 'eme');
    $all_events = eme_get_events(0, "future");
    $event_id = isset($_POST['event_id']) ? intval($_POST['event_id']) : 0;
    $current_userid = get_current_user_id();
    $templates_array = eme_get_templates_array_by_id();
    if (is_array($templates_array) && count($templates_array) > 0) {
        $templates_array[0] = '';
    } else {
        $templates_array[0] = __('No templates defined yet!', 'eme');
    }
    ksort($templates_array);
    ?>
   </p></div>
   <form id='send_mail' name='send_mail' action="" method="post">
   <input type='hidden' name='page' value='eme-send-mails' />
   <input type='hidden' name='eme_admin_action' value='send_mail' />
   <input type='hidden' id='onchange' name='onchange' value='0' />
   <select name="event_id" onchange="document.getElementById('onchange').value='1';this.form.submit();">
   <option value='0' ><?php 
    _e('Select the event', 'eme');
    ?>
</option>
   <?php 
    foreach ($all_events as $event) {
        $option_text = $event['event_name'] . " (" . eme_localised_date($event['event_start_date']) . ")";
        if ($event['event_rsvp'] && current_user_can(get_option('eme_cap_send_other_mails')) || current_user_can(get_option('eme_cap_send_mails')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) {
            if ($event['event_id'] == $event_id) {
                echo "<option selected='selected' value='" . $event['event_id'] . "' >" . $option_text . "</option>  ";
            } else {
                echo "<option value='" . $event['event_id'] . "' >" . $option_text . "</option>  ";
            }
        }
    }
    ?>
   </select>
   <p>
   <?php 
    if ($event_id > 0) {
        ?>
      <table>
      <tr>
	   <td><label><?php 
        _e('Select the type of mail', 'eme');
        ?>
</td>
      <td>
           <select name="eme_mail_type" required='required'>
           <option value=''></option>
           <option value='attendees'><?php 
        _e('Attendee mails', 'eme');
        ?>
</option>
           <option value='bookings'><?php 
        _e('Booking mails', 'eme');
        ?>
</option>
           <option value='all_wp'><?php 
        _e('Mail to all WP users', 'eme');
        ?>
</option>
           <option value='all_wp_not_registered'><?php 
        _e('All WP users except those registered for the event', 'eme');
        ?>
</option>
           </select>
      </td>
      </tr>
      <tr id="eme_pending_approved_row">
	   <td><label><?php 
        _e('Select your target audience', 'eme');
        ?>
</td>
      <td>
           <select name="pending_approved">
           <option value=0><?php 
        _e('All registered persons', 'eme');
        ?>
</option>
           <option value=2><?php 
        _e('Exclude pending registrations', 'eme');
        ?>
</option>
           <option value=1><?php 
        _e('Only pending registrations', 'eme');
        ?>
</option>
           </select></p><p>
      </td>
      </tr>
      <tr id="eme_only_unpayed_row">
      <td><?php 
        _e('Only send mails to attendees who did not pay yet', 'eme');
        ?>
&nbsp;</td>
      <td>
           <input type="checkbox" name="only_unpayed" value="1" />
      </td>
      </tr>
      </table>
	   <div id="titlediv" class="form-field form-required"><p>
      <b><?php 
        _e('Subject', 'eme');
        ?>
</b><br />
      <?php 
        _e('Either choose from a template: ', 'eme');
        echo eme_ui_select(0, 'subject_template', $templates_array);
        ?>
<br />
      <?php 
        _e('Or enter your own (if anything is entered here, it takes precedence over the selected template): ', 'eme');
        ?>
      <input type="text" name="mail_subject" id="mail_subject" value="" /></p>
	   </div>
	   <div class="form-field form-required"><p>
	   <b><?php 
        _e('Message', 'eme');
        ?>
</b><br />
      <?php 
        _e('Either choose from a template: ', 'eme');
        echo eme_ui_select(0, 'message_template', $templates_array);
        ?>
<br />
      <?php 
        _e('Or enter your own (if anything is entered here, it takes precedence over the selected template): ', 'eme');
        ?>
	   <textarea name="mail_message" id="mail_message" value="" rows=10></textarea> </p>
	   </div>
	   <div>
	   <?php 
        _e('You can use any placeholders mentioned here:', 'eme');
        print "<br /><a href='http://www.e-dynamics.be/wordpress/?cat=25'>" . __('Event placeholders', 'eme') . "</a>";
        print "<br /><a href='http://www.e-dynamics.be/wordpress/?cat=48'>" . __('Attendees placeholders', 'eme') . "</a> (" . __('for ', 'eme') . __('Attendee mails', 'eme') . ")";
        print "<br /><a href='http://www.e-dynamics.be/wordpress/?cat=45'>" . __('Booking placeholders', 'eme') . "</a> (" . __('for ', 'eme') . __('Booking mails', 'eme') . ")";
        ?>
	   </div>
      <br />
	   <input type="submit" value="<?php 
        _e('Send Mail', 'eme');
        ?>
" class="button-primary action" />
	   </form>

   <?php 
        $csv_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
        $available_seats = eme_get_available_seats($event['event_id']);
        $total_seats = $event['event_seats'];
        if ($total_seats != $available_seats) {
            echo "<br /><br /> <a id='booking_csv_" . $event['event_id'] . "'  target='' href='{$csv_address}'>" . __('CSV export', 'eme') . "</a>";
        }
    }
}
Ejemplo n.º 10
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 
}
Ejemplo n.º 11
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;
    }
}
Ejemplo n.º 12
0
function eme_global_map($atts) {
   global $eme_need_gmap_js, $eme_timezone;

   if (get_option('eme_gmap_is_active') == '1') {
      // the locations shortcode has been deteced, so we indicate
      // that we want the javascript in the footer as well
      $eme_need_gmap_js=1;
      extract(shortcode_atts(array(
                  'show_locations' => true,
                  'show_events' => false,
                  'eventful' => false,
                  'scope' => 'all',
                  'paging' => 0,
                  'category' => '',
                  'width' => 450,
                  'height' => 300,
                  'list_location' => 'after'
                  ), $atts));
      $eventful = ($eventful==="true" || $eventful==="1") ? true : $eventful;
      $show_events = ($show_events==="true" || $show_events==="1") ? true : $show_events;
      $show_locations = ($show_locations==="true" || $show_locations==="1") ? true : $show_locations;
      $eventful = ($eventful==="false" || $eventful==="0") ? false : $eventful;
      $show_events = ($show_events==="false" || $show_events==="0") ? false : $show_events;
      $show_locations = ($show_locations==="false" || $show_locations==="0") ? false : $show_locations;

      $events_page_link = eme_get_events_page(true, false);
      $prev_text = "";
      $next_text = "";
      $scope_offset=0;
      // for browsing: if paging=1 and only for this_week,this_month or today
      if ($eventful && $paging==1) {
         $eme_date_obj=new ExpressiveDate(null,$eme_timezone);

         if (isset($_GET['eme_offset']))
            $scope_offset=$_GET['eme_offset'];
         $prev_offset=$scope_offset-1;
         $next_offset=$scope_offset+1;
         if ($scope=="this_week") {
            $start_of_week = get_option('start_of_week');
            $eme_date_obj->setWeekStartDay($start_of_week);
            $eme_date_obj->modifyWeeks($scope_offset);
            $limit_start=$eme_date_obj->startOfWeek()->format('Y-m-d');
            $limit_end=$eme_date_obj->endOfWeek()->format('Y-m-d');
            $scope = "$limit_start--$limit_end";
            $scope_text = eme_localised_date($limit_start." ".$eme_timezone)." -- ".eme_localised_date($limit_end." ".$eme_timezone);
            $prev_text = __('Previous week','eme');
            $next_text = __('Next week','eme');

         } elseif ($scope=="this_month") {
            $eme_date_obj->modifyMonths($scope_offset);
            $limit_start = $eme_date_obj->startOfMonth()->format('Y-m-d');
            $limit_end   = $eme_date_obj->endOfMonth()->format('Y-m-d');
            $scope = "$limit_start--$limit_end";
            $scope_text = eme_localised_date($limit_start." ".$eme_timezone,get_option('eme_show_period_monthly_dateformat'));
            $prev_text = __('Previous month','eme');
            $next_text = __('Next month','eme');

         } elseif ($scope=="this_year") {
            $eme_date_obj->modifyYears($scope_offset);
            $year=$eme_date_obj->getYear();
            $limit_start = "$year-01-01";
            $limit_end   = "$year-12-31";
            $scope = "$limit_start--$limit_end";
            $scope = "$limit_start--$limit_end";
            $scope_text = eme_localised_date($limit_start." ".$eme_timezone,get_option('eme_show_period_yearly_dateformat'));
            $prev_text = __('Previous year','eme');
            $next_text = __('Next year','eme');

         } elseif ($scope=="today") {
            $scope = $eme_date_obj->modifyDays($scope_offset)->format('Y-m-d');
            $limit_start = $scope;
            $limit_end   = $scope;
            $scope_text = eme_localised_date($limit_start." ".$eme_timezone);
            $prev_text = __('Previous day','eme');
            $next_text = __('Next day','eme');

         } elseif ($scope=="tomorrow") {
            $scope_offset++;
            $scope = $eme_date_obj->modifyDays($scope_offset)->format('Y-m-d');
            $limit_start = $scope;
            $limit_end   = $scope;
            $scope_text = eme_localised_date($limit_start." ".$eme_timezone);
            $prev_text = __('Previous day','eme');
            $next_text = __('Next day','eme');
         }

         // to prevent going on indefinitely and thus allowing search bots to go on for ever,
         // we stop providing links if there are no more events left
         $older_events=eme_get_events ( 1, "--".$limit_start, "ASC", 0, $location['location_id'], $category);
         $newer_events=eme_get_events ( 1, "++".$limit_end, "ASC", 0, $location['location_id'], $category);
         if (count($older_events) == 0)
            $prev_text = "";
         if (count($newer_events) == 0)
            $next_text = "";
      }

      $id_base = preg_replace("/\D/","_",microtime(1));
      $id_base = rand()."_".$id_base;
      if (!preg_match('/\%$|px$/',$width)) $width=$width."px";
      if (!preg_match('/\%$|px$/',$height)) $height=$height."px";
      $result = "<div id='eme_global_map_$id_base' class='eme_global_map' style='width: $width; height: $height'>map</div>";
      // get the paging output ready
      if ($paging==1) {
         $pagination_top = "<div id='locations-pagination-top'> ";
         $this_page_url=$_SERVER['REQUEST_URI'];
         // remove the offset info
         $this_page_url= remove_query_arg('eme_offset',$this_page_url);
         if ($prev_text != "")
            $pagination_top.= "<a class='eme_nav_left' href='".add_query_arg(array('eme_offset'=>$prev_offset),$this_page_url)."'>&lt;&lt; $prev_text</a>";
         if ($next_text != "")
            $pagination_top.= "<a class='eme_nav_right' href='".add_query_arg(array('eme_offset'=>$next_offset),$this_page_url)."'>$next_text &gt;&gt;</a>";
         $pagination_top.= "<span class='eme_nav_center'>$scope_text</span>";
         $pagination_top.= "</div>";
         $pagination_bottom = str_replace("locations-pagination-top","locations-pagination-bottom",$pagination_top);
         $result = $pagination_top.$result.$pagination_bottom;
      }

      $eventful_string="eventful_".$id_base;
      $scope_string="scope_".$id_base;
      $category_string="category_".$id_base;
      $result .= "<script type='text/javascript'>
         <!--// 
      $eventful_string = '$eventful';
      $scope_string = '$scope';
      $category_string = '$category';
      events_page_link = '$events_page_link';
         //-->
         </script>";

      // we add the list if wanted (only for "before" or "after")
      $locations = eme_get_locations((bool)$eventful,$scope,$category,$scope_offset);
      $loc_list = "<div id='eme_div_locations_list_$id_base' class='eme_div_locations_list'><ol id='eme_locations_list_$id_base' class='eme_locations_list'>"; 
      $firstletter="A";
      foreach($locations as $location) {
         if ($show_locations) {
            $loc_list.="<li id='location-". $location['location_id']."_$id_base".
                           "' style='list-style-type: upper-alpha'><a>".
                           eme_trans_sanitize_html($location['location_name'])."</a></li>";
         }
         if ($show_events) {
            $events = eme_get_events(0,$scope,"ASC",$scope_offset,$location['location_id'], $category);
            $loc_list .= "<ol id='eme_events_list'>"; 
            foreach ($events as $event) {
               if ($show_locations)
                  $loc_list.="<li id='location-". $location['location_id']."_$id_base".
                           "' style='list-style-type: none'>- <a>".
                           eme_trans_sanitize_html($event['event_name'])."</a></li>";
               else
                  $loc_list.="<li id='location-". $location['location_id']."_$id_base".
                           "' style='list-style-type: none'>$firstletter. <a>".
                           eme_trans_sanitize_html($event['event_name'])."</a></li>";
            }
            $loc_list.= "</ol>"; 
         }
         // cool: we can increment strings in php, so we can mimic the CSS "style='list-style-type: upper-alpha'" thingie
         // usefull when we show events (more than one event per location)
         $firstletter++;
      }
      $loc_list .= "</ol></div>"; 
      if ($list_location=="before") {
         $result = $loc_list.$result;
      } elseif ($list_location=="after") {
         $result .= $loc_list;
      }
   } else {
      $result = "";
   }
   return $result;
}