/
base.php
462 lines (414 loc) · 12.2 KB
/
base.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<?php
/* ======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.2.2 Alpha 1 - Licence Number VBFSA2W3VC
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2013 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 # ||
|| #################################################################### ||
\*====================================================================== */
abstract class vB_ActivityStream_View_Perm_Base
{
/**
* Classes that must execute before this one
* Example. post->process() must execute before thread->process() so that threadids from the posts can
* be added to the thread content array.
*
* @var Array
*/
protected $requireFirst = array();
/**
* Classes that are required for this one to work
* Example. The post class is going to generate threadids so the thread class must also be loaded, which it possibly
* wouldn't be if this stream had no threads (new thread), just posts (new reply).
*
* @var Array
*/
protected $requireExist = array();
/*
*
*/
protected $content = array();
/*
*
*/
protected $vbphrase = array();
/**
* Processed users tracker
*
*/
protected $usersdone = false;
/**
* Constructor - info about this content
*
* @param array
*
*/
public function __construct(&$content, &$vbphrase)
{
$this->content =& $content;
$this->vbphrase =& $vbphrase;
}
/**
* Retrieve data once contentids have been set
*
* At the end of the function, set the idlist to an empty array so that if further records
* are requested, the already retrieved ids won't be needlessy retrieved again
*
*/
public function process()
{
}
/*
*
*/
public function setRequiredFirst($value)
{
$this->requireFirst[$value] = 1;
}
/*
*
*/
public function setRequiredExist($value)
{
$this->requireExist[$value] = 1;
}
/*
*
*/
public function fetchRequiredExist()
{
return $this->requireExist;
}
/*
* Fetch permission to view this activity
*
* return boolean
*/
public function fetchCanView($activity)
{
return true;
}
/*
*
*
*/
public function verifyRequiredFirst(&$classes, $done)
{
if (!$this->requireFirst)
{
return true;
}
else
{
$okay = true;
$need = array();
foreach ($this->requireFirst AS $classname => $null)
{
if (!$done[$classname] AND $classes[$classname])
{
$okay = false;
$need[] = $classname;
}
}
if (!$okay)
{
$this->sort($classes);
return false;
}
else
{
return true;
}
}
}
public function sort(&$classes)
{
$thisclass = get_class($this);
$new = array();
foreach ($classes AS $classname => $object)
{
if ($new[$classname])
{
continue;
}
if ($classname == $thisclass)
{
foreach ($this->requireFirst AS $_classname => $null)
{
if (!$classes[$_classname])
{
continue;
}
$new[$_classname] = $classes[$_classname];
}
$new[$classname] = $object;
}
else
{
$new[$classname] = $object;
}
}
$classes = $new;
}
/*
* Register Template
*
* @param string Template Name
* @param array Activity Record
*
* @return string Template
*/
abstract public function fetchTemplate($templatename, $activity, $skipgroup = false, $fetchphrase = false);
public function fetchPhrase($templatename, $activity, $skipgroup = false)
{
return $this->fetchTemplate($templatename, $activity, $skipgroup, true);
}
protected function processRecord(&$activity)
{
return;
}
protected function parse_array($array, $index)
{
$return = array();
$length = strlen($index);
foreach($array AS $key => $value)
{
if (strpos($key, $index, 0) !== false)
{
$return[substr($key, $length)] = $value;
}
}
return $return;
}
protected function processPicturecommentids()
{
if (!$this->content['picturecommentid'])
{
return true;
}
$comments = vB::$db->query_read_slave("
SELECT
p.commentid, p.postuserid, p.postuserid AS userid, p.postusername, p.state, p.title, p.dateline, p.pagetext,
p.sourcecontentid, p.sourcecontenttypeid, p.postusername,
a.attachmentid, a.dateline AS adateline, fd.thumbnail_width, fd.thumbnail_height, a.counter
FROM " . TABLE_PREFIX . "picturecomment AS p
INNER JOIN " . TABLE_PREFIX . "attachment AS a ON (a.attachmentid = p.sourceattachmentid)
INNER JOIN " . TABLE_PREFIX . "filedata AS fd ON (a.filedataid = fd.filedataid)
WHERE
p.commentid IN (" . implode(",", array_keys($this->content['picturecommentid'])) . ")
AND
p.state <> 'deleted'
");
while ($comment = vB::$db->fetch_array($comments))
{
$this->content['userid'][$comment['postuserid']] = 1;
$class = vB_Types::instance()->getContentClassFromId($comment['sourcecontenttypeid']);
if ($class['package'] = 'Forum' AND $class['class'] == 'SocialGroup')
{
$comment['groupid'] = $comment['sourcecontentid'];
$this->content['socialgroup_picturecomment'][$comment['commentid']] = $comment;
$this->content['socialgroup_attachmentid'][$comment['attachmentid']] = 1;
}
else if ($class['package'] = 'Forum' AND $class['class'] == 'Album')
{
$comment['albumid'] = $comment['sourcecontentid'];
$this->content['album_picturecomment'][$comment['commentid']] = $comment;
$this->content['album_attachmentid'][$comment['attachmentid']] = 1;
}
}
// unset picture commentids so that these only get processed once, either by socialgroups or albums
unset($this->content['picturecommentid']);
}
/*
* Why are we querying users directly and not joining in the other queries?
*
* Avatars are the main reason. If we join then it gets complicated with the
* cache system. We query all messages before discussions and group. The discussion and group belonging to the
* message is then cached so we don't have to query for them individually.
* Take a group message query. We have to join one for the message, once
* for the discussion, and once for the group. All within the same query. This query
* is fast and, in the end, probably faster than joining in all of the other queries
* especially when some will be redundant.
*
*/
protected function processUsers()
{
if (!$this->content['userid'])
{
return;
}
/* This bit handles processUsers() being executed multiple times .. remove any users that we already know about
* and only query if we have any unknown users left
*/
if ($this->content['user'])
{
foreach ($this->content['user'] AS $userid => $foo)
{
unset($this->content['userid'][$userid]);
}
if (!$this->content['userid'])
{
return;
}
}
require_once(DIR . '/includes/functions_user.php');
$users = vB::$db->query_read("
SELECT u.*
" . (vB::$vbulletin->options['avatarenabled'] ? ", av.avatarpath, NOT ISNULL(cu.userid) AS hascustomavatar,
cu.dateline AS avatardateline, cu.width AS avwidth, cu.height AS avheight, cu.height_thumb AS avheight_thumb,
cu.width_thumb AS avwidth_thumb, NOT ISNULL(cu.filedata_thumb) AS filedata_thumb" : "") . "
" . (vB::$vbulletin->userinfo['userid'] ? ",IF(userlist.userid IS NOT NULL, 1, 0) AS bbuser_iscontact_of_user" : "") . "
FROM " . TABLE_PREFIX . "user AS u
" . (vB::$vbulletin->options['avatarenabled'] ? "
LEFT JOIN " . TABLE_PREFIX . "avatar AS av ON(av.avatarid = u.avatarid)
LEFT JOIN " . TABLE_PREFIX . "customavatar AS cu ON(cu.userid = u.userid)" : "") . "
" . (vB::$vbulletin->userinfo['userid'] ? "LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist ON (userlist.userid = u.userid AND userlist.type = 'buddy' AND userlist.relationid = " . vB::$vbulletin->userinfo['userid'] . ")" : "") . "
WHERE u.userid IN (" . implode(",", array_keys($this->content['userid'])) . ")
");
while ($user = vB::$db->fetch_array($users))
{
$user = array_merge($user , convert_bits_to_array($user['options'], vB::$vbulletin->bf_misc_useroptions));
fetch_avatar_from_userinfo($user, true);
cache_permissions($user, false);
if (
empty($user['avatarurl'])
OR
(!$user['avatarid'] AND !($user['permissions']['genericpermissions'] & vB::$vbulletin->bf_ugp_genericpermissions['canuseavatar']) AND !$user['adminavatar'])
)
{
$user['avatarurl'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . '/unknown.gif';
$user['showavatar'] = true;
$user['avatarclass'] = 'hasavatar';
}
else if (vB::$vbulletin->userinfo['userid'] AND !vB::$vbulletin->userinfo['showavatars'])
{
$user['showavatar'] = false;
$user['avatarclass'] = 'noavatar';
}
else
{
$user['showavatar'] = true;
$user['avatarclass'] = 'hasavatar';
}
$this->content['user'][$user['userid']] = $user;
}
if (!$this->content['user'])
{
$this->content['user'] = array();
}
/*
* Reset the array so that if processUsers() is executed again we won't query anything
* unless new ids have been added to the array
*/
$this->content['userid'] = array();
}
/*
* Retrieve a user from the cache
* If no user then send back some guest stuff
*
* @param int userid to grab
* @param string Alternate username to use if this is a guest
*
* @return array User info
*/
protected function fetchUser($userid, $username = '')
{
global $vbphrase;
if ($this->content['user'][$userid])
{ // avatar stuff set by processUsers()
return $this->content['user'][$userid];
}
else // Guest
{
$showavatar = ((!vB::$vbulletin->userinfo['userid'] OR vB::$vbulletin->userinfo['showavatars']) AND vB::$vbulletin->options['avatarenabled']);
return array(
'userid' => 0,
'username' => $username ? $username : $vbphrase['unregistered'],
'avatarurl' => vB_Template_Runtime::fetchStyleVar('imgdir_misc') . '/unknown.gif',
'showavatar' => $showavatar,
'avatarclass' => $showavatar ? 'hasavatar' : 'noavatar',
);
}
}
protected function fetchCanViewMembers()
{
return (vB::$vbulletin->userinfo['permissions']['genericpermissions'] & vB::$vbulletin->bf_ugp_genericpermissions['canviewmembers']);
}
protected function fetchCanViewVisitorMessage($vmid)
{
if (!($message = $this->content['visitormessage'][$vmid]))
{
return false;
}
if (!($userinfo = $this->content['user'][$message['userid']]))
{
return false;
}
if ($userinfo['usergroupid'] == 4 AND !(vB::$vbulletin->userinfo['permissions']['adminpermissions'] & vB::$vbulletin->bf_ugp_adminpermissions['cancontrolpanel']))
{
return false;
}
if ((
$userinfo['vm_contactonly']
AND
!can_moderate(0,'canmoderatevisitormessages')
AND
$userinfo['userid'] != vB::$vbulletin->userinfo['userid']
AND
!$userinfo['bbuser_iscontact_of_user']
)
OR
(
!$userinfo['vm_enable']
AND
(
!can_moderate(0,'canmoderatevisitormessages')
OR
vB::$vbulletin->userinfo['userid'] == $userinfo['userid']
)
)
)
{
return false;
}
if (
!$this->fetchCanViewMembers()
OR
!(vB::$vbulletin->userinfo['forumpermissions'] & vB::$vbulletin->bf_ugp_forumpermissions['canview'])
OR
!(vB::$vbulletin->options['socnet'] & vB::$vbulletin->bf_misc_socnet['enable_visitor_messaging'])
)
{
return false;
}
if (!$this->content['user'][$message['userid']])
{
return false;
}
if (!can_view_profile_section($message['userid'], 'visitor_messaging'))
{
return false;
}
require_once(DIR . '/includes/functions_visitormessage.php');
if (
$message['state'] == 'moderation'
AND
!fetch_visitor_message_perm('canmoderatevisitormessages', $this->content['user'][$message['userid']], $message)
AND
$message['postuserid'] != vB::$vbulletin->userinfo['userid']
)
{
return false;
}
return true;
}
}
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 03:13, Sat Sep 7th 2013
|| # CVS: $RCSfile$ - $Revision: 57655 $
|| ####################################################################
\*======================================================================*/