Example #1
0
function mods_list_forum_leaders()
{
    if (!($db = db::get())) {
        return false;
    }
    $mod_list_array = array();
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $user_perm_admin_tools = USER_PERM_ADMIN_TOOLS;
    $sql = "SELECT USERS.UID, USERS.LOGON, COALESCE(USER_PEER.PEER_NICKNAME, USERS.NICKNAME) AS NICKNAME ";
    $sql .= "FROM ((SELECT DISTINCT USER.UID, USER.LOGON, USER.NICKNAME FROM USER INNER JOIN GROUP_USERS ";
    $sql .= "ON (GROUP_USERS.UID = USER.UID) INNER JOIN GROUP_PERMS ON (GROUP_PERMS.GID = GROUP_USERS.GID) ";
    $sql .= "INNER JOIN GROUPS ON (GROUPS.GID = GROUP_PERMS.GID) WHERE GROUPS.FORUM IN (0, {$forum_fid}) ";
    $sql .= "AND GROUP_PERMS.FID IN (0) AND GROUP_PERMS.PERM & {$user_perm_admin_tools}) UNION ALL ";
    $sql .= "(SELECT DISTINCT USER.UID, USER.LOGON, USER.NICKNAME FROM USER INNER JOIN USER_PERM ";
    $sql .= "ON (USER_PERM.UID = USER.UID) WHERE USER_PERM.FORUM IN (0, {$forum_fid}) AND USER_PERM.FID IN (0) ";
    $sql .= "AND USER_PERM.PERM & {$user_perm_admin_tools} > 0)) AS USERS LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ";
    $sql .= "ON (USER_PEER.PEER_UID = USERS.UID AND USER_PEER.UID = {$_SESSION['UID']})";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    while (($mod_list_data = $result->fetch_assoc()) !== null) {
        $mod_list_array[$mod_list_data['UID']] = $mod_list_data;
    }
    return $mod_list_array;
}
function mods_list_get_mods($fid)
{
    if (!($db = db::get())) {
        return false;
    }
    $mod_list_array = array();
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $sql = "SELECT USER.UID, USER.LOGON, USER.NICKNAME FROM USER USER ";
    $sql .= "LEFT JOIN GROUP_USERS GROUP_USERS ON (GROUP_USERS.UID = USER.UID) ";
    $sql .= "LEFT JOIN GROUP_PERMS GROUP_PERMS ON (GROUP_PERMS.GID = GROUP_USERS.GID) ";
    $sql .= "WHERE GROUP_PERMS.FID IN (0, {$fid}) AND GROUP_PERMS.FORUM IN (0, {$forum_fid}) ";
    if ($fid > 0) {
        $user_perm_folder_moderate = USER_PERM_FOLDER_MODERATE;
        $sql .= "AND (GROUP_PERMS.PERM & {$user_perm_folder_moderate}) > 0 ";
    } else {
        $user_perm_admin_tools = USER_PERM_ADMIN_TOOLS;
        $user_perm_folder_moderate = USER_PERM_FOLDER_MODERATE;
        $sql .= "AND ((GROUP_PERMS.PERM & {$user_perm_admin_tools}) > 0 ";
        $sql .= "OR (GROUP_PERMS.PERM & {$user_perm_folder_moderate}) > 0) ";
    }
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    while ($mod_list_data = $result->fetch_assoc()) {
        $mod_list_array[$mod_list_data['UID']] = $mod_list_data;
    }
    return $mod_list_array;
}
function messages_get_ratings($tid, &$messages_array)
{
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($tid)) {
        return false;
    }
    if (sizeof($messages_array) < 1) {
        return false;
    }
    $pid_list = implode("','", array_keys($messages_array));
    $sql = "SELECT PID, SUM(RATING) AS RATING, COUNT(RATING) AS RATING_COUNT ";
    $sql .= "FROM `{$table_prefix}POST_RATING` WHERE TID = {$tid} ";
    $sql .= "AND RATING IN (-1, 1) AND PID IN ('{$pid_list}') GROUP BY PID";
    if ($result = $db->query($sql)) {
        while (($rating_data = $result->fetch_assoc()) !== null) {
            $messages_array[$rating_data['PID']]['POST_RATING'] = $rating_data['RATING'];
            $messages_array[$rating_data['PID']]['POST_RATING_COUNT'] = $rating_data['RATING_COUNT'];
        }
    }
    $sql = "SELECT PID, RATING FROM `{$table_prefix}POST_RATING` WHERE TID = {$tid} ";
    $sql .= "AND PID IN ('{$pid_list}') AND UID = {$_SESSION['UID']}";
    if ($result = $db->query($sql)) {
        while (($rating_data = $result->fetch_assoc()) !== null) {
            $messages_array[$rating_data['PID']]['USER_POST_RATING'] = $rating_data['RATING'];
        }
    }
    return true;
}
Example #4
0
function thread_has_attachments(&$thread_data)
{
    if (!isset($thread_data['TID'])) {
        return false;
    }
    if (!is_numeric($thread_data['TID'])) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    $sql = "SELECT PAI.TID, PAF.AID FROM POST_ATTACHMENT_IDS PAI ";
    $sql .= "LEFT JOIN POST_ATTACHMENT_FILES PAF ON (PAF.AID = PAI.AID) ";
    $sql .= "WHERE PAI.FID = '{$forum_fid}' AND PAI.TID = '{$thread_data['TID']}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    while ($attachment_data = $result->fetch_assoc()) {
        $thread_data['AID'] = $attachment_data['AID'];
    }
    return true;
}
Example #5
0
function post_draw_to_dropdown_recent($default_uid)
{
    $class = defined('BEEHIVEMODE_LIGHT') ? 'select' : 'recent_user_dropdown';
    $html = "<select name=\"t_to_uid_recent\" class=\"{$class}\">";
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!is_numeric($default_uid)) {
        $default_uid = 0;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $uid = session::get_value('UID');
    if (isset($default_uid) && $default_uid != 0) {
        $sql = "SELECT USER.LOGON, USER.NICKNAME, USER_PEER.PEER_NICKNAME ";
        $sql .= "FROM USER LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ";
        $sql .= "ON (USER_PEER.PEER_UID = USER.UID AND USER_PEER.UID = '{$uid}') ";
        $sql .= "WHERE USER.UID = '{$default_uid}' ";
        if (!($result = $db->query($sql))) {
            return false;
        }
        if ($result->num_rows > 0) {
            if ($top_user = $result->fetch_assoc()) {
                if (isset($top_user['PEER_NICKNAME'])) {
                    if (!is_null($top_user['PEER_NICKNAME']) && strlen($top_user['PEER_NICKNAME']) > 0) {
                        $top_user['NICKNAME'] = $top_user['PEER_NICKNAME'];
                    }
                }
                $fmt_username = word_filter_add_ob_tags(format_user_name($top_user['LOGON'], $top_user['NICKNAME']), true);
                $html .= "<option value=\"{$default_uid}\" selected=\"selected\">{$fmt_username}</option>";
            }
        }
    }
    $html .= "<option value=\"0\">" . gettext("ALL") . "</option>";
    $sql = "SELECT VISITOR_LOG.UID, USER.LOGON, USER.NICKNAME, USER_PEER.PEER_NICKNAME, ";
    $sql .= "UNIX_TIMESTAMP(VISITOR_LOG.LAST_LOGON) AS LAST_LOGON FROM VISITOR_LOG VISITOR_LOG ";
    $sql .= "LEFT JOIN USER USER ON (USER.UID = VISITOR_LOG.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ";
    $sql .= "ON (USER_PEER.PEER_UID = USER.UID AND USER_PEER.UID = '{$uid}') ";
    $sql .= "WHERE VISITOR_LOG.FORUM = '{$forum_fid}' AND VISITOR_LOG.UID <> '{$default_uid}' ";
    $sql .= "AND VISITOR_LOG.UID > 0 ORDER BY VISITOR_LOG.LAST_LOGON DESC ";
    $sql .= "LIMIT 0, 20";
    if (!($result = $db->query($sql))) {
        return false;
    }
    while ($user_data = $result->fetch_assoc()) {
        if (isset($user_data['LOGON'])) {
            if (isset($user_data['LOGON']) && isset($user_data['PEER_NICKNAME'])) {
                if (!is_null($user_data['PEER_NICKNAME']) && strlen($user_data['PEER_NICKNAME']) > 0) {
                    $user_data['NICKNAME'] = $user_data['PEER_NICKNAME'];
                }
            }
            $fmt_username = word_filter_add_ob_tags(format_user_name($user_data['LOGON'], $user_data['NICKNAME']), true);
            $html .= "<option value=\"{$user_data['UID']}\">{$fmt_username}</option>";
        }
    }
    $html .= "</select>";
    return $html;
}
Example #6
0
function messages_get($tid, $pid = 1, $limit = 1)
{
    if (($uid = session::get_value('UID')) === false) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $session_gc_maxlifetime = ini_get('session.gc_maxlifetime');
    $session_cutoff_datetime = date(MYSQL_DATETIME, time() - $session_gc_maxlifetime);
    $sql = "SELECT POST.PID, POST.REPLY_TO_PID, POST.FROM_UID, POST.TO_UID, ";
    $sql .= "UNIX_TIMESTAMP(POST.CREATED) AS CREATED, UNIX_TIMESTAMP(POST.VIEWED) AS VIEWED, ";
    $sql .= "UNIX_TIMESTAMP(POST.EDITED) AS EDITED, POST.EDITED_BY, POST.IPADDRESS, ";
    $sql .= "POST.MOVED_TID, POST.MOVED_PID, UNIX_TIMESTAMP(POST.APPROVED) AS APPROVED, ";
    $sql .= "POST.APPROVED_BY, FUSER.LOGON AS FLOGON, FUSER.NICKNAME AS FNICK, ";
    $sql .= "USER_PEER_FROM.RELATIONSHIP AS FROM_RELATIONSHIP, TUSER.LOGON AS TLOGON, ";
    $sql .= "TUSER.NICKNAME AS TNICK, USER_PEER_TO.RELATIONSHIP AS TO_RELATIONSHIP, ";
    $sql .= "USER_PEER_TO.PEER_NICKNAME AS PTNICK, USER_PEER_FROM.PEER_NICKNAME AS PFNICK, ";
    $sql .= "USER_PREFS_GLOBAL.ANON_LOGON, COALESCE(USER_PREFS_FORUM.AVATAR_URL, USER_PREFS_GLOBAL.AVATAR_URL) AS AVATAR_URL, ";
    $sql .= "COALESCE(USER_PREFS_FORUM.AVATAR_AID, USER_PREFS_GLOBAL.AVATAR_AID) AS AVATAR_AID, ";
    $sql .= "(SELECT MAX(SESSIONS.TIME) FROM SESSIONS WHERE SESSIONS.TIME >= CAST('{$session_cutoff_datetime}' AS DATETIME) ";
    $sql .= "AND SESSIONS.FID = {$forum_fid} AND SESSIONS.UID = POST.FROM_UID) AS USER_ACTIVE ";
    $sql .= "FROM `{$table_prefix}POST` POST LEFT JOIN USER FUSER ON (POST.FROM_UID = FUSER.UID) ";
    $sql .= "LEFT JOIN USER TUSER ON (POST.TO_UID = TUSER.UID) LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER_TO ";
    $sql .= "ON (USER_PEER_TO.UID = '{$uid}' AND USER_PEER_TO.PEER_UID = POST.TO_UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER_FROM ";
    $sql .= "ON (USER_PEER_FROM.UID = '{$uid}' AND USER_PEER_FROM.PEER_UID = POST.FROM_UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PREFS` USER_PREFS_FORUM ON (USER_PREFS_FORUM.UID = POST.FROM_UID) ";
    $sql .= "LEFT JOIN USER_PREFS USER_PREFS_GLOBAL ON (USER_PREFS_GLOBAL.UID = POST.FROM_UID) ";
    $sql .= "WHERE POST.TID = '{$tid}' ";
    $sql .= "AND POST.PID >= '{$pid}' ";
    $sql .= "ORDER BY POST.PID ";
    $sql .= "LIMIT 0, {$limit}";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    $messages = array();
    while ($message = $result->fetch_assoc()) {
        $message['CONTENT'] = "";
        if (!isset($message['VIEWED'])) {
            $message['VIEWED'] = 0;
        }
        if (!isset($message['APPROVED'])) {
            $message['APPROVED'] = 0;
        }
        if (!isset($message['APPROVED_BY'])) {
            $message['APPROVED_BY'] = 0;
        }
        if (!isset($message['EDITED'])) {
            $message['EDITED'] = 0;
        }
        if (!isset($message['EDITED_BY'])) {
            $message['EDITED_BY'] = 0;
        }
        if (!isset($message['IPADDRESS'])) {
            $message['IPADDRESS'] = "";
        }
        if (!isset($message['FROM_RELATIONSHIP'])) {
            $message['FROM_RELATIONSHIP'] = 0;
        }
        if (!isset($message['TO_RELATIONSHIP'])) {
            $message['TO_RELATIONSHIP'] = 0;
        }
        if (isset($message['TLOGON']) && isset($message['PTNICK'])) {
            if (!is_null($message['PTNICK']) && strlen($message['PTNICK']) > 0) {
                $message['TNICK'] = $message['PTNICK'];
            }
        }
        if (isset($message['FLOGON']) && isset($message['PFNICK'])) {
            if (!is_null($message['PFNICK']) && strlen($message['PFNICK']) > 0) {
                $message['FNICK'] = $message['PFNICK'];
            }
        }
        if (!isset($message['FNICK'])) {
            $message['FNICK'] = gettext("Unknown user");
        }
        if (!isset($message['FLOGON'])) {
            $message['FLOGON'] = gettext("Unknown user");
        }
        if (!isset($message['FROM_UID'])) {
            $message['FROM_UID'] = -1;
        }
        if (!isset($message['TNICK'])) {
            $message['TNICK'] = gettext("ALL");
        }
        if (!isset($message['TLOGON'])) {
            $message['TLOGON'] = gettext("ALL");
        }
        if (!isset($message['MOVED_TID'])) {
            $message['MOVED_TID'] = 0;
        }
        if (!isset($message['MOVED_PID'])) {
            $message['MOVED_PID'] = 0;
        }
        if (!is_array($messages)) {
            $messages = array();
        }
        $messages[] = $message;
    }
    return $limit > 1 ? $messages : array_shift($messages);
}
Example #7
0
function poll_get_random_users($limit)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($limit)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (($uid = session::get_value('UID')) === false) {
        return false;
    }
    $sql = "SELECT UID, LOGON, NICKNAME, PEER_NICKNAME FROM (SELECT USER.UID, ";
    $sql .= "USER.LOGON, USER.NICKNAME, USER_PEER.PEER_NICKNAME, VISITOR_LOG.LAST_LOGON, ";
    $sql .= "(SELECT COUNT(*) FROM VISITOR_LOG WHERE FORUM = {$forum_fid}) ";
    $sql .= "AS VISITOR_COUNT FROM USER LEFT JOIN VISITOR_LOG VISITOR_LOG ";
    $sql .= "ON (VISITOR_LOG.UID = USER.UID AND VISITOR_LOG.FORUM = {$forum_fid}) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ";
    $sql .= "ON (USER_PEER.PEER_UID = USER.UID AND USER_PEER.UID = '{$uid}') HAVING VISITOR_COUNT = 0 ";
    $sql .= "OR VISITOR_LOG.LAST_LOGON > DATE_SUB(NOW(), INTERVAL 14 DAY) ";
    $sql .= "ORDER BY RAND() LIMIT {$limit}) AS RANDOM_USERS";
    if (!($result = $db->query($sql))) {
        return false;
    }
    $poll_get_random_votes = array();
    while ($poll_random_vote_data = $result->fetch_assoc()) {
        if (isset($poll_random_vote_data['PEER_NICKNAME'])) {
            if (!is_null($poll_random_vote_data['PEER_NICKNAME']) && strlen(trim($poll_random_vote_data['PEER_NICKNAME'])) > 0) {
                $poll_random_vote_data['NICKNAME'] = $poll_random_vote_data['PEER_NICKNAME'];
            }
        }
        unset($poll_random_vote_data['PEER_NICKNAME']);
        $poll_get_random_votes[] = $poll_random_vote_data;
    }
    return $poll_get_random_votes;
}
Example #8
0
function email_send_folder_subscription($tid, $pid)
{
    if (!is_numeric($tid)) {
        return false;
    }
    if (!is_numeric($pid)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (!($transport = Swift_TransportFactory::get())) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    $webtag = get_webtag();
    forum_check_webtag_available($webtag);
    $folder_subscribed = FOLDER_SUBSCRIBED;
    $thread_subscribed = THREAD_SUBSCRIBED;
    $user_ignored_completely = USER_IGNORED_COMPLETELY;
    $sql = "SELECT THREAD.TITLE AS THREAD_TITLE, THREAD.FID AS FOLDER_FID, TO_USER.UID, TO_USER.LOGON, ";
    $sql .= "TO_USER.NICKNAME, TO_USER.EMAIL, FROM_USER.LOGON AS FROM_LOGON, FROM_USER.NICKNAME AS FROM_NICKNAME, ";
    $sql .= "USER_PEER.RELATIONSHIP, POST_PREVIOUS.CREATED, USER_FORUM.LAST_VISIT FROM `{$table_prefix}THREAD` THREAD ";
    $sql .= "INNER JOIN `{$table_prefix}POST` POST ON (POST.TID = THREAD.TID) ";
    $sql .= "INNER JOIN `{$table_prefix}USER_FOLDER` USER_FOLDER ON (USER_FOLDER.FID = THREAD.FID AND USER_FOLDER.INTEREST = {$folder_subscribed}) ";
    $sql .= "INNER JOIN USER TO_USER ON (TO_USER.UID = USER_FOLDER.UID) ";
    $sql .= "INNER JOIN USER FROM_USER ON (FROM_USER.UID = POST.FROM_UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ON (USER_PEER.UID = TO_USER.UID AND USER_PEER.PEER_UID = POST.FROM_UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}POST` POST_PREVIOUS ON (POST_PREVIOUS.TID = POST.TID AND POST_PREVIOUS.PID = POST.PID - 1) ";
    $sql .= "LEFT JOIN USER_FORUM ON (USER_FORUM.UID = TO_USER.UID AND USER_FORUM.FID = {$forum_fid}) ";
    $sql .= "WHERE USER_FOLDER.UID NOT IN (SELECT UID FROM `{$table_prefix}USER_THREAD` WHERE TID = THREAD.TID AND INTEREST = {$thread_subscribed}) ";
    $sql .= "AND USER_FOLDER.UID NOT IN (SELECT FROM_UID FROM `{$table_prefix}POST` WHERE TID = POST.TID AND PID = POST.PID) ";
    $sql .= "AND USER_FOLDER.UID NOT IN (SELECT TO_UID FROM `{$table_prefix}POST_RECIPIENT` WHERE TID = POST.TID AND PID = POST.PID) ";
    $sql .= "AND THREAD.TID = {$tid} AND POST.PID = {$pid} ";
    $sql .= "HAVING (RELATIONSHIP IS NULL OR RELATIONSHIP & {$user_ignored_completely} = 0) ";
    $sql .= "AND (LAST_VISIT > CREATED OR CREATED IS NULL) ";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    $mailer = Swift_Mailer::newInstance($transport);
    $count = 0;
    while (($email_data = $result->fetch_assoc()) !== null) {
        if (!email_address_valid($email_data['EMAIL'])) {
            continue;
        }
        $forum_name = word_filter_apply(forum_get_setting('forum_name', null, 'A Beehive Forum'), $email_data['UID'], true);
        $subject = word_filter_apply(sprintf(gettext("Folder Subscription Notification from %1\$s"), $forum_name), $email_data['UID'], true);
        $recipient = word_filter_apply(format_user_name($email_data['LOGON'], $email_data['NICKNAME']), $email_data['UID'], true);
        $message_author = word_filter_apply(format_user_name($email_data['FROM_LOGON'], $email_data['FROM_NICKNAME']), $email_data['UID'], true);
        $thread_title = word_filter_apply($email_data['THREAD_TITLE'], $email_data['UID'], true);
        $forum_link = html_get_forum_uri("index.php?webtag={$webtag}&final_uri=folder_subscriptions.php%3Fwebtag%3D{$webtag}");
        $message_link = html_get_forum_uri("index.php?webtag={$webtag}&msg={$tid}.{$pid}");
        $message = Swift_MessageBeehive::newInstance();
        $message->setTo($email_data['EMAIL'], $recipient);
        $message->setSubject($subject);
        $message->setBody(wordwrap(sprintf(gettext("Hello %1\$s,\n\n%2\$s posted a message in a folder you are subscribed to on %3\$s.\n\nThe subject is: %4\$s.\n\nTo read that message and others in the same discussion, please go to:\n%5\$s\n\nNote: If you do not wish to receive email notifications of new messages in this thread, go to: %6\$s and adjust your Interest level by clicking on the folder's icon at the top of page."), $recipient, $message_author, $forum_name, $thread_title, $message_link, $forum_link)));
        $message->addPart(wordwrap_html(sprintf(gettext("<p>Hello %1\$s,</p><p>%2\$s posted a message in a folder you are subscribed to on %3\$s.</p><p>The subject is: %4\$s.</p><p>To read that message and others in the same discussion, please go to:<br /><a href=\"%5\$s\">%5\$s</a></p><p>Note: If you do not wish to receive email notifications of new messages in this thread, go to: <a href=\"%6\$s\">%6\$s</a><br />and adjust your Interest level by clicking on the folder's icon at the top of page.</p>"), $recipient, $message_author, $forum_name, $thread_title, $message_link, $forum_link)), 'text/html');
        $count += $mailer->send($message);
    }
    return $count;
}
Example #9
0
 public static function refresh($uid)
 {
     $ip_address = get_ip_address();
     $http_referer = session::get_http_referer();
     if (!($forum_fid = get_forum_fid())) {
         $forum_fid = 0;
     }
     if (!($user = user_get($uid))) {
         $user = array('UID' => 0, 'LOGON' => 'GUEST', 'NICKNAME' => 'Guest', 'EMAIL' => '');
     }
     unset($user['IPADDRESS'], $user['PASSWD'], $user['REFERER']);
     $_SESSION = array_merge($_SESSION, $user);
     $_SESSION['FID'] = $forum_fid;
     $_SESSION['IPADDRESS'] = get_ip_address();
     if (session::logged_in() && ($user_prefs = user_get_prefs($uid))) {
         $_SESSION = array_merge($_SESSION, $user_prefs);
     }
     if ($user_perms = session::get_perm_array($uid, $forum_fid)) {
         $_SESSION['PERMS'] = $user_perms;
     }
     if (!isset($_SESSION['REFERER'])) {
         $_SESSION['REFERER'] = session::get_http_referer();
     }
     if (!isset($_SESSION['RAND_HASH'])) {
         $_SESSION['RAND_HASH'] = md5(uniqid(mt_rand()));
     }
     if (isset($user_prefs['STYLE'])) {
         html_set_cookie("forum_style", $user_prefs['STYLE'], time() + YEAR_IN_SECONDS);
     }
 }
function attachments_get_folder_fid($aid)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_md5($aid)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $sql = "SELECT FOLDER.FID FROM POST_ATTACHMENT_IDS PAI ";
    $sql .= "LEFT JOIN `{$table_prefix}POST` POST ON (POST.TID = PAI.TID AND POST.PID = PAI.PID) ";
    $sql .= "LEFT JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = POST.TID) ";
    $sql .= "LEFT JOIN `{$table_prefix}FOLDER` FOLDER ON (FOLDER.FID = THREAD.FID) ";
    $sql .= "WHERE PAI.FID = '{$forum_fid}' AND PAI.AID = '{$aid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    list($folder_fid) = $result->fetch_row();
    return $folder_fid;
}
require_once BH_INCLUDE_PATH . 'post.inc.php';
require_once BH_INCLUDE_PATH . 'session.inc.php';
// Check we're logged in correctly
if (!session::logged_in()) {
    html_guest_error();
}
// Check we have Admin / Moderator access
if (!session::check_perm(USER_PERM_ADMIN_TOOLS, 0) || forum_get_setting('access_level', FORUM_DISABLED)) {
    html_draw_error(gettext("You do not have permission to use this section."));
}
// Perform additional admin login.
admin_check_credentials();
// Get the forum settings
$forum_settings = forum_get_settings();
// Get forum fid
$forum_fid = get_forum_fid();
if (isset($_GET['ret']) && strlen(trim($_GET['ret'])) > 0) {
    $ret = rawurldecode(trim($_GET['ret']));
} else {
    if (isset($_POST['ret']) && strlen(trim($_POST['ret'])) > 0) {
        $ret = trim($_POST['ret']);
    } else {
        $ret = "admin_forums.php?webtag={$webtag}";
    }
}
// Array to hold error messages
$error_msg_array = array();
// validate the return to page
if (isset($ret) && strlen(trim($ret)) > 0) {
    $available_files_preg = implode("|^", array_map('preg_quote_callback', get_available_files()));
    if (preg_match("/^{$available_files_preg}/u", basename($ret)) < 1) {
Example #12
0
function admin_send_link_approval_notification()
{
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $user_perm_links_moderate = USER_PERM_LINKS_MODERATE;
    $notification_success = true;
    $sql = "SELECT DISTINCT GROUP_USERS.UID, BIT_OR(GROUP_PERMS.PERM) AS PERM ";
    $sql .= "FROM GROUP_USERS INNER JOIN GROUPS ON (GROUPS.GID = GROUP_USERS.GID) ";
    $sql .= "INNER JOIN GROUP_PERMS ON (GROUP_PERMS.GID = GROUPS.GID) ";
    $sql .= "INNER JOIN USER ON (USER.UID = GROUP_USERS.UID) ";
    $sql .= "WHERE GROUP_PERMS.FORUM IN (0, {$forum_fid}) AND GROUP_PERMS.FID = 0 ";
    $sql .= "GROUP BY GROUP_USERS.UID HAVING PERM & {$user_perm_links_moderate} > 0";
    if (!($result = $db->query($sql))) {
        return false;
    }
    while (list($admin_uid) = $result->fetch_row()) {
        if (!email_send_link_approval_notification($admin_uid)) {
            $notification_success = false;
        }
    }
    return $notification_success;
}
Example #13
0
function user_is_active($uid)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($uid)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $sql = "SELECT COUNT(*) FROM SESSIONS WHERE UID = '{$uid}' ";
    $sql .= "AND FID = '{$forum_fid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($user_active_count) = $result->fetch_row();
    return $user_active_count > 0;
}
Example #14
0
function search_mysql_execute($search_arguments, &$error)
{
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    // Database connection.
    if (!($db = db::get())) {
        return false;
    }
    // If the user has specified a folder within their viewable scope limit them
    // to that folder, otherwise limit them to their available folders.
    $where_sql = "WHERE THREAD.FID IN ({$search_arguments['fid']}) ";
    // Can't search for deleted threads nor threads with no posts
    $where_sql .= "AND THREAD.DELETED = 'N' AND THREAD.LENGTH > 0 AND (THREAD.APPROVED IS NOT NULL OR THREAD.BY_UID = '{$_SESSION['UID']}') ";
    // Where query needs to limit the search results to the user specified date range.
    $where_sql .= search_date_range($search_arguments['date_from'], $search_arguments['date_to'], SEARCH_DATE_RANGE_SQL);
    // No select, joins, from or having clauses by default.
    $select_sql = null;
    $join_sql = null;
    $from_sql = null;
    $having_sql = null;
    // Username based search.
    if (isset($search_arguments['user_uid_array']) && sizeof($search_arguments['user_uid_array']) > 0) {
        // Base query slightly different if you're not searching by keywords
        if (isset($search_arguments['group_by_thread']) && $search_arguments['group_by_thread'] == SEARCH_GROUP_THREADS) {
            $select_sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) SELECT SQL_NO_CACHE ";
            $select_sql .= "SQL_BUFFER_RESULT {$_SESSION['UID']}, {$forum_fid}, POST.TID, MIN(POST.PID), ";
            $select_sql .= "1.0 AS RELEVANCE ";
        } else {
            $select_sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) SELECT SQL_NO_CACHE ";
            $select_sql .= "SQL_BUFFER_RESULT {$_SESSION['UID']}, {$forum_fid}, POST.TID, POST.PID, ";
            $select_sql .= "1.0 AS RELEVANCE ";
        }
        // Save the sort by and sort dir.
        search_save_arguments($search_arguments);
        // FROM query uses POST table if we're not using keyword searches.
        $from_sql = "FROM `{$table_prefix}POST` POST ";
        // Join to the THREAD table for the TID
        $join_sql = "INNER JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = POST.TID) ";
        // Combine the user UIDs into a comma-separated list.
        $user_uids = implode(',', array_filter($search_arguments['user_uid_array'], 'is_numeric'));
        // Check if we're searching for threads or posts started by these users.
        if (isset($search_arguments['user_include']) && is_numeric($search_arguments['user_include'])) {
            if ($search_arguments['user_include'] == SEARCH_FILTER_USER_THREADS) {
                $where_sql .= "AND THREAD.BY_UID IN ({$user_uids}) AND POST.PID = 1 ";
            } else {
                if ($search_arguments['user_include'] == SEARCH_FILTER_USER_POSTS) {
                    $where_sql .= "AND POST.FROM_UID IN ({$user_uids}) ";
                }
            }
        }
    }
    /// Keyword based search.
    if (isset($search_arguments['search_string']) && strlen(trim($search_arguments['search_string'])) > 0) {
        $search_string = $db->escape($search_arguments['search_string']);
        $from_sql = "FROM `{$table_prefix}POST_CONTENT` POST_CONTENT ";
        $join_sql = "INNER JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = POST_CONTENT.TID) ";
        $join_sql .= "INNER JOIN `{$table_prefix}POST` POST ON (POST.TID = POST_CONTENT.TID AND POST.PID = POST_CONTENT.PID) ";
        $having_sql = "HAVING RELEVANCE > 0.2 ";
        search_save_arguments($search_arguments);
        if (isset($search_arguments['group_by_thread']) && $search_arguments['group_by_thread'] == SEARCH_GROUP_THREADS) {
            $select_sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) ";
            $select_sql .= "SELECT SQL_NO_CACHE SQL_BUFFER_RESULT {$_SESSION['UID']}, {$forum_fid}, ";
            $select_sql .= "POST.TID, MIN(POST.PID), MATCH(POST_CONTENT.CONTENT, THREAD.TITLE) ";
            $select_sql .= "AGAINST('{$search_string}' IN BOOLEAN MODE) AS RELEVANCE ";
        } else {
            $select_sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) ";
            $select_sql .= "SELECT SQL_NO_CACHE SQL_BUFFER_RESULT {$_SESSION['UID']}, {$forum_fid}, ";
            $select_sql .= "POST.TID, POST.PID, MATCH(POST_CONTENT.CONTENT, THREAD.TITLE) ";
            $select_sql .= "AGAINST('{$search_string}' IN BOOLEAN MODE) AS RELEVANCE ";
        }
        $where_sql .= "AND MATCH(POST_CONTENT.CONTENT) AGAINST('{$search_string}' IN BOOLEAN MODE) ";
    } else {
        if (isset($search_arguments['search_tag']) && strlen(trim($search_arguments['search_tag'])) > 0) {
            $search_tag = $db->escape($search_arguments['search_tag']);
            $from_sql = "FROM `{$table_prefix}POST` POST ";
            $join_sql = "INNER JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = POST.TID) ";
            $join_sql .= "INNER JOIN `{$table_prefix}POST_TAG` POST_TAG ON (POST_TAG.TID = POST.TID AND POST_TAG.PID = POST.PID) ";
            $join_sql .= "INNER JOIN `{$table_prefix}TAG` TAG ON (TAG.TID = POST_TAG.TAG) ";
            search_save_arguments($search_arguments);
            if (isset($search_arguments['group_by_thread']) && $search_arguments['group_by_thread'] == SEARCH_GROUP_THREADS) {
                $select_sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) ";
                $select_sql .= "SELECT SQL_NO_CACHE SQL_BUFFER_RESULT {$_SESSION['UID']}, {$forum_fid}, ";
                $select_sql .= "POST.TID, MIN(POST.PID), 1.0 AS RELEVANCE ";
            } else {
                $select_sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) ";
                $select_sql .= "SELECT SQL_NO_CACHE SQL_BUFFER_RESULT {$_SESSION['UID']}, {$forum_fid}, ";
                $select_sql .= "POST.TID, POST.PID, 1.0 AS RELEVANCE ";
            }
            $where_sql .= "AND TAG.TAG = '{$search_tag}' ";
        } else {
            if (!isset($search_arguments['user_uid_array']) || sizeof($search_arguments['user_uid_array']) < 1) {
                $error = SEARCH_NO_MATCHES;
                return false;
            }
        }
    }
    // If the user wants results grouped by thread (TID) then do so.
    if (isset($search_arguments['group_by_thread']) && $search_arguments['group_by_thread'] == SEARCH_GROUP_THREADS) {
        $group_sql = "GROUP BY THREAD.TID ";
    } else {
        $group_sql = "";
    }
    // Get the correct sort dir
    $sort_dir = $search_arguments['sort_dir'] == SEARCH_SORT_DESC ? 'DESC' : 'ASC';
    // Construct the order by clause.
    switch ($search_arguments['sort_by']) {
        case SEARCH_SORT_RELEVANCE:
            $order_sql = "ORDER BY RELEVANCE {$sort_dir} ";
            break;
        case SEARCH_SORT_NUM_REPLIES:
            $order_sql = "ORDER BY THREAD.LENGTH {$sort_dir} ";
            break;
        case SEARCH_SORT_FOLDER_NAME:
            $order_sql = "ORDER BY THREAD.FID {$sort_dir} ";
            break;
        case SEARCH_SORT_AUTHOR_NAME:
            $order_sql = "ORDER BY POST.FROM_UID {$sort_dir} ";
            break;
        default:
            $order_sql = "ORDER BY POST.CREATED {$sort_dir} ";
            break;
    }
    // Set a limit of 1000 results.
    $limit_sql = "LIMIT 0, 1000 ";
    // Build the final query.
    $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ";
    $sql .= "{$group_sql} {$having_sql} {$order_sql} {$limit_sql}";
    // Execute the query
    if (!$db->query($sql)) {
        return false;
    }
    // Check the number of results
    if ($db->affected_rows > 0) {
        return true;
    }
    // No results from search.
    $error = SEARCH_NO_MATCHES;
    return false;
}
Example #15
0
function perm_folder_reset_user_permissions($fid)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($fid)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $folder_perms = perm_folder_get_permissions($fid);
    $user_perm_folder_moderate = USER_PERM_FOLDER_MODERATE;
    $remove_perms = (double) USER_PERM_BANNED | USER_PERM_WORMED;
    $remove_perms = (double) $remove_perms | USER_PERM_ADMIN_TOOLS | USER_PERM_FORUM_TOOLS;
    $remove_perms = (double) $remove_perms | USER_PERM_LINKS_MODERATE | USER_PERM_EMAIL_CONFIRM;
    $remove_perms = (double) $remove_perms | USER_PERM_CAN_IGNORE_ADMIN | USER_PERM_PILLORIED;
    $folder_perms = $folder_perms & ~$remove_perms;
    $sql = "UPDATE LOW_PRIORITY GROUPS INNER JOIN GROUP_PERMS ON (GROUP_PERMS.GID = GROUPS.GID) ";
    $sql .= "SET GROUP_PERMS.PERM = '{$folder_perms}' | (PERM & {$user_perm_folder_moderate}) ";
    $sql .= "WHERE GROUP_PERMS.FID = '{$fid}' AND GROUPS.FORUM = {$forum_fid}";
    if (!$db->query($sql)) {
        return false;
    }
    return true;
}
Example #16
0
function email_send_folder_subscription($fuid, $fid, $tid, $pid, $modified, &$exclude_user_array)
{
    // Validate function arguments
    if (!is_numeric($fuid)) {
        return false;
    }
    if (!is_numeric($fid)) {
        return false;
    }
    if (!is_numeric($tid)) {
        return false;
    }
    if (!is_numeric($pid)) {
        return false;
    }
    if (!is_numeric($modified)) {
        return false;
    }
    // Check the thread is valid
    if (!($thread = thread_get($tid))) {
        return false;
    }
    // Get the from user details
    if (!($from_user = user_get($fuid))) {
        return false;
    }
    // Get the forum details.
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    // Get the Swift Mailer Transport
    if (!($transport = Swift_TransportFactory::get())) {
        return false;
    }
    //Create the Mailer using the returned Transport
    $mailer = Swift_Mailer::newInstance($transport);
    // Create a new message
    $message = Swift_MessageBeehive::newInstance();
    // Database connection.
    if (!($db = db::get())) {
        return false;
    }
    // Make sure $exclude_user_array is an array.
    if (!is_array($exclude_user_array)) {
        $exclude_user_array = array();
    }
    // Add the $fuid to it.
    array_push($exclude_user_array, $fuid);
    // Make sure it only contains numbers and implode it.
    $exclude_user_list = implode(",", array_filter($exclude_user_array, 'is_numeric'));
    // Get the forum webtag
    $webtag = get_webtag();
    // Only send the email to people who logged after the thread was modified.
    $last_visit_datetime = date(MYSQL_DATETIME, $modified);
    $sql = "SELECT USER_FOLDER.UID, USER.LOGON, USER.NICKNAME, USER.EMAIL ";
    $sql .= "FROM `{$table_prefix}USER_FOLDER` USER_FOLDER ";
    $sql .= "LEFT JOIN USER ON (USER.UID = USER_FOLDER.UID) ";
    $sql .= "LEFT JOIN USER_FORUM ON (USER_FORUM.UID = USER_FOLDER.UID ";
    $sql .= "AND USER_FORUM.FID = '{$forum_fid}') WHERE USER_FOLDER.FID = '{$fid}' ";
    $sql .= "AND USER_FORUM.LAST_VISIT > CAST('{$last_visit_datetime}' AS DATETIME) ";
    $sql .= "AND USER_FOLDER.INTEREST = 1 AND USER_FOLDER.UID NOT IN ({$exclude_user_list})";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows < 1) {
        return false;
    }
    while ($to_user = $result->fetch_assoc()) {
        // Validate the email address before we continue.
        if (!email_address_valid($to_user['EMAIL'])) {
            continue;
        }
        // Add the uid to exclude array
        array_push($exclude_user_array, $to_user['UID']);
        // Get the required variables (forum name, subject, recipient, etc.) and
        // pass them all through the recipient's word filter.
        $forum_name = word_filter_apply(forum_get_setting('forum_name', null, 'A Beehive Forum'), $to_user['UID'], true);
        $subject = word_filter_apply(sprintf(gettext("Subscription Notification from %s"), $forum_name), $to_user['UID'], true);
        $recipient = word_filter_apply(format_user_name($to_user['LOGON'], $to_user['NICKNAME']), $to_user['UID'], true);
        $message_author = word_filter_apply(format_user_name($from_user['LOGON'], $from_user['NICKNAME']), $to_user['UID'], true);
        $thread_title = word_filter_apply($thread['TITLE'], $to_user['UID'], true);
        // Generate link to the forum itself
        $forum_link = html_get_forum_uri("index.php?webtag={$webtag}&fid={$fid}");
        // Generate the message link.
        $message_link = html_get_forum_uri("index.php?webtag={$webtag}&msg={$tid}.{$pid}");
        // Generate the message body.
        $message_body = wordwrap(sprintf(gettext("Hello %s,\r\n\r\n%s posted a message in a folder you are subscribed to on %s.\r\n\r\nThe subject is: %s.\r\n\r\nTo read that message and others in the same discussion, go to:\r\n%s\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nNote: If you do not wish to receive email notifications of new messages in this thread, go to: %s and adjust your Interest level by clicking on the folder's icon at the top of page."), $recipient, $message_author, $forum_name, $thread_title, $message_link, $forum_link));
        // Add the recipient
        $message->setTo($to_user['EMAIL'], $recipient);
        // Set the subject
        $message->setSubject($subject);
        // Set the message body
        $message->setBody($message_body);
        // Send the email
        $mailer->send($message);
    }
    return true;
}
Example #17
0
function thread_has_attachments(&$thread_data)
{
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (!isset($thread_data['TID'])) {
        return false;
    }
    if (!is_numeric($thread_data['TID'])) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    $sql = "SELECT PAI.TID, COUNT(PAF.HASH) AS ATTACHMENT_COUNT ";
    $sql .= "FROM POST_ATTACHMENT_IDS PAI INNER JOIN POST_ATTACHMENT_FILES PAF ";
    $sql .= "ON (PAF.AID = PAI.AID) WHERE PAI.FID = '{$forum_fid}' ";
    $sql .= "AND PAI.TID = '{$thread_data['TID']}' GROUP BY PAI.TID";
    if (!($result = $db->query($sql))) {
        return false;
    }
    $attachment_data = $result->fetch_assoc();
    $thread_data['ATTACHMENT_COUNT'] = $attachment_data['ATTACHMENT_COUNT'];
    return true;
}
Example #18
0
function poll_get($tid)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($tid)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    $session_gc_maxlifetime = ini_get('session.gc_maxlifetime');
    $session_cutoff_datetime = date(MYSQL_DATETIME, time() - $session_gc_maxlifetime);
    $sql = "SELECT FOLDER.FID, POST.TID, POST.PID, POST.REPLY_TO_PID, POST.FROM_UID, UNIX_TIMESTAMP(POST.CREATED) AS CREATED, ";
    $sql .= "UNIX_TIMESTAMP(POST.EDITED) AS EDITED, POST.EDITED_BY, POST.IPADDRESS, POST.MOVED_TID, POST.MOVED_PID, ";
    $sql .= "UNIX_TIMESTAMP(POST.APPROVED) AS APPROVED, POST.APPROVED_BY, USER.LOGON AS FROM_LOGON, ";
    $sql .= "COALESCE(USER_PEER.PEER_NICKNAME, USER.NICKNAME) AS FROM_NICKNAME, USER_PEER.RELATIONSHIP AS RELATIONSHIP, ";
    $sql .= "USER_PREFS_GLOBAL.ANON_LOGON, COALESCE(USER_PREFS_FORUM.AVATAR_URL, USER_PREFS_GLOBAL.AVATAR_URL) AS AVATAR_URL, ";
    $sql .= "COALESCE(USER_PREFS_FORUM.AVATAR_AID, USER_PREFS_GLOBAL.AVATAR_AID) AS AVATAR_AID, ";
    $sql .= "(SELECT MAX(SESSIONS.TIME) FROM SESSIONS WHERE SESSIONS.TIME >= CAST('{$session_cutoff_datetime}' AS DATETIME) ";
    $sql .= "AND SESSIONS.FID = {$forum_fid} AND SESSIONS.UID = POST.FROM_UID) AS USER_ACTIVE, ";
    $sql .= "POLL.CHANGEVOTE, POLL.POLLTYPE, POLL.SHOWRESULTS, POLL.VOTETYPE, POLL.OPTIONTYPE, ";
    $sql .= "UNIX_TIMESTAMP(POLL.CLOSES) AS CLOSES, POLL.ALLOWGUESTS ";
    $sql .= "FROM `{$table_prefix}POST` POST LEFT JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = POST.TID) ";
    $sql .= "LEFT JOIN `{$table_prefix}FOLDER` FOLDER ON (FOLDER.FID = THREAD.FID) LEFT JOIN USER ON (POST.FROM_UID = USER.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ON (USER_PEER.UID = '{$_SESSION['UID']}' ";
    $sql .= "AND USER_PEER.PEER_UID = POST.FROM_UID) LEFT JOIN `{$table_prefix}USER_PREFS` ";
    $sql .= "USER_PREFS_FORUM ON (USER_PREFS_FORUM.UID = POST.FROM_UID) LEFT JOIN USER_PREFS USER_PREFS_GLOBAL ";
    $sql .= "ON (USER_PREFS_GLOBAL.UID = POST.FROM_UID) LEFT JOIN `{$table_prefix}POLL` POLL ON (POST.TID = POLL.TID) ";
    $sql .= "WHERE POST.TID = '{$tid}' AND POST.PID = 1";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    if (!($message = $result->fetch_assoc())) {
        return false;
    }
    $message['CONTENT'] = '';
    $message['ATTACHMENTS'] = array();
    $message['RECIPIENTS'] = array();
    if (!isset($message['FROM_NICKNAME'])) {
        $message['FROM_NICKNAME'] = gettext("Unknown user");
    }
    if (!isset($message['FROM_LOGON'])) {
        $message['FROM_LOGON'] = gettext("Unknown user");
    }
    if (!isset($message['FROM_UID'])) {
        $message['FROM_UID'] = -1;
    }
    $messages_array = array($message['PID'] => $message);
    messages_get_recipients($tid, $messages_array);
    messages_have_attachments($tid, $messages_array);
    messages_get_ratings($tid, $messages_array);
    return $messages_array[$message['PID']];
}
function visitor_log_clean_up()
{
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    // Keep visitor log for 7 days.
    $visitor_cutoff_datetime = date(MYSQL_DATETIME_MIDNIGHT, time() - DAY_IN_SECONDS * 7);
    $sql = "DELETE QUICK FROM VISITOR_LOG WHERE FORUM = '{$forum_fid}' ";
    $sql .= "AND LAST_LOGON < CAST('{$visitor_cutoff_datetime}' AS DATETIME)";
    if (!$db->query($sql)) {
        return false;
    }
    return true;
}
Example #20
0
function sphinx_search_execute($search_arguments, &$error)
{
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    /** @var mysqli $sphinx */
    if (!($sphinx = sphinx_search_connect())) {
        $error = SEARCH_SPHINX_UNAVAILABLE;
        return false;
    }
    // Sphinx Search index name is the forum's webtag.
    if (!($sphinx_search_index = get_webtag())) {
        $error = SEARCH_SPHINX_UNAVAILABLE;
        return false;
    }
    // Validate the webtag
    if (!forum_check_webtag_available($sphinx_search_index)) {
        $error = SEARCH_SPHINX_UNAVAILABLE;
        return false;
    }
    // Regular Database connection.
    if (!($db = db::get())) {
        return false;
    }
    // If the user has specified a folder within their viewable scope limit them
    // to that folder, otherwise limit them to their available folders.
    $where_sql = "WHERE forum = {$forum_fid} AND fid IN ({$search_arguments['fid']}) ";
    // Where query needs to limit the search results to the user specified date range.
    $where_sql .= sphinx_search_date_range($search_arguments['date_from'], $search_arguments['date_to']);
    // Username based search.
    if (isset($search_arguments['user_uid_array']) && sizeof($search_arguments['user_uid_array']) > 0) {
        // Save the sort by and sort dir.
        search_save_arguments($search_arguments);
        // Combine the user UIDs into a comma-seperated list.
        $user_uids = implode(',', array_filter($search_arguments['user_uid_array'], 'is_numeric'));
        // Check if we're searching for threads or posts started by these users.
        if (isset($search_arguments['user_include']) && is_numeric($search_arguments['user_include'])) {
            if ($search_arguments['user_include'] == SEARCH_FILTER_USER_THREADS) {
                $where_sql .= "AND by_uid IN ({$user_uids}) AND pid = 1 ";
            } else {
                if ($search_arguments['user_include'] == SEARCH_FILTER_USER_POSTS) {
                    $where_sql .= "AND from_uid IN ({$user_uids}) ";
                }
            }
        }
    }
    /// Keyword based search.
    if (isset($search_arguments['search_string']) && strlen(trim($search_arguments['search_string'])) > 0) {
        // Sphinx doesn't like -- in MATCH. Don't know if it's because it
        // thinks it is a MySQL-style comment or a bug. We have no choice
        // but to strip it out.
        $search_string = $sphinx->real_escape_string(str_replace('--', '', $search_arguments['search_string']));
        search_save_arguments($search_arguments);
        $where_sql .= "AND MATCH('{$search_string}')";
    } else {
        if (!isset($search_arguments['user_uid_array']) || sizeof($search_arguments['user_uid_array']) < 1) {
            $error = SEARCH_NO_MATCHES;
            return false;
        }
    }
    // If the user wants results grouped by thread (TID) then do so.
    if (isset($search_arguments['group_by_thread']) && $search_arguments['group_by_thread'] == SEARCH_GROUP_THREADS) {
        $group_sql = "GROUP BY tid";
    } else {
        $group_sql = "";
    }
    // Get the correct sort dir
    $sort_dir = $search_arguments['sort_dir'] == SEARCH_SORT_DESC ? 'DESC' : 'ASC';
    // Construct the order by clause.
    switch ($search_arguments['sort_by']) {
        case SEARCH_SORT_NUM_REPLIES:
            $order_sql = "ORDER BY length {$sort_dir}";
            break;
        case SEARCH_SORT_FOLDER_NAME:
            $order_sql = "ORDER BY fid {$sort_dir}";
            break;
        case SEARCH_SORT_AUTHOR_NAME:
            $order_sql = "ORDER BY from_uid {$sort_dir}";
            break;
        default:
            $order_sql = "ORDER BY created {$sort_dir}";
            break;
    }
    // Prepend _DELTA to the end of the index name.
    $sphinx_search_index_delta = sprintf('%s_DELTA', $sphinx_search_index);
    // Build query including main and delta indexes.
    $sql = "SELECT *, WEIGHT() FROM {$sphinx_search_index}, {$sphinx_search_index_delta} ";
    $sql .= "{$where_sql} {$group_sql} {$order_sql} LIMIT 1000";
    // Execute the query
    if (!($result = $sphinx->query($sql))) {
        return false;
    }
    // Check if we have any results
    if ($result->num_rows == 0) {
        // No results from search.
        $error = SEARCH_NO_MATCHES;
        return false;
    }
    while (($search_result = $result->fetch_assoc()) !== null) {
        if (isset($search_result['weight()'])) {
            $weight = $search_result['weight()'];
        } else {
            if (isset($search_result['weight'])) {
                $weight = $search_result['weight'];
            } else {
                $weight = 0;
            }
        }
        $sql = "INSERT INTO SEARCH_RESULTS (UID, FORUM, TID, PID, RELEVANCE) ";
        $sql .= "SELECT '{$_SESSION['UID']}' AS UID, '{$forum_fid}' AS FORUM, THREAD.TID, POST.PID, ";
        $sql .= "{$weight} AS RELEVANCE FROM `{$table_prefix}POST` ";
        $sql .= "POST INNER JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = POST.TID) ";
        $sql .= "WHERE THREAD.TID = '{$search_result['tid']}' AND POST.PID = '{$search_result['pid']}' ";
        $sql .= "AND THREAD.LENGTH > 0 AND THREAD.DELETED = 'N' AND (THREAD.APPROVED IS NOT NULL ";
        $sql .= "OR THREAD.BY_UID = '{$_SESSION['UID']}') ";
        if (!$db->query($sql)) {
            return false;
        }
    }
    return true;
}
Example #21
0
function threads_have_attachments(&$threads_array)
{
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $tid_list = implode(",", array_filter(array_keys($threads_array), 'is_numeric'));
    if (!($db = db::get())) {
        return false;
    }
    $sql = "SELECT PAI.TID, PAF.AID FROM POST_ATTACHMENT_IDS PAI ";
    $sql .= "LEFT JOIN POST_ATTACHMENT_FILES PAF ON (PAF.AID = PAI.AID) ";
    $sql .= "WHERE PAI.FID = '{$forum_fid}' AND PAI.TID IN ({$tid_list}) ";
    if (!($result = $db->query($sql))) {
        return false;
    }
    while ($attachment_data = $result->fetch_assoc()) {
        $threads_array[$attachment_data['TID']]['AID'] = $attachment_data['AID'];
    }
    return true;
}
Example #22
0
 public static function update_visitor_log($uid, $force_update = false)
 {
     $http_referer = session::$db->escape(session::get_http_referer());
     $user_agent = session::$db->escape(session::get_user_agent());
     $ip_address = session::$db->escape(get_ip_address());
     if (!($forum_fid = get_forum_fid())) {
         $forum_fid = 0;
     }
     $current_datetime = date(MYSQL_DATETIME, time());
     $uid = is_numeric($uid) && $uid > 0 ? session::$db->escape($uid) : 'NULL';
     if (!($search_id = session::is_search_engine())) {
         $search_id = 'NULL';
     }
     if (!$force_update) {
         $sql = "SELECT UNIX_TIMESTAMP(MAX(LAST_LOGON)) FROM VISITOR_LOG WHERE FORUM = {$forum_fid} ";
         $sql .= "AND ((UID = {$uid} AND {$uid} IS NOT NULL) OR (SID = {$search_id} AND {$search_id} IS NOT NULL) ";
         $sql .= "OR (IPADDRESS = '{$ip_address}' AND {$uid} IS NULL AND {$search_id} IS NULL))";
         if (!($result = session::$db->query($sql))) {
             return false;
         }
         list($last_logon) = $result->fetch_row();
     }
     if (!isset($last_logon) || $last_logon < time() - HOUR_IN_SECONDS) {
         $sql = "REPLACE INTO VISITOR_LOG (FORUM, UID, LAST_LOGON, IPADDRESS, REFERER, USER_AGENT, SID) ";
         $sql .= "VALUES ('{$forum_fid}', {$uid}, CAST('{$current_datetime}' AS DATETIME), '{$ip_address}', ";
         $sql .= "'{$http_referer}', '{$user_agent}', {$search_id})";
         if (!session::$db->query($sql)) {
             return false;
         }
     }
     return true;
 }
