summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-01-22 23:45:52 +0100
committerpolo <ordipolo@gmx.fr>2025-01-22 23:45:52 +0100
commit4b21b40292de8ee08220ab901651a13ec5e35199 (patch)
treecf3a735e604a10e6d74c30a8c2c1323169bf463a /src
parentf1dd96bc67e497f6c07291d6e5f6f23ec243b091 (diff)
downloadckeditor5-4b21b40292de8ee08220ab901651a13ec5e35199.zip
gestion des $page, $from et $id
Diffstat (limited to 'src')
-rw-r--r--src/integration/ckeditor5/CKEditor.php101
-rw-r--r--src/integration/ckeditor5/view.php14
-rw-r--r--src/view/templates/page.php4
3 files changed, 90 insertions, 29 deletions
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 @@
1<?php 1<?php
2// src/integration/ckeditor5/CKEditor.php
3
2class CKEditor 4class CKEditor
3{ 5{
4 public const string INTEGRATION_PATH = 'src/integration/ckeditor5/'; 6 public const string INTEGRATION_PATH = 'src/integration/ckeditor5/';
5 private string $from = 'index.php';
6 public string $open_editor_link = 'index.php?action=editor';
7 private string $form_action_file = 'index.php?action=submit';
8 private string $upload_ajax_url = 'index.php?action=upload_image';
9 private string $php_ini_max_size;
10 public string $css_editor_tag = '';
11 public string $css_outside_editor_tag;
12 private string $toolbar_language = 'fr';
13 public string $storage = 'files';
14 public string $data_path = 'data/page';
15 public string $nom_article = "article";
16 7
17 private string $server_root; 8 //public const string SERVER_PATH = '/';
9 private const string SERVER_PATH = '/ckeditor5/';
10 private string $server_root; // pour les "imports" en javascript
18 // pour l'importmap: j'ai modifié la version "installation avec CDN de la doc pour utiliser les fichiers locaux 11 // pour l'importmap: j'ai modifié la version "installation avec CDN de la doc pour utiliser les fichiers locaux
19 // l'"importmap" permet d'utiliser "import" (ça ressemble pas mal au python) dans le navigateur comme n'importe quel langage de programmation normal 12 // l'"importmap" permet d'utiliser "import" (ça ressemble pas mal au python) dans le navigateur comme n'importe quel langage de programmation normal
20 13
14 private string $storage_mode = 'files';
15 private string $page = 'accueil';
16 private string $from = '';
17 private string $id_article = '';
18
19 private string $php_ini_max_size;
20 private string $css_editor_tag = '';
21 private string $css_outside_editor_tag = '';
22 private string $toolbar_language = 'fr';
23 private string $data_path = 'data/page';
24
21 25
22 public function __construct() 26 public function __construct()
23 { 27 {
24 $this->makeTranslationSymLink(); 28 $this->makeTranslationSymLink();
25 $this->from .= isset($_GET['from']) ? '?page=' . $_GET['from'] : ''; 29
26 $this->php_ini_max_size = $this->returnBytes(ini_get('upload_max_filesize')); // = 2M par défaut dans le php.ini 30 $this->php_ini_max_size = $this->returnBytes(ini_get('upload_max_filesize')); // = 2M par défaut dans le php.ini
27 $this->css_outside_editor_tag = '<link rel="stylesheet" href="' . self::INTEGRATION_PATH . 'article_hors_editeur.css" />'; 31 $this->css_outside_editor_tag = '<link rel="stylesheet" href="' . self::INTEGRATION_PATH . 'article_hors_editeur.css" />';
28 $this->server_root = $_SERVER['SERVER_NAME'] . '/ckeditor5/'; 32 $this->server_root = $_SERVER['SERVER_NAME'] . self::SERVER_PATH;
29 } 33 }
30 34
31 public function checkAjaxReqest() 35 // getters
36 public function getPage(): string
37 {
38 return $this->page;
39 }
40 public function getFrom(): string
41 {
42 return $this->from;
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
53 {
54 return $this->css_outside_editor_tag;
55 }
56 public function getCSSEditorTag(): string
57 {
58 return $this->css_editor_tag;
59 }
60 public function getStorageMode(): string
61 {
62 return $this->storage_mode;
63 }
64
65 // setters
66 public function setPage(string $page): void
67 {
68 $this->page = $page;
69 }
70 public function setFrom(string $from): void
71 {
72 $this->from = $from;
73 }
74 public function setIdArticle(string $id_article): void
75 {
76 $this->id_article = $id_article;
77 }
78 public function setStorageMode($mode): void
79 {
80 $this->storage_mode = $mode;
81 }
82
83 public function checkAjaxReqest(): void
32 { 84 {
33 // dans un fichier à part parce que trop de lignes 85 // dans un fichier à part parce que trop de lignes
34 require self::INTEGRATION_PATH . 'image_upload.php'; 86 require self::INTEGRATION_PATH . 'image_upload.php';
35 die; 87 die;
36 } 88 }
37 89
38 public function checkSubmitPOST() 90
91 public function checkSubmitPOST(): void
39 { 92 {
40 $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu']; 93 $html_from_editor = $this->getAndCleanEditorOutput($_POST["contenu"]); // manipule $_POST['contenu'];
41 94
@@ -47,18 +100,18 @@ class CKEditor
47 die; 100 die;
48 } 101 }
49 102
50 public function openEditor() 103 public function openEditor(): string
51 { 104 {
52 // version "minifiée" 105 // version "minifiée"
53 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />'; 106 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />';
54 // version normale aérée et commentée" 107 // version normale aérée et commentée"
55 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/ckeditor5.css" />'; 108 $this->css_editor_tag = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/ckeditor5.css" />';
56 109
57 if($this->storage === 'database') 110 if($this->getStorageMode() === 'database')
58 {} 111 {}
59 elseif($this->storage === 'files') 112 elseif($this->getStorageMode() === 'files')
60 { 113 {
61 $texte = file_get_contents($this->data_path . '/html/' . $this->nom_article . '.html'); 114 $texte = file_get_contents($this->data_path . '/html/' . $this->id_article . '.html');
62 115
63 $texte = trim(addcslashes($texte, "'")); // échapper les simples quotes pour javascript 116 $texte = trim(addcslashes($texte, "'")); // échapper les simples quotes pour javascript
64 //$texte = trim(addslashes($texte)); // échappe ', ", \ et NULL, je sais pas si c'est bien 117 //$texte = trim(addslashes($texte)); // échappe ', ", \ et NULL, je sais pas si c'est bien
@@ -99,9 +152,9 @@ class CKEditor
99 152
100 // conversion des 2M du php.ini en 2000000 153 // conversion des 2M du php.ini en 2000000
101 // note: les kibi, mébi et gibi sont inutiles ici 154 // note: les kibi, mébi et gibi sont inutiles ici
102 private function returnBytes($size_str) // chaine du style '2M' 155 private function returnBytes(string $size_str): int // chaine du style '2M'
103 { 156 {
104 switch (substr ($size_str, -1)) 157 switch(substr($size_str, -1))
105 { 158 {
106 case 'Ki': case 'ki': return (int)$size_str * 1024; 159 case 'Ki': case 'ki': return (int)$size_str * 1024;
107 case 'Mi': case 'mi': return (int)$size_str * 1048576; 160 case 'Mi': case 'mi': return (int)$size_str * 1048576;
@@ -109,7 +162,7 @@ class CKEditor
109 case 'K': case 'k': return (int)$size_str * 1000; 162 case 'K': case 'k': return (int)$size_str * 1000;
110 case 'M': case 'm': return (int)$size_str * 1000000; 163 case 'M': case 'm': return (int)$size_str * 1000000;
111 case 'G': case 'g': return (int)$size_str * 1000000000; 164 case 'G': case 'g': return (int)$size_str * 1000000000;
112 default: return $size_str; 165 default: return (int)$size_str;
113 } 166 }
114 } 167 }
115 168
@@ -150,4 +203,4 @@ class CKEditor
150 fclose($fichier); 203 fclose($fichier);
151 chmod('data/' . $page . '/' . $nom_fichier, 0666); 204 chmod('data/' . $page . '/' . $nom_fichier, 0666);
152 } 205 }
153} \ No newline at end of file 206}
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 @@
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;
5
6$cancel_button = 'index.php?page=' . $this->page;
7$cancel_button .= !empty($this->id_article) ? '&id=' . $this->id_article : '';
8
9$upload_ajax = 'index.php?action=upload_image_editor';
10$upload_ajax .= !empty($this->id_article) ? '&id=' . $this->id_article : '';
11
4ob_start(); 12ob_start();
5?> 13?>
6<div class="conteneur_article" > 14<div class="conteneur_article" >
7 <form action="<?= $this->form_action_file ?>" method="POST" enctype="multipart/form-data" > 15 <form action="<?= $submit_action ?>" method="POST" enctype="multipart/form-data" >
8 <textarea id="editor" name="contenu" ></textarea> 16 <textarea id="editor" name="contenu" ></textarea>
9 <input class="boutonSubmitEditeur" type="submit" value="Valider"> 17 <input class="boutonSubmitEditeur" type="submit" value="Valider">
10 <a class="boutonAnnuler" href="<?= $this->from ?>" > 18 <a class="boutonAnnuler" href="<?= $cancel_button ?>" >
11 <input type="button" value="Annuler"></a> 19 <input type="button" value="Annuler"></a>
12 <script type="importmap"> 20 <script type="importmap">
13 { 21 {
@@ -34,7 +42,7 @@ ob_start();
34 42
35 let editor; 43 let editor;
36 let html_existant = '<?= $texte ?>'; // $texte doit avoir été sécurisé: simple quotes échappées au minimum 44 let html_existant = '<?= $texte ?>'; // $texte doit avoir été sécurisé: simple quotes échappées au minimum
37 let upload_url = '<?= $this->upload_ajax_url ?>'; 45 let upload_url = '<?= $upload_ajax ?>';
38 46
39 // ATTENTION: si l'éditeur ne fonctionne pas, empêcher qu'on puisse cliquer sur Valider! 47 // ATTENTION: si l'éditeur ne fonctionne pas, empêcher qu'on puisse cliquer sur Valider!
40 // Il y a aussi des paramètres dans le fichier de config: ckeditor/webpack.config.js 48 // Il y a aussi des paramètres dans le fichier de config: ckeditor/webpack.config.js
diff --git a/src/view/templates/page.php b/src/view/templates/page.php
index 5051a5f..05c7444 100644
--- a/src/view/templates/page.php
+++ b/src/view/templates/page.php
@@ -4,8 +4,8 @@
4 <meta charset="utf-8"> 4 <meta charset="utf-8">
5 <title></title> 5 <title></title>
6 <link rel="icon" type="image/png" href=""> 6 <link rel="icon" type="image/png" href="">
7 <?= $ckeditor->css_outside_editor_tag ?> 7 <?= $ckeditor->getCSSOutsideEditorTag() ?>
8 <?= $ckeditor->css_editor_tag ?> 8 <?= $ckeditor->getCSSEditorTag() ?>
9</head> 9</head>
10<body> 10<body>
11 <div> 11 <div>