18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
19 require_once
'soap_form_based_common.inc';
23 define(
'MAX_COMPLEX_TYPE_PASRSE_LOOP', 3);
40 private static $recent_parsed_type = Array();
49 public static function _store_results($object, $prefix =
'soap_', &$soap_response_keywords=Array(), $file_keywords)
51 if (empty($object))
return;
53 $vars = is_object($object) ? get_object_vars($object) : $object;
54 if (empty($vars))
return;
56 foreach ($vars as $index => $value) {
57 if (is_object($value) || is_array($value)) {
58 self::_store_results ($value, $prefix.$index, $soap_response_keywords, $file_keywords);
64 if (in_array(
'%globals_session_'.$prefix.$index.
'%', $file_keywords)) {
65 $link_value = self::_save_file($value);
66 $_SESSION[SQ_SESSION_SANDBOX_INDEX][$prefix.$index] = $link_value;
67 $soap_response_keywords[$prefix.$index] = $link_value;
69 $_SESSION[SQ_SESSION_SANDBOX_INDEX][$prefix.$index] = $value;
70 $soap_response_keywords[$prefix.$index] = $value;
86 $type_name = preg_replace(
'/ .*/',
'', $type);
88 $sub_types = self::_is_complex_type($type_name, $types);
92 return self::_is_array_type($type_name, $types);
96 self::$recent_parsed_type = Array();
99 $node =
new SimpleXMLElement(
'<'.$type_name.
'/>');
100 self::_parse_type_recursive($type, $types, $node);
112 private static function _is_array_type($param, $types)
115 $array_types = Array();
116 foreach($types as $type) {
117 if (substr($type, -2) ==
'[]') {
118 $array_type = explode(
' ', $type);
119 if (count($array_type) > 1) {
120 $array_types[rtrim($array_type[1],
'[]')] = $array_type[0];
125 return isset($array_types[$param]);
139 foreach (self::$recent_parsed_type as $parsed) {
140 if ($parsed == $param)
return;
142 array_push(self::$recent_parsed_type, $param);
143 if(count(self::$recent_parsed_type) > MAX_COMPLEX_TYPE_PASRSE_LOOP) {
144 array_shift(self::$recent_parsed_type);
147 $param_type = preg_replace(
'/ .*/',
'', $param);
148 $param_name = preg_replace(
'/.* (.*);/',
'$1', $param);
150 $is_param_array = FALSE;
151 $sub_types = self::_is_complex_type($param_type, $types);
152 if(!$sub_types)
return;
155 foreach ($sub_types as $type) {
156 $is_type_array = FALSE;
157 $sub_type_type = preg_replace(
'/ .*/',
'', $type);
158 $sub_type_name = preg_replace(
'/.* (.*);/',
'$1', $type);
159 $sub_sub_types = self::_is_complex_type($sub_type_type, $types, $is_type_array);
161 if (!$sub_sub_types || ($sub_type_type == $param_type)) {
163 $node->addChild($sub_type_name,
'??');
166 $new_node = $node->addChild($sub_type_name.($is_type_array ?
'[ARRAY_ELEMENT]' :
''));
167 self::_parse_type_recursive($type, $types, $new_node);
183 $array_types = Array();
184 foreach($types as $type) {
185 if (substr($type, -2) ==
'[]') {
186 $array_type = explode(
' ', $type);
187 if (count($array_type) > 1) {
188 $array_types[rtrim($array_type[1],
'[]')] = $array_type[0];
192 if (isset($array_types[$param])) {
193 $param = $array_types[$param];
197 foreach ($types as $type) {
198 if (preg_match (
'/struct '.$param.
'\s*{/', $type)) {
200 preg_match_all (
'/\w+ \w+;/', $type, $matches);
219 $xml = preg_replace(
'/(>)(<)(\/*)/',
"$1\n$2$3", $xml);
222 $token = strtok($xml,
"\n");
228 while ($token !==
false) :
233 if (preg_match(
'/.+<\/\w[^>]*>$/', $token, $matches)) :
236 elseif (preg_match(
'/^<\/\w/', $token, $matches)) :
239 elseif (preg_match(
'/^<\w[^>]*[^\/]>.*$/', $token, $matches)) :
247 $line = str_pad($token, strlen($token)+$pad,
' ', STR_PAD_LEFT);
248 $result .= $line .
"\n";
249 $token = strtok(
"\n");
266 if (!is_object($response_xml))
return '';
268 $data = get_object_vars($response_xml);
271 foreach ($data as $index => $sub_object) {
272 if(is_object($sub_object) && !empty($sub_object)) {
273 $keywords_list .= self::_parse_response_keywords($sub_object, $prefix.$index);
275 $keywords_list .=
'%'.$prefix.$index.
'%<br/>';
279 return $keywords_list;
296 if (isset($settings[
'login']) && isset($settings[
'password'])) {
297 $options[
'login'] = $settings[
'login'];
298 $options[
'password'] = $settings[
'password'];
302 if(!empty($settings[
'local_cert'])) {
303 $file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'local_cert']);
304 if(empty($file) || !method_exists($file,
'getExistingFile')) {
305 if (!is_null($form)) $form->submission_errors = array_merge($form->submission_errors, Array(translate(
'no_cert')));
308 $file_info = $file->getExistingFile();
309 $options[
'local_cert'] = $file_info[
'path'];
312 if(isset($settings[
'passphrase'])) {
313 $options[
'passphrase'] = $settings[
'passphrase'];
316 if ($settings[
'run_test']) {
317 $options[
'trace'] = 1;
320 if ($settings[
'mute_exceptions']) {
321 $options[
'exceptions'] = 0;
324 $options[
'cache_wsdl'] = WSDL_CACHE_NONE;
340 for($i = 0, $param = Array(); $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
341 if(isset($settings[$settings[
'action'].
'parameters'.$i])) {
343 $soap_message = $settings[$settings[
'action'].
'parameters'.$i];
344 $object = @simplexml_load_string($soap_message);
345 if (is_null($form)) {
347 $object = self::toArray($object);
358 foreach ($param as $index => $object) {
359 $eval_string .= $index == 0 ?
'' :
', ';
360 $eval_string .=
'$param['.$index.
']';
365 eval(
'$data = $client->$function('.$eval_string.
');');
366 $soap_request = $client->__getLastRequest();
367 $soap_response = $client->__getLastResponse();
370 catch (Exception $e) {
371 trigger_error($e->getMessage());
375 return Array(
'request' => $soap_request,
'response' => $soap_response);
394 $file_name = random_password(10, TRUE, TRUE);
395 $sessionid = session_id();
397 if (!is_dir(SQ_DATA_PATH.
'/private/soap_action_file_responses/'.$sessionid)) mkdir(SQ_DATA_PATH.
'/private/soap_action_file_responses/'.$sessionid, 0777, TRUE);
399 file_put_contents(SQ_DATA_PATH.
'/private/soap_action_file_responses/'.$sessionid.
'/'.$file_name, $content);
403 $file_url =
'./?SQ_ACTION=get_soap_downloaded_file&soap_filename='.$file_name;
419 if (is_object($data)) $data = get_object_vars($data);
422 if(empty($data))
return '';
424 if(is_array($data)) {
426 foreach ($data as $index => $element) {
427 $result[$index] = self::toArray($element);