Пример #1
0
 /**
  * Creates the shortcode for the plugin.
  *
  * @since 1.0.0
  *
  * @global object $post The current post object.
  *
  * @param array $atts Array of shortcode attributes.
  * @return string     The slider output.
  */
 public function shortcode($atts)
 {
     global $post;
     // If no attributes have been passed, the slider should be pulled from the current post.
     $slider_id = false;
     if (empty($atts)) {
         $slider_id = $post->ID;
         $data = is_preview() ? $this->base->_get_slider($slider_id) : $this->base->get_slider($slider_id);
     } else {
         if (isset($atts['id'])) {
             $slider_id = (int) $atts['id'];
             $data = is_preview() ? $this->base->_get_slider($slider_id) : $this->base->get_slider($slider_id);
         } else {
             if (isset($atts['slug'])) {
                 $slider_id = $atts['slug'];
                 $data = is_preview() ? $this->base->_get_slider_by_slug($slider_id) : $this->base->get_slider_by_slug($slider_id);
             } else {
                 // A custom attribute must have been passed. Allow it to be filtered to grab data from a custom source.
                 $data = apply_filters('soliloquy_custom_slider_data', false, $atts, $post);
             }
         }
     }
     // If there is no data and the attribute used is an ID, try slug as well.
     if (!$data && isset($atts['id'])) {
         $slider_id = $atts['id'];
         $data = is_preview() ? $this->base->_get_slider_by_slug($slider_id) : $this->base->get_slider_by_slug($slider_id);
     }
     // Allow the data to be filtered before it is stored and used to create the slider output.
     $data = apply_filters('soliloquy_pre_data', $data, $slider_id);
     // If there is no data to output or the slider is inactive, do nothing.
     if (!$data || empty($data['slider']) || isset($data['status']) && 'inactive' == $data['status'] && !is_preview()) {
         return false;
     }
     // If the data is to be randomized, do it now.
     if ($this->get_config('random', $data)) {
         $data = $this->shuffle($data);
     }
     // Prepare variables.
     $this->data[$data['id']] = $data;
     $this->index[$data['id']] = array();
     $slider = '';
     $i = 1;
     // If this is a feed view, customize the output and return early.
     if (is_feed()) {
         return $this->do_feed_output($data);
     }
     // Load scripts
     wp_enqueue_script($this->base->plugin_slug . '-script');
     // Load custom slider themes if necessary.
     if ('base' !== $this->get_config('slider_theme', $data)) {
         $this->load_slider_theme($this->get_config('slider_theme', $data));
     }
     // Load CSS
     $this->get_stylesheets($data);
     // Load slider init code in the footer.
     add_action('wp_footer', array($this, 'slider_init'), 1000);
     // Run a hook before the slider output begins but after scripts and inits have been set.
     do_action('soliloquy_before_output', $data);
     // Apply a filter before starting the slider HTML.
     $slider = apply_filters('soliloquy_output_start', $slider, $data);
     // If mobile is set, add the filter to add in a mobile src attribute.
     if ($this->get_config('mobile', $data)) {
         add_filter('soliloquy_output_image_attr', array($this, 'mobile_image'), 999, 4);
     }
     // If positioning is set, add the filter to add the custom positioning style.
     if ($this->get_config('position', $data)) {
         add_filter('soliloquy_output_container_style', array($this, 'position_slider'), 999, 2);
     }
     // If using the full width option, run a special setting on the width/height.
     if ('full_width' == $this->get_config('slider_size', $data)) {
         add_filter('soliloquy_output_container_style', array($this, 'full_width'), 999, 2);
     }
     // Build out the slider HTML.
     $slider .= '<div id="soliloquy-container-' . sanitize_html_class($data['id']) . '" class="' . $this->get_slider_classes($data) . '" style="max-width:' . $this->get_config('slider_width', $data) . 'px;max-height:' . $this->get_config('slider_height', $data) . 'px;' . apply_filters('soliloquy_output_container_style', '', $data) . '"' . apply_filters('soliloquy_output_container_attr', '', $data) . '>';
     $slider .= '<ul id="soliloquy-' . sanitize_html_class($data['id']) . '" class="soliloquy-slider soliloquy-slides soliloquy-wrap soliloquy-clear">';
     $slider = apply_filters('soliloquy_output_before_container', $slider, $data);
     foreach ((array) $data['slider'] as $id => $item) {
         // Skip over images that are pending (ignore if in Preview mode).
         if (isset($item['status']) && 'pending' == $item['status'] && !is_preview()) {
             continue;
         }
         // Allow filtering of individual items.
         $item = apply_filters('soliloquy_output_item_data', $item, $id, $data, $i);
         $slider = apply_filters('soliloquy_output_before_item', $slider, $id, $item, $data, $i);
         $output = '<li class="' . $this->get_slider_item_classes($item, $i, $data) . '"' . apply_filters('soliloquy_output_item_attr', '', $id, $item, $data, $i) . ' draggable="false" style="' . apply_filters('soliloquy_output_item_style', 'list-style:none;', $id, $item, $data, $i) . '">';
         $output .= $this->get_slide($id, $item, $data, $i);
         $output .= '</li>';
         $output = apply_filters('soliloquy_output_single_item', $output, $id, $item, $data, $i);
         $slider .= $output;
         $slider = apply_filters('soliloquy_output_after_item', $slider, $id, $item, $data, $i);
         // Increment the iterator.
         $i++;
     }
     $slider = apply_filters('soliloquy_output_after_container', $slider, $data);
     $slider .= '</ul>';
     $slider = apply_filters('soliloquy_output_end', $slider, $data);
     $slider .= '</div>';
     // Increment the counter.
     $this->counter++;
     // Remove any contextual filters so they don't affect other sliders on the page.
     if ($this->get_config('mobile', $data)) {
         remove_filter('soliloquy_output_image_attr', array($this, 'mobile_image'), 999, 4);
     }
     if ($this->get_config('position', $data)) {
         remove_filter('soliloquy_output_container_style', array($this, 'position_slider'), 999, 2);
     }
     if ('full_width' == $this->get_config('slider_size', $data)) {
         remove_filter('soliloquy_output_container_style', array($this, 'full_width'), 999, 2);
     }
     // Add no JS fallback support.
     $no_js_css = '<style type="text/css">#soliloquy-container-' . sanitize_html_class($data['id']) . '{opacity:1}#soliloquy-container-' . sanitize_html_class($data['id']) . ' li > .soliloquy-caption{display:none}#soliloquy-container-' . sanitize_html_class($data['id']) . ' li:first-child > .soliloquy-caption{display:block}</style>';
     $no_js = '<noscript>';
     $no_js .= apply_filters('soliloquy_output_no_js', $no_js_css, $data);
     $index = $this->get_indexable_images($data['id']);
     $no_js .= '<div class="soliloquy-no-js" style="display:none;visibility:hidden;height:0;line-height:0;opacity:0;">' . $index . '</div>';
     $no_js .= '</noscript>';
     $slider .= $no_js;
     // Return the slider HTML.
     return apply_filters('soliloquy_output', $slider, $data);
 }
