]> git.mxchange.org Git - friendica.git/blobdiff - mod/contacts.php
Rename DBM method calls to DBA method calls
[friendica.git] / mod / contacts.php
index 09090e541a502e5254c726f2ca070421051d1b72..a71411f9ea4b9e7244b3ac8c510949af7a47bd5e 100644 (file)
@@ -12,7 +12,7 @@ use Friendica\Core\Addon;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Group;
@@ -41,10 +41,18 @@ function contacts_init(App $a)
        $contact = null;
        if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
                $contact_id = intval($a->argv[1]);
-               $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
        }
 
-       if (DBM::is_result($contact)) {
+       if (DBA::is_result($contact)) {
+               if ($contact['self']) {
+                       if (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts")) {
+                               goaway('profile/' . $contact['nick']);
+                       } else {
+                               goaway('profile/' . $contact['nick'] . '?tab=profile');
+                       }
+               }
+
                $a->data['contact'] = $contact;
 
                if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
@@ -57,7 +65,7 @@ function contacts_init(App $a)
                $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
                        '$name' => htmlentities($a->data['contact']['name']),
                        '$photo' => $a->data['contact']['photo'],
-                       '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/" . $a->data['contact']['id'] : $a->data['contact']['url'],
+                       '$url' => Contact::MagicLink($a->data['contact']['url']),
                        '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
                        '$network_name' => $networkname,
                        '$network' => L10n::t('Network:'),
@@ -79,7 +87,7 @@ function contacts_init(App $a)
                $findpeople_widget = Widget::findPeople();
        }
 
-       $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 0, $contact_id);
+       $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 'everyone', $contact_id);
 
        $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [
                '$vcard_widget' => $vcard_widget,
@@ -172,7 +180,7 @@ function contacts_post(App $a)
                return;
        }
 
-       if (!dba::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
+       if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
                notice(L10n::t('Could not access contact record.') . EOL);
                goaway('contacts');
                return; // NOTREACHED
@@ -182,7 +190,7 @@ function contacts_post(App $a)
 
        $profile_id = intval($_POST['profile-assign']);
        if ($profile_id) {
-               if (!dba::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
+               if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
                        notice(L10n::t('Could not locate selected profile.') . EOL);
                        return;
                }
@@ -216,14 +224,14 @@ function contacts_post(App $a)
                intval($contact_id),
                intval(local_user())
        );
-       if (DBM::is_result($r)) {
+       if (DBA::is_result($r)) {
                info(L10n::t('Contact updated.') . EOL);
        } else {
                notice(L10n::t('Failed to update contact record.') . EOL);
        }
 
-       $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
-       if (DBM::is_result($contact)) {
+       $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+       if (DBA::is_result($contact)) {
                $a->data['contact'] = $contact;
        }
 
@@ -234,8 +242,8 @@ function contacts_post(App $a)
 
 function _contact_update($contact_id)
 {
-       $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
-       if (!DBM::is_result($contact)) {
+       $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
+       if (!DBA::is_result($contact)) {
                return;
        }
 
@@ -255,8 +263,8 @@ function _contact_update($contact_id)
 
 function _contact_update_profile($contact_id)
 {
-       $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
-       if (!DBM::is_result($contact)) {
+       $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
+       if (!DBA::is_result($contact)) {
                return;
        }
 
@@ -327,7 +335,7 @@ function _contact_block($contact_id, $orig_record)
                intval($contact_id),
                intval(local_user())
        );
-       return DBM::is_result($r);
+       return DBA::is_result($r);
 }
 
 function _contact_ignore($contact_id, $orig_record)
@@ -338,7 +346,7 @@ function _contact_ignore($contact_id, $orig_record)
                intval($contact_id),
                intval(local_user())
        );
-       return DBM::is_result($r);
+       return DBA::is_result($r);
 }
 
 function _contact_archive($contact_id, $orig_record)
@@ -349,7 +357,7 @@ function _contact_archive($contact_id, $orig_record)
                intval($contact_id),
                intval(local_user())
        );
-       return DBM::is_result($r);
+       return DBA::is_result($r);
 }
 
 function _contact_drop($orig_record)
@@ -360,7 +368,7 @@ function _contact_drop($orig_record)
                WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
                intval($a->user['uid'])
        );
-       if (!DBM::is_result($r)) {
+       if (!DBA::is_result($r)) {
                return;
        }
 
@@ -387,8 +395,8 @@ function contacts_content(App $a)
 
                $cmd = $a->argv[2];
 
-               $orig_record = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]);
-               if (!DBM::is_result($orig_record)) {
+               $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]);
+               if (!DBA::is_result($orig_record)) {
                        notice(L10n::t('Could not access contact record.') . EOL);
                        goaway('contacts');
                        return; // NOTREACHED
@@ -528,11 +536,10 @@ function contacts_content(App $a)
 
                $relation_text = sprintf($relation_text, htmlentities($contact['name']));
 
-               if (($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
-                       $url = "redir/{$contact['id']}";
+               $url = Contact::magicLink($contact['url']);
+               if (strpos($url, 'redir/') === 0) {
                        $sparkle = ' class="sparkle" ';
                } else {
-                       $url = $contact['url'];
                        $sparkle = '';
                }
 
@@ -579,9 +586,10 @@ function contacts_content(App $a)
                        $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== NETWORK_DFRN) ? true : false));
                }
 
+               /// @todo Only show the following link with DFRN when the remote version supports it
                $follow = '';
                $follow_text = '';
-               if (in_array($contact['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS])) {
+               if (in_array($contact['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_DFRN])) {
                        if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
                                $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
                                $follow_text = L10n::t("Connect/Follow");
@@ -779,7 +787,7 @@ function contacts_content(App $a)
                WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
                intval($_SESSION['uid'])
        );
-       if (DBM::is_result($r)) {
+       if (DBA::is_result($r)) {
                $a->set_pager_total($r[0]['total']);
                $total = $r[0]['total'];
        }
@@ -793,7 +801,7 @@ function contacts_content(App $a)
                intval($a->pager['start']),
                intval($a->pager['itemspage'])
        );
-       if (DBM::is_result($r)) {
+       if (DBA::is_result($r)) {
                foreach ($r as $rr) {
                        $contacts[] = _contact_detail_for_template($rr);
                }
@@ -901,8 +909,8 @@ function contact_posts($a, $contact_id)
 {
        $o = contacts_tab($a, $contact_id, 1);
 
-       $contact = dba::selectFirst('contact', ['url'], ['id' => $contact_id]);
-       if (DBM::is_result($contact)) {
+       $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id]);
+       if (DBA::is_result($contact)) {
                $a->page['aside'] = "";
                Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
                $o .= Contact::getPostsFromUrl($contact["url"]);
@@ -931,10 +939,17 @@ function _contact_detail_for_template($rr)
                default:
                        break;
        }
-       if (($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
-               $url = "redir/{$rr['id']}";
+
+       $url = Contact::magicLink($rr['url']);
+       if (strpos($url, 'redir/') === 0) {
                $sparkle = ' class="sparkle" ';
        } else {
+               $sparkle = '';
+       }
+
+       if ($rr['self']) {
+               $dir_icon = 'images/larrow.gif';
+               $alt_text = L10n::t('This is you');
                $url = $rr['url'];
                $sparkle = '';
        }
@@ -954,6 +969,7 @@ function _contact_detail_for_template($rr)
                'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
                'url' => $url,
                'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
+               'nick' => htmlentities($rr['nick']),
        ];
 }