Jake Vanderwerf
2026-09-15 bdf344f19158a980a99dcca7c82c6e34e84533c0
inc/managers/IconsManager.php
@@ -1,6 +1,7 @@
<?php
namespace JVBase\managers;
use Exception;
use JVBase\registrar\Registrar;
use JVBase\base\Site;
@@ -486,41 +487,6 @@
      }
   }
   protected function regenerateCSS(array $sourcesToUpdate = []): void
   {
      error_log('[IconsManager]:regenerateCSS');
      $css_dir = JVB_CHILD_DIR.'/assets/css/';
      if (!file_exists($css_dir)) {
         wp_mkdir_p($css_dir);
      }
      // If no specific sources provided, regenerate all
      if (empty($sourcesToUpdate)) {
         $sourcesToUpdate = array_fill_keys(array_keys(self::$instances), true);
      }
      // Generate CSS only for sources that need it
      foreach (self::$instances as $source => $instance) {
         if (!isset($sourcesToUpdate[$source])) {
            continue; // Skip this source
         }
         $css = $instance->generateIconCSS();
         $css_path = $css_dir . $source . '.css';
         // Archive current version before overwriting
         $instance->archiveCurrentVersion($css);
         if (file_put_contents($css_path, $css) !== false) {
            Cache::for('icons_'.$source)->flush();
            error_log("[IconsManager] Updated {$source}.css");
         } else {
            error_log("[IconsManager] Could not write {$source}.css");
         }
      }
   }
   /**
    * Prevent cloning
    */
@@ -528,10 +494,11 @@
   /**
    * Prevent unserialization
    * @throws Exception
    */
   public function __wakeup()
   {
      throw new \Exception("Cannot unserialize singleton");
      throw new Exception("Cannot unserialize singleton");
   }
   /**
@@ -697,27 +664,36 @@
      foreach ($this->icons as $style => $names) {
         $styleClass = ($style !== $this->style) ? '-'.substr($style, 0, 2) : '';
         foreach ($names as $icon) {
            $svg = $this->getEncodedSVG($icon, $style);
            if ($svg !== '') {
               if ($icon === 'caret-down') {
                  $css .= 'details summary::after,';
               } elseif ($icon === 'faders-horizontal') {
                  $css .= 'details.all-filters summary::after,';
               } elseif ($icon === 'link') {
                  $css .= 'input[type=url],';
               } elseif ($icon === apply_filters('jvbSeparatorLogo', 'logo')) {
                  $css .= 'hr.logo::before,';
               }
               $css .= ".icon-{$icon}{$styleClass}{";
               $css .= "--icon:url('data:image/svg+xml;base64,{$svg}');";
               $css .= "}";
            }
            $css .= $this->generateSingleIconCss($icon, $style, $styleClass);
         }
      }
      update_option($this->timestampKey, time());
      return $this->minifyCss($css);
   }
   public function generateSingleIconCss(string $icon, ?string $style = null, ?string $styleClass = null):string
   {
      $style = $style??$this->style;
      $styleClass = $styleClass??($style !== $this->style) ? '-'.substr($style, 0, 2) : '';
      $css = '';
      $svg = $this->getEncodedSVG($icon, $style);
      if ($svg !== '') {
         if ($icon === 'caret-down') {
            $css .= 'details summary::after,';
         } elseif ($icon === 'faders-horizontal') {
            $css .= 'details.all-filters summary::after,';
         } elseif ($icon === 'link') {
            $css .= 'input[type=url],';
         } elseif ($icon === apply_filters('jvbSeparatorLogo', 'logo')) {
            $css .= 'hr.logo::before,';
         }
         $css .= ".icon-{$icon}{$styleClass}{";
         $css .= "--icon:url('data:image/svg+xml;base64,{$svg}');";
         $css .= "}";
      }
      return $css;
   }
   protected function minifyCSS(string $css): string
   {
      // Remove comments