function user_get_profile($uid)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($uid)) {
        return false;
    }
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $user_prefs = user_get_prefs($uid);
    $session_gc_maxlifetime = ini_get('session.gc_maxlifetime');
    $session_cutoff_datetime = date(MYSQL_DATETIME, time() - $session_gc_maxlifetime);
    $sql = "SELECT USER.UID, USER.LOGON, USER.NICKNAME, USER_PEER.PEER_NICKNAME, USER_PEER.RELATIONSHIP, ";
    $sql .= "SESSIONS.ID, UNIX_TIMESTAMP(USER_FORUM.LAST_VISIT) AS LAST_VISIT, UNIX_TIMESTAMP(USER.REGISTERED) AS REGISTERED, ";
    $sql .= "COALESCE(USER_POST_RATING.RATING, 0) AS POST_RATING, COUNT(POST_USER_RATING.RATING) AS POST_VOTE_TOTAL, ";
    $sql .= "COALESCE(SUM(IF(POST_USER_RATING.RATING > 0, 1, 0)), 0) AS POST_VOTE_UP, ";
    $sql .= "COALESCE(SUM(IF(POST_USER_RATING.RATING < 0, 1, 0)), 0) AS POST_VOTE_DOWN FROM USER USER ";
    $sql .= "LEFT JOIN USER_PREFS USER_PREFS_GLOBAL ON (USER_PREFS_GLOBAL.UID = USER.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PREFS` USER_PREFS_FORUM ON (USER_PREFS_FORUM.UID = USER.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ON (USER_PEER.PEER_UID = USER.UID AND USER_PEER.UID = '{$_SESSION['UID']}') ";
    $sql .= "LEFT JOIN USER_FORUM USER_FORUM ON (USER_FORUM.UID = USER.UID AND USER_FORUM.FID = '{$forum_fid}') ";
    $sql .= "LEFT JOIN SESSIONS ON (SESSIONS.UID = USER.UID AND SESSIONS.TIME >= CAST('{$session_cutoff_datetime}' AS DATETIME)) ";
    $sql .= "LEFT JOIN `{$table_prefix}POST_RATING` POST_USER_RATING ON (POST_USER_RATING.UID = USER.UID AND POST_USER_RATING.RATING IN (-1, 1)) ";
    $sql .= "LEFT JOIN (SELECT POST.FROM_UID AS UID, SUM(POST_RATING.RATING) AS RATING FROM `{$table_prefix}POST` POST ";
    $sql .= "INNER JOIN `{$table_prefix}POST_RATING` POST_RATING ON (POST_RATING.TID = POST.TID AND POST_RATING.PID = POST.PID) ";
    $sql .= "WHERE POST.FROM_UID = '{$uid}' GROUP BY POST.FROM_UID) AS USER_POST_RATING ON (USER_POST_RATING.UID = USER.UID) ";
    $sql .= "WHERE USER.UID = '{$uid}' GROUP BY USER.UID";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    $user_profile = $result->fetch_assoc();
    if (isset($user_prefs['ANON_LOGON']) && $user_prefs['ANON_LOGON'] > USER_ANON_DISABLED) {
        $anon_logon = $user_prefs['ANON_LOGON'];
    } else {
        $anon_logon = USER_ANON_DISABLED;
    }
    if ($anon_logon == USER_ANON_DISABLED && isset($user_profile['LAST_VISIT']) && $user_profile['LAST_VISIT'] > 0) {
        $user_profile['LAST_LOGON'] = format_date_time($user_profile['LAST_VISIT']);
    } else {
        $user_profile['LAST_LOGON'] = gettext("Unknown");
    }
    if (isset($user_profile['REGISTERED']) && $user_profile['REGISTERED'] > 0) {
        $user_profile['REGISTERED'] = format_date_time($user_profile['REGISTERED']);
    } else {
        $user_profile['REGISTERED'] = gettext("Unknown");
    }
    if (isset($user_prefs['DOB_DISPLAY']) && !empty($user_prefs['DOB']) && $user_prefs['DOB'] != "0000-00-00") {
        if ($user_prefs['DOB_DISPLAY'] == USER_DOB_DISPLAY_BOTH) {
            $user_profile['DOB'] = format_birthday($user_prefs['DOB']);
            $user_profile['AGE'] = format_age($user_prefs['DOB']);
        } else {
            if ($user_prefs['DOB_DISPLAY'] == USER_DOB_DISPLAY_DATE) {
                $user_profile['DOB'] = format_birthday($user_prefs['DOB']);
            } else {
                if ($user_prefs['DOB_DISPLAY'] == USER_DOB_DISPLAY_AGE) {
                    $user_profile['AGE'] = format_age($user_prefs['DOB']);
                }
            }
        }
    }
    if (isset($user_prefs['PIC_URL']) && filter_var($user_prefs['PIC_URL'], FILTER_VALIDATE_URL)) {
        $user_profile['PIC_URL'] = $user_prefs['PIC_URL'];
    }
    if (isset($user_prefs['PIC_AID']) && is_numeric($user_prefs['PIC_AID'])) {
        $user_profile['PIC_AID'] = $user_prefs['PIC_AID'];
    }
    if (isset($user_prefs['AVATAR_URL']) && filter_var($user_prefs['AVATAR_URL'], FILTER_VALIDATE_URL)) {
        $user_profile['AVATAR_URL'] = $user_prefs['AVATAR_URL'];
    }
    if (isset($user_prefs['AVATAR_AID']) && is_numeric($user_prefs['AVATAR_AID'])) {
        $user_profile['AVATAR_AID'] = $user_prefs['AVATAR_AID'];
    }
    if (isset($user_prefs['HOMEPAGE_URL']) && filter_var($user_prefs['HOMEPAGE_URL'], FILTER_VALIDATE_URL)) {
        $user_profile['HOMEPAGE_URL'] = $user_prefs['HOMEPAGE_URL'];
    }
    if (!isset($user_profile['RELATIONSHIP'])) {
        $user_profile['RELATIONSHIP'] = 0;
    }
    if (isset($user_profile['PEER_NICKNAME'])) {
        if (!is_null($user_profile['PEER_NICKNAME']) && strlen($user_profile['PEER_NICKNAME']) > 0) {
            $user_profile['NICKNAME'] = $user_profile['PEER_NICKNAME'];
        }
    }
    if ($anon_logon == USER_ANON_DISABLED) {
        if (isset($user_profile['ID'])) {
            $user_profile['STATUS'] = gettext("Online");
        } else {
            $user_profile['STATUS'] = gettext("Inactive / Offline");
        }
    } else {
        $user_profile['STATUS'] = gettext("Unknown");
    }
    if (($user_post_count = user_get_post_count($uid)) !== false) {
        $user_profile['POST_COUNT'] = $user_post_count;
    } else {
        $user_profile['POST_COUNT'] = 0;
    }
    if (($user_local_time = user_format_local_time($user_prefs)) !== false) {
        $user_profile['LOCAL_TIME'] = $user_local_time;
    }
    if (user_is_banned($uid)) {
        $user_profile['GROUPS'] = gettext("Banned");
    } else {
        if ($user_groups_array = perm_user_get_group_names($uid)) {
            $user_profile['GROUPS'] = implode(', ', $user_groups_array);
        } else {
            $user_profile['GROUPS'] = gettext("Registered");
        }
    }
    return $user_profile;
}
Example #24
0
function threads_have_attachments(&$threads_array)
{
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $tid_list = implode(',', array_filter(array_keys($threads_array), 'is_numeric'));
    if (!($db = db::get())) {
        return false;
    }
    $sql = "SELECT PAI.TID, COUNT(PAF.HASH) AS ATTACHMENT_COUNT ";
    $sql .= "FROM POST_ATTACHMENT_IDS PAI INNER JOIN POST_ATTACHMENT_FILES PAF ";
    $sql .= "ON (PAF.AID = PAI.AID) WHERE PAI.FID = '{$forum_fid}' ";
    $sql .= "AND PAI.TID IN ({$tid_list}) GROUP BY PAI.TID";
    if (!($result = $db->query($sql))) {
        return false;
    }
    while (($attachment_data = $result->fetch_assoc()) !== null) {
        $threads_array[$attachment_data['TID']]['ATTACHMENT_COUNT'] = $attachment_data['ATTACHMENT_COUNT'];
    }
    return true;
}
function user_get_profile($uid)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($uid)) {
        return false;
    }
    $peer_uid = session::get_value('UID');
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $user_groups_array = array();
    $user_prefs = user_get_prefs($uid);
    $session_gc_maxlifetime = ini_get('session.gc_maxlifetime');
    $session_cutoff_datetime = date(MYSQL_DATETIME, time() - $session_gc_maxlifetime);
    $sql = "SELECT USER.UID, USER.LOGON, USER.NICKNAME, USER_PEER.PEER_NICKNAME, ";
    $sql .= "UNIX_TIMESTAMP(USER_FORUM.LAST_VISIT) AS LAST_VISIT, ";
    $sql .= "UNIX_TIMESTAMP(USER.REGISTERED) AS REGISTERED, ";
    $sql .= "UNIX_TIMESTAMP(USER_TRACK.USER_TIME_BEST) AS USER_TIME_BEST, ";
    $sql .= "UNIX_TIMESTAMP(USER_TRACK.USER_TIME_TOTAL) AS USER_TIME_TOTAL, ";
    $sql .= "USER_PEER.RELATIONSHIP, SESSIONS.ID FROM USER USER ";
    $sql .= "LEFT JOIN USER_PREFS USER_PREFS_GLOBAL ON (USER_PREFS_GLOBAL.UID = USER.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PREFS` USER_PREFS_FORUM ";
    $sql .= "ON (USER_PREFS_FORUM.UID = USER.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ";
    $sql .= "ON (USER_PEER.PEER_UID = USER.UID AND USER_PEER.UID = '{$peer_uid}') ";
    $sql .= "LEFT JOIN USER_FORUM USER_FORUM ON (USER_FORUM.UID = USER.UID ";
    $sql .= "AND USER_FORUM.FID = '{$forum_fid}') ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_TRACK` USER_TRACK ";
    $sql .= "ON (USER_TRACK.UID = USER.UID) ";
    $sql .= "LEFT JOIN SESSIONS ON (SESSIONS.UID = USER.UID ";
    $sql .= "AND SESSIONS.TIME >= CAST('{$session_cutoff_datetime}' AS DATETIME)) ";
    $sql .= "WHERE USER.UID = '{$uid}' ";
    $sql .= "GROUP BY USER.UID";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    $user_profile = $result->fetch_assoc();
    if (isset($user_prefs['ANON_LOGON']) && $user_prefs['ANON_LOGON'] > USER_ANON_DISABLED) {
        $anon_logon = $user_prefs['ANON_LOGON'];
    } else {
        $anon_logon = USER_ANON_DISABLED;
    }
    if ($anon_logon == USER_ANON_DISABLED && isset($user_profile['LAST_VISIT']) && $user_profile['LAST_VISIT'] > 0) {
        $user_profile['LAST_LOGON'] = format_time($user_profile['LAST_VISIT']);
    } else {
        $user_profile['LAST_LOGON'] = gettext("Unknown");
    }
    if (isset($user_profile['REGISTERED']) && $user_profile['REGISTERED'] > 0) {
        $user_profile['REGISTERED'] = format_date($user_profile['REGISTERED']);
    } else {
        $user_profile['REGISTERED'] = gettext("Unknown");
    }
    if (isset($user_profile['USER_TIME_BEST']) && $user_profile['USER_TIME_BEST'] > 0) {
        $user_profile['USER_TIME_BEST'] = format_time_display($user_profile['USER_TIME_BEST']);
    } else {
        $user_profile['USER_TIME_BEST'] = gettext("Unknown");
    }
    if (isset($user_profile['USER_TIME_TOTAL']) && $user_profile['USER_TIME_TOTAL'] > 0) {
        $user_profile['USER_TIME_TOTAL'] = format_time_display($user_profile['USER_TIME_TOTAL']);
    } else {
        $user_profile['USER_TIME_TOTAL'] = gettext("Unknown");
    }
    if (isset($user_prefs['DOB_DISPLAY']) && !empty($user_prefs['DOB']) && $user_prefs['DOB'] != "0000-00-00") {
        if ($user_prefs['DOB_DISPLAY'] == USER_DOB_DISPLAY_BOTH) {
            $user_profile['DOB'] = format_birthday($user_prefs['DOB']);
            $user_profile['AGE'] = format_age($user_prefs['DOB']);
        } else {
            if ($user_prefs['DOB_DISPLAY'] == USER_DOB_DISPLAY_DATE) {
                $user_profile['DOB'] = format_birthday($user_prefs['DOB']);
            } else {
                if ($user_prefs['DOB_DISPLAY'] == USER_DOB_DISPLAY_AGE) {
                    $user_profile['AGE'] = format_age($user_prefs['DOB']);
                }
            }
        }
    }
    if (isset($user_prefs['PIC_URL']) && strlen($user_prefs['PIC_URL']) > 0) {
        $user_profile['PIC_URL'] = $user_prefs['PIC_URL'];
    }
    if (isset($user_prefs['PIC_AID']) && is_md5($user_prefs['PIC_AID'])) {
        $user_profile['PIC_AID'] = $user_prefs['PIC_AID'];
    }
    if (isset($user_prefs['AVATAR_URL']) && strlen($user_prefs['AVATAR_URL']) > 0) {
        $user_profile['AVATAR_URL'] = $user_prefs['AVATAR_URL'];
    }
    if (isset($user_prefs['AVATAR_AID']) && is_md5($user_prefs['AVATAR_AID'])) {
        $user_profile['AVATAR_AID'] = $user_prefs['AVATAR_AID'];
    }
    if (isset($user_prefs['HOMEPAGE_URL']) && strlen($user_prefs['HOMEPAGE_URL']) > 0) {
        $user_profile['HOMEPAGE_URL'] = $user_prefs['HOMEPAGE_URL'];
    }
    if (!isset($user_profile['RELATIONSHIP'])) {
        $user_profile['RELATIONSHIP'] = 0;
    }
    if (isset($user_profile['PEER_NICKNAME'])) {
        if (!is_null($user_profile['PEER_NICKNAME']) && strlen($user_profile['PEER_NICKNAME']) > 0) {
            $user_profile['NICKNAME'] = $user_profile['PEER_NICKNAME'];
        }
    }
    if ($anon_logon == USER_ANON_DISABLED) {
        if (isset($user_profile['ID'])) {
            $user_profile['STATUS'] = gettext("Online");
        } else {
            $user_profile['STATUS'] = gettext("Inactive / Offline");
        }
    } else {
        $user_profile['STATUS'] = gettext("Unknown");
    }
    if ($user_post_count = user_get_post_count($uid)) {
        $user_profile['POST_COUNT'] = $user_post_count;
    } else {
        $user_profile['POST_COUNT'] = 0;
    }
    if ($user_local_time = user_format_local_time($user_prefs)) {
        $user_profile['LOCAL_TIME'] = $user_local_time;
    }
    if (user_is_banned($uid)) {
        $user_profile['USER_GROUPS'] = gettext("Banned");
    } else {
        perm_user_get_group_names($uid, $user_groups_array);
        if (sizeof($user_groups_array) > 0) {
            $user_profile['USER_GROUPS'] = implode(', ', $user_groups_array);
        } else {
            $user_profile['USER_GROUPS'] = gettext("Registered");
        }
    }
    return $user_profile;
}
Example #26
0
function stats_get_visitor_counts()
{
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    // Year, Month, Week and Day
    list($year, $month, $week, $day) = explode('-', date('Y-m-w-d', time()));
    // Calculate the datetime for January 1st this year.
    $year_start_datetime = date(MYSQL_DATETIME_MIDNIGHT, mktime(0, 0, 0, 1, 1, $year));
    // Calculate the datetime for 1st of the month
    $month_start_datetime = date(MYSQL_DATETIME_MIDNIGHT, mktime(0, 0, 0, $month, 1, $year));
    // Calculate the timestamps for start of this week.
    $week_start_datetime = date(MYSQL_DATETIME_MIDNIGHT, mktime(0, 0, 0, $month, $day - $week, $year));
    // Calculate the datetime for start of today.
    $day_start_datetime = date(MYSQL_DATETIME_MIDNIGHT, mktime(0, 0, 0, $month, $day, $year));
    // Get visitors for today.
    $sql = "SELECT COUNT(UID) AS VISITOR_COUNT FROM VISITOR_LOG ";
    $sql .= "WHERE LAST_LOGON >= CAST('{$day_start_datetime}' AS DATETIME) ";
    $sql .= "AND FORUM = '{$forum_fid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($visitors_today) = $result->fetch_row();
    $sql = "SELECT COUNT(UID) AS VISITOR_COUNT FROM VISITOR_LOG ";
    $sql .= "WHERE LAST_LOGON >= CAST('{$week_start_datetime}' AS DATETIME) ";
    $sql .= "AND FORUM = '{$forum_fid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($visitors_this_week) = $result->fetch_row();
    $sql = "SELECT COUNT(UID) AS VISITOR_COUNT FROM VISITOR_LOG ";
    $sql .= "WHERE LAST_LOGON >= CAST('{$month_start_datetime}' AS DATETIME) ";
    $sql .= "AND FORUM = '{$forum_fid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($visitors_this_month) = $result->fetch_row();
    $sql = "SELECT COUNT(UID) AS VISITOR_COUNT FROM VISITOR_LOG ";
    $sql .= "WHERE LAST_LOGON >= CAST('{$year_start_datetime}' AS DATETIME) ";
    $sql .= "AND FORUM = '{$forum_fid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($visitors_this_year) = $result->fetch_row();
    return array('DAY' => $visitors_today, 'WEEK' => $visitors_this_week, 'MONTH' => $visitors_this_month, 'YEAR' => $visitors_this_year);
}
function attachments_get_all($uid)
{
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($uid)) {
        return false;
    }
    $sql = "SELECT PAF.AID, PAF.HASH, PAF.FILENAME, PAF.MIMETYPE, ";
    $sql .= "PAF.FILESIZE, PAF.WIDTH, PAF.HEIGHT, PAF.THUMBNAIL, ";
    $sql .= "PAF.DOWNLOADS FROM POST_ATTACHMENT_FILES PAF ";
    $sql .= "LEFT JOIN POST_ATTACHMENT_IDS PAI ON (PAI.AID = PAF.AID ";
    $sql .= "AND PAI.FID = '{$forum_fid}') LEFT JOIN PM_ATTACHMENT_IDS PMAI ";
    $sql .= "ON (PMAI.AID = PAF.AID) WHERE PAF.UID = '{$uid}' ";
    $sql .= "ORDER BY PAF.FILENAME";
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return false;
    }
    $attachments = array();
    while (($attachment_data = $result->fetch_assoc()) !== null) {
        $attachments[$attachment_data['HASH']] = array("aid" => $attachment_data['AID'], "downloads" => $attachment_data['DOWNLOADS'], "filename" => rawurldecode($attachment_data['FILENAME']), "filesize" => $attachment_data['FILESIZE'], "hash" => $attachment_data['HASH'], "height" => $attachment_data['HEIGHT'], "mimetype" => $attachment_data['MIMETYPE'], "thumbnail" => $attachment_data['THUMBNAIL'], "width" => $attachment_data['WIDTH']);
    }
    return $attachments;
}
Example #28
0
function forum_update_last_visit($uid)
{
    if ($uid == 0) {
        return false;
    }
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($uid)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    $current_datetime = date(MYSQL_DATETIME, time());
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $sql = "INSERT INTO USER_FORUM (UID, FID, LAST_VISIT) ";
    $sql .= "VALUES ('{$uid}', '{$forum_fid}', CAST('{$current_datetime}' AS DATETIME)) ";
    $sql .= "ON DUPLICATE KEY UPDATE LAST_VISIT = VALUES(LAST_VISIT)";
    if (!$db->query($sql)) {
        return false;
    }
    return true;
}
Example #29
0
function admin_send_link_approval_notification()
{
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!($forum_fid = get_forum_fid())) {
        return false;
    }
    $user_perm_links_moderate = USER_PERM_LINKS_MODERATE;
    $notification_success = false;
    $sql = "(SELECT DISTINCT GROUP_USERS.UID, BIT_OR(GROUP_PERMS.PERM) AS PERM ";
    $sql .= "FROM GROUPS INNER JOIN GROUP_PERMS ON (GROUP_PERMS.GID = GROUPS.GID) ";
    $sql .= "INNER JOIN GROUP_USERS ON (GROUP_USERS.GID = GROUPS.GID) ";
    $sql .= "INNER JOIN USER ON (USER.UID = GROUP_USERS.UID) ";
    $sql .= "WHERE GROUPS.FORUM = {$forum_fid} GROUP BY GROUP_USERS.UID ";
    $sql .= "HAVING PERM & {$user_perm_links_moderate} > 0) ";
    $sql .= "UNION (SELECT DISTINCT USER_PERM.UID, BIT_OR(USER_PERM.PERM) AS PERM ";
    $sql .= "FROM USER INNER JOIN USER_PERM ON (USER_PERM.UID = USER.UID) ";
    $sql .= "WHERE USER_PERM.FORUM IN (0, {$forum_fid}) GROUP BY USER.UID ";
    $sql .= "HAVING PERM & {$user_perm_links_moderate} > 0)";
    if (!($result = $db->query($sql))) {
        return false;
    }
    while (($admin_data = $result->fetch_assoc()) !== null) {
        if (email_send_link_approval_notification($admin_data['UID'])) {
            $notification_success = true;
        }
    }
    return $notification_success;
}