From 1ba74d824bcf69dfb7f4fc5d61bdc4b07b6ec612 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Dec 2015 15:51:15 -0800 Subject: usercache is no longer used --- include/api.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index f279b2aa3..e60583a01 100644 --- a/include/api.php +++ b/include/api.php @@ -382,7 +382,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 +395,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'], -- cgit v1.2.3 From 4b6dcbb05776c9630490e94a4b008872105fe65e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 9 Dec 2015 14:56:08 -0800 Subject: provide paths for include files --- include/api.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index e60583a01..69cc69415 100644 --- a/include/api.php +++ b/include/api.php @@ -1,10 +1,10 @@ Date: Thu, 10 Dec 2015 16:39:46 -0800 Subject: some major cleanup of api authentication stuff - still needs much more and this still may not solve #206 --- include/api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 69cc69415..4ad915c03 100644 --- a/include/api.php +++ b/include/api.php @@ -2298,12 +2298,11 @@ 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(); + $oauth = new ZotOAuth1(); $req = OAuthRequest::from_request(); -logger('Req: ' . var_export($req,true)); + 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)); @@ -2313,9 +2312,10 @@ logger('Req: ' . var_export($req,true)); echo $r; killme(); } + function api_oauth_access_token(&$a, $type){ try{ - $oauth = new FKOAuth1(); + $oauth = new ZotOAuth1(); $req = OAuthRequest::from_request(); $r = $oauth->fetch_access_token($req); }catch(Exception $e){ -- cgit v1.2.3 From 1f4c596841be66c96bc5acf28ba74e4f7154c6c8 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 11 Dec 2015 17:00:45 -0800 Subject: add deprecated update_with_media endpoint --- include/api.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 4ad915c03..1fb48d553 100644 --- a/include/api.php +++ b/include/api.php @@ -870,6 +870,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); -- cgit v1.2.3 From 395268da22bf5ec773de7fdc42a338a9cbe87d40 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 11 Dec 2015 21:10:20 -0800 Subject: a couple of api improvements --- include/api.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 1fb48d553..fd6883f44 100644 --- a/include/api.php +++ b/include/api.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; @@ -1079,6 +1082,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 +1325,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 +1343,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); -- cgit v1.2.3 From bb0e4044bf08bbac9d73a3e3b75d74c33dcacd7f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 13 Dec 2015 15:35:45 -0800 Subject: remove the unqualified "OAuth" namespace from the project. We need to reference either OAuth1 or OAuth2. --- include/api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index fd6883f44..9c31f994f 100644 --- a/include/api.php +++ b/include/api.php @@ -2311,12 +2311,12 @@ require_once('include/api_auth.php'); function api_oauth_request_token(&$a, $type){ try{ $oauth = new ZotOAuth1(); - $req = OAuthRequest::from_request(); + $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; @@ -2326,10 +2326,10 @@ require_once('include/api_auth.php'); function api_oauth_access_token(&$a, $type){ try{ $oauth = new ZotOAuth1(); - $req = OAuthRequest::from_request(); + $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(); -- cgit v1.2.3 From fdd2da905a27fab838aa34ef7baf0ee2c5c3c5f7 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 13 Dec 2015 19:15:42 -0800 Subject: more work on api media uploads --- include/api.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 9c31f994f..f37e0669f 100644 --- a/include/api.php +++ b/include/api.php @@ -855,13 +855,24 @@ 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; + $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; + } } } -- cgit v1.2.3 From b32bba47c8175bd791f9b5e512ff8c9e16a8f01a Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 14 Dec 2015 17:25:40 -0800 Subject: set following to false --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index f37e0669f..55c09092c 100644 --- a/include/api.php +++ b/include/api.php @@ -337,7 +337,7 @@ require_once('include/api_auth.php'); 'profile_background_tile' => false, 'profile_use_background_image' => false, 'notifications' => false, - 'following' => '', // #XXX: fix me + 'following' => false, // #XXX: fix me 'verified' => true // #XXX: fix me ); -- cgit v1.2.3 From 9b4e6e1ec028d4525635e2b1a25025f7fea0ed88 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 15 Dec 2015 20:21:40 -0800 Subject: some more minor api tweaks --- include/api.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 55c09092c..5c72a2d0c 100644 --- a/include/api.php +++ b/include/api.php @@ -251,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", @@ -266,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 ); } @@ -313,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), @@ -337,7 +341,7 @@ require_once('include/api_auth.php'); 'profile_background_tile' => false, 'profile_use_background_image' => false, 'notifications' => false, - 'following' => false, // #XXX: fix me + 'following' => $following, 'verified' => true // #XXX: fix me ); @@ -417,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, -- cgit v1.2.3 From 62a60e554235c66c88955d16134c874ad560bf72 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 17 Dec 2015 16:22:13 -0800 Subject: more work on media uploads via api --- include/api.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'include/api.php') diff --git a/include/api.php b/include/api.php index 5c72a2d0c..5053977c5 100644 --- a/include/api.php +++ b/include/api.php @@ -859,15 +859,29 @@ require_once('include/api_auth.php'); $_REQUEST['type'] = 'wall'; if(x($_FILES,'media')) { - $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]; - + 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'); -- cgit v1.2.3