Ejemplo n.º 1
0
 /**
  * Gets the visible reports of this content type for the viewing user.
  *
  * @see XenForo_ReportHandler_Abstract:getVisibleReportsForUser()
  */
 public function getVisibleReportsForUser(array $reports, array $viewingUser)
 {
     $reportsByForum = array();
     foreach ($reports as $reportId => $report) {
         $info = unserialize($report['content_info']);
         $reportsByForum[$info['node_id']][] = $reportId;
     }
     /* @var $forumModel XenForo_Model_Forum */
     $forumModel = XenForo_Model::create('XenForo_Model_Forum');
     $forums = $forumModel->getForumsByIds(array_keys($reportsByForum), array('permissionCombinationId' => $viewingUser['permission_combination_id']));
     $forums = $forumModel->unserializePermissionsInList($forums, 'node_permission_cache');
     foreach ($reportsByForum as $forumId => $forumReports) {
         $remove = false;
         if (!isset($forums[$forumId])) {
             $remove = true;
         } else {
             $forum = $forums[$forumId];
             if (!XenForo_Permission::hasContentPermission($forum['permissions'], 'editAnyPost') && !XenForo_Permission::hasContentPermission($forum['permissions'], 'deleteAnyPost')) {
                 $remove = true;
             }
         }
         if ($remove) {
             foreach ($forumReports as $reportId) {
                 unset($reports[$reportId]);
             }
         }
     }
     return $reports;
 }
Ejemplo n.º 2
0
 public function getPermissionsFromContext(array $context, array $parentContext = null)
 {
     if (isset($context['thread_id'])) {
         $thread = $context;
         $forum = $parentContext;
     } else {
         $thread = null;
         $forum = $context;
     }
     if (!$forum || !isset($forum['node_id'])) {
         throw new Exception("Context must be a thread and a forum or just a forum");
     }
     $visitor = XenForo_Visitor::getInstance();
     // creating a new thread (all tags would be by us)
     $nodePermissions = $visitor->getNodePermissions($forum['node_id']);
     if ($thread) {
         if ($thread['user_id'] == $visitor['user_id'] && XenForo_Permission::hasContentPermission($nodePermissions, 'manageOthersTagsOwnThread')) {
             $removeOthers = true;
         } else {
             $removeOthers = XenForo_Permission::hasContentPermission($nodePermissions, 'manageAnyTag');
         }
     } else {
         $removeOthers = false;
     }
     return array('edit' => $this->_getThreadModel()->canEditTags($thread, $forum), 'removeOthers' => $removeOthers, 'minTotal' => $forum['min_tags']);
 }
Ejemplo n.º 3
0
 /**
  * Gets the effective data that can be pushed up to a parent node.
  *
  * @param array $node Current node info
  * @param array $childPushable List of pushable data from all child nodes: [node id] => pushable data
  * @param array $permissions Permissions for this node
  *
  * @return array List of pushable data (key-value pairs)
  */
 public function getPushableDataForNode(array $node, array $childPushable, array $permissions)
 {
     if (!XenForo_Permission::hasContentPermission($permissions, 'viewOthers')) {
         return $this->_compileForumLikePushableData(array('privateInfo' => true), $childPushable);
     }
     return $this->_getForumLikePushableData($node, $childPushable);
 }
Ejemplo n.º 4
0
 /**
  * Gets visible moderation queue entries for specified user.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::getVisibleModerationQueueEntriesForUser()
  */
 public function getVisibleModerationQueueEntriesForUser(array $contentIds, array $viewingUser)
 {
     /* @var $resourceModel XenResource_Model_Resource */
     $resourceModel = XenForo_Model::create('XenResource_Model_Resource');
     $resources = $resourceModel->getResourcesByIds($contentIds, array('join' => XenResource_Model_Resource::FETCH_DESCRIPTION));
     $categories = XenForo_Model::create('XenResource_Model_Category')->getAllCategories(array('permissionCombinationId' => $viewingUser['permission_combination_id']));
     $output = array();
     foreach ($resources as $resource) {
         if (!isset($categories[$resource['resource_category_id']])) {
             continue;
         }
         $category = $categories[$resource['resource_category_id']];
         $categoryPermissions = XenForo_Permission::unserializePermissions($category['category_permission_cache']);
         $canManage = true;
         if (!$resourceModel->canViewResourceAndContainer($resource, $category, $null, $viewingUser, $categoryPermissions)) {
             $canManage = false;
         } else {
             if (!XenForo_Permission::hasContentPermission($categoryPermissions, 'editAny') || !XenForo_Permission::hasContentPermission($categoryPermissions, 'deleteAny') || !XenForo_Permission::hasContentPermission($categoryPermissions, 'approveUnapprove')) {
                 $canManage = false;
             }
         }
         if ($canManage) {
             $output[$resource['resource_id']] = array('message' => $resource['description'], 'user' => array('user_id' => $resource['user_id'], 'username' => $resource['username']), 'title' => $resource['title'], 'link' => XenForo_Link::buildPublicLink('resources', $resource), 'contentTypeTitle' => new XenForo_Phrase('resource'), 'titleEdit' => true);
         }
     }
     return $output;
 }
