Theme.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\common\library;
  3. class Theme
  4. {
  5. private static $config = [];
  6. public static function get()
  7. {
  8. if (empty(self::$config)) {
  9. $config = (array)json_decode(file_get_contents(self::getConfigFile()), true);
  10. self::$config = $config;
  11. }
  12. return self::$config;
  13. }
  14. public static function set($config, $overwrite = false)
  15. {
  16. self::$config = $overwrite ? $config : array_merge(self::$config, $config);
  17. file_put_contents(self::getConfigFile(), json_encode(self::$config, JSON_UNESCAPED_UNICODE));
  18. return self::$config;
  19. }
  20. public static function render($config)
  21. {
  22. if (isset($config['tabbar']['list']) && is_array($config['tabbar']['list'])) {
  23. $url = url('/', '', false, true);
  24. $url = preg_replace("/\/([\w]+)\.php\//i", "/", $url);
  25. $url = rtrim($url, "/");
  26. foreach ($config['tabbar']['list'] as $index => &$item) {
  27. $item['image'] = preg_match("/^\/assets\/addons/", $item['image']) ? $url . $item['image'] : cdnurl($item['image'], true);
  28. $item['selectedImage'] = preg_match("/^\/assets\/addons/", $item['selectedImage']) ? $url . $item['selectedImage'] : cdnurl($item['selectedImage'], true);
  29. }
  30. }
  31. return $config;
  32. }
  33. public static function getConfigFile()
  34. {
  35. return ADDON_PATH . 'shop' . DS . 'data' . DS . 'theme.json';
  36. }
  37. }