userbyid.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * User by ID action class.
  34. *
  35. * @category Action
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @author Robin Millette <millette@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  40. * @link http://status.net/
  41. */
  42. class UserbyidAction extends Action
  43. {
  44. /**
  45. * Is read only?
  46. *
  47. * @return boolean true
  48. */
  49. function isReadOnly($args)
  50. {
  51. return true;
  52. }
  53. /**
  54. * Class handler.
  55. *
  56. * @param array $args array of arguments
  57. *
  58. * @return nothing
  59. */
  60. protected function handle()
  61. {
  62. parent::handle();
  63. $id = $this->trimmed('id');
  64. if (!$id) {
  65. // TRANS: Client error displayed trying to find a user by ID without providing an ID.
  66. $this->clientError(_('No ID.'));
  67. }
  68. $user = User::getKV($id);
  69. if (!$user) {
  70. // TRANS: Client error displayed trying to find a user by ID for a non-existing ID.
  71. $this->clientError(_('No such user.'));
  72. }
  73. // Support redirecting to FOAF rdf/xml if the agent prefers it...
  74. // Internet Explorer doesn't specify "text/html" and does list "*/*"
  75. // at least through version 8. We need to list text/html up front to
  76. // ensure that only user-agents who specifically ask for RDF get it.
  77. $page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2';
  78. $httpaccept = isset($_SERVER['HTTP_ACCEPT'])
  79. ? $_SERVER['HTTP_ACCEPT'] : null;
  80. $type = common_negotiate_type(common_accept_to_prefs($httpaccept),
  81. common_accept_to_prefs($page_prefs));
  82. $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream';
  83. $url = common_local_url($page, array('nickname' => $user->nickname));
  84. common_redirect($url, 303);
  85. }
  86. }