Ejemplo n.º 5
0
 public function Tinhte_XenTag_getMaximumHashtags(array $forum, array $nodePermissions = null, array $viewingUser = null)
 {
     if (!Tinhte_XenTag_Option::get('useHashtag')) {
         return 0;
     }
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     return XenForo_Permission::hasContentPermission($nodePermissions, 'Tinhte_XenTag_maximumHts');
 }
Ejemplo n.º 6
0
 protected function _canMakeAnonymousPost($userId, $nodeId)
 {
     $userFetchOptions = array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS);
     $user = $this->_getUserModel()->getUserById($userId, $userFetchOptions);
     $user['permissions'] = @unserialize($user['global_permission_cache']);
     $nodePermissions = $this->_getNodeModel()->getNodePermissionsForPermissionCombination($user['permission_combination_id']);
     return XenForo_Permission::hasContentPermission($nodePermissions[$nodeId], 'postAnonymousReply');
 }
Ejemplo n.º 7
0
 public function canViewForum(array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $canView = parent::canViewForum($forum, $errorPhraseKey, $nodePermissions, $viewingUser);
     if ($canView && isset($GLOBALS['BRETI_ExtraThreadItem'])) {
         $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
         $canView = XenForo_Permission::hasContentPermission($nodePermissions, 'viewOthers');
     }
     return $canView;
 }
Ejemplo n.º 8
0
 /**
  * Determines if a moderation of replies in a thread can be enabled or
  * disabled in the specified forum with the given permissions.
  *
  * @param array $forum
  * @param string $errorPhraseKey
  * @param array|null $nodePermissions
  * @param array|null $viewingUser
  *
  * @return boolean
  */
 public function canEnableDisableModerateRepliesInForum(array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     if (!$viewingUser['user_id']) {
         return false;
     }
     if ($forum['moderate_replies']) {
         return false;
     }
     return XenForo_Permission::hasContentPermission($nodePermissions, 'enableModerateReplies');
 }
Ejemplo n.º 9
0
 /**
  * Determines if the forum can be watched with the given permissions.
  * This does not check forum viewing permissions.
  *
  * @param array $forum
  * @param string $errorPhraseKey
  * @param array|null $nodePermissions
  * @param array|null $viewingUser
  *
  * @return boolean
  */
 public function canWatchForum(array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     if (!parent::canWatchForum($forum, $errorPhraseKey, $nodePermissions, $viewingUser)) {
         return false;
     }
     if (!empty($forum['forum_is_watched'])) {
         return true;
     }
     return XenForo_Permission::hasContentPermission($nodePermissions, 'watchForum');
 }
Ejemplo n.º 10
0
 public function canAddResource(array $category = null, &$errorPhraseKey = '', array $viewingUser = null, array $categoryPermissions = null)
 {
     $canAddResource = parent::canAddResource($category, $errorPhraseKey, $viewingUser, $categoryPermissions);
     if ($category and !$canAddResource) {
         if (!empty($category['bdpaygate_allow_commercial_local'])) {
             $this->standardizeViewingUserReferenceForCategory($category, $viewingUser, $categoryPermissions);
             if (XenForo_Permission::hasContentPermission($categoryPermissions, 'add')) {
                 $canAddResource = true;
             }
         }
     }
     return $canAddResource;
 }
Ejemplo n.º 11
0
 public function getPostInsertMessageState(array $thread, array $forum, array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     if ($viewingUser['user_id'] && XenForo_Permission::hasContentPermission($nodePermissions, 'approveUnapprove')) {
         // do nothing
     } elseif ($viewingUser['user_id'] && XenForo_Permission::hasContentPermission($nodePermissions, 'enableModerateReplies')) {
         // do nothing
     } elseif (XenForo_Permission::hasPermission($viewingUser['permissions'], 'general', 'followModerationRules')) {
         if (!empty($thread['thread_id']) && $thread['moderate_replies_th']) {
             return 'moderated';
         }
     }
     return parent::getPostInsertMessageState($thread, $forum, $nodePermissions, $viewingUser);
 }
