aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php79
1 files changed, 68 insertions, 11 deletions
diff --git a/include/attach.php b/include/attach.php
index 71fad86a8..620c7620c 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,21 @@ 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;
+ if($arr['item'])
+ $args['item'] = $arr['item'];
+
+ $p = photo_upload($channel,$observer,$args);
if($p['success']) {
$ret['body'] = $p['body'];
}