Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_url_matches.inc
1 <?php
16 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_condition/trigger_condition.inc';
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
30 {
31 
32 
50  public static function evaluate($settings, &$state)
51  {
52  // grab the data we need to check the condition, if it's not already cached
53  // note that new state is modified and new data is available to other conditions
54  if (empty($state['asset'])) {
55  // grab the asset if assetid is given, but not the asset
56  if (empty($state['assetid'])) {
57  return FALSE;
58  } else {
59  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
60  }
61  }
62 
63  if (empty($settings['pattern'])) {
64  // if no pattern settings, fail
65  return FALSE;
66  }
67 
68  // see if the pattern occurs in the current url
69  if (isset($_SERVER['REQUEST_URI'])) {
70  $matches = strpos($_SERVER['REQUEST_URI'], $settings['pattern']);
71  // check the condition
72  if ($settings['match'] && $matches !== FALSE) {
73  return TRUE;
74  } else if (!$settings['match'] && $matches === FALSE) {
75  return TRUE;
76  }
77  }
78  return FALSE;
79 
80  }//end evaluate()
81 
82 
93  public static function getInterface($settings, $prefix, $write_access=FALSE)
94  {
95  if (!$write_access) {
96  $form_element_extras = 'disabled="disabled"';
97  } else {
98  $form_element_extras = '';
99  }
100 
101  $pattern = (isset($settings['pattern'])) ? $settings['pattern'] : '';
102  $match = (isset($settings['match'])) ? $settings['match'] : FALSE;
103 
104  // begin buffering basic options
105  ob_start();
106  if ($write_access) {
107  text_box($prefix.'[pattern]', $pattern, '100', '', FALSE, $form_element_extras);
108  echo '<br>';
109 
110  radio_button($prefix.'[match]', '1', $match, NULL, $form_element_extras);
111  echo ' Must be in URL<br>';
112  radio_button($prefix.'[match]', '0', !$match, NULL, $form_element_extras);
113  echo ' Must not be in URL<br>';
114  echo 'Note: this condition only checks the query string ($_SERVER["REQUEST_URI"]) part of the URL';
115  } else {
116  $match_str = ($match) ? 'must be in URL' : 'must not be in URL';
117  echo "\"$pattern\" $match_str .";
118  }
119  $basic_part_1 = ob_get_contents();
120  ob_end_clean();
121 
122  return ' URL pattern '.$basic_part_1;
123 
124  }//end getInterface()
125 
126 
136  public static function processInterface(&$settings, $request_data)
137  {
138  $pattern = array_get_index($request_data, 'pattern', FALSE);
139  if (!$pattern) {
140  return 'No URL pattern entered';
141  } else {
142  $settings['pattern'] = $pattern;
143  // store if we want to match pattern or not
144  $settings['match'] = array_get_index($request_data, 'match', FALSE);
145  return FALSE;
146  }
147 
148  }//end processInterface()
149 
150 
158  public static function allowMultiple()
159  {
160  // default to to disallow
161  return TRUE;
162 
163  }//end allowMultiple()
164 
165 
166 }//end class
167 
168 ?>