PluginProbe
Slideshow SE / 2.5
Slideshow SE v2.5
2.7.2 2.7.1 trunk 2.5 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.18 2.5.19 2.5.2 2.5.20 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 All 26 releases
slideshow-se / slideshow-se.php

slideshow-se.php in Slideshow SE 2.5, at slideshow-se.php

316 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.5.0
7 Requires at least: 5.0
8 Tested up to: 5.5
9 Requires PHP: 5.0
10 Author: John West, StefanBoonstra
11 Author URI: http://stefanboonstra.com/
12 License: GPLv2
13 Text Domain: slideshow-se
14 */
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Class SlideshowSEPluginMain fires up the application on plugin load and provides some
23 * methods for the other classes to use like the auto-includer and the
24 * base path/url returning method.
25 *
26 * @since 1.0.0
27 * @author Stefan Boonstra
28 */
29 class SlideshowSEPluginMain
30 {
31 /** @var string $version */
32 static $version = '2.5.0';
33
34 /**
35 * Bootstraps the application by assigning the right functions to
36 * the right action hooks.
37 *
38 * @since 1.0.0
39 */
40 static function bootStrap()
41 {
42 self::autoInclude();
43
44 // Initialize localization on init
45 add_action('init', array(__CLASS__, 'localize'));
46 // Initialize the Gutenberg block
47 add_action( 'init', 'f1rehead_slideshow_block_init' );
48
49 // Enqueue hooks
50 add_action('wp_enqueue_scripts' , array(__CLASS__, 'enqueueFrontendScripts'));
51 add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueueBackendScripts'));
52
53 // Ajax requests
54 SlideshowSEPluginAJAX::init();
55
56 // Register slideshow post type
57 SlideshowSEPluginPostType::init();
58
59 // Add general settings page
60 SlideshowSEPluginGeneralSettings::init();
61
62 // Initialize stylesheet builder
63 SlideshowSEPluginSlideshowStylesheet::init();
64
65 // Deploy slideshow on do_action('slideshow_deploy'); hook.
66 add_action('slideshow_deploy', array('SlideshowSEPlugin', 'deploy'));
67
68 // Initialize shortcode
69 SlideshowSEPluginShortcode::init();
70
71 // Register widget
72 add_action('widgets_init', array('SlideshowSEPluginWidget', 'registerWidget'));
73
74 // Initialize plugin updater
75 SlideshowSEPluginInstaller::init();
76 }
77
78 /**
79 * Enqueues frontend scripts and styles.
80 *
81 * Should always be called on the wp_enqueue_scripts hook.
82 *
83 * @since 2.3.0
84 */
85 static function enqueueFrontendScripts()
86 {
87 // Enqueue slideshow script if lazy loading is enabled
88 if (SlideshowSEPluginGeneralSettings::getEnableLazyLoading())
89 {
90 wp_enqueue_script(
91 'slideshow-jquery-image-gallery-script',
92 self::getPluginUrl() . '/js/min/all.frontend.min.js',
93 array('jquery'),
94 self::$version
95 );
96
97 wp_localize_script(
98 'slideshow-jquery-image-gallery-script',
99 'slideshow_jquery_image_gallery_script_adminURL',
100 admin_url()
101 );
102 }
103 }
104
105 /**
106 * Enqueues backend scripts and styles.
107 *
108 * Should always be called on the admin_enqueue_scrips hook.
109 *
110 * @since 2.2.12
111 */
112 static function enqueueBackendScripts()
113 {
114 // Function get_current_screen() should be defined, as this method is expected to fire at 'admin_enqueue_scripts'
115 if (!function_exists('get_current_screen'))
116 {
117 return;
118 }
119
120 $currentScreen = get_current_screen();
121
122 // Enqueue 3.5 uploader
123 if ($currentScreen->post_type === 'slideshow' &&
124 function_exists('wp_enqueue_media'))
125 {
126 wp_enqueue_media();
127 }
128
129 wp_enqueue_script(
130 'slideshow-se-jquery-image-gallery-backend-script',
131 self::getPluginUrl() . '/js/min/all.backend.min.js',
132 array(
133 'jquery',
134 'jquery-ui-sortable',
135 'wp-color-picker'
136 ),
137 SlideshowSEPluginMain::$version
138 );
139
140 wp_enqueue_style(
141 'slideshow-se-jquery-image-gallery-backend-style',
142 self::getPluginUrl() . '/css/all.backend.css',
143 array(
144 'wp-color-picker'
145 ),
146 SlideshowSEPluginMain::$version
147 );
148 }
149
150 /**
151 * Translates the plugin
152 *
153 * @since 1.0.0
154 */
155 static function localize()
156 {
157 load_plugin_textdomain(
158 'slideshow-se',
159 false,
160 dirname(plugin_basename(__FILE__)) . '/languages/'
161 );
162 }
163
164 /**
165 * Returns url to the base directory of this plugin.
166 *
167 * @since 1.0.0
168 * @return string pluginUrl
169 */
170 static function getPluginUrl()
171 {
172 return plugins_url('', __FILE__);
173 }
174
175 /**
176 * Returns path to the base directory of this plugin
177 *
178 * @since 1.0.0
179 * @return string pluginPath
180 */
181 static function getPluginPath()
182 {
183 return dirname(__FILE__);
184 }
185
186 /**
187 * Outputs the passed view. It's good practice to pass an object like an stdClass to the $data variable, as it can
188 * be easily checked for validity in the view itself using "instanceof".
189 *
190 * @since 2.3.0
191 * @param string $view
192 * @param stdClass $data (Optional, defaults to stdClass)
193 */
194 static function outputView($view, $data = null)
195 {
196 if (!($data instanceof stdClass))
197 {
198 $data = new stdClass();
199 }
200
201 $file = self::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view;
202
203 if (file_exists($file))
204 {
205 include $file;
206 }
207 }
208
209 /**
210 * Uses self::outputView to render the passed view. Returns the rendered view instead of outputting it.
211 *
212 * @since 2.3.0
213 * @param string $view
214 * @param stdClass $data (Optional, defaults to null)
215 * @return string
216 */
217 static function getView($view, $data = null)
218 {
219 ob_start();
220 self::outputView($view, $data);
221 return ob_get_clean();
222 }
223
224 /**
225 * This function will load classes automatically on-call.
226 *
227 * @since 1.0.0
228 */
229 static function autoInclude()
230 {
231 if (!function_exists('spl_autoload_register'))
232 {
233 return;
234 }
235
236 function SlideshowSEPluginAutoLoader($name)
237 {
238 $name = str_replace('\\', DIRECTORY_SEPARATOR, $name);
239 $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $name . '.php';
240
241 if (is_file($file))
242 {
243 require_once $file;
244 }
245 }
246 // Don't forget the render callback for the Gutenberg block
247 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'block.php';
248 spl_autoload_register('SlideshowSEPluginAutoLoader');
249 }
250 }
251
252 /**
253 * Registers all block assets so that they can be enqueued through the block editor
254 * in the corresponding context.
255 *
256 * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
257 */
258 function f1rehead_slideshow_block_init() {
259 $dir = dirname( __FILE__ );
260
261 $script_asset_path = "$dir/block/index.asset.php";
262 if ( ! file_exists( $script_asset_path ) ) {
263 throw new Error(
264 'You need to run `npm start` or `npm run build` for the "f1rehead/slideshow" block first.'
265 );
266 }
267 $index_js = 'block/index.js';
268 $script_asset = require( $script_asset_path );
269 wp_register_script(
270 'f1rehead-slideshow-block-editor',
271 plugins_url( $index_js, __FILE__ ),
272 $script_asset['dependencies'],
273 $script_asset['version']
274 );
275
276 $editor_css = 'block/index.css';
277 wp_register_style(
278 'f1rehead-slideshow-block-editor',
279 plugins_url( $editor_css, __FILE__ ),
280 array(),
281 filemtime( "$dir/$editor_css" )
282 );
283
284 $style_css = 'block/style-index.css';
285 wp_register_style(
286 'f1rehead-slideshow-block',
287 plugins_url( $style_css, __FILE__ ),
288 array(),
289 filemtime( "$dir/$style_css" )
290 );
291
292 // WP Localized globals. Use dynamic PHP stuff in JavaScript via `globals` object.
293 wp_localize_script(
294 'f1rehead-slideshow-block-editor',
295 'globals', // Array containing dynamic data for a JS Global.
296 [
297 'pluginDirPath' => plugin_dir_path( __DIR__ ),
298 'pluginDirUrl' => plugin_dir_url( __DIR__ ),
299 // Add data here to access from `globals` object.
300 'slideshows' => get_posts(['posts_per_page' => -1, 'post_type' => 'slideshow']),
301 ]
302 );
303
304 register_block_type( 'f1rehead/slideshow', array(
305 'editor_script' => 'f1rehead-slideshow-block-editor',
306 'editor_style' => 'f1rehead-slideshow-block-editor',
307 'style' => 'f1rehead-slideshow-block',
308 'render_callback' => 'f1rehead_slideshow_render_slideshow_block',
309 ) );
310 }
311
312 /**
313 * Activate plugin
314 */
315 SlideShowSEPluginMain::bootStrap();
316