blob: a7815be82e7269f8b525626aab90a17ca6a0f878 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<?php
// index.php
// code de l'appli principale
$page = isset($_GET['page']) ? $_GET['page'] : 'accueil';
$from = isset($_GET['from']) ? $_GET['from'] : 'accueil'; // pour revenir au même endroit après un submit
$id_article = isset($_GET['id']) ? $_GET['id'] : ''; // page pouvant avoir plusieurs articles
require 'src/integration/ckeditor5/CKEditor.php';
$ckeditor = new CKEditor();
$ckeditor->setStorageMode('files');
$ckeditor->setPage($page);
// routage
// upload images AJAX
if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor')
{
$ckeditor->checkAjaxReqest();
}
// submit normal
if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur
{
$ckeditor->setFrom($from);
$ckeditor->checkSubmitPOST();
}
// modèle - récupération des articles
$articles_id = []; // noms des id en BBD ou des fichiers
$articles_content = []; // contenu HTML
if($ckeditor->getStorageMode() === 'database')
{
// => modèle
}
elseif($ckeditor->getStorageMode() === 'files')
{
foreach(scandir(CKEditor::DATA_PATH . '/html/') as $file_name)
{
if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers
{
$articles_id[] = rtrim($file_name, '.html');
}
}
foreach($articles_id as $id)
{
$texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html'));
//$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien
// vue - afficher des articles et éventuellement l'éditeur dans un des articles
if(isset($_GET['action']) && $_GET['action'] === 'open_editor')
{
if($id === $id_article)
{
$texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript
$articles_content[] = $ckeditor->openEditor($id, $texte);
}
else
{
$articles_content[] = $ckeditor->displayArticle($id, $texte);
}
}
else
{
$articles_content[] = $ckeditor->displayArticle($id, $texte);
}
}
}
// vue
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="icon" type="image/png" href="">
<?= $ckeditor->getCSSOutsideEditorTag() ?>
<?= $ckeditor->getCSSEditorTag() ?>
</head>
<body>
<div>
<?php
foreach($articles_content as $article)
{
echo $article;
}
?>
</div>
</body>
</html>
|