From 13f24b014d07ab3f28c7a8ede4f4bd6eaebbaad4 Mon Sep 17 00:00:00 2001 From: git-pc-greta Date: Mon, 3 Feb 2025 01:09:04 +0100 Subject: bouton nouvel article, file_put_contents, setLanguage() --- .gitignore | 2 + data/page/html/1646148841.html | 2 +- data/page/html/1646148842.html | 2 +- index.php | 56 +++++++++++++++------- src/integration/ckeditor5/CKEditor.php | 36 +++++++++----- src/integration/ckeditor5/article_hors_editeur.css | 4 +- src/integration/ckeditor5/view.php | 9 ++-- 7 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..022b988 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +vendor diff --git a/data/page/html/1646148841.html b/data/page/html/1646148841.html index 3f0058d..291f6d0 100644 --- a/data/page/html/1646148841.html +++ b/data/page/html/1646148841.html @@ -1 +1 @@ -
image
image

hello

okah ouibon

c'est pas

grave

on verra

plus tard

salut

goodbye

\ No newline at end of file +
image
image

hello

okokpeut-êtrebon

c'est pas

grave

on verra

plus tard

coucou

goodbye

\ No newline at end of file diff --git a/data/page/html/1646148842.html b/data/page/html/1646148842.html index d9ac00b..78264ee 100644 --- a/data/page/html/1646148842.html +++ b/data/page/html/1646148842.html @@ -1 +1 @@ -
image
image

good bye

okah ouibon

c'est pas

grave

on verra

plus tard

salut

goodbye

\ No newline at end of file +
image
image

good bye

okah ouibon

c'est super

grave

on verra

plus tard

salut

goodbye

\ No newline at end of file diff --git a/index.php b/index.php index a7815be..f33b47b 100644 --- a/index.php +++ b/index.php @@ -1,14 +1,14 @@ setLanguage('fr'); // attention, exécute une autre fonction qui peut échouer $ckeditor->setStorageMode('files'); $ckeditor->setPage($page); @@ -18,19 +18,46 @@ $ckeditor->setPage($page); // upload images AJAX if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor') { - $ckeditor->checkAjaxReqest(); + $ckeditor->checkAjaxRequest(); } // submit normal -if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur +if(isset($_GET['action']) && $_GET['action'] === 'submit_editor' && isset($_POST["contenu"])) // HTML envoyé par l'éditeur { $ckeditor->setFrom($from); - $ckeditor->checkSubmitPOST(); + $html_from_editor = $ckeditor->checkSubmitPOST(); + + if($id_article == '') // nouvel article + { + $id_article = time(); + } + + if($ckeditor->getStorageMode() === 'database') + { + // => modèle + } + elseif($ckeditor->getStorageMode() === 'files') + { + file_put_contents(CKEditor::DATA_PATH . '/html/' . $id_article . '.html', $html_from_editor); + } + + header('Location: index.php?page=' . $ckeditor->getFrom()); + die; } // modèle - récupération des articles -$articles_id = []; // noms des id en BBD ou des fichiers +$id_array = []; // noms des id en BBD ou des fichiers $articles_content = []; // contenu HTML + +if(isset($_GET['action']) && $_GET['action'] === 'open_editor' && $id_article == '') +{ + $articles_content = $ckeditor->openEditor() . "\n"; +} +else +{ + $articles_content = $ckeditor->displayNewArticleButton() . "\n"; +} + if($ckeditor->getStorageMode() === 'database') { // => modèle @@ -41,10 +68,10 @@ elseif($ckeditor->getStorageMode() === 'files') { if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers { - $articles_id[] = rtrim($file_name, '.html'); + $id_array[] = rtrim($file_name, '.html'); } } - foreach($articles_id as $id) + foreach($id_array as $id) { $texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html')); //$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien @@ -55,16 +82,16 @@ elseif($ckeditor->getStorageMode() === 'files') if($id === $id_article) { $texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript - $articles_content[] = $ckeditor->openEditor($id, $texte); + $articles_content .= $ckeditor->openEditor($id, $texte) . "\n"; } else { - $articles_content[] = $ckeditor->displayArticle($id, $texte); + $articles_content .= $ckeditor->displayArticle($id, $texte) . "\n"; } } else { - $articles_content[] = $ckeditor->displayArticle($id, $texte); + $articles_content .= $ckeditor->displayArticle($id, $texte) . "\n"; } } } @@ -81,12 +108,7 @@ elseif($ckeditor->getStorageMode() === 'files')
- +
diff --git a/src/integration/ckeditor5/CKEditor.php b/src/integration/ckeditor5/CKEditor.php index 58fa42c..e7ec181 100644 --- a/src/integration/ckeditor5/CKEditor.php +++ b/src/integration/ckeditor5/CKEditor.php @@ -17,18 +17,15 @@ class CKEditor private string $storage_mode = 'files'; private string $page = 'accueil'; private string $from = ''; - //private string $id_article = ''; private int $php_ini_max_size; private string $css_editor_tag = ''; private string $css_outside_editor_tag = ''; - private string $toolbar_language = 'fr'; + private string $toolbar_language = 'en'; public function __construct() { - $this->makeTranslationSymLink(); - $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'] . self::SERVER_PATH; @@ -70,21 +67,34 @@ class CKEditor $this->storage_mode = $mode; } - public function checkAjaxReqest(): void + public function setLanguage(string $language): void + { + $this->toolbar_language = $language; + $this->makeTranslationSymLink(); + } + + public function checkAjaxRequest(): void { // dans un fichier à part parce que trop de lignes require self::INTEGRATION_PATH . 'image_upload.php'; die; } + public function displayNewArticleButton(): string + { + $html = '
+ +
'; + return $html; + } public function displayArticle(string $id, string $texte): string { - $html = '
' . $texte . '
-

ouvrir l\'éditeur

'; + $html = '
' . $texte . '
+ '; return $html; } - public function openEditor(string $id, string $texte): string + public function openEditor(string $id = '', string $texte = ''): string { // version "minifiée" $this->css_editor_tag = ''; @@ -95,16 +105,16 @@ class CKEditor return $editeurHTML; } - public function checkSubmitPOST(): void + public function checkSubmitPOST(): string { - $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu']; + return $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu']; // enregistrement des données //var_dump($html_from_editor); // debug - echo "ce programme n'enregistre rien, faîtes-le dans votre application et supprimer cette ligne dans index.php"; die; + //echo "ce programme n'enregistre rien, faîtes-le dans votre application et supprimer cette ligne dans index.php"; die; - header('Location: ' . $this->from); - die; + /*header('Location: ' . $this->from); + die;*/ } /* lien symbolique des traductions diff --git a/src/integration/ckeditor5/article_hors_editeur.css b/src/integration/ckeditor5/article_hors_editeur.css index a38b384..622b539 100644 --- a/src/integration/ckeditor5/article_hors_editeur.css +++ b/src/integration/ckeditor5/article_hors_editeur.css @@ -1,5 +1,5 @@ -.conteneur_article{width: 630px;} -.conteneur_article:after{content: ""; display: block; clear: both;} +article{width: 630px;} +article:after{content: ""; display: block; clear: both;} img{vertical-align: bottom;} @media screen and (max-width: 1000px) diff --git a/src/integration/ckeditor5/view.php b/src/integration/ckeditor5/view.php index b6e6a5f..d80a830 100644 --- a/src/integration/ckeditor5/view.php +++ b/src/integration/ckeditor5/view.php @@ -13,12 +13,11 @@ $upload_ajax .= !empty($id) ? '&id=' . $id : ''; ob_start(); ?> -
+
- - - + +
-
+