17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
19 require_once SQ_INCLUDE_PATH.
'/general.inc';
20 require_once dirname(dirname(dirname(__FILE__))).
'/lib/soap_common.inc';
45 public static function execute($settings, &$state)
50 if (empty($settings[
'wsdl'])) {
55 if (empty($settings[
'actions'])) {
60 if (!isset($settings[
'action'])) {
65 if (!isset ($settings[$settings[
'action'].
'parameters0'])) {
69 if(!isset($settings[
'actions'][$settings[
'action']])) {
73 if (empty($state[
'asset'])) {
75 if (empty($state[
'assetid'])) {
78 $state[
'asset'] = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
82 $function = $settings[
'action'];
83 $wsdl = $settings[
'wsdl'];
87 for($i = 0, $param = Array(); $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
88 if(isset($settings[$settings[
'action'].
'parameters'.$i])) {
89 $soap_message = self::getKeywordReplacementsFromAsset($settings[$settings[
'action'].
'parameters'.$i], $state[
'asset']);
90 $object = @simplexml_load_string($soap_message);
101 foreach ($param as $index => $object) {
102 $eval_string .= $index == 0 ?
'' :
', ';
103 $eval_string .=
'$param['.$index.
']';
107 $options[
'trace'] = 1;
110 if ($settings[
'mute_exceptions']) {
111 $options[
'exceptions'] = 0;
116 $client =
new SoapClient($wsdl, $options);
117 eval(
'$data = $client->$function('.$eval_string.
');');
119 catch (Exception $e) {
121 trigger_error($e->getMessage());
123 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'soap_trigger_action_error'] = $e->getMessage();
127 if ($settings[
'mute_exceptions'] && get_class($data) ==
'SoapFault') {
128 $soap_response = $client->__getLastResponse();
131 if (preg_match(
'|<([^:]+:)?Body>(.*)</([^:]+:)?Body>|msi', $soap_response, $match)) {
132 $data = simplexml_load_string($match[2]);
137 $soap_response_keywords = Array();
138 $file_saving_keywords = array_get_index($settings, $settings[
'action'].
'_file_response_to_save', Array());
142 foreach($soap_response_keywords as $key => $val) {
143 $soap_response_keywords[substr_replace($key,
'', 0, 5)] = $val;
144 unset($soap_response_keywords[$key]);
148 if (!empty($settings[$settings[
'action'].
'_response_error_fields'])) {
149 foreach($settings[$settings[
'action'].
'_response_error_fields'] as $check_field => $error_msg) {
150 if (!empty($soap_response_keywords[$check_field])) {
151 $warning_level = $settings[$settings[
'action'].
'_treat_as_fatal'] ? E_USER_ERROR : E_USER_WARNING;
152 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'soap_trigger_action_error'] = $error_msg;
153 trigger_error($error_msg, $warning_level);
175 public static function getInterface($settings, $prefix, $write_access=FALSE)
180 <p
class=
"sq-backend-section-subheading">Connection Details</p>
182 <table
class=
"sq-backend-table" >
184 <td width=
"120"><p>WSDL</p></td>
187 $wsdl = array_get_index($settings,
'wsdl',
'');
189 text_box($prefix.
'[wsdl]', $wsdl, 120);
196 <td><?php echo translate(
'login'); ?></td>
199 $login = array_get_index($settings,
'login',
'');
201 text_box($prefix.
'[login]', $login, 35);
209 <td><?php echo translate(
'password'); ?></td>
212 if($write_access) password_box($prefix.
'[password]', array_get_index($settings,
'password',
''), 35);
217 <td colspan=
"2"><?php echo translate(
'use_http_authentication'); ?></td>
220 <td><?php echo translate(
'mute_exception'); ?></td>
223 $mute_exp = array_get_index($settings,
'mute_exceptions', 0);
225 check_box($prefix.
'[mute_exceptions]', 1, $mute_exp);
227 $mute_exp_status = ($mute_exp ==
'1') ?
'tick' :
'cross';
228 echo
'<img class="sq-icon" width="16" height="16" src="'.sq_web_path(
'lib').
'/web/images/'.$mute_exp_status.
'.gif" alt="" style="border: 0;" />';
235 <table
class=
"sq-backend-table" >
237 <td><p><?php echo translate(
'local_cert'); ?></p></td>
240 $local_cert = array_get_index($settings,
'local_cert', 0);
242 asset_finder($prefix.
'[local_cert]', $local_cert, Array(
'file'=>
'D'));
244 if ($local_cert) echo get_asset_tag_line($local_cert);
250 <td><p><?php echo translate(
'passphrase'); ?></p></td>
253 if ($write_access) password_box($prefix.
'[passphrase]', array_get_index($settings,
'passphrase',
''), 35);
258 <td colspan=
"2"><?php echo translate(
'use_https'); ?></td>
262 <p
class=
"sq-backend-section-subheading">Test Response</p>
263 <div
id=
"<?php echo $prefix ?>_test_request_response" style=
"padding: 0.5em 0px 2em 30px;">
264 <table
class=
"sq-backend-table" >
266 <td width=
"120"><?php echo translate(
'run_test'); ?></td>
269 $run_test = array_get_index($settings,
'run_test', 0);
271 check_box($prefix.
'[run_test]', 1, $run_test);
273 $run_test_status = ($mute_exp ==
'1') ?
'tick' :
'cross';
274 echo
'<img class="sq-icon" width="16" height="16" src="'.sq_web_path(
'lib').
'/web/images/'.$run_test_status.
'.gif" alt="" style="border: 0;" />';
280 <td colspan=
"2"><?php echo translate(
'run_test_note'); ?></td>
287 if ($write_access && $run_test && !empty($settings[
'test_results'])) {
288 foreach($settings[
'test_results'] as $soap_func => $info) {
289 echo
"<b><u>$soap_func</u></b><br /><br />";
290 echo
"<b>Request:</b><br />";
291 echo (nl2br(str_replace(
' ',
' ', htmlentities($info[
'request']))));
293 echo
"<b>Response:</b><br />";
294 echo (nl2br(str_replace(
' ',
' ', htmlentities($info[
'response']))));
304 <?php
if (isset($settings[
'actions']) && !empty($settings[
'actions'])) { ?>
305 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'request_message'); ?></p>
307 <table
class=
"sq-backend-table" >
309 <td><strong><?php echo translate(
'action');?></strong><br /><br /></td>
312 $action_selected = array_get_index($settings,
'action',
'');
313 foreach ($settings[
'actions'] as $name => $detail) {
314 $action_list[$name] = $name;
317 combo_box($prefix.
'[action]', $action_list, FALSE, $action_selected);
319 echo $action_selected;
326 <td><span style=
"padding-top:10px;"><strong><?php echo translate(
'params');?></strong></span></td>
330 if(isset($settings[
'actions'][$settings[
'action']])) {
331 foreach ($settings[
'actions'][$settings[
'action']] as $parameter_xml) {
332 if ($write_access) text_area($prefix.
'['.$settings[
'action'].
'parameters'.$i.
']', array_get_index($settings,$settings[
'action'].
'parameters'.$i, $parameter_xml), 80, 15);
344 echo translate(
'keyword_usable_note');
350 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_message'); ?></p>
352 <table
class=
"sq-backend-table" >
357 if(isset($settings[
'responses'][$settings[
'action']])) {
358 echo (nl2br(str_replace(
' ',
' ', htmlentities($settings[
'responses'][$settings[
'action']]))));
366 <?php echo translate(
'response_message_note'); ?>
373 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_keywords'); ?></p>
375 <table
class=
"sq-backend-table" >
380 if(isset($settings[
'response_keywords'][$settings[
'action']])) {
381 echo ($settings[
'response_keywords'][$settings[
'action']]);
391 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'check_response')?></p>
393 <table
class=
"sq-backend-table" >
397 $selected_fields = isset($settings[$settings[
'action'].
'_response_error_fields']) ? $settings[$settings[
'action'].
'_response_error_fields'] : Array();
398 $selected_field_names = Array();
399 if (empty($selected_fields)) {
400 echo translate(
'no_field_selected');
403 <table
class=
"sq-backend-table">
405 <td
class=
"sq-backend-table-header"><?php echo translate(
'field_name'); ?></td>
406 <td
class=
"sq-backend-table-header"><?php echo translate(
'error_text'); ?></td>
407 <td
class=
"sq-backend-table-header"><?php echo translate(
'delete_question'); ?></td>
410 foreach ($selected_fields as $selected_field => $error_msg) {
413 <td
class=
"sq-backend-table-cell">
415 echo $selected_field;
416 $selected_field_names[] = $selected_field;
419 <td
class=
"sq-backend-table-cell">
422 text_box($prefix.
'['.$settings[
'action'].
'_error_msg_'.$selected_field.
']', $error_msg, 110);
429 <td
class=
"sq-backend-table-cell">
430 <?php
if ($write_access) check_box($prefix.
'['.$settings[
'action'].
'_delete_field_'.$selected_field.
']'); ?>
441 echo translate(
'add_new_field');
442 $response_fields = Array(
'' =>
'-- Select Field --');
443 if (isset($settings[
'response_keywords'][$settings[
'action']])) {
444 $response_keywords = explode(
'<br/>', $settings[
'response_keywords'][$settings[
'action']]);
445 foreach($response_keywords as $val) {
446 $val = trim($val,
'%');
447 $val = substr_replace($val,
'', 0, strlen(
'globals_session_soap_'));
450 $response_fields[$val] = $val;
454 combo_box($prefix.
'['.$settings[
'action'].
'_response_error_fields'.
']', $response_fields, TRUE, $selected_field_names);
462 $treating_fatal = array_get_index($settings, $settings[
'action'].
'_treat_as_fatal', 0);
464 check_box($prefix.
'['.$settings[
'action'].
'_treat_as_fatal]',
'1', $treating_fatal);
466 $treat_fatal_status = ($treating_fatal ==
'1') ?
'tick' :
'cross';
467 echo
'<img class="sq-icon" width="16" height="16" src="'.sq_web_path(
'lib').
'/web/images/'.$treat_fatal_status.
'.gif" alt="" style="border: 0;" />';
469 echo translate(
'treat_as_fatal_note');
476 echo translate(
'check_response_note');
481 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_to_download_as_file'); ?></p>
482 <table
class=
"sq-backend-table">
484 <td
class=
"sq-backend-table-header"><?php echo translate(
'field_keyword_tags'); ?></td>
487 $response_to_file = array_get_index($settings, $settings[
'action'].
'_file_response_to_save', Array());
488 $currently_configured = count($response_to_file);
490 foreach ($response_to_file as $i => $response) { ?>
495 text_box($prefix.
'['.$settings[
'action'].
'_file_response_to_save]['.$i.
']', $response, 50);
497 if (in_array($response, $settings[$settings[
'action'].
'_invalid_keywords_for_file'])) {
499 echo
"<span style=\"color:#FF0000\"><b> *invalid keyword</b></span>";
512 $count = $currently_configured++;
513 if ($write_access) text_box($prefix.
'['.$settings[
'action'].
'_file_response_to_save]['.$count.
']',
'', 50);
518 <td><?php echo translate(
'response_to_download_as_file_note'); ?></td>
524 return ob_get_clean();
542 $settings[
'wsdl'] = array_get_index($request_data,
'wsdl',
'');
543 $settings[
'login'] = array_get_index($request_data,
'login',
'');
544 $settings[
'password'] = array_get_index($request_data,
'password',
'');
545 $settings[
'mute_exceptions'] = array_get_index($request_data,
'mute_exceptions', FALSE);
546 $settings[
'local_cert'] = array_get_index($request_data[
'local_cert'],
'assetid',
'0');
547 $settings[
'passphrase'] = array_get_index($request_data,
'passphrase',
'');
548 $settings[
'run_test'] = array_get_index($request_data,
'run_test', 0);
549 $settings[
'action'] = array_get_index($request_data,
'action', NULL);
551 if(isset ($settings[
'wsdl']) && !empty($settings[
'wsdl'])) {
557 trigger_error(taranslate(
'no_cert'), E_USER_WARNING);
562 $client =
new SoapClient($settings[
'wsdl'], $options);
563 $functions = $client->__getFunctions();
564 $types = $client->__getTypes();
566 catch (Exception $e) {
567 trigger_error($e->getMessage());
571 $function_list = Array();
572 if(!empty($functions)) {
573 foreach ($functions as $function) {
574 $function_name = preg_replace(
'/^\w+ (\w+)\(.*\)/',
'$1', $function);
575 $function_params = explode(
', ', preg_replace(
'/^\w+ \w+\((.*)\)/',
'$1', $function));
576 $function_response = preg_replace(
'/^(\w+) \w+\(.*\)/',
'$1', $function);
579 if(isset($function_list[$function_name]))
continue;
582 $parsed_params = Array();
583 foreach ($function_params as $param) {
584 if (!trim($param))
continue;
590 $function_list[$function_name] = $parsed_params;
595 if ($xml_response === TRUE || $xml_response === FALSE) {
597 $keywords =
'globals_session_soap'.($xml_response ?
'0' :
'');
603 $keywords_list[$function_name] = str_replace(
'[ARRAY_ELEMENT]',
'0', $keywords);
606 $settings[
'actions'] = $function_list;
607 $settings[
'responses'] = $response_list;
608 $settings[
'response_keywords'] = $keywords_list;
612 $settings[$settings[
'action'].
'_treat_as_fatal'] = array_get_index($request_data, $request_data[
'action'].
'_treat_as_fatal',0);
615 $current_selected_fields = (isset($request_data[$settings[
'action'].
'_response_error_fields']) && $request_data[$settings[
'action'].
'_response_error_fields'] !=
'')? $request_data[$settings[
'action'].
'_response_error_fields'] : Array();
617 $field_error_msgs = Array();
620 $keywords_string =
'';
621 if (isset($settings[
'response_keywords'])) {
622 $keywords_string = implode(
';',$settings[
'response_keywords']);
625 foreach ($current_selected_fields as $index => $selected_field) {
628 if ((!isset($request_data[$settings[
'action'].
'_delete_field_'.$selected_field]) || !$request_data[$settings[
'action'].
'_delete_field_'.$selected_field]) && strpos($keywords_string,
'%globals_session_soap_'.$selected_field.
'%') !== FALSE) {
629 if (isset($request_data[$settings[
'action'].
'_error_msg_'.$selected_field])) {
630 $field_error_msgs[$selected_field] = trim($request_data[$settings[
'action'].
'_error_msg_'.$selected_field]);
632 $field_error_msgs[$selected_field] =
'';
638 if(isset($settings[
'actions'][$settings[
'action']])) {
639 $settings[$settings[
'action'].
'_response_error_fields'] = $field_error_msgs;
640 for($i = 0; $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
641 if(isset($request_data[$settings[
'action'].
'parameters'.$i])) {
642 $parameters_passed = $request_data[$settings[
'action'].
'parameters'.$i];
643 $settings[$settings[
'action'].
'parameters'.$i] = $request_data[$settings[
'action'].
'parameters'.$i];
648 $settings[$settings[
'action'].
'_invalid_keywords_for_file'] = Array();
649 if (isset($settings[
'actions'][$settings[
'action']])) {
650 $save_file_response = array_get_index($request_data, $settings[
'action'].
'_file_response_to_save', Array());
651 foreach ($save_file_response as $index => $response_kwd) {
654 if (trim($response_kwd) ==
'') {
655 unset($save_file_response[$index]);
659 if (strpos($settings[
'response_keywords'][$settings[
'action']], $response_kwd) === FALSE) {
660 $settings[$settings[
'action'].
'_invalid_keywords_for_file'][] = $response_kwd;
663 $settings[$settings[
'action'].
'_file_response_to_save'] = $save_file_response;
667 $test_results = Array();
668 if ($settings[
'run_test']) {
670 foreach($functions as $function) {
671 $function_name = preg_replace(
'/^\w+ (\w+)\(.*\)/',
'$1', $function);
672 if($function_name != $settings[
'action'])
continue;
676 $settings[
'test_results'] = $test_results;
692 $replacements = Array();
695 replace_global_keywords($content);
697 $keyword_list = extract_keywords($content);
699 if (empty($keyword_list))
return $content;
701 foreach ($keyword_list as $keyword) {
702 $modified_keyword = parse_keyword($keyword, $modifiers);
703 $replacement[$keyword] = $asset->getKeywordReplacement($modified_keyword);
704 if (!empty($modifiers)) {
705 apply_keyword_modifiers($replacement[$keyword], $modifiers, Array(
'assetid' => $asset->id));
709 if (!empty($replacement)) replace_keywords($content, $replacement);