コード例 #1
0
ファイル: polygon.php プロジェクト: lytranuit/wordpress
    public static function polygon($listings = array(), $map_args = array(), $marker_args = array())
    {
        $map_args = self::process_defaults($map_args);
        self::make_markers($listings, $marker_args, $map_args);
        extract($map_args, EXTR_SKIP);
        wp_enqueue_script('google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places');
        $polygon_html = '';
        // Doesn't seem to always be an array
        if (!is_array($listings)) {
            $listings = array($listings);
        }
        // Try to retrieve from the cache...
        $cache = new PLS_Cache('Map Polygon');
        if ($polygon_html_cached = $cache->get(array_merge($listings, $map_args, $marker_args))) {
            $polygon_html = $polygon_html_cached;
        }
        if ($polygon_html === '') {
            ob_start();
            ?>

		  <script src="<?php 
            echo trailingslashit(PLS_JS_URL) . 'libs/google-maps/text-overlay.js';
            ?>
"></script>
			<?php 
            echo self::get_lifestyle_controls($map_args);
            ?>
		<?php 
            $polygon_html = ob_get_clean();
            $cache->save($polygon_html);
        }
        return $polygon_html;
    }
コード例 #2
0
ファイル: style-util.php プロジェクト: lytranuit/wordpress
 static function get_options()
 {
     // Cache options
     $cache = new PLS_Cache('Theme PLS Options');
     $cache_args = array();
     if ($options = $cache->get($cache_args)) {
         self::$styles = array_merge(self::$styles, $options);
         return;
     }
     require PLS_Route::locate_blueprint_option('init.php');
     require_if_theme_supports("pls-user-options", PLS_Route::locate_blueprint_option('user.php'));
     require_if_theme_supports("pls-search-options", PLS_Route::locate_blueprint_option('search.php'));
     require_if_theme_supports("pls-color-options", PLS_Route::locate_blueprint_option('colors.php'));
     require_if_theme_supports("pls-slideshow-options", PLS_Route::locate_blueprint_option('slideshow.php'));
     require_if_theme_supports("pls-typography-options", PLS_Route::locate_blueprint_option('typography.php'));
     require_if_theme_supports("pls-header-options", PLS_Route::locate_blueprint_option('header.php'));
     require_if_theme_supports("pls-navigation-options", PLS_Route::locate_blueprint_option('navigation.php'));
     require_if_theme_supports("pls-listing-options", PLS_Route::locate_blueprint_option('listings.php'));
     require_if_theme_supports("pls-post-options", PLS_Route::locate_blueprint_option('post.php'));
     require_if_theme_supports("pls-widget-options", PLS_Route::locate_blueprint_option('widget.php'));
     require_if_theme_supports("pls-footer-options", PLS_Route::locate_blueprint_option('footer.php'));
     require_if_theme_supports("pls-css-options", PLS_Route::locate_blueprint_option('css.php'));
     // Cache options
     $cache->save(self::$styles);
 }
コード例 #3
0
ファイル: caching.php プロジェクト: lytranuit/wordpress
 public static function widget_cache_redirected_callback()
 {
     global $wp_registered_widgets;
     $params = func_get_args();
     // get all the passed params
     $id = array_pop($params);
     // take off the widget ID
     $params['widget_class'] = __CLASS__;
     $params['cache_url'] = $_SERVER['REQUEST_URI'];
     // Cache per page
     $cache = new PLS_Cache('Widget');
     if ('GET' === $_SERVER['REQUEST_METHOD'] && ($html = $cache->get($params))) {
         // Cache hit -- return the HTML...
         echo $html;
     } else {
         // Cache miss -- render the HTML...
         $callback = $wp_registered_widgets[$id]['callback_wc_redirect'];
         // find the real callback
         // Just in case the callback isn't callable...
         if (!is_callable($callback)) {
             return;
         }
         // Let the widget render itself into an output buffer
         // Cache it & echo the rendered HTML
         ob_start();
         call_user_func_array($callback, $params);
         $html = ob_get_clean();
         $cache->save($html, PLS_Cache::TTL_LOW);
         echo $html;
     }
 }
コード例 #4
0
 public static function shuffle_bricks($args = array())
 {
     // Check for existence of plugin and not go forward if it is not here
     if (pls_has_plugin_error()) {
         return array();
     }
     // process default args
     $args = self::process_defaults($args);
     //cache the whole html snippet if we can.
     $cache = new PLS_Cache('brick');
     if ($result = $cache->get($args)) {
         // return $result;
     }
     extract($args, EXTR_SKIP);
     // Merge standard types with the keys of the standard CPTs to get a consolidated list of standard brick types...
     $CPT_types = array_keys(self::$standard_CPTs);
     $types = array_merge(self::$standard_types, $CPT_types);
     // Remove excluded types from standard types to get a list of permissible brick types...
     $brick_types = array_diff($types, $excluded_types);
     // Construct bricks
     $bricks = array();
     foreach ($brick_types as $supported_type) {
         $bricks_to_add = array();
         switch ($supported_type) {
             case 'posts':
                 $bricks_to_add = self::get_brick_posts($post_options, $post_limit);
                 break;
             case 'listings':
                 $bricks_to_add = self::get_brick_listings($listing_params, $featured_option_id);
                 break;
             default:
                 // Check to see if type is a supported CPT...
                 if (array_key_exists($supported_type, self::$standard_CPTs)) {
                     // Fetch CPT's bricks via passing in its config...
                     $config = self::$standard_CPTs[$supported_type];
                     $bricks_to_add = self::get_bricks_CPT($config);
                 }
         }
         // Add bricks if necessary...
         if (!empty($bricks_to_add)) {
             $bricks = array_merge($bricks, $bricks_to_add);
         }
     }
     // Shuffle'em
     shuffle($bricks);
     return $bricks;
 }
コード例 #5
0
ファイル: twitter.php プロジェクト: lytranuit/wordpress
function get_twitter_feed($username, $count)
{
    $cache = new PLS_Cache('fb_feed');
    if ($result = $cache->get($username)) {
        return $result;
    }
    if (empty($username)) {
        return;
    }
    $name_count = strlen($username);
    $twitter_feed = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=' . $username;
    $feed = fetch_feed($twitter_feed);
    if (!is_wp_error($feed)) {
        // Checks that the object is created correctly
        if ($feed->get_items() != null) {
            $items = $feed->get_items();
        } else {
            break;
        }
        $twitter_feed_html = "";
        foreach ($feed->get_items() as $key => $item) {
            // Get title value hash
            $full_title = $item->get_title();
            $date = $item->get_date('Y-m-d');
            $date_object = new DateTime($date);
            $month = $date_object->format('M');
            $day = $date_object->format('j');
            $year = $date_object->format('Y');
            // $hour = date('g', $date);
            // $minute = date('i', $date);
            // $am_pm = date('a', $date);
            $date_string = '<p class="tweet-date"><span class="tweet-month">' . $month . '</span> <span class="tweet-day">' . $day . '</span> <span class="tweet-day">' . $year . '</span></p>';
            // <p class="tweet-time"><span class="tweet-hour">'.$hour.'</span>:<span class="tweet-minute">'.$minute.'</span> <span class="tweet-am-pm">'.$am_pm.'</span></p>';
            // Remove "gvinter" from the twitter feed
            $title = substr($full_title, $name_count + 2);
            // The Regular Expression filter
            $reg_exUrl = "/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/";
            // Check if there is a url in the text
            if (preg_match($reg_exUrl, $title, $url)) {
                // make the urls hyper links
                $filtered_title = preg_replace($reg_exUrl, '<a href="' . $url[0] . '" rel="nofollow" target="_blank">' . $url[0] . '</a>', $title);
            } else {
                // if no urls in the text just return the text
                $filtered_title = $title;
            }
            $twitter_feed_html = $twitter_feed_html . '<div class="single-tweet"><p class="tweet-content">' . $filtered_title . '</p>' . '<div class="tweet-date-wrapper">' . $date_string . '</div></div>';
            if ($key >= $count - 1) {
                break;
            }
        }
        //endforeach
        return $twitter_feed_html;
    }
}
コード例 #6
0
ファイル: maps-util.php プロジェクト: lytranuit/wordpress
    private static function get_area_selectors($map_args = array())
    {
        $cache = new PLS_Cache('form');
        if ($result = $cache->get($map_args)) {
            return $result;
        }
        $response = array();
        $form_options = array();
        $form_options['locality'] = array_merge(array('false' => '---'), PLS_Plugin_API::get_location_list('locality'));
        $form_options['region'] = array_merge(array('false' => '---'), PLS_Plugin_API::get_location_list('region'));
        $form_options['postal'] = array_merge(array('false' => '---'), PLS_Plugin_API::get_location_list('postal'));
        $form_options['neighborhood'] = array_merge(array('false' => '---'), PLS_Plugin_API::get_location_list('neighborhood'));
        $response['location'] = '<div class="location_select"><select name="location" class="location" style="width: 140px">
				<option value="locality">City</option>
				<option value="region">State</option>
				<option value="postal">Zip</option>
				<option value="neighborhood">Neighborhood</option>
			</select></div>';
        $response['locality'] = '<div class="location_select_wrapper" style="display: none">' . pls_h('select', array('name' => 'location[locality]', 'class' => 'locality'), pls_h_options($form_options['locality'], wp_kses_post(@$_POST['location']['locality']), true)) . '</div>';
        $response['region'] = '<div class="location_select_wrapper" style="display: none">' . pls_h('select', array('name' => 'location[region]', 'class' => 'region'), pls_h_options($form_options['region'], wp_kses_post(@$_POST['location']['region']), true)) . '</div>';
        $response['postal'] = '<div class="location_select_wrapper" style="display: none">' . pls_h('select', array('name' => 'location[postal]', 'class' => 'postal'), pls_h_options($form_options['postal'], wp_kses_post(@$_POST['location']['postal']), true)) . '</div>';
        $response['neighborhood'] = '<div class="location_select_wrapper" style="display: none">' . pls_h('select', array('name' => 'location[neighborhood]', 'class' => 'neighborhood'), pls_h_options($form_options['neighborhood'], wp_kses_post(@$_POST['location']['neighborhood']), true)) . '</div>';
        if ($map_args['lifestyle_distance'] == 'miles') {
            $response['radius'] = '<div class="location_select"><select name="radius" class="radius" style="width: 140px">
											<option value="402">1/4 mile</option>
											<option value="804">1/2 mile</option>
											<option value="1207">3/4 mile</option>
											<option value="1609">1 mile</option>
											<option value="4828" selected>3 miles</option>
											<option value="8046">5 miles</option>
											<option value="16093">10 miles</option>
										</select></div>';
        } else {
            $response['radius'] = '<div class="location_select"><select name="radius" class="radius" style="width: 140px">
											<option value="200">200 meters</option>
											<option value="500">500 meters</option>
											<option value="1000">1000 meters</option>
											<option value="2000">2000 meters</option>
											<option value="5000" selected>5000 meters</option>
											<option value="10000">10000 meters</option>
											<option value="20000">20000 meters</option>
										</select></div>';
        }
        $cache->save($response);
        return $response;
    }
