1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\View; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Admin; |
5
|
|
|
use Redaxscript\Html; |
6
|
|
|
use Redaxscript\Model; |
7
|
|
|
use Redaxscript\Module; |
8
|
|
|
use Redaxscript\Validator; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* children class to create the comment |
12
|
|
|
* |
13
|
|
|
* @since 4.0.0 |
14
|
|
|
* |
15
|
|
|
* @package Redaxscript |
16
|
|
|
* @category View |
17
|
|
|
* @author Henry Ruhs |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class Comment extends ViewAbstract |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* options of the comment |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
protected $_optionArray = |
29
|
|
|
[ |
30
|
|
|
'tag' => |
31
|
|
|
[ |
32
|
|
|
'title' => 'h3', |
33
|
|
|
'box' => 'blockquote' |
34
|
|
|
], |
35
|
|
|
'className' => |
36
|
|
|
[ |
37
|
|
|
'title' => 'rs-title-comment', |
38
|
|
|
'box' => 'rs-quote-default' |
39
|
|
|
], |
40
|
|
|
'orderColumn' => 'rank' |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* stringify the comment |
45
|
|
|
* |
46
|
|
|
* @since 4.0.0 |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
public function __toString() : string |
52
|
|
|
{ |
53
|
|
|
return $this->render(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* init the class |
58
|
|
|
* |
59
|
|
|
* @since 4.0.0 |
60
|
|
|
* |
61
|
|
|
* @param array $optionArray options of the comment |
62
|
|
|
*/ |
63
|
|
|
|
64
|
|
|
public function init(array $optionArray = []) |
65
|
|
|
{ |
66
|
|
|
$this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* render the view |
71
|
|
|
* |
72
|
|
|
* @since 4.0.0 |
73
|
|
|
* |
74
|
|
|
* @param int $articleId identifier of the article |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
|
79
|
|
|
public function render(int $articleId = null) : string |
80
|
|
|
{ |
81
|
|
|
if ($this->_registry->get('commentReplace')) |
82
|
|
|
{ |
83
|
|
|
return Module\Hook::trigger('commentReplace'); |
84
|
|
|
} |
85
|
|
|
$output = Module\Hook::trigger('commentStart'); |
86
|
|
|
$accessValidator = new Validator\Access(); |
87
|
|
|
$settingModel = new Model\Setting(); |
88
|
|
|
$commentModel = new Model\Comment(); |
89
|
|
|
$comments = null; |
|
|
|
|
90
|
|
|
$byline = new Helper\Byline($this->_registry, $this->_language); |
91
|
|
|
$byline->init(); |
92
|
|
|
$adminDock = new Admin\View\Helper\Dock($this->_registry, $this->_language); |
93
|
|
|
$adminDock->init(); |
94
|
|
|
$language = $this->_registry->get('language'); |
95
|
|
|
$loggedIn = $this->_registry->get('loggedIn'); |
96
|
|
|
$token = $this->_registry->get('token'); |
97
|
|
|
$firstParameter = $this->_registry->get('firstParameter'); |
98
|
|
|
$lastSubParameter = $this->_registry->get('lastSubParameter'); |
99
|
|
|
$myGroups = $this->_registry->get('myGroups'); |
100
|
|
|
|
101
|
|
|
/* html element */ |
102
|
|
|
|
103
|
|
|
$element = new Html\Element(); |
104
|
|
|
$titleElement = $element |
105
|
|
|
->copy() |
106
|
|
|
->init($this->_optionArray['tag']['title'], |
107
|
|
|
[ |
108
|
|
|
'class' => $this->_optionArray['className']['title'] |
109
|
|
|
]); |
110
|
|
|
$linkElement = $element->copy()->init('a', |
111
|
|
|
[ |
112
|
|
|
'rel' => 'nofollow' |
113
|
|
|
]); |
114
|
|
|
$boxElement = $element |
115
|
|
|
->copy() |
116
|
|
|
->init($this->_optionArray['tag']['box'], |
117
|
|
|
[ |
118
|
|
|
'class' => $this->_optionArray['className']['box'] |
119
|
|
|
]); |
120
|
|
|
|
121
|
|
|
/* query comments */ |
122
|
|
|
|
123
|
|
|
if ($articleId) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
if ($settingModel->get('pagination')) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
$comments = $commentModel->getByArticleAndLanguageAndOrderAndStep($articleId, $language, $this->_optionArray['orderColumn'], $lastSubParameter - 1); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
else |
130
|
|
|
{ |
131
|
|
|
$comments = $commentModel->getByArticleAndLanguageAndOrder($articleId, $language, $this->_optionArray['orderColumn']); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
else |
135
|
|
|
{ |
136
|
|
|
$comments = $commentModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/* process comments */ |
140
|
|
|
|
141
|
|
|
foreach ($comments as $value) |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
if ($accessValidator->validate($value->access, $myGroups)) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
$output .= Module\Hook::trigger('commentFragmentStart', (array)$value); |
146
|
|
|
$output .= $titleElement |
147
|
|
|
->attr('id', 'comment-' . $value->id) |
148
|
|
|
->html($value->url ? $linkElement |
149
|
|
|
->attr('href', $value->url) |
150
|
|
|
->text($value->author) : $value->author |
151
|
|
|
); |
152
|
|
|
$output .= $boxElement->text($value->text) . $byline->render($value->date) . Module\Hook::trigger('commentFragmentEnd', (array)$value); |
153
|
|
|
|
154
|
|
|
/* admin dock */ |
155
|
|
|
|
156
|
|
|
if ($loggedIn === $token && $firstParameter !== 'logout') |
157
|
|
|
{ |
158
|
|
|
$output .= $adminDock->render('comments', $value->id); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
$output .= Module\Hook::trigger('commentEnd'); |
163
|
|
|
return $output; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.