Example #1
0
function process_showgroups_userinfo($user)
{
    global $vbulletin, $permissions, $show;
    $user = array_merge($user, convert_bits_to_array($user['options'], $vbulletin->bf_misc_useroptions));
    $user = array_merge($user, convert_bits_to_array($user['adminoptions'], $vbulletin->bf_misc_adminoptions));
    cache_permissions($user, false);
    fetch_online_status($user);
    if (!$user['invisible'] or $permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehidden']) {
        $user['lastonline'] = vbdate($vbulletin->options['dateformat'], $user['lastactivity'], 1);
    } else {
        $user['lastonline'] = ' ';
    }
    fetch_musername($user);
    fetch_avatar_from_userinfo($user, true);
    return $user;
}
Example #2
0
    $templatename = 'socialgroups_group';
}
// #######################################################################
if ($_REQUEST['do'] == 'viewmembers') {
    $vbulletin->input->clean_array_gpc('r', array('perpage' => TYPE_UINT, 'pagenumber' => TYPE_UINT));
    $perpage = $vbulletin->GPC['perpage'];
    $pagenumber = $vbulletin->GPC['pagenumber'];
    $totalmembers = $group['members'];
    sanitize_pageresults($totalmembers, $pagenumber, $perpage);
    $groupmembers = $vbulletin->db->query_read("\n\t\tSELECT userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate,\n\t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible,\n\t\t\t" . ($vbulletin->options['avatarenabled'] ? 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight,' : '') . "\n\t\t\tcustomprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline, customprofilepic.width AS ppwidth, customprofilepic.height AS ppheight,\n\t\t\tuser.icq AS icq, user.aim AS aim, user.yahoo AS yahoo, user.msn AS msn, user.skype AS skype\n\t\tFROM " . TABLE_PREFIX . "socialgroupmember AS socialgroupmember\n\t\tINNER JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = socialgroupmember.userid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON (user.userid = userfield.userid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON (usertextfield.userid = user.userid)\n\t\t" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) " : '') . "\n\t\tLEFT JOIN " . TABLE_PREFIX . "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid)\n\t\tWHERE socialgroupmember.groupid = " . $vbulletin->GPC['groupid'] . " AND socialgroupmember.type = 'member'\n\t\tORDER BY user.username\n\t\tLIMIT " . ($pagenumber - 1) * $perpage . ", {$perpage}\n\t");
    require_once DIR . '/includes/functions_bigthree.php';
    while ($groupmember = $vbulletin->db->fetch_array($groupmembers)) {
        $width = 0;
        $height = 0;
        $alt = exec_switch_bg();
        fetch_avatar_from_userinfo($groupmember, true);
        fetch_musername($groupmember);
        $user =& $groupmember;
        fetch_online_status($user, true);
        construct_im_icons($user, true);
        ($hook = vBulletinHook::fetch_hook('group_memberbit')) ? eval($hook) : false;
        eval('$member_list .= "' . fetch_template('memberinfo_small') . '";');
    }
    $navbits = array('group.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['social_groups'], 'group.php?' . $vbulletin->session->vars['sessionurl'] . 'groupid=' . $group['groupid'] => $group['name'], '' => $vbphrase['member_list']);
    $custompagetitle = $group['name'] . ' - ' . $vbphrase['member_list'];
    $pagenav = construct_page_nav($pagenumber, $perpage, $totalmembers, 'group.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewmembers&groupid=' . $group['groupid'] . ($perpage ? "&pp={$perpage}" : ''));
    eval('$memberinfo_css = "' . fetch_template('memberinfo_css') . '";');
    $templatename = 'socialgroups_memberlist';
}
// #######################################################################
if ($_REQUEST['do'] == 'search') {
Example #3
0
 /**
  * Template method that does all the work to display an issue note, including processing the template
  *
  * @return	string	Templated note output
  */
 function construct()
 {
     ($hook = vBulletinHook::fetch_hook('group_messagebit_display_start')) ? eval($hook) : false;
     // preparation for display...
     $this->prepare_start();
     if ($this->message['userid']) {
         $this->process_registered_user();
     } else {
         $this->process_unregistered_user();
     }
     fetch_avatar_from_userinfo($this->message, true);
     $this->process_date_status();
     $this->process_display();
     $this->process_text();
     $this->prepare_end();
     // actual display...
     $group =& $this->group;
     $message =& $this->message;
     global $show, $vbphrase, $stylevar;
     global $spacer_open, $spacer_close;
     global $bgclass, $altbgclass;
     exec_switch_bg();
     ($hook = vBulletinHook::fetch_hook('group_messagebit_display_complete')) ? eval($hook) : false;
     eval('$output = "' . fetch_template($this->template) . '";');
     return $output;
 }
Example #4
0
 /**
  * Prepare any data needed for the output
  *
  * @param	string	The id of the block
  * @param	array	Options specific to the block
  */
 function prepare_output($id = '', $options = array())
 {
     global $show, $vbphrase;
     if ($this->profile->userinfo['friendcount'] != 0) {
         require_once DIR . '/includes/functions_bigthree.php';
         $this->block_data = array();
         if (is_array($options)) {
             $options = array_merge($this->option_defaults, $options);
         } else {
             $options = $this->option_defaults;
         }
         switch ($options['fetchorder']) {
             case 'asc':
                 $friendorder = 'user.username ASC';
                 break;
             case 'desc':
                 $friendorder = 'user.username DESC';
                 break;
             case 'rand':
             default:
                 $friendorder = 'RAND()';
         }
         $pagenumber = $options['pagenumber'];
         if (isset($options['perpage'])) {
             $perpage = $options['perpage'];
         } else {
             $perpage = $options['fetchamount'];
         }
         if (!$pagenumber or $options['tab'] != $id or empty($options['tab'])) {
             $pagenumber = 1;
         } else {
             if ($pagenumber > ceil($this->profile->userinfo['friendcount'] / $perpage)) {
                 $pagenumber = ceil($this->profile->userinfo['friendcount'] / $perpage);
             }
         }
         $limitstart = ($pagenumber - 1) * $perpage;
         $limitamount = max(1, min($perpage, $this->profile->userinfo['friendcount'] - $limitstart));
         $hook_query_fields = $hook_query_joins = $hook_query_where = '';
         ($hook = vBulletinHook::fetch_hook('member_profileblock_friends_query')) ? eval($hook) : false;
         $friends_sql = $this->registry->db->query_read_slave("\n\t\t\t\tSELECT user.*, (user.options & " . $this->registry->bf_misc_useroptions['invisible'] . ") AS invisible " . ($this->registry->options['avatarenabled'] ? ", avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustom, customavatar.dateline AS avatardateline, customavatar.filedata_thumb, customavatar.height AS avheight, customavatar.width AS avwidth, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb" : "") . "\n\t\t\t\t\t{$hook_query_fields}\n\t\t\t\tFROM " . TABLE_PREFIX . "userlist AS userlist\n\t\t\t\tINNER JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = userlist.relationid)" . ($this->registry->options['avatarenabled'] ? "\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid)\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) " : '') . "\n\t\t\t\t{$hook_query_joins}\n\t\t\t\tWHERE userlist.userid = " . $this->profile->userinfo['userid'] . "\n\t\t\t\t\tAND userlist.type = 'buddy'\n\t\t\t\t\tAND userlist.friend = 'yes'\n\t\t\t\t\t{$hook_query_where}\n\t\t\t\tORDER BY {$friendorder}\n\t\t\t\tLIMIT {$limitstart}, {$limitamount}\n\t\t\t");
         $friendbits = '';
         $alt = 'alt2';
         while ($user = $this->registry->db->fetch_array($friends_sql)) {
             fetch_avatar_from_userinfo($user, true);
             fetch_musername($user);
             $alt = $alt == 'alt1' ? 'alt2' : 'alt1';
             fetch_online_status($user, true);
             construct_im_icons($user, true);
             if ($user['userid'] == $this->registry->userinfo['userid'] or $this->profile->userinfo['userid'] == $this->registry->userinfo['userid']) {
                 if ($user['userid'] == $this->registry->userinfo['userid']) {
                     $show['return'] = true;
                     $remove = array('userid' => $this->profile->userinfo['userid'], 'return' => 1);
                 } else {
                     $remove = array('userid' => $user['userid']);
                 }
                 $show['breakfriendship'] = true;
             } else {
                 $show['breakfriendship'] = false;
             }
             ($hook = vBulletinHook::fetch_hook('member_profileblock_friendbit')) ? eval($hook) : false;
             $templater = vB_Template::create($options['membertemplate']);
             $templater->register('remove', $remove);
             $templater->register('user', $user);
             $friendbits .= $templater->render();
         }
         $pageinfo = array('tab' => $id);
         if ($perpage != $this->registry->options['friends_perpage']) {
             $paginfo['pp'] = $perpage;
         }
         $this->block_data['start_friends'] = $limitstart + 1;
         $this->block_data['friendbits'] = $friendbits;
         $this->block_data['showtotal'] = vb_number_format($this->registry->db->num_rows($friends_sql));
         $this->block_data['end_friends'] = $limitstart + $this->block_data['showtotal'];
         sanitize_pageresults($this->profile->userinfo['friendcount'], $pagenumber, $perpage, 100, 5);
         $this->block_data['pagenav'] = construct_page_nav($pagenumber, $perpage, $this->profile->userinfo['friendcount'], '', '', $id, 'member', $this->profile->userinfo, $pageinfo);
     }
 }
Example #5
0
 public function render($current_user, $criteria, $template = '')
 {
     //ensure that the phrases used by events are in the phrase list.
     $phrase = new vB_Legacy_Phrase();
     $phrase->add_phrase_groups(array('calendar', 'holiday', 'timezone', 'posting', 'user'));
     global $show, $bgclass;
     //a bunch of crap set by fetch_event_date_time that we send to the template
     global $date1, $date2, $time1, $time2, $recurcriteria, $eventdate;
     //a bunch of crap set by fetch_event_date_time that I can't find any use of.
     //leaving it in for now in case I missed some use of globals.
     global $titlecolor, $allday, $calendarinfo;
     $eventinfo = $this->event->get_record();
     $calendarinfo = $this->event->get_calendar()->get_record();
     //event['dst'] means "don't adjust event time for dst"
     $offset = $current_user->getTimezoneOffset(!$eventinfo['dst']);
     $eventinfo['dateline_from_user'] = $eventinfo['dateline_from'] + $offset * 3600;
     $eventinfo['dateline_to_user'] = $eventinfo['dateline_to'] + $offset * 3600;
     $eventinfo = fetch_event_date_time($eventinfo);
     fetch_musername($eventinfo);
     if (!$eventinfo['holidayid']) {
         $bgclass = 'alt2';
         //Custom fields are a little weird.  By default we don't show a blank value, but
         //the conditional is in the template so its possible that the user by change that.
         //We don't show the text block unless we have at least one set field, but again
         //the user can change that.  I'm not sure why somebody would want to do these
         //things but its not worth altering the behavior.  It does mean that we can't
         //rely on either field_text being blank when there are no set fields
         $custom_fields = $this->event->get_custom_fields();
         $custom_field_text = $this->render_custom_fields($custom_fields);
         $show['customfields'] = $this->have_set_customfield($custom_fields);
         $show['holiday'] = false;
         $show['caneditevent'] = $this->event->can_edit($current_user);
         $show['subscribed'] = !empty($eventinfo['subscribed']) ? true : false;
         $show['subscribelink'] = ($eventinfo['subscribed'] or $this->event->can_subscribe($current_user));
     } else {
         $custom_field_text = '';
         $show['holiday'] = true;
         $show['caneditevent'] = false;
         $show['subscribed'] = false;
         $show['subscribelink'] = false;
     }
     exec_switch_bg();
     if (!$eventinfo['singleday'] and gmdate('w', $eventinfo['dateline_from_user']) != gmdate('w', $eventinfo['dateline_from'] + $eventinfo['utc'] * 3600)) {
         $show['adjustedday'] = true;
         $eventinfo['timezone'] = str_replace(' ', ' ', $vbphrase[fetch_timezone($eventinfo['utc'])]);
     } else {
         $show['adjustedday'] = false;
     }
     $show['ignoredst'] = ($eventinfo['dst'] and !$eventinfo['singleday']) ? true : false;
     $show['postedby'] = !empty($eventinfo['userid']) ? true : false;
     $show['singleday'] = !empty($eventinfo['singleday']) ? true : false;
     if (($show['candeleteevent'] or $show['canmoveevent'] or $show['caneditevent']) and !$show['holiday']) {
         $show['eventoptions'] = true;
     }
     $eventinfo = array_merge($eventinfo, convert_bits_to_array($eventinfo['options'], vB::$vbulletin->bf_misc_useroptions));
     $eventinfo = array_merge($eventinfo, convert_bits_to_array($eventinfo['adminoptions'], vB::$vbulletin->bf_misc_adminoptions));
     cache_permissions($eventinfo, false);
     //we already have the avatar info, no need to refetch.
     fetch_avatar_from_userinfo($eventinfo);
     // prepare the member action drop-down menu
     $memberaction_dropdown = construct_memberaction_dropdown($eventinfo);
     ($hook = vBulletinHook::fetch_hook('calendar_getday_event')) ? eval($hook) : false;
     //some globals registered for the template's sake
     global $gobutton, $spacer_open, $spacer_close;
     $templater = vB_Template::create('calendar_showeventsbit');
     $templater->register('calendarinfo', $calendarinfo);
     $templater->register('customfields', $custom_field_text);
     $templater->register('date1', $date1);
     $templater->register('date2', $date2);
     $templater->register('time1', $time1);
     $templater->register('time2', $time2);
     $templater->register('eventdate', $eventdate);
     $templater->register('eventinfo', $eventinfo);
     $templater->register('gobutton', $gobutton);
     $templater->register('memberaction_dropdown', $memberaction_dropdown);
     $templater->register('recurcriteria', $recurcriteria);
     $templater->register('spacer_close', $spacer_close);
     $templater->register('spacer_open', $spacer_open);
     return $templater->render();
 }
Example #6
0
function do_get_subscriptions()
{
    global $vbulletin, $db, $show, $vbphrase, $permissions, $subscribecounters;
    $vbulletin->options['threadpreview'] = FR_PREVIEW_LEN;
    if (!$vbulletin->userinfo['userid']) {
        json_error(ERR_NO_PERMISSION);
    }
    if (!$vbulletin->userinfo['userid'] and $_REQUEST['do'] != 'removesubscription' or $vbulletin->userinfo['userid'] and !($permissions['forumpermissions'] & $vbulletin->bf_ugp_forumpermissions['canview']) or $vbulletin->userinfo['usergroupid'] == 4 or !($permissions['genericoptions'] & $vbulletin->bf_ugp_genericoptions['isnotbannedgroup'])) {
        json_error(ERR_NO_PERMISSION);
    }
    $thread_data = array();
    $unread_subs = 0;
    // vbulletin expects folderid, but we will just get them all
    $vbulletin->input->clean_array_gpc('r', array('folderid' => TYPE_NOHTML, 'perpage' => TYPE_UINT, 'pagenumber' => TYPE_UINT, 'sortfield' => TYPE_NOHTML, 'sortorder' => TYPE_NOHTML, 'previewtype' => TYPE_INT));
    $previewtype = $vbulletin->GPC['previewtype'];
    if (!$previewtype) {
        $previewtype = 1;
    }
    $vbulletin->GPC['folderid'] = 'all';
    // Values that are reused in templates
    $sortfield =& $vbulletin->GPC['sortfield'];
    $perpage =& $vbulletin->GPC['perpage'];
    $pagenumber =& $vbulletin->GPC['pagenumber'];
    $folderid =& $vbulletin->GPC['folderid'];
    if ($folderid == 'all') {
        $getallfolders = true;
        $show['allfolders'] = true;
    } else {
        $folderid = intval($folderid);
    }
    $folderselect["{$folderid}"] = 'selected="selected"';
    // Build folder jump
    require_once DIR . '/includes/functions_misc.php';
    $folders = construct_folder_jump(1, $folderid, false, '', true);
    $templater = vB_Template::create('subscribe_folder_jump');
    $templater->register('folders', $folders);
    $folderjump = $templater->render();
    // look at sorting options:
    if ($vbulletin->GPC['sortorder'] != 'asc') {
        $vbulletin->GPC['sortorder'] = 'desc';
        $sqlsortorder = 'DESC';
        $order = array('desc' => 'selected="selected"');
    } else {
        $sqlsortorder = '';
        $order = array('asc' => 'selected="selected"');
    }
    switch ($sortfield) {
        case 'title':
        case 'lastpost':
        case 'replycount':
        case 'views':
        case 'postusername':
            $sqlsortfield = 'thread.' . $sortfield;
            break;
        default:
            $handled = false;
            if (!$handled) {
                $sqlsortfield = 'thread.lastpost';
                $sortfield = 'lastpost';
            }
    }
    $sort = array($sortfield => 'selected="selected"');
    if ($getallfolders) {
        $totalallthreads = array_sum($subscribecounters);
    } else {
        $totalallthreads = $subscribecounters["{$folderid}"];
    }
    // set defaults
    sanitize_pageresults($totalallthreads, $pagenumber, $perpage, 200, $vbulletin->options['maxthreads']);
    // display threads
    $limitlower = ($pagenumber - 1) * $perpage + 1;
    $limitupper = $pagenumber * $perpage;
    if ($limitupper > $totalallthreads) {
        $limitupper = $totalallthreads;
        if ($limitlower > $totalallthreads) {
            $limitlower = $totalallthreads - $perpage;
        }
    }
    if ($limitlower <= 0) {
        $limitlower = 1;
    }
    $hook_query_fields = $hook_query_joins = $hook_query_where = '';
    $getthreads = $db->query_read_slave("\n\t\tSELECT thread.threadid, emailupdate, subscribethreadid, thread.forumid, thread.postuserid\n\t\t\t{$hook_query_fields}\n\t\tFROM " . TABLE_PREFIX . "subscribethread AS subscribethread\n\t\tLEFT JOIN " . TABLE_PREFIX . "thread AS thread ON(thread.threadid = subscribethread.threadid)\n\t\t{$hook_query_joins}\n\t\tWHERE subscribethread.userid = " . $vbulletin->userinfo['userid'] . "\n\t\t\tAND thread.visible = 1\n\t\t\tAND canview = 1\n\t\t" . iif(!$getallfolders, "\tAND folderid = {$folderid}") . "\n\t\t\t{$hook_query_where}\n\t\tORDER BY {$sqlsortfield} {$sqlsortorder}\n\t\tLIMIT " . ($limitlower - 1) . ", {$perpage}\n\t");
    if ($totalthreads = $db->num_rows($getthreads)) {
        $forumids = array();
        $threadids = array();
        $emailupdate = array();
        $killthreads = array();
        while ($getthread = $db->fetch_array($getthreads)) {
            $forumperms = fetch_permissions($getthread['forumid']);
            if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) or !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) or $getthread['postuserid'] != $vbulletin->userinfo['userid'] and !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers'])) {
                $killthreads["{$getthread['subscribethreadid']}"] = $getthread['subscribethreadid'];
                $totalallthreads--;
                continue;
            }
            $forumids["{$getthread['forumid']}"] = true;
            $threadids[] = $getthread['threadid'];
            $emailupdate["{$getthread['threadid']}"] = $getthread['emailupdate'];
            $subscribethread["{$getthread['threadid']}"] = $getthread['subscribethreadid'];
        }
        $threadids = implode(',', $threadids);
    }
    unset($getthread);
    $db->free_result($getthreads);
    if (!empty($killthreads)) {
        // Update thread subscriptions
        $vbulletin->db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "subscribethread\n\t\t\tSET canview = 0\n\t\t\tWHERE subscribethreadid IN (" . implode(', ', $killthreads) . ")\n\t\t");
    }
    if (!empty($threadids)) {
        cache_ordered_forums(1);
        $colspan = 5;
        $show['threadicons'] = false;
        // get last read info for each thread
        $lastread = array();
        foreach (array_keys($forumids) as $forumid) {
            if ($vbulletin->options['threadmarking']) {
                $lastread["{$forumid}"] = max($vbulletin->forumcache["{$forumid}"]['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400);
            } else {
                $lastread["{$forumid}"] = max(intval(fetch_bbarray_cookie('forum_view', $forumid)), $vbulletin->userinfo['lastvisit']);
            }
            if ($vbulletin->forumcache["{$forumid}"]['options'] & $vbulletin->bf_misc_forumoptions['allowicons']) {
                $show['threadicons'] = true;
                $colspan = 6;
            }
        }
        if ($previewtype == 1) {
            $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,";
            $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.firstpostid)";
        } else {
            $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,";
            $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.lastpostid)";
        }
        $hasthreads = true;
        $threadbits = '';
        $pagenav = '';
        $counter = 0;
        $toread = 0;
        $vbulletin->options['showvotes'] = intval($vbulletin->options['showvotes']);
        if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) {
            $lastpost_info = "IF(tachythreadpost.userid IS NULL, thread.lastpost, tachythreadpost.lastpost) AS lastpost, " . "IF(tachythreadpost.userid IS NULL, thread.lastposter, tachythreadpost.lastposter) AS lastposter, " . "IF(tachythreadpost.userid IS NULL, thread.lastposterid, tachythreadpost.lastposterid) AS lastposterid, " . "IF(tachythreadpost.userid IS NULL, thread.lastpostid, tachythreadpost.lastpostid) AS lastpostid";
            $tachyjoin = "LEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON " . "(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ')';
        } else {
            $lastpost_info = 'thread.lastpost, thread.lastposter, thread.lastposterid, thread.lastpostid';
            $tachyjoin = '';
        }
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $threads = $db->query_read_slave("\n\t\t\tSELECT\n\t\t\t\tIF(thread.votenum >= " . $vbulletin->options['showvotes'] . ", thread.votenum, 0) AS votenum,\n\t\t\t\tIF(thread.votenum >= " . $vbulletin->options['showvotes'] . " AND thread.votenum > 0, thread.votetotal / thread.votenum, 0) AS voteavg,\n\t\t\t\tthread.votetotal,\n\t\t\t\t{$previewfield} thread.threadid, thread.title AS threadtitle, thread.forumid, thread.pollid,\n\t\t\t\tthread.open, thread.replycount, thread.postusername, thread.prefixid,\n\t\t\t\t{$lastpost_info}, thread.postuserid, thread.dateline, thread.views, thread.iconid AS threadiconid,\n\t\t\t\tthread.notes, thread.visible, thread.attach, thread.taglist\n\t\t\t\t" . ($vbulletin->options['threadmarking'] ? ", threadread.readtime AS threadread" : '') . "\n\t\t\t\t{$hook_query_fields}\n\t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n\t\t\t{$previewjoin}\n\t\t\t" . ($vbulletin->options['threadmarking'] ? " LEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = " . $vbulletin->userinfo['userid'] . ")" : '') . "\n\t\t\t{$tachyjoin}\n\t\t\t{$hook_query_joins}\n\t\t\tWHERE thread.threadid IN ({$threadids})\n\t\t\tORDER BY {$sqlsortfield} {$sqlsortorder}\n\t\t");
        unset($sqlsortfield, $sqlsortorder);
        require_once DIR . '/includes/functions_forumdisplay.php';
        // Get Dot Threads
        $dotthreads = fetch_dot_threads_array($threadids);
        if ($vbulletin->options['showdots'] and $vbulletin->userinfo['userid']) {
            $show['dotthreads'] = true;
        } else {
            $show['dotthreads'] = false;
        }
        if ($vbulletin->options['threadpreview'] and $vbulletin->userinfo['ignorelist']) {
            // Get Buddy List
            $buddy = array();
            if (trim($vbulletin->userinfo['buddylist'])) {
                $buddylist = preg_split('/( )+/', trim($vbulletin->userinfo['buddylist']), -1, PREG_SPLIT_NO_EMPTY);
                foreach ($buddylist as $buddyuserid) {
                    $buddy["{$buddyuserid}"] = 1;
                }
            }
            DEVDEBUG('buddies: ' . implode(', ', array_keys($buddy)));
            // Get Ignore Users
            $ignore = array();
            if (trim($vbulletin->userinfo['ignorelist'])) {
                $ignorelist = preg_split('/( )+/', trim($vbulletin->userinfo['ignorelist']), -1, PREG_SPLIT_NO_EMPTY);
                foreach ($ignorelist as $ignoreuserid) {
                    if (!$buddy["{$ignoreuserid}"]) {
                        $ignore["{$ignoreuserid}"] = 1;
                    }
                }
            }
            DEVDEBUG('ignored users: ' . implode(', ', array_keys($ignore)));
        }
        $foruminfo['allowratings'] = true;
        $show['notificationtype'] = true;
        $show['threadratings'] = true;
        $show['threadrating'] = true;
        while ($thread = $db->fetch_array($threads)) {
            $threadid = $thread['threadid'];
            // build thread data
            $thread = process_thread_array($thread, $lastread["{$thread['forumid']}"]);
            switch ($emailupdate["{$thread['threadid']}"]) {
                case 0:
                    $thread['notification'] = $vbphrase['none'];
                    break;
                case 1:
                    $thread['notification'] = $vbphrase['instant'];
                    break;
                case 2:
                    $thread['notification'] = $vbphrase['daily'];
                    break;
                case 3:
                    $thread['notification'] = $vbphrase['weekly'];
                    break;
                default:
                    $thread['notification'] = $vbphrase['n_a'];
            }
            $avatarurl = '';
            if ($thread['lastpost_userid'] > 0) {
                $userinfoavatar = fetch_userinfo($thread['lastpost_userid'], FETCH_USERINFO_AVATAR);
                fetch_avatar_from_userinfo($userinfoavatar, true, false);
                if ($userinfoavatar['avatarurl'] != '') {
                    $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                }
                unset($userinfoavatar);
            }
            $tmp = array('thread_id' => $thread['threadid'], 'new_posts' => $show['gotonewpost'] ? true : false, 'forum_id' => $thread['forumid'], 'total_posts' => $thread['totalposts'] ? $thread['totalposts'] : 0, 'forum_title' => prepare_utf8_string($thread['forumtitle']), 'thread_title' => prepare_utf8_string($thread['threadtitle']), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($thread['preview']), FR_PREVIEW_LEN)), 'post_userid' => $thread['lastpost_userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($thread['lastpostdate']) . ' ' . $thread['lastposttime']), 'post_username' => prepare_utf8_string(strip_tags($thread['lastpost_username'])));
            if ($avatarurl != '') {
                $tmp['avatarurl'] = $avatarurl;
            }
            if ($thread['attach']) {
                $tmp['attach'] = true;
            }
            if ($thread['pollid']) {
                $tmp['poll'] = true;
            }
            $thread_data[] = $tmp;
        }
        $db->free_result($threads);
        unset($threadids);
    } else {
        $totalallthreads = 0;
    }
    $out = array('threads' => $thread_data, 'total_threads' => $totalallthreads);
    return $out;
}
Example #7
0
 /**
  * Prepares the User's Avatar
  *
  */
 function prepare_avatar()
 {
     fetch_avatar_from_userinfo($this->userinfo, true, false);
     if ($this->userinfo['avatarurl'] == '' or !$this->registry->options['avatarenabled'] or $this->userinfo['hascustomavatar'] and !($this->userinfo['permissions']['genericpermissions'] & $this->registry->bf_ugp_genericpermissions['canuseavatar']) and !$this->userinfo['adminavatar']) {
         $this->prepared['avatarurl'] = '';
         $this->prepared['avatarsize'] = '';
     } else {
         $this->prepared['avatarsize'] = ($this->userinfo['avatarwidth'] ? ' width="' . $this->userinfo['avatarwidth'] . '"' : '') . ($this->userinfo['avatarheight'] ? ' height="' . $this->userinfo['avatarheight'] . '"' : '');
         $this->prepared['avatarurl'] = $this->userinfo['avatarurl'];
     }
 }