Ejemplo n.º 12
0
 public function save()
 {
     $response = parent::save();
     if (!empty($this->_newData['xf_post']['thread_id']) && !empty($this->_newData['xf_post']['post_id'])) {
         $options = XenForo_Application::get('options');
         if ($options->dark_taigachat_activity != 'None') {
             $visitor = XenForo_Visitor::getInstance();
             $isThread = $this->_newData['xf_post']['position'] == 0;
             /** @var XenForo_Model_Thread */
             $threadModel = XenForo_Model::create("XenForo_Model_Thread");
             $thread = $threadModel->getThreadById($this->_newData['xf_post']['thread_id']);
             /** @var XenForo_Model_Node */
             $nodeModel = XenForo_Model::create("XenForo_Model_Node");
             $node = $nodeModel->getNodeById($thread['node_id']);
             $ok = false;
             // making the not-too-risky assumption that 1 will be guest group
             $permissionCombinationId = 1;
             if ($options->dark_taigachat_activity_userid > 0) {
                 /** @var XenForo_Model_User */
                 $userModel = XenForo_Model::create("XenForo_Model_User");
                 $activityUser = $userModel->getUserById($options->dark_taigachat_activity_userid);
                 $permissionCombinationId = $activityUser['permission_combination_id'];
             }
             $nodePermissions = $nodeModel->getNodePermissionsForPermissionCombination($permissionCombinationId);
             foreach ($nodePermissions as $nodeId => $nodePermission) {
                 if ($nodeId == $node['node_id'] && XenForo_Permission::hasContentPermission($nodePermission, 'view') && XenForo_Permission::hasContentPermission($nodePermission, 'viewOthers')) {
                     $ok = true;
                 }
             }
             if ($ok) {
                 if ($isThread) {
                     $activityMessage = new XenForo_Phrase('dark_posted_new_thread_in_x_x', array('forum' => "[url='" . XenForo_Link::convertUriToAbsoluteUri(XenForo_Link::buildPublicLink("forums", $node), true) . "']" . $node['title'] . "[/url]", 'thread' => "[url='" . XenForo_Link::convertUriToAbsoluteUri(XenForo_Link::buildPublicLink("threads", $thread), true) . "']" . $thread['title'] . "[/url]"), false);
                 } else {
                     $activityMessage = new XenForo_Phrase('dark_replied_to_x', array('thread' => "[url='" . XenForo_Link::convertUriToAbsoluteUri(XenForo_Link::buildPublicLink("posts", $this->_newData['xf_post']), true) . "']" . $thread['title'] . "[/url]"), false);
                 }
                 if ($isThread || $options->dark_taigachat_activity == 'Both') {
                     $dw = XenForo_DataWriter::create('Dark_TaigaChat_DataWriter_Message');
                     $dw->setOption(Dark_TaigaChat_DataWriter_Message::OPTION_IS_AUTOMATED, true);
                     $dw->set('user_id', $visitor['user_id']);
                     $dw->set('username', $visitor['user_id'] > 0 ? $visitor['username'] : new XenForo_Phrase('guest'));
                     $dw->set('message', $activityMessage);
                     $dw->set('activity', 1);
                     $dw->save();
                 }
             }
         }
     }
     return $response;
 }
Ejemplo n.º 13
0
 public function getAttachmentConstraints()
 {
     $constraints = parent::getAttachmentConstraints();
     $visitor = XenForo_Visitor::getInstance();
     if (SV_AttachmentImprovements_Globals::$nodePermissionsForAttachments) {
         $nodePermissions = SV_AttachmentImprovements_Globals::$nodePermissionsForAttachments;
         $size = XenForo_Permission::hasContentPermission($nodePermissions, 'attach_size');
         if ($size > 0 && $size < $constraints['size']) {
             $constraints['size'] = $size * 1024;
         }
         $count = XenForo_Permission::hasContentPermission($nodePermissions, 'attach_count');
         if ($count > 0 && $count < $constraints['count']) {
             $constraints['count'] = $count;
         }
     }
     return $constraints;
 }
Ejemplo n.º 14
0
 public function canReplyToThread(array $thread, array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $canReplyToThread = parent::canReplyToThread($thread, $forum, $errorPhraseKey, $nodePermissions, $viewingUser);
     if ($canReplyToThread and !empty($thread['discussion_type']) and $thread['discussion_type'] === 'resource') {
         // check for resource permission
         $resource = $this->_bdPaygate_getResourceByThreadId($thread['thread_id']);
         if (!empty($resource) and $this->_bdPaygate_getResourceModel()->bdPaygate_mustPurchaseToDownload($resource, $viewingUser)) {
             // this is a paid resource, check for discussion permission
             $this->standardizeViewingUserReferenceForNode($thread['node_id'], $viewingUser, $nodePermissions);
             if (XenForo_Permission::hasContentPermission($nodePermissions, 'bdPaygate_allThreads')) {
                 return true;
             } elseif (!$this->_bdPaygate_getResourceModel()->canDownloadResource($resource, $resource, $null, $viewingUser)) {
                 return false;
             }
         }
     }
     return $canReplyToThread;
 }
