foafgroup.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /*
  3. * StatusNet the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @category Mail
  20. * @package StatusNet
  21. * @author Evan Prodromou <evan@status.net>
  22. * @author Toby Inkster <mail@tobyinkster.co.uk>
  23. * @copyright 2009 StatusNet, Inc.
  24. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  25. * @link http://status.net/
  26. */
  27. if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  28. // @todo XXX: Documentation missing.
  29. class FoafGroupAction extends Action
  30. {
  31. function isReadOnly($args)
  32. {
  33. return true;
  34. }
  35. function prepare(array $args = array())
  36. {
  37. parent::prepare($args);
  38. $nickname_arg = $this->arg('nickname');
  39. if (empty($nickname_arg)) {
  40. // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname.
  41. $this->clientError(_('No such group.'), 404);
  42. }
  43. $this->nickname = common_canonical_nickname($nickname_arg);
  44. // Permanent redirect on non-canonical nickname
  45. if ($nickname_arg != $this->nickname) {
  46. common_redirect(common_local_url('foafgroup',
  47. array('nickname' => $this->nickname)),
  48. 301);
  49. return false;
  50. }
  51. $local = Local_group::getKV('nickname', $this->nickname);
  52. if (!$local) {
  53. // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group.
  54. $this->clientError(_('No such group.'), 404);
  55. }
  56. $this->group = User_group::getKV('id', $local->group_id);
  57. if (!$this->group) {
  58. // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group.
  59. $this->clientError(_('No such group.'), 404);
  60. }
  61. common_set_returnto($this->selfUrl());
  62. return true;
  63. }
  64. function handle()
  65. {
  66. parent::handle();
  67. header('Content-Type: application/rdf+xml');
  68. $this->startXML();
  69. $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
  70. 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  71. 'xmlns:dcterms' =>
  72. 'http://purl.org/dc/terms/',
  73. 'xmlns:sioc' =>
  74. 'http://rdfs.org/sioc/ns#',
  75. 'xmlns:foaf' =>
  76. 'http://xmlns.com/foaf/0.1/',
  77. 'xmlns:statusnet' =>
  78. 'http://status.net/ont/',
  79. 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
  80. $this->showPpd(common_local_url('foafgroup', array('nickname' => $this->nickname)), $this->group->permalink());
  81. $this->elementStart('Group', array('rdf:about' =>
  82. $this->group->permalink()));
  83. if ($this->group->fullname) {
  84. $this->element('name', null, $this->group->fullname);
  85. }
  86. if ($this->group->description) {
  87. $this->element('dcterms:description', null, $this->group->description);
  88. }
  89. if ($this->group->nickname) {
  90. $this->element('dcterms:identifier', null, $this->group->nickname);
  91. $this->element('nick', null, $this->group->nickname);
  92. }
  93. foreach ($this->group->getAliases() as $alias) {
  94. $this->element('nick', null, $alias);
  95. }
  96. if ($this->group->homeUrl()) {
  97. $this->element('weblog', array('rdf:resource' => $this->group->homeUrl()));
  98. }
  99. if ($this->group->homepage) {
  100. $this->element('page', array('rdf:resource' => $this->group->homepage));
  101. }
  102. if ($this->group->homepage_logo) {
  103. $this->element('depiction', array('rdf:resource' => $this->group->homepage_logo));
  104. }
  105. $members = $this->group->getMembers();
  106. $member_details = array();
  107. while ($members->fetch()) {
  108. $member_uri = common_local_url('userbyid', array('id'=>$members->id));
  109. $member_details[$member_uri] = array(
  110. 'nickname' => $members->nickname,
  111. 'is_admin' => false,
  112. );
  113. $this->element('member', array('rdf:resource' => $member_uri));
  114. }
  115. $admins = $this->group->getAdmins();
  116. while ($admins->fetch()) {
  117. $admin_uri = common_local_url('userbyid', array('id'=>$admins->id));
  118. $member_details[$admin_uri]['is_admin'] = true;
  119. $this->element('statusnet:groupAdmin', array('rdf:resource' => $admin_uri));
  120. }
  121. $this->elementEnd('Group');
  122. ksort($member_details);
  123. foreach ($member_details as $uri => $details) {
  124. if ($details['is_admin'])
  125. {
  126. $this->elementStart('Agent', array('rdf:about' => $uri));
  127. $this->element('nick', null, $details['nickname']);
  128. $this->elementStart('account');
  129. $this->elementStart('sioc:User', array('rdf:about'=>$uri.'#acct'));
  130. $this->elementStart('sioc:has_function');
  131. $this->elementStart('statusnet:GroupAdminRole');
  132. $this->element('sioc:scope', array('rdf:resource' => $this->group->permalink()));
  133. $this->elementEnd('statusnet:GroupAdminRole');
  134. $this->elementEnd('sioc:has_function');
  135. $this->elementEnd('sioc:User');
  136. $this->elementEnd('account');
  137. $this->elementEnd('Agent');
  138. }
  139. else
  140. {
  141. $this->element('Agent', array(
  142. 'foaf:nick' => $details['nickname'],
  143. 'rdf:about' => $uri,
  144. ));
  145. }
  146. }
  147. $this->elementEnd('rdf:RDF');
  148. $this->endXML();
  149. }
  150. function showPpd($foaf_url, $person_uri)
  151. {
  152. $this->elementStart('Document', array('rdf:about' => $foaf_url));
  153. $this->element('primaryTopic', array('rdf:resource' => $person_uri));
  154. $this->elementEnd('Document');
  155. }
  156. }