Update of /cvsroot/php-blog/jBlog
In directory sc8-pr-cvs1:/tmp/cvs-serv575
Modified Files:
jBlog-xmlrpc.php jBlog_functions.inc.php db.sql
Log Message:
categories partially implemented
to update your schema
alter table jBlog_entries add (categoryid int)
and add jBlog_category (at the bottom of db.sql)
categories must be added by hand
Posts via xml-rpc now support categories and clients which
support mt.getCategoryList via XML-RPC
Index: jBlog-xmlrpc.php
===================================================================
RCS file: /cvsroot/php-blog/jBlog/jBlog-xmlrpc.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- jBlog-xmlrpc.php 10 Mar 2003 06:04:28 -0000 1.5
+++ jBlog-xmlrpc.php 13 Mar 2003 03:35:59 -0000 1.6
@@ -73,6 +73,8 @@
function mt_getCategoryList($message)
{
+ global $jBlog;
+
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
@@ -80,8 +82,16 @@
if(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
- return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
-// return new XML_RPC_Response( new XML_RPC_Value(array(new XML_RPC_Value(array( 'categoryId' => new XML_RPC_Value('1'), 'categoryName' => new XML_RPC_Value('default')), 'struct')), 'array'));
+ $cats = jBlog_fetchCategories($jBlog['authorid']);
+ $xml_entries_vals = array();
+ foreach ( $cats as $cat ) {
+ $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');
+ }
+ $xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
+ return new XML_RPC_Response($xml_entries);
}
function mt_getRecentPostTitles($message)
@@ -152,7 +162,7 @@
$val = $message->params[4];
$entry['body'] = $val->getval();
$entry['user'] = $username;
- $id = jBlog_updertEntry($entry);
+ $id = jBlog_updateEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
}
@@ -192,8 +202,9 @@
$entry['body'] = $post_array['description'];
$entry['extended'] = $post_array['mt_text_more'];
$entry['user'] = $username;
+ $entry['authorid'] = $jBlog['authorid'];
$entry['id'] = $postid;
- $id = jBlog_updertEntry($entry);
+ $id = jBlog_updateEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id));
}
@@ -230,13 +241,24 @@
function metaWeblog_setPostCategories($message)
{
+ global $jBlog;
+ $val = $message->params[0];
+ $postid = $val->getval();
$val = $message->params[1];
$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(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
+ jBlog_updateEntryCategories($postid, $category_ids);
return new XML_RPC_Response( new XML_RPC_Value(1, 'boolean'));
}
Index: jBlog_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/jBlog/jBlog_functions.inc.php,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- jBlog_functions.inc.php 11 Mar 2003 19:23:21 -0000 1.56
+++ jBlog_functions.inc.php 13 Mar 2003 03:35:59 -0000 1.57
@@ -189,7 +189,7 @@
$limit = "LIMIT $limit";
}
- $query = "SELECT * FROM {$jBlog['dbPrefix']}entries e, {$jBlog['dbPrefix']}authors a WHERE e.authorid = a.authorid " . $and .
+ $query = "SELECT * FROM {$jBlog['dbPrefix']}entries e, {$jBlog['dbPrefix']}authors a left join {$jBlog['dbPrefix']}category c ON e.categoryid = c.categoryid WHERE e.authorid = a.authorid " . $and .
"ORDER BY timestamp DESC $limit";
$ret = jBlog_db_query($query);
if (!$ret) {
@@ -214,6 +214,22 @@
}
/**
+* Fetches a users categories
+**/
+function jBlog_fetchCategories($authorid) {
+ global $jBlog;
+ $querystring = "SELECT * FROM ".$jBlog['dbPrefix']."category
+ WHERE authorid = $authorid";
+ $query = mysql_db_query($jBlog["dbName"], $querystring);
+ $retval = array();
+ while( $row = mysql_fetch_assoc($query)) {
+ $retval[] = $row;
+ }
+ return $retval;
+}
+
+
+/**
* Give it a raw searchstring, it'll search
**/
function jBlog_searchEntries($term) {
@@ -279,7 +295,8 @@
. $entry['id']
. ".html\">Posted by "
. htmlentities($entry['username'])
- . " at "
+ . ($entry['category_name']?(" in ${entry['category_name']}"):"")
+ ." at "
. date("H:i", $entry['timestamp'])
. "</a>";
@@ -849,7 +866,35 @@
jBlog_purgeEntry($entry['id'], $entry['timestamp']);
- return !$query ? mysql_error() : true;
+ return mysql_error()?mysql_error():$entry['id'];
+}
+
+function jBlog_updateEntry($entry) {
+ global $jBlog;
+
+ $newEntry = 0;
+ $exflag = 0;
+
+ if (!is_numeric($entry["id"])) {
+ return;
+ }
+ if(strlen($entry["extended"])) {
+ $exflag = 1;
+ }
+ $querystring = "UPDATE ".$jBlog["dbPrefix"]."entries
+ SET title = '".mysql_escape_string($entry["title"])."',
+ body = '".mysql_escape_string($entry["body"])."',
+ extended = '".mysql_escape_string($entry["extended"])."',
+ exflag = '$exflag' WHERE id = ".$entry["id"];
+ $query = mysql_db_query($jBlog["dbName"], $querystring);
+ if($exflag) {
+ jBlog_handle_references($entry['id'], $jBlog['blogTitle'], $entry['title'], $entry['extended'], $newEntry);
+ }
+ else {
+ jBlog_handle_references($entry['id'], $jBlog['blogTitle'], $entry['title'], $entry['body'], $newEntry);
+ }
+ jBlog_purgeEntry($entry['id'], $entry['timestamp']);
+ return mysql_error()?mysql_error():$entry['id'];
}
/**
@@ -1385,12 +1430,13 @@
mysql_db_query($jBlog['dbName'], $gc);
}
-function jBlog_displayTopReferrers() {
+function jBlog_displayTopReferrers($limit=10) {
global $jBlog;
$query = "SELECT url, sum(count) total
FROM $jBlog[dbPrefix]referrers
GROUP BY url
- ORDER BY total desc";
+ ORDER BY total desc
+ LIMIT $limit";
$cursor = mysql_db_query($jBlog['dbName'], $query);
if($num_rows = mysql_num_rows($cursor)) {
while($row = mysql_fetch_assoc($cursor)) {
@@ -1470,6 +1516,22 @@
}
$init = true;
}
+
+function jBlog_updateEntryCategories($postid, $categories) {
+ global $jBlog;
+ if(!$postid || !$categories) {
+ return;
+ }
+ $query = "UPDATE $jBlog[dbPrefix]entries set categoryid = $categories[0] where id = $postid";
+ mysql_db_query($jBlog['dbName'], $query);
+ $fp = fopen("/tmp/a", "w");
+ fwrite($fp,$query);
+ if(mysql_error()) {
+ fwrite($fp, mysql_error());
+ }
+ fclose($fp);
+}
+
define("JBLOG_FUNCTIONS_LOADED", true);
?>
Index: db.sql
===================================================================
RCS file: /cvsroot/php-blog/jBlog/db.sql,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- db.sql 11 Mar 2003 19:26:39 -0000 1.16
+++ db.sql 13 Mar 2003 03:35:59 -0000 1.17
@@ -45,6 +45,7 @@
exflag int(1) default null,
author varchar(20) default null,
authorid int(11) default null,
+ categoryid int(11) default null,
primary key (id),
fulltext key title (title,body,extended)
) type=myisam;
@@ -101,3 +102,11 @@
sort_order int(4) not null,
PRIMARY KEY(name)
);
+
+CREATE TABLE {PREFIX}category (
+ categoryid int(11) NOT NULL auto_increment,
+ category_name varchar(255) default NULL,
+ category_description text,
+ authorid int(11) default NULL,
+ PRIMARY KEY (categoryid)
+) TYPE=MyISAM;
|