1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Discussion plugin |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Initialize the discussion component |
8
|
|
|
* |
9
|
|
|
* @return void |
10
|
|
|
*/ |
11
|
|
|
function discussion_init() { |
12
|
|
|
|
13
|
31 |
|
// prevent comments on closed discussions |
14
|
|
|
elgg_register_plugin_hook_handler('permissions_check:comment', 'object', 'discussion_comment_permissions'); |
15
|
31 |
|
|
16
|
|
|
// add link to owner block |
17
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'discussion_owner_block_menu'); |
18
|
31 |
|
|
19
|
|
|
elgg_extend_view('object/elements/imprint/contents', 'discussion/imprint/status'); |
20
|
|
|
|
21
|
31 |
|
// add the forum tool option |
22
|
|
|
add_group_tool_option('forum', elgg_echo('groups:enableforum'), true); |
23
|
|
|
elgg_extend_view('groups/tool_latest', 'discussion/group_module'); |
24
|
31 |
|
|
25
|
31 |
|
// notifications |
26
|
|
|
elgg_register_plugin_hook_handler('get', 'subscriptions', 'discussion_get_subscriptions'); |
27
|
|
|
elgg_register_notification_event('object', 'discussion'); |
28
|
31 |
|
elgg_register_plugin_hook_handler('prepare', 'notification:create:object:discussion', 'discussion_prepare_notification'); |
29
|
31 |
|
elgg_register_plugin_hook_handler('prepare', 'notification:create:object:comment', 'discussion_prepare_comment_notification'); |
30
|
31 |
|
|
31
|
31 |
|
// allow to be liked |
32
|
|
|
elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion', 'Elgg\Values::getTrue'); |
33
|
|
|
|
34
|
31 |
|
// Add latest discussions tab to /groups/all page |
35
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:filter:groups/all', 'discussion_setup_groups_filter_tabs'); |
36
|
|
|
|
37
|
31 |
|
// register database seed |
38
|
31 |
|
elgg_register_plugin_hook_handler('seeds', 'database', 'discussion_register_db_seeds'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Add owner block link for groups |
43
|
|
|
* |
44
|
|
|
* @param string $hook 'register' |
45
|
|
|
* @param string $type 'menu:owner_block' |
46
|
|
|
* @param ElggMenuItem[] $return current return value |
47
|
|
|
* @param array $params supplied params |
48
|
|
|
* |
49
|
|
|
* @return void|ElggMenuItem[] |
50
|
|
|
*/ |
51
|
|
|
function discussion_owner_block_menu($hook, $type, $return, $params) { |
|
|
|
|
52
|
|
|
|
53
|
|
|
$entity = elgg_extract('entity', $params); |
54
|
|
|
if (!$entity instanceof ElggGroup) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (!$entity->isToolEnabled('forum')) { |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$url = elgg_generate_url('collection:object:discussion:group', [ |
63
|
|
|
'guid' => $entity->guid, |
64
|
|
|
]); |
65
|
|
|
$item = new ElggMenuItem('discussion', elgg_echo('discussion:group'), $url); |
66
|
|
|
$return[] = $item; |
67
|
|
|
|
68
|
|
|
return $return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Prepare a notification message about a new discussion topic |
73
|
|
|
* |
74
|
|
|
* @param string $hook Hook name |
75
|
|
|
* @param string $type Hook type |
76
|
|
|
* @param Elgg\Notifications\Notification $notification The notification to prepare |
77
|
|
|
* @param array $params Hook parameters |
78
|
|
|
* |
79
|
|
|
* @return Elgg\Notifications\Notification |
80
|
|
|
*/ |
81
|
|
|
function discussion_prepare_notification($hook, $type, $notification, $params) { |
|
|
|
|
82
|
|
|
$entity = $params['event']->getObject(); |
83
|
|
|
$owner = $params['event']->getActor(); |
84
|
|
|
$language = $params['language']; |
85
|
|
|
|
86
|
|
|
$descr = $entity->description; |
87
|
|
|
$title = $entity->title; |
88
|
|
|
|
89
|
|
|
$notification->subject = elgg_echo('discussion:topic:notify:subject', [$title], $language); |
90
|
|
|
$notification->body = elgg_echo('discussion:topic:notify:body', [ |
91
|
|
|
$owner->name, |
92
|
|
|
$title, |
93
|
|
|
$descr, |
94
|
|
|
$entity->getURL() |
95
|
|
|
], $language); |
96
|
|
|
$notification->summary = elgg_echo('discussion:topic:notify:summary', [$entity->title], $language); |
97
|
|
|
$notification->url = $entity->getURL(); |
98
|
|
|
|
99
|
|
|
return $notification; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Prepare a notification message about a new comment on a discussion |
104
|
|
|
* |
105
|
|
|
* @param string $hook Hook name |
106
|
|
|
* @param string $type Hook type |
107
|
|
|
* @param Elgg\Notifications\Notification $notification The notification to prepare |
108
|
3 |
|
* @param array $params Hook parameters |
109
|
3 |
|
* |
110
|
3 |
|
* @return void|Elgg\Notifications\Notification |
111
|
|
|
*/ |
112
|
|
|
function discussion_prepare_comment_notification($hook, $type, $notification, $params) { |
|
|
|
|
113
|
|
|
|
114
|
|
|
$event = elgg_extract('event', $params); |
115
|
|
|
if (!$event instanceof Elgg\Notifications\NotificationEvent) { |
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$comment = $event->getObject(); |
120
|
|
|
if (!$comment instanceof ElggComment) { |
121
|
|
|
return; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$discussion = $comment->getContainerEntity(); |
125
|
|
|
if (!$discussion instanceof ElggDiscussion) { |
126
|
|
|
return; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$language = elgg_extract('language', $params); |
130
|
|
|
|
131
|
|
|
$poster = $comment->getOwnerEntity(); |
132
|
|
|
|
133
|
|
|
$notification->subject = elgg_echo('discussion:comment:notify:subject', [$discussion->getDisplayName()], $language); |
134
|
|
|
$notification->summary = elgg_echo('discussion:comment:notify:summary', [$discussion->getDisplayName()], $language); |
135
|
|
|
$notification->body = elgg_echo('discussion:comment:notify:body', [ |
136
|
|
|
$poster->getDisplayName(), |
137
|
|
|
$discussion->getDisplayName(), |
138
|
|
|
$comment->description, |
139
|
|
|
$comment->getURL(), |
140
|
|
|
], $language); |
141
|
|
|
$notification->url = $comment->getURL(); |
142
|
|
|
|
143
|
|
|
return $notification; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Add group members to the comment subscriber on a discussion |
148
|
|
|
* |
149
|
|
|
* @param string $hook 'get' |
150
|
|
|
* @param string $type 'subscriptions' |
151
|
|
|
* @param array $subscriptions Array containing subscriptions in the form |
152
|
|
|
* <user guid> => array('email', 'site', etc.) |
153
|
|
|
* @param array $params Hook parameters |
154
|
|
|
* |
155
|
|
|
* @return void|array |
156
|
|
|
*/ |
157
|
|
|
function discussion_get_subscriptions($hook, $type, $subscriptions, $params) { |
|
|
|
|
158
|
|
|
|
159
|
|
|
$event = elgg_extract('event', $params); |
160
|
|
|
if (!$event instanceof Elgg\Notifications\NotificationEvent) { |
161
|
|
|
return; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$comment = $event->getObject(); |
165
|
|
|
if (!$comment instanceof ElggComment) { |
166
|
|
|
return; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
$discussion = $comment->getContainerEntity(); |
170
|
|
|
if (!$discussion instanceof ElggDiscussion) { |
171
|
|
|
return; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$container = $discussion->getContainerEntity(); |
175
|
|
|
if (!$container instanceof ElggGroup) { |
176
|
|
|
return; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$group_subscriptions = elgg_get_subscriptions_for_container($container->guid); |
180
|
|
|
|
181
|
|
|
return ($subscriptions + $group_subscriptions); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Make sure that discussion comments can not be written to a discussion after it has been closed |
186
|
|
|
* |
187
|
|
|
* @param string $hook 'container_logic_check' |
188
|
|
|
* @param string $type 'object' |
189
|
|
|
* @param array $return Allowed or not |
190
|
|
|
* @param array $params Hook params |
191
|
|
|
* |
192
|
|
|
* @return void|false |
193
|
|
|
*/ |
194
|
|
|
function discussion_comment_permissions($hook, $type, $return, $params) { |
|
|
|
|
195
|
|
|
|
196
|
|
|
$discussion = elgg_extract('entity', $params); |
197
|
|
|
if (!$discussion instanceof ElggDiscussion) { |
198
|
|
|
return; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
if ($discussion->status == 'closed') { |
202
|
|
|
// do not allow new comments in closed discussions |
203
|
|
|
return false; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Prepare discussion topic form variables |
209
|
|
|
* |
210
|
|
|
* @param ElggObject $topic Topic object if editing |
211
|
|
|
* @return array |
212
|
|
|
*/ |
213
|
|
|
function discussion_prepare_form_vars($topic = null) { |
214
|
|
|
// input names => defaults |
215
|
|
|
$values = [ |
216
|
|
|
'title' => '', |
217
|
|
|
'description' => '', |
218
|
|
|
'status' => '', |
219
|
|
|
'access_id' => ACCESS_DEFAULT, |
220
|
|
|
'tags' => '', |
221
|
|
|
'container_guid' => elgg_get_page_owner_guid(), |
222
|
|
|
'guid' => null, |
223
|
|
|
'topic' => $topic, |
224
|
|
|
'entity' => $topic, |
225
|
|
|
]; |
226
|
|
|
|
227
|
|
|
if ($topic) { |
228
|
|
|
foreach (array_keys($values) as $field) { |
229
|
|
|
if (isset($topic->$field)) { |
230
|
|
|
$values[$field] = $topic->$field; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
} |
234
|
2 |
|
|
235
|
2 |
|
if (elgg_is_sticky_form('topic')) { |
236
|
|
|
$sticky_values = elgg_get_sticky_values('topic'); |
237
|
|
|
foreach ($sticky_values as $key => $value) { |
238
|
|
|
$values[$key] = $value; |
239
|
2 |
|
} |
240
|
2 |
|
} |
241
|
2 |
|
|
242
|
|
|
elgg_clear_sticky_form('topic'); |
243
|
|
|
|
244
|
|
|
return $values; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Add latest discussions tab to /groups/all page |
249
|
|
|
* |
250
|
|
|
* @param string $hook "register" |
251
|
|
|
* @param string $type "menu:filter:groups/all" |
252
|
|
|
* @param ElggMenuItem[] $return Menu |
253
|
|
|
* @param array $params Hook params |
254
|
|
|
* @return ElggMenuItem[] |
255
|
|
|
*/ |
256
|
|
|
function discussion_setup_groups_filter_tabs($hook, $type, $return, $params) { |
|
|
|
|
257
|
|
|
|
258
|
|
|
$filter_value = elgg_extract('filter_value', $params); |
259
|
|
|
|
260
|
|
|
$return[] = ElggMenuItem::factory([ |
261
|
|
|
'name' => 'discussion', |
262
|
|
|
'text' => elgg_echo('discussion:latest'), |
263
|
|
|
'href' => 'groups/all?filter=discussion', |
264
|
|
|
'priority' => 500, |
265
|
|
|
'selected' => $filter_value == 'discussion', |
266
|
|
|
]); |
267
|
|
|
|
268
|
|
|
return $return; |
269
|
|
|
} |
270
|
|
|
|
271
|
1 |
|
|
272
|
1 |
|
/** |
273
|
1 |
|
* Register database seed |
274
|
|
|
* |
275
|
|
|
* @elgg_plugin_hook seeds database |
276
|
|
|
* |
277
|
|
|
* @param \Elgg\Hook $hook Hook |
278
|
|
|
* @return array |
279
|
|
|
*/ |
280
|
|
|
function discussion_register_db_seeds(\Elgg\Hook $hook) { |
281
|
|
|
|
282
|
|
|
$seeds = $hook->getValue(); |
283
|
|
|
|
284
|
|
|
$seeds[] = \Elgg\Discussions\Seeder::class; |
285
|
|
|
|
286
|
|
|
return $seeds; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
return function() { |
290
|
|
|
elgg_register_event_handler('init', 'system', 'discussion_init'); |
291
|
|
|
}; |
292
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.