X-Git-Url: https://git.mxchange.org/?p=quix0rs-gnu-social.git;a=blobdiff_plain;f=lib%2Factivityutils.php;h=76e4777deb5feb471dc69960ff1c1feee64c00f4;hp=a0fc4872328e0f5103aea0797727098e9f5196db;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hpb=c909f351d07c50c433cd59fef00f41a67767ce9e diff --git a/lib/activityutils.php b/lib/activityutils.php index a0fc487232..76e4777deb 100644 --- a/lib/activityutils.php +++ b/lib/activityutils.php @@ -281,19 +281,20 @@ class ActivityUtils static function validateUri($uri) { // Check mailto: URIs first + $validate = new Validate(); if (preg_match('/^mailto:(.*)$/', $uri, $match)) { - return Validate::email($match[1], common_config('email', 'check_domain')); + return $validate->email($match[1], common_config('email', 'check_domain')); } - if (Validate::uri($uri)) { + if ($validate->uri($uri)) { return true; } // Possibly an upstream bug; tag: URIs aren't validated properly // unless you explicitly ask for them. All other schemes are accepted // for basic URI validation without asking. - if (Validate::uri($uri, array('allowed_scheme' => array('tag')))) { + if ($validate->uri($uri, array('allowed_scheme' => array('tag')))) { return true; } @@ -347,7 +348,7 @@ class ActivityUtils return null; } - static function compareTypes($type, array $objects) // this does verbs too! + static function compareTypes($type, array $objects) { $type = self::resolveUri($type); foreach ($objects as $object) { @@ -358,6 +359,11 @@ class ActivityUtils return false; } + static function compareVerbs($type, $objects) + { + return self::compareTypes($type, $objects); + } + static function resolveUri($uri, $make_relative=false) { if (empty($uri)) { @@ -374,32 +380,33 @@ class ActivityUtils } static function findLocalObject(array $uris, $type=ActivityObject::NOTE) { - $object = null; - // TODO: Extend this in plugins etc. - if (Event::handle('StartFindLocalActivityObject', array($uris, $type, &$object))) { + $obj_class = null; + // TODO: Extend this in plugins etc. and describe in EVENTS.txt + if (Event::handle('StartFindLocalActivityObject', array($uris, $type, &$obj_class))) { switch (self::resolveUri($type)) { case ActivityObject::PERSON: // GROUP will also be here in due time... - $object = new Profile(); + $obj_class = 'Profile'; break; default: - $object = new Notice(); + $obj_class = 'Notice'; } } - foreach (array_unique($uris) as $uri) { + $object = null; + $uris = array_unique($uris); + foreach ($uris as $uri) { try { // the exception thrown will cancel before reaching $object - $object = call_user_func(array($object, 'fromUri'), $uri); + $object = call_user_func("{$obj_class}::fromUri", $uri); break; - } catch (Exception $e) { - common_debug('Could not find local activity object from uri: '.$uri); + } catch (UnknownUriException $e) { + common_debug('Could not find local activity object from uri: '.$e->object_uri); } } - if (!empty($object)) { - Event::handle('EndFindLocalActivityObject', array($object->getUri(), $type, $object)); - } else { - throw new ServerException('Could not find any activityobject stored locally with given URI'); + if (!$object instanceof Managed_DataObject) { + throw new ServerException('Could not find any activityobject stored locally with given URIs: '.var_export($uris,true)); } + Event::handle('EndFindLocalActivityObject', array($object->getUri(), $object->getObjectType(), $object)); return $object; }