aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-07-29 06:59:13 +0000
committerMario <mario@mariovavti.com>2021-07-29 06:59:13 +0000
commit9722d157bf138753bc168f68c56b4963db6da4e9 (patch)
treea15bb81c35a2367fe4628614471d471ed86d2712 /include/text.php
parent219d47f04c7bb04dcc241b9ed6ca411fc9653f09 (diff)
parentc6133d2558ce29e44342fa7be8bb65e0059aea02 (diff)
downloadvolse-hubzilla-9722d157bf138753bc168f68c56b4963db6da4e9.tar.gz
volse-hubzilla-9722d157bf138753bc168f68c56b4963db6da4e9.tar.bz2
volse-hubzilla-9722d157bf138753bc168f68c56b4963db6da4e9.zip
Merge branch 'dev' into bs5
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php87
1 files changed, 62 insertions, 25 deletions
diff --git a/include/text.php b/include/text.php
index 8dc5ee188..841abdbd3 100644
--- a/include/text.php
+++ b/include/text.php
@@ -11,6 +11,7 @@ use Ramsey\Uuid\Exception\UnableToBuildUuidException;
use Zotlabs\Lib\Crypto;
use Zotlabs\Lib\SvgSanitizer;
+use Zotlabs\Lib\Libzot;
require_once("include/bbcode.php");
@@ -1714,19 +1715,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'];
+ }
+ }
}
}
@@ -2837,7 +2852,7 @@ function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true)
// BEGIN mentions
- if ( in_array($termtype, [ TERM_MENTION, TERM_FORUM ] )) {
+ if ($termtype === TERM_MENTION) {
// The @! tag will alter permissions
@@ -2864,14 +2879,13 @@ function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true)
$newname = substr($name,1);
$newname = substr($newname,0,-1);
- $r = q("SELECT * FROM xchan WHERE xchan_addr = '%s' OR xchan_url = '%s' AND xchan_deleted = 0",
+ $r = q("SELECT * FROM xchan WHERE ( xchan_addr = '%s' OR xchan_url = '%s' ) AND xchan_deleted = 0",
dbesc($newname),
dbesc($newname)
);
}
if(! $r) {
-
// look for matching names in the address book
// Double quote the entire mentioned term to include special characters
@@ -2926,7 +2940,10 @@ function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true)
// $r is set if we found something
if($r) {
- foreach($r as $xc) {
+
+ $xchan[0] = Libzot::zot_record_preferred($r, 'xchan_network');
+
+ foreach($xchan as $xc) {
$profile = $xc['xchan_url'];
$newname = $xc['xchan_name'];
// add the channel's xchan_hash to $access_tag if exclusive
@@ -2941,16 +2958,9 @@ function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true)
//create profile link
$profile = str_replace(',','%2c',$profile);
$url = $profile;
-/*
- if($termtype === TERM_FORUM) {
- $newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
- $body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
- }
-*/
- if ($termtype === TERM_MENTION) {
- $newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
- $body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
- }
+
+ $newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
+ $body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
// append tag to str_tags
if(! stristr($str_tags,$newtag)) {
@@ -3880,3 +3890,30 @@ function sanitize_text_field($str) {
return preg_replace('/\s+/S', ' ', $str);
}
+/**
+ * @brief shortens a string to $max_length without cutting off words
+ * @param string $str
+ * @param intval $max_length
+ * @param string $suffix (optional)
+
+ * @return string
+ */
+function substr_words($str, $max_length, $suffix = '...') {
+
+ if (strlen($str) > $max_length) {
+ $words = preg_split('/\s/', $str);
+ $ret = '';
+ $i = 0;
+ while (true) {
+ $length = (strlen($ret) + strlen($words[$i]));
+ if ($length > $max_length) {
+ break;
+ }
+ $ret .= " " . $words[$i];
+ ++$i;
+ }
+ $ret .= $suffix;
+ }
+
+ return (($ret) ? $ret : $str);
+}