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