* fixes while testing with WP iOS
* configurable if the interface should fake a WP version when asked
* configurable debug log.
* less dbug, more ob_start, ob_clean
This commit is contained in:
Grischa Brockhaus 2012-01-05 17:46:26 +01:00
parent 93bc98d5ac
commit f8a4d4daef
10 changed files with 108 additions and 30 deletions

View file

@ -1,7 +1,7 @@
# $Id$
Version 1.46:
* Enahnced the interface with WordPress RPC calls.
* Info about RPC caller URL in config.
* Enhanced the interface with WordPress RPC calls.
* Info about RPC caller URL in config, some configurations.
Version 1.45:
* Catch empty timestemps, thanks to TimNiceBut

View file

@ -7,7 +7,7 @@
*/
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Posílání příspěvků pomocí XML-RPC');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umožňuje posílat/editovat příspěvky pomocí XML-RPC API (MT, Blogger, Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umožňuje posílat/editovat příspěvky pomocí XML-RPC API (MT, Blogger, WordPress Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'Používat čas ve formátu GMT');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Výchozí kategorie');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Upřesněte výchozí kategorii, kam se mají umístit poslané příspěvky, pokud u nich není zadána kategorie.');

View file

@ -7,7 +7,7 @@
*/
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Posílání příspěvků pomocí XML-RPC');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umožňuje posílat/editovat příspěvky pomocí XML-RPC API (MT, Blogger, Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umožňuje posílat/editovat příspěvky pomocí XML-RPC API (MT, Blogger, WordPress Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'Používat čas ve formátu GMT');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Výchozí kategorie');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Upřesněte výchozí kategorii, kam se mají umístit poslané příspěvky, pokud u nich není zadána kategorie.');

View file

@ -1,9 +1,18 @@
<?php
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Einträge via XML-RPC erstellen');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Ermöglicht Einträge via XML-RPC API zu erstellen/bearbeiten (MT, Blogger API-Endpunkte)');
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Einträge via XML-RPC erstellen');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Ermöglicht Einträge via XML-RPC API zu erstellen/bearbeiten (MT, Blogger, WordPress API-Endpunkte)');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Standard-Kategorie');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Bestimmt die Standard-Kategorie für Blog-Artikel via XML-RPC, wenn der Client keine Kategorie setzt.');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'GMT Zeitzone verwenden');
@define('PLUGIN_EVENT_XMLRPC_DOC_RPCLINK','<b>Zur Information:</b><br/>Dieses Blog hat eine URL, an der XML-RPC Aufrufe abgearbeitet werden. Modernere Clients können diese automatisch mit der Blog URL ermitteln, bei älteren Clients muss sie explizit angegeben werden.<br/>Deine XML-RPC URL ist: <b>%s</b><br/>');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG', 'Debug Log');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_DESC', 'Wenn Du daran interessiert bist, was die XML-RPC Schnittstelle empfängt und antwortet, kannst Du das Debug Log anschalten. Das Logfile wird als rpc.log im Plugin Verzeichnis angelegt.');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_NONE', 'ausgeschaltet');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_NORMAL', 'angeschaltet');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_VERBOSE', 'ausführlich');
@define('PLUGIN_EVENT_XMLRPC_WPFAKEVERSION', 'WordPress Version vortäuschen');
@define('PLUGIN_EVENT_XMLRPC_WPFAKEVERSION_DESC', 'Die XML-RPC Schnittlstelle kann auf WordPress Aufrufe reagieren. Wenn sie nach der installierten Software Version gefragt wird, antwortet sie normaler Weise mit Serendipity ' . $serendipity['version'] .'. Wenn Du hier eine Version einträgst, dann wird sie mit WordPress (angegebene Version) antworten. Einige Clients könnten auf eine minimale WordPress Version testen, eine Version wie 3.2 erscheint dann okay.');

View file

@ -7,7 +7,7 @@
*/
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Posílání příspěvků pomocí XML-RPC');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umožòuje posílat/editovat pøíspìvky pomocí XML-RPC API (MT, Blogger, Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umožòuje posílat/editovat pøíspìvky pomocí XML-RPC API (MT, Blogger, WordPress Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'Používat čas ve formátu GMT');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Výchozí kategorie');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Upřesněte výchozí kategorii, kam se mají umístit poslané příspěvky, pokud u nich není zadána kategorie.');

