$row) { $key = (string) $key; if (!is_array($row)) { $row = array('label' => (string) $row); } $query = isset($row['query']) && is_array($row['query']) ? $row['query'] : array(); if (empty($query) && $default_arg !== '') { $query = array($default_arg => $key); } $out[$key] = array( 'id' => $key, 'label' => isset($row['label']) ? (string) $row['label'] : $key, 'query' => $query, 'align' => (isset($row['align']) && 'right' === $row['align']) ? 'right' : '', 'badge_class' => isset($row['badge_class']) ? (string) $row['badge_class'] : 'aieo-tab-count', 'icon' => isset($row['icon']) ? (string) $row['icon'] : '', ); } return $out; } public static function tab_strip($page_id, array $tabs, $active = '', array $opts = array()) { $arg = isset($opts['arg']) ? (string) $opts['arg'] : ''; $tabs = self::normalise_tabs($tabs, $arg); if (empty($tabs)) { return ''; } $keys = array_keys($tabs); $counts = isset($opts['counts']) && is_array($opts['counts']) ? $opts['counts'] : array(); if ($active === '' || !isset($tabs[$active])) { $active = self::active_from_request($tabs); } self::declare_tabs($page_id, $tabs); $base = isset($opts['base']) && $opts['base'] !== '' ? (string) $opts['base'] : add_query_arg( array('page' => AIEO_DMM::MENU_SLUG, 'dmm_tab' => $page_id), admin_url('admin.php') ); if (class_exists('AIEO_Chrome') && AIEO_Chrome::on() && function_exists('rooster_admin_tabs')) { $rows = array(); foreach ($tabs as $key => $tab) { $n = isset($counts[$key]) ? (int) $counts[$key] : 0; $rows[] = array( 'id' => $key, 'label' => $tab['label'], 'url' => add_query_arg($tab['query'], $base), 'icon' => $tab['icon'], 'count' => $n > 0 ? $n : null, 'end' => 'right' === $tab['align'], 'entry' => ($key === $active && false === strpos($key, '__')) ? 'rooster-one/tab/' . $page_id . '/' . $key : '', ); } echo rooster_admin_tabs($rows, $active); return $active; } $el = (isset($opts['wrapper']) && 'div' === $opts['wrapper']) ? 'div' : 'h2'; $margin = isset($opts['margin']) ? (string) $opts['margin'] : '16px'; self::print_tab_css(); printf('<%s class="nav-tab-wrapper" style="margin-bottom:%s;">', $el, esc_attr($margin)); foreach ($tabs as $key => $tab) { $url = add_query_arg($tab['query'], $base); $n = isset($counts[$key]) ? (int) $counts[$key] : 0; $badge = ''; if ($n > 0) { $badge = ' ' . (int) $n . ''; } printf( '%s%s', esc_url($url), ($key === $active ? ' nav-tab-active' : ''), ('right' === $tab['align'] ? ' style="float:right;margin-right:0;"' : ''), esc_html($tab['label']), $badge ); } if ($active !== '' && isset($tabs[$active]) && false === strpos($active, '__') && function_exists('rooster_admin_pin_button')) { echo rooster_admin_pin_button('rooster-one/tab/' . $page_id . '/' . $active); } printf('', $el); return $active; } public static function card(array $c) { if (!class_exists('AIEO_Table')) { require_once AIEO_DIR . 'includes/dmm/reports/class-aieo-table.php'; } self::$last_anchor = (string) ($c['anchor'] ?? ''); return AIEO_Table::card_shell($c); } public static function title_badge($text, $tone = 'mono') { $text = (string) $text; if ('' === $text || !class_exists('\Rooster\Admin\Ui')) { return ''; } return \Rooster\Admin\Ui::badge($text, (string) $tone, array('sm' => true)); } private static $last_anchor = ''; public static function current_anchor() { return self::$last_anchor; } public static function notice($html, $tone = 'info', array $opts = array()) { $title = (string) ($opts['title'] ?? ''); $detail = (string) ($opts['detail'] ?? ''); $id = (string) ($opts['id'] ?? ''); if (class_exists('\Rooster\Admin\Library') && wp_style_is(\Rooster\Admin\Library::HANDLE, 'enqueued')) { return \Rooster\Admin\Ui::notice((string) $html, (string) $tone, array_filter(array('inline' => true, 'title' => $title, 'detail' => $detail, 'id' => $id))); } $class = array('success' => 'notice-success', 'warning' => 'notice-warning', 'destructive' => 'notice-error', 'info' => 'notice-info', 'mono' => 'notice-info', 'primary' => 'notice-info'); return '' . ('' !== $title ? '

' . esc_html($title) . '

' : '') . ('' !== (string) $html ? '

' . $html . '

' : '') . $detail . ''; } public static function card_form($action, $group, $id, $html, array $opts = array()) { $attrs = array('data-aieo-save' => (string) $action, 'data-aieo-group' => (string) $group) + (is_array($opts['attrs'] ?? null) ? $opts['attrs'] : array()); if (isset($opts['nonce']) && '' !== (string) $opts['nonce']) { $attrs['data-aieo-nonce'] = (string) $opts['nonce']; $attrs['data-aieo-nonce-name'] = (string) ($opts['nonce_name'] ?? 'nonce'); } if (class_exists('\Rooster\Admin\States')) { return \Rooster\Admin\States::form((string) $id, (string) $html, array('url' => '', 'attrs' => $attrs, 'class' => (string) ($opts['class'] ?? ''), 'hidden' => is_array($opts['hidden'] ?? null) ? $opts['hidden'] : array())); } $out = '
$v) { $out .= ' ' . esc_attr($k) . '="' . esc_attr($v) . '"'; } $out .= '>'; foreach (is_array($opts['hidden'] ?? null) ? $opts['hidden'] : array() as $k => $v) { $out .= ''; } return $out . $html . '
'; } public static function active_tab($module) { $tabs = is_object($module) && method_exists($module, 'get_tabs') ? (array) $module->get_tabs() : array(); if (count($tabs) < 2) { return ''; } return (string) self::active_from_request(self::normalise_tabs($tabs, method_exists($module, 'get_tab_arg') ? (string) $module->get_tab_arg() : '')); } private static function active_from_request(array $tabs) { foreach ($tabs as $key => $tab) { if (empty($tab['query'])) { continue; } $hit = true; foreach ($tab['query'] as $k => $v) { $got = isset($_GET[$k]) ? sanitize_key(wp_unslash($_GET[$k])) : ''; if ($got !== (string) $v) { $hit = false; break; } } if ($hit) { return $key; } } $keys = array_keys($tabs); return $keys[0]; } public static function declare_tabs($page_id, array $tabs, $arg = '') { if (!isset(self::$declared[$page_id])) { self::$declared[$page_id] = array('tabs' => array(), 'panels' => array()); } foreach (self::normalise_tabs($tabs, $arg) as $key => $tab) { self::$declared[$page_id]['tabs'][$key] = $tab; } } public static function panel($page_id, $panel_id, $summary, $render, $note = '') { if (!isset(self::$declared[$page_id])) { self::$declared[$page_id] = array('tabs' => array(), 'panels' => array()); } self::$declared[$page_id]['panels'][$panel_id] = array( 'id' => $panel_id, 'label' => $summary, 'note' => $note, ); $want = isset($_GET['panel']) ? sanitize_key(wp_unslash($_GET['panel'])) : ''; $open = ($want === $panel_id) ? ' open' : ''; printf( '
', esc_attr($panel_id), esc_attr($panel_id), $open ); echo '' . esc_html($summary) . ''; if ($note !== '') { echo '

' . esc_html($note) . '

'; } if (is_callable($render)) { call_user_func($render); } echo '
'; } public static function action_attr($page_id, $action_id, $destructive = false, $variant = '') { $id = $page_id . '.' . $action_id; return 'data-aieo-action="' . esc_attr($id) . '"' . ($variant !== '' ? ' data-aieo-action-variant="' . esc_attr($variant) . '"' : '') . ($destructive ? ' data-aieo-action-destructive="1"' : ''); } public static function declared() { return self::$declared; } private static function print_tab_css() { static $printed = false; if ($printed) { return; } $printed = true; echo ''; } }