]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/classes/Ostatus_profile.php
Validate::uri replaced with filter_var for HTTP[S] URL checks
[quix0rs-gnu-social.git] / plugins / OStatus / classes / Ostatus_profile.php
index 661b7fe3f70285a6da416d421b55f1eeaf4f6935..4b81de92d895e8d5d7eb4eb3e6c5bb1ba311148a 100644 (file)
@@ -42,11 +42,6 @@ class Ostatus_profile extends Managed_DataObject
     public $created;
     public $modified;
 
-    public /*static*/ function staticGet($k, $v=null)
-    {
-        return parent::staticGet(__CLASS__, $k, $v);
-    }
-
     /**
      * Return table definition for Schema setup and DB_DataObject usage.
      *
@@ -88,7 +83,7 @@ class Ostatus_profile extends Managed_DataObject
     public function localProfile()
     {
         if ($this->profile_id) {
-            return Profile::staticGet('id', $this->profile_id);
+            return Profile::getKV('id', $this->profile_id);
         }
         return null;
     }
@@ -100,7 +95,7 @@ class Ostatus_profile extends Managed_DataObject
     public function localGroup()
     {
         if ($this->group_id) {
-            return User_group::staticGet('id', $this->group_id);
+            return User_group::getKV('id', $this->group_id);
         }
         return null;
     }
@@ -112,7 +107,7 @@ class Ostatus_profile extends Managed_DataObject
     public function localPeopletag()
     {
         if ($this->peopletag_id) {
-            return Profile_list::staticGet('id', $this->peopletag_id);
+            return Profile_list::getKV('id', $this->peopletag_id);
         }
         return null;
     }
@@ -233,7 +228,7 @@ class Ostatus_profile extends Managed_DataObject
      */
     public function garbageCollect()
     {
-        $feedsub = FeedSub::staticGet('uri', $this->feeduri);
+        $feedsub = FeedSub::getKV('uri', $this->feeduri);
         return $feedsub->garbageCollect();
     }
 
@@ -554,7 +549,7 @@ class Ostatus_profile extends Managed_DataObject
 
         $sourceUri = $activity->id;
 
