| 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"> |
| 29 |
<div class="wowp-header__logo"> |
| 30 |
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"> |
| 31 |
<g fill="#212121"> |
| 32 |
<path d="M19.562,18.75c-.69-.862-1.948-1.003-2.811-.312L1.75,30.438c-.474,.379-.75,.954-.75,1.562s.276,1.182,.75,1.562l15,12c.369,.295,.81,.438,1.248,.438,.587,0,1.168-.257,1.563-.75,.69-.863,.55-2.121-.312-2.811l-13.048-10.438,13.048-10.438c.862-.69,1.002-1.948,.312-2.811Z" fill="#fa2222"></path> |
| 33 |
<path d="M47.25,18.438c-.862-.691-2.121-.55-2.811,.312-.69,.863-.55,2.121,.312,2.811l13.048,10.438-13.048,10.438c-.862,.69-1.002,1.948-.312,2.811,.395,.494,.976,.75,1.563,.75,.438,0,.879-.143,1.248-.438l15-12c.474-.379,.75-.954,.75-1.562s-.276-1.182-.75-1.562l-15-12Z" fill="#5522fa"></path> |
| 34 |
<path d="M39.539,5.074c-1.063-.298-2.167,.324-2.465,1.387l-14,50c-.298,1.063,.323,2.167,1.387,2.465,.18,.051,.362,.075,.54,.075,.875,0,1.678-.578,1.925-1.461L40.926,7.539c.298-1.063-.323-2.167-1.387-2.465Z" fill="#5522fa"></path></g> |
| 35 |
</svg> |
| 36 |
</div> |
| 37 |
<h1 class="wowp-header__title"> |
| 38 |
<?php echo esc_html( WPCoder::info( 'name' ) ); ?> |
| 39 |
<sup class="wowp-header__title-version"><?php echo esc_html( WPCoder::info( 'version' ) ); ?></sup> |
| 40 |
</h1> |
| 41 |
<div class="wowp-header__links"> |
| 42 |
<?php do_action( WPCoder::PREFIX . '_admin_header_links' ); ?> |
| 43 |
</div> |
| 44 |
</div> |
| 45 |
|
| 46 |
|
| 47 |
<?php |
| 48 |
} |
| 49 |
|
| 50 |
public static function logo_url(): string { |
| 51 |
$logo_url = WPCoder::url() . 'assets/img/plugin-logo.png'; |
| 52 |
if ( filter_var( $logo_url, FILTER_VALIDATE_URL ) !== false ) { |
| 53 |
return $logo_url; |
| 54 |
} |
| 55 |
|
| 56 |
return ''; |
| 57 |
} |
| 58 |
|
| 59 |
public static function menu(): void { |
| 60 |
|
| 61 |
$pages = DashboardHelper::get_files( 'pages' ); |
| 62 |
unset( $pages["3"], $pages["4"] ); |
| 63 |
|
| 64 |
$current_page = self::get_current_page(); |
| 65 |
|
| 66 |
$action = ( isset( $_REQUEST["action"] ) ) ? sanitize_text_field( $_REQUEST["action"] ) : ''; |
| 67 |
|
| 68 |
echo '<h2 class="nav-tab-wrapper wowp-nav-tab-wrapper">'; |
| 69 |
foreach ( $pages as $key => $page ) { |
| 70 |
$class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : ''; |
| 71 |
$id = ''; |
| 72 |
|
| 73 |
if ( $action === 'update' && $page['file'] === 'settings' ) { |
| 74 |
$id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : ''; |
| 75 |
$page['name'] = __( 'Update', 'wp-coder' ) . ' #' . $id; |
| 76 |
} elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) { |
| 77 |
continue; |
| 78 |
} |
| 79 |
|
| 80 |
echo '<a class="nav-tab' . esc_attr( $class ) . '" href="' . esc_url( Link::menu( $page['file'], $action, $id ) ) . '">' . esc_html( $page['name'] ) . '</a>'; |
| 81 |
} |
| 82 |
echo '</h2>'; |
| 83 |
|
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
public static function include_pages(): void { |
| 88 |
$current_page = self::get_current_page(); |
| 89 |
|
| 90 |
$pages = DashboardHelper::get_files( 'pages' ); |
| 91 |
$default = DashboardHelper::first_file( 'pages' ); |
| 92 |
|
| 93 |
$current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default; |
| 94 |
|
| 95 |
$file = DashboardHelper::get_file( $current, 'pages' ); |
| 96 |
|
| 97 |
|
| 98 |
if ( $file !== false ) { |
| 99 |
$file = apply_filters( WPCoder::PREFIX . '_admin_filter_file', $file, $current ); |
| 100 |
|
| 101 |
$page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file; |
| 102 |
|
| 103 |
if ( file_exists( $page_path ) ) { |
| 104 |
require_once $page_path; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
public static function get_current_page(): string { |
| 112 |
$default = DashboardHelper::first_file( 'pages' ); |
| 113 |
|
| 114 |
return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( $_REQUEST["tab"] ) : $default; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
} |