From f7601756e99fcedb062d1f7ac3e53431ea72642d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 20 Oct 2015 09:36:15 +0200 Subject: create photo object if feature large photos is enabled and display those slightly different --- include/ItemObject.php | 12 ++++++++- include/bb2diaspora.php | 15 +++++++++++ include/items.php | 2 -- include/photos.php | 70 ++++++++++++++++++++++++++++++++++++------------- 4 files changed, 78 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index ee431dccb..9fe86118c 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -278,7 +278,16 @@ class Item extends BaseObject { $children = $this->get_children(); - $is_photo = ((($item['resource_type'] == 'photo') && (feature_enabled($conv->get_profile_owner(),'large_photos'))) ? true : false); + $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'] + ); + } $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false); @@ -334,6 +343,7 @@ class Item extends BaseObject { 'owner_photo' => $this->get_owner_photo(), 'owner_name' => $this->get_owner_name(), 'is_photo' => $is_photo, + 'photo' => (($is_photo) ? $photo : ''), 'has_tags' => $has_tags, // Item toolbar buttons diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 692128087..95de43ec3 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -305,6 +305,21 @@ function bb2diaspora_itembody($item, $force_update = false) { $matches = array(); + //if we have a photo item just prepend the photo bbcode to item['body'] + $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']), + 'link' => rawurldecode(get_rel_link($object['link'],'alternate')), + 'width' => $object['width'], + 'height' => $object['height'] + ); + + $photo_bb = '[zrl=' . $photo['link'] . ']' . '[zmg=' . $photo['width'] . 'x' . $photo['height'] . ']' . $photo['url'] . '[/zmg]' . '[/zrl]'; + $item['body'] = (($item['body']) ? $photo_bb . $item['body'] : $photo_bb); + } + if(($item['diaspora_meta']) && (! $force_update)) { $diaspora_meta = json_decode($item['diaspora_meta'],true); if($diaspora_meta) { diff --git a/include/items.php b/include/items.php index 9159f6da3..08be981e7 100755 --- a/include/items.php +++ b/include/items.php @@ -889,7 +889,6 @@ function get_item_elements($x,$allow_code = false) { $arr['mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'], ENT_COMPAT,'UTF-8',false) : ''); $arr['obj_type'] = (($x['object_type']) ? htmlspecialchars($x['object_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['tgt_type'] = (($x['target_type']) ? htmlspecialchars($x['target_type'], ENT_COMPAT,'UTF-8',false) : ''); - $arr['resource_type'] = (($x['resource_type']) ? htmlspecialchars($x['resource_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['public_policy'] = (($x['public_scope']) ? htmlspecialchars($x['public_scope'], ENT_COMPAT,'UTF-8',false) : ''); if($arr['public_policy'] === 'public') @@ -1286,7 +1285,6 @@ function encode_item($item,$mirror = false) { $x['verb'] = $item['verb']; $x['object_type'] = $item['obj_type']; $x['target_type'] = $item['tgt_type']; - $x['resource_type'] = $item['resource_type']; $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; diff --git a/include/photos.php b/include/photos.php index e78b899e0..2ec983833 100644 --- a/include/photos.php +++ b/include/photos.php @@ -186,7 +186,8 @@ function photo_upload($channel, $observer, $args) { $p['description'] = $args['description']; $r0 = $ph->save($p); - $r0wxh = $ph->getWidth() . 'x' . $ph->getHeight(); + $r0width = $ph->getWidth(); + $r0height = $ph->getHeight(); if(! $r0) $errors = true; @@ -198,7 +199,8 @@ function photo_upload($channel, $observer, $args) { $p['scale'] = 1; $r1 = $ph->save($p); - $r1wxh = $ph->getWidth() . 'x' . $ph->getHeight(); + $r1width = $ph->getWidth(); + $r1height = $ph->getHeight(); if(! $r1) $errors = true; @@ -207,7 +209,8 @@ function photo_upload($channel, $observer, $args) { $p['scale'] = 2; $r2 = $ph->save($p); - $r2wxh = $ph->getWidth() . 'x' . $ph->getHeight(); + $r2width = $ph->getWidth(); + $r2height = $ph->getHeight(); if(! $r2) $errors = true; @@ -216,7 +219,8 @@ function photo_upload($channel, $observer, $args) { $p['scale'] = 3; $r3 = $ph->save($p); - $r3wxh = $ph->getWidth() . 'x' . $ph->getHeight(); + $r3width = $ph->getWidth(); + $r3height = $ph->getHeight(); if(! $r3) $errors = true; @@ -242,17 +246,48 @@ function photo_upload($channel, $observer, $args) { } } - $larger = feature_enabled($channel['channel_id'], 'large_photos'); + $title = (($args['filename']) ? $args['filename'] : ''); - if($larger) { - $tag = (($r1wxh) ? '[zmg=' . $r1wxh . ']' : '[zmg]'); + $large_photos = feature_enabled($channel['channel_id'], 'large_photos'); + + if($large_photos) { $scale = 1; + $width = $r1width; + $height = $r1height; + $tag = (($r1) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); + + // Create item object + $href = rawurlencode(z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash); + $url = rawurlencode(z_root() . "/photo/{$photo_hash}-{$scale}.".$ph->getExt()); + + $link = array(); + $link[] = array( + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $href + ); + + $object = array( + 'type' => ACTIVITY_OBJ_PHOTO, + 'title' => $title, + 'id' => $url, + 'link' => $link, + 'width' => $width, + 'height' => $height + ); } else { - $tag = (($r2wxh) ? '[zmg=' . $r2wxh . ']' : '[zmg]'); $scale = 2; + $width = $r2width; + $height = $r2height; + $tag = (($r2) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); + + $body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' + . $tag . z_root() . "/photo/{$photo_hash}-{$scale}.".$ph->getExt() . '[/zmg]' + . '[/zrl]'; } + // Create item container if($args['item']) { @@ -263,13 +298,14 @@ function photo_upload($channel, $observer, $args) { if($item['mid'] === $item['parent_mid']) { - $item['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' - . $tag . z_root() . "/photo/{$photo_hash}-{$scale}.".$ph->getExt() . '[/zmg]' - . '[/zrl]'; + $item['body'] = (($body) ? $body: ''); + + $arr['obj_type'] = (($object) ? ACTIVITY_OBJ_PHOTO : ''); + $arr['object'] = (($object) ? json_encode($object) : ''); if($item['author_xchan'] === $channel['channel_hash']) { - $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey'])); - $item['item_verified'] = 1; + $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey'])); + $item['item_verified'] = 1; } else { $item['sig'] = ''; @@ -297,7 +333,6 @@ function photo_upload($channel, $observer, $args) { } } else { - $title = $args['filename'] ? $args['filename'] : ''; $mid = item_message_id(); $arr = array(); @@ -320,15 +355,14 @@ function photo_upload($channel, $observer, $args) { $arr['deny_cid'] = $ac['deny_cid']; $arr['deny_gid'] = $ac['deny_gid']; $arr['verb'] = ACTIVITY_POST; + $arr['obj_type'] = (($object) ? ACTIVITY_OBJ_PHOTO : ''); + $arr['object'] = (($object) ? json_encode($object) : ''); $arr['item_wall'] = 1; $arr['item_origin'] = 1; $arr['item_thread_top'] = 1; $arr['item_private'] = intval($acl->is_private()); $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - - $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' - . $tag . z_root() . "/photo/{$photo_hash}-{$scale}.".$ph->getExt() . '[/zmg]' - . '[/zrl]'; + $arr['body'] = (($body) ? $body : ''); $result = item_store($arr); $item_id = $result['item_id']; -- cgit v1.2.3