public function actionCheckInOutAsUser() { $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT); $username = $this->_input->filterSingle('username', XenForo_Input::STRING); if ($userId && !($user = $this->_getUserModel()->getUserById($userId))) { return $this->responseError(new XenForo_Phrase('requested_user_not_found')); } elseif ($username && !($user = $this->_getUserModel()->getUserByName($username))) { return $this->responseError(new XenForo_Phrase('requested_user_not_found')); } if (!$this->_getUserModel()->canChangeCheckInOutUser()) { return $this->responseNoPermission(); } if ($this->isConfirmedPost()) { if (!empty($user)) { $this->_getUserModel()->setCheckInOutUser($user['user_id']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect()); } return $this->responseError(new XenForo_Phrase('requested_user_not_found')); } $visitor = XenForo_Visitor::getUserId(); $username = ''; if ($visitor['check_in_out_user_id_th'] && !$userId) { $username = $visitor['username']; } elseif (!empty($user)) { $username = $user['username']; } $viewParams = array('username' => $username); return $this->responseView('ThemeHouse_ResCheckInOut_ViewPublic_CheckInOutAsUser', 'th_check_in_out_as_user_rescheckinout', $viewParams); }
/** * Single-stage logout procedure */ public function actionIndex() { $csrfToken = $this->_input->filterSingle('_xfToken', XenForo_Input::STRING); $redirectResponse = $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(false, false)); $userId = XenForo_Visitor::getUserId(); if (!$userId) { return $redirectResponse; } if ($this->_noRedirect() || !$csrfToken) { // request is likely from JSON, probably XenForo.OverlayTrigger, so show a confirmation dialog return $this->responseView('XenForo_ViewPublic_LogOut', 'log_out'); } else { $this->_checkCsrfFromToken($csrfToken); // remove an admin session if we're logged in as the same person if (XenForo_Visitor::getInstance()->get('is_admin')) { $class = XenForo_Application::resolveDynamicClass('XenForo_Session'); $adminSession = new $class(array('admin' => true)); $adminSession->start(); if ($adminSession->get('user_id') == $userId) { $adminSession->delete(); } } $this->getModelFromCache('XenForo_Model_Session')->processLastActivityUpdateForLogOut(XenForo_Visitor::getUserId()); XenForo_Application::get('session')->delete(); XenForo_Helper_Cookie::deleteAllCookies($this->_getRetainedCookies(), array('user' => array('httpOnly' => false))); XenForo_Visitor::setup(0); return $redirectResponse; } }
public function actionView() { $cameraPortion = $this->_input->filterSingle('camera_url', XenForo_Input::STRING); $cameraPortion = sonnb_XenGallery_Model_Gallery::getTitleForUrl($cameraPortion); if (!$cameraPortion) { return $this->responseReroute(__CLASS__, 'index'); } $cameraModel = $this->_getCameraModel(); $photoModel = $this->_getPhotoModel(); $xenOptions = XenForo_Application::getOptions(); $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT)); $photosPerPage = $xenOptions->sonnbXG_photoPerPage; list($defaultOrder, $defaultOrderDirection) = $this->_getDefaultPhotoSort(); $order = $this->_input->filterSingle('order', XenForo_Input::STRING, array('default' => $defaultOrder)); $orderDirection = $this->_input->filterSingle('direction', XenForo_Input::STRING, array('default' => $defaultOrderDirection)); $conditions = array('camera_url' => $cameraPortion); $fetchOptions = array('join' => sonnb_XenGallery_Model_Camera::FETCH_CAMERA, 'perPage' => $photosPerPage, 'page' => $page, 'order' => 'camera_id', 'orderDirection' => 'desc'); $cameras = $cameraModel->getCameras($conditions, $fetchOptions); $camera = reset($cameras); if ($camera) { $camera = $cameraModel->prepareCamera($camera); } $photoFetchOptions = array('join' => sonnb_XenGallery_Model_Photo::FETCH_USER | sonnb_XenGallery_Model_Photo::FETCH_DATA | sonnb_XenGallery_Model_Photo::FETCH_ALBUM, 'likeUserId' => XenForo_Visitor::getUserId(), 'followingUserId' => XenForo_Visitor::getUserId()); $photos = $cameraModel->getPhotosByCameras($cameras, $photoFetchOptions); $totalPhotos = $cameraModel->countCameras($conditions, $fetchOptions); foreach ($photos as $_photoId => $_photo) { if (!$photoModel->canViewContentAndContainer($_photo, $_photo['album'], $errorKey)) { unset($photos[$_photoId]); } } $pageNavParams = array(); $pageNavParams['order'] = $order != $defaultOrder ? $order : false; $pageNavParams['direction'] = $orderDirection != $defaultOrderDirection ? $orderDirection : false; return $this->responseView('sonnb_XenGallery_ViewPublic_Camera_View', 'sonnb_xengallery_camera_view', array('camera' => $camera, 'contents' => $photos, 'page' => $page, 'photosPerPage' => $photosPerPage, 'order' => $order, 'orderDirection' => $orderDirection, 'pageNavParams' => $pageNavParams, 'totalPhotos' => $totalPhotos, 'breadCrumbs' => $cameraModel->getCameraBreadCrumbs($camera))); }
public function prepareThreadFetchOptions(array $fetchOptions) { $fetchOptions = array_merge($fetchOptions, array(self::FETCH_TEAM_DISCUSSION => 1, self::FETCH_TEAM_BLOCK_USERID => XenForo_Visitor::getUserId())); $result = parent::prepareThreadFetchOptions($fetchOptions); extract($result); if (!empty($fetchOptions[self::FETCH_TEAM_DISCUSSION])) { $selectFields .= ',team.custom_url, team.team_state, team.user_id as team_user_id, team_privacy.privacy_state'; $joinTables .= ' LEFT JOIN xf_team AS team ON (team.team_id = thread.team_id AND thread.discussion_type = \'team\') LEFT JOIN xf_team_privacy AS team_privacy ON (team_privacy.team_id = team.team_id) '; } if (isset($fetchOptions[self::FETCH_TEAM_BLOCK_USERID])) { if (empty($fetchOptions[self::FETCH_TEAM_BLOCK_USERID])) { $selectFields .= ',team_block.end_date AS block_end_date, team_block.user_reason as block_user_reason'; $joinTables .= ' LEFT JOIN xf_team_ban AS team_block ON ( team_block.team_id = thread.team_id AND team_block.user_id = ' . $this->_getDb()->quote($fetchOptions[self::FETCH_TEAM_BLOCK_USERID]) . ' ) '; } else { $selectFields .= ',0 AS block_end_date'; } } return compact("selectFields", "joinTables", "orderClause"); }
protected function _thSocialForumDescriptionAboveSocialgroups() { $viewParams = $this->_fetchViewParams(); if ($viewParams['socialForum']['social_forum_type'] == 'resource') { /* @var $resourceModel XenResource_Model_Resource */ $resourceModel = XenForo_Model::create('XenResource_Model_Resource'); $fetchOptions = array('join' => XenResource_Model_Resource::FETCH_CATEGORY | XenResource_Model_Resource::FETCH_USER | XenResource_Model_Resource::FETCH_ATTACHMENT | XenResource_Model_Resource::FETCH_VERSION, 'watchUserId' => XenForo_Visitor::getUserId()); if (XenForo_Visitor::getInstance()->hasPermission('resource', 'viewDeleted')) { $fetchOptions['join'] |= XenResource_Model_Resource::FETCH_DELETION_LOG; } $resource = $resourceModel->getResourceBySocialForumId($viewParams['socialForum']['social_forum_id'], $fetchOptions); if ($resource && $resourceModel->canViewResourceAndContainer($resource, $resource)) { /* @var $categoryModel XenResource_Model_Category */ $categoryModel = XenForo_Model::create('XenResource_Model_Category'); $updateConditions = $categoryModel->getPermissionBasedFetchConditions($resource); if ($updateConditions['deleted'] === true || $updateConditions['moderated'] === true || $updateConditions['moderated'] == $resource['user_id']) { /* @var $updateModel XenResource_Model_Update */ $updateModel = XenForo_Model::create('XenResource_Model_Update'); $resourceUpdateCount = $updateModel->countUpdates($updateConditions + array('resource_id' => $resource['resource_id'], 'resource_update_id_not' => $resource['description_update_id'])); } else { $resourceUpdateCount = $resource['update_count']; } $resource = $resourceModel->prepareResource($resource, $resource); $this->_appendTemplate('resource_view_tabs', $viewParams + array('resource' => $resource, 'resourceUpdateCount' => $resourceUpdateCount, 'selectedTab' => 'discussion')); ThemeHouse_SocialGroups_SocialForum::getInstance()->setResource($resource); } } }
/** * Gets the extra, node-type-specified data for the list of nodes. * * @param array $nodeIds * * @return array Format: [node id] => info */ public function getExtraDataForNodes(array $nodeIds) { $userId = XenForo_Visitor::getUserId(); // TODO: ideally this should be passed in $forumFetchOptions = array('readUserId' => $userId); return $this->_getForumModel()->getExtraForumDataForNodes($nodeIds, $forumFetchOptions); }
/** * Check if the user is authorized to view the blog, per the privacy * permissions * @param array $blog blog contents */ protected function allowedByPrivacyOptions(array $blog, array $blogPermissions) { $visitorUserId = XenForo_Visitor::getUserId(); if ($blog['user_id'] == $visitorUserId) { return parent::allowedByPrivacyOptions($blog, $blogPermissions); } if ($blogPermissions['xfa_blogs_bypass_privacy']) { return parent::allowedByPrivacyOptions($blog, $blogPermissions); } if (empty($blog['allow_view_blog'])) { return parent::allowedByPrivacyOptions($blog, $blogPermissions); } if ($blog['allow_view_blog'] != 'group') { return parent::allowedByPrivacyOptions($blog, $blogPermissions); } if (empty($blog['allow_view_blog_group'])) { return true; } /* @var $privacyGroupModel ThemeHouse_PrivacyGroups_Model_PrivacyGroup */ $privacyGroupModel = $this->getModelFromCache('ThemeHouse_PrivacyGroups_Model_PrivacyGroup'); $privacyGroup = $privacyGroupModel->getPrivacyGroupById($blog['allow_view_blog_group']); if (!$privacyGroup) { return true; } return XenForo_Helper_Criteria::userMatchesCriteria($privacyGroup['user_criteria'], true); }
public function actionSocialForumsUpdate() { $this->_assertPostOnly(); $input = $this->_input->filter(array('social_forum_ids' => array(XenForo_Input::UINT, 'array' => true), 'do' => XenForo_Input::STRING)); $watch = $this->_getForumWatchModel()->getUserSocialForumWatchBySocialForumIds(XenForo_Visitor::getUserId(), $input['social_forum_ids']); foreach ($watch as $forumWatch) { $dw = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForumWatch'); $dw->setExistingData($forumWatch, true); switch ($input['do']) { case 'stop': $dw->delete(); break; case 'email': $dw->set('send_email', 1); $dw->save(); break; case 'no_email': $dw->set('send_email', 0); $dw->save(); break; case 'alert': $dw->set('send_alert', 1); $dw->save(); break; case 'no_alert': $dw->set('send_alert', 0); $dw->save(); break; } } return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildPublicLink('watched/social-forums'))); }
public function actionGetLogin() { $redirectUri = $this->_input->filterSingle('redirect_uri', XenForo_Input::STRING); if (empty($redirectUri)) { return $this->responseError(new XenForo_Phrase('bdapi_slash_tools_login_requires_redirect_uri'), 400); } /* @var $session bdApi_Session */ $session = XenForo_Application::getSession(); $clientId = $session->getOAuthClientId(); if (empty($clientId)) { $this->_response->setHeader('X-Api-Login-Error', 'client_id'); return $this->responseNoPermission(); } if (!$session->isValidRedirectUri($redirectUri)) { $this->_response->setHeader('X-Api-Login-Error', 'redirect_uri'); return $this->responseNoPermission(); } $userId = XenForo_Visitor::getUserId(); if (empty($userId)) { $this->_response->setHeader('X-Api-Login-Error', 'oauth_token'); return $this->responseNoPermission(); } $loginLinkData = array('redirect' => $redirectUri, 'timestamp' => XenForo_Application::$time + 10); $loginLinkData['user_id'] = bdApi_Crypt::encryptTypeOne($userId, $loginLinkData['timestamp']); $loginLink = XenForo_Link::buildPublicLink('login/api', '', $loginLinkData); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL_PERMANENT, $loginLink); }
public function actionTest() { $this->assertAdminPermission('user'); $this->_routeMatch->setSections('testPermissions'); $class = XenForo_Application::resolveDynamicClass('XenForo_Session'); $publicSession = new $class(); $publicSession->start(); if ($publicSession->get('user_id') != XenForo_Visitor::getUserId()) { return $this->responseError(new XenForo_Phrase('please_login_via_public_login_page_before_testing_permissions')); } if ($this->_request->isPost()) { $username = $this->_input->filterSingle('username', XenForo_Input::STRING); /* @var $userModel XenForo_Model_User */ $userModel = $this->getModelFromCache('XenForo_Model_User'); $user = $userModel->getUserByName($username); if (!$user) { return $this->responseError(new XenForo_Phrase('requested_user_not_found'), 404); } $publicSession->set('permissionTest', array('user_id' => $user['user_id'], 'username' => $user['username'])); $publicSession->save(); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('index')); } else { return $this->responseView('XenForo_ViewAdmin_Permission_Test', 'permission_test'); } }
/** * Displays a form to allow choice of content type and upload box. * * @return XenForo_ControllerResponse_Abstract */ public function actionUpload() { $adminImageModel = $this->_getAdminImageModel(); $adminImages = XenForo_Upload::getUploadedFiles('admin_image'); $input = $this->_input->filter(array('type' => XenForo_Input::STRING, 'type_id' => array(XenForo_Input::UINT, 'array' => true))); if (empty($adminImages) || !$input['type'] || !$input['type_id']) { $typeHandlers = $this->_getAdminImageModel()->getAdminImageHandlers(); $contentTypes = array_keys($typeHandlers); if (!$input['type']) { $input['type'] = reset($contentTypes); } $viewParams = array('type' => $input['type'], 'typeId' => $input['type_id'], 'typeHandlers' => $typeHandlers); return $this->responseView('ThemeHouse_AdminImages_ViewAdmin_AdminImage_Upload', 'th_admin_image_upload_adminimages', $viewParams); } $this->_assertPostOnly(); $handler = $adminImageModel->getAdminImageHandlers($input['type']); $contentId = isset($input['type_id'][$input['type']]) ? $input['type_id'][$input['type']] : 0; if (!$handler->getContentTitle($contentId)) { return $this->responseError(new XenForo_Phrase('th_please_select_a_valid_attach_to_item_adminimages'), 404); } $adminImage = reset($adminImages); $attachmentModel = $this->_getAttachmentModel(); if ($adminImage->isImage()) { $dataId = $attachmentModel->insertUploadedAttachmentData($adminImage, XenForo_Visitor::getUserId()); $attachmentId = $attachmentModel->insertTemporaryAttachment($dataId, 'adminimage-' . $input['type'] . '-' . $input['type_id'][$input['type']]); $this->_getAdminImageModel()->associateAttachment($input['type'], $input['type_id'][$input['type']]); } else { throw $this->responseException($this->responseError(new XenForo_Phrase('th_uploaded_file_is_not_an_image_adminimages'))); } return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('images')); }
/** * * @see XenForo_Model_User::couldBeSpammer() */ public function couldBeSpammer(array $user, &$errorKey = '') { $xenOptions = XenForo_Application::get('options'); if ($xenOptions->th_noForo_noMessageCount) { // self if ($user['user_id'] == XenForo_Visitor::getUserId()) { $errorKey = 'sorry_dave'; return false; } // staff if ($user['is_admin'] || $user['is_moderator']) { $errorKey = 'spam_cleaner_no_admins_or_mods'; return false; } $criteria = XenForo_Application::get('options')->spamUserCriteria; if ($criteria['register_date'] && $user['register_date'] < XenForo_Application::$time - $criteria['register_date'] * 86400) { $errorKey = array('spam_cleaner_registered_too_long', 'register_days' => $criteria['register_date']); return false; } if ($criteria['like_count'] && $user['like_count'] > $criteria['like_count']) { $errorKey = array('spam_cleaner_too_many_likes', 'like_count' => $criteria['like_count']); return false; } return true; } return parent::couldBeSpammer($user, $errorKey); }
public function getRSVPsByEvent(&$event) { $rsvps = array('yes' => array(), 'maybe' => array(), 'no' => array(), 'user'); $event['event_rsvps'] = 0; $event['event_guests'] = 0; if (!($guests = $this->_getDb()->fetchAll("\n\t\t\tSELECT EWRatendo_rsvps.*, xf_user.*\n\t\t\t\tFROM EWRatendo_rsvps\n\t\t\t\tLEFT JOIN xf_user ON (xf_user.user_id = EWRatendo_rsvps.user_id)\n\t\t\tWHERE event_id = ?\n\t\t\tORDER BY xf_user.username\n\t\t", $event['event_id']))) { return false; } foreach ($guests as $guest) { switch ($guest['rsvp_state']) { case "yes": $event['event_guests'] += $guest['rsvp_guests']; $event['event_rsvps']++; $rsvps['yes'][] = $guest; break; case "maybe": $rsvps['maybe'][] = $guest; break; case "no": $rsvps['no'][] = $guest; break; } if ($guest['user_id'] == XenForo_Visitor::getUserId()) { $rsvps['user'] = $guest; } } return $rsvps; }
public function actionAdd() { $this->_assertPostOnly(); list($team, $category) = $this->_getTeamHelper()->assertTeamValidAndViewable(); $teamId = $team['team_id']; $this->_assertCanViewMemberTab($team, $category); $username = $this->_input->filterSingle('username', XenForo_Input::STRING); $user = $this->getModelFromCache('XenForo_Model_User')->getUserByName($username); if (!$user) { return $this->responseError(new XenForo_Phrase('requested_member_not_found'), 404); } $memberModel = $this->_getMemberModel(); $existing = $memberModel->getRecordByKeys($user['user_id'], $team['team_id']); if ($existing) { return $this->responseError(new XenForo_Phrase('Teams_user_already_joined_in_team')); } if (XenForo_Visitor::getUserId() == $team['user_id']) { $defaultstate = 'accept'; } else { if ($memberModel->assertPermissionActionViewable($team, "canAssign")) { $defaultstate = 'accept'; } else { $defaultstate = 'request'; } } $visitor = XenForo_Visitor::getInstance(); $actionUser = array('action' => 'add', 'action_user_id' => $visitor['user_id'], 'action_username' => $visitor['username']); $memberModel->insertMember($user['user_id'], $teamId, 'member', $defaultstate, $actionUser); $hash = '#member-' . $teamId . '-' . $user['user_id']; return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, XenForo_Link::buildPublicLink(TEAM_ROUTE_PREFIX . '/members', $team) . $hash); }
/** * Write to the database for whatever was written in the form */ public function actionAddThread() { // get parent $parent = parent::actionAddThread(); $userId = XenForo_Visitor::getUserId(); $visitor = XenForo_Visitor::getInstance(); $styleId = $visitor->style_id; // print_r($styleId); // get all necessary inputs from this form $dbtc_thread_id = XenForo_Application::get('last_thread'); $dbtc_donor_id = $userId; $dbtc_date = $this->_input->filterSingle('dbtc_date', XenForo_Input::DATE_TIME); $dbtc_type_id = $this->_input->filterSingle('dbtc_type_id', XenForo_Input::UINT); $dbtc_description = $this->_input->filterSingle('dbtc_description', XenForo_Input::STRING); # make sure we've got dbtc data # TEMP WE NEED BETTER CHECK. MAKE SURE WE ARE SUBMITTING FROM DBTC STYLE if (empty($dbtc_description)) { return $parent; } //Create a instance of our DataWriter for the catalog $dwDBTCcatalog = XenForo_DataWriter::create('DBTC_DataWriter_DBTCCatalogEntry'); $dwDBTCtrans = XenForo_DataWriter::create('DBTC_DataWriter_DBTCNodeEntry'); $dataCatalog = array('dbtc_thread_id' => $dbtc_thread_id, 'dbtc_donor_id' => $dbtc_donor_id, 'dbtc_type_id' => $dbtc_type_id, 'dbtc_description' => $dbtc_description, 'dbtc_date' => $dbtc_date); $dataTrans = array('dbtc_thread_id' => $dbtc_thread_id, 'dbtc_receiver_id' => $dbtc_donor_id, 'dbtc_status_id' => "0", 'dbtc_donor_id' => "0", 'dbtc_date' => $dbtc_date, 'dbtc_parent_transaction_id' => 0); $dwDBTCcatalog->bulkSet($dataCatalog); $dwDBTCcatalog->save(); $dwDBTCtrans->bulkSet($dataTrans); $dwDBTCtrans->save(); return $parent; }
public function actionIndex() { // extend actionSave, so we can save using a submit button? // get parent //$response = parent::actionIndex(); //Get thread id and use it to get dbtc catalog info for this thread $dbtc_thread_id = $this->_input->filterSingle('thread_id', XenForo_Input::UINT); $userId = XenForo_Visitor::getUserId(); # get user model from donor id $userModel = $this->getModelFromCache('XenForo_Model_User'); $username = $userModel->getUserById($userId); # get userId of current person # get all dbtc started by user $dbtccataloginfo = $this->_getDBTCModel()->getDBTCCatalogByDonorId($userId); $transactions = $this->_getDBTCModel()->getDBTCTransByUserId($userId); $catalogthreadids = array_unique(array_column($dbtccataloginfo, 'dbtc_thread_id')); $transthreadids = array_unique(array_column($transactions, 'dbtc_thread_id')); $threadModel = $this->getModelFromCache('XenForo_Model_Thread'); $transthreads = $threadModel->getThreadsByIds($transthreadids, array('order' => 'post_date', 'limit' => 20)); $catalogthreads = $threadModel->getThreadsByIds($catalogthreadids, array('order' => 'post_date', 'limit' => 20)); # convert unix date and time to something we can all read // $date = gmdate("m-d-Y", $dbtccataloginfo['dbtc_date']); print_r($catalogthreadids); //print_r($catalogthreads); //Send a response view, using a template, to show all the data that we get it. $viewParams = array('catalogthreads' => $catalogthreads, 'transthreads' => $transthreads); return $this->responseView('DBTC_ViewPublic_Overview', 'dbtc_overview', $viewParams); }
/** * List of currently online users. * * @return XenForo_ControllerResponse_Abstract */ public function actionIndex() { if (!$this->_getUserModel()->canViewMemberList()) { return $this->responseNoPermission(); } $sessionModel = $this->_getSessionModel(); $page = $this->_input->filterSingle('page', XenForo_Input::UINT); $userPerPage = XenForo_Application::get('options')->membersPerPage; $bypassUserPrivacy = $this->_getUserModel()->canBypassUserPrivacy(); $userLimit = $this->_input->filterSingle('type', XenForo_Input::STRING); $conditions = array('userLimit' => $userLimit, 'cutOff' => array('>', $sessionModel->getOnlineStatusTimeout()), 'getInvisible' => $bypassUserPrivacy, 'getUnconfirmed' => $bypassUserPrivacy, 'forceInclude' => $bypassUserPrivacy ? false : XenForo_Visitor::getUserId()); $onlineUsers = $sessionModel->getSessionActivityRecords($conditions, array('perPage' => $userPerPage, 'page' => $page, 'join' => XenForo_Model_Session::FETCH_USER_FULL, 'order' => 'view_date')); $session = XenForo_Application::getSession(); foreach ($onlineUsers as &$online) { if ($online['robot_key']) { $online['robotInfo'] = $session->getRobotInfo($online['robot_key']); } $online['ipHex'] = bin2hex($online['ip']); $online['canViewCurrentActivity'] = $this->_getUserModel()->canViewUserCurrentActivity($online); } $visitor = XenForo_Visitor::getInstance(); //TODO: this is taken directly from the forum list, could be faster if just counts $onlineTotals = $sessionModel->getSessionActivityQuickList($visitor->toArray(), array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())), $visitor['user_id'] ? $visitor->toArray() : null); $viewParams = array('onlineUsers' => $sessionModel->addSessionActivityDetailsToList($onlineUsers), 'totalOnlineUsers' => $sessionModel->countSessionActivityRecords($conditions), 'userLimit' => $userLimit, 'page' => $page, 'usersPerPage' => $userPerPage, 'canViewIps' => $this->_getUserModel()->canViewIps(), 'onlineTotals' => $onlineTotals); return $this->responseView('XenForo_ViewPublic_Online_List', 'online_list', $viewParams); }
/** * Fetches all notices applicable to the visiting user * * @param array $params * @param array $containerData * * @return array */ protected function _getSocialNoticesContainerParams(XenForo_ControllerResponse_View $controllerResponse, array $notices = array()) { $socialForum = ThemeHouse_SocialGroups_SocialForum::getInstance(); /* @var $noticeModel XenForo_Model_Notice */ $noticeModel = XenForo_Model::create('XenForo_Model_Notice'); if (XenForo_Application::get('options')->enableNotices) { $user = XenForo_Visitor::getInstance()->toArray(); if (XenForo_Application::isRegistered('session')) { $dismissedNotices = XenForo_Application::getSession()->get('dismissedNotices'); } if (!isset($dismissedNotices) || !is_array($dismissedNotices)) { $dismissedNotices = array(); } // handle style overrides $user['style_id'] = XenForo_Application::get('options')->defaultStyleId; $noticeTokens = array('{name}' => $user['username'] !== '' ? $user['username'] : new XenForo_Phrase('guest'), '{user_id}' => $user['user_id']); $allNotices = $noticeModel->getNoticesForSocialForum($socialForum['social_forum_id']); foreach ($allNotices as $noticeId => $notice) { if (!in_array($noticeId, $dismissedNotices) && XenForo_Helper_Criteria::userMatchesCriteria($notice['user_criteria'], true, $user) && XenForo_Helper_Criteria::pageMatchesCriteria($notice['page_criteria'], true, $controllerResponse->params, $controllerResponse->containerParams)) { $notices[$noticeId] = array('title' => $notice['title'], 'message' => str_replace(array_keys($noticeTokens), $noticeTokens, $notice['message']), 'wrap' => $notice['wrap'], 'dismissible' => $notice['dismissible'] && XenForo_Visitor::getUserId()); } } } return $notices; }
public function actionSigPicUpload() { $this->_assertPostOnly(); if (!XenForo_Visitor::getInstance()->hasPermission('signature', 'sigpic')) { return $this->responseNoPermission(); } $sigpic = XenForo_Upload::getUploadedFile('sigpic'); $sigpicModel = $this->getModelFromCache('TPUSigPic_Model_SigPic'); $visitor = XenForo_Visitor::getInstance(); $inputData = $this->_input->filter(array('delete' => XenForo_Input::UINT)); if ($sigpic) { $sigpicData = $sigpicModel->uploadSigPic($sigpic, $visitor['user_id'], $visitor->getPermissions()); } else { if ($inputData['delete']) { $sigpicData = $sigpicModel->deleteSigPic(XenForo_Visitor::getUserId()); } } if (isset($sigpicData) && is_array($sigpicData)) { foreach ($sigpicData as $key => $val) { $visitor[$key] = $val; } } $message = new XenForo_Phrase('upload_completed_successfully'); if ($this->_noRedirect()) { // TODO } else { return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('account/signature'), $message); } }
/** * * @see XenForo_ControllerPublic_Thread::actionUnread() */ public function actionUnread() { $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT); $visitorUserId = XenForo_Visitor::getUserId(); $visitor = XenForo_Visitor::getInstance(); $ftpHelper = $this->getHelper('ForumThreadPost'); $threadFetchOptions = array('readUserId' => $visitorUserId); $forumFetchOptions = array('readUserId' => $visitorUserId); list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId, $threadFetchOptions, $forumFetchOptions); $threadModel = $this->_getThreadModel(); if ($threadModel->getThreadDisplayOrderForThread($thread) == 'newest_first') { if (!$visitorUserId) { return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, XenForo_Link::buildPublicLink('threads', $thread)); } $readDate = $this->_getThreadModel()->getMaxThreadReadDate($thread, $forum); $postModel = $this->_getPostModel(); $ignoredUserIds = !empty($visitor['ignored']) ? unserialize($visitor['ignored']) : array(); $ignoredUserIds = array_keys($ignoredUserIds); $fetchOptions = $postModel->getPermissionBasedPostFetchOptions($thread, $forum); $firstUnread = $postModel->getNextPostInThread($threadId, $readDate, $fetchOptions, $ignoredUserIds); if (!$firstUnread) { $firstUnread = $postModel->getLastPostInThread($threadId, $fetchOptions); } if ($firstUnread) { $page = floor(($thread['reply_count'] - $firstUnread['position']) / XenForo_Application::get('options')->messagesPerPage) + 1; $hashTag = $firstUnread['position'] > 0 ? '#post-' . $firstUnread['post_id'] : ''; return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, XenForo_Link::buildPublicLink('threads', $thread, array('page' => $page)) . $hashTag); } else { return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, XenForo_Link::buildPublicLink('threads', $thread)); } } return parent::actionUnread(); }
/** * Confirms a lost password reset request and resets the password. * * @return XenForo_ControllerResponse_Abstract */ public function actionConfirm() { $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT); if (!$userId) { return $this->responseError(new XenForo_Phrase('no_account_specified')); } $confirmationModel = $this->_getUserConfirmationModel(); $confirmation = $confirmationModel->getUserConfirmationRecord($userId, 'password'); if (!$confirmation) { if (XenForo_Visitor::getUserId()) { // probably already been reset return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, XenForo_Link::buildPublicLink('index')); } else { return $this->responseError(new XenForo_Phrase('your_password_could_not_be_reset')); } } $confirmationKey = $this->_input->filterSingle('c', XenForo_Input::STRING); if ($confirmationKey) { $accountConfirmed = $confirmationModel->validateUserConfirmationRecord($confirmationKey, $confirmation); } else { $accountConfirmed = false; } if ($accountConfirmed) { $confirmationModel->resetPassword($userId); $confirmationModel->deleteUserConfirmationRecord($userId, 'password'); XenForo_Visitor::setup(0); return $this->responseMessage(new XenForo_Phrase('your_password_has_been_reset')); } else { return $this->responseError(new XenForo_Phrase('your_password_could_not_be_reset')); } }
protected function _Tinhte_XenTag_updateTagsInDatabase() { $force = $this->getExtraData(self::DATA_FORCE_UPDATE_TAGS_IN_DATABASE); $skip = $this->getExtraData(self::DATA_SKIP_UPDATE_TAGS_IN_DATABASE); if ($force or $this->isChanged(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS) and empty($skip)) { $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($this->get(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS)); $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts); $updated = Tinhte_XenTag_Integration::updateTags(Tinhte_XenTag_Constants::CONTENT_TYPE_RESOURCE, $this->get('resource_id'), XenForo_Visitor::getUserId(), $tagTexts, $this); if (is_array($updated)) { $tagsCount = count($updated); $this->set(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS, $updated, '', array('setAfterPreSave' => true)); $this->_db->update('xf_resource', array(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS => serialize($updated)), array('resource_id = ?' => $this->get('resource_id'))); } else { $tagsCount = intval($updated); } $requiresTag = Tinhte_XenTag_Option::get('resourceRequiresTag'); $maximumTags = intval($this->getModelFromCache('XenResource_Model_Resource')->Tinhte_XenTag_getMaximumTags()); if ($requiresTag and $maximumTags !== 0 and $tagsCount == 0) { throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_resource_requires_tag'), true); } if ($maximumTags !== -1 and $tagsCount > $maximumTags) { throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_too_many_tags_x_of_y', array('maximum' => $maximumTags, 'count' => $tagsCount)), true); } } }
public function unfollow($followUserId, $userId = null) { $parent = parent::unfollow($followUserId, $userId); if ($userId === null) { $userId = XenForo_Visitor::getUserId(); } $albumModel = $this->_getAlbumModel(); $addConditions = array('album_user_id' => $userId, 'add_type' => 'followed'); $addAlbums = $albumModel->getAlbums($addConditions); $viewConditions = array('album_user_id' => $userId, 'view_type' => 'followed'); $viewAlbums = $albumModel->getAlbums($viewConditions); $albums = $addAlbums + $viewAlbums; foreach ($albums as $album) { $album = $albumModel->prepareAlbumWithPermissions($album); if (!isset($album['albumPermissions'])) { continue; } $shareUsers = $albumModel->unshare($followUserId, $album); if ($album['albumPermissions']['view']['access_type'] == 'followed') { $albumViewData = array('album_id' => $album['album_id'], 'permission' => 'view', 'access_type' => 'followed', 'share_users' => $shareUsers); $albumModel->writeAlbumPermission($albumViewData, $album['albumPermissions']['view']); } if ($album['albumPermissions']['add']['access_type'] == 'followed') { $albumAddData = array('album_id' => $album['album_id'], 'permission' => 'add', 'access_type' => 'followed', 'share_users' => $shareUsers); $albumModel->writeAlbumPermission($albumAddData, $album['albumPermissions']['add']); } } return $parent; }
public function bdApi_getUserNotificationOption($userId) { if (XenForo_Application::isRegistered('bdapi_user_notification')) { $userOptions = XenForo_Application::get('bdapi_user_notification'); } else { $userOptions = array(); } if (empty($userOptions) or !isset($userOptions[$userId])) { if ($userId == XenForo_Visitor::getUserId()) { $userOptions[$userId] = XenForo_Visitor::getInstance()->get('bdapi_user_notification'); } else { $userOptions[$userId] = $this->_getDb()->fetchOne(' SELECT `bdapi_user_notification` FROM `xf_user_option` WHERE user_id = ? ', $userId); } XenForo_Application::set('bdapi_user_notification', $userOptions); } $userOption = $userOptions[$userId]; if (!empty($userOption)) { $userOption = @unserialize($userOption); } if (empty($userOption)) { $userOption = array(); } return $userOption; }
public function actionWithdraw() { $visitor = XenForo_Visitor::getInstance(); $xenOptions = XenForo_Application::getOptions(); if (!$visitor->hasPermission('thAffiliatePermissions', 'earnAffiliatePoints') || !$xenOptions->th_affiliate_enableAffiliatePoints) { return $this->responseNoPermission(); } if ($this->isConfirmedPost()) { $amount = $this->_input->filterSingle('amount', XenForo_Input::FLOAT); if ($amount < $xenOptions->th_affiliate_minWithdraw) { return $this->responseError(new XenForo_Phrase('th_you_must_withdraw_at_least_x_affiliate', array('amount' => XenForo_Template_Helper_Core::numberFormat($xenOptions->th_affiliate_minWithdraw, 2)))); } if ($amount > $visitor['affiliate_points']) { return $this->responseError(new XenForo_Phrase('th_you_do_not_have_enough_points_affiliate', array('amount' => XenForo_Template_Helper_Core::numberFormat($xenOptions->th_affiliate_minWithdraw, 2)))); } $newPoints = $visitor['affiliate_points'] - $amount; $userWriter = XenForo_DataWriter::create('XenForo_DataWriter_User'); $userWriter->setExistingData(XenForo_Visitor::getUserId()); $userWriter->set('affiliate_points', $newPoints); $userWriter->save(); $withdrawalWriter = XenForo_DataWriter::create('ThemeHouse_Affiliate_DataWriter_Withdraw'); $withdrawalWriter->set('user_id', XenForo_Visitor::getUserId()); $withdrawalWriter->set('amount', $amount); $withdrawalWriter->save(); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('affiliate'), new XenForo_Phrase('th_your_withdrawal_request_has_been_submitted_affiliate')); } else { $viewParams = array(); return $this->responseView('ThemeHouse_Affiliate_ViewPublic_Affiliate_Withdraw', 'th_withdraw_affiliate', $viewParams); } }
protected function _preSave() { if (!$this->_existingData) { $this->set('user_id', XenForo_Visitor::getUserId()); $this->set('keylink_date', XenForo_Application::$time); } }
/** * * @see XenResource_DataWriter_Resource::_insertDiscussionThread() */ protected function _insertDiscussionThread($nodeId, $prefixId = 0) { /* @var $nodeModel XenForo_Model_Node */ $nodeModel = $this->getModelFromCache('XenForo_Model_Node'); $node = $nodeModel->getNodeById($nodeId); if (!$node) { return false; } if ($node['node_type_id'] == 'SocialCategory') { $socialForumId = 0; if (isset($GLOBALS['XenResource_ControllerPublic_Resource'])) { /* @var $controller XenResource_ControllerPublic_Resource */ $controller = $GLOBALS['XenResource_ControllerPublic_Resource']; $socialForumId = $controller->getInput()->filterSingle('social_forum_id', XenForo_Input::UINT); } if ($socialForumId) { $socialForumModel = ThemeHouse_SocialGroups_SocialForum::getSocialForumModel(); $socialForum = $socialForumModel->getSocialForumById($socialForumId); } if (!empty($socialForum) && $socialForum['node_id'] == $node['node_id']) { ThemeHouse_SocialGroups_SocialForum::setup($socialForum); // TODO check permissions } else { $writer = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForum'); $writer->bulkSet(array('node_id' => $nodeId, 'user_id' => XenForo_Visitor::getUserId(), 'title' => $this->_getThreadTitle(), 'description' => $this->get('tag_line'), 'social_forum_type' => 'resource')); $writer->save(); ThemeHouse_SocialGroups_SocialForum::setup($writer->getMergedData()); $this->set('social_forum_id', $writer->get('social_forum_id'), '', array('setAfterPreSave' => true)); } } return parent::_insertDiscussionThread($nodeId, $prefixId); }
public function actionIndex() { // get parent $parent = parent::actionIndex(); // get $userId $userId = XenForo_Visitor::getUserId(); if ($userId > 0) { // get variables $ip = $_SERVER['REMOTE_ADDR']; $user_agent = $_SERVER['HTTP_USER_AGENT']; $view_date = time(); // make safe for query $user_agent = addslashes($user_agent); // show n/a if over 250 characters if (strlen($user_agent) > 250) { $user_agent = 'n/a'; } // get database $db = XenForo_Application::get('db'); // delete row $db->query("\n\t\t\t\tDELETE FROM xf_user_agent\n\t\t\t\tWHERE user_id = ?\n\t\t\t", $userId); // insert new row $db->query("\n\t\t\t\tINSERT INTO xf_user_agent\n\t\t\t\t\t(user_id, ip, user_agent, view_date)\n\t\t\t\tVALUES\n\t\t\t\t\t('{$userId}', '{$ip}', '{$user_agent}', '{$view_date}')\n\t\t\t"); } // return parent return $parent; }
public function actionBanned() { $userId = XenForo_Visitor::getUserId(); $bannedUser = $this->getModelFromCache('XenForo_Model_Banning')->getBannedUserById($userId); if (!$bannedUser) { return $this->responseNoPermission(); } else { if ($bannedUser['triggered'] && !$bannedUser['end_date']) { /** @var XenForo_Model_Warning $warningModel */ $warningModel = $this->getModelFromCache('XenForo_Model_Warning'); $minUnbanDate = $warningModel->getMinimumWarningUnbanDate($userId); if ($minUnbanDate) { $bannedUser['end_date'] = $minUnbanDate; } } if ($bannedUser['user_reason']) { $message = new XenForo_Phrase('you_have_been_banned_for_following_reason_x', array('reason' => $bannedUser['user_reason'])); } else { $message = new XenForo_Phrase('you_have_been_banned'); } if ($bannedUser['end_date'] > XenForo_Application::$time) { $message .= ' ' . new XenForo_Phrase('your_ban_will_be_lifted_on_x', array('date' => XenForo_Locale::dateTime($bannedUser['end_date']))); } return $this->responseError($message, 403); } }
public static function criteriaUser($rule, array $data, array $user, &$returnValue) { switch ($rule) { case 'steam_state': if (XenForo_Visitor::getUserId() != 0) { switch ($data['state']) { case 'associated': if (!empty($user['externalAuth']['steam']) && $user['externalAuth']['steam'] > 0) { $returnValue = true; } else { $returnValue = false; } break; case 'deassociated': if (empty($user['externalAuth']['steam']) || $user['externalAuth']['steam'] <= 0) { $returnValue = true; } else { $returnValue = false; } break; default: $returnValue = false; break; } } break; case 'steam_game': if (array_key_exists('externalAuth', $user) && !empty($user['externalAuth']['steam']) && $user['externalAuth']['steam'] > 0) { // check if game is in users games table $games = implode(",", $data['games']); $db = XenForo_Application::get('db'); $results = $db->fetchAll("SELECT COUNT(*) AS count FROM xf_user_steam_games WHERE user_id = {$user['user_id']} AND game_id IN ({$games});"); foreach ($results as $row) { if ($row['count'] > 0) { $returnValue = true; } else { $returnValue = false; } break; } } break; case 'steam_not_game': if (array_key_exists('externalAuth', $user) && !empty($user['externalAuth']['steam']) && $user['externalAuth']['steam'] > 0) { // check if game is NOT in users games table $games = implode(",", $data['games']); $db = XenForo_Application::get('db'); $results = $db->fetchAll("SELECT COUNT(*) AS count FROM xf_user_steam_games WHERE user_id = {$user['user_id']} AND game_id IN ({$games});"); foreach ($results as $row) { if ($row['count'] > 0) { $returnValue = false; } else { $returnValue = true; } break; } } break; } }