Update of /cvsroot/php-blog/serendipity/plugins/serendipity_plugin_recententries
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20345/plugins/serendipity_plugin_recententries
Modified Files:
Tag: branch-smarty
serendipity_plugin_recententries.php
Log Message:
* "Recent Entries" Plugin can now have userdefined title and only
show entries of a specific category (+ subcategories).
Index: serendipity_plugin_recententries.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_plugin_recententries/serendipity_plugin_recententries.php,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -u -d -r1.9.2.1 -r1.9.2.2
--- serendipity_plugin_recententries.php 29 Oct 2004 11:02:41 -0000 1.9.2.1
+++ serendipity_plugin_recententries.php 4 Nov 2004 12:54:48 -0000 1.9.2.2
@@ -28,12 +28,19 @@
$propbag->add('description', PLUGIN_RECENTENTRIES_BLAHBLAH);
$propbag->add('stackable', true);
$propbag->add('author', 'Christian Machmeier');
- $propbag->add('version', '1.0');
- $propbag->add('configuration', array('number', 'dateformat'));
+ $propbag->add('version', '1.1');
+ $propbag->add('configuration', array('title', 'number', 'dateformat', 'category'));
}
function introspect_config_item($name, &$propbag) {
switch($name) {
+ case 'title':
+ $propbag->add('type', 'string');
+ $propbag->add('name', TITLE);
+ $propbag->add('description', TITLE_FOR_NUGGET);
+ $propbag->add('default', PLUGIN_RECENTENTRIES_TITLE);
+ break;
+
case 'number':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_RECENTENTRIES_NUMBER);
@@ -48,6 +55,35 @@
$propbag->add('default', '%A, %B %e %Y');
break;
+ case 'category':
+ $cats = serendipity_fetchCategories($serendipity['authorid']);
+ if (!is_array($cats)) {
+ return false;
+ }
+
+ $catlist = serendipity_generateCategoryList($cats, array(0), 4);
+ $tmp_select_cats = explode('@@@', $catlist);
+
+ if (!is_array($tmp_select_cats)) {
+ return false;
+ }
+
+ $select_cats = array();
+ $select_cats['none'] = ALL_CATEGORIES;
+ foreach($tmp_select_cats as $cidx => $tmp_select_cat) {
+ $select_cat = explode('|||', $tmp_select_cat);
+ if (!empty($select_cat[0]) && !empty($select_cat[1])) {
+ $select_cats[$select_cat[0]] = $select_cat[1];
+ }
+ }
+
+ $propbag->add('type', 'select');
+ $propbag->add('select_values', $select_cats);
+ $propbag->add('name', CATEGORY);
+ $propbag->add('description', CATEGORIES_TO_FETCH);
+ $propbag->add('default', 'none');
+ break;
+
default:
return false;
}
@@ -59,6 +95,16 @@
$number = $this->get_config('number');
$dateformat = $this->get_config('dateformat');
+ $category = $this->get_config('category', 'none');
+ $title = $this->get_config('title', $title);
+
+ $sql_join = '';
+ $sql_where = '';
+ if ($category != 'none' && is_numeric($category)) {
+ $sql_join = 'LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'entrycat AS ec ON id = ec.entryid
+ LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'category AS c ON ec.categoryid = c.categoryid';
+ $sql_where = ' AND (c.category_left BETWEEN ' . implode(' AND ', serendipity_fetchCategoryRange($category)) . ')';
+ }
if (!$number || !is_numeric($number) || $number < 1) {
$number = 10;
@@ -68,15 +114,16 @@
$dateformat = '%A, %B %e %Y';
}
- $title = PLUGIN_RECENTENTRIES_TITLE;
-
- $entries = serendipity_db_query("SELECT id,
+ $entries_query = "SELECT id,
title,
timestamp
FROM {$serendipity['dbPrefix']}entries
- WHERE isdraft = 'false'
+ $sql_join
+ WHERE isdraft = 'false' AND timestamp <= " . time() . "
+ $sql_where
ORDER BY timestamp DESC
- LIMIT $number");
+ LIMIT $number";
+ $entries = serendipity_db_query($entries_query);
if (isset($entries) && is_array($entries)) {
foreach ($entries as $k => $entry) {
|