/** * * This gets the information needed for a user's profile. Only public information unless this is an admin or the user. */ public function fetchProfileInfo($userid = false) { $options = vB::getDatastore()->getValue('options'); $currentUserid = vB::getCurrentSession()->get('userid'); if (empty($userid)) { $userid = $currentUserid; } else { $userid = intval($userid); } if ($userid < 1) { throw new vB_Exception_Api('invalid_data_w_x_y_z', array($userid, 'userid', __CLASS__, __FUNCTION__)); } $hashKey = 'vBProfileUser_' . $userid; $fastCache = vB_Cache::instance(vB_Cache::CACHE_FAST); $userInfo = $fastCache->read($hashKey); if (empty($userInfo)) { $userInfo = vB_User::fetchUserinfo($userid, array(vB_Api_User::USERINFO_AVATAR, vB_Api_User::USERINFO_PROFILEPIC, vB_Api_User::USERINFO_ADMIN, vB_Api_User::USERINFO_SIGNPIC)); // Some things even admins shouldn't see foreach (array('token', 'scheme', 'secret', 'coppauser', 'securitytoken_raw', 'securitytoken', 'logouthash', 'fbaccesstoken') as $field) { unset($userInfo[$field]); } try { $this->checkHasAdminPermission('canadminusers'); // If this doesn't throw an exception, the other data is visible to an admin. } catch (Exception $e) { if (vB::getCurrentSession()->get('userid') != $userid) { foreach (array('passworddate', 'parentemail', 'logintype', 'ipaddress', 'passworddate', 'email', 'referrerid', 'ipoints', 'infractions', 'warnings', 'infractiongroupids', 'infractiongroupid') as $field) { $userInfo[$field] = ''; } } } /** * * Fields for the user's profile pages */ $assertor = vB::getDbAssertor(); //see if we have a cached userfield $fields = vB_Cache::instance(vB_Cache::CACHE_FAST)->read("userFields_{$userid}"); if ($fields == false) { $fields = $assertor->getRow('vBForum:userfield', array('userid' => $userid)); vB_Cache::instance(vB_Cache::CACHE_FAST)->write("userFields_{$userid}", $fields, 1440, "userData_{$userid}"); } $customFields = array(); if (!empty($fields)) { // Show hidden fields only if the user views his own profile or if it has the permission to see them $hidden = array(0); $showHidden = ($currentUserid == $userid or vB_Api::instanceInternal('user')->hasPermissions('genericpermissions', 'canseehiddencustomfields')); $fieldsInfo = vB::getDatastore()->getValue('profilefield'); if (is_array($fieldsInfo) and array_key_exists('all', $fieldsInfo)) { $fieldsInfo = $fieldsInfo['all']; } else { $fieldsInfo = array(); } foreach ($fieldsInfo as $customField) { if ($customField['hidden'] == 0 or $showHidden) { $catNameString = $customField['profilefieldcategoryid'] ? 'category' . $customField['profilefieldcategoryid'] . '_title' : 'default'; $fieldNameString = 'field' . $customField['profilefieldid'] . '_title'; $customFields[$catNameString][$fieldNameString] = array('val' => $this->getCustomFieldValue($customField, $fields), 'hidden' => $customField['hidden']); } } } $userInfo['customFields'] = $customFields; /** * Check whether user has permission to use friends list (follow users) */ $userInfo['canusefriends'] = vB::getUserContext($userid)->hasPermission('genericpermissions2', 'canusefriends'); $userInfo['canviewmembers'] = vB::getUserContext($userid)->hasPermission('genericpermissions', 'canviewmembers'); /** * * User counts */ $followApi = vB_Api::instanceInternal('follow'); if ($currentUserid == $userid or $userInfo['canusefriends']) { $follows = $followApi->getFollowing($userid); $userInfo['followsCount'] = $follows['paginationInfo']['totalcount']; } $followers = $followApi->getFollowers($userid); $userInfo['followersCount'] = $followers['paginationInfo']['totalcount']; $userInfo['socialGroupsCount'] = 10; if (isset($this->referrals[$userid])) { $referrals = $this->referrals[$userid]; } else { $referrals = $assertor->getRow('vBForum:getReferralsCount', array('userid' => $userid)); $this->referrals[$userid] = $referrals; } $userInfo['birthdayTimestamp'] = 0; $userInfo['referralsCount'] = $referrals['referrals']; if ($userInfo['birthday_search']) { list($year, $month, $day) = explode("-", $userInfo['birthday_search']); $userInfo['birthdayTimestamp'] = mktime(0, 0, 0, $month, $day, $year); $userInfo['age'] = date("md") < $month . $day ? date("Y") - $year - 1 : date("Y") - $year; } /** * Get vms info */ $vms = $assertor->getRows('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'setfor' => $userid), array('field' => 'publishdate', 'direction' => vB_dB_Query::SORT_DESC)); vB_Library_Content::writeToCache($vms, vB_Library_Content::CACHELEVEL_NODE); $userInfo['vmCount'] = count($vms); $userInfo['vmMostRecent'] = $userInfo['vmCount'] ? $vms[0]['publishdate'] : 0; /** * Let's get posts per day */ $timeIn = (vB::getRequest()->getTimeNow() - $userInfo['joindate']) / (24 * 60 * 60); if ($timeIn >= 1 and $userInfo['posts'] > 0) { $userInfo['postPerDay'] = vb_number_format($userInfo['posts'] / $timeIn, 2); } else { $userInfo['postPerDay'] = $userInfo['posts']; } $fastCache->write($hashKey, $userInfo, 1440, 'userChg_' . $userid); } // add current user flags // if user is the profile owner.. $userInfo['showAvatar'] = 1; if ($currentUserid == $userid) { if (vB::getUserContext()->hasPermission('genericpermissions', 'canuseavatar')) { $userInfo['canuseavatar'] = 1; $userInfo['avatarmaxwidth'] = vB::getUserContext()->getLimit('avatarmaxwidth'); $userInfo['avatarmaxheight'] = vB::getUserContext()->getLimit('avatarmaxheight'); $userInfo['avatarmaxsize'] = vB::getUserContext()->getLimit('avatarmaxsize') / 1024; } else { $userInfo['canuseavatar'] = 0; } //Are there any default avatars this user could assign? $avatars = vB_Api::instanceInternal('profile')->getDefaultAvatars(); $userInfo['defaultAvatarCount'] = count($avatars); if ($userInfo['defaultAvatarCount'] or $userInfo['canuseavatar'] > 0) { $userInfo['showAvatarOptions'] = 1; } else { $userInfo['showAvatarOptions'] = 0; } if ($userInfo['profilepic']) { if ($options['usefileavatar']) { $userInfo['profilepicturepath'] = $options['bburl'] . '/' . $options['profilepicurl'] . "/profilepic{$currentUserid}" . '_' . $userInfo['profilepicrevision'] . '.gif'; } else { $userInfo['profilepicturepath'] = $options['bburl'] . "/image.php?u={$currentUserid}&type=profile&dateline=" . $userInfo['profilepicdateline']; } } } else { $userInfo['canuseavatar'] = $userInfo['showAvatarOptions'] = 0; //Check the privacy settings and see if this user has hidden his if ($userInfo['privacy_options'] and vB::getUserContext($userid)->hasPermission('usercsspermissions', 'caneditprivacy')) { switch ($userInfo['privacy_options']['profile_picture']) { case 1: //visible only if the current user is a subscriber. if ($currentUserid == 0 or vB_Api::instanceInternal('follow')->isFollowingUser($userid) != vB_Api_Follow::FOLLOWING_YES) { $userInfo['showAvatar'] = 0; } break; case 2: //visible only if the current user is a registered user. if ($currentUserid == 0) { $userInfo['showAvatar'] = 0; } break; } // switch } $userInfo['profilepicturepath'] = ''; } $this->setCurrentUserFlags($userInfo); // Add online status require_once DIR . '/includes/functions_bigthree.php'; fetch_online_status($userInfo); return $userInfo; }
/** returns the category list- direct children of the social group channel * * @return mixed array of nodeid => title */ public function getCategories() { $cache = vB_Cache::instance(vB_Cache::CACHE_FAST); $categories = $cache->read('vbSGChannels'); if (!empty($categories)) { return $categories; } $sgChannel = $this->getSGChannel(); $categories = vB::getDbAssertor()->getRows('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'parentid' => $sgChannel, 'contenttypeid' => vB_Types::instance()->getContentTypeID('vBForum_Channel')), 'title', 'nodeid'); $return = array(); $userContext = vB::getUserContext(); $events = array(); vB_Library::instance('node')->fetchClosureParent(array_keys($categories)); foreach ($categories as $category) { if ($userContext->getChannelPermission('forumpermissions', 'canview', $category['nodeid'], false, $sgChannel)) { $return[$category['nodeid']] = array('title' => $category['title'], 'htmltitle' => $category['htmltitle'], 'routeid' => $category['routeid'], 'content' => $category['content']); $events[] = 'routeChg_' . $category['routeid']; $events[] = 'nodeChg_' . $category['content']; } vB_Library_Content::writeToCache(array($category), vB_Library_Content::CACHELEVEL_NODE); } $cache->write('vbSGChannels', $return, 1440, $events); return $return; }
/** Gets the node info for a list of nodes * @param array of node ids * @param bool Include joinable content * * @return mixed array of node records **/ public function getNodes($nodeList, $withJoinableContent = false) { static $cachedNodeList = array(); if (empty($nodeList)) { return array(); } if (!is_array($nodeList)) { $nodeList = array($nodeList); } //if we are passed options we can't precache. $cachedNodeList = array_unique(array_merge($cachedNodeList, $nodeList)); vB_Api::instanceInternal('page')->registerPrecacheInfo('node', 'getNodes', $cachedNodeList); $cached = vB_Library_Content::fetchFromCache($nodeList, vB_Library_Content::CACHELEVEL_NODE); if (empty($cached['notfound'])) { //We found everything, so we're done. return $cached['found']; } if ($withJoinableContent) { $indexed = vB::getDbAssertor()->getRows('vBForum:fetchNodeWithContent', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'nodeid' => $cached['notfound']), false, 'nodeid'); } else { $indexed = vB::getDbAssertor()->getRows('vBForum:node', array('nodeid' => $cached['notfound']), false, 'nodeid'); } vB_Library_Content::writeToCache($indexed, vB_Library_Content::CACHELEVEL_NODE); //now we need to merge and sort them. $merged = array(); foreach ($nodeList as $nodeid) { if (array_key_exists($nodeid, $cached['found'])) { $merged[$nodeid] = $cached['found'][$nodeid]; } else { if (array_key_exists($nodeid, $indexed)) { $merged[$nodeid] = $indexed[$nodeid]; } } } unset($cached, $indexed); return $merged; }
protected function isFlood($data) { $isFlood = false; $node = vB::getDbAssertor()->getRow('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'userid', 'value' => $data['userid'], 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'created', 'value' => vB::getRequest()->getTimeNow() - $this->options['floodchecktime'], 'operator' => vB_dB_Query::OPERATOR_GT), array('field' => 'contenttypeid', 'value' => $this->contenttypeid, 'operator' => vB_dB_Query::OPERATOR_EQ))), array('field' => array('created'), 'direction' => array(vB_dB_Query::SORT_DESC))); if (!empty($node)) { $lastPostElapsed = vB::getRequest()->getTimeNow() - $node['created']; if ($lastPostElapsed < $this->options['floodchecktime']) { $isFlood = true; } vB_Library_Content::writeToCache(array($node), vB_Library_Content::CACHELEVEL_NODE); } if ($isFlood) { return $lastPostElapsed; } return false; }