|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Part of the files dealing with preparing the content for display posts |
|
5
|
|
|
* via callbacks (Display, PM, Search). |
|
6
|
|
|
* |
|
7
|
|
|
* @package ElkArte Forum |
|
8
|
|
|
* @copyright ElkArte Forum contributors |
|
9
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
|
10
|
|
|
* |
|
11
|
|
|
* This file contains code covered by: |
|
12
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
|
13
|
|
|
* |
|
14
|
|
|
* @version 2.0 dev |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ElkArte\MessagesCallback; |
|
19
|
|
|
|
|
20
|
|
|
use ElkArte\Helper\ValuesContainer; |
|
21
|
|
|
use ElkArte\Member; |
|
22
|
|
|
use ElkArte\MembersList; |
|
23
|
|
|
use ElkArte\MessagesCallback\BodyParser\BodyParserInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* PmRenderer |
|
27
|
|
|
* |
|
28
|
|
|
* Used by the \ElkArte\Controller\PersonalMessage to prepare both the subjects (for |
|
29
|
|
|
* the list of messages in the index) and the bodies of the PMs. |
|
30
|
|
|
*/ |
|
31
|
|
|
class PmRenderer extends Renderer |
|
32
|
|
|
{ |
|
33
|
|
|
public const BEFORE_PREPARE_HOOK = 'integrate_before_prepare_pm_context'; |
|
34
|
|
|
|
|
35
|
|
|
public const CONTEXT_HOOK = 'integrate_prepare_pm_context'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Array of selected personal messages |
|
39
|
|
|
* |
|
40
|
|
|
* @var int[] |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $_temp_pm_selected; |
|
43
|
|
|
|
|
44
|
2 |
|
/** |
|
45
|
|
|
* {@inheritDoc} |
|
46
|
2 |
|
*/ |
|
47
|
2 |
|
public function __construct($request, $user, BodyParserInterface $bodyParser, ValuesContainer $opt = null) |
|
48
|
2 |
|
{ |
|
49
|
|
|
parent::__construct($request, $user, $bodyParser, $opt); |
|
50
|
|
|
$this->_idx_mapper = new ValuesContainer([ |
|
51
|
|
|
'id_msg' => 'id_pm', |
|
52
|
|
|
'id_member' => 'id_member_from', |
|
53
|
|
|
'name' => 'from_name', |
|
54
|
2 |
|
'time' => 'msgtime', |
|
55
|
2 |
|
]); |
|
56
|
2 |
|
|
|
57
|
|
|
$this->_temp_pm_selected = $_SESSION['pm_selected'] ?? []; |
|
58
|
|
|
$_SESSION['pm_selected'] = []; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritDoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function _setupPermissions() |
|
65
|
|
|
{ |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritDoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function _adjustGuestContext($member_context) |
|
72
|
|
|
{ |
|
73
|
|
|
global $context; |
|
74
|
|
|
|
|
75
|
|
|
MembersList::loadGuest(); |
|
76
|
|
|
parent::_adjustGuestContext($member_context); |
|
77
|
|
|
|
|
78
|
|
|
// Sometimes the forum sends messages itself (Warnings are an example) |
|
79
|
|
|
// in this case don't label it from a guest. |
|
80
|
|
|
if ($this->_this_message['from_name'] === $context['forum_name']) |
|
81
|
|
|
{ |
|
82
|
|
|
$member_context['group'] = ''; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$member_context['email'] = ''; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* {@inheritDoc} |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function _adjustAllMembers($member_context) |
|
92
|
|
|
{ |
|
93
|
|
|
global $context; |
|
94
|
|
|
|
|
95
|
|
|
$member_context['show_profile_buttons'] = (!empty($member_context['can_view_profile']) |
|
96
|
|
|
|| (!empty($member_context['website']['url']) && !isset($context['disabled_fields']['website'])) |
|
97
|
|
|
|| $member_context['show_email'] |
|
98
|
|
|
|| $context['can_send_pm']); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritDoc} |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function _buildOutputArray() |
|
105
|
|
|
{ |
|
106
|
|
|
global $context, $modSettings, $scripturl; |
|
107
|
|
|
|
|
108
|
|
|
$id_pm = $this->_this_message['id_pm']; |
|
109
|
|
|
|
|
110
|
|
|
$output = parent::_buildOutputArray(); |
|
111
|
|
|
|
|
112
|
|
|
// Not a Member ValuesContainer. Check if this was a subject listing and the data in that request |
|
113
|
|
|
if (!$output['member'] instanceof Member && isset($this->_this_message['not_guest'])) |
|
114
|
|
|
{ |
|
115
|
|
|
$output['member'] = [ |
|
116
|
|
|
'id' => $this->_this_message['id_member_from'], |
|
117
|
|
|
'name' => $this->_this_message['from_name'], |
|
118
|
|
|
'link' => $this->_this_message['not_guest'] ? '<a href="' . $scripturl . '?action=profile;u=' . $this->_this_message['id_member_from'] . '">' . $this->_this_message['from_name'] . '</a>' : $this->_this_message['from_name'], |
|
119
|
|
|
'is_guest' => (int) $this->_this_message['not_guest'] === 0, |
|
120
|
|
|
]; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$output += [ |
|
124
|
|
|
'recipients' => $this->_options->recipients[$id_pm], |
|
|
|
|
|
|
125
|
|
|
'number_recipients' => count($this->_options->recipients[$id_pm]['to']), |
|
126
|
|
|
'labels' => &$context['message_labels'][$id_pm], |
|
127
|
|
|
'fully_labeled' => count($context['message_labels'][$id_pm]) === count($context['labels']), |
|
128
|
|
|
'is_replied_to' => &$context['message_replied'][$id_pm], |
|
129
|
|
|
'is_unread' => &$context['message_unread'][$id_pm], |
|
130
|
|
|
'is_selected' => !empty($this->_temp_pm_selected) && in_array($id_pm, $this->_temp_pm_selected), |
|
131
|
|
|
'is_message_author' => (int) $this->_this_message['id_member_from'] === (int) $this->user->id, |
|
132
|
|
|
'can_report' => !empty($modSettings['enableReportPM']), |
|
133
|
|
|
]; |
|
134
|
|
|
|
|
135
|
|
|
// Or give / take karma for a PM |
|
136
|
|
|
if (!empty($output['member']['karma']['allow'])) |
|
137
|
|
|
{ |
|
138
|
|
|
$output['member']['karma'] += [ |
|
139
|
|
|
'applaud_url' => getUrl('action', ['action' => 'karma', 'sa' => 'applaud', 'uid' => $output['member']['id'], 'f' => $context['folder'], 'start' => $context['start'], 'pm' => $output['id'], '{session_data}'] + ($context['current_label_id'] != -1 ? ['l' => $context['current_label_id']] : [])), |
|
140
|
|
|
'smite_url' => getUrl('action', ['action' => 'karma', 'sa' => 'smite', 'uid' => $output['member']['id'], 'f' => $context['folder'], 'start' => $context['start'], 'pm' => $output['id'], '{session_data}'] + ($context['current_label_id'] != -1 ? ['l' => $context['current_label_id']] : [])), |
|
141
|
|
|
]; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
// Build the PM buttons, like reply, report, etc. |
|
145
|
|
|
$output += $this->_buildPmButtons($output); |
|
146
|
|
|
|
|
147
|
|
|
return $output; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Generates a PM button array suitable for consumption by template_button_strip |
|
152
|
|
|
* |
|
153
|
|
|
* @param $output |
|
154
|
|
|
* @return array |
|
155
|
|
|
*/ |
|
156
|
|
|
protected function _buildPmButtons($output): array |
|
157
|
|
|
{ |
|
158
|
|
|
global $context, $txt; |
|
159
|
|
|
|
|
160
|
|
|
$pmButtons = [ |
|
161
|
|
|
// Show reply buttons if you have the permission to send PMs. |
|
162
|
|
|
// Is there than more than one recipient you can reply to? |
|
163
|
|
|
'reply_all_button' => [ |
|
164
|
|
|
'text' => 'reply_to_all', |
|
165
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'send', 'f' => $context['folder'], 'pmsg' => $output['id'], 'quote' => '', 'u' => 'all']) . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), |
|
166
|
|
|
'class' => 'reply_all_button', |
|
167
|
|
|
'icon' => 'comments', |
|
168
|
|
|
'enabled' => !$output['member']['is_guest'] && $output['number_recipients'] > 1 && $context['can_send_pm'], |
|
169
|
|
|
], |
|
170
|
|
|
// Reply, Quote |
|
171
|
|
|
'reply_button' => [ |
|
172
|
|
|
'text' => 'reply', |
|
173
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'send', 'f' => $context['folder'], 'pmsg' => $output['id'], 'u' => $output['member']['id']]) . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), |
|
174
|
|
|
'class' => 'reply_button', |
|
175
|
|
|
'icon' => 'modify', |
|
176
|
|
|
'enabled' => !$output['member']['is_guest'] && $context['can_send_pm'], |
|
177
|
|
|
], |
|
178
|
|
|
'quote_button' => [ |
|
179
|
|
|
'text' => 'quote', |
|
180
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'send', 'f' => $context['folder'], 'pmsg' => $output['id'], 'quote' => '']) . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '') . ($context['folder'] === 'sent' ? '' : ';u=' . $output['member']['id']), |
|
181
|
|
|
'class' => 'quote_button', |
|
182
|
|
|
'icon' => 'quote', |
|
183
|
|
|
'enabled' => !$output['member']['is_guest'] && $context['can_send_pm'], |
|
184
|
|
|
], |
|
185
|
|
|
// This is for "forwarding" - even if the member is gone. |
|
186
|
|
|
'reply_quote_button' => [ |
|
187
|
|
|
'text' => 'reply_quote', |
|
188
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'send', 'f' => $context['folder'], 'pmsg' => $output['id'], 'quote' => '']) . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), |
|
189
|
|
|
'class' => 'reply_button', |
|
190
|
|
|
'icon' => 'modify', |
|
191
|
|
|
'enabled' => $output['member']['is_guest'] && $context['can_send_pm'], |
|
192
|
|
|
], |
|
193
|
|
|
// Remove is always an option |
|
194
|
|
|
'remove_button' => [ |
|
195
|
|
|
'text' => 'delete', |
|
196
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'pmactions', 'pm_actions[' . $output['id'] . ']' => 'delete', 'f' => $context['folder'], 'start' => $context['start'], '{session_data}']) . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), |
|
197
|
|
|
'icon' => 'delete', |
|
198
|
|
|
'custom' => 'onclick="return confirm(\'' . addslashes($txt['remove_message']) . '?\');"', |
|
199
|
|
|
], |
|
200
|
|
|
// Maybe there is something...more :P (this is the more button) |
|
201
|
|
|
// *** Submenu => true |
|
202
|
|
|
// |
|
203
|
|
|
// Or mark it as unread |
|
204
|
|
|
'restore_button' => [ |
|
205
|
|
|
'text' => 'pm_mark_unread', |
|
206
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'markunread', 'l' => $context['current_label_id'], 'pmsg' => $output['id'], '{session_data}']), |
|
207
|
|
|
'icon' => 'recycle', |
|
208
|
|
|
'enabled' => empty($output['is_unread']) && $context['folder'] !== 'sent' && $output['member']['id'] != $this->user->id, |
|
209
|
|
|
'submenu' => true, |
|
210
|
|
|
], |
|
211
|
|
|
// Can they report this message |
|
212
|
|
|
'warn_button' => [ |
|
213
|
|
|
'text' => 'pm_report_to_admin', |
|
214
|
|
|
'url' => getUrl('action', ['action' => 'pm', 'sa' => 'report', 'l' => $context['current_label_id'], 'pmsg' => $output['id'], '{session_data}']), |
|
215
|
|
|
'icon' => 'warn', |
|
216
|
|
|
'enabled' => !empty($output['can_report']) && $context['folder'] !== 'sent' && $output['member']['id'] != $this->user->id, |
|
217
|
|
|
'submenu' => true, |
|
218
|
|
|
], |
|
219
|
|
|
// Showing all then give a remove item checkbox |
|
220
|
|
|
'inline_mod_check' => [ |
|
221
|
|
|
'id' => 'deletedisplay' . $output['id'], |
|
222
|
|
|
'class' => 'inline_mod_check', |
|
223
|
|
|
'enabled' => empty($context['display_mode']), |
|
224
|
|
|
'custom' => 'onclick="document.getElementById(\'deletelisting', $output['id'], '\').checked = this.checked;"', |
|
225
|
|
|
'checkbox' => 'always', |
|
226
|
|
|
'name' => 'pms', |
|
227
|
|
|
'value' => $output['id'], |
|
228
|
|
|
] |
|
229
|
|
|
]; |
|
230
|
|
|
|
|
231
|
|
|
// Drop any non-enabled ones |
|
232
|
|
|
$pmButtons = array_filter($pmButtons, static fn($button) => !isset($button['enabled']) || (bool) $button['enabled']); |
|
233
|
|
|
|
|
234
|
|
|
return ['pmbuttons' => $pmButtons]; |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|