/**
 * Strip all extensions from files, e.g. .php, .js, .html
 * 
 * @param array $filenames array of filenames or paths
 * @return array
 */
function stripAllFileExtensions($fileNames)
{
    $stripped = array();
    foreach ($fileNames as $fileName) {
        array_push($stripped, stripFileExtension($fileName));
    }
    return $stripped;
}
Example #2
0
function getLCIRootFolderFromPagePath($pagePath)
{
    // Given e.g. 	   "../userfolder/subfolder/pagename.php"
    // Needs to return "includes/userfolder/subfolder/pagename_cms_files/"
    // Note: Should also work without file extension
    if (!$pagePath) {
        return false;
    }
    // Strip off preceding ../
    $pagePath = ltrim($pagePath, './');
    // Strip off filename
    $pagePath = stripFileExtension($pagePath);
    return 'includes/' . $pagePath . '_cms_files';
}
Example #3
0
    // Show rendering set as drop-down
    $handle = opendir(STDIR);
    $itemsFound = 0;
    $newSetHTML = '';
    while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..') {
            $itemsFound++;
            if ($itemsFound == 1) {
                echo '<strong>Format using</strong>&nbsp;<select name="formattingTemplate">';
            }
            echo '<option value="' . $file . '"';
            if ($file == $inputArray[1]) {
                echo ' selected="selected"';
            }
            echo '>';
            echo stripFileExtension($file);
            if ($file == $inputArray[0]) {
                echo ' (default)';
            }
            echo '</option>';
        }
    }
    echo '</select><br /><br />';
}
?>
</div>
</form>

<div class="popup" id="newColPopup">
	<form id="newCol" onSubmit="return submitNewColDetails();">
		<div style="margin:.5em;">
function getPTChildIncludes($liveFile)
{
    // e.g. $liveFile = "pagetemplates/ptname/"
    global $xmlr;
    $lciDir = PTSDIR . '/' . stripFileExtension(substr($liveFile, strlen(PTSDIR) + 1));
    if (!is_dir($lciDir)) {
        return false;
        // Should we attempt to create folder??
    }
    $lciDirHandle = opendir($lciDir);
    while (False !== ($lciFile = readdir($lciDirHandle))) {
        if ($lciFile != '.' & $lciFile != '..' && !is_dir($lciDir . '/' . $lciFile)) {
            $xmlr .= '<lci>';
            $xmlr .= '<type>' . getFileExtension($lciFile) . '</type>';
            $xmlr .= '<filename>' . $lciFile . '</filename>';
            $xmlr .= '<filestatus>0</filestatus>';
            $xmlr .= '</lci>';
        }
    }
    closedir($lciDirHandle);
}
		*/
		#colsListBody input, #colsListBody select {
			width:7em;
		}
		#colsTable a.delete {
			margin:0;
		}
		legend button {
			margin:0 0 0 .5em;
		}
	</style>
</head>
<body>

<h1>Edit Set Template: <?php 
echo stripFileExtension($_GET['file']);
?>
</h1>
<form action="save-set-template.php" method="post">

<div style="text-align:center;">
		<button onClick="submitForm();" style="width:10em;">Save</button>
		&nbsp; &nbsp; 
		<button onClick="banish();">Cancel</button>
</div>





Example #6
0
function put($putWhat, $justReturnValue = False, $historyInc = array())
{
    global $mode, $pathToRoot, $pathToRoot2, $whereWeAre;
    $pageName = basename($_SERVER["SCRIPT_NAME"]);
    if (strpos($putWhat, '/')) {
        $putWhat = str_replace('SITEROOT/', '', $putWhat);
        $includeFileName = str_replace(array('<<', '>>'), '', $putWhat);
        // FREE INCLUDE
        if ($mode == "preview") {
            $includeFilePath = $pathToRoot . CMSDIRNAME . '/includes/' . $includeFileName;
        } else {
            $includeFilePath = $pathToRoot . $includeFileName;
        }
    } else {
        // CHILD INCLUDE
        if ($mode == 'preview') {
            $includeFilePath = $pathToRoot . CMSDIRNAME . '/includes/' . $whereWeAre . stripFileExtension(basename($_SERVER["SCRIPT_NAME"])) . '_cms_files/cms_preview/' . $putWhat;
        } else {
            $includeFilePath = $pathToRoot . CMSDIRNAME . '/includes/' . $whereWeAre . stripFileExtension(basename($_SERVER["SCRIPT_NAME"])) . '_cms_files/cms_live/' . $putWhat;
        }
    }
    // Prevent circular includes!
    if (in_array($includeFilePath, $historyInc)) {
        echo '<!-- Warning: Loop caused in includes! -->';
        return false;
    } else {
        array_push($historyInc, $includeFilePath);
    }
    /* 
    	If the file doesn't exist, try looking in the page's own directory (i.e. remove the /page_cms_files/cms_live|preview/ bit...
    */
    if (!file_exists($includeFilePath)) {
        $alternativePath = $pathToRoot . CMSDIRNAME . '/includes/' . $whereWeAre . basename($includeFilePath);
        if (file_exists($alternativePath)) {
            $includeFilePath = $alternativePath;
        }
    }
    $fileContents = @file_get_contents($includeFilePath);
    if ($fileContents !== False) {
        switch (getFileExtension($includeFilePath)) {
            case "text":
                $nestResult = nestIncludes($fileContents, $historyInc);
                $fileContents = $nestResult[0];
                $historyInc = $nestResult[1];
                if (!$justReturnValue) {
                    echo $fileContents;
                } else {
                    return $fileContents;
                }
                break;
            case "html":
                $nestResult = nestIncludes($fileContents, $historyInc);
                $fileContents = $nestResult[0];
                $historyInc = $nestResult[1];
                $fileContents = str_replace('"cmsimages/', '"' . CMSDIRNAME . '/cmsimages/', $fileContents);
                // May be redundant now?
                // $fileContents = str_replace('href="/' , 'href="' . $pathToRoot2 . '/', $fileContents) ; REDUNDANT
                $fileContents = convertSmartQuotes($fileContents);
                if (!$justReturnValue) {
                    echo $fileContents;
                } else {
                    return $fileContents;
                }
                break;
            case "set":
                if (!$justReturnValue) {
                    renderSet($fileContents, False, $historyInc);
                } else {
                    return renderSet($fileContents, True, $historyInc);
                }
                break;
            case "phpx":
                ob_start();
                include $includeFilePath;
                $contents = ob_get_contents();
                ob_end_clean();
                echo $contents;
                break;
        }
    } else {
        if ($mode == 'preview') {
            echo '<!-- Not found: ' . $includeFilePath . ' -->';
        }
    }
}
<?php

/*
* ***********************************************************************
* Copyright © Ben Hunt 2007, 2008
* 
* This file is part of cmsfromscratch.

   Cmsfromscratch is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Cmsfromscratch is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Cmsfromscratch.  If not, see <http://www.gnu.org/licenses/>.
   ***********************************************************************
*/
define("STDIR", 'settemplates');
$handle = opendir(STDIR);
while (false !== ($file = readdir($handle))) {
    if ($file != '.' && $file != '..') {
        echo '<option value="' . $file . '">' . stripFileExtension($file) . '</option>';
    }
}
?>
	
