| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if ( ! class_exists( 'reduxCorePanel' ) ) { |
| 8 |
/** |
| 9 |
* Class reduxCorePanel |
| 10 |
*/ |
| 11 |
class reduxCorePanel { |
| 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 |
Redux_Functions::$_parent = $parent; |
| 33 |
$this->template_path = $this->original_path = ReduxFramework::$_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 ReduxFramework |
| 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 ReduxFramework |
| 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 |
/** |
| 122 |
* Calls the various notification bars and sets the appropriate templates. |
| 123 |
*/ |
| 124 |
function notification_bar() { |
| 125 |
|
| 126 |
if ( isset( $this->parent->transients['last_save_mode'] ) ) { |
| 127 |
|
| 128 |
if ( $this->parent->transients['last_save_mode'] == "import" ) { |
| 129 |
/** |
| 130 |
* action 'redux/options/{opt_name}/import' |
| 131 |
* |
| 132 |
* @param object $this ReduxFramework |
| 133 |
*/ |
| 134 |
do_action( "redux/options/{$this->parent->args['opt_name']}/import", $this, $this->parent->transients['changed_values'] ); |
| 135 |
|
| 136 |
/** |
| 137 |
* filter 'redux-imported-text-{opt_name}' |
| 138 |
* |
| 139 |
* @param string translated "settings imported" text |
| 140 |
*/ |
| 141 |
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>'; |
| 142 |
//exit(); |
| 143 |
} else if ( $this->parent->transients['last_save_mode'] == "defaults" ) { |
| 144 |
/** |
| 145 |
* action 'redux/options/{opt_name}/reset' |
| 146 |
* |
| 147 |
* @param object $this ReduxFramework |
| 148 |
*/ |
| 149 |
do_action( "redux/options/{$this->parent->args['opt_name']}/reset", $this ); |
| 150 |
|
| 151 |
/** |
| 152 |
* filter 'redux-defaults-text-{opt_name}' |
| 153 |
* |
| 154 |
* @param string translated "settings imported" text |
| 155 |
*/ |
| 156 |
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>'; |
| 157 |
} else if ( $this->parent->transients['last_save_mode'] == "defaults_section" ) { |
| 158 |
/** |
| 159 |
* action 'redux/options/{opt_name}/section/reset' |
| 160 |
* |
| 161 |
* @param object $this ReduxFramework |
| 162 |
*/ |
| 163 |
do_action( "redux/options/{$this->parent->args['opt_name']}/section/reset", $this ); |
| 164 |
|
| 165 |
/** |
| 166 |
* filter 'redux-defaults-section-text-{opt_name}' |
| 167 |
* |
| 168 |
* @param string translated "settings imported" text |
| 169 |
*/ |
| 170 |
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>'; |
| 171 |
} else if ( $this->parent->transients['last_save_mode'] == "normal" ) { |
| 172 |
/** |
| 173 |
* action 'redux/options/{opt_name}/saved' |
| 174 |
* |
| 175 |
* @param mixed $value set/saved option value |
| 176 |
*/ |
| 177 |
do_action( "redux/options/{$this->parent->args['opt_name']}/saved", $this->parent->options, $this->parent->transients['changed_values'] ); |
| 178 |
|
| 179 |
/** |
| 180 |
* filter 'redux-saved-text-{opt_name}' |
| 181 |
* |
| 182 |
* @param string translated "settings saved" text |
| 183 |
*/ |
| 184 |
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>'; |
| 185 |
} |
| 186 |
|
| 187 |
unset( $this->parent->transients['last_save_mode'] ); |
| 188 |
//$this->parent->transients['last_save_mode'] = 'remove'; |
| 189 |
$this->parent->set_transients(); |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* action 'redux/options/{opt_name}/settings/changes' |
| 194 |
* |
| 195 |
* @param mixed $value set/saved option value |
| 196 |
*/ |
| 197 |
do_action( "redux/options/{$this->parent->args['opt_name']}/settings/change", $this->parent->options, $this->parent->transients['changed_values'] ); |
| 198 |
|
| 199 |
/** |
| 200 |
* filter 'redux-changed-text-{opt_name}' |
| 201 |
* |
| 202 |
* @param string translated "settings have changed" text |
| 203 |
*/ |
| 204 |
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>'; |
| 205 |
|
| 206 |
/** |
| 207 |
* action 'redux/options/{opt_name}/errors' |
| 208 |
* |
| 209 |
* @param array $this ->errors error information |
| 210 |
*/ |
| 211 |
do_action( "redux/options/{$this->parent->args['opt_name']}/errors", $this->parent->errors ); |
| 212 |
echo '<div class="redux-field-errors notice-red"><strong><span></span> ' . __( 'error(s) were found!', 'redux-framework' ) . '</strong></div>'; |
| 213 |
|
| 214 |
/** |
| 215 |
* action 'redux/options/{opt_name}/warnings' |
| 216 |
* |
| 217 |
* @param array $this ->warnings warning information |
| 218 |
*/ |
| 219 |
do_action( "redux/options/{$this->parent->args['opt_name']}/warnings", $this->parent->warnings ); |
| 220 |
echo '<div class="redux-field-warnings notice-yellow"><strong><span></span> ' . __( 'warning(s) were found!', 'redux-framework' ) . '</strong></div>'; |
| 221 |
|
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Used to intitialize the settings fields for this panel. Required for saving and redirect. |
| 226 |
*/ |
| 227 |
function init_settings_fields() { |
| 228 |
// Must run or the page won't redirect properly |
| 229 |
settings_fields( "{$this->parent->args['opt_name']}_group" ); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
/** |
| 234 |
* Used to select the proper template. If it doesn't exist in the path, then the original template file is used. |
| 235 |
* |
| 236 |
* @param $file |
| 237 |
*/ |
| 238 |
function get_template( $file ) { |
| 239 |
|
| 240 |
if ( empty( $file ) ) { |
| 241 |
return; |
| 242 |
} |
| 243 |
|
| 244 |
if ( file_exists( $this->template_path . $file ) ) { |
| 245 |
$path = $this->template_path . $file; |
| 246 |
} else { |
| 247 |
$path = $this->original_path . $file; |
| 248 |
} |
| 249 |
|
| 250 |
do_action( "redux/{$this->parent->args['opt_name']}/panel/template/" . $file . '/before' ); |
| 251 |
$path = apply_filters( "redux/{$this->parent->args['opt_name']}/panel/template/" . $file, $path ); |
| 252 |
do_action( "redux/{$this->parent->args['opt_name']}/panel/template/" . $file . '/after' ); |
| 253 |
|
| 254 |
require $path; |
| 255 |
|
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Scan the template files |
| 260 |
* |
| 261 |
* @param string $template_path |
| 262 |
* |
| 263 |
* @return array |
| 264 |
*/ |
| 265 |
public function scan_template_files( $template_path ) { |
| 266 |
$files = scandir( $template_path ); |
| 267 |
$result = array(); |
| 268 |
if ( $files ) { |
| 269 |
foreach ( $files as $key => $value ) { |
| 270 |
if ( ! in_array( $value, array( ".", ".." ) ) ) { |
| 271 |
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { |
| 272 |
$sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); |
| 273 |
foreach ( $sub_files as $sub_file ) { |
| 274 |
$result[] = $value . DIRECTORY_SEPARATOR . $sub_file; |
| 275 |
} |
| 276 |
} else { |
| 277 |
$result[] = $value; |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
return $result; |
| 284 |
} |
| 285 |
|
| 286 |
/** |
| 287 |
* Show a notice highlighting bad template files |
| 288 |
*/ |
| 289 |
public function template_file_check_notice() { |
| 290 |
|
| 291 |
if ( $this->template_path == $this->original_path ) { |
| 292 |
return; |
| 293 |
} |
| 294 |
|
| 295 |
$core_templates = $this->scan_template_files( $this->original_path ); |
| 296 |
$outdated = false; |
| 297 |
|
| 298 |
foreach ( $core_templates as $file ) { |
| 299 |
$developer_theme_file = false; |
| 300 |
|
| 301 |
if ( file_exists( $this->template_path . $file ) ) { |
| 302 |
$developer_theme_file = $this->template_path . $file; |
| 303 |
} |
| 304 |
|
| 305 |
if ( $developer_theme_file ) { |
| 306 |
$core_version = Redux_Helpers::get_template_version( $this->original_path . $file ); |
| 307 |
$developer_version = Redux_Helpers::get_template_version( $developer_theme_file ); |
| 308 |
|
| 309 |
if ( $core_version && $developer_version && version_compare( $developer_version, $core_version, '<' ) ) { |
| 310 |
?> |
| 311 |
<div id="message" class="error redux-message"> |
| 312 |
<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.', 'redux-framework' ); ?></p> |
| 313 |
</div> |
| 314 |
<?php |
| 315 |
return; |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* Outputs the HTML for a given section using the WordPress settings API. |
| 324 |
* |
| 325 |
* @param $k - Section number of settings panel to display |
| 326 |
*/ |
| 327 |
function output_section( $k ) { |
| 328 |
do_settings_sections( $this->parent->args['opt_name'] . $k . '_section_group' ); |
| 329 |
} |
| 330 |
|
| 331 |
} |
| 332 |
} |