reduxCorePanel

Class reduxCorePanel.

Defined (1)

The class is defined in the following location(s).

/library/admin/redux-framework/core/panel.php  
  1. class reduxCorePanel { 
  2. /** 
  3. * @var null 
  4. */ 
  5. public $parent = null; 
  6. /** 
  7. * @var null|string 
  8. */ 
  9. public $template_path = null; 
  10. /** 
  11. * @var null 
  12. */ 
  13. public $original_path = null; 
  14.  
  15. /** 
  16. * Sets the path from the arg or via filter. Also calls the panel template function. 
  17. * @param $parent 
  18. */ 
  19. public function __construct( $parent ) { 
  20. $this->parent = $parent; 
  21. Redux_Functions::$_parent = $parent; 
  22. $this->template_path = $this->original_path = ReduxFramework::$_dir . 'templates/panel/'; 
  23. if ( ! empty( $this->parent->args['templates_path'] ) ) { 
  24. $this->template_path = trailingslashit( $this->parent->args['templates_path'] ); 
  25. $this->template_path = trailingslashit( apply_filters( "redux/{$this->parent->args['opt_name']}/panel/templates_path", $this->template_path ) ); 
  26.  
  27. public function init() { 
  28. $this->panel_template(); 
  29.  
  30.  
  31. /** 
  32. * Loads the panel templates where needed and provides the container for Redux 
  33. */ 
  34. private function panel_template() { 
  35.  
  36. if ( $this->parent->args['dev_mode'] ) { 
  37. $this->template_file_check_notice(); 
  38.  
  39. /** 
  40. * action 'redux/{opt_name}/panel/before' 
  41. */ 
  42. do_action( "redux/{$this->parent->args['opt_name']}/panel/before" ); 
  43.  
  44. echo '<div class="wrap"><h2></h2></div>'; // Stupid hack for Wordpress alerts and warnings 
  45.  
  46. echo '<div class="clear"></div>'; 
  47. echo '<div class="wrap">'; 
  48.  
  49. // Do we support JS? 
  50. echo '<noscript><div class="no-js">' . __( 'Warning- This options panel will not work properly without javascript!', 'evolve' ) . '</div></noscript>'; 
  51.  
  52. // Security is vital! 
  53. echo '<input type="hidden" id="ajaxsecurity" name="security" value="' . wp_create_nonce( 'redux_ajax_nonce' . $this->parent->args['opt_name'] ) . '" />'; 
  54.  
  55. /** 
  56. * action 'redux-page-before-form-{opt_name}' 
  57. * @deprecated 
  58. */ 
  59. do_action( "redux-page-before-form-{$this->parent->args['opt_name']}" ); // Remove 
  60.  
  61. /** 
  62. * action 'redux/page/{opt_name}/form/before' 
  63. * @param object $this ReduxFramework 
  64. */ 
  65. do_action( "redux/page/{$this->parent->args['opt_name']}/form/before", $this ); 
  66.  
  67. $this->get_template( 'container.tpl.php' ); 
  68.  
  69. /** 
  70. * action 'redux-page-after-form-{opt_name}' 
  71. * @deprecated 
  72. */ 
  73. do_action( "redux-page-after-form-{$this->parent->args['opt_name']}" ); // REMOVE 
  74.  
  75. /** 
  76. * action 'redux/page/{opt_name}/form/after' 
  77. * @param object $this ReduxFramework 
  78. */ 
  79. do_action( "redux/page/{$this->parent->args['opt_name']}/form/after", $this ); 
  80. echo '<div class="clear"></div>'; 
  81. echo '</div>'; 
  82.  
  83. if ( $this->parent->args['dev_mode'] == true ) { 
  84. if ( current_user_can( 'administrator' ) ) { 
  85. global $wpdb; 
  86. echo "<br /><pre>"; 
  87. print_r( $wpdb->queries ); 
  88. echo "</pre>"; 
  89.  
  90. echo '<br /><div class="redux-timer">' . get_num_queries() . ' queries in ' . timer_stop( 0 ) . ' seconds<br/>Redux is currently set to developer mode.</div>'; 
  91.  
  92. /** 
  93. * action 'redux/{opt_name}/panel/after' 
  94. */ 
  95. do_action( "redux/{$this->parent->args['opt_name']}/panel/after" ); 
  96.  
  97.  
  98.  
  99. /** 
  100. * Calls the various notification bars and sets the appropriate templates. 
  101. */ 
  102. function notification_bar() { 
  103.  
  104. if ( isset( $this->parent->transients['last_save_mode'] ) ) { 
  105.  
  106. if ( $this->parent->transients['last_save_mode'] == "import" ) { 
  107. /** 
  108. * action 'redux/options/{opt_name}/import' 
  109. * @param object $this ReduxFramework 
  110. */ 
  111. do_action( "redux/options/{$this->parent->args['opt_name']}/import", $this, $this->parent->transients['changed_values'] ); 
  112.  
  113. /** 
  114. * filter 'redux-imported-text-{opt_name}' 
  115. * @param string translated "settings imported" text 
  116. */ 
  117. echo '<div class="admin-notice notice-blue saved_notice"><strong>' . apply_filters( "redux-imported-text-{$this->parent->args['opt_name']}", __( 'Settings Imported!', 'evolve' ) ) . '</strong></div>'; 
  118. //exit(); 
  119. } else if ( $this->parent->transients['last_save_mode'] == "defaults" ) { 
  120. /** 
  121. * action 'redux/options/{opt_name}/reset' 
  122. * @param object $this ReduxFramework 
  123. */ 
  124. do_action( "redux/options/{$this->parent->args['opt_name']}/reset", $this ); 
  125.  
  126. /** 
  127. * filter 'redux-defaults-text-{opt_name}' 
  128. * @param string translated "settings imported" text 
  129. */ 
  130. echo '<div class="saved_notice admin-notice notice-yellow"><strong>' . apply_filters( "redux-defaults-text-{$this->parent->args['opt_name']}", __( 'All Defaults Restored!', 'evolve' ) ) . '</strong></div>'; 
  131. } else if ( $this->parent->transients['last_save_mode'] == "defaults_section" ) { 
  132. /** 
  133. * action 'redux/options/{opt_name}/section/reset' 
  134. * @param object $this ReduxFramework 
  135. */ 
  136. do_action( "redux/options/{$this->parent->args['opt_name']}/section/reset", $this ); 
  137.  
  138. /** 
  139. * filter 'redux-defaults-section-text-{opt_name}' 
  140. * @param string translated "settings imported" text 
  141. */ 
  142. echo '<div class="saved_notice admin-notice notice-yellow"><strong>' . apply_filters( "redux-defaults-section-text-{$this->parent->args['opt_name']}", __( 'Section Defaults Restored!', 'evolve' ) ) . '</strong></div>'; 
  143. } else if ( $this->parent->transients['last_save_mode'] == "normal" ) { 
  144. /** 
  145. * action 'redux/options/{opt_name}/saved' 
  146. * @param mixed $value set/saved option value 
  147. */ 
  148. do_action( "redux/options/{$this->parent->args['opt_name']}/saved", $this->parent->options, $this->parent->transients['changed_values'] ); 
  149.  
  150. /** 
  151. * filter 'redux-saved-text-{opt_name}' 
  152. * @param string translated "settings saved" text 
  153. */ 
  154. echo '<div class="saved_notice admin-notice notice-green">' . apply_filters( "redux-saved-text-{$this->parent->args['opt_name']}", '<strong>'.__( 'Settings Saved!', 'evolve' ) ).'</strong>' . '</div>'; 
  155.  
  156. unset( $this->parent->transients['last_save_mode'] ); 
  157. //$this->parent->transients['last_save_mode'] = 'remove'; 
  158. $this->parent->set_transients(); 
  159.  
  160. /** 
  161. * action 'redux/options/{opt_name}/settings/changes' 
  162. * @param mixed $value set/saved option value 
  163. */ 
  164. do_action( "redux/options/{$this->parent->args['opt_name']}/settings/change", $this->parent->options, $this->parent->transients['changed_values'] ); 
  165.  
  166. /** 
  167. * filter 'redux-changed-text-{opt_name}' 
  168. * @param string translated "settings have changed" text 
  169. */ 
  170. echo '<div class="redux-save-warn notice-yellow"><strong>' . apply_filters( "redux-changed-text-{$this->parent->args['opt_name']}", __( 'Settings have changed, you should save them!', 'evolve' ) ) . '</strong></div>'; 
  171.  
  172. /** 
  173. * action 'redux/options/{opt_name}/errors' 
  174. * @param array $this ->errors error information 
  175. */ 
  176. do_action( "redux/options/{$this->parent->args['opt_name']}/errors", $this->parent->errors ); 
  177. echo '<div class="redux-field-errors notice-red"><strong><span></span> ' . __( 'error(s) were found!', 'evolve' ) . '</strong></div>'; 
  178.  
  179. /** 
  180. * action 'redux/options/{opt_name}/warnings' 
  181. * @param array $this ->warnings warning information 
  182. */ 
  183. do_action( "redux/options/{$this->parent->args['opt_name']}/warnings", $this->parent->warnings ); 
  184. echo '<div class="redux-field-warnings notice-yellow"><strong><span></span> ' . __( 'warning(s) were found!', 'evolve' ) . '</strong></div>'; 
  185.  
  186.  
  187. /** 
  188. * Used to intitialize the settings fields for this panel. Required for saving and redirect. 
  189. */ 
  190. function init_settings_fields() { 
  191. // Must run or the page won't redirect properly 
  192. settings_fields( "{$this->parent->args['opt_name']}_group" ); 
  193.  
  194.  
  195. /** 
  196. * Used to select the proper template. If it doesn't exist in the path, then the original template file is used. 
  197. * @param $file 
  198. */ 
  199. function get_template( $file ) { 
  200.  
  201. if ( empty( $file ) ) { 
  202. return; 
  203.  
  204. if ( file_exists( $this->template_path . $file ) ) { 
  205. $path = $this->template_path . $file; 
  206. } else { 
  207. $path = $this->original_path . $file; 
  208.  
  209. do_action( "redux/{$this->parent->args['opt_name']}/panel/template/" . $file . '/before' ); 
  210. $path = apply_filters( "redux/{$this->parent->args['opt_name']}/panel/template/" . $file, $path ); 
  211. do_action( "redux/{$this->parent->args['opt_name']}/panel/template/" . $file . '/after' ); 
  212.  
  213. require $path; 
  214.  
  215.  
  216. /** 
  217. * Scan the template files 
  218. * @param string $template_path 
  219. * @return array 
  220. */ 
  221. public function scan_template_files( $template_path ) { 
  222. $files = scandir( $template_path ); 
  223. $result = array(); 
  224. if ( $files ) { 
  225. foreach ( $files as $key => $value ) { 
  226. if ( ! in_array( $value, array( ".", ".." ) ) ) { 
  227. if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { 
  228. $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); 
  229. foreach ( $sub_files as $sub_file ) { 
  230. $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; 
  231. } else { 
  232. $result[] = $value; 
  233.  
  234. return $result; 
  235.  
  236. /** 
  237. * Show a notice highlighting bad template files 
  238. */ 
  239. public function template_file_check_notice() { 
  240.  
  241. if ( $this->template_path == $this->original_path ) { 
  242. return; 
  243.  
  244. $core_templates = $this->scan_template_files( $this->original_path ); 
  245. $outdated = false; 
  246.  
  247. foreach ( $core_templates as $file ) { 
  248. $developer_theme_file = false; 
  249.  
  250. if ( file_exists( $this->template_path . $file ) ) { 
  251. $developer_theme_file = $this->template_path . $file; 
  252.  
  253. if ( $developer_theme_file ) { 
  254. $core_version = Redux_Helpers::get_template_version( $this->original_path . $file ); 
  255. $developer_version = Redux_Helpers::get_template_version( $developer_theme_file ); 
  256.  
  257. if ( $core_version && $developer_version && version_compare( $developer_version, $core_version, '<' ) ) { 
  258. ?> 
  259. <div id="message" class="error redux-message"> 
  260. <p><?php _e( '<strong>Your panel has bundled outdated copies of Redux Framework template files</strong> – if you encounter functionality issues this could be the reason. Ensure you update or remove them.', 'evolve' ); ?></p> 
  261. </div> 
  262. <?php 
  263. return; 
  264.  
  265.  
  266. /** 
  267. * Outputs the HTML for a given section using the WordPress settings API. 
  268. * @param $k - Section number of settings panel to display 
  269. */ 
  270. function output_section( $k ) { 
  271. do_settings_sections( $this->parent->args['opt_name'] . $k . '_section_group' ); 
  272.