PluginProbe
QuadMenu – Mega Menu / trunk
QuadMenu – Mega Menu vtrunk
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / redux / ReduxCore / core / panel.php

panel.php in QuadMenu – Mega Menu trunk, at redux/ReduxCore/core/panel.php

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