function do_get_forum_data() { global $vbulletin, $db, $show, $vbphrase; $vbulletin->input->clean_array_gpc('r', array('forumids' => TYPE_STR)); if (!$vbulletin->GPC['forumids'] || strlen($vbulletin->GPC['forumids']) == 0) { return array('forums' => array()); } cache_ordered_forums(1, 1); $forumids = split(',', $vbulletin->GPC['forumids']); $forum_data = array(); foreach ($forumids as $forumid) { $foruminfo = fetch_foruminfo($forumid); $type = 'old'; if (is_array($foruminfo) and !empty($foruminfo['link'])) { // see if it is a redirect $type = 'link'; } else { if ($vbulletin->userinfo['lastvisitdate'] == -1) { $type = 'new'; } else { if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) { $userlastvisit = !empty($foruminfo['forumread']) ? $foruminfo['forumread'] : TIMENOW - $vbulletin->options['markinglimit'] * 86400; } else { $forumview = intval(fetch_bbarray_cookie('forum_view', $foruminfo['forumid'])); //use which one produces the highest value, most likely cookie $userlastvisit = $forumview > $vbulletin->userinfo['lastvisit'] ? $forumview : $vbulletin->userinfo['lastvisit']; } if ($foruminfo['lastpost'] and $userlastvisit < $foruminfo['lastpost']) { $type = 'new'; } else { $type = 'old'; } } } // If this forum has a password, check to see if we have // the proper cookie. If so, don't prompt for one $password = false; if ($foruminfo['password']) { $pw_ok = verify_forum_password($foruminfo['forumid'], $foruminfo['password'], false); if (!$pw_ok) { $password = true; } } $out = array('id' => $foruminfo['forumid'], 'new' => $type == 'new' ? true : false, 'name' => prepare_utf8_string(strip_tags($foruminfo['title'])), 'password' => $password); $icon = fr_get_forum_icon($foruminfo['forumid'], $foruminfo == 'new'); if ($icon) { $out['icon'] = $icon; } if ($foruminfo['link'] != '') { $link = fr_fix_url($foruminfo['link']); if (is_int($link)) { $out['id'] = $link; } else { $out['link'] = $link; } $linkicon = fr_get_forum_icon($foruminfo['forumid'], false, true); if ($linkicon) { $out['icon'] = $linkicon; } } if ($foruminfo['description'] != '') { $desc = prepare_utf8_string(strip_tags($foruminfo['description'])); if (strlen($desc) > 0) { $out['desc'] = $desc; } } $forum_data[] = $out; } return array('forums' => $forum_data); }
function fr_construct_forum_bit($parentid, $depth = 0, $subsonly = 0) { global $vbulletin, $vbphrase, $show; global $imodcache, $lastpostarray, $counters, $inforum; // Get exclude IDs $exclude_ids = @explode(',', $vbulletin->options['forumrunner_exclude']); if (in_array('-1', $exclude_ids)) { $exclude_ids = array(); } if (in_array($parentid, $exclude_ids)) { return; } // this function takes the constant MAXFORUMDEPTH as its guide for how // deep to recurse down forum lists. if MAXFORUMDEPTH is not defined, // it will assume a depth of 2. // call fetch_last_post_array() first to get last post info for forums if (!is_array($lastpostarray)) { fetch_last_post_array($parentid); } if (empty($vbulletin->iforumcache["{$parentid}"])) { return; } if (!defined('MAXFORUMDEPTH')) { define('MAXFORUMDEPTH', 2); } $forumbits = ''; $depth++; if ($parentid == -1) { $parent_is_category = false; } else { $parentforum = $vbulletin->forumcache[$parentid]; $parent_is_category = !(bool) ($parentforum['options'] & $vbulletin->bf_misc_forumoptions['cancontainthreads']); } foreach ($vbulletin->iforumcache["{$parentid}"] as $forumid) { if (in_array($forumid, $exclude_ids)) { continue; } // grab the appropriate forum from the $vbulletin->forumcache $forum = $vbulletin->forumcache["{$forumid}"]; //$lastpostforum = $vbulletin->forumcache["$lastpostarray[$forumid]"]; $lastpostforum = empty($lastpostarray[$forumid]) ? array() : $vbulletin->forumcache["{$lastpostarray[$forumid]}"]; if (!$forum['displayorder'] or !($forum['options'] & $vbulletin->bf_misc_forumoptions['active'])) { continue; } $forumperms = $vbulletin->userinfo['forumpermissions']["{$forumid}"]; $lastpostforumperms = empty($lastpostarray[$forumid]) ? 0 : $vbulletin->userinfo['forumpermissions']["{$lastpostarray[$forumid]}"]; if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) and ($vbulletin->forumcache["{$forumid}"]['showprivate'] == 1 or !$vbulletin->forumcache["{$forumid}"]['showprivate'] and !$vbulletin->options['showprivateforums'])) { // no permission to view current forum continue; } if ($subsonly) { $childforumbits = fr_construct_forum_bit($forum['forumid'], 1, $subsonly); } else { if ($depth < MAXFORUMDEPTH) { $childforumbits = fr_construct_forum_bit($forum['forumid'], $depth, $subsonly); } else { $childforumbits = ''; } } // do stuff if we are not doing subscriptions only, or if we ARE doing subscriptions, // and the forum has a subscribedforumid if (!$subsonly or $subsonly and !empty($forum['subscribeforumid'])) { $GLOBALS['forumshown'] = true; // say that we have shown at least one forum if ($forum['options'] & $vbulletin->bf_misc_forumoptions['cancontainthreads']) { // get appropriate suffix for template name $tempext = '_post'; } else { $tempext = '_nopost'; } if (!$vbulletin->options['showforumdescription']) { // blank forum description if set to not show $forum['description'] = ''; } // dates & thread title $lastpostinfo = empty($lastpostarray["{$forumid}"]) ? array() : $vbulletin->forumcache["{$lastpostarray[$forumid]}"]; // compare last post time for this forum with the last post time specified by // the $lastpostarray, and if it's less, use the last post info from the forum // specified by $lastpostarray if (!empty($lastpostinfo) and $vbulletin->forumcache["{$lastpostarray[$forumid]}"]['lastpost'] > 0) { if (!($lastpostforumperms & $vbulletin->bf_ugp_forumpermissions['canview']) or !($lastpostforumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) and $lastpostinfo['lastposter'] != $vbulletin->userinfo['username']) { $forum['lastpostinfo'] = $vbphrase['private']; } else { $lastpostinfo['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $lastpostinfo['lastpost'], 1); $lastpostinfo['lastposttime'] = vbdate($vbulletin->options['timeformat'], $lastpostinfo['lastpost']); $lastpostinfo['trimthread'] = fetch_trimmed_title(fetch_censored_text($lastpostinfo['lastthread'])); if ($lastpostinfo['lastprefixid'] and $vbulletin->options['showprefixlastpost']) { $lastpostinfo['prefix'] = $vbulletin->options['showprefixlastpost'] == 2 ? $vbphrase["prefix_{$lastpostinfo['lastprefixid']}_title_rich"] : htmlspecialchars_uni($vbphrase["prefix_{$lastpostinfo['lastprefixid']}_title_plain"]); } else { $lastpostinfo['prefix'] = ''; } if ($vbulletin->forumcache["{$lastpostforum['forumid']}"]['options'] & $vbulletin->bf_misc_forumoptions['allowicons'] and $icon = fetch_iconinfo($lastpostinfo['lasticonid'])) { $show['icon'] = true; } else { $show['icon'] = false; } $show['lastpostinfo'] = (!$lastpostforum['password'] or verify_forum_password($lastpostforum['forumid'], $lastpostforum['password'], false)); $pageinfo_lastpost = array('p' => $lastpostinfo['lastpostid']); $pageinfo_newpost = array('goto' => 'newpost'); $threadinfo = array('title' => $lastpostinfo['lastthread'], 'threadid' => $lastpostinfo['lastthreadid']); } } else { if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) { $forum['lastpostinfo'] = $vbphrase['private']; } else { $forum['lastpostinfo'] = $vbphrase['never']; } } // do light bulb $forum['statusicon'] = fetch_forum_lightbulb($forumid, $lastpostinfo, $forum); // add lock to lightbulb if necessary // from 3.6.9 & 3.7.0 we now show locks only if a user can not post AT ALL // previously it was just if they could not create new threads if ($vbulletin->options['showlocks'] and !$forum['link'] and (!($forum['options'] & $vbulletin->bf_misc_forumoptions['allowposting']) or !($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew']) and !($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyown']) and !($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyothers']))) { $forum['statusicon'] .= '_lock'; } // get counters from the counters cache ( prepared by fetch_last_post_array() ) $forum['threadcount'] = $counters["{$forum['forumid']}"]['threadcount']; $forum['replycount'] = $counters["{$forum['forumid']}"]['replycount']; // get moderators ( this is why we needed cache_moderators() ) if ($vbulletin->options['showmoderatorcolumn']) { $showmods = array(); $listexploded = explode(',', $forum['parentlist']); foreach ($listexploded as $parentforumid) { if (!isset($imodcache["{$parentforumid}"]) or $parentforumid == -1) { continue; } foreach ($imodcache["{$parentforumid}"] as $moderator) { if (isset($showmods["{$moderator['userid']}"])) { continue; } ($hook = vBulletinHook::fetch_hook('forumbit_moderator')) ? eval($hook) : false; $showmods["{$moderator['userid']}"] = true; if (!isset($forum['moderators'])) { $forum['moderators'] = ''; } } } if (!isset($forum['moderators'])) { $forum['moderators'] = ''; } } if ($forum['link']) { $forum['replycount'] = '-'; $forum['threadcount'] = '-'; $forum['lastpostinfo'] = '-'; } else { $forum['replycount'] = vb_number_format($forum['replycount']); $forum['threadcount'] = vb_number_format($forum['threadcount']); } if (($subsonly or $depth == MAXFORUMDEPTH) and $vbulletin->options['subforumdepth'] > 0) { //$forum['subforums'] = construct_subforum_bit($forumid, ($forum['options'] & $vbulletin->bf_misc_forumoptions['cancontainthreads'] ) ); $forum['subforums'] = ''; } else { $forum['subforums'] = ''; } $forum['browsers'] = 0; $children = explode(',', $forum['childlist']); foreach ($children as $childid) { $forum['browsers'] += isset($inforum["{$childid}"]) ? $inforum["{$childid}"] : 0; } if ($depth == 1 and $tempext == '_nopost') { global $vbcollapse; $collapseobj_forumid =& $vbcollapse["collapseobj_forumbit_{$forumid}"]; $collapseimg_forumid =& $vbcollapse["collapseimg_forumbit_{$forumid}"]; $show['collapsebutton'] = true; } else { $show['collapsebutton'] = false; } $show['forumsubscription'] = $subsonly ? true : false; $show['forumdescription'] = $forum['description'] != '' ? true : false; $show['subforums'] = $forum['subforums'] != '' ? true : false; $show['browsers'] = ($vbulletin->options['displayloggedin'] and !$forum['link'] and $forum['browsers'] ? true : false); // FRNR Start // If this forum has a password, check to see if we have // the proper cookie. If so, don't prompt for one $password = 0; if ($forum['password']) { $pw_ok = verify_forum_password($forum['forumid'], $forum['password'], false); if (!$pw_ok) { $password = 1; } } $new = array('id' => $forum['forumid'], 'new' => $forum['statusicon'] == 'new' ? true : false, 'name' => prepare_utf8_string(strip_tags($forum['title'])), 'password' => $password); $icon = fr_get_forum_icon($forum['forumid'], $forum['statusicon'] == 'new' ? true : false); if ($icon) { $new['icon'] = $icon; } if ($forum['link'] != '') { $link = fr_fix_url($forum['link']); if (is_int($link)) { $new['id'] = $link; } else { $new['link'] = $link; } $linkicon = fr_get_forum_icon($forum['forumid'], false, true); if ($linkicon) { $new['icon'] = $linkicon; } } if ($forum['description'] != '') { $desc = prepare_utf8_string(strip_tags($forum['description'])); if (strlen($desc) > 0) { $new['desc'] = $desc; } } $out[] = $new; // FRNR End } else { $forumbits .= $childforumbits; } } return $out; }
function do_get_photos() { global $vbulletin, $db, $show, $vbphrase, $foruminfo, $userinfo, $albuminfo, $session, $contenttypeid; if (empty($albuminfo)) { standard_error(fetch_error('invalidid', $vbphrase['album'], $vbulletin->options['contactuslink'])); } if ($vbulletin->GPC['addgroup'] and $albuminfo['userid'] != $vbulletin->userinfo['userid']) { print_no_permission(); } ($hook = vBulletinHook::fetch_hook('album_album')) ? eval($hook) : false; $perpage = 999999; $vbulletin->GPC['pagenumber'] = 1; $input_pagenumber = $vbulletin->GPC['pagenumber']; if (can_moderate(0, 'canmoderatepictures') or $albuminfo['userid'] == $vbulletin->userinfo['userid']) { $totalpictures = $albuminfo['visible'] + $albuminfo['moderation']; } else { $totalpictures = $albuminfo['visible']; } $total_pages = max(ceil($totalpictures / $perpage), 1); // 0 pictures still needs an empty page $pagenumber = $vbulletin->GPC['pagenumber'] > $total_pages ? $total_pages : $vbulletin->GPC['pagenumber']; $start = ($pagenumber - 1) * $perpage; $hook_query_fields = $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook('album_album_query')) ? eval($hook) : false; $pictures = $db->query_read("\n SELECT\n a.attachmentid, a.userid, a.caption, a.dateline, a.state,\n fd.filesize, IF(fd.thumbnail_filesize > 0, 1, 0) AS hasthumbnail, fd.thumbnail_dateline, fd.thumbnail_width, fd.thumbnail_height\n {$hook_query_fields}\n FROM " . TABLE_PREFIX . "attachment AS a\n INNER JOIN " . TABLE_PREFIX . "filedata AS fd ON (fd.filedataid = a.filedataid)\n {$hook_query_joins}\n WHERE\n a.contentid = {$albuminfo['albumid']}\n AND\n a.contenttypeid = " . intval($contenttypeid) . "\n " . ((!can_moderate(0, 'canmoderatepictures') and $albuminfo['userid'] != $vbulletin->userinfo['userid']) ? "AND a.state = 'visible'" : "") . "\n {$hook_query_where}\n ORDER BY a.dateline DESC\n LIMIT {$start}, {$perpage}\n "); // work out the effective picturebit height/width including any borders and paddings; the +4 works around an IE float issue $picturebit_height = $vbulletin->options['album_thumbsize'] + (($usercss ? 0 : $stylevar['cellspacing']) + $stylevar['cellpadding']) * 2 + 4; $picturebit_width = $vbulletin->options['album_thumbsize'] + (($usercss ? 0 : $stylevar['cellspacing']) + $stylevar['cellpadding']) * 2; $out_photos = array(); $picnum = 0; while ($picture = $db->fetch_array($pictures)) { $picture = prepare_pictureinfo_thumb($picture, $albuminfo); if ($picnum % $vbulletin->options['album_pictures_perpage'] == 0) { $show['page_anchor'] = true; $page_anchor = $picnum / $vbulletin->options['album_pictures_perpage'] + 1; } else { $show['page_anchor'] = false; } $picnum++; if ($picture['state'] != 'visible') { continue; } ($hook = vBulletinHook::fetch_hook('album_album_picturebit')) ? eval($hook) : false; $photo_url = "attachment.php?{$session[sessionurl]}attachmentid={$picture['attachmentid']}"; $out_photos[] = array('photoid' => $picture['attachmentid'], 'userid' => $picture['userid'], 'caption' => prepare_utf8_string(strip_tags(fetch_censored_text($picture['caption']))), 'photo_date' => prepare_utf8_string($picture['date'] . ' ' . $picture['time']), 'photo_url' => fr_fix_url($photo_url), 'thumb_url' => fr_fix_url($photo_url . '&thumb=1')); } $show['add_picture_option'] = ($userinfo['userid'] == $vbulletin->userinfo['userid'] and fetch_count_overage($userinfo['userid'], $albuminfo[albumid], $vbulletin->userinfo['permissions']['albummaxpics']) <= 0 and (!$vbulletin->options['album_maxpicsperalbum'] or $totalpictures - $vbulletin->options['album_maxpicsperalbum'] < 0)); if ($albuminfo['state'] == 'private') { $show['personalalbum'] = true; $albumtype = $vbphrase['private_album_paren']; } else { if ($albuminfo['state'] == 'profile') { $show['personalalbum'] = true; $albumtype = $vbphrase['profile_album_paren']; } } $out = array('photos' => $out_photos, 'total_photos' => $totalpictures, 'can_add_photo' => $show['add_picture_option'] ? true : false); return $out; }
public function actionGetForums() { $forumid = $this->_input->filterSingle('forumid', XenForo_Input::UINT); $page = max($this->_input->filterSingle('page', XenForo_Input::UINT), 1); $perpage = $this->_input->filterSingle('perpage', XenForo_Input::UINT); if (!$perpage) { $perpage = XenForo_Application::get('options')->discussionsPerPage; } $previewtype = $this->_input->filterSingle('previewtype', XenForo_Input::UINT); if (!$previewtype) { $previewtype = 2; } // Check for Thread Prefixes (XenForo 1.1.x+) $prefixes = array(); if (method_exists($this, '_getPrefixModel')) { $prefix_groups = $this->_getPrefixModel()->getUsablePrefixesInForums($forumid); foreach ($prefix_groups as $group) { foreach ($group['prefixes'] as $prefix_data) { $phrase = new XenForo_Phrase('thread_prefix_' . $prefix_data['prefix_id']); $prefixes[$prefix_data['prefix_id']] = $phrase->render(); } } } $this->_prefixes = $prefixes; $visitor = XenForo_Visitor::getInstance(); $node_data = $this->_getNodeModel()->getNodeDataForListDisplay(false, 0); $is_category = false; $out = false; foreach ($node_data['nodesGrouped'] as $node_id => $node) { foreach ($node as $subforum_id => $subforum) { if ($subforum_id == $forumid) { if ($subforum['node_type_id'] == 'Category') { $is_category = true; } $out = true; break; } } if ($out) { break; } } $exclude = XenForo_Application::get('options')->forumrunnerExcludeForums; if (!$exclude) { $exclude = array(); } $forum_data = array(); if (isset($node_data['nodesGrouped'][$forumid])) { foreach ($node_data['nodesGrouped'][$forumid] as $forum_info) { if (in_array($forum_info['node_id'], $exclude)) { continue; } $out = array('id' => $forum_info['node_id'], 'new' => $forum_info['hasNew'], 'name' => prepare_utf8_string(strip_tags($forum_info['title']))); $icon = fr_get_forum_icon($forum_info['node_id'], $forum_info['hasNew']); if ($icon) { $out['icon'] = $icon; } if ($forum_info['node_type_id'] == 'LinkForum') { $link_forum_model = $this->getModelFromCache('XenForo_Model_LinkForum'); $link_data = $link_forum_model->getLinkForumById($forum_info['node_id']); $link = fr_fix_url($link_data['link_url']); if (is_int($link)) { $out['id'] = $link; } else { $out['link'] = $link; } $linkicon = fr_get_forum_icon($forum_info['node_id'], false, true); if ($linkicon) { $out['icon'] = $linkicon; } } else { if ($forum_info['node_type_id'] == 'Page') { $page_model = $this->getModelFromCache('XenForo_Model_Page'); $page_data = $page_model->getPageById($forum_info['node_id']); $link = fr_fix_url(XenForo_Link::buildPublicLink('pages', $page_data)); $out['link'] = $link; $linkicon = fr_get_forum_icon($forum_info['node_id'], false, true); if ($linkicon) { $out['icon'] = $linkicon; } } } if ($forum_info['description'] != '') { $desc = prepare_utf8_string(strip_tags($forum_info['description'])); if (strlen($desc)) { $out['desc'] = $desc; } } $forum_data[] = $out; /* * RKJ XXX * * Still TODO: Password FOrum? * Link Forums */ } } $thread_data = $sticky_thread_data = array(); $total_threads = 0; $canpost = $canattach = false; if ($forumid && !$is_category) { $helper = $this->getHelper('ForumThreadPost'); $forum_model = $this->_getForumModel(); $forum_info = null; try { $forum_info = $helper->assertForumValidAndViewable($forumid, array('readUserId' => $visitor['user_id'])); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } if ($forum_info) { $canpost = $forum_model->canPostThreadInForum($forum_info); $canattach = $forum_model->canUploadAndManageAttachment($forum_info); $thread_model = $this->_getThreadModel(); $thread_conditions = array_merge($thread_model->getPermissionBasedThreadFetchConditions($forum_info), array('sticky' => 0)); $thread_options = array('perPage' => $perpage, 'page' => $page, 'join' => XenForo_Model_Thread::FETCH_USER, 'readUserId' => $visitor['user_id'], 'postCountUserId' => $visitor['user_id'], 'order' => 'last_post_date', 'orderDirection' => 'desc'); if (!empty($thread_conditions['deleted'])) { $thread_options['join'] |= XenForo_Model_Thread::FETCH_DELETION_LOG; } $total_threads = $thread_model->countThreadsInForum($forumid, $thread_conditions); $this->canonicalizePageNumber($page, $perpage, $total_threads, 'forums', $forum_info); $threads = $thread_model->getThreadsInForum($forumid, $thread_conditions, $thread_options); // Remove sticky threads from the first page $sticky_threads = array(); if ($page == 1) { $sticky_threads = $thread_model->getStickyThreadsInForum($forumid, $thread_conditions, $thread_options); foreach (array_keys($sticky_threads) as $sticky_threadid) { unset($threads[$sticky_threadid]); } } $perms = $visitor->getNodePermissions($forumid); foreach ($threads as &$thread) { $thread = $thread_model->prepareThread($thread, $forum_info, $perms); } foreach ($sticky_threads as &$thread) { $thread = $thread_model->prepareThread($thread, $forum_info, $perms); } unset($thread); if ($visitor['user_id'] && $page == 1 && $forum_info['forum_read_date'] < $forum_info['last_post_date']) { $hasNew = false; foreach ($threads as $thread) { if ($thread['isNew']) { $hasNew = true; break; } } if (!$hasNew) { $this->_getForumModel()->markForumReadIfNeeded($forum_info, $visitor['user_id']); } } $thread_data = $this->processThreads($threads, $previewtype); $sticky_thread_data = $this->processThreads($sticky_threads, $previewtype); } } $out = array('forums' => $forum_data, 'threads' => $thread_data, 'total_threads' => $total_threads, 'threads_sticky' => $sticky_thread_data, 'total_sticky_threads' => count($sticky_thread_data), 'canpost' => $canpost, 'canattach' => $canattach); // Output Prefixes (XenForo 1.1.x+) if (count($this->_prefixes)) { $out_prefixes = array(); foreach ($this->_prefixes as $id => $prefix) { $out_prefixes[] = array('prefixid' => $id, 'prefixcaption' => prepare_utf8_string($prefix)); } $out += array('prefixes' => $out_prefixes, 'prefixrequired' => false); } return $out; }