]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Many more app-variables removed
[friendica.git] / include / conversation.php
index 5b49bc9dc1297eb3fb43296476b0ce0fcefb9dea..32e705290ddc141cbfba3ebe4df009e69720366a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -42,95 +42,11 @@ use Friendica\Object\Thread;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 use Friendica\Util\XML;
 
-function item_extract_images($body) {
-
-       $saved_image = [];
-       $orig_body = $body;
-       $new_body = '';
-
-       $cnt = 0;
-       $img_start = strpos($orig_body, '[img');
-       $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
-       $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
-       while (($img_st_close !== false) && ($img_end !== false)) {
-
-               $img_st_close++; // make it point to AFTER the closing bracket
-               $img_end += $img_start;
-
-               if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
-                       // This is an embedded image
-
-                       $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
-                       $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
-
-                       $cnt++;
-               } else {
-                       $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
-               }
-
-               $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
-
-               if ($orig_body === false) {
-                       // in case the body ends on a closing image tag
-                       $orig_body = '';
-               }
-
-               $img_start = strpos($orig_body, '[img');
-               $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
-               $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
-       }
-
-       $new_body = $new_body . $orig_body;
-
-       return ['body' => $new_body, 'images' => $saved_image];
-}
-
-function item_redir_and_replace_images($body, $images, $cid) {
-
-       $origbody = $body;
-       $newbody = '';
-
-       $cnt = 1;
-       $pos = BBCode::getTagPosition($origbody, 'url', 0);
-       while ($pos !== false && $cnt < 1000) {
-
-               $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
-               $replace = '[url=' . DI::baseUrl() . '/redir/' . $cid
-                                  . '?url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
-
-               $newbody .= substr($origbody, 0, $pos['start']['open']);
-               $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
-               $origbody = substr($origbody, $pos['end']['close']);
-               if ($origbody === false) {
-                       $origbody = '';
-               }
-
-               $subject = preg_replace($search, $replace, $subject);
-               $newbody .= $subject;
-
-               $cnt++;
-               // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
-               $pos = BBCode::getTagPosition($origbody, 'url', 0);
-       }
-       $newbody .= $origbody;
-
-       $cnt = 0;
-       foreach ($images as $image) {
-               /*
-                * We're depending on the property of 'foreach' (specified on the PHP website) that
-                * it loops over the array starting from the first element and going sequentially
-                * to the last element.
-                */
-               $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
-               $cnt++;
-       }
-       return $newbody;
-}
-
 /**
  * Render actions localized
  *
@@ -140,12 +56,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
  */
 function localize_item(&$item)
 {
-       $extracted = item_extract_images($item['body']);
-       if ($extracted['images']) {
-               $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
-       }
-
-       /// @todo The following functionality needs to be cleaned up. 
+       /// @todo The following functionality needs to be cleaned up.
        if (!empty($item['verb'])) {
                $activity = DI::activity();
 
@@ -160,9 +71,6 @@ function localize_item(&$item)
                                return;
                        }
 
-                       $Aname = $item['author-name'];
-                       $Alink = $item['author-link'];
-
                        $obj = XML::parseString($xmlhead . $item['object']);
 
                        $Bname = $obj->title;
@@ -177,9 +85,17 @@ function localize_item(&$item)
                                }
                        }
 
-                       $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
-                       $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
-                       if ($Bphoto != "") {
+                       $author = ['uid' => 0, 'id' => $item['author-id'],
+                               'network' => $item['author-network'], 'url' => $item['author-link']];
+                       $A = '[url=' . Contact::magicLinkByContact($author) . ']' . $item['author-name'] . '[/url]';
+
+                       if (!empty($Blink)) {
+                               $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
+                       } else {
+                               $B = '';
+                       }
+
+                       if ($Bphoto != "" && !empty($Blink)) {
                                $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
                        }
 
@@ -254,19 +170,11 @@ function localize_item(&$item)
                }
        }
 
-       // add zrl's to public images
-       $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
-       if (preg_match($photo_pattern, $item['body'])) {
-               $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' , true) . '][img' . '$4' . ']h' . '$5'  . '[/img][/url]';
-               $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
-       }
-
        // add sparkle links to appropriate permalinks
-       $author = ['uid' => 0, 'id' => $item['author-id'],
-               'network' => $item['author-network'], 'url' => $item['author-link']];
-
        // Only create a redirection to a magic link when logged in
        if (!empty($item['plink']) && Session::isAuthenticated()) {
+               $author = ['uid' => 0, 'id' => $item['author-id'],
+                       'network' => $item['author-network'], 'url' => $item['author-link']];
                $item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
        }
 }
@@ -364,7 +272,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
 
        $ssl_state = (local_user() ? true : false);
 
-       $profile_owner = 0;
        $live_update_div = '';
 
        $blocklist = conv_get_blocklist();
