| | |
| | | <?php |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\utility\Features; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\base\Site; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | { |
| | | $this->source = $source; |
| | | $this->cache = Cache::for('icons_' . $source, WEEK_IN_SECONDS); |
| | | $this->style = (array_key_exists('icons', JVB_SITE) && in_array(JVB_SITE['icons'], $this->styles)) |
| | | ? JVB_SITE['icons'] |
| | | : 'regular'; |
| | | $this->style = Site::icon(); |
| | | |
| | | $this->addMap(); |
| | | |
| | |
| | | // Add icons from content/taxonomy/user configs (like old behavior) |
| | | $configIcons = $this->getIconsFromConfigs(); |
| | | if (!empty($configIcons)) { |
| | | foreach ($configIcons as $source => $icons) { |
| | | if (!isset($defaults[$source])) { |
| | | $defaults[$source] = []; |
| | | } |
| | | $defaults[$source] = array_merge($defaults[$source], $icons); |
| | | } |
| | | $defaults['icons'] = array_merge($defaults['icons'], $configIcons); |
| | | } |
| | | |
| | | // Allow filtering per source (extensibility) |
| | |
| | | } |
| | | |
| | | /** |
| | | * Get icons from JVB_CONTENT, JVB_TAXONOMY, JVB_USER configs |
| | | * Get icons from Registrar instances |
| | | * |
| | | */ |
| | | protected function getIconsFromConfigs(): array |
| | | { |
| | | $icons = []; |
| | | $check = [JVB_CONTENT, JVB_TAXONOMY, JVB_USER]; |
| | | $registered = Registrar::getRegistered(); |
| | | |
| | | foreach ($check as $constant) { |
| | | foreach ($constant as $key => $value) { |
| | | if (isset($value['icon'])) { |
| | | // Determine source based on context (you could add 'icon_source' to configs) |
| | | $source = $value['icon_source'] ?? 'icons'; |
| | | |
| | | if (!isset($icons[$source])) { |
| | | $icons[$source] = []; |
| | | } |
| | | $icons[$source][] = $value['icon']; |
| | | } |
| | | } |
| | | foreach ($registered as $type) { |
| | | $registrar = Registrar::getInstance($type); |
| | | $icons[] = $registrar->getIcon(); |
| | | } |
| | | |
| | | return $icons; |
| | | |
| | | return array_unique(array_filter($icons)); |
| | | } |
| | | |
| | | /** |
| | |
| | | $map = [ |
| | | 'seo' => 'robot' |
| | | ]; |
| | | if (Features::forSite()->has('referrals')) { |
| | | if (Site::has('referrals')) { |
| | | $map['referrals'] = 'hand-heart'; |
| | | } |
| | | if (Features::forSite()->has('dashboard')) { |
| | | if (Site::has('dashboard')) { |
| | | $map['dash'] = 'door'; |
| | | } |
| | | if (Features::forSite()->has('magicLink')) { |
| | | if (Site::has('magicLink')) { |
| | | $map['magicLink'] = 'magic-wand'; |
| | | } |
| | | if (Features::hasAnyIntegration()) { |
| | | if (Site::hasAnyIntegration()) { |
| | | $map['integrations'] = 'plugs-connected'; |
| | | } |
| | | update_option(BASE.'iconMap', $map); |
| | |
| | | */ |
| | | public function get(string $name, array $options = []): string |
| | | { |
| | | if ($name === '') { |
| | | if (empty($name)) { |
| | | //No icon requested |
| | | return ''; |
| | | } |
| | |
| | | if (!$style) { |
| | | $style = $this->style; |
| | | } |
| | | |
| | | $icon = $this->map[$icon] ?? $icon; |
| | | |
| | | // Validate icon exists |
| | | if (!$this->iconExists($icon, $style)) { |
| | | error_log('[IconsManager] Icon not found: ' . $icon); |
| | | return ''; |
| | | } |
| | | $svg = $this->getEncodedSVG($icon, $style); |
| | | if ($svg !== '') { |
| | | return "data:image/svg+xml;base64,{$svg}"; |