aboutsummaryrefslogtreecommitdiffstats
path: root/include/RedDAV
diff options
context:
space:
mode:
Diffstat (limited to 'include/RedDAV')
-rw-r--r--include/RedDAV/RedDirectory.php110
-rw-r--r--include/RedDAV/RedFile.php67
2 files changed, 129 insertions, 48 deletions
diff --git a/include/RedDAV/RedDirectory.php b/include/RedDAV/RedDirectory.php
index 922be378d..507fde46f 100644
--- a/include/RedDAV/RedDirectory.php
+++ b/include/RedDAV/RedDirectory.php
@@ -50,7 +50,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
*/
public function __construct($ext_path, &$auth_plugin) {
// $ext_path = urldecode($ext_path);
- //logger('directory ' . $ext_path, LOGGER_DATA);
+ logger('directory ' . $ext_path, LOGGER_DATA);
$this->ext_path = $ext_path;
// remove "/cloud" from the beginning of the path
$modulename = get_app()->module;
@@ -80,7 +80,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
* @return array \Sabre\DAV\INode[]
*/
public function getChildren() {
- //logger('children for ' . $this->ext_path, LOGGER_DATA);
+ logger('children for ' . $this->ext_path, LOGGER_DATA);
$this->log();
if (get_config('system', 'block_public') && (! $this->auth->channel_id) && (! $this->auth->observer)) {
@@ -200,9 +200,8 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
$mimetype = z_mime_content_type($name);
- $c = q("SELECT * FROM channel WHERE channel_id = %d AND NOT (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)
);
if (! $c) {
@@ -213,28 +212,55 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
$filesize = 0;
$hash = random_string();
- $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, folder, flags, filetype, filesize, revision, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
- VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ $f = 'store/' . $this->auth->owner_nick . '/' . (($this->os_path) ? $this->os_path . '/' : '') . $hash;
+
+ $direct = null;
+
+ if($this->folder_hash) {
+ $r = q("select * from attach where hash = '%s' and is_dir = 1 and uid = %d limit 1",
+ dbesc($this->folder_hash),
+ intval($c[0]['channel_id'])
+ );
+ if($r)
+ $direct = $r[0];
+ }
+
+ if(($direct) && (($direct['allow_cid']) || ($direct['allow_gid']) || ($direct['deny_cid']) || ($direct['deny_gid']))) {
+ $allow_cid = $direct['allow_cid'];
+ $allow_gid = $direct['allow_gid'];
+ $deny_cid = $direct['deny_cid'];
+ $deny_gid = $direct['deny_gid'];
+ }
+ else {
+ $allow_cid = $c[0]['channel_allow_cid'];
+ $allow_gid = $c[0]['channel_allow_gid'];
+ $deny_cid = $c[0]['channel_deny_cid'];
+ $deny_gid = $c[0]['channel_deny_gid'];
+ }
+
+ $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, folder, os_storage, filetype, filesize, revision, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
+ VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($c[0]['channel_account_id']),
intval($c[0]['channel_id']),
dbesc($hash),
dbesc($this->auth->observer),
dbesc($name),
dbesc($this->folder_hash),
- dbesc(ATTACH_FLAG_OS),
+ intval(1),
dbesc($mimetype),
intval($filesize),
intval(0),
+ intval($is_photo),
dbesc($this->os_path . '/' . $hash),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
- dbesc($c[0]['channel_allow_cid']),
- dbesc($c[0]['channel_allow_gid']),
- dbesc($c[0]['channel_deny_cid']),
- dbesc($c[0]['channel_deny_gid'])
+ dbesc($allow_cid),
+ dbesc($allow_gid),
+ dbesc($deny_cid),
+ dbesc($deny_gid)
);
- $f = 'store/' . $this->auth->owner_nick . '/' . (($this->os_path) ? $this->os_path . '/' : '') . $hash;
+
// returns the number of bytes that were written to the file, or FALSE on failure
$size = file_put_contents($f, $data);
@@ -248,9 +274,20 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
// returns now
$edited = datetime_convert();
+
+
+ $is_photo = 0;
+ $x = @getimagesize($f);
+ logger('getimagesize: ' . print_r($x,true), LOGGER_DATA);
+ if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) {
+ $is_photo = 1;
+ }
+
+
// updates entry with filesize and timestamp
- $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($hash),
intval($c[0]['channel_id'])
@@ -281,6 +318,23 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
return;
}
}
+
+ if($is_photo) {
+ $album = '';
+ if($this->folder_hash) {
+ $f1 = q("select filename from attach WHERE hash = '%s' AND uid = %d",
+ dbesc($this->folder_hash),
+ intval($c[0]['channel_id'])
+ );
+ if($f1)
+ $album = $f1[0]['filename'];
+ }
+
+ require_once('include/photos.php');
+ $args = array( 'resource_id' => $hash, 'album' => $album, 'os_path' => $f, 'filename' => $name, 'getimagesize' => $x, 'directory' => $direct);
+ $p = photo_upload($c[0],get_app()->get_observer(),$args);
+ }
+
}
/**
@@ -296,9 +350,8 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
throw new DAV\Exception\Forbidden('Permission denied.');
}
- $r = q("SELECT * FROM channel WHERE channel_id = %d AND NOT (channel_pageflags & %d)>0 LIMIT 1",
- intval($this->auth->owner_id),
- intval(PAGE_REMOVED)
+ $r = q("SELECT * FROM channel WHERE channel_id = %d AND channel_removed = 0 LIMIT 1",
+ intval($this->auth->owner_id)
);
if ($r) {
@@ -340,15 +393,14 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
* @return void
*/
function getDir() {
- //logger($this->ext_path, LOGGER_DEBUG);
+
+ logger('GetDir: ' . $this->ext_path, LOGGER_DEBUG);
$this->auth->log();
$modulename = get_app()->module;
$file = $this->ext_path;
$x = strpos($file, '/' . $modulename);
- if ($x === false)
- return;
if ($x === 0) {
$file = substr($file, strlen($modulename) + 1);
}
@@ -367,9 +419,8 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
$channel_name = $path_arr[0];
- $r = q("SELECT channel_id FROM channel WHERE channel_address = '%s' AND NOT ( channel_pageflags & %d )>0 LIMIT 1",
- dbesc($channel_name),
- intval(PAGE_REMOVED)
+ $r = q("SELECT channel_id FROM channel WHERE channel_address = '%s' AND channel_removed = 0 LIMIT 1",
+ dbesc($channel_name)
);
if (! $r) {
@@ -385,14 +436,12 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
$os_path = '';
for ($x = 1; $x < count($path_arr); $x++) {
- $r = q("select id, hash, filename, flags from attach where folder = '%s' and filename = '%s' and uid = %d and (flags & %d)>0",
+ $r = q("select id, hash, filename, flags, is_dir from attach where folder = '%s' and filename = '%s' and uid = %d and is_dir != 0",
dbesc($folder),
dbesc($path_arr[$x]),
- intval($channel_id),
- intval(ATTACH_FLAG_DIR)
+ intval($channel_id)
);
-
- if ($r && ( $r[0]['flags'] & ATTACH_FLAG_DIR)) {
+ if ($r && intval($r[0]['is_dir'])) {
$folder = $r[0]['hash'];
if (strlen($os_path))
$os_path .= '/';
@@ -445,9 +494,8 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
$free = disk_free_space('store');
if ($this->auth->owner_id) {
- $c = q("select * from channel where channel_id = %d and not (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)
);
$ulimit = service_class_fetch($c[0]['channel_id'], 'attach_upload_limit');
diff --git a/include/RedDAV/RedFile.php b/include/RedDAV/RedFile.php
index b7aa5473a..ec6871a69 100644
--- a/include/RedDAV/RedFile.php
+++ b/include/RedDAV/RedFile.php
@@ -49,7 +49,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
$this->data = $data;
$this->auth = $auth;
- //logger(print_r($this->data, true), LOGGER_DATA);
+ logger(print_r($this->data, true), LOGGER_DATA);
}
/**
@@ -97,24 +97,49 @@ 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 * 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'];
+ $direct = $f1[0];
+ }
+ }
+ $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 +158,20 @@ 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) {
+ require_once('include/photos.php');
+ $args = array( 'resource_id' => $this->data['hash'], 'album' => $album, 'os_path' => $f, 'filename' => $r[0]['filename'], 'getimagesize' => $gis, 'directory' => $direct );
+ $p = photo_upload($c[0],get_app()->get_observer(),$args);
+ }
+
// update the folder's lastmodified timestamp
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d",
dbesc($edited),
@@ -178,8 +210,9 @@ class RedFile extends DAV\Node implements DAV\IFile {
*/
public function get() {
logger('get file ' . basename($this->name), LOGGER_DEBUG);
+ logger('os_path: ' . $this->os_path, LOGGER_DATA);
- $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 +225,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 +304,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.');
}
}