From 1a3216efa64ee839659e4524468114d60c055d3f Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Fri, 27 May 2005 09:36:48 +0000 Subject: [PATCH] backports --- docs/NEWS | 12 +++ include/admin/category.inc.php | 1 + index.php | 6 +- .../serendipity_event_spartacus.php | 22 ++++- serendipity_xmlrpc.php | 97 ++++++++++++++++--- 5 files changed, 121 insertions(+), 17 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 7589581..2c903e8 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,18 @@ svn di# $Id$ Version 0.8.2 () ------------------------------------------------------------------------ + * Patch/Bug #1209410 by swiesinger: When using shortcut admin URL, + use https:// when specified by user + + * Fix deleting categories when having privileges but not being + administrator (Patch #1205347, many thanks to Penny Leach) + + * Increased level of output message from the Spartacus plugin + (garvinhicking) + + * Patched XML-RPC functions, thanks to Tim Putnam. This should enable + XML-RPC services to properly fetch existing articles and edit them. + * Fix Plugin API call performing too many unneeded SQL queries (garvinhicking) diff --git a/include/admin/category.inc.php b/include/admin/category.inc.php index f81f3c2..bc53c0a 100644 --- a/include/admin/category.inc.php +++ b/include/admin/category.inc.php @@ -114,6 +114,7 @@ if ($serendipity['GET']['adminAction'] == 'doDelete') { = USERLEVEL_CHIEF || $serendipity['authorid'] == $this_cat['authorid'] || $this_cat['authorid'] == '0') { ?>
diff --git a/index.php b/index.php index fd98224..70ee5df 100644 --- a/index.php +++ b/index.php @@ -206,7 +206,11 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range print $data; exit; } else if (preg_match(PAT_ADMIN, $uri)) { - header("Location: {$serendipity['baseURL']}serendipity_admin.php"); + $base = $serendipity['baseURL']; + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { + $base = str_replace('http://', 'https://', $base); + } + header("Location: {$base}serendipity_admin.php"); exit; } else if (preg_match(PAT_ARCHIVE, $uri)) { $serendipity['GET']['action'] = 'archives'; diff --git a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php index 9b2597a..ca58fef 100644 --- a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php +++ b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php @@ -21,7 +21,11 @@ switch ($serendipity['lang']) { @define('PLUGIN_EVENT_SPARTACUS_FETCH', 'Hier klicken um ein neues %s aus dem Netz zu installieren.'); @define('PLUGIN_EVENT_SPARTACUS_FETCHERROR', 'Die URL %s konnte nicht geöffnet werden. Möglicherweise existieren Server- oder Netzwerkprobleme.'); @define('PLUGIN_EVENT_SPARTACUS_FETCHING', 'Versuche URL %s zu öffnen...'); + @define('PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_URL', '%s bytes von obiger URL geladen. Speichere Inhalt als %s...'); + @define('PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_CACHE', '%s bytes von bereits bestehender Datei geladen. Speichere Inhalt als %s...'); + @define('PLUGIN_EVENT_SPARTACUS_FETCHED_DONE', 'Data successfully fetched.'); break; + case 'en': default: @define('PLUGIN_EVENT_SPARTACUS_NAME', 'Spartacus'); @@ -29,6 +33,9 @@ switch ($serendipity['lang']) { @define('PLUGIN_EVENT_SPARTACUS_FETCH', 'Click here to fetch a new %s from the Serendipity Online Repository'); @define('PLUGIN_EVENT_SPARTACUS_FETCHERROR', 'The URL %s could not be opened. Maybe the Serendipity or SourceForge.net Server is down - we are sorry, you need to try again later.'); @define('PLUGIN_EVENT_SPARTACUS_FETCHING', 'Trying to open URL %s...'); + @define('PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_URL', 'Fetched %s bytes from the URL above. Saving file as %s...'); + @define('PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_CACHE', 'Fetched %s bytes from already existing file on your server. Saving file as %s...'); + @define('PLUGIN_EVENT_SPARTACUS_FETCHED_DONE', 'Data successfully fetched.'); break; } @@ -44,7 +51,7 @@ class serendipity_event_spartacus extends serendipity_event $propbag->add('description', PLUGIN_EVENT_SPARTACUS_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking'); - $propbag->add('version', '1.01'); + $propbag->add('version', '1.1'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -120,23 +127,30 @@ class serendipity_event_spartacus extends serendipity_event } function &fetchfile($url, $target, $cacheTimeout = 0) { - printf(PLUGIN_EVENT_SPARTACUS_FETCHING, '' . serendipity_truncateString($url, 68) . ''); + printf(PLUGIN_EVENT_SPARTACUS_FETCHING, '' . basename($url) . ''); echo '
'; if (file_exists($target) && filesize($target) > 0 && filemtime($target) >= (time()-$cacheTimeout)) { $data = file_get_contents($target); + printf(PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_CACHE, strlen($data), $target); + echo '
'; } else { require_once S9Y_INCLUDE_PATH . 'bundled-libs/HTTP/Request.php'; $req = &new HTTP_Request($url); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { printf(PLUGIN_EVENT_SPARTACUS_FETCHERROR, $url); + echo '
'; if (file_exists($target) && filesize($target) > 0) { $data = file_get_contents($target); + printf(PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_CACHE, strlen($data), $target); + echo '
'; } } else { // Fetch file $data = $req->getResponseBody(); + printf(PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_URL, strlen($data), $target); + echo '
'; $tdir = dirname($target); if (!is_dir($tdir) && !$this->rmkdir($tdir)) { printf(FILE_WRITE_ERROR, $tdir); @@ -148,11 +162,14 @@ class serendipity_event_spartacus extends serendipity_event if (!$fp) { printf(FILE_WRITE_ERROR, $target); + echo '
'; return false; } fwrite($fp, $data); fclose($fp); + echo PLUGIN_EVENT_SPARTACUS_FETCHED_DONE; + echo '
'; } } @@ -277,6 +294,7 @@ class serendipity_event_spartacus extends serendipity_event $pdir = $serendipity['serendipityPath'] . '/plugins/'; if (!is_writable($pdir)) { printf(DIRECTORY_WRITE_ERROR, $pdir); + echo '
'; return false; } diff --git a/serendipity_xmlrpc.php b/serendipity_xmlrpc.php index d82df22..9883a26 100644 --- a/serendipity_xmlrpc.php +++ b/serendipity_xmlrpc.php @@ -46,7 +46,7 @@ $dispatches = array( 'metaWeblog.newMediaObject' => array('function' => 'metaWeblog_newMediaObject'), 'metaWeblog.getRecentPosts' => - array('function' => 'mt_getRecentPostTitles'), + array('function' => 'metaWeblog_getRecentPosts'), 'mt.getRecentPostTitles' => array('function' => 'mt_getRecentPostTitles'), 'mt.getCategoryList' => @@ -118,9 +118,10 @@ function blogger_getRecentPosts($message) { array( 'postid' => new XML_RPC_Value($entry['id'], 'string'), 'title' => new XML_RPC_Value($entry['title'], 'string'), + 'content' => new XML_RPC_Value($entry['body'], 'string'), 'userid' => new XML_RPC_Value($entry['authorid'], 'string'), - 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'), - 'postid' => new XML_RPC_Value($entry['id'], 'string')), 'struct'); + 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601') + ), 'struct'); } $xml_entries = new XML_RPC_Value($xml_entries_vals, 'array'); return new XML_RPC_Response($xml_entries); @@ -168,6 +169,44 @@ function mt_getCategoryList($message) { return new XML_RPC_Response($xml_entries); } +function metaWeblog_getRecentPosts($message) { + $val = $message->params[1]; + $username = $val->getval(); + $val = $message->params[2]; + $password = $val->getval(); + $val = $message->params[3]; + $numposts = $val->getval(); + if (!serendipity_authenticate_author($username, $password)) { + return new XML_RPC_Response('', 4, 'Authentication Failed'); + } + $entries = serendipity_fetchEntries('', false, $numposts); + $xml_entries_vals = array(); + + foreach ($entries as $tentry) { + $entry = serendipity_fetchEntry('id', $tentry['id']); + $xml_entries_vals[] = new XML_RPC_Value( + array( + 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'), + 'postid' => new XML_RPC_Value($entry['id'], 'string'), + 'userid' => new XML_RPC_Value($entry['authorid'], 'string'), + 'description' => new XML_RPC_Value($entry['body'], 'string'), + 'mt_excerpt' => new XML_RPC_Value('', 'string'), + 'mt_allow_comments' => new XML_RPC_Value(1, 'int'), + 'mt_text_more' => new XML_RPC_Value($entry['extended'], 'string' ), + 'mt_allow_pings' => new XML_RPC_Value(1, 'int'), + 'mt_convert_breaks' => new XML_RPC_Value('', 'string'), + 'mt_keywords' => new XML_RPC_Value('', 'string'), + 'title' => new XML_RPC_Value($entry['title'],'string'), + 'permalink' => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])), 'string'), + 'link' => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])), 'string') + ), + 'struct'); + + } + $xml_entries = new XML_RPC_Value($xml_entries_vals, 'array'); + return new XML_RPC_Response($xml_entries); + +} function mt_getRecentPostTitles($message) { $val = $message->params[1]; $username = $val->getval(); @@ -186,8 +225,7 @@ function mt_getRecentPostTitles($message) { 'postid' => new XML_RPC_Value($entry['id'], 'string'), 'title' => new XML_RPC_Value($entry['title'], 'string'), 'userid' => new XML_RPC_Value($entry['authorid'], 'string'), - 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'), - 'postid' => new XML_RPC_Value($entry['id'], 'string') + 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601') ), 'struct'); } @@ -211,6 +249,12 @@ function blogger_newPost($message) { } $val = $message->params[4]; $entry['body'] = $val->getval(); + $val = $message->params[5]; + $topublish = $val->getval(); + if ($topublish == 1){ + $entry['isdraft'] = 'false'; + } else { $entry['isdraft'] = 'true'; } + $entry['allow_comments'] = $serendipity['allowCommentsDefault']; $entry['moderate_comments'] = $serendipity['moderateCommentsDefault']; $id = serendipity_updertEntry($entry); @@ -244,9 +288,7 @@ function blogger_deletePost($message) { if (!serendipity_authenticate_author($username, $password)) { return new XML_RPC_Response('', 4, 'Authentication Failed'); } - $val = $message->params[4]; - $entry['body'] = $val->getval(); - $entry['author'] = $username; + $id = serendipity_deleteEntry($entry['id']); return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean')); } @@ -289,13 +331,20 @@ function metaWeblog_newPost($message) { $val = $message->params[4]; $publish = $val->getval(); + $entry['categories'] = universal_fetchCategories($post_array['categories']); $entry['title'] = $post_array['title']; $entry['body'] = $post_array['description']; $entry['extended'] = $post_array['mt_text_more']; $entry['isdraft'] = ($publish == 0) ? 'true' : 'false'; - $entry['allow_comments'] = $serendipity['allowCommentsDefault']; + if (isset($post_array['mt_allow_comments'])) { + $entry['allow_comments'] = $post_array['mt_allow_comments']; + } else { + $entry['allow_comments'] = $serendipity['allowCommentsDefault']; + } + $entry['moderate_comments'] = $serendipity['moderateCommentsDefault']; + $entry['keywords'] = $post_array['mt_keywords']; $id = serendipity_updertEntry($entry); @@ -342,7 +391,9 @@ function metaWeblog_editPost($message) { $val = $message->params[4]; $publish = $val->getval(); - $entry['categories'] = universal_fetchCategories($post_array['categories']); + if (isset($post_array['categories'])) { + $entry['categories'] = universal_fetchCategories($post_array['categories']); + } $entry['title'] = $post_array['title']; $entry['body'] = $post_array['description']; $entry['extended'] = $post_array['mt_text_more']; @@ -355,6 +406,7 @@ function metaWeblog_editPost($message) { return new XML_RPC_Response(new XML_RPC_Value($id ? true : false, 'boolean')); } + function metaWeblog_getPost($message) { global $serendipity; $val = $message->params[0]; @@ -368,9 +420,23 @@ function metaWeblog_getPost($message) { } $entry = serendipity_fetchEntry('id', $postid); - $entry = new XML_RPC_Value(metaWeblog_setEntry($entry), 'struct'); - return new XML_RPC_Response($entry); + $tmp = new XML_RPC_Value(array( + 'userid' => new XML_RPC_Value($entry['authorid'], 'string'), + 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'), + 'postid' => new XML_RPC_Value($postid, 'string'), + 'description' => new XML_RPC_Value($entry['body'], 'string'), + 'title' => new XML_RPC_Value($entry['title'],'string'), + 'link' => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])), 'string'), + 'permalink' => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])), 'string'), + 'mt_excerpt' => new XML_RPC_Value($entry['excerpt'], 'string'), + 'mt_text_more' => new XML_RPC_Value($entry['extended'], 'string'), + 'mt_allow_comments' => new XML_RPC_Value($entry['allow_comments'], 'int'), + 'mt_allow_pings' => new XML_RPC_Value($entry['mt_allow_pings'], 'int'), + 'mt_convert_breaks' => new XML_RPC_Value($entry['mt_convert_breaks'], 'string'), + 'mt_keywords' => new XML_RPC_Value($entry['mt_keywords'], 'string')), 'struct'); + + return new XML_RPC_Response($tmp); } function metaWeblog_deletePost($message) { @@ -405,7 +471,10 @@ function metaWeblog_setPostCategories($message) { } $category_ids = universal_fetchCategories($categories->getval(), true); - serendipity_updateEntryCategories($postid, $category_ids); + $entry = serendipity_fetchEntry ( 'id', $postid ); + $entry['categories'] = $category_ids; + $entry = serendipity_updertEntry ( $entry ); + //serendipity_updateEntryCategories($postid, $category_ids); return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean')); } @@ -459,7 +528,7 @@ function metaWeblog_newMediaObject($message) { } $fp = fopen($full, 'w'); - fwrite($fp, base64_decode($struct['bits'])); + fwrite($fp, $struct['bits']); fclose($fp); $path = $serendipity['baseURL'] . $serendipity['uploadPath'] . $struct['name']; return new XML_RPC_Response(new XML_RPC_Value(array('url' => new XML_RPC_Value($path, 'string')), 'struct')); -- 2.39.5