summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/page/html/1646148842.html1
-rw-r--r--data/page/images/garfield4.pngbin0 -> 339304 bytes
-rw-r--r--index.php51
-rw-r--r--src/integration/ckeditor5/CKEditor.php65
-rw-r--r--src/integration/ckeditor5/image_upload.php6
-rw-r--r--src/integration/ckeditor5/view.php6
-rw-r--r--src/view/templates/page.php7
7 files changed, 69 insertions, 67 deletions
diff --git a/data/page/html/1646148842.html b/data/page/html/1646148842.html
new file mode 100644
index 0000000..d9ac00b
--- /dev/null
+++ b/data/page/html/1646148842.html
@@ -0,0 +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
diff --git a/data/page/images/garfield4.png b/data/page/images/garfield4.png
new file mode 100644
index 0000000..466e226
--- /dev/null
+++ b/data/page/images/garfield4.png
Binary files differ
diff --git a/index.php b/index.php
index f388081..d998d96 100644
--- a/index.php
+++ b/index.php
@@ -25,35 +25,48 @@ if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor')
25if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur 25if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur
26{ 26{
27 $ckeditor->setFrom($from); 27 $ckeditor->setFrom($from);
28 $ckeditor->setIdArticle($id_article);
29 $ckeditor->checkSubmitPOST(); 28 $ckeditor->checkSubmitPOST();
30} 29}
31 30
32/*$articles = []; 31// modèle - récupération des articles
33foreach($articles as $article) 32$articles_id = []; // noms des id en BBD ou des fichiers
34{}*/ 33$articles_content = []; // contenu HTML
35 34if($ckeditor->getStorageMode() === 'database')
36// ouvrir l'éditeur
37if(isset($_GET['action']) && $_GET['action'] === 'open_editor')
38{ 35{
39 $ckeditor->setIdArticle($id_article); 36 // => modèle
40 $editeurHTML = $ckeditor->openEditor();
41} 37}
42else // affichage article 38elseif($ckeditor->getStorageMode() === 'files')
43{ 39{
44 $ckeditor->setIdArticle('1646148841'); 40 foreach(scandir(CKEditor::DATA_PATH . '/html/') as $file_name)
45 if($ckeditor->getStorageMode() === 'database')
46 { 41 {
47 // ton code 42 if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers
43 {
44 $articles_id[] = rtrim($file_name, '.html');
45 }
48 } 46 }
49 elseif($ckeditor->getStorageMode() === 'files') 47 foreach($articles_id as $id)
50 { 48 {
51 $texte = file_get_contents($ckeditor->getDataPath() . '/html/' . $ckeditor->getIdArticle() . '.html'); 49 $texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html'));
52 //$texte = trim(addcslashes($texte, "'")); // échappe seulement les simples quotes 50 //$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien
53 $texte = trim($texte); 51
52 // ouvrir l'éditeur sur un des articles ou aucun
53 if(isset($_GET['action']) && $_GET['action'] === 'open_editor')
54 {
55 if($id === $id_article)
56 {
57 $texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript
58 $articles_content[] = $ckeditor->openEditor($id, $texte);
59 }
60 else
61 {
62 $articles_content[] = $ckeditor->displayArticle($id, $texte);
63 }
64 }
65 else // affichage article
66 {
67 $articles_content[] = $ckeditor->displayArticle($id, $texte);
68 }
54 } 69 }
55 $editeurHTML = '<div class="conteneur_article" >' . $texte . '</div>
56 <p><a href="index.php?page=' . $ckeditor->getPage() . '&action=open_editor&id=' . $ckeditor->getIdArticle() . '">ouvrir l\'éditeur</a></p>';
57} 70}
58 71
59require 'src/view/templates/page.php'; 72require 'src/view/templates/page.php';
diff --git a/src/integration/ckeditor5/CKEditor.php b/src/integration/ckeditor5/CKEditor.php
index 6f630c8..9fa0f42 100644
--- a/src/integration/ckeditor5/CKEditor.php
+++ b/src/integration/ckeditor5/CKEditor.php
@@ -4,9 +4,10 @@
4class CKEditor 4class CKEditor
5{ 5{
6 public const string INTEGRATION_PATH = 'src/integration/ckeditor5/'; 6 public const string INTEGRATION_PATH = 'src/integration/ckeditor5/';
7 7 public const string DATA_PATH = 'data/page';
8 //public const string SERVER_PATH = '/'; 8 //public const string SERVER_PATH = '/';
9 private const string SERVER_PATH = '/ckeditor5/'; 9 private const string SERVER_PATH = '/ckeditor5/';
10
10 private string $server_root; // pour les "imports" en javascript 11 private string $server_root; // pour les "imports" en javascript
11 // pour l'importmap: j'ai modifié la version "installation avec CDN de la doc pour utiliser les fichiers locaux 12 // pour l'importmap: j'ai modifié la version "installation avec CDN de la doc pour utiliser les fichiers locaux
12 // l'"importmap" permet d'utiliser "import" (ça ressemble pas mal au python) dans le navigateur comme n'importe quel langage de programmation normal 13 // l'"importmap" permet d'utiliser "import" (ça ressemble pas mal au python) dans le navigateur comme n'importe quel langage de programmation normal
@@ -14,13 +15,12 @@ class CKEditor
14 private string $storage_mode = 'files'; 15 private string $storage_mode = 'files';
15 private string $page = 'accueil'; 16 private string $page = 'accueil';
16 private string $from = ''; 17 private string $from = '';
17 private string $id_article = ''; 18 //private string $id_article = '';
18 19
19 private string $php_ini_max_size; 20 private string $php_ini_max_size;
20 private string $css_editor_tag = ''; 21 private string $css_editor_tag = '';
21 private string $css_outside_editor_tag = ''; 22 private string $css_outside_editor_tag = '';
22 private string $toolbar_language = 'fr'; 23 private string $toolbar_language = 'fr';
23 private string $data_path = 'data/page';
24 24
25 25
26 public function __construct() 26 public function __construct()
@@ -41,14 +41,6 @@ class CKEditor
41 { 41 {
42 return $this->from; 42 return $this->from;
43 } 43 }
44 public function getIdArticle(): string
45 {
46 return $this->id_article;
47 }
48 public function getDataPath(): string
49 {
50 return $this->data_path;
51 }
52 public function getCSSOutsideEditorTag(): string 44 public function getCSSOutsideEditorTag(): string
53 { 45 {
54 return $this->css_outside_editor_tag; 46 return $this->css_outside_editor_tag;
@@ -71,10 +63,6 @@ class CKEditor
71 { 63 {
72 $this->from = $from; 64 $this->from = $from;
73 } 65 }
74 public function setIdArticle(string $id_article): void
75 {
76 $this->id_article = $id_article;
77 }
78 public function setStorageMode($mode): void 66 public function setStorageMode($mode): void
79 { 67 {
80 $this->storage_mode = $mode; 68 $this->storage_mode = $mode;
@@ -87,40 +75,36 @@ class CKEditor
87 die; 75 die;
88 } 76 }
89 77
90 78 public function displayArticle(string $id, string $texte): string
91 public function checkSubmitPOST(): void
92 { 79 {
93 $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu']; 80 $html = '<div class="conteneur_article" >' . $texte . '</div>
94 81 <p><a href="index.php?page=' . $this->getPage() . '&action=open_editor&id=' . $id . '">ouvrir l\'éditeur</a></p>';
95 // enregistrement des données 82 return $html;
96 //var_dump($html_from_editor);
97 echo "ce programme n'enregistre rien, faîtes-le dans votre application et supprimer cette ligne dans index.php"; die;
98
99 header('Location: ' . $this->from);
100 die;
101 } 83 }
102 84
103 public function openEditor(): string 85 public function openEditor(string $id, string $texte): string
104 { 86 {
105 // version "minifiée" 87 // version "minifiée"
106 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />'; 88 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />';
107 // version normale aérée et commentée" 89 // version normale aérée et commentée"
108 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/ckeditor5.css" />'; 90 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/ckeditor5.css" />';
109 91
110 if($this->getStorageMode() === 'database')
111 {}
112 elseif($this->getStorageMode() === 'files')
113 {
114 $texte = file_get_contents($this->data_path . '/html/' . $this->id_article . '.html');
115
116 $texte = trim(addcslashes($texte, "'")); // échapper les simples quotes pour javascript
117 //$texte = trim(addslashes($texte)); // échappe ', ", \ et NULL, je sais pas si c'est bien
118 }
119
120 require self::INTEGRATION_PATH . 'view.php'; // html + JS 92 require self::INTEGRATION_PATH . 'view.php'; // html + JS
121 return $editeurHTML; 93 return $editeurHTML;
122 } 94 }
123 95
96 public function checkSubmitPOST(): void
97 {
98 $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu'];
99
100 // enregistrement des données
101 //var_dump($html_from_editor); // debug
102 echo "ce programme n'enregistre rien, faîtes-le dans votre application et supprimer cette ligne dans index.php"; die;
103
104 header('Location: ' . $this->from);
105 die;
106 }
107
124 /* lien symbolique des traductions 108 /* lien symbolique des traductions
125 l'éditeur recherche un dans module/ckeditor5/dist/browser/translations 109 l'éditeur recherche un dans module/ckeditor5/dist/browser/translations
126 un fichier se trouvant dans module/ckeditor5/dist/translations 110 un fichier se trouvant dans module/ckeditor5/dist/translations
@@ -171,7 +155,7 @@ class CKEditor
171 // bugs possibles sans trim() lorsqu'on insère le HTML dans l'éditeur 155 // bugs possibles sans trim() lorsqu'on insère le HTML dans l'éditeur
172 $html = trim($html); 156 $html = trim($html);
173 157
174 //checkContentInFile($html, 'avant'); 158 //$this->checkContentInFile($html, 'avant');
175 159
176 // sécurisation du HTML (faille XSS) 160 // sécurisation du HTML (faille XSS)
177 require 'vendor/htmlawed/htmlawed/htmLawed.php'; 161 require 'vendor/htmlawed/htmlawed/htmLawed.php';
@@ -188,7 +172,7 @@ class CKEditor
188 $specHtmLawed = ''; // optionnel: faire qu'un certain élément puisse n'avoir que certains attributs 172 $specHtmLawed = ''; // optionnel: faire qu'un certain élément puisse n'avoir que certains attributs
189 $html = htmLawed($html, $configHtmLawed, $specHtmLawed); 173 $html = htmLawed($html, $configHtmLawed, $specHtmLawed);
190 174
191 //checkContentInFile($html, 'après'); 175 //$this->checkContentInFile($html, 'après');
192 176
193 return $html; 177 return $html;
194 } 178 }
@@ -196,11 +180,10 @@ class CKEditor
196 180
197 private function checkContentInFile($html, $file_name): void 181 private function checkContentInFile($html, $file_name): void
198 { 182 {
199 $page = 'page';
200 $nom_fichier = $file_name . ".html"; 183 $nom_fichier = $file_name . ".html";
201 $fichier = fopen('data/' . $page . '/' . $nom_fichier, 'w'); // w peut créer un fichier, si il existe déjà, il est effacé par le nouveau contenu 184 $fichier = fopen(self::DATA_PATH . '/' . $nom_fichier, 'w'); // w peut créer un fichier, si il existe déjà, il est effacé par le nouveau contenu
202 fputs($fichier, $html); 185 fputs($fichier, $html);
203 fclose($fichier); 186 fclose($fichier);
204 chmod('data/' . $page . '/' . $nom_fichier, 0666); 187 chmod(self::DATA_PATH . '/' . $nom_fichier, 0666);
205 } 188 }
206} 189}
diff --git a/src/integration/ckeditor5/image_upload.php b/src/integration/ckeditor5/image_upload.php
index 5764569..d549690 100644
--- a/src/integration/ckeditor5/image_upload.php
+++ b/src/integration/ckeditor5/image_upload.php
@@ -19,8 +19,8 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['upload'])
19 // on prend la même liste que celle côté javascript, le SVG est bloqué pour raison de sécurité (javascript à l'intérieur) 19 // on prend la même liste que celle côté javascript, le SVG est bloqué pour raison de sécurité (javascript à l'intérieur)
20 if(in_array($extension, $extautorisées)) 20 if(in_array($extension, $extautorisées))
21 { 21 {
22 move_uploaded_file ($_FILES['upload']['tmp_name'], $this->data_path . '/images/' . $_FILES['upload']['name']); 22 move_uploaded_file ($_FILES['upload']['tmp_name'], self::DATA_PATH . '/images/' . $_FILES['upload']['name']);
23 chmod($this->data_path . '/images/' . $_FILES['upload']['name'], 0666); 23 chmod(self::DATA_PATH . '/images/' . $_FILES['upload']['name'], 0666);
24 } 24 }
25 else 25 else
26 { 26 {
@@ -39,7 +39,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['upload'])
39 39
40 if(empty($erreur)) 40 if(empty($erreur))
41 { 41 {
42 $chemin = '{"url": "' . $this->data_path . '/images/' . $_FILES['upload']['name'] . '"}'; 42 $chemin = '{"url": "' . self::DATA_PATH . '/images/' . $_FILES['upload']['name'] . '"}';
43 echo $chemin; 43 echo $chemin;
44 } 44 }
45 else 45 else
diff --git a/src/integration/ckeditor5/view.php b/src/integration/ckeditor5/view.php
index bb1f6a2..4bcad52 100644
--- a/src/integration/ckeditor5/view.php
+++ b/src/integration/ckeditor5/view.php
@@ -1,13 +1,13 @@
1<?php 1<?php
2// src/integration/ckeditor5/view.php 2// src/integration/ckeditor5/view.php
3 3
4$submit_action = 'index.php?from=' . $this->page . '&action=submit_editor&id=' . $this->id_article; 4$submit_action = 'index.php?from=' . $this->page . '&action=submit_editor&id=' . $id;
5 5
6$cancel_button = 'index.php?page=' . $this->page; 6$cancel_button = 'index.php?page=' . $this->page;
7$cancel_button .= !empty($this->id_article) ? '&id=' . $this->id_article : ''; 7//$cancel_button .= !empty($id) ? '&id=' . $id : ''; // à ajouter si on a besoin de revenir sur un article spécifique
8 8
9$upload_ajax = 'index.php?action=upload_image_editor'; 9$upload_ajax = 'index.php?action=upload_image_editor';
10$upload_ajax .= !empty($this->id_article) ? '&id=' . $this->id_article : ''; 10$upload_ajax .= !empty($id) ? '&id=' . $id : '';
11 11
12ob_start(); 12ob_start();
13?> 13?>
diff --git a/src/view/templates/page.php b/src/view/templates/page.php
index 05c7444..3ea227a 100644
--- a/src/view/templates/page.php
+++ b/src/view/templates/page.php
@@ -9,7 +9,12 @@
9</head> 9</head>
10<body> 10<body>
11 <div> 11 <div>
12 <?= $editeurHTML ?> 12<?php
13foreach ($articles_content as $article)
14{
15 echo $article;
16}
17?>
13 </div> 18 </div>
14</body> 19</body>
15</html> 20</html>