forked from trhoppe/roadraceautox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroupsubscription.php
360 lines (301 loc) · 11.1 KB
/
groupsubscription.php
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
351
352
353
354
355
356
357
358
359
360
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.2.0 Patch Level 3 - Licence Number VBFBED0615
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2012 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'groupsubscription');
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
'user',
'forumdisplay',
'socialgroups'
);
// get special data templates from the datastore
$specialtemplates = array(
'iconcache',
'noavatarperms'
);
// pre-cache templates used by all actions
$globaltemplates = array(
'USERCP_SHELL'
);
$actiontemplates = array(
'viewsubscription' => array(
'forumdisplay_sortarrow',
'socialgroups_discussion',
'socialgroups_groupsub_bit',
'socialgroups_subscriptions',
'usercp_nav_folderbit'
)
);
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'viewsubscription';
}
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_user.php');
require_once(DIR . '/includes/functions_socialgroup.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
verify_forum_url();
$vbulletin->input->clean_array_gpc('r', array(
'groupid' => TYPE_UINT,
'gmid' => TYPE_UINT,
'discussionid' => TYPE_UINT
));
if ((!$vbulletin->userinfo['userid'] AND $_REQUEST['do'] != 'unsubscribe')
OR ($vbulletin->userinfo['userid'] AND !($permissions['forumpermissions'] & $vbulletin->bf_ugp_forumpermissions['canview']))
OR $vbulletin->userinfo['usergroupid'] == 4
OR !($permissions['genericoptions'] & $vbulletin->bf_ugp_genericoptions['isnotbannedgroup']))
{
print_no_permission();
}
// start the navbits breadcrumb
$navbits = array('usercp.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['user_control_panel']);
// ############################### start view threads ###############################
if ($_REQUEST['do'] == 'viewsubscription')
{
if (!($vbulletin->options['socnet'] & $vbulletin->bf_misc_socnet['enable_groups'])
OR !($vbulletin->userinfo['permissions']['socialgrouppermissions'] & $vbulletin->bf_ugp_socialgrouppermissions['canviewgroups'])
OR !$vbulletin->options['socnet_groups_msg_enabled']
)
{
print_no_permission();
}
// Get pagenav
$vbulletin->input->clean_array_gpc('r', array(
'perpage' => TYPE_UINT,
'pagenumber' => TYPE_UINT,
'sort' => TYPE_NOHTML,
'order' => TYPE_NOHTML
));
$perpage = (!$vbulletin->GPC['perpage'] OR $vbulletin->GPC['perpage'] > $vbulletin->options['sg_maxperpage']) ? $vbulletin->options['sg_perpage'] : $vbulletin->GPC['perpage'];
// get sorting
$desc = ('asc' == $vbulletin->GPC['order']) ? false : true;
$sortfield = $vbulletin->GPC['sort'];
// Create message collection
require_once(DIR . '/includes/class_groupmessage.php');
$collection_factory = new vB_Group_Collection_Factory($vbulletin);
$collection = $collection_factory->create('discussion', false, $vbulletin->GPC['pagenumber'], $perpage, $desc);
$collection->set_ignore_marking(false);
$collection->filter_show_unsubscribed(false);
$collection->filter_sort_field($sortfield);
// Get counts
list($start, $end, $shown, $totaldiscussions) = array_values($collection->fetch_counts());
$pagenumber = $collection->fetch_pagenumber();
// Check if the user is subscribed to any discussions
if ($totaldiscussions)
{
// Create bit factory
$bit_factory = new vB_Group_Bit_Factory($vbulletin, $itemtype);
// Build message bits for all items
$messagebits = '';
while ($item = $collection->fetch_item())
{
$group = fetch_socialgroupinfo($item['groupid']);
// add group name to message
$group['name'] = fetch_word_wrapped_string(fetch_censored_text($group['name']));
// force everything to be visible
if ('deleted' == $item['state'])
{
$item['state'] = 'visible';
}
// add bit
$bit =& $bit_factory->create($item, $group);
$bit->show_moderation_tools(false);
$bit->show_subscription(true);
// always show inline selection
$bit->force_inline_selection(true);
$discussionbits .= $bit->construct();
}
}
unset($bit, $bit_factory, $collection_factory, $collection);
$pagevars = array();
if ($perpage)
{
$pagevars['pp'] = $perpage;
}
if ($sortfield)
{
$pagevars['sort'] = $sortfield;
}
if (!$desc)
{
$pagevars['order'] = 'asc';
}
// Construct pagenav
$pagenav = construct_page_nav($pagenumber, $perpage, $totaldiscussions, '', '', '', 'groupsub', array(), $pagevars);
// Sort helpers
$oppositesort = $desc ? 'asc' : 'desc';
$orderlinks = array();
$sorts = array('replies', 'dateline', 'lastpost', 'subscription');
foreach ($sorts as $sort)
{
$pagevars['sort'] = $sort;
unset($pagevars['order']);
if ($sortfield == $sort)
{
$pagevars['order'] = $oppositesort;
}
$orderlinks[$sort] = fetch_seo_url('groupsub', array(), $pagevars);
}
$templater = vB_Template::create('forumdisplay_sortarrow');
$templater->register('oppositesort', $oppositesort);
$sortarrow["$sortfield"] = $templater->render();
$group_subscribe_list = '';
if ($pagenumber <= 1)
{
// show group subscriptions on page one
require_once(DIR . '/includes/class_socialgroup_search.php');
$socialgroupsearch = new vB_SGSearch($vbulletin);
$socialgroupsearch->add('subscribed', $vbulletin->userinfo['userid']);
$socialgroupsearch->set_sort('lastpost', 'ASC');
if ($numsocialgroups = $socialgroupsearch->execute(true))
{
foreach ($socialgroupsearch->fetch_results() AS $group)
{
$group = prepare_socialgroup($group);
$show['lastpostinfo'] = ($group['lastpost'] ? true : false);
switch ($group['emailupdate'])
{
case 'daily': $group['notification'] = $vbphrase['daily']; break;
case 'weekly': $group['notification'] = $vbphrase['weekly']; break;
case 'none':
default:
$group['notification'] = $vbphrase['none'];
}
$templater = vB_Template::create('socialgroups_groupsub_bit');
$templater->register('group', $group);
$group_subscribe_list .= $templater->render();
}
}
}
// Construct navbits
$navbits = array(
'usercp.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['user_control_panel'],
'' => $vbphrase['group_subscriptions']
);
$navbits = construct_navbits($navbits);
// Construct cp nav
construct_usercp_nav('socialgroups');
//this creates the "$forumjump" global parameter, but this doesn't appear to be used anywhere
//on the page.
$navpopup = array(
'id' => 'groupsub_navpopup',
'title' => $vbphrase['group_subscriptions'],
'link' => fetch_seo_url('groupsub', array()),
);
construct_quick_nav($navpopup);
$navbar = render_navbar_template($navbits);
$templater = vB_Template::create('socialgroups_subscriptions');
$templater->register('discussionbits', $discussionbits);
$templater->register('forumjump', $forumjump);
$templater->register('gobutton', $gobutton);
$templater->register('group_subscribe_list', $group_subscribe_list);
$templater->register('orderlinks', $orderlinks);
$templater->register('pagenav', $pagenav);
$templater->register('pagenumber', $pagenumber);
$templater->register('perpage', $perpage);
$templater->register('sortarrow', $sortarrow);
$templater->register('totaldiscussions', $totaldiscussions);
$HTML = $templater->render();
$templater = vB_Template::create('USERCP_SHELL');
$templater->register_page_templates();
$templater->register('cpnav', $cpnav);
$templater->register('HTML', $HTML);
$templater->register('navbar', $navbar);
$templater->register('navclass', $navclass);
$templater->register('onload', $onload);
$templater->register('pagetitle', $pagetitle);
$templater->register('template_hook', $template_hook);
print_output($templater->render());
}
// ########################## Bulk Subscription Updates ##############################
if ($_POST['do'] == 'noemail' OR $_POST['do'] == 'instantemail' OR $_POST['do'] == 'delete')
{
if (!($discussionlist = $vbulletin->input->clean_gpc('r', 'gdiscussionlist', TYPE_ARRAY_KEYS_INT)))
{
standard_error(fetch_error('you_did_not_select_any_valid_discussions'));
}
$discussionlist = implode(',', $vbulletin->GPC['gdiscussionlist']);
}
// ########################## Delete Subscriptions ###################################
if ($_POST['do'] == 'delete')
{
// Set message state
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "subscribediscussion
WHERE discussionid IN ($discussionlist)
AND userid = " . $vbulletin->userinfo['userid']
);
print_standard_redirect('subupdate');
}
// ########################## Update Subscription ###################################
if ($_POST['do'] == 'noemail' OR $_POST['do'] == 'instantemail')
{
// Set message state
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "subscribediscussion
SET emailupdate = '" . ($_POST['do'] == 'noemail' ? 0 : 1) . "'
WHERE discussionid IN ($discussionlist)
AND userid = " . $vbulletin->userinfo['userid']
);
print_standard_redirect('subupdate');
}
// ###############################################################
if ($_POST['do'] == 'updategroup')
{
$vbulletin->input->clean_array_gpc('p', array(
'grouplist' => TYPE_ARRAY_UINT,
'act' => TYPE_STR
));
if ($vbulletin->GPC['grouplist'])
{
$grouplist = implode(',', $vbulletin->GPC['grouplist']);
$update_type = '';
switch ($vbulletin->GPC['act'])
{
case 'delete':
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "subscribegroup
WHERE groupid IN ($grouplist)
AND userid = " . $vbulletin->userinfo['userid']
);
break;
case 'daily':
case 'weekly':
case 'none':
$update_type = $vbulletin->GPC['act'];
}
if ($update_type)
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "subscribegroup
SET emailupdate = '" . $db->escape_string($update_type) . "'
WHERE groupid IN ($grouplist)
AND userid = " . $vbulletin->userinfo['userid']
);
}
}
print_standard_redirect('subupdate');
}
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 16:29, Sun Dec 9th 2012
|| # CVS: $RCSfile$ - $Revision: 26399 $
|| ####################################################################
\*======================================================================*/
?>