コード例 #7
0
ファイル: facebook.php プロジェクト: lytranuit/wordpress
function get_facebook_feed($page_id, $limit, $post_types = array())
{
    $cache = new PLS_Cache('fb_feed');
    if ($result = $cache->get($page_id)) {
        return $result;
    }
    // Obtain App Access Token
    $app_id = "263914027073402";
    $app_secret = "3f864423935f5531bb3119ea8ed59147";
    $app_token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&client_secret=" . $app_secret . "&grant_type=client_credentials";
    $result = wp_remote_get($app_token_url);
    if (!is_array($result) || !isset($result['body']) || !$result['body']) {
        return;
    }
    $response = $result['body'];
    $params = null;
    parse_str($response, $params);
    // How to get a link to the app
    //$graph_url = "https://graph.facebook.com/app?access_token=" . $params['access_token'];
    //$app_details = json_decode(file_get_contents($graph_url), true);
    // how to get feed from Jeff Lobb's site
    // echo 'https://graph.facebook.com/68088808263/feed?access_token='.$params['access_token'];
    // remove feed to be able to pass params
    // echo 'https://graph.facebook.com/68088808263?access_token='.$params['access_token'].'&fields=posts.limit(2)';
    $limit = $limit + 5;
    $query = 'https://graph.facebook.com/' . $page_id . '?access_token=' . $params['access_token'] . '&fields=posts.limit(' . $limit . ').fields(message,caption,timeline_visibility,source,picture,description,name,type,link)';
    $content = wp_remote_get($query);
    if (!is_array($content) || !isset($content['body']) || !$content['body']) {
        return;
    }
    $feed = json_decode($content['body'], true);
    // remove posts that don't have a message, picture, caption, name, or source
    foreach ($feed['posts']['data'] as $key => $value) {
        if (!isset($feed['posts']['data'][$key]['message']) && !isset($feed['posts']['data'][$key]['picture']) && !isset($feed['posts']['data'][$key]['caption']) && !isset($feed['posts']['data'][$key]['name']) && !isset($feed['posts']['data'][$key]['source'])) {
            unset($feed['posts']['data'][$key]);
        }
    }
    // reset posts array keys
    $feed['posts']['data'] = array_values($feed['posts']['data']);
    // how many posts are available after unsetting empty ones?
    $count = count($feed['posts']['data']);
    // declare new var
    $custom_feed['posts']['data'] = array();
    // reset actual limit set by admin
    $real_limit = $limit - 5;
    for ($j = 0; $j < $real_limit; $j++) {
        array_push($custom_feed['posts']['data'], $feed['posts']['data'][$j]);
    }
    $cache->save($custom_feed);
    return $custom_feed;
}
コード例 #8
0
ファイル: routing-util.php プロジェクト: lytranuit/wordpress
 public static function router($template_names, $load = false, $require_once = true, $include_vars = false, $cache_type = self::CACHE_NONE)
 {
     // error_log("Templates: " . var_export($template_names, true) . "\n");
     // Try to locate the template file to use in order of those that appear in the 'template_names' array...
     $located = self::locate_blueprint_template($template_names);
     // error_log("Template found/selected: {$located}\n");
     if ($load && !empty($located)) {
         // Capture/cache rendered HTML of GET requests...
         $cache_on = $cache_type === self::CACHE_PER_PAGE && $_SERVER['REQUEST_METHOD'] === 'GET';
         // error_log("method: {$_SERVER['REQUEST_METHOD']}");
         // error_log("cache_type: {$cache_type}");
         // error_log("Will cache: " . ($cache_on ? "YES" : "NO") . "\n");
         if ($cache_on) {
             $cache = new PLS_Cache('Template');
             $cache_args = array('template' => $located, 'uri' => trailingslashit($_SERVER['REQUEST_URI']));
             // error_log(var_export($cache_args, true));
             if ($result = $cache->get($cache_args)) {
                 // error_log("[[Router cache hit!]] Returning rendered HTML for : {$located}\n");
                 echo $result;
                 return;
             }
             // Cache miss, so buffer the rendered template so it can be cached...
             ob_start();
         }
         load_template($located, $require_once);
         // Capture/cache rendered HTML unless we're in debug mode
         if ($cache_on) {
             $result = ob_get_clean();
             $cache->save($result);
             echo $result;
         }
     } elseif ($include_vars) {
         ob_start();
         extract($include_vars);
         load_template($located, $require_once);
         echo ob_get_clean();
     }
     return $located;
 }
コード例 #9
0
ファイル: taxonomy.php プロジェクト: lytranuit/wordpress
 public static function get($args = array())
 {
     $cache = new PLS_Cache('nbh');
     if ($result = $cache->get($args)) {
         return $result;
     }
     extract(self::process_args($args), EXTR_SKIP);
     $subject = array();
     if ($street) {
         $subject += array('taxonomy' => 'street', 'term' => $street, 'api_field' => 'address');
     } elseif ($neighborhood) {
         $subject += array('taxonomy' => 'neighborhood', 'term' => $neighborhood, 'api_field' => 'neighborhood');
     } elseif ($zip) {
         $subject += array('taxonomy' => 'zip', 'term' => $zip, 'api_field' => 'postal');
     } elseif ($city) {
         $subject += array('taxonomy' => 'city', 'term' => $city, 'api_field' => 'locality');
     } elseif ($state) {
         $subject += array('taxonomy' => 'state', 'term' => $state, 'api_field' => 'region');
     }
     $term = get_term_by('slug', $subject['term'], $subject['taxonomy'], ARRAY_A);
     $custom_data = array();
     foreach (self::$custom_meta as $meta) {
         $custom_data[$meta['id']] = get_tax_meta($term['term_id'], $meta['id']);
     }
     $term = wp_parse_args($term, $custom_data);
     $term['api_field'] = $subject['api_field'];
     //if there's a polygon, use that to get listings. Otherwise, use the name of the neighborhood
     $polygon = PLS_Plugin_API::get_taxonomies_by_slug($subject['term']);
     if (is_array($polygon) && !empty($polygon[0])) {
         $polygon[0]['neighborhood_polygons'] = $polygon[0]['name'];
         $listings_raw = PLS_Plugin_API::get_polygon_listings($polygon[0]);
         $term['listings'] = PLS_Partials::get_listings("limit=5&context=home&neighborhood_polygons=" . $polygon[0]['name']);
     } else {
         $listings_raw = PLS_Plugin_API::get_listings("location[" . $term['api_field'] . "]=" . $term['name']);
         $term['listings'] = PLS_Partials::get_listings("limit=5&context=home&request_params=location[" . $term['api_field'] . "]=" . $term['name']);
     }
     $term['areas'] = array('locality' => array(), 'postal' => array(), 'neighborhood' => array(), 'address' => array());
     $locality_tree = array('city' => array('postal', 'neighborhood', 'address'), 'zip' => array('neighborhood', 'address'), 'neighborhood' => array('address'), 'street' => array());
     $term['listings_raw'] = $listings_raw['listings'];
     //assemble all the photos
     $api_translations = array('locality' => 'city', 'neighborhood' => 'neighborhood', 'postal' => 'zip', 'address' => 'street');
     $term['listing_photos'] = array();
     $count = 0;
     if (isset($listings_raw['listings'])) {
         foreach ($listings_raw['listings'] as $key => $listing) {
             if (!empty($listing['images'])) {
                 foreach ($listing['images'] as $image) {
                     if ($count > $image_limit) {
                         break;
                     }
                     $term['listing_photos'][] = array('full_address' => $listing['location']['full_address'], 'image_url' => $image['url'], 'listing_url' => $listing['cur_data']['url']);
                     $count++;
                 }
             }
             if (isset($locality_tree[$subject['taxonomy']])) {
                 foreach ($locality_tree[$subject['taxonomy']] as $locality) {
                     $link = array('name' => $listing['location'][$locality], 'permalink' => get_term_link($listing['location'][$locality], $api_translations[$locality]));
                     if (is_string($link['permalink'])) {
                         $term['areas'][$locality][] = $link;
                     }
                 }
             }
         }
     }
     $term['polygon'] = PLS_Plugin_API::get_polygon_detail(array('tax' => $term['api_field'], 'slug' => $subject['term']));
     $cache->save($term);
     return $term;
 }
