diff options
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/MainBuilder.php | 4 | ||||
-rw-r--r-- | src/view/NewBuilder.php | 62 | ||||
-rw-r--r-- | src/view/PostBuilder.php | 2 | ||||
-rw-r--r-- | src/view/templates/new.php | 4 |
4 files changed, 45 insertions, 27 deletions
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index e6fc61a..8a40d82 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php | |||
@@ -23,11 +23,13 @@ class MainBuilder extends AbstractBuilder | |||
23 | die; | 23 | die; |
24 | } | 24 | } |
25 | 25 | ||
26 | // nouvel article | ||
26 | if($node->getAdoptedChild() == null){ | 27 | if($node->getAdoptedChild() == null){ |
27 | $date = new \DateTime; | 28 | $date = new \DateTime; |
28 | $article = new Article('', $date); | 29 | $article = new Article('', $date); |
29 | $new = new Node('new', 'i' . (string)$date->getTimestamp(), [], 0, null, null, $article); | 30 | $new = new Node('new', [], 0, null, null, $article); |
30 | } | 31 | } |
32 | // modification | ||
31 | else{ | 33 | else{ |
32 | $new = $node->getAdoptedChild(); | 34 | $new = $node->getAdoptedChild(); |
33 | } | 35 | } |
diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php index 332d92b..9965d15 100644 --- a/src/view/NewBuilder.php +++ b/src/view/NewBuilder.php | |||
@@ -9,31 +9,47 @@ class NewBuilder extends AbstractBuilder | |||
9 | { | 9 | { |
10 | static public bool $new_article_mode = false; | 10 | static public bool $new_article_mode = false; |
11 | 11 | ||
12 | public function __construct(Node $node, ) | 12 | public function __construct(Node $node) |
13 | { | 13 | { |
14 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | 14 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; |
15 | 15 | ||
16 | if(file_exists($viewFile)) | 16 | if(file_exists($viewFile)) |
17 | { | 17 | { |
18 | // id (timestamp) | 18 | if(self::$new_article_mode){ |
19 | if(!empty($node->getAttributes())) | 19 | $id = $_GET['id']; // ici l'id est le nom du block news_block parent |
20 | { | 20 | $title = ''; |
21 | extract($node->getAttributes()); | 21 | $preview = ''; |
22 | |||
23 | // lettre au début de l'id: t = title, p = preview, i = article, d = date | ||
24 | $id_title = $id; | ||
25 | $id_title[0] = 't'; | ||
26 | $id_preview = $id; | ||
27 | $id_preview[0] = 'p'; | ||
28 | $id_content = 'i' . $id; | ||
29 | $id_content[0] = 'i'; | ||
30 | $id_date = $id; | ||
31 | $id_date[0] = 'd'; | ||
22 | } | 32 | } |
33 | else{ | ||
34 | $id = (string)$node->getId(); | ||
23 | 35 | ||
24 | // html, date | 36 | // id (timestamp) |
25 | $title = $node->getArticle()->getTitle(); | 37 | if(!empty($node->getAttributes())) |
26 | $preview = $node->getArticle()->getPreview(); | 38 | { |
27 | 39 | extract($node->getAttributes()); | |
28 | // lettre au début de l'id: i = article, p = preview, t = title, d = date | 40 | } |
29 | $id = $node->getArticleTimestamp(); | ||
30 | $id_title = $id; | ||
31 | $id_title[0] = 't'; | ||
32 | $id_preview = $id; | ||
33 | $id_preview[0] = 'p'; | ||
34 | $id_date = $id; | ||
35 | $id_date[0] = 'd'; | ||
36 | 41 | ||
42 | // html, date | ||
43 | $title = $node->getArticle()->getTitle(); | ||
44 | $preview = $node->getArticle()->getPreview(); | ||
45 | |||
46 | // lettre au début de l'id: t = title, p = preview, i = article, d = date | ||
47 | $id_title = 't' . $id; | ||
48 | $id_preview = 'p' . $id; | ||
49 | $id_content = 'i' . $id; | ||
50 | $id_date = 'd' . $id; | ||
51 | } | ||
52 | |||
37 | $content = ''; | 53 | $content = ''; |
38 | 54 | ||
39 | // page article unique | 55 | // page article unique |
@@ -85,12 +101,12 @@ class NewBuilder extends AbstractBuilder | |||
85 | $submit_preview = '<p id="submit-' . $id_preview . '" class="hidden"><button ' . $submit_js_preview . '>Valider</button></p>'; | 101 | $submit_preview = '<p id="submit-' . $id_preview . '" class="hidden"><button ' . $submit_js_preview . '>Valider</button></p>'; |
86 | $preview_buttons = '<div class="button_zone">' . $modify_preview . $close_editor_preview . $submit_preview . '</div>'; | 102 | $preview_buttons = '<div class="button_zone">' . $modify_preview . $close_editor_preview . $submit_preview . '</div>'; |
87 | 103 | ||
88 | $article_js = 'onclick="openEditor(\'' . $id . '\')"'; | 104 | $article_js = 'onclick="openEditor(\'' . $id_content . '\')"'; |
89 | $modify_article = '<p id="edit-' . $id . '"><button ' . $article_js . '><img class="action_icon" src="assets/edit.svg">Article</button></p>' . "\n"; | 105 | $modify_article = '<p id="edit-' . $id_content . '"><button ' . $article_js . '><img class="action_icon" src="assets/edit.svg">Article</button></p>' . "\n"; |
90 | $close_js_article = 'onclick="closeEditor(\'' . $id . '\')"'; | 106 | $close_js_article = 'onclick="closeEditor(\'' . $id_content . '\')"'; |
91 | $close_editor_article = '<p id="cancel-' . $id . '" class="hidden"><button ' . $close_js_article . '>Annuler</button></p>'; | 107 | $close_editor_article = '<p id="cancel-' . $id_content . '" class="hidden"><button ' . $close_js_article . '>Annuler</button></p>'; |
92 | $submit_js_article = 'onclick="submitArticle(\'' . $id . '\')"'; | 108 | $submit_js_article = 'onclick="submitArticle(\'' . $id_content . '\')"'; |
93 | $submit_article = '<p id="submit-' . $id . '" class="hidden"><button ' . $submit_js_article . '>Valider</button></p>'; | 109 | $submit_article = '<p id="submit-' . $id_content . '" class="hidden"><button ' . $submit_js_article . '>Valider</button></p>'; |
94 | $article_buttons = '<div class="button_zone">' . $modify_article . $close_editor_article . $submit_article . '</div>'; | 110 | $article_buttons = '<div class="button_zone">' . $modify_article . $close_editor_article . $submit_article . '</div>'; |
95 | 111 | ||
96 | $date_js = 'onclick="changeDate(\'' . $id_date . '\', \'article\');'; | 112 | $date_js = 'onclick="changeDate(\'' . $id_date . '\', \'article\');'; |
diff --git a/src/view/PostBuilder.php b/src/view/PostBuilder.php index ae5cc9b..70a2d77 100644 --- a/src/view/PostBuilder.php +++ b/src/view/PostBuilder.php | |||
@@ -22,7 +22,7 @@ class PostBuilder extends AbstractBuilder | |||
22 | // html | 22 | // html |
23 | $title = $node->getArticle()->getTitle(); | 23 | $title = $node->getArticle()->getTitle(); |
24 | $html = $node->getArticle()->getContent(); | 24 | $html = $node->getArticle()->getContent(); |
25 | $id = $node->getArticleTimestamp(); | 25 | $id = (string)$node->getId(); |
26 | 26 | ||
27 | // partage | 27 | // partage |
28 | $share_link = new URL(['page' => CURRENT_PAGE], $id); | 28 | $share_link = new URL(['page' => CURRENT_PAGE], $id); |
diff --git a/src/view/templates/new.php b/src/view/templates/new.php index 1b25eba..fadf1a2 100644 --- a/src/view/templates/new.php +++ b/src/view/templates/new.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php declare(strict_types=1); ?> | 1 | <?php declare(strict_types=1); ?> |
2 | <article> | 2 | <article> |
3 | <div class="new_content"> | 3 | <div class="new_content" id="<?= $id ?>"> |
4 | <div class="article_title_zone"> | 4 | <div class="article_title_zone"> |
5 | <?= $share_button ?> | 5 | <?= $share_button ?> |
6 | <div class="data" id="<?= $id_title ?>"> | 6 | <div class="data" id="<?= $id_title ?>"> |
@@ -12,7 +12,7 @@ | |||
12 | <?= $preview ?> | 12 | <?= $preview ?> |
13 | </div> | 13 | </div> |
14 | <?= $preview_buttons ?> | 14 | <?= $preview_buttons ?> |
15 | <div class="data article_content_text" id="<?= $id ?>"> | 15 | <div class="data article_content_text" id="<?= $id_content ?>"> |
16 | <?= $content ?> | 16 | <?= $content ?> |
17 | </div> | 17 | </div> |
18 | <?= $article_buttons ?> | 18 | <?= $article_buttons ?> |