function getUnviewable($tableName = '') { global $db; if ($tableName) { $tableName = $tableName . '.'; } $wheres = array(); $wheres[] = '1=1'; // get forums user cannot view $unviewable = get_unviewable_forums(true); if ($unviewable) { $wheres[] = "{$tableName}fid NOT IN ({$unviewable})"; } // get inactive forums $inactive = get_inactive_forums(); if ($inactive) { $wheres[] = "{$tableName}fid NOT IN ({$inactive})"; } // get disallowed forums $disallowedforums = $db->escape_string($mybb->settings['tags_disallowedforums']); if ($disallowedforums) { $wheres[] = "{$tableName} NOT IN ({$disallowedforums})"; } return implode(' AND ', $wheres); }
function get_forum_func() { global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups, $forumpermissions, $fcache, $forum_cache; $lang->load("index"); $inactiveforums = get_inactive_forums(); if ($mybb->user['uid'] == 0) { // Build a forum cache. $query = $db->query("\n SELECT *, threads as unread_count\n FROM " . TABLE_PREFIX . "forums\n WHERE active != 0 " . ($inactiveforums ? " AND fid NOT IN ({$inactiveforums})" : '') . "\n ORDER BY pid, disporder\n "); $forumsread = unserialize($mybb->cookies['mybb']['forumread']); } else { // Build a forum cache. $query = $db->query("\n SELECT f.*, fr.dateline AS lastread, fs.fsid, (\n select count(*) from " . TABLE_PREFIX . "threads where fid=f.fid and lastpost > fr.dateline\n ) as unread_count\n FROM " . TABLE_PREFIX . "forums f\n LEFT JOIN " . TABLE_PREFIX . "forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')\n LEFT JOIN " . TABLE_PREFIX . "forumsubscriptions fs ON (fs.fid=f.fid AND fs.uid='{$mybb->user['uid']}')\n WHERE f.active != 0 " . ($inactiveforums ? " AND f.fid NOT IN ({$inactiveforums})" : '') . "\n ORDER BY pid, disporder\n "); } while ($forum = $db->fetch_array($query)) { if ($mybb->user['uid'] == 0) { if ($forumsread[$forum['fid']]) { $forum['lastread'] = $forumsread[$forum['fid']]; } } $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; } $forumpermissions = forum_permissions(); $excols = "index"; $permissioncache['-1'] = "1"; $showdepth = 10; $xml_nodes = new xmlrpcval(array(), 'array'); $done = array(); $xml_tree = treeBuild(0, $fcache, $xml_nodes, $done); $xml_nodes->addArray($xml_tree); return new xmlrpcresp($xml_nodes); }
// Divide up the cookie using our delimeter $multiquoted = explode("|", $mybb->cookies['multiquote']); $plugins->run_hooks("xmlhttp_get_multiquoted_start"); // No values - exit if (!is_array($multiquoted)) { exit; } // Loop through each post ID and sanitize it before querying foreach ($multiquoted as $post) { $quoted_posts[$post] = (int) $post; } // Join the post IDs back together $quoted_posts = implode(",", $quoted_posts); // Fetch unviewable forums $unviewable_forums = get_unviewable_forums(); $inactiveforums = get_inactive_forums(); if ($unviewable_forums) { $unviewable_forums = "AND t.fid NOT IN ({$unviewable_forums})"; } if ($inactiveforums) { $inactiveforums = "AND t.fid NOT IN ({$inactiveforums})"; } $message = ''; // Are we loading all quoted posts or only those not in the current thread? if (empty($mybb->input['load_all'])) { $from_tid = "p.tid != '" . $mybb->get_input('tid', MyBB::INPUT_INT) . "' AND "; } else { $from_tid = ''; } require_once MYBB_ROOT . "inc/class_parser.php"; $parser = new postParser();
/** * Builds a friendly named Who's Online location from an "activity" and array of user data. Assumes fetch_wol_activity has already been called. * * @param array Array containing activity and essential IDs. * @return string Location name for the activity being performed. */ function build_friendly_wol_location($user_activity) { global $db, $lang, $uid_list, $aid_list, $pid_list, $tid_list, $fid_list, $ann_list, $eid_list, $plugins, $parser, $mybb; global $threads, $forums, $forums_linkto, $forum_cache, $posts, $announcements, $events, $usernames, $attachments; // Fetch forum permissions for this user $unviewableforums = get_unviewable_forums(); $inactiveforums = get_inactive_forums(); $fidnot = ''; $unviewablefids = $inactivefids = array(); if ($unviewableforums) { $fidnot = " AND fid NOT IN ({$unviewableforums})"; $unviewablefids = explode(',', $unviewableforums); } if ($inactiveforums) { $fidnot .= " AND fid NOT IN ({$inactiveforums})"; $inactivefids = explode(',', $inactiveforums); } // Fetch any users if (!is_array($usernames) && count($uid_list) > 0) { $uid_sql = implode(",", $uid_list); if ($uid_sql != $mybb->user['uid']) { $query = $db->simple_select("users", "uid,username", "uid IN ({$uid_sql})"); while ($user = $db->fetch_array($query)) { $usernames[$user['uid']] = $user['username']; } } else { $usernames[$mybb->user['uid']] = $mybb->user['username']; } } // Fetch any attachments if (!is_array($attachments) && count($aid_list) > 0) { $aid_sql = implode(",", $aid_list); $query = $db->simple_select("attachments", "aid,pid", "aid IN ({$aid_sql})"); while ($attachment = $db->fetch_array($query)) { $attachments[$attachment['aid']] = $attachment['pid']; $pid_list[] = $attachment['pid']; } } // Fetch any announcements if (!is_array($announcements) && count($ann_list) > 0) { $aid_sql = implode(",", $ann_list); $query = $db->simple_select("announcements", "aid,subject", "aid IN ({$aid_sql}) {$fidnot}"); while ($announcement = $db->fetch_array($query)) { $announcement_title = htmlspecialchars_uni($parser->parse_badwords($announcement['subject'])); $announcements[$announcement['aid']] = $announcement_title; } } // Fetch any posts if (!is_array($posts) && count($pid_list) > 0) { $pid_sql = implode(",", $pid_list); $query = $db->simple_select("posts", "pid,tid", "pid IN ({$pid_sql}) {$fidnot}"); while ($post = $db->fetch_array($query)) { $posts[$post['pid']] = $post['tid']; $tid_list[] = $post['tid']; } } // Fetch any threads if (!is_array($threads) && count($tid_list) > 0) { $perms = array(); $tid_sql = implode(",", $tid_list); $query = $db->simple_select('threads', 'uid, fid, tid, subject, visible, prefix', "tid IN({$tid_sql}) {$fidnot}"); $threadprefixes = build_prefixes(); while ($thread = $db->fetch_array($query)) { $thread['threadprefix'] = ''; if ($thread['prefix'] && !empty($threadprefixes[$thread['prefix']])) { $thread['threadprefix'] = $threadprefixes[$thread['prefix']]['displaystyle']; } if (empty($perms[$thread['fid']])) { $perms[$thread['fid']] = forum_permissions($thread['fid']); } if (isset($perms[$thread['fid']]['canonlyviewownthreads']) && $perms[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'] && !is_moderator($thread['fid'])) { continue; } if (is_moderator($thread['fid']) || $thread['visible'] == 1) { $thread_title = ''; if ($thread['threadprefix']) { $thread_title = $thread['threadprefix'] . ' '; } $thread_title .= htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); $threads[$thread['tid']] = $thread_title; $fid_list[] = $thread['fid']; } } } // Fetch any forums if (!is_array($forums) && count($fid_list) > 0) { $fidnot = array_merge($unviewablefids, $inactivefids); foreach ($forum_cache as $fid => $forum) { if (in_array($fid, $fid_list) && !in_array($fid, $fidnot)) { $forums[$fid] = $forum['name']; $forums_linkto[$fid] = $forum['linkto']; } } } // And finaly any events if (!is_array($events) && count($eid_list) > 0) { $eid_sql = implode(",", $eid_list); $query = $db->simple_select("events", "eid,name", "eid IN ({$eid_sql})"); while ($event = $db->fetch_array($query)) { $events[$event['eid']] = htmlspecialchars_uni($parser->parse_badwords($event['name'])); } } // Now we've got everything we need we can put a name to the location switch ($user_activity['activity']) { // announcement.php functions case "announcements": if (!empty($announcements[$user_activity['ann']])) { $location_name = $lang->sprintf($lang->viewing_announcements, get_announcement_link($user_activity['ann']), $announcements[$user_activity['ann']]); } else { $location_name = $lang->viewing_announcements2; } break; // attachment.php actions // attachment.php actions case "attachment": $pid = $attachments[$user_activity['aid']]; $tid = $posts[$pid]; if (!empty($threads[$tid])) { $location_name = $lang->sprintf($lang->viewing_attachment2, $user_activity['aid'], $threads[$tid], get_thread_link($tid)); } else { $location_name = $lang->viewing_attachment; } break; // calendar.php functions // calendar.php functions case "calendar": $location_name = $lang->viewing_calendar; break; case "calendar_event": if (!empty($events[$user_activity['eid']])) { $location_name = $lang->sprintf($lang->viewing_event2, get_event_link($user_activity['eid']), $events[$user_activity['eid']]); } else { $location_name = $lang->viewing_event; } break; case "calendar_addevent": $location_name = $lang->adding_event; break; case "calendar_editevent": $location_name = $lang->editing_event; break; case "contact": $location_name = $lang->viewing_contact_us; break; // editpost.php functions // editpost.php functions case "editpost": $location_name = $lang->editing_post; break; // forumdisplay.php functions // forumdisplay.php functions case "forumdisplay": if (!empty($forums[$user_activity['fid']])) { if ($forums_linkto[$user_activity['fid']]) { $location_name = $lang->sprintf($lang->forum_redirect_to, get_forum_link($user_activity['fid']), $forums[$user_activity['fid']]); } else { $location_name = $lang->sprintf($lang->viewing_forum2, get_forum_link($user_activity['fid']), $forums[$user_activity['fid']]); } } else { $location_name = $lang->viewing_forum; } break; // index.php functions // index.php functions case "index": $location_name = $lang->sprintf($lang->viewing_index, $mybb->settings['bbname']); break; // managegroup.php functions // managegroup.php functions case "managegroup": $location_name = $lang->managing_group; break; // member.php functions // member.php functions case "member_activate": $location_name = $lang->activating_account; break; case "member_profile": if (!empty($usernames[$user_activity['uid']])) { $location_name = $lang->sprintf($lang->viewing_profile2, get_profile_link($user_activity['uid']), $usernames[$user_activity['uid']]); } else { $location_name = $lang->viewing_profile; } break; case "member_register": $location_name = $lang->registering; break; case "member": case "member_login": // Guest or member? if ($mybb->user['uid'] == 0) { $location_name = $lang->logging_in; } else { $location_name = $lang->logging_in_plain; } break; case "member_logout": $location_name = $lang->logging_out; break; case "member_emailuser": $location_name = $lang->emailing_user; break; case "member_rate": $location_name = $lang->rating_user; break; case "member_resendactivation": $location_name = $lang->member_resendactivation; break; case "member_lostpw": $location_name = $lang->member_lostpw; break; // memberlist.php functions // memberlist.php functions case "memberlist": $location_name = $lang->viewing_memberlist; break; // misc.php functions // misc.php functions case "misc_dstswitch": $location_name = $lang->changing_dst; break; case "misc_whoposted": if (!empty($threads[$user_activity['tid']])) { $location_name = $lang->sprintf($lang->viewing_whoposted2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']]); } else { $location_name = $lang->viewing_whoposted; } break; case "misc_markread": $location_name = $lang->sprintf($lang->marking_read, $mybb->post_code); break; case "misc_help": $location_name = $lang->viewing_helpdocs; break; case "misc_buddypopup": $location_name = $lang->viewing_buddylist; break; case "misc_smilies": $location_name = $lang->viewing_smilies; break; case "misc_syndication": $location_name = $lang->viewing_syndication; break; case "misc_imcenter": $location_name = $lang->viewing_imcenter; break; // modcp.php functions // modcp.php functions case "modcp_modlogs": $location_name = $lang->viewing_modlogs; break; case "modcp_announcements": $location_name = $lang->managing_announcements; break; case "modcp_finduser": $location_name = $lang->search_for_user; break; case "modcp_warninglogs": $location_name = $lang->managing_warninglogs; break; case "modcp_ipsearch": $location_name = $lang->searching_ips; break; case "modcp_report": $location_name = $lang->viewing_reports; break; case "modcp_new_announcement": $location_name = $lang->adding_announcement; break; case "modcp_delete_announcement": $location_name = $lang->deleting_announcement; break; case "modcp_edit_announcement": $location_name = $lang->editing_announcement; break; case "modcp_mod_queue": $location_name = $lang->managing_modqueue; break; case "modcp_editprofile": $location_name = $lang->editing_user_profiles; break; case "modcp_banning": $location_name = $lang->managing_bans; break; case "modcp": $location_name = $lang->viewing_modcp; break; // moderation.php functions // moderation.php functions case "moderation": $location_name = $lang->using_modtools; break; // newreply.php functions // newreply.php functions case "newreply": if (!empty($threads[$user_activity['tid']])) { $location_name = $lang->sprintf($lang->replying_thread2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']]); } else { $location_name = $lang->replying_thread; } break; // newthread.php functions // newthread.php functions case "newthread": if (!empty($forums[$user_activity['fid']])) { $location_name = $lang->sprintf($lang->posting_thread2, get_forum_link($user_activity['fid']), $forums[$user_activity['fid']]); } else { $location_name = $lang->posting_thread; } break; // online.php functions // online.php functions case "wol": $location_name = $lang->viewing_wol; break; case "woltoday": $location_name = $lang->viewing_woltoday; break; // polls.php functions // polls.php functions case "newpoll": $location_name = $lang->creating_poll; break; case "editpoll": $location_name = $lang->editing_poll; break; case "showresults": $location_name = $lang->viewing_pollresults; break; case "vote": $location_name = $lang->voting_poll; break; // printthread.php functions // printthread.php functions case "printthread": if (!empty($threads[$user_activity['tid']])) { $location_name = $lang->sprintf($lang->printing_thread2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']]); } else { $location_name = $lang->printing_thread; } break; // private.php functions // private.php functions case "private_send": $location_name = $lang->sending_pm; break; case "private_read": $location_name = $lang->reading_pm; break; case "private_folders": $location_name = $lang->editing_pmfolders; break; case "private": $location_name = $lang->using_pmsystem; break; /* Ratethread functions */ /* Ratethread functions */ case "ratethread": $location_name = $lang->rating_thread; break; // report.php functions // report.php functions case "report": $location_name = $lang->reporting_post; break; // reputation.php functions // reputation.php functions case "reputation": $location_name = $lang->sprintf($lang->giving_reputation, get_profile_link($user_activity['uid']), $usernames[$user_activity['uid']]); break; case "reputation_report": if (!empty($usernames[$user_activity['uid']])) { $location_name = $lang->sprintf($lang->viewing_reputation_report, "reputation.php?uid={$user_activity['uid']}", $usernames[$user_activity['uid']]); } else { $location_name = $lang->sprintf($lang->viewing_reputation_report2); } break; // search.php functions // search.php functions case "search": $location_name = $lang->sprintf($lang->searching_forum, $mybb->settings['bbname']); break; // showthread.php functions // showthread.php functions case "showthread": if (!empty($threads[$user_activity['tid']])) { $pagenote = ''; $location_name = $lang->sprintf($lang->reading_thread2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']], $pagenote); } else { $location_name = $lang->reading_thread; } break; case "showpost": if (!empty($posts[$user_activity['pid']]) && !empty($threads[$posts[$user_activity['pid']]])) { $pagenote = ''; $location_name = $lang->sprintf($lang->reading_thread2, get_thread_link($posts[$user_activity['pid']]), $threads[$posts[$user_activity['pid']]], $pagenote); } else { $location_name = $lang->reading_thread; } break; // showteam.php functions // showteam.php functions case "showteam": $location_name = $lang->viewing_team; break; // stats.php functions // stats.php functions case "stats": $location_name = $lang->viewing_stats; break; // usercp.php functions // usercp.php functions case "usercp_profile": $location_name = $lang->updating_profile; break; case "usercp_editlists": $location_name = $lang->managing_buddyignorelist; break; case "usercp_options": $location_name = $lang->updating_options; break; case "usercp_editsig": $location_name = $lang->editing_signature; break; case "usercp_avatar": $location_name = $lang->changing_avatar; break; case "usercp_subscriptions": $location_name = $lang->viewing_subscriptions; break; case "usercp_favorites": $location_name = $lang->viewing_favorites; break; case "usercp_notepad": $location_name = $lang->editing_pad; break; case "usercp_password": $location_name = $lang->editing_password; break; case "usercp": $location_name = $lang->user_cp; break; case "usercp2_favorites": $location_name = $lang->managing_favorites; break; case "usercp2_subscriptions": $location_name = $lang->managing_subscriptions; break; case "portal": $location_name = $lang->viewing_portal; break; // sendthread.php functions // sendthread.php functions case "sendthread": $location_name = $lang->sending_thread; break; // warnings.php functions // warnings.php functions case "warnings_revoke": $location_name = $lang->revoking_warning; break; case "warnings_warn": $location_name = $lang->warning_user; break; case "warnings_view": $location_name = $lang->viewing_warning; break; case "warnings": $location_name = $lang->managing_warnings; break; } $plugin_array = array('user_activity' => &$user_activity, 'location_name' => &$location_name); $plugins->run_hooks("build_friendly_wol_location_end", $plugin_array); if (isset($user_activity['nopermission']) && $user_activity['nopermission'] == 1) { $location_name = $lang->viewing_noperms; } if (!$location_name) { $location_name = $lang->sprintf($lang->unknown_location, $user_activity['location']); } return $location_name; }
/** * Generate the list of items for a sitemap. * This will be handed to google_seo_sitemap() to produce the XML output. * * @param string XML Sitemap URL scheme * @param string type of items to list in sitemap * @param int page number * @param int number of items per page * @return array List of items (in case of main index) */ function google_seo_sitemap_gen($scheme, $type, $page, $pagination) { global $lang, $db, $mybb, $settings; global $google_seo_url_optimize; if (!$settings["google_seo_sitemap_{$type}"]) { return; } switch ($type) { case "forums": $table = 'forums'; $idname = 'fid'; $datename = 'lastpost'; $getlink = 'get_forum_link'; // Additional permission check. $unviewableforums = get_unviewable_forums(); $inactiveforums = get_inactive_forums(); if ($unviewableforums) { $condition[] = "fid NOT IN ({$unviewableforums})"; } if ($inactiveforums) { $condition[] = "fid NOT IN ({$inactiveforums})"; } // passwords already taken care of unviewable forums, // but linkto needs special treatment... $condition[] = "linkto=''"; if ($condition) { $condition = implode(" AND ", $condition); } // Include pages? if ($settings['google_seo_sitemap_forums'] == 2) { $pagescount = ', threads AS pagescount'; $perpage = $mybb->settings['threadsperpage']; if (!$perpage) { $perpage = 20; } } break; case "threads": $table = 'threads'; $idname = 'tid'; $datename = 'lastpost'; $getlink = 'get_thread_link'; $condition = "visible>0 AND closed NOT LIKE 'moved|%'"; // Additional permission check. $unviewableforums = get_unviewable_forums(true); $inactiveforums = get_inactive_forums(); if ($unviewableforums) { $condition .= " AND fid NOT IN ({$unviewableforums})"; } if ($inactiveforums) { $condition .= " AND fid NOT IN ({$inactiveforums})"; } // Include pages? if ($settings['google_seo_sitemap_threads'] == 2) { $pagescount = ', replies+1 AS pagescount'; $perpage = $settings['postsperpage']; if (!$perpage) { $perpage = 20; } } break; case "users": if (!$mybb->usergroup['canviewprofiles']) { return; } $table = 'users'; $idname = 'uid'; $datename = 'regdate'; $getlink = 'get_profile_link'; $condition = '1=1'; break; case "announcements": $table = 'announcements'; $idname = 'aid'; $datename = 'startdate'; $getlink = 'get_announcement_link'; $time = TIME_NOW; $condition = "startdate <= '{$time}' AND (enddate >= '{$time}' OR enddate='0')"; // Additional permission check. $unviewableforums = get_unviewable_forums(true); $inactiveforums = get_inactive_forums(); if ($unviewableforums) { $condition .= " AND fid NOT IN ({$unviewableforums})"; } if ($inactiveforums) { $condition .= " AND fid NOT IN ({$inactiveforums})"; } break; case "calendars": if ($mybb->settings['enablecalendar'] == 0 || $mybb->usergroup['canviewcalendar'] == 0) { return; } $table = 'calendars'; $idname = 'cid'; $datename = 'disporder'; $getlink = 'get_calendar_link'; $condition = '1=1'; // Calendar permission check. $unviewablecalendars = google_seo_get_unviewable_calendars(); if ($unviewablecalendars) { $condition = "cid NOT IN ({$unviewablecalendars})"; } break; case "events": // Global permission check. if ($mybb->settings['enablecalendar'] == 0 || $mybb->usergroup['canviewcalendar'] == 0) { return; } $table = 'events'; $idname = 'eid'; $datename = 'dateline'; $getlink = 'get_event_link'; // Event specific permission check. $condition = "visible=1 AND private=0"; // Calendar permission check. $unviewablecalendars = google_seo_get_unviewable_calendars(); if ($unviewablecalendars) { $condition .= " AND cid NOT IN ({$unviewablecalendars})"; } break; default: error($lang->googleseo_sitemap_pageinvalid); } if (!$page) { // Do a pagination index. $query = $db->simple_select($table, "MAX({$datename}) AS lastmod, FLOOR({$idname}/{$pagination}.0)+1 AS page", "{$condition} GROUP BY FLOOR({$idname}/{$pagination}.0)"); $url = google_seo_expand($scheme, array('url' => $type)); $url .= (strpos($url, '?') === false ? '?' : '&') . 'page='; while ($row = $db->fetch_array($query)) { $row['loc'] = "{$url}{$row['page']}"; $items[] = $row; } // Do not build a sitemap here. Instead return the items. // This way, items for all types can be collected for the main index page. return $items; } // Build the sitemap for this page. $min = ($page - 1) * $pagination; $max = $min + $pagination; $query = $db->simple_select($table, "{$idname},{$datename}{$pagescount}", "{$condition} AND {$idname} > {$min} AND {$idname} <= {$max}", array('order_by' => $idname)); while ($row = $db->fetch_array($query)) { $id = $row[$idname]; $ids[] = $id; $dates[$id] = $row[$datename]; if ($pagescount) { $pages[$id] = (int) (($row['pagescount'] - 1) / $perpage) + 1; } else { $pages[$id] = 0; } // Google SEO URL Optimization: $type2id = array('users' => GOOGLE_SEO_USER, 'announcements' => GOOGLE_SEO_ANNOUNCEMENT, 'forums' => GOOGLE_SEO_FORUM, 'threads' => GOOGLE_SEO_THREAD, 'events' => GOOGLE_SEO_EVENT, 'calendars' => GOOGLE_SEO_CALENDAR); $google_seo_url_optimize[$type2id[$type]][$id] = 0; } if (!sizeof($ids)) { error($lang->googleseo_sitemap_emptyorinvalid); } foreach ($ids as $id) { $item = array(); $item['loc'] = call_user_func($getlink, $id); if ($dates[$id]) { $item['lastmod'] = $dates[$id]; } $items[] = $item; for ($p = 2; $p <= $pages[$id]; $p += 1) { $item = array(); $item['loc'] = call_user_func($getlink, $id, $p); if ($dates[$id]) { $item['lastmod'] = $dates[$id]; } // Give pages of items a lower priority. // TODO: Temporary solution until I make this a setting. $item['priority'] = '0.2'; $items[] = $item; } } google_seo_sitemap("url", $items); }
$reputation_cache[] = $reputation_vote; // If this is a post, hold it and gather some information about it if ($reputation_vote['pid'] && !isset($post_cache[$reputation_vote['pid']])) { $post_cache[$reputation_vote['pid']] = $reputation_vote['pid']; } } if (!empty($post_cache)) { $pids = implode(',', $post_cache); $sql = array("p.pid IN ({$pids})"); // get forums user cannot view $unviewable = get_unviewable_forums(true); if ($unviewable) { $sql[] = "p.fid NOT IN ({$unviewable})"; } // get inactive forums $inactive = get_inactive_forums(); if ($inactive) { $sql[] = "p.fid NOT IN ({$inactive})"; } if (!$mybb->user['ismoderator']) { $sql[] = "p.visible='1'"; $sql[] = "t.visible='1'"; } $sql = implode(' AND ', $sql); $query = $db->query("\n\t\t\tSELECT p.pid, p.uid, p.fid, p.visible, p.message, t.tid, t.subject, t.visible AS thread_visible\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tWHERE {$sql}\n\t\t"); $forumpermissions = array(); while ($post = $db->fetch_array($query)) { if (($post['visible'] == 0 || $post['thread_visible'] == 0) && !is_moderator($post['fid'], 'canviewunapprove')) { continue; } if (($post['visible'] == -1 || $post['thread_visible'] == -1) && !is_moderator($post['fid'], 'canviewdeleted')) {
/** * Perform a thread and post search under MySQL or MySQLi using boolean fulltext capabilities * * @param array Array of search data * @return array Array of search data with results mixed in */ function perform_search_mysql_ft($search) { global $mybb, $db, $lang; $keywords = clean_keywords_ft($search['keywords']); if (!$keywords && !$search['author']) { error($lang->error_nosearchterms); } // Attempt to determine minimum word length from MySQL for fulltext searches $query = $db->query("SHOW VARIABLES LIKE 'ft_min_word_len';"); $min_length = $db->fetch_field($query, 'Value'); if (is_numeric($min_length)) { $mybb->settings['minsearchword'] = $min_length; } else { $mybb->settings['minsearchword'] = 4; } if ($keywords) { $keywords_exp = explode("\"", $keywords); $inquote = false; foreach ($keywords_exp as $phrase) { if (!$inquote) { $split_words = preg_split("#\\s{1,}#", $phrase, -1); foreach ($split_words as $word) { $word = str_replace(array("+", "-", "*"), '', $word); if (!$word) { continue; } if (my_strlen($word) < $mybb->settings['minsearchword']) { $all_too_short = true; } else { $all_too_short = false; break; } } } else { $phrase = str_replace(array("+", "-", "*"), '', $phrase); if (my_strlen($phrase) < $mybb->settings['minsearchword']) { $all_too_short = true; } else { $all_too_short = false; break; } } $inquote = !$inquote; } // Show the minimum search term error only if all search terms are too short if ($all_too_short == true) { $lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']); error($lang->error_minsearchlength); } $message_lookin = "AND MATCH(message) AGAINST('" . $db->escape_string($keywords) . "' IN BOOLEAN MODE)"; $subject_lookin = "AND MATCH(subject) AGAINST('" . $db->escape_string($keywords) . "' IN BOOLEAN MODE)"; } $post_usersql = ''; $thread_usersql = ''; if ($search['author']) { $userids = array(); if ($search['matchusername']) { $query = $db->simple_select("users", "uid", "username='******'author']) . "'"); } else { $search['author'] = my_strtolower($search['author']); $query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%" . $db->escape_string_like($db->escape_string($search['author'])) . "%'"); } while ($user = $db->fetch_array($query)) { $userids[] = $user['uid']; } if (count($userids) < 1) { error($lang->error_nosearchresults); } else { $userids = implode(',', $userids); $post_usersql = " AND p.uid IN (" . $userids . ")"; $thread_usersql = " AND t.uid IN (" . $userids . ")"; } } $datecut = ''; if ($search['postdate']) { if ($search['pddir'] == 0) { $datecut = "<="; } else { $datecut = ">="; } $now = TIME_NOW; $datelimit = $now - 86400 * $search['postdate']; $datecut .= "'{$datelimit}'"; $post_datecut = " AND p.dateline {$datecut}"; $thread_datecut = " AND t.dateline {$datecut}"; } $thread_replycut = ''; if ($search['numreplies'] != '' && $search['findthreadst']) { if (intval($search['findthreadst']) == 1) { $thread_replycut = " AND t.replies >= '" . intval($search['numreplies']) . "'"; } else { $thread_replycut = " AND t.replies <= '" . intval($search['numreplies']) . "'"; } } $forumin = ''; $fidlist = array(); $searchin = array(); if ($search['forums'] != "all") { if (!is_array($search['forums'])) { $search['forums'] = array(intval($search['forums'])); } foreach ($search['forums'] as $forum) { $forum = intval($forum); if (!$searchin[$forum]) { switch ($db->type) { case "pgsql": case "sqlite3": case "sqlite2": $query = $db->query("\n\t\t\t\t\t\t\tSELECT f.fid \n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "forums f \n\t\t\t\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "forumpermissions p ON (f.fid=p.fid AND p.gid='" . $mybb->user['usergroup'] . "') \n\t\t\t\t\t\t\tWHERE INSTR(','||parentlist||',',',{$forum},') > 0 AND active!=0 AND (ISNULL(p.fid) OR p.cansearch=1)\n\t\t\t\t\t\t"); break; default: $query = $db->query("\n\t\t\t\t\t\t\tSELECT f.fid \n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "forums f \n\t\t\t\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "forumpermissions p ON (f.fid=p.fid AND p.gid='" . $mybb->user['usergroup'] . "') \n\t\t\t\t\t\t\tWHERE INSTR(CONCAT(',',parentlist,','),',{$forum},') > 0 AND active!=0 AND (ISNULL(p.fid) OR p.cansearch=1)\n\t\t\t\t\t\t"); } while ($sforum = $db->fetch_array($query)) { $fidlist[] = $sforum['fid']; } } } if (count($fidlist) == 1) { $forumin .= " AND t.fid='{$forum}' "; $searchin[$fid] = 1; } else { if (count($fidlist) > 1) { $forumin = " AND t.fid IN (" . implode(',', $fidlist) . ")"; } } } $unsearchforums = get_unsearchable_forums(); if ($unsearchforums) { $permsql = " AND t.fid NOT IN ({$unsearchforums})"; } $inactiveforums = get_inactive_forums(); if ($inactiveforums) { $permsql .= " AND t.fid NOT IN ({$inactiveforums})"; } // Searching a specific thread? if ($search['tid']) { $tidsql = " AND t.tid='" . intval($search['tid']) . "'"; } $limitsql = ''; if (intval($mybb->settings['searchhardlimit']) > 0) { $limitsql = "LIMIT " . intval($mybb->settings['searchhardlimit']); } // Searching both posts and thread titles $threads = array(); $posts = array(); $firstposts = array(); if ($search['postthread'] == 1) { // No need to search subjects when looking for results within a specific thread if (!$search['tid']) { $query = $db->query("\n\t\t\t\tSELECT t.tid, t.firstpost\n\t\t\t\tFROM " . TABLE_PREFIX . "threads t\n\t\t\t\tWHERE 1=1 {$thread_datecut} {$thread_replycut} {$forumin} {$thread_usersql} {$permsql} AND t.visible>=0 AND t.closed NOT LIKE 'moved|%' {$subject_lookin}\n\t\t\t\t{$limitsql}\n\t\t\t"); while ($thread = $db->fetch_array($query)) { $threads[$thread['tid']] = $thread['tid']; if ($thread['firstpost']) { $posts[$thread['tid']] = $thread['firstpost']; } } } $query = $db->query("\n\t\t\tSELECT p.pid, p.tid\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tWHERE 1=1 {$post_datecut} {$thread_replycut} {$forumin} {$post_usersql} {$permsql} {$tidsql} AND p.visible>=0 AND t.visible>=0 AND t.closed NOT LIKE 'moved|%' {$message_lookin}\n\t\t\t{$limitsql}\n\t\t"); while ($post = $db->fetch_array($query)) { $posts[$post['pid']] = $post['pid']; $threads[$post['tid']] = $post['tid']; } if (count($posts) < 1 && count($threads) < 1) { error($lang->error_nosearchresults); } $threads = implode(',', $threads); $posts = implode(',', $posts); } else { $query = $db->query("\n\t\t\tSELECT t.tid, t.firstpost\n\t\t\tFROM " . TABLE_PREFIX . "threads t\n\t\t\tWHERE 1=1 {$thread_datecut} {$thread_replycut} {$forumin} {$thread_usersql} {$permsql} AND t.visible>=0 {$subject_lookin}\n\t\t\t{$limitsql}\n\t\t"); while ($thread = $db->fetch_array($query)) { $threads[$thread['tid']] = $thread['tid']; if ($thread['firstpost']) { $firstposts[$thread['tid']] = $thread['firstpost']; } } if (count($threads) < 1) { error($lang->error_nosearchresults); } $threads = implode(',', $threads); $firstposts = implode(',', $firstposts); if ($firstposts) { $query = $db->simple_select("posts", "pid", "pid IN ({$firstposts}) AND visible >= '0' {$limitsql}"); while ($post = $db->fetch_array($query)) { $posts[$post['pid']] = $post['pid']; } $posts = implode(',', $posts); } } return array("threads" => $threads, "posts" => $posts, "querycache" => ''); }
require_once MYBB_ROOT . "inc/class_parser.php"; $parser = new postParser(); // Load global language phrases $lang->load("portal"); // Fetch the current URL $portal_url = get_current_location(); add_breadcrumb($lang->nav_portal, "portal.php"); $plugins->run_hooks("portal_start"); // get forums user cannot view $unviewable = get_unviewable_forums(true); if ($unviewable) { $unviewwhere = " AND fid NOT IN ({$unviewable})"; $tunviewwhere = " AND t.fid NOT IN ({$unviewable})"; } // get inactive forums $inactive = get_inactive_forums(true); if ($inactive) { $inactivewhere = " AND fid NOT IN ({$inactive})"; $tinactivewhere = " AND t.fid NOT IN ({$inactive})"; } // If user is known, welcome them if ($mybb->settings['portal_showwelcome'] != 0) { if ($mybb->user['uid'] != 0) { // Get number of new posts, threads, announcements $query = $db->simple_select("posts", "COUNT(pid) AS newposts", "visible=1 AND dateline>'" . $mybb->user['lastvisit'] . "' {$unviewwhere}{$inactivewhere}"); $newposts = $db->fetch_field($query, "newposts"); if ($newposts) { // If there aren't any new posts, there is no point in wasting two more queries $query = $db->simple_select("threads", "COUNT(tid) AS newthreads", "visible=1 AND dateline>'" . $mybb->user['lastvisit'] . "' {$unviewwhere}{$inactivewhere}"); $newthreads = $db->fetch_field($query, "newthreads"); if (!empty($mybb->settings['portal_announcementsfid'])) {
function asb_rand_quote_get_quote($settings, $width) { global $db, $mybb, $templates, $lang, $theme; if (!$lang->asb_addon) { $lang->load('asb_addon'); } // get forums user cannot view $unviewable = get_unviewable_forums(true); if ($unviewable) { $unviewwhere = " AND p.fid NOT IN ({$unviewable})"; } // get inactive forums $inactive = get_inactive_forums(); if ($inactive) { $inactivewhere = " AND p.fid NOT IN ({$inactive})"; } if ($settings['important_threads_only']) { $important_threads = ' AND NOT t.sticky=0'; } // build the exclude conditions $show['fids'] = asb_build_id_list($settings['forum_show_list'], 'p.fid'); $show['tids'] = asb_build_id_list($settings['thread_show_list'], 'p.tid'); $hide['fids'] = asb_build_id_list($settings['forum_hide_list'], 'p.fid'); $hide['tids'] = asb_build_id_list($settings['thread_hide_list'], 'p.tid'); $where['show'] = asb_build_SQL_where($show, ' OR '); $where['hide'] = asb_build_SQL_where($hide, ' OR ', ' NOT '); $query_where = $important_threads . $unviewwhere . $inactivewhere . asb_build_SQL_where($where, ' AND ', ' AND '); $post_query = $db->query("\n\t\tSELECT\n\t\t\tp.pid, p.message, p.fid, p.tid, p.subject, p.uid,\n\t\t\tu.username, u.usergroup, u.displaygroup, u.avatar,\n\t\t\tt.sticky\n\t\tFROM {$db->table_prefix}posts p\n\t\tLEFT JOIN {$db->table_prefix}users u ON (u.uid=p.uid)\n\t\tLEFT JOIN {$db->table_prefix}threads t ON (t.tid=p.tid)\n\t\tWHERE\n\t\t\tp.visible='1'{$query_where}\n\t\tORDER BY\n\t\t\tRAND()\n\t\tLIMIT 1;"); // if there was 1 . . . if ($db->num_rows($post_query) == 0) { return false; } $rand_post = $db->fetch_array($post_query); // build a post parser require_once MYBB_ROOT . 'inc/class_parser.php'; $parser = new postParser(); // we just need the text and smilies (we'll parse them after we check length) $pattern = "|[[\\/\\!]*?[^\\[\\]]*?]|si"; $new_message = asb_strip_url(preg_replace($pattern, '$1', $rand_post['message'])); // get some dimensions that make sense in relation to column width $asb_width = (int) $width; $asb_inner_size = $asb_width * 0.83; $avatar_size = (int) ($asb_inner_size / 5); $font_size = $asb_width / 4.5; $font_size = max(10, min(16, $font_size)); $username_font_size = (int) ($font_size * 0.9); $title_font_size = (int) ($font_size * 0.65); $message_font_size = (int) $font_size; if (strlen($new_message) < $settings['min_length']) { if ($settings['default_text']) { $new_message = $settings['default_text']; } else { // nothing to show return false; } } if ($settings['max_length'] && strlen($new_message) > $settings['max_length']) { $new_message = substr($new_message, 0, $settings['max_length']) . ' . . .'; } // set up the user name link so that it displays correctly for the display group of the user $plain_text_username = htmlspecialchars_uni($rand_post['username']); $username = format_name($plain_text_username, $rand_post['usergroup'], $rand_post['displaygroup']); $author_link = get_profile_link($rand_post['uid']); $post_link = get_post_link($rand_post['pid'], $rand_post['tid']) . '#pid' . $rand_post['pid']; $thread_link = get_thread_link($rand_post['tid']); // allow smilies, but kill $parser_options = array("allow_smilies" => 1); $new_message = str_replace(array('<br />', '/me'), array('', " * {$plain_text_username}"), $parser->parse_message($new_message . ' ', $parser_options)); // if the user has an avatar then display it, otherwise force the default avatar. $avatar_filename = "{$theme['imgdir']}/default_avatar.gif"; if ($rand_post['avatar'] != '') { $avatar_filename = $rand_post['avatar']; } $avatar_alt = $lang->sprintf($lang->asb_random_quote_users_profile, $plain_text_username); eval("\$read_more = \"" . $templates->get('asb_rand_quote_read_more') . "\";"); if (my_strlen($rand_post['subject']) > 40) { $rand_post['subject'] = my_substr($rand_post['subject'], 0, 40) . ' . . .'; } if (substr(strtolower($rand_post['subject']), 0, 3) == 're:') { $rand_post['subject'] = substr($rand_post['subject'], 3); } $rand_post['subject'] = htmlspecialchars_uni($parser->parse_badwords($rand_post['subject'])); $thread_title_link = <<<EOF <strong><a href="{$thread_link}" title="{$lang->asb_random_quotes_read_more_threadlink_title}"><span style="font-size: {$title_font_size}px;">{$rand_post['subject']}</span></a></strong> EOF; // eval() the template eval("\$this_quote = \"" . $templates->get("asb_rand_quote_sidebox") . "\";"); return $this_quote; }
/** * Prepare WHERE statement for unread posts search query * */ private function buildSQLWhere() { if ($this->where != '') { return; } // Standard where $this->where .= "t.visible = 1 AND t.closed NOT LIKE 'moved|%'"; // Only one fid theme if ($this->fid) { $this->where .= " AND t.fid = '{$this->fid}'"; } // Exceptions if ($this->getConfig('Exceptions') != '') { $exceptions_list = explode(',', $this->getConfig('Exceptions')); $exceptions_list = array_map('intval', $exceptions_list); if (sizeof($exceptions_list) > 0) { $this->where .= " AND t.fid NOT IN (" . implode(',', $exceptions_list) . ")"; } } // Permissions $onlyusfids = array(); // Check group permissions if we can't view threads not started by us $group_permissions = forum_permissions(); foreach ($group_permissions as $fid => $forum_permissions) { if ($forum_permissions['canonlyviewownthreads'] == 1) { $onlyusfids[] = $fid; } } if (!empty($onlyusfids)) { $this->where .= " AND ((t.fid IN(" . implode(',', $onlyusfids) . ") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(" . implode(',', $onlyusfids) . "))"; } // Unsearchable forums if (!function_exists('get_unsearchable_forums')) { require_once MYBB_ROOT . "inc/functions_search.php"; } global $permissioncache, $unsearchableforums; $permissioncache = $unsearchableforums = false; $unsearchforums = get_unsearchable_forums(); if ($unsearchforums) { $this->where .= " AND t.fid NOT IN ({$unsearchforums})"; } // Inactive forums $inactiveforums = get_inactive_forums(); if ($inactiveforums) { $this->where .= " AND t.fid NOT IN ({$inactiveforums})"; } }
function latest_threads_get_threadlist($settings, $width) { global $db, $mybb, $templates, $lang, $cache, $gotounread, $theme; if (!$lang->asb_addon) { $lang->load('asb_addon'); } if ($mybb->user['uid'] == 0) { $query = $db->query("\n\t\t\tSELECT\n\t\t\t\tfid\n\t\t\tFROM {$db->table_prefix}forums\n\t\t\tWHERE\n\t\t\t\tactive != 0\n\t\t\tORDER BY\n\t\t\t\tpid, disporder\n\t\t"); $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']); } else { $query = $db->query("\n\t\t\tSELECT\n\t\t\t\tf.fid, fr.dateline AS lastread\n\t\t\tFROM {$db->table_prefix}forums f\n\t\t\tLEFT JOIN {$db->table_prefix}forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')\n\t\t\tWHERE\n\t\t\t\tf.active != 0\n\t\t\tORDER BY\n\t\t\t\tpid, disporder\n\t\t"); } while ($forum = $db->fetch_array($query)) { if ($mybb->user['uid'] == 0) { if ($forumsread[$forum['fid']]) { $forum['lastread'] = $forumsread[$forum['fid']]; } } $readforums[$forum['fid']] = $forum['lastread']; } // Build a post parser require_once MYBB_ROOT . 'inc/class_parser.php'; $parser = new postParser(); // get forums user cannot view $unviewable = get_unviewable_forums(true); if ($unviewable) { $unviewwhere = " AND t.fid NOT IN ({$unviewable})"; } // get inactive forums $inactive = get_inactive_forums(); if ($inactive) { $inactivewhere = " AND t.fid NOT IN ({$inactive})"; } // new threads only? if ((int) $settings['new_threads_only'] > 0) { // use admin's time limit $thread_time_limit = TIME_NOW - 60 * 60 * 24 * (int) $settings['new_threads_only']; $new_threads = " AND t.dateline > {$thread_time_limit}"; } if ($settings['important_threads_only']) { $important_threads = ' AND NOT t.sticky=0'; } // build the exclude conditions $show['fids'] = asb_build_id_list($settings['forum_show_list'], 't.fid'); $show['tids'] = asb_build_id_list($settings['thread_show_list'], 't.tid'); $hide['fids'] = asb_build_id_list($settings['forum_hide_list'], 't.fid'); $hide['tids'] = asb_build_id_list($settings['thread_hide_list'], 't.tid'); $where['show'] = asb_build_SQL_where($show, ' OR '); $where['hide'] = asb_build_SQL_where($hide, ' OR ', ' NOT '); $query_where = $new_threads . $important_threads . $unviewwhere . $inactivewhere . asb_build_SQL_where($where, ' AND ', ' AND '); $altbg = alt_trow(); $maxtitlelen = 48; $threadlist = ''; // query for the latest forum discussions $query = $db->query("\n\t\tSELECT\n\t\t\tt.*,\n\t\t\tu.username, u.avatar, u.usergroup, u.displaygroup\n\t\tFROM {$db->table_prefix}threads t\n\t\tLEFT JOIN {$db->table_prefix}users u ON (u.uid=t.lastposteruid)\n\t\tWHERE\n\t\t\tt.visible='1' AND t.closed NOT LIKE 'moved|%'{$query_where}\n\t\tORDER BY\n\t\t\tt.lastpost DESC\n\t\tLIMIT\n\t\t\t0, " . (int) $settings['max_threads']); if ($db->num_rows($query) == 0) { // no content return false; } $thread_cache = array(); while ($thread = $db->fetch_array($query)) { $thread_cache[$thread['tid']] = $thread; } $thread_ids = implode(",", array_keys($thread_cache)); // fetch the read threads. if ($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0) { $query = $db->simple_select('threadsread', 'tid,dateline', "uid='{$mybb->user['uid']}' AND tid IN({$thread_ids})"); while ($readthread = $db->fetch_array($query)) { $thread_cache[$readthread['tid']]['lastread'] = $readthread['dateline']; } } foreach ($thread_cache as $thread) { $forumpermissions[$thread['fid']] = forum_permissions($thread['fid']); // make sure we can view this thread if ($forumpermissions[$thread['fid']]['canview'] == 0 || $forumpermissions[$thread['fid']]['canviewthreads'] == 0 || $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) { continue; } $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']); $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']); // don't link to guest's profiles (they have no profile). if ($thread['lastposteruid'] == 0) { $lastposterlink = $thread['lastposter']; } else { if ($settings['last_poster_avatar']) { if (strlen(trim($thread['avatar'])) == 0) { $thread['avatar'] = "{$theme['imgdir']}/default_avatar.gif"; } $avatar_width = (int) min($width / 2, max($width / 8, $settings['avatar_width'])); $last_poster_name = <<<EOF <img src="{$thread['avatar']}" alt="{$thread['last_post']}" title="{$thread['lastposter']}'s profile" style="width: {$avatar_width}px;"/> EOF; format_name($thread['lastposter'], $thread['usergroup'], $thread['displaygroup']); $lp_template = 'asb_latest_threads_last_poster_avatar'; } else { $last_poster_name = format_name($thread['lastposter'], $thread['usergroup'], $thread['displaygroup']); $lp_template = 'asb_latest_threads_last_poster_name'; } $lastposterlink = build_profile_link($last_poster_name, $thread['lastposteruid']); } if (my_strlen($thread['subject']) > $maxtitlelen) { $thread['subject'] = my_substr($thread['subject'], 0, $maxtitlelen) . "..."; } $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); $thread['threadlink'] = get_thread_link($thread['tid']); $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost"); eval("\$last_poster = \"" . $templates->get($lp_template) . "\";"); $gotounread = ''; $last_read = 0; if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) { $forum_read = $readforums[$thread['fid']]; $read_cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24; if ($forum_read == 0 || $forum_read < $read_cutoff) { $forum_read = $read_cutoff; } } else { $forum_read = $forumsread[$thread['fid']]; } if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read) { if ($thread['lastread']) { $last_read = $thread['lastread']; } else { $last_read = $read_cutoff; } } else { $last_read = my_get_array_cookie('threadread', $thread['tid']); } if ($forum_read > $last_read) { $last_read = $forum_read; } if ($thread['lastpost'] > $last_read && $last_read) { $thread['newpostlink'] = get_thread_link($thread['tid'], 0, 'newpost'); eval("\$gotounread = \"" . $templates->get("asb_latest_threads_gotounread") . "\";"); $unreadpost = 1; } eval("\$threadlist .= \"" . $templates->get("asb_latest_threads_thread") . "\";"); $altbg = alt_trow(); } if ($threadlist) { return $threadlist; } // no content return false; }
function latestposts() { global $mybb, $lang, $db, $templates, $postslist, $sidebar, $right, $left; $lang->load("latestposts"); $threadlimit = (int) $mybb->settings['latestposts_threadcount']; $where = NULL; if (!$threadlimit) { $threadlimit = 15; } if ($mybb->settings['latestposts_forumskip']) { $where .= " AND t.fid NOT IN(" . $mybb->settings['latestposts_forumskip'] . ") "; } require_once MYBB_ROOT . "inc/functions_search.php"; $unsearchforums = get_unsearchable_forums(); if ($unsearchforums) { $where .= " AND t.fid NOT IN ({$unsearchforums})"; } $inactiveforums = get_inactive_forums(); if ($inactiveforums) { $where .= " AND t.fid NOT IN ({$inactiveforums})"; } $permissions = forum_permissions(); for ($i = 0; $i <= sizeof($permissions); $i++) { if (isset($permissions[$i]['fid']) && ($permissions[$i]['canview'] == 0 || $permissions[$i]['canviewthreads'] == 0)) { $where .= " AND t.fid <> " . $permissions[$i]['fid']; } } $where .= " AND p.visible <> -1"; $query = $db->query("\r\n\t\tSELECT t.*, u.username AS userusername, u.usergroup, u.displaygroup, lp.usergroup AS lastusergroup, lp.displaygroup as lastdisplaygroup, p.visible\r\n\t\tFROM " . TABLE_PREFIX . "threads t\r\n\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=t.uid)\r\n\t\tLEFT JOIN " . TABLE_PREFIX . "users lp ON (t.lastposteruid=lp.uid)\r\n\t\tLEFT JOIN " . TABLE_PREFIX . "posts p ON (t.tid=p.tid AND replyto = 0)\r\n WHERE 1=1 {$where}\r\n\t\tORDER BY t.lastpost DESC\r\n\t\tLIMIT {$threadlimit}\r\n\t"); while ($thread = $db->fetch_array($query)) { $tid = $thread['tid']; $postname = $thread['subject']; $lastpostlink = get_thread_link($thread['tid'], "", "lastpost"); $lastposttimeago = my_date("relative", $thread['lastpost']); $lastposter = $thread['lastposter']; $lastposteruid = $thread['lastposteruid']; if ($mybb->settings['latestposts_showtime'] == 1) { $lang->latestposttime = $lang->sprintf($lang->latestposttime, $lastposttimeago); } else { $lang->latestposttime = NULL; } if ($lastposteruid == 0) { $lastposterlink = $lastposter; } else { $lastposterlink = build_profile_link(format_name($lastposter, $thread['lastusergroup'], $thread['lastdisplaygroup']), $lastposteruid); } eval("\$postslist .= \"" . $templates->get("index_sidebar_post") . "\";"); } if ($mybb->settings['latestposts_rightorleft'] == "right") { $right = "right"; $left = "left"; } else { $right = "left"; $left = "right"; } eval("\$sidebar = \"" . $templates->get("index_sidebar") . "\";"); }
function recent_posts_get_postlist($settings) { global $db, $mybb, $templates, $lang, $cache, $postlist, $gotounread, $theme; // load custom language phrases if (!$lang->asb_addon) { $lang->load('asb_addon'); } // get forums user cannot view $unviewable = get_unviewable_forums(true); if ($unviewable) { $unviewwhere = " AND p.fid NOT IN ({$unviewable})"; } // get inactive forums $inactive = get_inactive_forums(); if ($inactive) { $inactivewhere = " AND p.fid NOT IN ({$inactive})"; } if ($settings['important_threads_only']) { $important_threads = ' AND NOT t.sticky=0'; } // build the exclude conditions $show['fids'] = asb_build_id_list($settings['forum_show_list'], 'p.fid'); $show['tids'] = asb_build_id_list($settings['thread_show_list'], 'p.tid'); $hide['fids'] = asb_build_id_list($settings['forum_hide_list'], 'p.fid'); $hide['tids'] = asb_build_id_list($settings['thread_hide_list'], 'p.tid'); $where['show'] = asb_build_SQL_where($show, ' OR '); $where['hide'] = asb_build_SQL_where($hide, ' OR ', ' NOT '); $query_where = $important_threads . $unviewwhere . $inactivewhere . asb_build_SQL_where($where, ' AND ', ' AND '); $altbg = alt_trow(); $maxtitlelen = 48; $postlist = ''; // Query for the latest forum discussions $query = $db->query("\n\t\tSELECT p.tid, p.pid, p.message, p.fid, p.dateline, p.subject,\n\t\t\tu.username, u.uid, u.displaygroup, u.usergroup,\n\t\t\tt.sticky\n\t\tFROM {$db->table_prefix}posts p\n\t\tLEFT JOIN {$db->table_prefix}users u ON (u.uid=p.uid)\n\t\tLEFT JOIN {$db->table_prefix}threads t ON (t.tid=p.tid)\n\t\tWHERE\n\t\t\tp.visible='1'{$query_where}\n\t\tORDER BY\n\t\t\tp.dateline DESC\n\t\tLIMIT\n\t\t\t0, " . (int) $settings['max_posts']); if ($db->num_rows($query) == 0) { // no content return false; } // Build a post parser require_once MYBB_ROOT . 'inc/class_parser.php'; $parser = new postParser(); $post_cache = array(); while ($post = $db->fetch_array($query)) { $post_cache[$post['pid']] = $post; } foreach ($post_cache as $post) { $forumpermissions[$post['fid']] = forum_permissions($post['fid']); // make sure we can view this post if ($forumpermissions[$post['fid']]['canview'] == 0 || $forumpermissions[$post['fid']]['canviewthreads'] == 0 || $forumpermissions[$post['fid']]['canonlyviewownthreads'] == 1 && $post['uid'] != $mybb->user['uid']) { continue; } $lastposttime = my_date($mybb->settings['timeformat'], $post['dateline']); // don't link to guest's profiles (they have no profile). if ($post['uid'] == 0) { $post_author = $post['username']; } else { $post_author_name = format_name($post['username'], $post['usergroup'], $post['displaygroup']); $post_author = build_profile_link($post_author_name, $post['uid']); } if (my_strlen($post['subject']) > $maxtitlelen) { $post['subject'] = my_substr($post['subject'], 0, $maxtitlelen) . '...'; } if (substr(strtolower($post['subject']), 0, 3) == 're:') { $post['subject'] = substr($post['subject'], 3); } $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject'])); $post['link'] = get_thread_link($post['tid']) . "&pid={$post['pid']}#pid{$post['pid']}"; // we just need the text and smilies (we'll parse them after we check length) $pattern = "|[[\\/\\!]*?[^\\[\\]]*?]|si"; $post_excerpt = strip_tags(str_replace('<br />', '', asb_strip_url(preg_replace($pattern, '$1', $post['message'])))); if (strlen($post_excerpt) > $settings['max_length']) { $post_excerpt = substr($post_excerpt, 0, $settings['max_length']) . ' . . .'; } eval("\$postlist .= \"" . $templates->get("asb_recent_posts_post") . "\";"); $altbg = alt_trow(); } return $postlist; }