forked from 0bill0/threads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
350 lines (297 loc) · 9.92 KB
/
start.php
File metadata and controls
350 lines (297 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
/**
* Elgg threaded discussions plugin
*
* @package ElggThreads
*/
elgg_register_event_handler('init', 'system', 'threads_init');
/**
* Initialize the threads plugin
*/
function threads_init() {
elgg_register_library('elgg:discussion', elgg_get_plugins_path() . 'threads/lib/discussion.php');
elgg_register_library('elgg:threads', elgg_get_plugins_path() . 'threads/lib/threads.php');
elgg_register_page_handler('discussion', 'threads_page_handler');
elgg_register_page_handler('threaded_forums', 'threads_page_handler');
//elgg_register_entity_url_handler('object', 'groupforumtopic', 'threads_override_topic_url');
// commenting not allowed on discussion topics (use a different annotation)
//elgg_register_plugin_hook_handler('permissions_check:comment', 'object', 'threads_comment_override');
$action_base = elgg_get_plugins_path() . 'threads/actions/discussion';
elgg_register_action('discussion/save', "$action_base/save.php");
elgg_register_action('discussion/reply/save', "$action_base/reply/save.php");
elgg_register_action('discussion/reply/delete', "$action_base/reply/delete.php");
// add links to reply, edit or delete replies.
elgg_register_plugin_hook_handler('register', 'menu:reply', 'threads_reply_menu_setup');
// add link to owner block
//elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'threads_owner_block_menu');
/* Group module registers topics for search.
elgg_register_entity_type('object', 'groupforumtopic');*/
// because replies are not comments, need of our menu item
//elgg_register_plugin_hook_handler('register', 'menu:river', 'threads_add_to_river_menu');
/* Theese sentences are performed into groups module.
add_group_tool_option('forum', elgg_echo('groups:enableforum'), true);
elgg_extend_view('groups/tool_latest', 'discussion/group_module');*/
// notifications
/*register_notification_object('object', 'groupforumtopic', elgg_echo('groupforumtopic:new'));
elgg_register_plugin_hook_handler('object:notifications', 'object', 'group_object_notifications_intercept');
elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'groupforumtopic_notify_message');*/
// add link to reply topics
elgg_register_plugin_hook_handler('register', 'menu:river', 'threads_add_to_river_menu');
elgg_extend_view('css/elgg', 'discussion/css');
$threads_js = elgg_get_simplecache_url('js', 'threads');
elgg_register_js('elgg.threads', $threads_js);
$parsequery_js = 'mod/threads/vendors/jquery-plugins/parsequery.js';
elgg_register_js('jquery.plugins.parsequery', $parsequery_js);
// activity streams support
elgg_register_plugin_hook_handler('activitystreams:parent', 'entity', 'threads_activitystreams_parent');
elgg_register_plugin_hook_handler('activitystreams:object', 'river', 'threads_activitystreams_object');
elgg_register_event_handler('upgrade', 'system', 'threads_run_upgrades');
}
function threads_run_upgrades($event, $type, $details) {
if (include_once(elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php')) {
upgrade_module_run('threads');
}
}
function threads_activitystreams_object($hook, $type, $return, $params) {
$item = $params['item'];
$object = $item->getObjectEntity();
if (in_array($item->view, array('river/annotation/group_topic_post/reply'))) {
//$comment = elgg_get_annotation_from_id($item->annotation_id);
$entity = get_entity($item->annotation_id);
if ($entity)
return $entity;
}
return $return;
}
function threads_activitystreams_parent($hook, $type, $return, $params) {
$object = $params['entity'];
if ($object && $object->getSubtype() == 'topicreply') {
elgg_load_library('elgg:threads');
$parent = threads_parent($object->guid);
if ($parent) {
return $parent;
}
}
return $return;
}
/**
* Discussion page handler
*
* URLs take the form of
* All topics in site: discussion/all
* List topics in forum: discussion/owner/<guid>
* View discussion topic: discussion/view/<guid>
* Add discussion topic: discussion/add/<guid>
* Edit discussion topic: discussion/edit/<guid>
* Redirect old urls: threaded_forums/<guid> -> discussion/owner/<guid>
*
* @param array $page Array of url segments for routing
*/
function threads_page_handler($page, $handler) {
// Old urls
if ($handler == 'threaded_forums') {
forward('discussion/owner/' . $page[0]);
}
elgg_load_library('elgg:groups');
elgg_load_library('elgg:discussion');
elgg_push_breadcrumb(elgg_echo('discussion'), 'discussion/all');
switch ($page[0]) {
case 'all':
discussion_handle_all_page();
break;
case 'owner':
discussion_handle_list_page($page[1]);
break;
case 'add':
discussion_handle_edit_page('add', $page[1]);
break;
case 'edit':
discussion_handle_edit_page('edit', $page[1]);
break;
case 'view':
discussion_handle_view_page($page[1]);
break;
}
}
/**
* Override the discussion topic url
*
* @param ElggObject $entity Discussion topic
* @return string
*/
function threads_override_topic_url($entity) {
return 'discussion/view/' . $entity->guid;
}
/**
* We don't want people commenting on topics in the river
*/
function threads_comment_override($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'object', 'groupforumtopic')) {
return false;
}
}
/**
* Add owner block link
*/
function threads_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'group')) {
if ($params['entity']->forum_enable != "no") {
$url = "discussion/owner/{$params['entity']->guid}";
$item = new ElggMenuItem('discussion', elgg_echo('discussion:group'), $url);
$return[] = $item;
}
}
return $return;
}
/**
* Add the reply button for the river
*/
function threads_add_to_river_menu($hook, $type, $return, $params) {
if (elgg_is_logged_in() && !elgg_in_context('widgets')) {
$item = $params['item'];
$object = $item->getObjectEntity();
$reply = get_entity($item->annotation_id);
if (elgg_instanceof($object, 'object', 'groupforumtopic')) {
if ($reply) {
$group = $object->getContainerEntity();
if (($group && $group->canWriteToContainer()) || elgg_is_admin_logged_in()) {
$options = array(
'name' => 'reply',
'href' => "#groups-reply-$reply->guid",
'text' => elgg_view_icon('speech-bubble'),
'title' => elgg_echo('reply:this'),
'rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
}
}
}
}
return $return;
}
/**
* Event handler for group forum posts
*
*/
function threads_object_notifications($event, $object_type, $object) {
static $flag;
if (!isset($flag))
$flag = 0;
if (is_callable('object_notifications'))
if ($object instanceof ElggObject) {
if ($object->getSubtype() == 'groupforumtopic') {
//if ($object->countAnnotations('group_topic_post') > 0) {
if ($flag == 0) {
$flag = 1;
object_notifications($event, $object_type, $object);
}
//}
}
}
}
/**
* Intercepts the notification on group topic creation and prevents a notification from going out
* (because one will be sent on the annotation)
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
* @return unknown
*/
function threads_object_notifications_intercept($hook, $entity_type, $returnvalue, $params) {
if (isset($params)) {
if ($params['event'] == 'create' && $params['object'] instanceof ElggObject) {
if ($params['object']->getSubtype() == 'groupforumtopic') {
return true;
}
}
}
return null;
}
/**
* Returns a more meaningful message
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
/*function groupforumtopic_notify_message($hook, $entity_type, $returnvalue, $params) {
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'groupforumtopic')) {
$descr = $entity->description;
$title = $entity->title;
$url = $entity->getURL();
$msg = get_input('topicmessage');
if (empty($msg))
$msg = get_input('topic_post');
if (!empty($msg))
$msg = $msg . "\n\n"; else
$msg = '';
$owner = get_entity($entity->container_guid);
if ($method == 'sms') {
return elgg_echo("groupforumtopic:new") . ': ' . $url . " ({$owner->name}: {$title})";
} else {
return elgg_get_logged_in_user_entity()->name . ' ' . elgg_echo("groups:viagroups") . ': ' . $title . "\n\n" . $msg . "\n\n" . $entity->getURL();
}
}
return null;
}*/
/**
* A simple function to see who can edit a group discussion post
* @param the comment $entity
* @param user who owns the group $group_owner
* @return boolean
*/
function threads_can_edit_discussion($entity, $group_owner) {
//logged in user
$user = elgg_get_logged_in_user_guid();
if (($entity->owner_guid == $user) || $group_owner == $user || elgg_is_admin_logged_in()) {
return true;
} else {
return false;
}
}
/**
* Add edit and delete links for forum replies
*/
function threads_reply_menu_setup($hook, $type, $return, $params) {
if (elgg_in_context('widgets')) {
return $return;
}
$entity = $params['entity'];
if ($entity->type != 'object' || $entity->getSubtype() != 'topicreply') {
return $return;
}
if ($entity->canEdit()) {
$url = elgg_http_add_url_query_elements('action/discussion/reply/delete', array(
'entity_guid' => $entity->guid,
));
$options = array(
'name' => 'delete',
'href' => $url,
'text' => elgg_view_icon('delete'),
'confirm' => elgg_echo('deleteconfirm'),
'text_encode' => false,
'priority' => 500
);
$return[] = ElggMenuItem::factory($options);
$url = elgg_http_add_url_query_elements('', array(
'box' => 'edit',
'guid' => $entity->guid,
));
$options = array(
'name' => 'edit',
'href' => $url,
'text' => elgg_echo('edit'),
'text_encode' => false,
'priority' => 100,
);
$return[] = ElggMenuItem::factory($options);
}
return $return;
}