diff options
author | polo <ordipolo@gmx.fr> | 2025-10-22 15:28:02 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-10-22 15:28:02 +0200 |
commit | c9aff025aa7e01badaad8467af6165b400cdaac4 (patch) | |
tree | c6e56a3f13db401c9f75bf9f8e4169f50aaf25b9 /src | |
parent | 426a1a69cb73007538336debc31b34c4348e1ba1 (diff) | |
download | cms-c9aff025aa7e01badaad8467af6165b400cdaac4.zip |
possibilité d'éditer le texte dans header et footer, class JS InputText, Model::findWhateverNode
Diffstat (limited to 'src')
-rw-r--r-- | src/controller/HeadFootController.php | 33 | ||||
-rw-r--r-- | src/model/Model.php | 18 | ||||
-rw-r--r-- | src/router.php | 7 | ||||
-rw-r--r-- | src/view/FooterBuilder.php | 15 | ||||
-rw-r--r-- | src/view/HeadBuilder.php | 5 | ||||
-rw-r--r-- | src/view/HeaderBuilder.php | 27 | ||||
-rw-r--r-- | src/view/templates/footer.php | 27 | ||||
-rw-r--r-- | src/view/templates/header.php | 27 |
8 files changed, 147 insertions, 12 deletions
diff --git a/src/controller/HeadFootController.php b/src/controller/HeadFootController.php new file mode 100644 index 0000000..c7a9cec --- /dev/null +++ b/src/controller/HeadFootController.php | |||
@@ -0,0 +1,33 @@ | |||
1 | <?php | ||
2 | // src/controller/HeadFootController.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | //use App\Entity\Node; | ||
7 | //use App\Entity\NodeData; | ||
8 | //use App\Entity\Image; | ||
9 | //use Doctrine\Common\Collections\ArrayCollection; | ||
10 | use Doctrine\ORM\EntityManager; | ||
11 | |||
12 | class HeadFootController | ||
13 | { | ||
14 | static public function setTextData(EntityManager $entityManager, array $request_params, array $json): void | ||
15 | { | ||
16 | if(count($request_params) !== 2){ | ||
17 | echo json_encode(['success' => false]); | ||
18 | die; | ||
19 | } | ||
20 | |||
21 | $model = new Model($entityManager); | ||
22 | if($model->findWhateverNode('name_node', $request_params[0])){ | ||
23 | $node_data = $model->getNode()->getNodeData(); | ||
24 | $node_data->updateData($request_params[1], htmlspecialchars($json['new_text'])); // $request_params[1] n'est pas contrôlé | ||
25 | $entityManager->flush(); | ||
26 | echo json_encode(['success' => true]); | ||
27 | } | ||
28 | else{ | ||
29 | echo json_encode(['success' => false]); | ||
30 | } | ||
31 | die; | ||
32 | } | ||
33 | } \ No newline at end of file | ||
diff --git a/src/model/Model.php b/src/model/Model.php index ea8ef71..16061e7 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
@@ -185,6 +185,24 @@ class Model | |||
185 | $this->node = $this->entityManager->find('App\Entity\Node', $id); | 185 | $this->node = $this->entityManager->find('App\Entity\Node', $id); |
186 | return $this->node === null ? false : true; | 186 | return $this->node === null ? false : true; |
187 | } | 187 | } |
188 | public function findWhateverNode(string $field, string $value): bool | ||
189 | { | ||
190 | $queryBuilder = $this->entityManager->createQueryBuilder(); | ||
191 | $queryBuilder | ||
192 | ->select('n') | ||
193 | ->from('App\Entity\Node', 'n') | ||
194 | ->where("n.$field = :value") // avec le querybuilder, ce truc sale reste sécurisé | ||
195 | ->setParameter('value', $value); | ||
196 | $result = $queryBuilder->getQuery()->getOneOrNullResult(); | ||
197 | |||
198 | if($result === null){ | ||
199 | return false; | ||
200 | } | ||
201 | else{ | ||
202 | $this->node = $result; | ||
203 | return true; | ||
204 | } | ||
205 | } | ||
188 | 206 | ||
189 | // récupération d'un article pour modification | 207 | // récupération d'un article pour modification |
190 | public function makeArticleNode(string $id = '', bool $get_section = false): bool | 208 | public function makeArticleNode(string $id = '', bool $get_section = false): bool |
diff --git a/src/router.php b/src/router.php index 7459a0d..1127c81 100644 --- a/src/router.php +++ b/src/router.php | |||
@@ -141,11 +141,16 @@ elseif($request->getMethod() === 'POST'){ | |||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | /* -- site entier (header, footer, favicon) -- */ | ||
145 | elseif($request->query->has('entire_site_edit')){ | ||
146 | $request_params = explode('_', $request->query->get('entire_site_edit')); // header_title, header_description, footer_text, etc | ||
147 | HeadFootController::setTextData($entityManager, $request_params, $json); | ||
148 | } | ||
144 | 149 | ||
145 | /* -- page Menu et chemins -- */ | 150 | /* -- page Menu et chemins -- */ |
146 | elseif(isset($_GET['menu_edit'])) | 151 | elseif(isset($_GET['menu_edit'])) |
147 | { | 152 | { |
148 | // ne suit pas la règle, faire ça dans un contrôleur | 153 | // ne suit pas la règle, faire ça dans un contrôleur? |
149 | Model::$menu_data = new Menu($entityManager); // récupération des données | 154 | Model::$menu_data = new Menu($entityManager); // récupération des données |
150 | 155 | ||
151 | // flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions | 156 | // flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions |
diff --git a/src/view/FooterBuilder.php b/src/view/FooterBuilder.php index 0a3f55c..c1e0f7a 100644 --- a/src/view/FooterBuilder.php +++ b/src/view/FooterBuilder.php | |||
@@ -26,6 +26,17 @@ class FooterBuilder extends AbstractBuilder | |||
26 | $empty_admin_zone = ''; | 26 | $empty_admin_zone = ''; |
27 | if($_SESSION['admin']) | 27 | if($_SESSION['admin']) |
28 | { | 28 | { |
29 | $buttons_footer_name = '<img id="footer_name_open" class="action_icon" src="assets/edit.svg" onclick="footer_name.openTextInput()"> | ||
30 | <img id="footer_name_submit" class="action_icon hidden" src="assets/save.svg" onclick="footer_name.submitTextInput()"> | ||
31 | <img id="footer_name_cancel" class="action_icon hidden" src="assets/close.svg" onclick="footer_name.cancelTextInput()">'; | ||
32 | $buttons_footer_address = '<img id="footer_address_open" class="action_icon" src="assets/edit.svg" onclick="footer_address.openTextInput()"> | ||
33 | <img id="footer_address_submit" class="action_icon hidden" src="assets/save.svg" onclick="footer_address.submitTextInput()"> | ||
34 | <img id="footer_address_cancel" class="action_icon hidden" src="assets/close.svg" onclick="footer_address.cancelTextInput()">'; | ||
35 | $buttons_footer_email = '<img id="footer_email_open" class="action_icon" src="assets/edit.svg" onclick="footer_email.openTextInput()"> | ||
36 | <img id="footer_email_submit" class="action_icon hidden" src="assets/save.svg" onclick="footer_email.submitTextInput()"> | ||
37 | <img id="footer_email_cancel" class="action_icon hidden" src="assets/close.svg" onclick="footer_email.cancelTextInput()">'; | ||
38 | |||
39 | // zone admin | ||
29 | $empty_admin_zone = 'empty_admin_zone'; | 40 | $empty_admin_zone = 'empty_admin_zone'; |
30 | if(MainBuilder::$modif_mode){ | 41 | if(MainBuilder::$modif_mode){ |
31 | $mode = 'modification de page'; | 42 | $mode = 'modification de page'; |
@@ -61,6 +72,10 @@ class FooterBuilder extends AbstractBuilder | |||
61 | $url->addParams(['id' => $_GET['id']]); | 72 | $url->addParams(['id' => $_GET['id']]); |
62 | } | 73 | } |
63 | $zone_admin = '<button><a href="' . $url . '">Mode admin</a></button>'; | 74 | $zone_admin = '<button><a href="' . $url . '">Mode admin</a></button>'; |
75 | |||
76 | $buttons_footer_name = ''; | ||
77 | $buttons_footer_address = ''; | ||
78 | $buttons_footer_email = ''; | ||
64 | } | 79 | } |
65 | 80 | ||
66 | ob_start(); | 81 | ob_start(); |
diff --git a/src/view/HeadBuilder.php b/src/view/HeadBuilder.php index b1dfacb..978d9ed 100644 --- a/src/view/HeadBuilder.php +++ b/src/view/HeadBuilder.php | |||
@@ -33,8 +33,11 @@ class HeadBuilder extends AbstractBuilder | |||
33 | $js .= '<script src="' . self::versionedFileURL('js', 'modif_page') . '"></script>' . "\n"; | 33 | $js .= '<script src="' . self::versionedFileURL('js', 'modif_page') . '"></script>' . "\n"; |
34 | } | 34 | } |
35 | 35 | ||
36 | // tinymce, nécéssite un script de copie dans composer.json | ||
37 | if($_SESSION['admin']){ | 36 | if($_SESSION['admin']){ |
37 | // édition éléments sur toutes les pages (header, footer et favicon) | ||
38 | $js .= '<script src="' . self::versionedFileURL('js', 'InputText') . '"></script>' . "\n"; | ||
39 | |||
40 | // tinymce, nécéssite un script de copie dans composer.json | ||
38 | $css .= '<link rel="stylesheet" href="' . self::versionedFileURL('css', 'tinymce') . '">' . "\n"; | 41 | $css .= '<link rel="stylesheet" href="' . self::versionedFileURL('css', 'tinymce') . '">' . "\n"; |
39 | $js .= '<script src="' . self::versionedFileURL('js', 'tinymce/tinymce.min') . '"></script>' . "\n"; // pour js/tinymce/tinymce.min.js | 42 | $js .= '<script src="' . self::versionedFileURL('js', 'tinymce/tinymce.min') . '"></script>' . "\n"; // pour js/tinymce/tinymce.min.js |
40 | $js .= '<script src="' . self::versionedFileURL('js', 'tinymce') . '"></script>' . "\n"; | 43 | $js .= '<script src="' . self::versionedFileURL('js', 'tinymce') . '"></script>' . "\n"; |
diff --git a/src/view/HeaderBuilder.php b/src/view/HeaderBuilder.php index dc4aec4..5492340 100644 --- a/src/view/HeaderBuilder.php +++ b/src/view/HeaderBuilder.php | |||
@@ -77,6 +77,33 @@ class HeaderBuilder extends AbstractBuilder | |||
77 | <img src="assets/' . $one_key . '.svg" alt="' . $one_key . '_alt"></a>'; | 77 | <img src="assets/' . $one_key . '.svg" alt="' . $one_key . '_alt"></a>'; |
78 | } | 78 | } |
79 | 79 | ||
80 | // boutons mode admin | ||
81 | if($_SESSION['admin']){ | ||
82 | $edit_favicon_hidden = 'hidden'; | ||
83 | $button_favicon = ''; | ||
84 | $button_header_logo = ''; | ||
85 | //$edit_favicon_hidden = ''; | ||
86 | //$favicon = 'assets/favicon48x48.png'; // double le code dans HeadBuilder | ||
87 | //$button_favicon = '<button onclick="editFavicon()"><img class="action_icon" src="' . $favicon . '"> Favicon</button>'; | ||
88 | //$button_header_logo = '<img class="action_icon" src="assets/edit.svg" onclick="editHeaderLogo()">'; | ||
89 | $buttons_header_title = '<img id="header_title_open" class="action_icon" src="assets/edit.svg" onclick="header_title.openTextInput()"> | ||
90 | <img id="header_title_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_title.submitTextInput()"> | ||
91 | <img id="header_title_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_title.cancelTextInput()">'; | ||
92 | $buttons_header_description = '<img id="header_description_open" class="action_icon" src="assets/edit.svg" onclick="header_description.openTextInput()"> | ||
93 | <img id="header_description_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_description.submitTextInput()"> | ||
94 | <img id="header_description_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_description.cancelTextInput()">'; | ||
95 | //$buttons_social_networks = '<img class="action_icon" src="assets/edit.svg" onclick="editSocialNetworks()">'; | ||
96 | $buttons_social_networks = ''; | ||
97 | } | ||
98 | else{ | ||
99 | $edit_favicon_hidden = 'hidden'; | ||
100 | $button_favicon = ''; | ||
101 | $button_header_logo = ''; | ||
102 | $buttons_header_title = ''; | ||
103 | $buttons_header_description = ''; | ||
104 | $buttons_social_networks = ''; | ||
105 | } | ||
106 | |||
80 | ob_start(); | 107 | ob_start(); |
81 | require $viewFile; | 108 | require $viewFile; |
82 | $this->html .= ob_get_clean(); | 109 | $this->html .= ob_get_clean(); |
diff --git a/src/view/templates/footer.php b/src/view/templates/footer.php index 1b63edf..dbace6a 100644 --- a/src/view/templates/footer.php +++ b/src/view/templates/footer.php | |||
@@ -1,11 +1,28 @@ | |||
1 | <?php declare(strict_types=1); ?> | 1 | <?php declare(strict_types=1); ?> |
2 | <footer> | 2 | <footer> |
3 | <?= $breadcrumb ?> | 3 | <?= $breadcrumb ?> |
4 | <div> | 4 | <div class="data"> |
5 | <p class="contact"><?= $contact_nom ?><br> | 5 | <div class="contact"> |
6 | <?= $adresse ?><br> | 6 | <div id="footer_name"> |
7 | <a href="mailto:<?= $e_mail ?>"><?= $e_mail ?></a></p> | 7 | <script>let footer_name = new InputText('footer_name');</script> |
8 | <p class="footer_logo"><img src="<?= $footer_logo ?>" alt="logo"><p> | 8 | <span id="footer_name_span"><?= htmlspecialchars($name ?? '') ?></span> |
9 | <input type="text" id="footer_name_input" class="hidden" value="<?= htmlspecialchars($name ?? '') ?>" size="30"> | ||
10 | <?= $buttons_footer_name ?> | ||
11 | </div> | ||
12 | <div id="footer_address"> | ||
13 | <script>let footer_address = new InputText('footer_address');</script> | ||
14 | <span id="footer_address_span"><?= htmlspecialchars($adresse ?? '') ?></span> | ||
15 | <input type="text" id="footer_address_input" class="hidden" value="<?= htmlspecialchars($adresse ?? '') ?>" size="30"> | ||
16 | <?= $buttons_footer_address ?> | ||
17 | </div> | ||
18 | <div id="footer_email"> | ||
19 | <script>let footer_email = new InputText('footer_email');</script> | ||
20 | <a href="mailto:<?= $e_mail ?>"><span id="footer_email_span"><?= htmlspecialchars($email ?? '') ?></span></a> | ||
21 | <input type="text" id="footer_email_input" class="hidden" value="<?= htmlspecialchars($email ?? '') ?>" size="30"> | ||
22 | <?= $buttons_footer_email ?> | ||
23 | </div> | ||
24 | </div> | ||
25 | <p class="footer_logo"><img src="<?= $footer_logo ?>" alt="logo"></p> | ||
9 | </div> | 26 | </div> |
10 | <div class="<?= $empty_admin_zone ?>"></div> | 27 | <div class="<?= $empty_admin_zone ?>"></div> |
11 | <div class="<?= $div_admin ?>"> | 28 | <div class="<?= $div_admin ?>"> |
diff --git a/src/view/templates/header.php b/src/view/templates/header.php index d419a12..7977ef3 100644 --- a/src/view/templates/header.php +++ b/src/view/templates/header.php | |||
@@ -7,19 +7,36 @@ | |||
7 | </div> | 7 | </div> |
8 | 8 | ||
9 | <div class="header-content"> | 9 | <div class="header-content"> |
10 | <div class="head_logo"> | 10 | <div class="header_left_col"> |
11 | <a href="<?= new URL ?>"><img src="<?= $header_logo ?>" alt="logo_alt"></a> | 11 | <div id="edit_favicon_zone" class="<?= $edit_favicon_hidden ?>"> |
12 | <?= $button_favicon ?> | ||
13 | </div> | ||
14 | <div> | ||
15 | <a href="<?= new URL ?>"><img id="header_logo" src="<?= $header_logo ?>" alt="logo_alt"></a> | ||
16 | <?= $button_header_logo ?> | ||
17 | </div> | ||
12 | </div> | 18 | </div> |
13 | <div class="nav_button"> | 19 | <div class="nav_button"> |
14 | <button>MENU</button> | 20 | <button>MENU</button> |
15 | </div> | 21 | </div> |
16 | <div class="site_title"> | 22 | <div class="site_title"> |
17 | <a href="<?= new URL ?>"><h1><?= $title ?></h1></a> | 23 | <h1 id="header_title"> |
18 | <h2><?= $description ?></h2> | 24 | <script>let header_title = new InputText('header_title');</script> |
25 | <a href="<?= new URL ?>"><span id="header_title_span"><?= htmlspecialchars($title ?? '') ?></span></a> | ||
26 | <input type="text" id="header_title_input" class="hidden" value="<?= htmlspecialchars($title ?? '') ?>" size="30"> | ||
27 | <?= $buttons_header_title ?> | ||
28 | </h1> | ||
29 | <h2 id="header_description"> | ||
30 | <script>let header_description = new InputText('header_description');</script> | ||
31 | <span id="header_description_span"><?= htmlspecialchars($description ?? '') ?></span> | ||
32 | <input type="text" id="header_description_input" class="hidden" value="<?= htmlspecialchars($description ?? '') ?>" size="30"> | ||
33 | <?= $buttons_header_description ?> | ||
34 | </h2> | ||
19 | </div> | 35 | </div> |
20 | <div> | 36 | <div class="header_right_col"> |
21 | <div class="social"> | 37 | <div class="social"> |
22 | <?= $social_networks ?> | 38 | <?= $social_networks ?> |
39 | <?= $buttons_social_networks ?> | ||
23 | </div> | 40 | </div> |
24 | <?= $breadcrumb ?? '' ?> | 41 | <?= $breadcrumb ?? '' ?> |
25 | </div> | 42 | </div> |