From eb47b1606b86ca800706b8407725b861d5b17e03 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 21 Sep 2025 12:41:21 +0200 Subject: [PATCH] WIP comments draft and research --- app/class/Controllerpage.php | 24 +++++++++++++++++++ app/class/Routes.php | 1 + app/class/Servicepostprocess.php | 10 ++++++++ app/class/Servicerender.php | 28 ++++++++++++++++++++++ app/view/templates/alertcomment.php | 37 +++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 app/view/templates/alertcomment.php diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index eb0a779d..8bb7e4b4 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -590,6 +590,30 @@ public function update(string $page): never $this->routedirect('pageedit', ['page' => $this->page->id()]); } + public function comment(string $page): never + { + if (!isset($_POST['origin']) || !$this->pagemanager->exist($_POST['origin'])) { + $this->showtemplate('fordbidden'); + exit; + } + + if (!$this->user->isvisitor()) { + // store message in INBOX + $this->routedirect('pageread', ['page' => $_POST['origin']]); + } else { + if (isset($_POST['name'])) { + + } + + + + $this->showtemplate('alertcomment', [ + 'post' => $_POST, + ]); + } + exit; + } + /** * Permanent redirection to a page. * Send a `301` HTTP code. diff --git a/app/class/Routes.php b/app/class/Routes.php index f88a4ddc..458a0e22 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -87,6 +87,7 @@ public function match(): void ['GET', '/[cid:page]/render', 'Controllerpage#render', 'pagerender'], ['GET', '/[cid:page]/log', 'Controllerpage#log', 'pagelog'], ['GET', '/[cid:page]/download', 'Controllerpage#download', 'pagedownload'], + ['POST', '/[cid:page]/comment', 'Controllerpage#comment', 'pagecomment'], ['GET', '/[cid:page]/logout', 'Controllerpage#logout', 'pagelogout'], ['GET', '/[cid:page]/login', 'Controllerpage#login', 'pagelogin'], ['POST', '/[cid:page]/edit', 'Controllerpage#update', 'pageupdate'], diff --git a/app/class/Servicepostprocess.php b/app/class/Servicepostprocess.php index e8068262..173c3032 100644 --- a/app/class/Servicepostprocess.php +++ b/app/class/Servicepostprocess.php @@ -22,6 +22,12 @@ class Servicepostprocess public const EDIT_COUNT = '%EDITCOUNT%'; public const AFF_COUNT = '%DISPLAYCOUNT%'; + public const USER_ID = '%USERID%'; + public const USER_NAME = '%USERNAME%'; + public const USER_URL = '%USERURL%'; + + public const DISABLED = '%DISABLED%'; + public const COUNTERS = [ self::VISIT_COUNT, self::EDIT_COUNT, @@ -74,6 +80,10 @@ private function replace(string $text): string self::VISIT_COUNT => "$visitcount", self::EDIT_COUNT => "$editcount", self::AFF_COUNT => "$displaycount", + self::USER_ID => $this->user->id(), + self::USER_NAME => $this->user->name(), + self::USER_URL => $this->user->url(), + self::DISABLED => 'lol', ]; return strtr($text, $replacements); } diff --git a/app/class/Servicerender.php b/app/class/Servicerender.php index 9b92db10..a2a9c400 100644 --- a/app/class/Servicerender.php +++ b/app/class/Servicerender.php @@ -5,6 +5,7 @@ use AltoRouter; use DOMDocument; use DOMElement; +use DOMNode; use DOMNodeList; use DOMXPath; use Exception; @@ -498,6 +499,33 @@ protected function htmlparser(string $html): string } } + + $forms = $dom->getElementsByTagName('form'); + foreach ($forms as $form) { + assert($form instanceof DOMElement); + $action = $form->getAttribute('action'); + if (str_ends_with($action, '/comment')) { + $this->postprocessaction = true; + + $inputs = $form->getElementsByTagName('input'); + + foreach ($inputs as $input) { + if ($input->hasAttribute('name')) { + $input->setAttribute('value', Servicepostprocess::USER_NAME); + } + } + + + + // Add origin hidden input + $origin = $dom->createElement('input'); + $origin->setAttribute('type', 'hidden'); + $origin->setAttribute('name', 'origin'); + $origin->setAttribute('value', $this->page->id()); + $form->appendChild($origin); + } + } + // By passing the documentElement to saveHTML, special chars are not converted to entities return $dom->saveHTML($dom->documentElement); } diff --git a/app/view/templates/alertcomment.php b/app/view/templates/alertcomment.php new file mode 100644 index 00000000..0129cae8 --- /dev/null +++ b/app/view/templates/alertcomment.php @@ -0,0 +1,37 @@ +layout('alertlayout') ?> + +start('alert') ?> + + + +
+ + + + + + + + + + + + + + + +

+ +

+
+ + +stop() ?> +