| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 2 |
|
| 3 |
/** |
| 4 |
* HTML Elements for admin pages excluding boxes |
| 5 |
* |
| 6 |
* @copyright Copyright (C) 2018, Echo Plugins |
| 7 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 8 |
*/ |
| 9 |
class EPDA_HTML_Admin { |
| 10 |
|
| 11 |
/******************************************************************************** |
| 12 |
* |
| 13 |
* ADMIN HEADER |
| 14 |
* |
| 15 |
********************************************************************************/ |
| 16 |
|
| 17 |
/** |
| 18 |
* Show Admin Header |
| 19 |
* |
| 20 |
* @param string $content_type |
| 21 |
*/ |
| 22 |
public static function admin_header( $content_type='header' ) { ?> |
| 23 |
|
| 24 |
<!-- Admin Header --> |
| 25 |
<div class="epda-admin__header"> |
| 26 |
<div class="epda-admin__section-wrap epda-admin__section-wrap__header"> <?php |
| 27 |
|
| 28 |
switch ( $content_type ) { |
| 29 |
case 'header': |
| 30 |
default: |
| 31 |
echo self::admin_header_content(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 32 |
break; |
| 33 |
case 'logo': |
| 34 |
echo self::get_admin_header_logo(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 35 |
break; |
| 36 |
} ?> |
| 37 |
|
| 38 |
</div> |
| 39 |
</div> <?php |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Show content of Admin Header |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
private static function admin_header_content() { |
| 48 |
|
| 49 |
ob_start(); |
| 50 |
|
| 51 |
echo self::get_admin_header_logo(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 52 |
|
| 53 |
$result = ob_get_clean(); |
| 54 |
|
| 55 |
return empty( $result ) ? '' : $result; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Fill missing fields in single admin page view configuration array with default values |
| 60 |
* |
| 61 |
* @param $page_view |
| 62 |
* @return array |
| 63 |
*/ |
| 64 |
private static function admin_page_view_fill_missing_with_default( $page_view ){ |
| 65 |
|
| 66 |
// Do not fill empty or not valid array |
| 67 |
if ( empty( $page_view ) || ! is_array( $page_view ) ) { |
| 68 |
return $page_view; |
| 69 |
} |
| 70 |
|
| 71 |
// Default page view |
| 72 |
$default_page_view = array( |
| 73 |
|
| 74 |
// Shared |
| 75 |
'minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 76 |
'active' => false, |
| 77 |
'list_id' => '', |
| 78 |
'list_key' => '', |
| 79 |
|
| 80 |
// Top Panel Item |
| 81 |
'label_text' => '', |
| 82 |
'main_class' => '', |
| 83 |
'label_class' => '', |
| 84 |
'icon_class' => '', |
| 85 |
|
| 86 |
// Secondary Panel Items |
| 87 |
'secondary' => array(), |
| 88 |
|
| 89 |
// Boxes List |
| 90 |
'list_top_actions_html_escaped' => '', |
| 91 |
'top_actions_minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 92 |
'list_bottom_actions_html_escaped' => '', |
| 93 |
'bottom_actions_minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 94 |
'boxes_list' => array(), |
| 95 |
|
| 96 |
// List footer HTML |
| 97 |
'list_footer_html' => '', |
| 98 |
); |
| 99 |
|
| 100 |
// Default secondary view |
| 101 |
$default_secondary = array( |
| 102 |
|
| 103 |
// Shared |
| 104 |
'list_key' => '', |
| 105 |
'active' => false, |
| 106 |
'minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 107 |
|
| 108 |
// Secondary Panel Item |
| 109 |
'label_text' => '', |
| 110 |
'main_class' => '', |
| 111 |
'label_class' => '', |
| 112 |
'icon_class' => '', |
| 113 |
|
| 114 |
// Secondary Boxes List |
| 115 |
'list_top_actions_html_escaped' => '', |
| 116 |
'top_actions_minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 117 |
'list_bottom_actions_html_escaped' => '', |
| 118 |
'bottom_actions_minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 119 |
'boxes_list' => array(), |
| 120 |
); |
| 121 |
|
| 122 |
// Default box |
| 123 |
$default_box = array( |
| 124 |
'minimum_required_capability' => EPDA_Utilities::ADMIN_CAPABILITY, |
| 125 |
'icon_class' => '', |
| 126 |
'class' => '', |
| 127 |
'title' => '', |
| 128 |
'description' => '', |
| 129 |
'html' => '', |
| 130 |
'return_html' => false, |
| 131 |
'extra_tags' => [], |
| 132 |
); |
| 133 |
|
| 134 |
// Set default view |
| 135 |
$page_view = array_merge( $default_page_view, $page_view ); |
| 136 |
|
| 137 |
// Set default boxes |
| 138 |
foreach ( $page_view['boxes_list'] as $box_index => $box_content ) { |
| 139 |
|
| 140 |
// Do not fill empty or not valid array |
| 141 |
if ( empty( $page_view['boxes_list'][$box_index] ) || ! is_array( $page_view['boxes_list'][$box_index] ) ) { |
| 142 |
continue; |
| 143 |
} |
| 144 |
|
| 145 |
$page_view['boxes_list'][$box_index] = array_merge( $default_box, $box_content ); |
| 146 |
} |
| 147 |
|
| 148 |
// Set default secondary views |
| 149 |
foreach ( $page_view['secondary'] as $secondary_index => $secondary_content ) { |
| 150 |
|
| 151 |
// Do not fill empty or not valid array |
| 152 |
if ( empty( $page_view['secondary'][$secondary_index] ) || ! is_array( $page_view['secondary'][$secondary_index] ) ) { |
| 153 |
continue; |
| 154 |
} |
| 155 |
|
| 156 |
$page_view['secondary'][$secondary_index] = array_merge( $default_secondary, $secondary_content ); |
| 157 |
|
| 158 |
// Set default boxes |
| 159 |
foreach ( $page_view['secondary'][$secondary_index]['boxes_list'] as $box_index => $box_content ) { |
| 160 |
|
| 161 |
// Do not fill empty or not valid array |
| 162 |
if ( empty( $page_view['secondary'][$secondary_index]['boxes_list'][$box_index] ) || ! is_array( $page_view['secondary'][$secondary_index]['boxes_list'][$box_index] ) ) { |
| 163 |
continue; |
| 164 |
} |
| 165 |
|
| 166 |
$page_view['secondary'][$secondary_index]['boxes_list'][$box_index] = array_merge( $default_box, $box_content ); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
return $page_view; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Show Admin Toolbar |
| 175 |
* |
| 176 |
* @param $admin_page_views |
| 177 |
*/ |
| 178 |
public static function admin_toolbar( $admin_page_views ) { ?> |
| 179 |
|
| 180 |
<!-- Admin Top Panel --> |
| 181 |
<div class="epda-admin__top-panel"> |
| 182 |
<div class="epda-admin__section-wrap epda-admin__section-wrap__top-panel"> <?php |
| 183 |
|
| 184 |
foreach( $admin_page_views as $page_view ) { |
| 185 |
|
| 186 |
// Optionally we can have null in $page_view, make sure we handle it correctly |
| 187 |
if ( empty( $page_view ) || ! is_array( $page_view ) ) { |
| 188 |
continue; |
| 189 |
} |
| 190 |
|
| 191 |
// Fill missing fields in admin page view configuration array with default values |
| 192 |
$page_view = self::admin_page_view_fill_missing_with_default( $page_view ); |
| 193 |
|
| 194 |
// Do not render toolbar tab if the user does not have permission |
| 195 |
if ( ! current_user_can( $page_view['minimum_required_capability'] ) ) { |
| 196 |
continue; |
| 197 |
} ?> |
| 198 |
|
| 199 |
<div class="epda-admin__top-panel__item epda-admin__top-panel__item--<?php echo esc_attr( $page_view['list_key'] ); |
| 200 |
echo empty( $page_view['secondary'] ) ? '' : ' epda-admin__top-panel__item--parent '; |
| 201 |
echo esc_attr( $page_view['main_class'] ); ?>" |
| 202 |
<?php echo empty( $page_view['list_id'] ) ? '' : ' id="' . esc_attr( $page_view['list_id'] ) . '"'; ?> data-target="<?php echo esc_attr( $page_view['list_key'] ); ?>"> |
| 203 |
<div class="epda-admin__top-panel__icon epda-admin__top-panel__icon--<?php echo esc_attr( $page_view['list_key'] ); ?> <?php echo esc_attr( $page_view['icon_class'] ); ?>"></div> |
| 204 |
<p class="epda-admin__top-panel__label epda-admin__boxes-list__label--<?php echo esc_attr( $page_view['list_key'] ); ?>"><?php echo wp_kses_post( $page_view['label_text'] ); ?></p> |
| 205 |
</div> <?php |
| 206 |
} ?> |
| 207 |
|
| 208 |
</div> |
| 209 |
</div> <?php |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Display admin second-level tabs below toolbar |
| 214 |
* |
| 215 |
* @param $admin_page_views |
| 216 |
*/ |
| 217 |
public static function admin_secondary_tabs( $admin_page_views ) { ?> |
| 218 |
|
| 219 |
<!-- Admin Secondary Panels List --> |
| 220 |
<div class="epda-admin__secondary-panels-list"> |
| 221 |
<div class="epda-admin__section-wrap epda-admin__section-wrap__secondary-panel"> <?php |
| 222 |
|
| 223 |
foreach ( $admin_page_views as $page_view ) { |
| 224 |
|
| 225 |
// Optionally we can have null in $page_view, make sure we handle it correctly |
| 226 |
if ( empty( $page_view ) || ! is_array( $page_view ) ) { |
| 227 |
continue; |
| 228 |
} |
| 229 |
|
| 230 |
// Optionally we can have empty in $page_view['secondary'], make sure we handle it correctly |
| 231 |
if ( empty( $page_view['secondary'] ) || ! is_array( $page_view['secondary'] ) ) { |
| 232 |
continue; |
| 233 |
} |
| 234 |
|
| 235 |
// Fill missing fields in admin page view configuration array with default values |
| 236 |
$page_view = self::admin_page_view_fill_missing_with_default( $page_view ); |
| 237 |
|
| 238 |
// Do not render toolbar tab if the user does not have permission |
| 239 |
if ( ! current_user_can( $page_view['minimum_required_capability'] ) ) { |
| 240 |
continue; |
| 241 |
} ?> |
| 242 |
|
| 243 |
<!-- Admin Secondary Panel --> |
| 244 |
<div id="epda-admin__secondary-panel__<?php echo esc_attr( $page_view['list_key'] ); ?>" class="epda-admin__secondary-panel"> <?php |
| 245 |
|
| 246 |
foreach ( $page_view['secondary'] as $secondary ) { |
| 247 |
|
| 248 |
// Optionally we can have empty in $secondary, make sure we handle it correctly |
| 249 |
if ( empty( $secondary ) || ! is_array( $secondary ) ) { |
| 250 |
continue; |
| 251 |
} |
| 252 |
|
| 253 |
// Do not render secondary toolbar tab if the user does not have permission |
| 254 |
if ( ! current_user_can( $secondary['minimum_required_capability'] ) ) { |
| 255 |
continue; |
| 256 |
} ?> |
| 257 |
|
| 258 |
<div class="epda-admin__secondary-panel__item epda-admin__secondary-panel__<?php echo esc_attr( $secondary['list_key'] ); ?> <?php |
| 259 |
echo ( $secondary['active'] ? 'epda-admin__secondary-panel__item--active' : '' ); |
| 260 |
echo esc_attr( $secondary['main_class'] ); ?>" data-target="<?php echo esc_attr( $page_view['list_key'] ) . '__' .esc_attr( $secondary['list_key'] ); ?>"> <?php |
| 261 |
|
| 262 |
// Optional icon for secondary panel item |
| 263 |
if ( ! empty( $secondary['icon_class'] ) ) { ?> |
| 264 |
<span class="epda-admin__secondary-panel__icon <?php echo esc_attr( $secondary['icon_class'] ); ?>"></span> <?php |
| 265 |
} ?> |
| 266 |
|
| 267 |
<p class="epda-admin__secondary-panel__label epda-admin__secondary-panel__<?php echo esc_attr( $secondary['list_key'] ); ?>__label"><?php echo wp_kses_post( $secondary['label_text'] ); ?></p> |
| 268 |
</div> <?php |
| 269 |
|
| 270 |
} ?> |
| 271 |
</div> <?php |
| 272 |
|
| 273 |
} ?> |
| 274 |
|
| 275 |
</div> |
| 276 |
</div> <?php |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Show list of settings for each setting in a tab |
| 281 |
* |
| 282 |
* @param $admin_page_views |
| 283 |
* @param string $content_class |
| 284 |
*/ |
| 285 |
public static function admin_settings_tab_content( $admin_page_views, $content_class='' ) { ?> |
| 286 |
|
| 287 |
<!-- Admin Content --> |
| 288 |
<div class="epda-admin__content <?php echo esc_attr( $content_class ); ?>"> <?php |
| 289 |
|
| 290 |
echo '<div class="epda-admin__boxes-list-container">'; |
| 291 |
foreach ( $admin_page_views as $page_view ) { |
| 292 |
|
| 293 |
// Optionally we can have null in $page_view, make sure we handle it correctly |
| 294 |
if ( empty( $page_view ) || ! is_array( $page_view ) ) { |
| 295 |
continue; |
| 296 |
} |
| 297 |
|
| 298 |
// Fill missing fields in admin page view configuration array with default values |
| 299 |
$page_view = self::admin_page_view_fill_missing_with_default( $page_view ); |
| 300 |
|
| 301 |
// Do not render view if the user does not have permission |
| 302 |
if ( ! current_user_can( $page_view['minimum_required_capability'] ) ) { |
| 303 |
continue; |
| 304 |
} ?> |
| 305 |
|
| 306 |
<!-- Admin Boxes List --> |
| 307 |
<div id="epda-admin__boxes-list__<?php echo esc_attr( $page_view['list_key'] ); ?>" class="epda-admin__boxes-list"> <?php |
| 308 |
|
| 309 |
// List body |
| 310 |
self::admin_setting_boxes_for_tab( $page_view ); |
| 311 |
|
| 312 |
// Optional list footer |
| 313 |
if ( ! empty( $page_view['list_footer_html'] ) ) { ?> |
| 314 |
<div class="epda-admin__section-wrap epda-admin__section-wrap__<?php echo esc_attr( $page_view['list_key'] ); ?>"> |
| 315 |
<div class="epda-admin__boxes-list__footer"><?php echo wp_kses_post( $page_view['list_footer_html'] ); ?></div> |
| 316 |
</div> <?php |
| 317 |
} ?> |
| 318 |
|
| 319 |
</div><?php |
| 320 |
} |
| 321 |
echo '</div>'; ?> |
| 322 |
</div><?php |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* Show single List of Settings Boxes for Admin Page |
| 327 |
* |
| 328 |
* @param $page_view |
| 329 |
*/ |
| 330 |
private static function admin_setting_boxes_for_tab( $page_view ) { |
| 331 |
|
| 332 |
// Boxes List for view without secondary panel |
| 333 |
if ( empty( $page_view['secondary'] ) ) { |
| 334 |
|
| 335 |
// Make sure we can handle empty boxes list correctly |
| 336 |
if ( empty( $page_view['boxes_list'] ) || ! is_array( $page_view['boxes_list'] ) ) { |
| 337 |
return; |
| 338 |
} ?> |
| 339 |
|
| 340 |
<!-- Admin Section Wrap --> |
| 341 |
<div class="epda-admin__section-wrap epda-admin__section-wrap__<?php echo esc_attr( $page_view['list_key'] ); ?>"> <?php |
| 342 |
|
| 343 |
self::admin_settings_display_boxes_list( $page_view ); ?> |
| 344 |
|
| 345 |
</div> <?php |
| 346 |
|
| 347 |
// Boxes List for view with secondary tabs |
| 348 |
} else { |
| 349 |
|
| 350 |
// Secondary Lists of Boxes |
| 351 |
foreach ( $page_view['secondary'] as $secondary ) { |
| 352 |
|
| 353 |
// Make sure we can handle empty boxes list correctly |
| 354 |
if ( empty( $secondary['boxes_list'] ) || ! is_array( $secondary['boxes_list'] ) ) { |
| 355 |
continue; |
| 356 |
} ?> |
| 357 |
|
| 358 |
<!-- Admin Section Wrap --> |
| 359 |
<div class="epda-setting-box-container epda-setting-box-container-type-<?php echo esc_attr( $page_view['list_key'] ); ?>"> |
| 360 |
|
| 361 |
<!-- Secondary Boxes List --> |
| 362 |
<div id="epda-setting-box__list-<?php echo esc_attr( $page_view['list_key'] ) . '__' . esc_attr( $secondary['list_key'] ); ?>" |
| 363 |
class="epda-setting-box__list <?php echo ( $secondary['active'] ? 'epda-setting-box__list--active' : '' ); ?>"> <?php |
| 364 |
|
| 365 |
self::admin_settings_display_boxes_list( $secondary ); ?> |
| 366 |
|
| 367 |
</div> |
| 368 |
|
| 369 |
</div> <?php |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
/** |
| 375 |
* Display boxes list for admin settings |
| 376 |
* |
| 377 |
* @param $page_view |
| 378 |
*/ |
| 379 |
private static function admin_settings_display_boxes_list( $page_view ) { |
| 380 |
|
| 381 |
// Optional buttons row displayed at the top of the boxes list |
| 382 |
if ( ! empty( $page_view['list_top_actions_html_escaped'] ) && current_user_can( $page_view['top_actions_minimum_required_capability'] ) ) { |
| 383 |
echo $page_view['list_top_actions_html_escaped']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 384 |
} |
| 385 |
|
| 386 |
// Admin Boxes with configuration |
| 387 |
foreach ( $page_view['boxes_list'] as $box_options ) { |
| 388 |
|
| 389 |
// Do not render empty or not valid array |
| 390 |
if ( empty( $box_options ) || ! is_array( $box_options ) ) { |
| 391 |
continue; |
| 392 |
} |
| 393 |
|
| 394 |
// Do not render box if the user does not have permission |
| 395 |
if ( ! current_user_can( $box_options['minimum_required_capability'] ) ) { |
| 396 |
continue; |
| 397 |
} |
| 398 |
|
| 399 |
EPDA_HTML_Forms::admin_settings_box( $box_options ); |
| 400 |
} |
| 401 |
|
| 402 |
// Optional buttons row displayed at the bottom of the boxes list |
| 403 |
if ( ! empty( $page_view['list_bottom_actions_html_escaped'] ) && current_user_can( $page_view['top_actions_minimum_required_capability'] )) { |
| 404 |
echo $page_view['list_bottom_actions_html_escaped']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
/** |
| 409 |
* Get logo container for the admin header |
| 410 |
* |
| 411 |
* @return string |
| 412 |
*/ |
| 413 |
private static function get_admin_header_logo() { |
| 414 |
|
| 415 |
ob_start(); ?> |
| 416 |
|
| 417 |
<!-- Down Arrow Logo --> |
| 418 |
<div class="epda-admin__header__logo-wrap"> |
| 419 |
<div class="epda__desc__logo"> |
| 420 |
<span class="epda__desc__logo__icon"> |
| 421 |
<span class="ep-help-dialog-icon"> |
| 422 |
<span class="ep_font_icon_help_dialog"></span> |
| 423 |
<span class="ep_font_icon_help_dialog-background"></span> |
| 424 |
</span> |
| 425 |
</span> |
| 426 |
</div> |
| 427 |
<div class="epda__desc__name"><?php esc_html_e( 'Down Arrow', 'scroll-down-arrow' ); ?></div> |
| 428 |
</div> <?php |
| 429 |
|
| 430 |
$result = ob_get_clean(); |
| 431 |
|
| 432 |
return empty( $result ) ? '' : $result; |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
/******************************************************************************** |
| 437 |
* |
| 438 |
* VARIOUS |
| 439 |
* |
| 440 |
********************************************************************************/ |
| 441 |
|
| 442 |
/** |
| 443 |
* Widget Details Popup - user can only click 'OK' button |
| 444 |
* |
| 445 |
* @param string $title |
| 446 |
* @param string $body |
| 447 |
* @param string $accept_label |
| 448 |
*/ |
| 449 |
public static function widget_details_popup( $title='', $body='', $accept_label='' ) { |
| 450 |
|
| 451 |
$body_escaped = EPDA_Utilities::admin_ui_wp_kses( $body ); ?> |
| 452 |
|
| 453 |
<div class="epda-admin__widget-details-popup"> |
| 454 |
|
| 455 |
<!---- Header ----> |
| 456 |
<div class="epda-admin__widget-details-popup__header"> |
| 457 |
<h4><?php echo esc_html( $title ); ?></h4> |
| 458 |
</div> |
| 459 |
|
| 460 |
<!---- Body ----> |
| 461 |
<div class="epda-admin__widget-details-popup__body"> |
| 462 |
<?php echo $body_escaped; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped?> |
| 463 |
</div> |
| 464 |
|
| 465 |
<!---- Footer ----> |
| 466 |
<div class="epda-admin__widget-details-popup__footer"> |
| 467 |
<div class="epda-admin__widget-details-popup__footer__accept"> |
| 468 |
<span class="epda-admin__widget-details-popup__accept-btn"> |
| 469 |
<?php echo empty( $accept_label ) ? esc_html__( 'OK', 'scroll-down-arrow' ) : esc_html( $accept_label ); ?> |
| 470 |
</span> |
| 471 |
</div> |
| 472 |
</div> |
| 473 |
|
| 474 |
</div> |
| 475 |
|
| 476 |
<div class="epda-admin__widget-details-popup__overlay"></div> <?php |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Generic admin page to display message on configuration error |
| 481 |
* |
| 482 |
* @param string|WP_Error $wp_error |
| 483 |
*/ |
| 484 |
public static function display_config_error_page( $wp_error = '' ) { |
| 485 |
|
| 486 |
if ( is_wp_error( $wp_error ) ) { |
| 487 |
$wp_error = $wp_error->get_error_message(); |
| 488 |
} |
| 489 |
|
| 490 |
$title = $wp_error ? esc_html__( 'Cannot load configuration.', 'scroll-down-arrow' ) . ' (' . $wp_error . ')' : esc_html__( 'Cannot load configuration.', 'scroll-down-arrow' ); ?> |
| 491 |
<div id="epda-admin-page-wrap" class="epda-admin-page-wrap--config-error"> <?php |
| 492 |
EPDA_HTML_Forms::notification_box_middle( [ 'type' => 'error', 'title' => $title, 'desc' => EPDA_Utilities::contact_us_for_support() ] ); ?> |
| 493 |
</div> <?php |
| 494 |
} |
| 495 |
} |
| 496 |
|