kollapsminoriteten/wp-content/plugins/wp-lightbox-2/wp-lightbox-2.php

393 lines
15 KiB
PHP
Raw Permalink Normal View History

2020-12-17 14:35:39 +01:00
<?php
/**
* Plugin Name: WP Lightbox 2
2026-03-31 11:30:59 +02:00
* Plugin URI: https://wpdevart.com/wordpress-lightbox-plugin
2025-02-28 08:42:11 +01:00
* Description: WP Lightbox 2 adds stunning lightbox effects to images and galleries on your WordPress site.
2026-03-31 11:30:59 +02:00
* Version: 3.0.7
2025-02-28 08:42:11 +01:00
* Author: Syed Balkhi
2026-03-31 11:30:59 +02:00
* Author URI: https://syedbalkhi.com
2025-02-28 08:42:11 +01:00
* License: GNU General Public License, v2 (or newer)
2026-03-31 11:30:59 +02:00
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2020-12-17 14:35:39 +01:00
*/
2026-03-31 11:30:59 +02:00
/* Copyright 2015 Syed Balkhi
2020-12-17 14:35:39 +01:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation using version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
add_action( 'plugins_loaded', 'jqlb_init' );
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
function jqlb_init() {
2026-03-31 11:30:59 +02:00
if ( ! defined( 'JQLB_SCRIPT' ) ) {
define('JQLB_SCRIPT', 'js/dist/wp-lightbox-2.min.js');
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
load_plugin_textdomain( 'jqlb', false, dirname( plugin_basename( __FILE__ ) ) . '/I18n/' );
2020-12-17 14:35:39 +01:00
add_action('admin_init', 'jqlb_register_settings');
2026-03-31 11:30:59 +02:00
add_action('wp_enqueue_scripts', 'jqlb_css');
2020-12-17 14:35:39 +01:00
add_action('wp_enqueue_scripts', 'jqlb_js');
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
add_filter('the_content', 'jqlb_autoexpand_rel_wlightbox', 99);
2026-03-31 11:30:59 +02:00
if ( 1 === (int) get_option('jqlb_comments') ) {
2020-12-17 14:35:39 +01:00
remove_filter('pre_comment_content', 'wp_rel_nofollow');
add_filter('comment_text', 'jqlb_lightbox_comment', 99);
}
}
2026-03-31 11:30:59 +02:00
function jqlb_register_settings() {
register_setting( 'jqlb-settings-group', 'jqlb_automate', 'jqlb_bool_intval' );
register_setting( 'jqlb-settings-group', 'jqlb_comments', 'jqlb_bool_intval' );
register_setting( 'jqlb-settings-group', 'jqlb_resize_on_demand', 'jqlb_bool_intval' );
register_setting( 'jqlb-settings-group', 'jqlb_show_download', 'jqlb_bool_intval' );
register_setting( 'jqlb-settings-group', 'jqlb_navbarOnTop', 'jqlb_bool_intval' );
register_setting( 'jqlb-settings-group', 'jqlb_resize_speed', 'jqlb_pos_intval' );
register_setting( 'jqlb-settings-group', 'jqlb_margin_size', 'floatval' );
register_setting( 'jqlb-settings-group', 'jqlb_help_text', 'jplb_help_kses' );
add_option( 'jqlb_automate', 1 );
add_option( 'jqlb_comments', 1 );
add_option( 'jqlb_resize_on_demand', 0 );
add_option( 'jqlb_show_download', 0 );
add_option( 'jqlb_margin_size', 0 );
add_option( 'jqlb_navbarOnTop', 0 );
add_option( 'jqlb_resize_speed', 400 );
add_option( 'jqlb_help_text', '' );
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
function jqlb_register_menu_item() {
2020-12-17 14:35:39 +01:00
add_options_page('WP Lightbox Options', 'WP Lightbox 2', 'manage_options', 'jquery-lightbox-options', 'jqlb_options_panel');
}
2026-03-31 11:30:59 +02:00
function jqlb_get_locale() {
//$lang_locales and ICL_LANGUAGE_CODE are defined in the WPML plugin (https://wpml.org/)
2020-12-17 14:35:39 +01:00
global $lang_locales;
2026-03-31 11:30:59 +02:00
if (defined('ICL_LANGUAGE_CODE') && isset($lang_locales[ICL_LANGUAGE_CODE])) {
2020-12-17 14:35:39 +01:00
$locale = $lang_locales[ICL_LANGUAGE_CODE];
} else {
$locale = get_locale();
}
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
return $locale;
}
2026-03-31 11:30:59 +02:00
function jqlb_css() {
if ( is_admin() || is_feed() || wp_doing_ajax() ) {
return;
}
$locale = jqlb_get_locale();
$fileName = "lightbox.min.{$locale}.css";
$path = plugin_dir_path(__FILE__) . "styles/{$fileName}";
2020-12-17 14:35:39 +01:00
2026-03-31 11:30:59 +02:00
if ( ! is_readable( $path ) ) {
2020-12-17 14:35:39 +01:00
$fileName = 'lightbox.min.css';
}
2026-03-31 11:30:59 +02:00
wp_enqueue_style('wp-lightbox-2.min.css', plugin_dir_url(__FILE__) . 'styles/' . $fileName, false, '1.3.4');
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
function jqlb_js() {
if ( is_admin() || is_feed() || wp_doing_ajax() ) {
return;
}
wp_enqueue_script('jquery', '', array(), '1.7.1', true);
2020-12-17 14:35:39 +01:00
wp_enqueue_script('wp-jquery-lightbox', plugins_url(JQLB_SCRIPT, __FILE__ ), Array('jquery'), '1.3.4.1', true);
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
global $wp_lightbox_2;
$wp_lightbox_2->parametrs;
2026-03-31 11:30:59 +02:00
$parametrs_array = array(
'fitToScreen' => (int) get_option('jqlb_resize_on_demand'),
'resizeSpeed' => (int) get_option('jqlb_resize_speed'),
'displayDownloadLink' => (int) get_option('jqlb_show_download'),
'navbarOnTop' => (int) get_option('jqlb_navbarOnTop'),
'loopImages' => (int) get_option('jqlb_loopImages'),
'resizeCenter' => (int) get_option('jqlb_resizeCenter'),
'marginSize' => (int) get_option('jqlb_margin_size'),
'linkTarget' => esc_js( get_option('jqlb_link_target') ),
'help' => esc_js( get_option('jqlb_help_text') ),
'prevLinkTitle' => esc_js( $wp_lightbox_2->parametrs->get_design_settings['jqlb_previous_image_title'] ),
'nextLinkTitle' => esc_js( $wp_lightbox_2->parametrs->get_design_settings['jqlb_next_image_title'] ),
'closeTitle' => esc_js( $wp_lightbox_2->parametrs->get_design_settings['jqlb_close_image_title'] ),
'prevLinkText' => __( '&laquo; Previous', 'jqlb' ),
'nextLinkText' => __( 'Next &raquo;', 'jqlb' ),
'image' => __( 'Image ', 'jqlb' ),
'of' => __( ' of ', 'jqlb' ),
'download' => __( 'Download', 'jqlb' )
2020-12-17 14:35:39 +01:00
);
2026-03-31 11:30:59 +02:00
foreach ( $wp_lightbox_2->parametrs->get_design_settings as $key => $value ) {
$parametrs_array[ $key ] = $value;
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
wp_localize_script(
'wp-jquery-lightbox',
'JQLBSettings',
$parametrs_array
);
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
function jqlb_lightbox_comment( $comment = '' ) {
2020-12-17 14:35:39 +01:00
$comment = str_replace('rel=\'external nofollow\'','', $comment);
$comment = str_replace('rel=\'nofollow\'','', $comment);
$comment = str_replace('rel="external nofollow"','', $comment);
$comment = str_replace('rel="nofollow"','', $comment);
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
return jqlb_autoexpand_rel_wlightbox($comment);
}
2026-03-31 11:30:59 +02:00
function jqlb_autoexpand_rel_wlightbox( $content = '' ) {
if ( 1 === (int) get_option('jqlb_automate') ) {
global $post;
2020-12-17 14:35:39 +01:00
$id = ($post->ID) ? $post->ID : -1;
$content = jqlb_do_regexp($content, $id); //legacy regex function when images don't have rel tags
$content = wplbtwo_do_regexp($content, $id);
2026-03-31 11:30:59 +02:00
}
2020-12-17 14:35:39 +01:00
return $content;
}
2026-03-31 11:30:59 +02:00
function jqlb_apply_lightbox($content, $id = -1) {
if(!isset($id) || $id === -1) {
$id = time() . wp_rand( 0, 32768 );
2020-12-17 14:35:39 +01:00
}
return jqlb_do_regexp($content, $id);
}
/* automatically insert rel="lightbox[nameofpost]" to every image with no manual work.
if there are already rel="lightbox[something]" attributes, they are not clobbered.
2026-03-31 11:30:59 +02:00
Michael Tyson, you are a regular expressions god! - https://atastypixel.com */
function jqlb_do_regexp($content, $id) {
2020-12-17 14:35:39 +01:00
$pattern = "/(<a(?![^>]*?rel=['\"]lightbox.*)(?![^>]*?rel=.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)\?{0,1}\S{0,}['\"][^\>]*)>/i";
2026-03-31 11:30:59 +02:00
$replacement = '$1 rel="lightbox[' . esc_attr( $id ) . ']">';
2020-12-17 14:35:39 +01:00
return preg_replace($pattern, $replacement, $content);
}
/**
* Automatically includes 'lightbox[$id]' into rel tag of images.
*
* @param $content
* @param $id
*
* @return mixed
*
* @since 3.0.6.2
*/
2026-03-31 11:30:59 +02:00
function wplbtwo_do_regexp($content, $id) {
2020-12-17 14:35:39 +01:00
$pattern = "/(<a(?![^>]*?rel=['\"]lightbox.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)\?{0,1}\S{0,}['\"][^\>]*)(rel=['\"])(.*?)>/i";
2026-03-31 11:30:59 +02:00
$replacement = '$1 $2lightbox[' . esc_attr( $id ) . '] $3>';
2020-12-17 14:35:39 +01:00
return preg_replace($pattern, $replacement, $content);
}
2026-03-31 11:30:59 +02:00
function jqlb_bool_intval( $v = 0 ) {
return ( 1 === (int) $v ) ? '1' : '0';
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
function jqlb_pos_intval($v) {
2020-12-17 14:35:39 +01:00
return abs(intval($v));
}
2026-03-31 11:30:59 +02:00
function jplb_help_kses($t) {
return wp_kses_post($t);
}
function jqlb_options_panel() {
if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ) {
die(__('Cheatin&#8217; uh?', 'jqlb'));
}
2020-12-17 14:35:39 +01:00
?>
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
<div class="wrap">
2026-03-31 11:30:59 +02:00
<h2>WP Lightbox 2</h2>
<?php include_once plugin_dir_path(__FILE__) . 'about.php'; ?>
2020-12-17 14:35:39 +01:00
<form method="post" action="options.php">
<table>
2026-03-31 11:30:59 +02:00
<?php settings_fields('jqlb-settings-group'); ?>
2020-12-17 14:35:39 +01:00
<tr valign="baseline" colspan="2">
<td colspan="">
2026-03-31 11:30:59 +02:00
<input type="checkbox" id="jqlb_automate" name="jqlb_automate" value="1" <?php checked( (bool) get_option('jqlb_automate') ); ?> />
2020-12-17 14:35:39 +01:00
<label for="jqlb_automate" title="<?php _e('Let the plugin add necessary html to image links', 'jqlb') ?>"> <?php _e('Auto-lightbox image links', 'jqlb') ?></label>
</td>
</tr>
<tr valign="baseline" colspan="2">
<td colspan="2">
2026-03-31 11:30:59 +02:00
<input type="checkbox" id="jqlb_comments" name="jqlb_comments" value="1" <?php checked( (bool) get_option('jqlb_comments') ); ?> />
<label for="jqlb_comments" title="<?php _e('Note: this will disable the nofollow-attribute of comment links, that otherwise interfere with the lightbox.', 'jqlb') ?>"> <?php _e('Enable lightbox in comments (disables <a href="https://codex.wordpress.org/Nofollow">the nofollow attribute!</a>)', 'jqlb') ?></label>
2020-12-17 14:35:39 +01:00
</td>
</tr>
<tr valign="baseline" colspan="2">
<td>
2026-03-31 11:30:59 +02:00
<input type="checkbox" id="jqlb_show_download" name="jqlb_show_download" value="1" <?php checked( (bool) get_option('jqlb_show_download') ); ?> />
2020-12-17 14:35:39 +01:00
<label for="jqlb_show_download"> <?php _e('Show download link', 'jqlb') ?> </label>
2026-03-31 11:30:59 +02:00
</td>
2020-12-17 14:35:39 +01:00
<td>
2026-03-31 11:30:59 +02:00
<label for="jqlb_link_target" title="<?php _e('_blank: open the image in a new window or tab
2020-12-17 14:35:39 +01:00
_self: open the image in the same frame as it was clicked (default)
_parent: open the image in the parent frameset
2026-03-31 11:30:59 +02:00
_top: open the image in the full body of the window', 'jqlb') ?>"><?php _e('Target for download link:', 'jqlb'); ?></label>
<select id="jqlb_link_target" name="jqlb_link_target">
<option <?php selected( get_option('jqlb_link_target'), '_blank' ); ?>>_blank</option>
<option <?php selected( get_option('jqlb_link_target'), '_self' ); ?>>_self</option>
<option <?php selected( get_option('jqlb_link_target'), '_top' ); ?>>_top</option>
<option <?php selected( get_option('jqlb_link_target'), '_parent' ); ?>>_parent</option>
</select>
</td>
</tr>
<tr valign="baseline" colspan="2">
<td colspan="2">
<input type="checkbox" id="jqlb_navbarOnTop" name="jqlb_navbarOnTop" value="1" <?php checked( (bool) get_option('jqlb_navbarOnTop') ); ?> />
<label for="jqlb_navbarOnTop">
<?php _e('Show image info on top', 'jqlb') ?>
</label>
</td>
</tr>
<tr valign="baseline" colspan="2">
<td>
<input type="checkbox" id="jqlb_resize_on_demand" name="jqlb_resize_on_demand" value="1" <?php checked( (bool) get_option('jqlb_resize_on_demand') ); ?> />
<label for="jqlb_resize_on_demand"><?php _e('Shrink large images to fit smaller screens', 'jqlb') ?></label>
</td>
<?php if ( get_option('jqlb_resize_on_demand') ) : ?>
<td>
<input type="text" id="jqlb_margin_size" name="jqlb_margin_size" value="<?php echo floatval(get_option('jqlb_margin_size')) ?>" size="3" />
<label for="jqlb_margin_size" title="<?php _e('Keep a distance between the image and the screen edges.', 'jqlb') ?>"><?php _e('Minimum margin to screen edge (default: 0)', 'jqlb') ?></label>
</td>
<?php endif; ?>
</tr>
<tr valign="baseline" colspan="2">
<td colspan="2">
<input type="text" id="jqlb_resize_speed" name="jqlb_resize_speed" value="<?php echo intval(get_option('jqlb_resize_speed')) ?>" size="3" />
<label for="jqlb_resize_speed"><?php _e('Animation duration (in milliseconds) ', 'jqlb') ?></label>
2020-12-17 14:35:39 +01:00
</td>
</tr>
2026-03-31 11:30:59 +02:00
<tr valign="baseline" colspan="2">
<td>
<input type="text" id="jqlb_help_text" name="jqlb_help_text" value="<?php echo get_option('jqlb_help_text'); ?>" size="30" />
<label for="jqlb_help_text"><?php _e('Help text (default: none) ', 'jqlb'); ?></label>
</td>
</tr>
</table>
<p style="font-size:xx-small;font-style:italic;"><?php _e('Browse images with your keyboard: Arrows or P(revious)/N(ext) and X/C/ESC for close.', 'jqlb'); ?></p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes', 'jqlb') ?>" />
</p>
</form>
2020-12-17 14:35:39 +01:00
<?php
$locale = jqlb_get_locale();
$diskfile = plugin_dir_path(__FILE__)."I18n/howtouse-{$locale}.html";
2026-03-31 11:30:59 +02:00
if (!file_exists($diskfile)) {
2020-12-17 14:35:39 +01:00
$diskfile = plugin_dir_path(__FILE__).'I18n/howtouse.html';
}
$text = false;
2026-03-31 11:30:59 +02:00
if(function_exists('file_get_contents')) {
$text = file_get_contents($diskfile);
2020-12-17 14:35:39 +01:00
} else {
2026-03-31 11:30:59 +02:00
$text = file($diskfile);
if($text !== false) {
2020-12-17 14:35:39 +01:00
$text = implode("", $text);
2026-03-31 11:30:59 +02:00
}
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
if($text === false) {
$text = '<p>The documentation files are missing! Try <a href="https://wordpress.org/extend/plugins/wp-lightbox-2/">downloading</a> and <a href="https://wordpress.org/extend/plugins/wp-lightbox-2/installation/">re-installing</a> this lightbox plugin.</p>';
2020-12-17 14:35:39 +01:00
}
echo $text;
?>
2026-03-31 11:30:59 +02:00
</div>
2020-12-17 14:35:39 +01:00
<?php }
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
function jqlb_hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
2026-03-31 11:30:59 +02:00
if(empty($color)) {
return $default;
}
if ($color[0] == '#' ) {
$color = substr( $color, 1 );
}
if (strlen($color) == 6) {
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
} elseif ( strlen( $color ) == 3 ) {
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
} else {
return $default;
}
$rgb = array_map('hexdec', $hex);
if($opacity) {
if(abs($opacity) > 1) {
$opacity = 1.0;
}
$output = 'rgba('.implode(",",$rgb).','.$opacity.')';
} else {
$output = 'rgb('.implode(",",$rgb).')';
}
return $output;
2020-12-17 14:35:39 +01:00
}
class wp_lightbox_2{
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
private $plugin_url;
private $plugin_path;
private $version;
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
public $options;
2026-03-31 11:30:59 +02:00
public $parametrs;
public function __construct() {
2020-12-17 14:35:39 +01:00
$this->plugin_url = trailingslashit( plugins_url('', __FILE__ ) );
$this->plugin_path = trailingslashit( plugin_dir_path( __FILE__ ) );
$this->version = 1.0;
2026-03-31 11:30:59 +02:00
require_once $this->plugin_path . 'includes/install_database.php';
$this->parametrs = new wp_lightbox2_database_params();
2020-12-17 14:35:39 +01:00
$this->call_base_filters();
2026-03-31 11:30:59 +02:00
$this->create_admin_menu();
}
private function create_admin_menu() {
2020-12-17 14:35:39 +01:00
2026-03-31 11:30:59 +02:00
require_once $this->plugin_path.'admin/admin_menu.php';
$admin_menu = new wp_lightbox_admin_menu( array(
'plugin_url' => $this->plugin_url,
'plugin_path' => $this->plugin_path,
'databese_parametrs' => $this->parametrs
) );
add_action('admin_menu', array( $admin_menu, 'create_menu' ) );
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
public function registr_requeried_scripts() {
wp_register_script('angularejs',$this->plugin_url . 'admin/scripts/angular.min.js');
wp_register_style('admin_style_wp_lightbox',$this->plugin_url . 'admin/styles/admin_themplate.css');
wp_register_style('jquery-ui-style',$this->plugin_url . 'admin/styles/jquery-ui.css');
2020-12-17 14:35:39 +01:00
}
2026-03-31 11:30:59 +02:00
public function enqueue_requeried_scripts() {
2020-12-17 14:35:39 +01:00
wp_enqueue_style("jquery-ui-style");
wp_enqueue_script("jquery-ui-slider");
}
2026-03-31 11:30:59 +02:00
public function call_base_filters() {
2020-12-17 14:35:39 +01:00
add_action( 'init', array($this,'registr_requeried_scripts') );
add_action( 'admin_head', array($this,'enqueue_requeried_scripts') );
}
}
2026-03-31 11:30:59 +02:00
2020-12-17 14:35:39 +01:00
$wp_lightbox_2 = new wp_lightbox_2();