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.Slide.class.php
222 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class to display a slide in the slider on the front end. |
| 5 | * |
| 6 | * @since 2.0.0 |
| 7 | */ |
| 8 | class ewdusViewSlide extends ewdusView { |
| 9 | |
| 10 | // Set default content for a blank slide |
| 11 | public $title = ''; |
| 12 | public $filtered_content = ''; |
| 13 | public $image_url = EWD_US_PLUGIN_URL . '/assets/img/Black_Background.png'; |
| 14 | public $buttons = array(); |
| 15 | |
| 16 | /** |
| 17 | * Get the content (image, title, etc.) of the slide |
| 18 | * |
| 19 | * @since 2.0.0 |
| 20 | */ |
| 21 | public function get_slide_content() { |
| 22 | |
| 23 | if ( empty( $this->ID ) ) { return; } |
| 24 | |
| 25 | $this->title = $this->post_title; |
| 26 | $this->filtered_content = str_replace( ']]>', ']]>', apply_filters( 'the_content', $this->post_content ) ); |
| 27 | $this->post_thumbnail_id = get_post_thumbnail_id( $this->ID ); |
| 28 | |
| 29 | if ( $this->image_type == 'youtube_video' ) { $this->image_url = $this->get_youtube_image_url(); } |
| 30 | else { $this->image_url = $this->post_thumbnail_id ? wp_get_attachment_url( $this->post_thumbnail_id ) : $this->image_url; } |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Render the view |
| 35 | * @since 2.0.0 |
| 36 | */ |
| 37 | public function render() { |
| 38 | global $ewd_us_controller; |
| 39 | |
| 40 | $this->set_slide_specific_variables(); |
| 41 | |
| 42 | $this->get_slide_content(); |
| 43 | |
| 44 | $this->prep_slide_for_display(); |
| 45 | |
| 46 | // Add css classes to the slide |
| 47 | $this->classes = $this->slide_classes(); |
| 48 | |
| 49 | ob_start(); |
| 50 | |
| 51 | if ( $this->image_type == 'youtube_video' ) { $template = $this->find_template( 'slide-video' ); } |
| 52 | else { $template = $this->find_template( 'slide' ); } |
| 53 | |
| 54 | if ( $template ) { |
| 55 | include( $template ); |
| 56 | } |
| 57 | $output = ob_get_clean(); |
| 58 | |
| 59 | return apply_filters( 'ewd_us_slide_output', $output, $this ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Set the order this slide is being displayed in for the slider |
| 64 | * @since 2.0.0 |
| 65 | */ |
| 66 | public function set_slide_count( $slide_count ) { |
| 67 | |
| 68 | $this->slide_count = intval( $slide_count ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Apply max title and body chars, create watermark image if necessary |
| 73 | * @since 2.0.0 |
| 74 | */ |
| 75 | public function prep_slide_for_display() { |
| 76 | global $ewd_us_controller; |
| 77 | |
| 78 | $this->title = $this->max_title_chars ? substr( $this->title, 0, $this->max_title_chars ) : $this->title; |
| 79 | $this->filtered_content = $this->max_body_chars ? substr( $this->filtered_content, 0, $this->max_body_chars ) : $this->filtered_content; |
| 80 | |
| 81 | if ( $ewd_us_controller->settings->get_setting( 'add-watermark' ) and $this->image_type != 'youtube_video' ) { |
| 82 | |
| 83 | $this->image_url = $this->get_watermarked_image(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Return the lightbox attributes for the slide, if lightbox enabled |
| 89 | * @since 2.0.0 |
| 90 | */ |
| 91 | public function print_lightbox_data() { |
| 92 | global $ewd_us_controller; |
| 93 | |
| 94 | if ( ! $ewd_us_controller->settings->get_setting( 'lightbox' ) ) { return; } |
| 95 | |
| 96 | return 'data-ulbsource="' . esc_attr( $this->image_url ) . '" data-ulbtitle="' . esc_attr( $this->title ) . '" data-ulbdescription="' . esc_attr( $this->filtered_content ) . '"'; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Return the code to diplay a YouTube video slide |
| 101 | * @since 2.0.0 |
| 102 | */ |
| 103 | public function print_youtube_video_code() { |
| 104 | global $ewd_us_controller; |
| 105 | |
| 106 | if ( $ewd_us_controller->settings->get_setting( 'youtube-autoplay-video' ) ) { |
| 107 | $youtube_autoplay = '&autoplay=1'; |
| 108 | } |
| 109 | else { |
| 110 | $youtube_autoplay = ''; |
| 111 | } |
| 112 | |
| 113 | if ( ! $this->youtube_url ) { return; } |
| 114 | |
| 115 | if ( empty( $this->youtube_video_id ) ) { $this->set_youtube_video_id(); } |
| 116 | |
| 117 | return '<iframe class="ewd-us-video" width="640" height="360" src="https://www.youtube.com/embed/' . $this->youtube_video_id . '?rel=0&fs=1' . $youtube_autoplay . '&mute=1&controls=0" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Return the link for a slide button |
| 122 | * @since 2.0.0 |
| 123 | */ |
| 124 | public function get_button_link( $button ) { |
| 125 | |
| 126 | return ! $button['Post_ID'] ? $button['Custom_Link'] : get_permalink( $button['Post_ID'] ); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Return the link target for a slide button |
| 131 | * @since 2.0.0 |
| 132 | */ |
| 133 | public function get_button_link_target_text( $button ) { |
| 134 | global $ewd_us_controller; |
| 135 | |
| 136 | if ( $ewd_us_controller->settings->get_setting( 'link-action' ) == 'same' ) { return; } |
| 137 | elseif ( $ewd_us_controller->settings->get_setting( 'link-action' ) == 'smart' and strpos( $this->get_button_link( $button ), get_site_url() ) !== false ) { return; } |
| 138 | |
| 139 | return 'target="_blank"'; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Return the URL for the preview image of a YouTube video |
| 144 | * @since 2.0.0 |
| 145 | */ |
| 146 | public function get_youtube_image_url() { |
| 147 | |
| 148 | if ( ! $this->youtube_url ) { return; } |
| 149 | |
| 150 | if ( empty( $this->youtube_video_id ) ) { $this->set_youtube_video_id(); } |
| 151 | |
| 152 | return 'http://img.youtube.com/vi/' . $this->youtube_video_id . '/default.jpg'; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Determine the ID of a YouTube video |
| 157 | * @since 2.0.0 |
| 158 | */ |
| 159 | public function set_youtube_video_id() { |
| 160 | |
| 161 | preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $this->youtube_url, $matches); |
| 162 | |
| 163 | $this->youtube_video_id = $matches[0]; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Set the variables (max title chars, max body chars, etc.) specific to this slide |
| 168 | * @since 2.0.0 |
| 169 | */ |
| 170 | public function set_slide_specific_variables() { |
| 171 | |
| 172 | $this->max_title_chars = get_post_meta( $this->ID, 'EWD_US_Max_Title_Chars', true ); |
| 173 | $this->max_body_chars = get_post_meta( $this->ID, 'EWD_US_Max_Body_Chars', true ); |
| 174 | $this->image_type = get_post_meta( $this->ID, "EWD_US_Image_Type", true ); |
| 175 | $this->youtube_url = get_post_meta( $this->ID, "EWD_US_YouTube_URL", true ); |
| 176 | $this->buttons = get_post_meta( $this->ID, "EWD_US_Buttons", true ) ? get_post_meta( $this->ID, "EWD_US_Buttons", true ) : $this->buttons; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Create watermarked image if necessary and return watermarked image URL |
| 181 | * @since 2.0.0 |
| 182 | */ |
| 183 | public function get_watermarked_image() { |
| 184 | |
| 185 | $upload_dir = wp_upload_dir(); |
| 186 | $plugin_upload_dir = $upload_dir['baseurl'] . "/ultimate-slider/"; |
| 187 | |
| 188 | if ( ! file_exists($plugin_upload_dir . basename( $this->image_url ) ) ) { |
| 189 | |
| 190 | ewd_us_create_watermarked_image( $this->image_url ); |
| 191 | } |
| 192 | |
| 193 | $watermarked_image_url = $plugin_upload_dir . basename( $this->image_url ); |
| 194 | |
| 195 | return $watermarked_image_url; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Get the initial slide css classes |
| 200 | * @since 2.0.0 |
| 201 | */ |
| 202 | public function slide_classes( $classes = array() ) { |
| 203 | global $ewd_us_controller; |
| 204 | |
| 205 | $classes = array_merge( |
| 206 | $classes, |
| 207 | array( |
| 208 | 'ewd-us-slide', |
| 209 | ) |
| 210 | ); |
| 211 | |
| 212 | if ( $this->slide_count !== 0 ) { $classes[] = 'ewd-us-hidden'; } |
| 213 | |
| 214 | if ( $this->image_type == 'youtube_video' ) { $classes[] = 'ewd-us-video'; } |
| 215 | |
| 216 | if ( $ewd_us_controller->settings->get_setting( 'lightbox' ) ) { $classes[] = 'ewd-ulb-lightbox'; } |
| 217 | |
| 218 | return apply_filters( 'ewd_us_slide_classes', $classes, $this ); |
| 219 | } |
| 220 | |
| 221 | } |
| 222 |