From b60ba3e1daebefb60625cb24c7406e295cf17017 Mon Sep 17 00:00:00 2001 From: Andy Dixon Date: Tue, 1 Oct 2024 20:35:16 +0100 Subject: [PATCH 1/2] Initial code for New Page templating system --- cms/controller/index.php | 29 ++++++++++++++++++ cms/index.php | 17 ++++++++++- cms/js/cms.js | 66 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 2 deletions(-) diff --git a/cms/controller/index.php b/cms/controller/index.php index 8bee8ac..7001960 100644 --- a/cms/controller/index.php +++ b/cms/controller/index.php @@ -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; } \ No newline at end of file diff --git a/cms/index.php b/cms/index.php index 94357b3..9c71951 100644 --- a/cms/index.php +++ b/cms/index.php @@ -3,7 +3,7 @@ require_once "neoCMSCore.php"; require_once "init.php"; ?> - + NeoCMS @@ -58,6 +58,21 @@ require_once "init.php"; + +
+ +
+ diff --git a/cms/js/cms.js b/cms/js/cms.js index 151aa1c..855b1f6 100644 --- a/cms/js/cms.js +++ b/cms/js/cms.js @@ -51,6 +51,7 @@ $(document).ready(function () { }); }); + // Save changes made to a div, but not save to the file on the server $('#saveBtn').click(function () { // Get the data from TinyMCE var data = tinymce.get('editor').getContent(); @@ -69,13 +70,76 @@ $(document).ready(function () { } }); + // Handle Saving changes to the page $('#savePage').click(() => { $.post("./controller/", { action: "save", uri: $('#frameContainer').contents().get(0).location.pathname, content: new XMLSerializer().serializeToString($('#frameContainer').contents().get(0)) }, function (data) { - alert(data) + // alert(data) }); }); + + // Show dialog for page templates + $("#newPage").click(function() { + loadItems(); // Call the function to load items when the modal is opened + $("#newPageDialog").dialog({ + modal: true, + width: 500, + buttons: { + Close: function() { + $(this).dialog("close"); + } + } + }); + }); + + // Handle form submission + $("#newPageForm").submit(function(event) { + event.preventDefault(); // Prevent the default form submission + + let selectedItemId = $('input[name="item"]:checked').val(); + let filename = $("#filename").val(); + + $.ajax({ + url: "/controller/?action=newPage", + method: "POST", + data: { + template: selectedItemId, + filename: filename + }, + success: function(response) { + alert('Page created successfully, I think. TODO: Check JSON response'); + $("#newPageForm").dialog("close"); // Close the modal on success + }, + error: function() { + alert('Failed to create the new page.'); + } + }); + }); + + // Function to load the items via an AJAX GET request and populate the radio buttons for page templates + function loadItems() { + $.ajax({ + url: "/controller/?action=getTemplates", + method: "GET", + success: function(data) { + let radioList = $('#radioList'); + radioList.empty(); // Clear previous content + data.forEach(function(item, index) { + radioList.append(` + + `); + }); + }, + error: function() { + alert('Failed to load templates.'); + } + }); + } + }); \ No newline at end of file -- 2.53.0 From db3f33990ea644082008f0accfb899c32ab4bee4 Mon Sep 17 00:00:00 2001 From: Andy Dixon Date: Tue, 1 Oct 2024 22:15:28 +0100 Subject: [PATCH 2/2] Add new page system implemented, and Select Page system implemented, Code tidied --- README.md | 2 + cms/controller/index.php | 49 +- cms/css/editor.css | 69 ++ cms/index.php | 17 +- cms/js/cms.js | 78 +- cms/login/index.php | 13 +- cms/templates/another-example-template.html | 26 + cms/templates/example-template.html | 26 + cms/tinymce/plugins/help/js/i18n/keynav/ar.js | 184 ++-- .../plugins/help/js/i18n/keynav/bg_BG.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/ca.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/cs.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/da.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/de.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/el.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/en.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/es.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/eu.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/fa.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/fi.js | 184 ++-- .../plugins/help/js/i18n/keynav/fr_FR.js | 184 ++-- .../plugins/help/js/i18n/keynav/he_IL.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/hi.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/hr.js | 184 ++-- .../plugins/help/js/i18n/keynav/hu_HU.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/id.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/it.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/ja.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/kk.js | 184 ++-- .../plugins/help/js/i18n/keynav/ko_KR.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/ms.js | 184 ++-- .../plugins/help/js/i18n/keynav/nb_NO.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/nl.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/pl.js | 184 ++-- .../plugins/help/js/i18n/keynav/pt_BR.js | 184 ++-- .../plugins/help/js/i18n/keynav/pt_PT.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/ro.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/ru.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/sk.js | 184 ++-- .../plugins/help/js/i18n/keynav/sl_SI.js | 184 ++-- .../plugins/help/js/i18n/keynav/sv_SE.js | 184 ++-- .../plugins/help/js/i18n/keynav/th_TH.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/tr.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/uk.js | 184 ++-- cms/tinymce/plugins/help/js/i18n/keynav/vi.js | 184 ++-- .../plugins/help/js/i18n/keynav/zh_CN.js | 172 +-- .../plugins/help/js/i18n/keynav/zh_TW.js | 184 ++-- cms/tinymce/tinymce.d.ts | 991 ++++++++++++++++-- cms/welcome.html | 12 +- 49 files changed, 4752 insertions(+), 3695 deletions(-) create mode 100644 cms/templates/another-example-template.html create mode 100644 cms/templates/example-template.html diff --git a/README.md b/README.md index 4bc7011..9984523 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # NeoCMS + ## Version 2.0 Version 2.0 is a complete rewrite to ensure we support the latest jQuery and TinyMCE GPL version. @@ -16,6 +17,7 @@ To install: * PHP 8 on Linux. None of that Windows Server crap ## Known Bugs + * Templating (New Page) not yet implemented * File (not images) uploads need to be implemented * Not completely tested diff --git a/cms/controller/index.php b/cms/controller/index.php index 7001960..6fdbc01 100644 --- a/cms/controller/index.php +++ b/cms/controller/index.php @@ -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; + } \ No newline at end of file diff --git a/cms/css/editor.css b/cms/css/editor.css index d2a479c..c5f1922 100644 --- a/cms/css/editor.css +++ b/cms/css/editor.css @@ -100,3 +100,72 @@ body { position: relative; top: 1px; } + + +/** +New Page Modal + */ + +#newPageDialog { + display: none; +} + +.newpage-content { + padding: 20px; + background-color: #fefefe; + border: 1px solid #888; + width: 400px; + margin: auto; +} + +.newpage-content form { + display: flex; + flex-direction: column; +} + +.newpage-content label { + margin-bottom: 10px; +} + +.newpage-content input[type="text"] { + margin-bottom: 20px; + padding: 5px; +} + +#newPageForm label { + display: block; +} + +/** +File List Modal + */ + +#fileListDialog { + display: none; +} + +.filelist-content { + padding: 20px; + background-color: #fefefe; + border: 1px solid #888; + width: 400px; + margin: auto; +} + +#fileList { + list-style-type: none; + padding: 0; +} + +#fileList li { + padding: 10px; + cursor: pointer; + background-color: #f0f0f0; + margin-bottom: 5px; +} + +#fileList li:hover { + background-color: #e0e0e0; +} + + diff --git a/cms/index.php b/cms/index.php index 9c71951..e37fc7c 100644 --- a/cms/index.php +++ b/cms/index.php @@ -8,11 +8,15 @@ require_once "init.php"; NeoCMS + + + + @@ -59,8 +63,8 @@ require_once "init.php"; -
-