diff options
| author | polo <ordipolo@gmx.fr> | 2025-01-13 00:44:49 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-01-13 00:44:49 +0100 |
| commit | e9a5da044f63851aa37d401ef37c8102b08ae274 (patch) | |
| tree | 12ebf8a0aefd7a63d6d7dcbe4ad7d74e6ee3bb92 | |
| parent | 0023ec83932beddb0f1c604f3c210189113c9b7a (diff) | |
| download | ckeditor5-e9a5da044f63851aa37d401ef37c8102b08ae274.tar.gz ckeditor5-e9a5da044f63851aa37d401ef37c8102b08ae274.tar.bz2 ckeditor5-e9a5da044f63851aa37d401ef37c8102b08ae274.zip | |
chemins changés, dossier integration
| -rw-r--r-- | index.php | 36 | ||||
| -rw-r--r-- | lib/ckeditor5/create.php | 16 | ||||
| -rw-r--r-- | src/integration/ckeditor5/article_hors_editeur.css (renamed from lib/ckeditor5/article_hors_editeur.css) | 0 | ||||
| -rw-r--r-- | src/integration/ckeditor5/clean_html.php (renamed from lib/ckeditor5/clean_html.php) | 34 | ||||
| -rw-r--r-- | src/integration/ckeditor5/config.php (renamed from config.php) | 5 | ||||
| -rw-r--r-- | src/integration/ckeditor5/create.php | 18 | ||||
| -rw-r--r-- | src/integration/ckeditor5/image_upload.php (renamed from lib/ckeditor5/image_upload.php) | 8 | ||||
| -rw-r--r-- | src/integration/ckeditor5/init.php | 13 | ||||
| -rw-r--r-- | src/integration/ckeditor5/view.php (renamed from lib/ckeditor5/view.php) | 2 | ||||
| -rw-r--r-- | src/view/templates/page.php (renamed from src/templates/page.php) | 2 |
10 files changed, 72 insertions, 62 deletions
| @@ -1,25 +1,23 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // index.php | 2 | // index.php |
| 3 | // | ||
| 4 | // routeur | ||
| 5 | 3 | ||
| 6 | require 'config.php'; | 4 | require 'src/integration/ckeditor5/config.php'; |
| 5 | require 'src/integration/ckeditor5/init.php'; | ||
| 6 | makeTranslationSymLink(); | ||
| 7 | 7 | ||
| 8 | // lien symbolique des "translations" | ||
| 9 | $target = '../translations'; | ||
| 10 | $link = 'node_modules/ckeditor5/dist/browser/translations'; | ||
| 11 | if (!file_exists($link)) | ||
| 12 | { | ||
| 13 | symlink($target, $link); | ||
| 14 | } | ||
| 15 | 8 | ||
| 9 | // routage | ||
| 10 | |||
| 11 | // upload images AJAX | ||
| 16 | if(isset($_GET['action']) && $_GET['action'] === 'upload_image') // image insérée dans l'éditeur => requête AJAX | 12 | if(isset($_GET['action']) && $_GET['action'] === 'upload_image') // image insérée dans l'éditeur => requête AJAX |
| 17 | { | 13 | { |
| 18 | require 'lib/ckeditor5/image_upload.php'; | 14 | require $ckeditor_integration_path . 'image_upload.php'; |
| 19 | } | 15 | } |
| 16 | |||
| 17 | // submit normal | ||
| 20 | elseif(isset($_GET['action']) && $_GET['action'] === 'submit') // HTML envoyé par l'éditeur | 18 | elseif(isset($_GET['action']) && $_GET['action'] === 'submit') // HTML envoyé par l'éditeur |
| 21 | { | 19 | { |
| 22 | require 'lib/ckeditor5/clean_html.php'; | 20 | require $ckeditor_integration_path . 'clean_html.php'; |
| 23 | $html_from_editor = getAndCleanEditorOutput(); // manipule $_POST['contenu']; | 21 | $html_from_editor = getAndCleanEditorOutput(); // manipule $_POST['contenu']; |
| 24 | 22 | ||
| 25 | // enregistrement des données | 23 | // enregistrement des données |
| @@ -29,9 +27,11 @@ elseif(isset($_GET['action']) && $_GET['action'] === 'submit') // HTML envoyé p | |||
| 29 | header('Location: ' . $previous_page); | 27 | header('Location: ' . $previous_page); |
| 30 | die; | 28 | die; |
| 31 | } | 29 | } |
| 32 | elseif(isset($_GET['page']) && $_GET['page'] === 'editor') // ouvrir l'éditeur | 30 | |
| 31 | // ouvrir l'éditeur | ||
| 32 | elseif(isset($_GET['page']) && $_GET['page'] === 'editor') | ||
| 33 | { | 33 | { |
| 34 | require 'lib/ckeditor5/create.php'; | 34 | require $ckeditor_integration_path . 'create.php'; |
| 35 | } | 35 | } |
| 36 | else // $previous_page, affichage sans l'article | 36 | else // $previous_page, affichage sans l'article |
| 37 | { | 37 | { |
| @@ -43,8 +43,8 @@ else // $previous_page, affichage sans l'article | |||
| 43 | elseif($storage === 'files') | 43 | elseif($storage === 'files') |
| 44 | { | 44 | { |
| 45 | $texte = file_get_contents('data/' . $page . '/html/' . $nom_article . '.html'); | 45 | $texte = file_get_contents('data/' . $page . '/html/' . $nom_article . '.html'); |
| 46 | $texte = trim(addcslashes($texte, "'")); // échappe seulement les simples quotes | 46 | //$texte = trim(addcslashes($texte, "'")); // échappe seulement les simples quotes |
| 47 | //$texte = trim($texte); | 47 | $texte = trim($texte); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | // vue | 50 | // vue |
| @@ -54,6 +54,4 @@ else // $previous_page, affichage sans l'article | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | // vue | 56 | // vue |
| 57 | require 'src/templates/page.php'; | 57 | require 'src/view/templates/page.php'; |
| 58 | |||
| 59 | // fin du script | ||
diff --git a/lib/ckeditor5/create.php b/lib/ckeditor5/create.php deleted file mode 100644 index d62f893..0000000 --- a/lib/ckeditor5/create.php +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // lib/ckeditor5/create.php | ||
| 3 | |||
| 4 | // modèle | ||
| 5 | if($storage === 'database') | ||
| 6 | {} | ||
| 7 | elseif($storage === 'files') | ||
| 8 | { | ||
| 9 | // modèle | ||
| 10 | $texte = file_get_contents('data/' . $page . '/html/' . $nom_article . '.html'); | ||
| 11 | $texte = trim(addcslashes($texte, "'")); // échappe seulement les simples quotes | ||
| 12 | } | ||
| 13 | |||
| 14 | // vue | ||
| 15 | require 'lib/ckeditor5/view.php'; // html + JS | ||
| 16 | $contenu = $editeurHTML; | ||
diff --git a/lib/ckeditor5/article_hors_editeur.css b/src/integration/ckeditor5/article_hors_editeur.css index a38b384..a38b384 100644 --- a/lib/ckeditor5/article_hors_editeur.css +++ b/src/integration/ckeditor5/article_hors_editeur.css | |||
diff --git a/lib/ckeditor5/clean_html.php b/src/integration/ckeditor5/clean_html.php index 5d00532..e56f49c 100644 --- a/lib/ckeditor5/clean_html.php +++ b/src/integration/ckeditor5/clean_html.php | |||
| @@ -1,20 +1,12 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // lib/ckeditor5/clean_html.php | 2 | // src/integration/ckeditor5/clean_html.php |
| 3 | 3 | ||
| 4 | function getAndCleanEditorOutput(): string | 4 | function getAndCleanEditorOutput(): string |
| 5 | { | 5 | { |
| 6 | // bugs possibles sans trim() lorsqu'on insère le HTML dans l'éditeur | 6 | // bugs possibles sans trim() lorsqu'on insère le HTML dans l'éditeur |
| 7 | $html = trim($_POST["contenu"]); | 7 | $html = trim($_POST["contenu"]); |
| 8 | 8 | ||
| 9 | 9 | //checkContentInFile($html, 'avant'); | |
| 10 | // pour debugguer ou tester des paramètres avec htmlawed | ||
| 11 | |||
| 12 | //~ $nom_fichier = "avant.html"; | ||
| 13 | //~ $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 | ||
| 14 | //~ fputs($fichier, $html); | ||
| 15 | //~ fclose($fichier); | ||
| 16 | //~ chmod('data/' . $page . '/' . $nom_fichier, 0666); | ||
| 17 | |||
| 18 | 10 | ||
| 19 | // sécurisation du HTML (faille XSS) | 11 | // sécurisation du HTML (faille XSS) |
| 20 | require 'vendor/htmlawed/htmlawed/htmLawed.php'; | 12 | require 'vendor/htmlawed/htmlawed/htmLawed.php'; |
| @@ -31,16 +23,18 @@ function getAndCleanEditorOutput(): string | |||
| 31 | $specHtmLawed = ''; // optionnel: faire qu'un certain élément puisse n'avoir que certains attributs | 23 | $specHtmLawed = ''; // optionnel: faire qu'un certain élément puisse n'avoir que certains attributs |
| 32 | $html = htmLawed($html, $configHtmLawed, $specHtmLawed); | 24 | $html = htmLawed($html, $configHtmLawed, $specHtmLawed); |
| 33 | 25 | ||
| 26 | //checkContentInFile($html, 'après'); | ||
| 34 | 27 | ||
| 35 | //~ $nom_fichier = "après.html"; | 28 | return $html; |
| 36 | //~ $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 | ||
| 37 | //~ fputs($fichier, $html); | ||
| 38 | //~ fclose($fichier); | ||
| 39 | //~ chmod('data/' . $page . '/' . $nom_fichier, 0666); | ||
| 40 | |||
| 41 | |||
| 42 | return $html; | ||
| 43 | } | 29 | } |
| 44 | 30 | ||
| 45 | 31 | ||
| 46 | 32 | function checkContentInFile($html, $file_name) | |
| 33 | { | ||
| 34 | $page = 'page'; | ||
| 35 | $nom_fichier = $file_name . ".html"; | ||
| 36 | $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 | ||
| 37 | fputs($fichier, $html); | ||
| 38 | fclose($fichier); | ||
| 39 | chmod('data/' . $page . '/' . $nom_fichier, 0666); | ||
| 40 | } \ No newline at end of file | ||
diff --git a/config.php b/src/integration/ckeditor5/config.php index 43e8523..822884f 100644 --- a/config.php +++ b/src/integration/ckeditor5/config.php | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // config.php | 2 | // src/integration/ckeditor5/config.php |
| 3 | |||
| 4 | $ckeditor_integration_path = 'src/integration/ckeditor5/'; | ||
| 5 | $css_hors_editeur = '<link rel="stylesheet" href="' . $ckeditor_integration_path . 'article_hors_editeur.css" />'; | ||
| 3 | 6 | ||
| 4 | $server_root = $_SERVER['SERVER_NAME'] . '/ckeditor5/'; | 7 | $server_root = $_SERVER['SERVER_NAME'] . '/ckeditor5/'; |
| 5 | // pour l'importmap: j'ai modifié la version "installation avec CDN de la doc pour utiliser les fichiers locaux | 8 | // pour l'importmap: j'ai modifié la version "installation avec CDN de la doc pour utiliser les fichiers locaux |
diff --git a/src/integration/ckeditor5/create.php b/src/integration/ckeditor5/create.php new file mode 100644 index 0000000..863c420 --- /dev/null +++ b/src/integration/ckeditor5/create.php | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | <?php | ||
| 2 | // src/integration/ckeditor5/create.php | ||
| 3 | |||
| 4 | // modèle | ||
| 5 | if($storage === 'database') | ||
| 6 | {} | ||
| 7 | elseif($storage === 'files') | ||
| 8 | { | ||
| 9 | // modèle | ||
| 10 | $texte = file_get_contents('data/' . $page . '/html/' . $nom_article . '.html'); | ||
| 11 | |||
| 12 | $texte = trim(addcslashes($texte, "'")); // échapper les simples quotes pour javascript | ||
| 13 | //$texte = trim(addslashes($texte)); // échappe ', ", \ et NULL, je sais pas si c'est bien | ||
| 14 | } | ||
| 15 | |||
| 16 | // vue | ||
| 17 | require $ckeditor_integration_path . 'view.php'; // html + JS | ||
| 18 | $contenu = $editeurHTML; | ||
diff --git a/lib/ckeditor5/image_upload.php b/src/integration/ckeditor5/image_upload.php index 607be1b..9090ddf 100644 --- a/lib/ckeditor5/image_upload.php +++ b/src/integration/ckeditor5/image_upload.php | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // lib/ckeditor5/image_upload.php | 2 | // src/integration/ckeditor5/image_upload.php |
| 3 | 3 | ||
| 4 | // script récupérant les images téléchargée en AJAX par l'éditeur et c'est tout | 4 | // script récupérant les images téléchargée en AJAX par l'éditeur et c'est tout |
| 5 | // on récupère les données, on renvoie au navigateur la réponse qu'il attend et stop! | 5 | // on récupère les données, on renvoie au navigateur la réponse qu'il attend et stop! |
| @@ -55,10 +55,10 @@ else | |||
| 55 | if(empty($erreur)) | 55 | if(empty($erreur)) |
| 56 | { | 56 | { |
| 57 | $chemin = '{"url": "data/' . $page . '/images/' . $_FILES['upload']['name'] . '"}'; | 57 | $chemin = '{"url": "data/' . $page . '/images/' . $_FILES['upload']['name'] . '"}'; |
| 58 | echo $chemin; | 58 | echo $chemin; |
| 59 | } | 59 | } |
| 60 | else | 60 | else |
| 61 | { | 61 | { |
| 62 | echo $erreur; | 62 | echo $erreur; |
| 63 | } | 63 | } |
| 64 | die; | 64 | die; |
diff --git a/src/integration/ckeditor5/init.php b/src/integration/ckeditor5/init.php new file mode 100644 index 0000000..4d77cba --- /dev/null +++ b/src/integration/ckeditor5/init.php | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | <?php | ||
| 2 | // src/integration/ckeditor5/init.php | ||
| 3 | |||
| 4 | // lien symbolique des traductions | ||
| 5 | function makeTranslationSymLink(): void | ||
| 6 | { | ||
| 7 | $target = '../translations'; | ||
| 8 | $link = 'node_modules/ckeditor5/dist/browser/translations'; | ||
| 9 | if (!file_exists($link)) | ||
| 10 | { | ||
| 11 | symlink($target, $link); | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/lib/ckeditor5/view.php b/src/integration/ckeditor5/view.php index e592a73..794e55f 100644 --- a/lib/ckeditor5/view.php +++ b/src/integration/ckeditor5/view.php | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // lib/ckeditor5/view.php | 2 | // src/integration/ckeditor5/view.php |
| 3 | 3 | ||
| 4 | //$css_editeur = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/ckeditor5.css" />'; // version normale aérée et commentée | 4 | //$css_editeur = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/ckeditor5.css" />'; // version normale aérée et commentée |
| 5 | $css_editeur = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />'; // version "minifiée" | 5 | $css_editeur = '<link rel="stylesheet" href="node_modules/ckeditor5/dist/browser/ckeditor5.css" />'; // version "minifiée" |
diff --git a/src/templates/page.php b/src/view/templates/page.php index 98e7979..3153ced 100644 --- a/src/templates/page.php +++ b/src/view/templates/page.php | |||
| @@ -4,7 +4,7 @@ | |||
| 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 | <link rel="stylesheet" href="lib/ckeditor5/article_hors_editeur.css" /> | 7 | <?= $css_hors_editeur ?> |
| 8 | <?= $css_editeur ?> | 8 | <?= $css_editeur ?> |
| 9 | </head> | 9 | </head> |
| 10 | <body> | 10 | <body> |
