[Openupload-svn-update] SF.net SVN: openupload:[190] trunk
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-12-11 12:40:18
|
Revision: 190
http://openupload.svn.sourceforge.net/openupload/?rev=190&view=rev
Author: tsdogs
Date: 2008-12-11 12:40:04 +0000 (Thu, 11 Dec 2008)
Log Message:
-----------
added extended read api + some fixes for txtdb to work
Modified Paths:
--------------
trunk/lib/modules/db/pgsql.inc.php
trunk/lib/modules/db/txt.inc.php
trunk/lib/modules/default/admin.inc.php
trunk/lib/modules/default/files.inc.php
trunk/plugins/expire.inc.php
trunk/templates/default/modules/admin/maintenance.tpl
Added Paths:
-----------
trunk/sql/txt/activitylog.txt
trunk/templates/default/plugins/expire/
Modified: trunk/lib/modules/db/pgsql.inc.php
===================================================================
--- trunk/lib/modules/db/pgsql.inc.php 2008-12-11 11:06:59 UTC (rev 189)
+++ trunk/lib/modules/db/pgsql.inc.php 2008-12-11 12:40:04 UTC (rev 190)
@@ -112,6 +112,50 @@
return $result;
}
+ /* This is an extended function which extends the select criteria */
+ function readex($tbl,$criteria = array(), $sort = array(),$limit = '') {
+ $sql = 'SELECT * FROM "'.$this->prefix.$tbl.'"';
+
+ if (count($criteria)>0) {
+ $where = '';
+ foreach ($criteria as $ands) {
+ $where_save = $where;
+ $where = '';
+ foreach ($ands as $v) {
+ if ($where != '') $where .= ' AND ';
+ $where .= '"'.$v[0].'"'.$v[1].'\''.(pg_escape_string($v[2])).'\'';
+ }
+ if ($where_save!='') {
+ $where = $where_save.' OR ('.$where.')';
+ } else {
+ $where = '('.$where.')';
+ }
+ }
+ $sql .= ' WHERE '.$where;
+ }
+ if (count($sort)>0) {
+ $sorting = '';
+ foreach ($sort as $s) {
+ if ($sorting!='') $sorting.=',';
+ $sorting .= $s;
+ }
+ $sql .= ' ORDER BY '.$sorting;
+ }
+ if ($limit != '') {
+ $l = explode(',',$limit);
+ $sql .= ' LIMIT '.$l[1].' OFFSET '.$l[0];
+ }
+echo $sql;
+ $res = pg_query($sql);
+ if (!$res) { die('query failed: '.$sql); }
+ $result = array();
+ while ($row = pg_fetch_assoc($res)) {
+ $result[] = $row;
+ }
+ pg_free_result($res);
+ return $result;
+ }
+
function insert($tbl,$values,$fields = array()) {
$sql = 'INSERT INTO "'.$this->prefix.$tbl.'"';
$flist = '';
Modified: trunk/lib/modules/db/txt.inc.php
===================================================================
--- trunk/lib/modules/db/txt.inc.php 2008-12-11 11:06:59 UTC (rev 189)
+++ trunk/lib/modules/db/txt.inc.php 2008-12-11 12:40:04 UTC (rev 190)
@@ -12,7 +12,7 @@
"files" => array (
"type" => "file",
"fields" => array (
- "id", "name", "mime", "description", "size", "remove", "user_id", "ip", "upload_date",
+ "id", "name", "mime", "description", "size", "remove", "user_login", "ip", "upload_date",
)
),
"users" => array (
@@ -69,6 +69,13 @@
),
"auto_increment" => "id",
),
+ "activitylog" => array (
+ "type" => "file",
+ "fields" => array (
+ "id", "level", "log_time", "ip", "user_login", "module", "action", "realaction", "plugin", "result", "moreinfo",
+ ),
+ "auto_increment" => "id",
+ ),
);
$this->baseDir=$config['rootdir'];
$this->prefix=$config['prefix'];
@@ -201,6 +208,58 @@
return $result;
}
+ /* This is an extended function which extends the select criteria */
+ function readex($tbl,$criteria = array(), $sort = array(),$limit = '') {
+ $file = $this->baseDir.'/'.$this->prefix.$tbl;
+ if ($this->tables[$tbl]['type']=='dir') {
+
+ } else {
+ $result = array();
+ $rows = $this->readTxt($file.'.txt');
+ foreach ($rows as $row) {
+ $add = false;
+ if (count($criteria)>0) {
+ foreach ($criteria as $ands) {
+ $andres = true;
+ foreach ($ands as $v) {
+ switch($v[1]) {
+ case '=':
+ $sres = $row[$v[0]]==$v[2];
+ break;
+ case '<':
+ $sres = $row[$v[0]]<$v[2];
+ break;
+ case '>':
+ $sres = $row[$v[0]]>$v[2];
+ break;
+ case '<=':
+ $sres = $row[$v[0]]<=$v[2];
+ break;
+ case '>=':
+ $sres = $row[$v[0]]>=$v[2];
+ break;
+ case '!=':
+ $sres = $row[$v[0]]!=$v[2];
+ break;
+ default:
+ app()->error(tr('Unsupported query criteria %1',$v[1]));
+ return array();
+ }
+ $andres = ($andres and $sres)?true:false;
+ }
+ $add = ($add or $andres)?true:false;
+ }
+ } else {
+ $add = true;
+ }
+ if ($add) {
+ $result[] = $row;
+ }
+ }
+ }
+ return $result;
+ }
+
function insert($tbl,$values,$fields = array()) {
$file = $this->baseDir.'/'.$tbl;
if ($this->tables[$tbl]['type']=='dir') {
Modified: trunk/lib/modules/default/admin.inc.php
===================================================================
--- trunk/lib/modules/default/admin.inc.php 2008-12-11 11:06:59 UTC (rev 189)
+++ trunk/lib/modules/default/admin.inc.php 2008-12-11 12:40:04 UTC (rev 190)
@@ -484,7 +484,8 @@
if (isset($_POST['expire'])) {
/* get all the files which have an expire date */
$files = app()->db->readex('file_options',array(array(array('name','=','expire'),
- array('value','<=',date('Y-m-d',time()-(24 * 60 * 60))))));
+ array('value','<=',date('Y-m-d',time()-(24 * 60 * 60))),
+ array('value','!=',''))));
$result = array();
foreach ($files as $f) {
$result[]['id']=$f['file_id'];
@@ -503,7 +504,8 @@
break;
case 'older': $criteria[] = array('upload_date','<', date('Y-m-d',time()-($_POST[$n] * 24 * 60 * 60)));
break;
- case 'date': $criteria[] = array('upload_date','=', $_POST[$n]);
+ case 'date': $criteria[] = array('upload_date','>=', date('Y-m-d',(strtotime($_POST[$n]))));
+ $criteria[] = array('upload_date','<', date('Y-m-d',(strtotime($_POST[$n])+24*60*60)));
break;
case 'size': $criteria[] = array('size','>', $_POST[$n]*1024*1024);
break;
Modified: trunk/lib/modules/default/files.inc.php
===================================================================
--- trunk/lib/modules/default/files.inc.php 2008-12-11 11:06:59 UTC (rev 189)
+++ trunk/lib/modules/default/files.inc.php 2008-12-11 12:40:04 UTC (rev 190)
@@ -211,11 +211,13 @@
foreach (app()->plugins as $plugin) {
if (count($plugin->fields)>0) {
foreach ($plugin->fields as $f) {
- $pinfo['file_id'] = $finfo['id'];
- $pinfo['module'] = $plugin->name;
- $pinfo['name']=$f;
- $pinfo['value']=$finfo[$f];
- app()->db->insert('file_options',$pinfo,array('file_id','module','name','value'));
+ if (isset($finfo[$f])) {
+ $pinfo['file_id'] = $finfo['id'];
+ $pinfo['module'] = $plugin->name;
+ $pinfo['name']=$f;
+ $pinfo['value']=$finfo[$f];
+ app()->db->insert('file_options',$pinfo,array('file_id','module','name','value'));
+ }
}
}
}
Modified: trunk/plugins/expire.inc.php
===================================================================
--- trunk/plugins/expire.inc.php 2008-12-11 11:06:59 UTC (rev 189)
+++ trunk/plugins/expire.inc.php 2008-12-11 12:40:04 UTC (rev 190)
@@ -10,7 +10,7 @@
$this->fields = array('expire');
}
- function uploadComplete(&$finfo,$acl) {
+ function uploadForm(&$finfo,$acl) {
if ($acl!='enable') return true;
$group = $this->getGroup('days');
/* now set */
@@ -18,7 +18,23 @@
$this->config['days'][$group]=$this->config['days']['*'];
}
if ($this->config['days'][$group]>0) {
+ $this->assign('msg',tr('Files will be kept on our server for %1 days',$this->config['days'][$group]));
+ $this->display('uploadForm');
+ }
+ return true;
+ }
+
+ function uploadConfirm(&$finfo,$acl) {
+ if ($acl!='enable') return true;
+ $group = $this->getGroup('days');
+ /* now set */
+ if (!isset($this->config['days'][$group]) and isset($this->config['days']['*'])>0) {
+ $this->config['days'][$group]=$this->config['days']['*'];
+ }
+ if ($this->config['days'][$group]>0) {
$finfo[0]['expire']=date('Y-m-d',time()+($this->config['days'][$group]*24*60*60));
+ } else {
+ $finfo[0]['expire']='9999-12-31';
}
return true;
}
Added: trunk/sql/txt/activitylog.txt
===================================================================
--- trunk/sql/txt/activitylog.txt (rev 0)
+++ trunk/sql/txt/activitylog.txt 2008-12-11 12:40:04 UTC (rev 190)
@@ -0,0 +1 @@
+id|level|log_time|ip|user_login|module|action|realaction|plugin|result|moreinfo
Modified: trunk/templates/default/modules/admin/maintenance.tpl
===================================================================
--- trunk/templates/default/modules/admin/maintenance.tpl 2008-12-11 11:06:59 UTC (rev 189)
+++ trunk/templates/default/modules/admin/maintenance.tpl 2008-12-11 12:40:04 UTC (rev 190)
@@ -10,7 +10,7 @@
<input type="hidden" name="action" value="{$action}">
<input type="hidden" name="step" value="2">
<table border="0">
-<tr><td><input type="checkbox" name="c_older" value="1" {if $criteria.c_older==1}checked{/if}> {tr}Delete files older than{/tr}</td><td><input size="4" type="text" name="older" value="{$criteria.days}"> {tr}days{/tr}</td></tr>
+<tr><td><input type="checkbox" name="c_older" value="1" {if $criteria.c_older==1}checked{/if}> {tr}Delete files older than{/tr}</td><td><input size="4" type="text" name="older" value="{$criteria.older}"> {tr}days{/tr}</td></tr>
<tr><td><input type="checkbox" name="c_login" value="1" {if $criteria.c_login==1}checked{/if}> {tr}Which user name is{/tr}:</td><td>
{if isset($users)}
<select name="login">
@@ -22,7 +22,7 @@
<input size="20" type="text" name="login" value="{$criteria.login}">
{/if}</td></tr>
<tr><td><input type="checkbox" name="c_date" value="1" {if $criteria.c_date==1}checked{/if}> {tr}Which upload day is{/tr}:</td><td><input size="14" type="text" name="date" value="{$criteria.date}"> (yyyy-mm-dd)</td></tr>
-<tr><td><input type="checkbox" name="c_size" value="1" {if $criteria.c_size==1}checked{/if}> {tr}Which size is bigger than{/tr}:</td><td><input size="10" type="text" name="size" value=""> MB</td></tr>
+<tr><td><input type="checkbox" name="c_size" value="1" {if $criteria.c_size==1}checked{/if}> {tr}Which size is bigger than{/tr}:</td><td><input size="10" type="text" name="size" value="{$criteria.size}"> MB</td></tr>
<tr><td colspan="2"> </td>
<tr><td colspan="2" align="left"><input type="submit" class="submit" name="run" value="{tr}Proceed{/tr}"></td>
</table>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|