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.
 
 
 
 
 
 

396 lines
12 KiB

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