profilelist.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR.'/lib/peopletags.php';
  33. /**
  34. * Widget to show a list of profiles
  35. *
  36. * @category Public
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @author Evan Prodromou <evan@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class ProfileList extends Widget
  44. {
  45. /** Current profile, profile query. */
  46. var $profile = null;
  47. /** Action object using us. */
  48. var $action = null;
  49. function __construct($profile, $action=null)
  50. {
  51. parent::__construct($action);
  52. $this->profile = $profile;
  53. $this->action = $action;
  54. }
  55. function show()
  56. {
  57. $cnt = 0;
  58. if (Event::handle('StartProfileList', array($this))) {
  59. $this->startList();
  60. $cnt = $this->showProfiles();
  61. $this->endList();
  62. Event::handle('EndProfileList', array($this));
  63. }
  64. return $cnt;
  65. }
  66. function startList()
  67. {
  68. $this->out->elementStart('ul', 'profile_list xoxo');
  69. }
  70. function endList()
  71. {
  72. $this->out->elementEnd('ul');
  73. }
  74. function showProfiles()
  75. {
  76. $cnt = $this->profile->N;
  77. $profiles = $this->profile->fetchAll();
  78. $max = min($cnt, $this->maxProfiles());
  79. for ($i = 0; $i < $max; $i++) {
  80. $pli = $this->newListItem($profiles[$i]);
  81. $pli->show();
  82. }
  83. return $cnt;
  84. }
  85. function newListItem($profile)
  86. {
  87. return new ProfileListItem($profile, $this->action);
  88. }
  89. function maxProfiles()
  90. {
  91. return PROFILES_PER_PAGE;
  92. }
  93. }
  94. class ProfileListItem extends Widget
  95. {
  96. /** Current profile. */
  97. var $profile = null;
  98. /** Action object using us. */
  99. var $action = null;
  100. function __construct($profile, $action)
  101. {
  102. parent::__construct($action);
  103. $this->profile = $profile;
  104. $this->action = $action;
  105. }
  106. function show()
  107. {
  108. if (Event::handle('StartProfileListItem', array($this))) {
  109. $this->startItem();
  110. if (Event::handle('StartProfileListItemProfile', array($this))) {
  111. $this->showProfile();
  112. Event::handle('EndProfileListItemProfile', array($this));
  113. }
  114. if (Event::handle('StartProfileListItemActions', array($this))) {
  115. $this->showActions();
  116. Event::handle('EndProfileListItemActions', array($this));
  117. }
  118. $this->endItem();
  119. Event::handle('EndProfileListItem', array($this));
  120. }
  121. }
  122. function startItem()
  123. {
  124. $this->out->elementStart('li', array('class' => 'profile',
  125. 'id' => 'profile-' . $this->profile->id));
  126. }
  127. function showProfile()
  128. {
  129. $this->startProfile();
  130. if (Event::handle('StartProfileListItemProfileElements', array($this))) {
  131. if (Event::handle('StartProfileListItemAvatar', array($this))) {
  132. $aAttrs = $this->linkAttributes();
  133. $this->out->elementStart('a', $aAttrs);
  134. $this->showAvatar($this->profile);
  135. $this->out->elementEnd('a');
  136. Event::handle('EndProfileListItemAvatar', array($this));
  137. }
  138. if (Event::handle('StartProfileListItemNickname', array($this))) {
  139. $this->showNickname();
  140. Event::handle('EndProfileListItemNickname', array($this));
  141. }
  142. if (Event::handle('StartProfileListItemFullName', array($this))) {
  143. $this->showFullName();
  144. Event::handle('EndProfileListItemFullName', array($this));
  145. }
  146. if (Event::handle('StartProfileListItemLocation', array($this))) {
  147. $this->showLocation();
  148. Event::handle('EndProfileListItemLocation', array($this));
  149. }
  150. if (Event::handle('StartProfileListItemHomepage', array($this))) {
  151. $this->showHomepage();
  152. Event::handle('EndProfileListItemHomepage', array($this));
  153. }
  154. if (Event::handle('StartProfileListItemBio', array($this))) {
  155. $this->showBio();
  156. Event::handle('EndProfileListItemBio', array($this));
  157. }
  158. if (Event::handle('StartProfileListItemTags', array($this))) {
  159. $this->showTags();
  160. Event::handle('EndProfileListItemTags', array($this));
  161. }
  162. Event::handle('EndProfileListItemProfileElements', array($this));
  163. }
  164. $this->endProfile();
  165. }
  166. function startProfile()
  167. {
  168. $this->out->elementStart('div', 'entity_profile h-card');
  169. }
  170. function showNickname()
  171. {
  172. $this->out->element('a', array('href'=>$this->profile->getUrl(),
  173. 'class'=>'p-nickname'),
  174. $this->profile->getNickname());
  175. }
  176. function showFullName()
  177. {
  178. if (!empty($this->profile->fullname)) {
  179. $this->out->element('span', 'p-name', $this->profile->fullname);
  180. }
  181. }
  182. function showLocation()
  183. {
  184. if (!empty($this->profile->location)) {
  185. $this->out->element('span', 'label p-locality', $this->profile->location);
  186. }
  187. }
  188. function showHomepage()
  189. {
  190. if (!empty($this->profile->homepage)) {
  191. $this->out->text(' ');
  192. $aAttrs = $this->homepageAttributes();
  193. $this->out->elementStart('a', $aAttrs);
  194. $this->out->raw($this->highlight($this->profile->homepage));
  195. $this->out->elementEnd('a');
  196. }
  197. }
  198. function showBio()
  199. {
  200. if (!empty($this->profile->bio)) {
  201. $this->out->elementStart('p', 'note');
  202. $this->out->raw($this->highlight($this->profile->bio));
  203. $this->out->elementEnd('p');
  204. }
  205. }
  206. function showTags()
  207. {
  208. $user = common_current_user();
  209. if (!empty($user)) {
  210. if ($user->id == $this->profile->id) {
  211. $tags = new SelftagsWidget($this->out, $user, $this->profile);
  212. $tags->show();
  213. } else if ($user->getProfile()->canTag($this->profile)) {
  214. $tags = new PeopletagsWidget($this->out, $user, $this->profile);
  215. $tags->show();
  216. }
  217. }
  218. }
  219. function endProfile()
  220. {
  221. $this->out->elementEnd('div');
  222. }
  223. function showActions()
  224. {
  225. $this->startActions();
  226. if (Event::handle('StartProfileListItemActionElements', array($this))) {
  227. $this->showSubscribeButton();
  228. Event::handle('EndProfileListItemActionElements', array($this));
  229. }
  230. $this->endActions();
  231. }
  232. function startActions()
  233. {
  234. $this->out->elementStart('div', 'entity_actions');
  235. $this->out->elementStart('ul');
  236. }
  237. function showSubscribeButton()
  238. {
  239. // Is this a logged-in user, looking at someone else's
  240. // profile?
  241. $user = common_current_user();
  242. if (!empty($user) && $this->profile->id != $user->id) {
  243. $this->out->elementStart('li', 'entity_subscribe');
  244. if ($user->isSubscribed($this->profile)) {
  245. $usf = new UnsubscribeForm($this->out, $this->profile);
  246. $usf->show();
  247. } else {
  248. if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
  249. $sf = new SubscribeForm($this->out, $this->profile);
  250. $sf->show();
  251. Event::handle('EndShowProfileListSubscribeButton', array($this));
  252. }
  253. }
  254. $this->out->elementEnd('li');
  255. }
  256. }
  257. function endActions()
  258. {
  259. $this->out->elementEnd('ul');
  260. $this->out->elementEnd('div');
  261. }
  262. function endItem()
  263. {
  264. $this->out->elementEnd('li');
  265. }
  266. function highlight($text)
  267. {
  268. return htmlspecialchars($text);
  269. }
  270. function linkAttributes()
  271. {
  272. return array('href' => $this->profile->profileurl,
  273. 'class' => 'u-url',
  274. 'rel' => 'contact');
  275. }
  276. function homepageAttributes()
  277. {
  278. return array('href' => $this->profile->homepage,
  279. 'class' => 'u-url');
  280. }
  281. }