示例#1
0
文件: Base.php 项目: Sywooch/forums
 /**
  *
  * @see XenForo_BbCode_Formatter_Base::filterString()
  */
 public function filterString($string, array $rendererStates)
 {
     $string = parent::filterString($string, $rendererStates);
     $userGroupIds = XenForo_Application::get('options')->waindigo_keywordReplace_excludedUserGroups;
     $user = XenForo_Visitor::getInstance()->toArray();
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     if (!$userModel->isMemberOfUserGroup($user, $userGroupIds) && !isset($rendererStates['insideUrl'])) {
         $string = Waindigo_KeywordReplace_Helper_String::keywordReplaceString($string);
     }
     return $string;
 }
示例#2
0
文件: String.php 项目: Sywooch/forums
 /**
  * Replaces keywords in the given string.
  *
  * @param string $string
  * @param array|null $words Words to replace. Null to use option value.
  *
  * @return string
  */
 public static function keywordReplaceString($string, array $words = null)
 {
     $allowCache = $words === null;
     // ok to use cache for default
     $keywordReplaceCache = $allowCache ? self::$_keywordReplaceCache : null;
     $keywordLimitCache = $allowCache ? self::$_keywordLimitCache : null;
     $countCache = $allowCache ? self::$_countCache : null;
     if ($keywordReplaceCache === null) {
         if ($words === null) {
             $words = XenForo_Application::get('options')->waindigo_keywordReplace;
         }
         if (!$words) {
             if ($allowCache) {
                 self::$_keywordReplaceCache = array();
                 self::$_keywordLimitCache = array();
             }
             return $string;
         }
         $keywordReplaceArrays = self::buildKeywordReplaceArrays($words);
         $keywordReplaceCache = $keywordReplaceArrays['replaceCache'];
         $keywordLimitCache = $keywordReplaceArrays['limitCache'];
         $countCache = XenForo_Application::get('options')->waindigo_keywordReplace_limitPerPage;
         if ($allowCache) {
             self::$_keywordReplaceCache = $keywordReplaceCache;
             self::$_keywordLimitCache = $keywordLimitCache;
             self::$_countCache = $countCache;
         }
     }
     foreach (array_keys($keywordReplaceCache) as $keyword) {
         if (XenForo_Application::get('options')->waindigo_keywordReplace_limitPerPage) {
             if ($keywordLimitCache[$keyword] != -1) {
                 $limit = min(array($keywordLimitCache[$keyword], $countCache));
             } else {
                 $limit = $countCache;
             }
         } else {
             $limit = $keywordLimitCache[$keyword];
         }
         $string = preg_replace($keyword, $keywordReplaceCache[$keyword], $string, $limit, $count);
         if ($count && $limit != -1) {
             $countCache = $countCache - $count;
             if ($allowCache) {
                 self::$_countCache = $countCache;
                 self::$_keywordLimitCache[$keyword] = $keywordLimitCache[$keyword] - $count;
             }
         }
     }
     return $string;
 }