@@ -373,7 +280,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
 
        if ($mode === 'network') {
                $items = conversation_add_children($items, false, $order, $uid);
-               $profile_owner = local_user();
                if (!$update) {
                        /*
                         * The special div is needed for liveUpdate to kick in for this page.
@@ -400,7 +306,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                }
        } elseif ($mode === 'profile') {
                $items = conversation_add_children($items, false, $order, $uid);
-               $profile_owner = $a->profile['uid'];
 
                if (!$update) {
                        $tab = 'posts';
@@ -414,13 +319,12 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                 */
 
                                $live_update_div = '<div id="live-profile"></div>' . "\r\n"
-                                       . "<script> var profile_uid = " . $a->profile['uid']
+                                       . "<script> var profile_uid = " . $uid
                                        . "; var netargs = '?f='; </script>\r\n";
                        }
                }
        } elseif ($mode === 'notes') {
                $items = conversation_add_children($items, false, $order, local_user());
-               $profile_owner = local_user();
 
                if (!$update) {
                        $live_update_div = '<div id="live-notes"></div>' . "\r\n"
@@ -429,7 +333,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                }
        } elseif ($mode === 'display') {
                $items = conversation_add_children($items, false, $order, $uid);
-               $profile_owner = $a->profile['uid'];
 
                if (!$update) {
                        $live_update_div = '<div id="live-display"></div>' . "\r\n"
@@ -438,7 +341,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                }
        } elseif ($mode === 'community') {
                $items = conversation_add_children($items, true, $order, $uid);
-               $profile_owner = 0;
 
                if (!$update) {
                        $live_update_div = '<div id="live-community"></div>' . "\r\n"
@@ -449,7 +351,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                }
        } elseif ($mode === 'contacts') {
                $items = conversation_add_children($items, false, $order, $uid);
-               $profile_owner = 0;
 
                if (!$update) {
                        $live_update_div = '<div id="live-contact"></div>' . "\r\n"
@@ -460,7 +361,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                $live_update_div = '<div id="live-search"></div>' . "\r\n";
        }
 
-       $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
+       $page_dropping = ((local_user() && local_user() == $uid) ? true : false);
 
        if (!$update) {
                $_SESSION['return_path'] = DI::args()->getQueryString();
@@ -477,7 +378,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                'attendyes'   => [],
                'attendno'    => [],
                'attendmaybe' => [],
-               'announce'    => [],    
+               'announce'    => [],
        ];
 
        if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
@@ -599,7 +500,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                        'name' => $profile_name,
                                        'sparkle' => $sparkle,
                                        'lock' => false,
-                                       'thumb' => DI::baseUrl()->remove($item['author-avatar']),
+                                       'thumb' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)),
                                        'title' => $title,
                                        'body_html' => $body_html,
                                        'tags' => $tags['tags'],
@@ -619,7 +520,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                        'indent' => '',
                                        'owner_name' => '',
                                        'owner_url' => '',
-                                       'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']),
+                                       'owner_photo' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)),
                                        'plink' => Item::getPlink($item),
                                        'edpost' => false,
                                        'isstarred' => 'unstarred',
@@ -721,7 +622,7 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
        while ($row = Post::fetch($thread_items)) {
                if (!empty($activity)) {
                        if (($row['gravity'] == GRAVITY_PARENT)) {
-                               $row['post-type'] = Item::PT_ANNOUNCEMENT;
+                               $row['post-reason'] = Item::PR_ANNOUNCEMENT;
                                $row = array_merge($row, $activity);
                                $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
                                $row['causer-link'] = $contact['url'];
@@ -733,28 +634,26 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
                        }
                }
 
-               $name = $row['causer-contact-type'] == Contact::TYPE_RELAY ? $row['causer-link'] : $row['causer-name'];
-
-               switch ($row['post-type']) {
-                       case Item::PT_TO:
+               switch ($row['post-reason']) {
+                       case Item::PR_TO:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
                                break;
-                       case Item::PT_CC:
+                       case Item::PR_CC:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
                                break;
-                       case Item::PT_BTO:
+                       case Item::PR_BTO:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
                                break;
-                       case Item::PT_BCC:
+                       case Item::PR_BCC:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
                                break;
-                       case Item::PT_FOLLOWER:
+                       case Item::PR_FOLLOWER:
                                $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
                                break;
-                       case Item::PT_TAG:
+                       case Item::PR_TAG:
                                $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
                                break;
-                       case Item::PT_ANNOUNCEMENT:
+                       case Item::PR_ANNOUNCEMENT:
                                if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')) {
                                        $row['owner-id'] = $row['causer-id'];
                                        $row['owner-link'] = $row['causer-link'];
@@ -763,24 +662,26 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
                                }
 
                                if (($row['gravity'] == GRAVITY_PARENT) && !empty($row['causer-id'])) {
-                                       $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkById($row['causer-id'])) .'">' . htmlentities($name) . '</a>');
+                                       $causer = ['uid' => 0, 'id' => $row['causer-id'],
+                                               'network' => $row['causer-network'], 'url' => $row['causer-link']];
+                                       $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($row['causer-name']) . '</a>');
                                }
