The official, canonical postActiv repository. http://www.postactiv.com

apiusershow.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /* ============================================================================
  3. * Title: APIUserShow
  4. * Show a user's profile information
  5. *
  6. * postActiv:
  7. * the micro-blogging software
  8. *
  9. * Copyright:
  10. * Copyright (C) 2016-2018, Maiyannah Bishop
  11. *
  12. * Derived from code copyright various sources:
  13. * o GNU Social (C) 2013-2016, Free Software Foundation, Inc
  14. * o StatusNet (C) 2008-2012, StatusNet, Inc
  15. * ----------------------------------------------------------------------------
  16. * License:
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. *
  30. * <https://www.gnu.org/licenses/agpl.html>
  31. * ----------------------------------------------------------------------------
  32. * About:
  33. * Show a user's profile information
  34. *
  35. * PHP version:
  36. * Tested with PHP 7.0
  37. * ----------------------------------------------------------------------------
  38. * File Authors:
  39. * o Zach Copley
  40. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  41. * o Evan Prodromou
  42. * o Mikael Nordfeldth <mmn@hethane.se>
  43. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  44. *
  45. * Web:
  46. * o postActiv <http://www.postactiv.com>
  47. * o GNU social <https://www.gnu.org/s/social/>
  48. * ============================================================================
  49. */
  50. // This file is formatted so that it provides useful documentation output in
  51. // NaturalDocs. Please be considerate of this before changing formatting.
  52. if (!defined('POSTACTIV')) { exit(1); }
  53. /**
  54. * Ouputs information for a user, specified by ID or screen name.
  55. * The user's most recent status will be returned inline.
  56. */
  57. class ApiUserShowAction extends ApiPrivateAuthAction
  58. {
  59. /**
  60. * Take arguments for running
  61. *
  62. * @param array $args $_REQUEST args
  63. *
  64. * @return boolean success flag
  65. *
  66. */
  67. protected function prepare(array $args=array())
  68. {
  69. parent::prepare($args);
  70. $email = $this->arg('email');
  71. // XXX: email field deprecated in Twitter's API
  72. if (!empty($email)) {
  73. $user = User::getKV('email', $email);
  74. } else {
  75. $user = $this->getTargetUser($this->arg('id'));
  76. }
  77. if (!($user instanceof User)) {
  78. // TRANS: Client error displayed when requesting user information for a non-existing user.
  79. $this->clientError(_('User not found.'), 404);
  80. }
  81. $this->target = $user->getProfile();
  82. return true;
  83. }
  84. /**
  85. * Handle the request
  86. *
  87. * Check the format and show the user info
  88. *
  89. * @return void
  90. */
  91. protected function handle()
  92. {
  93. parent::handle();
  94. if (!in_array($this->format, array('xml', 'json'))) {
  95. // TRANS: Client error displayed when coming across a non-supported API method.
  96. $this->clientError(_('API method not found.'), 404);
  97. }
  98. $twitter_user = $this->twitterUserArray($this->target, true);
  99. if ($this->format == 'xml') {
  100. $this->initDocument('xml');
  101. $this->showTwitterXmlUser($twitter_user, 'user', true);
  102. $this->endDocument('xml');
  103. } elseif ($this->format == 'json') {
  104. $this->initDocument('json');
  105. $this->showJsonObjects($twitter_user);
  106. $this->endDocument('json');
  107. }
  108. }
  109. /**
  110. * Return true if read only.
  111. *
  112. * MAY override
  113. *
  114. * @param array $args other arguments
  115. *
  116. * @return boolean is read only action?
  117. */
  118. function isReadOnly($args)
  119. {
  120. return true;
  121. }
  122. }
  123. // END OF FILE
  124. // ============================================================================
  125. ?>