PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/tosin/framework/redux-framework/ReduxCore/core/panel.php

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