RSSThemes.php 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class RSSThemes extends Model {
  3. private static $themes_dir = '/themes';
  4. private static $list = array();
  5. public static function init() {
  6. $basedir = PUBLIC_PATH . self::$themes_dir;
  7. $themes_list = array_diff(
  8. scandir($basedir),
  9. array('..', '.')
  10. );
  11. foreach ($themes_list as $theme_dir) {
  12. $json_filename = $basedir . '/' . $theme_dir . '/metadata.json';
  13. if(file_exists($json_filename)) {
  14. $content = file_get_contents($json_filename);
  15. $res = json_decode($content, true);
  16. if($res &&
  17. isset($res['name']) &&
  18. isset($res['author']) &&
  19. isset($res['description']) &&
  20. isset($res['version']) &&
  21. isset($res['files']) && is_array($res['files'])) {
  22. $theme = $res;
  23. $theme['path'] = $theme_dir;
  24. self::$list[$theme_dir] = $theme;
  25. }
  26. }
  27. }
  28. }
  29. public static function get() {
  30. return self::$list;
  31. }
  32. public static function get_infos($theme_id) {
  33. if (isset(self::$list[$theme_id])) {
  34. return self::$list[$theme_id];
  35. }
  36. return false;
  37. }
  38. }