pages.php
194 lines
| 1 | <?php |
| 2 | |
| 3 | use IlluminateAgnostic\Arr\Support\Arr; |
| 4 | use Kubio\Core\StyleManager\Utils; |
| 5 | |
| 6 | function kubio_print_admin_page_header( $subtitle = null, $tabs = array(), $options = array() ) { |
| 7 | |
| 8 | global $_wp_admin_css_colors; |
| 9 | $color_scheme = get_user_option( 'admin_color', get_current_user_id() ); |
| 10 | |
| 11 | $colors = Arr::get( $_wp_admin_css_colors, "{$color_scheme}", array() ); |
| 12 | |
| 13 | $action_params = Arr::get( $options, 'action_params', array() ); |
| 14 | |
| 15 | $current_tab = sanitize_key( Arr::get( $_REQUEST, 'tab', 'get-started' ) ); |
| 16 | |
| 17 | if ( ! isset( $tabs[ $current_tab ] ) && count( $tabs ) > 0 ) { |
| 18 | $current_tab = array_keys( $tabs )[0]; |
| 19 | } |
| 20 | |
| 21 | $base_url = add_query_arg( 'page', 'kubio-get-started', admin_url( 'admin.php' ) ); |
| 22 | |
| 23 | ?> |
| 24 | |
| 25 | <style> |
| 26 | :root{ |
| 27 | <?php foreach ( Arr::get( (array) $colors, 'colors', array() ) as $index => $color ) : ?> |
| 28 | --kubio-admin-page-color-<?php echo esc_html( $index + 1 ); ?>:<?php echo esc_html( Utils::hex2rgba( $color, false, true ) ); ?>; |
| 29 | <?php endforeach; ?> |
| 30 | } |
| 31 | </style> |
| 32 | <div class="kubio-admin-page-header"> |
| 33 | <div class="limited-width"> |
| 34 | |
| 35 | <div class="kubio-admin-row"> |
| 36 | <div class="kubio-admin-col-1 no-gap"> |
| 37 | |
| 38 | <h1 class="kubio-admin-page-header-title"> |
| 39 | <?php echo wp_kses_post( file_get_contents( kubio_admin_assets_path() . '/kubio-logo.svg' ) ); ?> |
| 40 | </h1> |
| 41 | |
| 42 | <div class="kubio-admin-row kubio-admin-row-items-end"> |
| 43 | <?php if ( $subtitle ) : ?> |
| 44 | <div class="kubio-admin-page-header-subtitle"> |
| 45 | <?php echo esc_html( $subtitle ); ?> |
| 46 | </div> |
| 47 | <?php endif; ?> |
| 48 | </div> |
| 49 | |
| 50 | </div> |
| 51 | |
| 52 | <div class="kubio-admin-col justify-content-end"> |
| 53 | <div class="kubio-admin-page-header-start-editing"> |
| 54 | <a href="<?php echo esc_url( add_query_arg( 'page', 'kubio', admin_url( 'admin.php' ) ) ); ?>" |
| 55 | class="button button-hero button-primary"> |
| 56 | <?php esc_html_e( 'Start editing', 'kubio' ); ?> |
| 57 | </a> |
| 58 | </div> |
| 59 | </div> |
| 60 | |
| 61 | </div> |
| 62 | |
| 63 | |
| 64 | </div> |
| 65 | </div> |
| 66 | <?php if ( $tabs ) : ?> |
| 67 | <div class="kubio-admin-page-tabs"> |
| 68 | |
| 69 | <div class="kubio-admin-row limited-width"> |
| 70 | <ul class=""> |
| 71 | <?php |
| 72 | foreach ( $tabs as $tab_slug => $tab_data ) : |
| 73 | $class_add = ( $current_tab === $tab_slug ? 'active' : '' ); |
| 74 | if ( isset( $tab_data['class'] ) ) { |
| 75 | if ( ! is_array( $tab_data['class'] ) ) { |
| 76 | $tab_data['class'] = array( $tab_data['class'] ); |
| 77 | } |
| 78 | |
| 79 | $classes = array_merge( array( $class_add ), $tab_data['class'] ); |
| 80 | $class_add = implode( ' ', $classes ); |
| 81 | } |
| 82 | ?> |
| 83 | <li class="<?php echo $class_add; ?>"> |
| 84 | <?php if ( $tab_data['type'] === 'page' ) : ?> |
| 85 | <a href="<?php echo esc_url( add_query_arg( 'tab', $tab_slug, $base_url ) ); ?>"> |
| 86 | <?php echo esc_html( $tab_data['label'] ); ?> |
| 87 | </a> |
| 88 | <?php elseif ( $tab_data['type'] === 'link' ) : ?> |
| 89 | |
| 90 | <a href="<?php echo esc_url( $tab_data['href'] ); ?>" class="link-tab"> |
| 91 | <?php echo esc_html( $tab_data['label'] ); ?> |
| 92 | </a> |
| 93 | |
| 94 | <?php endif; ?> |
| 95 | |
| 96 | </li> |
| 97 | <?php endforeach; ?> |
| 98 | </ul> |
| 99 | </div> |
| 100 | |
| 101 | </div> |
| 102 | <?php endif; ?> |
| 103 | |
| 104 | |
| 105 | <?php do_action( 'kubio/welcome-page/after-header', $action_params ); ?> |
| 106 | <?php |
| 107 | } |
| 108 | |
| 109 | function kubio_print_admin_page_start() { |
| 110 | ?> |
| 111 | <div class="wrap"> |
| 112 | <div id="kubio-admin-page"> |
| 113 | <?php |
| 114 | |
| 115 | } |
| 116 | |
| 117 | function kubio_print_admin_page_end() { |
| 118 | ?> |
| 119 | </div> |
| 120 | </div> |
| 121 | <?php |
| 122 | |
| 123 | } |
| 124 | |
| 125 | function kubio_admin_assets_path() { |
| 126 | return KUBIO_ROOT_DIR . '/static/admin-pages/'; |
| 127 | |
| 128 | } |
| 129 | |
| 130 | |
| 131 | function kubio_admin_page_class( $page_name, $extra_classes = array(), $echo = true ) { |
| 132 | $classes = array_merge( |
| 133 | array( "kubio-admin-page--{$page_name}" ), |
| 134 | $extra_classes |
| 135 | ); |
| 136 | |
| 137 | $classes = implode( ' ', $classes ); |
| 138 | |
| 139 | if ( $echo ) { |
| 140 | echo esc_attr( $classes ); |
| 141 | } else { |
| 142 | return $classes; |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | |
| 147 | function kubio_admin_page_component_class( $component, $extra_classes = array(), $echo = true ) { |
| 148 | $classes = array_merge( |
| 149 | array( "kubio-admin-page-component--{$component}" ), |
| 150 | $extra_classes |
| 151 | ); |
| 152 | |
| 153 | $classes = implode( ' ', $classes ); |
| 154 | |
| 155 | if ( $echo ) { |
| 156 | echo esc_attr( $classes ); |
| 157 | } else { |
| 158 | return $classes; |
| 159 | } |
| 160 | |
| 161 | } |
| 162 | |
| 163 | function kubio_print_continous_loading_bar( $hidden = false ) { |
| 164 | ?> |
| 165 | <div class="kubio-progress-bar <?php echo( $hidden ? 'hidden' : '' ); ?>"> |
| 166 | <div class="kubio-progress-bar-value"></div> |
| 167 | </div> |
| 168 | <?php |
| 169 | } |
| 170 | |
| 171 | |
| 172 | add_action( |
| 173 | 'admin_enqueue_scripts', |
| 174 | function () { |
| 175 | wp_enqueue_style( 'kubio-admin-area' ); |
| 176 | wp_enqueue_script( 'kubio-admin-area' ); |
| 177 | |
| 178 | add_action( |
| 179 | 'admin_head', |
| 180 | function () { |
| 181 | ?> |
| 182 | <style> |
| 183 | :root { |
| 184 | --kubio-admin-pages-assets-root-url: <?php echo esc_url( kubio_url( '/static/admin-pages' ) ); ?>; |
| 185 | } |
| 186 | </style> |
| 187 | <?php |
| 188 | } |
| 189 | ); |
| 190 | } |
| 191 | ); |
| 192 | |
| 193 | require __DIR__ . '/kubio-get-started.php'; |
| 194 |