aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-08-24 20:58:12 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-08-24 20:58:12 -0700
commit5fa2aa6d481fe0597044f2e3d4434fc9f4311fe7 (patch)
tree2c7b59b4c1b099e6a5c90467b6d6e4e0b82c1c16 /include/attach.php
parent0edac8810b702ee4a8b8aeef18003d5549c1ac0d (diff)
downloadvolse-hubzilla-5fa2aa6d481fe0597044f2e3d4434fc9f4311fe7.tar.gz
volse-hubzilla-5fa2aa6d481fe0597044f2e3d4434fc9f4311fe7.tar.bz2
volse-hubzilla-5fa2aa6d481fe0597044f2e3d4434fc9f4311fe7.zip
lots of stuff that was needed for successful photo import from red
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php77
1 files changed, 66 insertions, 11 deletions
diff --git a/include/attach.php b/include/attach.php
index 71fad86a8..a23f0f81a 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -414,9 +414,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$hash = (($arr && $arr['hash']) ? $arr['hash'] : null);
$upload_path = (($arr && $arr['directory']) ? $arr['directory'] : '');
- logger('arr: ' . print_r($arr,true));
+ $observer = array();
- if(! perm_is_allowed($channel_id,get_observer_hash(), 'write_storage')) {
+ if($observer_hash) {
+ $x = q("select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($observer_hash)
+ );
+ if($x)
+ $observer = $x[0];
+ }
+
+ logger('arr: ' . print_r($arr,true));
+
+ if(! perm_is_allowed($channel_id,$observer_hash, 'write_storage')) {
$ret['message'] = t('Permission denied.');
return $ret;
}
@@ -434,7 +444,13 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
// revise or update must provide $arr['hash'] of the thing to revise/update
- if($options !== 'update') {
+ if($options === 'import') {
+ $src = $arr['src'];
+ $filename = $arr['filename'];
+ $filesize = @filesize($src);
+ $hash = $arr['resource_id'];
+ }
+ elseif($options !== 'update') {
if(! x($_FILES,'userfile')) {
$ret['message'] = t('No source file.');
return $ret;
@@ -480,12 +496,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
-
+ $def_extension = '';
$is_photo = 0;
$gis = @getimagesize($src);
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;
+ if($gis[2] === IMAGETYPE_GIF)
+ $def_extension = '.gif';
+ if($gis[2] === IMAGETYPE_JPEG)
+ $def_extension = '.jpg';
+ if($gis[2] === IMAGETYPE_PNG)
+ $def_extension = '.png';
+
}
$pathname = '';
@@ -527,7 +550,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$folder_hash = '';
}
- if(! $options) {
+ if((! $options) || ($options === 'import')) {
// A freshly uploaded file. Check for duplicate and resolve with the channel's overwrite settings.
@@ -544,9 +567,18 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$hash = $x[0]['hash'];
}
else {
+ if(strpos($filename,'.') !== false) {
+ $basename = substr($filename,0,strrpos($filename,'.'));
+ $ext = substr($filename,strrpos($filename,'.'));
+ }
+ else {
+ $basename = $filename;
+ $ext = $def_extension;
+ }
+
$r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
- dbesc($filename),
- dbesc($filename . '(%)'),
+ dbesc($basename . $ext),
+ dbesc($basename . '(%)' . $ext),
dbesc($folder_hash)
);
@@ -556,7 +588,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
do {
$found = false;
foreach($r as $rr) {
- if($rr['filename'] === $filename . '(' . $x . ')') {
+ if($rr['filename'] === $basename . '(' . $x . ')' . $ext) {
$found = true;
break;
}
@@ -565,8 +597,10 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$x++;
}
while($found);
- $filename = $filename . '(' . $x . ')';
+ $filename = $basename . '(' . $x . ')' . $ext;
}
+ else
+ $filename = $basename . $ext;
}
}
}
@@ -614,7 +648,16 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($src)
@file_put_contents($os_basepath . $os_relpath,@file_get_contents($src));
- $created = datetime_convert();
+ if(array_key_exists('created', $arr))
+ $created = $arr['created'];
+ else
+ $created = datetime_convert();
+
+ if(array_key_exists('edited', $arr))
+ $edited = $arr['edited'];
+ else
+ $edited = $created;
+
if($options === 'replace') {
$r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d",
@@ -704,7 +747,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$args['contact_deny'] = $arr['contact_deny'];
if($arr['group_deny'])
$args['group_deny'] = $arr['group_deny'];
- $p = photo_upload($channel,get_app()->get_observer(),$args);
+ if(array_key_exists('allow_cid',$arr))
+ $args['allow_cid'] = $arr['allow_cid'];
+ if(array_key_exists('allow_gid',$arr))
+ $args['allow_gid'] = $arr['allow_gid'];
+ if(array_key_exists('deny_cid',$arr))
+ $args['deny_cid'] = $arr['deny_cid'];
+ if(array_key_exists('deny_gid',$arr))
+ $args['deny_gid'] = $arr['deny_gid'];
+
+ $args['created'] = $created;
+ $args['edited'] = $edited;
+
+ $p = photo_upload($channel,$observer,$args);
if($p['success']) {
$ret['body'] = $p['body'];
}