mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Outdated ping functions removed from news and gsitemap. xmlrpc classes removed.
This commit is contained in:
parent
645c05cfbf
commit
68e251d771
@ -461,7 +461,7 @@ class news_admin_ui extends e_admin_ui
|
||||
'news_meta_robots' => array('title' => LAN_ROBOTS, 'type' => 'dropdown', 'data'=>'safestr', 'tab'=>1, 'inline'=>true, 'readParms'=>array('type'=>'checkboxes'), 'writeParms'=>array('multiple'=>1), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch'=>true, 'filter'=>true),
|
||||
|
||||
'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'batch'=>1, 'data'=>'str', 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'writeParms'=>array('size'=>'xxlarge', 'show'=>1, 'sef'=>'news_title')),
|
||||
'news_ping' => array('title' => LAN_PING, 'type' => 'checkbox', 'tab'=>1, 'data'=>false, 'writeParms'=>'value=0', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
|
||||
// 'news_ping' => array('title' => LAN_PING, 'type' => 'checkbox', 'tab'=>1, 'data'=>false, 'writeParms'=>'value=0', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
|
||||
|
||||
'news_author' => array('title' => LAN_AUTHOR, 'type' => 'method', 'tab'=>2, 'readParms'=>'idField=user_id&nameField=user_name', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
|
||||
'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'data'=>'int', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'filter'=>true),
|
||||
@ -490,8 +490,6 @@ class news_admin_ui extends e_admin_ui
|
||||
protected $prefs = array(
|
||||
|
||||
'news_category' => array('title' => NWSLAN_127, 'type' => 'dropdown', 'help'=> "Determines how the default news page should appear."),
|
||||
'news_ping_services' => array('title' => "Ping Services", 'type' => 'textarea', 'data'=> 'help'=> ">Notify these services when you create/update news items. <br />One per line."),
|
||||
|
||||
|
||||
|
||||
);
|
||||
@ -654,7 +652,7 @@ class news_admin_ui extends e_admin_ui
|
||||
}
|
||||
|
||||
|
||||
$this->processPings();
|
||||
|
||||
e107::getEvent()->trigger('newspost',$new_data);
|
||||
// e107::getEvent()->trigger('admin_news_created',$new_data);
|
||||
$evdata = array('method'=>'create', 'table'=>'news', 'id'=>$id, 'plugin'=>'news', 'function'=>'submit_item');
|
||||
@ -674,7 +672,7 @@ class news_admin_ui extends e_admin_ui
|
||||
$this->triggerNotify($new_data);
|
||||
}
|
||||
|
||||
$this->processPings();
|
||||
|
||||
|
||||
e107::getEvent()->trigger('newsupd', $new_data);
|
||||
// e107::getEvent()->trigger('admin_news_updated',$new_data);
|
||||
@ -777,7 +775,7 @@ class news_admin_ui extends e_admin_ui
|
||||
'news_meta_keywords',
|
||||
'news_meta_description' ,
|
||||
'news_meta_robots' ,
|
||||
'news_ping',
|
||||
|
||||
|
||||
'news_email_notify',
|
||||
'news_allow_comments' ,
|
||||
@ -960,7 +958,7 @@ class news_admin_ui extends e_admin_ui
|
||||
$temp['news_newdateheader'] = intval($_POST['news_newdateheader']);
|
||||
$temp['news_unstemplate'] = intval($_POST['news_unstemplate']);
|
||||
$temp['news_editauthor'] = intval($_POST['news_editauthor']);
|
||||
$temp['news_ping_services'] = explode("\n",$_POST['news_ping_services']);
|
||||
|
||||
$temp['news_default_template'] = preg_replace('#[^\w\pL\-]#u', '', $_POST['news_default_template']);
|
||||
$temp['news_list_limit'] = intval($_POST['news_list_limit']);
|
||||
$temp['news_list_templates'] = e107::getParser()->toDB($_POST['news_list_templates']);
|
||||
@ -977,174 +975,6 @@ class news_admin_ui extends e_admin_ui
|
||||
|
||||
|
||||
|
||||
|
||||
function processPings()
|
||||
{
|
||||
|
||||
// Ping Changes to Services.
|
||||
$pingServices = e107::getPref('news_ping_services');
|
||||
//TODO Use Ajax with progress-bar.
|
||||
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$mes->addDebug(LAN_NEWS_107,'default',true);
|
||||
|
||||
if(!empty($_POST['news_ping']) && (count($pingServices)>0) && (in_array(e_UC_PUBLIC, $_POST['news_class'])))
|
||||
{
|
||||
$mes->addDebug("Initiating ping",'default',true);
|
||||
|
||||
include (e_HANDLER.'xmlrpc/xmlrpc.inc.php');
|
||||
include (e_HANDLER.'xmlrpc/xmlrpcs.inc.php');
|
||||
include (e_HANDLER.'xmlrpc/xmlrpc_wrappers.inc.php');
|
||||
|
||||
$extendedServices = array('blogsearch.google.com');
|
||||
|
||||
$port = 80;
|
||||
|
||||
foreach($pingServices as $fullUrl)
|
||||
{
|
||||
$fullUrl = str_replace("http://","", trim($fullUrl));
|
||||
list($server,$path) = explode("/",$fullUrl, 2);
|
||||
|
||||
$path = "/".$path;
|
||||
|
||||
$weblog_name = SITENAME;
|
||||
$weblog_url = $_SERVER['HTTP_HOST'].e_HTTP;
|
||||
$changes_url = $_SERVER['HTTP_HOST'].e107::getUrl()->create('news/view/item', $_POST); // $_SERVER['HTTP_HOST'].e_HTTP."news.php?extend.".$_POST['news_id'];
|
||||
$cat_or_rss = $_SERVER['HTTP_HOST'].e_PLUGIN_ABS."rss_menu/rss.php?1.2";
|
||||
$extended = (in_array($server, $extendedServices)) ? true : false;
|
||||
|
||||
if($this->ping($server, $port, $path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss, $extended))
|
||||
{
|
||||
e107::getMessage()->addInfo("Successfully Pinged: ".$server .' with:<br />url: '.$changes_url .'<br />rss: '.$cat_or_rss , 'default', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
e107::getMessage()->addDebug("Ping failed!: ".$server .' with: '.$changes_url , 'default', true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// $mes->addDebug('Ping not triggerred','default',true);
|
||||
// $mes->addDebug("Services: ".print_a($pingServices, true),'default', true);
|
||||
// $mes->addDebug("Userclass: ".print_a($_POST['news_class'],true),'default', true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Multi-purpose ping for any XML-RPC server that supports the Weblogs.Com interface. */
|
||||
function ping($xml_rpc_server, $xml_rpc_port, $xml_rpc_path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss='', $extended = false)
|
||||
{
|
||||
$mes = e107::getMessage();
|
||||
$log = e107::getAdminLog();
|
||||
|
||||
$mes->addDebug("Attempting to ping: ".$xml_rpc_server, 'default', true);
|
||||
|
||||
|
||||
$name_param = new xmlrpcval($weblog_name, 'string');
|
||||
$url_param = new xmlrpcval($weblog_url, 'string');
|
||||
$changes_param = new xmlrpcval($changes_url, 'string');
|
||||
$cat_or_rss_param = new xmlrpcval($cat_or_rss, 'string');
|
||||
$method_name = ($extended) ? "weblogUpdates.extendedPing" : "weblogUpdates.ping";
|
||||
|
||||
if ($cat_or_rss != "")
|
||||
{
|
||||
$params = array($name_param, $url_param, $changes_param, $cat_or_rss_param);
|
||||
$call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\", \"$cat_or_rss\")";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($changes_url != "")
|
||||
{
|
||||
$params = array($name_param, $url_param, $changes_param);
|
||||
$call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\")";
|
||||
}
|
||||
else
|
||||
{
|
||||
$params = array($name_param, $url_param);
|
||||
$call_text = "$method_name(\"$weblog_name\", \"$weblog_url\")";
|
||||
}
|
||||
}
|
||||
|
||||
// create the message
|
||||
$message = new xmlrpcmsg($method_name, $params);
|
||||
$client = new xmlrpc_client($xml_rpc_path, $xml_rpc_server, $xml_rpc_port);
|
||||
$response = $client->send($message);
|
||||
|
||||
$this->log_ping("Request: " . $call_text);
|
||||
$this->log_ping($message->serialize(), true);
|
||||
|
||||
if ($response == 0)
|
||||
{
|
||||
$error_text = "Error: " . $xml_rpc_server . ": " . $client->errno . " " . $client->errstring;
|
||||
$this->report_error($error_text);
|
||||
$this->log_ping($error_text);
|
||||
$log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$client->errstring))->save('PING_01');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response->faultCode() != 0)
|
||||
{
|
||||
$error_text = "Error: " . $xml_rpc_server . ": " . $response->faultCode() . " " . $response->faultString();
|
||||
$this->report_error($error_text);
|
||||
$log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$response->faultString()))->save('PING_01');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$response_value = $response->value();
|
||||
if ($this->debug)
|
||||
{
|
||||
$this->report_error($response_value->serialize());
|
||||
}
|
||||
|
||||
$this->log_ping($response_value->serialize(), true);
|
||||
|
||||
/** @var xmlrpcval $fl_error */
|
||||
$fl_error = $response_value->structmem('flerror');
|
||||
|
||||
/** @var xmlrpcval $message */
|
||||
$message = $response_value->structmem('message');
|
||||
|
||||
// read the response
|
||||
if ($fl_error->scalarval() != false)
|
||||
{
|
||||
$error_text = "Error: " . $xml_rpc_server . ": " . $message->scalarval();
|
||||
$this->report_error($error_text);
|
||||
$log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01');
|
||||
|
||||
// $this->log_ping($error_text);
|
||||
return false;
|
||||
}
|
||||
|
||||
$log->addArray(array('status'=>LAN_OK, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// save ping data to a log file
|
||||
function log_ping($message, $xml_data = false)
|
||||
{
|
||||
$message = $xml_data." ".$message;
|
||||
file_put_contents(e_LOG."news_ping.log", $message, FILE_APPEND);
|
||||
}
|
||||
|
||||
// sDisplay Ping errors.
|
||||
function report_error($message)
|
||||
{
|
||||
e107::getMessage()->addError($message, 'default', true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function submittedPage()
|
||||
{
|
||||
$this->newspost->show_submitted_news();
|
||||
@ -1170,8 +1000,7 @@ class news_admin_ui extends e_admin_ui
|
||||
$frm = e107::getForm();
|
||||
|
||||
$sefbaseDiz = str_replace(array("[br]","[","]"), array("<br />","<a href='".e_ADMIN_ABS."eurl.php'>","</a>"), NWSLAN_128 );
|
||||
$pingOpt = array('placeholder'=>LAN_NEWS_87);
|
||||
$pingVal = (!empty($pref['news_ping_services'])) ? implode("\n",$pref['news_ping_services']) : '';
|
||||
|
||||
|
||||
$newsTemplates = array();
|
||||
|
||||
@ -1229,13 +1058,7 @@ class news_admin_ui extends e_admin_ui
|
||||
<div class='field-help'>".LAN_NEWS_94."</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>".LAN_NEWS_98."</td>
|
||||
<td>
|
||||
".$frm->textarea('news_ping_services', $pingVal, 4, 100, $pingOpt)."
|
||||
<div class='field-help'>".LAN_NEWS_89."<br />".LAN_NEWS_90."</div>
|
||||
</td>
|
||||
</tr>";
|
||||
";
|
||||
|
||||
|
||||
$tab1 .= "
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,955 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP-XMLRPC "wrapper" functions
|
||||
* Generate stubs to transparently access xmlrpc methods as php functions and viceversa
|
||||
*
|
||||
* @version $Id$
|
||||
* @author Gaetano Giunta
|
||||
* @copyright (C) 2006-2009 G. Giunta
|
||||
* @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
|
||||
*
|
||||
* @todo separate introspection from code generation for func-2-method wrapping
|
||||
* @todo use some better templating system for code generation?
|
||||
* @todo implement method wrapping with preservation of php objs in calls
|
||||
* @todo when wrapping methods without obj rebuilding, use return_type = 'phpvals' (faster)
|
||||
* @todo implement self-parsing of php code for PHP <= 4
|
||||
*/
|
||||
|
||||
// requires: xmlrpc.inc.php
|
||||
|
||||
/**
|
||||
* Given a string defining a php type or phpxmlrpc type (loosely defined: strings
|
||||
* accepted come from javadoc blocks), return corresponding phpxmlrpc type.
|
||||
* NB: for php 'resource' types returns empty string, since resources cannot be serialized;
|
||||
* for php class names returns 'struct', since php objects can be serialized as xmlrpc structs
|
||||
* for php arrays always return array, even though arrays sometiles serialize as json structs
|
||||
* @param string $phptype
|
||||
* @return string
|
||||
*/
|
||||
function php_2_xmlrpc_type($phptype)
|
||||
{
|
||||
switch(strtolower($phptype))
|
||||
{
|
||||
case 'string':
|
||||
return $GLOBALS['xmlrpcString'];
|
||||
case 'integer':
|
||||
case $GLOBALS['xmlrpcInt']: // 'int'
|
||||
case $GLOBALS['xmlrpcI4']:
|
||||
return $GLOBALS['xmlrpcInt'];
|
||||
case 'double':
|
||||
return $GLOBALS['xmlrpcDouble'];
|
||||
case 'boolean':
|
||||
return $GLOBALS['xmlrpcBoolean'];
|
||||
case 'array':
|
||||
return $GLOBALS['xmlrpcArray'];
|
||||
case 'object':
|
||||
return $GLOBALS['xmlrpcStruct'];
|
||||
case $GLOBALS['xmlrpcBase64']:
|
||||
case $GLOBALS['xmlrpcStruct']:
|
||||
return strtolower($phptype);
|
||||
case 'resource':
|
||||
return '';
|
||||
default:
|
||||
if(class_exists($phptype))
|
||||
{
|
||||
return $GLOBALS['xmlrpcStruct'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown: might be any 'extended' xmlrpc type
|
||||
return $GLOBALS['xmlrpcValue'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string defining a phpxmlrpc type return corresponding php type.
|
||||
* @param string $xmlrpctype
|
||||
* @return string
|
||||
*/
|
||||
function xmlrpc_2_php_type($xmlrpctype)
|
||||
{
|
||||
switch(strtolower($xmlrpctype))
|
||||
{
|
||||
case 'base64':
|
||||
case 'datetime.iso8601':
|
||||
case 'string':
|
||||
return $GLOBALS['xmlrpcString'];
|
||||
case 'int':
|
||||
case 'i4':
|
||||
return 'integer';
|
||||
case 'struct':
|
||||
case 'array':
|
||||
return 'array';
|
||||
case 'double':
|
||||
return 'float';
|
||||
case 'undefined':
|
||||
return 'mixed';
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
default:
|
||||
// unknown: might be any xmlrpc type
|
||||
return strtolower($xmlrpctype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a user-defined PHP function, create a PHP 'wrapper' function that can
|
||||
* be exposed as xmlrpc method from an xmlrpc_server object and called from remote
|
||||
* clients (as well as its corresponding signature info).
|
||||
*
|
||||
* Since php is a typeless language, to infer types of input and output parameters,
|
||||
* it relies on parsing the javadoc-style comment block associated with the given
|
||||
* function. Usage of xmlrpc native types (such as datetime.dateTime.iso8601 and base64)
|
||||
* in the @param tag is also allowed, if you need the php function to receive/send
|
||||
* data in that particular format (note that base64 encoding/decoding is transparently
|
||||
* carried out by the lib, while datetime vals are passed around as strings)
|
||||
*
|
||||
* Known limitations:
|
||||
* - requires PHP 5.0.3 +
|
||||
* - only works for user-defined functions, not for PHP internal functions
|
||||
* (reflection does not support retrieving number/type of params for those)
|
||||
* - functions returning php objects will generate special xmlrpc responses:
|
||||
* when the xmlrpc decoding of those responses is carried out by this same lib, using
|
||||
* the appropriate param in php_xmlrpc_decode, the php objects will be rebuilt.
|
||||
* In short: php objects can be serialized, too (except for their resource members),
|
||||
* using this function.
|
||||
* Other libs might choke on the very same xml that will be generated in this case
|
||||
* (i.e. it has a nonstandard attribute on struct element tags)
|
||||
* - usage of javadoc @param tags using param names in a different order from the
|
||||
* function prototype is not considered valid (to be fixed?)
|
||||
*
|
||||
* Note that since rel. 2.0RC3 the preferred method to have the server call 'standard'
|
||||
* php functions (ie. functions not expecting a single xmlrpcmsg obj as parameter)
|
||||
* is by making use of the functions_parameters_type class member.
|
||||
*
|
||||
* @param string $funcname the name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') and array('class', 'methodname') are ok too
|
||||
* @param string $newfuncname (optional) name for function to be created
|
||||
* @param array $extra_options (optional) array of options for conversion. valid values include:
|
||||
* bool return_source when true, php code w. function definition will be returned, not evaluated
|
||||
* bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
|
||||
* bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
|
||||
* bool suppress_warnings remove from produced xml any runtime warnings due to the php function being invoked
|
||||
* @return false on error, or an array containing the name of the new php function,
|
||||
* its signature and docs, to be used in the server dispatch map
|
||||
*
|
||||
* @todo decide how to deal with params passed by ref: bomb out or allow?
|
||||
* @todo finish using javadoc info to build method sig if all params are named but out of order
|
||||
* @todo add a check for params of 'resource' type
|
||||
* @todo add some trigger_errors / error_log when returning false?
|
||||
* @todo what to do when the PHP function returns NULL? we are currently returning an empty string value...
|
||||
* @todo add an option to suppress php warnings in invocation of user function, similar to server debug level 3?
|
||||
* @todo if $newfuncname is empty, we could use create_user_func instead of eval, as it is possibly faster
|
||||
* @todo add a verbatim_object_copy parameter to allow avoiding the same obj instance?
|
||||
*/
|
||||
function wrap_php_function($funcname, $newfuncname='', $extra_options=array())
|
||||
{
|
||||
$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
|
||||
$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
|
||||
$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
|
||||
$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
|
||||
$catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';
|
||||
|
||||
if(version_compare(phpversion(), '5.0.3') == -1)
|
||||
{
|
||||
// up to php 5.0.3 some useful reflection methods were missing
|
||||
error_log('XML-RPC: cannot not wrap php functions unless running php version bigger than 5.0.3');
|
||||
return false;
|
||||
}
|
||||
|
||||
$exists = false;
|
||||
if (is_string($funcname) && strpos($funcname, '::') !== false)
|
||||
{
|
||||
$funcname = explode('::', $funcname);
|
||||
}
|
||||
if(is_array($funcname))
|
||||
{
|
||||
if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))
|
||||
{
|
||||
error_log('XML-RPC: syntax for function to be wrapped is wrong');
|
||||
return false;
|
||||
}
|
||||
if(is_string($funcname[0]))
|
||||
{
|
||||
$plainfuncname = implode('::', $funcname);
|
||||
}
|
||||
elseif(is_object($funcname[0]))
|
||||
{
|
||||
$plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];
|
||||
}
|
||||
$exists = method_exists($funcname[0], $funcname[1]);
|
||||
if (!$exists && version_compare(phpversion(), '5.1') < 0)
|
||||
{
|
||||
// workaround for php 5.0: static class methods are not seen by method_exists
|
||||
$exists = is_callable( $funcname );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$plainfuncname = $funcname;
|
||||
$exists = function_exists($funcname);
|
||||
}
|
||||
|
||||
if(!$exists)
|
||||
{
|
||||
error_log('XML-RPC: function to be wrapped is not defined: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine name of new php function
|
||||
if($newfuncname == '')
|
||||
{
|
||||
if(is_array($funcname))
|
||||
{
|
||||
if(is_string($funcname[0]))
|
||||
$xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
|
||||
else
|
||||
$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlrpcfuncname = "{$prefix}_$funcname";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlrpcfuncname = $newfuncname;
|
||||
}
|
||||
while($buildit && function_exists($xmlrpcfuncname))
|
||||
{
|
||||
$xmlrpcfuncname .= 'x';
|
||||
}
|
||||
|
||||
// start to introspect PHP code
|
||||
if(is_array($funcname))
|
||||
{
|
||||
$func = new ReflectionMethod($funcname[0], $funcname[1]);
|
||||
if($func->isPrivate())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
if($func->isProtected())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
if($func->isConstructor())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
// php 503 always says isdestructor = true...
|
||||
if( version_compare(phpversion(), '5.0.3') != 0 && $func->isDestructor())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
if($func->isAbstract())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
/// @todo add more checks for static vs. nonstatic?
|
||||
}
|
||||
else
|
||||
{
|
||||
$func = new ReflectionFunction($funcname);
|
||||
}
|
||||
if($func->isInternal())
|
||||
{
|
||||
// Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs
|
||||
// instead of getparameters to fully reflect internal php functions ?
|
||||
error_log('XML-RPC: function to be wrapped is internal: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
|
||||
// retrieve parameter names, types and description from javadoc comments
|
||||
|
||||
// function description
|
||||
$desc = '';
|
||||
// type of return val: by default 'any'
|
||||
$returns = $GLOBALS['xmlrpcValue'];
|
||||
// desc of return val
|
||||
$returnsDocs = '';
|
||||
// type + name of function parameters
|
||||
$paramDocs = array();
|
||||
|
||||
$docs = $func->getDocComment();
|
||||
if($docs != '')
|
||||
{
|
||||
$docs = explode("\n", $docs);
|
||||
$i = 0;
|
||||
foreach($docs as $doc)
|
||||
{
|
||||
$doc = trim($doc, " \r\t/*");
|
||||
if(strlen($doc) && strpos($doc, '@') !== 0 && !$i)
|
||||
{
|
||||
if($desc)
|
||||
{
|
||||
$desc .= "\n";
|
||||
}
|
||||
$desc .= $doc;
|
||||
}
|
||||
elseif(strpos($doc, '@param') === 0)
|
||||
{
|
||||
// syntax: @param type [$name] desc
|
||||
if(preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
|
||||
{
|
||||
if(strpos($matches[1], '|'))
|
||||
{
|
||||
//$paramDocs[$i]['type'] = explode('|', $matches[1]);
|
||||
$paramDocs[$i]['type'] = 'mixed';
|
||||
}
|
||||
else
|
||||
{
|
||||
$paramDocs[$i]['type'] = $matches[1];
|
||||
}
|
||||
$paramDocs[$i]['name'] = trim($matches[2]);
|
||||
$paramDocs[$i]['doc'] = $matches[3];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
elseif(strpos($doc, '@return') === 0)
|
||||
{
|
||||
// syntax: @return type desc
|
||||
//$returns = preg_split('/\s+/', $doc);
|
||||
if(preg_match('/@return\s+(\S+)\s+(.+)/', $doc, $matches))
|
||||
{
|
||||
$returns = php_2_xmlrpc_type($matches[1]);
|
||||
if(isset($matches[2]))
|
||||
{
|
||||
$returnsDocs = $matches[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// execute introspection of actual function prototype
|
||||
$params = array();
|
||||
$i = 0;
|
||||
foreach($func->getParameters() as $paramobj)
|
||||
{
|
||||
$params[$i] = array();
|
||||
$params[$i]['name'] = '$'.$paramobj->getName();
|
||||
$params[$i]['isoptional'] = $paramobj->isOptional();
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
// start building of PHP code to be eval'd
|
||||
$innercode = '';
|
||||
$i = 0;
|
||||
$parsvariations = array();
|
||||
$pars = array();
|
||||
$pnum = count($params);
|
||||
foreach($params as $param)
|
||||
{
|
||||
if (isset($paramDocs[$i]['name']) && $paramDocs[$i]['name'] && strtolower($paramDocs[$i]['name']) != strtolower($param['name']))
|
||||
{
|
||||
// param name from phpdoc info does not match param definition!
|
||||
$paramDocs[$i]['type'] = 'mixed';
|
||||
}
|
||||
|
||||
if($param['isoptional'])
|
||||
{
|
||||
// this particular parameter is optional. save as valid previous list of parameters
|
||||
$innercode .= "if (\$paramcount > $i) {\n";
|
||||
$parsvariations[] = $pars;
|
||||
}
|
||||
$innercode .= "\$p$i = \$msg->getParam($i);\n";
|
||||
if ($decode_php_objects)
|
||||
{
|
||||
$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i, array('decode_php_objs'));\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i);\n";
|
||||
}
|
||||
|
||||
$pars[] = "\$p$i";
|
||||
$i++;
|
||||
if($param['isoptional'])
|
||||
{
|
||||
$innercode .= "}\n";
|
||||
}
|
||||
if($i == $pnum)
|
||||
{
|
||||
// last allowed parameters combination
|
||||
$parsvariations[] = $pars;
|
||||
}
|
||||
}
|
||||
|
||||
$sigs = array();
|
||||
$psigs = array();
|
||||
if(count($parsvariations) == 0)
|
||||
{
|
||||
// only known good synopsis = no parameters
|
||||
$parsvariations[] = array();
|
||||
$minpars = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$minpars = count($parsvariations[0]);
|
||||
}
|
||||
|
||||
if($minpars)
|
||||
{
|
||||
// add to code the check for min params number
|
||||
// NB: this check needs to be done BEFORE decoding param values
|
||||
$innercode = "\$paramcount = \$msg->getNumParams();\n" .
|
||||
"if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n" . $innercode;
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode;
|
||||
}
|
||||
|
||||
$innercode .= "\$np = false;\n";
|
||||
// since there are no closures in php, if we are given an object instance,
|
||||
// we store a pointer to it in a global var...
|
||||
if ( is_array($funcname) && is_object($funcname[0]) )
|
||||
{
|
||||
$GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];
|
||||
$innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";
|
||||
$realfuncname = '$obj->'.$funcname[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$realfuncname = $plainfuncname;
|
||||
}
|
||||
foreach($parsvariations as $pars)
|
||||
{
|
||||
$innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";
|
||||
// build a 'generic' signature (only use an appropriate return type)
|
||||
$sig = array($returns);
|
||||
$psig = array($returnsDocs);
|
||||
for($i=0; $i < count($pars); $i++)
|
||||
{
|
||||
if (isset($paramDocs[$i]['type']))
|
||||
{
|
||||
$sig[] = php_2_xmlrpc_type($paramDocs[$i]['type']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sig[] = $GLOBALS['xmlrpcValue'];
|
||||
}
|
||||
$psig[] = isset($paramDocs[$i]['doc']) ? $paramDocs[$i]['doc'] : '';
|
||||
}
|
||||
$sigs[] = $sig;
|
||||
$psigs[] = $psig;
|
||||
}
|
||||
$innercode .= "\$np = true;\n";
|
||||
$innercode .= "if (\$np) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}'); else {\n";
|
||||
//$innercode .= "if (\$_xmlrpcs_error_occurred) return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n";
|
||||
$innercode .= "if (is_a(\$retval, '{$prefix}resp')) return \$retval; else\n";
|
||||
if($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
|
||||
{
|
||||
$innercode .= "return new {$prefix}resp(new {$prefix}val(\$retval, '$returns'));";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($encode_php_objects)
|
||||
$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval, array('encode_php_objs')));\n";
|
||||
else
|
||||
$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval));\n";
|
||||
}
|
||||
// shall we exclude functions returning by ref?
|
||||
// if($func->returnsReference())
|
||||
// return false;
|
||||
$code = "function $xmlrpcfuncname(\$msg) {\n" . $innercode . "}\n}";
|
||||
//print_r($code);
|
||||
if ($buildit)
|
||||
{
|
||||
$allOK = 0;
|
||||
eval($code.'$allOK=1;');
|
||||
// alternative
|
||||
//$xmlrpcfuncname = create_function('$m', $innercode);
|
||||
|
||||
if(!$allOK)
|
||||
{
|
||||
error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap php function '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo examine if $paramDocs matches $parsvariations and build array for
|
||||
/// usage as method signature, plus put together a nice string for docs
|
||||
|
||||
$ret = array('function' => $xmlrpcfuncname, 'signature' => $sigs, 'docstring' => $desc, 'signature_docs' => $psigs, 'source' => $code);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a user-defined PHP class or php object, map its methods onto a list of
|
||||
* PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server
|
||||
* object and called from remote clients (as well as their corresponding signature info).
|
||||
*
|
||||
* @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class
|
||||
* @param array $extra_options see the docs for wrap_php_method for more options
|
||||
* string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance
|
||||
* @return array or false on failure
|
||||
*
|
||||
* @todo get_class_methods will return both static and non-static methods.
|
||||
* we have to differentiate the action, depending on wheter we recived a class name or object
|
||||
*/
|
||||
function wrap_php_class($classname, $extra_options=array())
|
||||
{
|
||||
$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
|
||||
$methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';
|
||||
|
||||
if(version_compare(phpversion(), '5.0.3') == -1)
|
||||
{
|
||||
// up to php 5.0.3 some useful reflection methods were missing
|
||||
error_log('XML-RPC: cannot not wrap php functions unless running php version bigger than 5.0.3');
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$mlist = get_class_methods($classname);
|
||||
foreach($mlist as $mname)
|
||||
{
|
||||
if ($methodfilter == '' || preg_match($methodfilter, $mname))
|
||||
{
|
||||
// echo $mlist."\n";
|
||||
$func = new ReflectionMethod($classname, $mname);
|
||||
if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())
|
||||
{
|
||||
if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||
|
||||
(!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))
|
||||
{
|
||||
$methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);
|
||||
if ( $methodwrap )
|
||||
{
|
||||
$result[$methodwrap['function']] = $methodwrap['function'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an xmlrpc client and a method name, register a php wrapper function
|
||||
* that will call it and return results using native php types for both
|
||||
* params and results. The generated php function will return an xmlrpcresp
|
||||
* oject for failed xmlrpc calls
|
||||
*
|
||||
* Known limitations:
|
||||
* - server must support system.methodsignature for the wanted xmlrpc method
|
||||
* - for methods that expose many signatures, only one can be picked (we
|
||||
* could in priciple check if signatures differ only by number of params
|
||||
* and not by type, but it would be more complication than we can spare time)
|
||||
* - nested xmlrpc params: the caller of the generated php function has to
|
||||
* encode on its own the params passed to the php function if these are structs
|
||||
* or arrays whose (sub)members include values of type datetime or base64
|
||||
*
|
||||
* Notes: the connection properties of the given client will be copied
|
||||
* and reused for the connection used during the call to the generated
|
||||
* php function.
|
||||
* Calling the generated php function 'might' be slow: a new xmlrpc client
|
||||
* is created on every invocation and an xmlrpc-connection opened+closed.
|
||||
* An extra 'debug' param is appended to param list of xmlrpc method, useful
|
||||
* for debugging purposes.
|
||||
*
|
||||
* @param xmlrpc_client $client an xmlrpc client set up correctly to communicate with target server
|
||||
* @param string $methodname the xmlrpc method to be mapped to a php function
|
||||
* @param array $extra_options array of options that specify conversion details. valid ptions include
|
||||
* integer signum the index of the method signature to use in mapping (if method exposes many sigs)
|
||||
* integer timeout timeout (in secs) to be used when executing function/calling remote method
|
||||
* string protocol 'http' (default), 'http11' or 'https'
|
||||
* string new_function_name the name of php function to create. If unsepcified, lib will pick an appropriate name
|
||||
* string return_source if true return php code w. function definition instead fo function name
|
||||
* bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
|
||||
* bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
|
||||
* mixed return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the xmlrpcresp object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values
|
||||
* bool debug set it to 1 or 2 to see debug results of querying server for method synopsis
|
||||
* @return string the name of the generated php function (or false) - OR AN ARRAY...
|
||||
*/
|
||||
function wrap_xmlrpc_method($client, $methodname, $extra_options=0, $timeout=0, $protocol='', $newfuncname='')
|
||||
{
|
||||
// mind numbing: let caller use sane calling convention (as per javadoc, 3 params),
|
||||
// OR the 2.0 calling convention (no options) - we really love backward compat, don't we?
|
||||
if (!is_array($extra_options))
|
||||
{
|
||||
$signum = $extra_options;
|
||||
$extra_options = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
|
||||
$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
|
||||
$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
|
||||
$newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : '';
|
||||
}
|
||||
//$encode_php_objects = in_array('encode_php_objects', $extra_options);
|
||||
//$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 :
|
||||
// in_array('build_class_code', $extra_options) ? 2 : 0;
|
||||
|
||||
$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
|
||||
$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
|
||||
$simple_client_copy = isset($extra_options['simple_client_copy']) ? (int)($extra_options['simple_client_copy']) : 0;
|
||||
$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
|
||||
$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
|
||||
if (isset($extra_options['return_on_fault']))
|
||||
{
|
||||
$decode_fault = true;
|
||||
$fault_response = $extra_options['return_on_fault'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$decode_fault = false;
|
||||
$fault_response = '';
|
||||
}
|
||||
$debug = isset($extra_options['debug']) ? ($extra_options['debug']) : 0;
|
||||
|
||||
$msgclass = $prefix.'msg';
|
||||
$valclass = $prefix.'val';
|
||||
$decodefunc = 'php_'.$prefix.'_decode';
|
||||
|
||||
$msg = new $msgclass('system.methodSignature');
|
||||
$msg->addparam(new $valclass($methodname));
|
||||
$client->setDebug($debug);
|
||||
$response =& $client->send($msg, $timeout, $protocol);
|
||||
if($response->faultCode())
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve method signature from remote server for method '.$methodname);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$msig = $response->value();
|
||||
if ($client->return_type != 'phpvals')
|
||||
{
|
||||
$msig = $decodefunc($msig);
|
||||
}
|
||||
if(!is_array($msig) || count($msig) <= $signum)
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve method signature nr.'.$signum.' from remote server for method '.$methodname);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pick a suitable name for the new function, avoiding collisions
|
||||
if($newfuncname != '')
|
||||
{
|
||||
$xmlrpcfuncname = $newfuncname;
|
||||
}
|
||||
else
|
||||
{
|
||||
// take care to insure that methodname is translated to valid
|
||||
// php function name
|
||||
$xmlrpcfuncname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
|
||||
array('_', ''), $methodname);
|
||||
}
|
||||
while($buildit && function_exists($xmlrpcfuncname))
|
||||
{
|
||||
$xmlrpcfuncname .= 'x';
|
||||
}
|
||||
|
||||
$msig = $msig[$signum];
|
||||
$mdesc = '';
|
||||
// if in 'offline' mode, get method description too.
|
||||
// in online mode, favour speed of operation
|
||||
if(!$buildit)
|
||||
{
|
||||
$msg = new $msgclass('system.methodHelp');
|
||||
$msg->addparam(new $valclass($methodname));
|
||||
$response =& $client->send($msg, $timeout, $protocol);
|
||||
if (!$response->faultCode())
|
||||
{
|
||||
$mdesc = $response->value();
|
||||
if ($client->return_type != 'phpvals')
|
||||
{
|
||||
$mdesc = $mdesc->scalarval();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results = build_remote_method_wrapper_code($client, $methodname,
|
||||
$xmlrpcfuncname, $msig, $mdesc, $timeout, $protocol, $simple_client_copy,
|
||||
$prefix, $decode_php_objects, $encode_php_objects, $decode_fault,
|
||||
$fault_response);
|
||||
|
||||
//print_r($code);
|
||||
if ($buildit)
|
||||
{
|
||||
$allOK = 0;
|
||||
eval($results['source'].'$allOK=1;');
|
||||
// alternative
|
||||
//$xmlrpcfuncname = create_function('$m', $innercode);
|
||||
if($allOK)
|
||||
{
|
||||
return $xmlrpcfuncname;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap remote method '.$methodname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$results['function'] = $xmlrpcfuncname;
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to wrap_xmlrpc_method, but will generate a php class that wraps
|
||||
* all xmlrpc methods exposed by the remote server as own methods.
|
||||
* For more details see wrap_xmlrpc_method.
|
||||
* @param xmlrpc_client $client the client obj all set to query the desired server
|
||||
* @param array $extra_options list of options for wrapped code
|
||||
* @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options)
|
||||
*/
|
||||
function wrap_xmlrpc_server($client, $extra_options=array())
|
||||
{
|
||||
$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
|
||||
//$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
|
||||
$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
|
||||
$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
|
||||
$newclassname = isset($extra_options['new_class_name']) ? $extra_options['new_class_name'] : '';
|
||||
$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
|
||||
$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
|
||||
$verbatim_client_copy = isset($extra_options['simple_client_copy']) ? !($extra_options['simple_client_copy']) : true;
|
||||
$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
|
||||
$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
|
||||
|
||||
$msgclass = $prefix.'msg';
|
||||
//$valclass = $prefix.'val';
|
||||
$decodefunc = 'php_'.$prefix.'_decode';
|
||||
|
||||
$msg = new $msgclass('system.listMethods');
|
||||
$response =& $client->send($msg, $timeout, $protocol);
|
||||
if($response->faultCode())
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve method list from remote server');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mlist = $response->value();
|
||||
if ($client->return_type != 'phpvals')
|
||||
{
|
||||
$mlist = $decodefunc($mlist);
|
||||
}
|
||||
if(!is_array($mlist) || !count($mlist))
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve meaningful method list from remote server');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pick a suitable name for the new function, avoiding collisions
|
||||
if($newclassname != '')
|
||||
{
|
||||
$xmlrpcclassname = $newclassname;
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlrpcclassname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
|
||||
array('_', ''), $client->server).'_client';
|
||||
}
|
||||
while($buildit && class_exists($xmlrpcclassname))
|
||||
{
|
||||
$xmlrpcclassname .= 'x';
|
||||
}
|
||||
|
||||
/// @todo add function setdebug() to new class, to enable/disable debugging
|
||||
$source = "class $xmlrpcclassname\n{\nvar \$client;\n\n";
|
||||
$source .= "function $xmlrpcclassname()\n{\n";
|
||||
$source .= build_client_wrapper_code($client, $verbatim_client_copy, $prefix);
|
||||
$source .= "\$this->client =& \$client;\n}\n\n";
|
||||
$opts = array('simple_client_copy' => 2, 'return_source' => true,
|
||||
'timeout' => $timeout, 'protocol' => $protocol,
|
||||
'encode_php_objs' => $encode_php_objects, 'prefix' => $prefix,
|
||||
'decode_php_objs' => $decode_php_objects
|
||||
);
|
||||
/// @todo build javadoc for class definition, too
|
||||
foreach($mlist as $mname)
|
||||
{
|
||||
if ($methodfilter == '' || preg_match($methodfilter, $mname))
|
||||
{
|
||||
$opts['new_function_name'] = preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
|
||||
array('_', ''), $mname);
|
||||
$methodwrap = wrap_xmlrpc_method($client, $mname, $opts);
|
||||
if ($methodwrap)
|
||||
{
|
||||
if (!$buildit)
|
||||
{
|
||||
$source .= $methodwrap['docstring'];
|
||||
}
|
||||
$source .= $methodwrap['source']."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('XML-RPC: will not create class method to wrap remote method '.$mname);
|
||||
}
|
||||
}
|
||||
}
|
||||
$source .= "}\n";
|
||||
if ($buildit)
|
||||
{
|
||||
$allOK = 0;
|
||||
eval($source.'$allOK=1;');
|
||||
// alternative
|
||||
//$xmlrpcfuncname = create_function('$m', $innercode);
|
||||
if($allOK)
|
||||
{
|
||||
return $xmlrpcclassname;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('XML-RPC: could not create class '.$xmlrpcclassname.' to wrap remote server '.$client->server);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return array('class' => $xmlrpcclassname, 'code' => $source, 'docstring' => '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the necessary info, build php code that creates a new function to
|
||||
* invoke a remote xmlrpc method.
|
||||
* Take care that no full checking of input parameters is done to ensure that
|
||||
* valid php code is emitted.
|
||||
* Note: real spaghetti code follows...
|
||||
* @access private
|
||||
*/
|
||||
function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname,
|
||||
$msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc',
|
||||
$decode_php_objects=false, $encode_php_objects=false, $decode_fault=false,
|
||||
$fault_response='')
|
||||
{
|
||||
$code = "function $xmlrpcfuncname (";
|
||||
if ($client_copy_mode < 2)
|
||||
{
|
||||
// client copy mode 0 or 1 == partial / full client copy in emitted code
|
||||
$innercode = build_client_wrapper_code($client, $client_copy_mode, $prefix);
|
||||
$innercode .= "\$client->setDebug(\$debug);\n";
|
||||
$this_ = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
// client copy mode 2 == no client copy in emitted code
|
||||
$innercode = '';
|
||||
$this_ = 'this->';
|
||||
}
|
||||
$innercode .= "\$msg = new {$prefix}msg('$methodname');\n";
|
||||
|
||||
if ($mdesc != '')
|
||||
{
|
||||
// take care that PHP comment is not terminated unwillingly by method description
|
||||
$mdesc = "/**\n* ".str_replace('*/', '* /', $mdesc)."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdesc = "/**\nFunction $xmlrpcfuncname\n";
|
||||
}
|
||||
|
||||
// param parsing
|
||||
$plist = array();
|
||||
$pcount = count($msig);
|
||||
for($i = 1; $i < $pcount; $i++)
|
||||
{
|
||||
$plist[] = "\$p$i";
|
||||
$ptype = $msig[$i];
|
||||
if($ptype == 'i4' || $ptype == 'int' || $ptype == 'boolean' || $ptype == 'double' ||
|
||||
$ptype == 'string' || $ptype == 'dateTime.iso8601' || $ptype == 'base64' || $ptype == 'null')
|
||||
{
|
||||
// only build directly xmlrpcvals when type is known and scalar
|
||||
$innercode .= "\$p$i = new {$prefix}val(\$p$i, '$ptype');\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($encode_php_objects)
|
||||
{
|
||||
$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i, array('encode_php_objs'));\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i);\n";
|
||||
}
|
||||
}
|
||||
$innercode .= "\$msg->addparam(\$p$i);\n";
|
||||
$mdesc .= '* @param '.xmlrpc_2_php_type($ptype)." \$p$i\n";
|
||||
}
|
||||
if ($client_copy_mode < 2)
|
||||
{
|
||||
$plist[] = '$debug=0';
|
||||
$mdesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
|
||||
}
|
||||
$plist = implode(', ', $plist);
|
||||
$mdesc .= '* @return '.xmlrpc_2_php_type($msig[0])." (or an {$prefix}resp obj instance if call fails)\n*/\n";
|
||||
|
||||
$innercode .= "\$res =& \${$this_}client->send(\$msg, $timeout, '$protocol');\n";
|
||||
if ($decode_fault)
|
||||
{
|
||||
if (is_string($fault_response) && ((strpos($fault_response, '%faultCode%') !== false) || (strpos($fault_response, '%faultString%') !== false)))
|
||||
{
|
||||
$respcode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '".str_replace("'", "''", $fault_response)."')";
|
||||
}
|
||||
else
|
||||
{
|
||||
$respcode = var_export($fault_response, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$respcode = '$res';
|
||||
}
|
||||
if ($decode_php_objects)
|
||||
{
|
||||
$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value(), array('decode_php_objs'));";
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value());";
|
||||
}
|
||||
|
||||
$code = $code . $plist. ") {\n" . $innercode . "\n}\n";
|
||||
|
||||
return array('source' => $code, 'docstring' => $mdesc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given necessary info, generate php code that will rebuild a client object
|
||||
* Take care that no full checking of input parameters is done to ensure that
|
||||
* valid php code is emitted.
|
||||
* @access private
|
||||
*/
|
||||
function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
|
||||
{
|
||||
$code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
|
||||
"', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
|
||||
|
||||
// copy all client fields to the client that will be generated runtime
|
||||
// (this provides for future expansion or subclassing of client obj)
|
||||
if ($verbatim_client_copy)
|
||||
{
|
||||
foreach($client as $fld => $val)
|
||||
{
|
||||
if($fld != 'debug' && $fld != 'return_type')
|
||||
{
|
||||
$val = var_export($val, true);
|
||||
$code .= "\$client->$fld = $val;\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
// only make sure that client always returns the correct data type
|
||||
$code .= "\$client->return_type = '{$prefix}vals';\n";
|
||||
//$code .= "\$client->setDebug(\$debug);\n";
|
||||
return $code;
|
||||
}
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection PhpMissingFieldTypeInspection */
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
@ -26,10 +26,10 @@ $gsm = new gsitemap;
|
||||
class gsitemap
|
||||
{
|
||||
|
||||
var $message;
|
||||
var $error;
|
||||
var $errortext;
|
||||
var $freq_list = array();
|
||||
protected $message;
|
||||
protected $error;
|
||||
protected $errortext;
|
||||
protected $freq_list = array();
|
||||
|
||||
//function gsitemap()
|
||||
function __construct()
|
||||
@ -120,7 +120,7 @@ class gsitemap
|
||||
$text = "
|
||||
<form action='".e_SELF."?import' id='import' method='post'>
|
||||
".GSLAN_39."<br /><br />"
|
||||
.$frm->admin_button('import',LAN_YES,'submit')."
|
||||
.$frm->admin_button('import',LAN_YES)."
|
||||
</form>";
|
||||
|
||||
$mes->addInfo($text);
|
||||
@ -255,9 +255,9 @@ class gsitemap
|
||||
{
|
||||
$sel = ($editArray['gsitemap_priority'] == number_format($i,1))? "selected='selected'" : "";
|
||||
$text .= "<option value='".number_format($i,1)."' $sel>".number_format($i,1)."</option>\n";
|
||||
};
|
||||
}
|
||||
|
||||
$text.="</select></td>
|
||||
$text.="</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>".LAN_ORDER."</td>
|
||||
@ -332,8 +332,8 @@ class gsitemap
|
||||
// Inserting new record
|
||||
else
|
||||
{
|
||||
$gmap['gsitemap_img'] = vartrue($_POST['gsitemap_img'], '');
|
||||
$gmap['gsitemap_cat'] = vartrue($_POST['gsitemap_cat'], '');
|
||||
$gmap['gsitemap_img'] = vartrue($_POST['gsitemap_img']);
|
||||
$gmap['gsitemap_cat'] = vartrue($_POST['gsitemap_cat']);
|
||||
|
||||
if($sql->insert('gsitemap', $gmap))
|
||||
{
|
||||
@ -360,7 +360,7 @@ class gsitemap
|
||||
if($sql->delete("gsitemap", "gsitemap_id='".$d_idt[0]."'"))
|
||||
{
|
||||
$this->message = LAN_DELETED;
|
||||
$log->log_event('GSMAP_02', $this->message.': '.$d_idt[0], E_LOG_INFORMATIVE,'');
|
||||
$log->log_event('GSMAP_02', $this->message.': '.$d_idt[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -381,7 +381,7 @@ class gsitemap
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$existing = array();
|
||||
$sql->select("gsitemap", "*");
|
||||
$sql->select("gsitemap");
|
||||
while($row = $sql->fetch())
|
||||
{
|
||||
$existing[] = $row['gsitemap_name'];
|
||||
@ -502,12 +502,14 @@ class gsitemap
|
||||
</table>
|
||||
<div class='buttons-bar center'>
|
||||
".
|
||||
$frm->admin_button('import_links',GSLAN_18,'submit')."
|
||||
$frm->admin_button('import_links',GSLAN_18)."
|
||||
</div>
|
||||
</form>
|
||||
";
|
||||
|
||||
$ns->tablerender(GSLAN_7, $mes->render(). $text);
|
||||
|
||||
unset($PLUGINS_DIRECTORY);
|
||||
}
|
||||
|
||||
|
||||
@ -529,7 +531,7 @@ class gsitemap
|
||||
}
|
||||
|
||||
$this->message = count($_POST['importid'])." link(s) imported.";
|
||||
$log->log_event('GSMAP_01',$this->message, E_LOG_INFORMATIVE,'');
|
||||
$log->log_event('GSMAP_01',$this->message);
|
||||
}
|
||||
|
||||
|
||||
@ -573,7 +575,7 @@ class gsitemap
|
||||
|
||||
require_once(e_ADMIN."footer.php");
|
||||
|
||||
|
||||
// loaded automatically.
|
||||
function admin_config_adminmenu()
|
||||
{
|
||||
$action = (e_QUERY) ? e_QUERY : "list";
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection PhpMissingReturnTypeInspection */
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
@ -42,7 +42,6 @@ class gsitemap_cron // include plugin-folder in the name.
|
||||
{
|
||||
// Whatever code you wish.
|
||||
e107::getMessage()->add("Executed dummy function within gsitemap/e_cron.php");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,30 +21,7 @@ if(!e107::isInstalled('gsitemap'))
|
||||
return '';
|
||||
}
|
||||
|
||||
global $e_event,$e107cache,$ns;
|
||||
// $e_event->register("newspost", "pingit");
|
||||
// $e_event->register("newsupd", "pingit"); // Disable these for now, until admin functions written
|
||||
|
||||
function pingit($vals)
|
||||
{
|
||||
global $admin_log;
|
||||
require(e_PLUGIN."gsitemap/weblog_pinger.php");
|
||||
$pinger = new Weblog_Pinger();
|
||||
// $pinger->ping_ping_o_matic("Ekzemplo", "http://www.ekzemplo.com/");
|
||||
|
||||
$xml_rpc_server = "blogsearch.google.com";
|
||||
$xml_rpc_port = 80;
|
||||
$xml_rpc_path = "/ping/RPC2";
|
||||
$xml_rpc_method = "weblogUpdates.extendedPing";
|
||||
$weblog_name = SITENAME;
|
||||
$weblog_url = $_SERVER['HTTP_HOST'].e_HTTP;
|
||||
$changes_url = $_SERVER['HTTP_HOST'].e_HTTP."news.php?extend.".$vals['news_id'];
|
||||
$cat_or_rss = $_SERVER['HTTP_HOST'].e_PLUGIN_ABS."rss_menu/rss.php?1.2";
|
||||
$extended = TRUE;
|
||||
|
||||
$pinger->ping($xml_rpc_server, $xml_rpc_port, $xml_rpc_path, $xml_rpc_method, $weblog_name, $weblog_url, $changes_url, $cat_or_rss, $extended);
|
||||
$log = strip_tags($vals['news_title']."\n".$changes_url."\n".$cat_or_rss."\n".$pinger->smessage);
|
||||
e107::getLog()->add("Gsitemap Google-ping",$log, 4);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,42 +1,4 @@
|
||||
<?php
|
||||
/* weblog_pinger.php
|
||||
|
||||
Weblog_Pinger PHP Class Library by Rogers Cadenhead
|
||||
Version 1.3
|
||||
Web: http://www.cadenhead.org/workbench/weblog-pinger
|
||||
|
||||
Copyright (C) 2005 Rogers Cadenhead
|
||||
|
||||
The Weblog_Pinger class can send a ping message over XML-RPC to
|
||||
weblog notification services such as Weblogs.Com, Blo.gs,
|
||||
and Technorati.
|
||||
|
||||
This class should be stored in a directory accessible to
|
||||
the PHP scripts that will use it.
|
||||
|
||||
This software requires the XML-RPC for PHP class library by
|
||||
Usefulinc: http://xmlrpc.usefulinc.com/php.html.
|
||||
|
||||
Example use:
|
||||
|
||||
require('weblog_pinger.php');
|
||||
$pinger = new Weblog_Pinger();
|
||||
echo $pinger->ping_ping_o_matic("Ekzemplo",
|
||||
"http://www.ekzemplo.com/");
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
if(!e107::isInstalled('gsitemap'))
|
||||
{
|
||||
@ -45,193 +7,3 @@ if(!e107::isInstalled('gsitemap'))
|
||||
}
|
||||
|
||||
|
||||
// include the XML-RPC class library
|
||||
include (e_HANDLER.'xmlrpc/xmlrpc.inc.php');
|
||||
include (e_HANDLER.'xmlrpc/xmlrpcs.inc.php');
|
||||
include (e_HANDLER.'xmlrpc/xmlrpc_wrappers.inc.php');
|
||||
|
||||
class Weblog_Pinger {
|
||||
// Weblogs.Com XML-RPC settings
|
||||
var $weblogs_com_server = "rpc.weblogs.com";
|
||||
var $weblogs_com_port = 80;
|
||||
var $weblogs_com_path = "/RPC2";
|
||||
var $weblogs_com_method = "weblogUpdates.ping";
|
||||
var $weblogs_com_extended_method = "weblogUpdates.extendedPing";
|
||||
// Blo.gs XML-RPC settings
|
||||
var $blo_gs_server = "ping.blo.gs";
|
||||
var $blo_gs_port = 80;
|
||||
var $blo_gs_path = "/";
|
||||
var $blo_gs_method = "weblogUpdates.ping";
|
||||
// Ping-o-Matic XML-RPC settings
|
||||
var $ping_o_matic_server = "rpc.pingomatic.com";
|
||||
var $ping_o_matic_port = 80;
|
||||
var $ping_o_matic_path = "/RPC2";
|
||||
var $ping_o_matic_method = "weblogUpdates.ping";
|
||||
// Technorati XML-RPC settings
|
||||
var $technorati_server = "rpc.technorati.com";
|
||||
var $technorati_port = 80;
|
||||
var $technorati_path = "/rpc/ping";
|
||||
var $technorati_method = "weblogUpdates.ping";
|
||||
// Audio.Weblogs.Com XML-RPC settings
|
||||
var $audio_weblogs_com_server = "audiorpc.weblogs.com";
|
||||
var $audio_weblogs_com_port = 80;
|
||||
var $audio_weblogs_com_path = "/RPC2";
|
||||
var $audio_weblogs_com_method = "weblogUpdates.ping";
|
||||
// log settings
|
||||
var $log_file = "";
|
||||
var $log_level = "full"; // full, short, or none;
|
||||
var $smessage = "";
|
||||
var $software_version = "1.3";
|
||||
var $debug = TRUE;
|
||||
|
||||
// report errors
|
||||
function report_error($message) {
|
||||
error_log("Weblog Pinger: " . $message);
|
||||
}
|
||||
|
||||
/* Ping Weblogs.Com to indicate that a weblog has been updated. Returns true
|
||||
on success and false on failure. */
|
||||
function ping_weblogs_com($weblog_name, $weblog_url, $changes_url = "", $category = "") {
|
||||
return $this->ping($this->weblogs_com_server, $this->weblogs_com_port,
|
||||
$this->weblogs_com_path, $this->weblogs_com_method, $weblog_name,
|
||||
$weblog_url, $changes_url, $category);
|
||||
}
|
||||
|
||||
/* Ping Blo.gs to indicate that a weblog has been updated. Returns true on success
|
||||
and false on failure. */
|
||||
function ping_blo_gs($weblog_name, $weblog_url, $changes_url = "", $category = "") {
|
||||
return $this->ping($this->blo_gs_server, $this->blo_gs_port,
|
||||
$this->blo_gs_path, $this->blo_gs_method, $weblog_name, $weblog_url,
|
||||
$changes_url, $category);
|
||||
}
|
||||
|
||||
/* Ping Technorati to indicate that a weblog has been updated. Returns true on
|
||||
success and false on failure. */
|
||||
function ping_technorati($weblog_name, $weblog_url, $changes_url = "", $category = "") {
|
||||
return $this->ping($this->technorati_server, $this->technorati_port,
|
||||
$this->technorati_path, $this->technorati_method, $weblog_name, $weblog_url,
|
||||
$changes_url, $category);
|
||||
}
|
||||
|
||||
/* Ping all of the above services to indicate that a weblog has been updated.
|
||||
Returns true on success and false on failure. */
|
||||
function ping_all($weblog_name, $weblog_url, $changes_url = "", $category = "") {
|
||||
$error[0] = $this->ping_technorati($weblog_name, $weblog_url, $changes_url, $category);
|
||||
$error[1] = $this->ping_weblogs_com($weblog_name, $weblog_url, $changes_url, $category);
|
||||
$error[2] = $this->ping_blo_gs($weblog_name, $weblog_url, $changes_url, $category);
|
||||
$all_ok = $error[0] & $error[1] & $error[2];
|
||||
return array($all_ok, $error);
|
||||
}
|
||||
|
||||
/* Ping Pingomatic to indicate that a weblog has been updated. Returns true on success
|
||||
and false on failure. */
|
||||
function ping_ping_o_matic($weblog_name, $weblog_url, $changes_url = "", $category = "") {
|
||||
return $this->ping($this->ping_o_matic_server, $this->ping_o_matic_port,
|
||||
$this->ping_o_matic_path, $this->ping_o_matic_method, $weblog_name,
|
||||
$weblog_url, $changes_url, $category);
|
||||
}
|
||||
|
||||
/* Ping Audio.Weblogs.Com to indicate that a weblog with a podcast has been updated.
|
||||
Returns true on success and false on failure. */
|
||||
function ping_audio_weblogs_com($weblog_name, $weblog_url, $changes_url = "",
|
||||
$category = "") {
|
||||
|
||||
return $this->ping($this->audio_weblogs_com_server, $this->audio_weblogs_com_port,
|
||||
$this->audio_weblogs_com_path, $this->audio_weblogs_com_method, $weblog_name,
|
||||
$weblog_url, $changes_url, $category);
|
||||
}
|
||||
|
||||
/* Ping Weblogs.Com (extended version) to indicate that a weblog has been updated.
|
||||
Returns true on success and false on failure. */
|
||||
function ping_weblogs_com_extended($weblog_name, $weblog_url, $changes_url, $rss_url) {
|
||||
if ($this->debug) $this->report_error(
|
||||
"Sending extended ping to Weblogs.Com for "
|
||||
. "$weblog_name, $weblog_url, $changes_url, $rss_url");
|
||||
return $this->ping($this->weblogs_com_server, $this->weblogs_com_port,
|
||||
$this->weblogs_com_path, $this->weblogs_com_extended_method, $weblog_name,
|
||||
$weblog_url, $changes_url, $rss_url, true);
|
||||
}
|
||||
|
||||
/* Multi-purpose ping for any XML-RPC server that supports the Weblogs.Com interface. */
|
||||
function ping($xml_rpc_server, $xml_rpc_port, $xml_rpc_path, $xml_rpc_method, $weblog_name, $weblog_url, $changes_url, $cat_or_rss, $extended = false)
|
||||
{
|
||||
|
||||
// build the parameters
|
||||
$name_param = new xmlrpcval($weblog_name, 'string');
|
||||
$url_param = new xmlrpcval($weblog_url, 'string');
|
||||
$changes_param = new xmlrpcval($changes_url, 'string');
|
||||
$cat_or_rss_param = new xmlrpcval($cat_or_rss, 'string');
|
||||
$method_name = "weblogUpdates.ping";
|
||||
if ($extended) $method_name = "weblogUpdates.extendedPing";
|
||||
|
||||
if ($cat_or_rss != "") {
|
||||
$params = array($name_param, $url_param, $changes_param, $cat_or_rss_param);
|
||||
$call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\", \"$cat_or_rss\")";
|
||||
} else {
|
||||
if ($changes_url != "") {
|
||||
$params = array($name_param, $url_param, $changes_param);
|
||||
$call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\")";
|
||||
} else {
|
||||
$params = array($name_param, $url_param);
|
||||
$call_text = "$method_name(\"$weblog_name\", \"$weblog_url\")";
|
||||
}
|
||||
}
|
||||
|
||||
// create the message
|
||||
$message = new xmlrpcmsg($xml_rpc_method, $params);
|
||||
$client = new xmlrpc_client($xml_rpc_path, $xml_rpc_server,
|
||||
$xml_rpc_port);
|
||||
$response = $client->send($message);
|
||||
// log the message
|
||||
$this->log_ping("Request: " . $call_text);
|
||||
$this->log_ping($message->serialize(), true);
|
||||
if ($response == 0) {
|
||||
$error_text = "Error: " . $xml_rpc_server . ": " . $client->errno . " "
|
||||
. $client->errstring;
|
||||
$this->report_error($error_text);
|
||||
$this->log_ping($error_text);
|
||||
return false;
|
||||
}
|
||||
if ($response->faultCode() != 0) {
|
||||
$error_text = "Error: " . $xml_rpc_server . ": " . $response->faultCode()
|
||||
. " " . $response->faultString();
|
||||
$this->report_error($error_text);
|
||||
return false;
|
||||
}
|
||||
$response_value = $response->value();
|
||||
if ($this->debug) $this->report_error($response_value->serialize());
|
||||
$this->log_ping($response_value->serialize(), true);
|
||||
$fl_error = $response_value->structmem('flerror');
|
||||
$message = $response_value->structmem('message');
|
||||
|
||||
// read the response
|
||||
if ($fl_error->scalarval() != false) {
|
||||
$error_text = "Error: " . $xml_rpc_server . ": " . $message->scalarval();
|
||||
$this->report_error($error_text);
|
||||
$this->log_ping($error_text);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// save ping data to a log file
|
||||
function log_ping($message, $xml_data = false) {
|
||||
$this->smessage = $xml_data." ".$message;
|
||||
return;
|
||||
/* if ($this->log_level == "none") {
|
||||
return;
|
||||
}
|
||||
if (($this->log_level == "short") & ($xml_data)) {
|
||||
return;
|
||||
}
|
||||
if (!is_writable($this->log_file)) {
|
||||
$this->report_error("File {$this->log_file} is not writable");
|
||||
return;
|
||||
}
|
||||
$fhandle = fopen($this->log_file, "a");
|
||||
fwrite($fhandle, $message . "\r\n");
|
||||
fclose($fhandle);*/
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user