(string) $profile['profile'], 'label' => (string) ($profile['short'] ?? $profile['profile']), 'title' => (string) ($profile['label'] ?? $profile['profile']), 'description' => $text, 'source' => !empty($profile['pinned']) ? 'set' : 'detected', 'url' => add_query_arg(array('page' => 'ai-eshop-dmm', 'dmm_tab' => 'seo_general'), admin_url('admin.php')), 'change' => __('Change', 'ai-eshop-optimizer'), ); } private static function profile() { if (!class_exists('AIEO_SEO_Score')) { $file = AIEO_DIR . 'includes/seo/class-aieo-seo-score.php'; if (file_exists($file)) { require_once $file; } } if (!class_exists('AIEO_SEO_Score') || !method_exists('AIEO_SEO_Score', 'profile_status')) { return null; } $profile = AIEO_SEO_Score::profile_status(); return is_array($profile) && !empty($profile['profile']) ? $profile : null; } public static function on() { return self::$library && function_exists('rooster_admin'); } public static function home_url() { return admin_url('admin.php?page=' . self::HOME_SLUG); } public static function page_head($id, $title = '', $icon = '', $board = '', $essential = false) { if (!self::on() || !class_exists('\Rooster\Admin\Ui') || !class_exists('\Rooster\Admin\Library')) { return ''; } $registry = \Rooster\Admin\Library::registry(); $entry_id = self::PRODUCT . '/' . (string) $id; $entry = null !== $registry ? $registry->get($entry_id) : null; $plain = static function ($s) { return html_entity_decode(wp_strip_all_tags((string) $s), ENT_QUOTES, 'UTF-8'); }; $desc = null !== $entry ? (string) ($entry['description'] ?? '') : ''; if ('' === $desc && class_exists('AIEO_Menu_Descriptions')) { $desc = AIEO_Menu_Descriptions::for_subtab((string) $id); } return \Rooster\Admin\Ui::pagehead( $plain(null !== $entry && '' !== (string) $entry['title'] ? $entry['title'] : $title), array( 'id' => 'aieo-page-' . sanitize_html_class((string) $id), 'icon' => null !== $entry && '' !== (string) ($entry['icon'] ?? '') ? (string) $entry['icon'] : (string) $icon, 'description' => $plain($desc), 'pin' => null !== $entry && function_exists('rooster_admin_pin_button') ? rooster_admin_pin_button($entry_id) : '', 'board' => (string) $board, 'essential' => (bool) $essential, ) ) . '
'; } public static function board_key($module, $id) { $key = is_object($module) && method_exists($module, 'board_key') ? (string) $module->board_key() : ''; if ('' === $key) { $key = (string) $id; $tab = class_exists('AIEO_DMM_UI') ? AIEO_DMM_UI::active_tab($module) : ''; if ('' !== $tab) { $key .= '/' . $tab; } } return 1 === preg_match('#^[a-z0-9][a-z0-9_./-]{0,119}$#', $key) ? $key : ''; } public static function register_product($registry) { if (class_exists('\Rooster\Admin\Adapters\RoosterOne')) { \Rooster\Admin\Adapters\RoosterOne::register_product($registry); $registry->register_home_card(self::PRODUCT, 'after_catalogue', array(__CLASS__, 'training_card'), 10); } } public static function training_card() { if (!function_exists('rooster_admin_card') || !class_exists('\Rooster\Admin\Ui')) { return ''; } $video_price = '€49'; $hourly_rate = '€100'; $learn = ''; foreach (array( __('Complete plugin setup and API configuration', 'ai-eshop-optimizer'), __('AI-powered recommendation strategies for maximum sales', 'ai-eshop-optimizer'), __('Advanced features: Chat integration, embeddings, and optimization', 'ai-eshop-optimizer'), __('Best practices for WooCommerce AI implementation', 'ai-eshop-optimizer'), ) as $item) { $learn .= '
  • ' . esc_html($item) . '
  • '; } $body = '

    ' . esc_html__('Learn setup, configuration, and optimization strategies from the experts who built the plugin.', 'ai-eshop-optimizer') . '

    ' . '

    ' . esc_html__('What you\'ll learn:', 'ai-eshop-optimizer') . '

    ' . '

    ' . esc_html__('One-time investment:', 'ai-eshop-optimizer') . ' ' . esc_html($video_price) . ' · ' . esc_html__('90 minutes • Lifetime access', 'ai-eshop-optimizer') . '

    ' . rooster_admin_card_section_html() . '

    ' . esc_html__('Partner with our AI specialists for a personalized setup session.', 'ai-eshop-optimizer') . ' ' . esc_html__('Get your store optimized in hours, not days.', 'ai-eshop-optimizer') . '

    ' . '

    ' . esc_html__('Starting at:', 'ai-eshop-optimizer') . ' ' . esc_html($hourly_rate) . '/' . esc_html__('hour', 'ai-eshop-optimizer') . ' · ' . esc_html__('Average session: 2-3 hours', 'ai-eshop-optimizer') . '

    '; $footer = \Rooster\Admin\Ui::button(__('Watch Training Video', 'ai-eshop-optimizer'), array('href' => 'https://eshop-optimizer.com/service/training-video-of-ai-eshop-optimizer-usage?ref=plugin', 'variant' => 'primary', 'external' => true)) . ' ' . \Rooster\Admin\Ui::button(__('Book Your Session', 'ai-eshop-optimizer'), array('href' => 'https://eshop-optimizer.com/service/optimizer-setup?ref=plugin', 'external' => true)); $connected = class_exists('AIEO_DMM_Subscription') && AIEO_DMM_Subscription::is_connected(); $footer .= ' ' . \Rooster\Admin\Ui::button( $connected ? __('Rooster One Pro', 'ai-eshop-optimizer') : __('Start my free Pro trial', 'ai-eshop-optimizer'), array( 'href' => admin_url('admin.php?page=ai-eshop-dmm&dmm_tab=subscription' . ($connected ? '' : '#aieo-card-get-pro')), 'icon' => $connected ? 'credit-card' : 'rocket', ) ) . ' ' . \Rooster\Admin\Ui::button(__('See pricing + full feature list', 'ai-eshop-optimizer'), array('href' => 'https://rooster.systems/get-rooster-one/', 'external' => true)); return rooster_admin_card('', __('Master Rooster One in 90 Minutes', 'ai-eshop-optimizer'), $body, array( 'dom_id' => 'aieo-home-training', 'dismissible' => true, 'icon' => 'graduation-cap', 'description' => __('Complete video training that covers everything you need to know.', 'ai-eshop-optimizer'), 'footer' => $footer, )); } public static function catalogue($rows, $registry) { unset($registry); if (!is_array($rows)) { return $rows; } $flags = self::card_flags(); foreach ($rows as $i => $row) { if (!is_array($row) || 'card' !== (string) ($row['kind'] ?? '') || self::PRODUCT !== (string) ($row['product'] ?? '')) { continue; } $url = (string) ($row['url'] ?? ''); $at = strpos($url, '#aieo-card-'); $key = false === $at ? '' : substr($url, $at + 11); if ('' === $key || !isset($flags[$key])) { continue; } $rows[$i]['pin'] = false; if ('section' === $flags[$key]) { $rows[$i]['listed'] = false; } } return $rows; } private static function card_flags() { static $flags = null; if (null !== $flags) { return $flags; } $flags = array(); $file = AIEO_DIR . 'includes/dmm/data/section-anchors.php'; $rows = is_readable($file) ? include $file : array(); foreach (is_array($rows) ? $rows : array() as $row) { if (!is_array($row) || empty($row['anchor']) || isset($flags[(string) $row['anchor']])) { continue; } if (!empty($row['section'])) { $flags[(string) $row['anchor']] = 'section'; } elseif (!empty($row['page_title'])) { $flags[(string) $row['anchor']] = 'page_title'; } } return $flags; } public static function status_rows(array $rows, $product) { if (self::PRODUCT !== $product || !class_exists('AIEO_Install_Status') || !method_exists('AIEO_Install_Status', 'rows')) { return $rows; } foreach ((array) AIEO_Install_Status::rows() as $row) { if (!is_array($row) || empty($row['id'])) { continue; } $state = isset($row['state']) ? (string) $row['state'] : 'off'; $version = isset($row['version']) ? trim((string) $row['version']) : ''; $detail = isset($row['detail']) ? trim((string) $row['detail']) : ''; $rows[(string) $row['id']] = array( 'name' => isset($row['name']) ? (string) $row['name'] : (string) $row['id'], 'state' => in_array($state, array('on', 'hold', 'off', 'error'), true) ? $state : 'off', 'detail' => trim($version . ('' !== $version && '' !== $detail ? ' · ' : '') . $detail), 'url' => isset($row['url']) ? (string) $row['url'] : '', ); } $profile = self::site_profile_row(); if (array() !== $profile) { $rows['site_profile'] = $profile; } return $rows; } public static function ai_chat_url($url, $product, $section = '') { if ('' !== (string) $url || !class_exists('AIEO_Merchant_Chat') || !AIEO_Merchant_Chat::user_can_chat()) { return (string) $url; } $args = array('page' => 'ai-eshop-dmm', 'dmm_tab' => 'insights_chat'); if ('' !== (string) $product) { $args['context'] = sanitize_key((string) $product) . ('' !== (string) $section ? '/' . sanitize_key((string) $section) : ''); } return add_query_arg($args, admin_url('admin.php')); } public static function current_product($product) { if ('' !== (string) $product) { return (string) $product; } if (class_exists('AIEO_Merchant_Chat') && AIEO_Merchant_Chat::is_window_mode()) { return ''; } return class_exists('AIEO_DMM') && AIEO_DMM::is_rooster_page() ? self::PRODUCT : ''; } public static function services(array $items, $product) { if (self::PRODUCT !== $product) { return $items; } $reopenable = class_exists('AIEO_Forms') && method_exists('AIEO_Forms', 'reopenable') ? (array) AIEO_Forms::reopenable() : array(); $here = remove_query_arg('aieo_form_open'); if (in_array('checkin', $reopenable, true)) { $items['survey'] = self::icon_item( 'survey', 'a', array('href' => add_query_arg('aieo_form_open', 'checkin', $here), 'data-aieo-form-load' => 'checkin'), '', __('Answer the survey', 'ai-eshop-optimizer') ); } if (in_array('welcome', $reopenable, true)) { $items['welcome'] = self::icon_item( 'welcome', 'a', array('href' => add_query_arg('aieo_form_open', 'welcome', $here), 'data-aieo-form-load' => 'welcome'), '', __('Read the welcome again', 'ai-eshop-optimizer') ); } return $items; } public static function feedback_sender($sender, $product) { unset($product); if (null !== $sender || !class_exists('AIEO_Feedback') || !class_exists('AIEO_Portal_Client')) { return $sender; } return array('AIEO_Feedback', 'send'); } private static function icon_item($key, $tag, array $attrs, $svg, $label) { $tag = 'button' === $tag ? 'button' : 'a'; $html = '
  • <' . $tag . ' class="rooster-admin-iconlink is-' . esc_attr($key) . ' aieo-top-' . esc_attr($key) . '"'; if ('button' === $tag) { $html .= ' type="button"'; } foreach ($attrs as $name => $value) { $html .= '' === (string) $value ? ' ' . $name : ' ' . $name . '="' . ('href' === $name ? esc_url($value) : esc_attr($value)) . '"'; } $html .= ' aria-label="' . esc_attr($label) . '" data-ra-tip="' . esc_attr($label) . '">' . '' . '
  • '; return $html; } private static function site_profile_row() { $profile = self::profile(); if (null === $profile) { return array(); } $label = (string) ($profile['label'] ?? $profile['profile']); $detected = (string) ($profile['detected'] ?? ''); if (!empty($profile['mismatch'])) { $labels = method_exists('AIEO_SEO_Score', 'profile_labels') ? (array) AIEO_SEO_Score::profile_labels() : array(); $detail = sprintf(__('%1$s, set by hand; the shop looks like %2$s', 'ai-eshop-optimizer'), $label, isset($labels[$detected]) ? (string) $labels[$detected] : $detected); } elseif (!empty($profile['pinned'])) { $detail = sprintf(__('%s, set by hand', 'ai-eshop-optimizer'), $label); } else { $detail = sprintf(__('%s, detected', 'ai-eshop-optimizer'), $label); } if (!empty($profile['also']) && is_array($profile['also'])) { $detail .= '; ' . implode('; ', array_map('strval', $profile['also'])); } return array( 'name' => __('Site profile', 'ai-eshop-optimizer'), 'state' => !empty($profile['mismatch']) ? 'hold' : 'on', 'detail' => $detail, 'url' => add_query_arg(array('page' => 'ai-eshop-dmm', 'dmm_tab' => 'seo_general'), admin_url('admin.php')), ); } public static function admin_init() { $user = get_current_user_id(); if ($user > 0 && class_exists('\Rooster\Admin\Adapters\RoosterOne')) { \Rooster\Admin\Adapters\RoosterOne::migrate_prefs($user); } if (wp_doing_ajax() || !self::on()) { return; } $page = isset($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : ''; $tab = isset($_GET['dmm_tab']) ? sanitize_key(wp_unslash($_GET['dmm_tab'])) : ''; if ('ai-eshop-dmm' === $page && ('welcome' === $tab || (class_exists('AIEO_DMM') && AIEO_DMM::INDEX_TAB === AIEO_DMM::instance()->get_active_subtab_id()))) { wp_safe_redirect(self::home_url(), 302); exit; } } }