more work on photos, including os_storage for the size '0' photo and numbering duplicate filenames
This commit is contained in:
parent
1a0655f34e
commit
86588bdd6c
4
boot.php
4
boot.php
@ -80,9 +80,9 @@ $DIRECTORY_FALLBACK_SERVERS = array(
|
|||||||
'https://zothub.com',
|
'https://zothub.com',
|
||||||
'https://zotid.net',
|
'https://zotid.net',
|
||||||
'https://red.zottel.red',
|
'https://red.zottel.red',
|
||||||
'https://hubzilla.info',
|
'https://redmatrix.info',
|
||||||
'https://my.federated.social',
|
'https://my.federated.social',
|
||||||
'https://hubzilla.nl'
|
'https://redmatrix.nl'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -391,10 +391,7 @@ 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));
|
// logger('arr: ' . print_r($arr,true));
|
||||||
|
|
||||||
// This is currently used only in mod/wall_attach
|
|
||||||
|
|
||||||
|
|
||||||
if(! perm_is_allowed($channel_id,get_observer_hash(), 'write_storage')) {
|
if(! perm_is_allowed($channel_id,get_observer_hash(), 'write_storage')) {
|
||||||
$ret['message'] = t('Permission denied.');
|
$ret['message'] = t('Permission denied.');
|
||||||
@ -417,6 +414,14 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
$src = $_FILES['userfile']['tmp_name'];
|
$src = $_FILES['userfile']['tmp_name'];
|
||||||
$filename = basename($_FILES['userfile']['name']);
|
$filename = basename($_FILES['userfile']['name']);
|
||||||
$filesize = intval($_FILES['userfile']['size']);
|
$filesize = intval($_FILES['userfile']['size']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$existing_size = 0;
|
$existing_size = 0;
|
||||||
@ -482,9 +487,9 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
|
|
||||||
|
|
||||||
$is_photo = 0;
|
$is_photo = 0;
|
||||||
$x = @getimagesize($src);
|
$gis = @getimagesize($src);
|
||||||
logger('getimagesize: ' . print_r($x,true), LOGGER_DATA);
|
logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA);
|
||||||
if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) {
|
if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) {
|
||||||
$is_photo = 1;
|
$is_photo = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,6 +524,30 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
$folder_hash = '';
|
$folder_hash = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
|
||||||
|
dbesc($filename),
|
||||||
|
dbesc($filename . '(%)'),
|
||||||
|
dbesc($folder_hash)
|
||||||
|
);
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
$x = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$found = false;
|
||||||
|
foreach($r as $rr) {
|
||||||
|
if($rr['filename'] === $filename . '(' . $x . ')') {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($found)
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
while($found);
|
||||||
|
$filename = $filename . '(' . $x . ')';
|
||||||
|
}
|
||||||
|
|
||||||
$os_basepath = 'store/' . $channel['channel_address'] . '/' ;
|
$os_basepath = 'store/' . $channel['channel_address'] . '/' ;
|
||||||
$os_relpath = '';
|
$os_relpath = '';
|
||||||
|
|
||||||
@ -614,7 +643,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($is_photo) {
|
if($is_photo) {
|
||||||
$args = array( 'source' => $source, 'visible' => 0, 'resource_id' => $hash, 'album' => basename($pathname), 'data' => @file_get_contents($src));
|
$args = array( 'source' => $source, 'visible' => 0, 'resource_id' => $hash, 'album' => basename($pathname), 'os_path' => $os_basepath . $os_relpath, 'filename' => $filename, 'getimagesize' => $gis);
|
||||||
if($arr['contact_allow'])
|
if($arr['contact_allow'])
|
||||||
$args['contact_allow'] = $arr['contact_allow'];
|
$args['contact_allow'] = $arr['contact_allow'];
|
||||||
$p = photo_upload($channel,get_app()->get_observer(),$args);
|
$p = photo_upload($channel,get_app()->get_observer(),$args);
|
||||||
|
@ -311,7 +311,11 @@ abstract class photo_driver {
|
|||||||
$p['title'] = (($arr['title']) ? $arr['title'] : '');
|
$p['title'] = (($arr['title']) ? $arr['title'] : '');
|
||||||
$p['description'] = (($arr['description']) ? $arr['description'] : '');
|
$p['description'] = (($arr['description']) ? $arr['description'] : '');
|
||||||
$p['photo_usage'] = intval($arr['photo_usage']);
|
$p['photo_usage'] = intval($arr['photo_usage']);
|
||||||
|
$p['os_storage'] = intval($arr['os_storage']);
|
||||||
|
$p['os_path'] = $arr['os_path'];
|
||||||
|
|
||||||
|
if(! intval($p['scale']))
|
||||||
|
logger('save: ' . print_r($arr,true));
|
||||||
|
|
||||||
$x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and `scale` = %d limit 1",
|
$x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and `scale` = %d limit 1",
|
||||||
dbesc($p['resource_id']),
|
dbesc($p['resource_id']),
|
||||||
@ -333,6 +337,7 @@ abstract class photo_driver {
|
|||||||
`height` = %d,
|
`height` = %d,
|
||||||
`width` = %d,
|
`width` = %d,
|
||||||
`data` = '%s',
|
`data` = '%s',
|
||||||
|
`os_storage` = %d,
|
||||||
`size` = %d,
|
`size` = %d,
|
||||||
`scale` = %d,
|
`scale` = %d,
|
||||||
`photo_usage` = %d,
|
`photo_usage` = %d,
|
||||||
@ -355,7 +360,8 @@ abstract class photo_driver {
|
|||||||
dbesc($p['album']),
|
dbesc($p['album']),
|
||||||
intval($this->getHeight()),
|
intval($this->getHeight()),
|
||||||
intval($this->getWidth()),
|
intval($this->getWidth()),
|
||||||
dbescbin($this->imageString()),
|
(intval($p['os_storage']) ? dbesc($p['os_path']) : dbescbin($this->imageString())),
|
||||||
|
intval($p['os_storage']),
|
||||||
intval(strlen($this->imageString())),
|
intval(strlen($this->imageString())),
|
||||||
intval($p['scale']),
|
intval($p['scale']),
|
||||||
intval($p['photo_usage']),
|
intval($p['photo_usage']),
|
||||||
@ -370,8 +376,8 @@ abstract class photo_driver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$r = q("INSERT INTO `photo`
|
$r = q("INSERT INTO `photo`
|
||||||
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `photo_usage`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
|
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `os_storage`, `size`, `scale`, `photo_usage`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
|
||||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' )",
|
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' )",
|
||||||
intval($p['aid']),
|
intval($p['aid']),
|
||||||
intval($p['uid']),
|
intval($p['uid']),
|
||||||
dbesc($p['xchan']),
|
dbesc($p['xchan']),
|
||||||
@ -383,7 +389,8 @@ abstract class photo_driver {
|
|||||||
dbesc($p['album']),
|
dbesc($p['album']),
|
||||||
intval($this->getHeight()),
|
intval($this->getHeight()),
|
||||||
intval($this->getWidth()),
|
intval($this->getWidth()),
|
||||||
dbescbin($this->imageString()),
|
(intval($p['os_storage']) ? dbesc($p['os_path']) : dbescbin($this->imageString())),
|
||||||
|
intval($p['os_storage']),
|
||||||
intval(strlen($this->imageString())),
|
intval(strlen($this->imageString())),
|
||||||
intval($p['scale']),
|
intval($p['scale']),
|
||||||
intval($p['photo_usage']),
|
intval($p['photo_usage']),
|
||||||
|
@ -55,7 +55,18 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
$str_group_deny = perms2str(((is_array($args['group_deny'])) ? $args['group_deny'] : explode(',',$args['group_deny'])));
|
$str_group_deny = perms2str(((is_array($args['group_deny'])) ? $args['group_deny'] : explode(',',$args['group_deny'])));
|
||||||
$str_contact_deny = perms2str(((is_array($args['contact_deny'])) ? $args['contact_deny'] : explode(',',$args['contact_deny'])));
|
$str_contact_deny = perms2str(((is_array($args['contact_deny'])) ? $args['contact_deny'] : explode(',',$args['contact_deny'])));
|
||||||
|
|
||||||
if ($args['data']) {
|
$os_storage = 0;
|
||||||
|
|
||||||
|
if($args['os_path'] && $args['getimagesize']) {
|
||||||
|
$imagedata = @file_get_contents($args['os_path']);
|
||||||
|
$filename = $args['filename'];
|
||||||
|
$filesize = strlen($imagedata);
|
||||||
|
// this is going to be deleted if it exists
|
||||||
|
$src = '/tmp/deletemenow';
|
||||||
|
$type = $args['getimagesize']['mime'];
|
||||||
|
$os_storage = 1;
|
||||||
|
}
|
||||||
|
elseif ($args['data']) {
|
||||||
|
|
||||||
// allow an import from a binary string representing the image.
|
// allow an import from a binary string representing the image.
|
||||||
// This bypasses the upload step and max size limit checking
|
// This bypasses the upload step and max size limit checking
|
||||||
@ -158,7 +169,8 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
$p = array('aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash,
|
$p = array('aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash,
|
||||||
'filename' => $filename, 'album' => $album, 'scale' => 0, 'photo_usage' => PHOTO_NORMAL,
|
'filename' => $filename, 'album' => $album, 'scale' => 0, 'photo_usage' => PHOTO_NORMAL,
|
||||||
'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
|
'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
|
||||||
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny
|
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny,
|
||||||
|
'os_storage' => $os_storage, 'os_path' => $args['os_path']
|
||||||
);
|
);
|
||||||
if($args['created'])
|
if($args['created'])
|
||||||
$p['created'] = $args['created'];
|
$p['created'] = $args['created'];
|
||||||
@ -173,6 +185,10 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
if(! $r1)
|
if(! $r1)
|
||||||
$errors = true;
|
$errors = true;
|
||||||
|
|
||||||
|
|
||||||
|
unset($p['os_storage']);
|
||||||
|
unset($p['os_path']);
|
||||||
|
|
||||||
if(($width > 640 || $height > 640) && (! $errors)) {
|
if(($width > 640 || $height > 640) && (! $errors)) {
|
||||||
$ph->scaleImage(640);
|
$ph->scaleImage(640);
|
||||||
$p['scale'] = 1;
|
$p['scale'] = 1;
|
||||||
|
Reference in New Issue
Block a user