/wp-content/themes/usaitv/lib/ReduxCore/inc/class.redux_instances.php

https://gitlab.com/thisishayat/itv-2016 · PHP · 166 lines · 106 code · 28 blank · 32 comment · 32 complexity · f5bce48aaa58b8ab2d50f4b145c87f96 MD5 · raw file

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