PageRenderTime 66ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/cms113/cms/read-dir.php

http://cmsfromscratch.googlecode.com/
PHP | 116 lines | 78 code | 11 blank | 27 comment | 29 complexity | 8955be466ed301f62c4633dda6b3428d MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?
  2. /*
  3. * ***********************************************************************
  4. * Copyright Š Ben Hunt 2007, 2008
  5. *
  6. * This file is part of cmsfromscratch.
  7. Cmsfromscratch is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. Cmsfromscratch is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with Cmsfromscratch. If not, see <http://www.gnu.org/licenses/>.
  17. ***********************************************************************
  18. */
  19. header("Content-type: text/xml") ;
  20. require 'check-login.php' ;
  21. require '../cmsfns.php' ;
  22. if (!isset($_GET['dir'])) exit ;
  23. // Strip off trailing slash if one exists
  24. define ("DIR", rtrim($_GET['dir'],'/')) ;
  25. $xmlr = '<xml>' ;
  26. $xmlr .= '<parentdir>' . DIR . '</parentdir>' ;
  27. $handle = opendir(pathFromID(DIR)) ;
  28. $arrDirs = array() ;
  29. $arrFiles = array() ;
  30. while (false !== ($file = readdir($handle))) {
  31. if (!in_array($file,$reserved_filenames) && !in_array(DIR.'/'.$file, $reserved_filenames)) {
  32. if (is_dir(DIR.'/'.$file)) {
  33. // Directory
  34. if ($_SESSION['loginStatus'] < 2 && DIR.'/'.$file == '../private') continue ;
  35. array_push($arrDirs, $file) ;
  36. }
  37. else {
  38. array_push($arrFiles, $file) ;
  39. }
  40. }
  41. }
  42. // Sort the 2 arrays and write contents to XML response
  43. asort($arrDirs) ;
  44. asort($arrFiles) ;
  45. foreach ($arrDirs as $arrDir) {
  46. if (
  47. (isSet($_SESSION['showNonCMSFiles']) && $_SESSION['showNonCMSFiles'] == 'yes')
  48. ||
  49. (
  50. is_dir(getPreviewFileFromLive(DIR . '/' . $arrDir))
  51. && $arrDir != '.'
  52. && $arrDir != '..'
  53. && False == stristr($arrDir, ".gif,,$reserved_filenames")
  54. )
  55. )
  56. {
  57. $xmlr .= "<dir>$arrDir</dir>" ;
  58. }
  59. }
  60. foreach ($arrFiles as $arrFile) {
  61. $previewFile = getPreviewFileFromLive(DIR.'/'.$arrFile) ;
  62. if (
  63. strstr($arrFile, 'phpthumb')
  64. || strstr($arrFile, 'phpThumb')
  65. // || False === file_exists($previewFile)
  66. )
  67. {
  68. continue ;
  69. }
  70. $liveFile = DIR.'/'.$arrFile ;
  71. if (file_exists($liveFile)) {
  72. if (False === file_exists($previewFile)) {
  73. $filesMatch = 'liveonly' ;
  74. }
  75. else {
  76. $filesMatch = (md5_file($previewFile) == md5_file($liveFile)) ? 'match' : 'dontmatch' ;
  77. }
  78. }
  79. else if (file_exists($previewFile)) {
  80. $filesMatch = 'previewonly' ;
  81. }
  82. /*
  83. Get the preview version - do the versions match?
  84. */
  85. if (getFileExtension($arrFile) == "php") {
  86. $xmlr .= '<page><name>' ;
  87. $xmlr .= $arrFile ;
  88. $xmlr .= '</name><match>' ;
  89. $xmlr .= $filesMatch ;
  90. $xmlr .= '</match></page>' ;
  91. }
  92. else {
  93. $xmlr .= '<file><name>' ;
  94. $xmlr .= $arrFile ;
  95. $xmlr .= '</name><match>' ;
  96. $xmlr .= $filesMatch ;
  97. $xmlr .= '</match></file>' ;
  98. }
  99. }
  100. $xmlr .= "</xml>" ;
  101. print $xmlr ;
  102. ?>