PluginProbe
Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery / 2.1.13
Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery v2.1.13
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 2.1.13, at loader.php

440 lines 13.1 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 do_action('bdthemes_pixel_gallery/init');
100 return self::$_instance;
101 }
102
103
104 /**
105 * we loaded module manager + admin php from here
106 * @return [type] [description]
107 */
108 private function _includes() {
109
110 $essential_shortcodes = pixel_gallery_option('essential-shortcodes', 'pixel_gallery_other_settings', 'off');
111
112 // Admin settings controller
113 require_once BDTPG_ADMIN_PATH . 'module-settings.php';
114 //Assets Manager
115 require_once 'admin/optimizer/asset-minifier-manager.php';
116
117 // Dynamic Select control
118 require_once BDTPG_INC_PATH . 'controls/select-input/dynamic-select-input-module.php';
119 require_once BDTPG_INC_PATH . 'controls/select-input/dynamic-select.php';
120
121 // Global Controls
122 require_once BDTPG_PATH . 'traits/global-widget-controls.php';
123 require_once BDTPG_PATH . 'traits/global-terms-query-controls.php';
124 // require_once BDTPG_PATH . 'traits/global-mask-controls.php';
125
126
127 // wpml compatibility class for wpml support
128 require_once BDTPG_PATH . 'includes/class-elements-wpml-compatibility.php';
129
130
131 // All modules loading from here
132 require_once BDTPG_INC_PATH . 'modules-manager.php';
133
134
135 // Shortcode loader for works some essential shortcode that need for any purpose
136 if ($essential_shortcodes == 'on') {
137 require_once BDTPG_INC_PATH . 'shortcodes/shortcode-loader.php';
138 }
139 }
140
141 /**
142 * Autoloader function for all classes files
143 *
144 * @param [type] class [description]
145 *
146 * @return [type] [description]
147 */
148 public function autoload($class) {
149 if (0 !== strpos($class, __NAMESPACE__)) {
150 return;
151 }
152
153
154 $class_to_load = $class;
155
156 if (!class_exists($class_to_load)) {
157 $filename = strtolower(
158 preg_replace(
159 ['/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z0-9])/', '/_/', '/\\\/'],
160 ['', '$1-$2', '-', DIRECTORY_SEPARATOR],
161 $class_to_load
162 )
163 );
164
165 $filename = BDTPG_PATH . $filename . '.php';
166
167 if (is_readable($filename)) {
168 include($filename);
169 }
170 }
171 }
172
173 /**
174 * Register all script that need for any specific widget on call basis.
175 * @return [type] [description]
176 */
177 public function register_site_scripts() {
178 wp_register_script('pg-animations', BDTPG_ASSETS_URL . 'js/extensions/pg-animations.min.js', ['jquery'], '', true);
179 }
180
181 /**
182 * Loading site related style from here.
183 * @return [type] [description]
184 */
185 public function enqueue_site_styles() {
186
187 $direction_suffix = is_rtl() ? '.rtl' : '';
188
189 wp_enqueue_style('pg-helper', BDTPG_ASSETS_URL . 'css/pg-helper.css', ['e-swiper'], BDTPG_VER);
190 wp_enqueue_style('pg-font', BDTPG_ASSETS_URL . 'css/pg-font.css', [], BDTPG_VER);
191 }
192
193 public function enqueue_editor_scripts() {
194
195 wp_enqueue_script(
196 'pg-editor',
197 BDTPG_ASSETS_URL . 'js/pg-editor.min.js',
198 [
199 'backbone-marionette',
200 'elementor-common-modules',
201 'elementor-editor-modules',
202 ],
203 BDTPG_VER,
204 true
205 );
206
207 $_is_pg_pro_activated = false;
208 if (function_exists('pg_license_validation') && true === pg_license_validation()) {
209 $_is_pg_pro_activated = true;
210 }
211
212 $localize_data = [
213 'pro_installed' => _is_pg_pro_activated(),
214 'pro_license_activated' => $_is_pg_pro_activated,
215 'promotional_widgets' => [],
216 ];
217
218 if (!$_is_pg_pro_activated) {
219 $pro_widget_map = new \PixelGallery\Includes\Pro_Widget_Map();
220 $localize_data['promotional_widgets'] = $pro_widget_map->get_pro_widget_map();
221 }
222
223 wp_localize_script('pg-editor', 'PixelGalleryConfigEditor', $localize_data);
224 }
225
226 public function enqueue_editor_styles() {
227 $direction_suffix = is_rtl() ? '.rtl' : '';
228
229 wp_enqueue_style('pg-editor', BDTPG_ASSETS_URL . 'css/pg-editor.css', '', BDTPG_VER);
230 wp_add_inline_style(
231 'pg-editor',
232 '#elementor-panel{'
233 . '--pg-pro-control-message:' . wp_json_encode( __( 'This is a pro control, available with Pixel Gallery Pro version.', 'pixel-gallery' ) ) . ';'
234 . '--pg-badge-new:' . wp_json_encode( __( 'NEW', 'pixel-gallery' ) ) . ';'
235 . '--pg-badge-pro:' . wp_json_encode( __( 'PRO', 'pixel-gallery' ) ) . ';'
236 . '}'
237 );
238 }
239
240
241 public function enqueue_minified_css() {
242 $direction_suffix = is_rtl() ? '.rtl' : '';
243
244 $upload_dir = $this->get_upload_dir() . 'css/pg-styles.css';
245 $version = get_option('pixel-gallery-minified-asset-manager-version');
246
247 if (pixel_gallery_is_asset_optimization_enabled() && file_exists($upload_dir)) {
248 $upload_url = $this->get_upload_url() . 'css/pg-styles.css';
249 wp_register_style('pg-styles', $upload_url, [], $version);
250 } else {
251 wp_register_style('pg-styles', BDTPG_URL . 'assets/css/pg-styles.css', [], BDTPG_VER);
252 }
253
254 if (pixel_gallery_is_asset_optimization_enabled()) {
255 wp_enqueue_style('pg-styles');
256 }
257 }
258
259 public function enqueue_minified_js() {
260
261 $upload_dir = $this->get_upload_dir() . 'js/pg-scripts.js';
262 $version = get_option('pixel-gallery-minified-asset-manager-version');
263
264 if (pixel_gallery_is_asset_optimization_enabled() && file_exists($upload_dir)) {
265 $upload_url = $this->get_upload_url() . 'js/pg-scripts.min.js';
266
267 wp_register_script('pg-scripts', $upload_url, ['elementor-frontend'], $version, true);
268 } else {
269 wp_register_script('pg-scripts', BDTPG_URL . 'assets/js/pg-scripts.min.js', ['elementor-frontend'], BDTPG_VER, true);
270 }
271
272 if (pixel_gallery_is_asset_optimization_enabled()) {
273 wp_enqueue_script('pg-scripts');
274 }
275 }
276
277
278 /**
279 * Callback to shortcodes template
280 * @param array $atts attributes for shortcode.
281 */
282 public function shortcode_template($atts) {
283
284 $atts = shortcode_atts(
285 array(
286 'id' => '',
287 ),
288 $atts,
289 'rooten_custom_template'
290 );
291
292 $id = !empty($atts['id']) ? intval($atts['id']) : '';
293
294 if (empty($id)) {
295 return '';
296 }
297
298 return self::elementor()->frontend->get_builder_content_for_display($id);
299 }
300
301
302 /**
303 * Add pixel_gallery_ajax_login() function with wp_ajax_nopriv_ function
304 * @return [type] [description]
305 */
306 public function pixel_gallery_ajax_login_init() {
307 // Enable the user with no privileges to run pixel_gallery_ajax_login() in AJAX
308 add_action('wp_ajax_nopriv_pixel_gallery_ajax_login', [$this, "pixel_gallery_ajax_login"]);
309 }
310
311 /**
312 * For ajax login
313 * @return [type] [description]
314 */
315 public function pixel_gallery_ajax_login() {
316 // First check the nonce, if it fails the function will break
317 check_ajax_referer('ajax-login-nonce', 'bdt-user-login-sc');
318
319 // Nonce is checked, get the POST data and sign user on
320 $access_info = [];
321 $access_info['user_login'] = !empty($_POST['user_login']) ? sanitize_text_field($_POST['user_login']) : "";
322 $access_info['user_password'] = !empty($_POST['user_password']) ? sanitize_text_field($_POST['user_password']) : "";
323 $access_info['remember'] = !empty($_POST['rememberme']) ? true : false;
324 $user_signon = wp_signon($access_info, false);
325
326 if (!is_wp_error($user_signon)) {
327 echo wp_json_encode(
328 [
329 'loggedin' => true,
330 'message' => esc_html_x('Login successful, Redirecting...', 'User Login and Register', 'pixel-gallery')
331 ]
332 );
333 } else {
334 echo wp_json_encode(
335 [
336 'loggedin' => false,
337 'message' => esc_html_x('Oops! Wrong username or password!', 'User Login and Register', 'pixel-gallery')
338 ]
339 );
340 }
341
342 die();
343 }
344
345 // Load WPML compatibility instance
346 public function wpml_compatiblity() {
347 return Pixel_Gallery_WPML::get_instance();
348 }
349
350 /**
351 * initialize the category
352 * @return void
353 */
354 public function pixel_gallery_init() {
355
356 $this->_modules_manager = new Manager();
357
358 do_action('pixel_gallery/init');
359 }
360
361
362 /**
363 * initialize the category
364 * @return [type] [description]
365 */
366 public function pixel_gallery_category_register() {
367
368 $elementor = Plugin::$instance;
369
370 // Add element category in panel
371 $elementor->elements_manager->add_category(BDTPG_SLUG, ['title' => BDTPG_TITLE, 'icon' => 'font']);
372 }
373
374 private function setup_hooks() {
375
376
377 add_action('elementor/elements/categories_registered', [$this, 'pixel_gallery_category_register']);
378 add_action('elementor/init', [$this, 'pixel_gallery_init']);
379
380
381 add_action('elementor/editor/after_enqueue_styles', [$this, 'enqueue_editor_styles']);
382
383 add_action('elementor/frontend/before_register_scripts', [$this, 'register_site_scripts']);
384
385 add_action('elementor/editor/after_enqueue_scripts', [$this, 'enqueue_editor_scripts']);
386
387 add_action('elementor/frontend/after_register_styles', [$this, 'enqueue_site_styles']);
388
389 // For frontend css load
390 add_action('elementor/frontend/after_enqueue_styles', [$this, 'enqueue_minified_css']);
391 add_action('elementor/frontend/after_enqueue_scripts', [$this, 'enqueue_minified_js']);
392
393
394 add_shortcode('rooten_custom_template', [$this, 'shortcode_template']);
395
396
397 // When user not login add this action
398 if (!is_user_logged_in()) {
399 add_action('elementor/init', [$this, 'pixel_gallery_ajax_login_init']);
400 }
401 }
402
403 public function init(){
404 if ( ! defined( 'BDTPG_CH' ) && is_admin() ) {
405 require_once BDTPG_ADMIN_PATH . 'admin.php';
406 new Admin();
407 // Biggopti class
408 require_once ( BDTPG_ADMIN_PATH . 'admin-biggopti.php' );
409 require_once ( BDTPG_ADMIN_PATH . 'admin-api-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