Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
condition_keyword_regexp.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/conditions/condition/condition.inc';
18 
31 {
32 
33 
40  function __construct($assetid=0)
41  {
42  parent::__construct($assetid);
43 
44  }//end constructor
45 
46 
56  public static function evaluate(Asset $asset, Array $condition_data)
57  {
58  if (!isset($condition_data['keyword']) || !isset($condition_data['keyword_match'])) {
59  return FALSE;
60  }
61 
62  if (isset($condition_data['keyword_value'])) {
63 
64  if (!preg_match('/^%globals_/', $condition_data['keyword_value'])) {
65  $keyword_replacement = $condition_data['keyword_value'];
66  }
67  else {
68  // If keyword is a global then its value is set as %global_%, which is evaluate only after bodycopy
69  // is created. But for processing global keyword here, its value needs to be evaluated right here.
70  // See bug #3716
71 
72  $keyword_replacement = replace_global_keywords($condition_data['keyword_value']);
73  }
74  } else {
75  $keyword_replacement = self::getRegExpKeywordReplacement($asset, $condition_data);
76  }
77 
78  $keyword_match = $condition_data['keyword_match'];
79 
80  if (array_get_index($condition_data, 'replace_keyword_in_match', '0') == '1') {
81  //replace global keywords
82  replace_global_keywords($keyword_match);
83 
84  //replace asset keywords
85  $keywords = retrieve_keywords_replacements($keyword_match);
86  $replacements = Array();
87  foreach ($keywords as $keyword) {
88  $replacements[$keyword] = $asset->getKeywordReplacement($keyword);
89  }
90  replace_keywords($keyword_match, $replacements);
91  }
92 
93  $matches = preg_match('/'.str_replace('/', '\\'.'/', $keyword_match).'/i', $keyword_replacement);
94  return ($matches > 0);
95 
96  }//end evaluate()
97 
98 
108  public static function getRegExpKeywordReplacement(Asset $asset, Array $condition_data)
109  {
110  $ret = '';
111 
112  if (preg_match('/^globals_/', $condition_data['keyword'])) {
113  $ret = '%'.$condition_data['keyword'].'%';
114  replace_global_keywords($ret);
115  } else {
116  $ret = $asset->getKeywordReplacement($condition_data['keyword']);
117  }
118 
119  return $ret;
120 
121  }//end getRegExpKeywordReplacement()
122 
123 
138  public static function updateKeywords(Array $logical_keywords, Array &$condition_data)
139  {
140  $keyword_name = parse_keyword($condition_data['keyword'], $modifiers);
141 
142  if (count($modifiers) >= 1) {
143  $condition_data['keyword_value'] = '%'.$condition_data['keyword'].'%';
144  } else {
145  $condition_data['keyword_value'] = isset($logical_keywords[$keyword_name]) ? $logical_keywords[$keyword_name] : '';
146  }//end if
147 
148  }//end updateKeywords()
149 
150 
164  public static function getRequiredKeywords(Array $condition_data)
165  {
166  return Array($condition_data['keyword']);
167 
168  }//end getRequiredKeywords()
169 
170 
171 }//end class
172 
173 ?>