-                               $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s', $name))];
+                               $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s <%s>', $row['causer-name'], $row['causer-link']))];
                                break;
-                       case Item::PT_COMMENT:
+                       case Item::PR_COMMENT:
                                $row['direction'] = ['direction' => 5, 'title' => DI::l10n()->t('%s is participating in this thread.', $row['author-name'])];
                                break;
-                       case Item::PT_STORED:
+                       case Item::PR_STORED:
                                $row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
                                break;
-                       case Item::PT_GLOBAL:
+                       case Item::PR_GLOBAL:
                                $row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
                                break;
-                       case Item::PT_RELAY:
-                               $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Relayed') : DI::l10n()->t('Relayed by %s.', $name))];
+                       case Item::PR_RELAY:
+                               $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Relayed') : DI::l10n()->t('Relayed by %s <%s>', $row['causer-name'], $row['causer-link']))];
                                break;
-                       case Item::PT_FETCHED:
-                               $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Fetched') : DI::l10n()->t('Fetched because of %s', $name))];
+                       case Item::PR_FETCHED:
+                               $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Fetched') : DI::l10n()->t('Fetched because of %s <%s>', $row['causer-name'], $row['causer-link']))];
                                break;
                        }
 
@@ -833,8 +734,8 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
                                $activity = ['causer-id' => $parent['author-id']];
                                foreach (['commented', 'received', 'created'] as $orderfields) {
                                        if (!empty($parent[$orderfields])) {
-                                               $activity[$orderfields] = $parent[$orderfields];        
-                                       }       
+                                               $activity[$orderfields] = $parent[$orderfields];
+                                       }
                                }
                        }
                } else {
@@ -872,7 +773,7 @@ function conversation_fetch_items(array $parent, array $items, array $condition,
                $condition[0] .= " AND NOT `author-hidden`";
        }
 
-       $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params);
+       $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
 
        $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity);
 
@@ -882,7 +783,8 @@ function conversation_fetch_items(array $parent, array $items, array $condition,
        return $items;
 }
 
-function item_photo_menu($item) {
+function item_photo_menu($item)
+{
        $sub_link = '';
        $poke_link = '';
        $contact_url = '';
@@ -893,7 +795,7 @@ function item_photo_menu($item) {
        $block_link = '';
        $ignore_link = '';
 
-       if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) {
+       if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
                $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
        }
 
@@ -903,7 +805,7 @@ function item_photo_menu($item) {
        $sparkle = (strpos($profile_link, 'redir/') === 0);
 
        $cid = 0;
-       $pcid = Contact::getIdForURL($item['author-link'], 0, false);
+       $pcid = $item['author-id'];
        $network = '';
        $rel = 0;
        $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
@@ -923,8 +825,8 @@ function item_photo_menu($item) {
        if (!empty($pcid)) {
                $contact_url = 'contact/' . $pcid;
                $posts_link  = $contact_url . '/posts';
-               $block_link  = $contact_url . '/block';
-               $ignore_link = $contact_url . '/ignore';
+               $block_link  = $item['self'] ? '' : $contact_url . '/block';
+               $ignore_link = $item['self'] ? '' : $contact_url . '/ignore';
        }
 
        if ($cid && !$item['self']) {
@@ -977,7 +879,7 @@ function item_photo_menu($item) {
                if (strpos($v, 'javascript:') === 0) {
                        $v = substr($v, 11);
                        $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
-               } elseif ($v!='') {
+               } elseif ($v) {
                        $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
                }
        }
@@ -1205,6 +1107,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$edimg'        => DI::l10n()->t('Image'),
                '$edurl'        => DI::l10n()->t('Link'),
                '$edattach'     => DI::l10n()->t('Link or Media'),
+               '$edvideo'      => DI::l10n()->t('Video'),
                '$setloc'       => DI::l10n()->t('Set your location'),
                '$shortsetloc'  => DI::l10n()->t('set location'),
                '$noloc'        => DI::l10n()->t('Clear browser location'),
@@ -1231,7 +1134,6 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$preview'      => DI::l10n()->t('Preview'),
                '$jotplugins'   => $jotplugins,
                '$notes_cid'    => $notes_cid,
-               '$sourceapp'    => DI::l10n()->t($a->sourcename),
                '$cancel'       => DI::l10n()->t('Cancel'),
                '$rand_num'     => Crypto::randomDigits(12),