read("usergroups"); $mcache = $cache->read("moderators"); // If the groups cache doesn't exist, update it and re-read it if(!is_array($groupscache)) { $cache->updateusergroups(); $groupscache = $cache->read("usergroups"); } // Read forum permissions cache $fpermissioncache = $cache->read("forumpermissions"); // Create session for this user require_once MYBB_ROOT."inc/class_session.php"; $session = new session; $session->init(); // Set and load the language if(!isset($mybb->settings['bblanguage'])) { $mybb->settings['bblanguage'] = "english"; } // Load language $lang->set_language($mybb->settings['bblanguage']); $lang->load("global"); function latestposts($db,$mybb) { $newinfo = array(); $query = $db->simple_select(TABLE_PREFIX."posts", "COUNT(pid) AS newposts", "dateline>'".$mybb->user['lastvisit']."' $unviewwhere"); $newinfo['newposts'] = $db->fetch_field($query, "newposts"); if($newinfo['newposts']) { // if there aren't any new posts, there is no point in wasting two more queries $query = $db->simple_select(TABLE_PREFIX."threads", "COUNT(tid) AS newthreads", "dateline>'".$mybb->user['lastvisit']."' $unviewwhere"); $newinfo['newthreads'] = $db->fetch_field($query, "newthreads"); $query = $db->simple_select(TABLE_PREFIX."threads", "COUNT(tid) AS newann", "dateline>'".$mybb->user['lastvisit']."' AND fid IN (".$mybb->settings['portal_announcementsfid'].") $unviewwhere"); $newinfo['newann'] = $db->fetch_field($query, "newann"); if(!$newinfo['newthreads']) { $newinfo['newthreads'] = 0; } if(!$newinfo['newann']) { $newinfo['newann'] = 0; } } else { $newinfo['newposts'] = 0; $newinfo['newthreads'] = 0; $newinfo['newann'] = 0; } return $newinfo; } function onlinelist($db,$mybb,$cache) { $timesearch = time() - $mybb->settings['wolcutoff']; $comma = ''; $guestcount = 0; $membercount = 0; $onlinemembers = ''; $query = $db->query(" SELECT s.sid, s.ip, s.uid, s.time, s.location, u.username, u.invisible, u.usergroup, u.displaygroup FROM ".TABLE_PREFIX."sessions s LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) WHERE s.time>'$timesearch' ORDER BY u.username ASC, s.time DESC "); $online = array(); while($user = $db->fetch_array($query)) { if($user['uid'] == "0") { $guestcount++; } else { if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']]) { $doneusers[$user['uid']] = $user['time']; $membercount++; if($user['invisible'] != "yes" || $mybb->usergroup['canviewwolinvis'] == "yes") { if($user['invisible'] == "yes") { $invisiblemark = "*"; } else { $invisiblemark = ''; } $online['users'][] = array('name' => $user['username'], 'uid' => $user['uid'], 'group' => $user['usergroup'], 'forumnamestyle' => format_name($user['username'], $user['usergroup'], $user['displayname'])); } } } } $onlinecount = $membercount + $guestcount + $anoncount; // Most users online $mostonline = $cache->read("mostonline"); if($onlinecount > $mostonline['numusers']) { $time = time(); $mostonline['numusers'] = $onlinecount; $mostonline['time'] = $time; $cache->update("mostonline", $mostonline); } $recordcount = $mostonline['numusers']; $recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']); $recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']); $online['count'] = $onlinecount; $online['members'] = $membercount; $online['guests'] = $guestcount; return $online; } function compare($x, $y) { if ( $x[4] == $y[4] ) return 0; else if ( $x[4] < $y[4] ) return -1; else return 1; } function compare2($a, $b) { if ($a['date'] == $b['date']) { return 0; } return ($a['date'] < $b['date']) ? -1 : 1; } function nextxevents($db,$mybb,$limit,$trim,$dateformat) { $eventlist = array(); $query = $db->simple_select(TABLE_PREFIX."events", "*", 'private="no"'); while ($event = $db->fetch_array($query)) { $event['date'] = explode("-", $event['date']); $event['date'] = gmmktime(0, 0, 0, $event['date'][1], $event['date'][0], $event['date'][2]); if ($event['date'] > gmmktime(0, 0, 0, date('n', time()), date('j', time())-1, date('Y', time()))) { if(my_strlen($event['subject']) > $trim) { $event['short_subject'] = trim(my_substr($event['subject'], 0, $trim)) . "..."; } $event['format_date'] = my_date($dateformat , $event['date'], "", 0); $eventlist[] = $event; } } usort($eventlist, 'compare2'); $eventlist = array_slice($eventlist, 0, $limit); return $eventlist; } function headlines($db,$mybb,$cache,$templates,$parser,$fid,$limit) { require_once MYBB_ROOT."inc/class_parser.php"; $parser = new postParser; $pids = ''; $comma=""; if (strpos($fid, ",")) { $fids = explode(",", $fid); $i = 1; foreach ($fids as $forumid) { if ($i > 1) { $forums .= " OR t.fid = '".$forumid."'"; } else { $forums .= "'".$forumid."'"; } $i++; } } else { $forums = "'".$fid."'"; } $query = $db->query(" SELECT p.pid, p.message, p.tid FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) WHERE t.fid = ".$forums." AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid ORDER BY t.dateline DESC LIMIT 0, ".$limit ); while($getid = $db->fetch_array($query)) { $pids .= ",'$getid[pid]'"; $posts[$getid['tid']] = $getid; } $pids = "pid IN(0$pids)"; // Now lets fetch all of the attachments for these posts $query = $db->query("SELECT * FROM ".TABLE_PREFIX."attachments WHERE $pids"); while($attachment = $db->fetch_array($query)) { $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; } $icon_cache = $cache->read("posticons"); $announcements = ''; $forums = ""; if (strpos($fid, ",")) { $fids = explode(",", $fid); $i = 1; foreach ($fids as $forumid) { if ($i > 1) { $forums .= " OR fid = '".$forumid."'"; } else { $forums .= "'".$forumid."'"; } $i++; } } else { $forums = "'".$fid."'"; } $query = $db->query(" SELECT t.*, t.username AS threadusername, u.username, u.avatar FROM ".TABLE_PREFIX."threads t LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid) WHERE fid = ".$forums." AND t.visible='1' AND t.closed NOT LIKE 'moved|%' ORDER BY t.dateline DESC LIMIT 0, ".$limit ); while($announcement = $db->fetch_array($query)) { $announcement['message'] = $posts[$announcement['tid']]['message']; $announcement['pid'] = $posts[$announcement['tid']]['pid']; $announcement['author'] = $announcement['uid']; if(!$announcement['username']) { $announcement['username'] = $announcement['threadusername']; } $announcement['subject'] = htmlspecialchars_uni($announcement['subject']); $anndate = my_date($mybb->settings['dateformat'], $announcement['dateline']); $anntime = my_date($mybb->settings['timeformat'], $announcement['dateline']); $parser_options = array( "allow_html" => $forum[$announcement['fid']]['allow_html'], "allow_mycode" => $forum[$announcement['fid']]['allow_mycode'], "allow_smilies" => $forum[$announcement['fid']]['allowsmilies'], "allow_imgcode" => $forum[$announcement['fid']]['allowimgcode'] ); if($announcement['smilieoff'] == "yes") { $parser_options['allow_smilies'] = "no"; } $announcement['message'] = $parser->parse_message($announcement['message'], $parser_options); if(is_array($attachcache[$announcement['pid']])) { // This post has 1 or more attachments $validationcount = 0; $id = $announcement['pid']; foreach($attachcache[$id] as $aid => $attachment) { if($attachment['visible']) { // There is an attachment thats visible! $attachment['name'] = htmlspecialchars_uni($attachment['name']); $attachment['filesize'] = get_friendly_size($attachment['filesize']); $ext = get_extension($attachment['filename']); if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg") { $isimage = true; } else { $isimage = false; } $attachment['icon'] = get_attachment_icon($ext); // Support for [attachment=id] code if(stripos($announcement['message'], "[attachment=".$attachment['aid']."]") !== false) { if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '') { // We have a thumbnail to show (and its not the "SMALL" enough image eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); } elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$announcement['fid']]['candlattachments'] == "yes") { // Image is small enough to show - no thumbnail eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";"); } else { // Show standard link to attachment eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";"); } $announcement['message'] = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $announcement['message']); } } else { $validationcount++; } } } $announcement['message'] = html_entity_decode(str_replace('attachment.php','forums/attachment.php',$announcement['message'])); unset($post); $announcement['dateline'] = my_date("jS F Y" , $announcement['dateline'], "", 0); $announcements[] = $announcement; } return $announcements; } function lastxposts($db,$mybb,$limit,$trim,$dateformat,$timeformat) { $unviewable = get_unviewable_forums(); if($unviewable) { $unviewwhere = " AND fid NOT IN ($unviewable)"; } $threadlist = array(); $query = $db->query(" SELECT t.*, u.username FROM ".TABLE_PREFIX."threads t LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid) WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' ORDER BY t.lastpost DESC LIMIT 0, ".$limit ); while($thread = $db->fetch_array($query)) { $thread['lastpostdate'] = my_date($dateformat, $thread['lastpost']); $thread['lastposttime'] = my_date($timeformat, $thread['lastpost']); if ($trim > 0) { if(my_strlen($thread['subject']) > $trim) { $thread['subject'] = trim(my_substr($thread['subject'], 0, $trim)) . "..."; } $thread['subject'] = htmlspecialchars_uni($thread['subject']); $threadlist[] = $thread; } } return $threadlist; } } ?>