Ejemplo n.º 1
0
 /**
  * Generate conditional fields for the "posts" slideshow type.
  * @since  1.0.0
  * @return array $fields An array of fields.
  */
 public function generate_conditional_fields_posts()
 {
     global $wooslider;
     $images_url = $wooslider->plugin_url . '/assets/images/';
     $fields = array();
     // Categories.
     $terms = get_categories();
     $terms_options = array();
     if (!is_wp_error($terms)) {
         foreach ($terms as $k => $v) {
             $terms_options[$v->slug] = $v->name;
         }
     }
     $categories_args = array('key' => 'category', 'data' => array('options' => $terms_options));
     // Tags.
     $terms = get_tags();
     $terms_options = array();
     if (!is_wp_error($terms)) {
         foreach ($terms as $k => $v) {
             $terms_options[$v->slug] = $v->name;
         }
     }
     $tags_args = array('key' => 'tag', 'data' => array('options' => $terms_options));
     $thumbnails = WooSlider_Utils::get_thumbnail_options();
     $thumbnails_options = array();
     foreach ($thumbnails as $k => $v) {
         $thumbnails_options[$k] = $v['name'];
     }
     $thumbnails_args = array('key' => 'thumbnails', 'data' => array('options' => $thumbnails_options, 'default' => 'Default'));
     $layout_types = WooSlider_Utils::get_posts_layout_types();
     $layout_options = array();
     foreach ((array) $layout_types as $k => $v) {
         $layout_options[$k] = $v['name'];
     }
     $layout_images = array('text-left' => esc_url($images_url . 'text-left.png'), 'text-right' => esc_url($images_url . 'text-right.png'), 'text-top' => esc_url($images_url . 'text-top.png'), 'text-bottom' => esc_url($images_url . 'text-bottom.png'));
     $layouts_args = array('key' => 'layout', 'data' => array('options' => $layout_options, 'images' => $layout_images));
     $overlay_images = array('none' => esc_url($images_url . 'default.png'), 'full' => esc_url($images_url . 'text-bottom.png'), 'natural' => esc_url($images_url . 'overlay-natural.png'));
     $overlay_options = array('none' => __('None', 'wooslider'), 'full' => __('Full', 'wooslider'), 'natural' => __('Natural', 'wooslider'));
     $overlay_args = array('key' => 'overlay', 'data' => array('options' => $overlay_options, 'images' => $overlay_images));
     $limit_options = array();
     for ($i = 1; $i <= 20; $i++) {
         $limit_options[$i] = $i;
     }
     $limit_args = array('key' => 'limit', 'data' => array('options' => $limit_options, 'default' => 5));
     //$thumbnails_args = array( 'key' => 'thumbnails', 'data' => array() );
     $sticky_posts_args = array('key' => 'sticky_posts', 'data' => array());
     $link_title_args = array('key' => 'link_title', 'data' => array());
     $display_excerpt_args = array('key' => 'display_excerpt', 'data' => array('default' => '1'));
     // Create final array.
     $fields['limit'] = array('name' => __('Number of Posts', 'wooslider'), 'type' => 'select', 'args' => $limit_args, 'description' => __('The maximum number of posts to display', 'wooslider'));
     $fields['sticky_posts'] = array('name' => __('Allow for Sticky Posts', 'wooslider'), 'type' => 'checkbox', 'args' => $sticky_posts_args, 'description' => __('Display sticky posts in the slider', 'wooslider'));
     $fields['thumbnails'] = array('name' => __('Use thumbnails for Pagination', 'wooslider'), 'type' => 'select', 'args' => $thumbnails_args, 'description' => __('Use thumbnails for pagination, instead of "dot" indicators (uses featured image)', 'wooslider'));
     $fields['link_title'] = array('name' => __('Link the post title to it\'s post', 'wooslider'), 'type' => 'checkbox', 'args' => $link_title_args, 'description' => __('Link the post title to it\'s single post screen', 'wooslider'));
     $fields['display_excerpt'] = array('name' => __('Display the post\'s excerpt', 'wooslider'), 'type' => 'checkbox', 'args' => $display_excerpt_args, 'description' => __('Display the post\'s excerpt on each slide', 'wooslider'));
     $fields['layout'] = array('name' => __('Layout', 'wooslider'), 'type' => 'images', 'args' => $layouts_args, 'description' => __('The layout to use when displaying posts', 'wooslider'));
     $fields['overlay'] = array('name' => __('Overlay', 'wooslider'), 'type' => 'images', 'args' => $overlay_args, 'description' => __('The type of overlay to use when displaying the post text', 'wooslider'));
     $fields['category'] = array('name' => __('Categories', 'wooslider'), 'type' => 'multicheck', 'args' => $categories_args, 'description' => __('The categories from which to display posts', 'wooslider'));
     $fields['tag'] = array('name' => __('Tags', 'wooslider'), 'type' => 'multicheck', 'args' => $tags_args, 'description' => __('The tags from which to display posts', 'wooslider'));
     return $fields;
 }
 /**
  * Get the slides for the "posts" slideshow type.
  * @since  1.0.0
  * @param  array $args Array of arguments to determine which slides to return.
  * @return array       An array of slides to render for the slideshow.
  */
 private function slideshow_type_posts($args = array())
 {
     global $post;
     $slides = array();
     $defaults = array('limit' => '5', 'category' => '', 'tag' => '', 'layout' => 'text-left', 'size' => 'large', 'link_title' => '', 'overlay' => 'none', 'display_excerpt' => 'true');
     $args = wp_parse_args($args, $defaults);
     // Determine and validate the layout type.
     $supported_layouts = WooSlider_Utils::get_posts_layout_types();
     if (!in_array($args['layout'], array_keys($supported_layouts))) {
         $args['layout'] = $defaults['layout'];
     }
     // Determine and validate the overlay setting.
     if (!in_array($args['overlay'], array('none', 'full', 'natural'))) {
         $args['overlay'] = $defaults['overlay'];
     }
     $query_args = array('post_type' => 'post', 'numberposts' => intval($args['limit']));
     if ($args['category'] != '') {
         $query_args['category_name'] = esc_attr($args['category']);
     }
     if ($args['tag'] != '') {
         $query_args['tag'] = esc_attr(str_replace(',', '+', $args['tag']));
     }
     $posts = get_posts($query_args);
     if (!is_wp_error($posts) && count($posts) > 0) {
         // Setup the CSS class.
         $class = 'layout-' . esc_attr($args['layout']) . ' overlay-' . esc_attr($args['overlay']);
         foreach ($posts as $k => $post) {
             setup_postdata($post);
             $image = get_the_post_thumbnail(get_the_ID(), $args['size']);
             // Allow plugins/themes to filter here.
             $excerpt = '';
             if (($args['display_excerpt'] == 'true' || $args['display_excerpt'] == 1) && has_excerpt(get_the_ID())) {
                 $excerpt = wpautop(get_the_excerpt());
             }
             $title = get_the_title(get_the_ID());
             if ($args['link_title'] == 'true' || $args['link_title'] == 1) {
                 $title = '<a href="' . get_permalink($post) . '">' . $title . '</a>';
                 $image = '<a href="' . get_permalink($post) . '">' . $image . '</a>';
             }
             $content = $image . '<div class="slide-excerpt"><h2 class="slide-title">' . $title . '</h2>' . $excerpt . '</div>';
             if ($args['layout'] == 'text-top') {
                 $content = '<div class="slide-excerpt"><h2 class="slide-title">' . $title . '</h2>' . $excerpt . '</div>' . $image;
             }
             $layed_out_content = apply_filters('wooslider_posts_layout_html', $content, $args, $post);
             $content = '<div class="' . esc_attr($class) . '">' . $layed_out_content . '</div>';
             $data = array('content' => $content);
             if (isset($args['thumbnails']) && ('true' == $args['thumbnails'] || 1 == $args['thumbnails'])) {
                 $thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium');
                 if (!is_bool($thumb_url) && isset($thumb_url[0])) {
                     $data['attributes'] = array('data-thumb' => esc_url($thumb_url[0]));
                 } else {
                     $data['attributes'] = array('data-thumb' => esc_url(WooSlider_Utils::get_placeholder_image()));
                 }
             }
             $slides[] = $data;
         }
         wp_reset_postdata();
     }
     return $slides;
 }
