18 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
19 require_once SQ_ATTRIBUTES_PATH.
'/http_request/http_request.inc';
43 public static function execute($settings, &$state)
45 if (empty($state[
'asset'])) {
47 if (empty($state[
'assetid'])) {
50 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
54 if (is_null($state[
'asset']))
return FALSE;
56 $assetid = $state[
'asset']->id;
58 $http_request_value = $settings[
'http_request'];
62 if (is_null($http_request_attr))
return FALSE;
64 $current_value = unserialize($http_request_attr->value);
67 if (empty($current_value[
'method']) && empty($current_value[
'urls'])) {
72 $keywords_list = Array();
73 if (isset($current_value[
'urls'])) {
74 $keywords_list = array_merge(
76 retrieve_keywords_replacements(implode(
', ', $current_value[
'urls']))
80 if (isset($current_value[
'request_headers'])) {
81 $keywords_list = array_merge(
83 retrieve_keywords_replacements(implode(
', ', $current_value[
'request_headers']))
87 if (isset($current_value[
'request_body'])) {
88 $keywords_list = array_merge(
90 retrieve_keywords_replacements($current_value[
'request_body'])
94 if (isset($current_value[
'http_auth_options'])) {
95 $keywords_list = array_merge(
97 retrieve_keywords_replacements(implode(
', ', $current_value[
'http_auth_options']))
101 $keywords_list = array_unique($keywords_list);
104 $replacements = Array();
105 foreach ($keywords_list as $keyword) {
106 $replacements[$keyword] = $state[
'asset']->getKeywordReplacement($keyword);
109 $http_request_attr->setKeywordReplacements($replacements);
112 $res =& $http_request_attr->run();
115 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_rest_response_received', $state[
'asset'], $res);
116 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($state[
'asset']);
119 'assetid' => $assetid,
135 public static function getInterface($settings, $prefix, $write_access=FALSE)
139 $new_prefix = str_replace(array(
'[',
']'),
'_', $prefix);
141 $http_request_value = array_get_index($settings,
'http_request', Array());
144 $http_request_attr->paint($new_prefix.
'_http_request', !$write_access);
146 hidden_field($prefix.
'[new_prefix]', $new_prefix);
148 return ob_get_clean();
166 if (!isset($settings[
'http_request'])) {
167 $http_request_value = serialize(Array());
169 $http_request_value = $settings[
'http_request'];
173 $new_prefix = str_replace(array(
'[',
']'),
'_', array_get_index($request_data,
'new_prefix',
''));
175 $http_request_attr->process($new_prefix.
'_http_request');
176 $settings[
'http_request'] = $http_request_attr->value;
192 public static function getLocks($settings, &$state)
194 return Array($state[
'assetid'] => Array(
'lookups'));