summaryrefslogtreecommitdiff
path: root/index.php
blob: d998d9603a83adb156b844d0ab375cf1196b3e58 (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
<?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

        // ouvrir l'éditeur sur un des articles ou aucun
        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 // affichage article
        {
            $articles_content[] = $ckeditor->displayArticle($id, $texte);
        }
    }
}

require 'src/view/templates/page.php';