[wp-cvs] wordpress xmlrpc.php,1.28.2.1,1.28.2.2
Matthew Mullenweg
saxmatt at users.sourceforge.net
Wed Dec 15 19:01:58 UTC 2004
Update of /cvsroot/cafelog/wordpress
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2504
Modified Files:
Tag: WordPress-Ver-1_2-Branch
xmlrpc.php
Log Message:
XML-RPC Patch
Index: xmlrpc.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/xmlrpc.php,v
retrieving revision 1.28.2.1
retrieving revision 1.28.2.2
diff -C2 -d -r1.28.2.1 -r1.28.2.2
*** xmlrpc.php 12 Oct 2004 21:15:12 -0000 1.28.2.1
--- xmlrpc.php 15 Dec 2004 19:01:54 -0000 1.28.2.2
***************
*** 978,983 ****
if ($postdata["Date"] != "") {
! $post_date = mysql2date("Ymd\TH:i:s", $postdata['Date']);
!
$content = "<title>".stripslashes($postdata["Title"])."</title>";
$content .= "<category>".$postdata["Category"]."</category>";
--- 978,983 ----
if ($postdata["Date"] != "") {
! // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
! $post_date = mysql2date("Ymd\TH:i:s", $postdata['Date'], 1, 1);
$content = "<title>".stripslashes($postdata["Title"])."</title>";
$content .= "<category>".$postdata["Category"]."</category>";
***************
*** 1055,1060 ****
);
! $post_date = mysql2date("Ymd\TH:i:s", $postdata['Date']);
!
$content = "<title>".stripslashes($postdata["Title"])."</title>";
$content .= "<category>".get_cat_name($postdata["Category"])."</category>";
--- 1055,1060 ----
);
! // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
! $post_date = mysql2date("Ymd\TH:i:s", $postdata['Date'], 1, 1);
$content = "<title>".stripslashes($postdata["Title"])."</title>";
$content .= "<category>".get_cat_name($postdata["Category"])."</category>";
***************
*** 1298,1305 ****
// Do some timestamp voodoo
$dateCreated = $contentstruct['dateCreated'];
! $dateCreated = $dateCreated ? iso8601_decode($dateCreated) : current_time('timestamp',1);
$post_date = gmdate('Y-m-d H:i:s', $dateCreated + get_settings('gmt_offset') * 3600);
$post_date_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $dateCreated));
$catnames = $contentstruct['categories'];
--- 1298,1308 ----
// Do some timestamp voodoo
+ // Patched by Adriaan Tijsseling (http://kung-foo.tv) to properly deal with UTC date strings -->
$dateCreated = $contentstruct['dateCreated'];
! $utc = $dateCreated[strlen($dateCreated)-1] == 'Z';
! $dateCreated = $dateCreated ? iso8601_decode($dateCreated,$utc) : current_time('timestamp',1);
$post_date = gmdate('Y-m-d H:i:s', $dateCreated + get_settings('gmt_offset') * 3600);
$post_date_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $dateCreated));
+ // <-- end patch
$catnames = $contentstruct['categories'];
***************
*** 1311,1315 ****
}
} else {
! $post_category[] = 1;
}
--- 1314,1318 ----
}
} else {
! $post_category = 0;
}
***************
*** 1409,1417 ****
// Do some timestamp voodoo
$dateCreated = $contentstruct['dateCreated'];
! $dateCreated = $dateCreated ? iso8601_decode($dateCreated) : current_time('timestamp',1);
! $post_date = date('Y-m-d H:i:s', $dateCreated);
! $post_date_gmt = get_gmt_from_date($post_date);
!
// We've got all the data -- post it:
--- 1412,1422 ----
// Do some timestamp voodoo
+ // Patched by Adriaan Tijsseling (http://kung-foo.tv) to properly deal with UTC date strings -->
$dateCreated = $contentstruct['dateCreated'];
! $utc = $dateCreated[strlen($dateCreated)-1] == 'Z';
! $dateCreated = $dateCreated ? iso8601_decode($dateCreated,$utc) : current_time('timestamp',1);
! $post_date = gmdate('Y-m-d H:i:s', $dateCreated + get_settings('gmt_offset') * 3600);
! $post_date_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $dateCreated));
! // <-- end patch
// We've got all the data -- post it:
***************
*** 1430,1437 ****
}
! pingback($content, $post_ID);
! trackback_url_list($content_struct['mt_tb_ping_urls'],$post_ID);
! logIO("O","(MW) Edited ! ID: $post_ID");
$myResp = new xmlrpcval(true,"boolean");
--- 1435,1442 ----
}
! pingback($content, $ID);
! trackback_url_list(implode(",", $contentstruct['mt_tb_ping_urls']),$ID);
! logIO("O","(MW) Edited ! ID: $ID");
$myResp = new xmlrpcval(true,"boolean");
***************
*** 1465,1470 ****
if ($postdata["Date"] != "") {
! $post_date = mysql2date('Ymd\TH:i:s', $postdata['Date']);
!
$catids = wp_get_post_cats($post_ID);
foreach($catids as $catid) {
--- 1470,1475 ----
if ($postdata["Date"] != "") {
! // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
! $post_date = mysql2date('Ymd\TH:i:s', $postdata['Date'], 1, 1);
$catids = wp_get_post_cats($post_ID);
foreach($catids as $catid) {
***************
*** 1477,1482 ****
$allow_pings = ('open' == $postdata['ping_status'])?1:0;
$resp = array(
! 'link' => new xmlrpcval(post_permalink($post_ID)),
'title' => new xmlrpcval($postdata["Title"]),
'description' => new xmlrpcval($post['main']),
--- 1482,1496 ----
$allow_pings = ('open' == $postdata['ping_status'])?1:0;
+ // Retrun if Markdown is active or not. Useful for ecto.
+ // without this, ecto could apply "Convert linebreaks" sometimes.
+ $current_plugins = explode("\n", (get_settings('active_plugins')));
+ if (!empty($current_plugins) && in_array( "markdown.php", $current_plugins)) {
+ $mt_convert_breaks = 'markdown';
+ } else {
+ $mt_convert_breaks = '__default__';
+ }
+
$resp = array(
! 'link' => new xmlrpcval(get_permalink($post_ID)),
'title' => new xmlrpcval($postdata["Title"]),
'description' => new xmlrpcval($post['main']),
***************
*** 1485,1494 ****
'postid' => new xmlrpcval($postdata["ID"]),
'content' => new xmlrpcval($postdata["Content"]),
! 'permalink' => new xmlrpcval(post_permalink($post_ID)),
! 'categories' => new xmlrpcval($catlist,'array'),
'mt_excerpt' => new xmlrpcval($postdata['Excerpt']),
'mt_allow_comments' => new xmlrpcval($allow_comments,'int'),
'mt_allow_pings' => new xmlrpcval($allow_pings,'int'),
! 'mt_text_more' => new xmlrpcval($post['extended'])
);
--- 1499,1510 ----
'postid' => new xmlrpcval($postdata["ID"]),
'content' => new xmlrpcval($postdata["Content"]),
! 'permaLink' => new xmlrpcval(get_permalink($post_ID)),
! // Disable this field. use 'mt.getPostCategories instead
! //'categories' => new xmlrpcval($catlist,'array'),
'mt_excerpt' => new xmlrpcval($postdata['Excerpt']),
'mt_allow_comments' => new xmlrpcval($allow_comments,'int'),
'mt_allow_pings' => new xmlrpcval($allow_pings,'int'),
! 'mt_text_more' => new xmlrpcval($post['extended']),
! 'mt_convert_breaks' => new xmlrpcval($mt_convert_breaks)
);
***************
*** 1534,1538 ****
foreach($postlist as $entry) {
! $isoString = mysql2date('Ymd\TH:i:s', $entry['post_date']);
$date = new xmlrpcval($isoString,"dateTime.iso8601");
$userid = new xmlrpcval($entry['post_author']);
--- 1550,1555 ----
foreach($postlist as $entry) {
! // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
! $isoString = mysql2date('Ymd\TH:i:s', $entry['post_date'], 1, 1 );
$date = new xmlrpcval($isoString,"dateTime.iso8601");
$userid = new xmlrpcval($entry['post_author']);
***************
*** 1540,1544 ****
$excerpt = new xmlrpcval($entry['post_excerpt']);
! $pcat = stripslashes(get_cat_name($entry['post_category']));
// For multiple cats, we might do something like
--- 1557,1561 ----
$excerpt = new xmlrpcval($entry['post_excerpt']);
! // $pcat = stripslashes(get_cat_name($entry['post_category']));
// For multiple cats, we might do something like
***************
*** 1550,1555 ****
//$catstruct2 = phpxmlrpc_encode($catstruct);
! $categories = new xmlrpcval(array(new xmlrpcval($pcat)),'array');
$post = get_extended($entry['post_content']);
--- 1567,1579 ----
//$catstruct2 = phpxmlrpc_encode($catstruct);
+
+ $catids = wp_get_post_cats('1', $entry['ID']);
+
+ // This should return multiple categories correctly
+ foreach($catids as $catid) {
+ $catarray[] = new xmlrpcval(get_cat_name($catid),'string');
+ }
! $categories = new xmlrpcval($catarray,'array');
$post = get_extended($entry['post_content']);
***************
*** 1558,1562 ****
$title = new xmlrpcval(stripslashes($entry['post_title']));
$description = new xmlrpcval(stripslashes($post['main']));
! $link = new xmlrpcval(post_permalink($entry['ID']));
$permalink = $link;
--- 1582,1586 ----
$title = new xmlrpcval(stripslashes($entry['post_title']));
$description = new xmlrpcval(stripslashes($post['main']));
! $link = new xmlrpcval(get_permalink($entry['ID']));
$permalink = $link;
***************
*** 1574,1578 ****
'description' => $description,
'link' => $link,
! 'permalink' => $permalink,
'mt_excerpt' => $excerpt,
'mt_allow_comments' => $allow_comments,
--- 1598,1602 ----
'description' => $description,
'link' => $link,
! 'permaLink' => $permalink,
'mt_excerpt' => $excerpt,
'mt_allow_comments' => $allow_comments,
***************
*** 1625,1635 ****
$mwnewmedia_sig = array(array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcStruct));
! $mwnewmedia_doc = 'Upload image or other binary data, MetaWeblog API-style (unimplemented)';
function mwnewmedia($params) { // ($blogid, $user, $pass, $struct)
global $xmlrpcerruser;
return new xmlrpcresp(0, $xmlrpcerruser+10, // user error 10
'metaWeblog.newMediaObject not implemented (yet)');
}
--- 1649,1764 ----
$mwnewmedia_sig = array(array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcStruct));
! $mwnewmedia_doc = 'Upload image or other binary data, MetaWeblog API-style';
!
! /* File Upload in WordPress XML-RPC
!
!
! metaWeblog.newMediaObject (blogid, username, password, struct)
!
! The blogid, username and password params are as in the Blogger API.
!
! The struct must contain at least three elements, name, type and bits.
!
! name is a string, it may be used to determine the name of the file
! that stores the object, or to display it in a list of objects.
! It determines how the weblog refers to the object. If the name is
! the same as an existing object stored in the weblog, it may replace
! the existing object.
!
! type is a string, it indicates the type of the object, it's a standard
! MIME type, like audio/mpeg or image/jpeg or video/quicktime.
!
! bits is a base64-encoded binary value containing the content of the object.
!
! The struct may contain other elements, which may or may not be stored by
! the content management system.
!
! If newMediaObject fails, it throws an error. If it succeeds, it returns
! a struct, which must contain at least one element, url, which is the url
! through which the object can be accessed. It must be either an FTP or HTTP url.
!
! */
function mwnewmedia($params) { // ($blogid, $user, $pass, $struct)
global $xmlrpcerruser;
+
+ $xblogid = $params->getParam(0);
+ $xuser = $params->getParam(1);
+ $xpass = $params->getParam(2);
+ $xdata = $params->getParam(3);
+
+ $blogid = $xblogid->scalarval();
+ $username = $xuser->scalarval();
+ $password = $xpass->scalarval();
+ $datastruct = phpxmlrpc_decode($xdata);
+
+ $name = $datastruct['name'];
+ $type = $datastruct['type'];
+ $bits = $datastruct['bits'];
+
+ $file_realpath = get_settings('fileupload_realpath');
+ $file_url = get_settings('fileupload_url');
+
+ $userdata = get_userdatabylogin($username);
+ $userlevel = $userdata->user_level;
+
+ if (user_pass_ok($username,$password)) {
+ if( !get_settings('use_fileupload')) {
+ // Uploads not allowed
+ logIO("O","(MW) Uploads not allowed");
+ return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
+ 'No uploads allowed for this site');
+ }
+
+ if( get_settings('fileupload_minlevel') > $userlevel) {
+ // User has not enough privileges
+ logIO("O","(MW) Not enough privilege");
+ return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
+ $username.' is not allowed to upload files to this site');
+ }
+
+ if( $file_realpath == "" || $file_url == "" ) {
+ // WordPress is not correctly configured
+ logIO("O","(MW) Bad configuration. Real/URL path not defined");
+ return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
+ 'Please configure WordPress with valid paths for file upload');
+ }
+
+ $prefix = "/";
+
+ if( !empty($name)) {
+ // Create the path
+ $localpath = $file_realpath.$prefix.$name;
+ $url = $file_url.$prefix.$name;
+
+ /* encode & write data (binary) */
+ $ifp = fopen( $localpath, "wb" );
+ $success = fwrite( $ifp, $bits );
+ fclose( $ifp );
+ chmod( $localpath, 0666 );
+
+ if( $success ) {
+ $resp = array(
+ 'url' => new xmlrpcval( $url ),
+ );
+
+ $resp = new xmlrpcval($resp,'struct');
+ return new xmlrpcresp($resp);
+ } else {
+ return new xmlrpcresp(0, $xmlrpcerruser+3,
+ 'Could not write file '.$name.' to '.$localpath );
+ }
+ }
+ } else {
+ logIO("O","(MW) Wrong username/password combination <b>$username / $password</b>");
+ return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
+ 'Wrong username/password combination '.$username.' / '.starify($password));
+ }
+
+ /*
return new xmlrpcresp(0, $xmlrpcerruser+10, // user error 10
'metaWeblog.newMediaObject not implemented (yet)');
+ */
}
***************
*** 1809,1814 ****
foreach($posts as $post) {
! $post_date = mysql2date('Ymd\TH:i:s', $post['post_date']);
!
$struct['dateCreated'] = new xmlrpcval($post_date, 'dateTime.iso8601');
$struct['userid'] = new xmlrpcval($post['post_author'], 'string');
--- 1938,1943 ----
foreach($posts as $post) {
! // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
! $post_date = mysql2date('Ymd\TH:i:s', $post['post_date'], 1, 1);
$struct['dateCreated'] = new xmlrpcval($post_date, 'dateTime.iso8601');
$struct['userid'] = new xmlrpcval($post['post_author'], 'string');
***************
*** 1816,1823 ****
$struct['title'] = new xmlrpcval($post['post_title'], 'string');
! $result[] = $struct;
}
! return new xmlrpcresp(new xmlrpcval($results,'array'));
} else {
--- 1945,1952 ----
$struct['title'] = new xmlrpcval($post['post_title'], 'string');
! $result[] = new xmlrpcval($struct,'struct');
}
! return new xmlrpcresp(new xmlrpcval($result,'array'));
} else {
***************
*** 1835,1839 ****
// and 'use_gmcode' config options.
! return new xmlrpcresp(new xmlrpcval(array(),'array'));
}
--- 1964,1976 ----
// and 'use_gmcode' config options.
! // Archaic Markdown check
! $current_plugins = explode("\n", (get_settings('active_plugins')));
! if (!empty($current_plugins) && in_array( "markdown.php", $current_plugins)) {
! $struct['label'] = 'Markdown';
! $struct['key'] = 'markdown';
! }
!
! $xmlstruct = phpxmlrpc_encode($struct);
! return new xmlrpcresp(new xmlrpcval(array($xmlstruct),'array'));
}
More information about the cvs
mailing list