View file

@ -7,7 +7,7 @@
*/
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Posílání příspěvků pomocí XML-RPC');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umo¾òuje posílat/editovat pøíspìvky pomocí XML-RPC API (MT, Blogger, Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Umo¾òuje posílat/editovat pøíspìvky pomocí XML-RPC API (MT, Blogger, WordPress Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'Používat čas ve formátu GMT');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Výchozí kategorie');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Upřesněte výchozí kategorii, kam se mají umístit poslané příspěvky, pokud u nich není zadána kategorie.');

View file

@ -1,9 +1,18 @@
<?php
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Einträge via XML-RPC erstellen');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Ermöglicht Einträge via XML-RPC API zu erstellen/bearbeiten (MT, Blogger API-Endpunkte)');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Ermöglicht Einträge via XML-RPC API zu erstellen/bearbeiten (MT, Blogger, WordPress API-Endpunkte)');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Standard-Kategorie');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Bestimmt die Standard-Kategorie für Blog-Artikel via XML-RPC, wenn der Client keine Kategorie setzt.');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'GMT Zeitzone verwenden');
@define('PLUGIN_EVENT_XMLRPC_DOC_RPCLINK','<b>Zur Information:</b><br/>Dieses Blog hat eine URL, an der XML-RPC Aufrufe abgearbeitet werden. Modernere Clients können diese automatisch mit der Blog URL ermitteln, bei älteren Clients muss sie explizit angegeben werden.<br/>Deine XML-RPC URL ist: <b>%s</b><br/>');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG', 'Debug Log');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_DESC', 'Wenn Du daran interessiert bist, was die XML-RPC Schnittstelle empfängt und antwortet, kannst Du das Debug Log anschalten. Das Logfile wird als rpc.log im Plugin Verzeichnis angelegt.');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_NONE', 'ausgeschaltet');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_NORMAL', 'angeschaltet');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_VERBOSE', 'ausführlich');
@define('PLUGIN_EVENT_XMLRPC_WPFAKEVERSION', 'WordPress Version vortäuschen');
@define('PLUGIN_EVENT_XMLRPC_WPFAKEVERSION_DESC', 'Die XML-RPC Schnittlstelle kann auf WordPress Aufrufe reagieren. Wenn sie nach der installierten Software Version gefragt wird, antwortet sie normaler Weise mit Serendipity ' . $serendipity['version'] .'. Wenn Du hier eine Version einträgst, dann wird sie mit WordPress (angegebene Version) antworten. Einige Clients könnten auf eine minimale WordPress Version testen, eine Version wie 3.2 erscheint dann okay.');

View file

@ -7,9 +7,18 @@
*/
@define('PLUGIN_EVENT_XMLRPC_NAME', 'Post via XML-RPC');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Allows to post/edit entries via the XML-RPC API (MT, Blogger Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_DESC', 'Allows to post/edit entries via the XML-RPC API (MT, Blogger, WordPress Endpoints)');
@define('PLUGIN_EVENT_XMLRPC_GMT', 'Use GMT time format');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT', 'Default category');
@define('PLUGIN_EVENT_XMLRPC_DEFAULTCAT_DESC', 'Specify the default category, when your blogging client specifies none.');
@define('PLUGIN_EVENT_XMLRPC_DOC_RPCLINK','<b>For your information:</b><br/>This blog has an URL where XMLRPC calls are handled. More modern clients are able to detect this RPC URL automatically from your blog URL, but for some older clients you have to tell them the RPC URL explicitly.<br/>Your XML-RPC URL is: <b>%s</b><br/>');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG', 'Debug log');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_DESC', 'If you are interested in what the XML-RPC interface is receiving and responding, switch on the debug log. The logfile is written as rpc.log in the plugins directory.');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_NONE', 'disabled');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_NORMAL', 'enabled');
@define('PLUGIN_EVENT_XMLRPC_DEBUGLOG_VERBOSE', 'verbose');
@define('PLUGIN_EVENT_XMLRPC_WPFAKEVERSION', 'Fake WordPress version');
@define('PLUGIN_EVENT_XMLRPC_WPFAKEVERSION_DESC', 'This XML-RPC interface is able to respond to WordPress type calls. Normally, if asked for the software used, it answers with Serendipity ' . $serendipity['version'] .'. But if you enter a version here, it will response as WordPress (version entered). Some clients might check, if the WP version is high enough, so a version like 3.2 would be okay here.');