Ejemplo n.º 3
0
 /**
  * Get the slides for the "slides" slideshow type.
  * @since  1.0.0
  * @param  array $args Array of arguments to determine which slides to return.
  * @return array       An array of slides to render for the slideshow.
  */
 private function slideshow_type_slides($args = array(), $settings = array())
 {
     global $post;
     $slides = array();
     $has_video = array('youtube' => false, 'vimeo' => false, 'wistia' => false);
     $defaults = array('limit' => '5', 'slide_page' => '', 'carousel' => '', 'thumbnails' => '', 'layout' => 'text-left', 'imageslide' => 'false', 'size' => 'large', 'display_title' => '', 'overlay' => 'none', 'display_content' => 'true', 'order' => 'DESC', 'order_by' => 'date', 'link_slide' => 'false');
     $args = wp_parse_args($args, $defaults);
     $query_args = array('post_type' => 'slide', 'numberposts' => intval($args['limit']), 'orderby' => $args['order_by'], 'order' => $args['order']);
     if (true == $settings['randomize']) {
         $query_args['orderby'] = 'rand';
     }
     if ('' != $args['slide_page']) {
         $cats_split = explode(',', $args['slide_page']);
         $query_args['tax_query'] = array(array('taxonomy' => 'slide-page', 'field' => 'slug', 'terms' => $cats_split));
     }
     $posts = get_posts($query_args);
     if (!is_wp_error($posts) && count($posts) > 0) {
         foreach ($posts as $k => $post) {
             setup_postdata($post);
             $class = '';
             if (isset($args['carousel']) && 'true' == $args['carousel']) {
                 $image = get_the_post_thumbnail(get_the_ID());
                 $wooslider_url = get_post_meta(get_the_ID(), '_wooslider_url', true);
                 if (('true' == $args['link_slide'] || 1 == $args['link_slide']) && '' != $wooslider_url) {
                     $image = '<a href="' . esc_url($wooslider_url) . '">' . $image . '</a>';
                 }
                 $data = array('content' => '<div class="slide-content">' . "\n" . apply_filters('wooslider_slide_carousel_slides', $image, $args) . "\n" . '</div>' . "\n");
             } else {
                 if ((isset($args['imageslide']) && 'true' == $args['imageslide'] || 1 == $args['imageslide']) && '' != get_the_post_thumbnail(get_the_ID())) {
                     // Determine and validate the layout type.
                     $supported_layouts = WooSlider_Utils::get_posts_layout_types();
                     if (!in_array($args['layout'], array_keys($supported_layouts))) {
                         $args['layout'] = $defaults['layout'];
                     }
                     // Determine and validate the overlay setting.
                     if (!in_array($args['overlay'], array('none', 'full', 'natural'))) {
                         $args['overlay'] = $defaults['overlay'];
                     }
                     if ($args['display_content'] == 'true' || $args['display_content'] == 1 || ($args['display_title'] == 'true' || $args['display_title'] == 1)) {
                         $class = 'layout-' . esc_attr($args['layout']) . ' overlay-' . esc_attr($args['overlay']);
                     }
                     $image = get_the_post_thumbnail(get_the_ID(), $args['size']);
                     $wooslider_url = get_post_meta(get_the_ID(), '_wooslider_url', true);
                     if (('true' == $args['link_slide'] || 1 == $args['link_slide']) && '' != $wooslider_url) {
                         $image = '<a href="' . esc_url($wooslider_url) . '">' . $image . '</a>';
                     }
                     $title = '';
                     if ('true' == $args['display_title'] || 1 == $args['display_title']) {
                         $title = get_the_title(get_the_ID());
                         if (('true' == $args['link_slide'] || 1 == $args['link_slide']) && '' != $wooslider_url) {
                             $title = '<a href="' . esc_url($wooslider_url) . '">' . $title . '</a>';
                         }
                         $title = '<h2 class="slide-title">' . $title . '</h2>';
                     }
                     $content = '';
                     if ('true' == $args['display_content'] || 1 == $args['display_content']) {
                         $content = wpautop(apply_filters('wooslider_slides_excerpt', get_the_content()));
                     }
                     if ('true' == $args['display_content'] || 1 == $args['display_content'] || ('true' == $args['display_title'] || 1 == $args['display_title'])) {
                         $content = '<div class="slide-excerpt">' . $title . $content . '</div>';
                         if ($args['layout'] == 'text-top') {
                             $content = $content . $image;
                         } else {
                             $content = $image . $content;
                         }
                     } else {
                         $content = $image;
                     }
                     $layed_out_content = apply_filters('wooslider_slides_layout_html', $content, $args, $post);
                     // If there is an image, add "has-featured-image" class
                     if ('' != $image) {
                         $class .= ' has-featured-image';
                     }
                     $content = '<div class="slide-content ' . esc_attr($class) . '">' . $layed_out_content . '</div>';
                     $data = array('content' => $content);
                 } else {
                     $content = apply_filters('wooslider_slides_content', get_the_content());
                     $data = array('content' => '<div class="slide-content">' . "\n" . apply_filters('wooslider_slide_content_slides', $content, $args) . "\n" . '</div>' . "\n");
                 }
             }
             if ('true' == $args['thumbnails'] || 1 == $args['thumbnails'] || 2 == $args['thumbnails'] || 'carousel' == $args['thumbnails'] || 'thumbnails' == $args['thumbnails']) {
                 $thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium');
                 if (!is_bool($thumb_url) && isset($thumb_url[0])) {
                     $data['attributes'] = array('data-thumb' => esc_url($thumb_url[0]));
                 } else {
                     $data['attributes'] = array('data-thumb' => esc_url(WooSlider_Utils::get_placeholder_image()));
                 }
             }
             $post_meta = get_post_custom(get_the_ID());
             foreach ($post_meta as $meta => $value) {
                 if ('_oembed' == substr(trim($meta), 0, 7)) {
                     if (preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $value[0], $match)) {
                         $has_video['youtube'] = true;
                         add_filter('wooslider_callback_start_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_youtube_start'));
                         add_filter('wooslider_callback_before_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_youtube_before'));
                     }
                     if (preg_match('#(?:https?:\\/\\/(?:[\\w]+\\.)*vimeo\\.com(?:[\\/\\w]*\\/videos?)?\\/([0-9]+)[^\\s]*)#i', $value[0], $match)) {
                         $has_video['vimeo'] = true;
                         add_filter('wooslider_callback_start_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_vimeo_start'));
                         add_filter('wooslider_callback_before_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_vimeo_before'));
                     }
                     if (preg_match('%(?:https?:\\/\\/(?:.+)?(?:wistia.com|wi.st|wistia.net)\\/(?:medias|embed)?\\/)(.*)%i', $value[0], $match)) {
                         $has_video['wistia'] = true;
                         add_filter('wooslider_callback_before_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_wistia_before'));
                     }
                 }
             }
             $data['video'] = $has_video;
             // add the post id to the list the slide
             $data['ID'] = $post->ID;
             $slides[] = $data;
         }
         wp_reset_postdata();
     }
     return $slides;
 }