userbyid.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * User by ID action class.
  18. *
  19. * @category Action
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @author Robin Millette <millette@status.net>
  23. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. /**
  28. * User by ID action class.
  29. *
  30. * @category Action
  31. * @package GNUsocial
  32. * @author Evan Prodromou <evan@status.net>
  33. * @author Robin Millette <millette@status.net>
  34. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  35. */
  36. class UserbyidAction extends ShowstreamAction
  37. {
  38. protected function doPreparation()
  39. {
  40. // accessing by ID just requires an ID, not a nickname
  41. $this->target = Profile::getByID($this->trimmed('id'));
  42. // For local users when accessed by id number, redirect with
  43. // the nickname as argument instead of id.
  44. if ($this->target->isLocal()) {
  45. // Support redirecting to FOAF rdf/xml if the agent prefers it...
  46. // Internet Explorer doesn't specify "text/html" and does list "*/*"
  47. // at least through version 8. We need to list text/html up front to
  48. // ensure that only user-agents who specifically ask for RDF get it.
  49. $page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2';
  50. $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
  51. $type = common_negotiate_type(
  52. common_accept_to_prefs($httpaccept),
  53. common_accept_to_prefs($page_prefs)
  54. );
  55. $page = ($type === 'application/rdf+xml') ? 'foaf' : 'showstream';
  56. $url = common_local_url($page, ['nickname' => $this->target->getNickname()]);
  57. common_redirect($url, 303);
  58. }
  59. }
  60. }