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.

318 lines
10 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
9 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
  1. <?php
  2. function profile_init(&$a) {
  3. require_once('include/contact_widgets.php');
  4. if(! x($a->page,'aside'))
  5. $a->page['aside'] = '';
  6. $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
  7. if($a->argc > 1)
  8. $which = $a->argv[1];
  9. else {
  10. $r = q("select nickname from user where blocked = 0 and account_expired = 0 and verified = 1 order by rand() limit 1");
  11. if(count($r)) {
  12. goaway($a->get_baseurl() . '/profile/' . $r[0]['nickname']);
  13. }
  14. else {
  15. logger('profile error: mod_profile ' . $a->query_string, LOGGER_DEBUG);
  16. notice( t('Requested profile is not available.') . EOL );
  17. $a->error = 404;
  18. return;
  19. }
  20. }
  21. $profile = 0;
  22. if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
  23. $which = $a->user['nickname'];
  24. $profile = $a->argv[1];
  25. }
  26. profile_load($a,$which,$profile);
  27. $userblock = (($a->profile['hidewall'] && (! local_user()) && (! remote_user())) ? true : false);
  28. if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) {
  29. $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
  30. }
  31. if(x($a->profile,'openidserver'))
  32. $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
  33. if(x($a->profile,'openid')) {
  34. $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
  35. $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
  36. }
  37. // site block
  38. if((! $blocked) && (! $userblock)) {
  39. $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
  40. $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
  41. if(strlen($keywords))
  42. $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
  43. }
  44. $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
  45. $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
  46. $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
  47. $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
  48. header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
  49. $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
  50. foreach($dfrn_pages as $dfrn)
  51. $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
  52. $a->page['htmlhead'] .= "<link rel=\"dfrn-poco\" href=\"".$a->get_baseurl()."/poco/{$which}\" />\r\n";
  53. }
  54. function profile_content(&$a, $update = 0) {
  55. $category = $datequery = $datequery2 = '';
  56. if($a->argc > 2) {
  57. for($x = 2; $x < $a->argc; $x ++) {
  58. if(is_a_date_arg($a->argv[$x])) {
  59. if($datequery)
  60. $datequery2 = escape_tags($a->argv[$x]);
  61. else
  62. $datequery = escape_tags($a->argv[$x]);
  63. }
  64. else
  65. $category = $a->argv[$x];
  66. }
  67. }
  68. if(! x($category)) {
  69. $category = ((x($_GET,'category')) ? $_GET['category'] : '');
  70. }
  71. if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
  72. return login();
  73. }
  74. require_once("include/bbcode.php");
  75. require_once('include/security.php');
  76. require_once('include/conversation.php');
  77. require_once('include/acl_selectors.php');
  78. require_once('include/items.php');
  79. $groups = array();
  80. $tab = 'posts';
  81. $o = '';
  82. if($update) {
  83. // Ensure we've got a profile owner if updating.
  84. $a->profile['profile_uid'] = $update;
  85. }
  86. else {
  87. if($a->profile['profile_uid'] == local_user()) {
  88. nav_set_selected('home');
  89. }
  90. }
  91. $contact = null;
  92. $remote_contact = false;
  93. if(remote_user()) {
  94. $contact_id = $_SESSION['visitor_id'];
  95. $groups = init_groups_visitor($contact_id);
  96. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  97. intval($contact_id),
  98. intval($a->profile['profile_uid'])
  99. );
  100. if(count($r)) {
  101. $contact = $r[0];
  102. $remote_contact = true;
  103. }
  104. }
  105. if(! $remote_contact) {
  106. if(local_user()) {
  107. $contact_id = $_SESSION['cid'];
  108. $contact = $a->contact;
  109. }
  110. }
  111. $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
  112. if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
  113. notice( t('Access to this profile has been restricted.') . EOL);
  114. return;
  115. }
  116. if(! $update) {
  117. if(x($_GET,'tab'))
  118. $tab = notags(trim($_GET['tab']));
  119. $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
  120. if($tab === 'profile') {
  121. require_once('include/profile_advanced.php');
  122. $o .= advanced_profile($a);
  123. call_hooks('profile_advanced',$o);
  124. return $o;
  125. }
  126. $o .= common_friends_visitor_widget($a->profile['profile_uid']);
  127. if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
  128. $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
  129. $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
  130. $commvisitor = (($commpage && $remote_contact == true) ? true : false);
  131. $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  132. $a->page['aside'] .= posted_date_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],$a->profile['profile_uid'],true);
  133. $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
  134. if(can_write_wall($a,$a->profile['profile_uid'])) {
  135. $x = array(
  136. 'is_owner' => $is_owner,
  137. 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
  138. 'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
  139. 'nickname' => $a->profile['nickname'],
  140. 'lockstate' => (((is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
  141. 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
  142. 'bang' => '',
  143. 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
  144. 'profile_uid' => $a->profile['profile_uid']
  145. );
  146. $o .= status_editor($a,$x);
  147. }
  148. }
  149. /**
  150. * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
  151. */
  152. $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
  153. if($update) {
  154. $r = q("SELECT distinct(parent) AS `item_id`, `contact`.`uid` AS `contact-uid`
  155. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  156. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  157. and `item`.`moderated` = 0 and `item`.`unseen` = 1
  158. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  159. AND `item`.`wall` = 1
  160. $sql_extra
  161. ORDER BY `item`.`created` DESC",
  162. intval($a->profile['profile_uid'])
  163. );
  164. }
  165. else {
  166. if(x($category)) {
  167. $sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
  168. }
  169. if($datequery) {
  170. $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
  171. }
  172. if($datequery2) {
  173. $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
  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 `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  179. AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
  180. $sql_extra $sql_extra2 ",
  181. intval($a->profile['profile_uid'])
  182. );
  183. if(count($r)) {
  184. $a->set_pager_total($r[0]['total']);
  185. $a->set_pager_itemspage(40);
  186. }
  187. $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
  188. $r = q("SELECT `item`.`id` AS `item_id`, `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 `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  192. AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
  193. $sql_extra $sql_extra2
  194. ORDER BY `item`.`created` DESC $pager_sql ",
  195. intval($a->profile['profile_uid'])
  196. );
  197. }
  198. $parents_arr = array();
  199. $parents_str = '';
  200. if(count($r)) {
  201. foreach($r as $rr)
  202. $parents_arr[] = $rr['item_id'];
  203. $parents_str = implode(', ', $parents_arr);
  204. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  205. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,
  206. `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
  207. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  208. FROM `item`, `contact`
  209. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  210. and `item`.`moderated` = 0
  211. AND `contact`.`id` = `item`.`contact-id`
  212. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  213. AND `item`.`parent` IN ( %s )
  214. $sql_extra ",
  215. intval($a->profile['profile_uid']),
  216. dbesc($parents_str)
  217. );
  218. $items = conv_sort($items,'created');
  219. } else {
  220. $items = array();
  221. }
  222. if($is_owner && ! $update) {
  223. $o .= get_birthdays();
  224. $o .= get_events();
  225. }
  226. if((! $update) && ($tab === 'posts')) {
  227. // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
  228. // because browser prefetching might change it on us. We have to deliver it with the page.
  229. $o .= '<div id="live-profile"></div>' . "\r\n";
  230. $o .= "<script> var profile_uid = " . $a->profile['profile_uid']
  231. . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  232. }
  233. if($is_owner) {
  234. $r = q("UPDATE `item` SET `unseen` = 0
  235. WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
  236. intval(local_user())
  237. );
  238. }
  239. $o .= conversation($a,$items,'profile',$update);
  240. if(! $update) {
  241. $o .= paginate($a);
  242. }
  243. return $o;
  244. }