public static function no_plugin() { $error_msg = pls_has_plugin_error(); $adminURL = defined('ADMIN_URL') ? ADMIN_URL : trailingslashit(admin_url()); if ($error_msg) { ob_start(); switch ($error_msg) { case "no_plugin": ?> <div style="margin-top: 10px; border: 1px solid #E6DB55;" class="update-nag">You are currently using a Placester theme without the <a href="http://wordpress.org/extend/plugins/placester/">Real Estate Website Builder</a> plugin. This theme wont work without it. Please <a class="button" href='<?php echo $adminURL; ?> plugin-install.php?tab=search&type=term&s="real+estate+website+builder"&plugin-search-input=Search+Plugins'>Install it Now</a></div> <?php break; case "no_api_key": ?> <div style="margin-top: 10px; border: 1px solid #E6DB55;" class="update-nag">There is no API key associated with the Real Estate Website Builder plugin. Please <a class="button" href='<?php echo $adminURL; ?> admin.php?page=placester_settings'>Set a Valid API Key</a></div> <?php break; } echo ob_get_clean(); } }
/** * Outputs and filters the widget. * * The widget connects to the plugin using the framework plugin api class. * If the class returns false, this means that either the plugin is * missing, either the it has no API key set. * * @since 0.0.1 */ public function widget($args, $instance) { list($args, $instance) = self::process_defaults($args, $instance); /** Extract the arguments into separate variables. */ extract($args, EXTR_SKIP); /* Output the theme's $before_widget wrapper. */ echo $before_widget; /* If a title was input by the user, display it. */ $widget_title = ''; if (!empty($instance['title']) && !pls_has_plugin_error()) { $widget_title = $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title; } /** Get the list of listings using the partial. */ $listings_args = array('limit' => $instance['number'], 'width' => $instance['width'], 'height' => $instance['height'], 'placeholder_img' => $instance['placeholder'], 'crop_description' => 1, 'context' => 'widget', 'context_var' => $widget_id, 'featured_option_id' => $featured_option_id); /** If field is empty, remove it so that the function's defaults can be used. */ if (empty($instance['placeholder'])) { unset($listings_args['placeholder_img']); } // set context so filter can customize the layout $listings_args['context'] = 'get_listings_widget'; // pls_dump($listings_args); $widget_body = PLS_Partials::get_listings($listings_args); /** Apply a filter on the whole widget */ echo apply_filters('pls_widget_listings', $widget_title . $widget_body, $widget_title, $before_title, $after_title, $widget_body, $instance, $widget_id, $listings_args); /* Close the theme's widget wrapper. */ echo $after_widget; }
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; }
function pls_styles() { // wp_enqueue_style( 'pls-default', '/css/style.css' . get_bloginfo( 'stylesheet_url' ) ); // Required by WordPress if (!isset($content_width)) { $content_width = 900; } /** * If the plugin is inactive, or the api key is missing from the * plugin enqueue a css file that deals with styling the plugin * notifications. */ if (pls_has_plugin_error()) { wp_enqueue_style('pls-plugin-nags', trailingslashit(PLS_CSS_URL) . 'styles/plugin-nags.css'); } wp_enqueue_style('contact-widget', trailingslashit(PLS_CSS_URL) . 'styles/contact.widget.ajax.css'); if (get_theme_support('pls-default-normalize')) { wp_enqueue_style('normalize', trailingslashit(PLS_CSS_URL) . 'styles/normalize.css'); } if (get_theme_support('pls-default-960')) { wp_enqueue_style('pls-default-960', trailingslashit(PLS_CSS_URL) . 'styles/960.css'); } /** Include default layout only if supported. */ if (get_theme_support('pls-default-css')) { wp_enqueue_style('pls-default-css', trailingslashit(PLS_CSS_URL) . 'styles/all.css'); } else { if (get_theme_support('pls-default-css-blog')) { wp_enqueue_style('pls-default-css-blog', trailingslashit(PLS_CSS_URL) . 'styles/blog.css'); } if (get_theme_support('pls-default-css-forms')) { wp_enqueue_style('pls-default-css-forms', trailingslashit(PLS_CSS_URL) . 'styles/forms.css'); } if (get_theme_support('pls-default-css-header')) { wp_enqueue_style('pls-default-css-header', trailingslashit(PLS_CSS_URL) . 'styles/header.css'); } if (get_theme_support('pls-default-css-listings-detail')) { wp_enqueue_style('pls-default-css-listings-detail', trailingslashit(PLS_CSS_URL) . 'styles/css-listings-detail.css'); } if (get_theme_support('pls-default-css-nav')) { wp_enqueue_style('pls-default-css-nav', trailingslashit(PLS_CSS_URL) . 'styles/nav.css'); } if (get_theme_support('pls-default-css-widgets')) { wp_enqueue_style('pls-default-css-widgets', trailingslashit(PLS_CSS_URL) . 'styles/widgets.css'); } } }
/** * Registers the core frameworks widgets. These widgets typically overwrite the equivalent default WordPress * widget by extending the available options of the widget. * * @since 0.0.1 * @uses register_widget() Registers individual widgets with WordPress * @link http://codex.wordpress.org/Function_Reference/register_widget */ function pls_register_widgets() { /** Load the Placester Agent widget. */ if (current_theme_supports('pls-widget-agent')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'agent.php'; register_widget('PLS_Widget_Agent'); } /** Load the Placester Office widget. */ if (current_theme_supports('pls-widget-office')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'office.php'; register_widget('PLS_Widget_Office'); } /** Load the Placester Contact widget. */ if (!pls_has_plugin_error() && current_theme_supports('pls-widget-contact')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'contact.php'; register_widget('Placester_Contact_Widget'); } /** Load the Placester Recent Posts widget. */ if (current_theme_supports('pls-widget-recent-posts')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'recent-posts.php'; register_widget('PLS_Widget_Recent_Posts'); } /** Load the Placester Quick Search widget. */ if (current_theme_supports('pls-widget-quick-search')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'quick-search.php'; register_widget('PLS_Quick_Search_Widget'); } /** Load the Placester Listings widget. */ if (current_theme_supports('pls-widget-listings')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'listings.php'; register_widget('PLS_Widget_Listings'); } /** Load the Placester Mortgage Calculator widget. */ if (current_theme_supports('pls-widget-mortgage-calculator')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'mortgage-calculator.php'; register_widget('PLS_Widget_Mortgage_Calculator'); } /** Load the Placester Feedburner Subscribe Form widget. */ if (current_theme_supports('pls-widget-feedburner-form')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'feedburner-subscribe-form.php'; register_widget('PLS_Widget_Feedburner_Widget'); } /** Load the Testimonials widget. */ if (current_theme_supports('pls-widget-testimonials')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'testimonials.php'; register_widget('PLS_Widget_Testimonials'); } /** Load the Agents widget. */ if (current_theme_supports('pls-widget-agents')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'agents.php'; register_widget('PLS_Widget_Agents'); } /** Load the Services widget. */ if (current_theme_supports('pls-widget-services')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'services.php'; register_widget('PLS_Widget_Services'); } /** Load the Twitter widget. */ if (current_theme_supports('pls-widget-twitter')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'twitter.php'; register_widget('PLS_Widget_Twitter'); } /** Load the Facebook widget. */ if (current_theme_supports('pls-widget-facebook')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'facebook.php'; register_widget('PLS_Widget_Facebook'); } /** Load the YouTube widget. */ if (current_theme_supports('pls-widget-youtube')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'youtube.php'; register_widget('PLS_Widget_YouTube'); } /** Load the Facebook Like Box widget. */ if (current_theme_supports('pls-widget-facebook-like-box')) { require_once trailingslashit(PLS_WIDGETS_DIR) . 'facebook-like-box.php'; register_widget('PLS_Widget_Facebook_Like_Box'); } }
/** * Returns a tailored placeholder message if there is a problem connecting * to the plugin. * * @param string $context Optional. Used to display the context of the error. * Usually the __FUNCTION__. * @access public * @return void * @since 0.0.1 */ function pls_get_no_plugin_placeholder($context = '') { $plugin_error = pls_has_plugin_error(); if ($plugin_error) { $messages = array('no_api_key' => 'You must add a valid API key to the Placester plugin to use this feature.', 'no_plugin' => 'You must activate the Placester plugin to use this feature.', 'timeout' => 'The Placester API connection timed out.'); $context = empty($context) ? 'ERROR' : $context; $css_class = str_replace('_', '-', $plugin_error); return pls_h('div', array('class' => "pls-plugin-error pls-{$css_class}", 'style' => "padding: 5px; border: 1px solid red; margin: 5px 0; clear: both; color: red;"), "<code>{$context}</code>: {$messages[$plugin_error]}"); } }
<?php PLS_Route::handle_header(); ?> <?php // only load bootloader if plugin is active if (!pls_has_plugin_error()) { ?> <script type="text/javascript"> var search_bootloader; jQuery(document).ready(function( $ ) { search_bootloader = new SearchLoader ({ map: { dom_id: 'map_canvas', filter_by_bounds: false }, filter: { context: 'listings_search' }, list: { context: 'custom_listings_search' } }); }); </script> <?php } ?> <?php PLS_Route::handle_dynamic();
/** * Adds default theme support. * * @since 0.0.1 */ function default_theme_support() { add_theme_support('post-thumbnails'); /** Add theme support for theme wrappers */ add_theme_support('pls-routing-util'); /** Add theme support for menus */ add_theme_support('pls-menus', array('primary', 'subsidiary')); // Adds default styling out of the box add_theme_support('pls-default-normalize'); add_theme_support('pls-default-960'); add_theme_support('pls-default-style'); add_theme_support('pls-default-css'); add_theme_support('pls-js', array('chosen' => array('script' => true, 'style' => true), 'floating' => array('script' => true, 'style' => true), 'datatable' => array('script' => true, 'style' => true), 'jquery-ui' => array('script' => true, 'style' => true), 'spinner' => array('script' => true, 'style' => true), 'masonry' => array('script' => true, 'style' => false), 'jquery-tools' => array('script' => true, 'style' => false), 'form' => array('script' => true, 'style' => true), 'cookies' => array('script' => true, 'style' => false), 'lead-capture' => array('script' => true, 'style' => false))); if (!function_exists('optionsframework_options')) { add_theme_support('pls-theme-options'); } add_theme_support('pls-image-util', array('fancybox')); add_theme_support('pls-slideshow', array('script', 'style')); add_theme_support('pls-maps-util'); add_theme_support('pls-debug'); add_theme_support('pls-meta-data'); add_theme_support('pls-meta-tags'); add_theme_support('pls-micro-data'); add_theme_support('pls-custom-meta'); add_theme_support('pls-walkscore'); //style options, need to be set in style-util.php add_theme_support('pls-typography-options'); add_theme_support('pls-header-options'); add_theme_support('pls-navigation-options'); add_theme_support('pls-listing-options'); add_theme_support('pls-post-options'); add_theme_support('pls-widget-options'); add_theme_support('pls-css-options'); add_theme_support('pls-search-options'); add_theme_support('pls-color-options'); add_theme_support('pls-user-options'); add_theme_support('pls-slideshow-options'); // Required for WordPress add_theme_support('automatic-feed-links'); /** Add theme support for sidebars - this doesn't turn all sidebars on. */ add_theme_support('pls-sidebars', array('primary', 'home', 'listings-search', 'footer-widgets', 'single-property', 'rental-search', 'sales-search', 'blog-index', 'single-post', 'neighborhoods', 'single-neighborhood', 'contact', 'testimonials', 'agents', 'services')); // Add Default Sidebars add_theme_support('pls-main-sidebar'); add_theme_support('pls-listings-search-sidebar'); add_theme_support('pls-single-property-sidebar'); // Add default widgets add_theme_support('pls-widget-recent-posts'); if (!pls_has_plugin_error()) { add_theme_support('pls-widget-contact'); } add_theme_support('pls-widget-agent'); add_theme_support('pls-widget-office'); add_theme_support('pls-widget-quick-search'); add_theme_support('pls-widget-listings'); }
/** * 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; }
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; }
/** * 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; }
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; }
function pls_scripts() { if (is_admin()) { return; } /** Register Modernizr. Will be enqueued using 'wp_print_scripts'. */ wp_register_script('modernizr', trailingslashit(PLS_JS_URL) . 'libs/modernizr/modernizr.min.js', array(), '2.6.1'); // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) // wp_localize_script( 'jquery', 'info', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); add_action('wp_print_scripts', 'pls_print_info_var'); /** * If the plugin is inactive, register the script that deals with adding * notification about needing the plugin. Localize the notification * message. Accompanied by plugin-nags.css. */ wp_register_script('jquery-placeholder', trailingslashit(PLS_JS_URL) . 'libs/jquery-placeholder/jquery.placeholder.min.js', array('jquery'), '1.0.1', true); wp_enqueue_script('jquery-placeholder'); wp_register_script('listings-object', trailingslashit(PLS_JS_URL) . 'scripts/listings.js', array('jquery'), '1.0.1', true); wp_enqueue_script('listings-object'); wp_register_script('get-listings-fav-ajax', trailingslashit(PLS_JS_URL) . 'scripts/get-listings-fav-ajax.js', array('jquery'), NULL, true); wp_enqueue_script('get-listings-fav-ajax'); wp_register_script('contact-widget', trailingslashit(PLS_JS_URL) . 'scripts/contact.widget.ajax.js', array('jquery'), NULL, true); wp_enqueue_script('contact-widget'); wp_register_script('client-edit-profile', trailingslashit(PLS_JS_URL) . 'scripts/client-edit-profile.js', array('jquery'), NULL, true); wp_enqueue_script('client-edit-profile'); wp_register_script('script-history', trailingslashit(PLS_JS_URL) . 'libs/history/jquery.address.js', array('jquery'), NULL, true); wp_enqueue_script('script-history'); wp_register_script('search-bootloader', trailingslashit(PLS_JS_URL) . 'scripts/search-loader.js', array('jquery'), NULL, true); wp_enqueue_script('search-bootloader'); wp_enqueue_script('underscore'); if (pls_has_plugin_error()) { /** Localize the script. Send the correct notification. */ $l10n = array(); if (pls_has_plugin_error() == 'no_api_key') { $l10n['no_api_key'] = 'You need to add a valid API Key to the <a href="' . admin_url('admin.php?page=placester_settings') . '">Placester Real Estate Pro plugin settings page</a>.'; } elseif (pls_has_plugin_error() == 'no_plugin') { $l10n['no_plugin'] = 'This theme needs the <a href="http://wordpress.org/extend/plugins/placester/" target="_blank">Placester Real Estate Pro plugin</a> to work.'; } wp_localize_script('pls-plugin-nags', 'messages', $l10n); } /** Get theme-supported js modules. */ $js = get_theme_support('pls-js'); /** If there is no support, return. */ if (!is_array($js[0])) { return; } /** * The "Chosen" script. * Deal with it only theme support has been added. * {@link: http://harvesthq.github.com/chosen/} */ if (array_key_exists('chosen', $js[0])) { /** Register the script and style. */ wp_register_script('chosen', trailingslashit(PLS_JS_URL) . 'libs/chosen/chosen.jquery.min.js', array('jquery'), NULL, false); wp_register_script('chosen-custom', trailingslashit(PLS_JS_URL) . 'libs/chosen/chosen-custom.js', array('jquery'), NULL, false); wp_register_style('chosen', trailingslashit(PLS_JS_URL) . 'libs/chosen/chosen.css'); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['chosen'])) { if (in_array('script', $js[0]['chosen'])) { wp_enqueue_script('chosen'); wp_enqueue_script('chosen-custom'); } /** Enqueue the chosen style */ if (in_array('style', $js[0]['chosen'])) { wp_enqueue_style('chosen'); } } } if (array_key_exists('spinner', $js[0])) { /** Register the script and style. */ wp_register_script('spinner', trailingslashit(PLS_JS_URL) . 'libs/spinner/spinner.js', array('jquery'), NULL, true); wp_register_style('spinner', trailingslashit(PLS_JS_URL) . 'libs/spinner/spinner.css'); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['spinner'])) { if (in_array('script', $js[0]['spinner'])) { wp_enqueue_script('spinner'); wp_enqueue_style('spinner'); } } } if (array_key_exists('picturefill', $js[0])) { /** Register the script and style. */ wp_register_script('picturefill', trailingslashit(PLS_JS_URL) . 'libs/picturefill/picturefill.js', array('jquery'), NULL, true); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['picturefill'])) { if (in_array('script', $js[0]['picturefill'])) { wp_enqueue_script('picturefill'); } } } if (array_key_exists('masonry', $js[0])) { /** Register the script and style. */ wp_register_script('masonry', trailingslashit(PLS_JS_URL) . 'scripts/masonry.js', array('jquery'), NULL, true); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['masonry'])) { if (in_array('script', $js[0]['masonry'])) { wp_enqueue_script('masonry'); } } } if (array_key_exists('datatable', $js[0])) { /** Register the script and style. */ wp_register_script('datatable', trailingslashit(PLS_JS_URL) . 'libs/datatables/jquery.dataTables.js', array('jquery'), NULL, true); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['datatable'])) { if (in_array('script', $js[0]['datatable'])) { wp_enqueue_script('datatable'); } } } if (array_key_exists('jquery-ui', $js[0])) { wp_register_style('jquery-ui', trailingslashit(PLS_JS_URL) . 'libs/jquery-ui/css/smoothness/jquery-ui-1.8.17.custom.css'); if (is_array($js[0]['jquery-ui'])) { if (in_array('script', $js[0]['jquery-ui'])) { wp_enqueue_script('jquery-ui-core'); if (isset($GLOBALS['wp_scripts']->registered['jquery-ui-datepicker'])) { wp_enqueue_script('jquery-ui-datepicker'); } else { wp_register_script('jquery-ui-datepicker', trailingslashit(PLS_JS_URL) . 'libs/jquery-ui/js/jquery.ui.datepicker.js', array('jquery'), NULL, true); wp_enqueue_script('jquery-ui-datepicker'); } if (isset($GLOBALS['wp_scripts']->registered['jquery-ui-dialog'])) { wp_enqueue_script('jquery-ui-dialog'); } else { // wp_register_script( 'jquery-ui-dialog', trailingslashit( PLS_JS_URL ) . 'libs/jquery-ui/js/jquery.ui.dialog.js' , array( 'jquery'), NULL, true ); // wp_enqueue_script( 'jquery-ui-dialog' ); } } if (in_array('style', $js[0]['jquery-ui'])) { wp_enqueue_style('jquery-ui'); } } } if (array_key_exists('jquery-tools', $js[0])) { /** Register the script and style. */ wp_register_script('tabs', trailingslashit(PLS_JS_URL) . 'libs/jquery-tools/tabs.js', array('jquery'), NULL, true); wp_register_script('rangeinput', trailingslashit(PLS_JS_URL) . 'libs/jquery-tools/rangeinput.js', array('jquery'), NULL, true); wp_register_script('validator', trailingslashit(PLS_JS_URL) . 'libs/jquery-tools/validator.js', array('jquery'), NULL, true); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['jquery-tools'])) { if (in_array('script', $js[0]['jquery-tools'])) { wp_enqueue_script('tabs'); wp_enqueue_script('rangeinput'); wp_enqueue_script('validator'); } } } if (array_key_exists('form', $js[0])) { /** Register the script and style. */ wp_enqueue_script('modernizr'); wp_register_script('form', trailingslashit(PLS_JS_URL) . 'scripts/form.js', array('jquery', 'modernizr'), NULL, true); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['form'])) { if (in_array('script', $js[0]['form'])) { wp_enqueue_script('form'); } } } /** * The "Cookies" script. * Deal with it only theme support has been added. * {@link: http://code.google.com/p/cookies/wiki/License} */ if (array_key_exists('cookies', $js[0])) { /** Register the script and style. */ wp_register_script('cookies', trailingslashit(PLS_JS_URL) . 'libs/cookies/cookies.jquery.js', array('jquery'), NULL, false); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['cookies'])) { if (in_array('script', $js[0]['cookies'])) { wp_enqueue_script('cookies'); } } } if (array_key_exists('lead-capture', $js[0])) { /** Register the script and style. */ wp_register_script('lead-capture', trailingslashit(PLS_JS_URL) . 'scripts/lead-capture.js', array('jquery'), NULL, true); /** Enqueue script and styles only if supported. */ if (is_array($js[0]['lead-capture'])) { if (in_array('script', $js[0]['lead-capture'])) { wp_enqueue_script('lead-capture'); } } } }