3 * @file include/text.php
6 use Friendica\Content\Text\BBCode;
7 use Friendica\Model\FileTag;
8 use Friendica\Model\Group;
9 use Friendica\Util\Strings;
12 * Wrap ACL elements in angle brackets for storage
15 function sanitise_acl(&$item) {
17 $item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
18 } elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
19 $item = '<' . $item . '>';
27 * Convert an ACL array to a storable string
29 * Normally ACL permissions will be an array.
30 * We'll also allow a comma-separated string.
32 * @param string|array $p
35 function perms2str($p) {
40 $tmp = explode(',', $p);
44 array_walk($tmp, 'sanitise_acl');
45 $ret = implode('', $tmp);
51 * Compare activity uri. Knows about activity namespace.
53 * @param string $haystack
54 * @param string $needle
57 function activity_match($haystack,$needle) {
58 return (($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
62 * quick and dirty quoted_printable encoding
68 return str_replace("%", "=", rawurlencode($s));
72 * @brief Given a text string, convert from bbcode to html and add smilie icons.
74 * @param string $text String with bbcode.
75 * @return string Formatted HTML
76 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
78 function prepare_text($text)
80 $s = BBCode::convert($text);
85 * return array with details for categories and folders for an item
91 * [ // categories array
93 * 'name': 'category name',
94 * 'removeurl': 'url to remove this category',
95 * 'first': 'is the first in this array? true/false',
96 * 'last': 'is the last in this array? true/false',
102 * 'name': 'folder name',
103 * 'removeurl': 'url to remove this folder',
104 * 'first': 'is the first in this array? true/false',
105 * 'last': 'is the last in this array? true/false',
111 function get_cats_and_terms($item)
117 foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
119 'name' => $savedFolderName,
121 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
128 if (count($categories)) {
129 $categories[count($categories) - 1]['last'] = true;
132 if (local_user() == $item['uid']) {
133 foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
135 'name' => $savedFolderName,
137 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
145 if (count($folders)) {
146 $folders[count($folders) - 1]['last'] = true;
149 return [$categories, $folders];
152 /// @TODO Rewrite this
153 function is_a_date_arg($s) {
159 if ($i <= $y + 1 && strpos($s, '-') == 4) {
160 $m = intval(substr($s, 5));
162 if ($m > 0 && $m <= 12) {