3 * @file include/text.php
6 use Friendica\Content\Text\BBCode;
7 use Friendica\Model\FileTag;
10 * Compare activity uri. Knows about activity namespace.
12 * @param string $haystack
13 * @param string $needle
16 function activity_match($haystack,$needle) {
17 return (($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
21 * quick and dirty quoted_printable encoding
27 return str_replace("%", "=", rawurlencode($s));
31 * @brief Given a text string, convert from bbcode to html and add smilie icons.
33 * @param string $text String with bbcode.
34 * @return string Formatted HTML
35 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
37 function prepare_text($text)
39 $s = BBCode::convert($text);
44 * return array with details for categories and folders for an item
50 * [ // categories array
52 * 'name': 'category name',
53 * 'removeurl': 'url to remove this category',
54 * 'first': 'is the first in this array? true/false',
55 * 'last': 'is the last in this array? true/false',
61 * 'name': 'folder name',
62 * 'removeurl': 'url to remove this folder',
63 * 'first': 'is the first in this array? true/false',
64 * 'last': 'is the last in this array? true/false',
70 function get_cats_and_terms($item)
76 foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
78 'name' => $savedFolderName,
80 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
87 if (count($categories)) {
88 $categories[count($categories) - 1]['last'] = true;
91 if (local_user() == $item['uid']) {
92 foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
94 'name' => $savedFolderName,
96 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
104 if (count($folders)) {
105 $folders[count($folders) - 1]['last'] = true;
108 return [$categories, $folders];
111 /// @TODO Rewrite this
112 function is_a_date_arg($s) {
118 if ($i <= $y + 1 && strpos($s, '-') == 4) {
119 $m = intval(substr($s, 5));
121 if ($m > 0 && $m <= 12) {