From 96f23758b4c0e2b997a8c3579639a57f5c533649 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 20 Oct 2015 09:40:32 +0200 Subject: hubzilla photo object compatibility --- include/ItemObject.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index d5601edf5..0add87510 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -263,7 +263,19 @@ class Item extends BaseObject { localize_item($item); - $body = prepare_body($item,true); + + $is_photo = (($item['obj_type'] == ACTIVITY_OBJ_PHOTO) ? true : false); + if($is_photo) { + $object = json_decode($item['object'],true); + $photo = array( + 'url' => rawurldecode($object['id']) . '?zid=' . $observer['xchan_addr'], + 'link' => rawurldecode(get_rel_link($object['link'],'alternate')) . '?zid=' . $observer['xchan_addr'], + 'width' => $object['width'], + 'height' => $object['height'] + ); + } + + $body .= prepare_body($item,true); // $viewthread (below) is only valid in list mode. If this is a channel page, build the thread viewing link // since we can't depend on llink or plink pointing to the right local location. @@ -323,6 +335,8 @@ class Item extends BaseObject { 'owner_url' => $this->get_owner_url(), 'owner_photo' => $this->get_owner_photo(), 'owner_name' => $this->get_owner_name(), + 'is_photo' => $is_photo, + 'photo' => (($is_photo) ? $photo : ''), // Item toolbar buttons 'like' => $like, -- cgit v1.2.3 From 9cbca24f7a333187961d35a77e5426dc4f2e122e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 22 Oct 2015 10:56:24 +0200 Subject: photo object compatibility revamped --- include/ItemObject.php | 15 +-------------- include/text.php | 9 ++++++++- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index 0add87510..dea2f75bf 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -264,18 +264,7 @@ class Item extends BaseObject { localize_item($item); - $is_photo = (($item['obj_type'] == ACTIVITY_OBJ_PHOTO) ? true : false); - if($is_photo) { - $object = json_decode($item['object'],true); - $photo = array( - 'url' => rawurldecode($object['id']) . '?zid=' . $observer['xchan_addr'], - 'link' => rawurldecode(get_rel_link($object['link'],'alternate')) . '?zid=' . $observer['xchan_addr'], - 'width' => $object['width'], - 'height' => $object['height'] - ); - } - - $body .= prepare_body($item,true); + $body = prepare_body($item,true); // $viewthread (below) is only valid in list mode. If this is a channel page, build the thread viewing link // since we can't depend on llink or plink pointing to the right local location. @@ -335,8 +324,6 @@ class Item extends BaseObject { 'owner_url' => $this->get_owner_url(), 'owner_photo' => $this->get_owner_photo(), 'owner_name' => $this->get_owner_name(), - 'is_photo' => $is_photo, - 'photo' => (($is_photo) ? $photo : ''), // Item toolbar buttons 'like' => $like, diff --git a/include/text.php b/include/text.php index f4122845e..2a8905efe 100644 --- a/include/text.php +++ b/include/text.php @@ -1440,12 +1440,19 @@ function generate_named_map($location) { function prepare_body(&$item,$attach = false) { + require_once('include/identity.php'); call_hooks('prepare_body_init', $item); unobscure($item); - $s = prepare_text($item['body'],$item['mimetype']); + $is_photo = (($item['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false); + if($is_photo) { + $object = json_decode($item['object'],true); + $s = ''; + } + + $s .= prepare_text($item['body'],$item['mimetype']); $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); -- cgit v1.2.3 From 4442da306a6a2ac88c6dd0ab10b21616fb66daf0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 25 Oct 2015 18:02:45 +0100 Subject: hubzilla compatibility: improve photo item object - we now provide the infos for all available photo sizes --- include/text.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 2a8905efe..c3abaeedf 100644 --- a/include/text.php +++ b/include/text.php @@ -1449,7 +1449,8 @@ function prepare_body(&$item,$attach = false) { $is_photo = (($item['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false); if($is_photo) { $object = json_decode($item['object'],true); - $s = ''; + $scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0); + $s = '
'; } $s .= prepare_text($item['body'],$item['mimetype']); -- cgit v1.2.3 From 59da3dfe030493dcb8511cc3c06d672d61e5ea48 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 28 Oct 2015 15:03:34 +0100 Subject: do not treat profile photo change posts like photo-items --- include/text.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index c3abaeedf..e0c8d018e 100644 --- a/include/text.php +++ b/include/text.php @@ -1446,11 +1446,15 @@ function prepare_body(&$item,$attach = false) { unobscure($item); + $s = ''; + $is_photo = (($item['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false); if($is_photo) { $object = json_decode($item['object'],true); - $scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0); - $s = '
'; + if($object['link'][0]['width']) { + $scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0); + $s = '
'; + } } $s .= prepare_text($item['body'],$item['mimetype']); -- cgit v1.2.3 From f1a3b281d4573e12f7a81efa03fb1db73ba34e27 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 28 Oct 2015 19:59:50 +0100 Subject: pathinfo() does not work in this case. getimagesize() seems more reliabel. this fixes transparent png avatars having a black background. --- include/photo/photo_driver.php | 10 +++++++++- include/photo/photo_gd.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 5d61556ab..db98f7085 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -541,7 +541,7 @@ function guess_image_type($filename, $headers = '') { // we aren't using imagick can find it } } - +/* if(is_null($type)) { $ext = pathinfo($filename, PATHINFO_EXTENSION); $ph = photo_factory(''); @@ -551,6 +551,14 @@ function guess_image_type($filename, $headers = '') { if ($ext==$e) $type = $m; } } +*/ + if(is_null($type)) { + $size = getimagesize($filename); + $ph = photo_factory(''); + $types = $ph->supportedTypes(); + $type = ((array_key_exists($size['mime'], $types)) ? $size['mime'] : 'image/jpeg'); + } + } logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG); return $type; diff --git a/include/photo/photo_gd.php b/include/photo/photo_gd.php index fa1f700e9..2ac7287e4 100644 --- a/include/photo/photo_gd.php +++ b/include/photo/photo_gd.php @@ -137,4 +137,4 @@ class photo_gd extends photo_driver { return $string; } -} \ No newline at end of file +} -- cgit v1.2.3 From e0a75f68d58d3c0074100ad342ecb889b88840dd Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 28 Oct 2015 21:52:56 +0100 Subject: re-enable pathinfo() check and try with getimagesize() if we have not got a result --- include/photo/photo_driver.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index db98f7085..bbcc110c8 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -541,17 +541,16 @@ function guess_image_type($filename, $headers = '') { // we aren't using imagick can find it } } -/* + if(is_null($type)) { $ext = pathinfo($filename, PATHINFO_EXTENSION); $ph = photo_factory(''); $types = $ph->supportedTypes(); - $type = "image/jpeg"; foreach ($types as $m=>$e){ if ($ext==$e) $type = $m; } } -*/ + if(is_null($type)) { $size = getimagesize($filename); $ph = photo_factory(''); -- cgit v1.2.3 From 98fd919647a0eb86131eb3863719dfd75ec700a7 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 29 Oct 2015 11:30:45 +0100 Subject: possibly better fix for profile photo image type issue --- include/photo/photo_driver.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index bbcc110c8..11e4c8af3 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -593,15 +593,24 @@ function import_profile_photo($photo,$xchan,$thing = false) { if($photo) { $filename = basename($photo); - $type = guess_image_type($photo); - - if(! $type) - $type = 'image/jpeg'; $result = z_fetch_url($photo,true); - if($result['success']) + if($result['success']) { $img_str = $result['body']; + + $h = explode("\n",$result['header']); + if($h) { + foreach($h as $hl) { + if(stristr($hl,'content-type:')) { + if(! stristr($hl,'image/')) { + $photo_failure = true; + } + } + } + } + $type = guess_image_type($photo, $result['header']); + } } $img = photo_factory($img_str, $type); -- cgit v1.2.3 From 3e459ed4345e9e19db92856e78b9bf4ebbd6ffdd Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 29 Oct 2015 11:34:56 +0100 Subject: move it up --- include/photo/photo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 11e4c8af3..96bde7587 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -598,6 +598,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { if($result['success']) { $img_str = $result['body']; + $type = guess_image_type($photo, $result['header']); $h = explode("\n",$result['header']); if($h) { @@ -609,7 +610,6 @@ function import_profile_photo($photo,$xchan,$thing = false) { } } } - $type = guess_image_type($photo, $result['header']); } } -- cgit v1.2.3