/** * Outputs and filters the widget. * * @since 0.0.1 */ public function widget($args, $instance) { /** Get the the cached posts list. */ $cache = wp_cache_get('pls_widget_recent_posts', 'widget'); /** If cache hasn't been set, initialize it. */ if (!is_array($cache)) { $cache = array(); } /** If cache has been set for this widget, echo it, and return. */ if (isset($args['widget_id']) && isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } /** Start output buffering. */ ob_start(); $args = self::process_defaults($args, $instance); extract($args, EXTR_SKIP); /** If conversion to non-negative integer results in 0, set the number of posts to 5. */ if (!($number = absint($instance['number']))) { $number = 5; } /** Get the posts. */ $query = new WP_Query(array('posts_per_page' => $number, 'cat' => $cat, 'no_found_rows' => true, 'post_status' => 'publish')); /** If there are posts... */ if ($query->have_posts()) { /* If a title was input by the user, store it. */ $widget_title = ''; if (!empty($instance['title'])) { $widget_title = $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title; } /* Output the theme's $before_widget wrapper. */ echo $before_widget; /** Will hold the combined posts html. */ $widget_body = ''; /** The loop. */ while ($query->have_posts()) { /** Setup post data. */ $query->the_post(); /** This array will hold the html elements for each post and will be passed to the filters. */ $post_html = $instance; unset($post_html['title']); $post_html['post_title'] = empty($instance['post_title']) ? '' : pls_h_a(get_permalink(), esc_attr(get_the_title() ? get_the_title() : get_the_ID()), array('class' => 'title')); $post_html['author'] = empty($instance['author']) ? '' : sprintf(' ' . 'by <span class="author">%1$s</span>', get_the_author()); $post_html['date'] = empty($instance['date']) ? '' : sprintf(' ' . 'on <time datetime="%1$s">%2$s</time>', get_the_date('Y-m-d'), get_the_date()); $post_html['excerpt'] = empty($instance['excerpt']) ? '' : pls_h_div(has_excerpt() ? get_the_excerpt() : '', array('class' => 'excerpt')); $post_html['url'] = empty($instance['excerpt']) ? '' : get_permalink(); $post_html['read_more'] = empty($instance['read_more']) ? '' : pls_h_a(get_permalink(), 'Read more', array('class' => 'read-more')); /** Combine the post information. */ $post_item = pls_get_if_not_empty($post_html['post_title']) . (!empty($post_html['author']) || !empty($post_html['date']) ? pls_h_p(sprintf('Posted%1$s%2$s.', pls_get_if_not_empty($post_html['author']), pls_get_if_not_empty($post_html['date'])), array('class' => 'meta p3')) : '') . pls_get_if_not_empty($post_html['excerpt']) . pls_get_if_not_empty($post_html['read_more']); /** Wrap the post in an article element and filter its contents. */ $post_item = pls_h('article', array('class' => 'recent-post-single', 'itemscope' => '', 'itemtype' => "http://schema.org/BlogPosting"), apply_filters('pls_widget_recent_posts_post_inner', $post_item, $post_html, $instance, $widget_id)); /** Append the filtered post to the post list. */ $widget_body .= apply_filters('pls_widget_recent_posts_post_outer', $post_item, $post_html, $instance, $widget_id); } /** while $query->have_posts() */ /** Wrap the widget body in a section element. */ $widget_body = pls_h('section', array('class' => 'widget-inner', 'itemscope' => '', 'itemtype' => 'http://schema.org/Blog'), apply_filters('pls_widget_recent_posts_inner', $widget_body, $instance, $widget_id)); // Now we need to put the "read more" strip at the bottom, linking to the selected category page // should come back and use pls_ methods $category_link = get_category_link($cat); $widget_body .= "<section class='more_posts'><a href='" . esc_url($category_link) . "' title='View More News'>View More News</a></section>"; /** Output and apply a filter on the whole widget. */ echo apply_filters('pls_widget_recent_posts', $widget_title . $widget_body, $widget_title, $before_title, $after_title, $widget_body, $instance, $widget_id); /* Output the theme's $after_widget wrapper. */ echo $after_widget; /** Reset the global $the_post as this query will have stomped on it. */ wp_reset_postdata(); } /** if $query->have_posts() */ /** Cache the widget contents */ $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('pls_widget_recent_posts', $cache, 'widget'); }
/** * 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 ); } }
/** * 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; }