summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/router.php98
-rw-r--r--lib/xrd.php10
-rw-r--r--lib/xrdaction.php85
3 files changed, 108 insertions, 85 deletions
diff --git a/lib/router.php b/lib/router.php
index eff88bb46..ca895c8bb 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -55,14 +55,14 @@ class StatusNet_URL_Mapper extends Net_URL_Mapper
$result = null;
if (Event::handle('StartConnectPath', array(&$path, &$defaults, &$rules, &$result))) {
$result = parent::connect($path, $defaults, $rules);
- if (array_key_exists('action', $defaults)) {
- $action = $defaults['action'];
- } elseif (array_key_exists('action', $rules)) {
- $action = $rules['action'];
- } else {
- $action = null;
- }
- $this->_mapAction($action, $result);
+ if (array_key_exists('action', $defaults)) {
+ $action = $defaults['action'];
+ } elseif (array_key_exists('action', $rules)) {
+ $action = $rules['action'];
+ } else {
+ $action = null;
+ }
+ $this->_mapAction($action, $result);
Event::handle('EndConnectPath', array($path, $defaults, $rules, $result));
}
return $result;
@@ -70,31 +70,31 @@ class StatusNet_URL_Mapper extends Net_URL_Mapper
protected function _mapAction($action, $path)
{
- if (!array_key_exists($action, $this->_actionToPath)) {
- $this->_actionToPath[$action] = array();
- }
- $this->_actionToPath[$action][] = $path;
- return;
+ if (!array_key_exists($action, $this->_actionToPath)) {
+ $this->_actionToPath[$action] = array();
+ }
+ $this->_actionToPath[$action][] = $path;
+ return;
}
public function generate($values = array(), $qstring = array(), $anchor = '')
{
- if (!array_key_exists('action', $values)) {
- return parent::generate($values, $qstring, $anchor);
- }
+ if (!array_key_exists('action', $values)) {
+ return parent::generate($values, $qstring, $anchor);
+ }
- $action = $values['action'];
+ $action = $values['action'];
- if (!array_key_exists($action, $this->_actionToPath)) {
- return parent::generate($values, $qstring, $anchor);
- }
+ if (!array_key_exists($action, $this->_actionToPath)) {
+ return parent::generate($values, $qstring, $anchor);
+ }
- $oldPaths = $this->paths;
- $this->paths = $this->_actionToPath[$action];
- $result = parent::generate($values, $qstring, $anchor);
- $this->paths = $oldPaths;
+ $oldPaths = $this->paths;
+ $this->paths = $this->_actionToPath[$action];
+ $result = parent::generate($values, $qstring, $anchor);
+ $this->paths = $oldPaths;
- return $result;
+ return $result;
}
}
@@ -127,19 +127,19 @@ class Router
function __construct()
{
if (empty($this->m)) {
- if (!common_config('router', 'cache')) {
+ if (!common_config('router', 'cache')) {
$this->m = $this->initialize();
- } else {
- $k = self::cacheKey();
- $c = Cache::instance();
- $m = $c->get($k);
- if (!empty($m)) {
- $this->m = $m;
- } else {
- $this->m = $this->initialize();
- $c->set($k, $this->m);
- }
- }
+ } else {
+ $k = self::cacheKey();
+ $c = Cache::instance();
+ $m = $c->get($k);
+ if (!empty($m)) {
+ $this->m = $m;
+ } else {
+ $this->m = $this->initialize();
+ $c->set($k, $this->m);
+ }
+ }
}
}
@@ -199,7 +199,7 @@ class Router
'deleteuser',
'geocode',
'version',
- );
+ );
foreach ($main as $a) {
$m->connect('main/'.$a, array('action' => $a));
@@ -222,8 +222,8 @@ class Router
array('action' => 'publicxrds'));
$m->connect('.well-known/host-meta',
array('action' => 'hostmeta'));
- $m->connect('main/xrd',
- array('action' => 'userxrd'));
+ $m->connect('main/xrd',
+ array('action' => 'userxrd'));
// these take a code
@@ -248,19 +248,19 @@ class Router
}
$m->connect('settings/oauthapps/show/:id',
- array('action' => 'showapplication'),
- array('id' => '[0-9]+')
+ array('action' => 'showapplication'),
+ array('id' => '[0-9]+')
);
$m->connect('settings/oauthapps/new',
- array('action' => 'newapplication')
+ array('action' => 'newapplication')
);
$m->connect('settings/oauthapps/edit/:id',
- array('action' => 'editapplication'),
- array('id' => '[0-9]+')
+ array('action' => 'editapplication'),
+ array('id' => '[0-9]+')
);
$m->connect('settings/oauthapps/delete/:id',
- array('action' => 'deleteapplication'),
- array('id' => '[0-9]+')
+ array('action' => 'deleteapplication'),
+ array('id' => '[0-9]+')
);
// search
@@ -951,14 +951,14 @@ class Router
$qpos = strpos($url, '?');
if ($qpos !== false) {
$url = substr($url, 0, $qpos+1) .
- str_replace('?', '&', substr($url, $qpos+1));
+ str_replace('?', '&', substr($url, $qpos+1));
// @fixme this is a hacky workaround for http_build_query in the
// lower-level code and bad configs that set the default separator
// to & instead of &. Encoded &s in parameters will not be
// affected.
$url = substr($url, 0, $qpos+1) .
- str_replace('&', '&', substr($url, $qpos+1));
+ str_replace('&', '&', substr($url, $qpos+1));
}
diff --git a/lib/xrd.php b/lib/xrd.php
index c8cffed9c..9c6d9f3ab 100644
--- a/lib/xrd.php
+++ b/lib/xrd.php
@@ -130,14 +130,24 @@ class XRD
foreach ($this->links as $link) {
$titles = array();
+ $properties = array();
if (isset($link['title'])) {
$titles = $link['title'];
unset($link['title']);
}
+ if (isset($link['property'])) {
+ $properties = $link['property'];
+ unset($link['property']);
+ }
$xs->elementStart('Link', $link);
foreach ($titles as $title) {
$xs->element('Title', null, $title);
}
+ foreach ($properties as $property) {
+ $xs->element('Property',
+ array('type' => $property['type']),
+ $property['value']);
+ }
$xs->elementEnd('Link');
}
diff --git a/lib/xrdaction.php b/lib/xrdaction.php
index 43826b32b..4377eab94 100644
--- a/lib/xrdaction.php
+++ b/lib/xrdaction.php
@@ -53,54 +53,67 @@ class XrdAction extends Action
$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' => self::PROFILEPAGE,
- 'type' => 'text/html',
- 'href' => $profile->profileurl);
+ if (Event::handle('StartXrdActionLinks', array(&$xrd, $this->user))) {
- // hCard
- $xrd->links[] = array('rel' => self::HCARD,
- 'type' => 'text/html',
- 'href' => common_local_url('hcard', array('nickname' => $nick)));
+ $xrd->links[] = array('rel' => self::PROFILEPAGE,
+ 'type' => 'text/html',
+ 'href' => $profile->profileurl);
- // 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)));
+ // 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)));
+
+ 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();