From 4b21b40292de8ee08220ab901651a13ec5e35199 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 22 Jan 2025 23:45:52 +0100 Subject: gestion des $page, $from et $id --- src/integration/ckeditor5/CKEditor.php | 101 +++++++++++++++++++++++++-------- src/integration/ckeditor5/view.php | 14 ++++- src/view/templates/page.php | 4 +- 3 files changed, 90 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/integration/ckeditor5/CKEditor.php b/src/integration/ckeditor5/CKEditor.php index f3a60e0..6f630c8 100644 --- a/src/integration/ckeditor5/CKEditor.php +++ b/src/integration/ckeditor5/CKEditor.php @@ -1,41 +1,94 @@ makeTranslationSymLink(); - $this->from .= isset($_GET['from']) ? '?page=' . $_GET['from'] : ''; + $this->php_ini_max_size = $this->returnBytes(ini_get('upload_max_filesize')); // = 2M par défaut dans le php.ini $this->css_outside_editor_tag = ''; - $this->server_root = $_SERVER['SERVER_NAME'] . '/ckeditor5/'; + $this->server_root = $_SERVER['SERVER_NAME'] . self::SERVER_PATH; } - public function checkAjaxReqest() + // getters + public function getPage(): string + { + return $this->page; + } + public function getFrom(): string + { + return $this->from; + } + public function getIdArticle(): string + { + return $this->id_article; + } + public function getDataPath(): string + { + return $this->data_path; + } + public function getCSSOutsideEditorTag(): string + { + return $this->css_outside_editor_tag; + } + public function getCSSEditorTag(): string + { + return $this->css_editor_tag; + } + public function getStorageMode(): string + { + return $this->storage_mode; + } + + // setters + public function setPage(string $page): void + { + $this->page = $page; + } + public function setFrom(string $from): void + { + $this->from = $from; + } + public function setIdArticle(string $id_article): void + { + $this->id_article = $id_article; + } + public function setStorageMode($mode): void + { + $this->storage_mode = $mode; + } + + public function checkAjaxReqest(): void { // dans un fichier à part parce que trop de lignes require self::INTEGRATION_PATH . 'image_upload.php'; die; } - public function checkSubmitPOST() + + public function checkSubmitPOST(): void { $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu']; @@ -47,18 +100,18 @@ class CKEditor die; } - public function openEditor() + public function openEditor(): string { // version "minifiée" $this->css_editor_tag = ''; // version normale aérée et commentée" $this->css_editor_tag = ''; - if($this->storage === 'database') + if($this->getStorageMode() === 'database') {} - elseif($this->storage === 'files') + elseif($this->getStorageMode() === 'files') { - $texte = file_get_contents($this->data_path . '/html/' . $this->nom_article . '.html'); + $texte = file_get_contents($this->data_path . '/html/' . $this->id_article . '.html'); $texte = trim(addcslashes($texte, "'")); // échapper les simples quotes pour javascript //$texte = trim(addslashes($texte)); // échappe ', ", \ et NULL, je sais pas si c'est bien @@ -99,9 +152,9 @@ class CKEditor // conversion des 2M du php.ini en 2000000 // note: les kibi, mébi et gibi sont inutiles ici - private function returnBytes($size_str) // chaine du style '2M' + private function returnBytes(string $size_str): int // chaine du style '2M' { - switch (substr ($size_str, -1)) + switch(substr($size_str, -1)) { case 'Ki': case 'ki': return (int)$size_str * 1024; case 'Mi': case 'mi': return (int)$size_str * 1048576; @@ -109,7 +162,7 @@ class CKEditor case 'K': case 'k': return (int)$size_str * 1000; case 'M': case 'm': return (int)$size_str * 1000000; case 'G': case 'g': return (int)$size_str * 1000000000; - default: return $size_str; + default: return (int)$size_str; } } @@ -150,4 +203,4 @@ class CKEditor fclose($fichier); chmod('data/' . $page . '/' . $nom_fichier, 0666); } -} \ No newline at end of file +} diff --git a/src/integration/ckeditor5/view.php b/src/integration/ckeditor5/view.php index ed1d0f7..bb1f6a2 100644 --- a/src/integration/ckeditor5/view.php +++ b/src/integration/ckeditor5/view.php @@ -1,13 +1,21 @@ page . '&action=submit_editor&id=' . $this->id_article; + +$cancel_button = 'index.php?page=' . $this->page; +$cancel_button .= !empty($this->id_article) ? '&id=' . $this->id_article : ''; + +$upload_ajax = 'index.php?action=upload_image_editor'; +$upload_ajax .= !empty($this->id_article) ? '&id=' . $this->id_article : ''; + ob_start(); ?>
-
+ - +