Beispiel #1
0
 /**
  *
  * @see XenForo_ControllerPublic_Member::_getNotableMembers()
  */
 protected function _getNotableMembers($type, $limit)
 {
     if ($type == 'leaderboard') {
         $leaderboardId = $this->_input->filterSingle('leaderboard_id', XenForo_Input::UINT);
         $leaderboardModel = $this->_getLeaderboardModel();
         $leaderboardEntries = $leaderboardModel->getLeaderboardEntries(array('leaderboard_id' => $leaderboardId));
         $userIds = array();
         foreach ($leaderboardEntries as $leaderboardEntry) {
             $userIds[$leaderboardEntry['user_id']] = $leaderboardEntry['user_id'];
         }
         /* @var $userModel XenForo_Model_User */
         $userModel = $this->_getUserModel();
         $fetchOptions = array('join' => XenForo_Model_User::FETCH_USER_FULL);
         $users = $userModel->getUsersByIds($userIds, $fetchOptions);
         $entries = XenForo_Application::arrayColumn($leaderboardEntries, 'entry', 'user_id');
         arsort($entries);
         $sortedUsers = array();
         foreach ($entries as $userId => $entry) {
             if (!empty($users[$userId]) && $entry) {
                 $sortedUsers[$userId] = $users[$userId];
                 $sortedUsers[$userId]['leaderboard_entry'] = $entry;
             }
         }
         return array($sortedUsers, 'leaderboard_entry');
     }
     return parent::_getNotableMembers($type, $limit);
 }
 /**
  * Gets visible moderation queue entries for specified user.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::getVisibleModerationQueueEntriesForUser()
  */
 public function getVisibleModerationQueueEntriesForUser(array $contentIds, array $viewingUser)
 {
     /** @var XenForo_Model_ProfilePost $profilePostModel */
     $profilePostModel = XenForo_Model::create('XenForo_Model_ProfilePost');
     $comments = $profilePostModel->getProfilePostCommentsByIds($contentIds);
     $profilePostIds = XenForo_Application::arrayColumn($comments, 'profile_post_id');
     $profilePosts = $profilePostModel->getProfilePostsByIds($profilePostIds, array('join' => XenForo_Model_ProfilePost::FETCH_USER_RECEIVER | XenForo_Model_ProfilePost::FETCH_USER_RECEIVER_PRIVACY | XenForo_Model_ProfilePost::FETCH_USER_POSTER, 'visitingUser' => $viewingUser));
     $output = array();
     foreach ($comments as $key => &$comment) {
         if (isset($profilePosts[$comment['profile_post_id']])) {
             $comment['profilePost'] = $profilePosts[$comment['profile_post_id']];
             $comment['profileUser'] = $profilePostModel->getProfileUserFromProfilePost($comment['profilePost'], $viewingUser);
             if (!$comment['profilePost'] || !$comment['profileUser']) {
                 continue;
             }
             $canManage = true;
             if (!$profilePostModel->canViewProfilePostAndContainer($comment['profilePost'], $comment['profileUser'], $null, $viewingUser)) {
                 $canManage = false;
             } else {
                 if (!$profilePostModel->canViewProfilePostComment($comment, $comment['profilePost'], $comment['profileUser'], $null, $viewingUser)) {
                     $canManage = false;
                 } else {
                     if (!XenForo_Permission::hasPermission($viewingUser['permissions'], 'profilePost', 'editAny') || !XenForo_Permission::hasPermission($viewingUser['permissions'], 'profilePost', 'deleteAny')) {
                         $canManage = false;
                     }
                 }
             }
             if ($canManage) {
                 $output[$comment['profile_post_comment_id']] = array('message' => $comment['message'], 'user' => array('user_id' => $comment['user_id'], 'username' => $comment['username']), 'title' => new XenForo_Phrase('profile_post_comment_by_x', array('username' => $comment['username'])), 'link' => XenForo_Link::buildPublicLink('profile-posts/comments', $comment), 'contentTypeTitle' => new XenForo_Phrase('profile_post_comment'), 'titleEdit' => false);
             }
         }
     }
     return $output;
 }
 public static function getTagOptions($content, $params)
 {
     /* @var $contactGroupCategoryDataModel ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroupCategory */
     $contactGroupCategoryDataModel = XenForo_Model::create('ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroupCategory');
     $contactGroupCategories = $contactGroupCategoryDataModel->getContactGroupCategories();
     $contactGroupCategoryIds = XenForo_Application::arrayColumn($contactGroupCategories, 'Id');
     /* @var $contactGroupDataModel ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroup */
     $contactGroupDataModel = XenForo_Model::create('ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroup');
     $contactGroups = $contactGroupDataModel->getContactGroupsForCategory($contactGroupCategoryIds);
     foreach ($contactGroups as $contactGroupId => $contactGroup) {
         $contactGroupCategories[$contactGroup['GroupCategoryId']]['groups'][$contactGroupId] = $contactGroup;
     }
     $content .= '<select id="ctrl_user_criteriainfusionsoft_contact_group_id_thdatacontact_group_id" name="user_criteria[infusionsoft_contact_group_id_th][data][contact_group_id]" class="textCtrl autoSize" />';
     foreach ($contactGroupCategories as $contactGroupCategory) {
         if (!empty($contactGroupCategory['groups'])) {
             $content .= '<optgroup label="' . $contactGroupCategory['CategoryName'] . '">';
             foreach ($contactGroupCategory['groups'] as $contactGroupId => $contactGroup) {
                 $selected = $params['value'] == $contactGroupId ? ' selected="selected"' : '';
                 $content .= '<option value="' . $contactGroupId . '" label="' . $contactGroup['GroupName'] . '"' . $selected . '/>';
             }
             $content .= '</optgroup>';
         }
     }
     $content .= '</select>';
     return $content;
 }
 /**
  * Verifies the registrationWelcome setting
  *
  * @param array $values
  * @param XenForo_DataWriter $dw Calling DW
  * @param string $fieldName Name of field/option
  *
  * @return true
  */
 public static function verifyOption(array &$values, XenForo_DataWriter $dw, $fieldName)
 {
     if ($dw->isInsert()) {
         // insert - just trust the default value
         return true;
     }
     if (!empty($values['messageEnabled'])) {
         /** @var XenForo_Model_User $userModel */
         $userModel = XenForo_Model::create('XenForo_Model_User');
         $participants = explode(',', $values['messageParticipants']);
         $starter = array_shift($participants);
         $participantUsers = $userModel->getUsersByNames($participants);
         $starterUser = $userModel->getUserByName($starter);
         if (!$starterUser) {
             if ($starter) {
                 $dw->error(new XenForo_Phrase('the_following_recipients_could_not_be_found_x', array('names' => $starter)), $fieldName);
             } else {
                 $dw->error(new XenForo_Phrase('please_enter_at_least_one_valid_recipient'), $fieldName);
             }
             return false;
         }
         /** @var XenForo_DataWriter_ConversationMaster $conversationDw */
         $conversationDw = XenForo_DataWriter::create('XenForo_DataWriter_ConversationMaster');
         $conversationDw->setExtraData(XenForo_DataWriter_ConversationMaster::DATA_ACTION_USER, $starterUser);
         $conversationDw->setExtraData(XenForo_DataWriter_ConversationMaster::DATA_MESSAGE, $values['messageBody']);
         $conversationDw->set('user_id', $starterUser['user_id']);
         $conversationDw->set('username', $starterUser['username']);
         $conversationDw->set('title', $values['messageTitle']);
         $conversationDw->addRecipientUserIds(array_keys($participantUsers));
         // skips permissions
         $messageDw = $conversationDw->getFirstMessageDw();
         $messageDw->set('message', $values['messageBody']);
         $conversationDw->preSave();
         if ($conversationDw->hasErrors()) {
             $errors = $conversationDw->getErrors();
             // Skip recipient errors. We've already verified the recipients are valid.
             if (isset($errors['recipients'])) {
                 unset($errors['recipients']);
             }
             if (count($errors)) {
                 $dw->error(reset($errors), $fieldName);
                 return false;
             }
         }
         $validUsernames = XenForo_Application::arrayColumn($participantUsers, 'username');
         array_unshift($validUsernames, $starter);
         $values['messageParticipants'] = implode(', ', array_unique($validUsernames));
     }
     if (!empty($values['emailEnabled']) && !strlen(trim($values['emailBody']))) {
         $dw->error(new XenForo_Phrase('you_must_enter_email_message_to_enable_welcome_email'), $fieldName);
         return false;
     }
     return true;
 }
 public function actionAutoComplete()
 {
     $q = $this->_input->filterSingle('q', XenForo_Input::STRING);
     if ($q) {
         $templates = $this->_getTemplateModel()->getEffectiveTemplateListForStyle(0, array('title' => array($q, 'r')), array('limit' => 10));
     } else {
         $templates = array();
     }
     $view = $this->responseView();
     $view->jsonParams = array('results' => XenForo_Application::arrayColumn($templates, 'title', 'title'));
     return $view;
 }
 public function actionAutoComplete()
 {
     $q = $this->_input->filterSingle('q', XenForo_Input::STRING);
     if ($q) {
         $templates = $this->_getEmailTemplateModel()->getMasterEmailTemplatesLikeTitle($q, 'r', 10);
     } else {
         $templates = array();
     }
     $view = $this->responseView();
     $view->jsonParams = array('results' => XenForo_Application::arrayColumn($templates, 'title', 'title'));
     return $view;
 }
 /**
  * Renders the contact groups option.
  *
  * @param XenForo_View $view View object
  * @param string $fieldPrefix Prefix for the HTML form field name
  * @param array $preparedOption Prepared option info
  * @param boolean $canEdit True if an "edit" link should appear
  *
  * @return XenForo_Template_Abstract Template object
  */
 public static function renderOption(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
 {
     if (self::$_contactGroupCategories === null) {
         /* @var $contactGroupCategoryDataModel ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroupCategory */
         $contactGroupCategoryDataModel = XenForo_Model::create('ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroupCategory');
         $contactGroupCategories = $contactGroupCategoryDataModel->getContactGroupCategories();
         $contactGroupCategoryIds = XenForo_Application::arrayColumn($contactGroupCategories, 'Id');
         /* @var $contactGroupDataModel ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroup */
         $contactGroupDataModel = XenForo_Model::create('ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_ContactGroup');
         $contactGroups = $contactGroupDataModel->getContactGroupsForCategory($contactGroupCategoryIds);
         foreach ($contactGroups as $contactGroupId => $contactGroup) {
             $contactGroupCategories[$contactGroup['GroupCategoryId']]['groups'][$contactGroupId] = $contactGroup;
         }
         self::$_contactGroupCategories = $contactGroupCategories;
     }
     $preparedOption['contactGroupCategories'] = self::$_contactGroupCategories;
     return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('th_option_template_tags_infusionsoftapi', $view, $fieldPrefix, $preparedOption, $canEdit);
 }
Beispiel #8
0
 public function actionThreadsByCategory()
 {
     $this->_routeMatch->setSections('forums');
     $threadModel = $this->_getThreadModel();
     $visitor = XenForo_Visitor::getInstance();
     $searchId = $this->_input->filterSingle('search_id', XenForo_Input::UINT);
     if (!$searchId) {
         return $this->findNewPosts();
     }
     $searchModel = $this->_getSearchModel();
     $search = $searchModel->getSearchById($searchId);
     if (!$search || $search['user_id'] != XenForo_Visitor::getUserId() || !in_array($search['search_type'], array('new-threads', 'recent-threads'))) {
         return $this->findNewPosts();
     }
     $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
     $perPage = XenForo_Application::get('options')->discussionsPerPage;
     $pageResultIds = $searchModel->sliceSearchResultsToPage($search, $page, $perPage);
     $threadIds = XenForo_Application::arrayColumn($pageResultIds, 1);
     $threadsMatched = $threadModel->getThreadsByIds($threadIds, array('join' => XenForo_Model_Thread::FETCH_FORUM | XenForo_Model_Thread::FETCH_USER | XenForo_Model_Thread::FETCH_FIRSTPOST, 'permissionCombinationId' => $visitor['permission_combination_id'], 'readUserId' => $visitor['user_id'], 'includeForumReadDate' => true, 'watchUserId' => $visitor['user_id'], 'forumWatchUserId' => $visitor['user_id'], 'postCountUserId' => $visitor['user_id']));
     $threads = array();
     $inlineModOptions = array();
     foreach ($threadIds as $threadId) {
         if (!isset($threadsMatched[$threadId])) {
             continue;
         }
         $thread = $threadsMatched[$threadId];
         $thread['permissions'] = XenForo_Permission::unserializePermissions($thread['node_permission_cache']);
         if (!$threadModel->canViewThreadAndContainer($thread, $thread, $null, $thread['permissions'])) {
             continue;
         }
         $thread = $threadModel->prepareThread($thread, $thread, $thread['permissions']);
         $thread['forum'] = array('node_id' => $thread['node_id'], 'node_name' => $thread['node_name'], 'title' => $thread['node_title']);
         $threadModOptions = $threadModel->addInlineModOptionToThread($thread, $thread, $thread['permissions']);
         $inlineModOptions += $threadModOptions;
         $threads[$thread['thread_id']] = $thread;
     }
     if (!$threads) {
         return $this->getNoPostsResponse();
     }
     $resultStartOffset = ($page - 1) * $perPage + 1;
     $resultEndOffset = ($page - 1) * $perPage + count($threadIds);
     $viewParams = array('search' => $search, 'threads' => $threads, 'inlineModOptions' => $inlineModOptions, 'threadStartOffset' => $resultStartOffset, 'threadEndOffset' => $resultEndOffset, 'ignoredNames' => $this->_getIgnoredContentUserNames($threads), 'page' => $page, 'perPage' => $perPage, 'totalThreads' => $search['result_count'], 'nextPage' => $resultEndOffset < $search['result_count'] ? $page + 1 : 0, 'showingNewPosts' => $search['search_type'] == 'new-posts');
     return $this->getFindNewWrapper($this->responseView('XenForo_ViewPublic_FindNew_Posts', 'find_new_posts', $viewParams), 'posts');
 }
Beispiel #9
0
 public function alertTaggedMembers($content, $contentId, $contentType, $tagged, array $alreadyAlerted = array())
 {
     $userIds = XenForo_Application::arrayColumn($tagged, 'user_id');
     $userIds = array_diff($userIds, $alreadyAlerted);
     $alertedUserIds = array();
     if ($userIds) {
         $userModel = $this->_getUserModel();
         $users = $userModel->getUsersByIds($userIds, array('join' => XenForo_Model_User::FETCH_USER_OPTION | XenForo_Model_User::FETCH_USER_PROFILE | XenForo_Model_User::FETCH_USER_PERMISSIONS));
         foreach ($users as $user) {
             if (isset($alertedUserIds[$user['user_id']]) || $user['user_id'] == $content['user_id'] || $user['user_id'] == $content['user_id']) {
                 continue;
             }
             $xfContentType = $this->_getXfContentType($contentType);
             if (!$userModel->isUserIgnored($user, $content['user_id']) && !$userModel->isUserIgnored($user, $content['user_id']) && XenForo_Model_Alert::userReceivesAlert($user, $xfContentType, 'tagging')) {
                 $alertedUserIds[$user['user_id']] = true;
                 XenForo_Model_Alert::alert($user['user_id'], $content['user_id'], $content['username'], $contentType, $contentId, 'tagging');
             }
         }
     }
     return array_keys($alertedUserIds);
 }
 /**
  * Fetches related content (profile post comments) by IDs
  *
  * @param array $contentIds
  * @param XenForo_Model_NewsFeed $model
  * @param array $viewingUser Information about the viewing user (keys: user_id, permission_combination_id, permissions)
  *
  * @return array
  */
 public function getContentByIds(array $contentIds, $model, array $viewingUser)
 {
     $profilePostModel = $this->_getProfilePostModel();
     $comments = $profilePostModel->getProfilePostCommentsByIds($contentIds);
     $profilePostIds = XenForo_Application::arrayColumn($comments, 'profile_post_id');
     $profilePosts = $profilePostModel->getProfilePostsByIds($profilePostIds, array('join' => XenForo_Model_ProfilePost::FETCH_USER_RECEIVER | XenForo_Model_ProfilePost::FETCH_USER_RECEIVER_PRIVACY | XenForo_Model_ProfilePost::FETCH_USER_POSTER, 'visitingUser' => $viewingUser));
     foreach ($comments as $key => &$comment) {
         if (isset($profilePosts[$comment['profile_post_id']])) {
             $comment['profilePost'] = $profilePosts[$comment['profile_post_id']];
             $comment['profileUser'] = $profilePostModel->getProfileUserFromProfilePost($comment['profilePost'], $viewingUser);
             if (!$comment['profilePost'] || !$comment['profileUser']) {
                 unset($comments[$key]);
                 continue;
             }
             if (!$profilePostModel->canViewProfilePostAndContainer($comment['profilePost'], $comment['profileUser'], $null, $viewingUser)) {
                 unset($comments[$key]);
             }
         } else {
             unset($comments[$key]);
         }
     }
     return $comments;
 }
Beispiel #11
0
 /**
  *
  * @param array $contacts
  * @param int $position
  */
 public function pullContacts(array $contacts, $position = 0, $targetRunTime = 0)
 {
     /* @var $userModel XenForo_Model_User */
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     $contactIds = XenForo_Application::arrayColumn($contacts, 'Id');
     if (!$contactIds) {
         return $position;
     }
     $contactUsers = $userModel->getUsersByContactIds($contactIds);
     $userContactIds = XenForo_Application::arrayColumn($contactUsers, 'infusionsoft_contact_id_th', 'user_id');
     $emails = XenForo_Application::arrayColumn($contacts, 'Email');
     $emails = array_unique(array_filter($emails));
     $fetchOptions = array('join' => XenForo_Model_User::FETCH_USER_PROFILE);
     $emailUsers = $userModel->getUsersByEmails($emails, $fetchOptions);
     $userEmails = XenForo_Application::arrayColumn($emailUsers, 'email', 'user_id');
     $s = microtime(true);
     foreach ($contacts as $contactId => $contact) {
         $targetRunTime = $this->getTargetRunTime($targetRunTime);
         if ($targetRunTime && microtime(true) - $s > $targetRunTime) {
             break;
         }
         $position++;
         $user = in_array($contactId, $userContactIds) ? $contactUsers[array_search($contactId, $userContactIds)] : false;
         if (!$user && !empty($contact['Email'])) {
             $user = in_array($contact['Email'], $userEmails) ? $emailUsers[array_search($contact['Email'], $userEmails)] : false;
             if ($user && !empty($user['infusionsoft_contact_id_th'])) {
                 continue;
             }
         }
         $this->pullContact($contact, $user);
     }
     return $position;
 }
Beispiel #12
0
 public function getTagCloudLevels(array $tags, $levels = 7)
 {
     if (!$tags) {
         return array();
     }
     $uses = XenForo_Application::arrayColumn($tags, 'use_count');
     $min = min($uses);
     $max = max($uses);
     $levelSize = ($max - $min) / $levels;
     $output = array();
     if ($min == $max) {
         $middle = ceil($levels / 2);
         foreach ($tags as $id => $tag) {
             $output[$id] = $middle;
         }
     } else {
         foreach ($tags as $id => $tag) {
             $diffFromMin = $tag['use_count'] - $min;
             if (!$diffFromMin) {
                 $level = 1;
             } else {
                 $level = min($levels, ceil($diffFromMin / $levelSize));
             }
             $output[$id] = $level;
         }
     }
     return $output;
 }
Beispiel #13
0
 public function actionMassToggle()
 {
     $addOnModel = $this->_getAddOnModel();
     $allAddOns = $addOnModel->getAllAddOns();
     if ($this->_input->filterSingle('enable', XenForo_Input::BOOLEAN)) {
         if ($this->isConfirmedPost()) {
             $addOns = $this->_input->filterSingle('add_ons', XenForo_Input::ARRAY_SIMPLE);
             $dws = array();
             foreach ($addOns as $addOnId) {
                 $dw = XenForo_DataWriter::create('XenForo_DataWriter_AddOn');
                 $dw->setExistingData($addOnId);
                 $dw->set('active', 1);
                 $dw->preSave();
                 $dws[] = $dw;
             }
             XenForo_Db::beginTransaction();
             foreach ($dws as $dw) {
                 $dw->save();
             }
             XenForo_Db::commit();
             /** @var XenForo_Model_DataRegistry $dataRegistry */
             $dataRegistry = $this->getModelFromCache('XenForo_Model_DataRegistry');
             $dataRegistry->set('disabledAddOns', array());
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('add-ons'));
         } else {
             $disabledAddOns = $addOnModel->getDisabledAddOnsCache();
             if (!$disabledAddOns) {
                 $disabledAddOns = $allAddOns;
             }
             $viewParams = array('addOns' => $allAddOns, 'disabledAddOns' => $disabledAddOns);
             return $this->responseView('XenForo_ViewAdmin_AddOn_MassEnable', 'addon_mass_enable', $viewParams);
         }
     } else {
         if ($this->isConfirmedPost()) {
             $activeAddOns = array();
             if (XenForo_Application::isRegistered('addOns')) {
                 $activeAddOns = XenForo_Application::get('addOns');
                 unset($activeAddOns['XenForo']);
                 $activeAddOns = array_combine(array_keys($activeAddOns), array_keys($activeAddOns));
             }
             $dws = array();
             foreach ($activeAddOns as $addOnId => $versionId) {
                 $dw = XenForo_DataWriter::create('XenForo_DataWriter_AddOn');
                 $dw->setExistingData($addOnId);
                 $dw->set('active', 0);
                 $dw->preSave();
                 $dws[] = $dw;
             }
             XenForo_Db::beginTransaction();
             foreach ($dws as $dw) {
                 $dw->save();
             }
             XenForo_Db::commit();
             /** @var XenForo_Model_DataRegistry $dataRegistry */
             $dataRegistry = $this->getModelFromCache('XenForo_Model_DataRegistry');
             $dataRegistry->set('disabledAddOns', $activeAddOns);
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('add-ons'));
         } else {
             $activeAddOns = XenForo_Application::arrayColumn($allAddOns, 'active', 'addon_id');
             $activeCount = array_sum($activeAddOns);
             if ($activeCount === 0) {
                 return $this->responseError(new XenForo_Phrase('there_currently_no_add_ons_to_disable'));
             }
             $viewParams = array('disabledAddOns' => $addOnModel->getDisabledAddOnsCache());
             return $this->responseView('XenForo_ViewAdmin_AddOn_MassDisable', 'addon_mass_disable', $viewParams);
         }
     }
 }
 public function alertTaggedMembers(array $profilePost, array $profileUser, array $tagged, array $alreadyAlerted = array(), $commentId = 0, array $taggingUser = null)
 {
     $userIds = XenForo_Application::arrayColumn($tagged, 'user_id');
     $userIds = array_diff($userIds, $alreadyAlerted);
     $alertedUserIds = array();
     if (!$taggingUser) {
         $taggingUser = $profilePost;
     }
     if ($userIds) {
         $userModel = $this->_getUserModel();
         $users = $userModel->getUsersByIds($userIds, array('join' => XenForo_Model_User::FETCH_USER_OPTION | XenForo_Model_User::FETCH_USER_PROFILE | XenForo_Model_User::FETCH_USER_PERMISSIONS));
         foreach ($users as $user) {
             if (isset($alertedUserIds[$user['user_id']])) {
                 continue;
             }
             $user['permissions'] = XenForo_Permission::unserializePermissions($user['global_permission_cache']);
             if ($user['user_id'] != $taggingUser['user_id'] && !$userModel->isUserIgnored($user, $profilePost['user_id']) && !$userModel->isUserIgnored($user, $profileUser['user_id']) && XenForo_Model_Alert::userReceivesAlert($user, 'profile_post', 'tag') && $this->canViewProfilePostAndContainer($profilePost, $profileUser, $null, $user)) {
                 $alertedUserIds[$user['user_id']] = true;
                 XenForo_Model_Alert::alert($user['user_id'], $taggingUser['user_id'], $taggingUser['username'], 'profile_post' . ($commentId ? '_comment' : ''), $commentId ? $commentId : $profilePost['profile_post_id'], 'tag');
             }
         }
     }
     return array_keys($alertedUserIds);
 }
 public static function unreadCategories()
 {
     $nodeModel = XenForo_Model::create('XenForo_Model_Node');
     $nodeData = $nodeModel->getNodeDataForListDisplay(false, 0);
     $xenOptions = XenForo_Application::get('options');
     $categoryIds = array();
     if (!empty($xenOptions->th_unreadCategories_nodeIds)) {
         $categoryIds = $xenOptions->th_unreadCategories_nodeIds;
     }
     $nodes = array();
     foreach ($nodeData['nodesGrouped'] as $parentNodeId => $groupedNodes) {
         foreach ($groupedNodes as $nodeId => $node) {
             if ($node['node_type_id'] == 'Category' && !empty($node['last_post_date']) && in_array($nodeId, $categoryIds)) {
                 $nodes[$nodeId] = $node;
             }
         }
     }
     $nodeLastPostDates = XenForo_Application::arrayColumn($nodes, 'last_post_date', 'node_id');
     $db = XenForo_Application::getDb();
     $timeNow = XenForo_Application::$time;
     $whereClauses = array();
     foreach ($nodeLastPostDates as $nodeId => $lastPostDate) {
         if ($lastPostDate > $timeNow - $xenOptions->alertsPopupExpiryHours * 3600) {
             $whereClauses[] = '(node_id = ' . $db->quote($nodeId) . ' AND category_read_date >= ' . $db->quote($lastPostDate) . ')';
         } else {
             unset($nodeLastPostDates[$nodeId]);
         }
     }
     $readCategories = array();
     if ($whereClauses) {
         $readCategories = $db->fetchPairs('
                 SELECT user_id, GROUP_CONCAT(node_id SEPARATOR \',\') AS node_ids FROM xf_category_read_th
                 WHERE ' . implode(' OR ', $whereClauses) . '
                 GROUP BY user_id
             ');
     }
     $readCategoryCombinations = array();
     $userCombinationIds = array();
     foreach ($readCategories as $userId => $nodeIds) {
         if (!in_array($nodeIds, $readCategoryCombinations)) {
             $readCategoryCombinations[] = $nodeIds;
         }
         $userCombinationIds[array_search($nodeIds, $readCategoryCombinations)][] = $userId;
     }
     $allNodeIds = array_keys($nodeLastPostDates);
     $updates = array();
     foreach ($readCategoryCombinations as $combinationId => $nodeIds) {
         $readNodeIds = explode(',', $nodeIds);
         $unreadNodeIds = array_diff($allNodeIds, $readNodeIds);
         $userIds = $userCombinationIds[$combinationId];
         $updates[] = 'WHEN user_id IN (' . $db->quote($userIds) . ') THEN ' . $db->quote(implode(',', $unreadNodeIds));
     }
     if ($updates) {
         $db->query('
             UPDATE xf_user_profile SET unread_category_ids_th = CASE
             ' . implode(' ', $updates) . '
             ELSE ' . $db->quote(implode(',', $allNodeIds)) . '
             END
         ');
     } else {
         $db->query('
             UPDATE xf_user_profile
             SET unread_category_ids_th = ' . $db->quote(implode(',', $allNodeIds)) . '
         ');
     }
 }
Beispiel #16
0
 public function alertTaggedMembers(array $post, array $team, array $tagged, array $alreadyAlerted)
 {
     $userIds = XenForo_Application::arrayColumn($tagged, 'user_id');
     $userIds = array_diff($userIds, $alreadyAlerted);
     $alertedUserIds = array();
     if ($userIds) {
         $userModel = $this->getModelFromCache('XenForo_Model_User');
         $memberModel = $this->_getMemberModel();
         $users = $memberModel->getAllMembersInTeam($team['team_id'], array('user_id' => $userIds, 'alert' => 1), array('join' => Nobita_Teams_Model_Member::FETCH_USER | Nobita_Teams_Model_Member::FETCH_USER_PERMISSIONS));
         foreach ($users as $user) {
             $user['permissions'] = XenForo_Permission::unserializePermissions($user['global_permission_cache']);
             if ($userModel->isUserIgnored($user, $post['user_id']) || !XenForo_Model_Alert::userReceivesAlert($user, "team_post", "tag")) {
                 continue;
             }
             if (empty($user['send_alert'])) {
                 continue;
             }
             if (!isset($alertedUserIds[$user['user_id']]) && $post['user_id'] != $user['user_id']) {
                 if ($this->canViewPostAndContainer($post, $team, $team, $null, $user)) {
                     $alertedUserIds[$user['user_id']] = true;
                     XenForo_Model_Alert::alert($user['user_id'], $post['user_id'], $post['username'], 'team_post', $post['post_id'], 'tag');
                 }
             }
         }
     }
     return array_keys($alertedUserIds);
 }
 /**
  * Gets the type-specific data for a collection of results of this content
  * type.
  *
  * @see XenForo_Search_DataHandler_Abstract::getDataForResults()
  */
 public function getDataForResults(array $ids, array $viewingUser, array $resultsGrouped)
 {
     $checkOutModel = $this->_getCheckOutModel();
     $checkOuts = $checkOutModel->getCheckOutsByIds($ids, array('permissionCombinationId' => $viewingUser['permission_combination_id'], 'join' => ThemeHouse_ResCheckInOut_Model_CheckOut::FETCH_CHECK_OUT_TO_USER));
     $resourceIds = XenForo_Application::arrayColumn($checkOuts, 'resource_id');
     $resourceIds = array_unique($resourceIds);
     /* @var $resourceModel XenResource_Model_Resource */
     $resourceModel = XenForo_Model::create('XenResource_Model_Resource');
     $resources = $resourceModel->getResourcesByIds($resourceIds, array('join' => XenResource_Model_Resource::FETCH_CATEGORY));
     foreach ($checkOuts as &$checkOut) {
         if (empty($resources[$checkOut['resource_id']])) {
             continue;
         }
         $checkOut['resource'] = $resources[$checkOut['resource_id']];
     }
     return $checkOuts;
 }
Beispiel #18
0
    /**
     * Currently handles attachments for posts and conversation messages only
     *
     * @param integer $start
     * @param array $options
     */
    public function stepAttachments($start, array $options)
    {
        $options = array_merge(array('data' => isset($this->_config['dir']['data']) ? $this->_config['dir']['data'] : '', 'internal_data' => isset($this->_config['dir']['internal_data']) ? $this->_config['dir']['internal_data'] : '', 'limit' => 50, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        $attachmentSqlContentInfo = $model->getAttachmentContentSqlInfo();
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(attachment_id)
				FROM xf_attachment
				WHERE content_type IN (' . $sDb->quote(array_keys($attachmentSqlContentInfo)) . ')
			');
        }
        $attachments = $sDb->fetchAll($sDb->limit('
				SELECT *
				FROM xf_attachment AS a
				LEFT JOIN xf_attachment_data AS ad ON (ad.data_id = a.data_id)
				WHERE a.content_type IN (' . $sDb->quote(array_keys($attachmentSqlContentInfo)) . ')
					AND a.attachment_id > ' . $sDb->quote($start) . '
				ORDER BY a.attachment_id
			', $options['limit']));
        if (!$attachments) {
            return true;
        }
        $next = 0;
        $total = 0;
        $userIdMap = $model->getUserIdsMapFromArray($attachments, 'user_id');
        $groupedAttachments = array();
        foreach ($attachments as $attachment) {
            $groupedAttachments[$attachment['content_type']][$attachment['attachment_id']] = $attachment;
        }
        $db = XenForo_Application::getDb();
        /* @var $attachModel XenForo_Model_Attachment */
        $attachModel = XenForo_Model::create('XenForo_Model_Attachment');
        foreach ($groupedAttachments as $contentType => $attachments) {
            list($sqlTableName, $sqlIdName) = $attachmentSqlContentInfo[$contentType];
            $contentIdMap = $model->getImportContentMap($contentType, XenForo_Application::arrayColumn($attachments, 'content_id'));
            if ($contentIdMap) {
                $contentItems = $db->fetchPairs("\r\r\n\t\t\t\t\tSELECT {$sqlIdName}, message\r\r\n\t\t\t\t\tFROM {$sqlTableName}\r\r\n\t\t\t\t\tWHERE {$sqlIdName} IN (" . $db->quote($contentIdMap) . ")\r\r\n\t\t\t\t");
            } else {
                $contentItems = array();
            }
            foreach ($attachments as $attachment) {
                $next = max($next, $attachment['attachment_id']);
                $contentId = $this->_mapLookUp($contentIdMap, $attachment['content_id']);
                if (!$contentId || !isset($contentItems[$contentId])) {
                    continue;
                }
                $attachFileOrig = $attachModel->getAttachmentDataFilePath($attachment, $options['internal_data']);
                if (!file_exists($attachFileOrig)) {
                    continue;
                }
                $userId = $this->_mapLookUp($userIdMap, $attachment['user_id'], 0);
                $attachFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
                copy($attachFileOrig, $attachFile);
                $success = $model->importAttachment($attachment['attachment_id'], $attachment['filename'], $attachFile, $userId, $contentType, $contentId, $attachment['upload_date'], array('view_count' => $attachment['view_count']), array($this, 'processAttachmentTags'), $contentItems[$contentId]);
                if ($success) {
                    $total++;
                }
                @unlink($attachFile);
            }
        }
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
Beispiel #19
0
 public function alertTaggedMembers(array $comment, array $post, array $team, array $tagged, array $alreadyAlerted = array())
 {
     $userIds = XenForo_Application::arrayColumn($tagged, 'user_id');
     $userIds = array_diff($userIds, $alreadyAlerted);
     $alertedUserIds = array();
     if ($comment['comment_type'] == self::COMMENT_TYPE_EVENT) {
         return;
         // nothing to do!
     }
     if ($userIds) {
         $memberModel = $this->getModelFromCache('Nobita_Teams_Model_Member');
         $users = $memberModel->getAllMembersInTeam($team['team_id'], array('user_id' => $userIds, 'alert' => 1), array('join' => Nobita_Teams_Model_Member::FETCH_USER | Nobita_Teams_Model_Member::FETCH_USER_PERMISSIONS));
         foreach ($users as $user) {
             $user['permissions'] = XenForo_Permission::unserializePermissions($user['global_permission_cache']);
             if (isset($alertedUserIds[$user['user_id']]) || $comment['user_id'] == $user['user_id'] || $comment['user_id'] == XenForo_Visitor::getUserId()) {
                 continue;
             }
             if (empty($user['send_alert'])) {
                 continue;
             }
             if (!$this->getModelFromCache('XenForo_Model_User')->isUserIgnored($user, $post['user_id']) && $this->getModelFromCache('Nobita_Teams_Model_Post')->canViewPostAndContainer($post, $team, $team, $null, $user)) {
                 $alertedUserIds[$user['user_id']] = true;
                 XenForo_Model_Alert::alert($user['user_id'], $comment['user_id'], $comment['username'], 'team_comment', $comment['comment_id'], 'tag');
             }
         }
     }
     return array_keys($alertedUserIds);
 }
 /**
  * Compiles all email templates that include the given phrase.
  *
  * @param string $phraseTitle
  * @param boolean $deferred
  */
 public function compileEmailTemplatesThatIncludePhrase($phraseTitle, $deferred = true)
 {
     $templates = $this->getEffectiveEmailTemplatesThatIncludePhrase($phraseTitle);
     if ($deferred) {
         XenForo_Application::defer('EmailTemplatePartialCompile', array('recompileTemplateIds' => XenForo_Application::arrayColumn($templates, 'template_id')), null, true);
     } else {
         foreach ($templates as $template) {
             $this->compileAndInsertEmailTemplate($template);
         }
     }
 }
Beispiel #21
0
 /**
  * @param array $nodes
  * @param integer $parentNodeId
  * @param integer $displayDepth
  * @param array|null $nodePermissions
  *
  * @return array
  */
 public function getNodeListDisplayData(array $nodes, $parentNodeId, $displayDepth, array $nodePermissions = null)
 {
     if (!$nodes) {
         return array();
     }
     if (!is_array($nodePermissions)) {
         $nodePermissions = $this->getNodePermissionsForPermissionCombination();
     }
     $nodeHandlers = $this->getNodeHandlersForNodeTypes($this->getUniqueNodeTypeIdsFromNodeList($nodes));
     $nodes = $this->getViewableNodesFromNodeList($nodes, $nodeHandlers, $nodePermissions);
     $nodes = $this->mergeExtraNodeDataIntoNodeList($nodes, $nodeHandlers);
     $nodes = $this->prepareNodesWithHandlers($nodes, $nodeHandlers);
     $groupedNodes = $this->groupNodesByParent($nodes);
     $groupedNodes = $this->pushNodeDataUpTree($parentNodeId, $groupedNodes, $nodeHandlers, $nodePermissions);
     if ($displayDepth) {
         $groupedNodes = $this->filterGroupedNodesToDepth($parentNodeId, $groupedNodes, $displayDepth);
     }
     $nodeParents = XenForo_Application::arrayColumn($nodes, 'parent_node_id', 'node_id');
     return array('nodeParents' => $nodeParents, 'nodesGrouped' => $groupedNodes, 'parentNodeId' => $parentNodeId, 'nodeHandlers' => $nodeHandlers, 'nodePermissions' => $nodePermissions);
 }
Beispiel #22
0
 public function actionTagAutoComplete()
 {
     if (!XenForo_Application::getOptions()->enableTagging) {
         return $this->responseNoPermission();
     }
     /** @var XenForo_Model_Tag $tagModel */
     $tagModel = $this->getModelFromCache('XenForo_Model_Tag');
     $q = $this->_input->filterSingle('q', XenForo_Input::STRING);
     $q = $tagModel->normalizeTag($q);
     if (strlen($q) >= 2) {
         $tags = $tagModel->autoCompleteTag($q);
         $tags = XenForo_Application::arrayColumn($tags, 'tag', 'tag');
     } else {
         $tags = array();
     }
     $view = $this->responseView();
     $view->jsonParams = array('results' => $tags);
     return $view;
 }
Beispiel #23
0
 public function alertTaggedMembers(array $post, array $thread, array $forum, array $tagged, array $alreadyAlerted)
 {
     $userIds = XenForo_Application::arrayColumn($tagged, 'user_id');
     $userIds = array_diff($userIds, $alreadyAlerted);
     $alertedUserIds = array();
     if ($userIds) {
         $userModel = $this->_getUserModel();
         $users = $userModel->getUsersByIds($userIds, array('join' => XenForo_Model_User::FETCH_USER_OPTION | XenForo_Model_User::FETCH_USER_PROFILE, 'nodeIdPermissions' => $thread['node_id']));
         foreach ($users as $user) {
             if (!isset($alertedUserIds[$user['user_id']]) && $user['user_id'] != $post['user_id']) {
                 $permissions = XenForo_Permission::unserializePermissions($user['node_permission_cache']);
                 if (!$userModel->isUserIgnored($user, $post['user_id']) && XenForo_Model_Alert::userReceivesAlert($user, 'post', 'tag') && $this->canViewPostAndContainer($post, $thread, $forum, $null, $permissions, $user)) {
                     $alertedUserIds[$user['user_id']] = true;
                     XenForo_Model_Alert::alert($user['user_id'], $post['user_id'], $post['username'], 'post', $post['post_id'], 'tag');
                 }
             }
         }
     }
     return array_keys($alertedUserIds);
 }
Beispiel #24
0
 public function actionProfilePosts()
 {
     $this->_routeMatch->setSections('members');
     $profilePostModel = $this->_getProfilePostModel();
     $searchId = $this->_input->filterSingle('search_id', XenForo_Input::UINT);
     if (!$searchId) {
         return $this->findNewProfilePosts();
     }
     $searchModel = $this->_getSearchModel();
     $search = $searchModel->getSearchById($searchId);
     if (!$search || $search['user_id'] != XenForo_Visitor::getUserId() || $search['search_type'] != 'new-profile-posts') {
         return $this->findNewProfilePosts();
     }
     $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
     $perPage = XenForo_Application::get('options')->messagesPerPage;
     $pageResultIds = $searchModel->sliceSearchResultsToPage($search, $page, $perPage);
     $profilePostIds = XenForo_Application::arrayColumn($pageResultIds, 1);
     $profilePostsMatched = $profilePostModel->getProfilePostsByIds($profilePostIds, array('join' => XenForo_Model_ProfilePost::FETCH_USER_POSTER | XenForo_Model_ProfilePost::FETCH_USER_RECEIVER | XenForo_Model_ProfilePost::FETCH_USER_RECEIVER_PRIVACY, 'likeUserId' => XenForo_Visitor::getUserId(), 'permissionCombinationId' => XenForo_Visitor::getInstance()->permission_combination_id));
     $profilePosts = array();
     $inlineModOptions = array();
     foreach ($profilePostIds as $profilePostId) {
         if (!isset($profilePostsMatched[$profilePostId])) {
             continue;
         }
         $profilePost = $profilePostsMatched[$profilePostId];
         $receivingUser = $profilePostModel->getProfileUserFromProfilePost($profilePost);
         if (!$profilePostModel->canViewProfilePostAndContainer($profilePost, $receivingUser)) {
             continue;
         }
         $profilePost = $profilePostModel->prepareProfilePost($profilePost, $receivingUser);
         $inlineModOptions += $profilePostModel->addInlineModOptionToProfilePost($profilePost, $receivingUser);
         $profilePosts[$profilePost['profile_post_id']] = $profilePost;
     }
     if (!$profilePosts) {
         return $this->getNoProfilePostsResponse();
     }
     $ignoredNames = $this->_getIgnoredContentUserNames($profilePosts);
     $profilePosts = $profilePostModel->addProfilePostCommentsToProfilePosts($profilePosts, array('join' => XenForo_Model_ProfilePost::FETCH_COMMENT_USER));
     foreach ($profilePosts as &$profilePost) {
         if (empty($profilePost['comments'])) {
             continue;
         }
         foreach ($profilePost['comments'] as &$comment) {
             $comment = $profilePostModel->prepareProfilePostComment($comment, $profilePost, $profilePost['profileUser']);
         }
         $ignoredNames += $this->_getIgnoredContentUserNames($profilePost['comments']);
     }
     $resultStartOffset = ($page - 1) * $perPage + 1;
     $resultEndOffset = ($page - 1) * $perPage + count($profilePostIds);
     $viewParams = array('search' => $search, 'profilePosts' => $profilePosts, 'inlineModOptions' => $inlineModOptions, 'startOffset' => $resultStartOffset, 'endOffset' => $resultEndOffset, 'ignoredNames' => $ignoredNames, 'page' => $page, 'perPage' => $perPage, 'total' => $search['result_count'], 'nextPage' => $resultEndOffset < $search['result_count'] ? $page + 1 : 0, 'canUpdateStatus' => XenForo_Visitor::getInstance()->canUpdateStatus());
     return $this->getFindNewWrapper($this->responseView('XenForo_ViewPublic_FindNew_ProfilePosts', 'find_new_profile_posts', $viewParams), 'profile_posts');
 }
Beispiel #25
0
 public function alertTaggedMembers(array $comment, array $tagged)
 {
     /** @var $albumModel XenGallery_Model_Album */
     $albumModel = $this->getModelFromCache('XenGallery_Model_Album');
     $album = array();
     if ($comment['album_id']) {
         $album = $albumModel->getAlbumById($comment['album_id']);
         $album = $albumModel->prepareAlbumWithPermissions($album);
     }
     $userIds = XenForo_Application::arrayColumn($tagged, 'user_id');
     $alertedUserIds = array();
     if ($userIds) {
         $userModel = $this->getModelFromCache('XenForo_Model_User');
         $users = $userModel->getUsersByIds($userIds, array('join' => XenForo_Model_User::FETCH_USER_FULL | XenForo_Model_User::FETCH_USER_PERMISSIONS));
         foreach ($users as $user) {
             if (!isset($alertedUserIds[$user['user_id']]) && $user['user_id'] != $comment['user_id']) {
                 $canViewMedia = true;
                 if ($album) {
                     $user['permissions'] = @unserialize($user['global_permission_cache']);
                     if (!$albumModel->canViewAlbum($album, $null, $user)) {
                         $canViewMedia = false;
                     }
                 }
                 if (!$userModel->isUserIgnored($user, $comment['user_id']) && XenForo_Model_Alert::userReceivesAlert($user, 'xengallery_comment', 'tag') && $canViewMedia) {
                     $alertedUserIds[$user['user_id']] = true;
                     XenForo_Model_Alert::alert($user['user_id'], $comment['user_id'], $comment['username'], 'xengallery_comment', $comment['comment_id'], 'tag');
                 }
             }
         }
     }
     return array_keys($alertedUserIds);
 }