Ejemplo n.º 15
0
 /**
  * Gets visible moderation queue entries for specified user.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::getVisibleModerationQueueEntriesForUser()
  */
 public function getVisibleModerationQueueEntriesForUser(array $contentIds, array $viewingUser)
 {
     $socialForumModel = ThemeHouse_SocialGroups_SocialForum::getSocialForumModel();
     $socialForums = $socialForumModel->getSocialForumsByIds($contentIds, array('join' => ThemeHouse_SocialGroups_Model_SocialForum::FETCH_FORUM | ThemeHouse_SocialGroups_Model_SocialForum::FETCH_USER, 'permissionCombinationId' => $viewingUser['permission_combination_id']));
     $output = array();
     foreach ($socialForums as $socialForum) {
         $socialForum['permissions'] = XenForo_Permission::unserializePermissions($socialForum['node_permission_cache']);
         $canManage = true;
         if (!$socialForumModel->canViewSocialForum($socialForum, $null, $socialForum['permissions'], $viewingUser)) {
             $canManage = false;
         } elseif (!XenForo_Permission::hasContentPermission($socialForum['permissions'], 'editSocialForum') || !XenForo_Permission::hasContentPermission($socialForum['permissions'], 'deleteSocialForum')) {
             $canManage = false;
         }
         if ($canManage) {
             $output[$socialForum['social_forum_id']] = array('message' => $socialForum['description'], 'user' => array('user_id' => $socialForum['user_id'], 'username' => $socialForum['username']), 'title' => $socialForum['title'], 'link' => XenForo_Link::buildPublicLink('social-forums', $socialForum), 'contentTypeTitle' => new XenForo_Phrase('th_social_forum_socialgroups'), 'titleEdit' => true);
         }
     }
     return $output;
 }
Ejemplo n.º 16
0
 /**
  * Gets visible moderation queue entries for specified user.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::getVisibleModerationQueueEntriesForUser()
  */
 public function getVisibleModerationQueueEntriesForUser(array $contentIds, array $viewingUser)
 {
     /* @var $threadModel XenForo_Model_Thread */
     $threadModel = XenForo_Model::create('XenForo_Model_Thread');
     $threads = $threadModel->getThreadsByIds($contentIds, array('join' => XenForo_Model_Thread::FETCH_FORUM | XenForo_Model_Thread::FETCH_FIRSTPOST, 'permissionCombinationId' => $viewingUser['permission_combination_id']));
     $output = array();
     foreach ($threads as $thread) {
         $thread['permissions'] = XenForo_Permission::unserializePermissions($thread['node_permission_cache']);
         $canManage = true;
         if (!$threadModel->canViewThreadAndContainer($thread, $thread, $null, $thread['permissions'], $viewingUser)) {
             $canManage = false;
         } else {
             if (!XenForo_Permission::hasContentPermission($thread['permissions'], 'editAnyPost') || !XenForo_Permission::hasContentPermission($thread['permissions'], 'deleteAnyThread')) {
                 $canManage = false;
             }
         }
         if ($canManage) {
             $output[$thread['thread_id']] = array('message' => $thread['message'], 'user' => array('user_id' => $thread['user_id'], 'username' => $thread['username']), 'title' => $thread['title'], 'link' => XenForo_Link::buildPublicLink('threads', $thread), 'contentTypeTitle' => new XenForo_Phrase('thread'), 'titleEdit' => true);
         }
     }
     return $output;
 }
Ejemplo n.º 17
0
 /**
  * Gets visible moderation queue entries for specified user.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::getVisibleModerationQueueEntriesForUser()
  */
 public function getVisibleModerationQueueEntriesForUser(array $contentIds, array $viewingUser)
 {
     /* @var $postModel XenForo_Model_Post */
     $postModel = XenForo_Model::create('XenForo_Model_Post');
     $posts = $postModel->getPostsByIds($contentIds, array('join' => XenForo_Model_Post::FETCH_THREAD | XenForo_Model_Post::FETCH_FORUM, 'permissionCombinationId' => $viewingUser['permission_combination_id']));
     $output = array();
     foreach ($posts as $post) {
         $post['permissions'] = XenForo_Permission::unserializePermissions($post['node_permission_cache']);
         $canManage = true;
         if (!$postModel->canViewPostAndContainer($post, $post, $post, $null, $post['permissions'], $viewingUser)) {
             $canManage = false;
         } else {
             if (!XenForo_Permission::hasContentPermission($post['permissions'], 'editAnyPost') || !XenForo_Permission::hasContentPermission($post['permissions'], 'deleteAnyPost')) {
                 $canManage = false;
             }
         }
         if ($canManage) {
             $output[$post['post_id']] = array('message' => $post['message'], 'user' => array('user_id' => $post['user_id'], 'username' => $post['username']), 'title' => new XenForo_Phrase('post_in_thread_x', array('title' => $post['title'])), 'link' => XenForo_Link::buildPublicLink('posts', $post), 'contentTypeTitle' => new XenForo_Phrase('post'), 'titleEdit' => false);
         }
     }
     return $output;
 }
