]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub.php
Merge pull request #8271 from MrPetovan/bug/8229-frio-mobile-back-to-top
[friendica.git] / src / Protocol / ActivityPub.php
index 6c7bbb4745c488f87bec60b9b421dacf6043f9c8..f1cd652f47d74885fcec77d72e55226524b20bc3 100644 (file)
@@ -1,7 +1,24 @@
 <?php
 /**
- * @file src/Protocol/ActivityPub.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Protocol;
 
 use Friendica\Util\JsonLD;
@@ -12,7 +29,8 @@ use Friendica\Model\User;
 use Friendica\Util\HTTPSignature;
 
 /**
- * @brief ActivityPub Protocol class
+ * ActivityPub Protocol class
+ *
  * The ActivityPub Protocol is a message exchange protocol defined by the W3C.
  * https://www.w3.org/TR/activitypub/
  * https://www.w3.org/TR/activitystreams-core/
@@ -57,8 +75,8 @@ class ActivityPub
         */
        public static function isRequest()
        {
-               return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') ||
-                       stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json');
+               return stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') ||
+                       stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json');
        }
 
        /**
@@ -194,4 +212,18 @@ class ActivityPub
                        ActivityPub\Receiver::processActivity($ldactivity, '', $uid, true);
                }
        }
+
+       /**
+        * Checks if the given contact url does support ActivityPub
+        *
+        * @param string  $url    profile url
+        * @param boolean $update true = always update, false = never update, null = update when not found or outdated
+        * @return boolean
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function isSupportedByContactUrl($url, $update = null)
+       {
+               return !empty(APContact::getByURL($url, $update));
+       }
 }