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:----UyrxKsUenu7BAObYwtgQ/BN5HIs2iKj1to0Hzex+5swxbBKQ6MpipNicwHzoNcSJ++Yaz7LUbMu54mxCes13OgWX6tf7Gd3fdkzGf+ySSLV7NKUZay4TkDsOCAJJbl01zRwjw28BFMDDXJYOELABTHSJKkV91IZWCcjN0JjSZLlzyi43Jyom9ZO9jeYksYNpWZzFpSzv2aiBo2o+gD7w3/vkHBRx4Ghc7CqC68TnFOchY6cssB4fuUEyACLGGfV2fQ5+Fis8XK986XFMuWBZZbKNWYa09lcI30yKgjR3IYrzk9tw5gmQuDlugdWAKXz0Zv4ghT/jSL7o+HY2Lzy1Jbd4XEljkkj95eZJ1jbnShYGTeWbOxkKkhEE7MpP6TxV+Z9+TozgSuYdQgK3ZgTvim6o+s9mMrKgVPtVhwPpu2jifCKAaIElr6HEnLCx7ecBh9Wl17YW6RNRMzeYlNS8zWh5wN+NDsP8Zj6WOV4opi+cNo4g3E2cOPA0Nv8beJfVqmRK7Cd3l4JTj6By8Tvuph6HYT5UYLivZtCpbADMAh4PQoHiPwmuDF7WvZVSoX2aqW1VLeG6o8VOLGBm7Cv0bSdZEU6MnOiUdAgD7d5+DxP7C/TKewcko28dyy8Og/dkt/mwt6zmogCO9leXaPYL4woPADtFwnAD2TVbHO8NHGs=----ATTACHMENT:----ODQ2OTEyMDY3MTQyNDI2NSA4NjM2Njc1NTgxNTYyOTkgNzY5NTIxOTcyMzc0MzYwNQ==