From d2b4ba7be6adee976972091d4fe11fe08016341b Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Mon, 9 Sep 2013 02:06:21 +0100 Subject: Quick and dirty file storage module. --- mod/filestorage.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 mod/filestorage.php (limited to 'mod') diff --git a/mod/filestorage.php b/mod/filestorage.php new file mode 100644 index 000000000..72112271d --- /dev/null +++ b/mod/filestorage.php @@ -0,0 +1,73 @@ + 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + $a->error = 404; + return; + } + + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + } + + $is_owner = (((local_user()) && ($owner == local_user())) ? true : false); + if (! $is_owner) { + info( t('Permission Denied.') . EOL ); + return; + } + if ((argc() > 3 && argv(3) === 'delete') ? true : false);{ + $file = argv(2); + $r = q("delete from attach where id = '%s' and uid = '%s' limit 1", + dbesc($file), + intval($owner) + ); + + + } + + +$r = q("select * from attach where uid = %d order by filename asc", + intval($owner) +); + + $files = null; + + if($r) { + $files = array(); + foreach($r as $rr) { + $files[$rr['id']][] = array('id' => $rr['id'],'download' => $rr['hash'], 'title' => $rr['filename'], 'size' => $rr['filesize']); + } + } + + + $limit = service_class_fetch ($owner,'attach_upload_limit'); +// if($limit !== false) { + $r = q("select sum(filesize) as total from attach where uid = %d ", + intval($owner) + ); + $used = $r[0]['total']; +//} + logger('limit: ' . print_r($limit,true)); + + $url = z_root() . "/filestorage/" . $which; + return $o . replace_macros(get_markup_template("filestorage.tpl"), array( + '$baseurl' => $url, + '$download' => t('Download'), + '$files' => $files, + '$channel' => $which, + '$delete' => t('Delete'), + '$used' => $used, + '$usedlabel' => t('Used: '), + '$limit' => $limit, + '$limitlabel' => t('Limit: '), + )); + + +} -- cgit v1.2.3 From 256ee236ad53beb1bc3fec43d716ce25856f618d Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Mon, 9 Sep 2013 02:11:26 +0100 Subject: Kill logger --- mod/filestorage.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'mod') diff --git a/mod/filestorage.php b/mod/filestorage.php index 72112271d..41055f98e 100644 --- a/mod/filestorage.php +++ b/mod/filestorage.php @@ -48,13 +48,10 @@ $r = q("select * from attach where uid = %d order by filename asc", $limit = service_class_fetch ($owner,'attach_upload_limit'); -// if($limit !== false) { $r = q("select sum(filesize) as total from attach where uid = %d ", intval($owner) ); $used = $r[0]['total']; -//} - logger('limit: ' . print_r($limit,true)); $url = z_root() . "/filestorage/" . $which; return $o . replace_macros(get_markup_template("filestorage.tpl"), array( -- cgit v1.2.3