public function writeOutput() { if ($this->isFault()) { XMLRPC_error($this->faultCode, $this->faultString); } elseif ($this->returnValue == null) { // TODO: Can we return nothing throuh xmlrpc? // TODO: Why is XMLRPC_prepare going nuts with an empty string passed? XMLRPC_response(XMLRPC_prepare("void")); } else { $type = $this->returnValue->getType(); if ($type == Types::DATE) { $convertedValue = XMLRPC_convert_timestamp_to_iso8601($this->returnValue->getValue()); } else { $convertedValue = $this->returnValue->getValue(); } XMLRPC_response(XMLRPC_prepare($convertedValue)); } }
function openthesaurus_searchSynonyms($query) { $start = getmicrotime(); $items = array(); $query_str = sprintf("\n\t\tSELECT words.id AS word_id, word, meaning_id\n\t\tFROM words, word_meanings, meanings\n\t\tWHERE \n\t\t\tword = '%s' AND\n\t\t\twords.id = word_meanings.word_id AND\n\t\t\tword_meanings.meaning_id = meanings.id AND\n\t\t\tmeanings.hidden = 0\n\t\n\t\tUNION\n\n\t\tSELECT words.id AS word_id, word, meaning_id\n\t\tFROM words, word_meanings, meanings\n\t\tWHERE \n\t\t\tlookup = '%s' AND\n\t\t\twords.id = word_meanings.word_id AND\n\t\t\tword_meanings.meaning_id = meanings.id AND\n\t\t\tmeanings.hidden = 0\n\n\t\tORDER BY word", myaddslashes($query), myaddslashes($query), myaddslashes($query), myaddslashes($query)); $db = new DB_Thesaurus(); $db->query($query_str); $synmatches = 1; if ($db->nf() == 0) { $item['words'] = array(); $items[] = $item; } while ($db->next_record()) { $mid = $db->f('meaning_id'); $item['words'] = getSynsetWithUsage($db->f('meaning_id'), 1); $items[] = $item; } $_GET['search'] = 1; # otherwise logSearch ignores the search logSearch($db, $query, $db->nf(), 0, getEndTimer(), 1); XMLRPC_response(XMLRPC_prepare($items), KD_XMLRPC_USERAGENT); }
function mt_publishPost($params) { global $loq; if ($loq->userauth($params[1], $params[2])) { // password accepted ob_start(); XMLRPC_response(XMLRPC_prepare(true), WEBLOG_XMLPRPC_USERAGENT); } else { XMLRPC_error("301", "The username and password you entered was not accepted. Please try again.", WEBLOG_XMLRPC_USERAGENT); } }
function sayHello($params) { $result = 'Привет, ' . $params[0] . '!'; XMLRPC_response(XMLRPC_prepare($result), WEBLOG_XMLRPC_USERAGENT); }
// Налоги и сборы, в % $taxes = array('НДС' => 18, 'Налог с продаж' => 5, 'Обработка заказа' => 10); // XML-PRC сервер require 'xmlrpc.php'; // Включим отладку define('XMLRPC_DEBUG', true); // Декларация методов и назначение методам функций $xmlrpc_methods = array('eshop.getDeliveryMethods' => 'getDeliveryMethods', 'eshop.calculateOrder' => 'calculateOrder'); // Обработка запроса $xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA); $methodName = XMLRPC_getMethodName($xmlrpc_request); $params = XMLRPC_getParams($xmlrpc_request); if (isset($xmlrpc_methods[$methodName])) { // Вызов метода $result = $xmlrpc_methods[$methodName]($params); XMLRPC_response(XMLRPC_prepare($result), WEBLOG_XMLRPC_USERAGENT); } else { // Ошибка: Нет такого метода XMLRPC_error('2', "Метод '{$methodName}' не найден.", WEBLOG_XMLRPC_USERAGENT); } // ----------------------------- Бизнес - логика ----------------------------- // Функция возвращает методы доставки function getDeliveryMethods($params) { global $deliveryMethods; return $deliveryMethods; } // Функция возвращает расчет стоимости заказа function calculateOrder($params) { global $deliveryMethods, $deliveryCost, $taxes;
// Include the xmlrpc library. require_once 'kd_xmlrpc.php'; $mgSessionId = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST['SESSION'] : $_GET['SESSION']; $success = false; $long = 0; $lat = 0; try { // Initialize the Web Extensions and connect to the Server using // the Web Extensions session identifier stored in PHP session state. MgInitializeWebTier($configFilePath); $userInfo = new MgUserInformation($mgSessionId); $siteConnection = new MgSiteConnection(); $siteConnection->Open($userInfo); $address = $_GET['address'] . ', Sheboygan, WI'; // Make the request to geocoder.us passing the address. list($success, $response) = XMLRPC_request('rpc.geocoder.us', '/service/xmlrpc', 'geocode', array(XMLRPC_prepare($address))); // Stuff the response into a new variable: $nested_array = $response; // For some reason (presumably a good one), geocoder.us responds with a nested // array. We need to extract the inner array from the outer and stuff it into a // new variable: $geoarray = array_pop($nested_array); // The $success variable is intended for error handling, but since geocoder.us // will send an error response to invalid queries (thus flagging $success to 1), // we can't use this to check for errors. Instead, we'll check the values in the // array and deem success or failure based on that. if (array_key_exists('lat', $geoarray) && array_key_exists('long', $geoarray)) { // The geocode successfully returned a location. $lat = $geoarray['lat']; $long = $geoarray['long']; // Build an address1 and address2 variables from the result.
function &XMLRPC_prepare($data, $type = NULL) { if (is_array($data) || is_object($data)) { // Иван Никитин: для PHP5 проверка is_object обязательна! $num_elements = count($data); if ((array_key_exists(0, $data) or !$num_elements) and $type != 'struct') { #it's an array if (!$num_elements) { #if the array is empty $returnvalue = array('array' => array('data' => NULL)); } else { $returnvalue['array']['data']['value'] = array(); $temp =& $returnvalue['array']['data']['value']; $count = count_numeric_items($data); for ($n = 0; $n < $count; $n++) { $type = NULL; if (array_key_exists("{$n} type", $data)) { $type = $data["{$n} type"]; } $temp[$n] = XMLRPC_prepare($data[$n], $type); } } } else { #it's a struct if (!$num_elements) { #if the struct is empty $returnvalue = array('struct' => NULL); } else { $returnvalue['struct']['member'] = array(); $temp =& $returnvalue['struct']['member']; while (list($key, $value) = each($data)) { if (substr($key, -5) != ' type') { #if it's not a type specifier $type = NULL; if (array_key_exists("{$key} type", $data)) { $type = $data["{$key} type"]; } $temp[] = array('name' => $key, 'value' => XMLRPC_prepare($value, $type)); } } } } } else { #it's a scalar if (!$type) { if (is_int($data)) { $returnvalue['int'] = $data; return $returnvalue; } elseif (is_float($data)) { $returnvalue['double'] = $data; return $returnvalue; } elseif (is_bool($data)) { $returnvalue['boolean'] = $data ? 1 : 0; return $returnvalue; } elseif (preg_match('/^\\d{8}T\\d{2}:\\d{2}:\\d{2}$/', $data, $matches)) { #it's a date $returnvalue['dateTime.iso8601'] = $data; return $returnvalue; } elseif (is_string($data)) { $returnvalue['string'] = htmlspecialchars($data); return $returnvalue; } } else { $returnvalue[$type] = htmlspecialchars($data); } } return $returnvalue; }
function metaWeblog_getRecentPosts($count) { // SPEC: metaWeblog.getRecentPosts (postid, username, password[, count]) returns struct $posts = array(); foreach ($this->ParentDocument->getChildren($count) as $d) { $posts[] = $this->_convertDocumentToStruct($d); } XMLRPC_response(XMLRPC_prepare($posts), IMPCMS_USERAGENT); }
<title>Example OpenThesaurus KD XML RPC News Client</title> </head> <body> <?php /* client.php */ include "kd_xmlrpc.php"; $query = "lange"; # must be in utf-8(?) #online server: $site = "www.openthesaurus.de"; $location = "/webservice/server.php"; #lokaler test: #$site = "localhost"; #$location = "/openthesaurus/www/webservice/server.php"; list($success, $response) = XMLRPC_request($site, $location, 'openthesaurus.searchSynonyms', array(XMLRPC_prepare($query))); if ($success) { $count = 0; while (list($key, $val) = each($response)) { print join(', ', $response[$count]['words']); print "<br />"; $count++; } } else { print "<p>Error: " . nl2br($response['faultString']); } ?> </body> </html>
<?php include 'inc/xmlrpc.php'; $pingname = $settings['sitename']; $pingfeed = $settings['url'] . "/podcast.php"; $pingurl = $settings['url']; //ping audio.weblogs.com @XMLRPC_request("audiorpc.weblogs.com", "/RPC2", "weblogUpdates.ping", array(XMLRPC_prepare($pingname), XMLRPC_prepare($pingurl)), "Loudblog"); //user agent //ping audio.weblogs.com RSS @XMLRPC_request("audiorpc.weblogs.com", "/RPC2", "rssUpdate", array(XMLRPC_prepare($pingname), XMLRPC_prepare($pingfeed)), "Loudblog"); //user agent //ping ping-o-matic @XMLRPC_request("rpc.pingomatic.com", "/RPC2", "weblogUpdates.ping", array(XMLRPC_prepare($pingname), XMLRPC_prepare($pingurl), XMLRPC_prepare(""), XMLRPC_prepare($pingfeed)), "Loudblog"); //user agent