profilelistitem.php 8.2 KB

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