lots of stuff that was needed for successful photo import from red
This commit is contained in:
parent
0edac8810b
commit
5fa2aa6d48
@ -414,9 +414,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
$hash = (($arr && $arr['hash']) ? $arr['hash'] : null);
|
$hash = (($arr && $arr['hash']) ? $arr['hash'] : null);
|
||||||
$upload_path = (($arr && $arr['directory']) ? $arr['directory'] : '');
|
$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.');
|
$ret['message'] = t('Permission denied.');
|
||||||
return $ret;
|
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
|
// 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')) {
|
if(! x($_FILES,'userfile')) {
|
||||||
$ret['message'] = t('No source file.');
|
$ret['message'] = t('No source file.');
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -480,12 +496,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$def_extension = '';
|
||||||
$is_photo = 0;
|
$is_photo = 0;
|
||||||
$gis = @getimagesize($src);
|
$gis = @getimagesize($src);
|
||||||
logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA);
|
logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA);
|
||||||
if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) {
|
if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) {
|
||||||
$is_photo = 1;
|
$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 = '';
|
$pathname = '';
|
||||||
@ -527,7 +550,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
$folder_hash = '';
|
$folder_hash = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! $options) {
|
if((! $options) || ($options === 'import')) {
|
||||||
|
|
||||||
// A freshly uploaded file. Check for duplicate and resolve with the channel's overwrite settings.
|
// 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'];
|
$hash = $x[0]['hash'];
|
||||||
}
|
}
|
||||||
else {
|
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' ",
|
$r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
|
||||||
dbesc($filename),
|
dbesc($basename . $ext),
|
||||||
dbesc($filename . '(%)'),
|
dbesc($basename . '(%)' . $ext),
|
||||||
dbesc($folder_hash)
|
dbesc($folder_hash)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -556,7 +588,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
do {
|
do {
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach($r as $rr) {
|
foreach($r as $rr) {
|
||||||
if($rr['filename'] === $filename . '(' . $x . ')') {
|
if($rr['filename'] === $basename . '(' . $x . ')' . $ext) {
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -565,8 +597,10 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
$x++;
|
$x++;
|
||||||
}
|
}
|
||||||
while($found);
|
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)
|
if($src)
|
||||||
@file_put_contents($os_basepath . $os_relpath,@file_get_contents($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') {
|
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",
|
$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'];
|
$args['contact_deny'] = $arr['contact_deny'];
|
||||||
if($arr['group_deny'])
|
if($arr['group_deny'])
|
||||||
$args['group_deny'] = $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']) {
|
if($p['success']) {
|
||||||
$ret['body'] = $p['body'];
|
$ret['body'] = $p['body'];
|
||||||
}
|
}
|
||||||
|
@ -52,12 +52,21 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
|
|
||||||
// Set to default channel permissions. If the parent directory (album) has permissions set,
|
// Set to default channel permissions. If the parent directory (album) has permissions set,
|
||||||
// use those instead. If we have specific permissions supplied, they take precedence over
|
// use those instead. If we have specific permissions supplied, they take precedence over
|
||||||
// all other settings.
|
// all other settings. 'allow_cid' being passed from an external source takes priority over channel settings.
|
||||||
|
// ...messy... needs re-factoring once the photos/files integration stabilises
|
||||||
|
|
||||||
$str_group_allow = $channel['channel_allow_gid'];
|
if(array_key_exists('allow_cid',$args)) {
|
||||||
$str_contact_allow = $channel['channel_allow_cid'];
|
$str_group_allow = $args['allow_gid'];
|
||||||
$str_group_deny = $channel['channel_deny_gid'];
|
$str_contact_allow = $args['allow_cid'];
|
||||||
$str_contact_deny = $channel['channel_deny_cid'];
|
$str_group_deny = $args['deny_gid'];
|
||||||
|
$str_contact_deny = $args['deny_cid'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$str_group_allow = $channel['channel_allow_gid'];
|
||||||
|
$str_contact_allow = $channel['channel_allow_cid'];
|
||||||
|
$str_group_deny = $channel['channel_deny_gid'];
|
||||||
|
$str_contact_deny = $channel['channel_deny_cid'];
|
||||||
|
}
|
||||||
|
|
||||||
if($args['directory']) {
|
if($args['directory']) {
|
||||||
$str_group_allow = $args['directory']['allow_gid'];
|
$str_group_allow = $args['directory']['allow_gid'];
|
||||||
|
Reference in New Issue
Block a user