Initial code for New Page templating system
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user