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.
 
 
 
 
 
 

332 lines
11 KiB

  1. <?php
  2. require_once('include/contact_widgets.php');
  3. function profile_init(&$a) {
  4. if(! x($a->page,'aside'))
  5. $a->page['aside'] = '';
  6. if($a->argc > 1)
  7. $which = $a->argv[1];
  8. else {
  9. $r = q("select nickname from user where blocked = 0 and account_expired = 0 and verified = 1 order by rand() limit 1");
  10. if(count($r)) {
  11. goaway($a->get_baseurl() . '/profile/' . $r[0]['nickname']);
  12. }
  13. else {
  14. logger('profile error: mod_profile ' . $a->query_string, LOGGER_DEBUG);
  15. notice( t('Requested profile is not available.') . EOL );
  16. $a->error = 404;
  17. return;
  18. }
  19. }
  20. $profile = 0;
  21. if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
  22. $which = $a->user['nickname'];
  23. $profile = $a->argv[1];
  24. }
  25. profile_load($a,$which,$profile);
  26. $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
  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. $contact_id = 0;
  94. if(is_array($_SESSION['remote'])) {
  95. foreach($_SESSION['remote'] as $v) {
  96. if($v['uid'] == $a->profile['profile_uid']) {
  97. $contact_id = $v['cid'];
  98. break;
  99. }
  100. }
  101. }
  102. if($contact_id) {
  103. $groups = init_groups_visitor($contact_id);
  104. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  105. intval($contact_id),
  106. intval($a->profile['profile_uid'])
  107. );
  108. if(count($r)) {
  109. $contact = $r[0];
  110. $remote_contact = true;
  111. }
  112. }
  113. if(! $remote_contact) {
  114. if(local_user()) {
  115. $contact_id = $_SESSION['cid'];
  116. $contact = $a->contact;
  117. }
  118. }
  119. $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
  120. if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
  121. notice( t('Access to this profile has been restricted.') . EOL);
  122. return;
  123. }
  124. if(! $update) {
  125. if(x($_GET,'tab'))
  126. $tab = notags(trim($_GET['tab']));
  127. $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
  128. if($tab === 'profile') {
  129. require_once('include/profile_advanced.php');
  130. $o .= advanced_profile($a);
  131. call_hooks('profile_advanced',$o);
  132. return $o;
  133. }
  134. $o .= common_friends_visitor_widget($a->profile['profile_uid']);
  135. if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
  136. $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
  137. $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
  138. $commvisitor = (($commpage && $remote_contact == true) ? true : false);
  139. $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  140. $a->page['aside'] .= posted_date_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],$a->profile['profile_uid'],true);
  141. $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
  142. if(can_write_wall($a,$a->profile['profile_uid'])) {
  143. $x = array(
  144. 'is_owner' => $is_owner,
  145. 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
  146. 'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
  147. 'nickname' => $a->profile['nickname'],
  148. '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'),
  149. 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
  150. 'bang' => '',
  151. 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
  152. 'profile_uid' => $a->profile['profile_uid']
  153. );
  154. $o .= status_editor($a,$x);
  155. }
  156. }
  157. /**
  158. * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
  159. */
  160. $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
  161. if($update) {
  162. $r = q("SELECT distinct(parent) AS `item_id`, `contact`.`uid` AS `contact-uid`
  163. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  164. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
  165. (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "')
  166. and `item`.`moderated` = 0 and `item`.`unseen` = 1
  167. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  168. AND `item`.`wall` = 1
  169. $sql_extra
  170. ORDER BY `item`.`created` DESC",
  171. intval($a->profile['profile_uid'])
  172. );
  173. }
  174. else {
  175. if(x($category)) {
  176. $sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
  177. }
  178. if($datequery) {
  179. $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
  180. }
  181. if($datequery2) {
  182. $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
  183. }
  184. if(! get_pconfig($a->profile['profile_uid'],'system','alt_pager')) {
  185. $r = q("SELECT COUNT(*) AS `total`
  186. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  187. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  188. and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  189. AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
  190. $sql_extra $sql_extra2 ",
  191. intval($a->profile['profile_uid'])
  192. );
  193. if(count($r)) {
  194. $a->set_pager_total($r[0]['total']);
  195. }
  196. }
  197. $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
  198. $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
  199. if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
  200. $itemspage_network = $a->force_max_items;
  201. $a->set_pager_itemspage($itemspage_network);
  202. $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
  203. $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
  204. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  205. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  206. and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  207. AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
  208. $sql_extra $sql_extra2
  209. ORDER BY `item`.`created` DESC $pager_sql ",
  210. intval($a->profile['profile_uid'])
  211. );
  212. }
  213. $parents_arr = array();
  214. $parents_str = '';
  215. if(count($r)) {
  216. foreach($r as $rr)
  217. $parents_arr[] = $rr['item_id'];
  218. $parents_str = implode(', ', $parents_arr);
  219. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  220. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,
  221. `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
  222. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  223. FROM `item`, `contact`
  224. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  225. and `item`.`moderated` = 0
  226. AND `contact`.`id` = `item`.`contact-id`
  227. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  228. AND `item`.`parent` IN ( %s )
  229. $sql_extra ",
  230. intval($a->profile['profile_uid']),
  231. dbesc($parents_str)
  232. );
  233. $items = conv_sort($items,'created');
  234. } else {
  235. $items = array();
  236. }
  237. if($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) {
  238. $o .= get_birthdays();
  239. $o .= get_events();
  240. }
  241. if($is_owner) {
  242. $r = q("UPDATE `item` SET `unseen` = 0
  243. WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
  244. intval(local_user())
  245. );
  246. }
  247. $o .= conversation($a,$items,'profile',$update);
  248. if(! $update) {
  249. if(! get_pconfig($a->profile['profile_uid'],'system','alt_pager')) {
  250. $o .= paginate($a);
  251. }
  252. else {
  253. $o .= alt_pager($a,count($items));
  254. }
  255. }
  256. return $o;
  257. }