mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 03:35:13 +00:00
import_xchan_photo: check the return headers to ensure it's an image content-type of some form as imagick chucks a wobbly if you try to initialise an image with an html error page.
This commit is contained in:
parent
9bde18492a
commit
9ab335626c
2 changed files with 71 additions and 53 deletions
|
@ -591,68 +591,86 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
|
|||
if(! $type)
|
||||
$type = 'image/jpeg';
|
||||
|
||||
|
||||
$result = z_fetch_url($photo,true);
|
||||
|
||||
if($result['success'])
|
||||
if($result['success']) {
|
||||
$img_str = $result['body'];
|
||||
}
|
||||
|
||||
$img = photo_factory($img_str, $type);
|
||||
if($img->is_valid()) {
|
||||
$width = $img->getWidth();
|
||||
$height = $img->getHeight();
|
||||
|
||||
if($width && $height) {
|
||||
if(($width / $height) > 1.2) {
|
||||
// crop out the sides
|
||||
$margin = $width - $height;
|
||||
$img->cropImage(300,($margin / 2),0,$height,$height);
|
||||
$h = explode("\n",$result['header']);
|
||||
if($h) {
|
||||
foreach($h as $hl) {
|
||||
if(stristr($hl,'content-type:')) {
|
||||
if(! stristr($hl,'image/')) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif(($height / $width) > 1.2) {
|
||||
// crop out the bottom
|
||||
$margin = $height - $width;
|
||||
$img->cropImage(300,0,0,$width,$width);
|
||||
|
||||
}
|
||||
else {
|
||||
$img->scaleImageSquare(300);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
$photo_failure = true;
|
||||
|
||||
$p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4);
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(80);
|
||||
$p['scale'] = 5;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(48);
|
||||
$p['scale'] = 6;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4';
|
||||
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5';
|
||||
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6';
|
||||
}
|
||||
else {
|
||||
logger('import_xchan_photo: invalid image from ' . $photo);
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
if(! $photo_failure) {
|
||||
$img = photo_factory($img_str, $type);
|
||||
if($img->is_valid()) {
|
||||
$width = $img->getWidth();
|
||||
$height = $img->getHeight();
|
||||
|
||||
if($width && $height) {
|
||||
if(($width / $height) > 1.2) {
|
||||
// crop out the sides
|
||||
$margin = $width - $height;
|
||||
$img->cropImage(300,($margin / 2),0,$height,$height);
|
||||
}
|
||||
elseif(($height / $width) > 1.2) {
|
||||
// crop out the bottom
|
||||
$margin = $height - $width;
|
||||
$img->cropImage(300,0,0,$width,$width);
|
||||
|
||||
}
|
||||
else {
|
||||
$img->scaleImageSquare(300);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
$photo_failure = true;
|
||||
|
||||
$p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4);
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(80);
|
||||
$p['scale'] = 5;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(48);
|
||||
$p['scale'] = 6;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4';
|
||||
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5';
|
||||
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6';
|
||||
}
|
||||
else {
|
||||
logger('import_xchan_photo: invalid image from ' . $photo);
|
||||
$photo_failure = true;
|
||||
}
|
||||
}
|
||||
if($photo_failure) {
|
||||
$photo = $a->get_baseurl() . '/' . get_default_profile_photo();
|
||||
$thumb = $a->get_baseurl() . '/' . get_default_profile_photo(80);
|
||||
|
|
|
@ -2866,7 +2866,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
|
|||
|
||||
// don't pass these elements, they should not be synchronised
|
||||
|
||||
$disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address');
|
||||
$disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address','channel_deleted','channel_removed','channel_system');
|
||||
|
||||
if(in_array($k,$disallowed))
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue