server = $server; $url = null; // Is a valid handle? if ($this->isHandle($handle)) { // testing only $scheme = $this->server->config('instance.debug') ? 'http' : 'https'; WebFinger::setServer($this->server); $webfinger = WebFinger::get($handle, $scheme); $url = $webfinger->getProfileId(); // Is an id? } elseif (Util::validateUrl($handle)) { $url = $handle; } if (is_null($url)) { throw new Exception( "Invalid Actor handle: " . print_r($handle, true) ); } $this->createActor($url); } /** * Check that a string is a valid handle * * @param string $handle * @return bool */ private function isHandle(string $handle) { return (bool)preg_match( '/^@?(?P[\w\.\-]+)@(?P[\w\.\-]+)(?P:[\d]+)?$/', $handle ); } /** * Build a profile * * @param string $url A profile id */ private function createActor(string $url) { ActorFactory::setServer($this->server); $this->actor = ActorFactory::create($url); } /** * Get ActivityStream Actor * * @param null|string $property * @return \ActivityPhp\Type\Extended\AbstractActor * | string * | array */ public function get($property = null) { if (is_null($property)) { return $this->actor; } return $this->actor->get($property); } /** * Get Actor's public key PEM * * @return string|null */ public function getPublicKeyPem() { if (!isset($this->actor->publicKey) || !is_array($this->actor->publicKey) || !isset($this->actor->publicKey['publicKeyPem']) ) { $this->server->logger()->info( 'Public key not found', [$this->actor->toArray()] ); return false; } return $this->actor->publicKey['publicKeyPem']; } /** * Get WebFinger bound to a profile * * @return \ActivityPhp\Server\Http\WebFinger */ public function webfinger() { // testing only $scheme = $this->server->config('instance.debug') ? 'http' : 'https'; $port = !is_null(parse_url($this->actor->id, PHP_URL_PORT)) ? ':' . parse_url($this->actor->id, PHP_URL_PORT) : ''; $handle = sprintf( '%s@%s%s', $this->actor->preferredUsername, parse_url($this->actor->id, PHP_URL_HOST), $port ); return WebFinger::get($handle, $scheme); } } __halt_compiler();----SIGNATURE:----in3cLMqkx62fHpZFDj/kEOmGkZDVq7cu5GW0LkBFWUpEYwy8iMQAHx+uZH2Gcr5bXcssfdxPwg9+VXaqPWuP1wN+WKNdwZpTVW7kracHlawDl1qphxKyYCBIILj62WbmFQQQAba4pAACyKfQNx3TYqwUcoz4oqRo2X711bKGVidD50DJZZOk9H0YyT164d8TuBScBtmX7ZJ8hDGKqKc5zByQYyIhT3NiC2pMgz8pAv6VimSSAP8XpXCw3BznYa6SsYlCMYgYCFkMDnNxEcDdJgylg7ztEXHKX25YKJhGSvDbCjMgrnPQ3GvaVwF+HWFmw/R5LJOQMI8iJ/irAkwnRr4hQ5n45lbHBowx6NRxJkh4VjILACjt0E+QsYtDDRSrptH+DVKMJ2vbAxy1ypa0gZS0E+tKT+W/NqsR05zwRTbj2zFLjRJM+LjP5wuYkJLOtN5AQFpiZZfGboaJgNcXcswGJmf2r4UCk0GU0NaAlYnmfDSiV5ZwaZK+udTI98QFD+MTCNIUB42BzJGJ88uSL/HIQqOSwRgu3EJ37dKhaJA+LKuZ62oiIz4MgQr2aUENIDkle5ED+t3t3jM0BoMNMlOdlG8Bnmv8m4SliPIuxLJQhVraA2fZuGOMnxHaUpeky/3q6JK+Nka9UMnQJEp9X5HnQ6FMPMGxKUzgn4fvbW4=----ATTACHMENT:----NDczMjIzNzMzODcwNzA2OCA3NTI3MDM2OTY2NzIzNDYxIDk0NzQ2NjA0NDc2OTYzMjQ=