| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Slideshow SE |
| 4 |
Plugin URI: http://wordpress.org/extend/plugins/slideshow-se/ |
| 5 |
Description: The slideshow plugin is easily deployable on your website. Add any image that has already been uploaded to add to your slideshow, add text slides, or even add a video. Options and styles are customizable for every single slideshow on your website. |
| 6 |
Version: 2.7.0 |
| 7 |
Requires at least: 6.3 |
| 8 |
Tested up to: 7.0 |
| 9 |
Requires PHP: 5.0 |
| 10 |
Author: John West |
| 11 |
License: GPLv2 |
| 12 |
Text Domain: slideshow-se |
| 13 |
*/ |
| 14 |
|
| 15 |
// Exit if accessed directly. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Class SlideshowSEPluginMain fires up the application on plugin load and provides some |
| 22 |
* methods for the other classes to use like the auto-includer and the |
| 23 |
* base path/url returning method. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @author Stefan Boonstra |
| 27 |
*/ |
| 28 |
class SlideshowSEPluginMain |
| 29 |
{ |
| 30 |
/** @var string $version */ |
| 31 |
static $version = '2.7.0'; |
| 32 |
|
| 33 |
/** |
| 34 |
* Bootstraps the application by assigning the right functions to |
| 35 |
* the right action hooks. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
*/ |
| 39 |
static function bootStrap() |
| 40 |
{ |
| 41 |
self::autoInclude(); |
| 42 |
|
| 43 |
// Initialize localization on init |
| 44 |
add_action('init', array(__CLASS__, 'localize')); |
| 45 |
// Initialize the Gutenberg block |
| 46 |
add_action( 'init', 'f1rehead_slideshow_block_init' ); |
| 47 |
|
| 48 |
// Enqueue hooks |
| 49 |
add_action('wp_enqueue_scripts' , array(__CLASS__, 'enqueueFrontendScripts')); |
| 50 |
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueueBackendScripts')); |
| 51 |
|
| 52 |
// Ajax requests |
| 53 |
SlideshowSEPluginAJAX::init(); |
| 54 |
|
| 55 |
// Register slideshow post type |
| 56 |
SlideshowSEPluginPostType::init(); |
| 57 |
|
| 58 |
// Add general settings page |
| 59 |
SlideshowSEPluginGeneralSettings::init(); |
| 60 |
|
| 61 |
// Initialize stylesheet builder |
| 62 |
SlideshowSEPluginSlideshowStylesheet::init(); |
| 63 |
|
| 64 |
// Deploy slideshow on do_action('slideshow_deploy'); hook. |
| 65 |
add_action('slideshow_deploy', array('SlideshowSEPlugin', 'deploy')); |
| 66 |
|
| 67 |
// Initialize shortcode |
| 68 |
SlideshowSEPluginShortcode::init(); |
| 69 |
|
| 70 |
// Register widget |
| 71 |
add_action('widgets_init', array('SlideshowSEPluginWidget', 'registerWidget')); |
| 72 |
|
| 73 |
// Initialize plugin updater |
| 74 |
SlideshowSEPluginInstaller::init(); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Enqueues frontend scripts and styles. |
| 79 |
* |
| 80 |
* Should always be called on the wp_enqueue_scripts hook. |
| 81 |
* |
| 82 |
* @since 2.3.0 |
| 83 |
*/ |
| 84 |
static function enqueueFrontendScripts() |
| 85 |
{ |
| 86 |
// Enqueue slideshow script if lazy loading is enabled |
| 87 |
if (SlideshowSEPluginGeneralSettings::getEnableLazyLoading()) |
| 88 |
{ |
| 89 |
wp_enqueue_script( |
| 90 |
'slideshow-jquery-image-gallery-script', |
| 91 |
self::getPluginUrl() . '/js/min/all.frontend.min.js', |
| 92 |
array('jquery'), |
| 93 |
self::$version, |
| 94 |
false |
| 95 |
); |
| 96 |
|
| 97 |
// adminURL string was removed in 6bc7f538425a2d399a747746500f363bd786331a |
| 98 |
// not sure why this wasn't removed back then... |
| 99 |
//wp_localize_script( |
| 100 |
// 'slideshow-jquery-image-gallery-script', |
| 101 |
// 'slideshow_jquery_image_gallery_script_adminURL', |
| 102 |
// admin_url() |
| 103 |
//); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Enqueues backend scripts and styles. |
| 109 |
* |
| 110 |
* Should always be called on the admin_enqueue_scrips hook. |
| 111 |
* |
| 112 |
* @since 2.2.12 |
| 113 |
*/ |
| 114 |
static function enqueueBackendScripts() |
| 115 |
{ |
| 116 |
// Function get_current_screen() should be defined, as this method is expected to fire at 'admin_enqueue_scripts' |
| 117 |
if (!function_exists('get_current_screen')) |
| 118 |
{ |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
$currentScreen = get_current_screen(); |
| 123 |
|
| 124 |
$backend_script_dependencies = array( |
| 125 |
'jquery', |
| 126 |
'jquery-ui-sortable', |
| 127 |
'wp-color-picker', |
| 128 |
); |
| 129 |
|
| 130 |
// Enqueue 3.5 uploader and editor for slideshow add/edit screens. |
| 131 |
if ($currentScreen->post_type === 'slideshow') { |
| 132 |
if (function_exists('wp_enqueue_media')) { |
| 133 |
wp_enqueue_media(); |
| 134 |
} |
| 135 |
if (function_exists('wp_enqueue_editor')) { |
| 136 |
wp_enqueue_editor(); |
| 137 |
$backend_script_dependencies[] = 'wp-editor'; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
wp_enqueue_script( |
| 142 |
'slideshow-se-jquery-image-gallery-backend-script', |
| 143 |
self::getPluginUrl() . '/js/min/all.backend.min.js', |
| 144 |
$backend_script_dependencies, |
| 145 |
SlideshowSEPluginMain::$version, |
| 146 |
false |
| 147 |
); |
| 148 |
|
| 149 |
wp_enqueue_style( |
| 150 |
'slideshow-se-jquery-image-gallery-backend-style', |
| 151 |
self::getPluginUrl() . '/css/all.backend.css', |
| 152 |
array( |
| 153 |
'wp-color-picker' |
| 154 |
), |
| 155 |
SlideshowSEPluginMain::$version |
| 156 |
); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Translates the plugin |
| 161 |
* |
| 162 |
* @since 1.0.0 |
| 163 |
*/ |
| 164 |
static function localize() |
| 165 |
{ |
| 166 |
load_plugin_textdomain( |
| 167 |
'slideshow-se', |
| 168 |
false, |
| 169 |
dirname(plugin_basename(__FILE__)) . '/languages/' |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Returns url to the base directory of this plugin. |
| 175 |
* |
| 176 |
* @since 1.0.0 |
| 177 |
* @return string pluginUrl |
| 178 |
*/ |
| 179 |
static function getPluginUrl() |
| 180 |
{ |
| 181 |
return plugins_url('', __FILE__); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Returns path to the base directory of this plugin |
| 186 |
* |
| 187 |
* @since 1.0.0 |
| 188 |
* @return string pluginPath |
| 189 |
*/ |
| 190 |
static function getPluginPath() |
| 191 |
{ |
| 192 |
return dirname(__FILE__); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Outputs the passed view. It's good practice to pass an object like an stdClass to the $data variable, as it can |
| 197 |
* be easily checked for validity in the view itself using "instanceof". |
| 198 |
* |
| 199 |
* @since 2.3.0 |
| 200 |
* @param string $view |
| 201 |
* @param stdClass $data (Optional, defaults to stdClass) |
| 202 |
*/ |
| 203 |
static function outputView($view, $data = null) |
| 204 |
{ |
| 205 |
if (!($data instanceof stdClass)) |
| 206 |
{ |
| 207 |
$data = new stdClass(); |
| 208 |
} |
| 209 |
|
| 210 |
$file = self::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view; |
| 211 |
|
| 212 |
if (file_exists($file)) |
| 213 |
{ |
| 214 |
include $file; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Uses self::outputView to render the passed view. Returns the rendered view instead of outputting it. |
| 220 |
* |
| 221 |
* @since 2.3.0 |
| 222 |
* @param string $view |
| 223 |
* @param stdClass $data (Optional, defaults to null) |
| 224 |
* @return string |
| 225 |
*/ |
| 226 |
static function getView($view, $data = null) |
| 227 |
{ |
| 228 |
ob_start(); |
| 229 |
self::outputView($view, $data); |
| 230 |
return ob_get_clean(); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* This function will load classes automatically on-call. |
| 235 |
* |
| 236 |
* @since 1.0.0 |
| 237 |
*/ |
| 238 |
static function autoInclude() |
| 239 |
{ |
| 240 |
if (!function_exists('spl_autoload_register')) |
| 241 |
{ |
| 242 |
return; |
| 243 |
} |
| 244 |
|
| 245 |
function SlideshowSEPluginAutoLoader($name) |
| 246 |
{ |
| 247 |
$name = str_replace('\\', DIRECTORY_SEPARATOR, $name); |
| 248 |
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $name . '.php'; |
| 249 |
|
| 250 |
if (is_file($file)) |
| 251 |
{ |
| 252 |
require_once $file; |
| 253 |
} |
| 254 |
} |
| 255 |
// Don't forget the render callback for the Gutenberg block |
| 256 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'block.php'; |
| 257 |
spl_autoload_register('SlideshowSEPluginAutoLoader'); |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* This function will return the list of HTML tags allowed in the wp_kses functions. |
| 262 |
* |
| 263 |
* @since 2.5.19 |
| 264 |
*/ |
| 265 |
|
| 266 |
static function getAllowedTags() |
| 267 |
{ |
| 268 |
// HTML tags to allow in the wp_kses calls |
| 269 |
$allowedTags = array( |
| 270 |
'input' => array( |
| 271 |
'type' => array(), |
| 272 |
'name' => array(), |
| 273 |
'class' => array(), |
| 274 |
'value' => array(), |
| 275 |
'checked' => array(), |
| 276 |
), |
| 277 |
'textarea' => array( |
| 278 |
'name' => array(), |
| 279 |
'class' => array(), |
| 280 |
'rows' => array(), |
| 281 |
'cols' => array(), |
| 282 |
), |
| 283 |
'select' => array( |
| 284 |
'name' => array(), |
| 285 |
'class' => array(), |
| 286 |
), |
| 287 |
'option' => array( |
| 288 |
'value' => array(), |
| 289 |
'selected' => array() |
| 290 |
), |
| 291 |
'label' => array( |
| 292 |
'style' => array(), |
| 293 |
) |
| 294 |
); |
| 295 |
|
| 296 |
return $allowedTags; |
| 297 |
} |
| 298 |
}; |
| 299 |
|
| 300 |
/** |
| 301 |
* Include the slideshow post type in front-end search without replacing other post types. |
| 302 |
* |
| 303 |
* @since 2.5.21 |
| 304 |
* @param WP_Query $query Main query. |
| 305 |
*/ |
| 306 |
function f1rehead_slideshow_include_custom_post_types_in_search_results( $query ) { |
| 307 |
if ( ! $query->is_main_query() || ! $query->is_search() || is_admin() ) { |
| 308 |
return; |
| 309 |
} |
| 310 |
|
| 311 |
$post_types = $query->get( 'post_type' ); |
| 312 |
|
| 313 |
if ( empty( $post_types ) ) { |
| 314 |
$searchable = get_post_types( array( 'exclude_from_search' => false ), 'names' ); |
| 315 |
$searchable['slideshow'] = SlideshowSEPluginPostType::$postType; |
| 316 |
$query->set( 'post_type', array_values( array_unique( $searchable ) ) ); |
| 317 |
return; |
| 318 |
} |
| 319 |
|
| 320 |
if ( is_array( $post_types ) ) { |
| 321 |
if ( ! in_array( SlideshowSEPluginPostType::$postType, $post_types, true ) ) { |
| 322 |
$post_types[] = SlideshowSEPluginPostType::$postType; |
| 323 |
$query->set( 'post_type', array_values( array_unique( $post_types ) ) ); |
| 324 |
} |
| 325 |
return; |
| 326 |
} |
| 327 |
|
| 328 |
if ( is_string( $post_types ) && SlideshowSEPluginPostType::$postType !== $post_types ) { |
| 329 |
$query->set( 'post_type', array( $post_types, SlideshowSEPluginPostType::$postType ) ); |
| 330 |
} |
| 331 |
} |
| 332 |
add_action( 'pre_get_posts', 'f1rehead_slideshow_include_custom_post_types_in_search_results' ); |
| 333 |
|
| 334 |
/** |
| 335 |
* Registers all block assets so that they can be enqueued through the block editor |
| 336 |
* in the corresponding context. |
| 337 |
* |
| 338 |
* @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/ |
| 339 |
*/ |
| 340 |
function f1rehead_slideshow_block_init() { |
| 341 |
$dir = dirname( __FILE__ ); |
| 342 |
|
| 343 |
$script_asset_path = $dir . '/block/index.asset.php'; |
| 344 |
$index_js_path = $dir . '/block/index.js'; |
| 345 |
if ( ! file_exists( $script_asset_path ) || ! file_exists( $index_js_path ) ) { |
| 346 |
_doing_it_wrong( |
| 347 |
__FUNCTION__, |
| 348 |
'Slideshow SE: run `npm install` and `npm run build` in the plugin directory so block assets exist.', |
| 349 |
'2.7.0' |
| 350 |
); |
| 351 |
if ( is_admin() && current_user_can( 'activate_plugins' ) ) { |
| 352 |
add_action( |
| 353 |
'admin_notices', |
| 354 |
static function () { |
| 355 |
echo '<div class="notice notice-error"><p>'; |
| 356 |
echo esc_html__( 'Slideshow SE: Gutenberg block assets are missing. From the plugin folder, run npm install and npm run build.', 'slideshow-se' ); |
| 357 |
echo '</p></div>'; |
| 358 |
} |
| 359 |
); |
| 360 |
} |
| 361 |
return; |
| 362 |
} |
| 363 |
$index_js = 'block/index.js'; |
| 364 |
$script_asset = require $script_asset_path; |
| 365 |
wp_register_script( |
| 366 |
'f1rehead-slideshow-block-editor', |
| 367 |
plugins_url( $index_js, __FILE__ ), |
| 368 |
$script_asset['dependencies'], |
| 369 |
$script_asset['version'], |
| 370 |
false |
| 371 |
); |
| 372 |
|
| 373 |
$block_css = 'block/index.css'; |
| 374 |
$block_css_full = $dir . '/' . $block_css; |
| 375 |
wp_register_style( |
| 376 |
'slideshow-se-editor-functional', |
| 377 |
plugins_url( 'style/SlideshowSEPlugin/functional.css', __FILE__ ), |
| 378 |
array(), |
| 379 |
SlideshowSEPluginMain::$version |
| 380 |
); |
| 381 |
|
| 382 |
wp_register_style( |
| 383 |
'f1rehead-slideshow-block', |
| 384 |
plugins_url( $block_css, __FILE__ ), |
| 385 |
array( 'slideshow-se-editor-functional' ), |
| 386 |
file_exists( $block_css_full ) ? filemtime( $block_css_full ) : false |
| 387 |
); |
| 388 |
|
| 389 |
// WP Localized globals. Use dynamic PHP stuff in JavaScript via `globals` object. |
| 390 |
$slideshow_posts = get_posts( |
| 391 |
array( |
| 392 |
'posts_per_page' => -1, |
| 393 |
'post_type' => 'slideshow', |
| 394 |
'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future' ), |
| 395 |
'orderby' => 'date', |
| 396 |
'order' => 'DESC', |
| 397 |
) |
| 398 |
); |
| 399 |
$slideshow_choices = array(); |
| 400 |
foreach ( $slideshow_posts as $p ) { |
| 401 |
$settings = SlideshowSEPluginSlideshowSettingsHandler::getSettings( (int) $p->ID, false ); |
| 402 |
$slideshow_height = isset( $settings['height'] ) |
| 403 |
? (int) filter_var( (string) $settings['height'], FILTER_SANITIZE_NUMBER_INT ) |
| 404 |
: 0; |
| 405 |
if ( $slideshow_height < 1 ) { |
| 406 |
$slideshow_height = 200; |
| 407 |
} |
| 408 |
$slideshow_choices[] = array( |
| 409 |
'ID' => (int) $p->ID, |
| 410 |
'post_title' => $p->post_title, |
| 411 |
'height' => $slideshow_height, |
| 412 |
); |
| 413 |
} |
| 414 |
wp_localize_script( |
| 415 |
'f1rehead-slideshow-block-editor', |
| 416 |
'globals', |
| 417 |
array( |
| 418 |
'pluginDirPath' => plugin_dir_path( __FILE__ ), |
| 419 |
'pluginDirUrl' => plugin_dir_url( __FILE__ ), |
| 420 |
'slideshows' => $slideshow_choices, |
| 421 |
) |
| 422 |
); |
| 423 |
|
| 424 |
register_block_type( |
| 425 |
'f1rehead/slideshow', |
| 426 |
array( |
| 427 |
'api_version' => 3, |
| 428 |
'editor_script' => 'f1rehead-slideshow-block-editor', |
| 429 |
'editor_style' => 'f1rehead-slideshow-block', |
| 430 |
'style' => 'f1rehead-slideshow-block', |
| 431 |
'render_callback' => 'f1rehead_slideshow_render_slideshow_block', |
| 432 |
// Must match src/index.js — REST block renderer validates against server registration. |
| 433 |
'attributes' => array( |
| 434 |
'selectedSlideshow' => array( |
| 435 |
'type' => 'string', |
| 436 |
'default' => '', |
| 437 |
), |
| 438 |
), |
| 439 |
) |
| 440 |
); |
| 441 |
} |
| 442 |
|
| 443 |
/** |
| 444 |
* Activate plugin |
| 445 |
*/ |
| 446 |
SlideshowSEPluginMain::bootStrap(); |
| 447 |
|