profilelistitem.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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)
  39. {
  40. parent::__construct($action);
  41. $this->target = $target;
  42. $this->profile = $this->target;
  43. $this->action = $action;
  44. }
  45. function getTarget()
  46. {
  47. return $this->target;
  48. }
  49. function show()
  50. {
  51. if (Event::handle('StartProfileListItem', array($this))) {
  52. $this->startItem();
  53. if (Event::handle('StartProfileListItemProfile', array($this))) {
  54. $this->showProfile();
  55. Event::handle('EndProfileListItemProfile', array($this));
  56. }
  57. if (Event::handle('StartProfileListItemActions', array($this))) {
  58. $this->showActions();
  59. Event::handle('EndProfileListItemActions', array($this));
  60. }
  61. $this->endItem();
  62. Event::handle('EndProfileListItem', array($this));
  63. }
  64. }
  65. function startItem()
  66. {
  67. $this->out->elementStart('li', array('class' => 'profile',
  68. 'id' => 'profile-' . $this->getTarget()->getID()));
  69. }
  70. function showProfile()
  71. {
  72. $this->startProfile();
  73. if (Event::handle('StartProfileListItemProfileElements', array($this))) {
  74. if (Event::handle('StartProfileListItemAvatar', array($this))) {
  75. $aAttrs = $this->linkAttributes();
  76. $this->out->elementStart('a', $aAttrs);
  77. $this->showAvatar($this->profile);
  78. $this->out->elementEnd('a');
  79. Event::handle('EndProfileListItemAvatar', array($this));
  80. }
  81. if (Event::handle('StartProfileListItemNickname', array($this))) {
  82. $this->showNickname();
  83. Event::handle('EndProfileListItemNickname', array($this));
  84. }
  85. if (Event::handle('StartProfileListItemFullName', array($this))) {
  86. $this->showFullName();
  87. Event::handle('EndProfileListItemFullName', array($this));
  88. }
  89. if (Event::handle('StartProfileListItemLocation', array($this))) {
  90. $this->showLocation();
  91. Event::handle('EndProfileListItemLocation', array($this));
  92. }
  93. if (Event::handle('StartProfileListItemHomepage', array($this))) {
  94. $this->showHomepage();
  95. Event::handle('EndProfileListItemHomepage', array($this));
  96. }
  97. if (Event::handle('StartProfileListItemBio', array($this))) {
  98. $this->showBio();
  99. Event::handle('EndProfileListItemBio', array($this));
  100. }
  101. if (Event::handle('StartProfileListItemTags', array($this))) {
  102. $this->showTags();
  103. Event::handle('EndProfileListItemTags', array($this));
  104. }
  105. Event::handle('EndProfileListItemProfileElements', array($this));
  106. }
  107. $this->endProfile();
  108. }
  109. function startProfile()
  110. {
  111. $this->out->elementStart('div', 'entity_profile h-card');
  112. }
  113. function showNickname()
  114. {
  115. $this->out->element('a', array('href'=>$this->profile->getUrl(),
  116. 'class'=>'p-nickname'),
  117. $this->profile->getNickname());
  118. }
  119. function showFullName()
  120. {
  121. if (!empty($this->profile->fullname)) {
  122. $this->out->element('span', 'p-name', $this->profile->fullname);
  123. }
  124. }
  125. function showLocation()
  126. {
  127. if (!empty($this->profile->location)) {
  128. $this->out->element('span', 'label p-locality', $this->profile->location);
  129. }
  130. }
  131. function showHomepage()
  132. {
  133. if (!empty($this->profile->homepage)) {
  134. $this->out->text(' ');
  135. $aAttrs = $this->homepageAttributes();
  136. $this->out->elementStart('a', $aAttrs);
  137. $this->out->raw($this->highlight($this->profile->homepage));
  138. $this->out->elementEnd('a');
  139. }
  140. }
  141. function showBio()
  142. {
  143. if (!empty($this->profile->bio)) {
  144. $this->out->elementStart('p', 'note');
  145. $this->out->raw($this->highlight($this->profile->bio));
  146. $this->out->elementEnd('p');
  147. }
  148. }
  149. function showTags()
  150. {
  151. $user = common_current_user();
  152. if (!empty($user)) {
  153. if ($user->id == $this->profile->id) {
  154. $tags = new SelftagsWidget($this->out, $user, $this->profile);
  155. $tags->show();
  156. } else if ($user->getProfile()->canTag($this->profile)) {
  157. $tags = new PeopletagsWidget($this->out, $user, $this->profile);
  158. $tags->show();
  159. }
  160. }
  161. }
  162. function endProfile()
  163. {
  164. $this->out->elementEnd('div');
  165. }
  166. function showActions()
  167. {
  168. $this->startActions();
  169. if (Event::handle('StartProfileListItemActionElements', array($this))) {
  170. $this->showSubscribeButton();
  171. Event::handle('EndProfileListItemActionElements', array($this));
  172. }
  173. $this->endActions();
  174. }
  175. function startActions()
  176. {
  177. $this->out->elementStart('div', 'entity_actions');
  178. $this->out->elementStart('ul');
  179. }
  180. function showSubscribeButton()
  181. {
  182. // Is this a logged-in user, looking at someone else's
  183. // profile?
  184. $user = common_current_user();
  185. if (!empty($user) && $this->profile->id != $user->id) {
  186. $this->out->elementStart('li', 'entity_subscribe');
  187. if ($user->isSubscribed($this->profile)) {
  188. $usf = new UnsubscribeForm($this->out, $this->profile);
  189. $usf->show();
  190. } else {
  191. if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
  192. $sf = new SubscribeForm($this->out, $this->profile);
  193. $sf->show();
  194. Event::handle('EndShowProfileListSubscribeButton', array($this));
  195. }
  196. }
  197. $this->out->elementEnd('li');
  198. }
  199. }
  200. function endActions()
  201. {
  202. $this->out->elementEnd('ul');
  203. $this->out->elementEnd('div');
  204. }
  205. function endItem()
  206. {
  207. $this->out->elementEnd('li');
  208. }
  209. function highlight($text)
  210. {
  211. return htmlspecialchars($text);
  212. }
  213. function linkAttributes()
  214. {
  215. return array('href' => $this->profile->profileurl,
  216. 'class' => 'u-url',
  217. 'rel' => 'contact');
  218. }
  219. function homepageAttributes()
  220. {
  221. return array('href' => $this->profile->homepage,
  222. 'class' => 'u-url');
  223. }
  224. }