Advertisement
TheSappy

estate.php

Oct 2nd, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 78.46 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Estate Addon class
  4.  */
  5. class PGL_Addon_Estate
  6. {
  7.     static function init()
  8.     {
  9.         self::register();
  10.         self::add_features();
  11.         self::add_actions();
  12.         self::add_filters();
  13.         self::add_shortcodes();
  14.     }
  15.  
  16.     /**
  17.      * #####################################
  18.      * Actions
  19.      * #####################################
  20.      */
  21.     static function register()
  22.     {
  23.         global $pgl_options;
  24.         $args = array(
  25.             'labels' => array(
  26.                 'name' => 'Estates',
  27.                 'singular_name' => 'Estate',
  28.             ),
  29.             'description' => __('This post type is used in RealEstast theme', PGL),
  30.             'public' => TRUE,
  31.             'show_ui' => TRUE,
  32.             'hierarchical' => FALSE,
  33.             'supports' => array(
  34.                 'title',
  35.                 'editor',
  36.                 'thumbnail',
  37.             ),
  38.             'has_archive' => TRUE,
  39.             'rewrite' => array(
  40.                 'slug' => $pgl_options->option('estate_slug') ? $pgl_options->option('estate_slug') : 'estate',
  41.                 'with_front' => false
  42.             ),
  43.         );
  44.         register_post_type('estate', $args);
  45.  
  46.         $args = array(
  47.             'labels' => array(
  48.                 'name' => __('Estate Categories', PGL),
  49.                 'singular_name' => __('Estate Category', PGL),
  50.             ),
  51.             'hierarchical' => TRUE,
  52.             'rewrite' => array(
  53.                 'slug' => ($pgl_options->option('estate_slug') ? $pgl_options->option('estate_slug') : 'estate').'-type',
  54.                 'with_front' => false,
  55.                 'hierarchical' => TRUE,
  56.             )
  57.         );
  58.         register_taxonomy('estate-type', 'estate', $args);
  59.  
  60.         $args = array(
  61.             'labels' => array(
  62.                 'name' => __('Estate Locations', PGL),
  63.                 'singular_name' => __('Estate location', PGL),
  64.             ),
  65.             'hierarchical' => FALSE,
  66.             'rewrite' => array(
  67.                 'slug' => ($pgl_options->option('estate_slug') ? $pgl_options->option('estate_slug') : 'estate').'-location',
  68.                 'with_front' => false,
  69.                 'hierarchical' => TRUE,
  70.             ),
  71.             'single_value' => TRUE,
  72.         );
  73.         register_taxonomy('estate-location', 'estate', $args);
  74.     }
  75.  
  76.     private static function add_features()
  77.     {
  78.         $image_size = array(
  79.             'estate-detail-thumbnail' => array(
  80.                 'w' => 620,
  81.                 'h' => 388,
  82.                 'c' => TRUE,
  83.             ),
  84.             'estate-detail-small-thumbnail' => array(
  85.                 'w' => 55,
  86.                 'h' => 55,
  87.                 'c' => TRUE,
  88.             ),
  89.             'estate-respond-thumbnail' => array(
  90.                 'w' => 720,
  91.                 'h' => 0,
  92.                 'c' => TRUE,
  93.             ),
  94.             'estate-showcase-big-thumbnail' => array(
  95.                 'w' => 600,
  96.                 'h' => 600,
  97.                 'c' => TRUE,
  98.             ),
  99.             'estate-showcase-small-thumbnail' => array(
  100.                 'w' => 400,
  101.                 'h' => 400,
  102.                 'c' => TRUE,
  103.             ),
  104.             'estate-grid-view-3-column-thumbnail' => array(
  105.                 'w' => 300,
  106.                 'h' => 200,
  107.                 'c' => TRUE,
  108.             ),
  109.             'estate-sidebar-widget-thumbnail' => array(
  110.                 'w' => 90,
  111.                 'h' => 54,
  112.                 'c' => TRUE,
  113.             ),
  114.             'estate-icon' => array(
  115.                 'w' => 0,
  116.                 'h' => 14,
  117.                 'c' => TRUE,
  118.             )
  119.         );
  120.  
  121.         foreach ($image_size as $key => $size) {
  122.             add_image_size(_PREFIX_ . $key, $size['w'], $size['h'], $size['c']);
  123.         }
  124.     }
  125.  
  126.     static function add_actions()
  127.     {
  128.         // add_action( 'init', array( 'PGL_Addon_Estate', 'register' ) );
  129.         add_action('admin_init', array(
  130.             'PGL_Addon_Estate',
  131.             'add_meta_box'
  132.         ));
  133.         add_action('save_post', array(
  134.             'PGL_Addon_Estate',
  135.             'save_meta_box'
  136.         ));
  137.         add_action('pre_get_posts', array(
  138.             'PGL_Addon_Estate',
  139.             '__action_list_display'
  140.         ));
  141.         //search action
  142.         add_action('pre_get_posts', array(
  143.             'PGL_Addon_Estate',
  144.             '__action_search'
  145.         ));
  146.         add_action('before_sidebar_hook', array(
  147.             'PGL_Addon_Estate',
  148.             'estate_detail_map'
  149.         ));
  150.         add_action('before_sidebar_hook', array(
  151.             'PGL_Addon_Estate',
  152.             'estate_detail_contact'
  153.         ));
  154.  
  155.         add_action( 'init', 'init_cmb_meta_boxes', 9999 );
  156.     }
  157.  
  158.     static function add_filters()
  159.     {
  160.         add_filter('estate_the_excerpt', array(
  161.             'PGL_Addon_Estate',
  162.             '__filter_the_excerpt'
  163.         ));
  164.         add_filter('search_template', array(
  165.             'PGL_Addon_Estate',
  166.             '__filter_load_search_template'
  167.         ));
  168.         add_filter('archive_template', array(
  169.             'PGL_Addon_Estate',
  170.             '__filter_load_search_template'
  171.         )); //load search template when the search keyword is empty (search by other conditions)
  172.         //      add_filter( 'posts_where', array( 'PGL_Addon_Estate', '__filter_search' ) );
  173.         add_filter( 'cmb_meta_boxes', array(
  174.             'PGL_Addon_Estate',
  175.             '_init_metaboxes'
  176.         ) );
  177.     }
  178.  
  179.     /**
  180.      * ###############################################
  181.      * Shortcodes
  182.      * ###############################################
  183.      */
  184.     private static function add_shortcodes()
  185.     {
  186.         add_shortcode('estate_list', array(
  187.             'PGL_Addon_Estate',
  188.             'estate_list_shortcode'
  189.         ));
  190.         add_shortcode('estate_horizontal_slide', array(
  191.             'PGL_Addon_Estate',
  192.             'estate_horizontal_slide_shortcode'
  193.         ));
  194.         add_shortcode('estate_search', array(
  195.             'PGL_Addon_Estate',
  196.             'estate_search_shortcode'
  197.         ));
  198.         add_shortcode('estate', array(
  199.             'PGL_Addon_Estate',
  200.             'estate_shortcode'
  201.         ));
  202.     }
  203.     static function _init_metaboxes( $meta_boxes ) {
  204.         global $pgl_options;
  205.         $prefix = 'estate_'; // Prefix for all fields
  206.  
  207.         $meta_boxes['estate-core-fields'] = array(
  208.             'id' => $prefix.'core_fields',
  209.             'title' => __('Estate Infomation', PGL),
  210.             'pages' => array('estate'),
  211.             'context' => 'normal',
  212.             'priority' => 'low',
  213.             'show_names' => true,
  214.             'cmb_styles' => false,
  215.             'fields' => array(
  216.                 array(
  217.                     'name' => __('Purpose', PGL),
  218.                     'id' => $prefix . 'purpose',
  219.                     'type' => 'select',
  220.                     'options' => array(
  221.                         array( 'name' => __( 'For sale', PGL ), 'value' => 'sale', ),
  222.                         array( 'name' => __( 'For rent', PGL ), 'value' => 'rent', )
  223.                     )
  224.                 ),
  225.                 array(
  226.                     'name'=> __('Price', PGL),
  227.                     'id' => $prefix . 'price',
  228.                     'type' => 'text_medium',
  229.                     'before' => ' ',
  230.                     'after' => PGL_Utilities::get_currency_symbol($pgl_options->option('estate_currency'))
  231.                 ),
  232.                 array(
  233.                     'name'=>__('Bathroom', PGL),
  234.                     'desc'=>__('Number of bathroom', PGL),
  235.                     'id'=> $prefix . 'bathrooms',
  236.                     'type'=> 'text_small'
  237.                 ),
  238.                 array(
  239.                     'name'=>__('Bedroom', PGL),
  240.                     'desc'=>__('Number of bedroom', PGL),
  241.                     'id'=> $prefix . 'bedrooms',
  242.                     'type'=> 'text_small'
  243.                 ),
  244.                 array(
  245.                     'name'=>__('Area', PGL),
  246.                     'id'=> $prefix . 'area',
  247.                     'after'=> $pgl_options->option('estate_area_unit'),
  248.                     'type'=> 'text_small'
  249.                 ),
  250.                 array(
  251.                     'name'=>__('Coordinates', PGL),
  252.                     'desc'=>__('Input coordinates to display map, lat long separated with ";" eg. 12.123123;34.234234'),
  253.                     'id'=> $prefix . 'coordinates',
  254.                     'type'=> 'text_medium'
  255.                 ),
  256.                 array(
  257.                     'name'=> __('Map position', PGL),
  258.                     'id' => $prefix . 'map_pos',
  259.                     'type' => 'select',
  260.                     'options' => array(
  261.                         array( 'name' => __( 'Sidebar', PGL ), 'value' => 'side', ),
  262.                         array( 'name' => __( 'Content', PGL ), 'value' => 'main', )
  263.                     )
  264.                 ),
  265.                 array(
  266.                     'name'=> __('Sold/Rented', PGL),
  267.                     'desc'=> __('Show sold or rented label', PGL),
  268.                     'id' => $prefix . 'status',
  269.                     'type' => 'select',
  270.                     'options' => array(
  271.                         array( 'name' => __( 'No', PGL ), 'value' => '0', ),
  272.                         array( 'name' => __( 'Yes', PGL ), 'value' => '1', )
  273.                     )
  274.                 ),
  275.                 array(
  276.                     'name'=> __('Featured', PGL),
  277.                     'desc'=> __('Show it in horizontal slider', PGL),
  278.                     'id' => $prefix . 'featured',
  279.                     'type' => 'select',
  280.                     'options' => array(
  281.                         array( 'name' => __( 'No', PGL ), 'value' => '0', ),
  282.                         array( 'name' => __( 'Yes', PGL ), 'value' => '1', )
  283.                     )
  284.                 ),
  285.             )
  286.         );
  287.         return $meta_boxes;
  288.     }
  289.     /**
  290.      * [__filter_search description]
  291.      *
  292.      * @param  string $query [description]
  293.      *
  294.      * @return string        [description]
  295.      */
  296.     static function __filter_search($query)
  297.     {
  298.         if ((isset($_GET['available_from']) && !empty($_GET['available_from'])) || (isset($_GET['available_to']) && !empty($_GET['available_to']))) {
  299.             /**
  300.              * @var $wpdb wpdb
  301.              */
  302.             global $wpdb;
  303.             $tmp = array();
  304.             if (isset($_GET['available_from'])) {
  305.                 $tmp[] = 'from_date >= ' . $_GET['available_from'];
  306.             }
  307.             if (isset($_GET['available_to'])) {
  308.                 $tmp[] = $_GET['available_to'] . ' >= to_date';
  309.             }
  310.             $sub_query = "SELECT post_id from {$wpdb->prefix}datelog WHERE " . implode(' AND ', $tmp);
  311.  
  312.             $query .= " AND {$wpdb->prefix}posts.ID in ($sub_query)";
  313.             // var_dump($query);exit;
  314.  
  315.         }
  316.  
  317.         return $query;
  318.     }
  319.  
  320.     static function info()
  321.     {
  322.  
  323.         return array(
  324.             'title' => 'Estate addon',
  325.         );
  326.     }
  327.  
  328.     /**
  329.      * ##############################################
  330.      * Template tag
  331.      * ##############################################
  332.      */
  333.     static function estate_detail_map(){
  334.         global $post;
  335.         if($post->post_type != 'estate' || get_post_meta($post->ID, 'estate_map_pos', true) == 'main'){
  336.             return false;
  337.         }
  338.         wp_enqueue_script('google-map-api', 'http://maps.google.com/maps/api/js?sensor=false');
  339.         $coordinates = get_post_meta($post->ID, 'estate_coordinates', true);
  340.         $coordinates = explode(',', $coordinates);
  341.         if (count($coordinates) < 2)
  342.             return;
  343.         ?>
  344.         <div class="sidebar-box">
  345.             <div class="title-get">
  346.                 <div class="heading">
  347.                     <span class="widget-name"><?php _e('Map & Direction', PGL) ?></span>
  348.                 </div>
  349.             </div>
  350.         <div id="map_canvas_side" style="width: 100%;height: 300px;"></div>
  351.         <script type="text/javascript">
  352.             var my_map;
  353.             function map_init() {
  354.                 var location = new google.maps.LatLng("<?php
  355.         echo $coordinates[0]; ?>", "<?php
  356.         echo $coordinates[1]; ?>");
  357.                 var map_options = {
  358.                     zoom: 15,
  359.                     center: location,
  360.                     mapTypeId: google.maps.MapTypeId.ROADMAP
  361.                 };
  362.                 my_map = new google.maps.Map(document.getElementById("map_canvas_side"), map_options);
  363.                 var marker = new google.maps.Marker({
  364.                     position: location,
  365.                     map: my_map
  366.                 });
  367.             }
  368.             jQuery(function () {
  369.                 map_init();
  370.             });
  371.         </script>
  372.         </div>
  373.         <?php
  374.     }
  375.     static function estate_detail_contact(){
  376.         global $post;
  377.         $agent_ids = get_post_meta($post->ID,'agent_id');
  378.         if($post->post_type != 'estate' || !$agent_ids){
  379.             return false;
  380.         }
  381.         $widget_name = __('Contact agent', PGL);
  382.         $html = <<<HTML
  383.         <div class="sidebar-box sidebar-agent">
  384.             <div class="title-get">
  385.                 <div class="heading">
  386.                     <span class="widget-name">{$widget_name}</span>
  387.                 </div>
  388.             </div>
  389. HTML;
  390.         foreach($agent_ids as $agent_id){
  391.             $agent = get_post($agent_id);
  392.             $agent_title = esc_html( get_post_meta( $agent->ID, 'agent_title', TRUE ) );
  393.             $agent_name = $agent->post_title;
  394.             $extra = get_agent_extra_info( $agent );
  395.             $image = get_the_post_thumbnail($agent_id, 'estate-agent-square-thumbnail', array('class'=>'img-responsive'));
  396.             $link = get_permalink($agent->ID);
  397.             $class = 'agent-row';
  398.             if($agent_id === end($agent_ids)){
  399.                 $class = 'agent-row-last';
  400.             }
  401.             $html .= <<<HTML
  402.             <div class="row {$class}">
  403.                 <div class="our-img col-md-4 col-sm-4 col-xs-4">
  404.                     <a href="{$link}" title="{$agent_name}">{$image}</a>
  405.                 </div>
  406.                 <div class="our-info col-md-8 col-sm-8 col-xs-8">
  407.                     <h4 class="title">{$agent_title}</h4>
  408.                     <h3 class="name"><a href="{$link}" title="{$agent_name}">{$agent_name}</a></h5>
  409.                     {$extra}
  410.                 </div>
  411.             </div>
  412. HTML;
  413.  
  414.         }
  415.         $html .= <<<HTML
  416.         </div>
  417. HTML;
  418.         echo $html;
  419.     }
  420.     static function estate_map($coordinates)
  421.     {
  422.         global $pgl_options;
  423.         wp_enqueue_script('google-map-api', 'http://maps.google.com/maps/api/js?sensor=false');
  424.         $coordinates = explode(',', $coordinates);
  425.         if (count($coordinates) < 2)
  426.             return;
  427.         ?>
  428.         <div id="map_canvas" style="width: 100%;height: 300px;"></div>
  429.         <script type="text/javascript">
  430.             var my_map;
  431.             function map_init() {
  432.                 var location = new google.maps.LatLng("<?php
  433.         echo $coordinates[0]; ?>", "<?php
  434.         echo $coordinates[1]; ?>");
  435.                 var map_options = {
  436.                     zoom: <?php echo $pgl_options->option('map_zoom_level')?$pgl_options->option('map_zoom_level'):'12' ?>,
  437.                     center: location,
  438.                     mapTypeId: google.maps.MapTypeId.ROADMAP
  439.                 };
  440.                 my_map = new google.maps.Map(document.getElementById("map_canvas"), map_options);
  441.                 var marker = new google.maps.Marker({
  442.                     position: location,
  443.                     map: my_map
  444.                 });
  445.             }
  446.             jQuery(function () {
  447.                 map_init();
  448.             });
  449.         </script>
  450.     <?php
  451.     }
  452.  
  453.     static function the_post_thumbnail($post_id = '', $size = 'estate-list-view-thumbnail', $echo = TRUE)
  454.     {
  455.         if (!$post_id) {
  456.             $post_id = get_the_ID();
  457.         }
  458.         if (has_post_thumbnail($post_id)) {
  459.             the_post_thumbnail(PGL_Image::_size($size));
  460.         } else {
  461.             PGL_Template_Tag::the_post_thumbnail($size);
  462.         }
  463.     }
  464.  
  465.     /**
  466.      * @param WP_Query $query
  467.      *
  468.      * @return \WP_Query
  469.      */
  470.     static function __action_list_display($query)
  471.     {
  472.         if (!is_admin() && $query->is_main_query() && ($query->is_post_type_archive('estate') || $query->is_tax('estate-type'))) {
  473.             /**
  474.              * @var PGL_Options $pgl_options
  475.              */
  476.             global $pgl_options;
  477.             global $paged;
  478.             if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
  479.             elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
  480.             else { $paged = 1; }
  481.  
  482.             $query->set('posts_per_page', $pgl_options->option('number_of_estate'));
  483.             $query->set('paged', $paged);
  484.             if (isset($_GET['sort']) && $order = $_GET['sort']){
  485.                 if($order == 'price'){
  486.                     $query->set('orderby', 'meta_value_num');
  487.                     $query->set('meta_key', 'estate_price');
  488.                 }else{
  489.                     $query->set('orderby', 'title');
  490.                 }
  491.                 $query->set('order', isset($_GET['dir']) ? $_GET['dir'] : "DESC");
  492.             }
  493.         }
  494.         return $query;
  495.     }
  496.  
  497.     /**
  498.      * @param WP_Query $query
  499.      *
  500.      * @return mixed
  501.      */
  502.     static function __action_search($query)
  503.     {
  504.         /**
  505.          * @var PGL_Options $pgl_options
  506.          */
  507.         global $pgl_options;
  508.         if (!is_admin()
  509.             &&
  510.             (
  511.                 ($query->is_search
  512.                     || ($query->is_post_type_archive('estate') && isset($_GET['search'])))
  513.                 && isset($_GET['post_type'])
  514.                 && $_GET['post_type'] == 'estate'
  515.             )
  516.         ) {
  517.             $searchable_fields = $pgl_options->option('estate_searchable_fields');
  518.             if (!empty($searchable_fields)) {
  519.                 $searchable_fields = array_keys($searchable_fields);
  520.             } else {
  521.                 $searchable_fields = array();
  522.             }
  523.             $searchable_fields[] = 'price';
  524.  
  525.             $conditional_array = array();
  526.             /**
  527.              * Automatic find & add search values to query. Only apply for number type
  528.              */
  529.             $sType = $pgl_options->option('estate_system_type');
  530.             if ($sType == 'both' || $sType == 'rental') {
  531.                 $conditional_array[] = array(
  532.                     'key' => 'estate_purpose',
  533.                     'value' => isset($_GET['purpose']) ? $_GET['purpose'] : 'rent',
  534.                     'compare' => 'LIKE',
  535.                 );
  536.             } elseif ($sType == 'both' || $sType == 'sale') {
  537.                 $conditional_array[] = array(
  538.                     'key' => 'estate_purpose',
  539.                     'value' => isset($_GET['purpose']) ? $_GET['purpose'] : 'sale',
  540.                     'compare' => 'LIKE',
  541.                 );
  542.             }
  543.  
  544.  
  545.             foreach ($searchable_fields as $field) {
  546.                 if (isset($_GET[$field . '_from']) && $_GET[$field . '_from']) {
  547.                     $conditional_array[] = array(
  548.                         'key' => 'estate_' . $field,
  549.                         'value' => $_GET[$field . '_from'],
  550.                         'compare' => '>=',
  551.                         'type' => 'numeric',
  552.                     );
  553.                 }
  554.  
  555.                 if (isset($_GET[$field . '_to']) && $_GET[$field . '_to']) {
  556.                     $conditional_array[] = array(
  557.                         'key' => 'estate_' . $field,
  558.                         'value' => $_GET[$field . '_to'],
  559.                         'compare' => '<=',
  560.                         'type' => 'numeric',
  561.                     );
  562.                 }
  563.             }
  564.  
  565.             $conditional_array = apply_filters('estate/filter/search/meta_query', $conditional_array);
  566.             if (count($conditional_array) > 1) {
  567.                 $conditional_array['relation'] = 'AND';
  568.             }
  569.             $query->set('meta_query', $conditional_array);
  570.  
  571.             $tax_query = array(
  572.                 'relation' => 'AND',
  573.             );
  574.             if (isset($_GET['term']) && $_GET['term']) {
  575.                 $tax_query[] = array(
  576.                     'taxonomy' => 'estate-type',
  577.                     'terms' => $_GET['term'],
  578.                     'field' => 'slug',
  579.                     'compare' => 'LIKE',
  580.                 );
  581.             }
  582.             if (isset($_GET['location']) && $_GET['location']) {
  583.                 $tax_query[] = array(
  584.                     'taxonomy' => 'estate-location',
  585.                     'terms' => $_GET['location'],
  586.                     'field' => 'slug',
  587.                     'compare' => 'LIKE',
  588.                 );
  589.             }
  590.             $query->set('tax_query', $tax_query);
  591.         }
  592.         return $query;
  593.     }
  594.  
  595.     /**
  596.      * ##############################################
  597.      * Add metabox
  598.      * ##############################################
  599.      */
  600.     static function add_meta_box()
  601.     {
  602.         wp_enqueue_style('estate-admin-css', PGL_URI_CSS . 'estate/estate-admin.css');
  603.         wp_enqueue_style('pgl-admin-css', PGL_URI_CSS . 'admin/admin-style.css');
  604.         add_meta_box('estate-gallery', __('Estate Gallery', PGL), array(
  605.             'PGL_Addon_Estate',
  606.             'estate_gallery_box2'
  607.         ), 'estate', 'normal', 'high');
  608.  
  609.         add_meta_box('estate-featured-video', __('Estate Featured Video', PGL), array(
  610.             'PGL_Addon_Estate',
  611.             'estate_featured_video'
  612.         ), 'estate', 'side', 'low');
  613.         /*add_meta_box('estate-core-fields', __('Estate information', PGL), array(
  614.             'PGL_Addon_Estate',
  615.             'estate_core_fields_box'
  616.         ), 'estate', 'normal', 'high');*/
  617.  
  618.         add_meta_box('estate-image-fields', __('Icon fields', PGL), array(
  619.             'PGL_Addon_Estate',
  620.             'icon_field_metabox'
  621.         ), 'estate', 'advanced', 'low');
  622.     }
  623.  
  624.     static function save_meta_box($post_id)
  625.     {
  626.         global $post;
  627.         if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  628.  
  629.             return $post_id;
  630.         }
  631.         if (is_null($post))
  632.             return NULL;
  633.         if ($post->post_type != 'estate') {
  634.  
  635.             return NULL;
  636.         }
  637.         $estate_video = sanitize_text_field($_POST['estate_video']);
  638.         update_post_meta($post->ID, 'estate_featured_video', sanitize_text_field($_POST['estate_video']));
  639.         if ($estate_video) {
  640.             update_post_meta($post->ID, 'estate_featured_video_thumbnail_url', PGL_Utilities::get_video_thumbnail($estate_video));
  641.         }
  642.  
  643.         update_post_meta($post->ID, '_estate_image_gallery', $_POST['estate_image_gallery']);
  644.  
  645.         if (isset($_POST['estate_icon'])) {
  646.             $icons = json_encode($_POST['estate_icon']);
  647.             update_post_meta($post->ID, 'estate_icon', $icons);
  648.         }
  649.  
  650.         return TRUE;
  651.     }
  652.  
  653.     static function icon_field_metabox()
  654.     {
  655.         global $post;
  656.         global $pgl_options;
  657.         $icons = get_post_meta($post->ID, 'estate_icon', TRUE);
  658.         if ($icons) {
  659.             $icons = json_decode($icons, TRUE);
  660.         } else {
  661.             $icons = array();
  662.         }
  663.         $icon_fields = $pgl_options->option('estate_image_fields');
  664.         $len = count($icon_fields);
  665.         ?>
  666.         <table>
  667.             <?php for ($i = 0; $i < $len; $i++) {
  668.                 ?>
  669.                 <tr>
  670.                     <td><?php
  671.                         echo wp_get_attachment_image($icon_fields[$i]['id']);
  672.                         ?></td>
  673.                     <td>
  674.                         <?php
  675.                         $icon_id = $icon_fields[$i]['id'] . '_' . (str_replace(' ', '_', strtolower($icon_fields[$i]['label'])));
  676.                         $name = "estate_icon[$icon_id]";
  677.                         ?>
  678.                         <input type="checkbox" name="<?php echo $name ?>"
  679.                                value="1" <?php if (isset($icons[$icon_id])) echo 'checked'; ?> />
  680.                     </td>
  681.                 </tr>
  682.             <?php
  683.             }?>
  684.         </table>
  685.     <?php
  686.     }
  687.  
  688.     static function estate_featured_video()
  689.     {
  690.         global $post;
  691.         $video_url = get_post_meta($post->ID, 'estate_featured_video', TRUE);
  692.         $video_thumbnail_url = get_post_meta($post->ID, 'estate_featured_video_thumbnail_url', TRUE);
  693.         // $thumbnail = PGL_Utilities::get_video_thumbnail( $video_url );
  694.  
  695.         ?>
  696.         <div id="estate-featured-video-container" class="estate-metabox side">
  697.             <input type="text" name="estate_video" id="estate-featured-video" value="<?php
  698.             echo esc_attr($video_url); ?>">
  699.  
  700.             <p>
  701.                 <img src="<?php
  702.                 echo esc_attr($video_thumbnail_url) ?>" alt=""/>
  703.             </p>
  704.  
  705.             <p class="notice">
  706.                 <?php
  707.                 _e('You must not set the featured image in order to display the feature video', PGL) ?>
  708.             </p>
  709.         </div>
  710.     <?php
  711.     }
  712.  
  713.     static function estate_gallery_box2()
  714.     {
  715.         global $post;
  716.         wp_enqueue_script('estate-admin-gallery', PGL_URI_JS . 'estate/admin-gallery2.js', array(
  717.             'jquery',
  718.             'backbone'
  719.         ), '1.0', true);
  720.         wp_enqueue_script('holderjs', '//cdn.jsdelivr.net/holder/1.9.0/holder.js', array(), '1.9', TRUE);
  721.  
  722.         $gallery_string = get_post_meta($post->ID, '_estate_image_gallery', TRUE);
  723.         ?>
  724.         <div id="gallery-container" class="pgl-meta-box">
  725.             <ul></ul>
  726.             <p class="gallery_commands">
  727.                 <a href="#" id="add_image"><?php
  728.                     _e('Add image', PGL); ?></a>
  729.                 <a id="add_video" href="#"><?php
  730.                     _e('Add video', PGL) ?></a>
  731.             </p>
  732.             <input type="hidden" id="ids" name="estate_image_gallery" value='<?php
  733.             echo esc_attr($gallery_string); ?>'/>
  734.         </div>
  735.     <?php
  736.     }
  737.  
  738.     static function estate_gallery_box()
  739.     {
  740.         global $post;
  741.         wp_enqueue_script('estate-admin-gallery', PGL_URI_JS . 'estate/admin-gallery.js', array(
  742.             'jquery'
  743.         ), '1.0');
  744.         wp_enqueue_script('holderjs', '//cdn.jsdelivr.net/holder/1.9.0/holder.js', array(), '1.9', TRUE);
  745.         ?>
  746.         <div id="estate_images_container">
  747.             <ul class="product_images">
  748.                 <?php
  749.                 $gallery = get_post_meta($post->ID, '_estate_image_gallery', TRUE);
  750.                 $gallery = array_filter(explode(',', $gallery));
  751.                 if (!empty($gallery)) {
  752.  
  753.                     foreach ($gallery as $image) {
  754.                         ?>
  755.                         <li data-id="<?php
  756.                         echo esc_attr($image); ?>">
  757.                             <?php
  758.                             echo wp_get_attachment_image($image) ?>
  759.                             <a class="close" href="#">&times;</a>
  760.                         </li>
  761.                     <?php
  762.                     }
  763.                 }
  764.                 ?>
  765.             </ul>
  766.             <input type="hidden" id="estate_image_gallery" name="estate_image_gallery" value="<?php
  767.             if (!empty($gallery)) echo esc_attr(implode(',', $gallery)); ?>"/>
  768.         </div>
  769.         <p class="gallery_commands">
  770.             <a href="#" class="add_image_btn"><?php
  771.                 _e('Add image', PGL); ?></a>
  772.             <!-- <a href="#" class="add_video_btn"><?php
  773.         _e('Add video', PGL); ?></a> -->
  774.         </p>
  775.     <?php
  776.     }
  777.  
  778.     /**
  779.      * ##############################################
  780.      * Add option to theme option panel
  781.      * ##############################################
  782.      */
  783.     static function add_option_panel()
  784.     {
  785.         /**
  786.          * @var PGL_Options $pgl_options
  787.          */
  788.         global $pgl_options;
  789.         /**
  790.          * Search settings
  791.          *
  792.          * @var array $search
  793.          */
  794.         $search     = array(
  795.             'id'         => 'search',
  796.             'icon'       => 'search',
  797.             'title'      => __( 'Estate search', PGL ),
  798.             'desc'       => __( 'Search setting(s)', PGL ),
  799.             'fields'     => array(
  800.                 array(
  801.                     'id' => 'estate_search_home',
  802.                     'title' => __('Show search form on homepage', PGL),
  803.                     'type'     => 'checkbox',
  804.                     'switch'   => TRUE,
  805.                     'std' => 1
  806.                 ),
  807.                 array(
  808.                     'id' => 'estate_search_archive',
  809.                     'title' => __('Show search form on archive page', PGL),
  810.                     'type'     => 'checkbox',
  811.                     'switch'   => TRUE,
  812.                     'std' => 0
  813.                 ),
  814.                 array(
  815.                     'id' => 'estate_search_result',
  816.                     'title' => __('Show search form on search result page', PGL),
  817.                     'type'     => 'checkbox',
  818.                     'switch'   => TRUE,
  819.                     'std' => 0
  820.                 ),
  821.                 array(
  822.                     'id' => 'estate_search_map',
  823.                     'title' => __('Estate search map', PGL),
  824.                     'type'     => 'checkbox',
  825.                     'switch'   => TRUE,
  826.                     'desc' => __('Display map under search form', PGL),
  827.                     'std' => 0
  828.                 ),
  829.                 array(
  830.                     'id' => 'estate_search_latlong',
  831.                     'title' => __('Centered map point(s)', PGL),
  832.                     'type' => 'text',
  833.                     'desc' => __('Latitude and Longitude, separated by semicolon (Example for London: 51.511214;-0.126160) click <a target="_blank" href="http://www.latlong.net/">here</a> to search', PGL),
  834.                     'std' => '51.511214;-0.126160'
  835.                 ),
  836.                 array(
  837.                     'id' => 'estate_search_zoom',
  838.                     'title' => __('Map zoom level', PGL),
  839.                     'type'     => 'text',
  840.                     'validate'  => 'numeric',
  841.                     'desc' => __('Zoom level of display map', PGL),
  842.                     'std' => 12
  843.                 ),
  844.                 array(
  845.                     'id' => 'estate_search_layout',
  846.                     'title' => __('Estate search layout', PGL),
  847.                     'type' => 'select',
  848.                     'options' => PGL_Utilities::list_template_file('templates/estate-loop', 'estate-loop'),
  849.                     'std' => 'estate-loop-default'
  850.                 ),
  851.                 array(
  852.                     'id' => 'estate_searchable_fields',
  853.                     'title' => __('Searchable Fields (By default, we can perform searching by title & price)', PGL),
  854.                     'type' => 'multi_checkbox',
  855.                     'options' => array(
  856.                         'bathrooms' => __('Bathrooms', PGL),
  857.                         'bedrooms' => __('Bedrooms', PGL),
  858.                         'area' => __('Area', PGL)
  859.                     )
  860.                 ),
  861.                 array(
  862.                     'id' => 'estate_searchable_field_sale_price_from',
  863.                     'title' => __('Price from for sale search', PGL),
  864.                     'type' => 'text',
  865.                     'desc' => __('Values are separated by semicolons (eg. 100;200;300)', PGL),
  866.                     'std' => ''
  867.                 ),
  868.                 array(
  869.                     'id' => 'estate_searchable_field_sale_price_to',
  870.                     'title' => __('Price to for sale search', PGL),
  871.                     'type' => 'text',
  872.                     'desc' => __('Values are separated by semicolons (eg. 100;200;300)', PGL),
  873.                     'std' => ''
  874.                 ),
  875.                 array(
  876.                     'id' => 'estate_searchable_field_rent_price_from',
  877.                     'title' => __('Price from for rental search', PGL),
  878.                     'type' => 'text',
  879.                     'desc' => __('Values are separated by semicolons (eg. 100;200;300)', PGL),
  880.                     'std' => ''
  881.                 ),
  882.                 array(
  883.                     'id' => 'estate_searchable_field_rent_price_to',
  884.                     'title' => __('Price to for rental search', PGL),
  885.                     'type' => 'text',
  886.                     'desc' => __('Values are separated by semicolons (eg. 100;200;300)', PGL),
  887.                     'std' => ''
  888.                 ),
  889.             )
  890.         );
  891.         if ($searchable_fields = $pgl_options->option('estate_searchable_fields')) {
  892.  
  893.             foreach ($searchable_fields as $key => $val) {
  894.                 $search['fields'][] = array(
  895.                     'id' => 'estate_searchable_field_' . $key,
  896.                     'title' => __('Configure value for ' . ucfirst($key) . ' search'),
  897.                     'type' => 'text',
  898.                     'desc' => __('Values are separated by semicolons', PGL),
  899.                     'std' => '0'
  900.                 );
  901.             }
  902.         }
  903.         $section = array(
  904.             'id' => 'estate',
  905.             'icon' => 'home',
  906.             'title' => __('Estate Property', PGL),
  907.             'desc' => __('Settings for estate custom post type', PGL),
  908.             'fields' => array(
  909.                 array(
  910.                     'id' => 'estate_slug',
  911.                     'title' => __('Custom Estate Slug', PGL),
  912.                     'type' => 'text',
  913.                     'desc' => __('Change url for browsing, viewing estate (estate,listings,..)', PGL),
  914.                     'std' => 'estate',
  915.                 ),
  916.                 array(
  917.                     'id' => 'estate_system_type',
  918.                     'title' => __('Estate system type', PGL),
  919.                     'type' => 'select',
  920.                     'options' => array('both' => __('Both Sale & Rental', PGL), 'sale' => __('Sale Only', PGL), 'rental' => __('Rental Only', PGL), 'showcase' => __('Showcase', PGL)),
  921.                     'std' => 'both'
  922.                 ),
  923.                 array(
  924.                     'id' => 'estate_currency',
  925.                     'title' => __('Estate Currency', PGL),
  926.                     'type' => 'select',
  927.                     'options' => PGL_Utilities::get_currencies(),
  928.                     'std' => 'USD',
  929.                 ),
  930.                 array(
  931.                     'id' => 'estate_currency_placement',
  932.                     'title' => __('Where to place currency symbol ? ', PGL),
  933.                     'type' => 'select',
  934.                     'options' => array(
  935.                         'before' => __('Before the price', PGL),
  936.                         'after' => __('After the price', PGL)
  937.                     ),
  938.                     'std' => 'before'
  939.                 ),
  940.                 array(
  941.                     'id' => 'estate_custom_currency',
  942.                     'title' => __('Estate Custom Currency Symbol', PGL),
  943.                     'type' => 'text',
  944.                     'std' => '$',
  945.                 ),
  946.                 array(
  947.                     'id'       => 'estate_price_decimal',
  948.                     'title'    => __( 'Decimal price', PGL ),
  949.                     'type'     => 'checkbox',
  950.                     'desc'     => __( 'Estate price with decimals', PGL ),
  951.                     'switch'   => TRUE,
  952.                     'std'      => '1',
  953.                 ),
  954.                 array(
  955.                     'id' => 'estate_thousand_sep',
  956.                     'title' => __('Thousand Separator', PGL),
  957.                     'type' => 'text',
  958.                     'std' => '.',
  959.                 ),
  960.                 array(
  961.                     'id' => 'estate_decimal_sep',
  962.                     'title' => __('Decimal Separator', PGL),
  963.                     'type' => 'text',
  964.                     'std' => ',',
  965.                 ),
  966.                 array(
  967.                     'id' => 'estate_decimal_num',
  968.                     'title' => __('Number of Decimals', PGL),
  969.                     'type' => 'text',
  970.                     'std' => '2',
  971.                     'sub_desc' => __('Number of decimals show in price, default is "2"',PGL)
  972.                 ),
  973.                 array(
  974.                     'id' => 'estate_sale_price_suffix',
  975.                     'title' => __('Sale price\'s suffix ', PGL),
  976.                     'type' => 'text',
  977.                     'std' => '',
  978.                     'desc' => ''
  979.                 ),
  980.                 array(
  981.                     'id' => 'estate_rent_price_suffix',
  982.                     'title' => __('Rental price \'s suffix ', PGL),
  983.                     'type' => 'text',
  984.                     'std' => '',
  985.                     'sub_desc' => 'You can set suffix for rental price here. For example: 100$ <strong>per month</strong>'
  986.                 ),
  987.                 array(
  988.                     'id' => 'estate_no_price_text',
  989.                     'title' => __('No price text', PGL),
  990.                     'sub_desc' => __('Text displayed when you leave the price field empty', PGL),
  991.                     'type' => 'text',
  992.                     'std' => __('Contact for price', PGL)
  993.                 ),
  994.                 array(
  995.                     'id' => 'estate_area_unit',
  996.                     'title' => __('Area unit', PGL),
  997.                     'type' => 'text',
  998.                     'std' => ''
  999.                 ),
  1000.                 array(
  1001.                     'id' => 'estate_list_layout',
  1002.                     'title' => __('Estate list layout', PGL),
  1003.                     'type' => 'select',
  1004.                     'options' => PGL_Utilities::list_template_file('templates/estate-loop', 'estate-loop'),
  1005.                     'std' => 'estate-loop-default'
  1006.                 ),
  1007.  
  1008.                 array(
  1009.                     'id' => 'number_of_estate',
  1010.                     'title' => __('How many estates are displayed per page ?', PGL),
  1011.                     'type' => 'text',
  1012.                     'std' => 5
  1013.                 ),
  1014.                 array(
  1015.                     'id' => 'estate_single_layout',
  1016.                     'title' => __('Estate Single Layout', PGL),
  1017.                     'type' => 'select',
  1018.                     'options' => PGL_Utilities::list_template_file('templates/estate-single'),
  1019.                     'std' => 'estate-single-default'
  1020.                 ),
  1021.                 array(
  1022.                     'id' => 'estate_image_fields',
  1023.                     'title' => __('Create icon fields', PGL),
  1024.                     'callback' => array('PGL_Addon_Estate', 'create_image_fields')
  1025.                 )
  1026.             )
  1027.         );
  1028.         $pgl_options->add_section($section, 'addons');
  1029.         $pgl_options->add_section($search, 'search');
  1030.     }
  1031.  
  1032.     static function create_image_fields($field, $value)
  1033.     {
  1034.         global $pgl_options;
  1035.         wp_enqueue_script('estate-image-field', PGL_URI_JS . 'estate/image_fields.js', array('jquery'));
  1036.         ?>
  1037.         <div class="estate_image_field_wrapper">
  1038.             <div class="actionbar">
  1039.                 <button id="add_image_field" type="button" class="button"><?php _e('Add image field', PGL);?></button>
  1040.                 <input type="hidden" id="id_field"
  1041.                        value="<?php echo $pgl_options->THEME_OPTION . '[' . $field['id'] . ']'; ?>"/>
  1042.             </div>
  1043.             <div class="fields">
  1044.                 <table id="image_field_tbl" class="table">
  1045.                     <?php
  1046.                     if (isset( $value ) && !empty($value)) {
  1047.                         $i = 0;
  1048.                         foreach ($value as $v) {
  1049.                             list($image) = wp_get_attachment_image_src($v['id']);
  1050.                             ?>
  1051.                             <tr>
  1052.                                 <td>
  1053.                                     <input type="hidden"
  1054.                                            name="<?php echo $pgl_options->THEME_OPTION . '[' . $field['id'] . '][' . $i . '][id]' ?>"
  1055.                                            value="<?php echo $v['id']; ?>"/><img src="<?php echo $image; ?>" alt=""/>
  1056.                                 </td>
  1057.                                 <td>
  1058.                                     <input type="text"
  1059.                                            name="<?php echo $pgl_options->THEME_OPTION . '[' . $field['id'] . '][' . $i . '][label]' ?>"
  1060.                                            value="<?php echo $v['label']; ?>"/>
  1061.                                 </td>
  1062.                                 <td>
  1063.                                     <input type="button" value="Remove" class="removeRowBtn"/>
  1064.                                 </td>
  1065.                             </tr>
  1066.                         <?php
  1067.                             $i++;
  1068.                         }
  1069.                     }
  1070.                     ?>
  1071.                 </table>
  1072.             </div>
  1073.         </div>
  1074.     <?php
  1075.     }
  1076.  
  1077.     static function estate_list_shortcode($atts)
  1078.     {
  1079.         extract(shortcode_atts(array(
  1080.             'display' => 'grid',
  1081.             'filter' => 1,
  1082.             'count' => 6,
  1083.             'column' => 3,
  1084.             'total_col' => 12,
  1085.             'agent_id' => '',
  1086.             'agent_slug' => '',
  1087.             'location_id' => '',
  1088.             'type_id' => '',
  1089.             'type_slug' => '',
  1090.             'acs' => '',
  1091.             'pager' => false
  1092.         ), $atts));
  1093.         /**
  1094.          * @var $display
  1095.          * @var $filter
  1096.          * @var $count
  1097.          * @var $column
  1098.          * @var $total_col
  1099.          * @var $agent_id
  1100.          * @var $agent_slug
  1101.          * @var $location_id
  1102.          * @var $type_id
  1103.          * @var $type_slug
  1104.          * @var $acs
  1105.          * @var $pager
  1106.          */
  1107.         $args = array(
  1108.             'posts_per_page' => $count,
  1109.             'meta_query' => array(),
  1110.             'tax_query' => array()
  1111.         );
  1112.         if ($agent_id) {
  1113.             $args['meta_query'][] = array(
  1114.                 'key' => 'agent_id',
  1115.                 'value' => explode(',', $agent_id),
  1116.                 'compare' => 'IN'
  1117.             );
  1118.         }elseif($agent_slug){
  1119.             $agents = get_posts(array('post_type'=>'estate_agent','name'=>$agent_slug));
  1120.             if(count($agents)){
  1121.                 $args['meta_query'][] = array(
  1122.                     'key' => 'agent_id',
  1123.                     'value' => explode(',', $agents[0]->ID),
  1124.                     'compare' => 'IN'
  1125.                 );
  1126.             }
  1127.         }
  1128.         if ($location_id) {
  1129.             $args['tax_query'][] = array(
  1130.                 'taxonomy' => 'estate-location',
  1131.                 'field' => 'id',
  1132.                 'terms' => explode(',', $location_id),
  1133.             );
  1134.         }
  1135.         if ($type_id) {
  1136.             $args['tax_query'][] = array(
  1137.                 'taxonomy' => 'estate-type',
  1138.                 'field' => 'id',
  1139.                 'terms' => explode(',', $type_id),
  1140.             );
  1141.         }elseif($type_slug){
  1142.             $args['tax_query'][] = array(
  1143.                 'taxonomy' => 'estate-type',
  1144.                 'field' => 'slug',
  1145.                 'terms' => $type_slug
  1146.             );
  1147.             $type_id = $type_slug;
  1148.         }
  1149.         if (count($args['meta_query']) > 2) {
  1150.             $args['tax_query']['relation'] = 'AND';
  1151.         }
  1152.         $output_html = null;
  1153.         if ($display == 'grid') {
  1154.             $output_html = self::estate_grid($args, $filter, $type_id, $column, $total_col, $pager, NULL, $acs);
  1155.         } else if ($display == 'list') {
  1156.             $output_html = self::estate_list($args, $type_id, $pager, NULL, $acs);
  1157.         }
  1158.         return $output_html;
  1159.     }
  1160.  
  1161.     static function estate_grid($args = array(), $show_filter = TRUE, $type = null, $column = 3, $total_span = 12, $pager = FALSE, $the_query = NULL, $acs_group = '')
  1162.     {
  1163.         global $paged;
  1164.         $paged = 1;
  1165.         if ( get_query_var('paged') ) $paged = get_query_var('paged');
  1166.         if ( get_query_var('page') ) $paged = get_query_var('page');
  1167.         if (is_null($the_query)) {
  1168.             $defaults = array(
  1169.                 'posts_per_page' => 9,
  1170.                 'post_type' => 'estate',
  1171.                 'meta_query' => array(),
  1172.                 'tax_query' => array()
  1173.             );
  1174.             if(1!=$paged){
  1175.                 $args['paged'] = $paged;
  1176.             }
  1177.             $params = wp_parse_args($args, $defaults);
  1178.             if ($acs_group) {
  1179.                 $the_query = add_acs_query($acs_group, $params);
  1180.             } else
  1181.                 $the_query = new WP_Query($params);
  1182.         }
  1183.         if ($the_query->have_posts()) {
  1184.             $htmlOut = null;
  1185.             wp_enqueue_script('jquery-mixitup', PGL_URI_JS . 'mixitup/jquery.mixitup.min.js', array(
  1186.                 'jquery'
  1187.             ), '2.0', TRUE);
  1188.  
  1189.             $estate_list_html = '';
  1190.             $taxonomies_list = array();
  1191.             $extract_func = create_function('$obj', 'return $obj->slug;');
  1192.             $extract_name = create_function('$obj', 'return $obj->name;');
  1193.             $item_span = ceil($total_span / $column);
  1194.             $count = 0;
  1195.             while ($the_query->have_posts()) {
  1196.                 $count++;
  1197.                 $the_query->the_post();
  1198.                 $the_id = get_the_ID();
  1199.                 $taxonomies = get_the_terms($the_id, 'estate-type');
  1200.                 if ($taxonomies) {
  1201.                     $taxonomies_list = $taxonomies_list + $taxonomies;
  1202.                     $taxonomy_slugs = array_map($extract_func, $taxonomies);
  1203.                 } else {
  1204.                     $taxonomy_slugs = array();
  1205.                 }
  1206.  
  1207.  
  1208.  
  1209.                 $purpose = get_post_meta($the_id, 'estate_purpose', TRUE);
  1210.                 $status = get_post_meta($the_id, 'estate_status', TRUE);
  1211.                 $status_span = '';
  1212.                 if($status){
  1213.                     if($purpose == 'sale'){
  1214.                         $status_span = '<span class="status">'.__('Sold', PGL).'</span>';
  1215.                     }elseif($purpose == 'rent'){
  1216.                         $status_span = '<span class="status">'.__('Rented', PGL).'</span>';
  1217.                     }
  1218.                 }
  1219.  
  1220.                 $types = explode(',',get_the_term_list( $the_id, 'estate-type', '', ',' ));
  1221.                 $typeHtml = '';
  1222.                 $tipHtml = null;
  1223.                 $typeLbl = __( 'Type', PGL );
  1224.                 if(!$show_filter && !$type){
  1225.                     $typeHtml .= <<<HTML
  1226.                 <div class="col-md-12 col-sm-12">
  1227.                     <span class="line-top">
  1228.                         {$typeLbl}:
  1229.                         <span class="pull-right">
  1230. HTML;
  1231.                     if(count($types)>3){
  1232.                         for($i=0; $i<3; $i++){
  1233.                             $typeHtml .= $types[$i];
  1234.                             if($i<2) $typeHtml .= ', ';
  1235.                         }
  1236.                         $count = 0;
  1237.                         for($i=3; $i<count($types); $i++){
  1238.                             $count++;
  1239.                             $tipHtml .= $types[$i];
  1240.                         }
  1241.                         $typeHtml .= <<<HTML
  1242.     <span class="more-type"><a href="javascript:void(0)" class="type-popover" data-toggle="popover" data-placement="left" data-container="body" data-content='{$tipHtml}' data-html="true">{$count}+</a></span>
  1243. HTML;
  1244.                     }else{
  1245.                         $typeHtml .= get_the_term_list( $the_id, 'estate-type', '', ', ' );
  1246.                     }
  1247.                 $typeHtml .= <<<HTML
  1248.                         </span>
  1249.                     </span>
  1250.                 </div>
  1251. HTML;
  1252.                 }
  1253.                 $params = array(
  1254.                     'thumb' => self::get_estate_thumbnail($the_id, 'estate-respond-thumbnail'),
  1255.                     'html' => apply_filters('estate/list/fields', ''),
  1256.                     'link' => get_permalink($the_id),
  1257.                     'title' => get_the_title($the_id),
  1258.                     'price' => PGL_Addon_Estate::format_price(get_post_meta($the_id, 'estate_price', TRUE), get_post_meta($the_id, 'estate_purpose', TRUE)),
  1259.                     'default_fields' => PGL_Addon_Estate::display_default_fields($the_id, 12),
  1260.                     'filters' => implode(' ', $taxonomy_slugs),
  1261.                     'status_span' => $status_span,
  1262.                     'item_span' => $item_span,
  1263.                     'typeHtml'  => $typeHtml
  1264.                 );
  1265.                 $estate_list_html .= PGL_Utilities::get_include_contents('templates/item/grid.php', $params);
  1266.             }
  1267.             wp_reset_postdata();
  1268.             $filterClass = ($show_filter)? ' filter-active' : '';
  1269.             $filterOn = ($show_filter)? ' filter-on' : '';
  1270.             $htmlJs = '';
  1271.             $pagerHtml = '';
  1272.             if ($pager) {
  1273.                 $pagination_links = PGL_pagination(array(
  1274.                     'next_text' => '<i class="fa fa-angle-right"></i>',
  1275.                     'prev_text' => '<i class="fa fa-angle-left"></i>',
  1276.                 ), $the_query);
  1277.                 $pagerHtml .= <<<HTML
  1278.                 <div class="page-ination onleft">
  1279.                     <div class="page-in">
  1280.                         <ul class="pager">
  1281. HTML;
  1282.                             if ($pagination_links) {
  1283.                                 foreach ($pagination_links as $link){
  1284.                                     $pagerHtml .= <<<HTML
  1285. <li>{$link}</li>
  1286. HTML;
  1287.  
  1288.                                 }
  1289.                             }
  1290.                 $pagerHtml .= <<<HTML
  1291.                         </ul>
  1292.                     </div>
  1293.                 </div>
  1294. HTML;
  1295.             }
  1296.             if ($show_filter) {
  1297.                 $htmlJs = <<<HTML
  1298.                 <script type="text/javascript">
  1299.                     jQuery(function($){
  1300.                         var mixList = $('#able-list');
  1301.                         var listFil = $('#able-filter');
  1302.                         var seleFil = $('#able-select');
  1303.                         $(window).load(function(){
  1304.  
  1305.                             mixList.mixitup({
  1306.                                 effects: ["fade","blur"],
  1307.                                 onMixLoad: function(){
  1308.                                     mixList.masonry({
  1309.                                         columnWidth: ".grid-sizer",
  1310.                                         itemSelector: ".mix",
  1311.                                         transitionDuration: 0
  1312.                                     })
  1313.                                 },
  1314.                                 onMixEnd: function(){
  1315.                                     mixList.data('masonry').layout();
  1316.                                     data = listFil.find("a.active").first().data("filter");
  1317.                                     seleFil.val(data);
  1318.                                 }
  1319.                             });
  1320.                         });
  1321.                         seleFil.change(function(){
  1322.                             mixList.mixitup("remix",seleFil.val());
  1323.                         });
  1324.                         $(window).resize(function(){
  1325.                             data = listFil.find("a.active").first().data("filter");
  1326.                             if(seleFil.is(":visible")){
  1327.                                 data=seleFil.val();
  1328.                             }
  1329.                             mixList.mixitup("remix",data);
  1330.                         });
  1331.                         $('.type-popover').popover({html:true});
  1332.                         $('.has-tooltip').tooltip();
  1333.                     });
  1334.                 </script>
  1335. HTML;
  1336.             }else{
  1337.                 $htmlJs = <<<HTML
  1338.                 <script type="text/javascript">
  1339.                     jQuery(function($){
  1340.                         var mixList = $('#able-list');
  1341.                         $(window).load(function(){
  1342.                             mixList.mixitup({
  1343.                                 effects: ["fade","blur"],
  1344.                                 onMixLoad: function(){
  1345.                                     mixList.masonry({
  1346.                                         columnWidth: ".grid-sizer",
  1347.                                         itemSelector: '.mix',
  1348.                                         transitionDuration: 0,
  1349.                                         isResizeBound: false
  1350.                                     })
  1351.                                 },
  1352.                                 onMixEnd: function(){
  1353.                                     mixList.data('masonry').layout();
  1354.                                 }
  1355.                             });
  1356.                         });
  1357.                         $(window).resize(function(){
  1358.                             mixList.mixitup("remix","all");
  1359.                         });
  1360.                         $('.type-popover').popover({html:true});
  1361.                         $('.has-tooltip').tooltip();
  1362.                     });
  1363.                 </script>
  1364. HTML;
  1365.             }
  1366.             $headText = __('Properties', PGL);
  1367.             $headClass = 'grid-title';
  1368.             if($type){
  1369.                 if(is_numeric($type)){
  1370.                     $term = get_term_by('id', $type, 'estate-type');
  1371.                     $headText = $term->name;
  1372.                 }else{
  1373.                     $term = get_term_by('slug', $type, 'estate-type');
  1374.                     $headText = $term->name;
  1375.                 }
  1376.             }elseif($post = get_post()){
  1377.                 if($post->post_type=='estate_agent'){
  1378.                     $headText = __('Agent\'s Properties', PGL);
  1379.                     $headClass = 'agent-estate';
  1380.                 }
  1381.  
  1382.             }
  1383.             $htmlOut = <<<HTML
  1384.             <div class="properties">
  1385.                 <div id="property-list" class="{$filterClass}">
  1386.                     <h3 class="{$headClass}">{$headText}</h3>
  1387. HTML;
  1388.             if($show_filter){
  1389.                 $label = __('All', PGL);
  1390.                 $selectHtml = null;
  1391.                 $htmlOut .= <<<HTML
  1392.                     <div class="filter-pro clearfix">
  1393.                         <div class="row">
  1394.                             <div class="col-md-12">
  1395.                                 <div id="able-filter" class="filter-options">
  1396.                                     <a href="javascript:void(0)" data-filter="all" class="filter active">{$label}</a>
  1397. HTML;
  1398.                 if (!empty($taxonomies_list)) {
  1399.                     foreach ($taxonomies_list as $tax) {
  1400.                         $htmlOut .= <<<HTML
  1401. <a class="filter" href="javascript:void(0)" data-filter="{$tax->slug}">{$tax->name}</a>
  1402. HTML;
  1403.                         $selectHtml .= <<<HTML
  1404. <option value="{$tax->slug}">{$tax->name}</option>
  1405. HTML;
  1406.                     }
  1407.                 }
  1408.                 $htmlOut .= <<<HTML
  1409.                                 </div>
  1410.                             </div>
  1411.                             <div class="col-sm-12 visible-xs">
  1412.                                 <select class="form-control" id="able-select">
  1413.                                     <option class="active" value="all">{$label}</option>
  1414.                                     {$selectHtml}
  1415.                                 </select>
  1416.                             </div>
  1417.                         </div>
  1418.                     </div>
  1419. HTML;
  1420.             }
  1421.             $htmlOut .= <<<HTML
  1422.                     <div class="row products{$filterOn}" id="able-list">
  1423.                         <div class="col-md-{$item_span} col-sm-6 col-xs-12 grid-sizer"></div>
  1424.                         {$estate_list_html}
  1425.  
  1426.                     </div>
  1427.                     {$htmlJs}
  1428.                     {$pagerHtml}
  1429.                 </div>
  1430.             </div>
  1431. HTML;
  1432.             if ($acs_group) {
  1433.                 reset_query_from_acs();
  1434.             }
  1435.             return $htmlOut;
  1436.         } else {
  1437.             //well, if there's no post, let's add some and comeback
  1438.         }
  1439.     }
  1440.  
  1441.     static function get_estate_thumbnail($id, $size = 'estate-detail-thumbnail', $echo = FALSE)
  1442.     {
  1443.  
  1444.         $thumbnail_id = get_post_meta($id, '_thumbnail_id', TRUE);
  1445.         if ($thumbnail_id) {
  1446.             list($thumbnail_url) = wp_get_attachment_image_src($thumbnail_id, PGL_Image::_size($size));
  1447.         } else {
  1448.             $thumbnail_url = get_post_meta($id, 'estate_featured_video_thumbnail_url', TRUE);
  1449.             if (!$thumbnail_url)
  1450.                 return '';
  1451.         }
  1452.         $size_info = PGL_Image::size($size);
  1453.         $img = '<img src="' . $thumbnail_url . '"  />';
  1454.         if ($echo) {
  1455.             echo $img;
  1456.         } else {
  1457.  
  1458.             return $img;
  1459.         }
  1460.     }
  1461.  
  1462.     /**
  1463.      * ##############################################
  1464.      * Utility functions
  1465.      * ##############################################
  1466.      */
  1467.     static function format_price($price = '', $price_type = NULL, $for_range = false)
  1468.     {
  1469.         /**
  1470.          * @var PGL_Options $pgl_options
  1471.          */
  1472.         global $pgl_options;
  1473.         $suffix = '';
  1474.         $tsep = $pgl_options->option('estate_thousand_sep');
  1475.         $dsep = $pgl_options->option('estate_decimal_sep');
  1476.         $decs = $pgl_options->option('estate_decimal_num');
  1477.         if(!$pgl_options->option('estate_price_decimal')){
  1478.             $decs = 0;
  1479.         }
  1480.         $pos = $pgl_options->option('estate_currency_placement');
  1481.         if (!$price) {
  1482.             $no_price_text = $pgl_options->option('estate_no_price_text');
  1483.             return apply_filters('estate/format_price/noprice', $no_price_text);
  1484.         } else {
  1485.             $symbol = PGL_Utilities::get_currency_symbol($pgl_options->option('estate_currency'));
  1486.             if (!is_null($price_type) && in_array($price_type, array('sale','rent'))) {
  1487.                 $suffix = '<span class="suffix"> ' . $pgl_options->option("estate_{$price_type}_price_suffix"). '</span>';
  1488.             }
  1489.             $price = number_format((float)$price, $decs, $dsep, $tsep);
  1490.             if($for_range){
  1491.                 return apply_filters('estate/format_price', (($pos == 'before') ? $symbol . ' ' . $price : $price . ' ' . $symbol) . $suffix);
  1492.             }else{
  1493.                 return apply_filters('estate/format_price', (($pos == 'before') ? '<span class="symbol">'. $symbol . '</span> <span class="price-value">' . $price . '</span>' : '<span class="price-value">' . $price . '</span> <span class="symbol">' . $symbol . '</span>') . $suffix);
  1494.             }
  1495.         }
  1496.     }
  1497.  
  1498.     /**
  1499.      * Display core extra fields (area, bathrooms, bedrooms)
  1500.      *
  1501.      * @param string $id
  1502.      *
  1503.      * @internal param string $before_list
  1504.      * @internal param string $after_list
  1505.      *
  1506.      * @return string
  1507.      */
  1508.     static function display_default_fields($id = '', $col = 6)
  1509.     {
  1510.         if (!$id) {
  1511.             $id = get_the_ID();
  1512.         }
  1513.         $html = '';
  1514.         $haveRoom = false;
  1515.         $bathrooms = get_post_meta($id, 'estate_bathrooms', TRUE);
  1516.         $bedrooms = get_post_meta($id, 'estate_bedrooms', TRUE);
  1517.         if($bathrooms || $bedrooms){
  1518.             $haveRoom = true;
  1519.             $html .= '<div class="col-md-'.$col.' col-sm-'.$col.'"><span class="line-top">'.__('Room(s)', PGL).'<span class="pull-right">';
  1520.         }
  1521.         if (is_numeric($bathrooms) && $bathrooms >= 0) $html .= sprintf( _n( '%d bath', '%d baths', $bathrooms, PGL ), $bathrooms );
  1522.         if ($bathrooms && $bedrooms) $html .= ', ';
  1523.         if (is_numeric($bedrooms) && $bedrooms >= 0) $html .= sprintf( _n( '%d bed', '%d beds', $bedrooms, PGL ), $bedrooms );
  1524.         if($haveRoom){
  1525.             $html .= '</span></span></div>';
  1526.         }
  1527.         $area = get_post_meta($id, 'estate_area', TRUE);
  1528.         if (is_numeric($area) && $area >= 0) $html .= '<div class="col-md-'.$col.' col-sm-'.$col.'"><span class="line-top">' . __('Area', PGL) . '<span> ' . self::format_area($area) . '</span></span></div>';
  1529.  
  1530.         $icon_fields = json_decode(get_post_meta($id, 'estate_icon', TRUE), true);
  1531.         if (!empty($icon_fields)) {
  1532.             $tmp = '';
  1533.             foreach (array_keys($icon_fields) as $key) {
  1534.                 $key = explode('_', $key);
  1535.                 $id = array_shift($key);
  1536.                 $title = ucfirst(implode(' ', $key));
  1537.                 $tmp .= '<span class="pull-right more-type"><a href="javascript:void(0)" class="has-tooltip" title="' . $title . '">' . wp_get_attachment_image($id,'PGL_estate-icon') . '</a></span>';
  1538.             }
  1539.             $html .= '<div class="col-md-'.$col.' col-sm-'.$col.'"><span class="line-top">'.__('Characteristics', PGL) . $tmp . '</span></div>';
  1540.         }
  1541.  
  1542.         return apply_filters('estate/list/display_default_field', $html);
  1543.     }
  1544.  
  1545.     static function format_area($area = 0)
  1546.     {
  1547.         global $pgl_options;
  1548.         $unit = $pgl_options->option('estate_area_unit');
  1549.  
  1550.         return apply_filters('estate/format_area', $area .' '. $unit);
  1551.     }
  1552.  
  1553.     static function estate_list($args = array(), $type = false, $pager = FALSE, $the_query = NULL, $acs_group = '')
  1554.     {
  1555.         global $paged;
  1556.         $paged = 1;
  1557.         if ( get_query_var('paged') ) $paged = get_query_var('paged');
  1558.         if ( get_query_var('page') ) $paged = get_query_var('page');
  1559.         global $pgl_options;
  1560.         if (is_null($the_query)) {
  1561.             $defaults = array(
  1562.                 'posts_per_page' => 9,
  1563.                 'post_type' => 'estate',
  1564.                 'meta_query' => array(),
  1565.                 'tax_query' => array()
  1566.             );
  1567.             if(1!=$paged){
  1568.                 $args['paged'] = $paged;
  1569.             }
  1570.             $params = wp_parse_args($args, $defaults);
  1571.             if ($acs_group) {
  1572.                 $the_query = add_acs_query($acs_group, $params);
  1573.             } else
  1574.                 $the_query = new WP_Query($params);
  1575.         }
  1576.         $isShowCase = false;
  1577.         $purpose =  $pgl_options->option('estate_system_type');
  1578.         if($purpose=='showcase'){
  1579.             $isShowCase = true;
  1580.         }
  1581.         $headText = __('Properties', PGL);
  1582.         $headClass = 'grid-title';
  1583.         if($type){
  1584.             if(is_numeric($type)){
  1585.                 $term = get_term_by('id', $type, 'estate-type');
  1586.                 $headText = $term->name;
  1587.             }else{
  1588.                 $term = get_term_by('slug', $type, 'estate-type');
  1589.                 $headText = $term->name;
  1590.             }
  1591.         }elseif($post = get_post()){
  1592.             if($post->post_type=='estate_agent'){
  1593.                 $headText = __('Agent\'s Properties', PGL);
  1594.                 $headClass = 'agent-estate';
  1595.             }
  1596.  
  1597.         }
  1598.         $html = '';
  1599.         if ($the_query->have_posts()) {
  1600.             $html .= <<<HTML
  1601.     <div class="grid_full_width">
  1602.         <div class="row">
  1603.             <div class="products grid_list_product">
  1604.                 <div class="col-md-12"><h3 class="{$headClass}">{$headText}</h3></div>
  1605. HTML;
  1606.             while ($the_query->have_posts()) {
  1607.                 $the_query->the_post();
  1608.                 $status = get_post_meta(get_the_ID(), 'estate_status', TRUE);
  1609.                 $purpose = get_post_meta(get_the_ID(), 'estate_purpose', TRUE);
  1610.                 $purpose_span = '';
  1611.                 $title = get_the_title();
  1612.                 $excerpt = PGL_Addon_Estate::the_excerpt(false);
  1613.                 $link = get_permalink(get_the_ID());
  1614.                 $thumb = PGL_Addon_Estate::get_estate_thumbnail( get_the_ID(), 'estate-respond-thumbnail', false );
  1615.                 $price = PGL_Addon_Estate::format_price( get_post_meta( get_the_ID(), 'estate_price', TRUE ) );
  1616.                 $default_fields = PGL_Addon_Estate::display_default_fields( get_the_ID(), 12 );
  1617.                 $default_fields = apply_filters( 'estate/list/fields', $default_fields );
  1618.                 if(!$isShowCase){
  1619.                     $purpose_span_content = '<span>'.__( 'Purpose', PGL ).'<span>';
  1620.                     $purpose_span_content .= get_post_meta( get_the_ID(), 'estate_purpose', TRUE )=="sale"?__('Sale', PGL):__('Rent', PGL);
  1621.                     $purpose_span_content .= '</span></span>';
  1622.                     $purpose_span .= <<<HTML
  1623.                     <div class="col-md-12 col-sm-12">
  1624.                         {$purpose_span_content}
  1625.                     </div>
  1626. HTML;
  1627.                 }
  1628.                 $status_span = '';
  1629.                 if($status){
  1630.                     $status_span .= '<span class="status">';
  1631.                     $status_span .= ($purpose == 'sale')?__('Sold', PGL):__('Rented', PGL);
  1632.                     $status_span .= '</span>';
  1633.                 }
  1634.                 $types = explode(',',get_the_term_list( get_the_ID(), 'estate-type', '', ',' ));
  1635.                 $typeHtml = '';
  1636.                 $tipHtml = null;
  1637.                 $typeLbl = __( 'Type', PGL );
  1638.                 $typeHtml .= <<<HTML
  1639.                 <div class="col-md-12 col-sm-12">
  1640.                     <span class="line-top">
  1641.                         {$typeLbl}:
  1642.                         <span class="pull-right">
  1643. HTML;
  1644.                             if(count($types)>3){
  1645.                                 for($i=0; $i<3; $i++){
  1646.                                     $typeHtml .= $types[$i];
  1647.                                     if($i<2) $typeHtml .= ', ';
  1648.                                 }
  1649.                                 $count = 0;
  1650.                                 for($i=3; $i<count($types); $i++){
  1651.                                     $count++;
  1652.                                     $tipHtml .= $types[$i];
  1653.                                 }
  1654.                                 $typeHtml .= <<<HTML
  1655. <span class="more-type"><a href="javascript:void(0)" class="type-popover" data-toggle="popover" data-placement="left" data-container="body" data-content='{$tipHtml}' data-html="true">{$count}+</a></span>
  1656. HTML;
  1657.                             }else{
  1658.                                 $typeHtml .= get_the_term_list( get_the_ID(), 'estate-type', '', ', ' );
  1659.                             }
  1660.                             $typeHtml .= <<<HTML
  1661.                         </span>
  1662.                     </span>
  1663.                 </div>
  1664. HTML;
  1665.                 $html .= <<<HTML
  1666.                             <div class="col-md-12 property col-sm-12">
  1667.                                 <div class="product-item">
  1668.                                     <div class="row">
  1669.                                         <div class="table-row">
  1670.                                             <div class="col-md-4 col-sm-4 image-container">
  1671.                                                 <div class="imagewrapper">
  1672.                                                     <a href="{$link}">
  1673.                                                         {$thumb}
  1674.                                                     </a>
  1675.                                                     <div class="label-hanger">
  1676.                                                         <span class="price">{$price}</span>
  1677.                                                         {$status_span}
  1678.                                                     </div>
  1679.                                                 </div>
  1680.                                             </div>
  1681.                                             <div class="col-md-8 col-sm-8 estate-data">
  1682.                                                 <div class="list-right-info">
  1683.                                                     <div class="row">
  1684.                                                         <div class="col-md-6 col-sm-7">
  1685.                                                             <h3>
  1686.                                                                 <a href="{$link}">{$title}</a>
  1687.                                                             </h3>
  1688.                                                             <p class="excerpt">{$excerpt}</p>
  1689.                                                         </div>
  1690.                                                         <div class="col-md-6 col-sm-5">
  1691.                                                             <div class="title-info row">
  1692.                                                                 {$purpose_span}
  1693.                                                                 {$typeHtml}
  1694.                                                                 {$default_fields}
  1695.                                                             </div>
  1696.                                                         </div>
  1697.                                                     </div>
  1698.                                                 </div>
  1699.                                             </div>
  1700.                                         </div>
  1701.                                     </div>
  1702.                                 </div>
  1703.                             </div>
  1704. HTML;
  1705.                         }
  1706.                         if ($acs_group) {
  1707.                             reset_query_from_acs();
  1708.                         }
  1709.                     }
  1710. $html .= <<<HTML
  1711.             </div>
  1712.         </div>
  1713.     </div>
  1714.         <script type="text/javascript">
  1715.         jQuery(function($){
  1716.             $('.type-popover').popover({html:true})
  1717.         });
  1718.         </script>
  1719. HTML;
  1720.         $pagerHtml = '';
  1721.         if ($pager) {
  1722.             $pagination_links = PGL_pagination(array(
  1723.                 'next_text' => '<i class="fa fa-angle-right"></i>',
  1724.                 'prev_text' => '<i class="fa fa-angle-left"></i>',
  1725.             ), $the_query);
  1726.  
  1727.             if ($pagination_links) {
  1728.                 $pagerHtml .= <<<HTML
  1729.                 <div class="page-ination onleft">
  1730.                     <div class="page-in">
  1731.                         <ul class="pager">
  1732. HTML;
  1733.                 foreach ($pagination_links as $link){
  1734.                     $pagerHtml .= <<<HTML
  1735. <li>{$link}</li>
  1736. HTML;
  1737.  
  1738.                 }
  1739.                 $pagerHtml .= <<<HTML
  1740.                         </ul>
  1741.                     </div>
  1742.                 </div>
  1743. HTML;
  1744.             }
  1745.  
  1746.         }
  1747.         $html .= $pagerHtml;
  1748.         return $html;
  1749.     }
  1750.  
  1751.     /**
  1752.      * Display the excerpt for estate custom post type
  1753.      */
  1754.     static function the_excerpt($echo = TRUE)
  1755.     {
  1756.         $excerpt = apply_filters('estate_the_excerpt', get_the_excerpt());
  1757.         if ($echo) {
  1758.             echo esc_html($excerpt);
  1759.  
  1760.             return '';
  1761.         } else
  1762.             return $excerpt;
  1763.     }
  1764.  
  1765.     static function estate_search_shortcode($atts)
  1766.     {
  1767.         ob_start();
  1768.         self::estate_search();
  1769.         $result = ob_get_clean();
  1770.         return $result;
  1771.     }
  1772.     static function cord_cal($post_id = null){
  1773.         $post_id = ($post_id) ? $post_id : get_the_ID();
  1774.         $ray = false;
  1775.         $cord = get_post_meta($post_id, 'estate_coordinates', TRUE);
  1776.         if($cord){
  1777.             $cord = explode(',', $cord);
  1778.         }
  1779.         if(count($cord)==2){
  1780.             $ray = array(
  1781.                 'id' => $post_id,
  1782.                 'title' => get_the_title($post_id),
  1783.                 'img' => get_the_post_thumbnail($post_id, 'PGL_estate-grid-view-3-column-thumbnail'),
  1784.                 'url' => esc_url( apply_filters( 'the_permalink', get_permalink($post_id) ) ),
  1785.                 'lat'=> $cord[0],
  1786.                 'lng'=> $cord[1]
  1787.             );
  1788.             return $ray;
  1789.         }
  1790.         return $ray;
  1791.     }
  1792.     static function estate_search()
  1793.     {
  1794.         global $pgl_options;
  1795.         $isMapOn = $pgl_options->option('estate_search_map');
  1796.         $map_js = null;
  1797.         if ($isMapOn) {
  1798.             wp_register_script('google-map', '//maps.googleapis.com/maps/api/js?sensor=false', array('jquery'), '3.0', false);
  1799.             wp_enqueue_script('google-map');
  1800.             $json = array();
  1801.             $json['err'] = false;
  1802.             $latlong = array(51.511214, -0.126160);
  1803.             $latlongCfg = $pgl_options->option('estate_search_latlong');
  1804.             $zoomCfg = $pgl_options->option('estate_search_zoom')?$pgl_options->option('estate_search_zoom'):14;
  1805.             if($latlongCfg )
  1806.             $latlong = explode(';',$latlongCfg);
  1807.             if(is_search()){
  1808.                 if(have_posts()){
  1809.                     $found = false;
  1810.                     while(have_posts()){
  1811.                         the_post();
  1812.                         $ray = self::cord_cal(get_the_ID());
  1813.                         if($ray){
  1814.                             if(!$found && $ray['lat']){
  1815.                                 $latlong = array($ray['lat'],$ray['lng']);
  1816.                                 $found = true;
  1817.                             }
  1818.                             $json['posts'][] = $ray;
  1819.                         }
  1820.                     }
  1821.  
  1822.                 }
  1823.             }else{
  1824.                 $posts = get_posts(array(
  1825.                     'offset' => 0,
  1826.                     'post_type' => 'estate',
  1827.                     'nopaging'  => 1
  1828.                 ));
  1829.                 if ($posts) {
  1830.                     foreach ($posts as $post) {
  1831.                         $ray = self::cord_cal($post->ID);
  1832.                         if($ray)
  1833.                             $json['posts'][] = $ray;
  1834.                     }
  1835.                 }
  1836.             }
  1837.             $json = json_encode($json);
  1838.             $map_js = <<<HTML
  1839. <script type="text/javascript">
  1840.   function initialize() {
  1841.     var mapOptions = {
  1842.       center: new google.maps.LatLng({$latlong[0]}, {$latlong[1]}),
  1843.       zoom: {$zoomCfg},
  1844.       scrollwheel: 0,
  1845.       mapTypeId: google.maps.MapTypeId.ROADMAP,
  1846.       panControl: false,
  1847.       zoomControlOptions: {
  1848.         style: google.maps.ZoomControlStyle.SMALL
  1849.       }
  1850.     };
  1851.     var map = new google.maps.Map(document.getElementById("search-map-canvas"),
  1852.         mapOptions);
  1853.     var json = {$json};
  1854.     var activeWin;
  1855.     if(json.posts){
  1856.         jQuery.each(json.posts, function(key, data){
  1857.             var latLng = new google.maps.LatLng(data.lat, data.lng);
  1858.             var marker = new google.maps.Marker({
  1859.                 map: map,
  1860.                 position: latLng,
  1861.                 title: data.title
  1862.             });
  1863.             var infWin = new google.maps.InfoWindow({
  1864.                 content: createWin(data),
  1865.                 maxWidth: 300
  1866.             });
  1867.             google.maps.event.addListener(marker,"click",function(){
  1868.                 if(activeWin)
  1869.                     activeWin.close();
  1870.                 infWin.open(map, marker);
  1871.                 activeWin = infWin;
  1872.             });
  1873.         });
  1874.     }
  1875.     function createWin(data){
  1876.         lo = '<a class="info-link" href="'+data.url+'" title="'+data.title+'">'; lc = '</a>'
  1877.         html = '<div style="width:300px; height:200px">'+lo+data.img+lc+'</div>';
  1878.         html += lo+data.title+lc;
  1879.         return html;
  1880.     }
  1881.   }
  1882.   jQuery(document).ready(function($){
  1883.     google.maps.event.addDomListener(window, 'load', initialize);
  1884.   });
  1885. </script>
  1886. HTML;
  1887.  
  1888.         }
  1889.         $terms_1 = get_terms('estate-type'); //search by category
  1890.         $term1_html = '';
  1891.         if (!empty($terms_1)) {
  1892.             $s_term = isset($_GET['term']) ? $_GET['term'] : '';
  1893.             foreach ($terms_1 as $term) {
  1894.                 $term1_html .= '<option value="' . $term->slug . '" ' . ($term->slug == $s_term ? 'selected' : '') . '>' . $term->name . '</option>';
  1895.             }
  1896.         }
  1897.         $term_2 = get_terms('estate-location'); //search by location
  1898.         $term2_html = '';
  1899.         if (!empty($term_2)) {
  1900.             $s_term = isset($_GET['location']) ? $_GET['location'] : '';
  1901.             foreach ($term_2 as $term) {
  1902.                 $term2_html .= '<option value="' . $term->slug . '" ' . ($term->slug == $s_term ? 'selected' : '') . '>' . $term->name . '</option>';
  1903.             }
  1904.         }
  1905.         ?>
  1906.         <div class="search-container<?php if($isMapOn){?> map-on<?php }else{?> map-off<?php }?> clearfix">
  1907.         <?php if($isMapOn):?>
  1908.         <div id="search-map-canvas"></div>
  1909.         <?php endif;?>
  1910.         <?php $sType = $pgl_options->option('estate_system_type'); ?>
  1911.         <?php $purpose = isset($_GET['purpose']) && $_GET['purpose'] ? trim($_GET['purpose']) : 'sale';?>
  1912.         <div id="findtabber" class="find tabberlive">
  1913.             <div class="container">
  1914.                 <ul class="nav nav-tabs tabbernav">
  1915.                     <?php if($sType == 'both' || $sType == 'sale'):?>
  1916.                     <li<?php if($purpose == 'sale' || $sType == 'sale'):?> class="active"<?php endif;?>>
  1917.                         <a href="#sale" data-toggle="tab">
  1918.                             <?php _e('For sale', PGL); ?>
  1919.                         </a>
  1920.                     </li>
  1921.                     <?php endif;?>
  1922.                     <?php if($sType == 'both' || $sType == 'rental'):?>
  1923.                     <li<?php if($purpose == 'rent' || $sType == 'rental'):?> class="active"<?php endif;?>>
  1924.                         <a href="#rent" data-toggle="tab">
  1925.                             <?php _e('For rent', PGL); ?>
  1926.                         </a>
  1927.                     </li>
  1928.                     <?php elseif($sType=='showcase'):?>
  1929.                     <li class="active">
  1930.                         <a href="#showcase" data-toggle="tab">
  1931.                             <?php _e('Search for estate', PGL); ?>
  1932.                         </a>
  1933.                     </li>
  1934.                     <?php endif;?>
  1935.                 </ul>
  1936.                 <div class="tab-content">
  1937.                         <?php if ($sType == 'both' || $sType == 'sale'): ?>
  1938.                         <div class="tab-pane<?php if($purpose == 'sale' || $sType == 'sale'):?> active<?php endif;?>" id="sale">
  1939.                             <div class="row">
  1940.                                 <form action="<?php echo get_home_url() ?>">
  1941.                                     <input type="hidden" name="s" />
  1942.                                     <input type="hidden" name="purpose" value="sale" />
  1943.                                     <input type="hidden" name="search" value="1" />
  1944.                                     <input type="hidden" name="post_type" value="estate" />
  1945.                                     <?php
  1946.                                     $sale_html_array = array();
  1947.                                     if ($term2_html) {
  1948.                                         $label = __('Select location', PGL);
  1949.                                         $sale_html_array[] .= <<<HTML
  1950.     <div class="col-md-3 col-sm-3">
  1951.     <select name="location" class="form-control">
  1952.         <option value="" selected>{$label}</option>
  1953.         {$term2_html}
  1954.     </select>
  1955.     </div>
  1956. HTML;
  1957.                                     }
  1958.  
  1959.                                     do_action('estate/search_field/before_default_fields_listing');
  1960.                                     $price_range['from'] = $pgl_options->option('estate_searchable_field_sale_price_from');
  1961.                                     $price_range['to'] = $pgl_options->option('estate_searchable_field_sale_price_to');
  1962.                                     if (!empty($price_range)) {
  1963.                                         $label = array( 'from' => __('Price from', PGL), 'to' => __('Price to', PGL));
  1964.                                         $col_class = (!empty($price_range['from'])&&!empty($price_range['to']))?'two-fields':'one-field';
  1965.                                         $html = '<div class="col-md-3 col-sm-3 '.$col_class.'">';
  1966.                                         foreach($price_range as $k => $value){
  1967.                                             if(!empty($value)):
  1968.                                                 $html .= '<select name="price_'.$k.'" class="form-control price-range price-'.$k.'">';
  1969.                                                 $prices = explode(';', $value);
  1970.                                                 $price_query = isset($_GET['price_'.$k]) ? $_GET['price_'.$k] : null;
  1971.                                                 if($price_query){
  1972.                                                     $html .= '<option value="">'.$label[$k].'</option>';
  1973.                                                 }else{
  1974.                                                     $html .= '<option value="" selected>'.$label[$k].'</option>';
  1975.                                                 }
  1976.                                                 foreach ($prices as $price) {
  1977.                                                     if ($price) {
  1978.                                                         $html .= '<option value="' . ($price) . '" ' . ($price == $price_query ? 'selected' : '') . '>' . PGL_Addon_Estate::format_price($price, null, true) . '</option>';
  1979.                                                     }
  1980.                                                 }
  1981.                                                 $html .= '</select>';
  1982.                                             endif;
  1983.                                         }
  1984.                                         $html .= '</div>';
  1985.                                         $sale_html_array[] = $html;
  1986.                                     }
  1987.  
  1988.                                     $searchable_fields = $pgl_options->option('estate_searchable_fields');
  1989.                                     if (!empty($searchable_fields)) {
  1990.                                         $sale_html_array = array_merge($sale_html_array, self::display_default_search_fields($searchable_fields, FALSE));
  1991.                                     }
  1992.  
  1993.                                     $sale_html_array = apply_filters('estate/search_field/after_default_fields_listing', $sale_html_array, 'search_form');
  1994.  
  1995.                                     if ($term1_html) {
  1996.                                         $label = __('Select type', PGL);
  1997.                                         $sale_html_array[] = <<<HTML
  1998.     <div class="col-md-3 col-sm-3">
  1999.     <select name="term" class="form-control">
  2000.         <option value="" selected>{$label}</option>
  2001.         {$term1_html}
  2002.     </select>
  2003.     </div>
  2004. HTML;
  2005.                                     }
  2006.                                     $label = __('Search', PGL);
  2007.                                     $sale_html_array[] = <<<HTML
  2008.     <div class="col-md-3 col-sm-3 col-xs-12 pull-right">
  2009.     <button class="search" type="submit" id="searchsubmit">{$label}</button>
  2010.     </div>
  2011. HTML;
  2012.                                     foreach ($sale_html_array as $part) {
  2013.                                         echo $part;
  2014.                                     }
  2015.                                     ?>
  2016.                                 </form>
  2017.                             </div>
  2018.                         </div>
  2019.                         <?php endif; ?>
  2020.                         <?php if ($sType == 'both' || $sType == 'rental'): ?>
  2021.                             <!-- Rent purpose -->
  2022.                             <div class="tab-pane<?php if($purpose == 'rent' || $sType == 'rental'):?> active<?php endif;?>" id="rent">
  2023.                                 <div class="row">
  2024.                                 <form action="<?php echo get_home_url() ?>">
  2025.                                     <input type="hidden" name="s" />
  2026.                                     <input type="hidden" name="purpose" value="rent" />
  2027.                                     <input type="hidden" name="search" value="1" />
  2028.                                     <input type="hidden" name="post_type" value="estate" />
  2029.                                     <?php
  2030.                                     $rent_html_array = array();
  2031.                                     if ($term2_html) {
  2032.                                         $label = __('Select location', PGL);
  2033.                                         $rent_html_array[] .= <<<HTML
  2034. <div class="col-md-3 col-sm-3">
  2035.     <select name="location" class="form-control">
  2036.         <option value="" selected>{$label}</option>
  2037.         {$term2_html}
  2038.     </select>
  2039. </div>
  2040. HTML;
  2041.                                     }
  2042.                                     ?>
  2043.                                     <?php
  2044.                                     do_action('estate/search_field/before_default_fields_listing');
  2045.                                     $price_range['from'] = $pgl_options->option('estate_searchable_field_rent_price_from');
  2046.                                     $price_range['to'] = $pgl_options->option('estate_searchable_field_rent_price_to');
  2047.                                     if (!empty($price_range)) {
  2048.                                         $label = array( 'from' => __('Price from', PGL), 'to' => __('Price to', PGL));
  2049.                                         $col_class = (!empty($price_range['from'])&&!empty($price_range['to']))?'two-fields':'one-field';
  2050.                                         $html = '<div class="col-md-3 col-sm-3 '.$col_class.'">';
  2051.                                         foreach($price_range as $k => $value){
  2052.                                             if(!empty($value)):
  2053.                                                 $html .= '<select name="price_'.$k.'" class="form-control price-range price-'.$k.'">';
  2054.                                                 $prices = explode(';', $value);
  2055.                                                 $price_query = isset($_GET['price_'.$k]) ? $_GET['price_'.$k] : null;
  2056.                                                 if($price_query){
  2057.                                                     $html .= '<option value="">'.$label[$k].'</option>';
  2058.                                                 }else{
  2059.                                                     $html .= '<option value="" selected>'.$label[$k].'</option>';
  2060.                                                 }
  2061.                                                 foreach ($prices as $price) {
  2062.                                                     if ($price) {
  2063.                                                         $html .= '<option value="' . ($price) . '" ' . ($price == $price_query ? 'selected' : '') . '>' . PGL_Addon_Estate::format_price($price) . '</option>';
  2064.                                                     }
  2065.                                                 }
  2066.                                                 $html .= '</select>';
  2067.                                             endif;
  2068.                                         }
  2069.                                         $html .= '</div>';
  2070.                                         $rent_html_array[] = $html;
  2071.                                     }
  2072.                                     $searchable_fields = $pgl_options->option('estate_searchable_fields');
  2073.                                     if (!empty($searchable_fields)) {
  2074.                                         $rent_html_array = array_merge($rent_html_array, self::display_default_search_fields($searchable_fields, FALSE));
  2075.                                     }
  2076.  
  2077.                                     $rent_html_array = apply_filters('estate/search_field/after_default_fields_listing', $rent_html_array, 'search_form');
  2078.  
  2079.                                     if ($term1_html) {
  2080.                                         $label = __('Select type', PGL);
  2081.                                         $rent_html_array[] = <<<HTML
  2082. <div class="col-md-3 col-sm-3">
  2083.     <select name="term" class="form-control">
  2084.         <option value="" selected>{$label}</option>
  2085.         {$term1_html}
  2086.     </select>
  2087. </div>
  2088. HTML;
  2089.                                     }
  2090.                                     $label = __('Search', PGL);
  2091.                                     $rent_html_array[] = <<<HTML
  2092. <div class="col-md-3 col-sm-3 col-xs-12 pull-right">
  2093.     <button class="search" type="submit" id="searchsubmit">{$label}</button>
  2094. </div>
  2095. HTML;
  2096.                                     foreach ($rent_html_array as $part) {
  2097.                                         echo $part;
  2098.                                     }
  2099.                                     ?>
  2100.                                 </form>
  2101.                                 </div>
  2102.                             </div>
  2103.                         <?php
  2104.                         endif;
  2105.                         ?>
  2106.                         <?php if ($sType == 'showcase'): ?>
  2107.                             <!-- Showcase purpose -->
  2108.                             <div class="tab-pane active">
  2109.                                 <div class="row">
  2110.                                 <form action="<?php echo get_home_url() ?>">
  2111.                                     <input type="hidden" name="s" />
  2112.                                     <input type="hidden" name="search" value="1" />
  2113.                                     <input type="hidden" name="post_type" value="estate" />
  2114.                                     <?php
  2115.                                     $rent_html_array = array();
  2116.                                     if ($term2_html) {
  2117.                                         $label = __('Select location', PGL);
  2118.                                         $rent_html_array[] .= <<<HTML
  2119. <div class="col-md-3 col-sm-3">
  2120.     <select name="location" id="term2" class="form-control">
  2121.         <option value="" selected>{$label}</option>
  2122.         {$term2_html}
  2123.     </select>
  2124. </div>
  2125. HTML;
  2126.                                     }
  2127.                                     ?>
  2128.                                     <?php
  2129.                                     do_action('estate/search_field/before_default_fields_listing');
  2130.                                     $price_value = $pgl_options->option('estate_searchable_field_rent_price');
  2131.                                     if (!empty($price_value)) {
  2132.                                         $prices = explode(';', $price_value);
  2133.                                         $html_price_from = $html_price_to = '';
  2134.                                         $price_from = isset($_GET['price_from']) ? $_GET['price_from'] : '';
  2135.  
  2136.                                         foreach ($prices as $price) {
  2137.                                             if ($price) {
  2138.                                                 $html_price_from .= '<option value="' . ($price) . '" ' . ($price == $price_from ? 'selected' : '') . '>' . PGL_Addon_Estate::format_price($price) . '</option>';
  2139.                                             }
  2140.                                         }
  2141.                                         $label = __('Price from', PGL);
  2142.                                         $rent_html_array[] = <<<HTML
  2143. <div class="col-md-3 col-sm-3">
  2144.     <select name="price_from" class="form-control">
  2145.         <option value="" selected>{$label}</option>
  2146.         {$html_price_from}
  2147.     </select>
  2148. </div>
  2149. HTML;
  2150.                                     }
  2151.  
  2152.                                     $searchable_fields = $pgl_options->option('estate_searchable_fields');
  2153.                                     if (!empty($searchable_fields)) {
  2154.                                         $rent_html_array = array_merge($rent_html_array, self::display_default_search_fields($searchable_fields, FALSE));
  2155.                                     }
  2156.  
  2157.                                     $rent_html_array = apply_filters('estate/search_field/after_default_fields_listing', $rent_html_array, 'search_form');
  2158.  
  2159.                                     if ($term1_html) {
  2160.                                         $label = __('Select type', PGL);
  2161.                                         $rent_html_array[] = <<<HTML
  2162. <div class="col-md-3 col-sm-3">
  2163.     <select name="term" class="form-control">
  2164.         <option value="" selected>{$label}</option>
  2165.         {$term1_html}
  2166.     </select>
  2167. </div>
  2168. HTML;
  2169.                                     }
  2170.                                     $label = __('Search', PGL);
  2171.                                     $rent_html_array[] = <<<HTML
  2172. <div class="col-md-3 col-sm-3 col-xs-12 pull-right">
  2173.     <button class="search" type="submit" id="searchsubmit">{$label}</button>
  2174. </div>
  2175. HTML;
  2176.                                     foreach ($rent_html_array as $part) {
  2177.                                         echo $part;
  2178.                                     }
  2179.                                     ?>
  2180.                                 </form>
  2181.                                 </div>
  2182.                             </div>
  2183.                         <?php
  2184.                         endif;
  2185.                         ?>
  2186.                 </div>
  2187.             </div>
  2188.         </div>
  2189.         <?php echo $map_js ?>
  2190.         </div>
  2191.     <?php
  2192.     }
  2193.  
  2194.     static function display_default_search_fields($searchable_fields, $echo = TRUE, $span_size = 3, $wrap = TRUE)
  2195.     {
  2196.         global $pgl_options;
  2197.         $return = array();
  2198.         if (isset($searchable_fields['bathrooms'])) {
  2199.             $bathrooms_search_values = $pgl_options->option('estate_searchable_field_bathrooms');
  2200.             if (!empty($bathrooms_search_values)) {
  2201.                 $values = explode(';', $bathrooms_search_values);
  2202.                 $bathrooms_value_from = isset($_GET['bathrooms_from']) ? $_GET['bathrooms_from'] : '';
  2203.                 $bathroom_html_from = '';
  2204.  
  2205.                 foreach ($values as $v) {
  2206.                     if ($v) {
  2207.                         $bathroom_html_from .= '<option value="' . ($v) . '" ' . ($bathrooms_value_from == $v ? 'selected' : '') . '>' . $v . '</option>';
  2208.                     }
  2209.                 }
  2210.                 $return[] = ($wrap ? '<div class="col-md-' . $span_size . ' col-sm-'.$span_size.'">' : '') . '
  2211.                         <select name="bathrooms_from" id="bathrooms_from" class="form-control">
  2212.                             <option value="" selected>' . __('Bathrooms from', PGL) . '</option>
  2213.                             ' . $bathroom_html_from . '
  2214.                         </select>
  2215.                 ' . ($wrap ? '</div>' : '');
  2216.             }
  2217.         }
  2218.  
  2219.         if (isset($searchable_fields['bedrooms'])) {
  2220.             $bedrooms_search_values = $pgl_options->option('estate_searchable_field_bedrooms');
  2221.             if (!empty($bedrooms_search_values)) {
  2222.                 $values = explode(';', $bedrooms_search_values);
  2223.                 $bedrooms_value_from = isset($_GET['bedrooms_from']) ? $_GET['bedrooms_from'] : '';
  2224.                 $bedrooms_html_from = '';
  2225.  
  2226.                 foreach ($values as $v) {
  2227.                     if ($v) {
  2228.                         $bedrooms_html_from .= '<option value="' . ($v) . '" ' . ($bedrooms_value_from == $v ? 'selected' : '') . '>' . $v . '</option>';
  2229.                     }
  2230.                 }
  2231.                 $return[] = ($wrap ? '<div class="col-md-' . $span_size . ' col-sm-'.$span_size.'">' : '') . '
  2232.                         <select name="bedrooms_from" id="bedrooms_from" class="form-control">
  2233.                             <option value="" selected>' . __('Bedrooms from', PGL) . '</option>
  2234.                             ' . $bedrooms_html_from . '
  2235.                         </select>
  2236.                 ' . ($wrap ? '</div>' : '');
  2237.             }
  2238.         }
  2239.  
  2240.         if (isset($searchable_fields['area'])) {
  2241.             $area_search_values = $pgl_options->option('estate_searchable_field_area');
  2242.             if (!empty($area_search_values)) {
  2243.                 $values = explode(';', $area_search_values);
  2244.                 $area_value_from = isset($_GET['area_from']) ? $_GET['area_from'] : '';
  2245.                 $area_html_from = '';
  2246.  
  2247.                 foreach ($values as $v) {
  2248.                     if ($v) {
  2249.                         $area_html_from .= '<option value="' . ($v) . '" ' . ($area_value_from == $v ? 'selected' : '') . '>' . $v . '</option>';
  2250.                     }
  2251.                 }
  2252.                 $return[] = ($wrap ? '<div class="col-md-' . $span_size . ' col-sm-'.$span_size.'">' : '') . '
  2253.                         <select name="area_from" id="area_from" class="form-control">
  2254.                             <option value="" selected>' . __('Area from', PGL) . '</option>
  2255.                             ' . $area_html_from . '
  2256.                         </select>
  2257.                 ' . ($wrap ? '</div>' : '');
  2258.             }
  2259.         }
  2260.  
  2261.         if ($echo) {
  2262.             echo implode('', $return);
  2263.         }
  2264.  
  2265.         return $return;
  2266.     }
  2267.  
  2268.     /**
  2269.      * #############################################
  2270.      * Filter
  2271.      * #############################################
  2272.      */
  2273.     static function __filter_the_excerpt($excerpt)
  2274.     {
  2275.         $len = 20;
  2276.         $num = $len + 1;
  2277.         $temp = explode(' ', $excerpt, $num);
  2278.         if (count($temp) >= $num) {
  2279.             array_pop($temp);
  2280.             $r = implode(' ', $temp);
  2281.  
  2282.             return $r . ' ...';
  2283.         }
  2284.  
  2285.         return implode(' ', $temp);
  2286.     }
  2287.  
  2288.     static function __filter_load_search_template($template)
  2289.     {
  2290.         global $wp_query;
  2291.         $search_template = locate_template('templates/estate-loop/estate-search.php');
  2292.         if ((is_search() && isset($_GET['post_type']) && trim($_GET['post_type']) == 'estate') || (is_post_type_archive('estate') && isset($_GET['search']))) {
  2293.             $wp_query->is_search = TRUE;
  2294.  
  2295.             return $search_template;
  2296.         } else {
  2297.  
  2298.             return $template;
  2299.         }
  2300.     }
  2301.  
  2302.     function add_default_options()
  2303.     {
  2304.         /**
  2305.          * @var PGL_Options $pgl_options
  2306.          */
  2307.         global $pgl_options;
  2308.         if (!$pgl_options->option('estate_list_layout')) {
  2309.             $pgl_options->set_option('estate_list_layout', 'estate-loop-default');
  2310.             $pgl_options->set_option('estate_search_layout', 'estate-loop-default');
  2311.             $pgl_options->set_option('estate_single_layout', 'estate-single-default');
  2312.             $pgl_options->set_option('estate_currency', 'USD');
  2313.             $pgl_options->set_option('estate_currency_placement', 'before');
  2314.             $pgl_options->set_option('number_of_estate', '5');
  2315.             $pgl_options->set_option('estate_searchable_fields', array(
  2316.                 'bathrooms' => '1',
  2317.                 'bedrooms' => '1',
  2318.                 'area' => '1'
  2319.             ));
  2320.             $pgl_options->set_option('estate_extra_fields', array(
  2321.                 'bathrooms' => '1',
  2322.                 'bedrooms' => '1',
  2323.                 'area' => '1'
  2324.             ));
  2325.         }
  2326.     }
  2327.     static function estate_horizontal_slide_shortcode($atts)
  2328.     {
  2329.         extract(shortcode_atts(array(
  2330.             'count' => 6,
  2331.             'item_id' => '',
  2332.             'acs' => ''
  2333.         ), $atts));
  2334.         /**
  2335.          * @var int $count
  2336.          * @var string $item_id
  2337.          * @var string $acs
  2338.          */
  2339.         $item_id = strlen($item_id) ? explode(',', $item_id) : array();
  2340.         $query_array = array(
  2341.             'posts_per_page' => $count
  2342.         );
  2343.         if (!empty($item_id)) {
  2344.             $query_array['post__in'] = $item_id;
  2345.         }
  2346.         ob_start();
  2347.         self::estate_horizontal_slider($query_array, $acs);
  2348.         $result = ob_get_clean();
  2349.  
  2350.         return do_shortcode(shortcode_unautop(trim($result)));
  2351.     }
  2352.  
  2353.     static function estate_horizontal_slider($args = array(), $acs_group = '')
  2354.     {
  2355.         $default_array = array(
  2356.             'posts_per_page' => 10,
  2357.             'post_type' => 'estate',
  2358.             'post__in' => array(),
  2359.             'orderby' => 'post__in',
  2360.             'meta_query' => array(
  2361.                 array(
  2362.                     'key' => 'estate_featured',
  2363.                     'value' => 1
  2364.                 )
  2365.             )
  2366.         );
  2367.         $args = wp_parse_args($args, $default_array);
  2368.         $cols = round($args['posts_per_page'] / 5);
  2369.         $page = ($args['posts_per_page']%5 == 0 ? $cols : $cols+1);
  2370.         $colClass = 12/$page;
  2371.         $acs_enable = FALSE;
  2372.         if ($acs_group) {
  2373.             global $acs;
  2374.             if (!is_null($acs) && get_class($acs) == 'Acs') {
  2375.                 $acs_enable = TRUE;
  2376.             }
  2377.         }
  2378.  
  2379.         if ($acs_enable) {
  2380.             $tmpa = array('group_name' => $acs_group);
  2381.             $acs->query_posts(array_merge($tmpa, $args));
  2382.             global $wp_query;
  2383.             $the_query = $wp_query;
  2384.         } else {
  2385.             $the_query = new WP_Query($args);
  2386.         }
  2387.         if ($the_query->have_posts()) {
  2388.             wp_enqueue_script('jquery-nicescroll', PGL_URI_JS . 'nicescroll/jquery.nicescroll.js', array(
  2389.                 'jquery'
  2390.             ), '3.2.0', TRUE);
  2391.             ?>
  2392.             <div class="properties">
  2393.                 <div id="property-scroll" class="container">
  2394.                     <div id="wrapper">
  2395.                         <div class="box<?php echo $page>1 ? ' rail-on' : ' rail-off'?>">
  2396.                             <div class="scroll-properties" style="width:<?php echo 100*$page?>%">
  2397.                                 <div class="row">
  2398.                                 <?php
  2399.                                 $i = 1;
  2400.                                 $items_per_big_column = 5;
  2401.                                 $html = '';
  2402.                                 while ($the_query->have_posts()) {
  2403.                                     $the_query->the_post();
  2404.                                     $the_id = get_the_ID();
  2405.                                     $class = 'small';
  2406.                                     if($i%5==1){
  2407.                                         $html.= '<div class="col-md-'.($colClass/2).' col-sm-'.($colClass/2).'">';
  2408.                                         $class = 'big';
  2409.                                     }
  2410.                                     if($class=='small'){
  2411.                                         $sm_class = in_array($i, array(2,3,7,8)) ? ' item-above' : ' item-under';
  2412.                                         $html .= '<div class="col-md-6 col-sm-6'.$sm_class.'">';
  2413.                                     }
  2414.                                     $html .= '<div class="container-'.$class.'">
  2415.                                                 <a href="' . get_permalink($the_id) . '">' . PGL_Template_Tag::the_post_thumbnail($the_id, 'estate-showcase-'.$class.'-thumbnail','', false) . '</a>
  2416.                                                 <article class="text-'.$class.'">
  2417.                                                     <div class="infotexthv">
  2418.                                                         <h3><a href="' . get_permalink($the_id) . '">' . get_the_title($the_id) . '</a></h3>
  2419.                                                         <p>' . PGL_Addon_Estate::the_excerpt(FALSE) . '</p>
  2420.                                                     </div>
  2421.                                                 </article>
  2422.                                             </div>';
  2423.                                     if($class=='small'){
  2424.                                         $html .= '</div>';
  2425.                                     }
  2426.                                     if($i%5==1){
  2427.                                         $html.= '</div>';
  2428.                                         $html.= '<div class="col-md-'.($colClass/2).' col-sm-'.($colClass/2).'">';
  2429.                                         $html.= '<div class="row">';
  2430.                                     }
  2431.                                     if($i%5==0||$i==$the_query->post_count){
  2432.                                         $html.= '</div>';
  2433.                                         $html.= '</div>';
  2434.                                     }
  2435.                                     $i++;
  2436.                                 }
  2437.                                 echo $html;
  2438.                                 ?>
  2439.                                 </div>
  2440.                             </div>
  2441.                         </div>
  2442.                     </div>
  2443.                 </div>
  2444.             </div>
  2445.             <?php if($page>1):?>
  2446.             <script type="text/javascript">
  2447.                 jQuery(function ($) {
  2448.                     var horScroll = $('.scroll-properties').first();
  2449.                     var addSpace = <?php echo $page*($page*5)?>;
  2450.                     horScroll.css({'width':horScroll.parent().outerWidth()*<?php echo $page?>+addSpace});
  2451.                     var scrollbar_color = $('.realestate-logo a').first().css('background-color');
  2452.                     jQuery('.box').niceScroll(".scroll-properties",{
  2453.                         autohidemode      : false,
  2454.                         scrollspeed       : 100,
  2455.                         cursorcolor       : scrollbar_color,
  2456.                         cursorwidth       : '15px',
  2457.                         cursorborderradius: '0px',
  2458.                         cursorborder      : '0',
  2459.                         background        : '#dddddd',
  2460.                         railpadding:{top:0,right:0,left:0,bottom:40}
  2461.                     });
  2462.                     $(window).resize(function(){
  2463.                         horScroll.css({'width':horScroll.parent().outerWidth()*<?php echo $page?>+addSpace});
  2464.                         horScroll.getNiceScroll().resize();
  2465.                     });
  2466.                 });
  2467.             </script>
  2468.             <?php endif;?>
  2469.             <?php
  2470.             if ($acs_enable) {
  2471.                 wp_reset_query();
  2472.             }
  2473.         }
  2474.     }
  2475.  
  2476.     static function estate_shortcode($atts)
  2477.     {
  2478.         extract(shortcode_atts(array(
  2479.             'id' => '',
  2480.             'display' => 'normal'
  2481.         ), $atts));
  2482.         /**
  2483.          * @var string $id
  2484.          */
  2485.         if (!$id) {
  2486.             return '';
  2487.         }
  2488.         $estate = get_post($id);
  2489.         if (!$estate) {
  2490.  
  2491.             return '';
  2492.         }
  2493.         global $post;
  2494.         $post = $estate;
  2495.         setup_postdata($post);
  2496.         ob_start();
  2497.         ?>
  2498.         <div class="estate-single">
  2499.             <div class="imagewrapper">
  2500.                 <a href="<?php the_permalink(); ?>"><?php
  2501.                     PGL_Addon_Estate::get_estate_thumbnail(get_the_ID(), 'estate-list-view-thumbnail', TRUE) ?></a>
  2502.                 <span class="price"><?php
  2503.                     echo PGL_Addon_Estate::format_price(get_post_meta(get_the_ID(), 'estate_price', TRUE)); ?></span>
  2504.             </div>
  2505.         </div>
  2506.         <?php
  2507.         $html = ob_get_clean();
  2508.         wp_reset_postdata();
  2509.         return $html;
  2510.     }
  2511. }
  2512.  
  2513. function add_acs_query($acs_group, $args = array())
  2514. {
  2515.     global $acs;
  2516.     if (!is_null($acs) && get_class($acs) == 'Acs') {
  2517.         $tmp = array('group_name' => $acs_group);
  2518.         $acs->query_posts(array_merge($tmp, $args));
  2519.         global $wp_query;
  2520.         return $wp_query;
  2521.     }
  2522. }
  2523.  
  2524. function reset_query_from_acs()
  2525. {
  2526.     wp_reset_query();
  2527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement