Add new page system implemented, and Select Page system implemented, Code tidied
This commit is contained in:
+36
-13
@@ -6,9 +6,9 @@ switch ($_REQUEST["action"]) {
|
||||
case "save":
|
||||
if (!empty($_POST['uri']) && !empty($_POST['content'])) {
|
||||
$_SESSION['core']->saveContent($_POST['uri'], $_POST['content']);
|
||||
die("Page Updated.");
|
||||
echo 'Page Updated.';
|
||||
} else {
|
||||
die('Unable to save page');
|
||||
echo 'Unable to save page';
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -17,27 +17,50 @@ switch ($_REQUEST["action"]) {
|
||||
*/
|
||||
case "getTemplates":
|
||||
header('Content-type: application/json');
|
||||
$files=array_diff(scandir("../templates/"),array('..', '.'));
|
||||
$returnArray = array();
|
||||
foreach($files as $file) {
|
||||
$returnArray[]=array("id" => $file, "name" => str_replace(array(".htm",".html"), "", $file));
|
||||
$files = array_diff(scandir("../templates/"), array('..', '.'));
|
||||
$returnArray = [];
|
||||
foreach ($files as $file) {
|
||||
$returnArray[] = array("id" => $file, "name" => str_replace(array(".html", ".htm"), "", $file));
|
||||
}
|
||||
return json_encode($returnArray);
|
||||
echo json_encode($returnArray);
|
||||
break;
|
||||
|
||||
/**
|
||||
* newPage AJAX call to take a template file and create a new page
|
||||
*/
|
||||
case "newPage":
|
||||
$filename = str_replace("..","",$_POST['filename']);
|
||||
$template = str_replace("..","",$_POST['template']);
|
||||
header('Content-type: application/json');
|
||||
|
||||
if(!str_ends_with($filename, ".htm") && !str_ends_with($filename, ".html")) {
|
||||
$filename = str_replace("..", "", $_POST['filename']);
|
||||
$template = str_replace("..", "", $_POST['template']);
|
||||
if (!str_ends_with($filename, ".htm") && !str_ends_with($filename, ".html")) {
|
||||
$filename .= ".html";
|
||||
}
|
||||
|
||||
if(!file_exists("../templates/".$template)) return json_encode(array("error" => "Template not found"));
|
||||
if(!copy("../templates/".$template,"../../".$filename)) return json_encode(array("error" => "Template copy failed"));
|
||||
return json_encode(array("ok" => "DONE_THE_NEEDFUL","url"=>$filename));
|
||||
// Some vhosts can supply a trailing slash on DOCUMENT_ROOT so tidy it up
|
||||
$destination = str_replace("//", "/", $_SERVER['DOCUMENT_ROOT'] . "/" . $filename);
|
||||
|
||||
|
||||
if (!file_exists("../templates/" . $template)) die(json_encode(array("error" => "Template not found")));
|
||||
if (file_exists($destination)) die(json_encode(array("error" => "Page or file already exists")));
|
||||
|
||||
file_put_contents($destination, file_get_contents("../templates/" . $template));
|
||||
if (!file_exists($destination)) die(json_encode(array("error" => "Template copy failed")));
|
||||
echo json_encode(array("ok" => "DONE_THE_NEEDFUL", "url" => str_replace("//", "/", "/" . $filename)));
|
||||
break;
|
||||
|
||||
case "getPages":
|
||||
header('Content-type: application/json');
|
||||
$it = new RecursiveDirectoryIterator("../../");
|
||||
$returnArray = [];
|
||||
foreach (new RecursiveIteratorIterator($it) as $file) {
|
||||
// Strip document root from URI, so relative
|
||||
$file = str_replace($_SERVER["DOCUMENT_ROOT"], "", $file->getRealPath());
|
||||
|
||||
if (!str_starts_with($file, "/cms/") && (str_ends_with($file, ".html") || str_ends_with($file, ".htm")))
|
||||
$returnArray[] = array("name" => $file, "url" => $file);
|
||||
}
|
||||
echo json_encode($returnArray);
|
||||
break;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user