Example #8
0
function do_online()
{
    global $vbulletin, $db;
    $showmembers = true;
    $showguests = true;
    $showspiders = true;
    $datecut = TIMENOW - $vbulletin->options['cookietimeout'];
    $wol_event = array();
    $wol_pm = array();
    $wol_calendar = array();
    $wol_user = array();
    $wol_forum = array();
    $wol_link = array();
    $wol_thread = array();
    $wol_post = array();
    $sqlsort = 'user.username';
    $sortfield = 'username';
    $hook_query_fields = $hook_query_joins = $hook_query_where = '';
    ($hook = vBulletinHook::fetch_hook('online_query')) ? eval($hook) : false;
    $allusers = $db->query_read_slave("\n\tSELECT\n\t    user.username, session.useragent, session.location, session.lastactivity, user.userid, user.options, session.host, session.badlocation, session.incalendar, user.aim, user.icq, user.msn, user.yahoo, user.skype,\n\t    IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n\t{$hook_query_fields}\n\tFROM " . TABLE_PREFIX . "session AS session\n\t" . iif($vbulletin->options['WOLguests'], " LEFT JOIN " . TABLE_PREFIX . "user AS user USING (userid) ", ", " . TABLE_PREFIX . "user AS user") . "\n\t{$hook_query_joins}\n\tWHERE session.lastactivity > {$datecut}\n\t" . iif(!$vbulletin->options['WOLguests'], " AND session.userid = user.userid", "") . "\n\t{$hook_query_where}\n\tORDER BY {$sqlsort} {$sortorder}\n    ");
    require_once DIR . '/includes/class_postbit.php';
    while ($users = $db->fetch_array($allusers)) {
        if ($users['userid']) {
            // Reg'd Member
            if (!$showmembers) {
                continue;
            }
            $users = array_merge($users, convert_bits_to_array($users['options'], $vbulletin->bf_misc_useroptions));
            $key = $users['userid'];
            if ($key == $vbulletin->userinfo['userid']) {
                // in case this is the first view for the user, fake it that show up to themself
                $foundviewer = true;
            }
            if (empty($userinfo["{$key}"]['lastactivity']) or $userinfo["{$key}"]['lastactivity'] < $users['lastactivity']) {
                unset($userinfo["{$key}"]);
                // need this to sort by lastactivity
                $userinfo["{$key}"] = $users;
                fetch_musername($users);
                $userinfo["{$key}"]['musername'] = $users['musername'];
                $userinfo["{$key}"]['useragent'] = htmlspecialchars_uni($users['useragent']);
                $userinfoavatar = fetch_userinfo($key, FETCH_USERINFO_AVATAR);
                fetch_avatar_from_userinfo($userinfoavatar, true, false);
                if ($userinfoavatar['avatarurl'] != '') {
                    $userinfo["{$key}"]['avatarurl'] = process_avatarurl($userinfoavatar['avatarurl']);
                }
                unset($userinfoavatar);
                if ($users['invisible']) {
                    if ($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehidden'] or $key == $vbulletin->userinfo['userid']) {
                        $userinfo["{$key}"]['hidden'] = '*';
                        $userinfo["{$key}"]['invisible'] = 0;
                    }
                }
                if ($vbulletin->options['WOLresolve'] and $permissions['wolpermissions'] & $vbulletin->bf_ugp_wolpermissions['canwhosonlineip']) {
                    $userinfo["{$key}"]['host'] = @gethostbyaddr($users['host']);
                }
                $userinfo["{$key}"]['buddy'] = $buddy["{$key}"];
            }
        } else {
            // Guest or Spider..
            $spider = '';
            if ($vbulletin->options['enablespiders'] and !empty($vbulletin->wol_spiders)) {
                if (preg_match('#(' . $vbulletin->wol_spiders['spiderstring'] . ')#si', $users['useragent'], $agent)) {
                    $agent = strtolower($agent[1]);
                    // Check ip address
                    if (!empty($vbulletin->wol_spiders['agents']["{$agent}"]['lookup'])) {
                        $ourip = ip2long($users['host']);
                        foreach ($vbulletin->wol_spiders['agents']["{$agent}"]['lookup'] as $key => $ip) {
                            if ($ip['startip'] and $ip['endip']) {
                                if ($ourip >= $ip['startip'] and $ourip <= $ip['endip']) {
                                    $spider = $vbulletin->wol_spiders['agents']["{$agent}"];
                                    break;
                                }
                            } else {
                                if ($ip['startip'] == $ourip) {
                                    $spider = $vbulletin->wol_spiders['agents']["{$agent}"];
                                    break;
                                }
                            }
                        }
                    } else {
                        $spider = $vbulletin->wol_spiders['agents']["{$agent}"];
                    }
                }
            }
            if ($spider) {
                if (!$showspiders) {
                    continue;
                }
                $guests["{$count}"] = $users;
                $guests["{$count}"]['spider'] = $spider['name'];
                $guests["{$count}"]['spidertype'] = $spider['type'];
            } else {
                if (!$showguests) {
                    continue;
                }
                $guests["{$count}"] = $users;
            }
            $guests["{$count}"]['username'] = $vbphrase['guest'];
            $guests["{$count}"]['invisible'] = 0;
            $guests["{$count}"]['displaygroupid'] = 1;
            fetch_musername($guests["{$count}"]);
            if ($vbulletin->options['WOLresolve'] and $permissions['wolpermissions'] & $vbulletin->bf_ugp_wolpermissions['canwhosonlineip']) {
                $guests["{$count}"]['host'] = @gethostbyaddr($users['host']);
            }
            $guests["{$count}"]['count'] = $count + 1;
            $guests["{$count}"]['useragent'] = htmlspecialchars_uni($users['useragent']);
            $count++;
            ($hook = vBulletinHook::fetch_hook('online_user')) ? eval($hook) : false;
        }
    }
    $online_users = array();
    if (is_array($userinfo)) {
        foreach ($userinfo as $userid => $user) {
            if ($user['invisible']) {
                continue;
            }
            $tmp = array('userid' => $userid, 'username' => prepare_utf8_string(strip_tags($user['username'])));
            if ($user['userid'] == $vbulletin->userinfo['userid']) {
                $tmp['me'] = true;
            }
            if ($user['avatarurl'] != '') {
                $tmp['avatarurl'] = $user['avatarurl'];
            }
            $online_users[] = $tmp;
        }
    }
    $numguests = 0;
    if (is_array($guests)) {
        $numguests = count($guests);
    }
    return array('users' => $online_users, 'num_guests' => $numguests);
}
 /**
  * Template method that does all the work to render the item, including processing the template
  *
  * @access public
  *
  * @return	string	Templated note output
  */
 function construct()
 {
     if ($this->hook_display_start) {
         ($hook = vBulletinHook::fetch_hook($this->hook_display_start)) ? eval($hook) : false;
     }
     // preparation for display...
     $this->prepare_start();
     if ($this->process_user) {
         if ($this->item['userid']) {
             $this->process_registered_user();
         } else {
             $this->process_unregistered_user();
         }
     }
     if ($this->use_avatar) {
         fetch_avatar_from_userinfo($this->item, true);
     }
     $this->process_date_status();
     $this->process_display();
     $this->process_text();
     $this->prepare_end();
     // actual display...
     if ($this->template_item_var) {
         ${$this->template_item_var} = $this->item;
     }
     global $show, $vbphrase, $stylevar;
     global $spacer_open, $spacer_close;
     global $perpage, $pagenumber;
     global $bgclass, $altbgclass;
     exec_switch_bg();
     if ($this->hook_display_complete) {
         ($hook = vBulletinHook::fetch_hook($this->hook_display_complete)) ? eval($hook) : false;
     }
     eval('$output = "' . fetch_template($this->template) . '";');
     return $output;
 }