コード例 #10
0
ファイル: get-listings.php プロジェクト: lytranuit/wordpress
    /**
     * Returns a list of properties listed formated in a default html.
     *
     * This function takes the raw properties data returned by the plugin and
     * formats wrapps it in html. The returned html is filterable in multiple
     * ways.
     *
     * The defaults are as follows:
     *     'width' - Default 100. The listing image width. If set to 0,
     *          width is not added.
     *     'height' - Default false. The listing image height. If set to 0,
     *          width is not added.
     *     'placeholder_img' - Defaults to placeholder image. The path to the
     *          listing image that should be use if the listing has no images.
     *     'context' - An execution context for the function. Used when the
     *          filters are created.
     *     'context_var' - Any variable that needs to be passed to the filters
     *          when function is executed.
     *     'limit' - Default is 5. Total number of listings to retrieve. Maximum
     *          set to 50.
     * Defines the following filters:
     * pls_listings_request[_context] - Filters the request parameters.
     * pls_listing[_context] - Filters the individual listing html.
     * pls_listings[_context] - Filters the complete listings list html.
     *
     * @static
     * @param array|string $args Optional. Overrides defaults.
     * @return string The html with the list of properties.
     * @since 0.0.1
     */
    public static function init($args = '')
    {
        $cache = new PLS_Cache('list');
        if ($result = $cache->get($args)) {
            // return $result;
        }
        /** Define the default argument array. */
        $defaults = array('width' => 100, 'height' => 0, 'context' => '', 'context_var' => false, 'featured_option_id' => false, 'limit' => 5, 'sort_type' => 'asc', 'request_params' => '', 'neighborhood_polygons' => false);
        /** Merge the arguments with the defaults. */
        $args = wp_parse_args($args, $defaults);
        /** Extract the arguments after they merged with the defaults. */
        extract($args, EXTR_SKIP);
        // Sanitize the width
        if ($width) {
            $width = absint($width);
        }
        /** Sanitize the height. */
        if ($height) {
            $height = absint($height);
        }
        $request_params = wp_parse_args($args, array('limit' => $limit, 'sort_type' => $sort_type));
        // Filter the request parameters
        $request_params = apply_filters(pls_get_merged_strings(array('pls_listings_request', $context), '_', 'pre', false), $request_params, $context_var);
        // Start off with a placeholder in case the plugin is not active or there is no API key...
        $listings_raw = PLS_Listing_Helper::$default_listing;
        // If plugin is active, grab listings intelligently...
        if (!pls_has_plugin_error()) {
            $listings_raw = false;
            if ($featured_option_id) {
                $listings_raw = PLS_Listing_Helper::get_featured($featured_option_id, $args);
            }
            if ($neighborhood_polygons) {
                $listings_raw = PLS_Plugin_API::get_polygon_listings(array('neighborhood_polygons' => $neighborhood_polygons));
            }
            if ($listings_raw === false || isset($listings_raw['listings']) && empty($listings_raw['listings'])) {
                $listings_raw = PLS_Plugin_API::get_listings($request_params);
            }
        }
        /** Define variable which will contain the html string with the listings. */
        $return = '';
        /** Set the listing image attributes. */
        $listing_img_attr = array();
        if ($width) {
            $listing_img_attr['width'] = $width;
        }
        if ($height) {
            $listing_img_attr['height'] = $height;
        }
        /** Collect the html for each listing. */
        $listings_html = array();
        // filter listings before output
        if (isset($featured_listing_id)) {
            $listings_raw = apply_filters($context . '_partial_get_listings', $listings_raw, $featured_listing_id);
        }
        // For repeated use in the loop...
        $listing_cache = new PLS_Cache('Listing');
        // Curate the listing_data...
        foreach ($listings_raw['listings'] as $listing_data) {
            // Ignore featured listings without images
            if (!empty($args['featured_option_id']) && empty($listing_data['images'])) {
                continue;
            }
            $listing_html = '';
            $cache_id = array('context' => $context, 'featured_option_id' => $featured_option_id, 'listing_id' => $listing_data['id']);
            if ($cached_listing_html = $listing_cache->get($cache_id)) {
                $listing_html = $cached_listing_html;
            }
            if (empty($listing_html)) {
                // Use the placeholder image if the property has no photo
                if (!$listing_data['images']) {
                    $listing_data['images'][0]['url'] = '';
                    $listing_data['images'][0]['order'] = 0;
                }
                // Remove the ID for each image (not needed by theme developers) and add the image HTML
                foreach ($listing_data['images'] as $image) {
                    unset($image['id']);
                    $image['html'] = pls_h_img($image['url'], $listing_data['location']['address'], $listing_img_attr);
                }
                $location = $listing_data['location'];
                $full_address = $location['address'] . ' ' . $location['region'] . ', ' . $location['locality'] . ' ' . $location['postal'];
                ob_start();
                ?>
                <div class="listing-item grid_8 alpha" itemscope itemtype="http://schema.org/Offer">

                  <div class="listing-thumbnail grid_3 alpha">
                    <a href="<?php 
                echo @$listing_data['cur_data']['url'];
                ?>
">

                      <?php 
                $property_images = is_array($listing_data['images']) ? $listing_data['images'] : array();
                usort($property_images, array(__CLASS__, 'order_listing_images'));
                ?>
                      
                      <?php 
                echo PLS_Image::load($property_images[0]['url'], array('resize' => array('w' => 210, 'h' => 140), 'fancybox' => true, 'as_html' => true, 'html' => array('alt' => $listing_data['location']['full_address'], 'itemprop' => 'image')));
                ?>
                    

                    </a>
                  </div>

                  <div class="listing-item-details grid_5 omega">
                    <p class="listing-item-address h4" itemprop="name">
                      <a href="<?php 
                echo PLS_Plugin_API::get_property_url($listing_data['id']);
                ?>
" rel="bookmark" title="<?php 
                echo $listing_data['location']['address'];
                ?>
" itemprop="url">
                        <?php 
                echo $listing_data['location']['address'] . ', ' . $listing_data['location']['locality'] . ' ' . $listing_data['location']['region'] . ' ' . $listing_data['location']['postal'];
                ?>
                      </a>
                    </p>

                    <div class="basic-details">
                      <ul>
                        <?php 
                if (!empty($listing_data['cur_data']['beds'])) {
                    ?>
                          <li class="basic-details-beds p1"><span>Beds:</span> <?php 
                    echo @$listing_data['cur_data']['beds'];
                    ?>
</li>
                        <?php 
                }
                ?>

                        <?php 
                if (!empty($listing_data['cur_data']['baths'])) {
                    ?>
                          <li class="basic-details-baths p1"><span>Baths:</span> <?php 
                    echo @$listing_data['cur_data']['baths'];
                    ?>
</li>
                        <?php 
                }
                ?>

                        <?php 
                if (!empty($listing_data['cur_data']['half_baths'])) {
                    ?>
                          <li class="basic-details-half-baths p1"><span>Half Baths:</span> <?php 
                    echo @$listing_data['cur_data']['half_baths'];
                    ?>
</li>
                        <?php 
                }
                ?>

                        <?php 
                if (!empty($listing_data['cur_data']['price'])) {
                    ?>
                          <li class="basic-details-price p1" itemprop="price"><span>Price:</span> <?php 
                    echo PLS_Format::number($listing_data['cur_data']['price'], array('abbreviate' => false, 'add_currency_sign' => true));
                    ?>
</li>
                        <?php 
                }
                ?>

                        <?php 
                if (!empty($listing_data['cur_data']['sqft'])) {
                    ?>
                          <li class="basic-details-sqft p1"><span>Sqft:</span> <?php 
                    echo PLS_Format::number($listing_data['cur_data']['sqft'], array('abbreviate' => false, 'add_currency_sign' => false));
                    ?>
</li>
                        <?php 
                }
                ?>

                        <?php 
                if (!empty($listing_data['rets']['mls_id'])) {
                    ?>
                          <li class="basic-details-mls p1"><span>MLS ID:</span> <?php 
                    echo @$listing_data['rets']['mls_id'];
                    ?>
</li>
                        <?php 
                }
                ?>
                      </ul>
                    </div>

                    <p class="listing-description p4">
                      <?php 
                echo substr($listing_data['cur_data']['desc'], 0, 300);
                ?>
                    </p>

                  </div>

                  <div class="actions">
                    <a class="more-link" href="<?php 
                echo PLS_Plugin_API::get_property_url($listing_data['id']);
                ?>
" itemprop="url">View Property Details</a>
                    <?php 
                echo PLS_Plugin_API::placester_favorite_link_toggle(array('property_id' => $listing_data['id']));
                ?>
                  </div>

                  <?php 
                PLS_Listing_Helper::get_compliance(array('context' => 'inline_search', 'agent_name' => @$listing_data['rets']['aname'], 'office_name' => @$listing_data['rets']['oname']));
                ?>

                </div>
                <?php 
                // Store the output...
                $listing_html = ob_get_clean();
                // Filter (pls_listing[_context]) the resulting HTML for a single listing
                $listing_html = apply_filters(pls_get_merged_strings(array('pls_listing', $context), '_', 'pre', false), $listing_html, $listing_data, $request_params, $context_var);
                // Cache the result...
                $listing_cache->save($listing_html, PLS_Cache::TTL_LOW);
            }
            // Append the HTML to an array -- this will be passed to the final filter
            $listings_html[] = $listing_html;
            // Merge all the listings HTML
            $return .= $listing_html;
        }
        // Wrap the listings HTML
        $return = pls_h('section', array('class' => "pls-listings pls-listings " . pls_get_merged_strings(array('pls-listing', $context), '-', 'pre', false)), $return);
        // Filter (pls_listings[_context]) the resulting HTML that contains the collection of listings
        $return = apply_filters(pls_get_merged_strings(array('pls_listings', $context), '_', 'pre', false), $return, $listings_raw, $listings_html, $request_params, $context_var);
        $cache->save($return);
        return $return;
    }
