aboutsummaryrefslogtreecommitdiffstats
path: root/include/api.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/api.php')
-rw-r--r--include/api.php98
1 files changed, 68 insertions, 30 deletions
diff --git a/include/api.php b/include/api.php
index f279b2aa3..5053977c5 100644
--- a/include/api.php
+++ b/include/api.php
@@ -1,10 +1,10 @@
<?php /** @file */
-require_once("bbcode.php");
-require_once("datetime.php");
-require_once("conversation.php");
-require_once("oauth.php");
-require_once("html2plain.php");
+require_once("include/bbcode.php");
+require_once("include/datetime.php");
+require_once("include/conversation.php");
+require_once("include/oauth.php");
+require_once("include/html2plain.php");
require_once('include/security.php');
require_once('include/photos.php');
require_once('include/items.php');
@@ -112,8 +112,11 @@ require_once('include/api_auth.php');
break;
case "json":
header ("Content-Type: application/json");
- foreach($r as $rr)
+ foreach($r as $rr) {
+ if(! $rr)
+ $rr = array();
$json = json_encode($rr);
+ }
if ($_GET['callback'])
$json = $_GET['callback']."(".$json.")";
return $json;
@@ -248,6 +251,7 @@ require_once('include/api_auth.php');
if (count($uinfo)==0) {
return False;
}
+ $following = false;
if(intval($uinfo[0]['abook_self'])) {
$usr = q("select * from channel where channel_id = %d limit 1",
@@ -263,18 +267,22 @@ require_once('include/api_auth.php');
$r = q("SELECT COUNT(`id`) as `count` FROM `item`
WHERE `uid` = %d
AND item_wall = 1 $item_normal
- AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
+ AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''
+ AND item_private = 0 ",
intval($usr[0]['channel_id'])
);
$countitms = $r[0]['count'];
+ $following = true;
}
else {
$r = q("SELECT COUNT(`id`) as `count` FROM `item`
WHERE author_xchan = '%s'
- AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
+ AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''
+ AND item_private = 0 ",
intval($uinfo[0]['xchan_hash'])
);
$countitms = $r[0]['count'];
+ $following = (($uinfo[0]['abook_myperms'] & PERMS_R_STREAM) ? true : false );
}
@@ -310,7 +318,6 @@ require_once('include/api_auth.php');
'location' => ($usr) ? $usr[0]['channel_location'] : '',
'profile_image_url' => $uinfo[0]['xchan_photo_l'],
'url' => $uinfo[0]['xchan_url'],
-//FIXME
'contact_url' => $a->get_baseurl() . "/connections/".$uinfo[0]['abook_id'],
'protected' => false,
'friends_count' => intval($countfriends),
@@ -334,7 +341,7 @@ require_once('include/api_auth.php');
'profile_background_tile' => false,
'profile_use_background_image' => false,
'notifications' => false,
- 'following' => '', // #XXX: fix me
+ 'following' => $following,
'verified' => true // #XXX: fix me
);
@@ -382,7 +389,6 @@ require_once('include/api_auth.php');
function api_item_get_user(&$a, $item) {
- global $usercache;
// The author is our direct contact, in a conversation with us.
@@ -396,11 +402,11 @@ require_once('include/api_auth.php');
$name = $item['author']['xchan_name'];
// Generating a random ID
- if (is_null($usercache[$nick]) or !array_key_exists($nick, $usercache))
- $usercache[$nick] = mt_rand(2000000, 2100000);
+ if (! $nick)
+ $nick = mt_rand(2000000, 2100000);
$ret = array(
- 'id' => $usercache[$nick],
+ 'id' => $nick,
'name' => $name,
'screen_name' => $nick,
'location' => '', //$uinfo[0]['default-location'],
@@ -415,7 +421,7 @@ require_once('include/api_auth.php');
'utc_offset' => 0, // #XXX: fix me
'time_zone' => '', //$uinfo[0]['timezone'],
'statuses_count' => 0,
- 'following' => 1,
+ 'following' => false,
'statusnet_blocking' => false,
'notifications' => false,
'uid' => 0,
@@ -853,13 +859,38 @@ require_once('include/api_auth.php');
$_REQUEST['type'] = 'wall';
if(x($_FILES,'media')) {
- $_FILES['userfile'] = $_FILES['media'];
- // upload the image if we have one
- $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo
- require_once('mod/wall_attach.php');
- $media = wall_attach_post($a);
- if(strlen($media)>0)
- $_REQUEST['body'] .= "\n\n".$media;
+ if(is_array($_FILES['media']['name'])) {
+ $num_uploads = count($_FILES['media']['name']);
+ for($x = 0; $x < $num_uploads; $x ++) {
+ $_FILES['userfile'] = array();
+ $_FILES['userfile']['name'] = $_FILES['media']['name'][$x];
+ $_FILES['userfile']['type'] = $_FILES['media']['type'][$x];
+ $_FILES['userfile']['tmp_name'] = $_FILES['media']['tmp_name'][$x];
+ $_FILES['userfile']['error'] = $_FILES['media']['error'][$x];
+ $_FILES['userfile']['size'] = $_FILES['media']['size'][$x];
+
+ // upload each image if we have any
+ $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo
+ require_once('mod/wall_attach.php');
+ $a->data['api_info'] = $user_info;
+ $media = wall_attach_post($a);
+
+ if(strlen($media)>0)
+ $_REQUEST['body'] .= "\n\n" . $media;
+ }
+ }
+ else {
+ // AndStatus doesn't present media as an array
+ $_FILES['userfile'] = $_FILES['media'];
+ // upload each image if we have any
+ $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo
+ require_once('mod/wall_attach.php');
+ $a->data['api_info'] = $user_info;
+ $media = wall_attach_post($a);
+
+ if(strlen($media)>0)
+ $_REQUEST['body'] .= "\n\n" . $media;
+ }
}
}
@@ -871,6 +902,7 @@ require_once('include/api_auth.php');
// this should output the last post (the one we just posted).
return api_status_show($a,$type);
}
+ api_register_func('api/statuses/update_with_media','api_statuses_update', true);
api_register_func('api/statuses/update','api_statuses_update', true);
@@ -1079,6 +1111,8 @@ require_once('include/api_auth.php');
'contributors' => ''
);
$status_info['user'] = $user_info;
+ if(array_key_exists('status',$status_info['user']))
+ unset($status_info['user']['status']);
}
return api_apply_template("status", $type, array('$status' => $status_info));
@@ -1320,6 +1354,8 @@ require_once('include/api_auth.php');
// params
$id = intval(argv(3));
+ if(! $id)
+ $id = $_REQUEST['id'];
logger('API: api_statuses_show: '.$id);
@@ -1336,10 +1372,12 @@ require_once('include/api_auth.php');
$r = q("select * from item where true $item_normal $sql_extra",
intval($id)
);
+
xchan_query($r,true);
$ret = api_format_items($r,$user_info);
+
if ($conversation) {
$data = array('$statuses' => $ret);
return api_apply_template("timeline", $type, $data);
@@ -2299,28 +2337,28 @@ require_once('include/api_auth.php');
api_register_func('api/direct_messages','api_direct_messages_inbox',true);
-
function api_oauth_request_token(&$a, $type){
try{
- $oauth = new FKOAuth1();
- $req = OAuthRequest::from_request();
-logger('Req: ' . var_export($req,true));
+ $oauth = new ZotOAuth1();
+ $req = OAuth1Request::from_request();
+ logger('Req: ' . var_export($req,true),LOGGER_DATA);
$r = $oauth->fetch_request_token($req);
}catch(Exception $e){
logger('oauth_exception: ' . print_r($e->getMessage(),true));
- echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage());
+ echo "error=". OAuth1Util::urlencode_rfc3986($e->getMessage());
killme();
}
echo $r;
killme();
}
+
function api_oauth_access_token(&$a, $type){
try{
- $oauth = new FKOAuth1();
- $req = OAuthRequest::from_request();
+ $oauth = new ZotOAuth1();
+ $req = OAuth1Request::from_request();
$r = $oauth->fetch_access_token($req);
}catch(Exception $e){
- echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme();
+ echo "error=". OAuth1Util::urlencode_rfc3986($e->getMessage()); killme();
}
echo $r;
killme();