diff options
Diffstat (limited to 'include/photos.php')
-rw-r--r-- | include/photos.php | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/include/photos.php b/include/photos.php index 9ae0e6874..d0c5f77fc 100644 --- a/include/photos.php +++ b/include/photos.php @@ -80,14 +80,15 @@ function photo_upload($channel, $observer, $args) { if($imagick_path && @file_exists($imagick_path)) { $tmp_name = $args['os_syspath'] . '-001'; $newsize = photo_calculate_scale(array_merge($args['getimagesize'],['max' => $max_thumb])); - $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $args['os_syspath']) . ' -thumbnail ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name); - // logger('imagick thumbnail command: ' . $cmd); + $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $args['os_syspath']) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name); + logger('imagick thumbnail command: ' . $cmd); for($x = 0; $x < 4; $x ++) { exec($cmd); - if(! file_exists($tmp_name)) { - logger('imagick scale failed. Retrying.'); - continue; + if(file_exists($tmp_name)) { + break; } + logger('imagick scale failed. Retrying.'); + continue; } if(! file_exists($tmp_name)) { logger('imagick scale failed. Abort.'); @@ -96,7 +97,7 @@ function photo_upload($channel, $observer, $args) { $imagedata = @file_get_contents($tmp_name); $filesize = @filesize($args['os_syspath']); - @unlink($tmp_name); +// @unlink($tmp_name); } else { $imagedata = @file_get_contents($args['os_syspath']); @@ -786,17 +787,31 @@ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { ); } if ($r) { - $arr = array(); - foreach ($r as $rr) { - $arr[] = "'" . dbesc($rr['hash']) . "'" ; - } - $str = implode(',',$arr); - return $str; + return ids_to_querystr($r,'hash',true); } return false; } +function photos_album_get_db_idstr_admin($channel_id, $album) { + + if(! is_site_admin()) + return false; + + $r = q("SELECT hash from attach where uid = %d and folder = '%s' ", + intval($channel_id), + dbesc($album) + ); + + if ($r) { + return ids_to_querystr($r,'hash',true); + } + + return false; +} + + + /** * @brief Creates a new photo item. * @@ -996,3 +1011,23 @@ function profile_photo_set_profile_perms($uid, $profileid = 0) { } } } + +function fetch_image_from_url($url,&$mimetype) { + + $redirects = 0; + $x = z_fetch_url($url,true,$redirects,[ 'novalidate' => true ]); + if($x['success']) { + $hdrs = []; + $h = explode("\n",$x['header']); + foreach ($h as $l) { + list($k,$v) = array_map("trim", explode(":", trim($l), 2)); + $hdrs[strtolower($k)] = $v; + } + if (array_key_exists('content-type', $hdrs)) + $mimetype = $hdrs['content-type']; + + return $x['body']; + } + + return EMPTY_STR; +}
\ No newline at end of file |