Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29570
Modified Files:
serendipity_admin_plugins.inc.php
Log Message:
Introducing event plugins (see mailing list)
Index: serendipity_admin_plugins.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_plugins.inc.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- serendipity_admin_plugins.inc.php 13 Oct 2003 12:02:10 -0000 1.14
+++ serendipity_admin_plugins.inc.php 9 Feb 2004 15:20:31 -0000 1.15
@@ -8,6 +8,144 @@
include_once 'serendipity_plugin_api.php';
include_once 'serendipity_sidebar_items.php';
+function show_plugins($event_only = false)
+{
+ global $serendipity;
+
+ /* list of classes for creating instances (standard plugins) */
+ $classes = serendipity_plugin_api::enum_plugin_classes($event_only);
+?>
+<form action="?serendipity[adminModule]=plugins" method="post">
+<?php
+ $event_only_uri = '';
+ if ($event_only) {
+ $event_only_uri = '&serendipity[event_plugin]=true';
+?>
+ <input type="hidden" name="serendipity[event_plugin]" value="true" />
+<?php
+ }
+?>
+ <div>
+ <select name="serendipity[plugin_to_add]">
+ <option value="0">[ <?php echo SELECT_A_PLUGIN_TO_ADD; ?> ]</option>
+<?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
+ }
+?>
+ </select>
+ <input name="NEW" value="<?php echo ADD_PLUGIN; ?>" type="submit" />
+ <br />
+ <br />
+
+ <table border="0" cellpadding="5" cellspacing="0">
+ <tr>
+ <th> </th>
+ <th><?php echo TITLE; ?></th>
+ <th><?php echo DESCRIPTION; ?></th>
+<?php
+ if (!$event_only) {
+?>
+ <th><?php echo PLACEMENT; ?></th>
+<?php
+ }
+?>
+ </tr>
+<?php
+
+ $sort_order = 0;
+
+ /* Block display the plugins per placement location. */
+ if ($event_only) {
+ $plugin_placements = array('event');
+ } else {
+ $plugin_placements = array('left', 'right', 'hide');
+ }
+
+ foreach ($plugin_placements as $plugin_placement) {
+ $plugins = serendipity_plugin_api::enum_plugins($plugin_placement);
+
+ if (!is_array($plugins)) {
+ continue;
+ }
+
+ $sort_idx = 0;
+ 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'));
+ if ($event_only) {
+ $place = '<input type="hidden" name="serendipity[placement][' . $plugin_data['name'] . ']" value="event" />';
+ } else {
+ $place = placement_box('serendipity[placement][' . $plugin_data['name'] . ']', $plugin_data['placement']);
+ }
+
+ $title = serendipity_plugin_api::get_plugin_title($plugin, ' ');
+
+ 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 . $event_only_uri . '">' . UP . '</a>';
+ }
+
+ if ($sort_idx == (count($plugins)-1)) {
+ $movedown = '';
+ } else {
+ $movedown = ($moveup != '' ? ' ' : '') . '<a href="?serendipity[adminModule]=plugins&submit=move+down&serendipity[plugin_to_move]=' . $key . $event_only_uri . '">' . DOWN . '</a>';
+ }
+?>
+ <tr>
+ <td style="border-bottom: 1px solid #000000">
+ <div>
+ <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 $desc; ?></td>
+ <td style="border-bottom: 1px solid #000000" nowrap="nowrap">
+ <div><?php echo $place . $moveup . $movedown; ?></div>
+ </td>
+ </tr>
+<?php
+ $sort_idx++;
+ }
+ }
+?>
+ </table>
+ <br />
+
+ <input type="submit" name="REMOVE" title="<?php echo REMOVE_TICKED_PLUGINS; ?>" value="<?php echo DELETE; ?>" />
+ <input type="submit" name="SAVE" title="<?php echo SAVE_CHANGES_TO_LAYOUT; ?>" value="<?php echo SAVE; ?>" />
+ </div>
+</form>
+<?php
+}
+
function placement_box($name, $val)
{
static $opts = array(
@@ -24,7 +162,11 @@
}
if (isset($_GET['serendipity']['plugin_to_move']) && isset($_GET['submit'])) {
- $plugins = serendipity_plugin_api::enum_plugins();
+ if (isset($_GET['serendipity']['event_plugin'])) {
+ $plugins = serendipity_plugin_api::enum_plugins('event', false);
+ } else {
+ $plugins = serendipity_plugin_api::enum_plugins('event', true);
+ }
/* Renumber the sort order to be certain that one actually exists
Also look for the one we're going to move */
@@ -79,6 +221,8 @@
$plugin->set_config($config_item, $_POST['serendipity']['plugin'][$config_item]);
}
}
+
+ $plugin->cleanup();
}
?>
<form method="post" name="serendipityPluginConfigure">
@@ -117,7 +261,7 @@
break;
case 'select':
- $select = $plugin->select_values;
+ $select = $cbag->get('select_values');
?>
<tr>
<td style="vertical-align: top"><?php echo $cname; ?></td>
@@ -255,7 +399,11 @@
}
if (isset($_POST['NEW']) && $_POST['serendipity']['plugin_to_add'] != '0') {
- $inst = serendipity_plugin_api::create_plugin_instance($_POST['serendipity']['plugin_to_add']);
+ if (isset($_POST['serendipity']['event_plugin'])) {
+ $inst = serendipity_plugin_api::create_plugin_instance($_POST['serendipity']['plugin_to_add'], null, 'event');
+ } else {
+ $inst = serendipity_plugin_api::create_plugin_instance($_POST['serendipity']['plugin_to_add']);
+ }
/* TODO: redirect to configuration for that instance */
}
@@ -265,123 +413,11 @@
}
}
- /* list of classes for creating instances */
- $classes = serendipity_plugin_api::enum_plugin_classes();
-?>
-<form action="?serendipity[adminModule]=plugins" method="post">
- <div>
- <select name="serendipity[plugin_to_add]">
- <option value="0">[ <?php echo SELECT_A_PLUGIN_TO_ADD; ?> ]</option>
-<?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
- }
-?>
- </select>
- <input name="NEW" value="<?php echo ADD_PLUGIN; ?>" type="submit" />
- <br />
- <br />
-
- <table border="0" cellpadding="5" cellspacing="0">
- <tr>
- <th> </th>
- <th><?php echo TITLE; ?></th>
- <th><?php echo DESCRIPTION; ?></th>
- <th><?php echo PLACEMENT; ?></th>
- </tr>
-<?php
-
- $sort_order = 0;
-
- /* Block display the plugins per placement location. */
- $plugin_placements = array('left', 'right', 'hide');
-
- foreach ($plugin_placements as $plugin_placement) {
- $plugins = serendipity_plugin_api::enum_plugins($plugin_placement);
-
- if (!is_array($plugins)) {
- continue;
- }
-
- $sort_idx = 0;
- 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();
- $plugin->generate_content($title);
- ob_end_clean();
-
- 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 {
- $movedown = ($moveup != '' ? ' ' : '') . '<a href="?serendipity[adminModule]=plugins&submit=move+down&serendipity[plugin_to_move]=' . $key . '">' . DOWN . '</a>';
- }
-?>
- <tr>
- <td style="border-bottom: 1px solid #000000">
- <div>
- <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 $desc; ?></td>
- <td style="border-bottom: 1px solid #000000" nowrap="nowrap">
- <div><?php echo $place . $moveup . $movedown; ?></div>
- </td>
- </tr>
-<?php
- $sort_idx++;
- }
- }
-?>
- </table>
- <br />
+ echo '<h2>' . SIDEBAR_PLUGINS . '</h2>';
+ show_plugins(false);
- <input type="submit" name="REMOVE" title="<?php echo REMOVE_TICKED_PLUGINS; ?>" value="<?php echo DELETE; ?>" />
- <input type="submit" name="SAVE" title="<?php echo SAVE_CHANGES_TO_LAYOUT; ?>" value="<?php echo SAVE; ?>" />
- </div>
-</form>
-<?php
+ echo '<h2>' . EVENT_PLUGINS . '</h2>';
+ show_plugins(true);
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|