Ejemplo n.º 18
0
 /**
  * Gets visible moderation queue entries for specified user.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::getVisibleModerationQueueEntriesForUser()
  */
 public function getVisibleModerationQueueEntriesForUser(array $contentIds, array $viewingUser)
 {
     /* @var $versionModel XenResource_Model_Version */
     $versionModel = XenForo_Model::create('XenResource_Model_Version');
     $versions = $versionModel->getVersionsByIds($contentIds);
     $categories = XenForo_Model::create('XenResource_Model_Category')->getAllCategories(array('permissionCombinationId' => $viewingUser['permission_combination_id']));
     /* @var $resourceModel XenResource_Model_Resource */
     $resourceModel = XenForo_Model::create('XenResource_Model_Resource');
     $resourceIds = array();
     foreach ($versions as $version) {
         $resourceIds[] = $version['resource_id'];
     }
     $resources = $resourceModel->getResourcesByIds($resourceIds);
     $output = array();
     foreach ($versions as $version) {
         if (!isset($resources[$version['resource_id']])) {
             continue;
         }
         $resource = $resources[$version['resource_id']];
         if (!isset($categories[$resource['resource_category_id']])) {
             continue;
         }
         $category = $categories[$resource['resource_category_id']];
         $categoryPermissions = XenForo_Permission::unserializePermissions($category['category_permission_cache']);
         $canManage = true;
         if (!$resourceModel->canViewResourceAndContainer($resource, $category, $null, $viewingUser, $categoryPermissions) || !$versionModel->canDownloadVersion($version, $resource, $category, $null, $viewingUser, $categoryPermissions)) {
             $canManage = false;
         } else {
             if (!XenForo_Permission::hasContentPermission($categoryPermissions, 'deleteAny') || !XenForo_Permission::hasContentPermission($categoryPermissions, 'approveUnapprove')) {
                 $canManage = false;
             }
         }
         if ($canManage) {
             $output[$version['resource_version_id']] = array('message' => $version['version_string'], 'user' => array('user_id' => $resource['user_id'], 'username' => $resource['username']), 'title' => $resource['title'] . ' ' . $version['version_string'], 'link' => XenForo_Link::buildPublicLink('resources/history', $resource), 'contentTypeTitle' => new XenForo_Phrase('resource_version'), 'titleEdit' => false);
         }
     }
     return $output;
 }
Ejemplo n.º 19
0
 /**
  * Determines if a thread can be stuck or unstuck in the specified forum
  * with the given permissions.
  *
  * @param array $forum
  * @param string $errorPhraseKey
  * @param array|null $nodePermissions
  * @param array|null $viewingUser
  *
  * @return boolean
  */
 public function canStickUnstickThreadInForum(array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     if (!$viewingUser['user_id']) {
         return false;
     }
     return XenForo_Permission::hasContentPermission($nodePermissions, 'stickUnstickThread');
 }
Ejemplo n.º 20
0
 public function hasPreview(array $thread, array $forum, array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($thread['node_id'], $viewingUser, $nodePermissions);
     return $thread['first_post_id'] && XenForo_Application::get('options')->discussionPreviewLength && $this->isRedirect($thread) == false && XenForo_Permission::hasContentPermission($nodePermissions, 'viewContent');
 }
Ejemplo n.º 21
0
 /**
  * Determines if the visitor has the specified permission on a specific node.
  *
  * @param integer $nodeId
  * @param string $permission
  *
  * @return boolean
  */
 public function hasNodePermission($nodeId, $permission)
 {
     return XenForo_Permission::hasContentPermission($this->getNodePermissions($nodeId), $permission);
 }
