| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: All In One Lightbox – Display Images, Audio, and Video in Popups |
| 4 |
* Description: Lightbox block is an excellent choice for your WordPress Lightbox Block. |
| 5 |
* Version: 1.1.45 |
| 6 |
* Author: bPlugins |
| 7 |
* Author URI: http://bplugins.com |
| 8 |
* License: GPLv2 or later |
| 9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 10 |
* Text Domain: lightbox-block |
| 11 |
*/ |
| 12 |
|
| 13 |
// ABS PATH |
| 14 |
if (!defined('ABSPATH')) {exit;} |
| 15 |
|
| 16 |
// Constant |
| 17 |
if (defined('WP_DEBUG') && WP_DEBUG === true) { |
| 18 |
define('LBB_LIGHTBOX_PLUGIN_VERSION', time()); |
| 19 |
} else { |
| 20 |
define('LBB_LIGHTBOX_PLUGIN_VERSION', '1.1.45'); |
| 21 |
} |
| 22 |
|
| 23 |
define('LBB_LIGHTBOX_ASSETS_DIR', plugin_dir_url(__FILE__) . 'assets/'); |
| 24 |
define('LBB_LIGHTBOX_DIR_URL', plugin_dir_url(__FILE__)); |
| 25 |
define('LBB_LIGHTBOX_DIR_PATH', plugin_dir_path(__FILE__)); |
| 26 |
|
| 27 |
// Create a helper function for easy SDK access. |
| 28 |
if (!function_exists('lbb_fs')) { |
| 29 |
function lbb_fs() |
| 30 |
{ |
| 31 |
global $lbb_fs; |
| 32 |
|
| 33 |
if (!isset($lbb_fs)) { |
| 34 |
|
| 35 |
require_once dirname( __FILE__ ) . '/vendor/freemius-lite/start.php'; |
| 36 |
|
| 37 |
$lbbConfig = (array( |
| 38 |
'id' => '13492', |
| 39 |
'slug' => 'lightbox-block', |
| 40 |
'type' => 'plugin', |
| 41 |
'public_key' => 'pk_8346b668170b2e4c33255d896d15c', |
| 42 |
'is_premium' => false, |
| 43 |
'menu' => array( |
| 44 |
'slug' => 'edit.php?post_type=lbb', |
| 45 |
'first-path' => 'edit.php?post_type=lbb&page=lightbox-block#/pricing', |
| 46 |
'support' => false, |
| 47 |
) |
| 48 |
|
| 49 |
)); |
| 50 |
$lbb_fs = fs_lite_dynamic_init( $lbbConfig ); |
| 51 |
} |
| 52 |
return $lbb_fs; |
| 53 |
} |
| 54 |
|
| 55 |
// Init Freemius. |
| 56 |
lbb_fs(); |
| 57 |
// Signal that SDK was initiated. |
| 58 |
do_action('lbb_fs_loaded'); |
| 59 |
} |
| 60 |
|
| 61 |
// Light Box |
| 62 |
if (!class_exists('LBB_Lightbox_Plugin')) { |
| 63 |
class LBB_Lightbox_Plugin |
| 64 |
{ |
| 65 |
public function __construct(){ |
| 66 |
$this->load_classes(); |
| 67 |
add_action('init', [$this, 'onInit']); |
| 68 |
add_action('enqueue_block_assets', [$this, 'enqueueBlockAssets'], 10); |
| 69 |
add_action('wp_ajax_bpllb_get_image_id', [$this, 'bpllb_get_image_id']); |
| 70 |
add_action('wp_enqueue_scripts', [$this, 'lbb_custom_popup']); |
| 71 |
add_filter( 'plugin_action_links', [$this, 'plugin_action_links'], 10, 2 ); |
| 72 |
} |
| 73 |
|
| 74 |
public function lbb_custom_popup(){ |
| 75 |
global $post; |
| 76 |
|
| 77 |
if ( ! is_singular() || ! ( $post instanceof WP_Post ) ) { |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
if ( ! has_block( 'lbb/lightbox', $post ) && ! has_shortcode( $post->post_content, 'lbb-lightbox-block' ) ) { |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
wp_enqueue_script('lbb-custom-popup', LBB_LIGHTBOX_DIR_URL . 'build/custom-popup.js', [], LBB_LIGHTBOX_PLUGIN_VERSION, true); |
| 86 |
wp_enqueue_style( 'lbb-custom-popup', LBB_LIGHTBOX_DIR_URL. 'build/custom-popup.css', [], LBB_LIGHTBOX_PLUGIN_VERSION ); |
| 87 |
} |
| 88 |
|
| 89 |
function onInit(){ |
| 90 |
register_block_type( __DIR__ . '/build' ); |
| 91 |
} |
| 92 |
|
| 93 |
public function enqueueBlockAssets(){ |
| 94 |
wp_register_style( 'fontAwesome', LBB_LIGHTBOX_ASSETS_DIR . 'css/font-awesome.min.css', [], '6.5.2' ); // Icon — enqueued via block.json when block is present |
| 95 |
|
| 96 |
wp_register_style('fancyapps-carousel', LBB_LIGHTBOX_ASSETS_DIR . 'css/carousel.css', [], '5.0'); |
| 97 |
wp_register_style('fancyapps-thum', LBB_LIGHTBOX_ASSETS_DIR . 'css/carousel-thum.css', [], '5.0'); |
| 98 |
wp_register_style('lbb-shortcode', LBB_LIGHTBOX_ASSETS_DIR . 'css/shortcode.css', [], LBB_LIGHTBOX_PLUGIN_VERSION); |
| 99 |
|
| 100 |
wp_register_style('lbb-plyr-style', LBB_LIGHTBOX_ASSETS_DIR . 'css/plyr.min.css', [], LBB_LIGHTBOX_PLUGIN_VERSION); |
| 101 |
|
| 102 |
wp_register_script('fancyapps-carousel', LBB_LIGHTBOX_ASSETS_DIR . 'js/carousel.js', [], '5.0', true); |
| 103 |
wp_register_script('fancyapps-thum', LBB_LIGHTBOX_ASSETS_DIR . 'js/carousel-thum.js', [], '5.0', true); |
| 104 |
|
| 105 |
wp_register_script('lbb-plyr-script', LBB_LIGHTBOX_ASSETS_DIR . 'js/plyr.min.js', [], LBB_LIGHTBOX_PLUGIN_VERSION, true); |
| 106 |
wp_register_script('lbb-shortcode', LBB_LIGHTBOX_ASSETS_DIR . 'js/shortcode.js', [], LBB_LIGHTBOX_PLUGIN_VERSION, true); |
| 107 |
|
| 108 |
wp_localize_script('lbb-plyr-script', 'bpllbMediaUrlId', [ |
| 109 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 110 |
'nonce' => wp_create_nonce('bpllb_get_image_id'), |
| 111 |
]); |
| 112 |
} |
| 113 |
|
| 114 |
//Class loaded |
| 115 |
public function load_classes () { |
| 116 |
|
| 117 |
require_once plugin_dir_path(__FILE__) . '/inc/AdminMenu.php'; |
| 118 |
require_once plugin_dir_path(__FILE__) . '/inc/custom-shortcode.php'; |
| 119 |
} |
| 120 |
|
| 121 |
public function bpllb_get_image_id(){ |
| 122 |
|
| 123 |
check_ajax_referer("bpllb_get_image_id", "nonce" ); |
| 124 |
|
| 125 |
if ( ! current_user_can( 'edit_posts' ) ) { |
| 126 |
wp_send_json_error( ['message' => 'Insufficient permissions'] ); |
| 127 |
} |
| 128 |
|
| 129 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- JSON is decoded first, then each field is sanitized individually below. |
| 130 |
$raw_items = isset($_POST['items']) ? wp_unslash($_POST['items']) : ''; |
| 131 |
$decoded_items = json_decode($raw_items, true); |
| 132 |
|
| 133 |
if (!is_array($decoded_items)) { |
| 134 |
wp_send_json_error(['message' => 'Invalid data']); |
| 135 |
} |
| 136 |
|
| 137 |
$response = []; |
| 138 |
|
| 139 |
foreach ($decoded_items as $item) { |
| 140 |
$type = isset($item['type']) ? sanitize_text_field($item['type']) : ''; |
| 141 |
|
| 142 |
if ( 'image' === $type ) { |
| 143 |
$content = isset($item['content']) ? esc_url_raw($item['content']) : ''; |
| 144 |
} else { |
| 145 |
$content = isset($item['thumbnail']) ? esc_url_raw($item['thumbnail']) : ''; |
| 146 |
} |
| 147 |
|
| 148 |
$attachment_id = attachment_url_to_postid($content); |
| 149 |
$item['type'] = $type; |
| 150 |
$item['id'] = $attachment_id; |
| 151 |
$response[] = $item; |
| 152 |
} |
| 153 |
wp_send_json_success($response); |
| 154 |
} |
| 155 |
|
| 156 |
public function plugin_action_links($links, $file) { |
| 157 |
|
| 158 |
if( plugin_basename( __FILE__ ) == $file ) { |
| 159 |
|
| 160 |
$dashboardLink = admin_url( 'edit.php?post_type=lbb&page=lightbox-block' ); |
| 161 |
|
| 162 |
$links['dashboard'] = sprintf( '<a href="%s" style="%s" target="_blank">%s</a>', $dashboardLink, 'color:#4527a4;font-weight:bold', __( 'Dashboard!', 'lightbox-block' ) ); |
| 163 |
} |
| 164 |
|
| 165 |
return $links; |
| 166 |
} |
| 167 |
} |
| 168 |
new LBB_Lightbox_Plugin; |
| 169 |
} |
| 170 |
|