forms
5 days ago
wpr-ajax-search.php
5 days ago
wpr-filter-grid-media.php
5 days ago
wpr-form-handlers.php
5 days ago
wpr-grid-helpers.php
5 days ago
wpr-load-more-instagram-posts.php
5 days ago
wpr-load-more-tweets.php
5 days ago
wpr-post-likes.php
5 days ago
wpr-woo-grid-helpers.php
5 days ago
wpr-filter-grid-media.php
926 lines
| 1 | <?php |
| 2 | namespace WprAddons\Classes\Modules; |
| 3 | |
| 4 | use Elementor\Utils; |
| 5 | use Elementor\Group_Control_Image_Size; |
| 6 | use WprAddons\Classes\Utilities; |
| 7 | |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; // Exit if accessed directly. |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * WPR_Filter_Grid_Media setup |
| 15 | * |
| 16 | * @since 3.4.6 |
| 17 | */ |
| 18 | |
| 19 | class WPR_Filter_Grid_Media { |
| 20 | |
| 21 | public function __construct() { |
| 22 | add_action('wp_ajax_wpr_filter_grid_media', [$this, 'wpr_filter_grid_media']); |
| 23 | add_action('wp_ajax_nopriv_wpr_filter_grid_media', [$this, 'wpr_filter_grid_media']); |
| 24 | add_action('wp_ajax_wpr_get_media_filtered_count', [$this, 'wpr_get_media_filtered_count']); |
| 25 | add_action('wp_ajax_nopriv_wpr_get_media_filtered_count', [$this, 'wpr_get_media_filtered_count']); |
| 26 | } |
| 27 | |
| 28 | // Get Taxonomies Related to Post Type |
| 29 | public function get_related_taxonomies() { |
| 30 | $relations = []; |
| 31 | $post_types = Utilities::get_custom_types_of( 'post', false ); |
| 32 | |
| 33 | foreach ( $post_types as $slug => $title ) { |
| 34 | $relations[$slug] = []; |
| 35 | |
| 36 | foreach ( get_object_taxonomies( $slug ) as $tax ) { |
| 37 | array_push( $relations[$slug], $tax ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return json_encode( $relations ); |
| 42 | } |
| 43 | |
| 44 | // Get Max Pages |
| 45 | public function get_max_num_pages( $settings ) { |
| 46 | $query = new \WP_Query( $this->get_main_query_args() ); |
| 47 | $max_num_pages = intval( ceil( $query->max_num_pages ) ); |
| 48 | |
| 49 | $adjustedTotalPosts = max(0, $query->found_posts - $query->query_vars['offset']); // Ensuring it doesn't go below 0 |
| 50 | $numberOfPages = ceil($adjustedTotalPosts / $query->query_vars['posts_per_page']); |
| 51 | |
| 52 | wp_send_json_success([ |
| 53 | 'page_count' => $numberOfPages, |
| 54 | 'max_num_pages' => $max_num_pages, |
| 55 | 'query_found' => $query->found_posts, |
| 56 | 'query_offset' => $query->query_vars['offset'], |
| 57 | 'query_num' => $query->query_vars['posts_per_page'] |
| 58 | ]); |
| 59 | |
| 60 | // Reset |
| 61 | wp_reset_postdata(); |
| 62 | |
| 63 | // $max_num_pages |
| 64 | return $max_num_pages; |
| 65 | } |
| 66 | |
| 67 | // Main Query Args |
| 68 | public function get_main_query_args() { |
| 69 | $settings = $_POST['grid_settings']; |
| 70 | $taxonomy = $_POST['wpr_taxonomy']; |
| 71 | $term = $_POST['wpr_filter']; |
| 72 | $tax_query = []; |
| 73 | |
| 74 | $author = ! empty( $settings[ 'query_author' ] ) ? implode( ',', $settings[ 'query_author' ] ) : ''; |
| 75 | |
| 76 | // Get Paged |
| 77 | if ( get_query_var( 'paged' ) ) { |
| 78 | $paged = get_query_var( 'paged' ); |
| 79 | } elseif ( get_query_var( 'page' ) ) { |
| 80 | $paged = get_query_var( 'page' ); |
| 81 | } else { |
| 82 | $paged = 1; |
| 83 | } |
| 84 | |
| 85 | if ( empty($settings['query_offset']) ) { |
| 86 | $settings[ 'query_offset' ] = 0; |
| 87 | } |
| 88 | |
| 89 | $offset = ( $paged - 1 ) * $settings['query_posts_per_page'] + $settings[ 'query_offset' ]; |
| 90 | |
| 91 | if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) { |
| 92 | $settings[ 'query_randomize' ] = ''; |
| 93 | $settings['order_posts'] = 'date'; |
| 94 | } |
| 95 | |
| 96 | $query_order_by = '' != $settings['query_randomize'] ? $settings['query_randomize'] : $settings['order_posts']; |
| 97 | |
| 98 | if ( 'manual' === $settings[ 'query_selection' ] ) { |
| 99 | $query_order_by = 'post__in'; |
| 100 | } |
| 101 | |
| 102 | // Dynamic |
| 103 | $args = [ |
| 104 | 'post_type' => 'attachment', |
| 105 | 'post_status' => 'inherit', |
| 106 | 'post_mime_type' => 'image', |
| 107 | 'tax_query' => $this->get_tax_query_args(), |
| 108 | 'post__not_in' => $settings[ 'query_exclude_attachment' ], |
| 109 | 'posts_per_page' => $settings['query_posts_per_page'], |
| 110 | 'orderby' => $query_order_by, |
| 111 | 'author' => $author, |
| 112 | 'paged' => $paged, |
| 113 | 'offset' => $offset |
| 114 | ]; |
| 115 | |
| 116 | // Manual |
| 117 | if ( 'manual' === $settings[ 'query_selection' ] ) { |
| 118 | $post_ids = ['']; |
| 119 | |
| 120 | $attachments = $settings['query_manual_attachment']; |
| 121 | |
| 122 | $attachments_count = 0; |
| 123 | |
| 124 | if (!empty($attachments) ) { |
| 125 | $attachments_count = count($attachments); |
| 126 | } |
| 127 | |
| 128 | for ( $i = 0; $i < $attachments_count; $i++ ) { |
| 129 | array_push( $post_ids, $settings['query_manual_attachment'][$i]['id'] ); |
| 130 | } |
| 131 | |
| 132 | $orderby = '' === $settings[ 'query_randomize' ] ? 'post__in' : 'rand'; |
| 133 | |
| 134 | $args = [ |
| 135 | 'post_type' => 'attachment', |
| 136 | 'post_status' => 'inherit', |
| 137 | 'post__in' => $post_ids, |
| 138 | 'orderby' => $orderby, |
| 139 | 'paged' => $paged, |
| 140 | 'posts_per_page' => $settings['query_posts_per_page'], |
| 141 | 'paged' => $paged, |
| 142 | ]; |
| 143 | |
| 144 | if ( isset($_POST['wpr_offset']) ) { |
| 145 | $args['offset'] = $_POST['wpr_offset']; |
| 146 | } |
| 147 | |
| 148 | $tax_query = $this->get_tax_query_args(); |
| 149 | |
| 150 | if ( ! empty( $tax_query ) ) { |
| 151 | $args['tax_query'] = $tax_query; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if ( isset($_POST['wpr_offset']) ) { |
| 156 | $args['offset'] = $_POST['wpr_offset']; |
| 157 | } |
| 158 | |
| 159 | if ( 'rand' !== $query_order_by && 'manual' !== $settings['query_selection'] ) { |
| 160 | $args['order'] = $settings['order_direction']; |
| 161 | } |
| 162 | |
| 163 | return $args; |
| 164 | } |
| 165 | |
| 166 | // Taxonomy Query Args |
| 167 | public function get_tax_query_args() { |
| 168 | $settings = $_POST['grid_settings']; |
| 169 | $tax_query = []; |
| 170 | |
| 171 | // Add filter for selected taxonomy and term if they exist |
| 172 | if (!empty($_POST['wpr_taxonomy']) && !empty($_POST['wpr_filter']) && $_POST['wpr_filter'] !== 'all' && $_POST['wpr_taxonomy'] !== '*') { |
| 173 | $tax_query[] = [ |
| 174 | 'taxonomy' => sanitize_text_field($_POST['wpr_taxonomy']), |
| 175 | 'field' => 'slug', // Use slug instead of ID for attachments |
| 176 | 'terms' => sanitize_text_field($_POST['wpr_filter']), |
| 177 | ]; |
| 178 | |
| 179 | return $tax_query; // Return early with just the selected filter |
| 180 | } |
| 181 | |
| 182 | // Otherwise, use the default taxonomies from settings |
| 183 | $media_taxonomies = get_taxonomies(['object_type' => ['attachment']], 'names'); // Get custom attachment taxonomies |
| 184 | |
| 185 | foreach ($media_taxonomies as $tax) { |
| 186 | if (!empty($settings['query_taxonomy_' . $tax])) { |
| 187 | $tax_query[] = [ |
| 188 | 'taxonomy' => $tax, |
| 189 | 'field' => 'slug', // Ensure it's using slug |
| 190 | 'terms' => $settings['query_taxonomy_' . $tax], |
| 191 | ]; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return $tax_query; |
| 196 | } |
| 197 | |
| 198 | // Get Animation Class |
| 199 | public function get_animation_class( $data, $object ) { |
| 200 | $class = ''; |
| 201 | |
| 202 | // Animation Class |
| 203 | if ( 'none' !== $data[ $object .'_animation'] ) { |
| 204 | $class .= ' wpr-'. $object .'-'. $data[ $object .'_animation']; |
| 205 | $class .= ' wpr-anim-size-'. $data[ $object .'_animation_size']; |
| 206 | $class .= ' wpr-anim-timing-'. $data[ $object .'_animation_timing']; |
| 207 | |
| 208 | if ( 'yes' === $data[ $object .'_animation_tr'] ) { |
| 209 | $class .= ' wpr-anim-transparency'; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | return $class; |
| 214 | } |
| 215 | |
| 216 | // Get Image Effect Class |
| 217 | public function get_image_effect_class( $settings ) { |
| 218 | $class = ''; |
| 219 | |
| 220 | if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) { |
| 221 | if ( 'pro-zi' == $settings['image_effects'] || 'pro-zo' == $settings['image_effects'] || 'pro-go' == $settings['image_effects'] || 'pro-bo' == $settings['image_effects'] ) { |
| 222 | $settings['image_effects'] = 'none'; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Animation Class |
| 227 | if ( 'none' !== $settings['image_effects'] ) { |
| 228 | $class .= ' wpr-'. $settings['image_effects']; |
| 229 | } |
| 230 | |
| 231 | // Slide Effect |
| 232 | if ( 'slide' !== $settings['image_effects'] ) { |
| 233 | $class .= ' wpr-effect-size-'. $settings['image_effects_size']; |
| 234 | } else { |
| 235 | $class .= ' wpr-effect-dir-'. $settings['image_effects_direction']; |
| 236 | } |
| 237 | |
| 238 | return $class; |
| 239 | } |
| 240 | |
| 241 | // Render Post Thumbnail |
| 242 | public function render_post_thumbnail( $settings ) { |
| 243 | $id = get_the_ID(); |
| 244 | $src = Group_Control_Image_Size::get_attachment_image_src( $id, 'layout_image_crop', $settings ); |
| 245 | $alt = '' === wp_get_attachment_caption( $id ) ? get_the_title() : wp_get_attachment_caption( $id ); |
| 246 | |
| 247 | echo '<div class="wpr-grid-image-wrap" data-src="'. esc_url( wp_get_attachment_url( $id ) ) .'">'; |
| 248 | echo '<img src="'. esc_url( $src ) .'" alt="'. wp_kses_post( $alt ) .'" class="wpr-anim-timing-'. esc_html($settings[ 'image_effects_animation_timing']) .'">'; |
| 249 | echo '</div>'; |
| 250 | } |
| 251 | |
| 252 | // Render Media Overlay |
| 253 | public function render_media_overlay( $settings ) { |
| 254 | echo '<div class="wpr-grid-media-hover-bg '. esc_attr($this->get_animation_class( $settings, 'overlay' )) .'" data-url="'. esc_url( get_the_permalink( get_the_ID() ) ) .'">'; |
| 255 | |
| 256 | if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { |
| 257 | if ( '' !== $settings['overlay_image']['url'] ) { |
| 258 | echo '<img src="'. esc_url( $settings['overlay_image']['url'] ) .'">'; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | echo '</div>'; |
| 263 | } |
| 264 | |
| 265 | // Render Post Title |
| 266 | public function render_post_title( $settings, $class ) { |
| 267 | $title_pointer = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? 'none' : $_POST['grid_settings']['title_pointer']; |
| 268 | $title_pointer_animation = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? 'fade' : $_POST['grid_settings']['title_pointer_animation']; |
| 269 | $pointer_item_class = ( isset( $_POST['grid_settings']['title_pointer'] ) && 'none' !== $_POST['grid_settings']['title_pointer'] ) ? 'wpr-pointer-item' : ''; |
| 270 | |
| 271 | $class .= ' wpr-pointer-'. $title_pointer; |
| 272 | $class .= ' wpr-pointer-line-fx wpr-pointer-fx-'. $title_pointer_animation; |
| 273 | |
| 274 | $tags_whitelist = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'span', 'p']; |
| 275 | $element_title_tag = Utilities::validate_html_tags_wl( $settings['element_title_tag'], 'h2', $tags_whitelist ); |
| 276 | |
| 277 | echo '<'. esc_attr($element_title_tag) .' class="'. esc_attr($class) .'">'; |
| 278 | echo '<div class="inner-block">'; |
| 279 | if ( 'yes' === $settings['element_disable_link'] ) { |
| 280 | echo '<span class="' . esc_attr( $pointer_item_class ) . '">'; |
| 281 | echo esc_html(wp_trim_words( get_the_title(), $settings['element_word_count'] )); |
| 282 | echo '</span>'; |
| 283 | } else { |
| 284 | echo '<a class="' . esc_attr( $pointer_item_class ) . '" href="' . esc_url( get_the_permalink() ) . '">'; |
| 285 | echo esc_html(wp_trim_words( get_the_title(), $settings['element_word_count'] )); |
| 286 | echo '</a>'; |
| 287 | } |
| 288 | echo '</div>'; |
| 289 | echo '</'. esc_attr($element_title_tag) .'>'; |
| 290 | } |
| 291 | |
| 292 | // Render Post Content |
| 293 | public function render_post_content( $settings, $class ) { |
| 294 | $dropcap_class = 'yes' === $settings['element_dropcap'] ? ' wpr-enable-dropcap' : ''; |
| 295 | $class .= $dropcap_class; |
| 296 | |
| 297 | if ( '' === get_the_content() ) { |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | echo '<div class="'. esc_attr($class) .'">'; |
| 302 | echo '<div class="inner-block">'; |
| 303 | echo wp_kses_post(get_the_content()); |
| 304 | echo '</div>'; |
| 305 | echo '</div>'; |
| 306 | } |
| 307 | |
| 308 | // Render Post Excerpt |
| 309 | public function render_post_excerpt( $settings, $class ) { |
| 310 | $dropcap_class = 'yes' === $settings['element_dropcap'] ? ' wpr-enable-dropcap' : ''; |
| 311 | $class .= $dropcap_class; |
| 312 | |
| 313 | if ( '' === get_the_excerpt() ) { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | echo '<div class="'. esc_attr($class) .'">'; |
| 318 | echo '<div class="inner-block">'; |
| 319 | echo '<p>'. esc_html(wp_trim_words( get_the_excerpt(), $settings['element_word_count'] )) .'</p>'; |
| 320 | echo '</div>'; |
| 321 | echo '</div>'; |
| 322 | } |
| 323 | |
| 324 | // Render Post Date |
| 325 | public function render_post_date( $settings, $class ) { |
| 326 | echo '<div class="'. esc_attr($class) .'">'; |
| 327 | echo '<div class="inner-block">'; |
| 328 | echo '<span>'; |
| 329 | // Text: Before |
| 330 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 331 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 332 | } |
| 333 | // Icon: Before |
| 334 | if ( 'before' === $settings['element_extra_icon_pos'] ) { |
| 335 | ob_start(); |
| 336 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 337 | $extra_icon = ob_get_clean(); |
| 338 | |
| 339 | echo '<span class="wpr-grid-extra-icon-left">'; |
| 340 | echo wp_kses_post( $extra_icon ); |
| 341 | echo '</span>'; |
| 342 | } |
| 343 | |
| 344 | // Date |
| 345 | echo esc_html(apply_filters( 'the_date', get_the_date( '' ), get_option( 'date_format' ), '', '' )); |
| 346 | |
| 347 | // Icon: After |
| 348 | if ( 'after' === $settings['element_extra_icon_pos'] ) { |
| 349 | ob_start(); |
| 350 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 351 | $extra_icon = ob_get_clean(); |
| 352 | |
| 353 | echo '<span class="wpr-grid-extra-icon-right">'; |
| 354 | echo wp_kses_post( $extra_icon ); |
| 355 | echo '</span>'; |
| 356 | } |
| 357 | // Text: After |
| 358 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 359 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 360 | } |
| 361 | echo '</span>'; |
| 362 | echo '</div>'; |
| 363 | echo '</div>'; |
| 364 | } |
| 365 | |
| 366 | // Render Post Time |
| 367 | public function render_post_time( $settings, $class ) { |
| 368 | echo '<div class="'. esc_attr($class) .'">'; |
| 369 | echo '<div class="inner-block">'; |
| 370 | echo '<span>'; |
| 371 | // Text: Before |
| 372 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 373 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 374 | } |
| 375 | // Icon: Before |
| 376 | if ( 'before' === $settings['element_extra_icon_pos'] ) { |
| 377 | ob_start(); |
| 378 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 379 | $extra_icon = ob_get_clean(); |
| 380 | |
| 381 | echo '<span class="wpr-grid-extra-icon-left">'; |
| 382 | echo wp_kses_post( $extra_icon ); |
| 383 | echo '</span>'; |
| 384 | } |
| 385 | |
| 386 | // Time |
| 387 | echo esc_html(get_the_time('')); |
| 388 | |
| 389 | // Icon: After |
| 390 | if ( 'after' === $settings['element_extra_icon_pos'] ) { |
| 391 | ob_start(); |
| 392 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 393 | $extra_icon = ob_get_clean(); |
| 394 | |
| 395 | echo '<span class="wpr-grid-extra-icon-right">'; |
| 396 | echo wp_kses_post( $extra_icon ); |
| 397 | echo '</span>'; |
| 398 | } |
| 399 | // Text: After |
| 400 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 401 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 402 | } |
| 403 | echo '</span>'; |
| 404 | echo '</div>'; |
| 405 | echo '</div>'; |
| 406 | } |
| 407 | |
| 408 | // Render Post Author |
| 409 | public function render_post_author( $settings, $class ) { |
| 410 | $author_id = get_post_field( 'post_author' ); |
| 411 | |
| 412 | echo '<div class="'. esc_attr($class) .'">'; |
| 413 | echo '<div class="inner-block">'; |
| 414 | // Text: Before |
| 415 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 416 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 417 | } |
| 418 | |
| 419 | // Author |
| 420 | echo '<a href="'. esc_url( get_author_posts_url( $author_id ) ) .'">'; |
| 421 | |
| 422 | // Icon: Before |
| 423 | if ( 'before' === $settings['element_extra_icon_pos'] ) { |
| 424 | ob_start(); |
| 425 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 426 | $extra_icon = ob_get_clean(); |
| 427 | |
| 428 | echo '<span class="wpr-grid-extra-icon-left">'; |
| 429 | echo wp_kses_post( $extra_icon ); |
| 430 | echo '</span>'; |
| 431 | } |
| 432 | if ( 'yes' === $settings['element_show_avatar'] ) { |
| 433 | echo get_avatar( $author_id, $settings['element_avatar_size'] ); |
| 434 | } |
| 435 | |
| 436 | echo '<span>'. esc_html(get_the_author_meta( 'display_name', $author_id )) .'</span>'; |
| 437 | |
| 438 | // Icon: After |
| 439 | if ( 'after' === $settings['element_extra_icon_pos'] ) { |
| 440 | ob_start(); |
| 441 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 442 | $extra_icon = ob_get_clean(); |
| 443 | |
| 444 | echo '<span class="wpr-grid-extra-icon-right">'; |
| 445 | echo wp_kses_post( $extra_icon ); |
| 446 | echo '</span>'; |
| 447 | } |
| 448 | echo '</a>'; |
| 449 | |
| 450 | // Text: After |
| 451 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 452 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 453 | } |
| 454 | echo '</div>'; |
| 455 | echo '</div>'; |
| 456 | } |
| 457 | |
| 458 | public function render_post_likes( $settings, $class, $post_id ) { |
| 459 | $post_likes = new WPR_Post_Likes(); |
| 460 | |
| 461 | echo '<div class="'. esc_attr($class) .'">'; |
| 462 | echo '<div class="inner-block">'; |
| 463 | // Text: Before |
| 464 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 465 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 466 | } |
| 467 | |
| 468 | echo wp_kses_post( $post_likes->get_button( $post_id, $settings ) ); |
| 469 | |
| 470 | // Text: After |
| 471 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 472 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 473 | } |
| 474 | echo '</div>'; |
| 475 | echo '</div>'; |
| 476 | } |
| 477 | |
| 478 | // Render Post Sharing |
| 479 | public function render_post_sharing_icons( $settings, $class ) { |
| 480 | $args = [ |
| 481 | 'icons' => 'yes', |
| 482 | 'tooltip' => $settings['element_sharing_tooltip'], |
| 483 | 'url' => esc_url( get_permalink( get_queried_object_id() ) ), |
| 484 | 'title' => esc_html( get_the_title() ), |
| 485 | 'text' => esc_html( get_the_excerpt() ), |
| 486 | 'image' => esc_url( get_the_post_thumbnail_url() ), |
| 487 | ]; |
| 488 | |
| 489 | $hidden_class = ''; |
| 490 | |
| 491 | echo '<div class="'. esc_attr($class) .'">'; |
| 492 | echo '<div class="inner-block">'; |
| 493 | // Text: Before |
| 494 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 495 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 496 | } |
| 497 | |
| 498 | echo '<span class="wpr-post-sharing">'; |
| 499 | |
| 500 | if ( 'yes' === $settings['element_sharing_trigger'] ) { |
| 501 | $hidden_class = ' wpr-sharing-hidden'; |
| 502 | $attributes = ' data-action="'. esc_attr( $settings['element_sharing_trigger_action'] ) .'"'; |
| 503 | $attributes .= ' data-direction="'. esc_attr( $settings['element_sharing_trigger_direction'] ) .'"'; |
| 504 | |
| 505 | echo '<a class="wpr-sharing-trigger wpr-sharing-icon"'. $attributes .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 506 | if ( 'yes' === $settings['element_sharing_tooltip'] ) { |
| 507 | echo '<span class="wpr-sharing-tooltip wpr-tooltip">'. esc_html__( 'Share', 'wpr-addons' ) .'</span>'; |
| 508 | } |
| 509 | |
| 510 | echo wp_kses_post( Utilities::get_wpr_icon( $settings['element_sharing_trigger_icon'], '' ) ); |
| 511 | echo '</a>'; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | echo '<span class="wpr-post-sharing-inner' . esc_attr( $hidden_class ) . '">'; |
| 516 | |
| 517 | for ( $i = 1; $i < 7; $i++ ) { |
| 518 | $args['network'] = $settings['element_sharing_icon_'. $i]; |
| 519 | |
| 520 | echo wp_kses_post( Utilities::get_post_sharing_icon( $args ) ); |
| 521 | } |
| 522 | |
| 523 | echo '</span>'; |
| 524 | |
| 525 | echo '</span>'; |
| 526 | |
| 527 | // Text: After |
| 528 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 529 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 530 | } |
| 531 | echo '</div>'; |
| 532 | echo '</div>'; |
| 533 | } |
| 534 | |
| 535 | // Render Post Lightbox |
| 536 | public function render_post_lightbox( $settings, $class, $post_id ) { |
| 537 | echo '<div class="'. esc_attr($class) .'">'; |
| 538 | echo '<div class="inner-block">'; |
| 539 | $lightbox_source = get_the_post_thumbnail_url( $post_id ); |
| 540 | |
| 541 | // Audio Post Type |
| 542 | if ( 'audio' === get_post_format() ) { |
| 543 | // Load Meta Value |
| 544 | if ( 'meta' === $settings['element_lightbox_pfa_select'] ) { |
| 545 | $utilities = new Utilities(); |
| 546 | $meta_value = get_post_meta( $post_id, $settings['element_lightbox_pfa_meta'], true ); |
| 547 | |
| 548 | // URL |
| 549 | if ( false === strpos( $meta_value, '<iframe ' ) ) { |
| 550 | add_filter( 'oembed_result', [ $utilities, 'filter_oembed_results' ], 50, 3 ); |
| 551 | $track_url = wp_oembed_get( $meta_value ); |
| 552 | remove_filter( 'oembed_result', [ $utilities, 'filter_oembed_results' ], 50 ); |
| 553 | |
| 554 | // Iframe |
| 555 | } else { |
| 556 | $track_url = Utilities::filter_oembed_results( $meta_value ); |
| 557 | } |
| 558 | |
| 559 | $lightbox_source = $track_url; |
| 560 | } |
| 561 | |
| 562 | // Video Post Type |
| 563 | } elseif ( 'video' === get_post_format() ) { |
| 564 | // Load Meta Value |
| 565 | if ( 'meta' === $settings['element_lightbox_pfv_select'] ) { |
| 566 | $meta_value = get_post_meta( $post_id, $settings['element_lightbox_pfv_meta'], true ); |
| 567 | |
| 568 | // URL |
| 569 | if ( false === strpos( $meta_value, '<iframe ' ) ) { |
| 570 | $video = \Elementor\Embed::get_video_properties( $meta_value ); |
| 571 | |
| 572 | // Iframe |
| 573 | } else { |
| 574 | $video = \Elementor\Embed::get_video_properties( Utilities::filter_oembed_results($meta_value) ); |
| 575 | } |
| 576 | |
| 577 | // Provider URL |
| 578 | if ( 'youtube' === $video['provider'] ) { |
| 579 | $video_url = '//www.youtube.com/embed/'. $video['video_id'] .'?feature=oembed&autoplay=1&controls=1'; |
| 580 | } elseif ( 'vimeo' === $video['provider'] ) { |
| 581 | $video_url = 'https://player.vimeo.com/video/'. $video['video_id'] .'?autoplay=1#t=0'; |
| 582 | } |
| 583 | |
| 584 | // Add Lightbox Attributes |
| 585 | if ( isset( $video_url ) ) { |
| 586 | $lightbox_source = $video_url; |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | if ( $lightbox_source == false ) { |
| 592 | $lightbox_source = wp_get_attachment_url( $post_id ); |
| 593 | } |
| 594 | |
| 595 | // Lightbox Button |
| 596 | echo '<span data-src="'. esc_url( $lightbox_source ) .'">'; |
| 597 | |
| 598 | // Text: Before |
| 599 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 600 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 601 | } |
| 602 | |
| 603 | // Lightbox Icon |
| 604 | echo '<i class="'. esc_attr( $settings['element_extra_icon']['value'] ) .'"></i>'; |
| 605 | |
| 606 | // Text: After |
| 607 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 608 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 609 | } |
| 610 | |
| 611 | echo '</span>'; |
| 612 | |
| 613 | // Media Overlay |
| 614 | if ( 'yes' === $settings['element_lightbox_overlay'] ) { |
| 615 | echo '<div class="wpr-grid-lightbox-overlay"></div>'; |
| 616 | } |
| 617 | echo '</div>'; |
| 618 | echo '</div>'; |
| 619 | } |
| 620 | |
| 621 | // Render Post Element Separator |
| 622 | public function render_post_element_separator( $settings, $class ) { |
| 623 | echo '<div class="'. esc_attr($class .' '. $settings['element_separator_style']) .'">'; |
| 624 | echo '<div class="inner-block"><span></span></div>'; |
| 625 | echo '</div>'; |
| 626 | } |
| 627 | |
| 628 | // Render Post Taxonomies |
| 629 | public function render_post_taxonomies( $settings, $class, $post_id ) { |
| 630 | $terms = wp_get_post_terms( $post_id, $settings['element_select'] ); |
| 631 | $count = 0; |
| 632 | |
| 633 | $tax1_pointer = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? 'none' : $_POST['grid_settings']['tax1_pointer']; |
| 634 | $tax1_pointer_animation = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? 'fade' : $_POST['grid_settings']['tax1_pointer_animation']; |
| 635 | $tax2_pointer = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? 'none' : $_POST['grid_settings']['tax2_pointer']; |
| 636 | $tax2_pointer_animation = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? 'fade' : $_POST['grid_settings']['tax2_pointer_animation']; |
| 637 | $pointer_item_class = (isset($_POST['grid_settings']['tax1_pointer']) && 'none' !== $_POST['grid_settings']['tax1_pointer']) || (isset($_POST['grid_settings']['tax2_pointer']) && 'none' !== $_POST['grid_settings']['tax2_pointer']) ? 'wpr-pointer-item' : ''; |
| 638 | |
| 639 | // Pointer Class |
| 640 | if ( 'wpr-grid-tax-style-1' === $settings['element_tax_style'] ) { |
| 641 | $class .= ' wpr-pointer-'. $tax1_pointer; |
| 642 | $class .= ' wpr-pointer-line-fx wpr-pointer-fx-'. $tax1_pointer_animation; |
| 643 | } else { |
| 644 | $class .= ' wpr-pointer-'. $tax2_pointer; |
| 645 | $class .= ' wpr-pointer-line-fx wpr-pointer-fx-'. $tax2_pointer_animation; |
| 646 | } |
| 647 | |
| 648 | echo '<div class="'. esc_attr($class .' '. $settings['element_tax_style']) .'">'; |
| 649 | echo '<div class="inner-block">'; |
| 650 | // Text: Before |
| 651 | if ( 'before' === $settings['element_extra_text_pos'] ) { |
| 652 | echo '<span class="wpr-grid-extra-text-left">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 653 | } |
| 654 | // Icon: Before |
| 655 | if ( 'before' === $settings['element_extra_icon_pos'] ) { |
| 656 | ob_start(); |
| 657 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 658 | $extra_icon = ob_get_clean(); |
| 659 | |
| 660 | echo '<span class="wpr-grid-extra-icon-left">'; |
| 661 | echo wp_kses_post( $extra_icon ); |
| 662 | echo '</span>'; |
| 663 | } |
| 664 | |
| 665 | // Taxonomies |
| 666 | foreach ( $terms as $term ) { |
| 667 | |
| 668 | // Custom Colors |
| 669 | $enable_custom_colors = !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ? '' : $_POST['grid_settings']['tax1_custom_color_switcher']; |
| 670 | |
| 671 | if ( 'yes' === $enable_custom_colors ) { |
| 672 | $custom_tax_styles = ''; |
| 673 | $cfc_text = get_term_meta($term->term_id, $_POST['grid_settings']['tax1_custom_color_field_text'], true); |
| 674 | $cfc_bg = get_term_meta($term->term_id, $_POST['grid_settings']['tax1_custom_color_field_bg'], true); |
| 675 | $color_styles = 'color:'. $cfc_text .'; background-color:'. $cfc_bg .'; border-color:'. $cfc_bg .';'; |
| 676 | $css_selector = '.elementor-element'. $this->get_unique_selector() .' .wpr-grid-tax-style-1 .inner-block a.wpr-tax-id-'. esc_attr($term->term_id); |
| 677 | $custom_tax_styles .= $css_selector .'{'. $color_styles .'}'; |
| 678 | echo '<style>'. esc_html($custom_tax_styles) .'</style>'; // TODO: take out of loop if possible |
| 679 | } |
| 680 | |
| 681 | echo '<a class="' . esc_attr( trim( $pointer_item_class . ' wpr-tax-id-' . $term->term_id ) ) . '" href="' . esc_url( get_term_link( $term->term_id ) ) . '">' . esc_html( $term->name ); |
| 682 | if ( ++$count !== count( $terms ) ) { |
| 683 | echo '<span class="tax-sep">'. esc_html($settings['element_tax_sep']) .'</span>'; |
| 684 | } |
| 685 | echo '</a>'; |
| 686 | } |
| 687 | |
| 688 | // Icon: After |
| 689 | if ( 'after' === $settings['element_extra_icon_pos'] ) { |
| 690 | ob_start(); |
| 691 | \Elementor\Icons_Manager::render_icon($settings['element_extra_icon'], ['aria-hidden' => 'true']); |
| 692 | $extra_icon = ob_get_clean(); |
| 693 | |
| 694 | echo '<span class="wpr-grid-extra-icon-right">'; |
| 695 | echo wp_kses_post( $extra_icon ); |
| 696 | echo '</span>'; |
| 697 | } |
| 698 | // Text: After |
| 699 | if ( 'after' === $settings['element_extra_text_pos'] ) { |
| 700 | echo '<span class="wpr-grid-extra-text-right">'. esc_html( $settings['element_extra_text'] ) .'</span>'; |
| 701 | } |
| 702 | echo '</div>'; |
| 703 | echo '</div>'; |
| 704 | } |
| 705 | |
| 706 | |
| 707 | // Get Elements |
| 708 | public function get_elements( $type, $settings, $class, $post_id ) { |
| 709 | if ( 'pro-lk' == $type || 'pro-shr' == $type ) { |
| 710 | $type = 'title'; |
| 711 | } |
| 712 | |
| 713 | switch ( $type ) { |
| 714 | case 'title': |
| 715 | $this->render_post_title( $settings, $class ); |
| 716 | break; |
| 717 | |
| 718 | case 'caption': |
| 719 | $this->render_post_excerpt( $settings, $class ); |
| 720 | break; |
| 721 | |
| 722 | case 'date': |
| 723 | $this->render_post_date( $settings, $class ); |
| 724 | break; |
| 725 | |
| 726 | case 'time': |
| 727 | $this->render_post_time( $settings, $class ); |
| 728 | break; |
| 729 | |
| 730 | case 'author': |
| 731 | $this->render_post_author( $settings, $class ); |
| 732 | break; |
| 733 | |
| 734 | case 'likes': |
| 735 | $this->render_post_likes( $settings, $class, $post_id ); |
| 736 | break; |
| 737 | |
| 738 | case 'sharing': |
| 739 | $this->render_post_sharing_icons( $settings, $class ); |
| 740 | break; |
| 741 | |
| 742 | case 'lightbox': |
| 743 | $this->render_post_lightbox( $settings, $class, $post_id ); |
| 744 | break; |
| 745 | |
| 746 | case 'separator': |
| 747 | $this->render_post_element_separator( $settings, $class ); |
| 748 | break; |
| 749 | |
| 750 | default: |
| 751 | $this->render_post_taxonomies( $settings, $class, $post_id ); |
| 752 | break; |
| 753 | } |
| 754 | |
| 755 | } |
| 756 | |
| 757 | // Get Elements by Location |
| 758 | public function get_elements_by_location( $location, $settings, $post_id ) { |
| 759 | $locations = []; |
| 760 | |
| 761 | foreach ( $settings['grid_elements'] as $data ) { |
| 762 | $place = $data['element_location']; |
| 763 | $align_vr = $data['element_align_vr']; |
| 764 | |
| 765 | if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) { |
| 766 | $align_vr = 'middle'; |
| 767 | } |
| 768 | |
| 769 | if ( ! isset($locations[$place]) ) { |
| 770 | $locations[$place] = []; |
| 771 | } |
| 772 | |
| 773 | if ( 'over' === $place ) { |
| 774 | if ( ! isset($locations[$place][$align_vr]) ) { |
| 775 | $locations[$place][$align_vr] = []; |
| 776 | } |
| 777 | |
| 778 | array_push( $locations[$place][$align_vr], $data ); |
| 779 | } else { |
| 780 | array_push( $locations[$place], $data ); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | if ( ! empty( $locations[$location] ) ) { |
| 785 | |
| 786 | if ( 'over' === $location ) { |
| 787 | foreach ( $locations[$location] as $align => $elements ) { |
| 788 | |
| 789 | if ( 'middle' === $align ) { |
| 790 | echo '<div class="wpr-cv-container"><div class="wpr-cv-outer"><div class="wpr-cv-inner">'; |
| 791 | } |
| 792 | |
| 793 | echo '<div class="wpr-grid-media-hover-'. esc_attr($align) .' elementor-clearfix">'; |
| 794 | foreach ( $elements as $data ) { |
| 795 | |
| 796 | // Get Class |
| 797 | $class = 'wpr-grid-item-'. $data['element_select']; |
| 798 | $class .= ' elementor-repeater-item-'. $data['_id']; |
| 799 | $class .= ' wpr-grid-item-display-'. $data['element_display']; |
| 800 | $class .= ' wpr-grid-item-align-'. $data['element_align_hr']; |
| 801 | $class .= $this->get_animation_class( $data, 'element' ); |
| 802 | |
| 803 | // Element |
| 804 | $this->get_elements( $data['element_select'], $data, $class, $post_id ); |
| 805 | } |
| 806 | echo '</div>'; |
| 807 | |
| 808 | if ( 'middle' === $align ) { |
| 809 | echo '</div></div></div>'; |
| 810 | } |
| 811 | } |
| 812 | } else { |
| 813 | echo '<div class="wpr-grid-item-'. esc_attr($location) .'-content elementor-clearfix">'; |
| 814 | foreach ( $locations[$location] as $data ) { |
| 815 | |
| 816 | // Get Class |
| 817 | $class = 'wpr-grid-item-'. $data['element_select']; |
| 818 | $class .= ' elementor-repeater-item-'. $data['_id']; |
| 819 | $class .= ' wpr-grid-item-display-'. $data['element_display']; |
| 820 | $class .= ' wpr-grid-item-align-'. $data['element_align_hr']; |
| 821 | |
| 822 | // Element |
| 823 | $this->get_elements( $data['element_select'], $data, $class, $post_id ); |
| 824 | } |
| 825 | echo '</div>'; |
| 826 | } |
| 827 | |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | public function wpr_get_media_filtered_count() { |
| 832 | $nonce = $_POST['nonce']; |
| 833 | |
| 834 | if (!isset($nonce) || !wp_verify_nonce($nonce, 'wpr-addons-js')) { |
| 835 | wp_send_json_error(array( |
| 836 | 'message' => esc_html__('Security check failed.', 'wpr-addons'), |
| 837 | )); |
| 838 | } |
| 839 | |
| 840 | $settings = $_POST['grid_settings']; |
| 841 | $page_count = $this->get_max_num_pages( $settings ); |
| 842 | |
| 843 | wp_send_json_success([ |
| 844 | 'page_count' => $page_count, |
| 845 | ]); |
| 846 | |
| 847 | wp_die(); |
| 848 | } |
| 849 | |
| 850 | public function wpr_filter_grid_media() { |
| 851 | $nonce = $_POST['nonce']; |
| 852 | |
| 853 | if (!isset($nonce) || !wp_verify_nonce($nonce, 'wpr-addons-js')) { |
| 854 | wp_send_json_error(array( |
| 855 | 'message' => esc_html__('Security check failed.', 'wpr-addons'), |
| 856 | )); |
| 857 | } |
| 858 | |
| 859 | // Get Settings |
| 860 | $settings = $_POST['grid_settings']; |
| 861 | // Get Posts |
| 862 | $posts = new \WP_Query( $this->get_main_query_args() ); |
| 863 | |
| 864 | // Loop: Start |
| 865 | if ( $posts->have_posts() ) : |
| 866 | |
| 867 | while ( $posts->have_posts() ) : $posts->the_post(); |
| 868 | |
| 869 | // $post_index++; |
| 870 | // if ( Utilities::is_new_free_user() && $post_index > 12 ) { |
| 871 | // return; |
| 872 | // } |
| 873 | |
| 874 | if ( ! wp_attachment_is( 'image', get_the_ID() ) ) { |
| 875 | continue; |
| 876 | } |
| 877 | |
| 878 | // Post Class |
| 879 | $post_class = implode( ' ', get_post_class( 'wpr-grid-item elementor-clearfix', get_the_ID() ) ); |
| 880 | |
| 881 | // Grid Item |
| 882 | echo '<article class="'. esc_attr( $post_class ) .'">'; |
| 883 | |
| 884 | // Inner Wrapper |
| 885 | echo '<div class="wpr-grid-item-inner">'; |
| 886 | |
| 887 | // Content: Above Media |
| 888 | $this->get_elements_by_location( 'above', $settings, get_the_ID() ); |
| 889 | |
| 890 | // Media |
| 891 | echo '<div class="wpr-grid-media-wrap'. esc_attr($this->get_image_effect_class( $settings )) .' ">'; |
| 892 | // Post Thumbnail |
| 893 | $this->render_post_thumbnail( $settings, get_the_ID() ); |
| 894 | |
| 895 | // Media Hover |
| 896 | echo '<div class="wpr-grid-media-hover wpr-animation-wrap">'; |
| 897 | // Media Overlay |
| 898 | $this->render_media_overlay( $settings ); |
| 899 | |
| 900 | // Content: Over Media |
| 901 | $this->get_elements_by_location( 'over', $settings, get_the_ID() ); |
| 902 | |
| 903 | echo '</div>'; |
| 904 | echo '</div>'; |
| 905 | |
| 906 | // Content: Below Media |
| 907 | $this->get_elements_by_location( 'below', $settings, get_the_ID() ); |
| 908 | |
| 909 | echo '</div>'; // End .wpr-grid-item-inner |
| 910 | |
| 911 | echo '</article>'; // End .wpr-grid-item |
| 912 | |
| 913 | endwhile; |
| 914 | |
| 915 | // reset |
| 916 | wp_reset_postdata(); |
| 917 | |
| 918 | // Loop: End |
| 919 | endif; |
| 920 | |
| 921 | die(); |
| 922 | } |
| 923 | |
| 924 | } |
| 925 | |
| 926 | new WPR_Filter_Grid_Media(); |