FoldersConfig.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class FoldersConfig {
  3. public static function getNfsOsPath() {
  4. if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac')) {
  5. return 'afp:';
  6. }
  7. return 'file:';
  8. }
  9. public static function getRawData() {
  10. static $_data;
  11. if (!is_array($_data)) {
  12. $_data = array();
  13. $_data = Config::getConfFile('folders');
  14. }
  15. return $_data;
  16. }
  17. public static function getRootPoints() {
  18. $data = self::getRawData();
  19. $rootData = V::get('root_points', null, $data);
  20. if (!$rootData) {
  21. error_log('Error: Brak konfiguracji FOLDERS! (root_points)');
  22. die('Error: Brak konfiguracji FOLDERS! (root_points)');
  23. }
  24. return $rootData;
  25. }
  26. public static function getRootPoint($key) {
  27. $data = self::getRawData();
  28. $rootData = V::get('root_points', null, $data);
  29. if (!$rootData) {
  30. error_log('Error: Brak konfiguracji FOLDERS! (root_point)');
  31. die('Error: Brak konfiguracji FOLDERS! (root_point)');
  32. }
  33. $rootValue = V::get($key, '', $rootData);
  34. return $rootValue;
  35. }
  36. public static function get($col_name, $key) {
  37. $retValue = array();
  38. $data = self::getRawData();
  39. $colData = V::get($col_name, null, $data);
  40. if (!$colData) {
  41. error_log('Error: Brak konfiguracji FOLDERS! ('.$col_name.')');
  42. die('Error: Brak konfiguracji FOLDERS! ('.$col_name.')');
  43. }
  44. $retValue = V::get($key, '', $colData);
  45. if (substr($key, -6) == '_point') {
  46. $rootData = V::get('root_points', null, $data);
  47. if (!$rootData) {
  48. error_log('Error: Brak konfiguracji FOLDERS! (root_points)');
  49. die('Error: Brak konfiguracji FOLDERS! (root_points)');
  50. }
  51. if (substr($retValue, 0, 1) != '/') {// relative path
  52. $rootValue = V::get($key, '', $rootData);
  53. if (!empty($rootValue)) {
  54. $retValue = rtrim($rootValue, '/') . '/' . ltrim($retValue, '/');
  55. }
  56. }
  57. }
  58. return $retValue;
  59. }
  60. public static function hasConfig($col_name) {
  61. $data = self::getRawData();
  62. $colData = V::get($col_name, null, $data);
  63. if (!$colData) {
  64. return false;
  65. }
  66. return true;
  67. }
  68. public static function getAll($col_name) {
  69. $colData = array();
  70. $data = self::getRawData();
  71. $colData = V::get($col_name, null, $data);
  72. if (!$colData) {
  73. error_log('Error: Brak konfiguracji FOLDERS! ('.$col_name.')');
  74. die('Error: Brak konfiguracji FOLDERS! ('.$col_name.')');
  75. }
  76. $rootData = V::get('root_points', null, $data);
  77. if (!$rootData) {
  78. die('Error: Brak konfiguracji FOLDERS! (root_points)');
  79. }
  80. foreach ($rootData as $key => $val) {
  81. if (array_key_exists($key, $colData)) {
  82. if (substr($colData[$key], 0, 1) != '/') {// relative path
  83. if (!empty($val)) {
  84. $colData[$key] = rtrim($val, '/') . '/' . ltrim($colData[$key], '/');
  85. }
  86. }
  87. }
  88. }
  89. return $colData;
  90. }
  91. }