[ Index ] |
PHP Cross Reference of MyBB |
[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$ 10 */ 11 12 define("IN_MYBB", 1); 13 define("IN_PORTAL", 1); 14 define('THIS_SCRIPT', 'portal.php'); 15 16 // set the path to your forums directory here (without trailing slash) 17 $forumdir = "./"; 18 19 // end editing 20 21 $change_dir = "./"; 22 23 if(!@chdir($forumdir) && !empty($forumdir)) 24 { 25 if(@is_dir($forumdir)) 26 { 27 $change_dir = $forumdir; 28 } 29 else 30 { 31 die("\$forumdir is invalid!"); 32 } 33 } 34 35 $templatelist = "portal_welcome,portal_welcome_membertext,portal_stats,portal_search,portal_whosonline_memberbit,portal_whosonline,portal_latestthreads_thread,portal_latestthreads,portal_announcement_numcomments_no,portal_announcement,portal_announcement_numcomments,portal_pms,portal"; 36 $templatelist .= ",portal_welcome_guesttext,postbit_attachments_thumbnails_thumbnail,postbit_attachments_images_image,postbit_attachments_attachment,postbit_attachments_thumbnails,postbit_attachments_images,postbit_attachments"; 37 38 require_once $change_dir."/global.php"; 39 require_once MYBB_ROOT."inc/functions_post.php"; 40 require_once MYBB_ROOT."inc/functions_user.php"; 41 require_once MYBB_ROOT."inc/class_parser.php"; 42 $parser = new postParser; 43 44 // Load global language phrases 45 $lang->load("portal"); 46 47 // Fetch the current URL 48 $portal_url = get_current_location(); 49 50 add_breadcrumb($lang->nav_portal, "portal.php"); 51 52 $plugins->run_hooks("portal_start"); 53 54 55 // get forums user cannot view 56 $unviewable = get_unviewable_forums(true); 57 if($unviewable) 58 { 59 $unviewwhere = " AND fid NOT IN ($unviewable)"; 60 } 61 // If user is known, welcome them 62 if($mybb->settings['portal_showwelcome'] != 0) 63 { 64 if($mybb->user['uid'] != 0) 65 { 66 // Get number of new posts, threads, announcements 67 $query = $db->simple_select("posts", "COUNT(pid) AS newposts", "visible=1 AND dateline>'".$mybb->user['lastvisit']."' $unviewwhere"); 68 $newposts = $db->fetch_field($query, "newposts"); 69 if($newposts) 70 { 71 // If there aren't any new posts, there is no point in wasting two more queries 72 $query = $db->simple_select("threads", "COUNT(tid) AS newthreads", "visible=1 AND dateline>'".$mybb->user['lastvisit']."' $unviewwhere"); 73 $newthreads = $db->fetch_field($query, "newthreads"); 74 75 if(!empty($mybb->settings['portal_announcementsfid'])) 76 { 77 $announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']); 78 if(is_array($announcementsfids)) 79 { 80 foreach($announcementsfids as $fid) 81 { 82 $fid_array[] = intval($fid); 83 } 84 85 $announcementsfids = implode(',', $fid_array); 86 $query = $db->simple_select("threads", "COUNT(tid) AS newann", "visible=1 AND dateline>'".$mybb->user['lastvisit']."' AND fid IN (".$announcementsfids.") $unviewwhere"); 87 $newann = $db->fetch_field($query, "newann"); 88 } 89 } 90 91 if(!$newthreads) 92 { 93 $newthreads = 0; 94 } 95 96 if(!$newann) 97 { 98 $newann = 0; 99 } 100 } 101 else 102 { 103 $newposts = 0; 104 $newthreads = 0; 105 $newann = 0; 106 } 107 108 // Make the text 109 if($newann == 1) 110 { 111 $lang->new_announcements = $lang->new_announcement; 112 } 113 else 114 { 115 $lang->new_announcements = $lang->sprintf($lang->new_announcements, $newann); 116 } 117 if($newthreads == 1) 118 { 119 $lang->new_threads = $lang->new_thread; 120 } 121 else 122 { 123 $lang->new_threads = $lang->sprintf($lang->new_threads, $newthreads); 124 } 125 if($newposts == 1) 126 { 127 $lang->new_posts = $lang->new_post; 128 } 129 else 130 { 131 $lang->new_posts = $lang->sprintf($lang->new_posts, $newposts); 132 } 133 eval("\$welcometext = \"".$templates->get("portal_welcome_membertext")."\";"); 134 135 } 136 else 137 { 138 $lang->guest_welcome_registration = $lang->sprintf($lang->guest_welcome_registration, $mybb->settings['bburl'] . '/member.php?action=register'); 139 $mybb->user['username'] = $lang->guest; 140 switch($mybb->settings['username_method']) 141 { 142 case 0: 143 $username = $lang->username; 144 break; 145 case 1: 146 $username = $lang->username1; 147 break; 148 case 2: 149 $username = $lang->username2; 150 break; 151 default: 152 $username = $lang->username; 153 break; 154 } 155 eval("\$welcometext = \"".$templates->get("portal_welcome_guesttext")."\";"); 156 } 157 $lang->welcome = $lang->sprintf($lang->welcome, $mybb->user['username']); 158 eval("\$welcome = \"".$templates->get("portal_welcome")."\";"); 159 if($mybb->user['uid'] == 0) 160 { 161 $mybb->user['username'] = ""; 162 } 163 } 164 // Private messages box 165 if($mybb->settings['portal_showpms'] != 0) 166 { 167 if($mybb->user['uid'] != 0 && $mybb->user['receivepms'] != 0 && $mybb->usergroup['canusepms'] != 0 && $mybb->settings['enablepms'] != 0) 168 { 169 switch($db->type) 170 { 171 case "sqlite": 172 case "pgsql": 173 $query = $db->simple_select("privatemessages", "COUNT(*) AS pms_total", "uid='".$mybb->user['uid']."'"); 174 $messages['pms_total'] = $db->fetch_field($query, "pms_total"); 175 176 $query = $db->simple_select("privatemessages", "COUNT(*) AS pms_unread", "uid='".$mybb->user['uid']."' AND CASE WHEN status = '0' AND folder = '0' THEN TRUE ELSE FALSE END"); 177 $messages['pms_unread'] = $db->fetch_field($query, "pms_unread"); 178 break; 179 default: 180 $query = $db->simple_select("privatemessages", "COUNT(*) AS pms_total, SUM(IF(status='0' AND folder='1','1','0')) AS pms_unread", "uid='".$mybb->user['uid']."'"); 181 $messages = $db->fetch_array($query); 182 } 183 184 // the SUM() thing returns "" instead of 0 185 if($messages['pms_unread'] == "") 186 { 187 $messages['pms_unread'] = 0; 188 } 189 $lang->pms_received_new = $lang->sprintf($lang->pms_received_new, $mybb->user['username'], $messages['pms_unread']); 190 eval("\$pms = \"".$templates->get("portal_pms")."\";"); 191 } 192 } 193 // Get Forum Statistics 194 if($mybb->settings['portal_showstats'] != 0) 195 { 196 $stats = $cache->read("stats"); 197 $stats['numthreads'] = my_number_format($stats['numthreads']); 198 $stats['numposts'] = my_number_format($stats['numposts']); 199 $stats['numusers'] = my_number_format($stats['numusers']); 200 if(!$stats['lastusername']) 201 { 202 $newestmember = "<strong>" . $lang->no_one . "</strong>"; 203 } 204 else 205 { 206 $newestmember = build_profile_link($stats['lastusername'], $stats['lastuid']); 207 } 208 eval("\$stats = \"".$templates->get("portal_stats")."\";"); 209 } 210 211 // Search box 212 if($mybb->settings['portal_showsearch'] != 0) 213 { 214 eval("\$search = \"".$templates->get("portal_search")."\";"); 215 } 216 217 // Get the online users 218 if($mybb->settings['portal_showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0) 219 { 220 $timesearch = TIME_NOW - $mybb->settings['wolcutoff']; 221 $comma = ''; 222 $guestcount = 0; 223 $membercount = 0; 224 $onlinemembers = ''; 225 $query = $db->query(" 226 SELECT s.sid, s.ip, s.uid, s.time, s.location, u.username, u.invisible, u.usergroup, u.displaygroup 227 FROM ".TABLE_PREFIX."sessions s 228 LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) 229 WHERE s.time>'$timesearch' 230 ORDER BY u.username ASC, s.time DESC 231 "); 232 while($user = $db->fetch_array($query)) 233 { 234 235 // Create a key to test if this user is a search bot. 236 $botkey = my_strtolower(str_replace("bot=", '', $user['sid'])); 237 238 if($user['uid'] == "0") 239 { 240 ++$guestcount; 241 } 242 elseif(my_strpos($user['sid'], "bot=") !== false && $session->bots[$botkey]) 243 { 244 // The user is a search bot. 245 $onlinemembers .= $comma.format_name($session->bots[$botkey], $session->botgroup); 246 $comma = $lang->comma; 247 ++$botcount; 248 } 249 else 250 { 251 if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']]) 252 { 253 ++$membercount; 254 255 $doneusers[$user['uid']] = $user['time']; 256 257 // If the user is logged in anonymously, update the count for that. 258 if($user['invisible'] == 1) 259 { 260 ++$anoncount; 261 } 262 263 if($user['invisible'] == 1) 264 { 265 $invisiblemark = "*"; 266 } 267 else 268 { 269 $invisiblemark = ''; 270 } 271 272 if(($user['invisible'] == 1 && ($mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])) || $user['invisible'] != 1) 273 { 274 $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']); 275 $user['profilelink'] = get_profile_link($user['uid']); 276 eval("\$onlinemembers .= \"".$templates->get("portal_whosonline_memberbit", 1, 0)."\";"); 277 $comma = $lang->comma; 278 } 279 } 280 } 281 } 282 283 $onlinecount = $membercount + $guestcount + $botcount; 284 285 // If we can see invisible users add them to the count 286 if($mybb->usergroup['canviewwolinvis'] == 1) 287 { 288 $onlinecount += $anoncount; 289 } 290 291 // If we can't see invisible users but the user is an invisible user incriment the count by one 292 if($mybb->usergroup['canviewwolinvis'] != 1 && $mybb->user['invisible'] == 1) 293 { 294 ++$onlinecount; 295 } 296 297 // Most users online 298 $mostonline = $cache->read("mostonline"); 299 if($onlinecount > $mostonline['numusers']) 300 { 301 $time = TIME_NOW; 302 $mostonline['numusers'] = $onlinecount; 303 $mostonline['time'] = $time; 304 $cache->update("mostonline", $mostonline); 305 } 306 $recordcount = $mostonline['numusers']; 307 $recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']); 308 $recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']); 309 310 if($onlinecount == 1) 311 { 312 $lang->online_users = $lang->online_user; 313 } 314 else 315 { 316 $lang->online_users = $lang->sprintf($lang->online_users, $onlinecount); 317 } 318 $lang->online_counts = $lang->sprintf($lang->online_counts, $membercount, $guestcount); 319 eval("\$whosonline = \"".$templates->get("portal_whosonline")."\";"); 320 } 321 322 // Latest forum discussions 323 if($mybb->settings['portal_showdiscussions'] != 0 && $mybb->settings['portal_showdiscussionsnum']) 324 { 325 $altbg = alt_trow(); 326 $threadlist = ''; 327 $query = $db->query(" 328 SELECT t.*, u.username 329 FROM ".TABLE_PREFIX."threads t 330 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid) 331 WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' 332 ORDER BY t.lastpost DESC 333 LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum'] 334 ); 335 while($thread = $db->fetch_array($query)) 336 { 337 $forumpermissions[$thread['fid']] = forum_permissions($thread['fid']); 338 339 // Make sure we can view this thread 340 if($forumpermissions[$thread['fid']]['canview'] == 0 || $forumpermissions[$thread['fid']]['canviewthreads'] == 0 || $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) 341 { 342 continue; 343 } 344 345 $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']); 346 $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']); 347 // Don't link to guest's profiles (they have no profile). 348 if($thread['lastposteruid'] == 0) 349 { 350 $lastposterlink = $thread['lastposter']; 351 } 352 else 353 { 354 $lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']); 355 } 356 if(my_strlen($thread['subject']) > 25) 357 { 358 $thread['subject'] = my_substr($thread['subject'], 0, 25) . "..."; 359 } 360 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 361 $thread['threadlink'] = get_thread_link($thread['tid']); 362 $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost"); 363 eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";"); 364 $altbg = alt_trow(); 365 } 366 if($threadlist) 367 { 368 // Show the table only if there are threads 369 eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";"); 370 } 371 } 372 373 $announcements = ''; 374 if(!empty($mybb->settings['portal_announcementsfid'])) 375 { 376 // Get latest news announcements 377 // First validate announcement fids: 378 $announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']); 379 if(is_array($announcementsfids)) 380 { 381 foreach($announcementsfids as $fid) 382 { 383 $fid_array[] = intval($fid); 384 } 385 $announcementsfids = implode(',', $fid_array); 386 } 387 // And get them! 388 foreach($forum_cache as $fid => $f) 389 { 390 if(is_array($fid_array) && in_array($fid, $fid_array)) 391 { 392 $forum[$fid] = $f; 393 } 394 } 395 396 $numannouncements = intval($mybb->settings['portal_numannouncements']); 397 if(!$numannouncements) 398 { 399 $numannouncements = 10; // Default back to 10 400 } 401 402 $pids = ''; 403 $tids = ''; 404 $comma = ''; 405 $posts = array(); 406 $query = $db->query(" 407 SELECT p.pid, p.message, p.tid, p.smilieoff 408 FROM ".TABLE_PREFIX."posts p 409 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 410 WHERE t.fid IN (".$announcementsfids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid 411 ORDER BY t.dateline DESC 412 LIMIT 0, {$numannouncements}" 413 ); 414 while($getid = $db->fetch_array($query)) 415 { 416 $pids .= ",'{$getid['pid']}'"; 417 $tids .= ",'{$getid['tid']}'"; 418 $posts[$getid['tid']] = $getid; 419 } 420 if(!empty($posts)) 421 { 422 $pids = "pid IN(0{$pids})"; 423 // Now lets fetch all of the attachments for these posts 424 $query = $db->simple_select("attachments", "*", $pids); 425 while($attachment = $db->fetch_array($query)) 426 { 427 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 428 } 429 430 if(is_array($forum)) 431 { 432 foreach($forum as $fid => $forumrow) 433 { 434 $forumpermissions[$fid] = forum_permissions($fid); 435 } 436 } 437 438 $icon_cache = $cache->read("posticons"); 439 440 $query = $db->query(" 441 SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions 442 FROM ".TABLE_PREFIX."threads t 443 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid) 444 WHERE t.fid IN (".$announcementsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%' 445 ORDER BY t.dateline DESC 446 LIMIT 0, {$numannouncements}" 447 ); 448 while($announcement = $db->fetch_array($query)) 449 { 450 // Make sure we can view this announcement 451 if($forumpermissions[$announcement['fid']]['canview'] == 0 || $forumpermissions[$announcement['fid']]['canviewthreads'] == 0 || $forumpermissions[$announcement['fid']]['canonlyviewownthreads'] == 1 && $announcement['uid'] != $mybb->user['uid']) 452 { 453 continue; 454 } 455 456 $announcement['message'] = $posts[$announcement['tid']]['message']; 457 $announcement['pid'] = $posts[$announcement['tid']]['pid']; 458 $announcement['smilieoff'] = $posts[$announcement['tid']]['smilieoff']; 459 $announcement['threadlink'] = get_thread_link($announcement['tid']); 460 461 if($announcement['uid'] == 0) 462 { 463 $profilelink = htmlspecialchars_uni($announcement['threadusername']); 464 } 465 else 466 { 467 $profilelink = build_profile_link($announcement['username'], $announcement['uid']); 468 } 469 470 if(!$announcement['username']) 471 { 472 $announcement['username'] = $announcement['threadusername']; 473 } 474 $announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject'])); 475 if($announcement['icon'] > 0 && $icon_cache[$announcement['icon']]) 476 { 477 $icon = $icon_cache[$announcement['icon']]; 478 $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />"; 479 } 480 else 481 { 482 $icon = " "; 483 } 484 if($announcement['avatar'] != '') 485 { 486 $avatar_dimensions = explode("|", $announcement['avatardimensions']); 487 if($avatar_dimensions[0] && $avatar_dimensions[1]) 488 { 489 $avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\""; 490 } 491 if (!stristr($announcement['avatar'], 'http://')) 492 { 493 $announcement['avatar'] = $mybb->settings['bburl'] . '/' . $announcement['avatar']; 494 } 495 $avatar = "<td class=\"trow1\" width=\"1\" align=\"center\" valign=\"top\"><img src=\"{$announcement['avatar']}\" alt=\"\" {$avatar_width_height} /></td>"; 496 } 497 else 498 { 499 $avatar = ''; 500 } 501 $anndate = my_date($mybb->settings['dateformat'], $announcement['dateline']); 502 $anntime = my_date($mybb->settings['timeformat'], $announcement['dateline']); 503 504 if($announcement['replies']) 505 { 506 eval("\$numcomments = \"".$templates->get("portal_announcement_numcomments")."\";"); 507 } 508 else 509 { 510 eval("\$numcomments = \"".$templates->get("portal_announcement_numcomments_no")."\";"); 511 $lastcomment = ''; 512 } 513 514 $plugins->run_hooks("portal_announcement"); 515 516 $parser_options = array( 517 "allow_html" => $forum[$announcement['fid']]['allowhtml'], 518 "allow_mycode" => $forum[$announcement['fid']]['allowmycode'], 519 "allow_smilies" => $forum[$announcement['fid']]['allowsmilies'], 520 "allow_imgcode" => $forum[$announcement['fid']]['allowimgcode'], 521 "allow_videocode" => $forum[$announcement['fid']]['allowvideocode'], 522 "filter_badwords" => 1 523 ); 524 if($announcement['smilieoff'] == 1) 525 { 526 $parser_options['allow_smilies'] = 0; 527 } 528 529 $message = $parser->parse_message($announcement['message'], $parser_options); 530 531 if(is_array($attachcache[$announcement['pid']])) 532 { // This post has 1 or more attachments 533 $validationcount = 0; 534 $id = $announcement['pid']; 535 foreach($attachcache[$id] as $aid => $attachment) 536 { 537 if($attachment['visible']) 538 { // There is an attachment thats visible! 539 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 540 $attachment['filesize'] = get_friendly_size($attachment['filesize']); 541 $ext = get_extension($attachment['filename']); 542 if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg") 543 { 544 $isimage = true; 545 } 546 else 547 { 548 $isimage = false; 549 } 550 $attachment['icon'] = get_attachment_icon($ext); 551 // Support for [attachment=id] code 552 if(stripos($message, "[attachment=".$attachment['aid']."]") !== false) 553 { 554 if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '') 555 { // We have a thumbnail to show (and its not the "SMALL" enough image 556 eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 557 } 558 elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$announcement['fid']]['candlattachments'] == 1) 559 { 560 // Image is small enough to show - no thumbnail 561 eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";"); 562 } 563 else 564 { 565 // Show standard link to attachment 566 eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";"); 567 } 568 $message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $message); 569 } 570 else 571 { 572 if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '') 573 { // We have a thumbnail to show 574 eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 575 if($tcount == 5) 576 { 577 $thumblist .= "<br />"; 578 $tcount = 0; 579 } 580 ++$tcount; 581 } 582 elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$announcement['fid']]['candlattachments'] == 1) 583 { 584 // Image is small enough to show - no thumbnail 585 eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";"); 586 } 587 else 588 { 589 eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";"); 590 } 591 } 592 } 593 else 594 { 595 $validationcount++; 596 } 597 } 598 if($post['thumblist']) 599 { 600 eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";"); 601 } 602 if($post['imagelist']) 603 { 604 eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";"); 605 } 606 if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist']) 607 { 608 eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";"); 609 } 610 } 611 612 eval("\$announcements .= \"".$templates->get("portal_announcement")."\";"); 613 unset($post); 614 } 615 } 616 } 617 618 $plugins->run_hooks("portal_end"); 619 620 eval("\$portal = \"".$templates->get("portal")."\";"); 621 output_page($portal); 622 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |