Example #1
0
    /**
     * 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;
    }
Example #2
0
 /**
  * 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);
     /** Get the agent information from the plugin. */
     $agent = PLS_Plugin_API::get_user_details();
     $agent_array = array();
     // pls_dump($agent);
     /** If the plugin is active, and has an API key set... */
     if ($agent) {
         /* 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'])) {
             $widget_title = $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
         }
         /** This array will hold the html for the agent info sections and will be passed to the filters. */
         $agent_html = $instance;
         unset($agent_html['title']);
         // Add Name
         if (!empty($instance['name_custom'])) {
             // if admin set custom name
             $agent_html['name'] = self::checkForCustom($instance, 'name');
             $agent_array['name'] = $instance['name_custom'];
         } else {
             // otherwise use admin's name
             if (!empty($instance['name']) && (!empty($agent['user']['first_name']) || !empty($agent['user']['last_name']))) {
                 $agent_html['name'] = pls_h_p(trim($agent['user']['first_name'] . ' ' . $agent['user']['last_name']), array('class' => 'fn h5', 'itemprop' => 'name'));
                 $agent_array['name'] = $agent['user']['first_name'] . ' ' . $agent['user']['last_name'];
             } else {
                 $agent_html['name'] = '';
                 $agent_array['name'] = '';
             }
         }
         // Add Email
         if (!empty($instance['email_custom'])) {
             // if admin set custom email
             $agent_html['email'] = self::checkForCustom($instance, 'email');
             $agent_array['email'] = $instance['email_custom'];
         } else {
             // otherwise use admin's email
             if (!empty($instance['email']) && !empty($agent['user']['email'])) {
                 $agent_html['email'] = pls_h_p(pls_h_a("mailto:{$agent['user']['email']}", $agent['user']['email']), array('class' => 'email', 'itemprop' => 'email'));
                 $agent_array['email'] = $agent['user']['email'];
             } else {
                 $agent_html['email'] = '';
                 $agent_array['email'] = '';
             }
         }
         // Add Phone
         if (!empty($instance['phone_custom'])) {
             // if admin set custom phone
             $agent_html['phone'] = self::checkForCustom($instance, 'phone');
             $agent_array['phone'] = $instance['phone_custom'];
         } else {
             // otherwise use admin's phone
             if (!empty($instance['phone']) && !empty($agent['user']['phone'])) {
                 $agent_html['phone'] = pls_h_p(PLS_Format::phone($agent['user']['phone']), array('class' => 'phone', 'itemprop' => 'phone'));
                 $agent_array['phone'] = PLS_Format::phone($agent['user']['phone'], array('class' => 'phone', 'itemprop' => 'phone'));
             } else {
                 $agent_html['phone'] = '';
                 $agent_array['phone'] = '';
             }
         }
         // Add Description
         if (!empty($instance['description_custom'])) {
             // if admin set custom description
             $agent_html['description'] = self::checkForCustom($instance, 'description');
             $agent_array['description'] = $instance['description_custom'];
         } else {
             // otherwise use admin's descriptions
             if (!empty($instance['description']) && pls_get_option('pls-user-description')) {
                 $agent_bio = pls_get_option('pls-user-description');
                 $agent_html['description'] = pls_h_p($agent_bio, array('class' => 'desc p4', 'itemprop' => 'description'));
                 $agent_array['description'] = $agent_bio;
             } else {
                 $agent_html['description'] = '';
                 $agent_array['description'] = '';
             }
         }
         // Add Photo
         if (!empty($instance['image_uri'])) {
             // if admin set custom photo
             self::checkForCustom($instance, 'photo');
             $agent_array['photo'] = $instance['image_uri'];
         } else {
             // otherwise use admin's photo
             $user_image_option = pls_get_option('pls-user-image');
             if (!empty($instance['photo']) && !empty($user_image_option)) {
                 $agent_html['photo'] = pls_h_img(@pls_get_option('pls-user-image'), trim($agent['user']['first_name'] . ' ' . $agent['user']['last_name']), array('class' => 'photo', 'itemprop' => 'image') + array() + array());
                 $agent_array['photo'] = $user_image_option;
             } else {
                 if (isset($agent['user']['headshot'])) {
                     $agent_html['photo'] = pls_h_img($agent['user']['headshot'], trim($agent['user']['first_name'] . ' ' . $agent['user']['last_name']), array('class' => 'photo', 'itemprop' => 'image') + array() + array());
                     $agent_array['photo'] = $agent['user']['headshot'];
                 } else {
                     $agent_array['photo'] = '';
                 }
             }
         }
         // Form the HTML elements
         // photo
         $agent_html['photo'] = '<img class="pls-agent-phone" src="' . esc_url($instance['image_uri']) . '" />';
         // texts
         $agent_info = array('name', 'email', 'phone', 'description');
         foreach ($agent_info as $value) {
             $agent_html[$value] = pls_h_p($agent_html[$value], array('class' => 'pls-agent-' . $value));
         }
         /** Combine the agent information. */
         $widget_body = $agent_html['photo'] . $agent_html['name'] . $agent_html['email'] . $agent_html['phone'] . $agent_html['description'];
         /** Wrap the agent information in a section element. */
         $widget_body = apply_filters('pls_widget_agent_inner', $widget_body, $agent_html, $agent_array, $instance, $agent, $widget_id);
         /** Apply a filter on the whole widget */
         echo apply_filters('pls_widget_agent', $widget_title . $widget_body, $widget_title, $before_title, $after_title, $widget_body, $agent_html, $agent, $instance, $widget_id);
         /* Close the theme's widget wrapper. */
         if ($args['clearfix']) {
             echo '<div class="clearfix"></div>';
         }
         echo $after_widget;
     } elseif (current_user_can('administrator')) {
         /** Display an error message if the user is admin. */
         // echo pls_get_no_plugin_placeholder( $widget_id );
     }
 }
Example #3
0
 /**
  * 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;
 }