PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/usaitv/lib/ReduxCore/inc/extensions/import_export/extension_import_export.php

https://gitlab.com/thisishayat/itv-2016
PHP | 209 lines | 125 code | 33 blank | 51 comment | 19 complexity | 29e844f6fe934a1879856a4ca8cefe2b MD5 | raw file
  1. <?php
  2. /**
  3. * Redux Framework is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * any later version.
  7. * Redux Framework is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. * You should have received a copy of the GNU General Public License
  12. * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
  13. *
  14. * @package ReduxFramework
  15. * @author Dovy Paukstys (dovy)
  16. * @version 4.0.0
  17. */
  18. // Exit if accessed directly
  19. if ( ! defined( 'ABSPATH' ) ) {
  20. exit;
  21. }
  22. // Don't duplicate me!
  23. if ( ! class_exists( 'ReduxFramework_extension_import_export' ) ) {
  24. /**
  25. * Main ReduxFramework import_export extension class
  26. *
  27. * @since 3.1.6
  28. */
  29. class ReduxFramework_extension_import_export {
  30. // Protected vars
  31. protected $parent;
  32. public $extension_url;
  33. public $extension_dir;
  34. public static $theInstance;
  35. public static $version = "4.0";
  36. public $is_field = false;
  37. /**
  38. * Class Constructor. Defines the args for the extions class
  39. *
  40. * @since 1.0.0
  41. * @access public
  42. *
  43. * @param array $sections Panel sections.
  44. * @param array $args Class constructor arguments.
  45. * @param array $extra_tabs Extra panel tabs.
  46. *
  47. * @return void
  48. */
  49. public function __construct( $parent ) {
  50. $this->parent = $parent;
  51. if ( empty( $this->extension_dir ) ) {
  52. //$this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) );
  53. }
  54. $this->field_name = 'import_export';
  55. self::$theInstance = $this;
  56. add_action( "wp_ajax_redux_link_options-" . $this->parent->args['opt_name'], array(
  57. $this,
  58. "link_options"
  59. ) );
  60. add_action( "wp_ajax_nopriv_redux_link_options-" . $this->parent->args['opt_name'], array(
  61. $this,
  62. "link_options"
  63. ) );
  64. add_action( "wp_ajax_redux_download_options-" . $this->parent->args['opt_name'], array(
  65. $this,
  66. "download_options"
  67. ) );
  68. add_action( "wp_ajax_nopriv_redux_download_options-" . $this->parent->args['opt_name'], array(
  69. $this,
  70. "download_options"
  71. ) );
  72. do_action( "redux/options/{$this->parent->args['opt_name']}/import", array( $this, 'remove_cookie' ) );
  73. $this->is_field = Redux_Helpers::isFieldInUse( $parent, 'import_export' );
  74. if ( ! $this->is_field && $this->parent->args['show_import_export'] ) {
  75. $this->add_section();
  76. }
  77. add_filter( 'redux/' . $this->parent->args['opt_name'] . '/field/class/' . $this->field_name, array(
  78. &$this,
  79. 'overload_field_path'
  80. ) ); // Adds the local field
  81. add_filter( 'upload_mimes', array(
  82. $this,
  83. 'custom_upload_mimes'
  84. ) );
  85. }
  86. /**
  87. * Adds the appropriate mime types to WordPress
  88. *
  89. * @param array $existing_mimes
  90. *
  91. * @return array
  92. */
  93. function custom_upload_mimes( $existing_mimes = array() ) {
  94. $existing_mimes['redux'] = 'application/redux';
  95. return $existing_mimes;
  96. }
  97. public function add_section() {
  98. $this->parent->sections[] = array(
  99. 'id' => 'import/export',
  100. 'title' => __( 'Import / Export', 'redux-framework' ),
  101. 'heading' => '',
  102. 'icon' => 'el el-refresh',
  103. 'customizer' => false,
  104. 'fields' => array(
  105. array(
  106. 'id' => 'redux_import_export',
  107. 'type' => 'import_export',
  108. //'class' => 'redux-field-init redux_remove_th',
  109. //'title' => '',
  110. 'full_width' => true,
  111. )
  112. ),
  113. );
  114. }
  115. function link_options() {
  116. if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ) ) {
  117. wp_die( 'Invalid Secret for options use' );
  118. exit;
  119. }
  120. $var = $this->parent->options;
  121. $var['redux-backup'] = '1';
  122. if ( isset( $var['REDUX_imported'] ) ) {
  123. unset( $var['REDUX_imported'] );
  124. }
  125. echo json_encode( $var );
  126. die();
  127. }
  128. public function download_options() {
  129. if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ) ) {
  130. wp_die( 'Invalid Secret for options use' );
  131. exit;
  132. }
  133. $this->parent->get_options();
  134. $backup_options = $this->parent->options;
  135. $backup_options['redux-backup'] = '1';
  136. if ( isset( $var['REDUX_imported'] ) ) {
  137. unset( $var['REDUX_imported'] );
  138. }
  139. // No need to escape this, as it's been properly escaped previously and through json_encode
  140. $content = json_encode( $backup_options );
  141. if ( isset( $_GET['action'] ) && $_GET['action'] == 'redux_download_options-' . $this->parent->args['opt_name'] ) {
  142. header( 'Content-Description: File Transfer' );
  143. header( 'Content-type: application/txt' );
  144. header( 'Content-Disposition: attachment; filename="redux_options_' . $this->parent->args['opt_name'] . '_backup_' . date( 'd-m-Y' ) . '.json"' );
  145. header( 'Content-Transfer-Encoding: binary' );
  146. header( 'Expires: 0' );
  147. header( 'Cache-Control: must-revalidate' );
  148. header( 'Pragma: public' );
  149. echo $content;
  150. exit;
  151. } else {
  152. header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  153. header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
  154. header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
  155. header( 'Cache-Control: no-store, no-cache, must-revalidate' );
  156. header( 'Cache-Control: post-check=0, pre-check=0', false );
  157. header( 'Pragma: no-cache' );
  158. // Can't include the type. Thanks old Firefox and IE. BAH.
  159. //header("Content-type: application/json");
  160. echo $content;
  161. exit;
  162. }
  163. }
  164. // Forces the use of the embeded field path vs what the core typically would use
  165. public function overload_field_path( $field ) {
  166. return dirname( __FILE__ ) . '/' . $this->field_name . '/field_' . $this->field_name . '.php';
  167. }
  168. public function remove_cookie() {
  169. // Remove the import/export tab cookie.
  170. if ( $_COOKIE['redux_current_tab'] == 'import_export_default' ) {
  171. setcookie( 'redux_current_tab', '', 1, '/' );
  172. $_COOKIE['redux_current_tab'] = 1;
  173. }
  174. }
  175. }
  176. }