Initial code for New Page templating system

This commit is contained in:
Andy Dixon
2024-10-03 08:07:54 +01:00
committed by Andy Dixon
parent 7cf45e8243
commit e4246eb60d
3 changed files with 110 additions and 2 deletions
+29
View File
@@ -11,4 +11,33 @@ switch ($_REQUEST["action"]) {
die('Unable to save page');
}
break;
/**
* getTemplates AJAX call to get list of files
*/
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));
}
return 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']);
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));
break;
}