Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1:/tmp/cvs-serv15776
Modified Files:
serendipity_admin_plugins.inc.php
Log Message:
o Code style (double/single quotes, html)
o Moved function declarations to the top of the file
o Now remove config entries when a plugin is removed
o After update, show the new values for the plugin instead the old ones.
Index: serendipity_admin_plugins.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_plugins.inc.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- serendipity_admin_plugins.inc.php 8 Jul 2003 09:13:27 -0000 1.6
+++ serendipity_admin_plugins.inc.php 16 Jul 2003 12:03:22 -0000 1.7
@@ -1,253 +1,292 @@
<?php # $Id$
-if (IN_serendipity !== true) die ("Don't hack!");
+if (IN_serendipity !== true) {
+ die ('Don\'t hack!');
+}
session_start();
-include_once "serendipity_plugin_api.php";
-include_once "serendipity_sidebar_items.php";
-
-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
- Also look for the one we're going to move */
- $idx_to_move = -1;
- for($idx=0; $idx<count($plugins); $idx++) {
- $plugins[$idx]['sort_order'] = $idx;
- if ($plugins[$idx]['name'] == $_GET['serendipity']['plugin_to_move'])
- $idx_to_move = $idx;
- }
- /* 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))) {
- /* Swap the one were moving with the one that's in the spot we're moving to */
- $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'");
- }
- }
+include_once 'serendipity_plugin_api.php';
+include_once 'serendipity_sidebar_items.php';
- /* 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. */
+function placement_box($name, $val)
+{
+ static $opts = array(
+ 'left' => LEFT,
+ '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";
+ }
+ return $x . "</select>\n";
}
-if (isset($_GET['serendipity']['plugin_to_conf'])) {
- /* configure a specific instance */
+if (isset($_GET['serendipity']['plugin_to_move']) && isset($_GET['submit'])) {
+ $plugins = serendipity_plugin_api::enum_plugins();
- $plugin =& serendipity_plugin_api::load_plugin($_GET['serendipity']['plugin_to_conf']);
+ /* 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++) {
+ $plugins[$idx]['sort_order'] = $idx;
- $bag = new serendipity_property_bag;
- $plugin->introspect($bag);
- $name = htmlentities($bag->get('name'));
- $desc = htmlentities($bag->get('description'));
-
- $config_names = $bag->get('configuration');
+ if ($plugins[$idx]['name'] == $_GET['serendipity']['plugin_to_move']) {
+ $idx_to_move = $idx;
+ }
+ }
- if (isset($_POST['SAVECONF'])) {
- /* enum properties and set their values */
+ /* 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))) {
- foreach ($config_names as $config_item) {
- $cbag = new serendipity_property_bag;
- if ($plugin->introspect_config_item($config_item, $cbag)) {
- $plugin->set_config($config_item, $_POST['serendipity']['plugin'][$config_item]);
- }
- }
- }
+ /* Swap the one were moving with the one that's in the spot we're moving to */
+ $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
+ 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'])) {
+ /* enum properties and set their values */
+
+ foreach ($config_names as $config_item) {
+ $cbag = new serendipity_property_bag;
+ if ($plugin->introspect_config_item($config_item, $cbag)) {
+ $plugin->set_config($config_item, $_POST['serendipity']['plugin'][$config_item]);
+ }
+ }
+ }
?>
-<form method="POST" name="serendipityPluginConfigure">
+<form method="post" name="serendipityPluginConfigure">
+ <table cellpadding="5">
+ <tr>
+ <th><?php echo NAME; ?></th>
+ <td><?php echo $name; ?></td>
+ </tr>
-<table cellpadding="5">
-<tr>
-<th>Name</th>
-<td><?php echo $name ; ?></td>
-</tr>
-<tr>
-<th>Description</th>
-<td><?php echo $desc ; ?></td>
-</tr>
-</table>
+ <tr>
+ <th><?php echo DESCRIPTION; ?></th>
+ <td><?php echo $desc; ?></td>
+ </tr>
+ </table>
-<table border="0" cellspacing="5" cellpadding="5">
+ <table border="0" cellspacing="5" cellpadding="5">
<?php
+ 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));
-
- 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 = htmlentities($value);
-
- switch ($cbag->get('type')) {
- case 'string':
- echo "<tr><td>$cname</td><td><input type=\"text\" name=\"serendipity[plugin][$config_item]\" value=\"$hvalue\"> <font color='#bbbbbb'>//$cdesc</font></td></tr>\n";
- break;
- case 'html':
- echo "<tr><td colspan=\"2\">$cname <font color='#bbbbbb'>//$cdesc</font></td></tr>\n<tr><td colspan=\"2\"><textarea name=\"serendipity[plugin][$config_item]\" rows=\"20\" cols=\"80\">$hvalue</textarea></td></tr>";
- serendipity_emit_htmlarea_code("document.forms['serendipityPluginConfigure']['serendipity[plugin][$config_item]']");
- break;
- }
-
- }
+ switch ($cbag->get('type')) {
+ case 'string':
?>
-</table>
-<input type="submit" name="SAVECONF" value="Save">
-</form>
+ <tr>
+ <td><?php echo $cname; ?></td>
+ <td>
+ <div>
+ <input type="text" name="serendipity[plugin][<?php echo $config_item; ?>]" value="<?php echo $hvalue; ?>" /> <span style="color: #bbbbbb">// <?php echo $cdesc; ?></span>
+ </div>
+ </td>
+ </tr>
<?php
+ break;
+ case 'html':
+?>
+ <tr>
+ <td colspan="2">
+ <?php echo $cname; ?> <span style="color: #bbbbbb">// <?php echo $cdesc; ?></span>
+ </td>
+ </tr>
+
+ <tr>
+ <td colspan="2">
+ <div>
+ <textarea name="serendipity[plugin][<?php echo $config_item; ?>]" rows="20" cols="80"><?php echo $hvalue; ?></textarea>
+ </div>
+ </td>
+ </tr>
+<?php
+ serendipity_emit_htmlarea_code("document.forms['serendipityPluginConfigure']['serendipity[plugin][$config_item]']");
+ break;
+ }
+ }
+?>
+ </table>
+ <div>
+ <input type="submit" name="SAVECONF" value="<?php echo SAVE; ?>" />
+ </div>
+</form>
+<?php
} else {
- /* show general plugin list */
+ /* show general plugin list */
-if (isset($_POST['SAVE']) && isset($_POST['serendipity']['placement'])) {
- foreach ($_POST['serendipity']['placement'] as $plugin_name => $placement) {
- serendipity_plugin_api::update_plugin_placement(
- addslashes($plugin_name),
- addslashes($placement)
- );
- }
-}
-if (isset($_POST['NEW']) && $_POST['serendipity']['plugin_to_add'] != '0') {
- $inst = serendipity_plugin_api::create_plugin_instance($_POST['serendipity']['plugin_to_add']);
- /* TODO: redirect to configuration for that instance */
-}
-if (isset($_POST['REMOVE'])) {
- foreach ($_POST['serendipity']['plugin_to_remove'] as $key) {
- serendipity_plugin_api::remove_plugin_instance($key);
- }
-}
+ if (isset($_POST['SAVE']) && isset($_POST['serendipity']['placement'])) {
+ foreach ($_POST['serendipity']['placement'] as $plugin_name => $placement) {
+ serendipity_plugin_api::update_plugin_placement(
+ addslashes($plugin_name),
+ addslashes($placement)
+ );
+ }
+ }
-/* list of classes for creating instances */
-$classes = serendipity_plugin_api::enum_plugin_classes();
+ if (isset($_POST['NEW']) && $_POST['serendipity']['plugin_to_add'] != '0') {
+ $inst = serendipity_plugin_api::create_plugin_instance($_POST['serendipity']['plugin_to_add']);
+ /* TODO: redirect to configuration for that instance */
+ }
+ if (isset($_POST['REMOVE'])) {
+ foreach ($_POST['serendipity']['plugin_to_remove'] as $key) {
+ serendipity_plugin_api::remove_plugin_instance($key);
+ }
+ }
+ /* list of classes for creating instances */
+ $classes = serendipity_plugin_api::enum_plugin_classes();
?>
<form action="?serendipity[adminModule]=plugins" method="post">
-
-<select name="serendipity[plugin_to_add]">
-<option value="0">[ <?php echo SELECT_A_PLUGIN_TO_ADD; ?> ]</option>
+ <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 = htmlentities($bag->get('name'));
- $desc = htmlentities($bag->get('description'));
-
- echo "<option value=\"$class_name\">$name - $desc</option>\n";
-}
-
-
+ 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 />
+ </select>
+ <input name="NEW" value="<?php echo ADD_PLUGIN; ?>" type="submit" />
+ <br />
+ <br />
-<table border="1" cellpadding="5">
-<tr>
-<th> </th>
-<th><?php echo TITLE; ?></th>
-<th><?php echo PLUGIN; ?></th>
-<th><?php echo DESCRIPTION; ?></th>
-<th><?php echo PLACEMENT; ?></th>
-</tr>
+ <table border="1" cellpadding="5">
+ <tr>
+ <th> </th>
+ <th><?php echo TITLE; ?></th>
+ <th><?php echo PLUGIN; ?></th>
+ <th><?php echo DESCRIPTION; ?></th>
+ <th><?php echo PLACEMENT; ?></th>
+ </tr>
<?php
-function placement_box($name, $val)
-{
- static $opts = array(
- 'left' => 'Left',
- 'right' => 'Right',
- 'hide' => 'Hidden'
- );
-
- $x = "<select name=\"$name\">";
- foreach ($opts as $k => $v) {
- $x .= "<option value=\"$k\"";
- if ($k == $val)
- $x .= " selected";
- $x .= ">$v</option>";
- }
- return $x . "</select>";
-}
-
-$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>";
- }
+ $sort_order = 0;
+
+ /* Block display the plugins per placement location. */
+ $plugin_placements = array('left', 'right', 'hide');
- /* 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>";
+ foreach ($plugin_placements as $plugin_placement) {
+ $plugins = serendipity_plugin_api::enum_plugins($plugin_placement);
- if ($sort_idx == (count($plugins)-1))
- $movedown = "";
- else
- $movedown = "<a href=\"?serendipity[adminModule]=plugins&submit=move+down&serendipity[plugin_to_move]=$key\">".DOWN."</a>";
+ 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 = '';
- echo "<tr><td><input type=\"checkbox\" name=\"serendipity[plugin_to_remove][]\" value=\"$plugin_data[name]\"></td><td>$title</td><td>$name</td><td>$desc</td><td>$place $moveup $movedown</td></tr>\n";
+ ob_start();
+ $plugin->generate_content($title);
+ ob_end_clean();
- $sort_idx++;
- }
-}
+ 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>';
+ }
?>
-</table>
-<br />
+ <tr>
+ <td>
+ <div>
+ <input type="checkbox" name="serendipity[plugin_to_remove][]" value="<?php echo $plugin_data['name']; ?>">
+ </div>
+ </td>
+
+ <td><?php echo $title; ?></td>
+ <td><?php echo $name; ?></td>
+ <td><?php echo $desc; ?></td>
+ <td>
+ <div><?php echo $place . $moveup . $movedown; ?></div>
+ </td>
+ </tr>
+<?php
+ $sort_idx++;
+ }
+ }
+?>
+ </table>
+ <br />
-<input type="submit" name="REMOVE" title="Remove Ticked Plugins" value="<?php echo DELETE; ?>">
-<input type="submit" name="SAVE" title="Save changes to layout" value="<?php echo SAVE; ?>">
+ <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
}
|