Example #8
0
        }
        if (!copy($sourceFile, $destinationFile2)) {
            echo 'error: Failed to copy PT include file: ' . $sourceFile;
            exit;
        }
        // Remove the reference from the array
        unset($ptIncludeFilesArray[$fileFound]);
    }
}
// Now, go through the array to find any files that haven't been referenced in the PT, and copy them over to both locations
if ($pt) {
    for ($filesLeft = 0; $filesLeft < sizeOf($ptIncludeFilesArray); $filesLeft++) {
        if (!strlen($ptIncludeFilesArray[$filesLeft])) {
            continue;
        }
        $sourceFile = PTSDIR . '/' . pathFromId(stripFileExtension($pt) . '/' . $ptIncludeFilesArray[$filesLeft]);
        $copiedPreview = @copy($sourceFile, $previewIncludesDirectory . $ptIncludeFilesArray[$filesLeft]);
        if (False === $copiedPreview) {
            print 'error: Failed to create new include: ' . $previewIncludesDirectory . '<<' . $ptIncludeFilesArray[$filesLeft] . '>>';
            exit;
        }
        $copiedLive = @copy($sourceFile, $liveIncludesDirectory . $ptIncludeFilesArray[$filesLeft]);
        if (False === $copiedLive) {
            print 'error: Failed to create new include: ' . $liveIncludesDirectory . '<<' . $ptIncludeFilesArray[$filesLeft] . '>>';
            exit;
        }
    }
}
// Create the actual page file...
// Duplicate! $ptContents = correctGeneralInclude($ptContents, $pathToPage) ;
$newLiveFileHandle = fopen($newLivePagePath, 'w');
    exit;
} else {
    $fileContents = simplifyContents($fileContents);
}
// Fixing relative path
// Force $pathToRoot = '' ;
//$fileContents = ereg_replace('\$pathToRoot=\'[./]*\';', '$pathToRoot=\'\';', $fileContents) ;
$newPTFilePath = PTSDIR . '/' . $newPTName . PTEXTENSION;
$newPTHandle = fopen($newPTFilePath, 'w');
if (False === fwrite($newPTHandle, 'blah blah blah' . $fileContents . 'end end end')) {
    fclose($newPTHandle);
    print 'error:Could not save new PT file: ' . $newPTFilePath;
    exit;
}
fclose($newPTHandle);
chmod($newPTFilePath, 0644);
// Copy preview LCIs folder to pagetemplates/newptname/
$pageLCIs = getLCIRootFolderFromPagePath($pagePath) . '/cms_preview/';
$newPTLCIs = PTSDIR . '/' . stripFileExtension(baseName($newPTName));
$newPTLCIsFolder = mkdir($newPTLCIs, 0755);
chmod($newPTLCIs, 0755);
$handle = opendir($pageLCIs);
while (False !== ($file = readdir($handle))) {
    if ($file == '..' || $file == '.') {
        continue;
    }
    copy($pageLCIs . '/' . $file, $newPTLCIs . '/' . $file);
}
// If success, return the name of the new PT!
echo $newPTName;
exit;
Example #10
0
if (!isset($_POST['template'])) {
    print 'error:No set template supplied';
    exit;
}
define("DIR", dirname($_POST['newfilepath']));
// Read in template
$templateArray = @unserialize(file_get_contents(STDIR . $_POST['template']));
$newArray = array();
$newArray[0] = $_POST['template'];
$newArray[1] = $newArray[0];
$newArray[2] = $templateArray['cols'];
// If it's going to belong to a PT, there's only one copy!
if (isset($_POST['parentpage'])) {
    if (isPageTemplate(pathFromID($_POST['parentpage']))) {
        // strip the .php and append a /
        $newPreviewFilePath = stripFileExtension(pathFromID($_POST['parentpage'])) . '/' . $_POST['newfilepath'] . '.set';
        $newLiveFilePath = False;
        $successReturnValue = $newPreviewFilePath;
    } else {
        $includesRoot = getLCIRootFolderFromPagePath(pathFromID($_POST['parentpage']));
        makeSureFoldersExist($includesRoot);
        $newPreviewFilePath = $includesRoot . '/cms_preview/' . $_POST['newfilepath'] . '.set';
        $newLiveFilePath = getLiveLCIFromPreview($newPreviewFilePath);
        $successReturnValue = $_POST['parentpage'] . '/' . $_POST['newfilepath'] . '.set';
        // Note: Simpler line below works in new text...
        // $returnFile = $_GET['parentpage'] . '/' . $fileName ;
    }
} else {
    // FREE INCLUDE: there are also 2 copies (i.e. parentpage not set)
    $newLiveFilePath = $newFilePath;
    // echo "debug:$newLiveFilePath" ; exit ;
    case "childinclude":
        // Make 2 copies: in includes / PATH / PAGENAME_AS_FOLDER / cmslive and .../cmspreview
        if (!isset($_GET['parentpage'])) {
            print 'error:noparentpagesupplied';
            exit;
        }
        $includesRoot = getLCIRootFolderFromPagePath(pathFromID($_GET['parentpage']));
        makeSureFoldersExist($includesRoot);
        $newPreviewFilePath = $includesRoot . '/cms_preview/' . $fileName;
        $newLiveFilePath = getLiveLCIFromPreview($newPreviewFilePath);
        // parentpage = e.g. DOTDOTSLASHpageDOTphp
        $returnFile = $_GET['parentpage'] . '/' . $fileName;
        break;
    case "ptchildinclude":
        // New text/html file belongs to a Page Template
        $newPreviewFilePath = stripFileExtension($_GET['parentpage']) . '/' . $fileName;
        $newLiveFilePath = False;
        break;
    case "freeinclude":
        $newPreviewFilePath = pathFromID($_GET['newfilepath']);
        $newLiveFilePath = getPreviewFileFromLive($newPreviewFilePath);
        break;
}
if ($newPreviewFilePath) {
    if (is_file($newPreviewFilePath)) {
        print 'error:newpreviewfilealreadyexists - ' . $newPreviewFilePath;
    }
    $createdPreview = @fopen($newPreviewFilePath, 'w');
    if (False === $createdPreview) {
        print 'error:Could not create new Preview text file.';
        fclose($createdPreview);
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Cmsfromscratch.  If not, see <http://www.gnu.org/licenses/>.
   ***********************************************************************
*/
require 'check-login.php';
require '../cmsfns.php';
if ($_SESSION['loginStatus'] < 2) {
    header('Location:index.php?message=norights');
}
if (!isset($_GET['newstname'])) {
    header('Location: set-templates.php?message=nonewstnamesupplied');
} else {
    $newSTName = stripFileExtension($_GET['newstname']);
    if (is_file(STDIR . $newSTName)) {
        header('Location: set-templates.php?message=newstexists');
        exit;
    }
    $newSTFileName = STDIR . $newSTName . STEXTENSION;
    $created = @fopen($newSTFileName, 'w+');
    if ($created) {
        // Success
        chmod($newSTFileName, 0644);
        $newST = array("cols" => array(), "before" => "", "repeat" => array(), "after" => "", "else" => "");
        fwrite($created, serialize($newST));
        fclose($created);
        header('Location: edit-set-template.php?file=' . $newSTName . STEXTENSION);
    } else {
        header('Location: set-templates.php?message=couldntcreatenewst');
    // We have a LCI. Get the live file from preview
    // Note: Use a generic function for this...!!!
    $killFile2 = str_replace('_cms_files/cms_preview/', '_cms_files/cms_live/', $killFile);
} else {
    if (isPageTemplate($killFile)) {
        // PT name is strip slash, add ".php"
        $killFile2 = false;
        $includesDir = stripFileExtension($killFile) . '/';
    } else {
        // Must be a page or Free Include, so find the corresponding Live file??? = $killFile2
        if (strstr($killFile, '../')) {
            $killFile2 = getPreviewFileFromLive($killFile);
        }
        if (getFileExtension($killFile) == "php") {
            // File is a PAGE, try to delete its local folders too
            $includesDir = stripFileExtension(getPreviewFileFromLive($killFile)) . '_cms_files';
            clearstatcache();
        }
    }
}
if (isset($includesDir) && is_dir($includesDir)) {
    if (wipeDir($includesDir)) {
        $includesDirWiped = @rmdir($includesDir);
        /* if (!$includesDirWiped) {
        				print('error:couldntwipepageincludesfolder') ;
        				exit ;
        			}*/
    }
}
/* 
	Delete the corresponding Page/FI
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Cmsfromscratch.  If not, see <http://www.gnu.org/licenses/>.
   ***********************************************************************
*/
require 'check-login.php';
require '../cmsfns.php';
if (!isset($_GET['newptname'])) {
    header('Location: page-templates.php?message=nonewptnamesupplied');
} else {
    if (is_file(PTSDIR . $_GET['newptname'])) {
        print "error:A page template of that name already exists";
        exit;
    }
    $newFilename = PTSDIR . '/' . stripFileExtension($_GET['newptname']) . PTEXTENSION;
    $created = @fopen($newFilename, 'a');
    if ($created) {
        chmod($newFilename, 0644);
        // Also try to create the PT's local folder
        $madeDir = @mkdir(PTSDIR . '/' . $_GET['newptname']);
        if (!$madeDir) {
            // Couldn't make PT's local folder
            print "error:Failed to create new local includes folder for Page Template";
        } else {
            // Success
            chmod(PTSDIR . '/' . $_GET['newptname'], 0755);
            print $newFilename;
        }
    } else {
        print "error:Failed to create new Page Template";
$newSetHTML = '';
$jsSTList = '';
while (false !== ($file = readdir($handle))) {
    if ($file != '.' && $file != '..') {
        $itemsFound++;
        if (strlen($jsSTList) > 0) {
            $jsSTList .= ',';
        }
        $jsSTList .= '"' . stripFileExtension($file) . '"';
        // Build HTML for this page
        if ($itemsFound == 1) {
            $listHTML .= '<ul class="morespace">';
        }
        $listHTML .= '<li><a title="Click to edit ' . stripFileExtension($file) . '" href="edit-set-template.php?file=' . $file . '">' . stripFileExtension($file) . '</a>';
        // $listHTML .= '<a title="Use this option to paste in code supplied from elsewhere" class="advanced-edit" href="edit-set-template-advanced.php?file=' . $file . '">paste-in</a>' ;
        $listHTML .= '<a href="javascript:deleteST(\'' . $file . '\');" class="delete" title="Delete ' . stripFileExtension($file) . '">delete</a></li>';
        // Also build new HTML for "New Set" drop-down
        if ($file != '.' && $file != '..') {
            if (strlen($newSetHTML)) {
                $newSetHTML .= ',';
            }
            $newSetHTML .= $file;
        }
    }
}
$listHTML .= '</ul>';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
}
$dir = dirname($filePath);
$ext = getFileExtension($filePath);
/* 
	If it's a SET TEMPLATE ???
*/
if (isPageTemplate($filePath)) {
    // PAGE TEMPLATE --- rename it and its LCI folder
    $newFilePath = $dir . '/' . $newFileName . '.' . $ext;
    if (False === @rename($filePath, $newFilePath)) {
        echo 'error:Failed to rename Page Template: ' . $filePath . ' >>> ' . $newFilePath;
        exit;
    }
    if ($ext == 'php') {
        $originalLCIFolder = stripFileExtension($filePath);
        $newLCIFolder = stripFileExtension($newFilePath);
        if (False === @rename($originalLCIFolder, $newLCIFolder)) {
            echo 'error:Failed to rename Page Template includes folder: ' . $originalLCIFolder . ' >>> ' . $newLCIFolder;
            exit;
        }
    }
    echo 'pt';
    exit;
} else {
    if ($ext == 'php') {
        // PAGE --- rename the page and its LCI folder, and its partner in Includes
        $newFilePath = $dir . '/' . $newFileName . '.' . $ext;
        if (False === @rename($filePath, $newFilePath)) {
            echo 'error:Failed to rename page: ' . $filePath . ' >>> ' . $newFilePath;
            exit;
        }