Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * 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;
 }
 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;
 }
Example #6
0
 /**
  * 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;
 }