prepare for OS file storage, and add bbcode attachment link to mod/filestorage. This isn't beautiful, but it's a start.
This commit is contained in:
parent
41df51a815
commit
5a5466346c
@ -188,13 +188,13 @@ function attach_by_hash($hash,$rev = 0) {
|
|||||||
$sql_extra = permissions_sql($r[0]['uid']);
|
$sql_extra = permissions_sql($r[0]['uid']);
|
||||||
|
|
||||||
// Now we'll see if we can access the attachment
|
// Now we'll see if we can access the attachment
|
||||||
dbg(1);
|
|
||||||
|
|
||||||
$r = q("SELECT * FROM attach WHERE hash = '%s' and uid = %d $sql_extra LIMIT 1",
|
$r = q("SELECT * FROM attach WHERE hash = '%s' and uid = %d $sql_extra LIMIT 1",
|
||||||
dbesc($hash),
|
dbesc($hash),
|
||||||
intval($r[0]['uid'])
|
intval($r[0]['uid'])
|
||||||
);
|
);
|
||||||
dbg(0);
|
|
||||||
if(! $r) {
|
if(! $r) {
|
||||||
$ret['message'] = t('Permission denied.');
|
$ret['message'] = t('Permission denied.');
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -672,3 +672,9 @@ function attach_change_permissions($channel_id,$resource,$allow_cid,$allow_gid,$
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function pipe_streams($in, $out) {
|
||||||
|
$size = 0;
|
||||||
|
while (!feof($in))
|
||||||
|
$size += fwrite($out,fread($in,8192));
|
||||||
|
return $size;
|
||||||
|
}
|
@ -376,11 +376,16 @@ class RedFile extends DAV\Node implements DAV\IFile {
|
|||||||
function get() {
|
function get() {
|
||||||
logger('RedFile::get: ' . basename($this->name));
|
logger('RedFile::get: ' . basename($this->name));
|
||||||
|
|
||||||
$r = q("select data from attach where hash = '%s' and uid = %d limit 1",
|
$r = q("select data, flags from attach where hash = '%s' and uid = %d limit 1",
|
||||||
dbesc($this->data['hash']),
|
dbesc($this->data['hash']),
|
||||||
intval($this->data['uid'])
|
intval($this->data['uid'])
|
||||||
);
|
);
|
||||||
if($r) return $r[0]['data'];
|
if($r) {
|
||||||
|
if($r[0]['flags'] & ATTACH_FLAG_OS ) {
|
||||||
|
return fopen($r[0]['data'],'rb');
|
||||||
|
}
|
||||||
|
return $r[0]['data'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,13 @@ function attach_init(&$a) {
|
|||||||
|
|
||||||
header('Content-type: ' . $r['data']['filetype']);
|
header('Content-type: ' . $r['data']['filetype']);
|
||||||
header('Content-disposition: attachment; filename=' . $r['data']['filename']);
|
header('Content-disposition: attachment; filename=' . $r['data']['filename']);
|
||||||
if($r['data']['flags'] & ATTACH_FLAG_OS )
|
if($r['data']['flags'] & ATTACH_FLAG_OS ) {
|
||||||
echo @file_get_contents($r['data']['data']);
|
$stream = fopen($r['data']['data'],'rb');
|
||||||
|
if($stream) {
|
||||||
|
pipe_stream($stream,STDOUT);
|
||||||
|
fclose($stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
echo $r['data']['data'];
|
echo $r['data']['data'];
|
||||||
killme();
|
killme();
|
||||||
|
@ -137,7 +137,9 @@ function filestorage_content(&$a) {
|
|||||||
'id' => $rr['id'],
|
'id' => $rr['id'],
|
||||||
'download' => $rr['hash'],
|
'download' => $rr['hash'],
|
||||||
'title' => $rr['filename'],
|
'title' => $rr['filename'],
|
||||||
'size' => $rr['filesize']
|
'size' => $rr['filesize'],
|
||||||
|
'rev' => $rr['revision']
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
{{foreach $files as $key => $items}}
|
{{foreach $files as $key => $items}}
|
||||||
{{foreach $items as $item}}
|
{{foreach $items as $item}}
|
||||||
<div class="files-list-item">
|
<div class="files-list-item">
|
||||||
<a href="attach/{{$item.download}}">{{$download}}</a> |
|
<a href="{{$baseurl}}/{{$item.id}}/edit">{{$edit}}</a> |
|
||||||
<a href="{{$baseurl}}/{{$item.id}}/edit">{{$edit}} |
|
<a href="{{$baseurl}}/{{$item.id}}/delete">{{$delete}}</a> |
|
||||||
<a href="{{$baseurl}}/{{$item.id}}/delete">{{$delete}}
|
[attachment]{{$item.download}},{{$item.rev}}[/attachment] |
|
||||||
<a href="page/{{$channel}}/{{$item.title}}">{{$title}}</a> {{$item.title}} |
|
<a href="attach/{{$item.download}}">{{$item.title}}</a> |
|
||||||
{{$item.size}} bytes
|
{{$item.size}} bytes
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user