]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge pull request #7711 from annando/gserver-2
[friendica.git] / include / text.php
index b4e8dbf1128aff15cdedfa4e991288a6b67cc5b4..2050e57026e77453560e4a81f6e53f56358289e7 100644 (file)
@@ -4,33 +4,12 @@
  */
 
 use Friendica\App;
-use Friendica\Content\ContactSelector;
-use Friendica\Content\Feature;
-use Friendica\Content\Smilies;
 use Friendica\Content\Text\BBCode;
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
-use Friendica\Core\System;
-use Friendica\Database\DBA;
 use Friendica\Model\Contact;
-use Friendica\Model\Event;
-use Friendica\Model\Item;
-use Friendica\Render\FriendicaSmarty;
-use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Map;
-use Friendica\Util\Proxy as ProxyUtils;
-
-use Friendica\Core\Logger;
-use Friendica\Core\Renderer;
 use Friendica\Model\FileTag;
+use Friendica\Model\Group;
 use Friendica\Util\Strings;
-use Friendica\Util\XML;
-use Friendica\Content\Text\HTML;
-
-require_once "include/conversation.php";
 
 /**
  * Turn user/group ACLs stored as angle bracketed text into arrays
@@ -41,18 +20,9 @@ require_once "include/conversation.php";
 function expand_acl($s) {
        // turn string array of angle-bracketed elements into numeric array
        // e.g. "<1><2><3>" => array(1,2,3);
-       $ret = [];
+       preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $s, $matches, PREG_PATTERN_ORDER);
 
-       if (strlen($s)) {
-               $t = str_replace('<', '', $s);
-               $a = explode('>', $t);
-               foreach ($a as $aa) {
-                       if (intval($aa)) {
-                               $ret[] = intval($aa);
-                       }
-               }
-       }
-       return $ret;
+       return $matches[1];
 }
 
 
@@ -62,7 +32,9 @@ function expand_acl($s) {
  */
 function sanitise_acl(&$item) {
        if (intval($item)) {
-               $item = '<' . intval(Strings::removeTags(trim($item))) . '>';
+               $item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
+       } elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
+               $item = '<' . $item . '>';
        } else {
                unset($item);
        }
@@ -141,7 +113,7 @@ function qp($s) {
  */
 function redir_private_images($a, &$item)
 {
-       $matches = false;
+       $matches = [];
        $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER);
        if ($cnt) {
                foreach ($matches as $mtch) {
@@ -150,7 +122,7 @@ function redir_private_images($a, &$item)
                        }
 
                        if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == Protocol::DFRN)) {
-                               $img_url = 'redir?f=1&quiet=1&url=' . urlencode($mtch[1]) . '&conurl=' . urlencode($item['author-link']);
+                               $img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]);
                                $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
                        }
                }
@@ -161,15 +133,12 @@ function redir_private_images($a, &$item)
  * @brief Given a text string, convert from bbcode to html and add smilie icons.
  *
  * @param string $text String with bbcode.
- * @return string Formattet HTML.
+ * @return string Formatted HTML
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
-function prepare_text($text) {
-       if (stristr($text, '[nosmile]')) {
-               $s = BBCode::convert($text);
-       } else {
-               $s = Smilies::replace(BBCode::convert($text));
-       }
-
+function prepare_text($text)
+{
+       $s = BBCode::convert($text);
        return trim($s);
 }
 
@@ -204,21 +173,17 @@ function get_cats_and_terms($item)
 {
        $categories = [];
        $folders = [];
-
-       $matches = false;
        $first = true;
-       $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER);
-       if ($cnt) {
-               foreach ($matches as $mtch) {
-                       $categories[] = [
-                               'name' => XML::escape(FileTag::decode($mtch[1])),
-                               'url' =>  "#",
-                               'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . XML::escape(FileTag::decode($mtch[1])):""),
-                               'first' => $first,
-                               'last' => false
-                       ];
-                       $first = false;
-               }
+
+       foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
+               $categories[] = [
+                       'name' => $savedFolderName,
+                       'url' => "#",
+                       'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
+                       'first' => $first,
+                       'last' => false
+               ];
+               $first = false;
        }
 
        if (count($categories)) {
@@ -226,20 +191,15 @@ function get_cats_and_terms($item)
        }
 
        if (local_user() == $item['uid']) {
-               $matches = false;
-               $first = true;
-               $cnt = preg_match_all('/\[(.*?)\]/', $item['file'], $matches, PREG_SET_ORDER);
-               if ($cnt) {
-                       foreach ($matches as $mtch) {
-                               $folders[] = [
-                                       'name' => XML::escape(FileTag::decode($mtch[1])),
-                                       'url' =>  "#",
-                                       'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . XML::escape(FileTag::decode($mtch[1])) : ""),
-                                       'first' => $first,
-                                       'last' => false
-                               ];
-                               $first = false;
-                       }
+               foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
+                       $folders[] = [
+                               'name' => $savedFolderName,
+                               'url' => "#",
+                               'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
+                               'first' => $first,
+                               'last' => false
+                       ];
+                       $first = false;
                }
        }
 
@@ -253,7 +213,7 @@ function get_cats_and_terms($item)
 /**
  * return number of bytes in size (K, M, G)
  * @param string $size_str
- * @return number
+ * @return int
  */
 function return_bytes($size_str) {
        switch (substr ($size_str, -1)) {