17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_condition_types/trigger_condition_asset_type/trigger_condition_asset_type.inc';
42 'exact' => translate(
'exact_match'),
43 'partial' => translate(
'partial_match'),
44 'regex' => translate(
'regex_match'),
69 public static function evaluate($settings, &$state)
71 if (empty($settings[
'keyword']))
return FALSE;
72 if (empty($settings[
'match_type']))
return FALSE;
74 if (empty($state[
'asset'])) {
75 if (empty($state[
'assetid']))
return FALSE;
76 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
83 $keyword = str_replace(
'%',
'', $settings[
'keyword']);
84 $asset_keyword_replacement = $state[
'asset']->getKeywordReplacement($keyword);
89 $original_current_asset = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_ASSET', NULL);
90 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_ASSET', $state[
'asset']);
91 replace_global_keywords($asset_keyword_replacement);
94 if (is_null($original_current_asset)) {
95 $GLOBALS[
'SQ_SYSTEM']->unsetGlobalDefine(
'CURRENT_ASSET');
97 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_ASSET', $original_current_asset);
100 switch ($settings[
'match_type']) {
102 return ($asset_keyword_replacement === $settings[
'comparison_value']);
104 return (strpos($asset_keyword_replacement, $settings[
'comparison_value']) !== FALSE);
106 return (preg_match(
'/'.str_replace(
'/',
'\/', $settings[
'comparison_value']).
'/', $asset_keyword_replacement) > 0);
125 public static function getInterface($settings, $prefix, $write_access=FALSE)
128 $keyword = isset($settings[
'keyword']) ? $settings[
'keyword'] :
'';
129 $replacement_value = isset($settings[
'comparison_value']) ? $settings[
'comparison_value'] :
'';
130 $operator = array_get_index($settings,
'match_type',
'exact');
132 $am = $GLOBALS[
'SQ_SYSTEM']->am;
137 text_box($prefix.
'[keyword]', $keyword,
'30px');
139 echo
'<b>'.$keyword.
'</b>';
141 $keyword_component = ob_get_contents();
147 text_box($prefix.
'[comparison_value]', $replacement_value ,
'50px');
149 echo
'<b>'.$replacement_value.
'</b>';
152 $replacement_value_component = ob_get_contents();
160 combo_box($prefix.
'[match_type]', $operator_options, FALSE, $operator);
162 echo
'<b>'.$operator_options[$operator].
'</b>';
164 $operator_component = ob_get_contents();
168 return translate(
'trigger_condition_keyword', $keyword_component, $operator_component, $replacement_value_component);
185 if (empty($request_data)) {
186 return translate(
'trigger_input_data_missing');
189 $settings[
'keyword'] = array_get_index($request_data,
'keyword',
'');
190 $settings[
'comparison_value'] = array_get_index($request_data,
'comparison_value',
'');
191 $settings[
'match_type'] = array_get_index($request_data,
'match_type',
'exact');