cleanup mod/filestorage before embarking on further changes to it

This commit is contained in:
friendica 2014-01-06 13:37:25 -08:00
parent 323fc1f9a5
commit e20fef3903

View File

@ -10,62 +10,66 @@ function filestorage_content(&$a) {
return; return;
} }
$r = q("select channel_id from channel where channel_address = '%s'", $r = q("select channel_id from channel where channel_address = '%s'",
dbesc($which) dbesc($which)
); );
if($r) { if($r) {
$owner = intval($r[0]['channel_id']); $owner = intval($r[0]['channel_id']);
} }
$observer = $a->get_observer(); $observer = $a->get_observer();
$ob_hash = (($observer) ? $observer['xchan_hash'] : ''); $ob_hash = (($observer) ? $observer['xchan_hash'] : '');
$perms = get_all_perms($owner,$ob_hash); $perms = get_all_perms($owner,$ob_hash);
if(! $perms['view_storage']) { if(! $perms['view_storage']) {
notice( t('Permission denied.') . EOL); notice( t('Permission denied.') . EOL);
return; return;
} }
// Since we have ACL'd files in the wild, but don't have ACL here yet, we // Since we have ACL'd files in the wild, but don't have ACL here yet, we
// need to return for anoyne other than the owner, despite the perms check for now. // need to return for anyone other than the owner, despite the perms check for now.
$is_owner = (((local_user()) && ($owner == local_user())) ? true : false); $is_owner = (((local_user()) && ($owner == local_user())) ? true : false);
if (! $is_owner) { if(! $is_owner) {
info( t('Permission Denied.') . EOL ); info( t('Permission Denied.') . EOL );
return; return;
} }
// TODO This will also need to check for files on disk and delete them from there as well as the DB. // TODO This will also need to check for files on disk and delete them from there as well as the DB.
if ((argc() > 3 && argv(3) === 'delete') ? true : false);{
if(! $perms['write_storage']) { if(argc() > 3 && argv(3) === 'delete') {
notice( t('Permission denied. VS.') . EOL); if(! $perms['write_storage']) {
return; notice( t('Permission denied. VS.') . EOL);
return;
} }
$file = argv(2); $file = intval(argv(2));
$r = q("delete from attach where id = '%s' and uid = '%s' limit 1", $r = q("delete from attach where id = %d and uid = %d limit 1",
dbesc($file), dbesc($file),
intval($owner) intval($owner)
); );
goaway(z_root() . '/filestorage' . $which);
} }
$r = q("select * from attach where uid = %d order by filename asc", $r = q("select * from attach where uid = %d order by edited desc",
intval($owner) intval($owner)
); );
$files = null; $files = null;
if($r) { if($r) {
$files = array(); $files = array();
foreach($r as $rr) { foreach($r as $rr) {
$files[$rr['id']][] = array('id' => $rr['id'],'download' => $rr['hash'], 'title' => $rr['filename'], 'size' => $rr['filesize']); $files[$rr['id']][] = array(
} 'id' => $rr['id'],
'download' => $rr['hash'],
'title' => $rr['filename'],
'size' => $rr['filesize']
);
} }
}
$limit = service_class_fetch ($owner,'attach_upload_limit'); $limit = service_class_fetch ($owner,'attach_upload_limit');
$r = q("select sum(filesize) as total from attach where uid = %d ", $r = q("select sum(filesize) as total from attach where uid = %d ",
@ -73,8 +77,8 @@ $r = q("select * from attach where uid = %d order by filename asc",
); );
$used = $r[0]['total']; $used = $r[0]['total'];
$url = z_root() . "/filestorage/" . $which; $url = z_root() . "/filestorage/" . $which;
return $o . replace_macros(get_markup_template("filestorage.tpl"), array( return $o . replace_macros(get_markup_template("filestorage.tpl"), array(
'$baseurl' => $url, '$baseurl' => $url,
'$download' => t('Download'), '$download' => t('Download'),
'$files' => $files, '$files' => $files,
@ -84,7 +88,6 @@ $r = q("select * from attach where uid = %d order by filename asc",
'$usedlabel' => t('Used: '), '$usedlabel' => t('Used: '),
'$limit' => $limit, '$limit' => $limit,
'$limitlabel' => t('Limit: '), '$limitlabel' => t('Limit: '),
)); ));
} }