123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiExternalUserShowAction extends ApiPrivateAuthAction
- {
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->format = 'json';
- $profileurl = urldecode($this->arg('profileurl'));
- $nickname = urldecode($this->arg('nickname'));
- $this->profile = new stdClass();
- $this->profile->external = null;
- $this->profile->local = null;
-
-
- $validate = new Validate();
- if ($validate->uri($profileurl)) {
- $ostatus_profile = Ostatus_profile::ensureProfileURL($profileurl);
- $local_profile = Profile::getKV('id',$ostatus_profile->profile_id);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(strstr($profileurl, '/user/')) {
- $external_user_id = substr($profileurl,strpos($profileurl,'/user/')+6);
- $external_instance_url = substr($profileurl,0,strpos($profileurl,'/user/')+1);
- if(!is_numeric($external_user_id)) {
- return true;
- }
- $external_profile = $this->getProfileFromExternalInstance($external_instance_url,$external_user_id);
- if(!isset($external_profile->statusnet_profile_url)) {
- return true;
- }
- $this->profile->external = $external_profile;
- $local_profile = Profile::getKV('profileurl',$external_profile->statusnet_profile_url);
- if(!$local_profile instanceof Profile) {
- return true;
- }
- $this->profile->local = $this->twitterUserArray($local_profile);
- return true;
- }
-
- if(!isset($local_profile)) {
- $local_profile = Profile::getKV('profileurl',$profileurl);
- }
- if($local_profile instanceof Profile) {
- $this->profile->local = $this->twitterUserArray($local_profile);
-
- if(!substr($local_profile->profileurl, -strlen($local_profile->nickname))===$local_profile->nickname) {
- $external_instance_url = $local_profile->profileurl;
- }
-
- else {
- $external_instance_url = substr($local_profile->profileurl, 0, strrpos($local_profile->profileurl, '/'));
- }
- $external_profile = $this->getProfileFromExternalInstance($external_instance_url,$local_profile->nickname);
- if(!isset($external_profile->statusnet_profile_url)) {
- return true;
- }
- $this->profile->external = $external_profile;
- return true;
- }
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- $this->initDocument('json');
- $this->showJsonObjects($this->profile);
- $this->endDocument('json');
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function getProfileFromExternalInstance($instance_url,$user_id_or_nickname)
- {
- $apicall = $instance_url.'/api/users/show.json?id='.$user_id_or_nickname;
- $client = new HTTPClient();
- $response = $client->get($apicall);
-
- return $response->isOk() ? json_decode($response->getBody()) : null;
- }
- }
|