]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Rename Friendica\Database\dba to Friendica\Database\DBA
[friendica.git] / include / conversation.php
index 5d013014b776c5eaaf0fe80ae788b02c3052ffe8..5dfd571ea58a3b1bcfbdd7fcccf6e3936fafe105 100644 (file)
@@ -12,10 +12,12 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\DBA;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
-use Friendica\Model\Profile;
 use Friendica\Model\Item;
+use Friendica\Model\Profile;
+use Friendica\Model\Term;
 use Friendica\Object\Post;
 use Friendica\Object\Thread;
 use Friendica\Util\DateTimeFormat;
@@ -262,14 +264,20 @@ function localize_item(&$item)
        }
 
        if (activity_match($item['verb'], ACTIVITY_TAG)) {
-               $fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
+               $fields = ['author-id', 'author-link', 'author-name', 'author-network',
+                       'verb', 'object-type', 'resource-id', 'body', 'plink'];
                $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
                if (!DBM::is_result($obj)) {
                        return;
                }
 
-               $author  = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
-               $objauthor =  '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
+               $author_arr = ['uid' => 0, 'id' => $item['author-id'],
+                       'network' => $item['author-network'], 'url' => $item['author-link']];
+               $author  = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $item['author-name'] . '[/url]';
+
+               $author_arr = ['uid' => 0, 'id' => $obj['author-id'],
+                       'network' => $obj['author-network'], 'url' => $obj['author-link']];
+               $objauthor  = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $obj['author-name'] . '[/url]';
 
                switch ($obj['verb']) {
                        case ACTIVITY_POST:
@@ -341,7 +349,12 @@ function localize_item(&$item)
        }
 
        // add sparkle links to appropriate permalinks
-       $item['plink'] = Contact::magicLinkById($item['author-id'], $item['plink']);
+       $author = ['uid' => 0, 'id' => $item['author-id'],
+               'network' => $item['author-network'], 'url' => $item['author-link']];
+
+       if (!empty($item['plink'])) {
+               $item['plink'] = Contact::magicLinkbyContact($author, $item['plink']);
+       }
 }
 
 /**
@@ -394,7 +407,7 @@ function visible_activity($item) {
  * that are based on unique features of the calling module.
  *
  */
-function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) {
+function conversation(App $a, array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) {
        require_once 'mod/proxy.php';
 
        $ssl_state = ((local_user()) ? true : false);
@@ -474,7 +487,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                $profile_owner = $a->profile['uid'];
                if (!$update) {
                        $live_update_div = '<div id="live-display"></div>' . "\r\n"
-                               . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
+                               . "<script> var profile_uid = " . defaults($_SESSION, 'uid', 0) . ";"
                                . " var profile_page = 1; </script>";
                }
        } elseif ($mode === 'community') {
@@ -562,21 +575,16 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                                        continue;
                                }
 
-                               if ($item['network'] == NETWORK_FEED) {
-                                       $item['author-avatar'] = $item['contact-avatar'];
-                                       $item['author-name'] = $item['contact-name'];
-                                       $item['owner-avatar'] = $item['contact-avatar'];
-                                       $item['owner-name'] = $item['contact-name'];
-                               }
-
-                               $profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']);
-                               if ($item['author-link'] && !$item['author-name']) {
+                               $profile_name = $item['author-name'];
+                               if (!empty($item['author-link']) && empty($item['author-name'])) {
                                        $profile_name = $item['author-link'];
                                }
 
-                               $tags = \Friendica\Model\Term::populateTagsFromItem($item);
+                               $tags = Term::populateTagsFromItem($item);
 
-                               $profile_link = Contact::magicLinkbyId($item['author-id']);
+                               $author = ['uid' => 0, 'id' => $item['author-id'],
+                                       'network' => $item['author-network'], 'url' => $item['author-link']];
+                               $profile_link = Contact::magicLinkbyContact($author);
 
                                if (strpos($profile_link, 'redir/') === 0) {
                                        $sparkle = ' sparkle';
@@ -628,8 +636,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
 
                                $tmp_item = [
                                        'template' => $tpl,
-                                       'id' => (($preview) ? 'P0' : $item['item_id']),
-                                       'guid' => (($preview) ? 'Q0' : $item['guid']),
+                                       'id' => ($preview ? 'P0' : $item['id']),
+                                       'guid' => ($preview ? 'Q0' : $item['guid']),
                                        'network' => $item['network'],
                                        'network_name' => ContactSelector::networkToName($item['network'], $profile_link),
                                        'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
@@ -676,7 +684,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                                $arr = ['item' => $item, 'output' => $tmp_item];
                                Addon::callHooks('display_item', $arr);
 
-                               $threads[$threadsid]['id'] = $item['item_id'];
+                               $threads[$threadsid]['id'] = $item['id'];
                                $threads[$threadsid]['network'] = $item['network'];
                                $threads[$threadsid]['items'] = [$arr['output']];
 
@@ -718,6 +726,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                                        continue;
                                }
 
+                               /// @todo Check if this call is needed or not
+                               $arr = ['item' => $item];
                                Addon::callHooks('display_item', $arr);
 
                                $item['pagedrop'] = $page_dropping;
@@ -760,7 +770,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
  *
  * @return array items with parents and comments
  */
-function conversation_add_children($parents, $block_authors, $order, $uid) {
+function conversation_add_children(array $parents, $block_authors, $order, $uid) {
        $max_comments = Config::get('system', 'max_comments', 100);
 
        $params = ['order' => ['uid', 'commented' => true]];
@@ -779,7 +789,7 @@ function conversation_add_children($parents, $block_authors, $order, $uid) {
                }
                $thread_items = Item::selectForUser(local_user(), [], $condition, $params);
 
-               $comments = dba::inArray($thread_items);
+               $comments = Item::inArray($thread_items);
 
                if (count($comments) != 0) {
                        $items = array_merge($items, $comments);
@@ -810,14 +820,16 @@ function item_photo_menu($item) {
                $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
        }
 
-       $profile_link = Contact::magicLinkById($item['author-id']);
+       $author = ['uid' => 0, 'id' => $item['author-id'],
+               'network' => $item['author-network'], 'url' => $item['author-link']];
+       $profile_link = Contact::magicLinkbyContact($author);
        $sparkle = (strpos($profile_link, 'redir/') === 0);
 
        $cid = 0;
        $network = '';
        $rel = 0;
        $condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])];
-       $contact = dba::selectFirst('contact', ['id', 'network', 'rel'], $condition);
+       $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition);
        if (DBM::is_result($contact)) {
                $cid = $contact['id'];
                $network = $contact['network'];
@@ -915,7 +927,9 @@ function builtin_activity_puller($item, &$conv_responses) {
                }
 
                if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
-                       $url = Contact::MagicLinkbyId($item['author-id']);
+                       $author = ['uid' => 0, 'id' => $item['author-id'],
+                               'network' => $item['author-network'], 'url' => $item['author-link']];
+                       $url = Contact::magicLinkbyContact($author);
                        if (strpos($url, 'redir/') === 0) {
                                $sparkle = ' class="sparkle" ';
                        }
@@ -1137,7 +1151,8 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$wait'         => L10n::t('Please wait'),
                '$permset'      => L10n::t('Permission settings'),
                '$shortpermset' => L10n::t('permissions'),
-               '$ptyp'         => $notes_cid ? 'note' : 'wall',
+               '$wall'         => $notes_cid ? 0 : 1,
+               '$posttype'     => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE,
                '$content'      => defaults($x, 'content', ''),
                '$post_id'      => defaults($x, 'post_id', ''),
                '$baseurl'      => System::baseUrl(true),