| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Redux Framework Instance Container Class |
| 5 |
* Automatically captures and stores all instances |
| 6 |
* of ReduxFramework at instantiation. |
| 7 |
* |
| 8 |
* @package Redux_Framework |
| 9 |
* @subpackage Core |
| 10 |
*/ |
| 11 |
class ReduxFrameworkInstances { |
| 12 |
|
| 13 |
/** |
| 14 |
* ReduxFrameworkInstances |
| 15 |
* |
| 16 |
* @var object |
| 17 |
*/ |
| 18 |
private static $instance; |
| 19 |
|
| 20 |
/** |
| 21 |
* ReduxFramework instances |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
private static $instances; |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* @var array |
| 30 |
*/ |
| 31 |
private $options = array(); |
| 32 |
|
| 33 |
/** |
| 34 |
* Get Instance |
| 35 |
* Get ReduxFrameworkInstances instance |
| 36 |
* OR an instance of ReduxFramework by [opt_name] |
| 37 |
* |
| 38 |
* @param string $opt_name the defined opt_name |
| 39 |
* |
| 40 |
* @return object class instance |
| 41 |
*/ |
| 42 |
public static function get_instance( $opt_name = false ) { |
| 43 |
|
| 44 |
if ( is_null( self::$instance ) ) { |
| 45 |
self::$instance = new self(); |
| 46 |
} |
| 47 |
|
| 48 |
if ( $opt_name && ! empty( self::$instances[ $opt_name ] ) ) { |
| 49 |
return self::$instances[ $opt_name ]; |
| 50 |
} |
| 51 |
|
| 52 |
return self::$instance; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get all instantiated ReduxFramework instances (so far) |
| 57 |
* |
| 58 |
* @return [type] [description] |
| 59 |
*/ |
| 60 |
public static function get_all_instances() { |
| 61 |
return self::$instances; |
| 62 |
} |
| 63 |
|
| 64 |
private function __construct() { |
| 65 |
|
| 66 |
add_action( 'redux/construct', array( $this, 'capture' ), 5, 1 ); |
| 67 |
|
| 68 |
$hash = md5( trailingslashit( network_site_url() ) . '-redux' ); |
| 69 |
add_action( 'wp_ajax_nopriv_' . $hash, array( $this, 'tracking_arg' ) ); |
| 70 |
add_action( 'wp_ajax_' . $hash, array( $this, 'tracking_arg' ) ); |
| 71 |
|
| 72 |
if (!class_exists('Redux_Tracking') || !method_exists('Redux_Tracking', 'trackingObject')) { |
| 73 |
$hash = md5( md5( AUTH_KEY . SECURE_AUTH_KEY . '-redux' ) . '-support' ); |
| 74 |
add_action( 'wp_ajax_nopriv_' . $hash, array( $this, 'support_args' ) ); |
| 75 |
add_action( 'wp_ajax_' . $hash, array( $this, 'support_args' ) ); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
function tracking_arg() { |
| 82 |
echo md5( AUTH_KEY . SECURE_AUTH_KEY . '-redux' ); |
| 83 |
die(); |
| 84 |
} |
| 85 |
|
| 86 |
function support_args() { |
| 87 |
|
| 88 |
$this->options = get_option( 'redux-framework-tracking' ); |
| 89 |
$this->options['dev_mode'] = false; |
| 90 |
|
| 91 |
if ( ! isset( $this->options['hash'] ) || ! $this->options['hash'] || empty( $this->options['hash'] ) ) { |
| 92 |
$this->options['hash'] = md5( network_site_url() . '-' . $_SERVER['REMOTE_ADDR'] ); |
| 93 |
update_option( 'redux-framework-tracking', $this->options ); |
| 94 |
} |
| 95 |
|
| 96 |
if ( isset( $_GET['redux_framework_disable_tracking'] ) && ! empty( $_GET['redux_framework_disable_tracking'] ) ) { |
| 97 |
$this->options['allow_tracking'] = false; |
| 98 |
update_option( 'redux-framework-tracking', $this->options ); |
| 99 |
} |
| 100 |
|
| 101 |
if ( isset( $_GET['redux_framework_enable_tracking'] ) && ! empty( $_GET['redux_framework_enable_tracking'] ) ) { |
| 102 |
$this->options['allow_tracking'] = true; |
| 103 |
update_option( 'redux-framework-tracking', $this->options ); |
| 104 |
} |
| 105 |
|
| 106 |
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); |
| 107 |
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); |
| 108 |
header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); |
| 109 |
header( 'Cache-Control: no-store, no-cache, must-revalidate' ); |
| 110 |
header( 'Cache-Control: post-check=0, pre-check=0', false ); |
| 111 |
header( 'Pragma: no-cache' ); |
| 112 |
$instances = ReduxFrameworkInstances::get_all_instances(); |
| 113 |
|
| 114 |
$array = array(); |
| 115 |
|
| 116 |
if ( isset( $_REQUEST['i'] ) && ! empty( $_REQUEST['i'] ) ) { |
| 117 |
if ( is_array( $instances ) && ! empty( $instances ) ) { |
| 118 |
foreach ( $instances as $opt_name => $data ) { |
| 119 |
if ( md5( $opt_name . '-debug' ) == $_REQUEST['i'] ) { |
| 120 |
$array = $instances[ $opt_name ]; |
| 121 |
} |
| 122 |
if ($data->args['dev_mode']) { |
| 123 |
$this->options['dev_mode'] = $data->args['dev_mode']; |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
if ( isset( $array ) ) { |
| 128 |
if ( isset( $array->extensions ) && is_array( $array->extensions ) && ! empty( $array->extensions ) ) { |
| 129 |
foreach ( $array->extensions as $key => $extension ) { |
| 130 |
if ( isset( $extension->version ) ) { |
| 131 |
$array->extensions[ $key ] = $extension->version; |
| 132 |
} else { |
| 133 |
$array->extensions[ $key ] = true; |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
if ( isset( $array->import_export ) ) { |
| 139 |
unset( $array->import_export ); |
| 140 |
} |
| 141 |
|
| 142 |
if ( isset( $array->debug ) ) { |
| 143 |
unset( $array->debug ); |
| 144 |
} |
| 145 |
} else { |
| 146 |
die(); |
| 147 |
} |
| 148 |
|
| 149 |
} else { |
| 150 |
$array = Redux_Helpers::trackingObject(); |
| 151 |
if ( is_array( $instances ) && ! empty( $instances ) ) { |
| 152 |
$array['instances'] = array(); |
| 153 |
foreach ( $instances as $opt_name => $data ) { |
| 154 |
$array['instances'][] = $opt_name; |
| 155 |
} |
| 156 |
} |
| 157 |
$array['key'] = md5( AUTH_KEY . SECURE_AUTH_KEY ); |
| 158 |
} |
| 159 |
|
| 160 |
echo @json_encode( $array, true ); |
| 161 |
die(); |
| 162 |
} |
| 163 |
|
| 164 |
function capture( $ReduxFramework ) { |
| 165 |
$this->store( $ReduxFramework ); |
| 166 |
} |
| 167 |
|
| 168 |
private function store( $ReduxFramework ) { |
| 169 |
if ( $ReduxFramework instanceof ReduxFramework ) { |
| 170 |
$key = $ReduxFramework->args['opt_name']; |
| 171 |
self::$instances[ $key ] = $ReduxFramework; |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|