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.

351 lines
12 KiB

11 years ago
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
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
9 years ago
9 years ago
11 years ago
11 years ago
11 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
11 years ago
  1. <?php
  2. require_once('include/contact_widgets.php');
  3. require_once('include/redir.php');
  4. function profile_init(&$a) {
  5. if(! x($a->page,'aside'))
  6. $a->page['aside'] = '';
  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 account_removed = 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. else {
  27. auto_redir($a, $which);
  28. }
  29. profile_load($a,$which,$profile);
  30. $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
  31. $userblock = (($a->profile['hidewall'] && (! local_user()) && (! remote_user())) ? true : false);
  32. if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) {
  33. $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
  34. }
  35. if(x($a->profile,'openidserver'))
  36. $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
  37. if(x($a->profile,'openid')) {
  38. $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
  39. $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
  40. }
  41. // site block
  42. if((! $blocked) && (! $userblock)) {
  43. $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
  44. $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
  45. if(strlen($keywords))
  46. $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
  47. }
  48. $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
  49. $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
  50. $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
  51. $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
  52. header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
  53. $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
  54. foreach($dfrn_pages as $dfrn)
  55. $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
  56. $a->page['htmlhead'] .= "<link rel=\"dfrn-poco\" href=\"".$a->get_baseurl()."/poco/{$which}\" />\r\n";
  57. }
  58. function profile_content(&$a, $update = 0) {
  59. $category = $datequery = $datequery2 = '';
  60. if($a->argc > 2) {
  61. for($x = 2; $x < $a->argc; $x ++) {
  62. if(is_a_date_arg($a->argv[$x])) {
  63. if($datequery)
  64. $datequery2 = escape_tags($a->argv[$x]);
  65. else
  66. $datequery = escape_tags($a->argv[$x]);
  67. }
  68. else
  69. $category = $a->argv[$x];
  70. }
  71. }
  72. if(! x($category)) {
  73. $category = ((x($_GET,'category')) ? $_GET['category'] : '');
  74. }
  75. if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
  76. return login();
  77. }
  78. require_once("include/bbcode.php");
  79. require_once('include/security.php');
  80. require_once('include/conversation.php');
  81. require_once('include/acl_selectors.php');
  82. require_once('include/items.php');
  83. $groups = array();
  84. $tab = 'posts';
  85. $o = '';
  86. if($update) {
  87. // Ensure we've got a profile owner if updating.
  88. $a->profile['profile_uid'] = $update;
  89. }
  90. else {
  91. if($a->profile['profile_uid'] == local_user()) {
  92. nav_set_selected('home');
  93. }
  94. }
  95. $contact = null;
  96. $remote_contact = false;
  97. $contact_id = 0;
  98. if(is_array($_SESSION['remote'])) {
  99. foreach($_SESSION['remote'] as $v) {
  100. if($v['uid'] == $a->profile['profile_uid']) {
  101. $contact_id = $v['cid'];
  102. break;
  103. }
  104. }
  105. }
  106. if($contact_id) {
  107. $groups = init_groups_visitor($contact_id);
  108. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  109. intval($contact_id),
  110. intval($a->profile['profile_uid'])
  111. );
  112. if(count($r)) {
  113. $contact = $r[0];
  114. $remote_contact = true;
  115. }
  116. }
  117. if(! $remote_contact) {
  118. if(local_user()) {
  119. $contact_id = $_SESSION['cid'];
  120. $contact = $a->contact;
  121. }
  122. }
  123. $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
  124. if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
  125. notice( t('Access to this profile has been restricted.') . EOL);
  126. return;
  127. }
  128. if(! $update) {
  129. if(x($_GET,'tab'))
  130. $tab = notags(trim($_GET['tab']));
  131. $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
  132. if($tab === 'profile') {
  133. require_once('include/profile_advanced.php');
  134. $o .= advanced_profile($a);
  135. call_hooks('profile_advanced',$o);
  136. return $o;
  137. }
  138. $o .= common_friends_visitor_widget($a->profile['profile_uid']);
  139. if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
  140. $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
  141. $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
  142. $commvisitor = (($commpage && $remote_contact == true) ? true : false);
  143. $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  144. $a->page['aside'] .= posted_date_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],$a->profile['profile_uid'],true);
  145. $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
  146. if(can_write_wall($a,$a->profile['profile_uid'])) {
  147. $x = array(
  148. 'is_owner' => $is_owner,
  149. 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
  150. 'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
  151. 'nickname' => $a->profile['nickname'],
  152. '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'),
  153. 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
  154. 'bang' => '',
  155. 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
  156. 'profile_uid' => $a->profile['profile_uid'],
  157. 'acl_data' => ( $is_owner ? construct_acl_data($a, $a->user) : '' ), // For non-Javascript ACL selector
  158. );
  159. $o .= status_editor($a,$x);
  160. }
  161. }
  162. /**
  163. * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
  164. */
  165. $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
  166. if($update) {
  167. $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`,
  168. `contact`.`uid` AS `contact-uid`
  169. FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  170. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  171. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
  172. (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "')
  173. and `item`.`moderated` = 0 and `item`.`unseen` = 1
  174. AND `item`.`wall` = 1
  175. $sql_extra
  176. ORDER BY `item`.`created` DESC",
  177. intval($a->profile['profile_uid'])
  178. );
  179. } else {
  180. $sql_post_table = "";
  181. if(x($category)) {
  182. $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
  183. dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
  184. //$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
  185. }
  186. if($datequery) {
  187. $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
  188. }
  189. if($datequery2) {
  190. $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
  191. }
  192. if(get_config('system', 'old_pager')) {
  193. $r = q("SELECT COUNT(*) AS `total`
  194. FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
  195. $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
  196. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  197. WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
  198. and `thread`.`moderated` = 0
  199. AND `thread`.`wall` = 1
  200. $sql_extra $sql_extra2 ",
  201. intval($a->profile['profile_uid'])
  202. );
  203. if(count($r)) {
  204. $a->set_pager_total($r[0]['total']);
  205. }
  206. }
  207. // check if we serve a mobile device and get the user settings
  208. // accordingly
  209. if ($a->is_mobile) {
  210. $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network');
  211. $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
  212. } else {
  213. $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
  214. $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
  215. }
  216. // now that we have the user settings, see if the theme forces
  217. // a maximum item number which is lower then the user choice
  218. if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
  219. $itemspage_network = $a->force_max_items;
  220. $a->set_pager_itemspage($itemspage_network);
  221. $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
  222. $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`,
  223. `thread`.`uid` AS `contact-uid`
  224. FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
  225. $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
  226. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  227. WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
  228. and `thread`.`moderated` = 0
  229. AND `thread`.`wall` = 1
  230. $sql_extra $sql_extra2
  231. ORDER BY `thread`.`created` DESC $pager_sql ",
  232. intval($a->profile['profile_uid'])
  233. );
  234. }
  235. $parents_arr = array();
  236. $parents_str = '';
  237. if(count($r)) {
  238. foreach($r as $rr)
  239. $parents_arr[] = $rr['item_id'];
  240. $parents_str = implode(', ', $parents_arr);
  241. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
  242. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,
  243. `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
  244. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  245. FROM `item`, `contact`
  246. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  247. and `item`.`moderated` = 0
  248. AND `contact`.`id` = `item`.`contact-id`
  249. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  250. AND `item`.`parent` IN ( %s )
  251. $sql_extra ",
  252. intval($a->profile['profile_uid']),
  253. dbesc($parents_str)
  254. );
  255. $items = conv_sort($items,'created');
  256. } else {
  257. $items = array();
  258. }
  259. if($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) {
  260. $o .= get_birthdays();
  261. $o .= get_events();
  262. }
  263. if($is_owner) {
  264. $r = q("UPDATE `item` SET `unseen` = 0
  265. WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
  266. intval(local_user())
  267. );
  268. }
  269. $o .= conversation($a,$items,'profile',$update);
  270. if(! $update) {
  271. if(!get_config('system', 'old_pager')) {
  272. $o .= alt_pager($a,count($items));
  273. } else {
  274. $o .= paginate($a);
  275. }
  276. }
  277. return $o;
  278. }