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.

90 lines
2.2 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. $d = opendir($this->path);
  18. while ($f = readdir($d)) {
  19. if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') {
  20. $d1 = json_decode(file_get_contents("{$this->path}/{$f}"), true);
  21. if (!$this->isCategory($d1)) {
  22. continue;
  23. }
  24. $data['categories'][$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const'))));
  25. }
  26. if (preg_match("/^(detailsBody|popupBody).html$/", $f, $m)) {
  27. $data['templates'][$m[1]] = file_get_contents("{$this->path}/{$f}");
  28. }
  29. }
  30. closedir($d);
  31. if (array_key_exists('lang', $options) && file_exists("{$this->path}/lang/{$options['lang']}.json")) {
  32. $data['lang'] = json_decode(file_get_contents("{$this->path}/lang/en.json"), true);
  33. $lang = json_decode(file_get_contents("{$this->path}/lang/{$options['lang']}.json"), true);
  34. foreach ($lang as $k => $v) {
  35. if ($v !== null && $v !== '') {
  36. $data['lang'][$k] = $v;
  37. }
  38. }
  39. }
  40. return $data;
  41. }
  42. function access ($file) {
  43. return (substr($file, 0, 1) !== '.' && !preg_match('/\/\./', $file));
  44. }
  45. function scandir($path="") {
  46. if (substr($path, 0, 1) === '.' || preg_match("/\/\./", $path)) {
  47. return false;
  48. }
  49. if (!$this->access($path)) {
  50. return false;
  51. }
  52. return scandir("{$this->path}/{$path}");
  53. }
  54. function file_get_contents ($file) {
  55. if (substr($file, 0, 1) === '.' || preg_match("/\/\./", $file)) {
  56. return null;
  57. }
  58. if (!$this->access($file)) {
  59. return false;
  60. }
  61. return file_get_contents("{$this->path}/{$file}");
  62. }
  63. function file_put_contents ($file, $content) {
  64. if (substr($file, 0, 1) === '.' || preg_match("/\/\./", $file)) {
  65. return false;
  66. }
  67. if (!$this->access($file)) {
  68. return false;
  69. }
  70. return file_put_contents("{$this->path}/{$file}", $content);
  71. }
  72. }