| [ Index ] |
PHP Cross Reference of MyBB 1.6.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: functions_forumlist.php 5623 2011-10-01 02:46:09Z ralgith $ 10 */ 11 12 /** 13 * Build a list of forum bits. 14 * 15 * @param int The parent forum to fetch the child forums for (0 assumes all) 16 * @param int The depth to return forums with. 17 * @return array Array of information regarding the child forums of this parent forum 18 */ 19 function build_forumbits($pid=0, $depth=1) 20 { 21 global $fcache, $moderatorcache, $forumpermissions, $theme, $mybb, $templates, $bgcolor, $collapsed, $lang, $showdepth, $plugins, $parser, $forum_viewers; 22 23 $forum_listing = ''; 24 25 // If no forums exist with this parent, do nothing 26 if(!is_array($fcache[$pid])) 27 { 28 return; 29 } 30 31 // Foreach of the forums in this parent 32 foreach($fcache[$pid] as $parent) 33 { 34 foreach($parent as $forum) 35 { 36 $forums = $subforums = $sub_forums = ''; 37 $lastpost_data = ''; 38 $counters = ''; 39 $forum_viewers_text = ''; 40 $forum_viewers_text_plain = ''; 41 42 // Get the permissions for this forum 43 $permissions = $forumpermissions[$forum['fid']]; 44 45 // If this user doesnt have permission to view this forum and we're hiding private forums, skip this forum 46 if($permissions['canview'] != 1 && $mybb->settings['hideprivateforums'] == 1) 47 { 48 continue; 49 } 50 51 $forum = $plugins->run_hooks("build_forumbits_forum", $forum); 52 53 // Build the link to this forum 54 $forum_url = get_forum_link($forum['fid']); 55 56 // This forum has a password, and the user isn't authenticated with it - hide post information 57 $hideinfo = false; 58 $hidelastpostinfo = false; 59 $showlockicon = 0; 60 if($permissions['canviewthreads'] != 1) 61 { 62 $hideinfo = true; 63 } 64 65 if($permissions['canonlyviewownthreads'] == 1) 66 { 67 $hideinfo = true; 68 $hidelastpostinfo = true; 69 } 70 71 if($forum['password'] != '' && $mybb->cookies['forumpass'][$forum['fid']] != md5($mybb->user['uid'].$forum['password'])) 72 { 73 $hideinfo = true; 74 $showlockicon = 1; 75 } 76 77 $lastpost_data = array( 78 "lastpost" => $forum['lastpost'], 79 "lastpostsubject" => $forum['lastpostsubject'], 80 "lastposter" => $forum['lastposter'], 81 "lastposttid" => $forum['lastposttid'], 82 "lastposteruid" => $forum['lastposteruid'] 83 ); 84 85 // Fetch subforums of this forum 86 if(isset($fcache[$forum['fid']])) 87 { 88 $forum_info = build_forumbits($forum['fid'], $depth+1); 89 90 // Increment forum counters with counters from child forums 91 $forum['threads'] += $forum_info['counters']['threads']; 92 $forum['posts'] += $forum_info['counters']['posts']; 93 $forum['unapprovedthreads'] += $forum_info['counters']['unapprovedthreads']; 94 $forum['unapprovedposts'] += $forum_info['counters']['unapprovedposts']; 95 $forum['viewers'] += $forum_info['counters']['viewing']; 96 97 // If the child forums' lastpost is greater than the one for this forum, set it as the child forums greatest. 98 if($forum_info['lastpost']['lastpost'] > $lastpost_data['lastpost']) 99 { 100 $lastpost_data = $forum_info['lastpost']; 101 102 /* 103 // If our subforum is unread, then so must be our parents. Force our parents to unread as well 104 if(strstr($forum_info['lightbulb']['folder'], "on") !== false) 105 { 106 $forum['lastread'] = 0; 107 } 108 // Otherwise, if we have an explicit record in the db, we must make sure that it is explicitly set 109 else 110 { 111 $lastpost_data['lastpost'] = $forum['lastpost']; 112 }*/ 113 } 114 115 $sub_forums = $forum_info['forum_list']; 116 } 117 118 // If we are hiding information (lastpost) because we aren't authenticated against the password for this forum, remove them 119 if($hideinfo == true || $hidelastpostinfo == true) 120 { 121 unset($lastpost_data); 122 } 123 124 // If the current forums lastpost is greater than other child forums of the current parent, overwrite it 125 if($lastpost_data['lastpost'] > $parent_lastpost['lastpost']) 126 { 127 $parent_lastpost = $lastpost_data; 128 } 129 130 if(is_array($forum_viewers) && $forum_viewers[$forum['fid']] > 0) 131 { 132 $forum['viewers'] = $forum_viewers[$forum['fid']]; 133 } 134 135 // Increment the counters for the parent forum (returned later) 136 if($hideinfo != true) 137 { 138 $parent_counters['threads'] += $forum['threads']; 139 $parent_counters['posts'] += $forum['posts']; 140 $parent_counters['unapprovedposts'] += $forum['unapprovedposts']; 141 $parent_counters['unapprovedthreads'] += $forum['unapprovedthreads']; 142 $parent_counters['viewers'] += $forum['viewers']; 143 } 144 145 // Done with our math, lets talk about displaying - only display forums which are under a certain depth 146 if($depth > $showdepth) 147 { 148 continue; 149 } 150 151 // Get the lightbulb status indicator for this forum based on the lastpost 152 $lightbulb = get_forum_lightbulb($forum, $lastpost_data, $showlockicon); 153 154 // Fetch the number of unapproved threads and posts for this forum 155 $unapproved = get_forum_unapproved($forum); 156 157 if($hideinfo == true) 158 { 159 unset($unapproved); 160 } 161 162 // Sanitize name and description of forum. 163 $forum['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&", $forum['name']); // Fix & but allow unicode 164 $forum['description'] = preg_replace("#&(?!\#[0-9]+;)#si", "&", $forum['description']); // Fix & but allow unicode 165 $forum['name'] = preg_replace("#&([^\#])(?![a-z1-4]{1,10};)#i", "&$1", $forum['name']); 166 $forum['description'] = preg_replace("#&([^\#])(?![a-z1-4]{1,10};)#i", "&$1", $forum['description']); 167 168 // If this is a forum and we've got subforums of it, load the subforums list template 169 if($depth == 2 && $sub_forums) 170 { 171 eval("\$subforums = \"".$templates->get("forumbit_subforums")."\";"); 172 } 173 // A depth of three indicates a comma separated list of forums within a forum 174 else if($depth == 3) 175 { 176 if($donecount < $mybb->settings['subforumsindex']) 177 { 178 $statusicon = ''; 179 180 // Showing mini status icons for this forum 181 if($mybb->settings['subforumsstatusicons'] == 1) 182 { 183 $lightbulb['folder'] = "mini".$lightbulb['folder']; 184 eval("\$statusicon = \"".$templates->get("forumbit_depth3_statusicon", 1, 0)."\";"); 185 } 186 187 // Fetch the template and append it to the list 188 eval("\$forum_list .= \"".$templates->get("forumbit_depth3", 1, 0)."\";"); 189 $comma = $lang->comma; 190 } 191 192 // Have we reached our max visible subforums? put a nice message and break out of the loop 193 ++$donecount; 194 if($donecount == $mybb->settings['subforumsindex']) 195 { 196 if(subforums_count($fcache[$pid]) > $donecount) 197 { 198 $forum_list .= $comma.$lang->sprintf($lang->more_subforums, (subforums_count($fcache[$pid]) - $donecount)); 199 } 200 } 201 continue; 202 } 203 204 205 // Forum is a category, set template type 206 if($forum['type'] == 'c') 207 { 208 $forumcat = '_cat'; 209 } 210 // Forum is a standard forum, set template type 211 else 212 { 213 $forumcat = '_forum'; 214 } 215 216 if($forum['linkto'] == '') 217 { 218 // No posts have been made in this forum - show never text 219 if(($lastpost_data['lastpost'] == 0 || $lastpost_data['lastposter'] == '') && $hideinfo != true) 220 { 221 $lastpost = "<div style=\"text-align: center;\">{$lang->lastpost_never}</div>"; 222 } 223 elseif($hideinfo != true) 224 { 225 // Format lastpost date and time 226 $lastpost_date = my_date($mybb->settings['dateformat'], $lastpost_data['lastpost']); 227 $lastpost_time = my_date($mybb->settings['timeformat'], $lastpost_data['lastpost']); 228 229 // Set up the last poster, last post thread id, last post subject and format appropriately 230 $lastpost_profilelink = build_profile_link($lastpost_data['lastposter'], $lastpost_data['lastposteruid']); 231 $lastpost_link = get_thread_link($lastpost_data['lastposttid'], 0, "lastpost"); 232 $lastpost_subject = $full_lastpost_subject = $parser->parse_badwords($lastpost_data['lastpostsubject']); 233 if(my_strlen($lastpost_subject) > 25) 234 { 235 $lastpost_subject = my_substr($lastpost_subject, 0, 25)."..."; 236 } 237 $lastpost_subject = htmlspecialchars_uni($lastpost_subject); 238 $full_lastpost_subject = htmlspecialchars_uni($full_lastpost_subject); 239 240 // Call lastpost template 241 if($depth != 1) 242 { 243 eval("\$lastpost = \"".$templates->get("forumbit_depth{$depth}_forum_lastpost")."\";"); 244 } 245 } 246 247 if($mybb->settings['showforumviewing'] != 0 && $forum['viewers'] > 0) 248 { 249 if($forum['viewers'] == 1) 250 { 251 $forum_viewers_text = $lang->viewing_one; 252 } 253 else 254 { 255 $forum_viewers_text = $lang->sprintf($lang->viewing_multiple, $forum['viewers']); 256 } 257 $forum_viewers_text_plain = $forum_viewers_text; 258 $forum_viewers_text = "<span class=\"smalltext\">{$forum_viewers_text}</span>"; 259 } 260 } 261 // If this forum is a link or is password protected and the user isn't authenticated, set lastpost and counters to "-" 262 if($forum['linkto'] != '' || $hideinfo == true) 263 { 264 $lastpost = "<div style=\"text-align: center;\">-</div>"; 265 $posts = "-"; 266 $threads = "-"; 267 } 268 // Otherwise, format thread and post counts 269 else 270 { 271 // If we're only hiding the last post information 272 if($hidelastpostinfo == true) 273 { 274 $lastpost = "<div style=\"text-align: center;\">-</div>"; 275 } 276 277 $posts = my_number_format($forum['posts']); 278 $threads = my_number_format($forum['threads']); 279 } 280 281 // Moderator column is not off 282 if($mybb->settings['modlist'] != 0) 283 { 284 $done_moderators = array( 285 "users" => array(), 286 "groups" => array() 287 ); 288 $moderators = ''; 289 // Fetch list of moderators from this forum and its parents 290 $parentlistexploded = explode(',', $forum['parentlist']); 291 foreach($parentlistexploded as $mfid) 292 { 293 // This forum has moderators 294 if(is_array($moderatorcache[$mfid])) 295 { 296 // Fetch each moderator from the cache and format it, appending it to the list 297 foreach($moderatorcache[$mfid] as $modtype) 298 { 299 foreach($modtype as $moderator) 300 { 301 if($moderator['isgroup']) 302 { 303 if(in_array($moderator['id'], $done_moderators['groups'])) 304 { 305 continue; 306 } 307 $moderators .= $comma.htmlspecialchars_uni($moderator['title']); 308 $done_moderators['groups'][] = $moderator['id']; 309 } 310 else 311 { 312 if(in_array($moderator['id'], $done_moderators['users'])) 313 { 314 continue; 315 } 316 $moderators .= "{$comma}<a href=\"".get_profile_link($moderator['id'])."\">".htmlspecialchars_uni($moderator['username'])."</a>"; 317 $done_moderators['users'][] = $moderator['id']; 318 } 319 $comma = $lang->comma; 320 } 321 } 322 } 323 } 324 $comma = ''; 325 326 // If we have a moderators list, load the template 327 if($moderators) 328 { 329 eval("\$modlist = \"".$templates->get("forumbit_moderators")."\";"); 330 } 331 else 332 { 333 $modlist = ''; 334 } 335 } 336 337 // Descriptions aren't being shown - blank them 338 if($mybb->settings['showdescriptions'] == 0) 339 { 340 $forum['description'] = ''; 341 } 342 343 // Check if this category is either expanded or collapsed and hide it as necessary. 344 $expdisplay = ''; 345 $collapsed_name = "cat_{$forum['fid']}_c"; 346 if(isset($collapsed[$collapsed_name]) && $collapsed[$collapsed_name] == "display: show;") 347 { 348 $expcolimage = "collapse_collapsed.gif"; 349 $expdisplay = "display: none;"; 350 $expaltext = "[+]"; 351 } 352 else 353 { 354 $expcolimage = "collapse.gif"; 355 $expaltext = "[-]"; 356 } 357 358 // Swap over the alternate backgrounds 359 $bgcolor = alt_trow(); 360 361 // Add the forum to the list 362 eval("\$forum_list .= \"".$templates->get("forumbit_depth$depth$forumcat")."\";"); 363 } 364 } 365 366 // Return an array of information to the parent forum including child forums list, counters and lastpost information 367 return array( 368 "forum_list" => $forum_list, 369 "counters" => $parent_counters, 370 "lastpost" => $parent_lastpost, 371 "lightbulb" => $lightbulb, 372 ); 373 } 374 375 /** 376 * Fetch the status indicator for a forum based on its last post and the read date 377 * 378 * @param array Array of information about the forum 379 * @param array Array of information about the lastpost date 380 * @return array Array of the folder image to be shown and the alt text 381 */ 382 function get_forum_lightbulb($forum, $lastpost, $locked=0) 383 { 384 global $mybb, $lang, $db, $unread_forums; 385 386 // This forum is closed, so override the folder icon with the "offlock" icon. 387 if($forum['open'] == 0 || $locked) 388 { 389 $folder = "offlock"; 390 $altonoff = $lang->forum_locked; 391 } 392 else 393 { 394 // Fetch the last read date for this forum 395 if($forum['lastread']) 396 { 397 $forum_read = $forum['lastread']; 398 } 399 elseif($mybb->cookies['mybb']['readallforums']) 400 { 401 // We've hit the read all forums as a guest, so use the lastvisit of the user 402 $forum_read = $mybb->cookies['mybb']['lastvisit']; 403 } 404 else 405 { 406 $forum_read = 0; 407 $threadcut = TIME_NOW - 60*60*24*$mybb->settings['threadreadcut']; 408 409 // If the user is a guest, do they have a forumsread cookie? 410 if(!$mybb->user['uid'] && $mybb->cookies['mybb']['forumread']) 411 { 412 // If they've visited us before, then they'll have this cookie - otherwise everything is unread... 413 $forum_read = my_get_array_cookie("forumread", $forum['fid']); 414 } 415 else if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && $threadcut > $lastpost['lastpost']) 416 { 417 // We have a user, the forum's unread and we're over our threadreadcut limit for the lastpost - we mark these as read 418 $forum_read = $lastpost['lastpost'] + 1; 419 } 420 } 421 422 //if(!$forum_read) 423 //{ 424 //$forum_read = $mybb->user['lastvisit']; 425 //} 426 427 // If the lastpost is greater than the last visit and is greater than the forum read date, we have a new post 428 if($lastpost['lastpost'] > $forum_read && $lastpost['lastpost'] != 0) 429 { 430 $unread_forums++; 431 $folder = "on"; 432 $altonoff = $lang->new_posts; 433 } 434 // Otherwise, no new posts 435 else 436 { 437 $folder = "off"; 438 $altonoff = $lang->no_new_posts; 439 } 440 } 441 442 return array( 443 "folder" => $folder, 444 "altonoff" => $altonoff 445 ); 446 } 447 448 /** 449 * Fetch the number of unapproved posts, formatted, from a forum 450 * 451 * @param array Array of information about the forum 452 * @return array Array containing formatted string for posts and string for threads 453 */ 454 function get_forum_unapproved($forum) 455 { 456 global $lang; 457 458 $unapproved_threads = $unapproved_posts = ''; 459 460 // If the user is a moderator we need to fetch the count 461 if(is_moderator($forum['fid'])) 462 { 463 // Forum has one or more unaproved posts, format language string accordingly 464 if($forum['unapprovedposts']) 465 { 466 if($forum['unapprovedposts'] > 1) 467 { 468 $unapproved_posts_count = $lang->sprintf($lang->forum_unapproved_posts_count, $forum['unapprovedposts']); 469 } 470 else 471 { 472 $unapproved_posts_count = $lang->sprintf($lang->forum_unapproved_post_count, 1); 473 } 474 $unapproved_posts = " <span title=\"{$unapproved_posts_count}\">(".my_number_format($forum['unapprovedposts']).")</span>"; 475 } 476 // Forum has one or more unapproved threads, format language string accordingly 477 if($forum['unapprovedthreads']) 478 { 479 if($forum['unapprovedthreads'] > 1) 480 { 481 $unapproved_threads_count = $lang->sprintf($lang->forum_unapproved_threads_count, $forum['unapprovedthreads']); 482 } 483 else 484 { 485 $unapproved_threads_count = $lang->sprintf($lang->forum_unapproved_thread_count, 1); 486 } 487 $unapproved_threads = " <span title=\"{$unapproved_threads_count}\">(".my_number_format($forum['unapprovedthreads']).")</span>"; 488 } 489 } 490 return array( 491 "unapproved_posts" => $unapproved_posts, 492 "unapproved_threads" => $unapproved_threads 493 ); 494 } 495 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Dec 11 14:16:27 2011 | Cross-referenced by PHPXref 0.7.1 |