[Openupload-svn-update] SF.net SVN: openupload:[124] trunk
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-11-06 19:57:35
|
Revision: 124
http://openupload.svn.sourceforge.net/openupload/?rev=124&view=rev
Author: tsdogs
Date: 2008-11-06 19:57:33 +0000 (Thu, 06 Nov 2008)
Log Message:
-----------
Plugin options now are in the db.
Modified Paths:
--------------
trunk/lib/classes.inc.php
trunk/lib/modules/default/admin.inc.php
trunk/plugins/mimetypes.inc.php
trunk/templates/default/modules/admin/groups.tpl
trunk/templates/default/modules/admin/pluginoptions.tpl
trunk/templates/default/modules/admin/rights.tpl
trunk/templates/default/plugins/mimetypes/uploadForm.tpl
Added Paths:
-----------
trunk/templates/default/modules/admin/pluginoptionadd.tpl
trunk/templates/default/modules/admin/pluginoptiondetail.tpl
trunk/templates/default/modules/admin/pluginoptionedit.tpl
Modified: trunk/lib/classes.inc.php
===================================================================
--- trunk/lib/classes.inc.php 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/lib/classes.inc.php 2008-11-06 19:57:33 UTC (rev 124)
@@ -90,10 +90,13 @@
function OpenUploadMoule() {
}
- function nextStep($step = 0, $action = '') {
+ function nextStep($step = 0, $action = '',$params='') {
$step = $step==0?app()->step+1:$step;
$action = $action==''?app()->action:$action;
- redirect('?action='.$action.'&step='.$step);
+ if ($params!='')
+ redirect('?action='.$action.'&step='.$step.'&'.$params);
+ else
+ redirect('?action='.$action.'&step='.$step);
}
function prevStep() {
@@ -115,6 +118,8 @@
var $messageHTML;
var $name;
var $fields = array();
+ var $options = array();
+ var $config = array();
function MySharePlugin() {
}
@@ -127,7 +132,34 @@
$this->pluginHTML .= app()->fetch('plugins/'.$this->name.'/'.$tpl);
}
+ function loadConfig() {
+ if (count($this->options)>0) {
+ $opt = app()->db->read('plugin_options',array('plugin' => $this->name),array(),'',array('name','group_name'));
+ if (count($opt)==0) return;
+ foreach ($this->options as $o) {
+ $this->config[$o['name']] = array();
+ if (isset($opt[$o['name']])) {
+ foreach ($opt[$o['name']] as $g => $v) {
+ switch ($o['type']) {
+ case 'list':
+ $this->config[$o['name']][$g] = explode("\n",chop($v['value']));
+ break;
+ case 'text':
+ $this->config[$o['name']][$g] = $v['value'];
+ break;
+ default:
+ $this->config[$o['name']][$g] = $v['value'];
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
function init() {
+ $this->loadConfig();
+
}
/* functions that can be called
Modified: trunk/lib/modules/default/admin.inc.php
===================================================================
--- trunk/lib/modules/default/admin.inc.php 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/lib/modules/default/admin.inc.php 2008-11-06 19:57:33 UTC (rev 124)
@@ -19,9 +19,10 @@
),
"adminpluginsoptions" => array (
1 => "pluginoptions",
- 2 => "pluginoptionadd",
- 3 => "pluginoptionedit",
- 4 => "pluginoptiondelete",
+ 2 => "pluginoptiondetail",
+ 3 => "pluginoptionadd",
+ 4 => "pluginoptionedit",
+ 5 => "pluginoptiondelete",
),
"adminfiles" => array (
1 => "files",
@@ -319,7 +320,7 @@
}
}
}
- redirect('?action=adminrights&step=2&id='.$id);
+ $this->nextStep(2,'','id='.$id);
} else {
$id = $_GET['id'];
}
@@ -473,16 +474,105 @@
}
function pluginoptiondetail() {
+ global $_GET;
+
+ if (isset($_GET['id'])) {
+ $groups = app()->auth->groupinfo();
+ $options = app()->db->read('plugin_options',array('plugin' => $_GET['id']),array('group_name'),
+ '',array('group_name','name'));
+ $this->tpl->assign('groups',$groups);
+ $this->tpl->assign('plugin_options',$options);
+ $this->tpl->assign('options',app()->plugins[$_GET['id']]->options);
+ $this->tpl->assign('pluginname',$_GET['id']);
+ } else {
+ $this->nextStep(1);
+ }
}
function pluginoptionadd() {
+ global $_GET;
+ global $_POST;
+
+ if (isset($_GET['id']) or isset($_POST['id'])) {
+ $plugin = isset($_POST['id'])?$_POST['id']:$_GET['id'];
+ $poptions = app()->plugins[$plugin]->options;
+ $groups = app()->auth->groupinfo();
+ $this->tpl->assign('groups',$groups);
+ $this->tpl->assign('options',$poptions);
+ $this->tpl->assign('pluginname',$plugin);
+ if (isset($_POST['id'])) {
+ $group = $_POST['gid'];
+ /* should check if values for this group already exsist */
+ $tmp = app()->db->read('plugin_options',array('group_name' => $group, 'plugin' => $plugin));
+ if (count($tmp)>0) {
+ app()->error(tr('Options for this group already exsist, please use the edit function!'));
+ } else {
+ foreach ($poptions as $o) {
+ $val = array();
+ $val['plugin']=$plugin;
+ $val['group_name']=$group;
+ $val['name']=$o['name'];
+ $val['value'] = $_POST[$o['name']];
+ app()->db->insert('plugin_options',$val);
+ }
+ $this->nextStep(2,'','id='.$plugin);
+ }
+ } else {
+ $options = array();
+ }
+ $this->tpl->assign('plugin_options',$options);
+ } else {
+ $this->nextStep(1);
+ }
}
function pluginoptionedit() {
+ global $_GET;
+ global $_POST;
+
+ if (isset($_GET['id']) or isset($_POST['id'])) {
+ $plugin = isset($_POST['id'])?$_POST['id']:$_GET['id'];
+ $group = isset($_POST['gid'])?$_POST['gid']:$_GET['gid'];
+ $options = app()->db->read('plugin_options',array('plugin' => $plugin, 'group_name' => $group),array(),'',
+ array('name'));
+ $poptions = app()->plugins[$plugin]->options;
+ if (isset($_POST['id'])) {
+ foreach ($poptions as $o) {
+ $val = array();
+ if (isset($options[$o['name']])) {
+ $val = $options[$o['name']];
+ $val['value'] = $_POST[$o['name']];
+ app()->db->update('plugin_options',$val,array('id' => $val['id']));
+ } else {
+ $val['plugin']=$plugin;
+ $val['group_name']=$group;
+ $val['name']=$o['name'];
+ $val['value'] = $_POST[$o['name']];
+ app()->db->insert('plugin_options',$val);
+ }
+ }
+ $this->nextStep(2,'','id='.$plugin);
+ } else if ($group!='') {
+ $this->tpl->assign('plugin_options',$options);
+ $this->tpl->assign('options',$poptions);
+ } else {
+ $this->nextStep(2,'','id='.$plugin);
+ }
+ $this->tpl->assign('gid',$group);
+ $this->tpl->assign('pluginname',$plugin);
+ } else {
+ $this->nextStep(1);
+ }
}
function pluginoptiondelete() {
+ global $_GET;
+
+ if (isset($_GET['id'])) {
+ app()->db->delete('plugin_options',array('group_name' => $_GET['gid'], 'plugin' => $_GET['id']));
+ $this->nextStep(2,'','id='.$_GET['id']);
+ }
}
function settings() {
@@ -519,11 +609,11 @@
app()->db->insert('banned',$ban);
app()->message(tr('IP %1 has been banned!',$ip));
if (isset($_GET['nextaction']))
- redirect('?action='.$_GET['nextaction']);
+ $this->nextStep(1,$_GET['nextaction']);
} else {
app()->error(tr('IP %1 was already in state: %2!',$ip,$ban['access']));
if (isset($_GET['newaction']))
- redirect('?action='.$_GET['newaction']);
+ $this->nextStep(1,$_GET['newaction']);
}
} else if (isset($_POST['addbannedip'])) {
$ip = $_POST['addbannedip'];
Modified: trunk/plugins/mimetypes.inc.php
===================================================================
--- trunk/plugins/mimetypes.inc.php 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/plugins/mimetypes.inc.php 2008-11-06 19:57:33 UTC (rev 124)
@@ -4,14 +4,38 @@
function MimeTypesPlugin() {
$this->description = tr('Limit the mimetypes a user can upload');
+ $this->options = array(
+ array('name' => 'allowed', 'description' => tr('Allowed mime types'), 'type' => 'list'),
+ array('name' => 'message', 'description' => tr('Types in message'), 'type' => 'text'),
+ );
+ /* load the plugin configuration */
}
+ function getGroup() {
+ $group = app()->user->group();
+ if (is_array($group)) {
+ /* check for which group there is a configuration */
+ foreach ($group as $g) {
+ if (isset($this->config['allowed'][$g])) {
+ if (count($this->config['allowed'])) {
+ return $g;
+ }
+ }
+ }
+ return $group[0];
+ } else {
+ return $group;
+ }
+ }
+
function uploadForm(&$finfo,$acl) {
if ($acl!='enable') return true;
- if (count(app()->config['mimetypes'])==0) {
+ $group = $this->getGroup();
+ if (count($this->config['allowed'][$group])==0) {
app()->error(tr('WARNING: no mime types defined. Plugin has been disabled!'));
} else {
- $this->assign('mimetypes',app()->config['mimetypes']);
+ $this->assign('message',$this->config['message'][$group]);
+ $this->assign('mimetypes',$this->config['allowed'][$group]);
$this->display('uploadForm');
}
return true;
@@ -19,9 +43,10 @@
function uploadOptions(&$finfo,$acl) {
if ($acl!='enable') return true;
- if (count(app()->config['mimetypes'])==0) {
+ $group = $this->getGroup();
+ if (count($this->config['allowed'][$group])==0) {
app()->error(tr('WARNING: no mime types defined. Plugin has been disabled!'));
- } else if (array_search($finfo['mime'],app()->config['mimetypes'])===FALSE) {
+ } else if (array_search($finfo['mime'],$this->config['allowed'][$group])===FALSE) {
app()->error(tr('This file type (%1) is not allowed on this site!',$finfo['mime']));
return false;
}
Modified: trunk/templates/default/modules/admin/groups.tpl
===================================================================
--- trunk/templates/default/modules/admin/groups.tpl 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/templates/default/modules/admin/groups.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -7,9 +7,9 @@
<table border="0" id="dbtable">
<tr>
<th width="10">S</th>
- <th width="100">Name</th>
- <th width="200">Description</th>
- <th width="100">Actions</th>
+ <th width="100">{tr}Group Name{/tr}</th>
+ <th>width="200">{tr}Description{/tr}</th>
+ <th width="100">{tr}Actions{/tr}</th>
</tr>
{foreach from=$groups item=g}
{cycle values="row1,row2" advance=true assign=rid}
Added: trunk/templates/default/modules/admin/pluginoptionadd.tpl
===================================================================
--- trunk/templates/default/modules/admin/pluginoptionadd.tpl (rev 0)
+++ trunk/templates/default/modules/admin/pluginoptionadd.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -0,0 +1,27 @@
+{include file="default/modules/admin/adminmenu.tpl"}
+
+<form action="{$script}" method="post">
+<input type="hidden" name="action" value="{$action}">
+<input type="hidden" name="step" value="{$step}">
+<input type="hidden" name="id" value="{$pluginname}">
+<table border="0">
+<tr><td>{tr}Group{/tr}:</td><td>
+ <select name="gid">
+ {foreach from=$groups item=g}
+ <option value="{$g.name}">{$g.description}</option>
+ {/foreach}
+ </select></td>
+</tr>
+{foreach from=$options item=o}
+<tr><td valign="top">{$o.description}:</td><td>
+{if $o.type=='list'}
+<textarea cols="40" rows="6" name="{$o.name}">
+{$plugin_options[$o.name].value}
+</textarea>
+{elseif $o.type=='text'}
+<input type="text" name="{$o.name}" value="{$plugin_options[$o.name].value}"></td></tr>
+{/if}
+{/foreach}
+<tr><td colspan="2" align=right><input type="submit" class="submit" value="{tr}Confirm{/tr}"></td></tr>
+</table>
+</form>
\ No newline at end of file
Added: trunk/templates/default/modules/admin/pluginoptiondetail.tpl
===================================================================
--- trunk/templates/default/modules/admin/pluginoptiondetail.tpl (rev 0)
+++ trunk/templates/default/modules/admin/pluginoptiondetail.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -0,0 +1,38 @@
+{include file="default/modules/admin/adminmenu.tpl"}
+<h3>{$pluginname}</h3>
+
+{if count($options)==0}
+<div id="message">{tr}Plugin does not have any option to be configured{/tr}</div>
+{else}
+<div id="toolbar">
+<a href="{$script}?action={$action}&step=3&id={$pluginname}"><img src="{tpl file=/img/admin/tadd.png}"></a>
+<img src="{tpl file=/img/admin/tdelete.png}">
+</div>
+<br>
+<table border="0" id="dbtable">
+ <tr>
+ <th width="150">{tr}Group{/tr}</th>
+{foreach from=$options item=o}
+ <th width="200">{$o.description}</th>
+{/foreach}
+ <th width="80">{tr}Actions{/tr}</th>
+ </tr>
+{foreach from=$groups item=g}
+ {cycle values="row1,row2" advance=true assign=rid}
+ {if isset($plugin_options[$g.name])}
+ <tr>
+ <td id="{$rid}" style="text-align:left; vertical-align: top;">
+ <a href="{$script}?action={$action}&step=4&id={$pluginname}&gid={$g.name}">{$g.name}</a></td>
+ {foreach from=$options item=o}
+ <td id="{$rid}" style="text-align:left; vertical-align: top;"><pre>{$plugin_options[$g.name][$o.name].value}</pre></td>
+ {/foreach}
+ <td id="{$rid}" style="text-align:justify">
+ <a href="{$script}?action={$action}&step=4&id={$pluginname}&gid={$g.name}"><img src="{tpl file=/img/admin/edit_plugin.png}"></a>
+
+ <a href="{$script}?action={$action}&step=5&id={$pluginname}&gid={$g.name}"><img src="{tpl file=/img/admin/delete.png}"></a></td>
+ </td>
+ </tr>
+ {/if}
+{/foreach}
+</table>
+{/if}
\ No newline at end of file
Added: trunk/templates/default/modules/admin/pluginoptionedit.tpl
===================================================================
--- trunk/templates/default/modules/admin/pluginoptionedit.tpl (rev 0)
+++ trunk/templates/default/modules/admin/pluginoptionedit.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -0,0 +1,19 @@
+{include file="default/modules/admin/adminmenu.tpl"}
+
+<form action="{$script}" method="post">
+<input type="hidden" name="action" value="{$action}">
+<input type="hidden" name="step" value="{$step}">
+<input type="hidden" name="id" value="{$pluginname}">
+<input type="hidden" name="gid" value="{$gid}">
+<table border="0">
+<tr><td>{tr}Group{/tr}:</td><td>{$gid}</td></tr>
+{foreach from=$options item=o}
+<tr><td valign="top">{$o.description}:</td><td>{if $o.type=='list'}
+<textarea cols="40" rows="6" name="{$o.name}">{$plugin_options[$o.name].value}</textarea>
+{elseif $o.type=='text'}
+<input type="text" name="{$o.name}" value="{$plugin_options[$o.name].value}"></td></tr>
+{/if}
+{/foreach}
+<tr><td colspan="2" align=right><input type="submit" class="submit" value="{tr}Confirm{/tr}"></td></tr>
+</table>
+</form>
\ No newline at end of file
Modified: trunk/templates/default/modules/admin/pluginoptions.tpl
===================================================================
--- trunk/templates/default/modules/admin/pluginoptions.tpl 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/templates/default/modules/admin/pluginoptions.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -1,4 +1,5 @@
{include file="default/modules/admin/adminmenu.tpl"}
+<br>
<table border="0" id="dbtable">
<tr>
<th width="100">Plugin</th>
Modified: trunk/templates/default/modules/admin/rights.tpl
===================================================================
--- trunk/templates/default/modules/admin/rights.tpl 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/templates/default/modules/admin/rights.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -2,9 +2,9 @@
<br>
<table border="0" id="dbtable">
<tr>
- <th width="100">Name</th>
- <th width="200">Description</th>
- <th width="100">Rights set?</th>
+ <th width="100">{tr}Gruppo{/tr}</th>
+ <th width="200">{tr}Description{/tr}</th>
+ <th width="100">{tr}Rights set?{/tr}</th>
</tr>
{foreach from=$groups item=g}
{cycle values="row1,row2" advance=true assign=rid}
Modified: trunk/templates/default/plugins/mimetypes/uploadForm.tpl
===================================================================
--- trunk/templates/default/plugins/mimetypes/uploadForm.tpl 2008-11-06 14:12:08 UTC (rev 123)
+++ trunk/templates/default/plugins/mimetypes/uploadForm.tpl 2008-11-06 19:57:33 UTC (rev 124)
@@ -1 +1,4 @@
-<div id="mime">{tr}Only the following mime types are allowed{/tr} ({foreach from=$mimetypes item=m}{$m}, {/foreach})</div>
\ No newline at end of file
+<div id="mime">{tr}Only the following mime types are allowed{/tr} (
+{if $message!=''}{$message}
+{else}{foreach from=$mimetypes item=m}{$m}, {/foreach}{/if}
+)</div>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|