Пример #2
0
 /**
  * Creates the shortcode for the plugin.
  *
  * @since 1.0.0
  *
  * @global object $post The current post object.
  *
  * @param array $atts Array of shortcode attributes.
  * @return string     The slider output.
  */
 public function shortcode($atts)
 {
     global $post;
     // If no attributes have been passed, the slider should be pulled from the current post.
     $slider_id = false;
     if (empty($atts)) {
         $slider_id = $post->ID;
         $data = is_preview() ? $this->base->_get_slider($slider_id) : $this->base->get_slider($slider_id);
     } else {
         if (isset($atts['id'])) {
             $slider_id = (int) $atts['id'];
             $data = is_preview() ? $this->base->_get_slider($slider_id) : $this->base->get_slider($slider_id);
         } else {
             if (isset($atts['slug'])) {
                 $slider_id = $atts['slug'];
                 $data = is_preview() ? $this->base->_get_slider_by_slug($slider_id) : $this->base->get_slider_by_slug($slider_id);
             } else {
                 // A custom attribute must have been passed. Allow it to be filtered to grab data from a custom source.
                 $data = apply_filters('soliloquy_custom_slider_data', false, $atts, $post);
             }
         }
     }
     // If there is no data and the attribute used is an ID, try slug as well.
     if (!$data && isset($atts['id'])) {
         $slider_id = $atts['id'];
         $data = is_preview() ? $this->base->_get_slider_by_slug($slider_id) : $this->base->get_slider_by_slug($slider_id);
     }
     // Allow the data to be filtered before it is stored and used to create the slider output.
     $data = apply_filters('soliloquy_pre_data', $data, $slider_id);
     // If there is no data to output or the slider is inactive, do nothing.
     if (!$data || empty($data['slider']) || isset($data['status']) && 'inactive' == $data['status'] && !is_preview()) {
         return false;
     }
     // If the data is to be randomized, do it now.
     if ($this->get_config('random', $data)) {
         $data = $this->shuffle($data);
     }
     // Prepare variables.
     $this->data[$data['id']] = $data;
     $slider = '';
     $i = 1;
     // If this is a feed view, customize the output and return early.
     if (is_feed()) {
         return $this->do_feed_output($data);
     }
     // Load scripts and styles.
     wp_enqueue_style($this->base->plugin_slug . '-style');
     wp_enqueue_script($this->base->plugin_slug . '-script');
     // Load custom slider themes if necessary.
     if ('base' !== $this->get_config('slider_theme', $data)) {
         $this->load_slider_theme($this->get_config('slider_theme', $data));
     }
     // Load slider init code in the footer.
     add_action('wp_footer', array($this, 'slider_init'), 1000);
     // Run a hook before the slider output begins but after scripts and inits have been set.
     do_action('soliloquy_before_output', $data);
     // Apply a filter before starting the slider HTML.
     $slider = apply_filters('soliloquy_output_start', $slider, $data);
     // Build out the slider HTML.
     $slider .= '<div aria-live="' . $this->get_config('aria_live', $data) . '" id="soliloquy-container-' . sanitize_html_class($data['id']) . '" class="' . $this->get_slider_classes($data) . '" style="max-width:' . $this->get_config('slider_width', $data) . 'px;max-height:' . $this->get_config('slider_height', $data) . 'px;' . apply_filters('soliloquy_output_container_style', '', $data) . '"' . apply_filters('soliloquy_output_container_attr', '', $data) . '>';
     $slider .= '<ul id="soliloquy-' . sanitize_html_class($data['id']) . '" class="soliloquy-slider soliloquy-slides soliloquy-wrap soliloquy-clear">';
     $slider = apply_filters('soliloquy_output_before_container', $slider, $data);
     foreach ((array) $data['slider'] as $id => $item) {
         // Skip over images that are pending (ignore if in Preview mode).
         if (isset($item['status']) && 'pending' == $item['status'] && !is_preview()) {
             continue;
         }
         // Allow filtering of individual items.
         $item = apply_filters('soliloquy_output_item_data', $item, $id, $data, $i);
         $slider = apply_filters('soliloquy_output_before_item', $slider, $id, $item, $data, $i);
         $output = '<li aria-hidden="true" class="' . $this->get_slider_item_classes($item, $i, $data) . '"' . apply_filters('soliloquy_output_item_attr', '', $id, $item, $data, $i) . ' draggable="false" style="list-style:none">';
         $output .= $this->get_slide($id, $item, $data, $i);
         $output .= '</li>';
         $output = apply_filters('soliloquy_output_single_item', $output, $id, $item, $data, $i);
         $slider .= $output;
         $slider = apply_filters('soliloquy_output_after_item', $slider, $id, $item, $data, $i);
         // Increment the iterator.
         $i++;
     }
     $slider = apply_filters('soliloquy_output_after_container', $slider, $data);
     $slider .= '</ul>';
     $slider = apply_filters('soliloquy_output_end', $slider, $data);
     $slider .= '</div>';
     // Increment the counter.
     $this->counter++;
     // Add no JS fallback support.
     $no_js = apply_filters('soliloquy_output_no_js', '<noscript><style type="text/css">#soliloquy-container-' . sanitize_html_class($data['id']) . '{opacity:1}</style></noscript>', $data);
     $slider .= $no_js;
     // Return the slider HTML.
     return apply_filters('soliloquy_output', $slider, $data);
 }