Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9206
Modified Files:
Tag: branch-smarty
NEWS serendipity_functions.inc.php serendipity_xmlrpc.php
Log Message:
MFH
Index: NEWS
===================================================================
RCS file: /cvsroot/php-blog/serendipity/NEWS,v
retrieving revision 1.214.2.13
retrieving revision 1.214.2.14
diff -u -d -r1.214.2.13 -r1.214.2.14
--- NEWS 20 Sep 2004 09:43:59 -0000 1.214.2.13
+++ NEWS 20 Sep 2004 14:00:38 -0000 1.214.2.14
@@ -20,6 +20,9 @@
Version 0.7-beta3 ()
------------------------------------------------------------------------
+ * Fixed XML RPC API to set categories when posting via BlogJet
+ or other interfaces (garvinhicking)
+
* Fixed invalid standard-SQL 'CURRENT_DATE' to use a real date
string. Fixes Exit-Tracking with SQLite. (garvinhicking)
Index: serendipity_xmlrpc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_xmlrpc.php,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -d -r1.16 -r1.16.2.1
--- serendipity_xmlrpc.php 9 Aug 2004 19:57:34 -0000 1.16
+++ serendipity_xmlrpc.php 20 Sep 2004 14:00:39 -0000 1.16.2.1
@@ -1,10 +1,20 @@
<?php # $Id$
+$debug_xmlrpc = false;
+if ($debug_xmlrpc) {
+ $fp = fopen('rpc.log', 'a');
+ fwrite($fp, '[' . date('d.m.Y H:i') . ']' . print_r($HTTP_RAW_POST_DATA, true));
+ fclose($fp);
+ ob_start();
+}
+
session_start();
require_once 'serendipity_config.inc.php';
require_once 'bundled-libs/XML/RPC/Server.php';
-$dispatches = array('blogger.getUsersBlogs' =>
+$dispatches = array(
+ /* BLOGGER API */
+ 'blogger.getUsersBlogs' =>
array('function' => 'blogger_getUsersBlogs'),
'blogger.getUserInfo' =>
array('function' => 'blogger_getUserInfo'),
@@ -18,6 +28,8 @@
array('function' => 'blogger_getRecentPosts'),
'blogger.getPost' =>
array('function' => 'blogger_getPost'),
+
+ /* MT/metaWeblog API */
'metaWeblog.newPost' =>
array('function' => 'metaWeblog_newPost'),
'metaWeblog.editPost' =>
@@ -26,6 +38,14 @@
array('function' => 'metaWeblog_getPost'),
'metaWeblog.deletePost' =>
array('function' => 'metaWeblog_deletePost'),
+ 'metaWeblog.setPostCategories' =>
+ array('function' => 'metaWeblog_setPostCategories'),
+ 'metaWeblog.getPostCategories' =>
+ array('function' => 'metaWeblog_getPostCategories'),
+ 'metaWeblog.newMediaObject' =>
+ array('function' => 'metaWeblog_newMediaObject'),
+ 'metaWeblog.getRecentPosts' =>
+ array('function' => 'mt_getRecentPostTitles'),
'mt.getRecentPostTitles' =>
array('function' => 'mt_getRecentPostTitles'),
'mt.getCategoryList' =>
@@ -34,14 +54,10 @@
array('function' => 'metaWeblog_getPostCategories'),
'mt.setPostCategories' =>
array('function' => 'metaWeblog_setPostCategories'),
- 'metaWeblog.setPostCategories' =>
- array('function' => 'metaWeblog_setPostCategories'),
- 'metaWeblog.getPostCategories' =>
- array('function' => 'metaWeblog_getPostCategories'),
- 'metaWeblog.newMediaObject' =>
- array('function' => 'metaWeblog_newMediaObject'),
'mt.supportedTextFilters' =>
- array('function' => 'mt_supportedTextFilters'));
+ array('function' => 'mt_supportedTextFilters'),
+ 'mt.publishPost' =>
+ array('function' => 'metaWeblog_publishPost'));
function blogger_getUsersBlogs($message) {
global $serendipity;
@@ -50,7 +66,7 @@
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
$blog1 = new XML_RPC_Value(
@@ -69,7 +85,7 @@
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
$userdata = new XML_RPC_Value(
@@ -91,7 +107,7 @@
$password = $val->getval();
$val = $message->params[4];
$numposts = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
$entries = serendipity_fetchEntries('', false, $numposts);
@@ -117,27 +133,13 @@
$username = $val->getval();
$val = $message->params[3];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
- $entry = serendipity_fetchEntry('id', $postid);
- $tmp = array(
- 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
- 'postid' => new XML_RPC_Value($postid, 'string'),
- 'userid' => new XML_RPC_Value($entry['authorid'], 'string'),
- 'description' => new XML_RPC_Value($entry['body'], 'string'),
- 'content' => new XML_RPC_Value($entry['extended'], 'string'),
- 'mt_excerpt' => new XML_RPC_Value('', 'string'),
- 'mt_allow_comments' => new XML_RPC_Value(1, 'int'),
- '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['baseURL'] . ($serendipity['rewrite'] == 'none' ? '/' . $serendipity['indexFile'] . '?' : '') . '/'.PATH_ARCHIVES.'/' . $postid . '_.html', 'string'),
- 'link' => new XML_RPC_Value($serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? '/' . $serendipity['indexFile'] . '?' : '') . '/'.PATH_ARCHIVES.'/' . $postid . '_.html', 'string'));
- $entry = new XML_RPC_Value($tmp, 'struct');
- return new XML_RPC_Response($entry);
+ $entry = serendipity_fetchEntry('id', $postid);
+ $entry = new XML_RPC_Value(blogger_setEntry($entry), 'struct');
+ return new XML_RPC_Response($entry);
}
function mt_getCategoryList($message) {
@@ -147,7 +149,7 @@
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
$cats = serendipity_fetchCategories($serendipity['authorid']);
@@ -156,10 +158,13 @@
$xml_entries_vals[] = new XML_RPC_Value(
array(
'categoryId' => new XML_RPC_Value($cat['categoryid'], 'string'),
- 'categoryName' => new XML_RPC_Value($cat['category_name'], 'string')), 'struct');
+ 'categoryName' => new XML_RPC_Value($cat['category_name'], 'string')
+ ),
+ 'struct'
+ );
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
- return new XML_RPC_Response($xml_entries);
+ return new XML_RPC_Response($xml_entries);
}
function mt_getRecentPostTitles($message) {
@@ -169,19 +174,21 @@
$password = $val->getval();
$val = $message->params[3];
$numposts = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ 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 $entry ) {
+ foreach ($entries as $entry) {
$xml_entries_vals[] = new XML_RPC_Value(
array(
- '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')), 'struct');
+ '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')
+ ),
+ 'struct');
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
@@ -189,7 +196,7 @@
function mt_supportedTextFilters($message) {
# we support no text filters currently
- return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
+ return new XML_RPC_Response(new XML_RPC_Value(array(), 'array'));
}
function blogger_newPost($message) {
@@ -198,7 +205,7 @@
$username = $val->getval();
$val = $message->params[3];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
$val = $message->params[4];
@@ -206,7 +213,7 @@
$entry['allow_comments'] = $serendipity['allowCommentsDefault'];
$entry['moderate_comments'] = $serendipity['moderateCommentsDefault'];
$id = serendipity_updertEntry($entry);
- return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
+ return new XML_RPC_Response(new XML_RPC_Value($id, 'string'));
}
function blogger_editPost($message) {
@@ -216,14 +223,14 @@
$username = $val->getval();
$val = $message->params[3];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ 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_updertEntry($entry);
- return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
+ return new XML_RPC_Response(new XML_RPC_Value($id, 'string'));
}
function blogger_deletePost($message) {
@@ -233,14 +240,36 @@
$username = $val->getval();
$val = $message->params[3];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ 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'));
+ return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
+}
+
+function universal_fetchCategories($post_categories) {
+ global $serendipity;
+
+ $categories = array();
+ if (is_array($post_categories)) {
+ foreach($post_categories AS $cat_id => $cat_obj) {
+ if (is_object($cat_obj)) {
+ $cat_name = $cat_obj->getval();
+ $cat = serendipity_fetchCategories(null, $cat_name);
+ if (isset($cat[0]['categoryid'])) {
+ $categories[$cat[0]['categoryid']] = $cat[0]['categoryid'];
+ }
+ } elseif (is_array($cat_obj) && isset($cat_obj['categoryId'])) {
+ $cat_id = $cat_obj['categoryId']->getval();
+ $categories[$cat_id] = $cat_id;
+ }
+ }
+ }
+
+ return $categories;
}
function metaWeblog_newPost($message) {
@@ -249,46 +278,80 @@
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
+
$val = $message->params[3];
$post_array = $val->getval();
$val = $message->params[4];
$publish = $val->getval();
- $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'];
+
+ $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'];
$entry['moderate_comments'] = $serendipity['moderateCommentsDefault'];
+
$id = serendipity_updertEntry($entry);
- return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
+
+ return new XML_RPC_Response(new XML_RPC_Value($id, 'string'));
+}
+
+function metaWeblog_publishPost($message) {
+ global $serendipity;
+
+ $val = $message->params[0];
+ $postid = $val->getval();
+ $val = $message->params[1];
+ $username = $val->getval();
+ $val = $message->params[2];
+ $password = $val->getval();
+
+ if (!serendipity_authenticate_author($username, $password)) {
+ return new XML_RPC_Response('', 4, 'Authentication Failed');
+ }
+
+ $entry['isdraft'] = 'false';
+ $entry['id'] = $postid;
+
+ $id = serendipity_updertEntry($entry);
+ return new XML_RPC_Response(new XML_RPC_Value($id ? true : false, 'boolean'));
}
function metaWeblog_editPost($message) {
+ global $serendipity;
+
$val = $message->params[0];
$postid = $val->getval();
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
+
$val = $message->params[3];
$post_array = $val->getval();
$val = $message->params[4];
$publish = $val->getval();
- $entry['title'] = $post_array['title'];
- $entry['body'] = $post_array['description'];
- $entry['extended'] = $post_array['mt_text_more'];
- $entry['author'] = $username;
- $entry['authorid'] = $serendipity['authorid'];
- $entry['id'] = $postid;
- $entry['isdraft'] = ($publish == 0)?'true':'false';
+
+ $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['author'] = $username;
+ $entry['authorid'] = $serendipity['authorid'];
+ $entry['id'] = $postid;
+
$id = serendipity_updertEntry($entry);
- return new XML_RPC_Response( new XML_RPC_Value($id));
+ return new XML_RPC_Response(new XML_RPC_Value($id ? true : false, 'boolean'));
}
function metaWeblog_getPost($message) {
@@ -299,44 +362,31 @@
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
+
$entry = serendipity_fetchEntry('id', $postid);
+ $entry = new XML_RPC_Value(metaWeblog_setEntry($entry), 'struct');
- $tmp = array(
- 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
- 'postid' => new XML_RPC_Value($postid, 'string'),
- 'userid' => new XML_RPC_Value($entry['authorid'], 'string'),
- 'description' => new XML_RPC_Value($entry['body'], 'string'),
- 'mt_text_more' => new XML_RPC_Value($entry['extended'], 'string'),
- 'mt_excerpt' => new XML_RPC_Value('', 'string'),
- 'mt_allow_comments' => new XML_RPC_Value(1, 'int'),
- '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['baseURL'] . ($serendipity['rewrite'] == 'none' ? '/' . $serendipity['indexFile'] . '?' : '') . '/'.PATH_ARCHIVES.'/' . $postid . '_.html', 'string'),
- 'link' => new XML_RPC_Value($serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? '/' . $serendipity['indexFile'] . '?' : '') . '/'.PATH_ARCHIVES.'/' . $postid . '_.html', 'string'));
- $entry = new XML_RPC_Value($tmp, 'struct');
- return new XML_RPC_Response($entry);
+ return new XML_RPC_Response($entry);
}
-function metaweblog_deletePost($message) {
+function metaWeblog_deletePost($message) {
$val = $message->params[1];
$entry['id'] = $val->getval();
$val = $message->params[2];
$username = $val->getval();
$val = $message->params[3];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ 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'));
+ return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
}
function metaWeblog_setPostCategories($message) {
@@ -347,29 +397,44 @@
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- $val = $message->params[3];
- $categories = $val->getval();
- $category_ids = array();
- foreach ($categories as $cat) {
- $val = $cat['categoryId'];
- $category_ids[] = $val->getval();
- }
- if(!serendipity_authenticate_author($username, $password)) {
+ $categories = $message->params[3];
+
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
+
+ $category_ids = universal_fetchCategories($categories->getval(), true);
serendipity_updateEntryCategories($postid, $category_ids);
- return new XML_RPC_Response( new XML_RPC_Value(1, 'boolean'));
+ return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
}
function metaWeblog_getPostCategories($message) {
+ $val = $message->params[0];
+ $postid = $val->getval();
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
- return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
+
+ $entry = serendipity_fetchEntry('id', (int)$postid);
+
+ $categories = array();
+ if (is_array($entry['categories'])) {
+ foreach($entry['categories'] AS $i => $cat) {
+ $categories[] = new XML_RPC_Value(
+ array(
+ 'categoryId' => new XML_RPC_Value($cat['categoryid'], 'string'),
+ 'categoryName' => new XML_RPC_Value($cat['category_name'], 'string')
+ ),
+ 'struct'
+ );
+ }
+ }
+
+ return new XML_RPC_Response(new XML_RPC_Value($categories, 'array'));
}
function metaWeblog_newMediaObject($message) {
@@ -382,7 +447,7 @@
$password = $val->getval();
$val = $message->params[3];
$struct = $val->getval();
- if(!serendipity_authenticate_author($username, $password)) {
+ if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, 'Authentication Failed');
}
@@ -390,9 +455,48 @@
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'));
+ return new XML_RPC_Response(new XML_RPC_Value(array('url' => new XML_RPC_Value($path, 'string')), 'struct'));
+}
+
+function blogger_setEntry(&$entry) {
+ $tmp = array(
+ 'content' => new XML_RPC_Value($entry['extended'], 'string'),
+ );
+ return universal_setEntry($entry, $tmp);
+}
+
+function metaWeblog_setEntry(&$entry) {
+ $tmp = array(
+ 'mt_text_more' => new XML_RPC_Value($entry['extended'], 'string'),
+ );
+ return universal_setEntry($entry, $tmp);
+}
+
+function universal_setEntry(&$entry, &$tmp) {
+ $tmp = array(
+ 'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
+ 'postid' => new XML_RPC_Value($postid, '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_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['baseURL'] . ($serendipity['rewrite'] == 'none' ? '/' . $serendipity['indexFile'] . '?' : '') . '/'.PATH_ARCHIVES.'/' . $postid . '_.html', 'string'),
+ 'link' => new XML_RPC_Value($serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? '/' . $serendipity['indexFile'] . '?' : '') . '/'.PATH_ARCHIVES.'/' . $postid . '_.html', 'string'),
+ );
+
+ return array_merge($entry, $tmp);
}
$server = new XML_RPC_Server($dispatches,1);
+if ($debug_xmlrpc) {
+ $fp = fopen('rpc.log', 'a');
+ fwrite($fp, ob_get_contents() . "\n---------------------------------------\n");
+ fclose($fp);
+ ob_end_flush();
+}
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.419.2.23
retrieving revision 1.419.2.24
diff -u -d -r1.419.2.23 -r1.419.2.24
--- serendipity_functions.inc.php 20 Sep 2004 09:43:59 -0000 1.419.2.23
+++ serendipity_functions.inc.php 20 Sep 2004 14:00:38 -0000 1.419.2.24
@@ -799,7 +799,7 @@
/**
* Fetches a users categories
**/
-function serendipity_fetchCategories($authorid = null) {
+function serendipity_fetchCategories($authorid = null, $name = '') {
global $serendipity;
if (!isset($authorid) || $authorid === null) {
@@ -811,11 +811,21 @@
}
if ($authorid != 'all' && is_numeric($authorid)) {
- $where = " WHERE (c.authorid = $authorid OR c.authorid = 0) OR a.userlevel < ".$serendipity['serendipityUserlevel'];
+ $where = " WHERE ((c.authorid = $authorid OR c.authorid = 0) OR a.userlevel < " . $serendipity['serendipityUserlevel'] . ')';
} else {
$where = '';
}
+ if (!empty($name)) {
+ if ($where == '') {
+ $where = ' WHERE ';
+ } else {
+ $where = ' AND ';
+ }
+
+ $where .= " c.category_name = '" . serendipity_db_escape_string($name) . "'";
+ }
+
$querystring = "SELECT
c.*,
a.username
@@ -1574,7 +1584,7 @@
$query .= " VALUES ('$id', '$parentid', '$ip', '$name', '$email', '$url', '$commentsFixed', '$type', '$t', '$title', '$subscribe', '$status')";
serendipity_db_query($query);
- $cid = serendipity_db_insert_id();
+ $cid = serendipity_db_insert_id('comments', 'id');
$query = "SELECT a.email, e.title, a.mail_comments, a.mail_trackbacks, e.moderate_comments
FROM {$serendipity['dbPrefix']}entries e, {$serendipity['dbPrefix']}authors a
@@ -2401,17 +2411,18 @@
if (!$_SESSION['serendipityRightPublish']) {
$entry['isdraft'] = 'true';
}
- if(!isset($entry['allow_comments'])){
- $entry['allow_comments']='false';
- }
- if(!isset($entry['moderate_comments'])){
- $entry['moderate_comments']='false';
- }
+
+ if(!isset($entry['allow_comments'])){
+ $entry['allow_comments']='false';
+ }
+ if(!isset($entry['moderate_comments'])){
+ $entry['moderate_comments']='false';
+ }
$res = serendipity_db_insert('entries', $entry);
if ($res) {
- $entry['id'] = serendipity_db_insert_id();
+ $entry['id'] = serendipity_db_insert_id('entries', 'id');
if (is_array($categories)) {
foreach ($categories as $cat) {
if (is_numeric($cat))
@@ -2440,9 +2451,11 @@
unset($entry['isdraft']);
}
- serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entrycat WHERE entryid={$entry['id']}");
- foreach ($categories as $cat) {
- serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
+ if (is_array($categories)) {
+ serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entrycat WHERE entryid={$entry['id']}");
+ foreach ($categories as $cat) {
+ serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
+ }
}
$res = serendipity_db_update('entries', array('id' => $entry['id']), $entry);
@@ -3257,8 +3270,14 @@
$query = "DELETE FROM $serendipity[dbPrefix]entrycat WHERE entryid = " . (int)$postid;
serendipity_db_query($query);
- $query = "INSERT INTO $serendipity[dbPrefix]entrycat (entryid, categoryid) VALUES (" . (int)$categories[0] . ", " . (int)$postid . ")";
- serendipity_db_query($query);
+ if (!is_array($categories)) {
+ $categories = array(0 => $categories);
+ }
+
+ foreach($categories AS $idx => $cat) {
+ $query = "INSERT INTO $serendipity[dbPrefix]entrycat (categoryid, entryid) VALUES (" . (int)$cat . ", " . (int)$postid . ")";
+ serendipity_db_query($query);
+ }
}
/*
|