summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgit-pc-greta <ordipolo@gmx.fr>2025-02-03 01:09:04 +0100
committergit-pc-greta <ordipolo@gmx.fr>2025-02-03 01:09:04 +0100
commit13f24b014d07ab3f28c7a8ede4f4bd6eaebbaad4 (patch)
tree1ce4a7f59f002502f7ca1e01601b63876b564f98
parent376bb178196bdea3604e230436dbabb8259ce74c (diff)
downloadckeditor5-13f24b014d07ab3f28c7a8ede4f4bd6eaebbaad4.zip
bouton nouvel article, file_put_contents, setLanguage()
-rw-r--r--.gitignore2
-rw-r--r--data/page/html/1646148841.html2
-rw-r--r--data/page/html/1646148842.html2
-rw-r--r--index.php56
-rw-r--r--src/integration/ckeditor5/CKEditor.php36
-rw-r--r--src/integration/ckeditor5/article_hors_editeur.css4
-rw-r--r--src/integration/ckeditor5/view.php9
7 files changed, 72 insertions, 39 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..022b988
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
1node_modules
2vendor
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 @@
<figure class="image image-style-side"><img src="data/page/images/chirurgien jaune.jpg" alt="image" /><figcaption>image</figcaption></figure><h2>hello</h2><figure class="table"><table><tbody><tr><td>ok</td><td>ah oui</td><td>bon</td></tr><tr><td><p>c'est pas</p><p>grave</p></td><td><p>on verra</p><p>plus tard</p></td><td>salut</td></tr></tbody></table></figure><p><i><mark class="marker-green">goodbye</mark></i></p> \ No newline at end of file <figure class="image image-style-side"><img src="data/page/images/chirurgien jaune.jpg" alt="image" /><figcaption>image</figcaption></figure><h2>hello</h2><figure class="table"><table><tbody><tr><td>okok</td><td>peut-être</td><td>bon</td></tr><tr><td><p>c'est pas</p><p>grave</p></td><td><p>on verra</p><p>plus tard</p></td><td>coucou</td></tr></tbody></table></figure><p><i><mark class="marker-green">goodbye</mark></i></p> \ 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 @@
<figure class="image image-style-side"><img src="data/page/images/garfield4.png" alt="image" /><figcaption>image</figcaption></figure><h2>good bye</h2><figure class="table"><table><tbody><tr><td>ok</td><td>ah oui</td><td>bon</td></tr><tr><td><p>c'est pas</p><p>grave</p></td><td><p>on verra</p><p>plus tard</p></td><td>salut</td></tr></tbody></table></figure><p><i><mark class="marker-green">goodbye</mark></i></p> \ No newline at end of file <figure class="image image-style-side"><img src="data/page/images/garfield4.png" alt="image" /><figcaption>image</figcaption></figure><h2>good bye</h2><figure class="table"><table><tbody><tr><td>ok</td><td>ah oui</td><td>bon</td></tr><tr><td><p>c'est super</p><p>grave</p></td><td><p>on verra</p><p>plus tard</p></td><td>salut</td></tr></tbody></table></figure><p><i><mark class="marker-green">goodbye</mark></i></p> \ 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 @@
1<?php 1<?php
2// index.php 2// index.php
3 3
4// code de l'appli principale
5$page = isset($_GET['page']) ? $_GET['page'] : 'accueil'; 4$page = isset($_GET['page']) ? $_GET['page'] : 'accueil';
6$from = isset($_GET['from']) ? $_GET['from'] : 'accueil'; // pour revenir au même endroit après un submit 5$from = isset($_GET['from']) ? $_GET['from'] : 'accueil'; // pour revenir au même endroit après un submit
7$id_article = isset($_GET['id']) ? $_GET['id'] : ''; // page pouvant avoir plusieurs articles 6$id_article = isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : '';
8 7
9 8
10require 'src/integration/ckeditor5/CKEditor.php'; 9require 'src/integration/ckeditor5/CKEditor.php';
11$ckeditor = new CKEditor(); 10$ckeditor = new CKEditor();
11$ckeditor->setLanguage('fr'); // attention, exécute une autre fonction qui peut échouer
12$ckeditor->setStorageMode('files'); 12$ckeditor->setStorageMode('files');
13$ckeditor->setPage($page); 13$ckeditor->setPage($page);
14 14
@@ -18,19 +18,46 @@ $ckeditor->setPage($page);
18// upload images AJAX 18// upload images AJAX
19if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor') 19if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor')
20{ 20{
21 $ckeditor->checkAjaxReqest(); 21 $ckeditor->checkAjaxRequest();
22} 22}
23 23
24// submit normal 24// submit normal
25if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur 25if(isset($_GET['action']) && $_GET['action'] === 'submit_editor' && isset($_POST["contenu"])) // HTML envoyé par l'éditeur
26{ 26{
27 $ckeditor->setFrom($from); 27 $ckeditor->setFrom($from);
28 $ckeditor->checkSubmitPOST(); 28 $html_from_editor = $ckeditor->checkSubmitPOST();
29
30 if($id_article == '') // nouvel article
31 {
32 $id_article = time();
33 }
34
35 if($ckeditor->getStorageMode() === 'database')
36 {
37 // => modèle
38 }
39 elseif($ckeditor->getStorageMode() === 'files')
40 {
41 file_put_contents(CKEditor::DATA_PATH . '/html/' . $id_article . '.html', $html_from_editor);
42 }
43
44 header('Location: index.php?page=' . $ckeditor->getFrom());
45 die;
29} 46}
30 47
31// modèle - récupération des articles 48// modèle - récupération des articles
32$articles_id = []; // noms des id en BBD ou des fichiers 49$id_array = []; // noms des id en BBD ou des fichiers
33$articles_content = []; // contenu HTML 50$articles_content = []; // contenu HTML
51
52if(isset($_GET['action']) && $_GET['action'] === 'open_editor' && $id_article == '')
53{
54 $articles_content = $ckeditor->openEditor() . "\n";
55}
56else
57{
58 $articles_content = $ckeditor->displayNewArticleButton() . "\n";
59}
60
34if($ckeditor->getStorageMode() === 'database') 61if($ckeditor->getStorageMode() === 'database')
35{ 62{
36 // => modèle 63 // => modèle
@@ -41,10 +68,10 @@ elseif($ckeditor->getStorageMode() === 'files')
41 { 68 {
42 if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers 69 if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers
43 { 70 {
44 $articles_id[] = rtrim($file_name, '.html'); 71 $id_array[] = rtrim($file_name, '.html');
45 } 72 }
46 } 73 }
47 foreach($articles_id as $id) 74 foreach($id_array as $id)
48 { 75 {
49 $texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html')); 76 $texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html'));
50 //$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien 77 //$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien
@@ -55,16 +82,16 @@ elseif($ckeditor->getStorageMode() === 'files')
55 if($id === $id_article) 82 if($id === $id_article)
56 { 83 {
57 $texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript 84 $texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript
58 $articles_content[] = $ckeditor->openEditor($id, $texte); 85 $articles_content .= $ckeditor->openEditor($id, $texte) . "\n";
59 } 86 }
60 else 87 else
61 { 88 {
62 $articles_content[] = $ckeditor->displayArticle($id, $texte); 89 $articles_content .= $ckeditor->displayArticle($id, $texte) . "\n";
63 } 90 }
64 } 91 }
65 else 92 else
66 { 93 {
67 $articles_content[] = $ckeditor->displayArticle($id, $texte); 94 $articles_content .= $ckeditor->displayArticle($id, $texte) . "\n";
68 } 95 }
69 } 96 }
70} 97}
@@ -81,12 +108,7 @@ elseif($ckeditor->getStorageMode() === 'files')
81</head> 108</head>
82<body> 109<body>
83 <div> 110 <div>
84<?php 111<?= $articles_content ?>
85foreach($articles_content as $article)
86{
87 echo $article;
88}
89?>
90 </div> 112 </div>
91</body> 113</body>
92</html> 114</html>
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
17 private string $storage_mode = 'files'; 17 private string $storage_mode = 'files';
18 private string $page = 'accueil'; 18 private string $page = 'accueil';
19 private string $from = ''; 19 private string $from = '';
20 //private string $id_article = '';
21 20
22 private int $php_ini_max_size; 21 private int $php_ini_max_size;
23 private string $css_editor_tag = ''; 22 private string $css_editor_tag = '';
24 private string $css_outside_editor_tag = ''; 23 private string $css_outside_editor_tag = '';
25 private string $toolbar_language = 'fr'; 24 private string $toolbar_language = 'en';
26 25
27 26
28 public function __construct() 27 public function __construct()
29 { 28 {
30 $this->makeTranslationSymLink();
31
32 $this->php_ini_max_size = $this->returnBytes(ini_get('upload_max_filesize')); // = 2M par défaut dans le php.ini 29 $this->php_ini_max_size = $this->returnBytes(ini_get('upload_max_filesize')); // = 2M par défaut dans le php.ini
33 $this->css_outside_editor_tag = '<link rel="stylesheet" href="' . self::INTEGRATION_PATH . 'article_hors_editeur.css" />'; 30 $this->css_outside_editor_tag = '<link rel="stylesheet" href="' . self::INTEGRATION_PATH . 'article_hors_editeur.css" />';
34 $this->server_root = $_SERVER['SERVER_NAME'] . self::SERVER_PATH; 31 $this->server_root = $_SERVER['SERVER_NAME'] . self::SERVER_PATH;
@@ -70,21 +67,34 @@ class CKEditor
70 $this->storage_mode = $mode; 67 $this->storage_mode = $mode;
71 } 68 }
72 69
73 public function checkAjaxReqest(): void 70 public function setLanguage(string $language): void
71 {
72 $this->toolbar_language = $language;
73 $this->makeTranslationSymLink();
74 }
75
76 public function checkAjaxRequest(): void
74 { 77 {
75 // dans un fichier à part parce que trop de lignes 78 // dans un fichier à part parce que trop de lignes
76 require self::INTEGRATION_PATH . 'image_upload.php'; 79 require self::INTEGRATION_PATH . 'image_upload.php';
77 die; 80 die;
78 } 81 }
79 82
83 public function displayNewArticleButton(): string
84 {
85 $html = '<article>
86 <a href="index.php?page=' . $this->page . '&action=open_editor"><button>Nouvel article</button></a>
87 </article>';
88 return $html;
89 }
80 public function displayArticle(string $id, string $texte): string 90 public function displayArticle(string $id, string $texte): string
81 { 91 {
82 $html = '<div class="conteneur_article" >' . $texte . '</div> 92 $html = '<article>' . $texte . '</article>
83 <p><a href="index.php?page=' . $this->getPage() . '&action=open_editor&id=' . $id . '">ouvrir l\'éditeur</a></p>'; 93 <a href="index.php?page=' . $this->page . '&action=open_editor&id=' . $id . '"><button>ouvrir l\'éditeur</button></a>';
84 return $html; 94 return $html;
85 } 95 }
86 96
87 public function openEditor(string $id, string $texte): string 97 public function openEditor(string $id = '', string $texte = ''): string
88 { 98 {
89 // version "minifiée" 99 // version "minifiée"
90 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />'; 100 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />';
@@ -95,16 +105,16 @@ class CKEditor
95 return $editeurHTML; 105 return $editeurHTML;
96 } 106 }
97 107
98 public function checkSubmitPOST(): void 108 public function checkSubmitPOST(): string
99 { 109 {
100 $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu']; 110 return $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu'];
101 111
102 // enregistrement des données 112 // enregistrement des données
103 //var_dump($html_from_editor); // debug 113 //var_dump($html_from_editor); // debug
104 echo "ce programme n'enregistre rien, faîtes-le dans votre application et supprimer cette ligne dans index.php"; die; 114 //echo "ce programme n'enregistre rien, faîtes-le dans votre application et supprimer cette ligne dans index.php"; die;
105 115
106 header('Location: ' . $this->from); 116 /*header('Location: ' . $this->from);
107 die; 117 die;*/
108 } 118 }
109 119
110 /* lien symbolique des traductions 120 /* 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 @@
1.conteneur_article{width: 630px;} 1article{width: 630px;}
2.conteneur_article:after{content: ""; display: block; clear: both;} 2article:after{content: ""; display: block; clear: both;}
3 3
4img{vertical-align: bottom;} 4img{vertical-align: bottom;}
5@media screen and (max-width: 1000px) 5@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 : '';
13 13
14ob_start(); 14ob_start();
15?> 15?>
16<div class="conteneur_article" > 16<article>
17 <form action="<?= $submit_action ?>" method="POST" enctype="multipart/form-data" > 17 <form action="<?= $submit_action ?>" method="POST" enctype="multipart/form-data" >
18 <textarea id="editor" name="contenu" ></textarea> 18 <textarea id="editor" name="contenu" ></textarea>
19 <input class="boutonSubmitEditeur" type="submit" value="Valider"> 19 <input type="submit" value="Valider">
20 <a class="boutonAnnuler" href="<?= $cancel_button ?>" > 20 <a href="<?= $cancel_button ?>" ><input type="button" value="Annuler"></a>
21 <input type="button" value="Annuler"></a>
22 <script type="importmap"> 21 <script type="importmap">
23 { 22 {
24 "imports": { 23 "imports": {
@@ -174,6 +173,6 @@ ob_start();
174 } ); 173 } );
175 </script> 174 </script>
176 </form> 175 </form>
177</div> 176</article>
178<?php 177<?php
179$editeurHTML = ob_get_clean(); 178$editeurHTML = ob_get_clean();