Themes.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. class FreshRSS_Themes extends Minz_Model {
  3. private static $themesUrl = '/themes/';
  4. private static $defaultIconsUrl = '/themes/icons/';
  5. public static function get() {
  6. $themes_list = array_diff(
  7. scandir(PUBLIC_PATH . self::$themesUrl),
  8. array('..', '.')
  9. );
  10. $list = array();
  11. foreach ($themes_list as $theme_dir) {
  12. $theme = self::get_infos($theme_dir);
  13. if ($theme) {
  14. $list[$theme_dir] = $theme;
  15. }
  16. }
  17. return $list;
  18. }
  19. public static function get_infos($theme_id) {
  20. $theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id ;
  21. if (is_dir($theme_dir)) {
  22. $json_filename = $theme_dir . '/metadata.json';
  23. if (file_exists($json_filename)) {
  24. $content = file_get_contents($json_filename);
  25. $res = json_decode($content, true);
  26. if ($res && isset($res['files']) && is_array($res['files'])) {
  27. $res['path'] = $theme_id;
  28. return $res;
  29. }
  30. }
  31. }
  32. return false;
  33. }
  34. private static $themeIconsUrl;
  35. private static $themeIcons;
  36. public static function setThemeId($theme_id) {
  37. self::$themeIconsUrl = self::$themesUrl . $theme_id . '/icons/';
  38. self::$themeIcons = is_dir(PUBLIC_PATH . self::$themeIconsUrl) ? array_fill_keys(array_diff(
  39. scandir(PUBLIC_PATH . self::$themeIconsUrl),
  40. array('..', '.')
  41. ), 1) : array();
  42. }
  43. public static function icon($name, $urlOnly = false) {
  44. static $alts = array(
  45. 'add' => '✚',
  46. 'all' => '☰',
  47. 'bookmark' => '★',
  48. 'category' => '☷',
  49. 'category-white' => '☷',
  50. 'close' => '❌',
  51. 'configure' => '⚙',
  52. 'down' => '▽',
  53. 'favorite' => '★',
  54. 'help' => 'ⓘ',
  55. 'link' => '↗',
  56. 'login' => '🔒',
  57. 'logout' => '🔓',
  58. 'next' => '⏩',
  59. 'non-starred' => '☆',
  60. 'prev' => '⏪',
  61. 'read' => '☑',
  62. 'unread' => '☐',
  63. 'refresh' => '🔃', //↻
  64. 'search' => '🔍',
  65. 'share' => '♺',
  66. 'starred' => '★',
  67. 'tag' => '⚐',
  68. 'up' => '△',
  69. );
  70. if (!isset($alts[$name])) {
  71. return '';
  72. }
  73. $url = $name . '.svg';
  74. $url = isset(self::$themeIcons[$url]) ? (self::$themeIconsUrl . $url) :
  75. (self::$defaultIconsUrl . $url);
  76. return $urlOnly ? Minz_Url::display($url) :
  77. '<img class="icon" src="' . Minz_Url::display($url) . '" alt="' . $alts[$name] . '" />';
  78. }
  79. }