PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / views / sp-framework / classes / setup.class.php

setup.class.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.2.2, at admin/views/sp-framework/classes/setup.class.php

419 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot a cess directly.
3
4 /**
5 *
6 * Setup Class
7 *
8 * @since 1.0.0
9 * @version 1.0.0
10 */
11 if ( ! class_exists( 'SP_PC' ) ) {
12 class SP_PC {
13
14 // constants.
15 public static $version = '2.0.6';
16 public static $premium = true;
17 public static $dir = null;
18 public static $url = null;
19 public static $inited = array();
20 public static $fields = array();
21 public static $args = array(
22 'options' => array(),
23 'customize_options' => array(),
24 'metaboxes' => array(),
25 'shortcoders' => array(),
26 'taxonomy_options' => array(),
27 'widgets' => array(),
28 );
29
30 // shortcode instances.
31 public static $shortcode_instances = array();
32
33 // init.
34 public static function init() {
35
36 // init action.
37 do_action( 'spf_init' );
38
39 // set constants.
40 self::constants();
41
42 // include files.
43 self::includes();
44
45 add_action( 'after_setup_theme', array( 'SP_PC', 'setup' ) );
46 add_action( 'init', array( 'SP_PC', 'setup' ) );
47 add_action( 'switch_theme', array( 'SP_PC', 'setup' ) );
48 add_action( 'admin_enqueue_scripts', array( 'SP_PC', 'add_admin_enqueue_scripts' ), 20 );
49
50 }
51
52 // setup.
53 public static function setup() {
54
55 // setup options.
56 $params = array();
57 if ( ! empty( self::$args['options'] ) ) {
58 foreach ( self::$args['options'] as $key => $value ) {
59 if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
60
61 $params['args'] = $value;
62 $params['sections'] = self::$args['sections'][ $key ];
63 self::$inited[ $key ] = true;
64
65 SP_PC_Options::instance( $key, $params );
66
67 if ( ! empty( $value['show_in_customizer'] ) ) {
68 self::$args['customize_options'][ $key ] = ( is_array( $value['show_in_customizer'] ) ) ? $value['show_in_customizer'] : $value;
69 }
70 }
71 }
72 }
73
74 // setup metaboxes.
75 $params = array();
76 if ( ! empty( self::$args['metaboxes'] ) ) {
77 foreach ( self::$args['metaboxes'] as $key => $value ) {
78 if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
79
80 $params['args'] = $value;
81 $params['sections'] = self::$args['sections'][ $key ];
82 self::$inited[ $key ] = true;
83
84 SP_PC_Metabox::instance( $key, $params );
85
86 }
87 }
88 }
89
90 // create widgets
91 if ( ! empty( self::$args['widgets'] ) && class_exists( 'WP_Widget_Factory' ) ) {
92
93 $wp_widget_factory = new WP_Widget_Factory();
94
95 foreach ( self::$args['widgets'] as $key => $value ) {
96 if ( ! isset( self::$inited[ $key ] ) ) {
97 self::$inited[ $key ] = true;
98 $wp_widget_factory->register( SP_PC_Widget::instance( $key, $value ) );
99 }
100 }
101 }
102
103 do_action( 'spf_loaded' );
104
105 }
106
107 // create options.
108 public static function createOptions( $id, $args = array() ) {
109 self::$args['options'][ $id ] = $args;
110 }
111
112 // create metabox options.
113 public static function createMetabox( $id, $args = array() ) {
114 self::$args['metaboxes'][ $id ] = $args;
115 }
116
117 // create widget.
118 public static function createWidget( $id, $args = array() ) {
119 self::$args['widgets'][ $id ] = $args;
120 self::set_used_fields( $args );
121 }
122
123 // create section.
124 public static function createSection( $id, $sections ) {
125 self::$args['sections'][ $id ][] = $sections;
126 self::set_used_fields( $sections );
127 }
128
129 // constants.
130 public static function constants() {
131
132 // we need this path-finder code for set URL of framework.
133 $dirname = wp_normalize_path( dirname( dirname( __FILE__ ) ) );
134 $theme_dir = wp_normalize_path( get_parent_theme_file_path() );
135 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
136 $located_plugin = ( preg_match( '#' . self::sanitize_dirname( $plugin_dir ) . '#', self::sanitize_dirname( $dirname ) ) ) ? true : false;
137 $directory = ( $located_plugin ) ? $plugin_dir : $theme_dir;
138 $directory_uri = ( $located_plugin ) ? SP_PC_URL : get_parent_theme_file_uri();
139 $foldername = str_replace( $directory, '', $dirname );
140 $protocol_uri = ( is_ssl() ) ? 'https' : 'http';
141 $directory_uri = set_url_scheme( $directory_uri, $protocol_uri );
142
143 self::$dir = $dirname;
144 self::$url = $directory_uri . $foldername;
145
146 }
147
148 public static function include_plugin_file( $file, $load = true ) {
149
150 $path = '';
151 $file = ltrim( $file, '/' );
152 $override = apply_filters( 'spf_override', 'spf-override' );
153
154 if ( file_exists( get_parent_theme_file_path( $override . '/' . $file ) ) ) {
155 $path = get_parent_theme_file_path( $override . '/' . $file );
156 } elseif ( file_exists( get_theme_file_path( $override . '/' . $file ) ) ) {
157 $path = get_theme_file_path( $override . '/' . $file );
158 } elseif ( file_exists( self::$dir . '/' . $override . '/' . $file ) ) {
159 $path = self::$dir . '/' . $override . '/' . $file;
160 } elseif ( file_exists( self::$dir . '/' . $file ) ) {
161 $path = self::$dir . '/' . $file;
162 }
163
164 if ( ! empty( $path ) && ! empty( $file ) && $load ) {
165
166 global $wp_query;
167
168 if ( is_object( $wp_query ) && function_exists( 'load_template' ) ) {
169
170 load_template( $path, true );
171
172 } else {
173
174 require_once $path;
175
176 }
177 } else {
178
179 return self::$dir . '/' . $file;
180
181 }
182
183 }
184
185 public static function is_active_plugin( $file = '' ) {
186 return in_array( $file, (array) get_option( 'active_plugins', array() ) );
187 }
188
189 // Sanitize dirname.
190 public static function sanitize_dirname( $dirname ) {
191 return preg_replace( '/[^A-Za-z]/', '', $dirname );
192 }
193
194 // General includes.
195 public static function includes() {
196
197 // includes helpers.
198 self::include_plugin_file( 'functions/actions.php' );
199 self::include_plugin_file( 'functions/deprecated.php' );
200 self::include_plugin_file( 'functions/helpers.php' );
201 self::include_plugin_file( 'functions/sanitize.php' );
202 self::include_plugin_file( 'functions/validate.php' );
203
204 // includes free version classes.
205 self::include_plugin_file( 'classes/abstract.class.php' );
206 self::include_plugin_file( 'classes/fields.class.php' );
207 self::include_plugin_file( 'classes/options.class.php' );
208
209 // includes premium version classes.
210 if ( self::$premium ) {
211 //self::include_plugin_file( 'classes/customize-options.class.php' );
212 self::include_plugin_file( 'classes/metabox.class.php' );
213
214 self::include_plugin_file( 'classes/widgets.class.php' );
215 }
216
217 }
218
219 /**
220 * Include field.
221 *
222 * @param string $type File type.
223 * @return void
224 */
225 public static function maybe_include_field( $type = '' ) {
226 if ( ! class_exists( 'SP_PC_Field_' . $type ) && class_exists( 'SP_PC_Fields' ) ) {
227 self::include_plugin_file( 'fields/' . $type . '/' . $type . '.php' );
228 }
229 }
230
231 /**
232 * Get all of fields.
233 *
234 * @param array $sections All the sections used in the plugin.
235 * @return void
236 */
237 public static function set_used_fields( $sections ) {
238
239 if ( ! empty( $sections['fields'] ) ) {
240
241 foreach ( $sections['fields'] as $field ) {
242
243 if ( ! empty( $field['fields'] ) ) {
244 self::set_used_fields( $field );
245 }
246
247 if ( ! empty( $field['tabs'] ) ) {
248 self::set_used_fields( array( 'fields' => $field['tabs'] ) );
249 }
250
251 if ( ! empty( $field['accordions'] ) ) {
252 self::set_used_fields( array( 'fields' => $field['accordions'] ) );
253 }
254
255 if ( ! empty( $field['type'] ) ) {
256 self::$fields[ $field['type'] ] = $field;
257 }
258 }
259 }
260
261 }
262
263 //
264 // Enqueue admin and fields styles and scripts.
265 public static function add_admin_enqueue_scripts() {
266 $current_screen = get_current_screen();
267 $the_current_post_type = $current_screen->post_type;
268 if ( 'sp_post_carousel' === $the_current_post_type ) {
269 // check for developer mode.
270 $min = ( apply_filters( 'spf_dev_mode', false ) || WP_DEBUG ) ? '' : '.min';
271 // admin utilities.
272 wp_enqueue_media();
273 // wp color picker.
274 wp_enqueue_style( 'wp-color-picker' );
275 wp_enqueue_script( 'wp-color-picker' );
276 // framework core styles.
277 wp_enqueue_style( 'spf', SP_PC_URL . 'admin/views/sp-framework/assets/css/spf.css', array(), SP_PC_VERSION, 'all' );
278 // rtl styles.
279 if ( is_rtl() ) {
280 wp_enqueue_style( 'spf-rtl', SP_PC_URL . 'admin/views/sp-framework/assets/css/spf-rtl' . $min . '.css', array(), SP_PC_VERSION, 'all' );
281 }
282
283 // framework core scripts.
284 wp_enqueue_script( 'spf-plugins', SP_PC_URL . 'admin/views/sp-framework/assets/js/spf-plugins' . $min . '.js', array(), SP_PC_VERSION, true );
285 wp_enqueue_script( 'spf', SP_PC_URL . 'admin/views/sp-framework/assets/js/spf' . $min . '.js', array( 'spf-plugins' ), SP_PC_VERSION, true );
286
287 wp_localize_script(
288 'spf',
289 'spf_vars',
290 array(
291 'color_palette' => apply_filters( 'spf_color_palette', array() ),
292 'i18n' => array(
293 // global localize.
294 'confirm' => esc_html__( 'Are you sure?', 'smart-post-show' ),
295 'reset_notification' => esc_html__( 'Restoring options.', 'smart-post-show' ),
296 'import_notification' => esc_html__( 'Importing options.', 'smart-post-show' ),
297
298 // chosen localize.
299 'typing_text' => esc_html__( 'Please enter %s or more characters', 'smart-post-show' ),
300 'searching_text' => esc_html__( 'Searching...', 'smart-post-show' ),
301 'no_results_text' => esc_html__( 'No results match', 'smart-post-show' ),
302 ),
303 )
304 );
305
306 // load admin enqueue scripts and styles.
307 $enqueued = array();
308
309 if ( ! empty( self::$fields ) ) {
310 foreach ( self::$fields as $field ) {
311 if ( ! empty( $field['type'] ) ) {
312 $classname = 'SP_PC_Field_' . $field['type'];
313 self::maybe_include_field( $field['type'] );
314 if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) {
315 $instance = new $classname( $field );
316 if ( method_exists( $classname, 'enqueue' ) ) {
317 $instance->enqueue();
318 }
319 unset( $instance );
320 }
321 }
322 }
323 }
324
325 do_action( 'spf_enqueue' );
326 } // Check screen ID.
327
328 }
329
330 //
331 // Add a new framework field.
332 public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
333
334 // Check for unallow fields.
335 if ( ! empty( $field['_notice'] ) ) {
336
337 $field_type = $field['type'];
338
339 $field = array();
340 $field['content'] = sprintf( esc_html__( 'Ooops! This field type (%s) can not be used here, yet.', 'smart-post-show' ), '<strong>' . $field_type . '</strong>' );
341 $field['type'] = 'notice';
342 $field['style'] = 'danger';
343
344 }
345
346 $depend = '';
347 $hidden = '';
348 $unique = ( ! empty( $unique ) ) ? $unique : '';
349 $class = ( ! empty( $field['class'] ) ) ? ' ' . $field['class'] : '';
350 $is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' spf-pseudo-field' : '';
351 $field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : '';
352
353 if ( ! empty( $field['dependency'] ) ) {
354
355 $dependency = $field['dependency'];
356 $hidden = ' hidden';
357 $data_controller = '';
358 $data_condition = '';
359 $data_value = '';
360 $data_global = '';
361
362 if ( is_array( $dependency[0] ) ) {
363 $data_controller = implode( '|', array_column( $dependency, 0 ) );
364 $data_condition = implode( '|', array_column( $dependency, 1 ) );
365 $data_value = implode( '|', array_column( $dependency, 2 ) );
366 $data_global = implode( '|', array_column( $dependency, 3 ) );
367 } else {
368 $data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : '';
369 $data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : '';
370 $data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : '';
371 $data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : '';
372 }
373
374 $depend .= ' data-controller="' . $data_controller . '"';
375 $depend .= ' data-condition="' . $data_condition . '"';
376 $depend .= ' data-value="' . $data_value . '"';
377 $depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : '';
378
379 }
380
381 if ( ! empty( $field_type ) ) {
382
383 echo '<div class="spf-field spf-field-' . $field_type . $is_pseudo . $class . $hidden . '"' . $depend . '>';
384
385 if ( ! empty( $field['title'] ) ) {
386 $subtitle = ( ! empty( $field['subtitle'] ) ) ? '<p class="spf-text-subtitle">' . $field['subtitle'] . '</p>' : '';
387 echo '<div class="spf-title"><h4>' . $field['title'] . '</h4>' . $subtitle . '</div>';
388 }
389
390 echo ( ! empty( $field['title'] ) ) ? '<div class="spf-fieldset">' : '';
391
392 $value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value;
393 $value = ( isset( $field['value'] ) ) ? $field['value'] : $value;
394
395 self::maybe_include_field( $field_type );
396
397 $classname = 'SP_PC_Field_' . $field_type;
398
399 if ( class_exists( $classname ) ) {
400 $instance = new $classname( $field, $value, $unique, $where, $parent );
401 $instance->render();
402 } else {
403 echo '<p>' . esc_html__( 'This field class is not available!', 'smart-post-show' ) . '</p>';
404 }
405 } else {
406 echo '<p>' . esc_html__( 'This type is not found!', 'smart-post-show' ) . '</p>';
407 }
408
409 echo ( ! empty( $field['title'] ) ) ? '</div>' : '';
410 echo '<div class="clear"></div>';
411 echo '</div>';
412
413 }
414
415 }
416
417 SP_PC::init();
418 }
419