aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php195
1 files changed, 108 insertions, 87 deletions
diff --git a/include/text.php b/include/text.php
index b03e2d1a9..9ac6efdc2 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1145,7 +1145,7 @@ function chanlink_cid($d) {
function magiclink_url($observer,$myaddr,$url) {
return (($observer)
- ? z_root() . '/magic?f=&owa=1&bdest=' . bin2hex($url) . '&addr=' . $myaddr
+ ? z_root() . '/magic?owa=1&bdest=' . bin2hex($url) . '&addr=' . $myaddr
: $url
);
}
@@ -1272,24 +1272,38 @@ function sslify($s) {
function get_emojis() {
$emojis = [
// Reactions (emojitwo emojis)
- 'astonished_face' => ['shortname' => ':astonished_face:', 'filepath' => 'images/emoji/astonished_face.png'],
- 'bottle_with_popping_cork' => ['shortname' => ':bottle_with_popping_cork:', 'filepath' => 'images/emoji/bottle_with_popping_cork.png'],
- 'clapping_hands' => ['shortname' => ':clapping_hands:', 'filepath' => 'images/emoji/clapping_hands.png'],
- 'disappointed_face' => ['shortname' => ':disappointed_face:', 'filepath' => 'images/emoji/disappointed_face.png'],
- 'grinning_face' => ['shortname' => ':grinning_face:', 'filepath' => 'images/emoji/grinning_face.png'],
- 'kiss_mark' => ['shortname' => ':kiss_mark:', 'filepath' => 'images/emoji/kiss_mark.png'],
- 'red_heart' => ['shortname' => ':red_heart:', 'filepath' => 'images/emoji/red_heart.png'],
- 'sleeping_face' => ['shortname' => ':sleeping_face:', 'filepath' => 'images/emoji/sleeping_face.png'],
- 'slightly_smiling_face' => ['shortname' => ':slightly_smiling_face:', 'filepath' => 'images/emoji/slightly_smiling_face.png'],
- 'smiling_face_with_halo' => ['shortname' => ':smiling_face_with_halo:', 'filepath' => 'images/emoji/smiling_face_with_halo.png'],
- 'smiling_face_with_horns' => ['shortname' => ':smiling_face_with_horns:', 'filepath' => 'images/emoji/smiling_face_with_horns.png'],
- 'winking_face_with_tongue' => ['shortname' => ':winking_face_with_tongue:', 'filepath' => 'images/emoji/winking_face_with_tongue.png'],
-
- 'facepalm' => ['shortname' => ':facepalm:', 'filepath' => 'images/emoticons/smiley-facepalm.gif']
+ 'astonished_face' => ['shortname' => ':astonished_face:', 'filepath' => 'images/emoji/emojitwo/astonished_face.png'],
+ 'bottle_with_popping_cork' => ['shortname' => ':bottle_with_popping_cork:', 'filepath' => 'images/emoji/emojitwo/bottle_with_popping_cork.png'],
+ 'clapping_hands' => ['shortname' => ':clapping_hands:', 'filepath' => 'images/emoji/emojitwo/clapping_hands.png'],
+ 'disappointed_face' => ['shortname' => ':disappointed_face:', 'filepath' => 'images/emoji/emojitwo/disappointed_face.png'],
+ 'grinning_face' => ['shortname' => ':grinning_face:', 'filepath' => 'images/emoji/emojitwo/grinning_face.png'],
+ 'kiss_mark' => ['shortname' => ':kiss_mark:', 'filepath' => 'images/emoji/emojitwo/kiss_mark.png'],
+ 'red_heart' => ['shortname' => ':red_heart:', 'filepath' => 'images/emoji/emojitwo/red_heart.png'],
+ 'sleeping_face' => ['shortname' => ':sleeping_face:', 'filepath' => 'images/emoji/emojitwo/sleeping_face.png'],
+ 'slightly_smiling_face' => ['shortname' => ':slightly_smiling_face:', 'filepath' => 'images/emoji/emojitwo/slightly_smiling_face.png'],
+ 'smiling_face_with_halo' => ['shortname' => ':smiling_face_with_halo:', 'filepath' => 'images/emoji/emojitwo/smiling_face_with_halo.png'],
+ 'smiling_face_with_horns' => ['shortname' => ':smiling_face_with_horns:', 'filepath' => 'images/emoji/emojitwo/smiling_face_with_horns.png'],
+ 'winking_face_with_tongue' => ['shortname' => ':winking_face_with_tongue:', 'filepath' => 'images/emoji/emojitwo/winking_face_with_tongue.png'],
+
+ // Hubzilla custom
+ 'facepalm' => ['shortname' => ':facepalm:', 'filepath' => 'images/emoji/hubzilla/smiley-facepalm.gif'],
+ 'hubzilla' => ['shortname' => ':hubzilla:', 'filepath' => 'images/emoji/hubzilla/hubzilla.png']
];
+ // Provided by addon
call_hooks('get_emojis', $emojis);
+ // Custom site emojis
+ $custom_json_path = 'images/emoji/custom/custom_emojis.json';
+ if (file_exists($custom_json_path)) {
+ $custom_json = file_get_contents($custom_json_path);
+ $custom_arr = json_decode($custom_json, true);
+
+ if ($custom_arr) {
+ $emojis = array_merge($emojis, $custom_arr);
+ }
+ }
+
return $emojis;
}
@@ -1406,14 +1420,12 @@ function list_smilies($default_only = false) {
* @param boolean $sample (optional) default false
* @return string
*/
-function smilies($s, $sample = false) {
-
+function smilies($s, $sample = false, $terms = []) {
if(intval(Config::Get('system', 'no_smilies'))
|| (local_channel() && intval(get_pconfig(local_channel(), 'system', 'no_smilies'))))
return $s;
-
- $s = preg_replace_callback('{<(pre|code)>.*?</\1>}ism', 'smile_shield', $s);
+ $s = preg_replace_callback('/<(pre|code)\b[^>]*>.*?<\/(pre|code)>/ism', 'smile_shield', $s);
$s = preg_replace_callback('/<[a-z]+ .*?>/ism', 'smile_shield', $s);
if (preg_match_all('/(\:(\w|\+|\-)+\:)(?=|[\!\.\?]|$)/', $s, $match)) {
@@ -1421,13 +1433,23 @@ function smilies($s, $sample = false) {
$emojis = get_emojis();
foreach ($match[0] as $mtch) {
$name = trim($mtch, ':');
+ $emoji = $emojis[$name] ?? [];
+
+ if (!$emoji && !empty($terms)) {
+ foreach($terms as $term) {
+ // some platforms provide the term without :
+ $term['term'] = ':' . trim($term['term'], ':') . ':';
+ if (intval($term['ttype']) === TERM_EMOJI && $term['term'] === $mtch) {
+ $emoji['filepath'] = $term['imgurl'];
+ $emoji['shortname'] = $term['term'];
+ }
+ }
+ }
- if (!isset($emojis[$name])) {
+ if (!$emoji || empty($emoji['filepath'])) {
continue;
}
- $emoji = $emojis[$name];
-
$class = 'emoji';
if (is_solo_string($mtch, $s)) {
$class .= ' single-emoji';
@@ -1579,18 +1601,16 @@ function theme_attachments(&$item) {
$title = t('Size') . ' ' . (isset($r['length']) ? userReadableSize($r['length']) : t('unknown'));
- $revision = $r['revision'] ?? '';
-
require_once('include/channel.php');
if (isset($r['href'])) {
if(is_foreigner($item['author_xchan']))
$url = $r['href'];
else
- $url = z_root() . '/magic?f=&owa=1&hash=' . $item['author_xchan'] . '&bdest=' . bin2hex($r['href'] . '/' . $revision);
+ $url = z_root() . '/magic?owa=1&bdest=' . bin2hex($r['href']);
}
- if (isset($label) && isset($url) && isset($icon) && isset($title)) {
+ if (isset($label, $url, $icon, $title)) {
array_unshift($attaches, ['label' => $label, 'url' => $url, 'icon' => $icon, 'title' => $title]);
}
}
@@ -1652,7 +1672,7 @@ function format_hashtags(&$item) {
if($s)
$s .= ' ';
- $s .= '<span class="badge rounded-pill bg-info"><i class="fa fa-hashtag"></i>&nbsp;<a class="text-white" href="' . zid($t['url']) . '" >' . $term . '</a></span>';
+ $s .= '<span class="badge rounded-pill bg-info"><i class="bi bi-hash"></i>&nbsp;<a class="text-white" href="' . zid($t['url']) . '" >' . $term . '</a></span>';
}
}
@@ -1675,7 +1695,7 @@ function format_mentions(&$item) {
continue;
if($s)
$s .= ' ';
- $s .= '<span class="badge rounded-pill bg-success"><i class="fa fa-at"></i>&nbsp;<a class="text-white" href="' . zid($t['url']) . '" >' . $term . '</a></span>';
+ $s .= '<span class="badge rounded-pill bg-success"><i class="bi bi-at"></i>&nbsp;<a class="text-white" href="' . zid($t['url']) . '" >' . $term . '</a></span>';
}
}
@@ -1795,7 +1815,7 @@ function prepare_body(&$item,$attach = false,$opts = false) {
$s .= prepare_text('[summary]' . $item['summary'] . '[/summary]' . $item['body'],$item['mimetype'],$opts);
}
else {
- $s .= prepare_text($item['body'],$item['mimetype'], $opts);
+ $s .= prepare_text($item['body'],$item['mimetype'], $opts, $item['term'] ?? []);
}
}
@@ -2004,7 +2024,7 @@ function format_poll($item,$s,$opts) {
$message .= t('Poll has ended');
}
else {
- $message .= sprintf(t('Poll ends in %s'), '<span class="autotime" title="' . $t . '"></span>');
+ $message .= sprintf(t('Poll ends %s'), '<span class="autotime" title="' . $t . '"></span>');
}
}
@@ -2041,8 +2061,7 @@ function format_poll($item,$s,$opts) {
* @return string
* The parsed $text as prepared HTML.
*/
-function prepare_text($text, $content_type = 'text/bbcode', $opts = false) {
-
+function prepare_text($text, $content_type = 'text/bbcode', $opts = false, $terms = []) {
switch($content_type) {
case 'text/plain':
$s = escape_tags($text);
@@ -2088,7 +2107,7 @@ function prepare_text($text, $content_type = 'text/bbcode', $opts = false) {
$s = bbcode($text, ((is_array($opts)) ? $opts : [] ));
}
else {
- $s = smilies(bbcode($text, ((is_array($opts)) ? $opts : [] )));
+ $s = smilies(bbcode($text, ((is_array($opts)) ? $opts : [] )), terms: $terms);
}
}
@@ -2168,7 +2187,7 @@ function get_plink($item,$conversation_mode = true) {
if(array_key_exists('author',$item) && $item['author']['xchan_network'] !== 'zot6')
$zidify = false;
- if(x($item,$key)) {
+ if(!empty($item[$key])) {
return array(
'href' => (($zidify) ? zid($item[$key]) : $item[$key]),
'title' => t('Link to Source'),
@@ -2361,17 +2380,19 @@ function item_post_type($item) {
$post_type = t('event');
break;
default:
- $post_type = t('post');
+ $post_type = t('conversation');
if($item['mid'] != $item['parent_mid'])
- $post_type = t('comment');
+ $post_type = t('message');
break;
}
- if(strlen($item['verb']) && (! activity_match($item['verb'],ACTIVITY_POST)))
+ if(strlen($item['verb']) && (!activity_match($item['verb'], ['Create', ACTIVITY_POST]))) {
$post_type = t('activity');
+ }
- if($item['obj_type'] === 'Question')
+ if($item['obj_type'] === 'Question') {
$post_type = t('poll');
+ }
return $post_type;
}
@@ -2632,20 +2653,20 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0) {
$arr[] = "'" . dbesc($item['owner_xchan']) . "'";
if($item['author_xchan'] && (! in_array("'" . dbesc($item['author_xchan']) . "'",$arr)))
$arr[] = "'" . dbesc($item['author_xchan']) . "'";
- if($item['source_xchan'] && (! in_array("'" . dbesc($item['source_xchan']) . "'",$arr)))
+ if(!empty($item['source_xchan']) && (! in_array("'" . dbesc($item['source_xchan']) . "'",$arr)))
$arr[] = "'" . dbesc($item['source_xchan']) . "'";
}
}
if(count($arr)) {
if($abook) {
$chans = q("select * from xchan left join hubloc on hubloc_hash = xchan_hash left join abook on abook_xchan = xchan_hash and abook_channel = %d
- where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_deleted = 0 order by hubloc_primary desc",
+ where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") order by hubloc_primary desc, hubloc_deleted ASC",
intval($item['uid'])
);
}
else {
$chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash
- where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_deleted = 0 order by hubloc_primary desc");
+ where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") order by hubloc_primary desc, hubloc_deleted ASC");
}
$xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$arr)) . ") and xchan_network in ('rss','unknown', 'anon', 'token')");
if(! $chans)
@@ -2657,7 +2678,9 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0) {
for($x = 0; $x < count($items); $x ++) {
$items[$x]['owner'] = find_xchan_in_array($items[$x]['owner_xchan'],$chans);
$items[$x]['author'] = find_xchan_in_array($items[$x]['author_xchan'],$chans);
- $items[$x]['source'] = find_xchan_in_array($items[$x]['source_xchan'],$chans);
+ if (!empty($items[$x]['source_xchan'])) {
+ $items[$x]['source'] = find_xchan_in_array($items[$x]['source_xchan'],$chans);
+ }
}
}
}
@@ -3203,53 +3226,54 @@ function linkify_tags(&$body, $uid, $in_network = true) {
function getIconFromType($type) {
$iconMap = array(
//Folder
- 'Collection' => 'fa-folder-o',
- 'multipart/mixed' => 'fa-folder-o', //dirs in attach use this mime type
+ 'Collection' => 'bi-folder',
+ 'multipart/mixed' => 'bi-folder', //dirs in attach use this mime type
//Common file
- 'application/octet-stream' => 'fa-file-o',
+ 'application/octet-stream' => 'bi-file-earmark',
//Text
- 'text/plain' => 'fa-file-text-o',
- 'text/markdown' => 'fa-file-text-o',
- 'text/bbcode' => 'fa-file-text-o',
- 'text/html' => 'fa-file-text-o',
- 'application/msword' => 'fa-file-word-o',
- 'application/pdf' => 'fa-file-pdf-o',
- 'application/vnd.oasis.opendocument.text' => 'fa-file-word-o',
- 'application/epub+zip' => 'fa-book',
+ 'text/plain' => 'bi-file-earmark-text',
+ 'text/markdown' => 'bi-filetype-md',
+ 'text/bbcode' => 'bi-file-earmark-text',
+ 'text/html' => 'bi-filetype-html',
+ 'text/uri-list' => 'bi-box-arrow-up-right',
+ 'application/msword' => 'bi-file-earmark-word',
+ 'application/pdf' => 'bi-file-earmark-pdf',
+ 'application/vnd.oasis.opendocument.text' => 'bifile--earmark-text',
+ 'application/epub+zip' => 'bi-file-earmark-text',
//Spreadsheet
- 'application/vnd.oasis.opendocument.spreadsheet' => 'fa-file-excel-o',
- 'application/vnd.ms-excel' => 'fa-file-excel-o',
+ 'application/vnd.oasis.opendocument.spreadsheet' => 'bi-file-earmark-spreadsheet',
+ 'application/vnd.ms-excel' => 'bi-file-earmark-spreadsheet',
//Image
- 'image/jpeg' => 'fa-picture-o',
- 'image/png' => 'fa-picture-o',
- 'image/gif' => 'fa-picture-o',
- 'image/webp' => 'fa-picture-o',
- 'image/svg+xml' => 'fa-picture-o',
+ 'image/jpeg' => 'bi-file-earmark-image',
+ 'image/png' => 'bi-file-earmark-image',
+ 'image/gif' => 'bi-file-earmark-image',
+ 'image/webp' => 'bi-file-earmark-image',
+ 'image/svg+xml' => 'bi-filetype-svg',
//Archive
- 'application/zip' => 'fa-file-archive-o',
- 'application/x-rar-compressed' => 'fa-file-archive-o',
+ 'application/zip' => 'bi-file-earmark-zip',
+ 'application/x-rar-compressed' => 'bi-file-earmark-zip',
//Audio
- 'audio/mpeg' => 'fa-file-audio-o',
- 'audio/wav' => 'fa-file-audio-o',
- 'application/ogg' => 'fa-file-audio-o',
- 'audio/ogg' => 'fa-file-audio-o',
- 'audio/webm' => 'fa-file-audio-o',
- 'audio/mp4' => 'fa-file-audio-o',
+ 'audio/mpeg' => 'bi-file-earmark-music',
+ 'audio/wav' => 'bi-file-earmark-music',
+ 'application/ogg' => 'bi-file-earmark-music',
+ 'audio/ogg' => 'bi-file-earmark-music',
+ 'audio/webm' => 'bi-file-earmark-music',
+ 'audio/mp4' => 'bi-file-earmark-music',
//Video
- 'video/quicktime' => 'fa-file-video-o',
- 'video/webm' => 'fa-file-video-o',
- 'video/mp4' => 'fa-file-video-o',
- 'video/x-matroska' => 'fa-file-video-o'
+ 'video/quicktime' => 'bi-file-earmark-play',
+ 'video/webm' => 'bi-file-earmark-play',
+ 'video/mp4' => 'bi-file-earmark-play',
+ 'video/x-matroska' => 'bi-file-earmark-play'
);
$catMap = [
- 'application' => 'fa-file-code-o',
- 'multipart' => 'fa-folder',
- 'audio' => 'fa-file-audio-o',
- 'video' => 'fa-file-video-o',
- 'text' => 'fa-file-text-o',
- 'image' => 'fa=file-picture-o',
- 'message' => 'fa-file-text-o'
+ 'application' => 'bi-file-earmark',
+ 'multipart' => 'bi-folder',
+ 'audio' => 'bi-file-earmark-music',
+ 'video' => 'bi-file-earmark-play',
+ 'text' => 'bi-file-earmark-text',
+ 'image' => 'bi-file-earmark-image',
+ 'message' => 'bi-file-earmark-text'
];
@@ -3266,7 +3290,7 @@ function getIconFromType($type) {
}
if(! $iconFromType) {
- $iconFromType = 'fa-file-o';
+ $iconFromType = 'bi-file-earmark';
}
@@ -3755,12 +3779,9 @@ function cleanup_bbcode($body) {
$body = preg_replace_callback('/\[img(.*?)\[\/(img)\]/ism','\red_escape_codeblock',$body);
$body = preg_replace_callback('/\[zmg(.*?)\[\/(zmg)\]/ism','\red_escape_codeblock',$body);
- $body = preg_replace_callback("/([^\]\='".'"'."\;\/\{]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\
-+\,\(\)]+)/ismu", '\nakedoembed', $body);
-
- $body = preg_replace_callback("/([^\]\='".'"'."\;\/\{]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\
-+\,\(\)]+)/ismu", '\red_zrl_callback', $body);
+ $body = preg_replace_callback("/([^\]\='".'"'."\;\/\{]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\+\,\(\)]+)/ismu", '\nakedoembed', $body);
+ $body = preg_replace_callback("/([^\]\='".'"'."\;\/\{]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\+\,\(\)]+)/ismu", '\red_zrl_callback', $body);
$body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','\red_unescape_codeblock',$body);
$body = preg_replace_callback('/\[\$b64summary(.*?)\[\/(summary)\]/ism','\red_unescape_codeblock',$body);
@@ -3846,7 +3867,7 @@ function featured_sort($a,$b) {
function unpunify($s) {
- if (function_exists('idn_to_utf8') && isset($s)) {
+ if (function_exists('idn_to_utf8') && !empty($s)) {
return idn_to_utf8($s);
}
return $s;
@@ -3854,7 +3875,7 @@ function unpunify($s) {
function punify($s) {
- if (function_exists('idn_to_ascii') && isset($s)) {
+ if (function_exists('idn_to_ascii') && !empty($s)) {
return idn_to_ascii($s);
}
return $s;