function queryRemoteServer($url, $method, $params, $toArray = true) { global $config; include_once 'SOAP/Client.php'; $client = new SOAP_Client($url); if (!$config['utf8']) { $params = utf8_encode_recursive($params); } $response = $client->call($method, $params, array('namespace' => 'urn:DILPSQuery')); if (is_a($response, 'SOAP_Fault')) { $fault = $response->getFault(); $response = new stdClass(); $err = new stdClass(); $err->error = var_export($fault, true); $response->result = $err; } if ($toArray) { $response = _stdclass2array($response); if (!$config['utf8']) { $response = utf8_decode_recursive($response); } $result = $response['result']; } else { $result = $response->result; } return $result; }
function utf8_encode_recursive($array) { $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result[$key] = utf8_encode_recursive($value); } else { if (is_string($value)) { $result[$key] = utf8_encode($value); } else { $result[$key] = $value; } } } return $result; }
function utf8_encode_recursive(&$input) { if (is_string($input)) { $input = utf8_encode($input); } else { if (is_array($input)) { foreach ($input as &$value) { utf8_encode_recursive($value); } unset($value); } else { if (is_object($input)) { $vars = array_keys(get_object_vars($input)); foreach ($vars as $var) { utf8_encode_recursive($input->{$var}); } } } } }
function ninja_forms_json_response() { global $ninja_forms_processing; $form_id = $ninja_forms_processing->get_form_ID(); $errors = $ninja_forms_processing->get_all_errors(); $success = $ninja_forms_processing->get_all_success_msgs(); $fields = $ninja_forms_processing->get_all_fields(); $form_settings = $ninja_forms_processing->get_all_form_settings(); $extras = $ninja_forms_processing->get_all_extras(); // Success will default to false if there is not success message. if (!$success && !$errors) { $success = true; } if (version_compare(phpversion(), '5.3', '>=')) { $json = json_encode(array('form_id' => $form_id, 'errors' => $errors, 'success' => $success, 'fields' => $fields, 'form_settings' => $form_settings, 'extras' => $extras), JSON_HEX_QUOT | JSON_HEX_TAG); } else { $errors = ninja_forms_html_entity_decode_deep($errors); $success = ninja_forms_html_entity_decode_deep($success); $fields = ninja_forms_html_entity_decode_deep($fields); $form_settings = ninja_forms_html_entity_decode_deep($form_settings); $extras = ninja_forms_html_entity_decode_deep($extras); $errors = utf8_encode_recursive($errors); $success = utf8_encode_recursive($success); $fields = utf8_encode_recursive($fields); $form_settings = utf8_encode_recursive($form_settings); $extras = utf8_encode_recursive($extras); $errors = ninja_forms_str_replace_deep('"', "\\u0022", $errors); $errors = ninja_forms_str_replace_deep("'", "\\u0027", $errors); $errors = ninja_forms_str_replace_deep('<', "\\u003C", $errors); $errors = ninja_forms_str_replace_deep('>', "\\u003E", $errors); $success = ninja_forms_str_replace_deep('"', "\\u0022", $success); $success = ninja_forms_str_replace_deep("'", "\\u0027", $success); $success = ninja_forms_str_replace_deep('<', "\\u003C", $success); $success = ninja_forms_str_replace_deep('>', "\\u003E", $success); $fields = ninja_forms_str_replace_deep('"', "\\u0022", $fields); $fields = ninja_forms_str_replace_deep("'", "\\u0027", $fields); $fields = ninja_forms_str_replace_deep('<', "\\u003C", $fields); $fields = ninja_forms_str_replace_deep('>', "\\u003E", $fields); $form_settings = ninja_forms_str_replace_deep('"', "\\u0022", $form_settings); $form_settings = ninja_forms_str_replace_deep("'", "\\u0027", $form_settings); $form_settings = ninja_forms_str_replace_deep('<', "\\u003C", $form_settings); $form_settings = ninja_forms_str_replace_deep('>', "\\u003E", $form_settings); $extras = ninja_forms_str_replace_deep('"', "\\u0022", $extras); $extras = ninja_forms_str_replace_deep("'", "\\u0027", $extras); $extras = ninja_forms_str_replace_deep('<', "\\u003C", $extras); $extras = ninja_forms_str_replace_deep('>', "\\u003E", $extras); $json = json_encode(array('form_id' => $form_id, 'errors' => $errors, 'success' => $success, 'fields' => $fields, 'form_settings' => $form_settings, 'extras' => $extras)); $json = str_replace("\\\\u0022", "\\u0022", $json); $json = str_replace("\\\\u0027", "\\u0027", $json); $json = str_replace("\\\\u003C", "\\u003C", $json); $json = str_replace("\\\\u003E", "\\u003E", $json); } return $json; }
function utf8_encode_recursive($array) { foreach ($array as $key => $val) { if (is_string($val)) { $array[$key] = utf8_encode($val); } elseif (is_array($val)) { $array[$key] = utf8_encode_recursive($val); } } return $array; }
function queryCount($querystruct) { global $db, $db_prefix; if (is_object($querystruct)) { $querystruct = _stdclass2array($querystruct); } // take care of empty arrays which are mysteriously turned into empty strings by the soap monster: if (!is_array($querystruct['connectors'])) {$querystruct['connectors'] = array();} if (!is_array($querystruct['phrases'])) {$querystruct['phrases'] = array();} $dbQuery = new dilpsQuery($db, $db_prefix); $fields = 'count(*) as count'; //return array('result'=>array('count'=>'here')); $where = $dbQuery->buildWhere($querystruct) ." and {$db_prefix}meta.status = 'reviewed'"; $from = "{$db_prefix}meta "; $sql = "SELECT DISTINCT $fields FROM $from WHERE $where"; if ($rs = $db->GetRow($sql)) { $result = $rs; } else { $result = array('error'=>$db->ErrorMsg()); if ($this->needsUtf8Conversion) { $result = utf8_encode_recursive($result); } } $response = array('result'=>$result); return $response; }
/** * Recursively utf8_encodes all the strings in an array * * @param array $ar * * @return array */ function utf8_encode_recursive($ar) { $result = array(); foreach ($ar as $key => $el) { if (is_array($el)) { $result[$key] = utf8_encode_recursive($el); } else { if (is_string($el)) { $result[$key] = utf8_encode($el); } else { $result[$key] = $el; } } } return $result; }