Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1:/tmp/cvs-serv31398
Modified Files:
.cvsignore rss.php serendipity_admin_installer.inc.php
serendipity_functions.inc.php serendipity_lang_de.inc.php
serendipity_lang_en.inc.php serendipity_sidebar_items.php
Log Message:
o Added the 'plugins' directory to CVS to provide some bundled external plugins for examples
o Removed creating the plugins directory in the installer, removed plugins from .cvsignore
o Fixed the RSS feed for comments to be feeded. Implemented them into the RSS/XML sidebar item plugin.
o Fixed some more language issues, outsourced strings to constants.
o UTF8encode description and title in the RSS feeds
o Implemented 'category' tag for RSS2.0 feed
o Optimized RSS-feed SQL queries to be only used if no email was already provided from an earlier query
o Added a 'content rewrite' external plugin. Allows any strings to be rewritten to customized strings. See my other posts about this for details.
o Force inline display of emoticons (XHTML)
Happy testing. :) I checked all changes now for a week in my personal
blog (www.supergarv.de/serendipity/) with the new plugin, and without
problems
.
Index: .cvsignore
===================================================================
RCS file: /cvsroot/php-blog/serendipity/.cvsignore,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- .cvsignore 29 Mar 2003 15:39:03 -0000 1.2
+++ .cvsignore 2 Aug 2003 15:14:19 -0000 1.3
@@ -2,5 +2,4 @@
serendipity_config_local.inc.php
.htaccess
uploads
-archives
-plugins
+archives
\ No newline at end of file
Index: rss.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/rss.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rss.php 8 Jul 2003 09:13:27 -0000 1.7
+++ rss.php 2 Aug 2003 15:14:19 -0000 1.8
@@ -9,11 +9,13 @@
$description = $serendipity['blogDescription'];
$title = $serendipity['blogTitle'];
-switch ($type) {
+$comments = FALSE;
+switch ($_GET['type']) {
case 'comments':
- $entries = serendipity_fetchComments(null, true, 15);
- $title = $title . ' Comments';
- $description = 'Comments from ' . $description;
+ $entries = serendipity_fetchComments(null, 15);
+ $title = $title . ' ' . COMMENTS;
+ $description = COMMENTS_FROM . ' ' . $description;
+ $comments = TRUE;
break;
case 'content':
default:
@@ -25,6 +27,9 @@
break;
}
+$title = utf8_encode($title);
+$description = utf8_encode($description);
+
echo '<?xml version="1.0" encoding="utf-8" ?>';
echo "\n";
switch ($version) {
@@ -49,9 +54,9 @@
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:robot="http://www.edwardbear.org/def/xml/robot">
<channel>
-<title>{$serendipity['blogTitle']}</title>
+<title>$title</title>
<link>{$serendipity['baseURL']}</link>
-<description>{$serendipity['blogDescription']}</description>
+<description>$description</description>
<dc:language>{$serendipity['lang']}</dc:language>
HEAD;
@@ -60,7 +65,7 @@
die("Invalid RSS version specified\n");
}
-serendipity_printEntries_rss($entries, $version);
+serendipity_printEntries_rss($entries, $version, $comments);
switch ($version) {
case '0.91':
Index: serendipity_admin_installer.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_installer.inc.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- serendipity_admin_installer.inc.php 23 Jul 2003 21:12:38 -0000 1.22
+++ serendipity_admin_installer.inc.php 2 Aug 2003 15:14:19 -0000 1.23
@@ -184,12 +184,7 @@
$errs[] = " -> and <i>chmod g+rwx ".$_POST["serendipityPath"]."archives</i>";
}
- // Attempt to create the plugins dir
- if ( !is_dir($_POST['serendipityPath'] . "plugins") && @mkdir($_POST['serendipityPath'] . "plugins", 0770) !== true ) {
- $errs[] = "Couldn't create the plugins directory, you do it:";
- $errs[] = " -> Run <i>mkdir ".$_POST["serendipityPath"]."plugins</i>";
- $errs[] = " -> and <i>chmod g+rwx ".$_POST["serendipityPath"]."plugins</i>";
- }
+ // plugins directory now part of basic CVS
// Check imagick
if ($_POST["magick"] == "true" && !is_executable($_POST["convert"])) {
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -d -r1.109 -r1.110
--- serendipity_functions.inc.php 26 Jul 2003 09:04:58 -0000 1.109
+++ serendipity_functions.inc.php 2 Aug 2003 15:14:19 -0000 1.110
@@ -365,6 +365,7 @@
$query = "SELECT
e.*,
a.username,
+ a.email,
c.category_name
FROM
({$serendipity['dbPrefix']}entries AS e
@@ -592,16 +593,42 @@
{
global $serendipity;
- $query = "SELECT * FROM {$serendipity['dbPrefix']}comments WHERE entry_id=$id AND type LIKE 'NORMAL' ORDER BY id";
- if (isset($limit)) {
- $query .= " LIMIT $limit";
+ if (!empty($limit)) {
+ if ( strtolower($serendipity['dbType']) == 'postgres' ) {
+ $limit = 'LIMIT ' . join (' OFFSET ', split(',', $limit));
+ } else {
+ $limit = 'LIMIT '. $limit;
+ }
+ } else {
+ $limit = '';
+ }
+
+ if (!empty($id)) {
+ $and = 'AND co.entry_id=' . $id;
}
+ $query = "SELECT
+ co.*,
+ co.author AS username,
+ e.title,
+ c.category_name
+ FROM
+ ({$serendipity['dbPrefix']}comments co
+ LEFT JOIN {$serendipity['dbPrefix']}entries e
+ ON co.entry_id = e.id
+ LEFT JOIN {$serendipity['dbPrefix']}category c
+ ON e.categoryid = c.categoryid)
+ WHERE co.type LIKE 'NORMAL' $and
+ ORDER BY
+ co.id DESC
+ $limit";
+
$comments = serendipity_db_query($query);
+
if (!is_array($comments)) {
return array();
}
-
+
return $comments;
}
@@ -825,23 +852,31 @@
}
-function serendipity_printEntries_rss($entries, $version) {
+function serendipity_printEntries_rss($entries, $version, $comments = false) {
global $serendipity;
if ($version == '0.91' || $version == '2.0' && is_array($entries)) {
foreach ($entries as $entry) {
$guid = serendipity_archiveURL($entry['id'], $entry['title']);
+ if ($comments == true) {
+ // Display username as part of the title for easier feed-readability
+ $entry['title'] = $entry['username'] . ': ' . $entry['title'];
+ }
?>
<item>
- <title><?php echo htmlentities($entry['title']); ?></title>
+ <title><?php echo utf8_encode(htmlspecialchars($entry['title'])); ?></title>
<link><?php echo $guid; ?></link>
+ <category><?php echo utf8_encode(htmlspecialchars($entry['category_name'])); ?></category>
<?php
if ($version == '2.0') {
// extract author information
- $query = "select email from {$serendipity['dbPrefix']}authors where username='{$entry['username']}'";
- $results = serendipity_db_query($query);
+ if (empty($entry['email'])) {
+ $query = "select email from {$serendipity['dbPrefix']}authors where username='{$entry['username']}'";
+ $results = serendipity_db_query($query);
+ $entry['email'] = $results[0]['email'];
+ }
?>
- <author><?php echo htmlentities($results[0]['email']) . ' (' . htmlentities($entry['username']) . ')'; ?></author>
+ <author><?php echo htmlentities($entry['email']) . ' (' . htmlentities($entry['username']) . ')'; ?></author>
<content:encoded>
<?php echo utf8_encode(htmlspecialchars(serendipity_emoticate(serendipity_markup_text($entry['body'])))); ?>
</content:encoded>
@@ -870,6 +905,102 @@
return('<tt>' . str_replace(' ', ' ', $arg[1]) . '</tt>');
}
+function serendipity_content_rewrite($str) {
+ global $serendipity;
+
+ // Do this only once!
+ if (!class_exists('serendipity_plugin_api')) {
+ include_once('serendipity_plugin_api.php');
+ }
+
+ // If this variable is not set, this function is called for the first time.
+ // Now let's search for plugins needing content rewriting
+ if (!isset($serendipity['content_rewrite']['active'])) {
+
+ // We set this to false, so when this function is called later, it won't have to enumerate all plugins again
+ $serendipity['content_rewrite']['active'] = false;
+
+ // Get those nifty plugins
+ $plugins = serendipity_plugin_api::enum_plugins();
+
+ if (is_array($plugins)) {
+
+ // store the rewrite items in our main container for later usage.
+ $serendipity['content_rewrite']['data']['rewrite_from'] = array();
+ $serendipity['content_rewrite']['data']['rewrite_to'] = array();
+
+ // load each plugin to make some introspection
+ foreach ($plugins as $plugin_data) {
+ $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name']);
+ $bag = new serendipity_property_bag;
+ $plugin->introspect($bag);
+
+ if ($bag->get('rewrite_active') === true) {
+
+ // Store necessary data in our main container
+ $serendipity['content_rewrite']['string'] = $plugin->get_config('rewrite_string');
+
+ if ($serendipity['content_rewrite']['string'] != '') {
+ $rewrite_from = $bag->get('rewrite_from');
+ $serendipity['content_rewrite']['data']['rewrite_char'][$serendipity['content_rewrite']['string']] = &$plugin->get_config('rewrite_char');
+
+ foreach($rewrite_from AS $nr => $key) {
+ $serendipity['content_rewrite']['data']['rewrite_from'][$serendipity['content_rewrite']['string']][] = $plugin->get_config($key);
+ }
+
+ $rewrite_to = $bag->get('rewrite_to');
+ foreach($rewrite_to AS $nr => $key) {
+ $serendipity['content_rewrite']['data']['rewrite_to'][$serendipity['content_rewrite']['string']][] = $plugin->get_config($key);
+ }
+
+ // We now have at least one active plugin.
+ $serendipity['content_rewrite']['active'] = true;
+ }
+ }
+ }
+ }
+ }
+
+ // Check if we have any plugin data needing rewrite
+ if (is_array($serendipity['content_rewrite']['data']['rewrite_from'])) {
+ foreach($serendipity['content_rewrite']['data']['rewrite_from'] AS $rewrite_string => $rewrite_values) {
+ foreach($rewrite_values AS $key => $val) {
+ if (trim($val) != '') {
+
+ // Use the supplied rewrite string and replace the {from} and {to} values with the ones we got from the plugin
+ $new =
+ str_replace(
+ array(
+ '{from}',
+ '{to}'
+ ),
+
+ array(
+ str_replace(
+ $serendipity['content_rewrite']['data']['rewrite_char'][$rewrite_string],
+ '',
+ $val
+ ),
+
+ $serendipity['content_rewrite']['data']['rewrite_to'][$rewrite_string][$key]
+ ),
+
+ $rewrite_string
+ );
+
+ // Build a regular expression (ungreedy, multiline) with our quoted value. $val here is the word needing the replacement
+ $regex = '°([^\d\w])(' . preg_quote($val) . ')([^\d\w])°msU';
+
+ // \1 and \3 are the prepend/append strings (usually whitespaces) and $new containing the new value
+ $str = preg_replace($regex, '\1' . $new . '\3', $str);
+ }
+ }
+ }
+ }
+
+ return $str;
+}
+
function serendipity_markup_text($str, $entry_id = 0) {
global $serendipity;
@@ -913,6 +1044,9 @@
);
}
+ // Do some content rewrite, if necessary
+ $ret = serendipity_content_rewrite($ret);
+
return $ret;
}
@@ -943,7 +1077,7 @@
global $serendipity;
foreach ($serendipity['smiles'] as $key => $value) {
- $str = preg_replace("/([\t\ ]?)" . preg_quote($key, '/') . "([\t\ \!\.\)]?)/m", "$1<img src=\"$value\" alt=\"$key\" />$2", $str);
+ $str = preg_replace("/([\t\ ]?)" . preg_quote($key, '/') . "([\t\ \!\.\)]?)/m", "$1<img src=\"$value\" alt=\"$key\" style=\"display: inline; vertical-align: bottom;\" />$2", $str);
}
return $str;
Index: serendipity_lang_de.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_lang_de.inc.php,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- serendipity_lang_de.inc.php 16 Jul 2003 11:58:24 -0000 1.16
+++ serendipity_lang_de.inc.php 2 Aug 2003 15:14:19 -0000 1.17
@@ -181,6 +181,7 @@
define('HIDDEN', 'versteckt');
define('REMOVE_TICKED_PLUGINS', 'Markierte plugins entfernen');
define('SAVE_CHANGES_TO_LAYOUT', 'Änderungen am Layout speichern');
+define('COMMENTS_FROM', 'Kommentare von');
define('serendipity_LANG_LOADED', true);
/* vim: set sts=4 ts=4 expandtab : */
Index: serendipity_lang_en.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_lang_en.inc.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- serendipity_lang_en.inc.php 18 Jul 2003 17:51:15 -0000 1.22
+++ serendipity_lang_en.inc.php 2 Aug 2003 15:14:19 -0000 1.23
@@ -181,6 +181,7 @@
define('HIDDEN', 'hidden');
define('REMOVE_TICKED_PLUGINS', 'Remove ticked plugins');
define('SAVE_CHANGES_TO_LAYOUT', 'Save changes to layout');
+define('COMMENTS_FROM', 'Comments from');
define('serendipity_LANG_LOADED', true);
/* vim: set sts=4 ts=4 expandtab : */
Index: serendipity_sidebar_items.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_sidebar_items.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- serendipity_sidebar_items.php 16 Jul 2003 12:08:22 -0000 1.22
+++ serendipity_sidebar_items.php 2 Aug 2003 15:14:19 -0000 1.23
@@ -145,6 +145,9 @@
<br />
<a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0"><img src="<?php echo $serendipity['serendipityHTTPPath']; ?>xml.gif" border="0" alt="XML" /></a>
<a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0">RSS 2.0 feed</a>
+ <br />
+ <a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0&type=comments"><img src="<?php echo $serendipity['serendipityHTTPPath']; ?>xml.gif" border="0" alt="XML" /></a>
+ <a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0&type=comments">RSS 2.0 <?php echo COMMENTS; ?></a>
<?php
}
}
|