1
|
|
|
<?php |
2
|
|
|
namespace Chp\TextContent; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* A page controller |
6
|
|
|
* Made by Rasmus Berg (c) 2014-2017 |
7
|
|
|
* |
8
|
|
|
* @Property Object $this->di Anax-MVC class handler |
9
|
|
|
* @Property Object $this->request Anax-MVC $_POST, $_GET and $_SERVER handler class |
10
|
|
|
* @Property Object $this->url Anax-MVC url-handler class |
11
|
|
|
* @Property Object $this->theme Anax-MVC theme-handler class |
12
|
|
|
* @Property Object $this->views Anax-MVC views-handler class |
13
|
|
|
* @Property Object $this->textFilter Anax-MVC textformat-handler class |
14
|
|
|
*/ |
15
|
|
|
class PageController implements \Anax\DI\IInjectionAware |
16
|
|
|
{ |
17
|
|
|
use \Anax\DI\TInjectable; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Properties |
21
|
|
|
*/ |
22
|
|
|
private $content = null; |
23
|
|
|
private $urlPrefix = "content.php/"; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initialize the controller |
27
|
|
|
* |
28
|
|
|
* @Return Void |
29
|
|
|
*/ |
30
|
|
|
public function initialize(){ |
31
|
|
|
$this->content = new \Chp\TextContent\Content(); |
32
|
|
|
$this->content->setDI($this->di); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Index content - Redirect to startpage |
37
|
|
|
* |
38
|
|
|
* @Return Void |
39
|
|
|
*/ |
40
|
|
|
public function indexAction(){ |
41
|
|
|
$url = $this->request->getGet('url'); |
|
|
|
|
42
|
|
|
$this->pageAction($url); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Visit page made by database content |
47
|
|
|
* |
48
|
|
|
* @Param String $url Select url to content |
49
|
|
|
* @Return Void |
50
|
|
|
*/ |
51
|
|
|
public function pageAction($url = null){ |
52
|
|
|
if(is_null($url)) |
53
|
|
|
throw new \Anax\Exception\NotFoundException(); |
54
|
|
|
|
55
|
|
|
$page = $this->content->getContentByUrl($url, 'page'); |
56
|
|
|
|
57
|
|
|
if(empty($page)) |
58
|
|
|
throw new \Anax\Exception\NotFoundException(); |
59
|
|
|
|
60
|
|
|
// Prepare page for show in view |
61
|
|
|
$page = $this->preparePage($page); |
62
|
|
|
|
63
|
|
|
$title = $page->title; |
64
|
|
|
|
65
|
|
|
$this->theme->setTitle($title); |
|
|
|
|
66
|
|
|
$this->views->addString($title, 'page-title'); |
|
|
|
|
67
|
|
|
$this->views->add('text-content/page', |
|
|
|
|
68
|
|
|
[ |
69
|
|
|
'title' => $title, |
70
|
|
|
'page' => $page |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Prepare page to show in view |
77
|
|
|
* |
78
|
|
|
* @Param Object $page Page information |
79
|
|
|
* @Return Object $result Prepared page information |
80
|
|
|
*/ |
81
|
1 |
|
public function preparePage($page = null){ |
82
|
1 |
|
$result = null; |
83
|
|
|
|
84
|
1 |
|
if(!is_null($page)){ |
85
|
1 |
|
$result = (object)[]; |
86
|
|
|
|
87
|
1 |
|
foreach($page as $key => $value){ |
88
|
1 |
|
$result->{$key} = $value; |
89
|
1 |
|
} |
90
|
|
|
|
91
|
1 |
|
$result->title = htmlspecialchars($page->title, ENT_QUOTES); |
92
|
1 |
|
$result->ingress = htmlspecialchars($page->ingress, ENT_QUOTES); |
93
|
1 |
|
$result->text = $this->textFilter->doFilter(htmlentities($page->text, ENT_QUOTES), $page->filters); |
|
|
|
|
94
|
1 |
|
$result->editUrl = $this->url->create("content/edit/{$page->id}"); |
|
|
|
|
95
|
|
|
//$result->authorId = $author; |
96
|
|
|
//$result->authorName = htmlentities($page->name, ENT_QUOTES); |
97
|
|
|
//$result->authorUrl = $this->url->create('users/id/' . $page->author); |
98
|
|
|
|
99
|
|
|
//unset($author); |
100
|
1 |
|
} |
101
|
|
|
|
102
|
1 |
|
return $result; |
103
|
|
|
} |
104
|
|
|
} |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.