userbyid.php 2.7 KB

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