Example #10
0
 /**
  * Template method that does all the work to render the item, including processing the template
  *
  * @access public
  *
  * @return	string	Templated note output
  */
 function construct()
 {
     if ($this->hook_display_start) {
         ($hook = vBulletinHook::fetch_hook($this->hook_display_start)) ? eval($hook) : false;
     }
     // preparation for display...
     $this->prepare_start();
     if ($this->use_avatar) {
         fetch_avatar_from_userinfo($this->item, true);
     }
     if ($this->process_user) {
         if ($this->item['userid']) {
             $this->process_registered_user();
         } else {
             $this->process_unregistered_user();
         }
     }
     $this->process_date_status();
     $this->process_display();
     $this->process_text();
     $this->prepare_end();
     // actual display...
     foreach ($this->template_data_vars as $varname) {
         ${$varname} = $this->{$varname};
     }
     global $show, $vbphrase;
     global $spacer_open, $spacer_close;
     global $perpage, $pagenumber;
     global $bgclass, $altbgclass;
     exec_switch_bg();
     if ($this->hook_display_complete) {
         ($hook = vBulletinHook::fetch_hook($this->hook_display_complete)) ? eval($hook) : false;
     }
     $templater = vB_Template::create($this->template);
     if ($this->template_item_var) {
         $templater->register($this->template_item_var, $this->item);
     }
     $templater->register('pagenumber', $pagenumber);
     $templater->register('perpage', $perpage);
     $templater->register('template_hook', $template_hook);
     return $templater->render();
 }
