diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 56 |
1 files changed, 39 insertions, 17 deletions
@@ -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 | ||
10 | require 'src/integration/ckeditor5/CKEditor.php'; | 9 | require '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 |
19 | if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor') | 19 | if(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 |
25 | if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur | 25 | if(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 | |||
52 | if(isset($_GET['action']) && $_GET['action'] === 'open_editor' && $id_article == '') | ||
53 | { | ||
54 | $articles_content = $ckeditor->openEditor() . "\n"; | ||
55 | } | ||
56 | else | ||
57 | { | ||
58 | $articles_content = $ckeditor->displayNewArticleButton() . "\n"; | ||
59 | } | ||
60 | |||
34 | if($ckeditor->getStorageMode() === 'database') | 61 | if($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 ?> |
85 | foreach($articles_content as $article) | ||
86 | { | ||
87 | echo $article; | ||
88 | } | ||
89 | ?> | ||
90 | </div> | 112 | </div> |
91 | </body> | 113 | </body> |
92 | </html> | 114 | </html> |