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

apifriendshipsexists.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* ============================================================================
  3. * Title: APIFriendshipsExists
  4. * Show whether there is a friendship between two users
  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 whether there is a friendship between two users
  34. *
  35. * PHP version:
  36. * Tested with PHP 7.0
  37. * ----------------------------------------------------------------------------
  38. * File Authors:
  39. * o Zach Copley
  40. * o Evan Prodromou
  41. * o Robin Millette <robin@millette.info>
  42. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  43. * o Mikael Nordfeldth <mmn@hethane.se>
  44. * o Hannes Mannerheim <h@nnesmannerhe.im>
  45. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  46. *
  47. * Web:
  48. * o postActiv <http://www.postactiv.com>
  49. * o GNU social <https://www.gnu.org/s/social/>
  50. * ============================================================================
  51. */
  52. // This file is formatted so that it provides useful documentation output in
  53. // NaturalDocs. Please be considerate of this before changing formatting.
  54. if (!defined('POSTACTIV')) { exit(1); }
  55. /**
  56. * Tests for the existence of friendship between two users. Will return true if
  57. * user_a follows user_b, otherwise will return false.
  58. */
  59. class ApiFriendshipsExistsAction extends ApiPrivateAuthAction
  60. {
  61. var $profile_a = null;
  62. var $profile_b = null;
  63. /**
  64. * Take arguments for running
  65. *
  66. * @param array $args $_REQUEST args
  67. *
  68. * @return boolean success flag
  69. */
  70. protected function prepare(array $args=array())
  71. {
  72. parent::prepare($args);
  73. $this->profile_a = $this->getTargetProfile($this->trimmed('user_a'));
  74. $this->profile_b = $this->getTargetProfile($this->trimmed('user_b'));
  75. return true;
  76. }
  77. /**
  78. * Handle the request
  79. *
  80. * Check the format and show the user info
  81. *
  82. * @return void
  83. */
  84. protected function handle()
  85. {
  86. parent::handle();
  87. if (empty($this->profile_a) || empty($this->profile_b)) {
  88. $this->clientError(
  89. // TRANS: Client error displayed when supplying invalid parameters to an API call checking if a friendship exists.
  90. _('Two valid IDs or nick names must be supplied.'),
  91. 400
  92. );
  93. }
  94. $result = Subscription::exists($this->profile_a, $this->profile_b);
  95. switch ($this->format) {
  96. case 'xml':
  97. $this->initDocument('xml');
  98. $this->element('friends', null, $result);
  99. $this->endDocument('xml');
  100. break;
  101. case 'json':
  102. $this->initDocument('json');
  103. print json_encode($result);
  104. $this->endDocument('json');
  105. break;
  106. default:
  107. break;
  108. }
  109. }
  110. /**
  111. * Return true if read only.
  112. *
  113. * MAY override
  114. *
  115. * @param array $args other arguments
  116. *
  117. * @return boolean is read only action?
  118. */
  119. function isReadOnly($args)
  120. {
  121. return true;
  122. }
  123. }
  124. // END OF FILE
  125. // ============================================================================
  126. ?>