| 1 |
<?php |
| 2 |
/** |
| 3 |
* The public-facing functionality of the module. |
| 4 |
* |
| 5 |
* @link https://codesupply.co |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Powerkit |
| 9 |
* @subpackage Modules/public |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* The public-facing functionality of the module. |
| 19 |
*/ |
| 20 |
class Powerkit_Lightbox_Public extends Powerkit_Module_Public { |
| 21 |
|
| 22 |
/** |
| 23 |
* Initialize |
| 24 |
*/ |
| 25 |
public function initialize() { |
| 26 |
add_filter( 'wp_kses_allowed_html', array( $this, 'filter_allowed_html' ), 10, 2 ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Allow pinterest data attributes on our links. |
| 31 |
* |
| 32 |
* @param array $allowed array The allowed. |
| 33 |
* @param string $context string The context. |
| 34 |
*/ |
| 35 |
public function filter_allowed_html( $allowed, $context ) { |
| 36 |
if ( 'post' === $context ) { |
| 37 |
$allowed['img']['data-lightbox-description'] = true; |
| 38 |
} |
| 39 |
|
| 40 |
return $allowed; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Register the stylesheets for the public-facing side of the site. |
| 45 |
*/ |
| 46 |
public function wp_enqueue_scripts() { |
| 47 |
// Styles. |
| 48 |
wp_enqueue_style( 'glightbox', plugin_dir_url( __FILE__ ) . 'css/glightbox.min.css', array(), powerkit_get_setting( 'version' ), 'all' ); |
| 49 |
|
| 50 |
wp_enqueue_style( 'powerkit-lightbox', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-lightbox.css' ), array(), powerkit_get_setting( 'version' ), 'all' ); |
| 51 |
|
| 52 |
// Add RTL support. |
| 53 |
wp_style_add_data( 'powerkit-lightbox', 'rtl', 'replace' ); |
| 54 |
|
| 55 |
// Scripts. |
| 56 |
wp_enqueue_script( 'glightbox', plugin_dir_url( __FILE__ ) . 'js/glightbox.min.js', array( 'jquery', 'imagesloaded' ), powerkit_get_setting( 'version' ), true ); |
| 57 |
|
| 58 |
wp_enqueue_script( 'powerkit-lightbox', plugin_dir_url( __FILE__ ) . 'js/public-powerkit-lightbox.js', array( 'jquery', 'imagesloaded' ), powerkit_get_setting( 'version' ), true ); |
| 59 |
|
| 60 |
$single_image_selectors = get_option( 'powerkit_lightbox_single_image_selectors', array( '.entry-content img' ) ); |
| 61 |
$gallery_selectors = get_option( 'powerkit_lightbox_gallery_selectors', array( '.wp-block-gallery', '.gallery' ) ); |
| 62 |
$exclude_selectors = get_option( 'powerkit_lightbox_exclude_selectors', array() ); |
| 63 |
|
| 64 |
$single_image_selectors = powerkit_lightbox_process_selectors( $single_image_selectors ); |
| 65 |
$gallery_selectors = powerkit_lightbox_process_selectors( $gallery_selectors ); |
| 66 |
$exclude_selectors = powerkit_lightbox_process_selectors( $exclude_selectors ); |
| 67 |
|
| 68 |
$single_image_selectors = apply_filters( 'powerkit_lightbox_image_selectors', $single_image_selectors ); |
| 69 |
$gallery_selectors = apply_filters( 'powerkit_lightbox_gallery_selectors', $gallery_selectors ); |
| 70 |
$exclude_selectors = apply_filters( 'powerkit_lightbox_exclude_selectors', $exclude_selectors ); |
| 71 |
|
| 72 |
wp_localize_script( 'powerkit-lightbox', 'powerkit_lightbox_localize', array( |
| 73 |
'text_previous' => esc_html__( 'Previous', 'powerkit' ), |
| 74 |
'text_next' => esc_html__( 'Next', 'powerkit' ), |
| 75 |
'text_close' => esc_html__( 'Close', 'powerkit' ), |
| 76 |
'text_loading' => esc_html__( 'Loading', 'powerkit' ), |
| 77 |
'text_counter' => esc_html__( 'of', 'powerkit' ), |
| 78 |
'single_image_selectors' => implode( ',', $single_image_selectors ), |
| 79 |
'gallery_selectors' => implode( ',', $gallery_selectors ), |
| 80 |
'exclude_selectors' => implode( ',', $exclude_selectors ), |
| 81 |
'zoom_icon' => get_option( 'powerkit_lightbox_zoom_icon', true ), |
| 82 |
) ); |
| 83 |
} |
| 84 |
} |
| 85 |
|