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