apiqvitterallfollowing.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · Everybody I'm following and all groups I'm member of ·
  5. · (to use for auto-suggestions) ·
  6. · ·
  7. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8. · ·
  9. · ·
  10. · Q V I T T E R ·
  11. · ·
  12. · https://git.gnu.io/h2p/Qvitter ·
  13. · ·
  14. · ·
  15. · ·
  16. · <o) ·
  17. · /_//// ·
  18. · (____/ ·
  19. · (o< ·
  20. · o> \\\\_\ ·
  21. · \\) \____) ·
  22. · ·
  23. · ·
  24. · Qvitter is free software: you can redistribute it and / or modify it ·
  25. · under the terms of the GNU Affero General Public License as published by ·
  26. · the Free Software Foundation, either version three of the License or (at ·
  27. · your option) any later version. ·
  28. · ·
  29. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  30. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  31. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  32. · more details. ·
  33. · ·
  34. · You should have received a copy of the GNU Affero General Public License ·
  35. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  36. · ·
  37. · Contact h@nnesmannerhe.im if you have any questions. ·
  38. · ·
  39. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  40. if (!defined('GNUSOCIAL')) { exit(1); }
  41. class ApiQvitterAllFollowingAction extends ApiBareAuthAction
  42. {
  43. var $profiles = null;
  44. var $users_stripped = null;
  45. var $groups_stripped = null;
  46. var $blocks = null;
  47. /**
  48. * Take arguments for running
  49. *
  50. * @param array $args $_REQUEST args
  51. *
  52. * @return boolean success flag
  53. */
  54. protected function prepare(array $args=array())
  55. {
  56. parent::prepare($args);
  57. $this->format = 'json';
  58. $this->count = 5000; // max 5000, completely arbitrary...
  59. $this->target = $this->getTargetProfile($this->arg('id'));
  60. if (!($this->target instanceof Profile)) {
  61. // TRANS: Client error displayed when requesting a list of followers for a non-existing user.
  62. $this->clientError(_('No such user.'), 404);
  63. }
  64. $this->profiles = $this->getProfiles();
  65. $this->groups = $this->getGroups();
  66. $this->blocks = QvitterBlocked::getBlockedIDs($this->target->id,0,10000);
  67. // profiles: only keep id, name, nickname and avatar URL
  68. foreach($this->profiles as $p) {
  69. try {
  70. $avatar = Avatar::urlByProfile($p, AVATAR_STREAM_SIZE);
  71. } catch (Exception $e) {
  72. $avatar = false;
  73. }
  74. $this_user = array($p->fullname,$p->nickname,$avatar);
  75. if(!$p->isLocal()) {
  76. $this_user[3] = $p->getUrl();
  77. }
  78. else {
  79. $this_user[3] = false;
  80. }
  81. $this->users_stripped[$p->id] = $this_user;
  82. }
  83. // groups: only keep id, name, nickname, avatar and local aliases
  84. foreach($this->groups as $user_group) {
  85. $p = $user_group->getProfile();
  86. $avatar = $user_group->stream_logo;
  87. $this_group = array($p->fullname,$p->nickname,$avatar);
  88. if(!$user_group->isLocal()) {
  89. $this_group[3] = $p->getUrl();
  90. }
  91. else {
  92. $this_group[3] = false;
  93. }
  94. $this->groups_stripped[$user_group->id] = $this_group;
  95. }
  96. return true;
  97. }
  98. /**
  99. * Handle the request
  100. *
  101. * @param array $args $_REQUEST data (unused)
  102. *
  103. * @return void
  104. */
  105. protected function handle()
  106. {
  107. parent::handle();
  108. $this->initDocument('json');
  109. $this->showJsonObjects(array('users'=>$this->users_stripped,'groups'=>$this->groups_stripped,'blocks'=>$this->blocks));
  110. $this->endDocument('json');
  111. }
  112. /**
  113. * Get profiles
  114. *
  115. * @return array Profiles
  116. */
  117. protected function getProfiles()
  118. {
  119. $offset = ($this->page - 1) * $this->count;
  120. $limit = $this->count + 1;
  121. $subs = null;
  122. $subs = $this->target->getSubscribed(
  123. $offset,
  124. $limit
  125. );
  126. $profiles = array();
  127. while ($subs->fetch()) {
  128. $profiles[] = clone($subs);
  129. }
  130. return $profiles;
  131. }
  132. /**
  133. * Get groups
  134. *
  135. * @return array groups
  136. */
  137. function getGroups()
  138. {
  139. $groups = array();
  140. $group = $this->target->getGroups(
  141. ($this->page - 1) * $this->count,
  142. $this->count,
  143. $this->since_id,
  144. $this->max_id
  145. );
  146. if(!empty($group)) {
  147. while ($group->fetch()) {
  148. $groups[] = clone($group);
  149. }
  150. }
  151. return $groups;
  152. }
  153. }