Example #1
0
 /**
  * Returns json for javascript templating functions throughout the plugin.
  *
  * @since 3.3
  * @param $event
  * @param $additional
  * @author Modern Tribe
  * @return string
  */
 function tribe_events_template_data($event, array $additional = null)
 {
     $has_image = false;
     $start_time = '';
     $end_time = '';
     $image_src = '';
     $image_tool_src = '';
     if (!empty($event->EventStartDate)) {
         $start_time .= date_i18n(get_option('date_format', 'F j, Y'), strtotime($event->EventStartDate));
     }
     if (!tribe_get_event_meta($event->ID, '_EventAllDay', true)) {
         $start_time .= ' ' . date_i18n(get_option('time_format', 'g:i a'), strtotime($event->EventStartDate));
     }
     if (!empty($event->EventEndDate) && $event->EventStartDate !== $event->EventEndDate) {
         if (date('Y-m-d', strtotime($event->EventStartDate)) == date('Y-m-d', strtotime($event->EventEndDate))) {
             $time_format = get_option('time_format', 'g:i a');
             if (!tribe_get_event_meta($event->ID, '_EventAllDay', true)) {
                 $end_time .= date_i18n($time_format, strtotime($event->EventEndDate));
             }
         } else {
             $end_time .= date_i18n(get_option('date_format', 'F j, Y'), strtotime($event->EventEndDate));
             if (!tribe_get_event_meta($event->ID, '_EventAllDay', true)) {
                 $end_time .= ' ' . date_i18n(get_option('time_format', 'g:i a'), strtotime($event->EventEndDate));
             }
         }
     }
     if (function_exists('has_post_thumbnail') && has_post_thumbnail($event->ID)) {
         $has_image = true;
         $image_arr = wp_get_attachment_image_src(get_post_thumbnail_id($event->ID), 'medium');
         $image_src = $image_arr[0];
     }
     if ($has_image) {
         $image_tool_arr = wp_get_attachment_image_src(get_post_thumbnail_id($event->ID), array(75, 75));
         $image_tool_src = $image_tool_arr[0];
     }
     if (has_excerpt($event->ID)) {
         $excerpt = $event->post_excerpt;
     } else {
         $excerpt = $event->post_content;
     }
     $excerpt = tribe_prepare_for_json(TribeEvents::instance()->truncate($excerpt, 30));
     $json = array('eventId' => $event->ID, 'title' => tribe_prepare_for_json($event->post_title), 'permalink' => tribe_get_event_link($event->ID), 'imageSrc' => $image_src, 'startTime' => $start_time, 'endTime' => $end_time, 'imageTooltipSrc' => $image_tool_src, 'excerpt' => $excerpt);
     if ($additional) {
         $additional = array_map('tribe_prepare_for_json', $additional);
         $json = array_merge((array) $json, (array) $additional);
     }
     return json_encode($json);
 }
Example #2
0
 /**
  * Recursively iterate through an nested structure, calling
  * tribe_prepare_for_json() on all scalar values
  *
  * @category Events
  *
  * @param mixed $value The data to be cleaned
  *
  * @return mixed The clean data
  */
 function tribe_prepare_for_json_deep($value)
 {
     if (is_array($value)) {
         $value = array_map('tribe_prepare_for_json_deep', $value);
     } elseif (is_object($value)) {
         $vars = get_object_vars($value);
         foreach ($vars as $key => $data) {
             $value->{$key} = tribe_prepare_for_json_deep($data);
         }
     } elseif (is_string($value)) {
         $value = tribe_prepare_for_json($value);
     }
     return $value;
 }
Example #3
0
 /**
  * Returns json for javascript templating functions throughout the plugin.
  *
  * @param $event
  * @param $additional
  * @return string
  */
 function tribe_events_template_data($event, array $additional = null)
 {
     $has_image = false;
     $start_time = '';
     $end_time = '';
     $image_src = '';
     $image_tool_src = '';
     // @TODO use tribe_events_event_schedule_details()
     $date_format = tribe_get_date_format(true);
     $time_format = get_option('time_format', TribeDateUtils::TIMEFORMAT);
     $date_time_separator = tribe_get_option('dateTimeSeparator', ' @ ');
     if (!empty($event->EventStartDate)) {
         $start_time .= date_i18n($date_format, strtotime($event->EventStartDate));
     }
     if (!tribe_get_event_meta($event->ID, '_EventAllDay', true)) {
         $start_time .= $date_time_separator . date_i18n($time_format, strtotime($event->EventStartDate));
     }
     if (!empty($event->EventEndDate) && $event->EventStartDate !== $event->EventEndDate) {
         if (date('Y-m-d', strtotime($event->EventStartDate)) == date('Y-m-d', strtotime($event->EventEndDate))) {
             if (!tribe_get_event_meta($event->ID, '_EventAllDay', true)) {
                 $end_time .= date_i18n($time_format, strtotime($event->EventEndDate));
             }
         } else {
             $end_time .= date_i18n($date_format, strtotime($event->EventEndDate));
             if (!tribe_get_event_meta($event->ID, '_EventAllDay', true)) {
                 $end_time .= $date_time_separator . date_i18n($time_format, strtotime($event->EventEndDate));
             }
         }
     }
     if (function_exists('has_post_thumbnail') && has_post_thumbnail($event->ID)) {
         $has_image = true;
         $image_arr = wp_get_attachment_image_src(get_post_thumbnail_id($event->ID), 'medium');
         $image_src = $image_arr[0];
     }
     if ($has_image) {
         $image_tool_arr = wp_get_attachment_image_src(get_post_thumbnail_id($event->ID), array(75, 75));
         $image_tool_src = $image_tool_arr[0];
     }
     if (has_excerpt($event->ID)) {
         $excerpt = $event->post_excerpt;
     } else {
         $excerpt = $event->post_content;
     }
     $excerpt = tribe_prepare_for_json(TribeEvents::instance()->truncate($excerpt, 30));
     $category_classes = tribe_prepare_for_json(tribe_events_event_classes($event->ID, false));
     $json = array('eventId' => $event->ID, 'title' => tribe_prepare_for_json($event->post_title), 'permalink' => tribe_get_event_link($event->ID), 'imageSrc' => $image_src, 'startTime' => $start_time, 'endTime' => $end_time, 'imageTooltipSrc' => $image_tool_src, 'excerpt' => $excerpt, 'categoryClasses' => $category_classes);
     if ($additional) {
         $additional = array_map('tribe_prepare_for_json', $additional);
         $json = array_merge((array) $json, (array) $additional);
     }
     return json_encode($json);
 }