View file

@ -35,7 +35,9 @@ class serendipity_event_xmlrpc extends serendipity_event
'frontend_xmlrpc' => true,
'frontend_header' => true
));
$propbag->add('configuration', array('doc_rpclink','category', 'gmt'));
$propbag->add('configuration',
array('doc_rpclink','category', 'gmt', 'debuglog', 'wpfakeversion')
);
$propbag->add('groups', array('FRONTEND_FULL_MODS', 'FRONTEND_EXTERNAL_SERVICES'));
}
@ -72,13 +74,32 @@ class serendipity_event_xmlrpc extends serendipity_event
$propbag->add('type', 'content');
$propbag->add('default', sprintf(PLUGIN_EVENT_XMLRPC_DOC_RPCLINK, $serendipity['baseURL'] . 'serendipity_xmlrpc.php'));
break;
case 'debuglog':
$debuglevels = array(
'none' => PLUGIN_EVENT_XMLRPC_DEBUGLOG_NONE,
'normal' => PLUGIN_EVENT_XMLRPC_DEBUGLOG_NORMAL,
'verbose' => PLUGIN_EVENT_XMLRPC_DEBUGLOG_VERBOSE
);
$propbag->add('type', 'select');
$propbag->add('select_values', $debuglevels);
$propbag->add('name', PLUGIN_EVENT_XMLRPC_DEBUGLOG);
$propbag->add('description', PLUGIN_EVENT_XMLRPC_DEBUGLOG_DESC);
$propbag->add('default', 'none');
break;
case 'gmt':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_EVENT_XMLRPC_GMT);
$propbag->add('description', '');
$propbag->add('default', false);
break;
case 'wpfakeversion' :
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_XMLRPC_WPFAKEVERSION);
$propbag->add('description', PLUGIN_EVENT_XMLRPC_WPFAKEVERSION_DESC);
$propbag->add('default', '');
break;
case 'category':
$cats = serendipity_fetchCategories($serendipity['authorid']);
if (!is_array($cats)) {
@ -141,6 +162,8 @@ class serendipity_event_xmlrpc extends serendipity_event
unset($serendipity['GET']['category']);
unset($serendipity['GET']['hide_category']);
$serendipity['xmlrpc_default_category'] = $this->get_config('category');
$serendipity['xmlrpc_debuglog'] = $this->get_config('debuglog','none');
$serendipity['xmlrpc_wpfakeversion'] = $this->get_config('wpfakeversion','');
@define('SERENDIPITY_IS_XMLRPC', true);
$serendipity['XMLRPC_GMT'] = serendipity_db_bool($this->get_config('gmt'));

View file

@ -7,10 +7,14 @@ if (empty($HTTP_RAW_POST_DATA)) {
$HTTP_RAW_POST_DATA = implode("\r\n", file('php://input'));
}
$debug_xmlrpc = 1;
global $serendipity;
if ($serendipity['xmlrpc_debuglog']=='normal') $debug_xmlrpc = 1;
elseif ($serendipity['xmlrpc_debuglog']=='verbose') $debug_xmlrpc = 2;
else $debug_xmlrpc = 0;
if ($debug_xmlrpc) {
//@define('DEBUG_LOG_XMLRPC', '/tmp/rpc.log');
@define('DEBUG_LOG_XMLRPC', dirname(__FILE__) . "/rpc.log");
@define('DEBUG_LOG_XMLRPC', dirname(__FILE__) . "/rpc.log");
$fp = fopen(DEBUG_LOG_XMLRPC, 'a');
fwrite($fp, '[' . date('d.m.Y H:i') . ']' . print_r($HTTP_RAW_POST_DATA, true));
fclose($fp);
@ -213,8 +217,10 @@ function wp_getPostFormats( $message ) {
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
$formats_to_show = $val->getval();
if (count($message->params)>3) {
$val = $message->params[3];
$formats_to_show = $val->getval();
}
$all_formats = new XML_RPC_Value(
array(
@ -232,15 +238,16 @@ function wp_getPostFormats( $message ) {
);
$supported_formats = new XML_RPC_Value(
array(
'standard' => new XML_RPC_Value("Article (S9Y)", 'string'),
'standard' => new XML_RPC_Value("Article (Serendipity)", 'string'),
),'struct'
);
//return new XML_RPC_Response($all_formats);
return new XML_RPC_Response($supported_formats);
}
function wp_getOptions($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
@ -249,21 +256,39 @@ function wp_getOptions($message) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
if (count($message->params)>3) {
$val = $message->params[3];
$filter = XML_RPC_decode($val);
}
$doFilter = !empty($filter) && is_array($filter) && count($filter) >0;
$xml_entries_vals = array();
$xml_entries_vals[] = wp_getOptions_createOption('software_name', 'Serendipity');
$xml_entries_vals[] = wp_getOptions_createOption('software_version', $serendipity['version']);
$xml_entries_vals[] = wp_getOptions_createOption('blog_url', $serendipity['baseURL']);
$xml_entries_vals[] = wp_getOptions_createOption('blog_title', $serendipity['blogTitle']);
if (empty($serendipity['xmlrpc_wpfakeversion'])) {
if (!$doFilter || in_array('software_name', $filter))
$xml_entries_vals[] = wp_getOptions_createOption('software_name', 'Serendipity');
if (!$doFilter || in_array('software_version', $filter))
$xml_entries_vals[] = wp_getOptions_createOption('software_version', $serendipity['version']);
}
else {
if (!$doFilter || in_array('software_name', $filter))
$xml_entries_vals[] = wp_getOptions_createOption('software_name', 'WordPress');
if (!$doFilter || in_array('software_version', $filter))
$xml_entries_vals[] = wp_getOptions_createOption('software_version', $serendipity['xmlrpc_wpfakeversion']);
}
if (!$doFilter || in_array('blog_url', $filter))
$xml_entries_vals[] = wp_getOptions_createOption('blog_url', $serendipity['baseURL']);
if (!$doFilter || in_array('blog_title', $filter))
$xml_entries_vals[] = wp_getOptions_createOption('blog_title', $serendipity['blogTitle']);
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
/**
* Private function to create a single wpOption
* Enter description here ...
* @param unknown_type $desc
* @param unknown_type $value
* @param unknown_type $readonly
* @param string $desc
* @param string $value
* @param boolean $readonly default true
*/
function wp_getOptions_createOption($desc, $value, $readonly=true) {
$values = array(
@ -460,16 +485,16 @@ function wp_editComment($message) {
$comment_id = $val->getval();
$val = $message->params[4];
$rpccomment = $val->getval();
universal_debug("Edit comment: " . print_r($rpccomment,true));
if (!empty($comment_id)) {
ob_start();
// We need the entryid, so fetch it:
$commentInfo = serendipity_db_query("SELECT c.entry_id as entry_id, c.body as content, c.email as author_email, c.author as comment_author, c.status as comment_status, c.url as author_url, e.authorid AS entry_authorid
FROM {$serendipity['dbPrefix']}comments c
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)
WHERE c.id = $comment_id"
, true);
universal_debug("Fetched commentInfos: " . print_r($commentInfo, TRUE));
// If we fetched a row, process it
if (is_array($commentInfo)) {
@ -496,10 +521,12 @@ function wp_editComment($message) {
elseif ($rpc_comment_status=='approve' && $comment_status != 'approved') serendipity_plugin_api::hook_event('xmlrpc_comment_approve', $comment);
}
}
}
else {
} else {
$result = false;
}
$errs = ob_get_contents();
if (!empty($errs)) universal_debug("errors: $errs");
ob_clean();
}
else {
$result = false;
@ -1434,6 +1461,7 @@ function universal_debug($message) {
if (DEBUG_XMLRPC) {
$fp = fopen(DEBUG_LOG_XMLRPC, 'a');
fwrite($fp, $message . "\n");
fflush($fp);
fclose($fp);
}
}