Ejemplo n.º 22
0
 public function sendNotificationToWatchUsersOnTagged($tag, array $contentData = array(), array $contentPermissionConfig = array())
 {
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     list($noEmail, $noAlert) = Tinhte_XenTag_Integration::getNoEmailAndAlert($contentData['content_type'], $contentData['content_id']);
     $emailed = array();
     $alerted = array();
     $emailTemplate = 'tinhte_xentag_watch_tag_' . $contentData['content_type'];
     if (XenForo_Application::get('options')->emailWatchedThreadIncludeMessage) {
         $parseBbCode = true;
     } else {
         $parseBbCode = false;
     }
     // fetch a full user record if we don't have one already
     if (!isset($contentData['avatar_width']) or !isset($contentData['custom_title'])) {
         $contentUser = $userModel->getUserById($contentData['user_id']);
         if ($contentUser) {
             $contentData = array_merge($contentUser, $contentData);
         } else {
             $contentData['avatar_width'] = 0;
             $contentData['custom_title'] = '';
         }
     }
     if (!empty($contentPermissionConfig['content_type']) and !empty($contentPermissionConfig['content_id'])) {
         $users = $this->getUsersWatchingTag($tag['tag_id'], $contentPermissionConfig['content_type'], $contentPermissionConfig['content_id']);
     } else {
         $users = $this->getUsersWatchingTag($tag['tag_id']);
     }
     foreach ($users as $user) {
         if ($user['user_id'] == $contentData['user_id']) {
             // self notification? That's silly
             continue;
         }
         if ($userModel->isUserIgnored($user, $contentData['user_id'])) {
             continue;
         }
         $globalPermissions = XenForo_Permission::unserializePermissions($user['global_permission_cache']);
         if (!XenForo_Permission::hasPermission($globalPermissions, 'general', Tinhte_XenTag_Constants::PERM_USER_WATCH)) {
             // no tag watch permission (or revoked)
             continue;
         }
         if (!empty($contentPermissionConfig['content_type']) and !empty($contentPermissionConfig['content_id']) and !empty($contentPermissionConfig['permissions'])) {
             $contentPermissions = XenForo_Permission::unserializePermissions($user['content_permission_cache']);
             $contentPermissionFound = true;
             foreach ($contentPermissionConfig['permissions'] as $contentPermissionRequired) {
                 if (!XenForo_Permission::hasContentPermission($contentPermissions, $contentPermissionRequired)) {
                     $contentPermissionFound = false;
                 }
             }
             if (!$contentPermissionFound) {
                 // no content permission
                 continue;
             }
         }
         if ($user['send_email'] and $user['email'] and $user['user_state'] == 'valid' and !in_array($user['user_id'], $noEmail)) {
             if (!empty($contentData['message']) and !isset($contentData['messageText']) and $parseBbCode) {
                 $bbCodeParserText = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Text'));
                 $contentData['messageText'] = new XenForo_BbCode_TextWrapper($contentData['message'], $bbCodeParserText);
                 $bbCodeParserHtml = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
                 $contentData['messageHtml'] = new XenForo_BbCode_TextWrapper($contentData['message'], $bbCodeParserHtml);
             }
             if (!empty($contentData['title']) and !isset($contentData['titleCensored'])) {
                 $contentData['titleCensored'] = XenForo_Helper_String::censorString($contentData['title']);
             }
             $user['email_confirm_key'] = $userModel->getUserEmailConfirmKey($user);
             $mail = XenForo_Mail::create($emailTemplate, array('tag' => $tag, 'contentType' => $contentData['content_type'], 'contentId' => $contentData['content_id'], 'contentData' => $contentData, 'receiver' => $user), $user['language_id']);
             $mail->enableAllLanguagePreCache();
             $mail->queue($user['email'], $user['username']);
             $emailed[] = $user['user_id'];
         }
         if ($user['send_alert'] and !in_array($user['user_id'], $noAlert)) {
             call_user_func_array(array('XenForo_Model_Alert', 'alert'), array($user['user_id'], $contentData['user_id'], $contentData['username'], $contentData['content_type'], $contentData['content_id'], 'tinhte_xentag_tag_watch', array('tag' => $tag)));
             $alerted[] = $user['user_id'];
         }
     }
     Tinhte_XenTag_Integration::updateNoEmailAndAlert($contentData['content_type'], $contentData['content_id'], $emailed, $alerted);
 }
Ejemplo n.º 23
0
 public function canViewWidgetPage(array $widgetPage, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($widgetPage['node_id'], $viewingUser, $nodePermissions);
     return XenForo_Permission::hasContentPermission($nodePermissions, 'view');
 }
Ejemplo n.º 24
0
 /**
  * Determines if a new anonymous reply can be posted in the specified forum,
  * with the given permissions. If no permissions are specified, permissions
  * are retrieved from the currently visiting user. This does not check viewing permissions.
  *
  * @param array $forum Info about the forum posting in
  * @param string $errorPhraseKey Returned phrase key for a specific error
  * @param array|null $nodePermissions
  * @param array|null $viewingUser
  *
  * @return boolean
  */
 public function canPostAnonymousReplyInForum(array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     return XenForo_Permission::hasContentPermission($nodePermissions, 'postAnonymousReply');
 }
Ejemplo n.º 25
0
 /**
  * Determines if a user can view check outs for a given resource.
  * Does not check viewing perms.
  *
  * @param array $resource
  * @param array $category
  * @param string $errorPhraseKey
  * @param array $viewingUser
  * @param array|null $categoryPermissions
  *
  * @return boolean
  */
 public function canViewCheckInsAndOuts(array $resource, array $category, &$errorPhraseKey = '', array $viewingUser = null, array $categoryPermissions = null)
 {
     $this->standardizeViewingUserReferenceForCategory($category, $viewingUser, $categoryPermissions);
     return $viewingUser['user_id'] && XenForo_Permission::hasContentPermission($categoryPermissions, 'viewCheckOut');
 }