-        $dupe = Notice::staticGet('uri', $sourceUri);
+        $dupe = Notice::getKV('uri', $sourceUri);
         if ($dupe) {
             common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
             return $dupe;
@@ -656,7 +651,7 @@ class Ostatus_profile extends Managed_DataObject
             // Maintain direct reply associations
             // @todo FIXME: What about conversation ID?
             if (!empty($activity->context->replyToID)) {
-                $orig = Notice::staticGet('uri',
+                $orig = Notice::getKV('uri',
                                           $activity->context->replyToID);
                 if (!empty($orig)) {
                     $options['reply_to'] = $orig->id;
@@ -727,7 +722,7 @@ class Ostatus_profile extends Managed_DataObject
         // protecting against duplicate saves. It isn't required to be a URL;
         // tag: URIs for instance are found in Google Buzz feeds.
         $sourceUri = $note->id;
-        $dupe = Notice::staticGet('uri', $sourceUri);
+        $dupe = Notice::getKV('uri', $sourceUri);
         if ($dupe) {
             common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
             return $dupe;
@@ -826,7 +821,7 @@ class Ostatus_profile extends Managed_DataObject
             // Maintain direct reply associations
             // @todo FIXME: What about conversation ID?
             if (!empty($activity->context->replyToID)) {
-                $orig = Notice::staticGet('uri',
+                $orig = Notice::getKV('uri',
                                           $activity->context->replyToID);
                 if (!empty($orig)) {
                     $options['reply_to'] = $orig->id;
@@ -907,7 +902,7 @@ class Ostatus_profile extends Managed_DataObject
         $replies = array();
         foreach (array_unique($attention_uris) as $recipient) {
             // Is the recipient a local user?
-            $user = User::staticGet('uri', $recipient);
+            $user = User::getKV('uri', $recipient);
             if ($user) {
                 // @todo FIXME: Sender verification, spam etc?
                 $replies[] = $recipient;
@@ -915,10 +910,10 @@ class Ostatus_profile extends Managed_DataObject
             }
 
             // Is the recipient a local group?
-            // $group = User_group::staticGet('uri', $recipient);
+            // $group = User_group::getKV('uri', $recipient);
             $id = OStatusPlugin::localGroupFromUrl($recipient);
             if ($id) {
-                $group = User_group::staticGet('id', $id);
+                $group = User_group::getKV('id', $id);
                 if ($group) {
                     // Deliver to all members of this local group if allowed.
                     $profile = $sender->localProfile();
@@ -1016,14 +1011,14 @@ class Ostatus_profile extends Managed_DataObject
 
         // Check if they've got an LRDD header
 
-        $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
-
-        if (!empty($lrdd)) {
-
-            $xrd = Discovery::fetchXrd($lrdd);
+        $lrdd = LinkHeader::getLink($response, 'lrdd');
+        try {
+            $xrd = new XML_XRD();
+            $xrd->loadFile($lrdd);
             $xrdHints = DiscoveryHints::fromXRD($xrd);
-
             $hints = array_merge($hints, $xrdHints);
+        } catch (Exception $e) {
+            // No hints available from XRD
         }
 
         // If discovery found a feedurl (probably from LRDD), use it.
@@ -1057,7 +1052,7 @@ class Ostatus_profile extends Managed_DataObject
      */
     static function getFromProfileURL($profile_url)
     {
-        $profile = Profile::staticGet('profileurl', $profile_url);
+        $profile = Profile::getKV('profileurl', $profile_url);
 
         if (empty($profile)) {
             return null;
@@ -1065,7 +1060,7 @@ class Ostatus_profile extends Managed_DataObject
 
         // Is it a known Ostatus profile?
 
-        $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
+        $oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
 
         if (!empty($oprofile)) {
             return $oprofile;
@@ -1073,7 +1068,7 @@ class Ostatus_profile extends Managed_DataObject
 
         // Is it a local user?
 
-        $user = User::staticGet('id', $profile->id);
+        $user = User::getKV('id', $profile->id);
 
         if (!empty($user)) {
             // @todo i18n FIXME: use sprintf and add i18n (?)
@@ -1254,11 +1249,7 @@ class Ostatus_profile extends Managed_DataObject
         // http://status.net/open-source/issues/2663
         chmod(Avatar::path($filename), 0644);
 
-        $profile = $this->localProfile();
-
-        if (!empty($profile)) {
-            $profile->setOriginal($filename);
-        }
+        $self->setOriginal($filename);
 
         $orig = clone($this);
         $this->avatar = $url;
@@ -1332,7 +1323,7 @@ class Ostatus_profile extends Managed_DataObject
         }
         if ($url) {
             $opts = array('allowed_schemes' => array('http', 'https'));
-            if (Validate::uri($url, $opts)) {
+            if (common_valid_http_url($url)) {
                 return $url;
             }
         }
@@ -1397,7 +1388,7 @@ class Ostatus_profile extends Managed_DataObject
     protected static function getActivityObjectProfile($object)
     {
         $uri = self::getActivityObjectProfileURI($object);
-        return Ostatus_profile::staticGet('uri', $uri);
+        return Ostatus_profile::getKV('uri', $uri);
     }
 
     /**
@@ -1453,7 +1444,7 @@ class Ostatus_profile extends Managed_DataObject
             throw new Exception(_m('No profile URI.'));
         }
 
-        $user = User::staticGet('uri', $homeuri);
+        $user = User::getKV('uri', $homeuri);
         if ($user) {
             // TRANS: Exception.
             throw new Exception(_m('Local user cannot be referenced as remote.'));
@@ -1464,9 +1455,9 @@ class Ostatus_profile extends Managed_DataObject
             throw new Exception(_m('Local group cannot be referenced as remote.'));
         }
 
-        $ptag = Profile_list::staticGet('uri', $homeuri);
+        $ptag = Profile_list::getKV('uri', $homeuri);
         if ($ptag) {
-            $local_user = User::staticGet('id', $ptag->tagger);
+            $local_user = User::getKV('id', $ptag->tagger);
             if (!empty($local_user)) {
                 // TRANS: Exception.
                 throw new Exception(_m('Local list cannot be referenced as remote.'));
@@ -1624,7 +1615,7 @@ class Ostatus_profile extends Managed_DataObject
             $profile->profileurl = $object->link;
         } else if (array_key_exists('profileurl', $hints)) {
             $profile->profileurl = $hints['profileurl'];
-        } else if (Validate::uri($object->id, array('allowed_schemes' => array('http', 'https')))) {
+        } else if (common_valid_http_url($object->id)) {
             $profile->profileurl = $object->id;
         }
 
@@ -1867,14 +1858,14 @@ class Ostatus_profile extends Managed_DataObject
                 // TRANS: Exception.
                 throw new Exception(_m('Not a valid webfinger address.'));
             }
-            $oprofile = Ostatus_profile::staticGet('uri', $uri);
+            $oprofile = Ostatus_profile::getKV('uri', $uri);
             if (!empty($oprofile)) {
                 return $oprofile;
             }
         }
 
         // Try looking it up
-        $oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
+        $oprofile = Ostatus_profile::getKV('uri', 'acct:'.$addr);
 
         if (!empty($oprofile)) {
             self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
@@ -2052,7 +2043,7 @@ class Ostatus_profile extends Managed_DataObject
 
         // First, try to query it
 
-        $oprofile = Ostatus_profile::staticGet('uri', $uri);
+        $oprofile = Ostatus_profile::getKV('uri', $uri);
 
         // If unfound, do discovery stuff