apiqvittermutes.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · API for getting all muted profiles for a profile ·
  5. · ·
  6. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7. · ·
  8. · ·
  9. · Q V I T T E R ·
  10. · ·
  11. · https://git.gnu.io/h2p/Qvitter ·
  12. · ·
  13. · ·
  14. · <o) ·
  15. · /_//// ·
  16. · (____/ ·
  17. · (o< ·
  18. · o> \\\\_\ ·
  19. · \\) \____) ·
  20. · ·
  21. · ·
  22. · ·
  23. · Qvitter is free software: you can redistribute it and / or modify it ·
  24. · under the terms of the GNU Affero General Public License as published by ·
  25. · the Free Software Foundation, either version three of the License or (at ·
  26. · your option) any later version. ·
  27. · ·
  28. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  29. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  30. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  31. · more details. ·
  32. · ·
  33. · You should have received a copy of the GNU Affero General Public License ·
  34. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  35. · ·
  36. · Contact h@nnesmannerhe.im if you have any questions. ·
  37. · ·
  38. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  39. if (!defined('GNUSOCIAL')) { exit(1); }
  40. class ApiQvitterMutesAction extends ApiPrivateAuthAction
  41. {
  42. var $profiles = null;
  43. /**
  44. * Take arguments for running
  45. *
  46. * @param array $args $_REQUEST args
  47. *
  48. * @return boolean success flag
  49. */
  50. protected function prepare(array $args=array())
  51. {
  52. parent::prepare($args);
  53. $this->format = 'json';
  54. $this->count = (int)$this->arg('count', 100);
  55. return true;
  56. }
  57. /**
  58. * Handle the request
  59. *
  60. * Show the profiles
  61. *
  62. * @return void
  63. */
  64. protected function handle()
  65. {
  66. parent::handle();
  67. $this->target = $this->scoped;
  68. if(!$this->target instanceof Profile) {
  69. $this->clientError(_('You have to be logged in to view your mutes.'), 403);
  70. }
  71. $this->profiles = $this->getProfiles();
  72. $this->initDocument('json');
  73. print json_encode($this->showProfiles());
  74. $this->endDocument('json');
  75. }
  76. /**
  77. * Get the user's muted profiles
  78. *
  79. * @return array Profiles
  80. */
  81. protected function getProfiles()
  82. {
  83. $offset = ($this->page - 1) * $this->count;
  84. $limit = $this->count;
  85. $mutes = QvitterMuted::getMutedProfiles($this->target->id, $offset, $limit);
  86. if($mutes) {
  87. return $mutes;
  88. } else {
  89. return false;
  90. }
  91. }
  92. /**
  93. * Is this action read only?
  94. *
  95. * @param array $args other arguments
  96. *
  97. * @return boolean true
  98. */
  99. function isReadOnly($args)
  100. {
  101. return true;
  102. }
  103. /**
  104. * When was this feed last modified?
  105. *
  106. * @return string datestamp of the latest profile in the stream
  107. */
  108. function lastModified()
  109. {
  110. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  111. return strtotime($this->profiles[0]->modified);
  112. }
  113. return null;
  114. }
  115. /**
  116. * An entity tag for this action
  117. *
  118. * Returns an Etag based on the action name, language, user ID, and
  119. * timestamps of the first and last profiles in the subscriptions list
  120. * There's also an indicator to show whether this action is being called
  121. * as /api/statuses/(friends|followers) or /api/(friends|followers)/ids
  122. *
  123. * @return string etag
  124. */
  125. function etag()
  126. {
  127. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  128. $last = count($this->profiles) - 1;
  129. return '"' . implode(
  130. ':',
  131. array($this->arg('action'),
  132. common_user_cache_hash($this->auth_user),
  133. common_language(),
  134. $this->target->id,
  135. 'Profiles',
  136. strtotime($this->profiles[0]->modified),
  137. strtotime($this->profiles[$last]->modified))
  138. )
  139. . '"';
  140. }
  141. return null;
  142. }
  143. /**
  144. * Show the profiles as Twitter-style useres and statuses
  145. *
  146. * @return void
  147. */
  148. function showProfiles()
  149. {
  150. $user_arrays = array();
  151. if($this->profiles !== false) {
  152. foreach ($this->profiles as $profile) {
  153. $user_arrays[] = $this->twitterUserArray($profile, false );
  154. }
  155. }
  156. return $user_arrays;
  157. }
  158. }