]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Profile.php
Merge pull request #7095 from annando/ap-connect
[friendica.git] / src / Model / Profile.php
index aacceedb3a9f8876e85850c11f510b4d315f1b68..9d2600b3daab16156c825ff4f458cd352ad1bf6a 100644 (file)
@@ -112,8 +112,6 @@ class Profile
 
                if (!DBA::isResult($user) && empty($profiledata)) {
                        Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
-                       notice(L10n::t('Requested account is not available.') . EOL);
-                       $a->error = 404;
                        return;
                }
 
@@ -130,8 +128,6 @@ class Profile
 
                if (empty($pdata) && empty($profiledata)) {
                        Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
-                       notice(L10n::t('Requested profile is not available.') . EOL);
-                       $a->error = 404;
                        return;
                }
 
@@ -641,7 +637,6 @@ class Profile
                }
                $tpl = Renderer::getMarkupTemplate('birthdays_reminder.tpl');
                return Renderer::replaceMacros($tpl, [
-                       '$baseurl' => System::baseUrl(),
                        '$classtoday' => $classtoday,
                        '$count' => $total,
                        '$event_reminders' => L10n::t('Birthday Reminders'),
@@ -730,7 +725,6 @@ class Profile
                }
                $tpl = Renderer::getMarkupTemplate('events_reminder.tpl');
                return Renderer::replaceMacros($tpl, [
-                       '$baseurl' => System::baseUrl(),
                        '$classtoday' => $classtoday,
                        '$count' => count($r),
                        '$event_reminders' => L10n::t('Event Reminders'),
@@ -787,7 +781,7 @@ class Profile
                                $profile['marital']['with'] = $a->profile['with'];
                        }
 
-                       if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= DBA::NULL_DATETIME) {
+                       if (strlen($a->profile['howlong']) && $a->profile['howlong'] > DBA::NULL_DATETIME) {
                                $profile['howlong'] = Temporal::getRelativeDate($a->profile['howlong'], L10n::t('for %1$d %2$s'));
                        }
 
@@ -1083,34 +1077,20 @@ class Profile
        }
 
        /**
-        * OpenWebAuth authentication.
-        *
-        * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/zid.php
+        * Set the visitor cookies (see remote_user()) for the given handle
         *
-        * @param string $token
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        * @throws \ImagickException
+        * @param string $handle Visitor handle
+        * @return array Visitor contact array
         */
-       public static function openWebAuthInit($token)
+       public static function addVisitorCookieForHandle($handle)
        {
                $a = \get_app();
 
-               // Clean old OpenWebAuthToken entries.
-               OpenWebAuthToken::purge('owt', '3 MINUTE');
-
-               // Check if the token we got is the same one
-               // we have stored in the database.
-               $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
-
-               if($visitor_handle === false) {
-                       return;
-               }
-
                // Try to find the public contact entry of the visitor.
-               $cid = Contact::getIdForURL($visitor_handle);
-               if(!$cid) {
-                       Logger::log('owt: unable to finger ' . $visitor_handle, Logger::DEBUG);
-                       return;
+               $cid = Contact::getIdForURL($handle);
+               if (!$cid) {
+                       Logger::log('unable to finger ' . $handle, Logger::DEBUG);
+                       return [];
                }
 
                $visitor = DBA::selectFirst('contact', [], ['id' => $cid]);
@@ -1133,6 +1113,43 @@ class Profile
 
                        $_SESSION['remote'][] = ['cid' => $contact['id'], 'uid' => $contact['uid'], 'url' => $visitor['url']];
                }
+
+               $a->contact = $visitor;
+
+               Logger::info('Authenticated visitor', ['url' => $visitor['url']]);
+
+               return $visitor;
+       }
+
+       /**
+        * OpenWebAuth authentication.
+        *
+        * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/zid.php
+        *
+        * @param string $token
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function openWebAuthInit($token)
+       {
+               $a = \get_app();
+
+               // Clean old OpenWebAuthToken entries.
+               OpenWebAuthToken::purge('owt', '3 MINUTE');
+
+               // Check if the token we got is the same one
+               // we have stored in the database.
+               $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
+
+               if ($visitor_handle === false) {
+                       return;
+               }
+
+               $visitor = self::addVisitorCookieForHandle($visitor_handle);
+               if (empty($visitor)) {
+                       return;
+               }
+
                $arr = [
                        'visitor' => $visitor,
                        'url' => $a->query_string
@@ -1218,4 +1235,75 @@ class Profile
        {
                return preg_replace('/[\?&]' . $param . '=(.*?)(&|$)/ism', '$2', $s);
        }
+
+       /**
+        * search for Profiles
+        *
+        * @param int  $start
+        * @param int  $count
+        * @param null $search
+        *
+        * @return array [ 'total' => 123, 'entries' => [...] ];
+        *
+        * @throws \Exception
+        */
+       public static function searchProfiles($start = 0, $count = 100, $search = null)
+       {
+               if ($search) {
+                       $search = DBA::escape($search);
+
+                       $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
+                               (`user`.`nickname` LIKE '%$search%') OR
+                               (`profile`.`pdesc` LIKE '%$search%') OR
+                               (`profile`.`locality` LIKE '%$search%') OR
+                               (`profile`.`region` LIKE '%$search%') OR
+                               (`profile`.`country-name` LIKE '%$search%') OR
+                               (`profile`.`gender` LIKE '%$search%') OR
+                               (`profile`.`marital` LIKE '%$search%') OR
+                               (`profile`.`sexual` LIKE '%$search%') OR
+                               (`profile`.`about` LIKE '%$search%') OR
+                               (`profile`.`romance` LIKE '%$search%') OR
+                               (`profile`.`work` LIKE '%$search%') OR
+                               (`profile`.`education` LIKE '%$search%') OR
+                               (`profile`.`pub_keywords` LIKE '%$search%') OR
+                               (`profile`.`prv_keywords` LIKE '%$search%'))";
+               } else {
+                       $sql_extra = '';
+               }
+
+               $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
+
+               $total = 0;
+               $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` 
+                               FROM `profile`
+                               LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
+                               WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` $sql_extra");
+               if (DBA::isResult($cnt)) {
+                       $total = $cnt['total'];
+               }
+
+               $order = " ORDER BY `name` ASC ";
+               $limit = $start . ',' . $count;
+
+               $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
+                       `contact`.`addr`, `contact`.`url` AS `profile_url`
+                       FROM `profile`
+                       LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
+                       LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
+                       WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
+                       $sql_extra $order LIMIT $limit"
+               );
+
+               if (DBA::isResult($profiles)) {
+                       return [
+                               'total'   => $total,
+                               'entries' => DBA::toArray($profiles),
+                       ];
+               } else {
+                       return [
+                               'total'   => $total,
+                               'entries' => [],
+                       ];
+               }
+       }
 }