Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

419 lines
14 KiB

  1. <?php
  2. function profile_init(&$a) {
  3. if($a->argc > 1)
  4. $which = $a->argv[1];
  5. else {
  6. notice( t('No profile') . EOL );
  7. $a->error = 404;
  8. return;
  9. }
  10. $profile = 0;
  11. if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
  12. $which = $a->user['nickname'];
  13. $profile = $a->argv[1];
  14. }
  15. profile_load($a,$which,$profile);
  16. if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] & PAGE_COMMUNITY)) {
  17. $a->page['htmlhead'] .= '<meta name="friendika.community" content="true" />';
  18. }
  19. if(x($a->profile,'openidserver'))
  20. $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
  21. if(x($a->profile,'openid')) {
  22. $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
  23. $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
  24. }
  25. $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
  26. $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
  27. $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
  28. $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
  29. header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
  30. $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
  31. foreach($dfrn_pages as $dfrn)
  32. $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
  33. }
  34. function profile_content(&$a, $update = 0) {
  35. require_once("include/bbcode.php");
  36. require_once('include/security.php');
  37. $groups = array();
  38. $tab = 'posts';
  39. $o = '';
  40. if($update) {
  41. // Ensure we've got a profile owner if updating.
  42. $a->profile['profile_uid'] = $update;
  43. }
  44. else {
  45. if($a->profile['profile_uid'] == local_user())
  46. $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
  47. }
  48. $contact = null;
  49. $remote_contact = false;
  50. if(remote_user()) {
  51. $contact_id = $_SESSION['visitor_id'];
  52. $groups = init_groups_visitor($contact_id);
  53. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  54. intval($contact_id),
  55. intval($a->profile['profile_uid'])
  56. );
  57. if(count($r)) {
  58. $contact = $r[0];
  59. $remote_contact = true;
  60. }
  61. }
  62. if(! $remote_contact) {
  63. if(local_user()) {
  64. $contact_id = $_SESSION['cid'];
  65. $contact = $a->contact;
  66. }
  67. }
  68. $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
  69. if(! $update) {
  70. if(x($_GET,'tab'))
  71. $tab = notags(trim($_GET['tab']));
  72. $tpl = load_view_file('view/profile_tabs.tpl');
  73. $o .= replace_macros($tpl,array(
  74. '$url' => $a->get_baseurl() . '/' . $a->cmd,
  75. '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
  76. ));
  77. if($tab === 'profile') {
  78. $profile_lang = get_config('system','language');
  79. if(! $profile_lang)
  80. $profile_lang = 'en';
  81. if(file_exists("view/$profile_lang/profile_advanced.php"))
  82. require_once("view/$profile_lang/profile_advanced.php");
  83. else
  84. require_once('view/profile_advanced.php');
  85. call_hooks('profile_advanced',$o);
  86. return $o;
  87. }
  88. $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
  89. $commvisitor = (($commpage && $remote_contact == true) ? true : false);
  90. $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  91. if(can_write_wall($a,$a->profile['profile_uid'])) {
  92. $geotag = ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
  93. $tpl = load_view_file('view/jot-header.tpl');
  94. $a->page['htmlhead'] .= replace_macros($tpl, array(
  95. '$baseurl' => $a->get_baseurl(),
  96. '$geotag' => $geotag,
  97. '$nickname' => $a->profile['nickname']
  98. ));
  99. require_once('include/acl_selectors.php');
  100. $tpl = load_view_file('view/jot.tpl');
  101. if(is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))
  102. $lockstate = 'lock';
  103. else
  104. $lockstate = 'unlock';
  105. $jotplugins = '';
  106. $jotnets = '';
  107. call_hooks('jot_tool', $jotplugins);
  108. call_hooks('jot_networks', $jotnets);
  109. $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
  110. $o .= replace_macros($tpl,array(
  111. '$baseurl' => $a->get_baseurl(),
  112. '$action' => 'item',
  113. '$share' => t('Share'),
  114. '$upload' => t('Upload photo'),
  115. '$weblink' => t('Insert web link'),
  116. '$youtube' => t('Insert YouTube video'),
  117. '$setloc' => t('Set your location'),
  118. '$noloc' => t('Clear browser location'),
  119. '$wait' => t('Please wait'),
  120. '$permset' => t('Permission settings'),
  121. '$content' => '',
  122. '$post_id' => '',
  123. '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
  124. '$return_path' => $a->cmd,
  125. '$visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
  126. '$lockstate' => $lockstate,
  127. '$emailcc' => t('CC: email addresses'),
  128. '$jotnets' => $jotnets,
  129. '$emtitle' => t('Example: bob@example.com, mary@example.com'),
  130. '$bang' => '',
  131. '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
  132. '$profile_uid' => $a->profile['profile_uid']
  133. ));
  134. }
  135. // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
  136. // because browser prefetching might change it on us. We have to deliver it with the page.
  137. if($tab === 'posts') {
  138. $o .= '<div id="live-profile"></div>' . "\r\n";
  139. $o .= "<script> var profile_uid = " . $a->profile['profile_uid']
  140. . "; var netargs = ''; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  141. }
  142. }
  143. // Construct permissions
  144. // default permissions - anonymous user
  145. $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
  146. // Profile owner - everything is visible
  147. if($is_owner) {
  148. $sql_extra = '';
  149. // Oh - while we're here... reset the Unseen messages
  150. $r = q("UPDATE `item` SET `unseen` = 0
  151. WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
  152. intval($_SESSION['uid'])
  153. );
  154. }
  155. // authenticated visitor - here lie dragons
  156. // If $remotecontact is true, we know that not only is this a remotely authenticated
  157. // person, but that it is *our* contact, which is important in multi-user mode.
  158. elseif($remote_contact) {
  159. $gs = '<<>>'; // should be impossible to match
  160. if(count($groups)) {
  161. foreach($groups as $g)
  162. $gs .= '|<' . intval($g) . '>';
  163. }
  164. $sql_extra = sprintf(
  165. " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
  166. AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
  167. AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
  168. AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
  169. intval($_SESSION['visitor_id']),
  170. intval($_SESSION['visitor_id']),
  171. dbesc($gs),
  172. dbesc($gs)
  173. );
  174. }
  175. $r = q("SELECT COUNT(*) AS `total`
  176. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  177. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  178. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  179. AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
  180. $sql_extra ",
  181. intval($a->profile['profile_uid'])
  182. );
  183. if(count($r))
  184. $a->set_pager_total($r[0]['total']);
  185. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  186. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`,
  187. `contact`.`thumb`, `contact`.`self`,
  188. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  189. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  190. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  191. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  192. AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
  193. $sql_extra
  194. ORDER BY `parent` DESC, `gravity` ASC, `id` ASC LIMIT %d ,%d ",
  195. intval($a->profile['profile_uid']),
  196. intval($a->pager['start']),
  197. intval($a->pager['itemspage'])
  198. );
  199. if($is_owner && ! $update)
  200. $o .= get_birthdays();
  201. $cmnt_tpl = load_view_file('view/comment_item.tpl');
  202. $like_tpl = load_view_file('view/like.tpl');
  203. $tpl = load_view_file('view/wall_item.tpl');
  204. $droptpl = load_view_file('view/wall_item_drop.tpl');
  205. $fakedrop = load_view_file('view/wall_fake_drop.tpl');
  206. if($update)
  207. $return_url = $_SESSION['return_url'];
  208. else
  209. $return_url = $_SESSION['return_url'] = $a->cmd;
  210. $alike = array();
  211. $dlike = array();
  212. if($r !== false && count($r)) {
  213. foreach($r as $item) {
  214. like_puller($a,$item,$alike,'like');
  215. like_puller($a,$item,$dlike,'dislike');
  216. }
  217. foreach($r as $item) {
  218. $sparkle = '';
  219. $comment = '';
  220. $likebuttons = '';
  221. $template = $tpl;
  222. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  223. if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
  224. && ($item['id'] != $item['parent']))
  225. continue;
  226. $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  227. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  228. ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
  229. : '<div class="wall-item-lock"></div>');
  230. if(can_write_wall($a,$a->profile['profile_uid'])) {
  231. if($item['id'] == $item['parent']) {
  232. $likebuttons = replace_macros($like_tpl,array(
  233. '$id' => $item['id'],
  234. '$likethis' => t("I like this \x28toggle\x29"),
  235. '$nolike' => t("I don't like this \x28toggle\x29"),
  236. '$wait' => t('Please wait')
  237. ));
  238. }
  239. if($item['last-child']) {
  240. $comment = replace_macros($cmnt_tpl,array(
  241. '$return_path' => '',
  242. '$jsreload' => '', // $_SESSION['return_url'],
  243. '$type' => 'wall-comment',
  244. '$id' => $item['item_id'],
  245. '$parent' => $item['parent'],
  246. '$profile_uid' => $a->profile['profile_uid'],
  247. '$mylink' => $contact['url'],
  248. '$mytitle' => t('This is you'),
  249. '$myphoto' => $contact['thumb'],
  250. '$ww' => ''
  251. ));
  252. }
  253. }
  254. $profile_url = $item['url'];
  255. // This is my profile page but I'm not the author of this post/comment. If it's somebody that's a fan or mutual friend,
  256. // I can go directly to their profile as an authenticated guest.
  257. if(local_user() && ($item['contact-uid'] == $_SESSION['uid'])
  258. && ($item['network'] === 'dfrn') && (! $item['self'] )) {
  259. $profile_url = $redirect_url;
  260. $sparkle = ' sparkle';
  261. }
  262. else
  263. $sparkle = '';
  264. // We would prefer to use our own avatar link for this item because the one in the author-avatar might reference a
  265. // remote site (which could be down). We will use author-avatar if we haven't got something stored locally.
  266. // We use this same logic block in mod/network.php to determine it this is a third party post and we don't have any
  267. // local contact info at all. In this module you should never encounter a third-party author, but we still will do
  268. // the right thing if you ever do.
  269. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  270. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  271. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
  272. $profile_link = $profile_url;
  273. $drop = '';
  274. $dropping = false;
  275. if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  276. $dropping = true;
  277. $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
  278. $like = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
  279. $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
  280. $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  281. $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  282. if($coord) {
  283. if($location)
  284. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  285. else
  286. $location = '<span class="smalltext">' . $coord . '</span>';
  287. }
  288. $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
  289. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  290. $indent .= ' shiny';
  291. $tmp_item = replace_macros($template,array(
  292. '$id' => $item['item_id'],
  293. '$linktitle' => t('View $name\'s profile'),
  294. '$profile_url' => $profile_link,
  295. '$name' => $profile_name,
  296. '$thumb' => $profile_avatar,
  297. '$sparkle' => $sparkle,
  298. '$title' => $item['title'],
  299. '$body' => smilies(bbcode($item['body'])),
  300. '$ago' => relative_date($item['created']),
  301. '$lock' => $lock,
  302. '$location' => $location,
  303. '$indent' => $indent,
  304. '$plink' => get_plink($item),
  305. '$drop' => $drop,
  306. '$like' => $like,
  307. '$vote' => $likebuttons,
  308. '$dislike' => $dislike,
  309. '$comment' => $comment
  310. ));
  311. $arr = array('item' => $item, 'output' => $tmp_item);
  312. call_hooks('display_item', $arr);
  313. $o .= $arr['output'];
  314. }
  315. }
  316. if($update) {
  317. return $o;
  318. }
  319. $o .= paginate($a);
  320. $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
  321. return $o;
  322. }