Ejemplo n.º 26
0
 /**
  * Gets permission-based conditions that apply to thread fetching functions.
  *
  * @param array $forum Forum the threads will belong to
  * @param array|null $nodePermissions
  * @param array|null $viewingUser
  *
  * @return array Keys: deleted (boolean), moderated (boolean or integer, if can only view single user's)
  */
 public function getPermissionBasedThreadFetchConditions(array $forum, array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     if (XenForo_Permission::hasContentPermission($nodePermissions, 'viewModerated')) {
         $viewModerated = true;
     } else {
         if ($viewingUser['user_id']) {
             $viewModerated = $viewingUser['user_id'];
         } else {
             $viewModerated = false;
         }
     }
     return array('deleted' => XenForo_Permission::hasContentPermission($nodePermissions, 'viewDeleted'), 'moderated' => $viewModerated);
 }
Ejemplo n.º 27
0
 public function canViewExtraThreads(array $thread, array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($thread['node_id'], $viewingUser, $nodePermissions);
     if (!XenForo_Permission::hasContentPermission($nodePermissions, 'BRETI_viewExtraThreads')) {
         return false;
     }
     return true;
 }
Ejemplo n.º 28
0
 public function Team_moveThread(array $thread, array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($thread['node_id'], $viewingUser, $nodePermissions);
     return $viewingUser['user_id'] && empty($thread['team_id']) && XenForo_Permission::hasContentPermission($nodePermissions, 'Team_moveThread');
 }
