|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package sitemaker |
|
5
|
|
|
* @copyright (c) 2016 Daniel A. (blitze) |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace blitze\content\services\comments; |
|
11
|
|
|
|
|
12
|
|
|
class form |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var \phpbb\auth\auth */ |
|
15
|
|
|
protected $auth; |
|
16
|
|
|
|
|
17
|
|
|
/** @var \phpbb\config\config */ |
|
18
|
|
|
protected $config; |
|
19
|
|
|
|
|
20
|
|
|
/** @var \phpbb\language\language */ |
|
21
|
|
|
protected $language; |
|
22
|
|
|
|
|
23
|
|
|
/** @var \phpbb\template\template */ |
|
24
|
|
|
protected $template; |
|
25
|
|
|
|
|
26
|
|
|
/** @var \phpbb\user */ |
|
27
|
|
|
protected $user; |
|
28
|
|
|
|
|
29
|
|
|
/** @var string */ |
|
30
|
|
|
protected $phpbb_root_path; |
|
31
|
|
|
|
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
protected $php_ext; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Constructor |
|
37
|
|
|
* |
|
38
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
|
39
|
|
|
* @param \phpbb\config\config $config Config object |
|
40
|
|
|
* @param \phpbb\language\language $language Language Object |
|
41
|
|
|
* @param \phpbb\template\template $template Template object |
|
42
|
|
|
* @param \phpbb\user $user User object |
|
43
|
|
|
* @param string $root_path Path to the phpbb includes directory. |
|
44
|
|
|
* @param string $php_ext php file extension |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\user $user, $root_path, $php_ext) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->auth = $auth; |
|
49
|
|
|
$this->config = $config; |
|
50
|
|
|
$this->language = $language; |
|
51
|
|
|
$this->template = $template; |
|
52
|
|
|
$this->user = $user; |
|
53
|
|
|
$this->phpbb_root_path = $root_path; |
|
54
|
|
|
$this->php_ext = $php_ext; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @inheritdoc |
|
59
|
|
|
*/ |
|
60
|
|
|
public function show_form(array $topic_data) |
|
61
|
|
|
{ |
|
62
|
|
|
if (!$this->user_can_post_comment($topic_data)) |
|
63
|
|
|
{ |
|
64
|
|
|
add_form_key('posting'); |
|
65
|
|
|
|
|
66
|
|
|
$qr_hidden_fields = array( |
|
67
|
|
|
'topic_cur_post_id' => (int) $topic_data['topic_last_post_id'], |
|
68
|
|
|
'lastclick' => (int) time(), |
|
69
|
|
|
'topic_id' => (int) $topic_data['topic_id'], |
|
70
|
|
|
'forum_id' => (int) $topic_data['forum_id'], |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
$this->set_smilies($topic_data['forum_id'], $qr_hidden_fields); |
|
74
|
|
|
$this->set_bbcode($topic_data['forum_id'], $qr_hidden_fields); |
|
75
|
|
|
$this->set_notification($s_watching_topic['is_watching'], $qr_hidden_fields); |
|
|
|
|
|
|
76
|
|
|
$this->set_topic_lock($topic_data['topic_status'], $qr_hidden_fields); |
|
77
|
|
|
$this->set_magic_urls($qr_hidden_fields); |
|
78
|
|
|
|
|
79
|
|
|
$this->template->assign_vars(array( |
|
80
|
|
|
'S_QUICK_REPLY' => true, |
|
81
|
|
|
'L_QUICKREPLY' => $this->language->lang('NEW_COMMENT'), |
|
82
|
|
|
'U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$topic_data['forum_id']}&t={$topic_data['topic_id']}"), |
|
83
|
|
|
'QR_HIDDEN_FIELDS' => build_hidden_fields($qr_hidden_fields), |
|
84
|
|
|
'SUBJECT' => 'Re: ' . censor_text($topic_data['topic_title']), |
|
85
|
|
|
)); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param array $topic_data |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function user_can_post_comment(array $topic_data) |
|
94
|
|
|
{ |
|
95
|
|
|
if ($this->user->data['is_registered'] && ($topic_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) && $this->auth->acl_get('f_reply', $topic_data['forum_id'])) |
|
96
|
|
|
{ |
|
97
|
|
|
return !$this->topic_is_locked($topic_data); |
|
98
|
|
|
} |
|
99
|
|
|
return false; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param array $topic_data |
|
104
|
|
|
* @return bool |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function topic_is_locked(array $topic_data) |
|
107
|
|
|
{ |
|
108
|
|
|
return (($topic_data['forum_status'] == ITEM_UNLOCKED && $topic_data['topic_status'] == ITEM_UNLOCKED) || $this->auth->acl_get('m_edit', $topic_data['forum_id'])) ? true : false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param int $forum_id |
|
113
|
|
|
* @param array $qr_hidden_fields |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function set_smilies($forum_id, array &$qr_hidden_fields) |
|
117
|
|
|
{ |
|
118
|
|
|
if (!($this->config['allow_smilies'] && $this->user->optionget('smilies') && $this->auth->acl_get('f_smilies', $forum_id))) |
|
119
|
|
|
{ |
|
120
|
|
|
$qr_hidden_fields['disable_smilies'] = 1; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param int $forum_id |
|
126
|
|
|
* @param array $qr_hidden_fields |
|
127
|
|
|
* @return bool |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function set_bbcode($forum_id, array &$qr_hidden_fields) |
|
130
|
|
|
{ |
|
131
|
|
|
if (!($this->config['allow_bbcode'] && $this->user->optionget('bbcode') && $this->auth->acl_get('f_bbcode', $forum_id))) |
|
132
|
|
|
{ |
|
133
|
|
|
$qr_hidden_fields['disable_bbcode'] = 1; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param bool $is_watching |
|
139
|
|
|
* @param array $qr_hidden_fields |
|
140
|
|
|
* @return bool |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function set_notification($is_watching, array &$qr_hidden_fields) |
|
143
|
|
|
{ |
|
144
|
|
|
if ($this->config['allow_topic_notify'] && ($this->user->data['user_notify'] || $is_watching)) |
|
145
|
|
|
{ |
|
146
|
|
|
$qr_hidden_fields['notify'] = 1; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param int $topic_status |
|
152
|
|
|
* @param array $qr_hidden_fields |
|
153
|
|
|
* @return bool |
|
154
|
|
|
*/ |
|
155
|
|
|
protected function set_topic_lock($topic_status, array &$qr_hidden_fields) |
|
156
|
|
|
{ |
|
157
|
|
|
if ($topic_status == ITEM_LOCKED) |
|
158
|
|
|
{ |
|
159
|
|
|
$qr_hidden_fields['lock_topic'] = 1; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param array $qr_hidden_fields |
|
165
|
|
|
* @return bool |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function set_magic_urls(array &$qr_hidden_fields) |
|
168
|
|
|
{ |
|
169
|
|
|
if (!$this->config['allow_post_links']) |
|
170
|
|
|
{ |
|
171
|
|
|
$qr_hidden_fields['disable_magic_url'] = 1; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.