forked from GNUsocial/gnu-social
Update indentation, whitespace and line breaks.
This commit is contained in:
parent
3bcff2fa86
commit
a4c5a0a229
|
@ -64,9 +64,6 @@ define('MOLLOM_REDIRECT', 1200);
|
||||||
*
|
*
|
||||||
* @see Event
|
* @see Event
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MollomPlugin extends Plugin
|
class MollomPlugin extends Plugin
|
||||||
{
|
{
|
||||||
public $public_key;
|
public $public_key;
|
||||||
|
@ -110,11 +107,12 @@ class MollomPlugin extends Plugin
|
||||||
}
|
}
|
||||||
return '127.0.0.1';
|
return '127.0.0.1';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call a remote procedure at the Mollom server. This function will
|
* Call a remote procedure at the Mollom server. This function will
|
||||||
* automatically add the information required to authenticate against
|
* automatically add the information required to authenticate against
|
||||||
* Mollom.
|
* Mollom.
|
||||||
*/
|
*/
|
||||||
function mollom($method, $data = array()) {
|
function mollom($method, $data = array()) {
|
||||||
if (!extension_loaded('xmlrpc')) {
|
if (!extension_loaded('xmlrpc')) {
|
||||||
if (!dl('xmlrpc.so')) {
|
if (!dl('xmlrpc.so')) {
|
||||||
|
@ -132,7 +130,7 @@ class MollomPlugin extends Plugin
|
||||||
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
||||||
|
|
||||||
// Store the list of servers in the database:
|
// Store the list of servers in the database:
|
||||||
// TODO! variable_set('mollom_servers', $servers);
|
// TODO! variable_set('mollom_servers', $servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($servers)) {
|
if (is_array($servers)) {
|
||||||
|
@ -179,30 +177,30 @@ class MollomPlugin extends Plugin
|
||||||
|
|
||||||
// If none of the servers worked, activate the fallback mechanism:
|
// If none of the servers worked, activate the fallback mechanism:
|
||||||
common_debug("none of the servers worked");
|
common_debug("none of the servers worked");
|
||||||
// _mollom_fallback();
|
// _mollom_fallback();
|
||||||
|
|
||||||
// If everything failed, we reset the server list to force Mollom to request a new list:
|
// If everything failed, we reset the server list to force Mollom to request a new list:
|
||||||
//TODO variable_set('mollom_servers', array());
|
//TODO variable_set('mollom_servers', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function generate an array with all the information required to
|
* This function generate an array with all the information required to
|
||||||
* authenticate against Mollom. To prevent that requests are forged and
|
* authenticate against Mollom. To prevent that requests are forged and
|
||||||
* that you are impersonated, each request is signed with a hash computed
|
* that you are impersonated, each request is signed with a hash computed
|
||||||
* based on a private key and a timestamp.
|
* based on a private key and a timestamp.
|
||||||
*
|
*
|
||||||
* Both the client and the server share the secret key that is used to
|
* Both the client and the server share the secret key that is used to
|
||||||
* create the authentication hash based on a timestamp. They both hash
|
* create the authentication hash based on a timestamp. They both hash
|
||||||
* the timestamp with the secret key, and if the hashes match, the
|
* the timestamp with the secret key, and if the hashes match, the
|
||||||
* authenticity of the message has been validated.
|
* authenticity of the message has been validated.
|
||||||
*
|
*
|
||||||
* To avoid that someone can intercept a (hash, timestamp)-pair and
|
* To avoid that someone can intercept a (hash, timestamp)-pair and
|
||||||
* use that to impersonate a client, Mollom will reject the request
|
* use that to impersonate a client, Mollom will reject the request
|
||||||
* when the timestamp is more than 15 minutes off.
|
* when the timestamp is more than 15 minutes off.
|
||||||
*
|
*
|
||||||
* Make sure your server's time is synchronized with the world clocks,
|
* Make sure your server's time is synchronized with the world clocks,
|
||||||
* and that you don't share your private key with anyone else.
|
* and that you don't share your private key with anyone else.
|
||||||
*/
|
*/
|
||||||
private function authentication() {
|
private function authentication() {
|
||||||
|
|
||||||
$public_key = $this->public_key;
|
$public_key = $this->public_key;
|
||||||
|
@ -227,7 +225,6 @@ class MollomPlugin extends Plugin
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function xmlrpc($url) {
|
function xmlrpc($url) {
|
||||||
//require_once './includes/xmlrpc.inc';
|
//require_once './includes/xmlrpc.inc';
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
@ -235,15 +232,15 @@ class MollomPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively turn a data structure into objects with 'data' and 'type' attributes.
|
* Recursively turn a data structure into objects with 'data' and 'type' attributes.
|
||||||
*
|
*
|
||||||
* @param $data
|
* @param $data
|
||||||
* The data structure.
|
* The data structure.
|
||||||
* @param $type
|
* @param $type
|
||||||
* Optional type assign to $data.
|
* Optional type assign to $data.
|
||||||
* @return
|
* @return
|
||||||
* Object.
|
* Object.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value($data, $type = FALSE) {
|
function xmlrpc_value($data, $type = FALSE) {
|
||||||
$xmlrpc_value = new stdClass();
|
$xmlrpc_value = new stdClass();
|
||||||
$xmlrpc_value->data = $data;
|
$xmlrpc_value->data = $data;
|
||||||
|
@ -266,15 +263,15 @@ class MollomPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map PHP type to XML-RPC type.
|
* Map PHP type to XML-RPC type.
|
||||||
*
|
*
|
||||||
* @param $xmlrpc_value
|
* @param $xmlrpc_value
|
||||||
* Variable whose type should be mapped.
|
* Variable whose type should be mapped.
|
||||||
* @return
|
* @return
|
||||||
* XML-RPC type as string.
|
* XML-RPC type as string.
|
||||||
* @see
|
* @see
|
||||||
* http://www.xmlrpc.com/spec#scalars
|
* http://www.xmlrpc.com/spec#scalars
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
|
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
|
||||||
// http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
|
// http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
|
||||||
if (is_bool($xmlrpc_value->data)) {
|
if (is_bool($xmlrpc_value->data)) {
|
||||||
|
@ -304,77 +301,77 @@ class MollomPlugin extends Plugin
|
||||||
return 'string';
|
return 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate XML representing the given value.
|
* Generate XML representing the given value.
|
||||||
*
|
*
|
||||||
* @param $xmlrpc_value
|
* @param $xmlrpc_value
|
||||||
* @return
|
* @return
|
||||||
* XML representation of value.
|
* XML representation of value.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value_get_xml($xmlrpc_value) {
|
function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
switch ($xmlrpc_value->type) {
|
switch ($xmlrpc_value->type) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
|
return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
|
||||||
break;
|
break;
|
||||||
case 'int':
|
case 'int':
|
||||||
return '<int>'. $xmlrpc_value->data .'</int>';
|
return '<int>'. $xmlrpc_value->data .'</int>';
|
||||||
break;
|
break;
|
||||||
case 'double':
|
case 'double':
|
||||||
return '<double>'. $xmlrpc_value->data .'</double>';
|
return '<double>'. $xmlrpc_value->data .'</double>';
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
// Note: we don't escape apostrophes because of the many blogging clients
|
// Note: we don't escape apostrophes because of the many blogging clients
|
||||||
// that don't support numerical entities (and XML in general) properly.
|
// that don't support numerical entities (and XML in general) properly.
|
||||||
return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
|
return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'array':
|
||||||
$return = '<array><data>'."\n";
|
$return = '<array><data>'."\n";
|
||||||
foreach ($xmlrpc_value->data as $item) {
|
foreach ($xmlrpc_value->data as $item) {
|
||||||
$return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
|
$return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
|
||||||
|
}
|
||||||
|
$return .= '</data></array>';
|
||||||
|
return $return;
|
||||||
|
break;
|
||||||
|
case 'struct':
|
||||||
|
$return = '<struct>'."\n";
|
||||||
|
foreach ($xmlrpc_value->data as $name => $value) {
|
||||||
|
$return .= " <member><name>". htmlentities($name) ."</name><value>";
|
||||||
|
$return .= $this->xmlrpc_value_get_xml($value) ."</value></member>\n";
|
||||||
|
}
|
||||||
|
$return .= '</struct>';
|
||||||
|
return $return;
|
||||||
|
break;
|
||||||
|
case 'date':
|
||||||
|
return $this->xmlrpc_date_get_xml($xmlrpc_value->data);
|
||||||
|
break;
|
||||||
|
case 'base64':
|
||||||
|
return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$return .= '</data></array>';
|
return FALSE;
|
||||||
return $return;
|
}
|
||||||
break;
|
|
||||||
case 'struct':
|
|
||||||
$return = '<struct>'."\n";
|
|
||||||
foreach ($xmlrpc_value->data as $name => $value) {
|
|
||||||
$return .= " <member><name>". htmlentities($name) ."</name><value>";
|
|
||||||
$return .= $this->xmlrpc_value_get_xml($value) ."</value></member>\n";
|
|
||||||
}
|
|
||||||
$return .= '</struct>';
|
|
||||||
return $return;
|
|
||||||
break;
|
|
||||||
case 'date':
|
|
||||||
return $this->xmlrpc_date_get_xml($xmlrpc_value->data);
|
|
||||||
break;
|
|
||||||
case 'base64':
|
|
||||||
return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform an HTTP request.
|
* Perform an HTTP request.
|
||||||
*
|
*
|
||||||
* This is a flexible and powerful HTTP client implementation. Correctly handles
|
* This is a flexible and powerful HTTP client implementation. Correctly handles
|
||||||
* GET, POST, PUT or any other HTTP requests. Handles redirects.
|
* GET, POST, PUT or any other HTTP requests. Handles redirects.
|
||||||
*
|
*
|
||||||
* @param $url
|
* @param $url
|
||||||
* A string containing a fully qualified URI.
|
* A string containing a fully qualified URI.
|
||||||
* @param $headers
|
* @param $headers
|
||||||
* An array containing an HTTP header => value pair.
|
* An array containing an HTTP header => value pair.
|
||||||
* @param $method
|
* @param $method
|
||||||
* A string defining the HTTP request to use.
|
* A string defining the HTTP request to use.
|
||||||
* @param $data
|
* @param $data
|
||||||
* A string containing data to include in the request.
|
* A string containing data to include in the request.
|
||||||
* @param $retry
|
* @param $retry
|
||||||
* An integer representing how many times to retry the request in case of a
|
* An integer representing how many times to retry the request in case of a
|
||||||
* redirect.
|
* redirect.
|
||||||
* @return
|
* @return
|
||||||
* An object containing the HTTP request headers, response code, headers,
|
* An object containing the HTTP request headers, response code, headers,
|
||||||
* data and redirect status.
|
* data and redirect status.
|
||||||
*/
|
*/
|
||||||
function http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
|
function http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
|
||||||
global $db_prefix;
|
global $db_prefix;
|
||||||
|
|
||||||
|
@ -535,13 +532,13 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object representing an XML-RPC message.
|
* Construct an object representing an XML-RPC message.
|
||||||
*
|
*
|
||||||
* @param $message
|
* @param $message
|
||||||
* String containing XML as defined at http://www.xmlrpc.com/spec
|
* String containing XML as defined at http://www.xmlrpc.com/spec
|
||||||
* @return
|
* @return
|
||||||
* Object
|
* Object
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message($message) {
|
function xmlrpc_message($message) {
|
||||||
$xmlrpc_message = new stdClass();
|
$xmlrpc_message = new stdClass();
|
||||||
$xmlrpc_message->array_structs = array(); // The stack used to keep track of the current array/struct
|
$xmlrpc_message->array_structs = array(); // The stack used to keep track of the current array/struct
|
||||||
|
@ -552,14 +549,14 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an XML-RPC message. If parsing fails, the faultCode and faultString
|
* Parse an XML-RPC message. If parsing fails, the faultCode and faultString
|
||||||
* will be added to the message object.
|
* will be added to the message object.
|
||||||
*
|
*
|
||||||
* @param $xmlrpc_message
|
* @param $xmlrpc_message
|
||||||
* Object generated by xmlrpc_message()
|
* Object generated by xmlrpc_message()
|
||||||
* @return
|
* @return
|
||||||
* TRUE if parsing succeeded; FALSE otherwise
|
* TRUE if parsing succeeded; FALSE otherwise
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message_parse(&$xmlrpc_message) {
|
function xmlrpc_message_parse(&$xmlrpc_message) {
|
||||||
// First remove the XML declaration
|
// First remove the XML declaration
|
||||||
$xmlrpc_message->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $xmlrpc_message->message);
|
$xmlrpc_message->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $xmlrpc_message->message);
|
||||||
|
@ -587,13 +584,13 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a copy of the $xmlrpc_message object temporarily.
|
* Store a copy of the $xmlrpc_message object temporarily.
|
||||||
*
|
*
|
||||||
* @param $value
|
* @param $value
|
||||||
* Object
|
* Object
|
||||||
* @return
|
* @return
|
||||||
* The most recently stored $xmlrpc_message
|
* The most recently stored $xmlrpc_message
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message_set($value = NULL) {
|
function xmlrpc_message_set($value = NULL) {
|
||||||
static $xmlrpc_message;
|
static $xmlrpc_message;
|
||||||
if ($value) {
|
if ($value) {
|
||||||
|
@ -691,6 +688,7 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
$xmlrpc_message->methodname = trim($xmlrpc_message->current_tag_contents);
|
$xmlrpc_message->methodname = trim($xmlrpc_message->current_tag_contents);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value_flag) {
|
if ($value_flag) {
|
||||||
if (count($xmlrpc_message->array_structs ) > 0) {
|
if (count($xmlrpc_message->array_structs ) > 0) {
|
||||||
// Add value to struct or array
|
// Add value to struct or array
|
||||||
|
@ -715,15 +713,15 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object representing an XML-RPC request
|
* Construct an object representing an XML-RPC request
|
||||||
*
|
*
|
||||||
* @param $method
|
* @param $method
|
||||||
* The name of the method to be called
|
* The name of the method to be called
|
||||||
* @param $args
|
* @param $args
|
||||||
* An array of parameters to send with the method.
|
* An array of parameters to send with the method.
|
||||||
* @return
|
* @return
|
||||||
* Object
|
* Object
|
||||||
*/
|
*/
|
||||||
function xmlrpc_request($method, $args) {
|
function xmlrpc_request($method, $args) {
|
||||||
$xmlrpc_request = new stdClass();
|
$xmlrpc_request = new stdClass();
|
||||||
$xmlrpc_request->method = $method;
|
$xmlrpc_request->method = $method;
|
||||||
|
@ -735,6 +733,7 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
<params>
|
<params>
|
||||||
|
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
foreach ($xmlrpc_request->args as $arg) {
|
foreach ($xmlrpc_request->args as $arg) {
|
||||||
$xmlrpc_request->xml .= '<param><value>';
|
$xmlrpc_request->xml .= '<param><value>';
|
||||||
$v = $this->xmlrpc_value($arg);
|
$v = $this->xmlrpc_value($arg);
|
||||||
|
@ -868,26 +867,25 @@ EOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last XML-RPC client error number
|
* Returns the last XML-RPC client error number
|
||||||
*/
|
*/
|
||||||
function xmlrpc_errno() {
|
function xmlrpc_errno() {
|
||||||
$error = $this->xmlrpc_error();
|
$error = $this->xmlrpc_error();
|
||||||
return ($error != NULL ? $error->code : NULL);
|
return ($error != NULL ? $error->code : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last XML-RPC client error message
|
* Returns the last XML-RPC client error message
|
||||||
*/
|
*/
|
||||||
function xmlrpc_error_msg() {
|
function xmlrpc_error_msg() {
|
||||||
$error = xmlrpc_error();
|
$error = xmlrpc_error();
|
||||||
return ($error != NULL ? $error->message : NULL);
|
return ($error != NULL ? $error->message : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears any previous error.
|
* Clears any previous error.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_clear_error() {
|
function xmlrpc_clear_error() {
|
||||||
$this->xmlrpc_error(NULL, NULL, TRUE);
|
$this->xmlrpc_error(NULL, NULL, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,9 @@ addPlugin('Mollom',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
replace '...' with your own public and private keys for your site, which you can get from mollom.com
|
replace '...' with your own public and private keys for your site, which you can
|
||||||
|
get from mollom.com.
|
||||||
|
|
||||||
If you're using this plugin, i'd love to know about it -- shiny@cpan.org or shiny on freenode.
|
If you're using this plugin, i'd love to know about it -- shiny@cpan.org or
|
||||||
|
shiny on freenode.
|
||||||
|
|
Loading…
Reference in New Issue