aboutsummaryrefslogtreecommitdiffstats
path: root/include/RedDAV/RedFile.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/RedDAV/RedFile.php')
-rw-r--r--include/RedDAV/RedFile.php61
1 files changed, 45 insertions, 16 deletions
diff --git a/include/RedDAV/RedFile.php b/include/RedDAV/RedFile.php
index b7aa5473a..b33b30832 100644
--- a/include/RedDAV/RedFile.php
+++ b/include/RedDAV/RedFile.php
@@ -97,24 +97,47 @@ class RedFile extends DAV\Node implements DAV\IFile {
$size = 0;
// @todo only 3 values are needed
- $c = q("SELECT * FROM channel WHERE channel_id = %d AND (channel_pageflags & %d) = 0 LIMIT 1",
- intval($this->auth->owner_id),
- intval(PAGE_REMOVED)
+ $c = q("SELECT * FROM channel WHERE channel_id = %d AND channel_removed = 0 LIMIT 1",
+ intval($this->auth->owner_id)
);
- $r = q("SELECT flags, folder, data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
+ $is_photo = false;
+ $album = '';
+
+ $r = q("SELECT flags, folder, os_storage, filename, is_photo FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($this->data['hash']),
intval($c[0]['channel_id'])
);
if ($r) {
- if ($r[0]['flags'] & ATTACH_FLAG_OS) {
- $fname = dbunescbin($r[0]['data']);
- $f = 'store/' . $this->auth->owner_nick . '/' . (($fname) ? $fname : '');
- // @todo check return value and set $size directly
- @file_put_contents($f, $data);
- $size = @filesize($f);
- logger('filename: ' . $f . ' size: ' . $size, LOGGER_DEBUG);
- } else {
+ if (intval($r[0]['os_storage'])) {
+ $d = q("select folder, data from attach where hash = '%s' and uid = %d limit 1",
+ dbesc($this->data['hash']),
+ intval($c[0]['channel_id'])
+ );
+ if($d) {
+ if($d[0]['folder']) {
+ $f1 = q("select filename from attach where is_dir = 1 and hash = '%s' and uid = %d limit 1",
+ dbesc($d[0]['folder']),
+ intval($c[0]['channel_id'])
+ );
+ if($f1)
+ $album = $f1[0]['filename'];
+ }
+ $fname = dbunescbin($d[0]['data']);
+ $f = 'store/' . $this->auth->owner_nick . '/' . (($fname) ? $fname : '');
+ // @todo check return value and set $size directly
+ @file_put_contents($f, $data);
+ $size = @filesize($f);
+ logger('filename: ' . $f . ' size: ' . $size, LOGGER_DEBUG);
+ }
+ $gis = @getimagesize($f);
+ logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA);
+ if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) {
+ $is_photo = 1;
+ }
+ }
+ else {
+ // this shouldn't happen any more
$r = q("UPDATE attach SET data = '%s' WHERE hash = '%s' AND uid = %d",
dbescbin(stream_get_contents($data)),
dbesc($this->data['hash']),
@@ -133,13 +156,19 @@ class RedFile extends DAV\Node implements DAV\IFile {
// returns now()
$edited = datetime_convert();
- $d = q("UPDATE attach SET filesize = '%s', edited = '%s' WHERE hash = '%s' AND uid = %d",
+ $d = q("UPDATE attach SET filesize = '%s', is_photo = %d, edited = '%s' WHERE hash = '%s' AND uid = %d",
dbesc($size),
+ intval($is_photo),
dbesc($edited),
dbesc($this->data['hash']),
intval($c[0]['channel_id'])
);
+ if($is_photo) {
+ $args = array( 'resource_id' => $this->data['hash'], 'album' => $album, 'os_path' => $f, 'filename' => $r[0]['filename'], 'getimagesize' => $gis );
+ $p = photo_upload($c[0],$this->auth->observer,$args);
+ }
+
// update the folder's lastmodified timestamp
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d",
dbesc($edited),
@@ -179,7 +208,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
public function get() {
logger('get file ' . basename($this->name), LOGGER_DEBUG);
- $r = q("SELECT data, flags, filename, filetype FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
+ $r = q("SELECT data, flags, os_storage, filename, filetype FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($this->data['hash']),
intval($this->data['uid'])
);
@@ -192,7 +221,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
header('Content-type: text/plain');
}
- if ($r[0]['flags'] & ATTACH_FLAG_OS ) {
+ if (intval($r[0]['os_storage'])) {
$f = 'store/' . $this->auth->owner_nick . '/' . (($this->os_path) ? $this->os_path . '/' : '') . dbunescbin($r[0]['data']);
return fopen($f, 'rb');
}
@@ -271,7 +300,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
}
if ($this->auth->owner_id !== $this->auth->channel_id) {
- if (($this->auth->observer !== $this->data['creator']) || ($this->data['flags'] & ATTACH_FLAG_DIR)) {
+ if (($this->auth->observer !== $this->data['creator']) || intval($this->data['is_dir'])) {
throw new DAV\Exception\Forbidden('Permission denied.');
}
}