Example #11
0
function cache_events($range)
{
    global $vbulletin, $calendarinfo, $vbphrase, $serveroffset;
    $numdays = date('j', mktime(0, 0, 0, $range['nextmonth'] + 1, 1, $range['nextyear']) - 1);
    $beginday = gmmktime(0, 0, 0, $range['frommonth'], 1, $range['fromyear']) + -12 * 3600;
    $endday = gmmktime(24, 0, 0, $range['nextmonth'], $numdays, $range['nextyear']) + 12 * 3600;
    $event = array();
    $eventids = array();
    if ($calendarinfo['showholidays']) {
        // Holidays show across all calendars that a user has access to.
        $holidays = $vbulletin->db->query_read_slave("\n\t\t\tSELECT *\n\t\t\tFROM " . TABLE_PREFIX . "holiday\n\t\t");
        if ($vbulletin->db->num_rows($holidays)) {
            while ($ev = $vbulletin->db->fetch_array($holidays)) {
                $ev['visible'] = 1;
                $ev['title'] =& $vbphrase['holiday' . $ev['holidayid'] . '_title'];
                $ev['event'] =& $vbphrase['holiday' . $ev['holidayid'] . '_desc'];
                $ev['preview'] = strip_quotes($ev['event']);
                $ev['preview'] = htmlspecialchars_uni(strip_bbcode(fetch_trimmed_title($ev['preview'], 300), false, true));
                if ($ev['recurring'] == 6) {
                    $event['holiday1']["{$ev['recuroption']}"][] = $ev;
                } else {
                    $ev['dateline_from'] = $beginday;
                    $ev['dateline_to'] = $endday;
                    $offset = $vbulletin->userinfo['timezoneoffset'] ? $vbulletin->userinfo['tzoffset'] : $vbulletin->userinfo['timezoneoffset'];
                    $ev['dateline_from_user'] = $ev['dateline_from'] + $offset * 3600;
                    $ev['dateline_to_user'] = $ev['dateline_to'] + $offset * 3600;
                    $recuroption = substr($ev['recuroption'], 2);
                    $event['holiday2']["{$recuroption}"][] = $ev;
                }
            }
        }
    }
    require_once DIR . '/includes/functions_user.php';
    $events = $vbulletin->db->query_read_slave("\n\t\tSELECT event.*,\n\t\tuser.username, IF(user.displaygroupid = 0, user.usergroupid, user.displaygroupid) AS displaygroupid,\n\t\tuser.adminoptions, user.usergroupid, user.usertitle, user.membergroupids, user.infractiongroupids, IF(options & " . $vbulletin->bf_misc_useroptions['hasaccessmask'] . ", 1, 0) AS hasaccessmask,\n\t\tIF(dateline_to = 0, 1, 0) AS singleday\n\t\t" . iif($vbulletin->userinfo['userid'], ", subscribeevent.eventid AS subscribed") . "\n\t\t" . ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,\n\t\t\t\tcustomavatar.width AS avwidth,customavatar.height AS avheight, customavatar.width_thumb AS avwidth_thumb, user.avatarrevision,\n\t\t\t\tcustomavatar.height_thumb AS avheight_thumb, customavatar.filedata_thumb, NOT ISNULL(customavatar.userid) AS hascustom" : "") . "\n\t\tFROM " . TABLE_PREFIX . "event AS event\n\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = event.userid)\n\t\t" . iif($vbulletin->userinfo['userid'], "LEFT JOIN " . TABLE_PREFIX . "subscribeevent AS subscribeevent ON (subscribeevent.eventid = event.eventid AND subscribeevent.userid = " . $vbulletin->userinfo['userid'] . ")") . "\n\t\t" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "\n\t\tWHERE calendarid = {$calendarinfo['calendarid']} AND\n\t\t\t((dateline_to >= {$beginday} AND dateline_from < {$endday}) OR (dateline_to = 0 AND dateline_from >= {$beginday} AND dateline_from <= {$endday} ))\tAND\n\t\t\tevent.visible = 1\n\t\tORDER BY dateline_from\n\t");
    // Cache Events
    if ($vbulletin->db->num_rows($events)) {
        while ($ev = $vbulletin->db->fetch_array($events)) {
            if ($ev['userid'] != $vbulletin->userinfo['userid'] and !($vbulletin->userinfo['calendarpermissions']["{$calendarinfo['calendarid']}"] & $vbulletin->bf_ugp_calendarpermissions['canviewothersevent'])) {
                continue;
            }
            $ev = array_merge($ev, convert_bits_to_array($ev['options'], $vbulletin->bf_misc_useroptions));
            $ev = array_merge($ev, convert_bits_to_array($ev['adminoptions'], $vbulletin->bf_misc_adminoptions));
            cache_permissions($ev, false);
            fetch_avatar_from_userinfo($ev, true);
            $ev['preview'] = strip_quotes($ev['event']);
            $ev['preview'] = htmlspecialchars_uni(strip_bbcode(fetch_trimmed_title($ev['preview'], 300), false, true));
            $offset = $ev['dst'] ? $vbulletin->userinfo['timezoneoffset'] : $vbulletin->userinfo['tzoffset'];
            $ev['dateline_from_user'] = $ev['dateline_from'] + $offset * 3600;
            $ev['dateline_to_user'] = $ev['dateline_to'] + $offset * 3600;
            fetch_musername($ev);
            if (!$ev['recurring']) {
                if ($ev['singleday']) {
                    $event['singleday']["{$ev['dateline_from']}"][] = $ev;
                } else {
                    $found = false;
                    $date = explode('-', gmdate('n-j-Y', $ev['dateline_from_user']));
                    $beginday = gmmktime(0, 0, 0, $date[0], $date[1], $date[2]);
                    while ($beginday <= $ev['dateline_to_user']) {
                        if (!$found) {
                            $event['ranged']["{$beginday}"][] = $ev;
                            $count = count($event['ranged']["{$beginday}"]) - 1;
                            $tempevent =& $event['ranged']["{$beginday}"]["{$count}"];
                            $found = true;
                        } else {
                            // if event ends at the start of the day, don't display it for that day
                            if ($ev['dateline_to_user'] != $beginday) {
                                $event['ranged']["{$beginday}"][] =& $tempevent;
                            }
                        }
                        $beginday += 86400;
                    }
                }
            } else {
                $event['recurring'][] = $ev;
            }
        }
    }
    return $event;
}
Example #12
0
 protected function processUsers()
 {
     if (!$this->content['userid']) {
         return;
     }
     /* This bit handles processUsers() being executed multiple times .. remove any users that we already know about
      * and only query if we have any unknown users left
      */
     if ($this->content['user']) {
         foreach ($this->content['user'] as $userid => $foo) {
             unset($this->content['userid'][$userid]);
         }
         if (!$this->content['userid']) {
             return;
         }
     }
     require_once DIR . '/includes/functions_user.php';
     $users = vB::$db->query_read("\n\t\t\tSELECT u.*\n\t\t\t\t" . (vB::$vbulletin->options['avatarenabled'] ? ", av.avatarpath, NOT ISNULL(cu.userid) AS hascustomavatar,\n\t\t\t\t\tcu.dateline AS avatardateline, cu.width AS avwidth, cu.height AS avheight, cu.height_thumb AS avheight_thumb,\n\t\t\t\t\tcu.width_thumb AS avwidth_thumb, NOT ISNULL(cu.filedata_thumb) AS filedata_thumb" : "") . "\n\t\t\t\t\t" . (vB::$vbulletin->userinfo['userid'] ? ",IF(userlist.userid IS NOT NULL, 1, 0) AS bbuser_iscontact_of_user" : "") . "\n\t\t\tFROM " . TABLE_PREFIX . "user AS u\n\t\t\t" . (vB::$vbulletin->options['avatarenabled'] ? "\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "avatar AS av ON(av.avatarid = u.avatarid)\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "customavatar AS cu ON(cu.userid = u.userid)" : "") . "\n\t\t\t\t" . (vB::$vbulletin->userinfo['userid'] ? "LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist ON (userlist.userid = u.userid AND userlist.type = 'buddy' AND userlist.relationid = " . vB::$vbulletin->userinfo['userid'] . ")" : "") . "\n\t\t\tWHERE u.userid IN (" . implode(",", array_keys($this->content['userid'])) . ")\n\t\t");
     while ($user = vB::$db->fetch_array($users)) {
         $user = array_merge($user, convert_bits_to_array($user['options'], vB::$vbulletin->bf_misc_useroptions));
         fetch_avatar_from_userinfo($user, true);
         cache_permissions($user, false);
         if (empty($user['avatarurl']) or !$user['avatarid'] and !($user['permissions']['genericpermissions'] & vB::$vbulletin->bf_ugp_genericpermissions['canuseavatar']) and !$user['adminavatar']) {
             $user['avatarurl'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . '/unknown.gif';
             $user['showavatar'] = true;
             $user['avatarclass'] = 'hasavatar';
         } else {
             if (vB::$vbulletin->userinfo['userid'] and !vB::$vbulletin->userinfo['showavatars']) {
                 $user['showavatar'] = false;
                 $user['avatarclass'] = 'noavatar';
             } else {
                 $user['showavatar'] = true;
                 $user['avatarclass'] = 'hasavatar';
             }
         }
         $this->content['user'][$user['userid']] = $user;
     }
     if (!$this->content['user']) {
         $this->content['user'] = array();
     }
     /*
      * Reset the array so that if processUsers() is executed again we won't query anything
      * unless new ids have been added to the array
      */
     $this->content['userid'] = array();
 }
Example #13
0
function do_get_pms()
{
    global $vbulletin, $db, $messagecounters;
    if (!$vbulletin->userinfo['userid']) {
        json_error(ERR_INVALID_LOGGEDIN, RV_NOT_LOGGED_IN);
    }
    $vbulletin->input->clean_array_gpc('r', array('folderid' => TYPE_INT, 'perpage' => TYPE_UINT, 'pagenumber' => TYPE_UINT));
    // Fetch PM unread count
    $result = $db->query_read_slave("\n\tSELECT COUNT(messageread) AS unread\n\tFROM " . TABLE_PREFIX . "pm\n\tWHERE userid = " . $vbulletin->userinfo['userid'] . "\n\tAND messageread = 0");
    $unread = 0;
    if ($row = $db->fetch_array($result)) {
        $unread = $row['unread'];
    }
    $pm_out = array();
    // vBulletin Code Begin
    $folderjump = construct_folder_jump(0, $vbulletin->GPC['folderid']);
    $foldername = $foldernames["{$vbulletin->GPC['folderid']}"];
    // count receipts
    $receipts = $db->query_first_slave("\n\t\tSELECT\n\t\t\tSUM(IF(readtime <> 0, 1, 0)) AS confirmed,\n\t\t\tSUM(IF(readtime = 0, 1, 0)) AS unconfirmed\n\t\tFROM " . TABLE_PREFIX . "pmreceipt\n\t\tWHERE userid = " . $vbulletin->userinfo['userid']);
    // get ignored users
    $ignoreusers = preg_split('#\\s+#s', $vbulletin->userinfo['ignorelist'], -1, PREG_SPLIT_NO_EMPTY);
    $totalmessages = intval($messagecounters["{$vbulletin->GPC['folderid']}"]);
    // build pm counters bar, folder is 100 if we have no quota so red shows on the main bar
    $tdwidth = array();
    $tdwidth['folder'] = $permissions['pmquota'] ? ceil($totalmessages / $permissions['pmquota'] * 100) : 100;
    $tdwidth['total'] = $permissions['pmquota'] ? ceil($vbulletin->userinfo['pmtotal'] / $permissions['pmquota'] * 100) - $tdwidth['folder'] : 0;
    $tdwidth['quota'] = 100 - $tdwidth['folder'] - $tdwidth['total'];
    $show['thisfoldertotal'] = iif($tdwidth['folder'], true, false);
    $show['allfolderstotal'] = iif($tdwidth['total'], true, false);
    $show['pmicons'] = iif($vbulletin->options['privallowicons'], true, false);
    // build navbar
    $navbits[''] = $foldernames["{$vbulletin->GPC['folderid']}"];
    if ($totalmessages == 0) {
        $show['messagelist'] = false;
    } else {
        $show['messagelist'] = true;
        $vbulletin->input->clean_array_gpc('r', array('sort' => TYPE_NOHTML, 'order' => TYPE_NOHTML, 'searchtitle' => TYPE_NOHTML, 'searchuser' => TYPE_NOHTML, 'startdate' => TYPE_UNIXTIME, 'enddate' => TYPE_UNIXTIME, 'searchread' => TYPE_UINT));
        $search = array('sort' => 'sender' == $vbulletin->GPC['sort'] ? 'sender' : ('title' == $vbulletin->GPC['sort'] ? 'title' : 'date'), 'order' => $vbulletin->GPC['order'] == 'asc' ? 'asc' : 'desc', 'searchtitle' => $vbulletin->GPC['searchtitle'], 'searchuser' => $vbulletin->GPC['searchuser'], 'startdate' => $vbulletin->GPC['startdate'], 'enddate' => $vbulletin->GPC['enddate'], 'read' => $vbulletin->GPC['searchread']);
        // make enddate inclusive
        $search['enddate'] = $search['enddate'] ? $search['enddate'] + 86400 : 0;
        $show['openfilter'] = ($search['searchtitle'] or $search['searchuser'] or $search['startdate'] or $search['enddate']);
        $sortfield = 'sender' == $search['sort'] ? 'pmtext.fromusername' : ('title' == $search['sort'] ? 'pmtext.title' : 'pmtext.dateline');
        $desc = $search['order'] == 'desc';
        //($hook = vBulletinHook::fetch_hook('private_messagelist_filter')) ? eval($hook) : false;
        // get a sensible value for $perpage
        sanitize_pageresults($totalmessages, $vbulletin->GPC['pagenumber'], $vbulletin->GPC['perpage'], $vbulletin->options['pmmaxperpage'], $vbulletin->options['pmperpage']);
        // work out the $startat value
        $startat = ($vbulletin->GPC['pagenumber'] - 1) * $vbulletin->GPC['perpage'];
        $perpage = $vbulletin->GPC['perpage'];
        $pagenumber = $vbulletin->GPC['pagenumber'];
        // array to store private messages in period groups
        $pm_period_groups = array();
        $need_sql_calc_rows = ($search['searchtitle'] or $search['searchuser'] or $search['startdate'] or $search['enddate'] or $search['read']);
        $readstatus = array(0 => '', 1 => '= 0', 2 => '> 0', 3 => '< 2', 4 => '= 2');
        $readstatus = $search['read'] == 0 ? '' : 'AND pm.messageread ' . $readstatus[$search['read']];
        // query private messages
        $pms = $db->query_read_slave("\n\t\t\tSELECT " . ($need_sql_calc_rows ? 'SQL_CALC_FOUND_ROWS' : '') . " pm.*, pmtext.*\n\t\t\t\t" . iif($vbulletin->options['privallowicons'], ", icon.title AS icontitle, icon.iconpath") . "\n\t\t\tFROM " . TABLE_PREFIX . "pm AS pm\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "pmtext AS pmtext ON(pmtext.pmtextid = pm.pmtextid)\n\t\t\t" . iif($vbulletin->options['privallowicons'], "LEFT JOIN " . TABLE_PREFIX . "icon AS icon ON(icon.iconid = pmtext.iconid)") . "\n\t\t\tWHERE pm.userid=" . $vbulletin->userinfo['userid'] . " AND pm.folderid=" . $vbulletin->GPC['folderid'] . ($search['searchtitle'] ? " AND pmtext.title LIKE '%" . $vbulletin->db->escape_string($search['searchtitle']) . "%'" : '') . ($search['searchuser'] ? " AND pmtext.fromusername LIKE '%" . $vbulletin->db->escape_string($search['searchuser']) . "%'" : '') . ($search['startdate'] ? " AND pmtext.dateline >= {$search['startdate']}" : '') . ($search['enddate'] ? " AND pmtext.dateline <= {$search['enddate']}" : '') . "\n\t\t\t{$readstatus}\n\t\t\tORDER BY {$sortfield} " . ($desc ? 'DESC' : 'ASC') . "\n\t\t\tLIMIT {$startat}, " . $vbulletin->GPC['perpage'] . "\n\t\t");
        while ($pm = $db->fetch_array($pms)) {
            if ('title' == $search['sort']) {
                $pm_period_groups[fetch_char_group($pm['title'])]["{$pm['pmid']}"] = $pm;
            } else {
                if ('sender' == $search['sort']) {
                    $pm_period_groups["{$pm['fromusername']}"]["{$pm['pmid']}"] = $pm;
                } else {
                    $pm_period_groups[fetch_period_group($pm['dateline'])]["{$pm['pmid']}"] = $pm;
                }
            }
        }
        $db->free_result($pms);
        // ensure other group is last
        if (isset($pm_period_groups['other'])) {
            $pm_period_groups = $desc ? array_merge($pm_period_groups, array('other' => $pm_period_groups['other'])) : array_merge(array('other' => $pm_period_groups['other']), $pm_period_groups);
        }
        // display returned messages
        $show['pmcheckbox'] = true;
        require_once DIR . '/includes/functions_bigthree.php';
        foreach ($pm_period_groups as $groupid => $pms) {
            if ('date' == $search['sort'] and preg_match('#^(\\d+)_([a-z]+)_ago$#i', $groupid, $matches)) {
                $groupname = construct_phrase($vbphrase["x_{$matches['2']}_ago"], $matches[1]);
            } else {
                if ('title' == $search['sort'] or 'date' == $search['sort']) {
                    if ('older' == $groupid and sizeof($pm_period_groups) == 1) {
                        $groupid = 'old_messages';
                    }
                    $groupname = $vbphrase["{$groupid}"];
                } else {
                    $groupname = $groupid;
                }
            }
            $groupid = $vbulletin->GPC['folderid'] . '_' . $groupid;
            $collapseobj_groupid =& $vbcollapse["collapseobj_pmf{$groupid}"];
            $collapseimg_groupid =& $vbcollapse["collapseimg_pmf{$groupid}"];
            $messagesingroup = sizeof($pms);
            $messagelistbits = '';
            foreach ($pms as $pmid => $pm) {
                if (in_array($pm['fromuserid'], $ignoreusers)) {
                    // from user is on Ignore List
                    //eval('$messagelistbits .= "' . fetch_template('pm_messagelistbit_ignore') . '";');
                } else {
                    switch ($pm['messageread']) {
                        case 0:
                            // unread
                            $pm['statusicon'] = 'new';
                            break;
                        case 1:
                            // read
                            $pm['statusicon'] = 'old';
                            break;
                        case 2:
                            // replied to
                            $pm['statusicon'] = 'replied';
                            break;
                        case 3:
                            // forwarded
                            $pm['statusicon'] = 'forwarded';
                            break;
                    }
                    $pm['senddate'] = vbdate($vbulletin->options['dateformat'], $pm['dateline']);
                    $pm['sendtime'] = vbdate($vbulletin->options['timeformat'], $pm['dateline']);
                    // get userbit
                    if ($vbulletin->GPC['folderid'] == -1) {
                        $users = unserialize($pm['touserarray']);
                        $touser = array();
                        $tousers = array();
                        if (!empty($users)) {
                            foreach ($users as $key => $item) {
                                if (is_array($item)) {
                                    foreach ($item as $subkey => $subitem) {
                                        $touser["{$subkey}"] = $subitem;
                                    }
                                } else {
                                    $touser["{$key}"] = $item;
                                }
                            }
                            uasort($touser, 'strnatcasecmp');
                        }
                        foreach ($touser as $userid => $username) {
                            //eval('$tousers[] = "' . fetch_template('pm_messagelistbit_user') . '";');
                        }
                        $userbit = implode(', ', $tousers);
                    } else {
                        $userid =& $pm['fromuserid'];
                        $username =& $pm['fromusername'];
                        //eval('$userbit = "' . fetch_template('pm_messagelistbit_user') . '";');
                    }
                    $show['pmicon'] = iif($pm['iconpath'], true, false);
                    $show['unread'] = iif(!$pm['messageread'], true, false);
                    //($hook = vBulletinHook::fetch_hook('private_messagelist_messagebit')) ? eval($hook) : false;
                    //eval('$messagelistbits .= "' . fetch_template('pm_messagelistbit') . '";');
                }
                $to_users = unserialize($pm['touserarray']);
                $users = array();
                if ($to_users !== false) {
                    if ($to_users['cc']) {
                        $users = $to_users['cc'];
                    }
                }
                if (!is_array($users)) {
                    $users = array();
                }
                $pm_new = 0;
                switch ($pm['messageread']) {
                    case 0:
                        $pm_new = 1;
                        break;
                    case 1:
                        $pm_new = 0;
                        break;
                    case 2:
                        $pm_new = 2;
                        break;
                }
                $avatarurl = '';
                $userinfoavatar = fetch_userinfo($pm['fromuserid'], FETCH_USERINFO_AVATAR);
                fetch_avatar_from_userinfo($userinfoavatar, true, false);
                if ($userinfoavatar['avatarurl'] != '') {
                    $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                }
                unset($userinfoavatar);
                $tmp = array('id' => $pm['pmid'], 'new_pm' => $pm_new, 'username' => prepare_utf8_string(strip_tags($pm['fromusername'])), 'to_usernames' => prepare_utf8_string(implode('; ', $users)), 'title' => prepare_utf8_string($pm['title']), 'message' => prepare_utf8_string(htmlspecialchars_uni(fetch_censored_text(strip_bbcode(strip_quotes($pm['message']), false, true)))), 'pm_timestamp' => prepare_utf8_string(date_trunc($pm['senddate'] . ' ' . $pm['sendtime'])));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                $pm_out[] = $tmp;
            }
            // free up memory not required any more
            unset($pm_period_groups["{$groupid}"]);
            //($hook = vBulletinHook::fetch_hook('private_messagelist_period')) ? eval($hook) : false;
            // build group template
            //eval('$messagelist_periodgroups .= "' . fetch_template('pm_messagelist_periodgroup') . '";');
        }
        if ($desc) {
            unset($search['order']);
        }
        $sorturl = urlimplode($search);
        // build pagenav
        if ($need_sql_calc_rows) {
            list($totalmessages) = $vbulletin->db->query_first_slave("SELECT FOUND_ROWS()", DBARRAY_NUM);
        }
        $pagenav = construct_page_nav($pagenumber, $perpage, $totalmessages, 'private.php?' . $vbulletin->session->vars['sessionurl'] . 'folderid=' . $vbulletin->GPC['folderid'] . '&amp;pp=' . $vbulletin->GPC['perpage'] . '&amp;' . $sorturl);
        $sortfield = $search['sort'];
        unset($search['sort']);
        $sorturl = 'private.php?' . $vbulletin->session->vars['sessionurl'] . 'folderid=' . $vbulletin->GPC['folderid'] . ($searchurl = urlimplode($search) ? '&amp;' . $searchurl : '');
        $oppositesort = $desc ? 'asc' : 'desc';
        $orderlinks = array('date' => $sorturl . '&amp;sort=date' . ($sortfield == 'date' ? '&amp;order=' . $oppositesort : ''), 'title' => $sorturl . '&amp;sort=title' . ($sortfield == 'title' ? '&amp;order=' . $oppositesort : '&amp;order=asc'), 'sender' => $sorturl . '&amp;sort=sender' . ($sortfield == 'sender' ? '&amp;order=' . $oppositesort : '&amp;order=asc'));
        //eval('$sortarrow["$sortfield"] = "' . fetch_template('forumdisplay_sortarrow') . '";');
        // values for filters
        $startdate = fetch_datearray_from_timestamp($search['startdate'] ? $search['startdate'] : strtotime('last month', TIMENOW));
        $enddate = fetch_datearray_from_timestamp($search['enddate'] ? $search['enddate'] : TIMENOW);
        $startmonth[$startdate[month]] = 'selected="selected"';
        $endmonth[$enddate[month]] = 'selected="selected"';
        $readselection[$search['read']] = 'selected="selected"';
        //eval('$sortfilter = "' . fetch_template('pm_filter') . '";');
    }
    if ($vbulletin->GPC['folderid'] == -1) {
        $show['sentto'] = true;
        $show['movetofolder'] = false;
    } else {
        $show['sentto'] = false;
        $show['movetofolder'] = true;
    }
    return array('pms' => $pm_out, 'total_pms' => $totalmessages, 'unread_pms' => $unread);
}
Example #14
0
             $post['del_phrase'] = 'message_deleted_by_x';
             $show['deleted'] = true;
         } else {
             if ($post['tdel_userid']) {
                 $post['del_username'] =& $post['tdel_username'];
                 $post['del_userid'] =& $post['tdel_userid'];
                 $post['del_reason'] = fetch_censored_text($post['tdel_reason']);
                 $post['del_phrase'] = 'thread_deleted_by_x';
                 $show['deleted'] = true;
             } else {
                 $show['deleted'] = false;
             }
         }
         exec_switch_bg();
         ($hook = vBulletinHook::fetch_hook('postbit_lite')) ? eval($hook) : false;
         fetch_avatar_from_userinfo($post, true);
         $pageinfo_post = array('p' => $post['postid']);
         $templater = vB_Template::create('postbit_lite');
         $templater->register('pageinfo_post', $pageinfo_post);
         $templater->register('pageinfo_thread', $pageinfo_thread);
         $templater->register('post', $post);
         $templater->register('threadinfo', $threadinfo);
         $postbits .= $templater->render();
     }
     $db->free_result($posts);
     unset($postids);
     $sorturl = 'moderation.php?' . $vbulletin->session->vars['sessionurl'] . "do=viewposts&amp;type=" . $type . "&amp;pp={$perpage}&amp;daysprune={$daysprune}";
     $pagenav = construct_page_nav($pagenumber, $perpage, $totalposts, $sorturl . "&amp;sort={$sortfield}" . iif(!empty($vbulletin->GPC['sortorder']), "&amp;order=" . $vbulletin->GPC['sortorder']));
     $show['haveposts'] = true;
 } else {
     $totalposts = 0;
Example #15
0
function do_get_forum()
{
    global $vbulletin, $db, $show, $vbphrase, $foruminfo;
    $canpost = true;
    $vbulletin->input->clean_array_gpc('r', array('fid' => TYPE_INT, 'previewtype' => TYPE_INT));
    $previewtype = $vbulletin->GPC['previewtype'];
    if (!$previewtype) {
        $previewtype = 1;
    }
    if (empty($foruminfo['forumid'])) {
        $forumid = -1;
    } else {
        $vbulletin->input->clean_array_gpc('r', array('password' => TYPE_STR));
        // Check the forum password
        if ($vbulletin->GPC['password'] && $foruminfo['password'] == $vbulletin->GPC['password']) {
            // Set a temp cookie for guests
            if (!$vbulletin->userinfo['userid']) {
                set_bbarray_cookie('forumpwd', $foruminfo['forumid'], md5($vbulletin->userinfo['userid'] . $vbulletin->GPC['password']));
            } else {
                set_bbarray_cookie('forumpwd', $foruminfo['forumid'], md5($vbulletin->userinfo['userid'] . $vbulletin->GPC['password']), 1);
            }
        }
        $perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT);
        $pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT);
        $daysprune = $vbulletin->input->clean_gpc('r', 'daysprune', TYPE_INT);
        $sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR);
        // get permission to view forum
        $_permsgetter_ = 'forumdisplay';
        $forumperms = fetch_permissions($foruminfo['forumid']);
        if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) {
            json_error(ERR_NO_PERMISSION);
        }
        // Check for forum password!
        if (!verify_forum_password($foruminfo['forumid'], $foruminfo['password'], false)) {
            json_error(ERR_NEED_PASSWORD, RV_NEED_FORUM_PASSWORD);
        }
        // Can we post in this forum?
        if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew'])) {
            $canpost = false;
        }
        $forumid = $foruminfo['forumid'];
    }
    // Can forum contain threads?
    $announcements_out = array();
    // These $_REQUEST values will get used in the sort template so they are assigned to normal variables
    $perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT);
    $pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT);
    $daysprune = $vbulletin->input->clean_gpc('r', 'daysprune', TYPE_INT);
    $sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR);
    // get permission to view forum
    $_permsgetter_ = 'forumdisplay';
    $forumperms = fetch_permissions($foruminfo['forumid']);
    if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) {
        json_error(ERR_NO_PERMISSION);
    }
    // disable thread preview if we can't view threads
    if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])) {
        $vbulletin->options['threadpreview'] = 0;
    }
    // check if there is a forum password and if so, ensure the user has it set
    verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
    // verify that we are at the canonical SEO url
    // and redirect to this if not
    //verify_seo_url('forum', $foruminfo, array('pagenumber' => $_REQUEST['pagenumber']));
    // get vbulletin->iforumcache - for use by makeforumjump and forums list
    // fetch the forum even if they are invisible since its needed
    // for the title but we'll unset that further down
    // also fetch subscription info for $show['subscribed'] variable
    cache_ordered_forums(1, 1, $vbulletin->userinfo['userid']);
    $show['newthreadlink'] = iif(!$show['search_engine'] and $foruminfo['allowposting'], true, false);
    $show['threadicons'] = iif($foruminfo['allowicons'], true, false);
    $show['threadratings'] = iif($foruminfo['allowratings'], true, false);
    $show['subscribed_to_forum'] = $vbulletin->forumcache["{$foruminfo['forumid']}"]['subscribeforumid'] != '' ? true : false;
    if (!$daysprune) {
        if ($vbulletin->userinfo['daysprune']) {
            $daysprune = $vbulletin->userinfo['daysprune'];
        } else {
            $daysprune = iif($foruminfo['daysprune'], $foruminfo['daysprune'], 30);
        }
    }
    $daysprune = -1;
    // FRNR
    // ### GET FORUMS, PERMISSIONS, MODERATOR iCACHES ########################
    cache_moderators();
    // draw nav bar
    $navbits = array();
    $navbits[$vbulletin->options['forumhome'] . '.php' . $vbulletin->session->vars['sessionurl_q']] = $vbphrase['forum'];
    $parentlist = array_reverse(explode(',', substr($foruminfo['parentlist'], 0, -3)));
    foreach ($parentlist as $forumID) {
        $forumTitle = $vbulletin->forumcache["{$forumID}"]['title'];
        $navbits[fetch_seo_url('forum', array('forumid' => $forumID, 'title' => $forumTitle))] = $forumTitle;
    }
    // pop the last element off the end of the $nav array so that we can show it without a link
    array_pop($navbits);
    $navbits[''] = $foruminfo['title'];
    $navbits = construct_navbits($navbits);
    $navbar = render_navbar_template($navbits);
    $moderatorslist = '';
    $listexploded = explode(',', $foruminfo['parentlist']);
    $showmods = array();
    $show['moderators'] = false;
    $totalmods = 0;
    foreach ($listexploded as $parentforumid) {
        if (!$imodcache["{$parentforumid}"] or $parentforumid == -1) {
            continue;
        }
        foreach ($imodcache["{$parentforumid}"] as $moderator) {
            if ($showmods["{$moderator['userid']}"] === true) {
                continue;
            }
            $showmods["{$moderator['userid']}"] = true;
            $show['comma_leader'] = $moderatorslist != '';
            $show['moderators'] = true;
            $totalmods++;
        }
    }
    // ### BUILD FORUMS LIST #################################################
    // get an array of child forum ids for this forum
    $foruminfo['childlist'] = explode(',', $foruminfo['childlist']);
    // define max depth for forums display based on $vbulletin->options[forumhomedepth]
    define('MAXFORUMDEPTH', $vbulletin->options['forumdisplaydepth']);
    if (($vbulletin->options['showforumusers'] == 1 or $vbulletin->options['showforumusers'] == 2 or $vbulletin->options['showforumusers'] > 2 and $vbulletin->userinfo['userid']) and !$show['search_engine']) {
        $datecut = TIMENOW - $vbulletin->options['cookietimeout'];
        $forumusers = $db->query_read_slave("\n    \t\tSELECT user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,\n    \t\t\tsession.userid, session.inforum, session.lastactivity, session.badlocation,\n    \t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n    \t\tFROM " . TABLE_PREFIX . "session AS session\n    \t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)\n    \t\tWHERE session.lastactivity > {$datecut}\n    \t\tORDER BY" . iif($vbulletin->options['showforumusers'] == 1 or $vbulletin->options['showforumusers'] == 3, " username ASC,") . " lastactivity DESC\n    \t");
        $numberregistered = 0;
        $numberguest = 0;
        $doneuser = array();
        if ($vbulletin->userinfo['userid']) {
            // fakes the user being in this forum
            $loggedin = array('userid' => $vbulletin->userinfo['userid'], 'username' => $vbulletin->userinfo['username'], 'invisible' => $vbulletin->userinfo['invisible'], 'invisiblemark' => $vbulletin->userinfo['invisiblemark'], 'inforum' => $foruminfo['forumid'], 'lastactivity' => TIMENOW, 'musername' => $vbulletin->userinfo['musername']);
            $numberregistered = 1;
            fetch_online_status($loggedin);
            $show['comma_leader'] = false;
            $doneuser["{$vbulletin->userinfo['userid']}"] = 1;
        }
        $inforum = array();
        // this require the query to have lastactivity ordered by DESC so that the latest location will be the first encountered.
        while ($loggedin = $db->fetch_array($forumusers)) {
            if ($loggedin['badlocation']) {
                continue;
            }
            if (empty($doneuser["{$loggedin['userid']}"])) {
                if (in_array($loggedin['inforum'], $foruminfo['childlist']) and $loggedin['inforum'] != -1) {
                    if (!$loggedin['userid']) {
                        // this is a guest
                        $numberguest++;
                        $inforum["{$loggedin['inforum']}"]++;
                    } else {
                        $numberregistered++;
                        $inforum["{$loggedin['inforum']}"]++;
                        if (fetch_online_status($loggedin)) {
                            fetch_musername($loggedin);
                            $show['comma_leader'] = $activeusers != '';
                        }
                    }
                }
                if ($loggedin['userid']) {
                    $doneuser["{$loggedin['userid']}"] = 1;
                }
            }
        }
        if (!$vbulletin->userinfo['userid']) {
            $numberguest = $numberguest == 0 ? 1 : $numberguest;
        }
        $totalonline = $numberregistered + $numberguest;
        unset($joingroupid, $key, $datecut, $invisibleuser, $userinfo, $userid, $loggedin, $index, $value, $forumusers, $parentarray);
        $show['activeusers'] = true;
    } else {
        $show['activeusers'] = false;
    }
    // #############################################################################
    // get read status for this forum and children
    $unreadchildforums = 0;
    foreach ($foruminfo['childlist'] as $val) {
        if ($val == -1 or $val == $foruminfo['forumid']) {
            continue;
        }
        if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) {
            $lastread_child = max($vbulletin->forumcache["{$val}"]['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400);
        } else {
            $lastread_child = max(intval(fetch_bbarray_cookie('forum_view', $val)), $vbulletin->userinfo['lastvisit']);
        }
        if ($vbulletin->forumcache["{$val}"]['lastpost'] > $lastread_child) {
            $unreadchildforums = 1;
            break;
        }
    }
    $forumbits = fr_construct_forum_bit($forumid);
    // admin tools
    $show['post_queue'] = can_moderate($foruminfo['forumid'], 'canmoderateposts');
    $show['attachment_queue'] = can_moderate($foruminfo['forumid'], 'canmoderateattachments');
    $show['mass_move'] = can_moderate($foruminfo['forumid'], 'canmassmove');
    $show['mass_prune'] = can_moderate($foruminfo['forumid'], 'canmassprune');
    $show['post_new_announcement'] = can_moderate($foruminfo['forumid'], 'canannounce');
    $show['addmoderator'] = $permissions['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'];
    $show['adminoptions'] = ($show['post_queue'] or $show['attachment_queue'] or $show['mass_move'] or $show['mass_prune'] or $show['addmoderator'] or $show['post_new_announcement']);
    $navpopup = array('id' => 'forumdisplay_navpopup', 'title' => $foruminfo['title_clean'], 'link' => fetch_seo_url('forum', $foruminfo));
    construct_quick_nav($navpopup);
    /////////////////////////////////
    if ($foruminfo['cancontainthreads']) {
        /////////////////////////////////
        if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) {
            $foruminfo['forumread'] = $vbulletin->forumcache["{$foruminfo['forumid']}"]['forumread'];
            $lastread = max($foruminfo['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400);
        } else {
            $bbforumview = intval(fetch_bbarray_cookie('forum_view', $foruminfo['forumid']));
            $lastread = max($bbforumview, $vbulletin->userinfo['lastvisit']);
        }
        // Inline Moderation
        $show['movethread'] = can_moderate($forumid, 'canmanagethreads') ? true : false;
        $show['deletethread'] = (can_moderate($forumid, 'candeleteposts') or can_moderate($forumid, 'canremoveposts')) ? true : false;
        $show['approvethread'] = can_moderate($forumid, 'canmoderateposts') ? true : false;
        $show['openthread'] = can_moderate($forumid, 'canopenclose') ? true : false;
        $show['inlinemod'] = ($show['movethread'] or $show['deletethread'] or $show['approvethread'] or $show['openthread']) ? true : false;
        $show['spamctrls'] = ($show['inlinemod'] and $show['deletethread']);
        $url = $show['inlinemod'] ? SCRIPTPATH : '';
        // fetch popup menu
        if ($show['popups'] and $show['inlinemod']) {
        } else {
            $threadadmin_imod_thread_menu = '';
        }
        // get announcements
        $announcebits = '';
        if ($show['threadicons'] and $show['inlinemod']) {
            $announcecolspan = 6;
        } else {
            if (!$show['threadicons'] and !$show['inlinemod']) {
                $announcecolspan = 4;
            } else {
                $announcecolspan = 5;
            }
        }
        $mindate = TIMENOW - 2592000;
        // 30 days
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $announcements = $db->query_read_slave("\n    \t\tSELECT\n    \t\t\tannouncement.announcementid, startdate, title, announcement.views,\n    \t\t\tuser.username, user.userid, user.usertitle, user.customtitle, user.usergroupid,\n    \t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n    \t\t\t" . ($vbulletin->userinfo['userid'] ? ", NOT ISNULL(announcementread.announcementid) AS readannounce" : "") . "\n    \t\t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "announcement AS announcement\n    \t\t" . ($vbulletin->userinfo['userid'] ? "LEFT JOIN " . TABLE_PREFIX . "announcementread AS announcementread ON (announcementread.announcementid = announcement.announcementid AND announcementread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "\n    \t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = announcement.userid)\n    \t\t{$hook_query_joins}\n    \t\tWHERE startdate <= " . TIMENOW . "\n    \t\t\tAND enddate >= " . TIMENOW . "\n    \t\t\tAND " . fetch_forum_clause_sql($foruminfo['forumid'], 'forumid') . "\n    \t\t\t{$hook_query_where}\n    \t\tORDER BY startdate DESC, announcement.announcementid DESC\n    \t\t" . iif($vbulletin->options['oneannounce'], "LIMIT 1"));
        while ($announcement = $db->fetch_array($announcements)) {
            fetch_musername($announcement);
            $announcement['title'] = fetch_censored_text($announcement['title']);
            $announcement['postdate'] = vbdate($vbulletin->options['dateformat'], $announcement['startdate']);
            if ($announcement['readannounce'] or $announcement['startdate'] <= $mindate) {
                $announcement['statusicon'] = 'old';
            } else {
                $announcement['statusicon'] = 'new';
            }
            $announcement['views'] = vb_number_format($announcement['views']);
            $announcementidlink = iif(!$vbulletin->options['oneannounce'], "&amp;a={$announcement['announcementid']}");
            // FRNR START
            if ($pagenumber == 1) {
                $avatarurl = '';
                $userinfoavatar = fetch_userinfo($announcement['userid'], FETCH_USERINFO_AVATAR);
                fetch_avatar_from_userinfo($userinfoavatar, true, false);
                if ($userinfoavatar['avatarurl'] != '') {
                    $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                }
                unset($userinfoavatar);
                $tmp = array('thread_id' => $foruminfo['forumid'], 'announcement' => 1, 'new_posts' => $announcement['readannounce'] ? 0 : 1, 'thread_title' => prepare_utf8_string(strip_tags($announcement['title'])), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($announcement['pagetext']), FR_PREVIEW_LEN)), 'post_userid' => $announcement['userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($announcement['postdate'])), 'post_username' => prepare_utf8_string(strip_tags($announcement['username'])));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                $announcements_out[] = $tmp;
            }
            // FRNR END
        }
        // display threads
        if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers'])) {
            $limitothers = "AND postuserid = " . $vbulletin->userinfo['userid'] . " AND " . $vbulletin->userinfo['userid'] . " <> 0";
        } else {
            $limitothers = '';
        }
        if (can_moderate($foruminfo['forumid'])) {
            $redirectjoin = "LEFT JOIN " . TABLE_PREFIX . "threadredirect AS threadredirect ON(thread.open = 10 AND thread.threadid = threadredirect.threadid)";
        } else {
            $redirectjoin = '';
        }
        // filter out deletion notices if can't be seen
        if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'] or can_moderate($foruminfo['forumid'])) {
            $canseedelnotice = true;
            $deljoin = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND deletionlog.type = 'thread')";
        } else {
            $canseedelnotice = false;
            $deljoin = '';
        }
        // remove threads from users on the global ignore list if user is not a moderator
        if ($Coventry = fetch_coventry('string') and !can_moderate($foruminfo['forumid'])) {
            $globalignore = "AND postuserid NOT IN ({$Coventry}) ";
        } else {
            $globalignore = '';
        }
        // look at thread limiting options
        $stickyids = '';
        $stickycount = 0;
        if ($daysprune != -1) {
            if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) {
                $tachyjoin = "LEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON " . "(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ")";
                $datecut = " AND (thread.lastpost >= " . (TIMENOW - $daysprune * 86400) . " OR tachythreadpost.lastpost >= " . (TIMENOW - $daysprune * 86400) . ")";
            } else {
                $datecut = "AND lastpost >= " . (TIMENOW - $daysprune * 86400);
                $tachyjoin = "";
            }
            $show['noposts'] = false;
        } else {
            $tachyjoin = "";
            $datecut = "";
            $show['noposts'] = true;
        }
        // complete form fields on page
        $daysprunesel = iif($daysprune == -1, 'all', $daysprune);
        $daysprunesel = array($daysprunesel => 'selected="selected"');
        $vbulletin->input->clean_array_gpc('r', array('sortorder' => TYPE_NOHTML, 'prefixid' => TYPE_NOHTML));
        // prefix options
        $prefix_options = fetch_prefix_html($foruminfo['forumid'], $vbulletin->GPC['prefixid']);
        $prefix_selected = array('anythread', 'anythread' => '', 'none' => '');
        if ($vbulletin->GPC['prefixid']) {
            //no prefix id
            if ($vbulletin->GPC['prefixid'] == '-1') {
                $prefix_filter = "AND thread.prefixid = ''";
                $prefix_selected['none'] = ' selected="selected"';
            } else {
                if ($vbulletin->GPC['prefixid'] == '-2') {
                    $prefix_filter = "AND thread.prefixid <> ''";
                    $prefix_selected['anyprefix'] = ' selected="selected"';
                } else {
                    $prefix_filter = "AND thread.prefixid = '" . $db->escape_string($vbulletin->GPC['prefixid']) . "'";
                }
            }
        } else {
            $prefix_filter = '';
            $prefix_selected['anythread'] = ' selected="selected"';
        }
        // default sorting methods
        if (empty($sortfield)) {
            $sortfield = $foruminfo['defaultsortfield'];
        }
        if (empty($vbulletin->GPC['sortorder'])) {
            $vbulletin->GPC['sortorder'] = $foruminfo['defaultsortorder'];
        }
        // look at sorting options:
        if ('asc' != ($sortorder = $vbulletin->GPC['sortorder'])) {
            $sqlsortorder = 'DESC';
            $order = array('desc' => 'checked="checked"');
            $vbulletin->GPC['sortorder'] = 'desc';
        } else {
            $sqlsortorder = '';
            $order = array('asc' => 'checked="checked"');
        }
        $sqlsortfield2 = '';
        switch ($sortfield) {
            case 'title':
                $sqlsortfield = 'thread.title';
                break;
            case 'lastpost':
                $sqlsortfield = 'lastpost';
                break;
            case 'replycount':
            case 'views':
                $sqlsortfield = 'views';
            case 'postusername':
                $sqlsortfield = $sortfield;
                break;
            case 'voteavg':
                if ($foruminfo['allowratings']) {
                    $sqlsortfield = 'voteavg';
                    $sqlsortfield2 = 'votenum';
                    break;
                }
            case 'dateline':
                $sqlsortfield = 'thread.dateline';
                break;
                // else, use last post
            // else, use last post
            default:
                $handled = false;
                if (!$handled) {
                    $sqlsortfield = 'lastpost';
                    $sortfield = 'lastpost';
                }
        }
        $sort = array($sortfield => 'selected="selected"');
        $visiblethreads = " AND visible = 1";
        /*if (!can_moderate($forumid, 'canmoderateposts'))
            	{
            		if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice']))
            		{
            			$visiblethreads = " AND visible = 1 ";
            		}
            		else
            		{
            			$visiblethreads = " AND visible IN (1,2)";
            		}
            	}
            	else
            	{
            		$visiblethreads = " AND visible IN (0,1,2)";
        	}*/
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        # Include visible IN (0,1,2) in order to hit upon the 4 column index
        $threadscount = $db->query_first_slave("\n    \t\tSELECT COUNT(*) AS threads, SUM(IF(thread.lastpost > {$lastread} AND open <> 10, 1, 0)) AS newthread\n    \t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t{$tachyjoin}\n    \t\t{$hook_query_joins}\n    \t\tWHERE forumid = {$foruminfo['forumid']}\n    \t\t\tAND sticky = 0\n    \t\t\t{$prefix_filter}\n    \t\t\t{$visiblethreads}\n    \t\t\t{$globalignore}\n    \t\t\t{$limitothers}\n    \t\t\t{$datecut}\n    \t\t\t{$hook_query_where}\n    \t");
        $totalthreads = $threadscount['threads'];
        $newthreads = $threadscount['newthread'];
        // set defaults
        sanitize_pageresults($totalthreads, $pagenumber, $perpage, 200, $vbulletin->options['maxthreads']);
        // get number of sticky threads for the first page
        // on the first page there will be the sticky threads PLUS the $perpage other normal threads
        // not quite a bug, but a deliberate feature!
        if ($pagenumber == 1) {
            $stickies = $db->query_read_slave("\n    \t\t\tSELECT thread.threadid, lastpost, open\n    \t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t\tWHERE forumid = {$foruminfo['forumid']}\n    \t\t\t\tAND sticky = 1\n    \t\t\t\t{$prefix_filter}\n    \t\t\t\t{$visiblethreads}\n    \t\t\t\t{$limitothers}\n    \t\t\t\t{$globalignore}\n    \t\t");
            while ($thissticky = $db->fetch_array($stickies)) {
                $stickycount++;
                if ($thissticky['lastpost'] >= $lastread and $thissticky['open'] != 10) {
                    $newthreads++;
                }
                $stickyids .= ",{$thissticky['threadid']}";
            }
            $db->free_result($stickies);
            unset($thissticky, $stickies);
        }
        $limitlower = ($pagenumber - 1) * $perpage;
        $limitupper = $pagenumber * $perpage;
        if ($limitupper > $totalthreads) {
            $limitupper = $totalthreads;
            if ($limitlower > $totalthreads) {
                $limitlower = $totalthreads - $perpage - 1;
            }
        }
        if ($limitlower < 0) {
            $limitlower = 0;
        }
        if ($foruminfo['allowratings']) {
            $vbulletin->options['showvotes'] = intval($vbulletin->options['showvotes']);
            $votequery = "\n    \t\t\tIF(votenum >= " . $vbulletin->options['showvotes'] . ", votenum, 0) AS votenum,\n    \t\t\tIF(votenum >= " . $vbulletin->options['showvotes'] . " AND votenum > 0, votetotal / votenum, 0) AS voteavg,\n    \t\t";
        } else {
            $votequery = '';
        }
        if ($previewtype == 1) {
            $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,";
            $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.firstpostid)";
        } else {
            $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,";
            $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.lastpostid)";
        }
        if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) {
            $tachyjoin = "\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON\n    \t\t\t\t(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ")\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "tachythreadcounter AS tachythreadcounter ON\n    \t\t\t\t(tachythreadcounter.threadid = thread.threadid AND tachythreadcounter.userid = " . $vbulletin->userinfo['userid'] . ")\n    \t\t";
            $tachy_columns = "\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastpost, tachythreadpost.lastpost) AS lastpost,\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastposter, tachythreadpost.lastposter) AS lastposter,\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastposterid, tachythreadpost.lastposterid) AS lastposterid,\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastpostid, tachythreadpost.lastpostid) AS lastpostid,\n    \t\t\tIF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount) AS replycount,\n    \t\t\tIF(thread.views<=IF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount), IF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount)+1, thread.views) AS views\n    \t\t";
        } else {
            $tachyjoin = '';
            $tachy_columns = 'thread.lastpost, thread.lastposter, thread.lastposterid, thread.lastpostid, thread.replycount, IF(thread.views<=thread.replycount, thread.replycount+1, thread.views) AS views';
        }
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $getthreadids = $db->query_read_slave("\n    \t\tSELECT " . iif($sortfield == 'voteavg', $votequery) . " thread.threadid,\n    \t\t\t{$tachy_columns}\n    \t\t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t{$tachyjoin}\n    \t\t{$hook_query_joins}\n    \t\tWHERE forumid = {$foruminfo['forumid']}\n    \t\t\tAND sticky = 0\n    \t\t\t{$prefix_filter}\n    \t\t\t{$visiblethreads}\n    \t\t\t{$globalignore}\n    \t\t\t{$limitothers}\n    \t\t\t{$datecut}\n    \t\t\t{$hook_query_where}\n    \t\tORDER BY sticky DESC, {$sqlsortfield} {$sqlsortorder}" . (!empty($sqlsortfield2) ? ", {$sqlsortfield2} {$sqlsortorder}" : '') . "\n    \t\tLIMIT {$limitlower}, {$perpage}\n    \t");
        $ids = '';
        while ($thread = $db->fetch_array($getthreadids)) {
            $ids .= ',' . $thread['threadid'];
        }
        $ids .= $stickyids;
        $db->free_result($getthreadids);
        unset($thread, $getthreadids);
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $threads = $db->query_read_slave("\n    \t\tSELECT {$votequery} {$previewfield}\n    \t\t\tthread.threadid, thread.title AS threadtitle, thread.forumid, pollid, open, postusername, postuserid, thread.iconid AS threadiconid,\n    \t\t\tthread.dateline, notes, thread.visible, sticky, votetotal, thread.attach, {$tachy_columns},\n    \t\t\tthread.prefixid, thread.taglist, hiddencount, deletedcount,\n    \t\t\tuser.usergroupid, user.homepage, user.options AS useroptions, IF(userlist.friend = 'yes', 1, 0) AS isfriend\n    \t\t\t" . (($vbulletin->options['threadsubscribed'] and $vbulletin->userinfo['userid']) ? ", NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed" : "") . "\n    \t\t\t" . ($deljoin ? ", deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason" : "") . "\n    \t\t\t" . (($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) ? ", threadread.readtime AS threadread" : "") . "\n    \t\t\t" . ($redirectjoin ? ", threadredirect.expires" : "") . "\n    \t\t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.lastposterid)\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "userlist AS userlist ON (userlist.relationid = user.userid AND userlist.type = 'buddy' AND userlist.userid = " . $vbulletin->userinfo['userid'] . ")\n    \t\t\t{$deljoin}\n    \t\t\t" . (($vbulletin->options['threadsubscribed'] and $vbulletin->userinfo['userid']) ? " LEFT JOIN " . TABLE_PREFIX . "subscribethread AS subscribethread ON(subscribethread.threadid = thread.threadid AND subscribethread.userid = " . $vbulletin->userinfo['userid'] . " AND canview = 1)" : "") . "\n    \t\t\t" . (($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) ? " LEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "\n    \t\t\t{$previewjoin}\n    \t\t\t{$tachyjoin}\n    \t\t\t{$redirectjoin}\n    \t\t\t{$hook_query_joins}\n    \t\tWHERE thread.threadid IN (0{$ids}) {$hook_query_where}\n    \t\tORDER BY sticky DESC, {$sqlsortfield} {$sqlsortorder}" . (!empty($sqlsortfield2) ? ", {$sqlsortfield2} {$sqlsortorder}" : '') . "\n    \t");
        unset($limitothers, $delthreadlimit, $deljoin, $datecut, $votequery, $sqlsortfield, $sqlsortorder, $threadids, $sqlsortfield2);
        // Get Dot Threads
        $dotthreads = fetch_dot_threads_array($ids);
        if ($vbulletin->options['showdots'] and $vbulletin->userinfo['userid']) {
            $show['dotthreads'] = true;
        } else {
            $show['dotthreads'] = false;
        }
        unset($ids);
        $pageinfo = array();
        if ($vbulletin->GPC['prefixid']) {
            $pageinfo['prefixid'] = $vbulletin->GPC['prefixid'];
        }
        if ($vbulletin->GPC['daysprune']) {
            $pageinfo['daysprune'] = $daysprune;
        }
        $show['fetchseo'] = true;
        $oppositesort = $vbulletin->GPC['sortorder'] == 'asc' ? 'desc' : 'asc';
        $pageinfo_voteavg = $pageinfo + array('sort' => 'voteavg', 'order' => 'voteavg' == $sortfield ? $oppositesort : 'desc');
        $pageinfo_title = $pageinfo + array('sort' => 'title', 'order' => 'title' == $sortfield ? $oppositesort : 'asc');
        $pageinfo_postusername = $pageinfo + array('sort' => 'postusername', 'order' => 'postusername' == $sortfield ? $oppositesort : 'asc');
        $pageinfo_flastpost = $pageinfo + array('sort' => 'lastpost', 'order' => 'lastpost' == $sortfield ? $oppositesort : 'asc');
        $pageinfo_replycount = $pageinfo + array('sort' => 'replycount', 'order' => 'replycount' == $sortfield ? $oppositesort : 'desc');
        $pageinfo_views = $pageinfo + array('sort' => 'views', 'order' => 'views' == $sortfield ? $oppositesort : 'desc');
        $pageinfo_sort = $pageinfo + array(sort => $sortfield, 'order' => $oppositesort, 'pp' => $perpage, 'page' => $pagenumber);
        if ($totalthreads > 0 or $stickyids) {
            if ($totalthreads > 0) {
                $limitlower++;
            }
            // check to see if there are any threads to display. If there are, do so, otherwise, show message
            if ($vbulletin->options['threadpreview'] > 0) {
                // Get Buddy List
                $buddy = array();
                if (trim($vbulletin->userinfo['buddylist'])) {
                    $buddylist = preg_split('/( )+/', trim($vbulletin->userinfo['buddylist']), -1, PREG_SPLIT_NO_EMPTY);
                    foreach ($buddylist as $buddyuserid) {
                        $buddy["{$buddyuserid}"] = 1;
                    }
                }
                DEVDEBUG('buddies: ' . implode(', ', array_keys($buddy)));
                // Get Ignore Users
                $ignore = array();
                if (trim($vbulletin->userinfo['ignorelist'])) {
                    $ignorelist = preg_split('/( )+/', trim($vbulletin->userinfo['ignorelist']), -1, PREG_SPLIT_NO_EMPTY);
                    foreach ($ignorelist as $ignoreuserid) {
                        if (!$buddy["{$ignoreuserid}"]) {
                            $ignore["{$ignoreuserid}"] = 1;
                        }
                    }
                }
                DEVDEBUG('ignored users: ' . implode(', ', array_keys($ignore)));
            }
            $show['threads'] = true;
            $threadbits = '';
            $threadbits_sticky = '';
            $counter = 0;
            $toread = 0;
            while ($thread = $db->fetch_array($threads)) {
                // AND $counter++ < $perpage)
                // build thread data
                $thread = process_thread_array($thread, $lastread, $foruminfo['allowicons']);
                $realthreadid = $thread['realthreadid'];
                if ($thread['sticky']) {
                    $threadbit =& $threadbits_sticky;
                } else {
                    $threadbit =& $threadbits;
                }
                // Soft Deleted Thread
                if ($thread['visible'] == 2) {
                    $thread['deletedcount']++;
                    $show['threadtitle'] = (can_moderate($forumid) or $vbulletin->userinfo['userid'] != 0 and $vbulletin->userinfo['userid'] == $thread['postuserid']) ? true : false;
                    $show['deletereason'] = !empty($thread['del_reason']) ? true : false;
                    $show['viewthread'] = can_moderate($forumid) ? true : false;
                    $show['managethread'] = (can_moderate($forumid, 'candeleteposts') or can_moderate($forumid, 'canremoveposts')) ? true : false;
                    $show['moderated'] = ($thread['hiddencount'] > 0 and can_moderate($forumid, 'canmoderateposts')) ? true : false;
                    $show['deletedthread'] = $canseedelnotice;
                } else {
                    if (!$thread['visible']) {
                        $thread['hiddencount']++;
                    }
                    $show['moderated'] = ($thread['hiddencount'] > 0 and can_moderate($forumid, 'canmoderateposts')) ? true : false;
                    $show['deletedthread'] = ($thread['deletedcount'] > 0 and $canseedelnotice) ? true : false;
                    $pageinfo_lastpage = array();
                    if ($show['pagenavmore']) {
                        $pageinfo_lastpage['page'] = $thread['totalpages'];
                    }
                    $pageinfo_newpost = array('goto' => 'newpost');
                    $pageinfo_lastpost = array('p' => $thread['lastpostid']);
                    // prepare the member action drop-down menu
                    $memberaction_dropdown = construct_memberaction_dropdown(fetch_lastposter_userinfo($thread));
                }
                // FRNR Start
                $avatarurl = '';
                if ($thread['lastpost_userid'] > 0) {
                    $userinfoavatar = fetch_userinfo($thread['lastpost_userid'], FETCH_USERINFO_AVATAR);
                    fetch_avatar_from_userinfo($userinfoavatar, true, false);
                    if ($userinfoavatar['avatarurl'] != '') {
                        $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                    }
                    unset($userinfoavatar);
                }
                $tmp = array('thread_id' => $thread['threadid'], 'new_posts' => $show['gotonewpost'] ? 1 : 0, 'forum_id' => $thread['forumid'], 'total_posts' => $thread['totalposts'] ? $thread['totalposts'] : 0, 'thread_title' => prepare_utf8_string(strip_tags($thread['threadtitle'])), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($thread['preview']), FR_PREVIEW_LEN)), 'post_userid' => $thread['lastpost_userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($thread['lastpostdate']) . ' ' . $thread['lastposttime']), 'post_username' => prepare_utf8_string(strip_tags($thread['lastpost_username'])));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                if ($thread['prefixid']) {
                    $tmp['prefix'] = prepare_utf8_string(strip_tags($vbphrase["prefix_{$thread['prefixid']}_title_plain"]));
                }
                if ($thread['attach']) {
                    $tmp['attach'] = true;
                }
                if ($thread['pollid']) {
                    $tmp['poll'] = true;
                }
                if ($thread['open'] == 10) {
                    // Special case for redirect threads
                    $tmp = array_merge($tmp, array('post_userid' => $thread['postuserid'], 'post_username' => prepare_utf8_string(strip_tags($thread['postusername'])), 'poll' => false));
                }
                if ($thread['sticky']) {
                    $thread_data_sticky[] = $tmp;
                } else {
                    $thread_data[] = $tmp;
                }
                // FRNR Stop
            }
            $db->free_result($threads);
            unset($thread, $counter);
            $pageinfo_pagenav = array();
            if (!empty($vbulletin->GPC['perpage'])) {
                $pageinfo_pagenav['pp'] = $perpage;
            }
            if (!empty($vbulletin->GPC['prefixid'])) {
                $pageinfo_pagenav['prefixid'] = $vbulletin->GPC['prefixid'];
            }
            if (!empty($vbulletin->GPC['sortfield'])) {
                $pageinfo_pagenav['sort'] = $sortfield;
            }
            if (!empty($vbulletin->GPC['sortorder'])) {
                $pageinfo_pagenav['order'] = $vbulletin->GPC['sortorder'];
            }
            if (!empty($vbulletin->GPC['daysprune'])) {
                $pageinfo_pagenav['daysprune'] = $daysprune;
            }
            $pagenav = construct_page_nav($pagenumber, $perpage, $totalthreads, 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f={$foruminfo['forumid']}", '', '', 'forum', $foruminfo, $pageinfo_pagenav);
        }
        unset($threads, $dotthreads);
        // get colspan for bottom bar
        $foruminfo['bottomcolspan'] = 5;
        if ($foruminfo['allowicons']) {
            $foruminfo['bottomcolspan']++;
        }
        if ($show['inlinemod']) {
            $foruminfo['bottomcolspan']++;
        }
        $show['threadslist'] = true;
        /////////////////////////////////
    } else {
        $show['threadslist'] = false;
        $canpost = false;
        // FRNR
    }
    /////////////////////////////////
    if (!$vbulletin->GPC['prefixid'] and $newthreads < 1 and $unreadchildforums < 1) {
        mark_forum_read($foruminfo, $vbulletin->userinfo['userid'], TIMENOW);
    }
    // FNRN Below
    $out = array();
    if (is_array($thread_data) && count($thread_data) > 0) {
        $out['threads'] = $thread_data;
    } else {
        $out['threads'] = array();
    }
    if (is_array($thread_data_sticky) && count($thread_data_sticky) > 0) {
        $out['threads_sticky'] = $thread_data_sticky;
        $out['total_sticky_threads'] = count($thread_data_sticky);
    } else {
        $out['threads_sticky'] = array();
        $out['total_sticky_threads'] = 0;
    }
    // Announcements become #1 on the threads
    if (is_array($announcements_out) && count($announcements_out) == 1) {
        array_unshift($out['threads'], $announcements_out[0]);
        $totalthreads++;
    }
    $out['total_threads'] = $totalthreads ? $totalthreads : 0;
    if ($forumbits) {
        $out['forums'] = $forumbits;
    } else {
        $out['forums'] = array();
    }
    $out['canpost'] = $canpost ? 1 : 0;
    $out['canattach'] = ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] and $vbulletin->userinfo['userid']);
    // Get thread prefixes for this forum (if any)
    $prefix_out = array();
    if ($prefixsets = fetch_prefix_array($forumid)) {
        foreach ($prefixsets as $prefixsetid => $prefixes) {
            $optgroup_options = '';
            foreach ($prefixes as $prefixid => $prefix) {
                if ($permcheck and !can_use_prefix($prefixid, $prefix['restrictions'])) {
                    continue;
                }
                $optionvalue = $prefixid;
                $optiontitle = htmlspecialchars_uni($vbphrase["prefix_{$prefixid}_title_plain"]);
                $prefix_out[] = array('prefixid' => $prefixid, 'prefixcaption' => prepare_utf8_string($optiontitle));
            }
        }
    }
    if ($foruminfo['options'] & $vbulletin->bf_misc_forumoptions['prefixrequired']) {
        $out['prefixrequired'] = true;
    } else {
        $out['prefixrequired'] = false;
    }
    $out['prefixes'] = $prefix_out;
    return $out;
}
Example #16
0
	/**
	* Template method that does all the work to display an issue note, including processing the template
	*
	* @return	string	Templated note output
	*/
	function construct()
	{
		($hook = vBulletinHook::fetch_hook('visitor_messagebit_display_start')) ? eval($hook) : false;

		// preparation for display...
		$this->prepare_start();

		if ($this->message['userid'])
		{
			$this->process_registered_user();
		}
		else
		{
			$this->process_unregistered_user();
		}

		fetch_avatar_from_userinfo($this->message, true);

		$this->process_date_status();
		$this->process_display();
		$this->process_text();
		$this->prepare_end();

		// actual display...
		$userinfo =& $this->userinfo;

		fetch_avatar_from_userinfo($userinfo, true);

		$message =& $this->message;

		global $show, $vbphrase;
		global $spacer_open, $spacer_close;

		global $bgclass, $altbgclass;
		exec_switch_bg();

		$pageinfo_vm_ignored = array(
			'vmid'        => $message['vmid'],
			'showignored' => 1,
		);

		$pageinfo_vm = array('vmid' => $message['vmid']);

		$messageinfo = array(
			'userid'   => $message['profileuserid'],
			'username' => $message['profileusername'],
		);

		($hook = vBulletinHook::fetch_hook('visitor_messagebit_display_complete')) ? eval($hook) : false;

		$templater = vB_Template::create($this->template);
			$templater->register('message', $message);
			$templater->register('messageinfo', $messageinfo);
			$templater->register('pageinfo_vm', $pageinfo_vm);
			$templater->register('pageinfo_vm_ignored', $pageinfo_vm_ignored);
			$templater->register('userinfo', $userinfo);
		return $templater->render();

	}
