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