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.

92 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. $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. if (!$this->isCategory($d1)) {
  32. continue;
  33. }
  34. $data['categories'][$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const'), array('filter'))));
  35. }
  36. if (preg_match("/^(detailsBody|popupBody).html$/", $f, $m)) {
  37. $data['templates'][$m[1]] = file_get_contents("{$this->path}/{$f}");
  38. }
  39. }
  40. closedir($d);
  41. return $data;
  42. }
  43. function access ($file) {
  44. return (substr($file, 0, 1) !== '.' && !preg_match('/\/\./', $file));
  45. }
  46. function scandir($path="") {
  47. if (substr($path, 0, 1) === '.' || preg_match("/\/\./", $path)) {
  48. return false;
  49. }
  50. if (!$this->access($path)) {
  51. return false;
  52. }
  53. return scandir("{$this->path}/{$path}");
  54. }
  55. function file_get_contents ($file) {
  56. if (substr($file, 0, 1) === '.' || preg_match("/\/\./", $file)) {
  57. return null;
  58. }
  59. if (!$this->access($file)) {
  60. return false;
  61. }
  62. return file_get_contents("{$this->path}/{$file}");
  63. }
  64. function file_put_contents ($file, $content) {
  65. if (substr($file, 0, 1) === '.' || preg_match("/\/\./", $file)) {
  66. return false;
  67. }
  68. if (!$this->access($file)) {
  69. return false;
  70. }
  71. return file_put_contents("{$this->path}/{$file}", $content);
  72. }
  73. }