Ejemplo n.º 29
0
 public function actionSave()
 {
     $this->_assertPostOnly();
     $categoryModel = $this->_getCategoryModel();
     if ($resourceId = $this->_input->filterSingle('resource_id', XenForo_Input::UINT)) {
         list($resource, $category) = $this->_getResourceHelper()->assertResourceValidAndViewable($resourceId);
         if (!$this->_getResourceModel()->canEditResource($resource, $category, $errorPhraseKey)) {
             throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
         }
         $categoryPermissions = $categoryModel->getCategoryPermCache(null, $category['resource_category_id']);
         $canEditCategory = XenForo_Permission::hasContentPermission($categoryPermissions, 'editAny');
     } else {
         $category = false;
         $resource = false;
         $canEditCategory = true;
     }
     $resourceData = $this->_input->filter(array('resource_category_id' => XenForo_Input::UINT, 'title' => XenForo_Input::STRING, 'tag_line' => XenForo_Input::STRING, 'external_url' => XenForo_Input::STRING, 'alt_support_url' => XenForo_Input::STRING, 'prefix_id' => XenForo_Input::UINT));
     if (!$resourceData['resource_category_id']) {
         return $this->responseError(new XenForo_Phrase('you_must_select_category'));
     }
     $newCategory = $category;
     if ($canEditCategory) {
         if (!$resource || $resource['resource_category_id'] != $resourceData['resource_category_id']) {
             // new resource or changing category - let's make sure we can do that
             $newCategory = $this->_getResourceHelper()->assertCategoryValidAndViewable($resourceData['resource_category_id']);
             if (!$categoryModel->canAddResource($newCategory, $key)) {
                 throw $this->getErrorOrNoPermissionResponseException($key);
             }
         }
         $categoryId = $resourceData['resource_category_id'];
     } else {
         $categoryId = $resource['resource_category_id'];
         unset($resourceData['resource_category_id']);
     }
     if (!$resource || $resource['prefix_id'] != $resourceData['prefix_id'] || $resource['resource_category_id'] != $categoryId) {
         if (!$this->_getPrefixModel()->verifyPrefixIsUsable($resourceData['prefix_id'], $categoryId)) {
             $resourceData['prefix_id'] = 0;
             // not usable, just blank it out
         }
     }
     /* @var $dw XenResource_DataWriter_Resource */
     $dw = XenForo_DataWriter::create('XenResource_DataWriter_Resource');
     if ($resourceId) {
         $dw->setExistingData($resource['resource_id']);
     } else {
         $visitor = XenForo_Visitor::getInstance();
         $dw->set('user_id', $visitor['user_id']);
         $dw->set('username', $visitor['username']);
     }
     $dw->bulkSet($resourceData);
     if (!$resourceId || $newCategory['resource_category_id'] != $category['resource_category_id']) {
         if ($newCategory['always_moderate_create'] && ($dw->get('resource_state') == 'visible' || !$resourceId) && !XenForo_Visitor::getInstance()->hasPermission('resource', 'approveUnapprove')) {
             $dw->set('resource_state', 'moderated');
         }
     }
     if (!$resourceId) {
         $watch = XenForo_Visitor::getInstance()->default_watch_state;
         if (!$watch) {
             $watch = 'watch_no_email';
         }
         $dw->setExtraData(XenResource_DataWriter_Resource::DATA_THREAD_WATCH_DEFAULT, $watch);
     }
     $customFields = $this->_getResourceHelper()->getCustomFieldValues($null, $shownCustomFields);
     $dw->setCustomFields($customFields, $shownCustomFields);
     $extraData = $this->_input->filter(array('attachment_hash' => XenForo_Input::STRING, 'file_hash' => XenForo_Input::STRING, 'version_string' => XenForo_Input::STRING, 'resource_file_type' => XenForo_Input::STRING, 'download_url' => XenForo_Input::STRING, 'price' => XenForo_Input::UNUM, 'currency' => XenForo_Input::STRING, 'external_purchase_url' => XenForo_Input::STRING));
     $message = $this->getHelper('Editor')->getMessageText('message', $this->_input);
     $message = XenForo_Helper_String::autoLinkBbCode($message);
     $descriptionDw = $dw->getDescriptionDw();
     $descriptionDw->set('message', $message);
     $descriptionDw->setExtraData(XenResource_DataWriter_Update::DATA_ATTACHMENT_HASH, $extraData['attachment_hash']);
     $versionDw = $dw->getVersionDw();
     if (!$resourceId) {
         switch ($extraData['resource_file_type']) {
             case 'file':
                 if ($newCategory['allow_local']) {
                     $versionDw->setExtraData(XenResource_DataWriter_Version::DATA_ATTACHMENT_HASH, $extraData['file_hash']);
                 }
                 break;
             case 'url':
                 if ($newCategory['allow_external']) {
                     if (!$extraData['download_url']) {
                         $versionDw->error(new XenForo_Phrase('please_enter_external_download_url'), 'download_url');
                     } else {
                         $versionDw->set('download_url', $extraData['download_url']);
                     }
                 }
                 break;
             case 'commercial_external':
                 if ($newCategory['allow_commercial_external']) {
                     if (!$extraData['price'] || !$extraData['currency'] || !$extraData['external_purchase_url']) {
                         $dw->error(new XenForo_Phrase('please_complete_required_fields'));
                     } else {
                         $dw->bulkSet(array('is_fileless' => 1, 'price' => $extraData['price'], 'currency' => $extraData['currency'], 'external_purchase_url' => $extraData['external_purchase_url']));
                         $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
                     }
                 }
                 break;
             case 'fileless':
                 if ($newCategory['allow_fileless']) {
                     $dw->set('is_fileless', 1);
                     $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
                 }
                 break;
         }
     } else {
         if ($resource['external_purchase_url']) {
             // already an external purchase
             if (!$extraData['price'] || !$extraData['currency'] || !$extraData['external_purchase_url']) {
                 $dw->error(new XenForo_Phrase('please_complete_required_fields'));
             } else {
                 $dw->bulkSet(array('price' => $extraData['price'], 'currency' => $extraData['currency'], 'external_purchase_url' => $extraData['external_purchase_url']));
                 $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
             }
         }
     }
     if ($extraData['version_string'] === '') {
         $extraData['version_string'] = XenForo_Locale::date(XenForo_Application::$time, 'Y-m-d');
     }
     $versionDw->set('version_string', $extraData['version_string']);
     $dw->preSave();
     // when editing, we can only do this check if not changing the category
     if ($newCategory['require_prefix'] && !$dw->get('prefix_id') && (!$resource || $resource['resource_category_id'] == $newCategory['resource_category_id'])) {
         $dw->error(new XenForo_Phrase('please_select_a_prefix'), 'prefix_id');
     }
     if (!$dw->hasErrors()) {
         $this->assertNotFlooding('post');
         // use the action of "posting" as the trigger
     }
     $dw->save();
     $resource = $dw->getMergedData();
     $update = $descriptionDw->getMergedData();
     if ($dw->isUpdate() && XenForo_Visitor::getUserId() != $resource['user_id']) {
         $basicLog = $this->_getLogChanges($dw);
         if ($basicLog) {
             XenForo_Model_Log::logModeratorAction('resource', $resource, 'edit', $basicLog);
         }
         $basicLog = $this->_getLogChanges($descriptionDw);
         if ($basicLog) {
             XenForo_Model_Log::logModeratorAction('resource_update', $update, 'edit', $basicLog, $resource);
         }
     }
     if ($dw->isInsert()) {
         $this->_getDraftModel()->deleteDraft("resource-category-{$categoryId}");
     }
     if ($this->_input->filterSingle('edit_icon', XenForo_Input::BOOLEAN)) {
         XenForo_Application::getSession()->set('autoClickTrigger', '#EditIconTrigger');
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('resources', $resource));
 }
Ejemplo n.º 30
0
 /**
  * Determines if a thread can be created live with the given permissions.
  * This does not check thread viewing permissions.
  *
  * @param array $forum
  * @param string $errorPhraseKey
  * @param array|null $nodePermissions
  * @param array|null $viewingUser
  *
  * @return boolean
  */
 public function canLiveUnliveThreadInForum(array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
 {
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     return $viewingUser['user_id'] && XenForo_Permission::hasContentPermission($nodePermissions, 'liveUnliveThread');
 }