Advertisement
Apina

custom venue shortcode

Mar 18th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.01 KB | None | 0 0
  1. /**
  2.   Venue Details Shortcode
  3.   http://eventespresso.com/forums/2010/10/post-type-variables-and-shortcodes/#venue_shortcode
  4.  
  5.   Example:
  6.   [ESPRESSO_VENUE outside_wrapper="div" outside_wrapper_class="event_venue"]
  7.  
  8.   Parameters:
  9.   outside_wrapper
  10.   outside_wrapper_class
  11.   title_wrapper
  12.   title_class
  13.   inside_wrapper
  14.   inside_wrapper_class
  15.   image_class
  16.   show_google_map_link (true|false default true)
  17.   map_link_text
  18.   show_map_image (true|false default true)
  19.   map_image_wrapper
  20.   map_image_class
  21.   map_w (map image width default 400)
  22.   map_h (map image height default 400)
  23.   show_title (true|false default true)
  24.   show_image (true|false default true)
  25.   show_description (true|false default true)
  26.   show_address (true|false default true)
  27.   show_additional_details (true|false default true)
  28.  * */
  29. if (!function_exists('espresso_venue_details_scz')) {
  30.  
  31.     function espresso_venue_details_scz($atts) {
  32.  
  33.         global $wpdb, $this_event_id;
  34.  
  35.         empty($atts) ? '' : extract($atts);
  36.  
  37.         //Outside wrapper
  38.         $outside_wrapper_class = isset($outside_wrapper_class) ? 'class="' . $outside_wrapper_class . '"' : 'class="event_venue"';
  39.         $wrapper_start = isset($outside_wrapper) ? '<' . $outside_wrapper . ' ' . $outside_wrapper_class : '<div ' . $outside_wrapper_class;
  40.         $wrapper_end = isset($outside_wrapper) ? '</' . $outside_wrapper . '>' : '</div>';
  41.  
  42.         //Image class
  43.         $image_class = isset($image_class) ? 'class="' . $image_class . '"' : 'class="venue_image"';
  44.         $image_wrapper_class = isset($image_wrapper_class) ? 'class="' . $image_wrapper_class . '"' : 'class="image_wrapper"';
  45.         $image_wrapper_start = isset($image_wrapper) ? '<' . $image_wrapper . ' ' . $image_wrapper_class : '<p ' . $image_wrapper_class . '>';
  46.         $image_wrapper_end = isset($image_wrapper) ? '</' . $image_wrapper . '>' : '</p>';
  47.  
  48.         //Venue title
  49.         $title_class = isset($title_class) ? 'class="' . $title_class . '"' : 'class="venue_name"';
  50.         $title_wrapper_start = isset($title_wrapper) ? '<' . $title_wrapper . ' ' . $title_class : '<h3 ' . $title_class;
  51.         $title_wrapper_end = isset($title_wrapper) ? '</' . $title_wrapper . '>' : '</h3>';
  52.  
  53.         //Inside wrappers
  54.         $inside_wrapper_class = isset($inside_wrapper_class) ? 'class="' . $inside_wrapper_class . '"' : 'class="venue_details"';
  55.         $inside_wrapper_before = isset($inside_wrapper) ? '<' . $inside_wrapper . ' ' . $inside_wrapper_class . '>' : '<p ' . $inside_wrapper_class . '>';
  56.         $inside_wrapper_after = isset($inside_wrapper) ? '</' . $inside_wrapper . '>' : '</p>';
  57.  
  58.         //Map image class
  59.         $map_image_class = isset($map_image_class) ? 'class="' . $map_image_class . '"' : 'class="venue_map_image"';
  60.         $map_image_wrapper_class = isset($map_image_wrapper_class) ? 'class="' . $map_image_wrapper_class . '">' : 'class="map_image_wrapper">';
  61.         $map_image_wrapper_start = isset($map_image_wrapper) ? '<' . $map_image_wrapper . ' ' . $map_image_wrapper_class : '<p ' . $map_image_wrapper_class;
  62.         $map_image_wrapper_end = isset($map_image_wrapper) ? '</' . $map_image_wrapper . '>' : '</p>';
  63.  
  64.         //Google Map link text
  65.         $show_google_map_link = isset($show_google_map_link) && $show_google_map_link == 'false' ? false : true;
  66.         $map_link_text = isset($map_link_text) ? $map_link_text : __('Map and Directions', 'event_espresso');
  67.  
  68.         //Show Google map image?
  69.         $show_map_image = isset($show_map_image) && $show_map_image == 'false' ? false : true;
  70.  
  71.         //Show title?
  72.         $show_title = isset($show_title) && $show_title == 'false' ? false : true;
  73.  
  74.         //Show image?
  75.         $show_image = isset($show_image) && $show_image == 'false' ? false : true;
  76.  
  77.         //Show the description?
  78.         $show_description = isset($show_description) && $show_description == 'false' ? false : true;
  79.  
  80.         //Show address details?
  81.         $show_address = isset($show_address) && $show_address == 'false' ? false : true;
  82.  
  83.         //Show additional details
  84.         $show_additional_details = isset($show_additional_details) && $show_additional_details == 'false' ? false : true;
  85.  
  86.         $FROM = " FROM ";
  87.         $order_by = isset($order_by) && $order_by != '' ? " ORDER BY " . $order_by . " ASC " : " ORDER BY name ASC ";
  88.         $limit = isset( $limit ) && $limit > 0 ? " LIMIT 0," . $limit . " " : '';
  89.  
  90.         $using_id = false;
  91.         //Find the event id
  92.         if (isset($id) && $id > 0) {
  93.  
  94.         } elseif (isset($event_id)) {
  95.             $event_id = $event_id; //Check to see if the event is used in the shortcode parameter
  96.             $using_id = true;
  97.         } elseif (isset($this_event_id)) {
  98.             $event_id = $this_event_id; //Check to see if the global event id is being used
  99.             $using_id = true;
  100.         } elseif (isset($_REQUEST['event_id'])) {
  101.             $event_id = $_REQUEST['event_id']; //If the first two are not being used, then get the event id from the url
  102.             $using_id = true;
  103.         }
  104.  
  105.         $sql = "SELECT ev.* ";
  106.  
  107.         if ($using_id == true) {
  108.             $sql .= " $FROM " . EVENTS_DETAIL_TABLE . " e ";
  109.             $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON e.id = vr.event_id ";
  110.             $FROM = " LEFT JOIN ";
  111.         }
  112.  
  113.         $sql .= " $FROM " . EVENTS_VENUE_TABLE . " ev ";
  114.  
  115.         if ($using_id == true) {
  116.             $sql .= " ON vr.venue_id = ev.id ";
  117.         }
  118.  
  119.         if (isset($id) && $id > 0) {
  120.             $sql .= " WHERE ev.id = '" . $id . "' ";
  121.         } elseif (isset($event_id) && $event_id > 0) {
  122.             $sql .= " WHERE e.id ='" . $event_id . "' ";
  123.         } else {
  124.             $sql .= " GROUP BY ev.name ";
  125.         }
  126.  
  127.         if ($using_id == false) {
  128.             $sql .= $order_by;
  129.             $sql .= $limit;
  130.         }
  131.         //echo $sql ;
  132.  
  133.         $venues = $wpdb->get_results($sql);
  134.  
  135.         $num_rows = $wpdb->num_rows;
  136.         if ($num_rows > 0) {
  137.             $html = '';
  138.             foreach ($venues as $venue) {
  139.                 $venue_id = $venue->id;
  140.                 $meta = unserialize($venue->meta);
  141.  
  142.                 //Google map link creation
  143.                 $google_map_link = espresso_google_map_link(array('address' => $venue->address, 'city' => $venue->city, 'state' => $venue->state, 'zip' => $venue->zip, 'country' => $venue->country, 'text' => $map_link_text, 'type' => 'text'));
  144.  
  145.                 //Google map image creation
  146.                 if ($show_map_image != false) {
  147.                     $map_w = isset($map_w) ? $map_w : 400;
  148.                     $map_h = isset($map_h) ? $map_h : 400;
  149.                     $google_map_image = espresso_google_map_link(array('id' => $venue_id, 'map_image_class' => $map_image_class, 'address' => $venue->address, 'city' => $venue->city, 'state' => $venue->state, 'zip' => $venue->zip, 'country' => $venue->country, 'text' => $map_link_text, 'type' => 'map', 'map_h' => $map_h, 'map_w' => $map_w));
  150.                 }
  151.  
  152.                 //Build the venue title
  153.                 if ($show_title != false) {
  154.                     $html .= $venue->name != '' ? $title_wrapper_start . '>' . stripslashes_deep($venue->name) . $title_wrapper_end : '';
  155.                 }
  156.  
  157.                 //Build the venue image
  158.                 if ($show_image != false) {
  159.                     $html .= $meta['image'] != '' ? $image_wrapper_start . '<img id="venue_image_' . $venue_id . '" ' . $image_class . ' src="' . stripslashes_deep($meta['image']) . '" />' . $image_wrapper_end : '';
  160.                 }
  161.  
  162.                 //Build the description
  163.                 if ($show_description != false) {
  164.                     $html .= $meta['description'] != '' ? espresso_format_content($meta['description']) : '';
  165.                 }
  166.  
  167.                 //Build the address details
  168.                 if ($show_address != false) {
  169.                     $html .= $inside_wrapper_before;
  170.                     $html .= $venue->address != '' ? stripslashes_deep($venue->address) . '<br />' : '';
  171.                     $html .= $venue->address2 != '' ? stripslashes_deep($venue->address2) . '<br />' : '';
  172.                     //$html .= $venue->city != '' ? stripslashes_deep($venue->city) . '<br />' : '';
  173.                     $html .= $venue->state != '' ? stripslashes_deep($venue->state) . '<br />' : '';
  174.                     $html .= $venue->zip != '' ? stripslashes_deep($venue->zip) . ' ' : '';
  175.                                         $html .= $venue->city != '' ? stripslashes_deep($venue->city) . '<br />' : '';
  176.  
  177.                     $html .= $venue->country != '' ? stripslashes_deep($venue->country) . '<br />' : '';
  178.                     $html .= $show_google_map_link != false ? $google_map_link : '';
  179.                     $html .= $inside_wrapper_after;
  180.                 }
  181.  
  182.                 //Build the additional details
  183.                 if ($show_additional_details != false) {
  184.                     $html .= $inside_wrapper_before;
  185.                     $html .= $meta['website'] != '' ? __('Website:', 'event_espresso') . ' <a href="' . stripslashes_deep($meta['website']) . '" target="_blank">' . stripslashes_deep($meta['website']) . '</a><br />' : '';
  186.                     $html .= $meta['contact'] != '' ? __('Contact:', 'event_espresso') . ' ' . stripslashes_deep($meta['contact']) . '<br />' : '';
  187.                     $html .= $meta['phone'] != '' ? __('Phone:', 'event_espresso') . ' ' . stripslashes_deep($meta['phone']) . '<br />' : '';
  188.                     $html .= $meta['twitter'] != '' ? __('Twitter:', 'event_espresso') . ' <a href="http://twitter.com/#!/' . stripslashes_deep($meta['twitter']) . '" target="_blank">@' . stripslashes_deep($meta['twitter']) . '</a><br />' : '';
  189.                     $html .= $inside_wrapper_after;
  190.                 }
  191.  
  192.                 //Build the venue image
  193.                 if ($show_map_image != false) {
  194.                     $html .= $map_image_wrapper_start . $google_map_image . $map_image_wrapper_end;
  195.                 }
  196.             }
  197.         }
  198.         //ob_start();
  199.         return $wrapper_start . ' id="venue_id_' . $venue_id . '">' . $html . $wrapper_end;
  200.         //$buffer = ob_get_contents();
  201.         //ob_end_clean();
  202.         //return $buffer;
  203.     }
  204.  
  205. }
  206. add_shortcode('ESPRESSO_VENUEZ', 'espresso_venue_details_scz');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement