*/ require_once 'XML/RPC.php'; } else { if (substr(dirname(__FILE__), -9, -6) != 'XML') { echo "The parent directory must be named 'XML'.\n"; exit; } ini_set('include_path', '../../' . PATH_SEPARATOR . '.' . PATH_SEPARATOR . ini_get('include_path')); /** * Get the needed class from the parent directory */ require_once '../RPC.php'; } $input = "First lfs\n\nSecond crlfs\r\n\r\nThird crs\r\rFourth line"; $expect_removed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<methodCall>\n\n<methodName>nada</methodName>\n\n<params>\n\n<param>\n\n<value><string>First lfs\n\nSecond crlfs\n\nThird crs\n\nFourth line</string></value>\n\n</param>\n\n</params>\n\n</methodCall>\n\n"; $expect_not_removed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<methodCall>\n\n<methodName>nada</methodName>\n\n<params>\n\n<param>\n\n<value><string>First lfs\n\n\n\nSecond crlfs\n\n\n\nThird crs\n\n\n\nFourth line</string></value>\n\n</param>\n\n</params>\n\n</methodCall>\n\n"; $msg = new XML_RPC_Message('nada', array(XML_RPC_encode($input))); $msg->createPayload(); if ($msg->payload == $expect_removed) { echo "passed\n"; } else { echo "PROBLEM\n"; } $msg = new XML_RPC_Message('nada', array(XML_RPC_encode($input))); $msg->remove_extra_lines = false; $msg->createPayload(); if ($msg->payload == $expect_not_removed) { echo "passed\n"; } else { echo "PROBLEM\n"; }
function event_hook($event, &$bag, &$eventData) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'backend_display': ?> <fieldset style="margin: 5px"> <legend><?php echo PLUGIN_EVENT_WEBLOGPING_PING; ?> </legend> <?php $noneclick = ''; foreach ($this->services as $index => $service) { // Detect if the current checkbox needs to be saved. We use the field chk_timestamp to see, // if the form has already been submitted and individual changes shall be preserved $selected = $serendipity['POST']['chk_timestamp'] && $serendipity['POST']['announce_entries_' . $service['name']] || !isset($serendipity['POST']['chk_timestamp']) && $this->get_config($service['name']) == 'true' ? 'checked="checked"' : ''; $noneclick .= 'document.getElementById(\'serendipity[announce_entries_' . $service['name'] . ']\').checked = false; '; $onclick = ''; if (!empty($service['supersedes'])) { $onclick = 'onclick="'; $supersedes = explode(', ', $service['supersedes']); foreach ($supersedes as $sid => $servicename) { $onclick .= 'document.getElementById(\'serendipity[announce_entries_' . $servicename . ']\').checked = false; '; } $onclick .= '"'; } $title = sprintf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING, $service['name']) . (!empty($service['supersedes']) ? ' ' . sprintf(PLUGIN_EVENT_WEBLOGPING_SUPERSEDES, $service['supersedes']) : ''); ?> <input <?php echo $onclick; ?> class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" name="serendipity[announce_entries_<?php echo $service['name']; ?> ]" id="serendipity[announce_entries_<?php echo $service['name']; ?> ]" value="true" <?php echo $selected; ?> /> <label title="<?php echo $title; ?> " style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_<?php echo $service['name']; ?> ]"> <?php echo $service['name']; ?> </label><br /> <?php } ?> <input onclick="<?php echo $noneclick; ?> " class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" value="none" id="serendipity[announce_entries_none]" /> <label title="<?php echo NONE; ?> " style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_none]"> <?php echo NONE; ?> </label><br /> </fieldset> <?php return true; break; case 'backend_publish': if (!class_exists('XML_RPC_Base')) { include_once S9Y_PEAR_PATH . "XML/RPC.php"; } // First cycle through list of services to remove superseding services which may have been checked foreach ($this->services as $index => $service) { if (!empty($service['supersedes']) && isset($serendipity['POST']['announce_entries_' . $service['name']])) { $supersedes = explode(', ', $service['supersedes']); foreach ($supersedes as $sid => $servicename) { // A service has been checked that is superseded by another checked meta-service. Remove that service from the list of services to be ping'd unset($serendipity['POST']['announce_entries_' . $servicename]); } } } foreach ($this->services as $index => $service) { if (isset($serendipity['POST']['announce_entries_' . $service['name']]) || defined('SERENDIPITY_IS_XMLRPC') && serendipity_db_bool($this->get_config($service['name']))) { if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) { printf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING . '...', $service['host']); } flush(); # XXX append $serendipity['indexFile'] to baseURL? $args = array(new XML_RPC_Value($serendipity['blogTitle'], 'string'), new XML_RPC_Value($serendipity['baseURL'], 'string')); if ($service['extended']) { # the checkUrl: for when the main page is not really the main page $args[] = new XML_RPC_Value('', 'string'); # the rssUrl $args[] = new XML_RPC_Value($serendipity['baseURL'] . 'rss.php?version=2.0', 'string'); } $message = new XML_RPC_Message($service['extended'] ? 'weblogUpdates.extendedPing' : 'weblogUpdates.ping', $args); $client = new XML_RPC_Client(trim($service['path']), trim($service['host'])); # 15 second timeout may not be long enough for weblogs.com $message->createPayload(); $options = array(); serendipity_plugin_api::hook_event('backend_http_request', $options, 'weblogping'); serendipity_request_start(); $req = new HTTP_Request("http://" . $service['host'] . $service['path'], $options); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addHeader("Content-Type", "text/xml"); if (strtoupper(LANG_CHARSET) != 'UTF-8') { $payload = utf8_encode($message->payload); } else { $payload = $message->payload; } $req->addRawPostData($payload); $http_result = $req->sendRequest(); $http_response = $req->getResponseBody(); $xmlrpc_result = $message->parseResponse($http_response); if ($xmlrpc_result->faultCode()) { $out = sprintf(PLUGIN_EVENT_WEBLOGPING_SEND_FAILURE . "<br />", htmlspecialchars($xmlrpc_result->faultString())); } else { $out = PLUGIN_EVENT_WEBLOGPING_SEND_SUCCESS . "<br />"; } serendipity_request_end(); if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) { echo $out; } } } return true; break; case 'external_plugin': if ($eventData == 'xmlrpc_ping') { echo "XMLRPC START\n"; @define('SERENDIPITY_IS_XMLRPC', true); @define('SERENDIPITY_XMLRPC_VERBOSE', true); $this->event_hook('backend_publish', $bag, $eventData); echo "XMLRPC DONE\n"; } return true; case 'frontend_display': case 'backend_insert': case 'backend_update': case 'backend_draft': default: return false; break; } } else { return false; } }
/** * Transmit the RPC request via HTTP 1.0 protocol * Requests should be sent using XML_RPC_Client send() rather than * calling this method directly. * * @param XML_RPC_Message $msg the XML_RPC_Message object * @param string $server the server to send the request to * @param int $port the server port send the request to * @param int $timeout how many seconds to wait for the request * before giving up * @param string $userName a user name for accessing the RPC server * @param string $password a password for accessing the RPC server * @return XML_RPC_Response|int 0 is returned if any problems happen. * @see XML_RPC_Client::send() */ protected function sendPayloadHTTP10(XML_RPC_Message $msg, $server, $port, $timeout = 0, $userName = '', $password = '') { // Preemptive BC hacks for fools calling sendPayloadHTTP10() directly if ($userName != $this->userName) { $this->setCredentials($userName, $password); } // Only create the payload if it was not created previously if (empty($msg->payload)) { $msg->createPayload(); } $this->createHeaders($msg); $op = $this->headers . "\r\n\r\n"; $op .= $msg->payload; if ($this->debug) { echo "\n<pre>---SENT---\n"; echo $op; echo "\n---END---</pre>\n"; } /* * If we're using a proxy open a socket to the proxy server * instead to the xml-rpc server */ if ($this->proxy) { if ($this->proxyProtocol === 'http://') { $protocol = ''; } else { $protocol = $this->proxyProtocol; } if ($timeout > 0) { $fp = @fsockopen($protocol . $this->proxy, $this->proxyPort, $this->errNo, $this->errString, $timeout); } else { $fp = @fsockopen($protocol . $this->proxy, $this->proxyPort, $this->errNo, $this->errString); } } else { if ($this->protocol === 'http://') { $protocol = ''; } else { $protocol = $this->protocol; } if ($timeout > 0) { $fp = @fsockopen($protocol . $server, $port, $this->errNo, $this->errString, $timeout); } else { $fp = @fsockopen($protocol . $server, $port, $this->errNo, $this->errString); } } /* * Just raising the error without returning it is strange, * but keep it here for backwards compatibility. */ if (!$fp && $this->proxy) { $this->raiseError('Connection to proxy server ' . $this->proxy . ':' . $this->proxyPort . ' failed. ' . $this->errString, XML_RPC_ERROR_CONNECTION_FAILED); return 0; } elseif (!$fp) { $this->raiseError('Connection to RPC server ' . $server . ':' . $port . ' failed. ' . $this->errString, XML_RPC_ERROR_CONNECTION_FAILED); return 0; } if ($timeout) { /* * Using socket_set_timeout() because stream_set_timeout() * was introduced in 4.3.0, but we need to support 4.2.0. */ socket_set_timeout($fp, $timeout); } if (!fputs($fp, $op, strlen($op))) { $this->errString = 'Write error'; return 0; } $resp = $msg->parseResponseFile($fp); $meta = socket_get_status($fp); if ($meta['timed_out']) { fclose($fp); $this->errString = 'RPC server did not send response before timeout.'; $this->raiseError($this->errString, XML_RPC_ERROR_CONNECTION_FAILED); return 0; } fclose($fp); return $resp; }