Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1:/tmp/cvs-serv16857
Modified Files:
serendipity_plugin_api.php serendipity_sidebar_items.php
serendipity_admin_plugins.inc.php
Log Message:
Commited patch as proposed on the mailinglist
(Part 5/5)
Index: serendipity_plugin_api.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_plugin_api.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- serendipity_plugin_api.php 16 Jul 2003 12:05:40 -0000 1.6
+++ serendipity_plugin_api.php 18 Sep 2003 12:58:52 -0000 1.7
@@ -36,7 +36,7 @@
}
}
}
-
+
/* Create an instance of a plugin.
* $plugin_class_id is of the form:
* @class_name for a built-in plugin
@@ -52,38 +52,38 @@
function create_plugin_instance($plugin_class_id, $copy_from_instance = null)
{
global $serendipity;
-
+
$id = md5(uniqid(''));
-
+
$key = $plugin_class_id . ':' . $id;
-
+
$rs = serendipity_db_query("SELECT MAX(sort_order) as sort_order_max FROM {$serendipity['dbPrefix']}plugins", true, 'num');
-
+
if (is_array($rs)) {
$nextidx = intval($rs[0]+1);
} else {
$nextidx = 0;
}
-
+
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}plugins (name, sort_order) values ('$key', $nextidx)");
-
+
return $key;
}
-
+
function remove_plugin_instance($plugin_instance_id)
{
global $serendipity;
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}plugins where name='$plugin_instance_id'");
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}config where name LIKE '$plugin_instance_id/%'");
}
-
+
/* Retrieves a list of available plugins */
function enum_plugin_classes()
{
global $serendipity;
-
+
$classes = array();
-
+
/* built-in classes first */
$cls = get_declared_classes();
foreach ($cls as $class_name) {
@@ -102,7 +102,7 @@
}
/* third-party classes next */
- $d = opendir($serendipity['serendipityPath'] . 'plugins');
+ $d = opendir((isset($serendipity['serendipityPath']) ? $serendipity['serendipityPath'] : '') . 'plugins');
while (($f = readdir($d)) !== false) {
if ($f{0} == '.' || $f == 'CVS') {
continue;
@@ -112,7 +112,7 @@
}
return $classes;
}
-
+
/* Retrieves a list of plugin instances */
function enum_plugins($filter = '*')
{
@@ -125,25 +125,25 @@
}
$sql .= ' ORDER BY placement, sort_order';
-
+
return serendipity_db_query($sql);
}
-
+
/* Creates an instance of a named plugin */
function &load_plugin($instance_id)
{
global $serendipity;
-
+
list($name, $uniq) = explode(':', $instance_id);
-
+
if ($name{0} == '@') {
$class_name = substr($name, 1);
} else {
/* plugin from the plugins/ dir */
if (!class_exists($name)) {
-
+
include $serendipity['serendipityPath'] . 'plugins/' . $name . '/' . $name . '.php';
-
+
if (!class_exists($name)) {
return false;
}
@@ -151,12 +151,12 @@
$class_name = $name;
}
-
+
$p =& new $class_name($instance_id);
-
+
return $p;
}
-
+
function update_plugin_placement($name, $placement, $order=null)
{
global $serendipity;
@@ -166,12 +166,12 @@
if ($order !== null) {
$sql .= ", sort_order=$order ";
}
-
+
$sql .= "WHERE name='$name'";
return serendipity_db_query($sql);
}
-
+
function generate_plugins($side, $tagname = 'div')
{
$plugins = serendipity_plugin_api::enum_plugins($side);
@@ -179,7 +179,7 @@
if (!is_array($plugins)) {
return;
}
-
+
echo "<$tagname id=\"serendipity" . ucfirst($side) . "SideBar\">\n";
foreach ($plugins as $plugin_data) {
$plugin =& serendipity_plugin_api::load_plugin($plugin_data['name']);
@@ -215,7 +215,7 @@
'value' => $value
);
}
-
+
function get($name)
{
$v = array();
@@ -228,10 +228,10 @@
if (count($v) == 1) {
return $v[0];
}
-
+
return implode(', ', $v);
}
-
+
function is_set($name)
{
foreach ($this->properties as $data) {
@@ -258,7 +258,7 @@
{
$this->instance = $instance;
}
-
+
/* Called by serendipity when it wants to display information
* about your plugin.
* You need to override this method in your child class.
@@ -267,7 +267,7 @@
{
$propbag->add('copyright', 'MIT License');
$propbag->add('name' , get_class($this));
-
+
// $propbag->add(
// 'configuration',
// array(
@@ -277,7 +277,7 @@
// );
return true;
}
-
+
/* Called by serendipity when it wants to display the configuration
* editor for your plugin.
* $name is the name of a configuration item you added in
@@ -292,7 +292,7 @@
{
return false;
}
-
+
/* Called by serendipity when it wants your plugin to display itself.
* You need to set $title to be whatever text you want want to
* appear in the item caption space.
@@ -305,7 +305,7 @@
$title = 'Sample!';
echo 'This is a sample!';
}
-
+
/* Fetches a configuration value for this plugin */
function get_config($name, $defaultvalue = null)
{
@@ -313,7 +313,7 @@
return serendipity_get_config_var($name, $defaultvalue);
}
-
+
function set_config($name, $value)
{
$name = $this->instance . '/' . $name;
Index: serendipity_sidebar_items.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_sidebar_items.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- serendipity_sidebar_items.php 11 Sep 2003 08:32:19 -0000 1.28
+++ serendipity_sidebar_items.php 18 Sep 2003 12:58:52 -0000 1.29
@@ -6,15 +6,15 @@
$propbag->add('name', CALENDAR);
$propbag->add('description', QUICKJUMP_CALENDAR);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = QUICKJUMP;
- if (!$serendipity['GET']['calendarZoom']) {
- if (!$serendipity['GET']['range']) {
+ if (!isset($serendipity['GET']['calendarZoom'])) {
+ if (!isset($serendipity['GET']['range'])) {
$serendipity['GET']['calendarZoom'] = date('Y') . date('m');
} else {
$serendipity['GET']['calendarZoom'] = $serendipity['GET']['range'];
@@ -23,12 +23,12 @@
serendipity_drawCalendar(
substr(
- $serendipity['GET']['calendarZoom'],
+ (isset($serendipity['GET']['calendarZoom']) ? $serendipity['GET']['calendarZoom'] : ''),
4,
2
),
substr(
- $serendipity['GET']['calendarZoom'],
+ (isset($serendipity['GET']['calendarZoom']) ? $serendipity['GET']['calendarZoom'] : ''),
0,
4
)
@@ -42,11 +42,11 @@
$propbag->add('name', QUICKSEARCH);
$propbag->add('description', SEARCH_FOR_ENTRY);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = QUICKSEARCH;
?>
<form action="<?php echo $serendipity['serendipityHTTPPath']; ?>search.php" method="get">
@@ -65,11 +65,11 @@
$propbag->add('name', ARCHIVES);
$propbag->add('description', BROWSE_ARCHIVES);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = ARCHIVES;
$ts = mktime(0, 0, 0, (date('m')+1), 1, date('Y'));
@@ -82,9 +82,9 @@
} else {
$link = 'fixme';
}
-
+
$ts_title = $serendipity['months'][date('n', $ts)] . ' ' . date('Y', $ts);
-
+
echo '<a href="' . $link . '" title="' . $ts_title . '">' . $ts_title . '</a><br />' . "\n";
$ts = mktime(0, 0, 0, date('m', $ts), 1, date('Y', $ts));
@@ -101,11 +101,11 @@
$propbag->add('name', TOP_REFERRER);
$propbag->add('description', SHOWS_TOP_SITES);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = TOP_REFERRER;
echo serendipity_displayTopReferrers();
}
@@ -117,11 +117,11 @@
$propbag->add('name', TOP_EXITS);
$propbag->add('description', SHOWS_TOP_EXIT);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = TOP_EXITS;
echo serendipity_displayTopExits();
}
@@ -147,7 +147,7 @@
)
);
}
-
+
function introspect_config_item($name, &$propbag)
{
switch($name) {
@@ -168,7 +168,7 @@
$propbag->add('name', SYNDICATION_PLUGIN_20c);
$propbag->add('description', '');
break;
-
+
case 'seperator':
$propbag->add('type', 'seperator');
break;
@@ -218,7 +218,7 @@
function generate_content(&$title)
{
global $serendipity;
-
+
$title = SYNDICATE_THIS_BLOG;
if ($this->get_config('show_0.91') != 'false') {
@@ -228,7 +228,7 @@
<br />
<?php
}
-
+
if ($this->get_config('show_2.0') != 'false') {
?>
<a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0"><img src="<?php echo $serendipity['serendipityHTTPPath']; ?>xml.gif" border="0" alt="XML" /></a>
@@ -236,11 +236,11 @@
<br />
<?php
}
-
+
if ($this->get_config('show_2.0c') != 'false') {
?>
<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>
+ <a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0&type=comments"><nobr>RSS 2.0 <?php echo COMMENTS; ?></nobr></a>
<?php
}
}
@@ -252,11 +252,11 @@
$propbag->add('name', SUPERUSER);
$propbag->add('description', ALLOWS_YOU_BLAHBLAH);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = SUPERUSER . ':';
echo "<a href=\"{$serendipity['serendipityHTTPPath']}entries\" title=\"$title\">\$ su -</a>";
}
@@ -268,11 +268,11 @@
$propbag->add('name', POWERED_BY);
$propbag->add('description', ADVERTISES_BLAHBLAH);
}
-
+
function generate_content(&$title)
{
global $serendipity;
-
+
$title = POWERED_BY . ":";
?>
<div class="serendipityPlug">
@@ -293,7 +293,7 @@
)
);
}
-
+
function introspect_config_item($name, &$propbag)
{
switch($name) {
@@ -302,7 +302,7 @@
$propbag->add('name', TITLE);
$propbag->add('description', TITLE_FOR_NUGGET);
break;
-
+
case 'content':
$propbag->add('type', 'html');
$propbag->add('name', CONTENT);
@@ -314,7 +314,7 @@
}
return true;
}
-
+
function generate_content(&$title)
{
$title = $this->get_config('title', $title);
@@ -324,30 +324,68 @@
class serendipity_categories_plugin extends serendipity_plugin {
function introspect(&$propbag) {
- $propbag->add('name', 'Categories');
- $propbag->add('description', 'Shows the list of categories.');
+ global $serendipity;
+
+ $propbag->add('name', CATEGORIES);
+ $propbag->add('description', CATEGORY_PLUGIN_DESC);
+ $propbag->add('configuration', array('authorid'));
+
+ $row_authors = serendipity_db_query("SELECT username, authorid FROM {$serendipity['dbPrefix']}authors");
+ $authors = array('all' => ALL_AUTHORS);
+ foreach($row_authors AS $rownr => $row) {
+ $authors[$row['authorid']] = $row['username'];
+ }
+
+ $this->select_values = $authors;
}
-
+
+ function introspect_config_item($name, &$propbag)
+ {
+ switch($name) {
+ case 'authorid':
+ $propbag->add('type', 'select');
+ $propbag->add('name', CATEGORIES_TO_FETCH);
+ $propbag->add('description', CATEGORIES_TO_FETCH_DESC);
+ break;
+
+ default:
+ return false;
+ }
+ return true;
+ }
+
function generate_content(&$title) {
global $serendipity;
- $categories = serendipity_fetchCategories(1);
+ $categories = serendipity_fetchCategories($this->get_config('authorid'));
+ $title = CATEGORIES;
$html = '';
- $title = 'Categories';
- foreach ($categories as $category) {
- $category_id = serendipity_makeFilename($category['category_name']);
+ if (is_array($categories)) {
+ foreach ($categories as $category) {
+ $category_id = serendipity_makeFilename($category['category_name']);
- $html .= sprintf(
- '<a href="%s"><img alt="xml" border="0" src="%s"</a> ' .
- '<a href="%s">%s</a><br />',
+ $html .= sprintf(
+ '<a href="%s" title="%s"><img style="display: inline;" alt="xml" border="0" src="%s" /></a> ' .
+ '<a href="%s" title="%s">%s</a><br />',
- $serendipity['serendipityHTTPPath'] . 'rss.php?category=' . $category_id,
- $serendipity['serendipityHTTPPath'] . 'xml.gif',
- $serendipity['serendipityHTTPPath'] . 'categories/' . $category_id . '.html',
- $category['category_name']
- );
+ $serendipity['serendipityHTTPPath'] . 'rss.php?category=' . $category['categoryid'] . '_' . $category_id,
+ htmlentities($category['category_description']),
+ $serendipity['serendipityHTTPPath'] . 'xml.gif',
+ $serendipity['serendipityHTTPPath'] . 'categories/' . $category['categoryid'] . '_' . $category_id,
+ htmlentities($category['category_description']),
+ $category['category_name']
+ );
+ }
}
+
+ $html .= sprintf(
+ '<br /><a href="%s" title="%s">%s</a>',
+
+ $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'],
+ ALL_CATEGORIES,
+ ALL_CATEGORIES
+ );
print $html;
}
Index: serendipity_admin_plugins.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_plugins.inc.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- serendipity_admin_plugins.inc.php 25 Aug 2003 16:43:27 -0000 1.10
+++ serendipity_admin_plugins.inc.php 18 Sep 2003 12:58:52 -0000 1.11
@@ -15,7 +15,7 @@
'right' => RIGHT,
'hide' => HIDDEN
);
-
+
$x = "\n<select name=\"$name\">\n";
foreach ($opts as $k => $v) {
$x .= " <option value=\"$k\"" . ($k == $val ? ' selected="selected"' : '') . ">$v</option>\n";
@@ -26,7 +26,7 @@
if (isset($_GET['serendipity']['plugin_to_move']) && isset($_GET['submit'])) {
$plugins = serendipity_plugin_api::enum_plugins();
- /* Renumber the sort order to be certain that one actually exists
+ /* Renumber the sort order to be certain that one actually exists
Also look for the one we're going to move */
$idx_to_move = -1;
for($idx = 0; $idx < count($plugins); $idx++) {
@@ -37,7 +37,7 @@
}
}
- /* If idx_to_move is still -1 then we never found it (shouldn't happen under normal conditions)
+ /* If idx_to_move is still -1 then we never found it (shouldn't happen under normal conditions)
Also make sure the swaping idx is around */
if ($idx_to_move >= 0 && (($_GET['submit'] == 'move down' && $idx_to_move < (count($plugins)-1)) || ($_GET['submit'] == 'move up' && $idx_to_move > 0))) {
@@ -45,29 +45,29 @@
$tmp = $plugins[$idx_to_move]['sort_order'];
$plugins[$idx_to_move]['sort_order'] = (int)$plugins[$idx_to_move + ($_GET['submit'] == 'move down' ? 1 : -1)]['sort_order'];
$plugins[$idx_to_move + ($_GET['submit'] == 'move down' ? 1 : -1)]['sort_order'] = (int)$tmp;
-
+
/* Update table */
foreach($plugins as $plugin) {
$key = serendipity_db_escape_string($plugin['name']);
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = {$plugin['sort_order']} WHERE name='$key'");
}
}
-
- /* TODO: Moving The first Right oriented plugin up,
- or the last left oriented plugin down
+
+ /* TODO: Moving The first Right oriented plugin up,
+ or the last left oriented plugin down
should not be displayed to the user as an option.
It's a behavior which really has no meaning. */
}
-
+
if (isset($_GET['serendipity']['plugin_to_conf'])) {
/* configure a specific instance */
$plugin =& serendipity_plugin_api::load_plugin($_GET['serendipity']['plugin_to_conf']);
-
+
$bag = new serendipity_property_bag;
$plugin->introspect($bag);
$name = htmlentities($bag->get('name'));
$desc = htmlentities($bag->get('description'));
-
+
$config_names = $bag->get('configuration');
if (isset($_POST['SAVECONF'])) {
@@ -99,13 +99,14 @@
foreach ($config_names as $config_item) {
$cbag = new serendipity_property_bag;
$plugin->introspect_config_item($config_item, $cbag);
-
- $cname = htmlentities($cbag->get('name'));
- $cdesc = htmlentities($cbag->get('description'));
- $value = $plugin->get_config($config_item);
- $hvalue = (isset($_POST['serendipity']['plugin'][$config_item]) ? htmlentities($_POST['serendipity']['plugin'][$config_item]) : htmlentities($value));
- $radio = array();
-
+
+ $cname = htmlentities($cbag->get('name'));
+ $cdesc = htmlentities($cbag->get('description'));
+ $value = $plugin->get_config($config_item);
+ $hvalue = (isset($_POST['serendipity']['plugin'][$config_item]) ? htmlentities($_POST['serendipity']['plugin'][$config_item]) : htmlentities($value));
+ $radio = array();
+ $select = array();
+
switch ($cbag->get('type')) {
case 'seperator':
?>
@@ -114,14 +115,46 @@
</tr>
<?php
break;
-
+
case 'boolean':
$radio['value'][] = 'true';
$radio['desc'][] = YES;
-
+
$radio['value'][] = 'false';
$radio['desc'][] = NO;
+ case 'select':
+ $select = $plugin->select_values;
+?>
+ <tr>
+ <td style="vertical-align: top"><?php echo $cname; ?></td>
+ <td style="vertical-align: top">
+ <div>
+ <select name="serendipity[plugin][<?php echo $config_item; ?>]">
+<?php
+ foreach($select AS $select_value => $select_desc) {
+ $id = htmlspecialchars($config_item . $select_value);
+?>
+ <option value="<?php echo $select_value; ?>" <?php echo ($select_value == $hvalue ? 'selected="selected"' : ''); ?> title="<?php echo htmlentities($select_desc); ?>" />
+ <?php echo htmlentities($select_desc); ?>
+ </option>
+<?php
+ }
+?>
+ </select>
+ </div>
+<?php
+ if ($cdesc != '') {
+?>
+ <br /><span style="color: #bbbbbb">// <?php echo $cdesc; ?></span>
+<?php
+ }
+?>
+ </td>
+ </tr>
+<?php
+ break;
+
case 'radio':
if (!count($radio) > 0) {
$radio = $cbag->get('radio');
@@ -156,7 +189,7 @@
<?php
}
}
-
+
if ($cdesc != '') {
?>
<br /><span style="color: #bbbbbb">// <?php echo $cdesc; ?></span>
@@ -167,7 +200,7 @@
</tr>
<?php
break;
-
+
case 'string':
?>
<tr>
@@ -188,7 +221,7 @@
<?php echo $cname; ?> <span style="color: #bbbbbb">// <?php echo $cdesc; ?></span>
</td>
</tr>
-
+
<tr>
<td colspan="2">
<div>
@@ -242,14 +275,14 @@
<?php
foreach ($classes as $class_name) {
$plugin =& serendipity_plugin_api::load_plugin($class_name);
-
+
/* query for its name, description and configuration data */
$bag = new serendipity_property_bag;
$plugin->introspect($bag);
-
+
$name = $bag->get('name');
$desc = $bag->get('description');
-?>
+?>
<option value="<?php echo $class_name; ?>"><?php echo $name . ' - ' . $desc; ?></option>
<?php
}
@@ -270,7 +303,7 @@
<?php
$sort_order = 0;
-
+
/* Block display the plugins per placement location. */
$plugin_placements = array('left', 'right', 'hide');
@@ -285,15 +318,15 @@
foreach ($plugins as $plugin_data) {
$plugin =& serendipity_plugin_api::load_plugin($plugin_data['name']);
$key = urlencode($plugin_data['name']);
-
+
/* query for its name, description and configuration data */
$bag = new serendipity_property_bag;
$plugin->introspect($bag);
-
+
$name = htmlentities($bag->get('name'));
$desc = htmlentities($bag->get('description'));
$place = placement_box('serendipity[placement][' . $plugin_data['name'] . ']', $plugin_data['placement']);
-
+
$title = '';
ob_start();
@@ -303,21 +336,21 @@
if (strlen(trim($title)) == 0) {
$title = ' ';
}
-
+
if ($bag->is_set('configuration')) {
$url = '?serendipity[adminModule]=plugins&serendipity[plugin_to_conf]=' . $key;
$desc = '<a href="' . $url . '">' . $desc . '</a>';
$name = '<a href="' . $url . '">' . $name . '</a>';
$title = '<a href="' . $url . '">' . $title . '</a>';
}
-
+
/* Only display UP/DOWN links if there's somewhere for the plugin to go */
if ($sort_idx == 0) {
$moveup = '';
} else {
$moveup = '<a href="?serendipity[adminModule]=plugins&submit=move+up&serendipity[plugin_to_move]=' . $key . '">' . UP . '</a>';
}
-
+
if ($sort_idx == (count($plugins)-1)) {
$movedown = '';
} else {
@@ -330,7 +363,7 @@
<input type="checkbox" name="serendipity[plugin_to_remove][]" value="<?php echo $plugin_data['name']; ?>">
</div>
</td>
-
+
<td style="border-bottom: 1px solid #000000"><?php echo $title; ?></td>
<td style="border-bottom: 1px solid #000000"><?php echo $name; ?></td>
<td style="border-bottom: 1px solid #000000"><?php echo $desc; ?></td>
|