profilelistitem.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget to show a list of profiles
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Public
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('GNUSOCIAL')) { exit(1); }
  30. class ProfileListItem extends Widget
  31. {
  32. /** Current profile. */
  33. protected $target = null;
  34. var $profile = null;
  35. /** Action object using us. */
  36. var $action = null;
  37. // FIXME: Directory plugin sends a User_group here, but should send a Profile and handle User_group specifics itself?
  38. function __construct($target, HTMLOutputter $action, Profile $owner = null)
  39. {
  40. parent::__construct($action);
  41. $this->target = $target;
  42. if ($owner !== null) {
  43. $this->profile = $owner;
  44. } else {
  45. $this->profile = $this->target;
  46. }
  47. $this->action = $action;
  48. }
  49. function getTarget()
  50. {
  51. return $this->target;
  52. }
  53. function show()
  54. {
  55. if (Event::handle('StartProfileListItem', array($this))) {
  56. $this->startItem();
  57. if (Event::handle('StartProfileListItemProfile', array($this))) {
  58. $this->showProfile();
  59. Event::handle('EndProfileListItemProfile', array($this));
  60. }
  61. if (Event::handle('StartProfileListItemActions', array($this))) {
  62. $this->showActions();
  63. Event::handle('EndProfileListItemActions', array($this));
  64. }
  65. $this->endItem();
  66. Event::handle('EndProfileListItem', array($this));
  67. }
  68. }
  69. function startItem()
  70. {
  71. $this->out->elementStart('li', array('class' => 'profile',
  72. 'id' => 'profile-' . $this->getTarget()->getID()));
  73. }
  74. function showProfile()
  75. {
  76. $this->startProfile();
  77. if (Event::handle('StartProfileListItemProfileElements', array($this))) {
  78. if (Event::handle('StartProfileListItemAvatar', array($this))) {
  79. $aAttrs = $this->linkAttributes();
  80. $this->out->elementStart('a', $aAttrs);
  81. $this->showAvatar($this->profile);
  82. $this->out->elementEnd('a');
  83. Event::handle('EndProfileListItemAvatar', array($this));
  84. }
  85. if (Event::handle('StartProfileListItemNickname', array($this))) {
  86. $this->showNickname();
  87. Event::handle('EndProfileListItemNickname', array($this));
  88. }
  89. if (Event::handle('StartProfileListItemFullName', array($this))) {
  90. $this->showFullName();
  91. Event::handle('EndProfileListItemFullName', array($this));
  92. }
  93. if (Event::handle('StartProfileListItemLocation', array($this))) {
  94. $this->showLocation();
  95. Event::handle('EndProfileListItemLocation', array($this));
  96. }
  97. if (Event::handle('StartProfileListItemHomepage', array($this))) {
  98. $this->showHomepage();
  99. Event::handle('EndProfileListItemHomepage', array($this));
  100. }
  101. if (Event::handle('StartProfileListItemBio', array($this))) {
  102. $this->showBio();
  103. Event::handle('EndProfileListItemBio', array($this));
  104. }
  105. if (Event::handle('StartProfileListItemTags', array($this))) {
  106. $this->showTags();
  107. Event::handle('EndProfileListItemTags', array($this));
  108. }
  109. Event::handle('EndProfileListItemProfileElements', array($this));
  110. }
  111. $this->endProfile();
  112. }
  113. function startProfile()
  114. {
  115. $this->out->elementStart('div', 'entity_profile h-card');
  116. }
  117. function showNickname()
  118. {
  119. $this->out->element('a', array('href'=>$this->profile->getUrl(),
  120. 'class'=>'p-nickname'),
  121. $this->profile->getNickname());
  122. }
  123. function showFullName()
  124. {
  125. if (!empty($this->profile->fullname)) {
  126. $this->out->element('span', 'p-name', $this->profile->fullname);
  127. }
  128. }
  129. function showLocation()
  130. {
  131. if (!empty($this->profile->location)) {
  132. $this->out->element('span', 'label p-locality', $this->profile->location);
  133. }
  134. }
  135. function showHomepage()
  136. {
  137. if (!empty($this->profile->homepage)) {
  138. $this->out->text(' ');
  139. $aAttrs = $this->homepageAttributes();
  140. $this->out->elementStart('a', $aAttrs);
  141. $this->out->raw($this->highlight($this->profile->homepage));
  142. $this->out->elementEnd('a');
  143. }
  144. }
  145. function showBio()
  146. {
  147. if (!empty($this->profile->bio)) {
  148. $this->out->elementStart('p', 'note');
  149. $this->out->raw($this->highlight($this->profile->bio));
  150. $this->out->elementEnd('p');
  151. }
  152. }
  153. function showTags()
  154. {
  155. $user = common_current_user();
  156. if (!empty($user)) {
  157. if ($user->id == $this->profile->getID()) {
  158. $tags = new SelftagsWidget($this->out, $user, $this->profile);
  159. $tags->show();
  160. } else if ($user->getProfile()->canTag($this->profile)) {
  161. $tags = new PeopletagsWidget($this->out, $user, $this->profile);
  162. $tags->show();
  163. }
  164. }
  165. }
  166. function endProfile()
  167. {
  168. $this->out->elementEnd('div');
  169. }
  170. function showActions()
  171. {
  172. $this->startActions();
  173. if (Event::handle('StartProfileListItemActionElements', array($this))) {
  174. $this->showSubscribeButton();
  175. Event::handle('EndProfileListItemActionElements', array($this));
  176. }
  177. $this->endActions();
  178. }
  179. function startActions()
  180. {
  181. $this->out->elementStart('div', 'entity_actions');
  182. $this->out->elementStart('ul');
  183. }
  184. function showSubscribeButton()
  185. {
  186. // Is this a logged-in user, looking at someone else's
  187. // profile?
  188. $user = common_current_user();
  189. if (!empty($user) && $this->profile->id != $user->id) {
  190. $this->out->elementStart('li', 'entity_subscribe');
  191. if ($user->isSubscribed($this->profile)) {
  192. $usf = new UnsubscribeForm($this->out, $this->profile);
  193. $usf->show();
  194. } else {
  195. if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
  196. $sf = new SubscribeForm($this->out, $this->profile);
  197. $sf->show();
  198. Event::handle('EndShowProfileListSubscribeButton', array($this));
  199. }
  200. }
  201. $this->out->elementEnd('li');
  202. }
  203. }
  204. function endActions()
  205. {
  206. $this->out->elementEnd('ul');
  207. $this->out->elementEnd('div');
  208. }
  209. function endItem()
  210. {
  211. $this->out->elementEnd('li');
  212. }
  213. function highlight($text)
  214. {
  215. return htmlspecialchars($text);
  216. }
  217. function linkAttributes()
  218. {
  219. return array('href' => $this->profile->profileurl,
  220. 'class' => 'u-url',
  221. 'rel' => 'contact');
  222. }
  223. function homepageAttributes()
  224. {
  225. return array('href' => $this->profile->homepage,
  226. 'class' => 'u-url');
  227. }
  228. }