diff options
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/ArticleController.php | 11 | ||||
-rw-r--r-- | src/controller/ViewController.php | 25 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index cb132cf..411c1dc 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php | |||
@@ -36,14 +36,19 @@ class ArticleController | |||
36 | if($json['id'][0] === 'n') // ici $id est un bloc | 36 | if($json['id'][0] === 'n') // ici $id est un bloc |
37 | { | 37 | { |
38 | $section_id = (int)substr($id, 1); // id du bloc <section> | 38 | $section_id = (int)substr($id, 1); // id du bloc <section> |
39 | if(!$director->findNodeById($section_id)){ | 39 | if(!$director->findNodeById($section_id)){ // erreur mauvais id |
40 | echo json_encode(['success' => false, 'error' => 'article_not_saved']); | 40 | echo json_encode(['success' => false, 'error' => 'article_not_saved, bad id']); |
41 | die; | 41 | die; |
42 | } | 42 | } |
43 | $director->makeSectionNode(); | 43 | $director->makeSectionNode(); |
44 | $node = $director->getNode(); // = <section> | 44 | $node = $director->getNode(); // = <section> |
45 | 45 | ||
46 | if(is_array($content)){ // cas d'une nouvelle "news" | 46 | if(is_array($content)){ // cas d'une nouvelle "news" |
47 | if($node->getPage()->getEndOfPath() !== $json['from']){ // erreur mauvais from | ||
48 | echo json_encode(['success' => false, 'error' => 'article_not_saved, bad from']); | ||
49 | die; | ||
50 | } | ||
51 | |||
47 | $date = new \DateTime($content['d'] . ':' . (new \DateTime)->format('s')); // l'input type="datetime-local" ne donne pas les secondes, on les ajoute: 'hh:mm' . ':ss' | 52 | $date = new \DateTime($content['d'] . ':' . (new \DateTime)->format('s')); // l'input type="datetime-local" ne donne pas les secondes, on les ajoute: 'hh:mm' . ':ss' |
48 | $article = new Article($content['i'], $date, $content['t'], $content['p']); | 53 | $article = new Article($content['i'], $date, $content['t'], $content['p']); |
49 | $article_node = new Node('new', [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); | 54 | $article_node = new Node('new', [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); |
diff --git a/src/controller/ViewController.php b/src/controller/ViewController.php index 668fa25..f66baff 100644 --- a/src/controller/ViewController.php +++ b/src/controller/ViewController.php | |||
@@ -33,17 +33,24 @@ class ViewController extends AbstractBuilder // ViewController est aussi le prem | |||
33 | } | 33 | } |
34 | 34 | ||
35 | // page article: mode création et erreurs d'id | 35 | // page article: mode création et erreurs d'id |
36 | if($_SESSION['admin'] && $request->query->has('page') && $request->query->get('page') === 'article'){ | 36 | if($request->query->has('page') && $request->query->get('page') === 'article'){ |
37 | if(!$request->query->has('id')){ | 37 | if($_SESSION['admin']){ |
38 | return new Response($this->html, 302); | 38 | if(!$request->query->has('id')){ |
39 | } | ||
40 | else{ | ||
41 | if($request->query->get('id')[0] === 'n'){ // mode création d'article (vérification de l'id du bloc dans ArticleController) | ||
42 | NewBuilder::$new_article_mode = true; | ||
43 | } | ||
44 | elseif(self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ // id inconnu | ||
45 | return new Response($this->html, 302); | 39 | return new Response($this->html, 302); |
46 | } | 40 | } |
41 | else{ | ||
42 | // mode création d'article | ||
43 | // l'id du bloc et 'from=' sont vérifiés dans ArticleController::editorSubmit | ||
44 | if($request->query->get('id')[0] === 'n' && $request->query->has('from') && !empty($request->query->get('from'))){ | ||
45 | NewBuilder::$new_article_mode = true; | ||
46 | } | ||
47 | elseif(self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ // id inconnu | ||
48 | return new Response($this->html, 302); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | elseif($request->query->get('id')[0] === 'n'){ // accès page nouvelle article interdit sans être admin | ||
53 | return new Response($this->html, 302); | ||
47 | } | 54 | } |
48 | } | 55 | } |
49 | 56 | ||