Example #17
0
function do_showresults($searchid, $pagenumber = 1, $perpage = 25)
{
    global $vbulletin, $db, $show, $vbphrase, $current_user, $show;
    $vbulletin->options['threadpreview'] = FR_PREVIEW_LEN;
    $vbulletin->input->clean_array_gpc('r', array('previewtype' => TYPE_INT));
    $previewtype = $vbulletin->GPC['previewtype'];
    if (!$previewtype) {
        $previewtype = 1;
    }
    $bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
    // Get exclude IDs
    $exclude_ids = @explode(',', $vbulletin->options['forumrunner_exclude']);
    if (in_array('-1', $exclude_ids)) {
        $exclude_ids = array();
    }
    if ($results = vB_Search_Results::create_from_searchid($current_user, $searchid)) {
        $pages = $results->get_page($pagenumber, $perpage, 10000);
    } else {
        $pages = array();
    }
    if (count($pages) == 0) {
        $threads[]['error'] = strip_tags(fetch_error('searchnoresults', ''));
        return array('threads' => $threads, 'total_threads' => count($threads));
    }
    $thread_data = array();
    $skipped = 0;
    foreach ($pages as $item) {
        switch (get_class($item)) {
            case 'vBForum_Search_Result_Thread':
                $thread = $item->get_thread();
                $foruminfo = fetch_foruminfo($thread->get_field('forumid'));
                $parentlist = explode(',', substr($foruminfo['parentlist'], 0, -3));
                $skip = false;
                foreach ($parentlist as $parent_id) {
                    if (in_array($parent_id, $exclude_ids)) {
                        $skip = true;
                    }
                }
                if ($thread->get_field('visible') == 2) {
                    $skip = true;
                }
                if ($skip) {
                    $skipped++;
                    continue;
                }
                $lastread = $thread->get_forum()->get_last_read_by_current_user($current_user);
                $legacy_thread = process_thread_array($thread->get_record(), $lastread);
                $date = vbdate($vbulletin->options['dateformat'], $thread->get_field('lastpost'));
                $time = vbdate($vbulletin->options['timeformat'], $thread->get_field('lastpost'));
                $previewinfo = $db->query_first_slave("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "post\n\t\tWHERE postid = " . $thread->get_field($previewtype == 1 ? 'firstpostid' : 'lastpostid') . "\n\t    ");
                $preview = '';
                if (method_exists($bbcode_parser, 'get_preview')) {
                    $preview = $bbcode_parser->get_preview(fetch_censored_text($previewinfo['pagetext']), 200);
                } else {
                    // vB4 prior to vB4.0.4 did not have get_preview()
                    list($text, $nuked_quotes, $images) = parse_post($previewinfo['pagetext'], true, array());
                    $preview = preview_chop(fetch_censored_text($nuked_quotes), 200);
                }
                $avatarurl = '';
                if ($previewinfo['userid'] > 0) {
                    $userinfoavatar = fetch_userinfo($previewinfo['userid'], FETCH_USERINFO_AVATAR);
                    fetch_avatar_from_userinfo($userinfoavatar, true, false);
                    if ($userinfoavatar['avatarurl'] != '') {
                        $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                    }
                    unset($userinfoavatar);
                }
                $tmp = array('thread_id' => $thread->get_field('threadid'), 'new_posts' => $show['gotonewpost'], 'forum_id' => $thread->get_field('forumid'), 'total_posts' => $thread->get_field('replycount'), 'forum_title' => prepare_utf8_string(strip_tags($foruminfo['title'])), 'thread_title' => prepare_utf8_string(strip_tags($thread->get_field('title'))), 'thread_preview' => prepare_utf8_string(preview_chop(strip_tags(strip_bbcode(html_entity_decode($preview))), FR_PREVIEW_LEN)), 'post_userid' => $previewinfo['userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($date) . ' ' . $time), 'post_username' => prepare_utf8_string(strip_tags($previewinfo['username'])));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                if ($thread->get_field('prefixid')) {
                    $prefixid = $thread->get_field('prefixid');
                    $tmp['prefix'] = prepare_utf8_string(strip_tags($vbphrase["prefix_{$prefixid}_title_plain"]));
                }
                if ($thread->get_field('attach')) {
                    $tmp['attach'] = true;
                }
                if ($thread->get_field('pollid')) {
                    $tmp['poll'] = true;
                }
                $thread_data[] = $tmp;
                break;
            case 'vBForum_Search_Result_Post':
                $post = $item->get_post();
                $thread = $post->get_thread();
                $foruminfo = fetch_foruminfo($thread->get_field('forumid'));
                $parentlist = explode(',', substr($foruminfo['parentlist'], 0, -3));
                $skip = false;
                foreach ($parentlist as $parent_id) {
                    if (in_array($parent_id, $exclude_ids)) {
                        $skip = true;
                    }
                }
                if ($post->get_field('visible') == 2) {
                    $skip = true;
                }
                if ($skip) {
                    $skipped++;
                    continue;
                }
                $date = vbdate($vbulletin->options['dateformat'], $post->get_field('dateline'));
                $time = vbdate($vbulletin->options['timeformat'], $post->get_field('dateline'));
                $avatarurl = '';
                if ($post->get_field('userid') > 0) {
                    $userinfoavatar = fetch_userinfo($post->get_field('userid'), FETCH_USERINFO_AVATAR);
                    fetch_avatar_from_userinfo($userinfoavatar, true, false);
                    if ($userinfoavatar['avatarurl'] != '') {
                        $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                    }
                    unset($userinfoavatar);
                }
                $tmp = array('thread_id' => $post->get_field('threadid'), 'post_id' => $post->get_field('postid'), 'jump_to_post' => 1, 'forum_id' => $thread->get_field('forumid'), 'forum_title' => prepare_utf8_string(strip_tags($foruminfo['title'])), 'thread_title' => prepare_utf8_string(strip_tags($thread->get_field('title'))), 'thread_preview' => prepare_utf8_string(preview_chop(htmlspecialchars_uni(fetch_censored_text(strip_bbcode(strip_quotes(html_entity_decode($post->get_field('pagetext'))), false, true))), FR_PREVIEW_LEN)), 'post_userid' => $post->get_field('userid'), 'post_lastposttime' => prepare_utf8_string(date_trunc($date) . ' ' . $time), 'post_username' => prepare_utf8_string(strip_tags($post->get_field('username'))));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                if ($thread->get_field('prefixid')) {
                    $prefixid = $thread->get_field('prefixid');
                    $tmp['prefix'] = prepare_utf8_string(strip_tags($vbphrase["prefix_{$prefixid}_title_plain"]));
                }
                if ($post->get_field('attach')) {
                    $tmp['attach'] = true;
                }
                $thread_data[] = $tmp;
                break;
        }
    }
    $out = array();
    if (is_array($thread_data) && count($thread_data) > 0) {
        $out['threads'] = $thread_data;
        $out['total_threads'] = max($results->get_confirmed_count() - $skipped, 0);
    } else {
        $out['threads'] = array();
        $out['total_threads'] = 0;
    }
    $out['searchid'] = $searchid;
    return $out;
}
function cache_group_members($groupids = null, $force_rebuild = false)
{
    global $vbulletin;
    static $group_members;
    if ($group_members and !$force_rebuild) {
        return $group_members;
    }
    if (!is_array($groupids) or !$groupids) {
        return null;
    }
    /*
     * Explain to this query:
     * We only need to fetch at most 10 new joined member info for each group.
     * Fetching the members for each group separately is faster than one query with a heavy subquery
     */
    $group_members = array();
    foreach ($groupids as $groupid) {
        $result = $vbulletin->db->query_read_slave("\n\t\t\tSELECT user.*, socialgroupmember.groupid\n\t\t\t" . ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight" : "") . "\n\t\t\tFROM " . TABLE_PREFIX . "socialgroupmember AS socialgroupmember\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (socialgroupmember.userid = user.userid)\n\t\t\t" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "\n\t\t\tWHERE socialgroupmember.groupid = {$groupid}\n\t\t\tORDER BY socialgroupmember.dateline DESC\n\t\t\tLIMIT 10\n\t\t\t\t");
        while ($member = $vbulletin->db->fetch_array($result)) {
            fetch_avatar_from_userinfo($member, true, true);
            $group_members[$member['groupid']][] = $member;
        }
    }
    return $group_members;
}
Example #19
0
function cache_group_members($groupids = null, $force_rebuild = false)
{
	global $vbulletin;
	static $group_members;

	if ($group_members AND !$force_rebuild)
	{
		return $group_members;
	}

	if (!is_array($groupids) OR !$groupids)
	{
		return null;
	}

	/*
	 * Explain to this query:
	 * We only need to fetch at most 10 new joined member info for each group.
	 * So the sub query is a trick to implement that.
	 */
	$result = $vbulletin->db->query_read_slave("
		SELECT user.*, socialgroupmember.groupid
			" . ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight" : "") . "
		FROM " . TABLE_PREFIX . "socialgroupmember AS socialgroupmember
		LEFT JOIN " . TABLE_PREFIX . "user AS user ON (socialgroupmember.userid = user.userid)
		" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "
		WHERE socialgroupmember.groupid IN (" . implode(',', $groupids) . ")
		AND socialgroupmember.type = 'member'
		AND 10 > (
			SELECT COUNT( * )
			FROM " . TABLE_PREFIX . "socialgroupmember AS socialgroupmember2
			WHERE socialgroupmember2.groupid = socialgroupmember.groupid
			AND socialgroupmember2.dateline > socialgroupmember.dateline
			AND socialgroupmember2.type = 'member'
		)
		ORDER BY socialgroupmember.dateline DESC
	");

	$group_members = array();
	while ($member = $vbulletin->db->fetch_array($result))
	{
		fetch_avatar_from_userinfo($member, true, true);
		$group_members[$member['groupid']][] = $member;
	}

	return $group_members;

}
Example #20
0
 }
 $getevents = $db->query_read_slave("\n\t\tSELECT event.*, IF(dateline_to = 0, 1, 0) AS singleday, user.username, user.options, user.adminoptions, user.usergroupid, user.membergroupids, user.infractiongroupids, IF(options & " . $vbulletin->bf_misc_useroptions['hasaccessmask'] . ", 1, 0) AS hasaccessmask,\n\t\t\tsubscribeevent.reminder, subscribeevent.subscribeeventid\n\t\t\t" . ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb, filedata_thumb, NOT ISNULL(customavatar.userid) AS hascustom" : "") . "\n\t\tFROM " . TABLE_PREFIX . "subscribeevent AS subscribeevent\n\t\tLEFT JOIN " . TABLE_PREFIX . "event AS event ON (subscribeevent.eventid = event.eventid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (event.userid = user.userid)\n\t\t" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "\n\t\tWHERE\n\t\t\tsubscribeevent.userid = " . $vbulletin->userinfo['userid'] . "\n\t\t\t\tAND\n\t\t\tevent.visible = 1\n\t\tORDER BY\n\t\t\t{$sqlsortfield} {$sortorder}\n\t\tLIMIT " . ($limitlower - 1) . ", {$perpage}\n\t");
 $itemcount = ($pagenumber - 1) * $perpage;
 $first = $itemcount + 1;
 if ($db->num_rows($getevents)) {
     $show['haveevents'] = true;
     while ($event = $db->fetch_array($getevents)) {
         if (empty($reminders["{$event['reminder']}"])) {
             $event['reminder'] = 3600;
         }
         $event['reminder'] = $vbphrase[$reminders[$event['reminder']]];
         $offset = $event['dst'] ? $vbulletin->userinfo['timezoneoffset'] : $vbulletin->userinfo['tzoffset'];
         $event = array_merge($event, convert_bits_to_array($event['options'], $vbulletin->bf_misc_useroptions));
         $event = array_merge($event, convert_bits_to_array($event['adminoptions'], $vbulletin->bf_misc_adminoptions));
         cache_permissions($event, false);
         fetch_avatar_from_userinfo($event, true);
         $event['dateline_from_user'] = $event['dateline_from'] + $offset * 3600;
         $event['dateline_to_user'] = $event['dateline_to'] + $offset * 3600;
         $event['preview'] = htmlspecialchars_uni(strip_bbcode(fetch_trimmed_title(strip_quotes($event['event']), 300), false, true));
         $event = fetch_event_date_time($event);
         $event['calendar'] = $calendarcache["{$event['calendarid']}"];
         $show['singleday'] = !empty($event['singleday']) ? true : false;
         ($hook = vBulletinHook::fetch_hook('calendar_viewreminder_event')) ? eval($hook) : false;
         $oppositesort = $sortorder == 'asc' ? 'desc' : 'asc';
         $templater = vB_Template::create('calendar_reminder_eventbit');
         $templater->register('date1', $date1);
         $templater->register('date2', $date2);
         $templater->register('daterange', $daterange);
         $templater->register('event', $event);
         $templater->register('eventdate', $eventdate);
         $templater->register('recurcriteria', $recurcriteria);
Example #21
0
function get_article_comments($article, $associated_thread_id, $userinfo, &$pageno, &$perpage, &$total)
{
    require_once DIR . '/includes/functions_misc.php';
    require_once DIR . '/includes/functions.php';
    require_once DIR . '/includes/functions_databuild.php';
    require_once DIR . '/includes/functions_bigthree.php';
    $posts_out = array();
    fetch_phrase_group('posting');
    $threadinfo = verify_id('thread', $associated_thread_id, 0, 1);
    $foruminfo = verify_id('forum', $threadinfo['forumid'], 0, 1);
    //First let's see if we have forum/thread view permissions. If not,
    // we're done
    if (!($permissions = can_view_thread($article->getNodeId(), $userinfo))) {
        return array();
    }
    $forumperms = fetch_permissions($threadinfo['forumid']);
    //Normally this thread will be wide open, so let's get the list first
    // without checking. We'll verify each post anyway.
    //get our results
    $results = get_comments($permissions, $associated_thread_id);
    $record_count = count($results);
    if (!$results or !count($results)) {
        return array();
    }
    //we accept the parameter "last" for pageno.
    if ($pageno == FR_LAST_POST) {
        $pageno = intval(($record_count + $perpage - 1) / $perpage);
        $first = ($pageno - 1) * $perpage;
    } else {
        $pageno = max(1, intval($pageno));
        $first = $perpage * ($pageno - 1);
    }
    //Let's trim off the results we need.
    //This also tells us if we should show the "next" button.
    $post_array = array_slice($results, $first, $perpage, true);
    if (!$post_array) {
        return array();
    }
    $firstpostid = false;
    $displayed_dateline = 0;
    if (vB::$vbulletin->options['threadmarking'] and vB::$vbulletin->userinfo['userid']) {
        $threadview = max($threadinfo['threadread'], $threadinfo['forumread'], TIMENOW - vB::$vbulletin->options['markinglimit'] * 86400);
    } else {
        $threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));
        if (!$threadview) {
            $threadview = vB::$vbulletin->userinfo['lastvisit'];
        }
    }
    require_once DIR . '/includes/functions_user.php';
    $show['inlinemod'] = false;
    $postids = array();
    $postids = ' post.postid in (' . implode(', ', $post_array) . ')';
    $posts = vB::$vbulletin->db->query_read($sql = "\n\tSELECT\n\tpost.*, post.username AS postusername, post.ipaddress AS ip, IF(post.visible = 2, 1, 0) AS isdeleted,\n\t    user.*, userfield.*, usertextfield.*,\n\t    " . iif($forum['allowicons'], 'icon.title as icontitle, icon.iconpath,') . "\n\t    " . iif(vB::$vbulletin->options['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight,') . "\n\t    " . ((can_moderate($thread['forumid'], 'canmoderateposts') or can_moderate($thread['forumid'], 'candeleteposts')) ? 'spamlog.postid AS spamlog_postid,' : '') . "\n\t    " . iif($deljoin, 'deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason,') . "\n\t    editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline,\n\t    editlog.reason AS edit_reason, editlog.hashistory,\n\t    postparsed.pagetext_html, postparsed.hasimages,\n\t    sigparsed.signatureparsed, sigparsed.hasimages AS sighasimages,\n\t    sigpic.userid AS sigpic, sigpic.dateline AS sigpicdateline, sigpic.width AS sigpicwidth, sigpic.height AS sigpicheight,\n\t    IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid,\n\t    customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline, customprofilepic.width AS ppwidth, customprofilepic.height AS ppheight\n\t    " . iif(!($permissions['genericpermissions'] & vB::$vbulletin->bf_ugp_genericpermissions['canseehiddencustomfields']), vB::$vbulletin->profilefield['hidden']) . "\n\t    {$hook_query_fields}\n\t    FROM " . TABLE_PREFIX . "post AS post\n\t    LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid)\n\t    LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON(userfield.userid = user.userid)\n\t    LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)\n\t    " . iif($forum['allowicons'], "LEFT JOIN " . TABLE_PREFIX . "icon AS icon ON(icon.iconid = post.iconid)") . "\n\t    " . iif(vB::$vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "\n\t    " . ((can_moderate($thread['forumid'], 'canmoderateposts') or can_moderate($thread['forumid'], 'candeleteposts')) ? "LEFT JOIN " . TABLE_PREFIX . "spamlog AS spamlog ON(spamlog.postid = post.postid)" : '') . "\n\t    {$deljoin}\n\t    LEFT JOIN " . TABLE_PREFIX . "editlog AS editlog ON(editlog.postid = post.postid)\n\t    LEFT JOIN " . TABLE_PREFIX . "postparsed AS postparsed ON(postparsed.postid = post.postid AND postparsed.styleid = " . intval(STYLEID) . " AND postparsed.languageid = " . intval(LANGUAGEID) . ")\n\t    LEFT JOIN " . TABLE_PREFIX . "sigparsed AS sigparsed ON(sigparsed.userid = user.userid AND sigparsed.styleid = " . intval(STYLEID) . " AND sigparsed.languageid = " . intval(LANGUAGEID) . ")\n\t    LEFT JOIN " . TABLE_PREFIX . "sigpic AS sigpic ON(sigpic.userid = post.userid)\n\t    LEFT JOIN " . TABLE_PREFIX . "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid)\n\t    {$hook_query_joins}\n\t    WHERE {$postids}\n\t    ORDER BY post.dateline\n\t    ");
    if (!($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canseethumbnails']) and !($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['cangetattachment'])) {
        vB::$vbulletin->options['attachthumbs'] = 0;
    }
    if (!($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['cangetattachment'])) {
        vB::$vbulletin->options['viewattachedimages'] = 0;
    }
    $postcount = count($postid_array);
    $counter = 0;
    $postbits = '';
    vB::$vbulletin->noheader = true;
    while ($post = vB::$vbulletin->db->fetch_array($posts)) {
        if (!$privileges['can_moderate_forums']) {
            if ($privileges['is_coventry'] or $post['visible'] == 2) {
                continue;
            }
        }
        // post/thread is deleted by moderator and we don't have permission to see it
        if (!($post['visible'] or $privileges['can_moderate_posts'])) {
            continue;
        }
        if (!intval($post['userid'])) {
            $post['avatarid'] = false;
        } else {
            if (!$post['hascustomavatar']) {
                if ($post['profilepic']) {
                    $post['hascustomavatar'] = 1;
                    $post['avatarid'] = true;
                    $post['avatarpath'] = "./image.php?u=" . $post['userid'] . "&amp;dateline=" . $post['profilepicdateline'] . "&amp;type=profile";
                    $post['avwidth'] = $post['ppwidth'];
                    $post['avheight'] = $post['ppheight'];
                } else {
                    $post['hascustomavatar'] = 1;
                    $post['avatarid'] = true;
                    // explicity setting avatarurl to allow guests comments to show unknown avatar
                    $post['avatarurl'] = $post['avatarpath'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . '/unknown.gif';
                    $post['avwidth'] = 60;
                    $post['avheight'] = 60;
                }
            }
        }
        if ($tachyuser = in_coventry($post['userid']) and !can_moderate($thread['forumid'])) {
            continue;
        }
        if ($post['visible'] == 1 and !$tachyuser) {
            ++$counter;
            if ($postorder) {
                $post['postcount'] = --$postcount;
            } else {
                $post['postcount'] = ++$postcount;
            }
        }
        if ($tachyuser) {
            $fetchtype = 'post_global_ignore';
        } else {
            if ($ignore["{$post['userid']}"]) {
                $fetchtype = 'post_ignore';
            } else {
                if ($post['visible'] == 2) {
                    $fetchtype = 'post_deleted';
                } else {
                    $fetchtype = 'post';
                }
            }
        }
        if (vB::$vbulletin->GPC['viewfull'] and $post['postid'] == $postinfo['postid'] and $fetchtype != 'post' and (can_moderate($threadinfo['forumid']) or !$post['isdeleted'])) {
            $fetchtype = 'post';
        }
        if (!$firstpostid) {
            $firstpostid = $post['postid'];
        }
        $post['islastshown'] = $post['postid'] == $lastpostid;
        $post['isfirstshown'] = ($counter == 1 and $fetchtype == 'post' and $post['visible'] == 1);
        $post['islastshown'] = $post['postid'] == $lastpostid;
        $post['attachments'] = $postattach["{$post['postid']}"];
        $canedit = false;
        if (!$threadinfo['isdeleted'] and !$post['isdeleted'] and (can_moderate($threadinfo['forumid'], 'caneditposts') or $threadinfo['open'] and $post['userid'] == vB::$vbulletin->userinfo['userid'] and $forumperms & vB::$vbulletin->bf_ugp_forumpermissions['caneditpost'] and ($post['dateline'] >= TIMENOW - vB::$vbulletin->options['edittimelimit'] * 60 or vB::$vbulletin->options['edittimelimit'] == 0))) {
            $canedit = true;
        }
        // Get post date/time
        $postdate = vbdate(vB::$vbulletin->options['dateformat'], $post['dateline'], 1);
        $posttime = vbdate(vB::$vbulletin->options['timeformat'], $post['dateline']);
        $attachments = array();
        $fr_images = array();
        // Attachments (images).
        if (count($post['attachments']) > 0) {
            foreach ($post['attachments'] as $attachment) {
                $lfilename = strtolower($attachment['filename']);
                if (strpos($lfilename, '.jpe') !== false || strpos($lfilename, '.png') !== false || strpos($lfilename, '.gif') !== false || strpos($lfilename, '.jpg') !== false || strpos($lfilename, '.jpeg') !== false) {
                    $fr_images[] = array('img' => vB::$vbulletin->options['bburl'] . '/attachment.php?attachmentid=' . $attachment['attachmentid'], 'tmb' => vB::$vbulletin->options['bburl'] . '/attachment.php?attachmentid=' . $attachment['attachmentid'] . '&stc=1&thumb=1');
                }
            }
        }
        // Parse the post for quotes and inline images
        list($text, $nuked_quotes, $images) = parse_post($post['pagetext'], false);
        if (count($fr_images) > 0) {
            $text .= "<br/>";
            foreach ($fr_images as $attachment) {
                $text .= "<img src=\"{$attachment['img']}\"/>";
            }
        }
        foreach ($images as $image) {
            $fr_images[] = array('img' => $image);
        }
        $avatarurl = '';
        // Avatar work
        if (vB::$vbulletin->options['avatarenabled']) {
            require_once DIR . '/includes/functions_user.php';
            $userinfo = fetch_userinfo($post['userid'], FETCH_USERINFO_AVATAR);
            fetch_avatar_from_userinfo($userinfo);
            if ($userinfo['avatarurl']) {
                $avatarurl = process_avatarurl($userinfo['avatarurl']);
            }
        }
        $tmp = array('post_id' => $post['postid'], 'thread_id' => $post['threadid'], 'forum_id' => $foruminfo['forumid'], 'username' => prepare_utf8_string(strip_tags($post['username'])), 'joindate' => prepare_utf8_string($post['joindate']), 'usertitle' => prepare_utf8_string(strip_tags($post['usertitle'])), 'numposts' => $post['posts'], 'userid' => $post['userid'], 'title' => prepare_utf8_string($post['title']), 'post_timestamp' => prepare_utf8_string(date_trunc($postdate) . ' ' . $posttime), 'fr_images' => $fr_images, 'image_thumbs' => array());
        // Soft Deleted
        if ($post['visible'] == 2) {
            $tmp['deleted'] = true;
            $tmp['del_username'] = prepare_utf8_string($post['del_username']);
            if ($post['del_reason']) {
                $tmp['del_reason'] = prepare_utf8_string($post['del_reason']);
            }
        } else {
            $tmp['text'] = $text;
            $tmp['quotable'] = $nuked_quotes;
            if ($canedit) {
                $tmp['canedit'] = true;
                $tmp['edittext'] = prepare_utf8_string($post['pagetext']);
            }
        }
        if ($avatarurl != '') {
            $tmp['avatarurl'] = $avatarurl;
        }
        $posts_out[] = $tmp;
    }
    if ($LASTPOST['dateline'] > $displayed_dateline) {
        $displayed_dateline = $LASTPOST['dateline'];
        if ($displayed_dateline <= $threadview) {
            $updatethreadcookie = true;
        }
    }
    // Set thread last view
    if ($displayed_dateline and $displayed_dateline > $threadview) {
        mark_thread_read($threadinfo, $foruminfo, vB::$vbulletin->userinfo['userid'], $displayed_dateline);
    }
    vB::$vbulletin->db->free_result($posts);
    unset($post);
    $total = $record_count;
    return $posts_out;
}
Example #22
0
     $user['checked'] = ' checked="checked"';
     $friend_list["{$user['userid']}"] = $user['friend'];
     $show['friend_checkbox'] = ($show['friend_controls'] and $user['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends'] and $vbulletin->userinfo['userid'] != $user['userid'] or !empty($friendcheck_checked) and $vbulletin->options['socnet'] & $vbulletin->bf_misc_socnet['enable_friends']);
     eval('$buddylist .= "' . fetch_template('modifybuddylist_user') . '";');
 }
 $buddycount = $db->num_rows($users_result);
 $incomingcount = 0;
 $users_result = $db->query_read_slave("\n\t\tSELECT user.*, userlist.type, userlist.friend\n\t\t" . ($vbulletin->options['avatarenabled'] ? ', avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb, customavatar.width as avwidth, customavatar.height as avheight, customavatar.filedata_thumb' : '') . "\n\t\tFROM " . TABLE_PREFIX . "userlist AS userlist\n\t\tLEFT JOIN " . TABLE_PREFIX . "userlist AS userlist_ignore ON (userlist_ignore.userid = " . $vbulletin->userinfo['userid'] . " AND userlist_ignore.relationid = userlist.userid AND userlist_ignore.type = 'ignore')\n\t\tINNER JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = userlist.userid)\n\t\t" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) " : '') . "\n\t\tWHERE userlist.relationid = " . $vbulletin->userinfo['userid'] . " AND userlist.type = 'buddy' AND userlist.friend = 'pending' AND userlist_ignore.type IS NULL\n\t\tORDER BY user.username\n\t");
 while ($user = $db->fetch_array($users_result)) {
     // User is a friend already, the other side must have a broken relationship. update theirs
     if ($friend_list["{$user['userid']}"] == 'yes') {
         $db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "userlist\n\t\t\t\tSET friend = 'yes'\n\t\t\t\tWHERE relationid = " . $vbulletin->userinfo['userid'] . "\n\t\t\t\t\tAND userid = " . $user['userid'] . "\n\t\t\t\t\tAND type = 'buddy'\n\t\t\t");
         continue;
     }
     $user['extended_type'] = $user['type'] = 'incoming';
     fetch_avatar_from_userinfo($user, true);
     $container = 'incomingreqs';
     $show['incomingrequest'] = true;
     $show['outgoingrequest'] = false;
     $friendcheck_checked = '';
     $show['friend_checkbox'] = false;
     $incomingcount++;
     eval('$incominglist .= "' . fetch_template('modifybuddylist_user') . '";');
 }
 $show['incominglist'] = !empty($incominglist);
 $show['buddylist'] = !empty($buddylist);
 // Adjust the friend req count if it doesn't match what we really have
 if ($_GET['do'] == 'buddylist' and $vbulletin->userinfo['friendreqcount'] != $incomingcount) {
     $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
     $userdata->set_condition("userid = " . $vbulletin->userinfo['userid'] . " AND friendreqcount = " . $vbulletin->userinfo['friendreqcount']);
     $userdata->set('friendreqcount', $incomingcount);
 /**
  * Template method that does all the work to display an issue note, including processing the template
  *
  * @return	string	Templated note output
  */
 function construct()
 {
     // Legacy Hook 'visitor_messagebit_display_start' Removed //
     // preparation for display...
     $this->prepare_start();
     if ($this->message['userid']) {
         $this->process_registered_user();
     } else {
         $this->process_unregistered_user();
     }
     fetch_avatar_from_userinfo($this->message, true);
     $this->process_date_status();
     $this->process_display();
     $this->process_text();
     $this->prepare_end();
     // actual display...
     $userinfo =& $this->userinfo;
     fetch_avatar_from_userinfo($userinfo, true);
     $message =& $this->message;
     global $show, $vbphrase;
     global $spacer_open, $spacer_close;
     global $bgclass, $altbgclass;
     exec_switch_bg();
     $pageinfo_vm_ignored = array('vmid' => $message['vmid'], 'showignored' => 1);
     $pageinfo_vm = array('vmid' => $message['vmid']);
     $messageinfo = array('userid' => $message['profileuserid'], 'username' => $message['profileusername']);
     if (defined('VB_API') && VB_API === true) {
         $message['message'] = strip_tags($message['message']);
     }
     // Legacy Hook 'visitor_messagebit_display_complete' Removed //
     $templater = vB_Template::create($this->template);
     $templater->register('message', $message);
     $templater->register('messageinfo', $messageinfo);
     $templater->register('pageinfo_vm', $pageinfo_vm);
     $templater->register('pageinfo_vm_ignored', $pageinfo_vm_ignored);
     $templater->register('userinfo', $userinfo);
     return $templater->render();
 }