X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fxrdaction.php;h=b59e0f78a40f3c2dab4a8eb43053f2d2b579f5c1;hb=1543af748c7fe4be28348dfbfcdbde226c05ae29;hp=85a70f8b31a91874f31c94d36fb1531c28b6c555;hpb=0a4911552e6930f2e5d2830615b29be518af2a8a;p=quix0rs-gnu-social.git diff --git a/lib/xrdaction.php b/lib/xrdaction.php index 85a70f8b31..b59e0f78a4 100644 --- a/lib/xrdaction.php +++ b/lib/xrdaction.php @@ -28,6 +28,10 @@ if (!defined('STATUSNET')) { class XrdAction extends Action { + const PROFILEPAGE = 'http://webfinger.net/rel/profile-page'; + const UPDATESFROM = 'http://schemas.google.com/g/2010#updates-from'; + const HCARD = 'http://microformats.org/profile/hcard'; + public $uri; public $user; @@ -46,64 +50,113 @@ class XrdAction extends Action } if (empty($xrd->subject)) { - $xrd->subject = Discovery::normalize($this->uri); + $xrd->subject = self::normalize($this->uri); } - if (Event::handle('StartXrdActionAliases', array(&$xrd, $this->user))) { + if (Event::handle('StartXrdActionAliases', array(&$xrd, $this->user))) { - // Possible aliases for the user + // Possible aliases for the user - $uris = array($this->user->uri, $profile->profileurl); + $uris = array($this->user->uri, $profile->profileurl); - // FIXME: Webfinger generation code should live somewhere on its own + // FIXME: Webfinger generation code should live somewhere on its own - $path = common_config('site', 'path'); + $path = common_config('site', 'path'); - if (empty($path)) { - $uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server')); - } + if (empty($path)) { + $uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server')); + } - foreach ($uris as $uri) { - if ($uri != $xrd->subject) { - $xrd->alias[] = $uri; - } - } + foreach ($uris as $uri) { + if ($uri != $xrd->subject) { + $xrd->alias[] = $uri; + } + } - Event::handle('EndXrdActionAliases', array(&$xrd, $this->user)); - } + Event::handle('EndXrdActionAliases', array(&$xrd, $this->user)); + } - if (Event::handle('StartXrdActionLinks', array(&$xrd, $this->user))) { - - $xrd->links[] = array('rel' => Discovery::PROFILEPAGE, - 'type' => 'text/html', - 'href' => $profile->profileurl); - - // hCard - $xrd->links[] = array('rel' => Discovery::HCARD, - 'type' => 'text/html', - 'href' => common_local_url('hcard', array('nickname' => $nick))); + if (Event::handle('StartXrdActionLinks', array(&$xrd, $this->user))) { - // XFN - $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11', - 'type' => 'text/html', - 'href' => $profile->profileurl); - // FOAF - $xrd->links[] = array('rel' => 'describedby', - 'type' => 'application/rdf+xml', - 'href' => common_local_url('foaf', - array('nickname' => $nick))); + $xrd->links[] = array('rel' => self::PROFILEPAGE, + 'type' => 'text/html', + 'href' => $profile->profileurl); - $xrd->links[] = array('rel' => Discovery::UPDATESFROM, - 'href' => common_local_url('ApiTimelineUser', - array('id' => $this->user->id, - 'format' => 'atom')), - 'type' => 'application/atom+xml'); + // hCard + $xrd->links[] = array('rel' => self::HCARD, + 'type' => 'text/html', + 'href' => common_local_url('hcard', array('nickname' => $nick))); - Event::handle('EndXrdActionLinks', array(&$xrd, $this->user)); - } + // XFN + $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11', + 'type' => 'text/html', + 'href' => $profile->profileurl); + // FOAF + $xrd->links[] = array('rel' => 'describedby', + 'type' => 'application/rdf+xml', + 'href' => common_local_url('foaf', + array('nickname' => $nick))); + $xrd->links[] = array('rel' => 'http://apinamespace.org/atom', + 'type' => 'application/atomsvc+xml', + 'href' => common_local_url('ApiAtomService', array('id' => $nick)), + 'property' => array(array('type' => 'http://apinamespace.org/atom/username', + 'value' => $nick))); + + if (common_config('site', 'fancy')) { + $apiRoot = common_path('api/', true); + } else { + $apiRoot = common_path('index.php/api/', true); + } + + $xrd->links[] = array('rel' => 'http://apinamespace.org/twitter', + 'href' => $apiRoot, + 'property' => array(array('type' => 'http://apinamespace.org/twitter/username', + 'value' => $nick))); + + Event::handle('EndXrdActionLinks', array(&$xrd, $this->user)); + } header('Content-type: application/xrd+xml'); print $xrd->toXML(); } + + /** + * Given a "user id" make sure it's normalized to either a webfinger + * acct: uri or a profile HTTP URL. + */ + + public static function normalize($user_id) + { + if (substr($user_id, 0, 5) == 'http:' || + substr($user_id, 0, 6) == 'https:' || + substr($user_id, 0, 5) == 'acct:') { + return $user_id; + } + + if (strpos($user_id, '@') !== FALSE) { + return 'acct:' . $user_id; + } + + return 'http://' . $user_id; + } + + public static function isWebfinger($user_id) + { + $uri = self::normalize($user_id); + + return (substr($uri, 0, 5) == 'acct:'); + } + + /** + * Is this action read-only? + * + * @param array $args other arguments + * + * @return boolean is read only action? + */ + function isReadOnly($args) + { + return true; + } }