aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-10-27 00:57:19 -0700
committerFriendika <info@friendika.com>2011-10-27 00:57:19 -0700
commit31502207bd8361a5fa27cb10ea037e4cca5a5678 (patch)
tree5c185598ea8dfa8923075f986f3c986bbe1afdbe
parentfaa078b83f57b74183ee35165f0f9d7bac9e6bde (diff)
downloadvolse-hubzilla-31502207bd8361a5fa27cb10ea037e4cca5a5678.tar.gz
volse-hubzilla-31502207bd8361a5fa27cb10ea037e4cca5a5678.tar.bz2
volse-hubzilla-31502207bd8361a5fa27cb10ea037e4cca5a5678.zip
more poco spec compliance
-rw-r--r--mod/poco.php85
-rw-r--r--mod/tagger.php2
-rw-r--r--view/poco_xml.tpl21
3 files changed, 88 insertions, 20 deletions
diff --git a/mod/poco.php b/mod/poco.php
index 79d5b7fb0..d0e32816e 100644
--- a/mod/poco.php
+++ b/mod/poco.php
@@ -7,7 +7,9 @@ function poco_init(&$a) {
$user = notags(trim($a->argv[1]));
}
if(! x($user) || get_config('system','block_public'))
- killme();
+ http_status_exit(401);
+
+ $format = (($_GET['format']) ? $_GET['format'] : 'json');
$justme = false;
@@ -26,7 +28,7 @@ function poco_init(&$a) {
dbesc($user)
);
if(! count($r) || $r[0]['hidewall'] || $r[0]['hide-friends'])
- killme();
+ http_status_exit(404);
$user = $r[0];
@@ -57,28 +59,73 @@ function poco_init(&$a) {
intval($itemsPerPage)
);
- $ret = array(
- 'startIndex' => $startIndex,
- 'itemsPerPage' => $itemsPerPage,
- 'totalResults' => $totalResults,
- 'entry' => array()
+ $ret = array();
+ if(x($_GET,'sorted'))
+ $ret['sorted'] = 'false';
+ if(x($_GET,'filtered'))
+ $ret['filtered'] = 'false';
+ if(x($_GET,'updatedSince'))
+ $ret['updateSince'] = 'false';
+
+ $ret['startIndex'] = $startIndex;
+ $ret['itemsPerPage'] = $itemsPerPage;
+ $ret['totalResults'] = $totalResults;
+ $ret['entry'] = array();
+
+
+ $fields_ret = array(
+ 'id' => false,
+ 'displayName' => false,
+ 'urls' => false,
+ 'preferredName' => false,
+ 'photos' => false
);
- if(count($r)) {
- foreach($r as $rr) {
- $entry = array();
- $entry['id'] = $rr['id'];
- $entry['displayName'] = $rr['name'];
- $entry['urls'] = array('value' => $rr['url'], 'type' => 'profile');
- $entry['preferredUsername'] = $rr['nick'];
- $entry['photos'] = array('value' => $rr['photo'], 'type' => 'profile');
- $ret['entry'][] = $entry;
+ if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
+ foreach($fields_ret as $f)
+ $f = true;
+ else {
+ $fields_req = explode(',',$_GET['fields']);
+ foreach($fields_req as $f)
+ $fields_ret[trim($f)] = true;
+ }
+
+ if(is_array($r)) {
+ if(count($r)) {
+ foreach($r as $rr) {
+ $entry = array();
+ if($fields_ret['id'])
+ $entry['id'] = $rr['id'];
+ if($fields_ret['displayName'])
+ $entry['displayName'] = $rr['name'];
+ if($fields_ret['urls'])
+ $entry['urls'] = array('value' => $rr['url'], 'type' => 'profile');
+ if($fields_ret['preferredUsername'])
+ $entry['preferredUsername'] = $rr['nick'];
+ if($fields_ret['photos'])
+ $entry['photos'] = array('value' => $rr['photo'], 'type' => 'profile');
+ $ret['entry'][] = $entry;
+ }
}
+ else
+ $ret['entry'][] = array();
}
- header('Content-type: application/json');
- echo json_encode($ret);
- killme();
+ else
+ http_status_exit(500);
+ if($format === 'xml') {
+ header('Content-type: text/xml');
+ echo replace_macros(get_markup_template('poco.xml',array('response' => $ret)));
+ http_status_exit(500);
+
+ }
+ if($format === 'json') {
+ header('Content-type: application/json');
+ echo json_encode($ret);
+ killme();
+ }
+ else
+ http_status_exit(500);
} \ No newline at end of file
diff --git a/mod/tagger.php b/mod/tagger.php
index 7114ed0ce..da4e74c61 100644
--- a/mod/tagger.php
+++ b/mod/tagger.php
@@ -13,7 +13,7 @@ function tagger_content(&$a) {
$term = notags(trim($_GET['term']));
// no commas allowed
- $term = str_replace(',','',$term);
+ $term = str_replace(array(',',' '),array('','_'),$term);
if(! $term)
return;
diff --git a/view/poco_xml.tpl b/view/poco_xml.tpl
new file mode 100644
index 000000000..59b8e8a95
--- /dev/null
+++ b/view/poco_xml.tpl
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<response>
+
+{{ if $response.sorted }}<sorted>$response.sorted</sorted>{{ endif }}
+{{ if $response.filtered }}<filtered>$response.filtered</filtered>{{ endif }}
+{{ if $response.updatedSince }}<updatedSince>$response.updatedSince</updatedSince>{{ endif }}
+{{ if $response.startIndex }}<startIndex>$response.startIndex</startIndex>{{ endif }}
+{{ if $response.itemsPerPage }}<itemsPerPage>$response.itemsPerPage</itemsPerPage>{{ endif }}
+{{ if $response.totalResults }}<totalResults>$response.totalResults</totalResults>{{ endif }}
+
+{{ for $response.entry as $ent }}
+<entry>
+{{ if $ent.id }}<id>$ent.id</id>{{ endif }}
+{{ if $ent.displayName }}<displayName>$ent.displayName</displayName>{{ endif }}
+{{ if $ent.preferredName }}<preferredName>$ent.preferredName</preferredName>{{ endif }}
+{{ if $ent.urls }}<urls><value>$ent.urls.value</value><type>$ent.urls.type</type></urls>{{ endif }}
+{{ if $ent.photos }}<photos><value>$ent.photos.value</value><type><$ent.photos.type></type></photos>{{ endif }}
+</entry>
+{{ endfor }}
+
+</response>