profilelistitem.php 7.7 KB

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