Example #1
0
/**
 * Output the Resonsive Images
 * 
 * @package lsx
 * @subpackage extras
 * @category thumbnails
 */
function lsx_thumbnail($size = 'thumbnail', $image_src = false)
{
    echo lsx_get_thumbnail($size, $image_src);
}
 /**
  * Bind meta data objects
  *
  * @since 0.0.1
  *
  * @return    array room post objects
  */
 public function build_metaplate_data($data, $metaplate)
 {
     global $post;
     if ($post->post_type !== 'property') {
         return $data;
     }
     self::remove_jetpack_sharing();
     // add content
     ob_start();
     the_content();
     $data['post_content'] = ob_get_clean();
     //add exceprt
     $data['excerpt'] = str_replace('[…]', '', get_the_excerpt());
     // permalink
     $data['permalink'] = get_the_permalink();
     // add taxonomies in with a taxonomy. alias
     $taxonomies = get_object_taxonomies($post);
     if (!empty($taxonomies)) {
         foreach ($taxonomies as $taxonomy_name) {
             $taxonomy = get_taxonomy($taxonomy_name);
             $data['taxonomy'][$taxonomy_name] = $data[$taxonomy_name] = wp_get_post_terms($post->ID, $taxonomy_name, array("fields" => "all"));
         }
     }
     if (!empty(get_the_post_thumbnail())) {
         $data['post_thumbnail'] = lsx_get_thumbnail('thumbnail-wide');
     }
     $classes = get_post_class();
     $data['post_class'] = implode(' ', $classes);
     // get rooms and base rate
     if (isset($data['connected_room']) && $post->post_type === 'property') {
         if (is_object($data['connected_room'])) {
             $data['connected_room'] = array($data['connected_room']);
         }
         foreach ((array) $data['connected_room'] as $index => $room) {
             $is_room = get_post($room);
             if ($is_room->post_type == 'room' || $is_room->post_type == 'accommodation') {
                 $data['connected_room'][$index] = $is_room;
                 if (!empty($is_room->_from_price)) {
                     if (!isset($data['accommodation_from']['price']) || $data['accommodation_from']['price'] > $is_room->_from_price) {
                         $data['accommodation_from']['price'] = $is_room->_from_price;
                         $data['accommodation_from']['price_view'] = hb_currency_view($is_room->_from_price, null, false);
                     }
                 }
                 if (!empty($is_room->_rate_type)) {
                     $data['accommodation_from']['rate_type'] = $is_room->_rate_type;
                 }
             }
         }
         $data['accommodation_count'] = (string) count($data['connected_room']);
     }
     if (!empty($data['offers_connect'])) {
         $data['offers_count'] = (string) count($data['offers_connect']);
     }
     if (!empty($data['activities_connect'])) {
         $data['activities_count'] = (string) count($data['activities_connect']);
     }
     if (!empty($data['restaurants_connect'])) {
         $data['restaurants_count'] = (string) count($data['restaurants_connect']);
     }
     $data['global']['site_url'] = site_url();
     // get currency stuff
     $currencys = get_option('_happybeds_currency');
     if (!empty($currencys)) {
         foreach ($currencys['currency'] as $currency) {
             $currency_line = array('code' => $currency['code']);
             if ($currency['_id'] == $currencys['default_currency']) {
                 $currency_line['default'] = true;
             }
             $data['global']['currency'][] = $currency_line;
         }
         $data['global']['base_currency'][] = $currency['code'];
     }
     if (!empty($data['gallery_page'])) {
         $media = get_attached_media('image', $data['gallery_page']);
         $data['gallery_link'] = get_permalink($data['gallery_page']);
     } else {
         $media = get_attached_media('image', $post->ID);
     }
     if (!empty($media)) {
         $data['media'] = $media;
         $images = array();
         foreach ($media as $image) {
             $images[] = $image->ID;
         }
         $columns = 3;
         if (count($images) > 10) {
             $columns = 4;
         }
         if (count($images) > 20) {
             $columns = 5;
         }
         if (count($images) > 40) {
             $columns = 6;
         }
         if (count($images) > 100) {
             $columns = 8;
         }
         $data['gallery'] = do_shortcode('[gallery columns="' . $columns . '" link="file" ids="' . implode(',', $images) . '"]');
         if (count($images) > 3) {
             $images = array_chunk($images, 3);
             $data['gallery_summary'] = do_shortcode('[gallery columns="' . $columns . '" link="file" ids="' . implode(',', $images[0]) . '"]');
         }
     }
     // room rates
     if (!empty($data['connected_room'])) {
         foreach ($data['connected_room'] as $room_key => &$room) {
             $room->permalink = get_permalink($room);
             if (!empty($room->rates) && !empty($room->rates['rate_group'])) {
                 $rates = array();
                 foreach ($room->rates['rate_group'] as $key => $value) {
                     // get rate group
                     $group_parts = explode('-', $value);
                     $post_meta = get_post_meta($group_parts[0], 'rate_groups', true);
                     $price = $room->rates['price'][$key];
                     if (function_exists('hb_currency_view')) {
                         ob_start();
                         hb_currency_view($price);
                         $price = ob_get_clean();
                     }
                     if (!empty($post_meta['group_name'])) {
                         $rate_group = array('group_name' => $post_meta['group_name'][$group_parts[1]], 'start_date' => date('j M Y', strtotime($post_meta['start_date'][$group_parts[1]])), 'end_date' => date('j M Y', strtotime($post_meta['end_date'][$group_parts[1]])), 'price' => $price, 'rate_type' => $room->_rate_type);
                         $rates[] = $rate_group;
                     }
                 }
                 $room->rates = $rates;
             }
             // misc rates
             if (!empty($post->misc_rate)) {
                 $rates = array();
                 foreach ($post->misc_rate['rate_name'] as $key => $value) {
                     // get rate group
                     $price = $post->misc_rate['rate_price'][$key];
                     if (function_exists('hb_currency_view')) {
                         ob_start();
                         hb_currency_view($price);
                         $price = ob_get_clean();
                     }
                     $rate_group = array('group_name' => $value, 'start_date' => date('j M Y', strtotime($post->misc_rate['rate_start_date'][$key])), 'end_date' => date('j M Y', strtotime($post->misc_rate['rate_end_date'][$key])), 'price' => $price);
                     $rates[] = $rate_group;
                 }
                 $room->misc_rate = $rates;
             }
         }
     }
     ob_start();
     echo '<pre>';
     var_dump($data);
     echo '</pre>';
     $data['_fields'] = ob_get_clean();
     //var_dump( $data );
     return $data;
 }