diff options
| author | git-pc-greta <ordipolo@gmx.fr> | 2025-01-30 14:52:59 +0100 |
|---|---|---|
| committer | git-pc-greta <ordipolo@gmx.fr> | 2025-01-30 14:52:59 +0100 |
| commit | 63759dbbf023daa8f7f310b914a04310a4770154 (patch) | |
| tree | 54432d8c60c3f00d3a8f9866ecd7e3089007d467 /src | |
| parent | 4b21b40292de8ee08220ab901651a13ec5e35199 (diff) | |
| download | ckeditor5-63759dbbf023daa8f7f310b914a04310a4770154.tar.gz ckeditor5-63759dbbf023daa8f7f310b914a04310a4770154.tar.bz2 ckeditor5-63759dbbf023daa8f7f310b914a04310a4770154.zip | |
foreach articles, modèle et id à l'extérieur
Diffstat (limited to 'src')
| -rw-r--r-- | src/integration/ckeditor5/CKEditor.php | 65 | ||||
| -rw-r--r-- | src/integration/ckeditor5/image_upload.php | 6 | ||||
| -rw-r--r-- | src/integration/ckeditor5/view.php | 6 | ||||
| -rw-r--r-- | src/view/templates/page.php | 7 |
4 files changed, 36 insertions, 48 deletions
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 @@ | |||
| 4 | class CKEditor | 4 | class 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 | ||
| 12 | ob_start(); | 12 | ob_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 |
| 13 | foreach ($articles_content as $article) | ||
| 14 | { | ||
| 15 | echo $article; | ||
| 16 | } | ||
| 17 | ?> | ||
| 13 | </div> | 18 | </div> |
| 14 | </body> | 19 | </body> |
| 15 | </html> | 20 | </html> |
