aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/bbcode.php21
-rw-r--r--include/conversation.php3
-rw-r--r--include/html2plain.php10
-rw-r--r--include/photos.php91
-rw-r--r--include/text.php36
5 files changed, 123 insertions, 38 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index a362e9ce9..87a7e6af6 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1099,6 +1099,27 @@ function bbcode($Text, $options = []) {
call_hooks('bbcode_filter', $Text);
+ if(isset($options['drop_media'])) {
+ if (strpos($Text,'[/img]') !== false) {
+ $Text = preg_replace('/\[img(.*?)\[\/(img)\]/ism', '', $Text);
+ }
+ if (strpos($Text,'[/audio]') !== false) {
+ $Text = preg_replace('/\[audio(.*?)\[\/(audio)\]/ism', '', $Text);
+ }
+ if (strpos($Text,'[/video]') !== false) {
+ $Text = preg_replace('/\[video(.*?)\[\/(video)\]/ism', '', $Text);
+ }
+ if (strpos($Text,'[/zmg]') !== false) {
+ $Text = preg_replace('/\[zmg(.*?)\[\/(zmg)\]/ism', '', $Text);
+ }
+ if (strpos($Text,'[/zaudio]') !== false) {
+ $Text = preg_replace('/\[zaudio(.*?)\[\/(zaudio)\]/ism', '', $Text);
+ }
+ if (strpos($Text,'[/zvideo]') !== false) {
+ $Text = preg_replace('/\[zvideo(.*?)\[\/(zvideo)\]/ism', '', $Text);
+ }
+ }
+
// Hide all [noparse] contained bbtags by spacefying them
if (strpos($Text,'[noparse]') !== false) {
$Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
diff --git a/include/conversation.php b/include/conversation.php
index 39ff8d7ad..d8f0e8155 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -1388,7 +1388,8 @@ function hz_status_editor($a, $x, $popup = false) {
'$nocomment_enabled' => t('Comments enabled'),
'$nocomment_disabled' => t('Comments disabled'),
'$auto_save_draft' => $feature_auto_save_draft,
- '$reset' => $reset
+ '$reset' => $reset,
+ '$popup' => $popup
];
call_hooks('jot_header_tpl_filter',$tplmacros);
diff --git a/include/html2plain.php b/include/html2plain.php
index bf8581bdb..48bbe3d9e 100644
--- a/include/html2plain.php
+++ b/include/html2plain.php
@@ -78,10 +78,10 @@ function quotelevel($message, $wraplength = 75)
function collecturls($message) {
-
+
$pattern = '/<a.*?href="(.*?)".*?>(.*?)<\/a>/is';
preg_match_all($pattern, $message, $result, PREG_SET_ORDER);
-
+
$urls = [];
if ($result) {
$ignore = false;
@@ -104,15 +104,15 @@ function collecturls($message) {
foreach ($list as $listitem)
if (strpos($treffer[1], $listitem) !== false)
$ignore = true;
-
+
if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/posts") !== false))
$ignore = false;
-
+
if (! $ignore)
$urls[$treffer[1]] = $treffer[1];
}
}
-
+
return($urls);
}
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'];
+ }
+ }
}
}