| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPCoder\Dashboard; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
use WPCoder\WPCoder; |
| 8 |
|
| 9 |
class DashboardInitializer { |
| 10 |
|
| 11 |
public static function init(): void { |
| 12 |
self::header(); |
| 13 |
echo '<div class="wrap wowp-wrap">'; |
| 14 |
// self::menu(); |
| 15 |
// self::include_pages(); |
| 16 |
echo '</div>'; |
| 17 |
} |
| 18 |
|
| 19 |
public static function header(): void { |
| 20 |
$logo_url = self::logo_url(); |
| 21 |
$add_url = add_query_arg( [ |
| 22 |
'page' => WPCoder::SLUG, |
| 23 |
'tab' => 'settings', |
| 24 |
'action' => 'new' |
| 25 |
], admin_url( 'admin.php' ) ); |
| 26 |
?> |
| 27 |
|
| 28 |
<div class="wowp-header-border"></div> |
| 29 |
<div class="wowp-header"> |
| 30 |
<div class="wowp-logo"> |
| 31 |
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 64 64"><title>64px_code</title><rect data-element="frame" x="0" y="0" width="64" height="64" rx="13" ry="13" stroke="none" fill="#007ea1"></rect><g transform="translate(12.8 12.8) scale(0.6)" fill="#ffffff"><path d="M19.562 18.75a2 2 0 0 0-2.811-.312l-15.001 12a2 2 0 0 0 0 3.124l15 12a1.997 1.997 0 0 0 2.811-.312 2 2 0 0 0-.312-2.811L6.201 32.001l13.048-10.438a2 2 0 0 0 .312-2.811z" fill="#ffffff"></path><path d="M47.25 18.438a2 2 0 1 0-2.499 3.123l13.048 10.438-13.048 10.438a2 2 0 0 0 2.499 3.123l15-12a2 2 0 0 0 0-3.124l-15-12z" fill="#FF6B6B"></path><path d="M39.539 5.074a2 2 0 0 0-2.465 1.387l-14 50a2 2 0 0 0 3.852 1.079l14-50.001a2 2 0 0 0-1.387-2.465z" fill="#FF6B6B"></path></g></svg> |
| 32 |
</div> |
| 33 |
<h1><?php echo esc_html( WPCoder::info('name') ); ?> <sup |
| 34 |
class="wowp-version"><?php echo esc_html( WPCoder::info('version') ); ?></sup></h1> |
| 35 |
|
| 36 |
<?php do_action( WPCoder::PREFIX . '_admin_header_links' ); ?> |
| 37 |
</div> |
| 38 |
|
| 39 |
|
| 40 |
<?php |
| 41 |
} |
| 42 |
|
| 43 |
public static function logo_url(): string { |
| 44 |
$logo_url = WPCoder::url() . 'assets/img/plugin-logo.png'; |
| 45 |
if ( filter_var( $logo_url, FILTER_VALIDATE_URL ) !== false ) { |
| 46 |
return $logo_url; |
| 47 |
} |
| 48 |
|
| 49 |
return ''; |
| 50 |
} |
| 51 |
|
| 52 |
public static function menu(): void { |
| 53 |
|
| 54 |
$pages = DashboardHelper::get_files( 'pages' ); |
| 55 |
unset($pages["3"], $pages["4"]); |
| 56 |
|
| 57 |
$current_page = self::get_current_page(); |
| 58 |
|
| 59 |
$action = ( isset( $_REQUEST["action"] ) ) ? sanitize_text_field( $_REQUEST["action"] ) : ''; |
| 60 |
|
| 61 |
echo '<h2 class="nav-tab-wrapper wowp-nav-tab-wrapper">'; |
| 62 |
foreach ( $pages as $key => $page ) { |
| 63 |
$class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : ''; |
| 64 |
$id = ''; |
| 65 |
|
| 66 |
if ( $action === 'update' && $page['file'] === 'settings' ) { |
| 67 |
$id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : ''; |
| 68 |
$page['name'] = __( 'Update', 'wpcoder' ) . ' #' . $id; |
| 69 |
} elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) { |
| 70 |
continue; |
| 71 |
} |
| 72 |
|
| 73 |
echo '<a class="nav-tab' . esc_attr( $class ) . '" href="' . esc_url( Link::menu( $page['file'], $action, $id ) ) . '">' . esc_html( $page['name'] ) . '</a>'; |
| 74 |
} |
| 75 |
echo '</h2>'; |
| 76 |
|
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
public static function include_pages(): void { |
| 81 |
$current_page = self::get_current_page(); |
| 82 |
|
| 83 |
$pages = DashboardHelper::get_files( 'pages' ); |
| 84 |
$default = DashboardHelper::first_file( 'pages' ); |
| 85 |
|
| 86 |
$current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default; |
| 87 |
|
| 88 |
$file = DashboardHelper::get_file( $current, 'pages' ); |
| 89 |
|
| 90 |
|
| 91 |
if ( $file !== false ) { |
| 92 |
$file = apply_filters( WPCoder::PREFIX . '_admin_filter_file', $file, $current ); |
| 93 |
|
| 94 |
$page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file; |
| 95 |
|
| 96 |
if ( file_exists( $page_path ) ) { |
| 97 |
require_once $page_path; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
public static function get_current_page(): string { |
| 105 |
$default = DashboardHelper::first_file( 'pages' ); |
| 106 |
|
| 107 |
return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( $_REQUEST["tab"] ) : $default; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
} |