Ok, i've just read part of the documentation on s9y.org regarding the plugin API - nice concept btw

- and made a simple extension on the mycalendar: Autopruning of old entries.
All this code does is delete old events from the database after 3 days.
Why 3 days ? Apparently the sidebar never showed events older than 3 days. I didn't notice that when I started coding though

Perhaps that time interval should be made into a preference itself, or maybe even make mycalendar understand multi-day events...
Feedback is welcome.
diff -uN:
Code: Select all
--- serendipity_plugin_mycalendar.php.old 2005-08-03 20:51:27.000000000 +0200
+++ serendipity_plugin_mycalendar.php 2005-08-03 21:15:16.000000000 +0200
@@ -12,6 +12,8 @@
@define('PLUGIN_MYCALENDAR_SIDE_DESC', 'Zeigt einen eigenen Kalendar mit den nächsten X Terminen');
@define('PLUGIN_MYCALENDAR_SIDE_ITEMS', 'Einträge');
@define('PLUGIN_MYCALENDAR_SIDE_ITEMS_DESC', 'Wieviele Einträge sollen gezeigt werden?');
+ @define('PLUGIN_MYCALENDAR_SIDE_PRUNE', 'Automatisch bereinigen');
+ @define('PLUGIN_MYCALENDAR_SIDE_PRUNE_DESC', 'Sollen Einträge 3 Tage nach dem Termin automatisch gelöscht werden?');
break;
case 'en':
@@ -20,7 +22,8 @@
@define('PLUGIN_MYCALENDAR_SIDE_DESC', 'Shows your personal calendar with X upcoming scheduled events');
@define('PLUGIN_MYCALENDAR_SIDE_ITEMS', 'Amount of items');
@define('PLUGIN_MYCALENDAR_SIDE_ITEMS_DESC', 'How many items to show?');
-
+ @define('PLUGIN_MYCALENDAR_SIDE_PRUNE', 'Pruning');
+ @define('PLUGIN_MYCALENDAR_SIDE_PRUNE_DESC', 'Delete events 3 days after they took place?');
break;
}
@@ -37,7 +40,7 @@
'smarty' => '2.6.7',
'php' => '4.1.0'
));
- $propbag->add('configuration', array('title', 'items', 'datefm'));
+ $propbag->add('configuration', array('title', 'items', 'datefm', 'autoprune'));
// Register (multiple) dependencies. KEY is the name of the depending plugin. VALUE is a mode of either 'remove' or 'keep'.
// If the mode 'remove' is set, removing the plugin results in a removal of the depending plugin. 'Keep' meens to
@@ -69,6 +72,13 @@
$propbag->add('default', '%d.%m');
break;
+ case 'autoprune':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_MYCALENDAR_SIDE_PRUNE);
+ $propbag->add('description', PLUGIN_MYCALENDAR_SIDE_PRUNE_DESC);
+ $propbag->add('default', false);
+ break;
+
default:
return false;
}
@@ -78,9 +88,16 @@
function generate_content(&$title) {
global $serendipity;
$title = $this->get_config('title', $title);
+ $autoprune = $this->get_config('autoprune', false);
$ts = time();
- $items = serendipity_db_query("SELECT * from {$serendipity['dbPrefix']}mycalendar WHERE eventdate > " . ($ts - 60*60*24*3) . " ORDER BY eventdate LIMIT " . $this->get_config('items', 5));
+ if ($autoprune) {
+ $filter = "";
+ } else {
+ $filter = "WHERE eventdate > ". ($ts - 60*60*24*3);
+ }
+
+ $items = serendipity_db_query("SELECT * from {$serendipity['dbPrefix']}mycalendar " . $filter . " ORDER BY eventdate LIMIT " . $this->get_config('items', 5));
if (!is_array($items)) {
return true;
}
@@ -101,10 +118,15 @@
}
$days = ceil(($item['eventdate'] - $ts) / 86400);
- echo serendipity_strftime($this->get_config('datefm'), $item['eventdate'], false) .
- ' - ' . $cont .
- ($days > 0 ? ' (' . $days . ' ' . DAYS . ')' : '') .
- '<br />';
+ if ($days > -3) {
+ echo serendipity_strftime($this->get_config('datefm'), $item['eventdate'], false) .
+ ' - ' . $cont .
+ ($days > 0 ? ' (' . $days . ' ' . DAYS . ')' : '') .
+ '<br />';
+ } elseif ($autoprune) {
+ serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}mycalendar WHERE eventdate < ". ($ts - 60*60*24*3));
+ $autoprune = false;
+ }
}
return true;
}