PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / redux / ReduxCore / inc / class.redux_helpers.php

class.redux_helpers.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/class.redux_helpers.php

795 lines 23.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 // Don't duplicate me!
9 if ( ! class_exists( 'ReduxLegacy_Helpers' ) ) {
10
11 /**
12 * Redux Helpers Class
13 * Class of useful functions that can/should be shared among all Redux files.
14 *
15 * @since 1.0.0
16 */
17 class ReduxLegacy_Helpers {
18
19 public static function tabFromField( $parent, $field ) {
20 foreach ( $parent->sections as $k => $section ) {
21 if ( ! isset( $section['title'] ) ) {
22 continue;
23 }
24
25 if ( isset( $section['fields'] ) && ! empty( $section['fields'] ) ) {
26 if ( self::recursive_array_search( $field, $section['fields'] ) ) {
27 return $k;
28 continue;
29 }
30 }
31 }
32 }
33
34 public static function isFieldInUseByType( $fields, $field = array() ) {
35 foreach ( $field as $name ) {
36 if ( array_key_exists( $name, $fields ) ) {
37 return true;
38 }
39 }
40
41 return false;
42 }
43
44 public static function get_auth_key_secret_key() {
45 $key = '';
46 $key .= defined( 'AUTH_KEY' ) ? AUTH_KEY : get_site_url();
47 $key .= defined( 'SECURE_AUTH_KEY' ) ? SECURE_AUTH_KEY : get_site_url();
48
49 return $key;
50 }
51
52 public static function isFieldInUse( $parent, $field ) {
53 foreach ( $parent->sections as $k => $section ) {
54 if ( ! isset( $section['title'] ) ) {
55 continue;
56 }
57
58 if ( isset( $section['fields'] ) && ! empty( $section['fields'] ) ) {
59 if ( self::recursive_array_search( $field, $section['fields'] ) ) {
60 return true;
61 continue;
62 }
63 }
64 }
65 }
66
67 public static function major_version( $v ) {
68 $version = explode( '.', $v );
69 if ( count( $version ) > 1 ) {
70 return $version[0] . '.' . $version[1];
71 } else {
72 return $v;
73 }
74 }
75
76 public static function isLocalHost() {
77 return ( isset( $_SERVER['REMOTE_ADDR'] ) && ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' || $_SERVER['REMOTE_ADDR'] === 'localhost' ) ) ? 1 : 0;
78 }
79
80 public static function isWpDebug() {
81 return ( defined( 'WP_DEBUG' ) && WP_DEBUG == true );
82 }
83
84 public static function getTrackingObject() {
85 global $wpdb;
86
87 $hash = md5( network_site_url() . '-' . $_SERVER['REMOTE_ADDR'] );
88
89 global $blog_id, $wpdb;
90 $pts = array();
91
92 foreach ( get_post_types( array( 'public' => true ) ) as $pt ) {
93 $count = wp_count_posts( $pt );
94 $pts[ $pt ] = $count->publish;
95 }
96
97 $comments_count = wp_count_comments();
98 $theme_data = wp_get_theme();
99 $theme = array(
100 'version' => $theme_data->Version,
101 'name' => $theme_data->Name,
102 'author' => $theme_data->Author,
103 'template' => $theme_data->Template,
104 );
105
106 if ( ! function_exists( 'get_plugin_data' ) ) {
107 if ( file_exists( ABSPATH . 'wp-admin/includes/plugin.php' ) ) {
108 require_once ABSPATH . 'wp-admin/includes/plugin.php';
109 }
110 if ( file_exists( ABSPATH . 'wp-admin/includes/admin.php' ) ) {
111 require_once ABSPATH . 'wp-admin/includes/admin.php';
112 }
113 }
114
115 $plugins = array();
116 foreach ( get_option( 'active_plugins', array() ) as $plugin_path ) {
117 $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
118
119 $slug = str_replace( '/' . basename( $plugin_path ), '', $plugin_path );
120 $plugins[ $slug ] = array(
121 'version' => $plugin_info['Version'],
122 'name' => $plugin_info['Name'],
123 'plugin_uri' => $plugin_info['PluginURI'],
124 'author' => $plugin_info['AuthorName'],
125 'author_uri' => $plugin_info['AuthorURI'],
126 );
127 }
128 if ( is_multisite() ) {
129 foreach ( get_option( 'active_sitewide_plugins', array() ) as $plugin_path ) {
130 $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
131 $slug = str_replace( '/' . basename( $plugin_path ), '', $plugin_path );
132 $plugins[ $slug ] = array(
133 'version' => $plugin_info['Version'],
134 'name' => $plugin_info['Name'],
135 'plugin_uri' => $plugin_info['PluginURI'],
136 'author' => $plugin_info['AuthorName'],
137 'author_uri' => $plugin_info['AuthorURI'],
138 );
139 }
140 }
141
142 $version = explode( '.', PHP_VERSION );
143 $version = array(
144 'major' => $version[0],
145 'minor' => $version[0] . '.' . $version[1],
146 'release' => PHP_VERSION,
147 );
148
149 $user_query = new WP_User_Query(
150 array(
151 'blog_id' => $blog_id,
152 'count_total' => true,
153 )
154 );
155 $comments_query = new WP_Comment_Query();
156
157 $data = array(
158 '_id' => $hash,
159 'localhost' => ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) ? 1 : 0,
160 'php' => $version,
161 'site' => array(
162 'hash' => $hash,
163 'version' => get_bloginfo( 'version' ),
164 'multisite' => is_multisite(),
165 'users' => $user_query->get_total(),
166 'lang' => get_locale(),
167 'wp_debug' => ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? true : false : false ),
168 'memory' => WP_MEMORY_LIMIT,
169 ),
170 'pts' => $pts,
171 'comments' => array(
172 'total' => $comments_count->total_comments,
173 'approved' => $comments_count->approved,
174 'spam' => $comments_count->spam,
175 'pings' => $comments_query->query(
176 array(
177 'count' => true,
178 'type' => 'pingback',
179 )
180 ),
181 ),
182 'options' => apply_filters( 'redux/tracking/options', array() ),
183 'theme' => $theme,
184 'redux' => array(
185 'mode' => ReduxFrameworkLegacy::$_is_plugin ? 'plugin' : 'theme',
186 'version' => ReduxFrameworkLegacy::$_version,
187 'demo_mode' => get_option( 'ReduxFrameworkPlugin' ),
188 ),
189 'developer' => apply_filters( 'redux/tracking/developer', array() ),
190 'plugins' => $plugins,
191 );
192
193 $parts = explode( ' ', $_SERVER['SERVER_SOFTWARE'] );
194 $software = array();
195 foreach ( $parts as $part ) {
196 if ( $part[0] == '(' ) {
197 continue;
198 }
199 if ( strpos( $part, '/' ) !== false ) {
200 $chunk = explode( '/', $part );
201 $software[ strtolower( $chunk[0] ) ] = $chunk[1];
202 }
203 }
204 $software['full'] = $_SERVER['SERVER_SOFTWARE'];
205 $data['environment'] = $software;
206 $data['environment']['mysql'] = $wpdb->db_version();
207 // if ( function_exists( 'mysqli_get_server_info' ) ) {
208 // $link = mysqli_connect() or die( "Error " . mysqli_error( $link ) );
209 // $data['environment']['mysql'] = mysqli_get_server_info( $link );
210 // } else if ( class_exists( 'PDO' ) && method_exists( 'PDO', 'getAttribute' ) ) {
211 // $data['environment']['mysql'] = PDO::getAttribute( PDO::ATTR_SERVER_VERSION );
212 // } else {
213 // $data['environment']['mysql'] = mysql_get_server_info();
214 // }
215
216 if ( empty( $data['developer'] ) ) {
217 unset( $data['developer'] );
218 }
219
220 return $data;
221 }
222
223 public static function trackingObject() {
224
225 $data = wp_remote_post(
226 'http://verify.redux.io',
227 array(
228 'body' => array(
229 'hash' => $_GET['action'],
230 'site' => esc_url( home_url( '/' ) ),
231 ),
232 )
233 );
234
235 $data['body'] = urldecode( $data['body'] );
236
237 if ( ! isset( $_GET['code'] ) || $data['body'] != $_GET['code'] ) {
238 die();
239 }
240
241 return self::getTrackingObject();
242 }
243
244 public static function isParentTheme( $file ) {
245 $file = self::cleanFilePath( $file );
246 $dir = self::cleanFilePath( get_template_directory() );
247
248 $file = str_replace( '//', '/', $file );
249 $dir = str_replace( '//', '/', $dir );
250
251 if ( strpos( $file, $dir ) !== false ) {
252 return true;
253 }
254
255 return false;
256 }
257
258 public static function isChildTheme( $file ) {
259 $file = self::cleanFilePath( $file );
260 $dir = self::cleanFilePath( get_stylesheet_directory() );
261
262 $file = str_replace( '//', '/', $file );
263 $dir = str_replace( '//', '/', $dir );
264
265 if ( strpos( $file, $dir ) !== false ) {
266 return true;
267 }
268
269 return false;
270 }
271
272 private static function reduxAsPlugin() {
273 return ReduxFrameworkLegacy::$_as_plugin;
274 }
275
276 public static function isTheme( $file ) {
277
278 if ( true == self::isChildTheme( $file ) || true == self::isParentTheme( $file ) ) {
279 return true;
280 }
281
282 return false;
283 }
284
285 public static function array_in_array( $needle, $haystack ) {
286 // Make sure $needle is an array for foreach
287 if ( ! is_array( $needle ) ) {
288 $needle = array( $needle );
289 }
290 // For each value in $needle, return TRUE if in $haystack
291 foreach ( $needle as $pin ) {
292 if ( in_array( $pin, $haystack ) ) {
293 return true;
294 }
295 }
296
297 // Return FALSE if none of the values from $needle are found in $haystack
298 return false;
299 }
300
301 public static function recursive_array_search( $needle, $haystack ) {
302 foreach ( $haystack as $key => $value ) {
303 if ( $needle === $value || ( is_array( $value ) && self::recursive_array_search(
304 $needle,
305 $value
306 ) !== false ) ) {
307 return true;
308 }
309 }
310
311 return false;
312 }
313
314 /**
315 * Take a path and return it clean
316 *
317 * @since 3.1.7
318 *
319 * @param string $path
320 */
321 public static function cleanFilePath( $path ) {
322 $path = str_replace( '', '', str_replace( array( '\\', '\\\\' ), '/', $path ) );
323
324 if ( $path[ strlen( $path ) - 1 ] === '/' ) {
325 $path = rtrim( $path, '/' );
326 }
327
328 return $path;
329 }
330
331 /**
332 * Take a path and delete it
333 *
334 * @since 3.3.3
335 *
336 * @param string $path
337 */
338 public static function rmdir( $dir ) {
339 if ( is_dir( $dir ) ) {
340 $objects = scandir( $dir );
341 foreach ( $objects as $object ) {
342 if ( $object != '.' && $object != '..' ) {
343 if ( filetype( $dir . '/' . $object ) == 'dir' ) {
344 rrmdir( $dir . '/' . $object );
345 } else {
346 unlink( $dir . '/' . $object );
347 }
348 }
349 }
350 reset( $objects );
351 rmdir( $dir );
352 }
353 }
354
355 /**
356 * Field Render Function.
357 * Takes the color hex value and converts to a rgba.
358 *
359 * @since ReduxFrameworkLegacy 3.0.4
360 */
361 public static function hex2rgba( $hex, $alpha = '' ) {
362 $hex = str_replace( '#', '', $hex );
363 if ( strlen( $hex ) == 3 ) {
364 $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
365 $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
366 $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
367 } else {
368 $r = hexdec( substr( $hex, 0, 2 ) );
369 $g = hexdec( substr( $hex, 2, 2 ) );
370 $b = hexdec( substr( $hex, 4, 2 ) );
371 }
372 $rgb = $r . ',' . $g . ',' . $b;
373
374 if ( '' == $alpha ) {
375 return $rgb;
376 } else {
377 $alpha = floatval( $alpha );
378
379 return 'rgba(' . $rgb . ',' . $alpha . ')';
380 }
381 }
382
383 public static function makeBoolStr( $var ) {
384 if ( $var === false || $var === 'false' || $var === 0 || $var === '0' || $var === '' || empty( $var ) ) {
385 return 'false';
386 } elseif ( $var === true || $var === 'true' || $var === 1 || $var === '1' ) {
387 return 'true';
388 } else {
389 return $var;
390 }
391 }
392
393 public static function localize( $localize ) {
394 $redux = ReduxFrameworkInstancesLegacy::get_instance( $localize['args']['opt_name'] );
395 $nonce = wp_create_nonce( 'redux-ads-nonce' );
396 $base = admin_url( 'admin-ajax.php' ) . '?action=redux_p&nonce=' . $nonce . '&url=';
397 $localize['rAds'] = self::rURL_fix( $base, $redux->args['opt_name'] );
398
399 return $localize;
400 }
401
402 public static function compileSystemStatus( $json_output = false, $remote_checks = false ) {
403 global $wpdb;
404
405 $sysinfo = array();
406
407 $sysinfo['home_url'] = home_url();
408 $sysinfo['site_url'] = site_url();
409 $sysinfo['redux_ver'] = esc_html( ReduxFrameworkLegacy::$_version );
410 $sysinfo['redux_data_dir'] = ReduxFrameworkLegacy::$_upload_dir;
411 $f = 'fo' . 'pen';
412
413 $res = true;
414 if ( $f( ReduxFrameworkLegacy::$_upload_dir . 'test-log.log', 'a' ) === false ) {
415 $res = false;
416 }
417
418 // Only is a file-write check
419 $sysinfo['redux_data_writeable'] = $res;
420 $sysinfo['wp_content_url'] = WP_CONTENT_URL;
421 $sysinfo['wp_ver'] = get_bloginfo( 'version' );
422 $sysinfo['wp_multisite'] = is_multisite();
423 $sysinfo['permalink_structure'] = get_option( 'permalink_structure' ) ? get_option(
424 'permalink_structure'
425 ) : 'Default';
426 $sysinfo['front_page_display'] = get_option( 'show_on_front' );
427 if ( $sysinfo['front_page_display'] == 'page' ) {
428 $front_page_id = get_option( 'page_on_front' );
429 $blog_page_id = get_option( 'page_for_posts' );
430
431 $sysinfo['front_page'] = $front_page_id != 0 ? get_the_title(
432 $front_page_id
433 ) . ' (#' . $front_page_id . ')' : 'Unset';
434 $sysinfo['posts_page'] = $blog_page_id != 0 ? get_the_title(
435 $blog_page_id
436 ) . ' (#' . $blog_page_id . ')' : 'Unset';
437 }
438
439 $sysinfo['wp_mem_limit']['raw'] = self::let_to_num( WP_MEMORY_LIMIT );
440 $sysinfo['wp_mem_limit']['size'] = size_format( $sysinfo['wp_mem_limit']['raw'] );
441
442 $sysinfo['db_table_prefix'] = 'Length: ' . strlen( $wpdb->prefix ) . ' - Status: ' . ( strlen(
443 $wpdb->prefix
444 ) > 16 ? 'ERROR: Too long' : 'Acceptable' );
445
446 $sysinfo['wp_debug'] = 'false';
447 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
448 $sysinfo['wp_debug'] = 'true';
449 }
450
451 $sysinfo['wp_lang'] = get_locale();
452
453 if ( ! class_exists( 'Browser' ) ) {
454 require_once ReduxFrameworkLegacy::$_dir . 'inc/browser.php';
455 }
456
457 $browser = new Browser();
458
459 $sysinfo['browser'] = array(
460 'agent' => $browser->getUserAgent(),
461 'browser' => $browser->getBrowser(),
462 'version' => $browser->getVersion(),
463 'platform' => $browser->getPlatform(),
464 // 'mobile' => $browser->isMobile() ? 'true' : 'false',
465 );
466
467 $sysinfo['server_info'] = esc_html( $_SERVER['SERVER_SOFTWARE'] );
468 $sysinfo['localhost'] = self::makeBoolStr( self::isLocalHost() );
469 $sysinfo['php_ver'] = function_exists( 'phpversion' ) ? esc_html(
470 phpversion()
471 ) : 'phpversion() function does not exist.';
472 $sysinfo['abspath'] = ABSPATH;
473
474 if ( function_exists( 'ini_get' ) ) {
475 $sysinfo['php_mem_limit'] = size_format( self::let_to_num( ini_get( 'memory_limit' ) ) );
476 $sysinfo['php_post_max_size'] = size_format( self::let_to_num( ini_get( 'post_max_size' ) ) );
477 $sysinfo['php_time_limit'] = ini_get( 'max_execution_time' );
478 $sysinfo['php_max_input_var'] = ini_get( 'max_input_vars' );
479 $sysinfo['php_display_errors'] = self::makeBoolStr( ini_get( 'display_errors' ) );
480 }
481
482 $sysinfo['suhosin_installed'] = extension_loaded( 'suhosin' );
483 $sysinfo['mysql_ver'] = $wpdb->db_version();
484 $sysinfo['max_upload_size'] = size_format( wp_max_upload_size() );
485
486 $sysinfo['def_tz_is_utc'] = 'true';
487 if ( date_default_timezone_get() !== 'UTC' ) {
488 $sysinfo['def_tz_is_utc'] = 'false';
489 }
490
491 $sysinfo['fsockopen_curl'] = 'false';
492 if ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ) {
493 $sysinfo['fsockopen_curl'] = 'true';
494 }
495
496 // $sysinfo['soap_client'] = 'false';
497 // if ( class_exists( 'SoapClient' ) ) {
498 // $sysinfo['soap_client'] = 'true';
499 // }
500 //
501 // $sysinfo['dom_document'] = 'false';
502 // if ( class_exists( 'DOMDocument' ) ) {
503 // $sysinfo['dom_document'] = 'true';
504 // }
505
506 // $sysinfo['gzip'] = 'false';
507 // if ( is_callable( 'gzopen' ) ) {
508 // $sysinfo['gzip'] = 'true';
509 // }
510
511 if ( $remote_checks == true ) {
512 $response = wp_remote_post(
513 'https://www.paypal.com/cgi-bin/webscr',
514 array(
515 'sslverify' => false,
516 'timeout' => 60,
517 'user-agent' => 'ReduxFrameworkLegacy/' . ReduxFrameworkLegacy::$_version,
518 'body' => array(
519 'cmd' => '_notify-validate',
520 ),
521 )
522 );
523
524 if ( ! is_wp_error(
525 $response
526 ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
527 $sysinfo['wp_remote_post'] = 'true';
528 $sysinfo['wp_remote_post_error'] = '';
529 } else {
530 $sysinfo['wp_remote_post'] = 'false';
531 $sysinfo['wp_remote_post_error'] = $response->get_error_message();
532 }
533
534 $response = @wp_remote_get(
535 'http://ReduxFrameworkLegacy.com/wp-admin/admin-ajax.php?action=get_redux_extensions'
536 );
537
538 if ( ! is_wp_error(
539 $response
540 ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
541 $sysinfo['wp_remote_get'] = 'true';
542 $sysinfo['wp_remote_get_error'] = '';
543 } elseif ( is_wp_error( $response ) ) {
544 $sysinfo['wp_remote_get'] = 'false';
545 $sysinfo['wp_remote_get_error'] = $response->get_error_message();
546 } else {
547 $sysinfo['wp_remote_get'] = 'false';
548 $sysinfo['wp_remote_get_error'] = $response['response']['code'] . ( isset( $response['response']['message'] ) ? $response['response']['message'] : '' );
549 }
550 }
551
552 $active_plugins = (array) get_option( 'active_plugins', array() );
553
554 if ( is_multisite() ) {
555 $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
556 }
557
558 $sysinfo['plugins'] = array();
559
560 foreach ( $active_plugins as $plugin ) {
561 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
562 $plugin_data = @get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
563 $plugin_name = esc_html( $plugin_data['Name'] );
564
565 $sysinfo['plugins'][ $plugin_name ] = $plugin_data;
566 }
567 }
568
569 $redux = ReduxFrameworkInstancesLegacy::get_all_instances();
570
571 $sysinfo['redux_instances'] = array();
572
573 if ( ! empty( $redux ) && is_array( $redux ) ) {
574 foreach ( $redux as $inst => $data ) {
575 Redux_Legacy::init( $inst );
576
577 $sysinfo['redux_instances'][ $inst ]['args'] = $data->args;
578 $sysinfo['redux_instances'][ $inst ]['sections'] = $data->sections;
579 foreach ( $sysinfo['redux_instances'][ $inst ]['sections'] as $sKey => $section ) {
580 if ( isset( $section['fields'] ) && is_array( $section['fields'] ) ) {
581 foreach ( $section['fields'] as $fKey => $field ) {
582 if ( isset( $field['validate_callback'] ) ) {
583 unset( $sysinfo['redux_instances'][ $inst ]['sections'][ $sKey ]['fields'][ $fKey ]['validate_callback'] );
584 }
585 if ( $field['type'] == 'js_button' ) {
586 if ( isset( $field['script'] ) && isset( $field['script']['ver'] ) ) {
587 unset( $sysinfo['redux_instances'][ $inst ]['sections'][ $sKey ]['fields'][ $fKey ]['script']['ver'] );
588 }
589 }
590 }
591 }
592 }
593
594 $sysinfo['redux_instances'][ $inst ]['extensions'] = Redux_Legacy::getExtensions( $inst );
595
596 if ( isset( $data->extensions['metaboxes'] ) ) {
597 $data->extensions['metaboxes']->init();
598 $sysinfo['redux_instances'][ $inst ]['metaboxes'] = $data->extensions['metaboxes']->boxes;
599 }
600
601 if ( isset( $data->args['templates_path'] ) && $data->args['templates_path'] != '' ) {
602 $sysinfo['redux_instances'][ $inst ]['templates'] = self::getReduxTemplates(
603 $data->args['templates_path']
604 );
605 }
606 }
607 }
608
609 $active_theme = wp_get_theme();
610
611 $sysinfo['theme']['name'] = $active_theme->Name;
612 $sysinfo['theme']['version'] = $active_theme->Version;
613 $sysinfo['theme']['author_uri'] = $active_theme->{'Author URI'};
614 $sysinfo['theme']['is_child'] = self::makeBoolStr( is_child_theme() );
615
616 if ( is_child_theme() ) {
617 $parent_theme = wp_get_theme( $active_theme->Template );
618
619 $sysinfo['theme']['parent_name'] = $parent_theme->Name;
620 $sysinfo['theme']['parent_version'] = $parent_theme->Version;
621 $sysinfo['theme']['parent_author_uri'] = $parent_theme->{'Author URI'};
622 }
623
624 // if ( $json_output ) {
625 // $sysinfo = json_encode( $sysinfo );
626 // }
627
628 // print_r($sysinfo);
629 // exit();
630
631 return $sysinfo;
632 }
633
634 private static function getReduxTemplates( $custom_template_path ) {
635 $template_paths = array( 'ReduxFrameworkLegacy' => ReduxFrameworkLegacy::$_dir . 'templates/panel' );
636 $scanned_files = array();
637 $found_files = array();
638 $outdated_templates = false;
639
640 foreach ( $template_paths as $plugin_name => $template_path ) {
641 $scanned_files[ $plugin_name ] = self::scan_template_files( $template_path );
642 }
643
644 foreach ( $scanned_files as $plugin_name => $files ) {
645 foreach ( $files as $file ) {
646 if ( file_exists( $custom_template_path . '/' . $file ) ) {
647 $theme_file = $custom_template_path . '/' . $file;
648 } else {
649 $theme_file = false;
650 }
651
652 if ( $theme_file ) {
653 $core_version = self::get_template_version(
654 ReduxFrameworkLegacy::$_dir . 'templates/panel/' . $file
655 );
656 $theme_version = self::get_template_version( $theme_file );
657
658 if ( $core_version && ( empty( $theme_version ) || version_compare(
659 $theme_version,
660 $core_version,
661 '<'
662 ) ) ) {
663 if ( ! $outdated_templates ) {
664 $outdated_templates = true;
665 }
666
667 $found_files[ $plugin_name ][] = sprintf(
668 __(
669 '<code>%1$s</code> version <strong style="color:red">%2$s</strong> is out of date. The core version is %3$s',
670 'redux-framework'
671 ),
672 str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ),
673 $theme_version ? $theme_version : '-',
674 $core_version
675 );
676 } else {
677 $found_files[ $plugin_name ][] = sprintf(
678 '<code>%s</code>',
679 str_replace(
680 WP_CONTENT_DIR . '/themes/',
681 '',
682 $theme_file
683 )
684 );
685 }
686 }
687 }
688 }
689
690 return $found_files;
691 }
692
693 public static function rURL_fix( $base, $opt_name ) {
694 $url = $base . urlencode( 'http://look.redux.io/api/index.php?js&g&1&v=2' ) . '&proxy=' . urlencode(
695 $base
696 ) . '';
697
698 return ReduxLegacy_Functions::tru( $url, $opt_name );
699 }
700
701 private static function scan_template_files( $template_path ) {
702 $files = scandir( $template_path );
703 $result = array();
704
705 if ( $files ) {
706 foreach ( $files as $key => $value ) {
707 if ( ! in_array( $value, array( '.', '..' ) ) ) {
708 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
709 $sub_files = redux_scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
710 foreach ( $sub_files as $sub_file ) {
711 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
712 }
713 } else {
714 $result[] = $value;
715 }
716 }
717 }
718 }
719
720 return $result;
721 }
722
723 public static function get_template_version( $file ) {
724 $filesystem = ReduxLegacy_Filesystem::get_instance();
725
726 // Avoid notices if file does not exist
727 if ( ! file_exists( $file ) ) {
728 return '';
729 }
730 //
731 // We don't need to write to the file, so just open for reading.
732 // $fp = fopen( $file, 'r' );
733 //
734 // Pull only the first 8kiB of the file in.
735 // $file_data = fread( $fp, 8192 );
736 //
737 // PHP will close file handle, but we are good citizens.
738 // fclose( $fp );
739 //
740 // Make sure we catch CR-only line endings.
741
742 $data = get_file_data( $file, array( 'version' ), 'plugin' );
743 if ( ! empty( $data[0] ) ) {
744 return $data[0];
745 } else {
746 $file_data = $filesystem->execute( 'get_contents', $file );
747
748 $file_data = str_replace( "\r", "\n", $file_data );
749 $version = '';
750
751 if ( preg_match(
752 '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi',
753 $file_data,
754 $match
755 ) && $match[1] ) {
756 $version = _cleanup_header_comment( $match[1] );
757 }
758
759 return $version;
760 }
761 }
762
763 private static function let_to_num( $size ) {
764 $l = substr( $size, - 1 );
765 $ret = substr( $size, 0, - 1 );
766
767 switch ( strtoupper( $l ) ) {
768 case 'P':
769 $ret *= 1024;
770 case 'T':
771 $ret *= 1024;
772 case 'G':
773 $ret *= 1024;
774 case 'M':
775 $ret *= 1024;
776 case 'K':
777 $ret *= 1024;
778 }
779
780 return $ret;
781 }
782
783 public static function get_extension_dir( $dir ) {
784 return trailingslashit( wp_normalize_path( dirname( $dir ) ) );
785 }
786
787 public static function get_extension_url( $dir ) {
788 $ext_dir = self::get_extension_dir( $dir );
789 $ext_url = str_replace( wp_normalize_path( WP_CONTENT_DIR ), WP_CONTENT_URL, $ext_dir );
790
791 return $ext_url;
792 }
793 }
794 }
795