/** * 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); }
protected function _getAutoWarningAddEditResponse(array $autoWarning) { /* @var $warningModel XenForo_Model_Warning */ $warningModel = $this->getModelFromCache('XenForo_Model_Warning'); $warnings = $warningModel->prepareWarningDefinitions($warningModel->getWarningDefinitions()); $viewParams = array('autoWarning' => $autoWarning, 'warnings' => $warnings, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($autoWarning['user_criteria']), 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection()); return $this->responseView('ThemeHouse_AutoWarning_ViewAdmin_Warning_AutoAdd', 'th_auto_warning_add_autowarning', $viewParams); }
public function actionEdit() { $advId = $this->_input->filterSingle('adv_id', XenForo_Input::STRING); $addOnModel = $this->getModelFromCache('Turki_Adv_Model_Hooks'); $adv = $this->_getAdvOrError($advId); // die(var_dump($adv['post_criteria'])); $viewParams = array('userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection(''), 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection(), 'pageCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection(''), 'pageCriteriaData' => XenForo_Helper_Criteria::getDataForPageCriteriaSelection(), 'advs' => $adv, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($adv['user_criteria']), 'pageCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($adv['page_criteria']), 'postCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($adv['post_criteria']), 'hookOptions' => $addOnModel->getHooksListIfAvailable(), 'adv_display' => array('top' => new XenForo_Phrase('top'), 'bottom' => new XenForo_Phrase('bottom')), 'hookSelected' => isset($adv['adv_hook_name']) ? $adv['adv_hook_name'] : $addOnModel->getDefaultHook()); return $this->responseView('Turki_Adv_ViewAdmin_Edit', 'adv_xenfor_edit', $viewParams); }
public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) { $options = XenForo_Application::get('options'); $enableadvxenforo = $options->enableadvxenforo; $thread_id = $hookParams['thread']['thread_id']; if ($enableadvxenforo) { $PermissionEnable = XenForo_Visitor::getInstance()->hasPermission('adv_xenforo', 'adv_xenforo_enable_adv') ? TRUE : FALSE; if ($hookName == 'account_preferences_options' && $PermissionEnable) { $ourTemplate = $template->create('adv_xenforo_account_options', $template->getparams()); $rendered = $ourTemplate->render(); $contents = $contents . $rendered; } $hasPermission = XenForo_Visitor::getInstance()->hasPermission('adv_xenforo', 'adv_xenforo_show') ? TRUE : FALSE; $advs = XenForo_Application::getSimpleCacheData('adv_xenforo'); $user = XenForo_Visitor::getInstance()->toArray(); $enable_adv = $PermissionEnable === TRUE ? $user['enable_adv'] : TRUE; $containerData = self::$containerData; if (empty(self::$containerData)) { $containerData = XenForo_Template_Public::getExtraContainerData(); } if ($enable_adv) { if ($hasPermission === TRUE && $advs["AdvsHook"]) { $isMobile = XenForo_Visitor::isBrowsingWith('mobile'); switch (TRUE) { case $isMobile == TRUE: $adv_adv = 'adv_small'; break; default: $adv_adv = 'adv_large'; break; } foreach ($advs["AdvsHook"] as $_asv) { if ($_asv['active'] && XenForo_Helper_Criteria::userMatchesCriteria($_asv['user_criteria'], TRUE, $user) && XenForo_Helper_Criteria::pageMatchesCriteria($_asv['page_criteria'], TRUE, $template->getParams(), $containerData)) { $ourTemplate = $template->create('ads_xf_ar_xenforo', array('advanced' => $_asv[$adv_adv])); $rendered = $ourTemplate->render(); if ($hookName == 'message_content' && Turki_Adv_Helper_Criteria::postCriteria($_asv['post_criteria'], TRUE) === FALSE) { if ($hookParams['message']['thread_id']) { $decode = XenForo_Helper_Criteria::prepareCriteriaForSelection($_asv['post_criteria']); $position = $decode['active']['page'] ? $hookParams['message']['position'] % $options->messagesPerPage : $hookParams['message']['position']; if ($position == $decode['active']['post_id'] - 1) { $contents = $decode['active']['position'] ? Turki_Adv_Helper_Helpers::advhtml($contents, $rendered) : $contents . $rendered; } } } else { if ($hookName == $_asv['adv_hook_name'] && Turki_Adv_Helper_Criteria::postCriteria($_asv['post_criteria'], TRUE)) { $contents = $_asv['display'] == 'top' ? $rendered . $contents : $contents . $rendered; } } } } } } self::_templateHook($hookName, $contents, $hookParams, $template); } }
public function rebuildNoticeCache() { $cache = array(); foreach ($this->getAllNotices() as $noticeId => $notice) { if ($notice['active']) { $cache[$noticeId] = array('title' => $notice['title'], 'message' => $notice['message'], 'dismissible' => $notice['dismissible'], 'wrap' => $notice['wrap'], 'user_criteria' => XenForo_Helper_Criteria::unserializeCriteria($notice['user_criteria']), 'page_criteria' => XenForo_Helper_Criteria::unserializeCriteria($notice['page_criteria']), 'display_image' => $notice['display_image'], 'image_url' => $notice['image_url'], 'visibility' => $notice['visibility'], 'notice_type' => $notice['notice_type'], 'display_style' => $notice['display_style'], 'css_class' => $notice['css_class'], 'display_duration' => $notice['display_duration'], 'delay_duration' => $notice['delay_duration'], 'auto_dismiss' => $notice['auto_dismiss']); } } $this->_getDataRegistryModel()->set('notices', $cache); return $cache; }
/** * Verifies that the criteria is valid and formats is correctly. * Expected input format: [] with children: [rule] => name, [data] => info * * @param array|string $criteria Criteria array or serialize string; see above for format. Modified by ref. * * @return boolean */ protected function _verifyCriteria(&$criteria) { $criteriaFiltered = XenForo_Helper_Criteria::prepareCriteriaForSave($criteria); $criteria = serialize($criteriaFiltered); if (!$criteriaFiltered) { $this->error(new XenForo_Phrase('please_select_criteria_that_must_be_met'), 'user_criteria'); return false; } else { return true; } }
/** * Helper to get the tab rule add/edit form controller response. * * @param array $tabRule * * @return XenForo_ControllerResponse_View */ protected function _getTabRuleAddEditResponse(array $tabRule) { /* @var $tabNameModel Waindigo_Tabs_Model_TabName */ $tabNameModel = $this->getModelFromCache('Waindigo_Tabs_Model_TabName'); $tabNames = $tabNameModel->prepareTabNames($tabNameModel->getTabNames()); $tabModel = $this->_getTabModel(); $matchContentTypes = $tabModel->getMatchContentTypes(); $createContentTypes = $tabModel->getCreateContentTypes(); $viewParams = array('tabRule' => $tabRule, 'matchCriteria' => array($tabRule['match_content_type'] => XenForo_Helper_Criteria::prepareCriteriaForSelection($tabRule['match_criteria'])), 'matchCriteriaData' => Waindigo_Tabs_Helper_Criteria::getDataForMatchCriteriaSelection(), 'matchContentTypes' => $matchContentTypes, 'createCriteria' => array($tabRule['create_content_type'] => $tabRule['create_criteria'] ? unserialize($tabRule['create_criteria']) : array()), 'createCriteriaData' => Waindigo_Tabs_Helper_Criteria::getDataForCreateCriteriaSelection(), 'createContentTypes' => $createContentTypes, 'tabNames' => $tabNames, 'customMessage' => $this->_getTabRuleModel()->getTabRuleMasterCustomMessagePhraseValue($tabRule['tab_rule_id'])); return $this->responseView('Waindigo_Tabs_ViewAdmin_TabRule_Edit', 'waindigo_tab_rule_edit_tabs', $viewParams); }
public function rebuildNoticeCache() { $cache = array(); foreach ($this->getAllNotices() as $noticeId => $notice) { if ($notice['active']) { $cache[$noticeId] = array('title' => $notice['title'], 'message' => $notice['message'], 'dismissible' => $notice['dismissible'], 'wrap' => $notice['wrap'], 'user_criteria' => XenForo_Helper_Criteria::unserializeCriteria($notice['user_criteria']), 'page_criteria' => XenForo_Helper_Criteria::unserializeCriteria($notice['page_criteria'])); } } $this->_getDataRegistryModel()->set('notices', $cache); return $cache; }
/** * * @see sonnb_XenGallery_Model_Photo::passesPrivacyCheck() */ public function passesPrivacyCheck(array $photo, $type, $typeData, &$errorPhraseKey = '', array $viewingUser = null) { if (is_numeric($type)) { /* @var $privacyGroupModel ThemeHouse_PrivacyGroups_Model_PrivacyGroup */ $privacyGroupModel = $this->getModelFromCache('ThemeHouse_PrivacyGroups_Model_PrivacyGroup'); $privacyGroup = $privacyGroupModel->getPrivacyGroupById($type); if (!$privacyGroup) { return true; } return XenForo_Helper_Criteria::userMatchesCriteria($privacyGroup['user_criteria'], true, $viewingUser); } return parent::passesPrivacyCheck($photo, $type, $typeData, $errorPhraseKey, $viewingUser); }
/** * Verifies that the criteria is valid and formats is correctly. * Expected input format: [] with children: [rule] => name, [data] => info * * @param array|string $criteria Criteria array or serialize string; see above for format. Modified by ref. * * @return boolean */ protected function _verifyCriteria(&$criteria) { $criteria = XenForo_Helper_Criteria::unserializeCriteria($criteria); $criteriaFiltered = array(); foreach ($criteria as $criterion) { if (!empty($criterion['rule'])) { if (empty($criterion['data']) || !is_array($criterion['data'])) { $criterion['data'] = array(); } $criteriaFiltered[] = array('rule' => $criterion['rule'], 'data' => $criterion['data']); } } $criteria = serialize($criteriaFiltered); return true; }
/** * Helper to get the user spam rule add/edit form controller response. * * @param array $userSpamRule * * @return XenForo_ControllerResponse_View */ protected function _getUserSpamRuleAddEditResponse(array $userSpamRule) { $userSpamRule = $this->_getUserSpamRuleModel()->prepareUserSpamRule($userSpamRule); $isoCountries = array(); if (function_exists('geoip_country_code_by_name')) { $countries = preg_split("/\r\n|\n|\r/", XenForo_Application::get('options')->th_spamRules_countries); foreach ($countries as $countryId => $country) { preg_match('/([A-Z][0-9A-Z]),"?([^"]*)"?/', $country, $matches); if ($matches) { $isoCountries[$matches[1]] = $matches[2]; } } asort($isoCountries); } $viewParams = array('userSpamRule' => $userSpamRule, 'countries' => $isoCountries, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($userSpamRule['user_criteria']), 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection(), 'requestCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($userSpamRule['request_criteria'])); return $this->responseView('ThemeHouse_SpamRules_ViewAdmin_UserSpamRule_Edit', 'th_user_spam_rule_edit_spamrules', $viewParams); }
public function canTagUser(array $user, &$errorPhraseKey = '', array $viewingUser = null) { $this->standardizeViewingUserReference($viewingUser); if ($user['user_id'] == $viewingUser['user_id']) { return true; } /* END canTagUser */ if (is_numeric($user['xengallery']['allow_tagging'])) { /* @var $privacyGroupModel ThemeHouse_PrivacyGroups_Model_PrivacyGroup */ $privacyGroupModel = $this->getModelFromCache('ThemeHouse_PrivacyGroups_Model_PrivacyGroup'); $privacyGroup = $privacyGroupModel->getPrivacyGroupById($user['xengallery']['allow_tagging']); if (!$privacyGroup) { return true; } return XenForo_Helper_Criteria::userMatchesCriteria($privacyGroup['user_criteria'], true, $viewingUser); } return parent::canTagUser($user, $errorPhraseKey, $viewingUser); }
public static function processAutoWarnings() { /* @var $warningModel XenForo_Model_Warning */ $warningModel = XenForo_Model::create('XenForo_Model_Warning'); $queueEntries = $warningModel->getAllAutoWarningQueueEntries(); $entries = array(); foreach ($queueEntries as $queueEntry) { $entries[$queueEntry['content_type']][$queueEntry['content_id']] = $queueEntry; } if (isset($entries['post'])) { /* @var $postModel XenForo_Model_Post */ $postModel = XenForo_Model::create('XenForo_Model_Post'); $posts = $postModel->getPostsByIds(array_keys($entries['post']), array('join' => XenForo_Model_Post::FETCH_THREAD | XenForo_Model_Post::FETCH_USER)); foreach ($posts as $postId => $post) { $entries['post'][$postId] = array_merge($post, $entries['post'][$postId]); $entries['post'][$postId]['content_title'] = $post['title']; } } if (isset($entries['profile_post'])) { /* @var $profilePostModel XenForo_Model_Profile_Post */ $profilePostModel = XenForo_Model::create('XenForo_Model_ProfilePost'); $profilePosts = $profilePostModel->getProfilePostsByIds(array_keys($entries['profile_post']), array('join' => XenForo_Model_ProfilePost::FETCH_USER_RECEIVER | XenForo_Model_ProfilePost::FETCH_USER_POSTER)); $profilePostEntries = array(); foreach ($profilePosts as $profilePostId => $profilePost) { $profilePostEntries[$profilePostId] = array_merge($profilePost, $entries['profile_post'][$profilePostId]); } $entries['profile_post'] = $profilePostEntries; } $autoWarnings = $warningModel->prepareAutoWarnings($warningModel->getAutoWarnings(), true); foreach ($entries as $contentType => $contentTypeEntries) { foreach ($autoWarnings as $autoWarning) { if (!in_array($contentType, $autoWarning['contentTypes'])) { continue; } foreach ($contentTypeEntries as $contentId => $entry) { if (ThemeHouse_AutoWarning_Helper_Criteria::contentMatchesCriteria($autoWarning['contentCriteria'], true, $entry['message']) && XenForo_Helper_Criteria::userMatchesCriteria($autoWarning['user_criteria'], true, $entry)) { self::_createWarning($autoWarning, $entry); } $warningModel->deleteFromAutoWarningQueue($contentType, $contentId); } } } }
/** * * @see XenForo_Model_User::passesPrivacyCheck() */ public function passesPrivacyCheck($privacyRequirement, array $user, array $viewingUser = null) { if (!parent::passesPrivacyCheck($privacyRequirement, $user, $viewingUser)) { return false; } $privacyRequirementParts = explode('_', $privacyRequirement); if (count($privacyRequirementParts) != 2) { return true; } list($privacyRequirement, $privacyGroupId) = $privacyRequirementParts; if ($privacyRequirement != 'group') { return true; } /* @var $privacyGroupModel ThemeHouse_PrivacyGroups_Model_PrivacyGroup */ $privacyGroupModel = $this->getModelFromCache('ThemeHouse_PrivacyGroups_Model_PrivacyGroup'); $privacyGroup = $privacyGroupModel->getPrivacyGroupById($privacyGroupId); if (!$privacyGroup) { return true; } return XenForo_Helper_Criteria::userMatchesCriteria($privacyGroup['user_criteria'], true, $viewingUser); }
protected function _checkUserSpamRules(array $user, Zend_Controller_Request_Http $request) { /* @var $userSpamRuleModel ThemeHouse_SpamRules_Model_UserSpamRule */ $userSpamRuleModel = $this->getModelFromCache('ThemeHouse_SpamRules_Model_UserSpamRule'); $userSpamRules = $userSpamRuleModel->prepareUserSpamRules($userSpamRuleModel->getUserSpamRules()); $result = self::RESULT_ALLOWED; foreach ($userSpamRules as $userSpamRule) { $requestMatches = ThemeHouse_SpamRules_Helper_Criteria::requestMatchesCriteria($userSpamRule['requestCriteria'], true, $request); $userMatches = XenForo_Helper_Criteria::userMatchesCriteria($userSpamRule['user_criteria'], true); if ($requestMatches && $userMatches) { switch ($userSpamRule['action']) { case 'moderate': $result = self::RESULT_MODERATED; break; case 'reject': $result = self::RESULT_DENIED; break 2; } } } return $result; }
public function run() { if (self::$checkRedirectRules == $this->_templateName) { $redirectRules = XenForo_Application::getSimpleCacheData('th_redirectRules'); $user = XenForo_Visitor::getInstance()->toArray(); $template = $this->_template; $containerData = $this->_containerData; if ($redirectRules) { foreach ($redirectRules as $redirectRule) { if (XenForo_Helper_Criteria::userMatchesCriteria($redirectRule['user_criteria'], true, $user) && XenForo_Helper_Criteria::pageMatchesCriteria($redirectRule['page_criteria'], true, $template->getParams(), $containerData)) { $url = $this->_getRedirectUrl($redirectRule['reroute_domain']); if (filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) !== FALSE) { header("HTTP/1.1 301 Moved Permanently"); header('Location : ' . $url); exit; } } } } } return parent::run(); }
/** * Runs the cron-based check for new trophies that users should be awarded. */ public static function runTrophyCheck() { /* @var $trophyModel XenForo_Model_Trophy */ $trophyModel = XenForo_Model::create('XenForo_Model_Trophy'); $trophies = $trophyModel->getAllTrophies(); if (!$trophies) { return; } /* @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); $users = $userModel->getUsers(array('user_state' => 'valid', 'is_banned' => 0, 'last_activity' => array('>', XenForo_Application::$time - 86400)), array('join' => XenForo_Model_User::FETCH_USER_OPTION)); $userTrophies = $trophyModel->getUserTrophiesByUserIds(array_keys($users)); foreach ($users as $user) { foreach ($trophies as $trophy) { if (isset($userTrophies[$user['user_id']][$trophy['trophy_id']])) { continue; } if (XenForo_Helper_Criteria::userMatchesCriteria($trophy['criteria'], false, $user)) { $trophyModel->awardUserTrophy($user, $user['username'], $trophy); } } } }
/** * Determines if the given media matches the criteria. * * @param array|string $criteria List of criteria, format: [] with keys rule * and data; may be serialized * @param boolean $matchOnEmpty If true and there's no criteria, true is * returned; otherwise, false * @param array $media * * @return boolean */ public static function mediaMatchesCriteria($criteria, $matchOnEmpty = false, array $media) { if (!($criteria = XenForo_Helper_Criteria::unserializeCriteria($criteria))) { return (bool) $matchOnEmpty; } foreach ($criteria as $criterion) { $data = $criterion['data']; switch ($criterion['rule']) { case 'categories': if (!isset($media['category_id'])) { return false; } if (empty($data['category_ids'])) { return false; } if (!in_array($media['category_id'], $data['category_ids'])) { return false; } break; default: $eventReturnValue = false; XenForo_CodeEvent::fire('criteria_xengallery_media', array($criterion['rule'], $data, $media, &$eventReturnValue)); if ($eventReturnValue === false) { return false; } } } return true; }
/** * Helper to get the redirect rule add/edit form controller response. * * @param array $redirectRule * * @return XenForo_ControllerResponse_View */ protected function _getRedirectRuleAddEditResponse(array $redirectRule) { $viewParams = array('redirectRule' => $redirectRule, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($redirectRule['user_criteria']), 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection(), 'pageCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($redirectRule['page_criteria']), 'pageCriteriaData' => XenForo_Helper_Criteria::getDataForPageCriteriaSelection(), 'showInactiveCriteria' => true); return $this->responseView('ThemeHouse_RedirectRules_ViewAdmin_RedirectRule_Edit', 'th_redirect_rule_edit_redirectrules', $viewParams); }
/** * Verifies that the criteria is valid and formats is correctly. * Expected input format: [] with children: [rule] => name, [data] => info * * @param array|string $criteria Criteria array or serialize string; see above for format. Modified by ref. * * @return boolean */ protected function _verifyCriteria(&$criteria) { $criteriaFiltered = XenForo_Helper_Criteria::prepareCriteriaForSave($criteria); $criteria = serialize($criteriaFiltered); return true; }
/** * Gets the add/edit form response for a privacy group. * * @param array $privacyGroup * * @return XenForo_ControllerResponse_Abstract */ protected function _getPrivacyGroupAddEditResponse(array $privacyGroup) { $viewParams = array('privacyGroup' => $privacyGroup, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($privacyGroup['user_criteria']), 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection(), 'privacyOptions' => $this->_getPrivacyGroupModel()->getPrivacyOptions($privacyGroup['privacy_options'])); return $this->responseView('ThemeHouse_PrivacyGroups_ViewAdmin_PrivacyGroup_Edit', 'th_privacy_group_edit_privacygroups', $viewParams); }
public function rebuildRedirectRuleCache() { $cache = array(); foreach ($this->getRedirectRules() as $redirectRuleId => $redirectRule) { if ($redirectRule['active']) { $cache[$redirectRuleId] = array('title' => $redirectRule['title'], 'reroute_domain' => $redirectRule['reroute_domain'], 'user_criteria' => XenForo_Helper_Criteria::unserializeCriteria($redirectRule['user_criteria']), 'page_criteria' => XenForo_Helper_Criteria::unserializeCriteria($redirectRule['page_criteria'])); } } XenForo_Application::setSimpleCacheData('th_redirectRules', $cache); return $cache; }
/** * Gets the add/edit form response for a promotion. * * @param array $promotion * * @return XenForo_ControllerResponse_Abstract */ protected function _getPromotionAddEditResponse(array $promotion) { $userGroupOptions = $this->_getUserGroupModel()->getUserGroupOptions($promotion['extra_user_group_ids']); $viewParams = array('promotion' => $promotion, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($promotion['user_criteria']), 'userGroupOptions' => $userGroupOptions, 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection()); return $this->responseView('XenForo_ViewAdmin_UserGroupPromotion_Edit', 'user_group_promotion_edit', $viewParams); }
public function updateTrophiesForUser(array $user, array $userTrophies = null, array $trophies = null) { $awarded = 0; if ($trophies === null) { $trophies = $this->getAllTrophies(); } if (!$trophies) { return 0; } if ($userTrophies === null) { $userTrophies = $this->getTrophiesForUserId($user['user_id']); } foreach ($trophies as $trophy) { if (isset($userTrophies[$trophy['trophy_id']])) { continue; } if (XenForo_Helper_Criteria::userMatchesCriteria($trophy['user_criteria'], false, $user)) { $this->awardUserTrophy($user, $user['username'], $trophy); $awarded++; } } return $awarded; }
/** * Fetches all notices applicable to the visiting user * * @param XenForo_Template_Abstract $template * @param array $containerData * * @return array */ protected function _getNoticesContainerParams(XenForo_Template_Abstract $template, array $containerData) { $notices = array(); foreach ($this->_dependencies->notices as $param => $noticeKey) { if ($template->getParam($param)) { $notices['block'][$noticeKey] = array('title' => new XenForo_Phrase($noticeKey), 'message' => $template->create($noticeKey, $template->getParams()), 'wrap' => true, 'dismissible' => false); } } if (XenForo_Application::get('options')->enableNotices) { if (XenForo_Application::isRegistered('notices')) { $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 $visitorStyle = $template->getParam('visitorStyle'); if (!empty($visitorStyle)) { $user['style_id'] = $visitorStyle['style_id']; } $noticeList = XenForo_Application::get('notices'); foreach (XenForo_Application::get('notices') as $noticeId => $notice) { if (!empty($notice['dismissible']) && in_array($noticeId, $dismissedNotices) || !XenForo_Helper_Criteria::userMatchesCriteria($notice['user_criteria'], true, $user) || !XenForo_Helper_Criteria::pageMatchesCriteria($notice['page_criteria'], true, $template->getParams(), $containerData)) { unset($noticeList[$noticeId]); } } $noticeTokens = array('{name}' => $user['username'] !== '' ? htmlspecialchars($user['username']) : new XenForo_Phrase('guest'), '{user_id}' => $user['user_id']); XenForo_CodeEvent::fire('notices_prepare', array(&$noticeList, &$noticeTokens, $template, $containerData)); foreach ($noticeList as $noticeId => $notice) { $noticeTokens['{title}'] = $notice['title']; $imageUrl = ''; if ($notice['display_image'] == 'avatar') { $imageUrl = XenForo_Template_Helper_Core::callHelper('avatar', array($user, 's')); } else { if ($notice['display_image'] == 'image') { $imageUrl = $notice['image_url']; } } $notices[$notice['notice_type']][$noticeId] = array('title' => $notice['title'], 'message' => str_replace(array_keys($noticeTokens), $noticeTokens, $notice['message']), 'wrap' => $notice['wrap'], 'dismissible' => $notice['dismissible'], 'delay_duration' => $notice['delay_duration'], 'display_duration' => $notice['display_duration'], 'auto_dismiss' => $notice['auto_dismiss'], 'display_image' => $notice['display_image'], 'display_style' => $notice['display_style'], 'css_class' => $notice['css_class'], 'visibility' => $notice['visibility'], 'imageUrl' => $imageUrl); } } } return $notices; }
/** * Determines if the given content matches the criteria. * * @param array|string $criteria List of criteria, format: [] with keys rule * and data; may be serialized * @param boolean $matchOnEmpty If true and there's no criteria, true is * returned; otherwise, false * @param string $content Content to check against * * @return boolean */ public static function contentMatchesCriteria($criteria, $matchOnEmpty = false, $content = '') { if (!($criteria = XenForo_Helper_Criteria::unserializeCriteria($criteria))) { return (bool) $matchOnEmpty; } foreach ($criteria as $criterion) { $data = $criterion['data']; switch ($criterion['rule']) { // contains at least x links case 'contains_links': if (!isset($data['links'])) { return false; } $pattern = '#\\[url(?:.*)\\[/url\\]#Uis'; preg_match_all($pattern, $content, $matches); if (count($matches[0]) < $data['links']) { return false; } break; // contains specific words // contains specific words case 'contains_words': if (!isset($data['words'])) { return false; } $matched = false; foreach ($data['words'] as $word) { if (!empty($word['word'])) { if (!empty($word['exact'])) { if (strpos($content, $word['word']) !== false) { $matched = true; break; } } else { if (stripos($content, $word['word']) !== false) { $matched = true; break; } } } } if ($matched == false) { return false; } break; // contains uppercase // contains uppercase case 'contains_uppercase': if (!isset($data['percent'])) { return false; } $newContent = self::cleanTextForChecks($content); if (!$newContent) { return false; } $capitalLetters = strlen(preg_replace('![^A-Z]+!', '', $newContent)); $percent = $capitalLetters / strlen($newContent) * 100; if ($percent < $data['percent']) { return false; } break; } } return true; }
public function updatePromotionsForUser(array $user, array $promotionStates = null, array $promotions = null) { $changes = 0; if ($promotions === null) { $promotions = $this->getPromotions(array('active' => 1)); } if (!$promotions) { return 0; } if ($promotionStates === null) { $promotionStates = $this->getPromotionStatesByUserId($user['user_id']); } foreach ($promotions as $promotionId => $promotion) { if (isset($promotionStates[$promotionId])) { $skip = false; switch ($promotionStates[$promotionId]) { case 'manual': // has it, don't take it away // has it, don't take it away case 'disabled': // never give it $skip = true; } if ($skip) { continue; } $hasPromotion = true; } else { $hasPromotion = false; } if (XenForo_Helper_Criteria::userMatchesCriteria($promotion['user_criteria'], false, $user)) { if (!$hasPromotion) { $this->promoteUser($promotion, $user['user_id']); $changes++; } } else { if ($hasPromotion) { $this->demoteUser($promotion, $user['user_id']); $changes++; } } } return $changes; }
protected function _getNoticeAddEditResponse(array $notice) { if (ThemeHouse_SocialGroups_SocialForum::hasInstance()) { $socialForum = ThemeHouse_SocialGroups_SocialForum::getInstance()->toArray(); } else { return $this->responseError('th_requested_social_forum_not_found_socialgroups'); } $this->_assertCanManageSocialNotices($socialForum); $noticeModel = $this->_getNoticeModel(); $ftpHelper = $this->getHelper('ForumThreadPost'); $forum = $this->getHelper('ForumThreadPost')->assertForumValidAndViewable($socialForum['node_id'], array()); $viewParams = array('socialForum' => $socialForum, 'notice' => $notice, 'userCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($notice['user_criteria']), 'userCriteriaData' => XenForo_Helper_Criteria::getDataForUserCriteriaSelection(), 'pageCriteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($notice['page_criteria']), 'pageCriteriaData' => XenForo_Helper_Criteria::getDataForPageCriteriaSelection(), 'showInactiveCriteria' => true, 'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum, true)); return $this->responseView('ThemeHouse_SocialNotices_ViewPublic_SocialForum_Notice_Edit', 'th_social_notice_edit_socialnotices', $viewParams); }
/** * Gets the add/edit form response for a trophy. * * @param array $trophy * * @return XenForo_ControllerResponse_Abstract */ protected function _getTrophyAddEditResponse(array $trophy) { $trophyModel = $this->_getTrophyModel(); $viewParams = array('trophy' => $trophy, 'masterTitle' => $trophyModel->getTrophyMasterTitlePhraseValue($trophy['trophy_id']), 'masterDescription' => $trophyModel->getTrophyMasterDescriptionPhraseValue($trophy['trophy_id']), 'criteria' => XenForo_Helper_Criteria::prepareCriteriaForSelection($trophy['criteria'])); return $this->responseView('XenForo_ViewAdmin_Trophy_Edit', 'trophy_edit', $viewParams); }
/** * Fetches all notices applicable to the visiting user * * @param XenForo_Template_Abstract $template * @param array $containerData * * @return array */ protected function _getNoticesContainerParams(XenForo_Template_Abstract $template, array $containerData) { $notices = array(); foreach ($this->_dependencies->notices as $param => $noticeKey) { if ($template->getParam($param)) { $notices[$noticeKey] = array('title' => new XenForo_Phrase($noticeKey), 'message' => $template->create($noticeKey, $template->getParams()), 'wrap' => true, 'dismissible' => false); } } if (XenForo_Application::get('options')->enableNotices) { if (XenForo_Application::isRegistered('notices')) { $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 $visitorStyle = $template->getParam('visitorStyle'); if (!empty($visitorStyle)) { $user['style_id'] = $visitorStyle['style_id']; } $noticeList = XenForo_Application::get('notices'); foreach (XenForo_Application::get('notices') as $noticeId => $notice) { if (!empty($notice['dismissible']) && in_array($noticeId, $dismissedNotices) || !XenForo_Helper_Criteria::userMatchesCriteria($notice['user_criteria'], true, $user) || !XenForo_Helper_Criteria::pageMatchesCriteria($notice['page_criteria'], true, $template->getParams(), $containerData)) { unset($noticeList[$noticeId]); } } $noticeTokens = array('{name}' => $user['username'] !== '' ? $user['username'] : new XenForo_Phrase('guest'), '{user_id}' => $user['user_id']); XenForo_CodeEvent::fire('notices_prepare', array(&$noticeList, &$noticeTokens, $template, $containerData)); foreach ($noticeList as $noticeId => $notice) { $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; }