You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.7 KiB

  1. <?php
  2. class RepositoryDir extends RepositoryBase {
  3. function timestamp () {
  4. $ts = 0;
  5. $d = opendir($this->path);
  6. while ($f = readdir($d)) {
  7. $t = filemtime("{$this->path}/{$f}");
  8. if ($t > $ts) {
  9. $ts = $t;
  10. }
  11. }
  12. closedir($d);
  13. return $ts;
  14. }
  15. function data ($options) {
  16. $data = parent::data($options);
  17. $lang = array_key_exists('lang', $options) ? $options['lang'] : 'en';
  18. if (file_exists("{$this->path}/lang/{$lang}.json")) {
  19. $data['lang'] = json_decode(file_get_contents("{$this->path}/lang/en.json"), true);
  20. $lang = json_decode(file_get_contents("{$this->path}/lang/{$options['lang']}.json"), true);
  21. foreach ($lang as $k => $v) {
  22. if ($v !== null && $v !== '') {
  23. $data['lang'][$k] = $v;
  24. }
  25. }
  26. }
  27. $d = opendir($this->path);
  28. while ($f = readdir($d)) {
  29. if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') {
  30. $d1 = json_decode(file_get_contents("{$this->path}/{$f}"), true);
  31. $d1['format'] = 'json';
  32. $d1['fileName'] = $f;
  33. if (!$this->isCategory($d1)) {
  34. continue;
  35. }
  36. $data['categories'][$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const'), array('filter'))));
  37. }
  38. if (preg_match("/^([0-9a-zA-Z_\-]+)\.yaml$/", $f, $m)) {
  39. $d1 = yaml_parse(file_get_contents("{$this->path}/{$f}"));
  40. $d1['format'] = 'yaml';
  41. $d1['fileName'] = $f;
  42. if (!$this->isCategory($d1)) {
  43. continue;
  44. }
  45. $data['categories'][$m[1]] = $d1;
  46. }
  47. if (preg_match("/^(detailsBody|popupBody).html$/", $f, $m)) {
  48. $data['templates'][$m[1]] = file_get_contents("{$this->path}/{$f}");
  49. }
  50. }
  51. closedir($d);
  52. return $data;
  53. }
  54. function access ($file) {
  55. return (substr($file, 0, 1) !== '.' && !preg_match('/\/\./', $file));
  56. }
  57. function scandir($path="") {
  58. if (substr($path, 0, 1) === '.' || preg_match("/\/\./", $path)) {
  59. return false;
  60. }
  61. if (!$this->access($path)) {
  62. return false;
  63. }
  64. return scandir("{$this->path}/{$path}");
  65. }
  66. function file_get_contents ($file) {
  67. if (substr($file, 0, 1) === '.' || preg_match("/\/\./", $file)) {
  68. return false;
  69. }
  70. if (!$this->access($file)) {
  71. return false;
  72. }
  73. if (!file_exists("{$this->path}/{$file}")) {
  74. return null;
  75. }
  76. return file_get_contents("{$this->path}/{$file}");
  77. }
  78. function file_put_contents ($file, $content) {
  79. if (substr($file, 0, 1) === '.' || preg_match("/\/\./", $file)) {
  80. return false;
  81. }
  82. if (!$this->access($file)) {
  83. return false;
  84. }
  85. return file_put_contents("{$this->path}/{$file}", $content);
  86. }
  87. }