コード例 #11
0
    public static function get($args = array())
    {
        // Store this for use in the final output/response...
        $sEcho = isset($_POST['sEcho']) ? $_POST['sEcho'] : 0;
        unset($_POST['sEcho']);
        $context_orig = isset($_POST['context']) ? $_POST['context'] : '';
        unset($_POST['context']);
        // If length is not set for number of listings to return, set it to our Theme Options default
        $_POST['limit'] = isset($_POST['iDisplayLength']) ? $_POST['iDisplayLength'] : pls_get_option('listings_default_list_length');
        unset($_POST['iDisplayLength']);
        $_POST['offset'] = isset($_POST['iDisplayStart']) ? $_POST['iDisplayStart'] : 0;
        unset($_POST['iDisplayStart']);
        $saved_search_lookup = isset($_POST['saved_search_lookup']) ? $_POST['saved_search_lookup'] : null;
        unset($_POST['saved_search_lookup']);
        // Remove this so it doesn't accidentally end up as a superfluous argument of an API call...
        unset($_POST['action']);
        // Handle location edge-case...
        if (!empty($_POST['location']) && !empty($_POST['location']['address']) && empty($_POST['location']['address_match'])) {
            $_POST['location']['address_match'] = 'like';
        }
        // Handle saved search...
        if (!is_null($saved_search_lookup)) {
            // Attempt to retrieve search filters associated with the given saved search lookup ID...
            // NOTE: If no filters exist for the passed ID,
            $filters = PLS_Plugin_API::get_saved_search_filters($saved_search_lookup);
            if (empty($filters) || !is_array($filters)) {
                PLS_Plugin_API::save_search($saved_search_lookup, $_POST);
            } else {
                // For backwards compatibility, handle older fields that are no longer stored as saved search filters...
                $old_field_map = array('sEcho' => false, 'context' => false, 'iDisplayLength' => 'limit', 'iDisplayStart' => 'offset', 'saved_search_lookup' => false, 'action' => false);
                foreach ($old_field_map as $old => $new) {
                    if (isset($filters[$old])) {
                        if ($new !== false) {
                            $filters[$new] = $filters[$old];
                        }
                        unset($filters[$old]);
                    }
                }
                // Swap all existing POST filters for the ones associated with the retrieved saved search...
                $_POST = $filters;
            }
        }
        // Define the default argument array
        $defaults = array('loading_img' => admin_url('images/wpspin_light.gif'), 'image_width' => 100, 'crop_description' => 0, 'sort_type' => pls_get_option('listings_default_sort_type'), 'listings_per_page' => pls_get_option('listings_default_list_length'), 'context' => $context_orig, 'context_var' => NULL, 'append_to_map' => true, 'search_query' => $_POST, 'property_ids' => isset($_POST['property_ids']) ? $_POST['property_ids'] : '', 'allow_id_empty' => false);
        // Resolve function args with default ones (which include any existing POST fields)...
        $merged_args = wp_parse_args($args, $defaults);
        $cache = new PLS_Cache('list');
        if ($cached_response = $cache->get($merged_args)) {
            // This field must match the one passed in with this request...
            $cached_response['sEcho'] = $sEcho;
            echo json_encode($cached_response);
            die;
        }
        // Extract the arguments after they merged with the defaults
        extract($merged_args, EXTR_SKIP);
        // Start off with a placeholder in case the plugin is not active or there is no API key...
        $api_response = PLS_Listing_Helper::$default_listing;
        // If plugin is active, grab listings intelligently...
        if (!pls_has_plugin_error()) {
            // Get the listings list markup and JS
            if (!empty($property_ids) || $allow_id_empty) {
                // Sometimes property_ids are passed in as a flat screen from the JS post object
                if (is_string($property_ids)) {
                    $property_ids = explode(',', $property_ids);
                }
                $api_response = PLS_Plugin_API::get_listing_details(array('property_ids' => $property_ids, 'limit' => $_POST['limit'], 'offset' => $_POST['offset']));
            } elseif (isset($search_query['neighborhood_polygons']) && !empty($search_query['neighborhood_polygons'])) {
                $api_response = PLS_Plugin_API::get_polygon_listings($search_query);
            } else {
                $api_response = PLS_Plugin_API::get_listings($search_query);
            }
        }
        $response = array();
        // Build response for datatables.js
        $listings = array();
        $listings_cache = new PLS_Cache('Listing Thumbnail');
        foreach ($api_response['listings'] as $key => $listing) {
            // Check for cached listing thumbnail...
            $cache_id = array('context' => $context, 'listing_id' => $listing['id']);
            if (!($item_html = $listings_cache->get($cache_id))) {
                // Handle case of zero listing images...
                if (empty($listing['images'])) {
                    $listing['images'][0]['url'] = '';
                }
                ob_start();
                ?>
                    <div class="listing-item grid_8 alpha" itemscope itemtype="http://schema.org/Offer" data-listing="<?php 
                echo $listing['id'];
                ?>
">
                        <div class="listing-thumbnail grid_3 alpha">
                            <?php 
                $property_images = is_array($listing['images']) ? $listing['images'] : array();
                usort($property_images, array(__CLASS__, 'order_images'));
                ?>
                              
                             <a href="<?php 
                echo @$listing['cur_data']['url'];
                ?>
" itemprop="url">
                                <?php 
                echo PLS_Image::load($property_images[0]['url'], array('resize' => array('w' => 210, 'h' => 140), 'fancybox' => true, 'as_html' => true, 'html' => array('alt' => $listing['location']['full_address'], 'itemprop' => 'image', 'placeholder' => PLS_IMG_URL . "/null/listing-300x180.jpg")));
                ?>
                            </a>
                        </div>

                        <div class="listing-item-details grid_5 omega">
                            <header>
                                <p class="listing-item-address h4" itemprop="name">
                                    <a href="<?php 
                echo PLS_Plugin_API::get_property_url($listing['id']);
                ?>
" rel="bookmark" title="<?php 
                echo $listing['location']['address'];
                ?>
" itemprop="url">
                                        <?php 
                echo $listing['location']['address'] . ', ' . $listing['location']['locality'] . ' ' . $listing['location']['region'] . ' ' . $listing['location']['postal'];
                ?>
                                    </a>
                                </p>
                            </header>

                            <div class="basic-details">
                                <ul>
                                  	<?php 
                if (!empty($listing['cur_data']['beds'])) {
                    ?>
                                  		<li class="basic-details-beds p1"><span>Beds:</span> <?php 
                    echo @$listing['cur_data']['beds'];
                    ?>
</li>
                                  	<?php 
                }
                ?>

                                  	<?php 
                if (!empty($listing['cur_data']['baths'])) {
                    ?>
                                  		<li class="basic-details-baths p1"><span>Baths:</span> <?php 
                    echo @$listing['cur_data']['baths'];
                    ?>
</li>
                                  	<?php 
                }
                ?>

                                  	<?php 
                if (!empty($listing['cur_data']['half_baths'])) {
                    ?>
                                  		<li class="basic-details-half-baths p1"><span>Half Baths:</span> <?php 
                    echo @$listing['cur_data']['half_baths'];
                    ?>
</li>
                                  	<?php 
                }
                ?>

                                  	<?php 
                if (!empty($listing['cur_data']['price'])) {
                    ?>
                                  		<li class="basic-details-price p1" itemprop="price"><span>Price:</span> <?php 
                    echo PLS_Format::number($listing['cur_data']['price'], array('abbreviate' => false, 'add_currency_sign' => true));
                    ?>
</li>
                                  	<?php 
                }
                ?>

                                  	<?php 
                if (!empty($listing['cur_data']['sqft'])) {
                    ?>
                                  		<li class="basic-details-sqft p1"><span>Sqft:</span> <?php 
                    echo PLS_Format::number($listing['cur_data']['sqft'], array('abbreviate' => false, 'add_currency_sign' => false));
                    ?>
</li>
                                  	<?php 
                }
                ?>

                                    <?php 
                if (!empty($listing['rets']['mls_id'])) {
                    ?>
                                        <li class="basic-details-mls p1"><span>MLS ID:</span> <?php 
                    echo @$listing['rets']['mls_id'];
                    ?>
</li>
                                    <?php 
                }
                ?>
                                </ul>
                            </div>

                            <p class="listing-description p4" itemprop="description">
                                <?php 
                echo substr($listing['cur_data']['desc'], 0, 300);
                ?>
                            </p>

                        </div>

                        <div class="actions">
                            <a class="more-link" href="<?php 
                echo PLS_Plugin_API::get_property_url($listing['id']);
                ?>
" itemprop="url">View Property Details</a>
                            <?php 
                echo PLS_Plugin_API::placester_favorite_link_toggle(array('property_id' => $listing['id']));
                ?>
                        </div>

                        <?php 
                PLS_Listing_Helper::get_compliance(array('context' => 'inline_search', 'agent_name' => @$listing['rets']['aname'], 'office_name' => @$listing['rets']['oname']));
                ?>
                    </div>
                <?php 
                $item_html = ob_get_clean();
                $item_html = apply_filters(pls_get_merged_strings(array("pls_listings_list_ajax_item_html", $context), '_', 'pre', false), htmlspecialchars_decode($item_html), $listing, $context_var);
                $listings_cache->save($item_html);
            }
            $listings[$key][] = $item_html;
            $listings[$key][] = $listing;
        }
        // Required for datatables.js to function properly...
        $response['sFirst'] = 'Previous';
        $response['sPrevious'] = 'Next';
        $response['sEcho'] = $sEcho;
        $response['aaData'] = $listings;
        $api_total = isset($api_response['total']) ? $api_response['total'] : 0;
        $response['iTotalRecords'] = $api_total;
        $response['iTotalDisplayRecords'] = $api_total;
        $cache->save($response);
        ob_start("ob_gzhandler");
        echo json_encode($response);
        // Wordpress echos out a "0" randomly -- die prevents this...
        die;
    }
コード例 #12
0
ファイル: slideshow.php プロジェクト: lytranuit/wordpress
 /**
  * Slideshow
  * 
  * @param string $args 
  * @param mixed $data 
  * @static
  * @access public
  * @return void
  */
 public static function slideshow($args = '')
 {
     /** Define the default argument array */
     $defaults = array('animation' => 'fade', 'animationSpeed' => 800, 'timer' => true, 'advanceSpeed' => 4000, 'pauseOnHover' => true, 'startClockOnMouseOut' => true, 'startClockOnMouseOutAfter' => 500, 'directionalNav' => true, 'captions' => true, 'captionAnimation' => 'fade', 'captionAnimationSpeed' => 800, 'afterSlideChange' => 'function(){}', 'bullets' => 'false', 'width' => 620, 'height' => 300, 'container_height' => false, 'context' => '', 'context_var' => false, 'featured_option_id' => false, 'allow_user_slides' => false, 'user_slides_header_id' => false, 'listings' => 'limit=5&sort_by=price', 'data' => false, 'post_id' => false, 'post_meta_key' => false, 'fluid' => false);
     $args = wp_parse_args($args, $defaults);
     /** Check cache, return something is there **/
     $cache = new PLS_Cache('slide');
     if ($result = $cache->get($args)) {
         return $result;
     }
     /** Extract all args for easy usage **/
     extract($args, EXTR_SKIP);
     /** If the slideshow data is null or not an array AND the plugin is working, try to fetch the proper data... **/
     if ((!$data || !is_array($data)) && !pls_has_plugin_error()) {
         /** Data assumed to take this form. */
         $data = array('images' => array(), 'links' => array(), 'captions' => array());
         // If the calling theme allows user input, get slideshow config option...
         if ($allow_user_slides && $user_slides_header_id) {
             $slides = pls_get_option($user_slides_header_id, array());
             // Check to see if slides are set to custom, but are empty
             $custom_but_empty = isset($slides[0]) && $slides[0]['type'] == 'custom' && empty($slides[0]['image']);
             // Populate slides when '$custom_but_empty' is true OR when no slides exist...
             if ($custom_but_empty || empty($slides)) {
                 $slides = self::empty_slides_and_add_random_listings();
             }
             foreach ($slides as $index => $slide) {
                 switch ($slide['type']) {
                     case 'listing':
                         unset($slide['html'], $slide['image'], $slide['type'], $slide['link']);
                         // In this case, the slide's remaining key will correspond to it's property ID...
                         $property_id = key($slide);
                         $api_response = PLS_Plugin_API::get_listing_details(array('property_ids' => array($property_id)));
                         if (!empty($api_response['listings']) && $api_response['listings'][0]['id'] === false) {
                             self::$listings_to_delete[] = $property_id;
                         }
                         if ($api_response['total'] == '1') {
                             $listing = $api_response['listings'][0];
                             $first_valid_img_url = null;
                             // Overwrite the placester url with the local url...
                             $listing_url = PLS_Plugin_API::get_property_url($listing['id']);
                             $data['links'][] = $listing_url;
                             // Try to retrieve the image url if order is set...
                             if (is_array($listing['images']) && isset($listing['images'][0]['order'])) {
                                 foreach ($listing['images'] as $key => $image) {
                                     if ($image['order'] == 1) {
                                         $data['images'][$index] = $image['url'];
                                         // break, just in case the listing has more than one '1' in the 'order' param
                                         break;
                                     }
                                     // Record the first valid image URL in case no image has the top order...
                                     if (!isset($first_valid_img_url) && isset($image['url'])) {
                                         $first_valid_img_url = $image['url'];
                                     }
                                 }
                             }
                             // If image still isn't set, use first valid image URL discovered above, or just set to default...
                             if (empty($data['images'][$index])) {
                                 $data['images'][$index] = isset($first_valid_img_url) ? $first_valid_img_url : self::$default_img_url;
                             }
                             $data['type'][] = 'listing';
                             $data['listing'][] = $listing;
                             /** Get the listing caption **/
                             $data['captions'][] = trim(self::render_listing_caption($listing, $index));
                         }
                         break;
                     case 'custom':
                         $is_empty = empty($slide['image']) && empty($slide['link']) && empty($slide['image']) && empty($slide['html']);
                         // Only include a custom slide if it's not entirely empty...
                         if (!$is_empty) {
                             $data['images'][] = $slide['image'];
                             $data['links'][] = $slide['link'];
                             $data['type'][] = 'custom';
                             $data['captions'][] = trim(self::render_custom_caption($slide['html'], $index));
                         }
                         break;
                 }
             }
         } else {
             if (!empty($args['post_id']) && !empty($args['post_meta_key'])) {
                 $api_response = PLS_Listing_Helper::get_featured_from_post($args['post_id'], $args['post_meta_key']);
             } elseif ($featured_option_id) {
                 $api_response = PLS_Listing_Helper::get_featured($featured_option_id);
             }
             if (empty($api_response['listings'])) {
                 $api_response = PLS_Plugin_API::get_listings($listings);
             }
             foreach ($api_response['listings'] as $index => $listing) {
                 if (empty($listing['id'])) {
                     continue;
                 }
                 $listing_url = PLS_Plugin_API::get_property_url($listing['id']);
                 /** Overwrite the placester url with the local url. */
                 $data['links'][] = $listing_url;
                 $data['images'][] = !empty($listing['images']) ? $listing['images'][0]['url'] : self::$default_img_url;
                 $data['listing'][] = $listing;
                 // Get the listing caption
                 $listing_caption = trim(self::render_listing_caption($listing, $index));
                 // Add a filter for a single caption, to be edited via a template
                 $single_caption = apply_filters(pls_get_merged_strings(array('pls_slideshow_single_caption', $context), '_', 'pre', false), $listing_caption, $listing, $context, $context_var, $index);
                 $data['captions'][] = $single_caption;
             }
         }
     }
     /** Filter the data array */
     $data = apply_filters(pls_get_merged_strings(array('pls_slideshow_data', $context), '_', 'pre', false), $data, $context, $context_var);
     /** Create the slideshow */
     $html = array('slides' => '', 'captions' => '');
     if (is_array($data['images'])) {
         foreach ($data['images'] as $index => $slide_src) {
             $extra_attr = array();
             $extra_attr['title'] = '';
             /** Save the caption and the title attribute for the img. */
             if (isset($data['captions'][$index])) {
                 $html['captions'] .= $data['captions'][$index];
                 $extra_attr['title'] = "#caption-{$index}";
             }
             if (isset($data['type'][$index])) {
                 // Get image, but only Dragonfly listing images
                 switch ($data['type'][$index]) {
                     case "listing":
                         $slide_src = PLS_Image::load($slide_src, array('resize' => array('w' => $width, 'h' => $height), 'fancybox' => false, 'as_html' => false));
                         break;
                     case "custom":
                         $slide_src = PLS_Image::load($slide_src, array('allow_resize' => false, 'fancybox' => false, 'as_html' => false));
                         break;
                 }
             }
             /** Create the img element. */
             $slide = pls_h_img($slide_src, false, $extra_attr);
             /** Wrap it in an achor if the anchor exists. */
             if (isset($data['links'][$index])) {
                 $slide = pls_h_a($data['links'][$index], $slide, array('data-caption' => "#caption-{$index}"));
             }
             $html['slides'] .= $slide;
         }
     }
     /** Combine the HTML **/
     $html = pls_h_div($html['slides'], array('id' => 'slider', 'class' => 'orbitSlider')) . $html['captions'];
     /** Filter the HTML array */
     $html = apply_filters(pls_get_merged_strings(array('pls_slideshow_html', $context), '_', 'pre', false), $html, $data, $context, $context_var, $args);
     if (!$container_height) {
         $container_height = $height;
     }
     /** Render the necessary inline CSS... */
     $css_args = array('width' => $width, 'height' => $height, 'container_height' => $container_height);
     $css = self::render_inline_css($css_args);
     /** Render the necessary inline JS... **/
     $args['data'] = is_string($data) ? $data : '';
     // For compatibility...
     $js = self::render_inline_js($args);
     /** Filter inline JS **/
     $js = apply_filters(pls_get_merged_strings(array('pls_slideshow_js', $context), '_', 'pre', false), $js, $html, $data, $context, $context_var);
     /** Filter the final output **/
     $full_slideshow = apply_filters(pls_get_merged_strings(array('pls_slideshow', $context), '_', 'pre', false), $css . $html . $js, $html, $js, $data, $context, $context_var, $args);
     /** Cache rendered slideshow for future retrieval **/
     $cache->save($full_slideshow);
     return $full_slideshow;
 }
