# definitions
-VERSION = 0.9.18.1
+VERSION = 0.9.19pre2
PKG_DIST = diogenes-$(VERSION)
LIB_DIST = libdiogenes-$(VERSION)
class DiogenesDbInit extends DiogenesDatabaseCreator
{
/** database versions history */
- var $versions = array("0.9.9.3", "0.9.10", "0.9.12", "0.9.15", "0.9.16", "0.9.16+0.9.17pre15", "0.9.16+0.9.17pre19", "0.9.16+0.9.17pre21", "0.9.18+0.9.19pre1");
+ var $versions = array("0.9.9.3", "0.9.10", "0.9.12", "0.9.15", "0.9.16", "0.9.16+0.9.17pre15", "0.9.16+0.9.17pre19", "0.9.16+0.9.17pre21", "0.9.18+0.9.19pre2");
/**
* Upgrades the database from one version to the next
$this->dbh->query("INSERT INTO diogenes_logactions VALUES (16, 'page_plugins', 'the page plugins were modified');");
break;
- case "0.9.18+0.9.19pre1":
+ case "0.9.18+0.9.19pre2":
$this->info(" - adding 'status' field to 'diogenes_plugin' table");
$this->dbh->query("ALTER TABLE `diogenes_plugin` ADD `status` INT( 1 ) UNSIGNED NOT NULL default '0'");
- $this->dbh->query("update diogenes_plugin set status=1 where page=0");
- $this->dbh->query("update diogenes_plugin set status=2 where page!=0");
+ $this->dbh->query("update diogenes_plugin set status=0 where page=0");
+ $this->dbh->query("update diogenes_plugin set status=1 where page!=0");
+ $this->info(" - removing 'pos' field to 'diogenes_plugin' table");
+ $this->dbh->query("ALTER TABLE `diogenes_plugin` DROP `pos`");
break;
default:
/* plugin editor */
$editor = new Diogenes_Plugin_Editor($barrel, 0);
-//$editor->hide_params(1);
+$editor->set_mode(MODE_ROOT);
$editor->run($page,'editor_content');
// translations
require_once 'Barrel/Page.php';
require_once 'Barrel/Options.php';
require_once 'diogenes/diogenes.flagset.inc.php';
+require_once 'Plugin/Skel.php';
/** This class describes a Diogenes Barrel.
}
- /** List the plugins that are active in a given context
- *
- * @param $page
- */
- function getPlugins($page = 0)
- {
- $plugins = array();
- foreach ($this->pluginsCache as $plug)
- {
- if ($plug['page'] == $page)
- {
- array_push($plugins, $plug);
- }
- }
- return $plugins;
- }
-
-
/** Check whether the barrel has a given flag
*
* @param $flag
}
- /** Load all plugins for the specified page.
+ /** Load all active plugins for the specified page.
*
* @param $bpage
*/
{
global $globals;
- $plugins = $this->getPlugins($bpage->props['PID']);
-
+ $plugins = $globals->plugins->cacheGetActive($this->pluginsCache, $this->alias, $page);
$loaded = array();
- foreach ($plugins as $plugentry)
+ foreach ($plugins as $plugname => $plugentry)
{
- $loaded[$plugentry['plugin']] =& $globals->plugins->load($plugentry);
+ $loaded[$plugname] =& $globals->plugins->load($plugname, $plugentry);
}
return $loaded;
}
if ($props['PID'])
{
$cache = $globals->plugins->readCache($this->barrel->pluginsCacheFile, $this->barrel->alias);
- $plugs_active = $globals->plugins->cachedActive($cache, $this->barrel->alias, $props['PID']);
+ $plugs_active = $globals->plugins->cacheGetActive($cache, $this->barrel->alias, $props['PID']);
foreach($plugs_active as $plugentry)
{
$plug_h = $globals->plugins->load($plugentry);
// dependency on PEAR
require_once 'System.php';
+define('MODE_NORMAL', 0);
+define('MODE_ROOT', 1);
+define('MODE_READONLY', 2);
+define('MODE_NOPARAMS', 4);
/** This class provides a configuration tool for Diogenes plugins.
*/
class Diogenes_Plugin_Editor {
- /** Should we show plugins parameters? */
- var $show_params = 1;
-
- /** Should editing functions be disabled? */
- var $readonly = false;
-
/** The alias of the barrel we are working on. */
var $plug_barrel;
/** The write permissions of the page we are working on. */
var $plug_page_wperms;
+
+ /** The plugin editor mode */
+ var $mode = MODE_NORMAL;
/** Construct a new plugin editor.
*
$globals->plugins->compileCache($this->plug_barrel, $page);
}
$cache = $globals->plugins->readCache($cachefile, $this->plug_barrel);
- $available = $globals->plugins->cachedVisible($cache, $this->plug_barrel, $this->plug_page);
+ $available = $globals->plugins->cacheGetVisible($cache, $this->plug_barrel, $this->plug_page);
// handle updates
$rebuild_cache = 0;
switch ($action) {
- case "move_up": case "move_down":
- if ($this->readonly) die("Sorry, this plugin view is read-only.");
-
- $delta = ($action == "move_down") ? 1 : -1;
- $page->info("moving plugin '$target'..");
- $plugcache_a = $globals->plugins->cacheGet($cache, $this->plug_barrel, $this->plug_page, $target);
- $plug_a =& $globals->plugins->load($plugcache_a['name'], $plugcache_a);
-
- if (is_object($plug_a) && ($plug_a->active)) {
- $old_pos = $plug_a->pos;
- $plugcache_b = $globals->plugins->cacheGetAtPos($cache, $this->plug_barrel, $this->plug_page, $old_pos + $delta);
-
- if (is_array($plugcache_b))
- {
- $plug_b =& $globals->plugins->load($plugcache_b['name'], $plugcache_b);
-
- // swap the current plugin and the next plugin
- if (is_object($plug_b) && ($plug_b->active))
- {
- $plug_a->toDatabase($this->plug_barrel, $this->plug_page, $old_pos + $delta);
- $plug_b->toDatabase($this->plug_barrel, $this->plug_page, $old_pos);
- }
- }
- }
- $rebuild_cache = 1;
- break;
-
case "update":
- if ($this->readonly) die("Sorry, this plugin view is read-only.");
+ if ($this->mode & MODE_READONLY) die("Sorry, this plugin view is read-only.");
foreach ($available as $plugin => $plugentry)
{
// check we have a valid cache entry
// retrieve parameters from REQUEST
if (isset($_REQUEST[$plug_h->name."_status"]))
- {
+ {
$plug_h->status = $_REQUEST[$plug_h->name."_status"];
}
foreach ($plug_h->getParamNames() as $key)
}
// write parameters to database
- $plug_h->toDatabase($this->plug_barrel, $this->plug_page, $pos);
+ if ($plug_h->status & PLUG_SET)
+ {
+ $plug_h->toDatabase($this->plug_barrel, $this->plug_page, $pos);
+ } else {
+ $plug_h->eraseParameters($this->plug_barrel, $his->plug_page);
+ }
$rebuild_cache = 1;
}
}
// rebuild plugin cache
$globals->plugins->compileCache($this->plug_barrel, $page);
$cache = $globals->plugins->readCache($cachefile, $this->plug_barrel);
- $available = $globals->plugins->cachedVisible($cache, $this->plug_barrel, $this->plug_page);
+ $available = $globals->plugins->cacheGetVisible($cache, $this->plug_barrel, $this->plug_page);
}
// get dump of plugins to fill out form
$rw_plugs_on = array();
$rw_plugs_off = array();
- // start by adding the active plugins
+ /* run over the plugins and split plugins into the following categories:
+ * - read-only,
+ * - read-write/active
+ * - read-write/inactive
+ */
foreach ($available as $plugname => $plugcache)
{
$plugentry = $plugcache;
$plugentry['icon'] = $globals->icons->get_action_icon('plugins');
$type = $plugentry['type'];
- if ($plugentry['status'] & PLUG_LOCK)
+ // FIXME : the test below needs to be refined
+ if (!($this->mode & MODE_ROOT) && ($plugentry['status'] & PLUG_LOCK))
{
$o_plugs =& $ro_plugs;
$plugentry['readonly'] = 1;
$o_plugs =& $rw_plugs_off;
}
- if (!empty($o_plugs[$type])) {
- $plugentry['move_up'] = 1;
- $last = count($o_plugs[$type]) - 1;
- $o_plugs[$type][$last]['move_down'] = 1;
- } else {
+ if (empty($o_plugs[$type])) {
$o_plugs[$type] = array();
}
array_push($o_plugs[$type], $plugentry);
}
- // next we add the inactive plugins
+ // merge the different plugin categories into a global list
$plugs = array_merge_recursive($rw_plugs_on, $rw_plugs_off);
+ $plugs = array_merge_recursive($plugs, $ro_plugs);
$page->assign('plugins', $plugs);
+
// debugging
foreach ($plugs as $p_type => $p_entries)
{
}
// values
- $page->assign('show_params', $this->show_params);
- $page->assign('readonly',$this->readonly);
- $statusvals = array(0 => 'off', 1 => 'on', 2 => 'off (lock)', 3 => 'on (lock)');
+ $page->assign('show_params', !($this->mode & MODE_NOPARAMS));
+ $page->assign('readonly', ($this->mode & MODE_READONLY));
+ $statusvals = array(
+ PLUG_DISABLED => 'default',
+ PLUG_SET | PLUG_DISABLED => 'off',
+ PLUG_SET | PLUG_ACTIVE => 'on',
+ PLUG_SET | PLUG_DISABLED | PLUG_LOCK => 'off (lock)',
+ PLUG_SET | PLUG_ACTIVE | PLUG_LOCK => 'on (lock)',
+ );
+ $rwstatusvals = $statusvals;
+ if (!($this->mode & MODE_ROOT)) {
+ unset($rwstatusvals[PLUG_SET | PLUG_DISABLED | PLUG_LOCK]);
+ unset($rwstatusvals[PLUG_SET | PLUG_ACTIVE | PLUG_LOCK]);
+ }
$page->assign('statusvals', $statusvals);
+ $page->assign('rwstatusvals', $rwstatusvals);
- // translations
+ // translations
$page->assign('msg_submit', __("Submit"));
- $page->assign('msg_plugedit_plugin', __("plugin"));
+ $page->assign('msg_plugedit_plugin', __("plugin"));
$page->assign('msg_plugedit_plugins', __("plugins"));
$page->assign('msg_plugedit_description', __("description"));
$page->assign('msg_plugedit_parameters', __("parameters"));
- $page->assign('msg_move_up', __("move up"));
- $page->assign('msg_move_down', __("move down"));
// if requested, assign the content to be displayed
if (!empty($outputvar)) {
$page->assign($outputvar, $page->fetch('plugin-editor.tpl'));
}
}
-
-
- /** Do not display plugin parameters.
- *
- * @param $hide boolean
+
+ /** Set the editor mode.
*/
- function hide_params($hide)
+ function set_mode($mode)
{
- $this->show_params = !$hide;
+ $this->mode = $mode;
}
-
}
?>
define('PLUG_DISABLED', 0);
define('PLUG_ACTIVE', 1);
define('PLUG_LOCK', 2);
+define('PLUG_SET', 4);
/** Recursive stripslashes.
*
/** The plugin status (disabled, available, active) */
var $status = PLUG_DISABLED;
-
+
/** Is the plugin allowed with respect to a given write permission on a page ?
*
* @param $wperms
*/
function declareParam($key, $val)
{
- $this->params[$key] = $val;
+ $this->params[$key]['value'] = $val;
}
*/
function getParamValue($key)
{
- return isset($this->params[$key]) ? $this->params[$key] : '';
+ return isset($this->params[$key]['value']) ? $this->params[$key]['value'] : '';
}
*/
function setParamValue($key, $val)
{
- if (isset($this->params[$key])) {
- $this->params[$key] = $val;
- } else {
+ if (isset($this->params[$key]['value'])) {
+ $this->params[$key]['value'] = $val;
}
}
$this->status = $plugentry['status'];
foreach ($plugentry['params'] as $key => $val)
{
- $this->setParamValue($key, $val);
+ $this->setParamValue($key, $val['value']);
}
}
return $cachefile;
}
+
/** Return the cache entry for specified plugin
*
* @param $cache
}
- /** Return the cache entry for a plugin at a specified position
- *
- * @param $cache
- * @param $barrel
- * @param $page
- * @param $pos
- */
- function cacheGetAtPos($cache, $barrel, $page, $pos)
- {
- $p_node = $this->cacheGetPageNode($cache, $barrel, $page);
- foreach ($p_node->data as $plugname => $plugentry)
- {
- if ($plugentry['pos'] == $pos)
- {
- $plugentry['plugin'] = $plugname;
- return $plugentry;
- }
- }
- }
-
-
/** Return the cache entry for specified plugin
*
* @param $cache
* @param $barrel
* @param $page
*/
- function cachedActive($cache, $barrel, $page)
+ function cacheGetActive($cache, $barrel, $page)
{
$p_node = $this->cacheGetPageNode($cache, $barrel, $page);
$plugins = array();
foreach ($p_node->data as $plugname => $plugentry)
{
- //echo "cachedEditable : examining $plugname (status {$plugentry['status']})<br/>\n";
+ //echo "cacheGetActive : examining $plugname (status {$plugentry['status']})<br/>\n";
if ($plugentry['status'] & PLUG_ACTIVE)
{
- //echo "cachedActive : adding $plugname<br/>\n";
+ //echo "cacheGetActive : adding $plugname<br/>\n";
$plugins[$plugname] = $plugentry;
}
}
* @param $barrel
* @param $page
*/
- function cachedVisible($cache, $barrel, $page)
+ function cacheGetVisible($cache, $barrel, $page)
{
$p_node = $this->cacheGetPageNode($cache, $barrel, $page);
return $p_node->data;
-/*
- $available = array();
- foreach ($p_node->data as $plugname => $plugentry)
- {
- //echo "cachedEditable : examining $plugname (status {$plugentry['status']})<br/>\n";
- if (!($plugentry['status'] & PLUG_LOCK) || !$barrel)
- {
- //echo "cachedEditable : adding $plugname<br/>\n";
- $available[$plugname] = $plugentry;
- // }
- }
- return $available;
-*/
}
{
//echo "* plugin '$plugin' not locked off parent level<br/>\n";
$outval = $parentval;
- if (is_array($node->data[$plugin]))
+ if ((is_array($node->data[$plugin])) && ($node->data[$plugin]['status'] & PLUG_SET))
{
//echo "** plugin set at current level<br/>\n";
- $outval['pos'] = $node->data[$plugin]['pos'];
$outval['params'] = $node->data[$plugin]['params'];
if (!($parentval['status'] & PLUG_LOCK)) {
//echo "*** plugin status set to DB-specified value<br/>\n";
$dbcache = array();
$sql_limit = $barrel ? " where barrel='{$barrel}' or barrel=''" : "";
- $sql = "select barrel, page, plugin, status, pos, params from diogenes_plugin" . $sql_limit;
+ $sql = "select barrel, page, plugin, status, params from diogenes_plugin" . $sql_limit;
$res = $this->dbh->query($sql);
while($row = mysql_fetch_row($res))
{
$plugin = array_shift($row);
$plugentry = array(
'status' => $row[0],
- 'pos' => $row[1],
- 'params' => ($row[2] ? var_decode_bin($row[2]) : array())
+ 'params' => ($row[1] ? var_decode_bin($row[1]) : array())
);
$plug_h = $this->load($plugin, $plugentry);
//echo "Got params from DB for '$plugin', barrel '$c_barrel', page '$c_page' : ".$row[2]."<br/>";
$trclass = $odd ? ' class="odd"' : '';
$out .= "<tr><th colspan=\"2\">{$val['name']} v{$val['version']}</th></tr>\n";
$out .= "<tr><td>status</td><td>{$val['status']}</td></tr>\n";
- if (isset($val['pos'])) {
- $out .= "<tr><td>position</td><td>{$val['pos']}</td></tr>\n";
- }
$out .= "<tr$trclass><td>type</td><td>{$val['type']}</td></tr>\n";
$out .= "<tr$trclass><td>description</td><td>{$val['description']}</td></tr>\n";
if (!empty($val['params'])) {
function var_encode_text($var, $level = 0, $no_children = FALSE, $tabstr = ' ', $eol = "\n")
{
- if (is_object($var) && (get_class($var) == 'Diogenes_Tree_Node')) {
+ if (is_object($var) && (strtolower(get_class($var)) == 'diogenes_tree_node')) {
// node name
$code = str_repeat($tabstr, $level) . "node : {$var->name}" . $eol;
function var_encode_bin($var, $no_children = FALSE)
{
- if (is_object($var) && (get_class($var) == 'Diogenes_Tree_Node')) {
+ if (is_object($var) && (strtolower(get_class($var)) == 'diogenes_tree_node')) {
$code = pack('C', VAR_TYPE_NODE);
$code .= var_encode_bin($var->name);
$code .= var_encode_bin($var->data);
{
$bin = file_get_contents($filename);
$node = var_decode_bin($bin);
- if (!is_object($node) || get_class($node) != 'Diogenes_Tree_Node')
+ if (!is_object($node) || strtolower(get_class($node)) != 'diogenes_tree_node')
{
trigger_error('readFile : not a Diogenes_Tree_Node', E_USER_ERROR);
}
/* plugin editor */
$editor = new Diogenes_Plugin_Editor($page->alias, $dir, $wperms);
if ($dir == 0) {
- $editor->readonly = 1;
- $editor->hide_params(1);
+ $editor->set_mode(MODE_NOPARAMS);
}
$editor->run($page,'page_content');
$page->display('');
$render_plugin = $plugobj;
}
}
+
// source page or pass it to a rendering plugin
if (is_object($render_plugin)) {
$content = $render_plugin->render($path);
{if !$readonly}
-{literal}
-<script type="text/javascript">
- <!--
- function move_up( myplug ) {
- document.plug_form.action.value = "move_up";
- document.plug_form.plug_target.value = myplug;
- document.plug_form.submit();
- return true;
- }
- function move_down( myplug ) {
- document.plug_form.action.value = "move_down";
- document.plug_form.plug_target.value = myplug;
- document.plug_form.submit();
- return true;
- }
- // -->
-</script>
-{/literal}
-
<form name="plug_form" method="post" action="{$post}">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="plug_target" value="" />
<tr class="odd">
<td><img class="fileicon" src="{$plug.icon}"/> {$plug.name} v{$plug.version}</td>
<td>
-{if $plug.readonly}
- status {$plug.status}
+{if $readonly || $plug.readonly}
+ {$statusvals[$plug.status]}
{else}
- <select name="{$plug.name}_status">{html_options options=$statusvals selected=$plug.status}</select>
- <a class="action"{if $plug.move_up}href="javascript:move_up('{$plug.name}');"{/if}>{$msg_move_up}</a> <a class="action"{if $plug.move_down}href="javascript:move_down('{$plug.name}');"{/if}>{$msg_move_down}</a>
+ <select name="{$plug.name}_status">{html_options options=$rwstatusvals selected=$plug.status}</select>
{/if}
</td>
</tr>
{foreach from=$plug.params key=key item=val}
<tr>
<td>{$key}</td>
- <td><input type="text" name="{$plug.name}_{$key}" value="{$val|escape}" size="30" /></td>
+ <td><input type="text" name="{$plug.name}_{$key}" value="{$val.value|escape}" size="30" /></td>
</tr>
{/foreach}
</table>
+{else}
+
{/if}
</td>
</tr>