]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Profile.php
Avoid duplicated multibyte tags
[friendica.git] / src / Model / Profile.php
index c91fdc1a9e32d69f8d1d31e46f7898fe2a05e0b8..ec53d064d6b83704d24ff2bd99f8a5b6c8f96640 100644 (file)
@@ -500,6 +500,8 @@ class Profile
                        $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
                }
 
+               $p['url'] = self::magicLink($p['url']);
+
                $tpl = get_markup_template('profile_vcard.tpl');
                $o .= replace_macros($tpl, [
                        '$profile' => $p,
@@ -642,24 +644,26 @@ class Profile
                $classtoday = '';
 
                $s = dba::p(
-                       "SELECT `event`.*, `item`.`id`, `item`.`thr-parent`, `item`.`parent-uri`
+                       "SELECT *
                        FROM `event`
-                       LEFT JOIN `item`
-                               ON `item`.`uid` = `event`.`uid`
-                               AND `item`.`parent-uri` = `event`.`uri`
-                               AND `item`.`verb` = ?
-                               AND `item`.`visible`
-                               AND NOT `item`.`deleted`
                        WHERE `event`.`uid` = ?
                        AND  `event`.`type` != 'birthday'
                        AND  `event`.`start` < ?
                        AND  `event`.`start` >= ?
-                       AND `item`.`id` IS NULL
+                       AND NOT EXISTS (
+                               SELECT `id`
+                               FROM `item`
+                               WHERE `item`.`uid` = `event`.`uid`
+                               AND `item`.`parent-uri` = `event`.`uri`
+                               AND `item`.`verb` = ?
+                               AND `item`.`visible`
+                               AND NOT `item`.`deleted`
+                       )
                        ORDER BY  `event`.`start` ASC",
-                       ACTIVITY_ATTENDNO,
                        local_user(),
                        DateTimeFormat::utc('now + 7 days'),
-                       DateTimeFormat::utc('now - 1 days')
+                       DateTimeFormat::utc('now - 1 days'),
+                       ACTIVITY_ATTENDNO
                );
 
                $r = [];
@@ -1003,6 +1007,29 @@ class Profile
                }
        }
 
+       /**
+        * @brief Returns a magic link to authenticate remote visitors
+        *
+        * @param string $contact_url The address of the contact profile
+        * @param integer $uid The user id, "local_user" is the default
+        *
+        * @return string with "redir" link
+        */
+       public static function magicLink($contact_url, $uid = -1)
+       {
+               if ($uid == -1) {
+                       $uid = local_user();
+               }
+               $condition = ['pending' => false, 'uid' => $uid,
+                               'nurl' => normalise_link($contact_url),
+                               'network' => NETWORK_DFRN, 'self' => false];
+               $contact = dba::selectFirst('contact', ['id'], $condition);
+               if (DBM::is_result($contact)) {
+                       return System::baseUrl() . '/redir/' . $contact['id'];
+               }
+               return self::zrl($contact_url);
+       }
+
        public static function zrl($s, $force = false)
        {
                if (!strlen($s)) {