more file/photo merge work
This commit is contained in:
parent
9642728e7d
commit
f0b255b1a9
@ -213,12 +213,8 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
|
|||||||
$filesize = 0;
|
$filesize = 0;
|
||||||
$hash = random_string();
|
$hash = random_string();
|
||||||
|
|
||||||
$is_photo = 0;
|
$f = 'store/' . $this->auth->owner_nick . '/' . (($this->os_path) ? $this->os_path . '/' : '') . $hash;
|
||||||
$x = @getimagesize($src);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
$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 )
|
$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' ) ",
|
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
|
||||||
@ -242,7 +238,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
|
|||||||
dbesc($c[0]['channel_deny_gid'])
|
dbesc($c[0]['channel_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
|
// returns the number of bytes that were written to the file, or FALSE on failure
|
||||||
$size = file_put_contents($f, $data);
|
$size = file_put_contents($f, $data);
|
||||||
@ -256,9 +252,20 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
|
|||||||
// returns now
|
// returns now
|
||||||
$edited = datetime_convert();
|
$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
|
// 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),
|
dbesc($size),
|
||||||
|
intval($is_photo),
|
||||||
dbesc($edited),
|
dbesc($edited),
|
||||||
dbesc($hash),
|
dbesc($hash),
|
||||||
intval($c[0]['channel_id'])
|
intval($c[0]['channel_id'])
|
||||||
@ -289,6 +296,13 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($is_photo) {
|
||||||
|
require_once('include/photos.php');
|
||||||
|
$args = array( 'data' => @file_get_contents($f));
|
||||||
|
$p = photo_upload($c[0],get_app()->get_observer(),$args);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,19 +102,33 @@ class RedFile extends DAV\Node implements DAV\IFile {
|
|||||||
intval(PAGE_REMOVED)
|
intval(PAGE_REMOVED)
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = q("SELECT flags, folder, os_storage, data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
|
$is_photo = false;
|
||||||
|
|
||||||
|
$r = q("SELECT flags, folder, os_storage, is_photo FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
|
||||||
dbesc($this->data['hash']),
|
dbesc($this->data['hash']),
|
||||||
intval($c[0]['channel_id'])
|
intval($c[0]['channel_id'])
|
||||||
);
|
);
|
||||||
if ($r) {
|
if ($r) {
|
||||||
if (intval($r[0]['os_storage'])) {
|
if (intval($r[0]['os_storage'])) {
|
||||||
$fname = dbunescbin($r[0]['data']);
|
$d = q("select data from attach where hash = '%s' and uid = %d limit 1",
|
||||||
$f = 'store/' . $this->auth->owner_nick . '/' . (($fname) ? $fname : '');
|
dbesc($this->data['hash']),
|
||||||
// @todo check return value and set $size directly
|
intval($c[0]['channel_id'])
|
||||||
@file_put_contents($f, $data);
|
);
|
||||||
$size = @filesize($f);
|
if($d) {
|
||||||
logger('filename: ' . $f . ' size: ' . $size, LOGGER_DEBUG);
|
$fname = dbunescbin($d[0]['data']);
|
||||||
} else {
|
$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);
|
||||||
|
}
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
$r = q("UPDATE attach SET data = '%s' WHERE hash = '%s' AND uid = %d",
|
$r = q("UPDATE attach SET data = '%s' WHERE hash = '%s' AND uid = %d",
|
||||||
dbescbin(stream_get_contents($data)),
|
dbescbin(stream_get_contents($data)),
|
||||||
dbesc($this->data['hash']),
|
dbesc($this->data['hash']),
|
||||||
@ -133,13 +147,19 @@ class RedFile extends DAV\Node implements DAV\IFile {
|
|||||||
// returns now()
|
// returns now()
|
||||||
$edited = datetime_convert();
|
$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),
|
dbesc($size),
|
||||||
|
intval($is_photo),
|
||||||
dbesc($edited),
|
dbesc($edited),
|
||||||
dbesc($this->data['hash']),
|
dbesc($this->data['hash']),
|
||||||
intval($c[0]['channel_id'])
|
intval($c[0]['channel_id'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if($is_photo) {
|
||||||
|
$args = array( 'data' => @file_get_contents($fname));
|
||||||
|
$p = photo_upload($c[0],$this->auth->observer,$args);
|
||||||
|
}
|
||||||
|
|
||||||
// update the folder's lastmodified timestamp
|
// update the folder's lastmodified timestamp
|
||||||
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d",
|
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d",
|
||||||
dbesc($edited),
|
dbesc($edited),
|
||||||
|
Reference in New Issue
Block a user