Base.class.php
5 years ago
View.Slide.UPCP.class.php
4 years ago
View.Slide.URP.class.php
4 years ago
View.Slide.WooCommerce.class.php
4 years ago
View.Slide.class.php
4 years ago
View.Slider.class.php
4 years ago
View.class.php
4 years ago
View.Slider.class.php
345 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class to display a slider on the front end. |
| 5 | * |
| 6 | * @since 2.0.0 |
| 7 | */ |
| 8 | class ewdusViewSlider extends ewdusView { |
| 9 | |
| 10 | /** |
| 11 | * Define the the slides for this slider |
| 12 | * |
| 13 | * @since 2.0.0 |
| 14 | */ |
| 15 | public function get_slides() { |
| 16 | |
| 17 | $this->slides = array(); |
| 18 | |
| 19 | if ( $this->slider_type == 'woocommerce' ) { |
| 20 | |
| 21 | $args = array( |
| 22 | 'posts_per_page' => $posts, |
| 23 | 'post_type' => 'product', |
| 24 | 'product_cat' => $category, |
| 25 | 'orderby' => 'rand', |
| 26 | ); |
| 27 | |
| 28 | $slider_query = new WP_Query( $args ); |
| 29 | |
| 30 | while ( $slider_query->have_posts() ) : $slider_query->the_post(); |
| 31 | |
| 32 | $post = get_post(); |
| 33 | |
| 34 | $this->slides[] = new ewdusViewSlideWooCommerce( $post ); |
| 35 | |
| 36 | endwhile; |
| 37 | |
| 38 | wp_reset_query(); |
| 39 | } |
| 40 | |
| 41 | elseif ( $this->slider_type == 'upcp' ) { |
| 42 | |
| 43 | $args = array( |
| 44 | 'posts_per_page' => $this->posts, |
| 45 | 'post_type' => 'upcp_product', |
| 46 | 'product_cat' => $this->category, |
| 47 | 'orderby' => 'rand' |
| 48 | ); |
| 49 | |
| 50 | $slider_query = new WP_Query( $args ); |
| 51 | |
| 52 | while ( $slider_query->have_posts() ) : $slider_query->the_post(); |
| 53 | |
| 54 | $post = get_post(); |
| 55 | |
| 56 | $this->slides[] = new ewdusViewSlideUPCP( $post ); |
| 57 | |
| 58 | endwhile; |
| 59 | |
| 60 | wp_reset_query(); |
| 61 | } |
| 62 | |
| 63 | elseif ( $this->slider_type == 'urp' ) { |
| 64 | |
| 65 | $post__in = explode( ',', $this->post__in_string ); |
| 66 | |
| 67 | $args = array( |
| 68 | 'posts_per_page' => $this->posts, |
| 69 | 'post_type' => 'urp_review', |
| 70 | 'post__in' => $post__in |
| 71 | ); |
| 72 | |
| 73 | $slider_query = new WP_Query( $args ); |
| 74 | |
| 75 | while ( $slider_query->have_posts() ) : $slider_query->the_post(); |
| 76 | |
| 77 | $post = get_post(); |
| 78 | |
| 79 | $this->slides[] = new ewdusViewSlideURP( $post ); |
| 80 | |
| 81 | endwhile; |
| 82 | |
| 83 | wp_reset_query(); |
| 84 | |
| 85 | } |
| 86 | |
| 87 | elseif ( $this->post__in_string != '' ) { |
| 88 | |
| 89 | $post__in = explode( ',', $this->post__in_string ); |
| 90 | |
| 91 | $args = array( |
| 92 | 'posts' => $this->posts, |
| 93 | 'post_type' => 'attachment', |
| 94 | 'post_status' => array( 'publish', 'inherit' ), |
| 95 | 'post__in' => $post__in |
| 96 | ); |
| 97 | |
| 98 | $slider_query = new WP_Query( $args ); |
| 99 | |
| 100 | while ( $slider_query->have_posts() ) : $slider_query->the_post(); |
| 101 | |
| 102 | $post = get_post(); |
| 103 | |
| 104 | $this->slides[] = new ewdusViewSlide( $post ); |
| 105 | |
| 106 | endwhile; |
| 107 | |
| 108 | wp_reset_query(); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | else { |
| 113 | |
| 114 | $args = array( |
| 115 | 'posts_per_page' => $this->posts, |
| 116 | 'post_type' => EWD_US_SLIDER_POST_TYPE, |
| 117 | 'ultimate_slider_categories' => $this->category, |
| 118 | 'meta_key' => 'EWD_US_Slide_Order', |
| 119 | 'orderby' => 'meta_value_num', |
| 120 | 'order' => 'ASC', |
| 121 | ); |
| 122 | |
| 123 | $slider_query = new WP_Query( $args ); |
| 124 | |
| 125 | while ( $slider_query->have_posts() ) : $slider_query->the_post(); |
| 126 | |
| 127 | $post = get_post(); |
| 128 | |
| 129 | $content_type = get_post_meta( $post->ID, "EWD_US_Content_Type", true ); |
| 130 | |
| 131 | if ( $content_type == 'upcp_product' ) { |
| 132 | |
| 133 | $this->slides[] = new ewdusViewSlideUPCP( $post ); |
| 134 | } |
| 135 | elseif ( $content_type == 'woocommerce_product' ) { |
| 136 | |
| 137 | $this->slides[] = new ewdusViewSlideWooCommerce( $post ); |
| 138 | } |
| 139 | elseif ( $content_type == 'urp_review' ) { |
| 140 | |
| 141 | $this->slides[] = new ewdusViewSlideURP( $post ); |
| 142 | } |
| 143 | else { |
| 144 | |
| 145 | $this->slides[] = new ewdusViewSlide( $post ); |
| 146 | } |
| 147 | |
| 148 | endwhile; |
| 149 | |
| 150 | wp_reset_query(); |
| 151 | |
| 152 | } |
| 153 | |
| 154 | $this->slides = apply_filters( 'ewd_us_slides', $this->slides ); |
| 155 | |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Render the view and enqueue required stylesheets |
| 160 | * @since 2.0.0 |
| 161 | */ |
| 162 | public function render() { |
| 163 | global $ewd_us_controller; |
| 164 | |
| 165 | $this->get_slides(); |
| 166 | if ( ! count( $this->slides ) ) { |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | // Set attribute-alterable options |
| 171 | $this->set_slider_options(); |
| 172 | |
| 173 | // Add any dependent stylesheets or javascript |
| 174 | $this->enqueue_assets(); |
| 175 | |
| 176 | // Add css classes to the slider |
| 177 | $this->classes = $this->slider_classes(); |
| 178 | |
| 179 | ob_start(); |
| 180 | $this->add_custom_styling(); |
| 181 | $template = $this->find_template( 'slider' ); |
| 182 | if ( $template ) { |
| 183 | include( $template ); |
| 184 | } |
| 185 | $output = ob_get_clean(); |
| 186 | |
| 187 | return apply_filters( 'ewd_us_slider_output', $output, $this ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Print the slides in the slider |
| 192 | * |
| 193 | * @since 2.0.0 |
| 194 | */ |
| 195 | public function print_slides() { |
| 196 | |
| 197 | $output = ''; |
| 198 | |
| 199 | foreach ( $this->slides as $slide_count => $slide ) { |
| 200 | |
| 201 | $slide->set_slide_count( $slide_count ); |
| 202 | $output .= $slide->render(); |
| 203 | } |
| 204 | |
| 205 | return $output; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Print the arrows that increment and decrement slides in the slider |
| 210 | * |
| 211 | * @since 2.0.0 |
| 212 | */ |
| 213 | public function print_slide_arrows() { |
| 214 | |
| 215 | $template = $this->find_template( 'slide-arrows' ); |
| 216 | |
| 217 | if ( $template ) { |
| 218 | include( $template ); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Print the indicators (dots, thumbnails, etc.) for slides in the slider |
| 224 | * |
| 225 | * @since 2.0.0 |
| 226 | */ |
| 227 | public function print_slide_indicators() { |
| 228 | global $ewd_us_controller; |
| 229 | |
| 230 | if ( $ewd_us_controller->settings->get_setting( 'slide-indicators') == 'dots' ) { $template = $this->find_template( 'slide-indicators-dots' ); } |
| 231 | elseif ( $ewd_us_controller->settings->get_setting( 'slide-indicators') == 'thumbnails' ) { $template = $this->find_template( 'slide-indicators-thumbnails' ); } |
| 232 | elseif ( $ewd_us_controller->settings->get_setting( 'slide-indicators') == 'sidethumbnails' ) { $template = $this->find_template( 'slide-indicators-sidethumbnails' ); } |
| 233 | else { $template = false; } |
| 234 | |
| 235 | if ( $template ) { |
| 236 | include( $template ); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Print the selected arrow letter (or default) |
| 242 | * |
| 243 | * @since 2.0.0 |
| 244 | */ |
| 245 | public function print_selected_arrow( $direction = 'left' ) { |
| 246 | global $ewd_us_controller; |
| 247 | |
| 248 | return $direction == 'left' ? $ewd_us_controller->settings->get_setting( 'arrow' ) : chr( ord( $ewd_us_controller->settings->get_setting( 'arrow' ) ) + 1 ); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Print the class for the selected arrow background shape |
| 253 | * |
| 254 | * @since 2.0.0 |
| 255 | */ |
| 256 | public function print_arrow_shape_class() { |
| 257 | global $ewd_us_controller; |
| 258 | |
| 259 | return 'ewd-us-arrow-background-shape-' . $ewd_us_controller->settings->get_setting( 'arrow-background-shape' ); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Add in default options if not overwritten by shortcode attributes |
| 264 | * |
| 265 | * @since 2.0.0 |
| 266 | */ |
| 267 | public function set_slider_options() { |
| 268 | global $ewd_us_controller; |
| 269 | |
| 270 | $this->timer_bar = $this->timer_bar == 'No' ? false : $ewd_us_controller->settings->get_setting( 'timer-bar' ); |
| 271 | $this->carousel = $this->carousel == 'Yes' ? true : $ewd_us_controller->settings->get_setting( 'carousel' ); |
| 272 | $this->slide_indicators = $this->slide_indicators ? strtolower( $this->slide_indicators ) : $ewd_us_controller->settings->get_setting( 'slide-indicators' ); |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Get the initial slider css classes |
| 277 | * @since 2.0.0 |
| 278 | */ |
| 279 | public function slider_classes( $classes = array() ) { |
| 280 | global $ewd_us_controller; |
| 281 | |
| 282 | $classes = array_merge( |
| 283 | $classes, |
| 284 | array( |
| 285 | 'ewd-us-slider', |
| 286 | 'ewd-us-slider-slide-indicators-' . $ewd_us_controller->settings->get_setting( 'slide-indicators' ), |
| 287 | ) |
| 288 | ); |
| 289 | |
| 290 | foreach ( $ewd_us_controller->settings->get_setting( 'hide-from-slider' ) as $slider_item ) { $classes[] = 'ewd-us-slider-hide-' . $slider_item; } |
| 291 | foreach ( $ewd_us_controller->settings->get_setting( 'hide-on-mobile' ) as $slider_item ) { $classes[] = 'ewd-us-slider-mobile-hide-' . $slider_item; } |
| 292 | |
| 293 | if ( $this->carousel ) { $classes[] = 'ewd-us-carousel'; } |
| 294 | |
| 295 | return apply_filters( 'ewd_us_slider_classes', $classes, $this ); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Enqueue the necessary CSS and JS files |
| 300 | * @since 2.0.0 |
| 301 | */ |
| 302 | public function enqueue_assets() { |
| 303 | global $ewd_us_controller; |
| 304 | |
| 305 | wp_enqueue_script( 'jquery-ui-core' ); |
| 306 | wp_enqueue_script( 'jquery-effects-slide' ); |
| 307 | wp_enqueue_script( 'ewd-us-js' ); |
| 308 | wp_enqueue_script( 'iframe-clicks' ); |
| 309 | |
| 310 | $aspect_fraction = ewd_us_get_aspect_fraction( $ewd_us_controller->settings->get_setting( 'aspect-ratio' ) ); |
| 311 | $mobile_aspect_fraction = ewd_us_get_aspect_fraction( $ewd_us_controller->settings->get_setting( 'mobile-aspect-ratio' ) ); |
| 312 | |
| 313 | $slider_data = array( |
| 314 | 'autoplay_slideshow' => $ewd_us_controller->settings->get_setting( 'autoplay-slideshow' ), |
| 315 | 'autoplay_delay' => substr( $ewd_us_controller->settings->get_setting( 'autoplay-delay' ), 0, strpos( $ewd_us_controller->settings->get_setting( 'autoplay-delay' ), '_' ) ), |
| 316 | 'autoplay_interval' => substr( $ewd_us_controller->settings->get_setting( 'autoplay-interval' ), 0, strpos( $ewd_us_controller->settings->get_setting( 'autoplay-delay' ), '_' ) ), |
| 317 | 'slide_transition_effect' => $ewd_us_controller->settings->get_setting( 'slide-transition-effect' ), |
| 318 | 'transition_time' => substr( $ewd_us_controller->settings->get_setting( 'transition-time' ), 0, strpos( $ewd_us_controller->settings->get_setting( 'autoplay-delay' ), '_' ) ), |
| 319 | 'aspect_ratio' => $aspect_fraction, |
| 320 | 'mobile_aspect_ratio' => $mobile_aspect_fraction, |
| 321 | 'slider_carousel' => $ewd_us_controller->settings->get_setting( 'carousel' ), |
| 322 | 'carousel_columns' => $ewd_us_controller->settings->get_setting( 'carousel-columns' ), |
| 323 | 'carousel_link_to_full' => $ewd_us_controller->settings->get_setting( 'carousel-link-to-full' ), |
| 324 | 'carousel_advance' => $ewd_us_controller->settings->get_setting( 'carousel-advance' ), |
| 325 | 'title_animate' => $ewd_us_controller->settings->get_setting( 'title-animate' ), |
| 326 | 'lightbox' => $ewd_us_controller->settings->get_setting( 'lightbox' ), |
| 327 | 'timer_bar' => $ewd_us_controller->settings->get_setting( 'timer-bar' ), |
| 328 | 'force_full_width' => $ewd_us_controller->settings->get_setting( 'force-full-width' ), |
| 329 | 'autoplay_pause_hover' => $ewd_us_controller->settings->get_setting( 'autoplay-pause-hover' ) |
| 330 | ); |
| 331 | |
| 332 | wp_localize_script( 'ewd-us-js', 'ewd_us_php_data', $slider_data ); |
| 333 | |
| 334 | wp_enqueue_style( 'ewd-us-css' ); |
| 335 | |
| 336 | if ( $ewd_us_controller->settings->get_setting( 'lightbox' ) ) { |
| 337 | |
| 338 | wp_enqueue_script( 'ultimate-lightbox' ); |
| 339 | |
| 340 | wp_enqueue_style( 'ewd-ulb-main' ); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | } |
| 345 |