PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/cms113/cms/get-file-details.php

http://cmsfromscratch.googlecode.com/
PHP | 127 lines | 69 code | 12 blank | 46 comment | 18 complexity | 87b49b3a8064f791c81f13ce011851bf 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. /*
  20. All files:
  21. - Return match status
  22. If file is a page:
  23. - Return list of local child includes, with status code for each LCI
  24. Note: LIVE is the master collection...
  25. */
  26. header("Content-type: text/xml") ;
  27. require "../cmsfns.php" ;
  28. // DEBUG echo $_GET['file'] ; exit ;
  29. if (!isset($_GET['file'])) {
  30. echo 'error:No file name provided.' ;
  31. exit ;
  32. }
  33. /*
  34. Get details of file itself (Page/FI)
  35. */
  36. $matchStatus = false ;
  37. $liveFile = pathFromID($_GET['file']) ;
  38. /*
  39. If $liveFile starts with "pagetemplates/"... it's a PT
  40. In which case, get the LCIs from pagetemplates/ptname/
  41. */
  42. // echo 'error:' . $isPT ; exit ;
  43. if (isPageTemplate($liveFile)) {
  44. $xmlr = '<xml>' ;
  45. $xmlr .= '<file>' . $_GET['file'] . '</file>' ;
  46. $xmlr .= '<filestatus>0</filestatus>' ;
  47. getPTChildIncludes($liveFile) ;
  48. }
  49. else {
  50. $previewFile = getPreviewFileFromLive($liveFile) ;
  51. $matchStatus = matchFiles($previewFile,$liveFile) ;
  52. $xmlr = '<xml>' ;
  53. $xmlr .= '<file>' . $_GET['file'] . '</file>' ;
  54. $xmlr .= '<filestatus>' . $matchStatus . '</filestatus>' ;
  55. /*
  56. If it's a page, we need details on all LCIs
  57. */
  58. if (getFileExtension($liveFile) == "php") {
  59. $xmlr .= '<localchildincludes>' ;
  60. getChildIncludes($liveFile) ;
  61. $xmlr .= '</localchildincludes>' ;
  62. }
  63. }
  64. $xmlr .= "</xml>" ;
  65. print $xmlr ;
  66. exit ;
  67. /*
  68. Functions
  69. */
  70. function getChildIncludes($liveFile) {
  71. global $xmlr ;
  72. $localRootDir = getLCIRootFolderFromPagePath($liveFile) ;
  73. $localPreviewDir = $localRootDir . '/cms_preview' ;
  74. $localLiveDir = $localRootDir . '/cms_live' ;
  75. if (!is_dir($localPreviewDir) || !is_dir($localLiveDir)) {
  76. return false ;
  77. }
  78. $localPreviewDirHandle = opendir($localPreviewDir) ;
  79. while (False !== ($lciFile = readdir($localPreviewDirHandle))) {
  80. if ($lciFile != '.' & $lciFile != '..' && !is_dir($localPreviewDir . '/' . $lciFile)) {
  81. $xmlr .= '<lci>' ;
  82. $xmlr .= '<type>' . getFileExtension($lciFile) . '</type>' ;
  83. $xmlr .= '<filename>' . $lciFile . '</filename>' ;
  84. $xmlr .= '<filestatus>' . matchFiles($localPreviewDir . '/' . $lciFile, getLiveLCIFromPreview($localPreviewDir . '/' . $lciFile)) . '</filestatus>' ;
  85. $xmlr .= '</lci>' ;
  86. }
  87. }
  88. closedir($localPreviewDirHandle) ;
  89. }
  90. function getPTChildIncludes($liveFile) {
  91. // e.g. $liveFile = "pagetemplates/ptname/"
  92. global $xmlr ;
  93. $lciDir = PTSDIR . '/' .stripFileExtension(substr($liveFile, strlen(PTSDIR)+1)) ;
  94. if (!is_dir($lciDir)) {
  95. return false ;
  96. // Should we attempt to create folder??
  97. }
  98. $lciDirHandle = opendir($lciDir) ;
  99. while (False !== ($lciFile = readdir($lciDirHandle))) {
  100. if ($lciFile != '.' & $lciFile != '..' && !is_dir($lciDir . '/' . $lciFile)) {
  101. $xmlr .= '<lci>' ;
  102. $xmlr .= '<type>' . getFileExtension($lciFile) . '</type>' ;
  103. $xmlr .= '<filename>' . $lciFile . '</filename>' ;
  104. $xmlr .= '<filestatus>0</filestatus>' ;
  105. $xmlr .= '</lci>' ;
  106. }
  107. }
  108. closedir($lciDirHandle) ;
  109. }
  110. ?>