コード例 #13
0
 /**
  * Returns a form that can be used to search for listings.
  * 
  * The defaults are as follows:
  *     'ajax' - Default is false. Wether the resulting form should use ajax 
  *          or not. If ajax is set to true, then for the form to work, the 
  *          results container should be defined on the page. 
  *          {@link PLS_Partials::get_listings_list_ajax()} should be used.
  *     'context' - An execution context for the function. Used when the 
  *          filters are created.
  *     'context_var' - Any variable that needs to be passed to the filters 
  *          when function is executed.
  * Defines the following hooks.
  *      pls_listings_search_form_bedrooms_array[_context] - Filters the 
  *          array with the data used to generate the select.
  *      pls_listings_search_form_bathrooms_array[_context]
  *      pls_listings_search_form_available_on_array[_context]
  *      pls_listings_search_form_cities_array[_context]
  *      pls_listings_search_form_min_price_array[_context]
  *      pls_listings_search_form_max_price_array[_context]
  *      
  *      pls_listings_search_form_bedrooms_attributes[_context] - Filters 
  *          the attribute array for the select. If extra attributes need to 
  *          be added to the select element, they should be provided in 
  *          a array( $attribute_key => $attribute_value ) form.
  *      pls_listings_search_form_bathrooms_attributes[_context]
  *      pls_listings_search_form_available_on_attributes[_context]
  *      pls_listings_search_form_cities_attributes[_context]
  *      pls_listings_search_form_min_price_attributes[_context]
  *      pls_listings_search_form_max_price_attributes[_context]
  *      
  *      pls_listings_search_form_bedrooms_html[_context] - Filters the html 
  *          for this option. Can be used to add extra containers.
  *      pls_listings_search_form_bathrooms_html[_context]
  *      pls_listings_search_form_available_on_html[_context]
  *      pls_listings_search_form_cities_html[_context]
  *      pls_listings_search_form_min_price_html[_context]
  *      pls_listings_search_form_max_price_html[_context]
  *      
  *      pls_listings_search_form_submit[_context] - Filters the form submit 
  *          button.
  *
  *      pls_listings_search_form_inner[_context] - Filters the form inner html.
  *      pls_listings_search_form_outer[_context] - Filters the form html.
  *
  * @static
  * @param array $args Optional. Overrides defaults.
  * @return string The html for the listings search form.
  * @since 0.0.1
  */
 public static function init($args = '')
 {
     // Define the default argument array
     $defaults = array('ajax' => false, 'class' => 'pls_search_form_listings', 'context' => '', 'theme_option_id' => '', 'context_var' => null, 'bedrooms' => 1, 'min_beds' => 1, 'max_beds' => 1, 'bathrooms' => 1, 'min_baths' => 1, 'max_baths' => 1, 'price' => 1, 'half_baths' => 1, 'property_type' => 1, 'listing_types' => 1, 'zoning_types' => 1, 'purchase_types' => 1, 'available_on' => 1, 'cities' => 1, 'multi_cities' => 0, 'states' => 1, 'multi_states' => 0, 'zips' => 1, 'neighborhood' => 1, 'multi_neighborhoods' => 0, 'county' => 1, 'min_price' => 1, 'max_price' => 1, 'min_price_rental' => 1, 'max_price_rental' => 1, 'min_price_sales' => 1, 'max_price_sales' => 1, 'neighborhood_polygons' => 0, 'neighborhood_polygons_type' => false, 'min_sqft' => 1, 'max_sqft' => 1, 'include_submit' => true, 'pls_empty_value' => array());
     $args = wp_parse_args($args, $defaults);
     $cache_id = $args;
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $cache_id['$_POST'] = $_POST;
     }
     $cache = new PLS_Cache('Search Form');
     if ($result = $cache->get($cache_id)) {
         return $result;
     }
     $form_options = array();
     // Set Form Defaults for params onload, set in Theme Options
     $form_options['location']['locality'] = pls_get_option('form_default_options_locality');
     $form_options['location']['region'] = pls_get_option('form_default_options_region');
     $form_options['location']['postal'] = pls_get_option('form_default_options_postal');
     $form_options['location']['neighborhood'] = pls_get_option('form_default_options_neighborhood');
     $form_options['location']['county'] = pls_get_option('form_default_options_county');
     $form_options['property_type'] = pls_get_option('form_default_options_property_type');
     $_POST = wp_parse_args($_POST, $form_options);
     //respect user settings, unless they are all empty.
     $user_search_params = pls_get_option($args['theme_option_id']);
     if (isset($user_search_params['hide_all']) && $user_search_params['hide_all'] == 1) {
         return '';
     }
     $args = wp_parse_args($args, $user_search_params);
     /** Extract the arguments after they merged with the defaults. */
     extract(wp_parse_args($args, $defaults), EXTR_SKIP);
     // Set the default empty values for the all the form elements.
     // Dev can change defaults via a filter in process defaults.
     $pls_empty_value = self::process_default_value_array($pls_empty_value, $context);
     /**
      * Elements options arrays. Used to generate the HTML.
      */
     /** Prepend the default empty valued element. */
     $user_beds_start = pls_get_option('pls-option-bed-min');
     $user_beds_end = pls_get_option('pls-option-bed-max');
     if (is_numeric($user_beds_start) && is_numeric($user_beds_end)) {
         $beds_range = range($user_beds_start, $user_beds_end);
         $form_options['bedrooms'] = array('pls_empty_value' => $pls_empty_value['bedrooms']) + array_combine($beds_range, $beds_range);
     } else {
         $form_options['bedrooms'] = array('pls_empty_value' => $pls_empty_value['bedrooms']) + range(0, 16);
     }
     /** Prepend the default empty valued element. */
     $user_baths_start = pls_get_option('pls-option-bath-min');
     $user_baths_end = pls_get_option('pls-option-bath-max');
     if (is_numeric($user_baths_start) && is_numeric($user_baths_end)) {
         $baths_range = range($user_baths_start, $user_baths_end);
         $form_options['bathrooms'] = array('pls_empty_value' => $pls_empty_value['bathrooms']) + array_combine($baths_range, $baths_range);
     } else {
         $form_options['bathrooms'] = array('pls_empty_value' => $pls_empty_value['bathrooms']) + range(0, 10);
     }
     /** Prepend the default empty valued element. */
     $user_half_baths_start = pls_get_option('pls-option-half-bath-min');
     $user_half_baths_end = pls_get_option('pls-option-half-bath-max');
     if (is_numeric($user_half_baths_start) && is_numeric($user_half_baths_end)) {
         $half_bath_range = range($user_half_baths_start, $user_half_baths_end);
         $form_options['half_baths'] = array('pls_empty_value' => $pls_empty_value['half_baths']) + array_combine($half_bath_range, $half_bath_range);
     } else {
         $form_options['half_baths'] = array('pls_empty_value' => $pls_empty_value['half_baths']) + range(0, 10);
     }
     /** Generate an array with the next 12 months. */
     $current_month = (int) date('m');
     for ($i = $current_month; $i < $current_month + 12; $i++) {
         $form_options['available_on'][date('d-m-Y', mktime(0, 0, 0, $i, 1))] = date('F Y', mktime(0, 0, 0, $i, 1));
     }
     /** Get the property type options */
     $get_type_response = PLS_Plugin_API::get_type_list();
     // error_log("GET_TYPE_RESPONSE\n" . serialize($get_type_response) . "\n");
     if (empty($get_type_response)) {
         $form_options['property_type'] = array('pls_empty_value' => $pls_empty_value['property_type']);
     } else {
         // if API serves up 'false' key in the array, remove it, because we're going to add one.
         if (isset($get_type_response['false'])) {
             unset($get_type_response['false']);
         }
         $form_options['property_type'] = array_merge(array('pls_empty_value' => $pls_empty_value['property_type']), $get_type_response);
     }
     /** Get the listing type options. */
     $form_options['listing_types'] = array('pls_empty_value' => $pls_empty_value['listing_types']) + PLS_Plugin_API::get_type_values('listing');
     /** Get the zoning type options. */
     $form_options['zoning_types'] = array('pls_empty_value' => $pls_empty_value['zoning_types']) + PLS_Plugin_API::get_type_values('zoning');
     // removed "All" - it's not giving all listings. jquery needs to change to not include "[]"s
     // $form_options['zoning_types'] = PLS_Plugin_API::get_type_values( 'zoning' ); // for Multiple, not for single, see below
     /** Get the purchase type options. */
     $form_options['purchase_types'] = array('pls_empty_value' => $pls_empty_value['purchase_types']) + PLS_Plugin_API::get_type_values('purchase');
     // removed "All" - it's not giving all listings. jquery needs to change to not include "[]"s
     // $form_options['purchase_types'] = PLS_Plugin_API::get_type_values( 'purchase' );
     /** Prepend the default empty valued element. */
     $form_options['available_on'] = array('pls_empty_value' => $pls_empty_value['available_on']) + $form_options['available_on'];
     /** Prepend the default empty valued element. */
     $locations = PLS_Plugin_API::get_location_list();
     $neighborhood_polygons_options = PLS_Plugin_API::get_location_list_polygons($neighborhood_polygons_type);
     if (empty($locations['locality'])) {
         $form_options['cities'] = array('pls_empty_value' => $pls_empty_value['cities']);
     } else {
         unset($locations['locality']['false']);
         sort($locations['locality']);
         $form_options['cities'] = array('pls_empty_value' => $pls_empty_value['cities']) + $locations['locality'];
     }
     if (empty($locations['region'])) {
         $form_options['states'] = array('pls_empty_value' => $pls_empty_value['states']);
     } else {
         unset($locations['region']['false']);
         sort($locations['region']);
         $form_options['states'] = array('pls_empty_value' => $pls_empty_value['states']) + $locations['region'];
     }
     if (empty($locations['postal'])) {
         $form_options['zips'] = array('pls_empty_value' => $pls_empty_value['zips']);
     } else {
         unset($locations['postal']['false']);
         sort($locations['postal']);
         $form_options['zips'] = array('pls_empty_value' => $pls_empty_value['zips']) + $locations['postal'];
     }
     if (empty($locations['neighborhood'])) {
         $form_options['neighborhood'] = array('pls_empty_value' => $pls_empty_value['neighborhoods']);
     } else {
         unset($locations['neighborhood']['false']);
         sort($locations['neighborhood']);
         $form_options['neighborhood'] = array('pls_empty_value' => $pls_empty_value['neighborhoods']) + $locations['neighborhood'];
     }
     if (empty($locations['county'])) {
         $form_options['county'] = array('pls_empty_value' => $pls_empty_value['county']);
     } else {
         unset($locations['county']['false']);
         sort($locations['county']);
         $form_options['county'] = array('pls_empty_value' => $pls_empty_value['county']) + $locations['county'];
     }
     if (empty($neighborhood_polygons_options)) {
         $form_options['neighborhood_polygons'] = array('pls_empty_value' => $pls_empty_value['neighborhood_polygons']);
     } else {
         unset($neighborhood_polygons_options['false']);
         sort($neighborhood_polygons_options);
         $form_options['neighborhood_polygons'] = array('pls_empty_value' => $pls_empty_value['neighborhood_polygons']) + $neighborhood_polygons_options;
     }
     // Min/Max Sqft
     /** Define the minimum price options array. */
     $form_options['min_sqft'] = array('pls_empty_value' => $pls_empty_value['min_sqft'], '200' => '200', '400' => '400', '600' => '600', '800' => '800', '1000' => '1,000', '1200' => '1,200', '1400' => '1,400', '1600' => '1,600', '1800' => '1,800', '2000' => '2,000', '2200' => '2,200', '2400' => '2,400', '2600' => '2,600', '2800' => '2,800', '3000' => '3,000', '3500' => '3,500', '4000' => '4,000', '4500' => '4,500', '5000' => '5,000', '6000' => '6,000', '7000' => '7,000', '8000' => '8,000');
     $user_start_sqft = pls_get_option('pls-option-sqft-min') ? pls_get_option('pls-option-sqft-min') : 0;
     $user_end_sqft = pls_get_option('pls-option-sqft-max');
     $user_inc_sqft = pls_get_option('pls-option-sqft-inc');
     if (is_numeric($user_start_sqft) && is_numeric($user_end_sqft) && is_numeric($user_inc_sqft)) {
         // Handle when increment is larger than the range from start to end
         if ($user_inc_sqft > $user_end_sqft - $user_start_sqft) {
             $user_inc_sqft = $user_end_sqft - $user_start_sqft;
         }
         $range = range($user_start_sqft, $user_end_sqft, $user_inc_sqft);
         $form_options['min_sqft'] = array();
         foreach ($range as $sqft_value) {
             $form_options['min_sqft'][$sqft_value] = PLS_Format::number($sqft_value, array('abbreviate' => false));
         }
     }
     /** Set the maximum price options array. */
     $form_options['max_sqft'] = $form_options['min_sqft'];
     /* max_sqft default needs to be set too */
     $form_options['max_sqft']['pls_empty_value'] = __($pls_empty_value['max_sqft'], pls_get_textdomain());
     // Price Ranges
     /** Define the minimum price options array. */
     $form_options['min_price'] = array('pls_empty_value' => __($pls_empty_value['min_price'], pls_get_textdomain()), '0' => '$0', '400' => '$400', '500' => '$500', '2000' => '$2,000', '3000' => '$3,000', '4000' => '$4,000', '5000' => '$5,000', '50000' => '$50,000', '100000' => '$100,000', '200000' => '$200,000', '350000' => '$350,000', '400000' => '$400,000', '450000' => '$450,000', '500000' => '$500,000', '600000' => '$600,000', '700000' => '$700,000', '800000' => '$800,000', '900000' => '$900,000', '1000000' => '$1,000,000');
     /* Set the maximum price options array + its default */
     $form_options['max_price'] = $form_options['min_price'];
     $form_options['max_price']['pls_empty_value'] = __($pls_empty_value['max_price'], pls_get_textdomain());
     $user_price_start = pls_get_option('pls-option-price-min') ? pls_get_option('pls-option-price-min') : 0;
     $user_price_end = pls_get_option('pls-option-price-max');
     $user_price_inc = pls_get_option('pls-option-price-inc');
     if (is_numeric($user_price_start) && is_numeric($user_price_end) && is_numeric($user_price_inc)) {
         $range = range($user_price_start, $user_price_end, $user_price_inc);
         // Create empty arrays
         $form_options['min_price'] = array();
         $form_options['max_price'] = array();
         // set empty values
         $form_options['min_price']['pls_empty_value'] = __($pls_empty_value['min_price'], pls_get_textdomain());
         $form_options['max_price']['pls_empty_value'] = __($pls_empty_value['max_price'], pls_get_textdomain());
         foreach ($range as $price_value) {
             $form_options['min_price'][$price_value] = PLS_Format::number($price_value, array('abbreviate' => false));
             $form_options['max_price'][$price_value] = PLS_Format::number($price_value, array('abbreviate' => false));
         }
     }
     // Price for Rentals
     /** Define the minimum price options array. */
     $form_options['min_price_rental'] = array('pls_empty_value' => __($pls_empty_value['min_price_rental'], pls_get_textdomain()), '200' => '$200', '400' => '$400', '600' => '$600', '800' => '$800', '1000' => '$1,000', '1100' => '$1,100', '1200' => '$1,200', '1300' => '$1,300', '1400' => '$1,400', '1500' => '$1,500', '1600' => '$1,600', '1700' => '$1,700', '1800' => '$1,800', '1900' => '$1,900', '2000' => '$2,000', '2100' => '$2,100', '2200' => '$2,200', '2300' => '$2,300', '2400' => '$2,400', '2500' => '$2,500', '2600' => '$2,600', '2700' => '$2,700', '2800' => '$2,800', '2900' => '$2,900', '3000' => '$3,000', '3500' => '$3,500', '4000' => '$4,000', '4500' => '$4,500', '5000' => '$5,000', '6000' => '$6,000', '7000' => '$7,000', '8000' => '$8,000');
     /* Set the maximum price rental options array + its default */
     $form_options['max_price_rental'] = $form_options['min_price_rental'];
     $form_options['max_price_rental']['pls_empty_value'] = __($pls_empty_value['max_price_rental'], pls_get_textdomain());
     $user_price_start_rental = pls_get_option('pls-option-rental-price-min') ? pls_get_option('pls-option-rental-price-min') : 0;
     $user_price_end_rental = pls_get_option('pls-option-rental-price-max');
     $user_price_inc_rental = pls_get_option('pls-option-rental-price-inc');
     if (is_numeric($user_price_start_rental) && is_numeric($user_price_end_rental) && is_numeric($user_price_inc_rental)) {
         // Handle when increment is larger than the range from start to end
         if ($user_price_inc_rental > $user_price_end_rental - $user_price_start_rental) {
             $user_price_inc_rental = $user_price_end_rental - $user_price_start_rental;
         }
         $range = range($user_price_start_rental, $user_price_end_rental, $user_price_inc_rental);
         // Create empty arrays
         $form_options['min_price_rental'] = array();
         $form_options['max_price_rental'] = array();
         // set empty values
         $form_options['min_price_rental']['pls_empty_value'] = __($pls_empty_value['min_price_rental'], pls_get_textdomain());
         $form_options['max_price_rental']['pls_empty_value'] = __($pls_empty_value['max_price_rental'], pls_get_textdomain());
         foreach ($range as $price_value) {
             $form_options['min_price_rental'][$price_value] = PLS_Format::number($price_value, array('abbreviate' => false));
             $form_options['max_price_rental'][$price_value] = PLS_Format::number($price_value, array('abbreviate' => false));
         }
     }
     // Price for Sales
     /** Define the minimum price options array. */
     $form_options['min_price_sales'] = array('pls_empty_value' => __($pls_empty_value['min_price_sales'], pls_get_textdomain()), '20000' => '$20,000', '40000' => '$40,000', '60000' => '$60,000', '80000' => '$80,000', '100000' => '$100,000', '120000' => '$120,000', '140000' => '$140,000', '160000' => '$160,000', '180000' => '$180,000', '200000' => '$200,000', '250000' => '$250,000', '300000' => '$300,000', '350000' => '$350,000', '400000' => '$400,000', '450000' => '$450,000', '500000' => '$500,000', '550000' => '$550,000', '600000' => '$600,000', '650000' => '$650,000', '700000' => '$700,000', '750000' => '$750,000', '800000' => '$800,000', '850000' => '$850,000', '900000' => '$900,000', '950000' => '$950,000', '1000000' => '$1,000,000');
     /* Set the maximum price sales options array + its default */
     $form_options['max_price_sales'] = $form_options['min_price_sales'];
     $form_options['max_price_sales']['pls_empty_value'] = __($pls_empty_value['max_price_sales'], pls_get_textdomain());
     $user_price_start_sales = pls_get_option('pls-option-sales-price-min') ? pls_get_option('pls-option-sales-price-min') : 0;
     $user_price_end_sales = pls_get_option('pls-option-sales-price-max');
     $user_price_inc_sales = pls_get_option('pls-option-sales-price-inc');
     if (is_numeric($user_price_start_sales) && is_numeric($user_price_end_sales) && is_numeric($user_price_inc_sales)) {
         // Handle when increment is larger than the range from start to end
         if ($user_price_inc_sales > $user_price_end_sales - $user_price_start_sales) {
             $user_price_inc_sales = $user_price_end_sales - $user_price_start_sales;
         }
         $range = range($user_price_start_sales, $user_price_end_sales, $user_price_inc_sales);
         // Create empty arrays
         $form_options['min_price_sales'] = array();
         $form_options['max_price_sales'] = array();
         // set empty values
         $form_options['min_price_sales']['pls_empty_value'] = __($pls_empty_value['min_price_sales'], pls_get_textdomain());
         $form_options['max_price_sales']['pls_empty_value'] = __($pls_empty_value['max_price_sales'], pls_get_textdomain());
         foreach ($range as $price_value) {
             $form_options['min_price_sales'][$price_value] = PLS_Format::number($price_value, array('abbreviate' => false));
             $form_options['max_price_sales'][$price_value] = PLS_Format::number($price_value, array('abbreviate' => false));
         }
     }
     // Set min_beds/max_beds form element
     $form_options['min_beds'] = array('pls_empty_value' => __($pls_empty_value['min_beds'], pls_get_textdomain()), '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15');
     $user_bed_start = pls_get_option('pls-option-bed-min') ? pls_get_option('pls-option-bed-min') : 0;
     $user_bed_end = pls_get_option('pls-option-bed-max') ? pls_get_option('pls-option-bed-max') : 15;
     $user_bed_inc = pls_get_option('pls-option-bed-inc') ? pls_get_option('pls-option-bed-inc') : 1;
     if (is_numeric($user_bed_start) && is_numeric($user_bed_end) && is_numeric($user_bed_inc)) {
         $range = range($user_bed_start, $user_bed_end, $user_bed_inc);
         $form_options['min_beds'] = array();
         foreach ($range as $bed_value) {
             $form_options['min_beds'][$bed_value] = $bed_value;
         }
         $form_options['min_beds'] = array('pls_empty_value' => $pls_empty_value['min_beds']) + $form_options['min_beds'];
     }
     /** Set the max beds array too. */
     $form_options['max_beds'] = $form_options['min_beds'];
     // Set min_baths/max_baths form element
     $form_options['min_baths'] = array('pls_empty_value' => __($pls_empty_value['min_baths'], pls_get_textdomain()), '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10');
     $user_bath_start = pls_get_option('pls-option-bath-min') ? pls_get_option('pls-option-bath-min') : 0;
     $user_bath_end = pls_get_option('pls-option-bath-max') ? pls_get_option('pls-option-bath-max') : 10;
     $user_bath_inc = pls_get_option('pls-option-bath-inc') ? pls_get_option('pls-option-bath-inc') : 1;
     if (is_numeric($user_bath_start) && is_numeric($user_bath_end) && is_numeric($user_bath_inc)) {
         $range = range($user_bath_start, $user_bath_end, $user_bath_inc);
         $form_options['min_baths'] = array();
         foreach ($range as $bath_value) {
             $form_options['min_baths'][$bath_value] = $bath_value;
         }
         $form_options['min_baths'] = array('pls_empty_value' => $pls_empty_value['min_baths']) + $form_options['min_baths'];
     }
     /** Set the max baths array too. */
     $form_options['max_baths'] = $form_options['min_baths'];
     /** Define an array for extra attributes. */
     $form_opt_attr = array();
     /** Filter form fields. */
     $form_option_keys = array_keys($form_options);
     $form_options_count = count($form_option_keys);
     // foreach( $form_options as $option_name => &$opt_array ) {
     // replace the foreach with for to provide reference update functionality in the loop
     for ($i = 0; $i < $form_options_count; $i++) {
         $option_name = $form_option_keys[$i];
         $opt_array = $form_options[$option_name];
         /** Filter each of the fields options arrays. */
         $opt_array = apply_filters(pls_get_merged_strings(array("pls_listings_search_form_{$option_name}_array", $context), '_', 'pre', false), $opt_array, $context_var);
         /** Form options array. */
         $form_opt_attr[$option_name] = apply_filters(pls_get_merged_strings(array("pls_listings_search_form_{$option_name}_attributes", $context), '_', 'pre', false), array(), $context_var);
         /** Make sure it is an array. */
         if (!is_array($form_opt_attr[$option_name])) {
             $form_opt_attr[$option_name] = array();
         }
         /** Append the data-placeholder attribute. */
         if (isset($opt_array['pls_empty_value'])) {
             $form_opt_attr[$option_name] = $form_opt_attr[$option_name] + array('data-placeholder' => $opt_array['pls_empty_value']);
         }
         $form_options[$option_name] = $opt_array;
     }
     if (!isset($_POST['metadata'])) {
         $_POST['metadata'] = array();
     }
     /**
      * Elements HTML.
      */
     /** Add the bedrooms select element. */
     if ($bedrooms == 1) {
         $selected_beds = isset($_POST['metadata']['beds']) ? wp_kses_post($_POST['metadata']['beds']) : false;
         $form_html['bedrooms'] = pls_h('select', array('name' => 'metadata[beds]') + $form_opt_attr['bedrooms'], pls_h_options($form_options['bedrooms'], $selected_beds));
     }
     /** Add the bedrooms select element. */
     if ($min_beds == 1) {
         $selected_min_beds = isset($_POST['metadata']['min_beds']) ? $_POST['metadata']['min_beds'] : false;
         $form_html['min_beds'] = pls_h('select', array('name' => 'metadata[min_beds]') + $form_opt_attr['min_beds'], pls_h_options($form_options['min_beds'], $selected_min_beds));
     }
     /** Add the bedrooms select element. */
     if ($max_beds == 1) {
         $selected_max_beds = isset($_POST['metadata']['max_beds']) ? $_POST['metadata']['max_beds'] : false;
         $form_html['max_beds'] = pls_h('select', array('name' => 'metadata[max_beds]') + $form_opt_attr['max_beds'], pls_h_options($form_options['max_beds'], $selected_max_beds));
     }
     /** Add the bathroms select element. */
     if ($bathrooms == 1) {
         $selected_baths = isset($_POST['metadata']['baths']) ? wp_kses_post($_POST['metadata']['baths']) : false;
         $form_html['bathrooms'] = pls_h('select', array('name' => 'metadata[baths]') + $form_opt_attr['bathrooms'], pls_h_options($form_options['bathrooms'], $selected_baths));
     }
     /** Add the min baths select element. */
     if ($min_baths == 1) {
         $selected_min_baths = isset($_POST['metadata']['min_baths']) ? $_POST['metadata']['min_baths'] : false;
         $form_html['min_baths'] = pls_h('select', array('name' => 'metadata[min_baths]') + $form_opt_attr['min_baths'], pls_h_options($form_options['min_baths'], $selected_min_baths));
     }
     /** Add the max baths select element. */
     if ($max_baths == 1) {
         $selected_max_baths = isset($_POST['metadata']['max_baths']) ? $_POST['metadata']['max_baths'] : false;
         $form_html['max_baths'] = pls_h('select', array('name' => 'metadata[max_baths]') + $form_opt_attr['max_baths'], pls_h_options($form_options['max_baths'], $selected_max_baths));
     }
     /** Add the bathroms select element. */
     if ($half_baths == 1) {
         $selected_half_baths = isset($_POST['metadata']['half_baths']) ? wp_kses_post($_POST['metadata']['half_baths']) : false;
         $form_html['half_baths'] = pls_h('select', array('name' => 'metadata[half_baths]') + $form_opt_attr['half_baths'], pls_h_options($form_options['half_baths'], $selected_half_baths));
     }
     /** Add the property type select element. */
     if ($property_type == 1) {
         $selected_property_type = isset($_POST['property_type']) ? wp_kses_post($_POST['property_type']) : false;
         $form_html['property_type'] = pls_h('select', array('name' => 'property_type') + $form_opt_attr['property_type'], pls_h_options($form_options['property_type'], $selected_property_type));
     }
     /** Add the listing type select element. */
     if ($listing_types == 1) {
         $selected_listing_types = isset($_POST['listing_types']) ? wp_kses_post($_POST['listing_types']) : false;
         $form_html['listing_types'] = pls_h('select', array('name' => 'listing_types') + $form_opt_attr['listing_types'], pls_h_options($form_options['listing_types'], $selected_listing_types));
     }
     /** Add the zoning type select element. */
     if ($zoning_types == 1) {
         $selected_zoning_types = isset($_POST['zoning_types']) ? wp_kses_post($_POST['zoning_types']) : false;
         $form_html['zoning_types'] = pls_h('select', array('name' => 'zoning_types[]') + $form_opt_attr['zoning_types'], pls_h_options($form_options['zoning_types'], $selected_zoning_types));
     }
     /** Add the purchase type select element. */
     if ($purchase_types == 1) {
         $default_purchase_types = @pls_get_option('default_form_options_purchase_types');
         // Set Default
         if (empty($_POST['purchase_types'])) {
             $purchase_types_select = array($default_purchase_types);
         } else {
             $purchase_types_select = wp_kses_post($_POST['purchase_types']);
         }
         $form_html['purchase_types'] = pls_h('select', array('name' => 'purchase_types[]') + $form_opt_attr['purchase_types'], pls_h_options($form_options['purchase_types'], $purchase_types_select));
     }
     /** Add the availability select element. */
     if ($available_on == 1) {
         $selected_avail_on = isset($_POST['metadata']['avail_on']) ? wp_kses_post($_POST['metadata']['avail_on']) : false;
         $form_html['available_on'] = pls_h('select', array('name' => 'metadata[avail_on]') + $form_opt_attr['available_on'], pls_h_options($form_options['available_on'], $selected_avail_on));
     }
     /** Add the cities select element. */
     if ($multi_cities == 1) {
         // multi-city select option enabled
         $selected_locality = isset($_POST['location']['locality']) ? wp_kses_post($_POST['location']['locality']) : false;
         $form_html['cities'] = pls_h('select', array('name' => 'location[locality][]', 'multiple' => 'multiple') + $form_opt_attr['cities'], pls_h_options($form_options['cities'], $selected_locality, true));
     } elseif ($cities == 1) {
         $selected_locality = isset($_POST['location']['locality']) ? wp_kses_post($_POST['location']['locality']) : false;
         $form_html['cities'] = pls_h('select', array('name' => 'location[locality]') + $form_opt_attr['cities'], pls_h_options($form_options['cities'], $selected_locality, true));
     }
     /** Add the cities select element. */
     if ($multi_states == 1) {
         // multi-state select option enabled
         $selected_region = isset($_POST['location']['region']) ? wp_kses_post($_POST['location']['region']) : false;
         $form_html['states'] = pls_h('select', array('name' => 'location[region][]', 'multiple' => 'multiple') + $form_opt_attr['states'], pls_h_options($form_options['states'], $selected_region, true));
     } elseif ($states == 1) {
         $selected_region = isset($_POST['location']['region']) ? wp_kses_post($_POST['location']['region']) : false;
         $form_html['states'] = pls_h('select', array('name' => 'location[region]') + $form_opt_attr['states'], pls_h_options($form_options['states'], $selected_region, true));
     }
     /** Add the cities select element. */
     if ($zips == 1) {
         $selected_postal = isset($_POST['location']['postal']) ? wp_kses_post($_POST['location']['postal']) : false;
         $form_html['zips'] = pls_h('select', array('name' => 'location[postal]') + $form_opt_attr['zips'], pls_h_options($form_options['zips'], $selected_postal, true));
     }
     /** Add the neighborhood select element. */
     if ($multi_neighborhoods == 1) {
         // multi-neighborhood select option enabled
         $selected_neighborhood = isset($_POST['location']['neighborhood']) ? wp_kses_post($_POST['location']['neighborhood']) : false;
         $form_html['neighborhood'] = pls_h('select', array('name' => 'location[neighborhood][]', 'multiple' => 'multiple') + $form_opt_attr['neighborhood'], pls_h_options($form_options['neighborhood'], $selected_neighborhood, true));
     } elseif ($neighborhood == 1) {
         $selected_neighborhood = isset($_POST['location']['neighborhood']) ? wp_kses_post($_POST['location']['neighborhood']) : false;
         $form_html['neighborhood'] = pls_h('select', array('name' => 'location[neighborhood]') + $form_opt_attr['neighborhood'], pls_h_options($form_options['neighborhood'], $selected_neighborhood, true));
     }
     /** Add the county select element. */
     if ($county == 1) {
         $selected_county = isset($_POST['location']['county']) ? wp_kses_post($_POST['location']['county']) : false;
         $form_html['county'] = pls_h('select', array('name' => 'location[county]') + $form_opt_attr['county'], pls_h_options($form_options['county'], $selected_county, true));
     }
     /** Add the neighborhood / neighborhood_polygon select element. */
     if ($neighborhood_polygons == 1) {
         if (count($form_options['neighborhood_polygons']) > 1) {
             $selected_polygons = isset($_POST['neighborhood_polygons']) ? wp_kses_post($_POST['neighborhood_polygons']) : false;
             $form_html['neighborhood_polygons'] = pls_h('select', array('name' => 'neighborhood_polygons') + $form_opt_attr['neighborhood_polygons'], pls_h_options($form_options['neighborhood_polygons'], $selected_polygons, true));
         } else {
             // default to MLS data for neighborhoods if no polygons are set
             $selected_polygons = isset($_POST['location']['neighborhood']) ? wp_kses_post($_POST['location']['neighborhood']) : false;
             $form_html['neighborhood_polygons'] = pls_h('select', array('name' => 'location[neighborhood]') + $form_opt_attr['neighborhood'], pls_h_options($form_options['neighborhood'], $selected_neighborhood, true));
         }
     }
     /** Add the minimum sqft select element. */
     if ($min_sqft == 1) {
         $selected_min_sqft = isset($_POST['metadata']['min_sqft']) ? wp_kses_post($_POST['metadata']['min_sqft']) : false;
         $form_html['min_sqft'] = pls_h('select', array('name' => 'metadata[min_sqft]') + $form_opt_attr['min_sqft'], pls_h_options($form_options['min_sqft'], $selected_min_sqft));
     }
     /** Add the minimum price select element. */
     if ($max_sqft == 1) {
         $selected_max_sqft = isset($_POST['metadata']['max_sqft']) ? wp_kses_post($_POST['metadata']['max_sqft']) : false;
         $form_html['max_sqft'] = pls_h('select', array('name' => 'metadata[max_sqft]') + $form_opt_attr['max_sqft'], pls_h_options($form_options['max_sqft'], $selected_max_sqft));
     }
     /** Add the minimum price select element. */
     if ($min_price == 1) {
         $selected_min_price = isset($_POST['metadata']['min_price']) ? wp_kses_post($_POST['metadata']['min_price']) : false;
         $form_html['min_price'] = pls_h('select', array('name' => 'metadata[min_price]') + $form_opt_attr['min_price'], pls_h_options($form_options['min_price'], $selected_min_price));
     }
     /** Add the maximum price select element. */
     if ($max_price == 1) {
         $selected_max_price = isset($_POST['metadata']['max_price']) ? wp_kses_post($_POST['metadata']['max_price']) : false;
         $form_html['max_price'] = pls_h('select', array('name' => 'metadata[max_price]') + $form_opt_attr['max_price'], pls_h_options($form_options['max_price'], $selected_max_price));
     }
     /** Add the minimum price select element. */
     if ($min_price_rental == 1) {
         $selected_min_price = isset($_POST['metadata']['min_price']) ? wp_kses_post($_POST['metadata']['min_price']) : false;
         $form_html['min_price_rental'] = pls_h('select', array('name' => 'metadata[min_price]') + $form_opt_attr['min_price'], pls_h_options($form_options['min_price_rental'], $selected_min_price));
     }
     /** Add the maximum price select element. */
     if ($max_price_rental == 1) {
         $selected_max_price = isset($_POST['metadata']['max_price']) ? wp_kses_post($_POST['metadata']['max_price']) : false;
         $form_html['max_price_rental'] = pls_h('select', array('name' => 'metadata[max_price]') + $form_opt_attr['max_price'], pls_h_options($form_options['max_price_rental'], $selected_max_price));
     }
     /** Add the minimum price select element. */
     if ($min_price_sales == 1) {
         $selected_min_price = isset($_POST['metadata']['min_price']) ? wp_kses_post($_POST['metadata']['min_price']) : false;
         $form_html['min_price_sales'] = pls_h('select', array('name' => 'metadata[min_price]') + $form_opt_attr['min_price'], pls_h_options($form_options['min_price_sales'], $selected_min_price));
     }
     /** Add the maximum price select element. */
     if ($max_price_sales == 1) {
         $selected_max_price = isset($_POST['metadata']['max_price']) ? wp_kses_post($_POST['metadata']['max_price']) : false;
         $form_html['max_price_sales'] = pls_h('select', array('name' => 'metadata[max_price]') + $form_opt_attr['max_price'], pls_h_options($form_options['max_price_sales'], $selected_max_price));
     }
     $section_title = array('bedrooms' => 'Beds', 'min_beds' => 'Min Beds', 'max_beds' => 'Max Beds', 'bathrooms' => 'Baths', 'min_baths' => 'Min Baths', 'max_baths' => 'Max Baths', 'half_baths' => 'Half Baths', 'property_type' => 'Property Type', 'zoning_types' => 'Zoning Type', 'listing_types' => 'Listing Type', 'purchase_types' => 'Purchase Type', 'available_on' => 'Available', 'cities' => 'Near', 'states' => 'State', 'zips' => 'Zip Code', 'min_price' => 'Min Price', 'max_price' => 'Max Price', 'neighborhood' => 'Neighborhood', 'county' => 'County', 'min_beds' => 'Min Beds', 'max_beds' => 'Max Beds', 'min_price_rental' => 'Min Price Rental', 'max_price_rental' => 'Max Price Rental', 'min_price_sales' => 'Min Price Sales', 'max_price_sales' => 'Max Price Sales', 'neighborhood_polygons' => 'Neighborhood Polygon', 'min_sqft' => 'Min Sqft', 'max_sqft' => 'Max Sqft');
     // In case user somehow disables all filters.
     if (empty($form_html)) {
         return '';
     }
     /** Apply filters on all the form elements html. */
     $form_html_keys = array_keys($form_html);
     $form_html_count = count($form_html_keys);
     // foreach( $form_html as $option_name => &$opt_html ) {
     for ($i = 0; $i < $form_html_count; $i++) {
         $option_name = $form_html_keys[$i];
         $opt_html = $form_html[$option_name];
         $opt_html = apply_filters(pls_get_merged_strings(array("pls_listings_search_form_{$option_name}_html", $context), '_', 'pre', false), $opt_html, $form_options[$option_name], $section_title[$option_name], $context_var);
         $form_html[$option_name] = $opt_html;
     }
     /** Combine the form elements. */
     $form = '';
     foreach ($form_html as $label => $select) {
         $form .= pls_h('section', array('class' => $label . ' pls_search_form'), pls_h_label($section_title[$label], $label) . $select);
     }
     /** Add the filtered submit button. */
     if ($include_submit) {
         $form_html['submit'] = apply_filters(pls_get_merged_strings(array("pls_listings_search_submit", $context), '_', 'pre', false), pls_h('input', array('class' => 'pls_search_button', 'type' => 'submit', 'value' => 'Search')), $context_var);
         /** Append the form submit. */
         $form .= $form_html['submit'];
     }
     /** Wrap the combined form content in the form element and filter it. */
     $form_id = pls_get_merged_strings(array('pls-listings-search-form', $context), '-', 'pre', false);
     $form = pls_h('form', array('action' => @$form_data->action, 'method' => 'post', 'id' => $form_id, 'class' => $class), @$form_data->hidden_field . apply_filters(pls_get_merged_strings(array("pls_listings_search_form_inner", $context), '_', 'pre', false), $form, $form_html, $form_options, $section_title, $context_var));
     /** Filter the form. */
     $result = apply_filters(pls_get_merged_strings(array("pls_listings_search_form_outer", $context), '_', 'pre', false), $form, $form_html, $form_options, $section_title, @$form_data, $form_id, $context_var);
     // Load the filters.js script...
     $result .= '<script type="text/javascript" src="' . trailingslashit(PLS_JS_URL) . 'scripts/filters.js"></script>';
     $cache->save($result);
     return $result;
 }
コード例 #14
0
ファイル: compatibility.php プロジェクト: lytranuit/wordpress
 public static function get_property_url($id = false)
 {
     // Make sure $id is set...
     if (!$id) {
         return false;
     }
     $cache = new PLS_Cache("Property URL");
     if ($url = $cache->get($id)) {
         return $url;
     }
     // Test the function for any exceptions
     $return = self::_try_for_exceptions(array("PL_Page_Helper", "get_url"), $id);
     // If no exceptions were detected, return the result
     if ($return) {
         $cache->save($return, PLS_Cache::TTL_LOW);
         return $return;
     }
     if (pls_has_plugin_error()) {
         $page = get_page_by_title('Sample Listing', 'ARRAY_A');
         if ($page && isset($page['guid'])) {
             return $page['guid'];
         }
     }
     return false;
 }