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

/cms113/cms/make-pt-from-page.php

http://cmsfromscratch.googlecode.com/
PHP | 83 lines | 46 code | 11 blank | 26 comment | 13 complexity | db4b84cdd8af37d850a15d4f0f2be5a6 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. require 'check-login.php' ;
  20. require '../cmsfns.php' ;
  21. if (!isSet($_POST['pagePath'])) {
  22. echo 'error:No page path provided.' ;
  23. exit ;
  24. }
  25. else $pagePath = getPreviewFileFromLive(pathFromID($_POST['pagePath'])) ;
  26. if (!isSet($_POST['newPTName'])) {
  27. echo 'error:No new page template name provided.' ;
  28. exit ;
  29. }
  30. else $newPTName = $_POST['newPTName'] ;
  31. // Check PT name is not already used
  32. if (file_exists(PTSDIR . '/' . $newPTName . PTEXTENSION)) {
  33. echo 'error: A page template of that name already exists.' ;
  34. exit ;
  35. }
  36. $fileContents = @file_get_contents($pagePath) ;
  37. if ($fileContents === False) {
  38. echo 'error: Could not read source page file: ' . $pagePath ;
  39. exit ;
  40. }
  41. else {
  42. $fileContents = simplifyContents($fileContents) ;
  43. }
  44. // Fixing relative path
  45. // Force $pathToRoot = '' ;
  46. //$fileContents = ereg_replace('\$pathToRoot=\'[./]*\';', '$pathToRoot=\'\';', $fileContents) ;
  47. $newPTFilePath = PTSDIR . '/' . $newPTName . PTEXTENSION ;
  48. $newPTHandle = fopen($newPTFilePath, 'w') ;
  49. if (False === fwrite($newPTHandle, 'blah blah blah' . $fileContents . 'end end end')) {
  50. fclose($newPTHandle) ;
  51. print('error:Could not save new PT file: ' . $newPTFilePath) ;
  52. exit ;
  53. }
  54. fclose($newPTHandle) ;
  55. chmod($newPTFilePath, 0644) ;
  56. // Copy preview LCIs folder to pagetemplates/newptname/
  57. $pageLCIs = getLCIRootFolderFromPagePath($pagePath) . '/cms_preview/' ;
  58. $newPTLCIs = PTSDIR . '/' . stripFileExtension(baseName($newPTName)) ;
  59. $newPTLCIsFolder = mkdir($newPTLCIs, 0755) ;
  60. chmod($newPTLCIs, 0755) ;
  61. $handle = opendir($pageLCIs) ;
  62. while (False !== ($file = readdir($handle))) {
  63. if ($file == '..' || $file == '.') continue ;
  64. copy($pageLCIs . '/' . $file, $newPTLCIs . '/' . $file) ;
  65. }
  66. // If success, return the name of the new PT!
  67. echo $newPTName ;
  68. exit ;
  69. ?>