PluginProbe
Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery / trunk
Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery vtrunk
2.1.14 2.1.13 2.1.12 2.1.11 2.1.10 2.1.9 2.1.8 2.1.7 trunk 1.2.2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0 1.4.1 1.4.10 1.4.11 1.4.2 1.4.3 1.4.5 1.4.6 All 74 releases
pixel-gallery / loader.php

loader.php in Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery trunk, at loader.php

440 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PixelGallery;
4
5 use Pixel_Gallery\Includes\Pixel_Gallery_WPML;
6
7 use Elementor\Plugin;
8
9 if (!defined('ABSPATH')) {
10 exit;
11 } // Exit if accessed directly
12
13 /**
14 * Main class for pixel gallery
15 */
16 class Pixel_Gallery_Loader {
17
18 /**
19 * @var Pixel_Gallery_Loader
20 */
21 private static $_instance;
22
23 /**
24 * @var Manager
25 */
26 private $_modules_manager;
27
28 public $elements_data = [
29 'sections' => [],
30 'columns' => [],
31 'widgets' => [],
32 ];
33
34 private function get_upload_dir() {
35 return trailingslashit(wp_upload_dir()['basedir']) . 'pixel-gallery/minified/';
36 }
37
38 private function get_upload_url() {
39 return trailingslashit(wp_upload_dir()['baseurl']) . 'pixel-gallery/minified/';
40 }
41
42 /**
43 * @return string
44 * @deprecated
45 *
46 */
47 public function get_version() {
48 return BDTPG_VER;
49 }
50
51 /**
52 * return active theme
53 */
54 public function get_theme() {
55 return wp_get_theme();
56 }
57
58 /**
59 * Throw error on object clone
60 *
61 * The whole idea of the singleton design pattern is that there is a single
62 * object therefore, we don't want the object to be cloned.
63 *
64 * @return void
65 * @since 1.0.0
66 */
67 public function __clone() {
68 // Cloning instances of the class is forbidden
69 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&#8217; huh?', 'pixel-gallery'), '1.6.0');
70 }
71
72 /**
73 * Disable unserializing of the class
74 *
75 * @return void
76 * @since 1.0.0
77 */
78 public function __wakeup() {
79 // Unserializing instances of the class is forbidden
80 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&#8217; huh?', 'pixel-gallery'), '1.6.0');
81 }
82
83 /**
84 * @return Plugin
85 */
86
87 public static function elementor() {
88 return Plugin::$instance;
89 }
90
91 /**
92 * @return Pixel_Gallery_Loader
93 */
94 public static function instance() {
95 if (is_null(self::$_instance)) {
96 self::$_instance = new self();
97 }
98
99 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Long-standing public hook; renaming would break released Pixel Gallery Pro versions and third-party integrations.
100 do_action('bdthemes_pixel_gallery/init');
101 return self::$_instance;
102 }
103
104
105 /**
106 * we loaded module manager + admin php from here
107 * @return [type] [description]
108 */
109 private function _includes() {
110
111 $essential_shortcodes = pixel_gallery_option('essential-shortcodes', 'pixel_gallery_other_settings', 'off');
112
113 // Admin settings controller
114 require_once BDTPG_ADMIN_PATH . 'module-settings.php';
115 //Assets Manager
116 require_once 'admin/optimizer/asset-minifier-manager.php';
117
118 // Dynamic Select control
119 require_once BDTPG_INC_PATH . 'controls/select-input/dynamic-select-input-module.php';
120 require_once BDTPG_INC_PATH . 'controls/select-input/dynamic-select.php';
121
122 // Global Controls
123 require_once BDTPG_PATH . 'traits/global-widget-controls.php';
124 require_once BDTPG_PATH . 'traits/global-terms-query-controls.php';
125 // require_once BDTPG_PATH . 'traits/global-mask-controls.php';
126
127
128 // wpml compatibility class for wpml support
129 require_once BDTPG_PATH . 'includes/class-elements-wpml-compatibility.php';
130
131
132 // All modules loading from here
133 require_once BDTPG_INC_PATH . 'modules-manager.php';
134
135
136 // Shortcode loader for works some essential shortcode that need for any purpose
137 if ($essential_shortcodes == 'on') {
138 require_once BDTPG_INC_PATH . 'shortcodes/shortcode-loader.php';
139 }
140 }
141
142 /**
143 * Autoloader function for all classes files
144 *
145 * @param [type] class [description]
146 *
147 * @return [type] [description]
148 */
149 public function autoload($class) {
150 if (0 !== strpos($class, __NAMESPACE__)) {
151 return;
152 }
153
154
155 $class_to_load = $class;
156
157 if (!class_exists($class_to_load)) {
158 $filename = strtolower(
159 preg_replace(
160 ['/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z0-9])/', '/_/', '/\\\/'],
161 ['', '$1-$2', '-', DIRECTORY_SEPARATOR],
162 $class_to_load
163 )
164 );
165
166 $filename = BDTPG_PATH . $filename . '.php';
167
168 if (is_readable($filename)) {
169 include($filename);
170 }
171 }
172 }
173
174 /**
175 * Register all script that need for any specific widget on call basis.
176 * @return [type] [description]
177 */
178 public function register_site_scripts() {
179 wp_register_script('pg-animations', BDTPG_ASSETS_URL . 'js/extensions/pg-animations.min.js', ['jquery'], BDTPG_VER, true);
180 }
181
182 /**
183 * Loading site related style from here.
184 * @return [type] [description]
185 */
186 public function enqueue_site_styles() {
187
188 $direction_suffix = is_rtl() ? '.rtl' : '';
189
190 wp_enqueue_style('pg-helper', BDTPG_ASSETS_URL . 'css/pg-helper.css', ['e-swiper'], BDTPG_VER);
191 wp_enqueue_style('pg-font', BDTPG_ASSETS_URL . 'css/pg-font.css', [], BDTPG_VER);
192 }
193
194 public function enqueue_editor_scripts() {
195
196 wp_enqueue_script(
197 'pg-editor',
198 BDTPG_ASSETS_URL . 'js/pg-editor.min.js',
199 [
200 'backbone-marionette',
201 'elementor-common-modules',
202 'elementor-editor-modules',
203 ],
204 BDTPG_VER,
205 true
206 );
207
208 $_is_pg_pro_activated = false;
209 if (function_exists('pixel_gallery_license_validation') && true === pixel_gallery_license_validation()) {
210 $_is_pg_pro_activated = true;
211 }
212
213 $localize_data = [
214 'pro_installed' => _is_pg_pro_activated(),
215 'pro_license_activated' => $_is_pg_pro_activated,
216 'promotional_widgets' => [],
217 ];
218
219 if (!$_is_pg_pro_activated) {
220 $pro_widget_map = new \PixelGallery\Includes\Pro_Widget_Map();
221 $localize_data['promotional_widgets'] = $pro_widget_map->get_pro_widget_map();
222 }
223
224 wp_localize_script('pg-editor', 'PixelGalleryConfigEditor', $localize_data);
225 }
226
227 public function enqueue_editor_styles() {
228 $direction_suffix = is_rtl() ? '.rtl' : '';
229
230 wp_enqueue_style('pg-editor', BDTPG_ASSETS_URL . 'css/pg-editor.css', '', BDTPG_VER);
231 wp_add_inline_style(
232 'pg-editor',
233 '#elementor-panel{'
234 . '--pg-pro-control-message:' . wp_json_encode( __( 'This is a pro control, available with Pixel Gallery Pro version.', 'pixel-gallery' ) ) . ';'
235 . '--pg-badge-new:' . wp_json_encode( __( 'NEW', 'pixel-gallery' ) ) . ';'
236 . '--pg-badge-pro:' . wp_json_encode( __( 'PRO', 'pixel-gallery' ) ) . ';'
237 . '}'
238 );
239 }
240
241
242 public function enqueue_minified_css() {
243 $direction_suffix = is_rtl() ? '.rtl' : '';
244
245 $upload_dir = $this->get_upload_dir() . 'css/pg-styles.css';
246 $version = get_option('pixel-gallery-minified-asset-manager-version');
247
248 if (pixel_gallery_is_asset_optimization_enabled() && file_exists($upload_dir)) {
249 $upload_url = $this->get_upload_url() . 'css/pg-styles.css';
250 wp_register_style('pg-styles', $upload_url, [], $version);
251 } else {
252 wp_register_style('pg-styles', BDTPG_URL . 'assets/css/pg-styles.css', [], BDTPG_VER);
253 }
254
255 if (pixel_gallery_is_asset_optimization_enabled()) {
256 wp_enqueue_style('pg-styles');
257 }
258 }
259
260 public function enqueue_minified_js() {
261
262 $upload_dir = $this->get_upload_dir() . 'js/pg-scripts.js';
263 $version = get_option('pixel-gallery-minified-asset-manager-version');
264
265 if (pixel_gallery_is_asset_optimization_enabled() && file_exists($upload_dir)) {
266 $upload_url = $this->get_upload_url() . 'js/pg-scripts.min.js';
267
268 wp_register_script('pg-scripts', $upload_url, ['elementor-frontend'], $version, true);
269 } else {
270 wp_register_script('pg-scripts', BDTPG_URL . 'assets/js/pg-scripts.min.js', ['elementor-frontend'], BDTPG_VER, true);
271 }
272
273 if (pixel_gallery_is_asset_optimization_enabled()) {
274 wp_enqueue_script('pg-scripts');
275 }
276 }
277
278
279 /**
280 * Callback to shortcodes template
281 * @param array $atts attributes for shortcode.
282 */
283 public function shortcode_template($atts) {
284
285 $atts = shortcode_atts(
286 array(
287 'id' => '',
288 ),
289 $atts,
290 'rooten_custom_template'
291 );
292
293 $id = !empty($atts['id']) ? intval($atts['id']) : '';
294
295 if (empty($id)) {
296 return '';
297 }
298
299 return self::elementor()->frontend->get_builder_content_for_display($id);
300 }
301
302
303 /**
304 * Add pixel_gallery_ajax_login() function with wp_ajax_nopriv_ function
305 * @return [type] [description]
306 */
307 public function pixel_gallery_ajax_login_init() {
308 // Enable the user with no privileges to run pixel_gallery_ajax_login() in AJAX
309 add_action('wp_ajax_nopriv_pixel_gallery_ajax_login', [$this, "pixel_gallery_ajax_login"]);
310 }
311
312 /**
313 * For ajax login
314 * @return [type] [description]
315 */
316 public function pixel_gallery_ajax_login() {
317 // First check the nonce, if it fails the function will break
318 check_ajax_referer('ajax-login-nonce', 'bdt-user-login-sc');
319
320 // Nonce is checked, get the POST data and sign user on
321 $access_info = [];
322 $access_info['user_login'] = !empty($_POST['user_login']) ? sanitize_text_field(wp_unslash($_POST['user_login'])) : "";
323 $access_info['user_password'] = !empty($_POST['user_password']) ? sanitize_text_field(wp_unslash($_POST['user_password'])) : "";
324 $access_info['remember'] = !empty($_POST['rememberme']) ? true : false;
325 $user_signon = wp_signon($access_info, false);
326
327 if (!is_wp_error($user_signon)) {
328 echo wp_json_encode(
329 [
330 'loggedin' => true,
331 'message' => esc_html_x('Login successful, Redirecting...', 'User Login and Register', 'pixel-gallery')
332 ]
333 );
334 } else {
335 echo wp_json_encode(
336 [
337 'loggedin' => false,
338 'message' => esc_html_x('Oops! Wrong username or password!', 'User Login and Register', 'pixel-gallery')
339 ]
340 );
341 }
342
343 die();
344 }
345
346 // Load WPML compatibility instance
347 public function wpml_compatiblity() {
348 return Pixel_Gallery_WPML::get_instance();
349 }
350
351 /**
352 * initialize the category
353 * @return void
354 */
355 public function pixel_gallery_init() {
356
357 $this->_modules_manager = new Manager();
358
359 do_action('pixel_gallery/init');
360 }
361
362
363 /**
364 * initialize the category
365 * @return [type] [description]
366 */
367 public function pixel_gallery_category_register() {
368
369 $elementor = Plugin::$instance;
370
371 // Add element category in panel
372 $elementor->elements_manager->add_category(BDTPG_SLUG, ['title' => BDTPG_TITLE, 'icon' => 'font']);
373 }
374
375 private function setup_hooks() {
376
377
378 add_action('elementor/elements/categories_registered', [$this, 'pixel_gallery_category_register']);
379 add_action('elementor/init', [$this, 'pixel_gallery_init']);
380
381
382 add_action('elementor/editor/after_enqueue_styles', [$this, 'enqueue_editor_styles']);
383
384 add_action('elementor/frontend/before_register_scripts', [$this, 'register_site_scripts']);
385
386 add_action('elementor/editor/after_enqueue_scripts', [$this, 'enqueue_editor_scripts']);
387
388 add_action('elementor/frontend/after_register_styles', [$this, 'enqueue_site_styles']);
389
390 // For frontend css load
391 add_action('elementor/frontend/after_enqueue_styles', [$this, 'enqueue_minified_css']);
392 add_action('elementor/frontend/after_enqueue_scripts', [$this, 'enqueue_minified_js']);
393
394
395 add_shortcode('rooten_custom_template', [$this, 'shortcode_template']);
396
397
398 // When user not login add this action
399 if (!is_user_logged_in()) {
400 add_action('elementor/init', [$this, 'pixel_gallery_ajax_login_init']);
401 }
402 }
403
404 public function init(){
405 if ( ! defined( 'BDTPG_CH' ) && is_admin() ) {
406 require_once BDTPG_ADMIN_PATH . 'admin.php';
407 new Admin();
408 // Biggopti class
409 require_once ( BDTPG_ADMIN_PATH . 'admin-biggopti.php' );
410 require_once ( BDTPG_ADMIN_PATH . 'admin-feeds.php' );
411 }
412 }
413
414 /**
415 * Pixel_Gallery_Loader constructor.
416 */
417 private function __construct() {
418 // Register class automatically
419 spl_autoload_register([$this, 'autoload']);
420 // Include some backend files
421 $this->_includes();
422
423 // Finally hooked up all things here
424 $this->setup_hooks();
425
426 $this->wpml_compatiblity()->init();
427
428 add_action('init', [$this, 'init']);
429 }
430 }
431
432 if (!defined('BDTPG_TESTS')) {
433 // In tests we run the instance manually.
434 Pixel_Gallery_Loader::instance();
435 }
436 // handy function for push data
437 function pixel_gallery_config() {
438 return Pixel_Gallery_Loader::instance();
439 }
440