diff options
author | Mario <mario@mariovavti.com> | 2021-06-23 15:52:04 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-06-23 15:52:04 +0000 |
commit | 6e91bee0ba605b938bddf0570e747d6d7be1c712 (patch) | |
tree | 8fa11dc01ab4114510105f6171b91951037d18bd /include | |
parent | c6d872d1773a0470c9a707e7fe1ae610699bc8dd (diff) | |
download | volse-hubzilla-6e91bee0ba605b938bddf0570e747d6d7be1c712.tar.gz volse-hubzilla-6e91bee0ba605b938bddf0570e747d6d7be1c712.tar.bz2 volse-hubzilla-6e91bee0ba605b938bddf0570e747d6d7be1c712.zip |
some work on streamlining mod photos
Diffstat (limited to 'include')
-rw-r--r-- | include/photos.php | 91 | ||||
-rw-r--r-- | include/text.php | 36 |
2 files changed, 95 insertions, 32 deletions
diff --git a/include/photos.php b/include/photos.php index 11dd07586..a783875bb 100644 --- a/include/photos.php +++ b/include/photos.php @@ -4,6 +4,9 @@ * @brief Functions related to photo handling. */ +use Zotlabs\Lib\Activity; + + require_once('include/permissions.php'); require_once('include/items.php'); require_once('include/photo/photo_driver.php'); @@ -259,7 +262,7 @@ function photo_upload($channel, $observer, $args) { $link = array(); $r0 = $ph->save($p); - $link[0] = array( + $url[0] = array( 'rel' => 'alternate', 'type' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(), @@ -278,7 +281,7 @@ function photo_upload($channel, $observer, $args) { $ph->scaleImage(1024); $r1 = $ph->storeThumbnail($p, PHOTO_RES_1024); - $link[1] = array( + $url[1] = array( 'rel' => 'alternate', 'type' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(), @@ -292,7 +295,7 @@ function photo_upload($channel, $observer, $args) { $ph->scaleImage(640); $r2 = $ph->storeThumbnail($p, PHOTO_RES_640); - $link[2] = array( + $url[2] = array( 'rel' => 'alternate', 'type' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(), @@ -306,7 +309,7 @@ function photo_upload($channel, $observer, $args) { $ph->scaleImage(320); $r3 = $ph->storeThumbnail($p, PHOTO_RES_320); - $link[3] = array( + $url[3] = array( 'rel' => 'alternate', 'type' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(), @@ -353,7 +356,7 @@ function photo_upload($channel, $observer, $args) { $large_photos = feature_enabled($channel['channel_id'], 'large_photos'); - linkify_tags($args['body'], $channel_id); + $found_tags = linkify_tags($args['body'], $channel_id); if($large_photos) { $scale = 1; @@ -382,22 +385,62 @@ function photo_upload($channel, $observer, $args) { . $tag . z_root() . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]' . '[/zrl]'; - // Create item object - $object = array( - 'type' => ACTIVITY_OBJ_PHOTO, - 'title' => $title, - 'created' => $p['created'], - 'edited' => $p['edited'], - 'id' => z_root() . '/item/' . $photo_hash, - 'link' => $link, - 'body' => $summary - ); + $url[] = [ + 'type' => 'Link', + 'mediaType' => 'text/html', + 'href' => z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash + ]; + + $post_tags = []; + + if($found_tags) { + foreach($found_tags as $result) { + $success = $result['success']; + if($success['replaced']) { + $post_tags[] = array( + 'uid' => $channel['channel_id'], + 'ttype' => $success['termtype'], + 'otype' => TERM_OBJ_POST, + 'term' => $success['term'], + 'url' => $success['url'] + ); + } + } + } - $target = array( - 'type' => ACTIVITY_OBJ_ALBUM, - 'title' => (($album) ? $album : '/'), - 'id' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album) - ); + //// Create item object + $object = [ + 'type' => 'Image', + 'name' => $title, + 'summary' => $p['description'], + 'published' => datetime_convert('UTC','UTC',$p['created'],ATOM_TIME), + 'updated' => datetime_convert('UTC','UTC',$p['edited'],ATOM_TIME), + // This is a placeholder and will get over-ridden by the item mid, which is critical for sharing as a conversational item over activitypub + 'id' => z_root() . '/photo/' . $photo_hash, + 'url' => $url, + 'source' => [ 'content' => $summary, 'mediaType' => 'text/bbcode' ], + 'content' => bbcode($summary) + ]; + + if ($post_tags) { + $object['tag'] = Activity::encode_taxonomy(['term' => $post_tags]); + } + + $public = (($ac['allow_cid'] || $ac['allow_gid'] || $ac['deny_cid'] || $ac['deny_gid']) ? false : true); + + if ($public) { + $object['to'] = [ ACTIVITY_PUBLIC_INBOX ]; + $object['cc'] = [ z_root() . '/followers/' . $channel['channel_address'] ]; + } + else { + $object['to'] = Activity::map_acl(array_merge($ac, ['item_private' => 1 - intval($public) ])); + } + + $target = [ + 'type' => 'orderedCollection', + 'name' => ((strlen($album)) ? $album : '/'), + 'id' => z_root() . '/album/' . $channel['channel_address'] . ((isset($args['folder'])) ? '/' . $args['folder'] : EMPTY_STR) + ]; // Create item container if($args['item']) { @@ -415,7 +458,9 @@ function photo_upload($channel, $observer, $args) { $item['tgt_type'] = ACTIVITY_OBJ_ALBUM; $item['target'] = json_encode($target); - + if ($post_tags) { + $arr['term'] = $post_tags; + } $force = true; } $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", @@ -469,6 +514,10 @@ function photo_upload($channel, $observer, $args) { 'body' => $summary ]; + if ($post_tags) { + $arr['term'] = $post_tags; + } + $arr['plink'] = $mid; if($lat && $lon) diff --git a/include/text.php b/include/text.php index a0c2689af..c0f8c0fb1 100644 --- a/include/text.php +++ b/include/text.php @@ -1714,19 +1714,33 @@ function prepare_body(&$item,$attach = false,$opts = false) { $photo = ''; $is_photo = ((($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) ? true : false); - if($is_photo) { - + if ($is_photo) { $object = json_decode($item['obj'],true); + $ptr = null; + if (array_key_exists('url',$object) && is_array($object['url'])) { + if (array_key_exists(0,$object['url'])) { + foreach ($object['url'] as $link) { + if(array_key_exists('width',$link) && $link['width'] >= 640 && $link['width'] <= 1024) { + $ptr = $link; + } + } + if (! $ptr) { + $ptr = $object['url'][0]; + } + } + else { + $ptr = $object['url']; + } - // if original photo width is <= 640px prepend it to item body - if($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) { - $s .= '<div class="inline-photo-item-wrapper"><a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener" ><img class="inline-photo-item" style="max-width:' . $object['link'][0]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][0]['href'])) . '"></a></div>' . $s; - } - - // if original photo width is > 640px make it a cover photo - if($object['link'][0]['width'] && $object['link'][0]['width'] > 640) { - $scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0); - $photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener"><img style="max-width:' . $object['link'][$scale]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][$scale]['href'])) . '"></a>'; + // if original photo width is > 640px make it a cover photo + if ($ptr) { + if (array_key_exists('width',$ptr) && $ptr['width'] > 640) { + $photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener"><img style="max-width:' . $ptr['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($ptr['href'])) . '"></a>'; + } + else { + $item['body'] = '[zmg]' . $ptr['href'] . '[/zmg]' . "\n\n" . $item['body']; + } + } } } |