Esempio n. 1
0
     unset($search['order']);
 }
 $sorturl = urlimplode($search);
 // build pagenav
 $pagenav = construct_page_nav($pagenumber, $perpage, $totalmessages, 'private.php?' . $vbulletin->session->vars['sessionurl'] . 'folderid=' . $vbulletin->GPC['folderid'] . '&pp=' . $vbulletin->GPC['perpage'] . '&' . $sorturl);
 $sortfield = $search['sort'];
 unset($search['sort']);
 $sorturl = 'private.php?' . $vbulletin->session->vars['sessionurl'] . 'folderid=' . $vbulletin->GPC['folderid'] . ($searchurl = urlimplode($search) ? '&' . $searchurl : '');
 $oppositesort = $desc ? 'asc' : 'desc';
 $orderlinks = array('date' => $sorturl . '&sort=date' . ($sortfield == 'date' ? '&order=' . $oppositesort : ''), 'title' => $sorturl . '&sort=title' . ($sortfield == 'title' ? '&order=' . $oppositesort : '&order=asc'), 'sender' => $sorturl . '&sort=sender' . ($sortfield == 'sender' ? '&order=' . $oppositesort : '&order=asc'));
 $templater = vB_Template::create('forumdisplay_sortarrow');
 $templater->register('oppositesort', $oppositesort);
 $sortarrow["{$sortfield}"] = $templater->render();
 // 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"';
 $templater = vB_Template::create('pm_filter');
 $templater->register('enddate', $enddate);
 $templater->register('endmonth', $endmonth);
 $templater->register('order', $order);
 $templater->register('pagenumber', $pagenumber);
 $templater->register('perpage', $perpage);
 $templater->register('readselection', $readselection);
 $templater->register('search', $search);
 $templater->register('sortfield', $sortfield);
 $templater->register('startdate', $startdate);
 $templater->register('startmonth', $startmonth);
 $sortfilter = $templater->render();
Esempio n. 2
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);
}