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.

868 lines
26 KiB

  1. <?php
  2. /**
  3. * @file include/identity.php
  4. */
  5. require_once('include/ForumManager.php');
  6. require_once('include/bbcode.php');
  7. require_once("mod/proxy.php");
  8. /**
  9. *
  10. * @brief Loads a profile into the page sidebar.
  11. *
  12. * The function requires a writeable copy of the main App structure, and the nickname
  13. * of a registered local account.
  14. *
  15. * If the viewer is an authenticated remote viewer, the profile displayed is the
  16. * one that has been configured for his/her viewing in the Contact manager.
  17. * Passing a non-zero profile ID can also allow a preview of a selected profile
  18. * by the owner.
  19. *
  20. * Profile information is placed in the App structure for later retrieval.
  21. * Honours the owner's chosen theme for display.
  22. *
  23. * @attention Should only be run in the _init() functions of a module. That ensures that
  24. * the theme is chosen before the _init() function of a theme is run, which will usually
  25. * load a lot of theme-specific content
  26. *
  27. * @param App $a
  28. * @param string $nickname
  29. * @param int $profile
  30. * @param array $profiledata
  31. */
  32. function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
  33. $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
  34. dbesc($nickname)
  35. );
  36. if(!$user && count($user) && !count($profiledata)) {
  37. logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
  38. notice( t('Requested account is not available.') . EOL );
  39. $a->error = 404;
  40. return;
  41. }
  42. $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
  43. if(($pdata === false) || (!count($pdata)) && !count($profiledata)) {
  44. logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
  45. notice( t('Requested profile is not available.') . EOL );
  46. $a->error = 404;
  47. return;
  48. }
  49. // fetch user tags if this isn't the default profile
  50. if(!$pdata['is-default']) {
  51. $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
  52. intval($pdata['profile_uid'])
  53. );
  54. if($x && count($x))
  55. $pdata['pub_keywords'] = $x[0]['pub_keywords'];
  56. }
  57. $a->profile = $pdata;
  58. $a->profile_uid = $pdata['profile_uid'];
  59. $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
  60. $a->profile['network'] = NETWORK_DFRN;
  61. $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
  62. if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
  63. $_SESSION['theme'] = $a->profile['theme'];
  64. $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
  65. /*
  66. * load/reload current theme info
  67. */
  68. $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
  69. $theme_info_file = "view/theme/".current_theme()."/theme.php";
  70. if (file_exists($theme_info_file)){
  71. require_once($theme_info_file);
  72. }
  73. if(! (x($a->page,'aside')))
  74. $a->page['aside'] = '';
  75. if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
  76. $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
  77. '$editprofile' => t('Edit profile'),
  78. '$profid' => $a->profile['id']
  79. ));
  80. }
  81. $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
  82. /**
  83. * @todo
  84. * By now, the contact block isn't shown, when a different profile is given
  85. * But: When this profile was on the same server, then we could display the contacts
  86. */
  87. if ($profiledata)
  88. $a->page['aside'] .= profile_sidebar($profiledata, true);
  89. else
  90. $a->page['aside'] .= profile_sidebar($a->profile, $block);
  91. /*if(! $block)
  92. $a->page['aside'] .= contact_block();*/
  93. return;
  94. }
  95. /**
  96. * @brief Get all profil data of a local user
  97. *
  98. * If the viewer is an authenticated remote viewer, the profile displayed is the
  99. * one that has been configured for his/her viewing in the Contact manager.
  100. * Passing a non-zero profile ID can also allow a preview of a selected profile
  101. * by the owner
  102. *
  103. * @param string $nickname
  104. * @param int $uid
  105. * @param int $profile
  106. * ID of the profile
  107. * @returns array
  108. * Includes all available profile data
  109. */
  110. function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
  111. if(remote_user() && count($_SESSION['remote'])) {
  112. foreach($_SESSION['remote'] as $visitor) {
  113. if($visitor['uid'] == $uid) {
  114. $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
  115. intval($visitor['cid'])
  116. );
  117. if (dbm::is_result($r))
  118. $profile = $r[0]['profile-id'];
  119. break;
  120. }
  121. }
  122. }
  123. $r = null;
  124. if($profile) {
  125. $profile_int = intval($profile);
  126. $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
  127. `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
  128. FROM `profile`
  129. INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
  130. INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
  131. WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d LIMIT 1",
  132. dbesc($nickname),
  133. intval($profile_int)
  134. );
  135. }
  136. if (!dbm::is_result($r)) {
  137. $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
  138. `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
  139. FROM `profile`
  140. INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
  141. INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
  142. WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` LIMIT 1",
  143. dbesc($nickname)
  144. );
  145. }
  146. return $r[0];
  147. }
  148. /**
  149. * @brief Formats a profile for display in the sidebar.
  150. *
  151. * It is very difficult to templatise the HTML completely
  152. * because of all the conditional logic.
  153. *
  154. * @param array $profile
  155. * @param int $block
  156. *
  157. * @return HTML string stuitable for sidebar inclusion
  158. *
  159. * @note Returns empty string if passed $profile is wrong type or not populated
  160. *
  161. * @hooks 'profile_sidebar_enter'
  162. * array $profile - profile data
  163. * @hooks 'profile_sidebar'
  164. * array $arr
  165. */
  166. function profile_sidebar($profile, $block = 0) {
  167. $a = get_app();
  168. $o = '';
  169. $location = false;
  170. $address = false;
  171. // $pdesc = true;
  172. if((! is_array($profile)) && (! count($profile)))
  173. return $o;
  174. $profile['picdate'] = urlencode($profile['picdate']);
  175. if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
  176. $profile['network_name'] = format_network_name($profile['network'],$profile['url']);
  177. } else
  178. $profile['network_name'] = "";
  179. call_hooks('profile_sidebar_enter', $profile);
  180. // don't show connect link to yourself
  181. $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
  182. // don't show connect link to authenticated visitors either
  183. if(remote_user() && count($_SESSION['remote'])) {
  184. foreach($_SESSION['remote'] as $visitor) {
  185. if($visitor['uid'] == $profile['uid']) {
  186. $connect = false;
  187. break;
  188. }
  189. }
  190. }
  191. // Is the local user already connected to that user?
  192. if ($connect AND local_user()) {
  193. if (isset($profile["url"])) {
  194. $profile_url = normalise_link($profile["url"]);
  195. }
  196. else {
  197. $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]);
  198. }
  199. $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
  200. local_user(), $profile_url);
  201. if (dbm::is_result($r))
  202. $connect = false;
  203. }
  204. if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
  205. $connect = false;
  206. $remoteconnect = NULL;
  207. if (isset($profile['remoteconnect']))
  208. $remoteconnect = $profile['remoteconnect'];
  209. if ($connect AND ($profile['network'] == NETWORK_DFRN) AND !isset($remoteconnect))
  210. $subscribe_feed = t("Atom feed");
  211. else
  212. $subscribe_feed = false;
  213. if (remote_user() OR (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
  214. $wallmessage = t('Message');
  215. $wallmessage_link = "wallmessage/".$profile["nickname"];
  216. if (remote_user()) {
  217. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
  218. intval($profile['uid']),
  219. intval(remote_user()),
  220. intval(CONTACT_IS_FRIEND));
  221. } else {
  222. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
  223. intval($profile['uid']),
  224. dbesc(normalise_link(get_my_url())),
  225. intval(CONTACT_IS_FRIEND));
  226. }
  227. if ($r) {
  228. $remote_url = $r[0]["url"];
  229. $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
  230. $wallmessage_link = $message_path.base64_encode($profile["addr"]);
  231. }
  232. } else {
  233. $wallmessage = false;
  234. $wallmessage_link = false;
  235. }
  236. // show edit profile to yourself
  237. if ($profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
  238. $profile['edit'] = array(App::get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
  239. $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
  240. local_user());
  241. $profile['menu'] = array(
  242. 'chg_photo' => t('Change profile photo'),
  243. 'cr_new' => t('Create New Profile'),
  244. 'entries' => array(),
  245. );
  246. if (dbm::is_result($r)) {
  247. foreach ($r as $rr) {
  248. $profile['menu']['entries'][] = array(
  249. 'photo' => $rr['thumb'],
  250. 'id' => $rr['id'],
  251. 'alt' => t('Profile Image'),
  252. 'profile_name' => $rr['profile-name'],
  253. 'isdefault' => $rr['is-default'],
  254. 'visibile_to_everybody' => t('visible to everybody'),
  255. 'edit_visibility' => t('Edit visibility'),
  256. );
  257. }
  258. }
  259. }
  260. if ($profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
  261. $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
  262. $profile['menu'] = array(
  263. 'chg_photo' => t('Change profile photo'),
  264. 'cr_new' => null,
  265. 'entries' => array(),
  266. );
  267. }
  268. // Fetch the account type
  269. $account_type = account_type($profile);
  270. if((x($profile,'address') == 1)
  271. || (x($profile,'location') == 1)
  272. || (x($profile,'locality') == 1)
  273. || (x($profile,'region') == 1)
  274. || (x($profile,'postal-code') == 1)
  275. || (x($profile,'country-name') == 1))
  276. $location = t('Location:');
  277. $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
  278. $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
  279. $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
  280. $about = ((x($profile,'about') == 1) ? t('About:') : False);
  281. $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
  282. if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
  283. $location = $pdesc = $gender = $marital = $homepage = $about = False;
  284. }
  285. $firstname = ((strpos($profile['name'],' '))
  286. ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
  287. $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
  288. if ($profile['guid'] != "")
  289. $diaspora = array(
  290. 'guid' => $profile['guid'],
  291. 'podloc' => App::get_baseurl(),
  292. 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
  293. 'nickname' => $profile['nickname'],
  294. 'fullname' => $profile['name'],
  295. 'firstname' => $firstname,
  296. 'lastname' => $lastname,
  297. 'photo300' => App::get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
  298. 'photo100' => App::get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
  299. 'photo50' => App::get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
  300. );
  301. else
  302. $diaspora = false;
  303. if (!$block){
  304. $contact_block = contact_block();
  305. if(is_array($a->profile) AND !$a->profile['hide-friends']) {
  306. $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
  307. intval($a->profile['uid']));
  308. if (dbm::is_result($r))
  309. $updated = date("c", strtotime($r[0]['updated']));
  310. $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `hidden` AND NOT `archive`
  311. AND `network` IN ('%s', '%s', '%s', '')",
  312. intval($profile['uid']),
  313. dbesc(NETWORK_DFRN),
  314. dbesc(NETWORK_DIASPORA),
  315. dbesc(NETWORK_OSTATUS)
  316. );
  317. if (dbm::is_result($r))
  318. $contacts = intval($r[0]['total']);
  319. }
  320. }
  321. $p = array();
  322. foreach($profile as $k => $v) {
  323. $k = str_replace('-','_',$k);
  324. $p[$k] = $v;
  325. }
  326. if (isset($p["about"]))
  327. $p["about"] = bbcode($p["about"]);
  328. if (isset($p["address"]))
  329. $p["address"] = bbcode($p["address"]);
  330. else
  331. $p["address"] = bbcode($p["location"]);
  332. if (isset($p["photo"]))
  333. $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
  334. if($a->theme['template_engine'] === 'internal')
  335. $location = template_escape($location);
  336. $tpl = get_markup_template('profile_vcard.tpl');
  337. $o .= replace_macros($tpl, array(
  338. '$profile' => $p,
  339. '$xmpp' => $xmpp,
  340. '$connect' => $connect,
  341. '$remoteconnect' => $remoteconnect,
  342. '$subscribe_feed' => $subscribe_feed,
  343. '$wallmessage' => $wallmessage,
  344. '$wallmessage_link' => $wallmessage_link,
  345. '$account_type' => $account_type,
  346. '$location' => $location,
  347. '$gender' => $gender,
  348. // '$pdesc' => $pdesc,
  349. '$marital' => $marital,
  350. '$homepage' => $homepage,
  351. '$about' => $about,
  352. '$network' => t('Network:'),
  353. '$contacts' => $contacts,
  354. '$updated' => $updated,
  355. '$diaspora' => $diaspora,
  356. '$contact_block' => $contact_block,
  357. ));
  358. $arr = array('profile' => &$profile, 'entry' => &$o);
  359. call_hooks('profile_sidebar', $arr);
  360. return $o;
  361. }
  362. function get_birthdays() {
  363. $a = get_app();
  364. $o = '';
  365. if(! local_user() || $a->is_mobile || $a->is_tablet)
  366. return $o;
  367. // $mobile_detect = new Mobile_Detect();
  368. // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
  369. // if($is_mobile)
  370. // return $o;
  371. $bd_format = t('g A l F d') ; // 8 AM Friday January 18
  372. $bd_short = t('F d');
  373. $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
  374. INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
  375. WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
  376. ORDER BY `start` ASC ",
  377. intval(local_user()),
  378. dbesc(datetime_convert('UTC','UTC','now + 6 days')),
  379. dbesc(datetime_convert('UTC','UTC','now'))
  380. );
  381. if (dbm::is_result($r)) {
  382. $total = 0;
  383. $now = strtotime('now');
  384. $cids = array();
  385. $istoday = false;
  386. foreach ($r as $rr) {
  387. if(strlen($rr['name']))
  388. $total ++;
  389. if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
  390. $istoday = true;
  391. }
  392. $classtoday = $istoday ? ' birthday-today ' : '';
  393. if($total) {
  394. foreach($r as &$rr) {
  395. if(! strlen($rr['name']))
  396. continue;
  397. // avoid duplicates
  398. if(in_array($rr['cid'],$cids))
  399. continue;
  400. $cids[] = $rr['cid'];
  401. $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
  402. $sparkle = '';
  403. $url = $rr['url'];
  404. if($rr['network'] === NETWORK_DFRN) {
  405. $sparkle = " sparkle";
  406. $url = App::get_baseurl() . '/redir/' . $rr['cid'];
  407. }
  408. $rr['link'] = $url;
  409. $rr['title'] = $rr['name'];
  410. $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
  411. $rr['startime'] = Null;
  412. $rr['today'] = $today;
  413. }
  414. }
  415. }
  416. $tpl = get_markup_template("birthdays_reminder.tpl");
  417. return replace_macros($tpl, array(
  418. '$baseurl' => App::get_baseurl(),
  419. '$classtoday' => $classtoday,
  420. '$count' => $total,
  421. '$event_reminders' => t('Birthday Reminders'),
  422. '$event_title' => t('Birthdays this week:'),
  423. '$events' => $r,
  424. '$lbr' => '{', // raw brackets mess up if/endif macro processing
  425. '$rbr' => '}'
  426. ));
  427. }
  428. function get_events() {
  429. require_once('include/bbcode.php');
  430. $a = get_app();
  431. if(! local_user() || $a->is_mobile || $a->is_tablet)
  432. return $o;
  433. // $mobile_detect = new Mobile_Detect();
  434. // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
  435. // if($is_mobile)
  436. // return $o;
  437. $bd_format = t('g A l F d') ; // 8 AM Friday January 18
  438. $bd_short = t('F d');
  439. $r = q("SELECT `event`.* FROM `event`
  440. WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
  441. ORDER BY `start` ASC ",
  442. intval(local_user()),
  443. dbesc(datetime_convert('UTC','UTC','now + 7 days')),
  444. dbesc(datetime_convert('UTC','UTC','now - 1 days'))
  445. );
  446. if (dbm::is_result($r)) {
  447. $now = strtotime('now');
  448. $istoday = false;
  449. foreach ($r as $rr) {
  450. if(strlen($rr['name']))
  451. $total ++;
  452. $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
  453. if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
  454. $istoday = true;
  455. }
  456. $classtoday = (($istoday) ? 'event-today' : '');
  457. $skip = 0;
  458. foreach($r as &$rr) {
  459. $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
  460. if(strlen($title) > 35)
  461. $title = substr($title,0,32) . '... ';
  462. $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
  463. if(! $description)
  464. $description = t('[No description]');
  465. $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
  466. if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
  467. $skip++;
  468. continue;
  469. }
  470. $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
  471. $rr['title'] = $title;
  472. $rr['description'] = $desciption;
  473. $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
  474. $rr['startime'] = $strt;
  475. $rr['today'] = $today;
  476. }
  477. }
  478. $tpl = get_markup_template("events_reminder.tpl");
  479. return replace_macros($tpl, array(
  480. '$baseurl' => App::get_baseurl(),
  481. '$classtoday' => $classtoday,
  482. '$count' => count($r) - $skip,
  483. '$event_reminders' => t('Event Reminders'),
  484. '$event_title' => t('Events this week:'),
  485. '$events' => $r,
  486. ));
  487. }
  488. function advanced_profile(App &$a) {
  489. $o = '';
  490. $uid = $a->profile['uid'];
  491. $o .= replace_macros(get_markup_template('section_title.tpl'),array(
  492. '$title' => t('Profile')
  493. ));
  494. if($a->profile['name']) {
  495. $tpl = get_markup_template('profile_advanced.tpl');
  496. $profile = array();
  497. $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
  498. if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
  499. if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
  500. $year_bd_format = t('j F, Y');
  501. $short_bd_format = t('j F');
  502. $val = ((intval($a->profile['dob']))
  503. ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
  504. : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
  505. $profile['birthday'] = array( t('Birthday:'), $val);
  506. }
  507. if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age );
  508. if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
  509. if($a->profile['with']) $profile['marital']['with'] = $a->profile['with'];
  510. if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
  511. $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
  512. }
  513. if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
  514. if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
  515. if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
  516. if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
  517. if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
  518. if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
  519. if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt );
  520. if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
  521. if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
  522. if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
  523. if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
  524. if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
  525. if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
  526. if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt);
  527. if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
  528. if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
  529. if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
  530. if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
  531. //show subcribed forum if it is enabled in the usersettings
  532. if (feature_enabled($uid,'forumlist_profile')) {
  533. $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
  534. }
  535. if ($a->profile['uid'] == local_user()) {
  536. $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
  537. }
  538. return replace_macros($tpl, array(
  539. '$title' => t('Profile'),
  540. '$basic' => t('Basic'),
  541. '$advanced' => t('Advanced'),
  542. '$profile' => $profile
  543. ));
  544. }
  545. return '';
  546. }
  547. function profile_tabs($a, $is_owner=False, $nickname=Null){
  548. //echo "<pre>"; var_dump($a->user); killme();
  549. if (is_null($nickname))
  550. $nickname = $a->user['nickname'];
  551. if(x($_GET,'tab'))
  552. $tab = notags(trim($_GET['tab']));
  553. $url = App::get_baseurl() . '/profile/' . $nickname;
  554. $tabs = array(
  555. array(
  556. 'label'=>t('Status'),
  557. 'url' => $url,
  558. 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
  559. 'title' => t('Status Messages and Posts'),
  560. 'id' => 'status-tab',
  561. 'accesskey' => 'm',
  562. ),
  563. array(
  564. 'label' => t('Profile'),
  565. 'url' => $url.'/?tab=profile',
  566. 'sel' => ((isset($tab) && $tab=='profile')?'active':''),
  567. 'title' => t('Profile Details'),
  568. 'id' => 'profile-tab',
  569. 'accesskey' => 'r',
  570. ),
  571. array(
  572. 'label' => t('Photos'),
  573. 'url' => App::get_baseurl() . '/photos/' . $nickname,
  574. 'sel' => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
  575. 'title' => t('Photo Albums'),
  576. 'id' => 'photo-tab',
  577. 'accesskey' => 'h',
  578. ),
  579. array(
  580. 'label' => t('Videos'),
  581. 'url' => App::get_baseurl() . '/videos/' . $nickname,
  582. 'sel' => ((!isset($tab)&&$a->argv[0]=='videos')?'active':''),
  583. 'title' => t('Videos'),
  584. 'id' => 'video-tab',
  585. 'accesskey' => 'v',
  586. ),
  587. );
  588. // the calendar link for the full featured events calendar
  589. if ($is_owner && $a->theme_events_in_profile) {
  590. $tabs[] = array(
  591. 'label' => t('Events'),
  592. 'url' => App::get_baseurl() . '/events',
  593. 'sel' =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
  594. 'title' => t('Events and Calendar'),
  595. 'id' => 'events-tab',
  596. 'accesskey' => 'e',
  597. );
  598. // if the user is not the owner of the calendar we only show a calendar
  599. // with the public events of the calendar owner
  600. } elseif (! $is_owner) {
  601. $tabs[] = array(
  602. 'label' => t('Events'),
  603. 'url' => App::get_baseurl() . '/cal/' . $nickname,
  604. 'sel' =>((!isset($tab)&&$a->argv[0]=='cal')?'active':''),
  605. 'title' => t('Events and Calendar'),
  606. 'id' => 'events-tab',
  607. 'accesskey' => 'e',
  608. );
  609. }
  610. if ($is_owner){
  611. $tabs[] = array(
  612. 'label' => t('Personal Notes'),
  613. 'url' => App::get_baseurl() . '/notes',
  614. 'sel' =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
  615. 'title' => t('Only You Can See This'),
  616. 'id' => 'notes-tab',
  617. 'accesskey' => 't',
  618. );
  619. }
  620. if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
  621. $tabs[] = array(
  622. 'label' => t('Contacts'),
  623. 'url' => App::get_baseurl() . '/viewcontacts/' . $nickname,
  624. 'sel' => ((!isset($tab)&&$a->argv[0]=='viewcontacts')?'active':''),
  625. 'title' => t('Contacts'),
  626. 'id' => 'viewcontacts-tab',
  627. 'accesskey' => 'k',
  628. );
  629. }
  630. $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
  631. call_hooks('profile_tabs', $arr);
  632. $tpl = get_markup_template('common_tabs.tpl');
  633. return replace_macros($tpl,array('$tabs' => $arr['tabs']));
  634. }
  635. function get_my_url() {
  636. if(x($_SESSION,'my_url'))
  637. return $_SESSION['my_url'];
  638. return false;
  639. }
  640. function zrl_init(App &$a) {
  641. $tmp_str = get_my_url();
  642. if(validate_url($tmp_str)) {
  643. // Is it a DDoS attempt?
  644. // The check fetches the cached value from gprobe to reduce the load for this system
  645. $urlparts = parse_url($tmp_str);
  646. $result = Cache::get("gprobe:".$urlparts["host"]);
  647. if (!is_null($result)) {
  648. if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
  649. logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
  650. return;
  651. }
  652. }
  653. proc_run(PRIORITY_LOW, 'include/gprobe.php',bin2hex($tmp_str));
  654. $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
  655. call_hooks('zrl_init',$arr);
  656. }
  657. }
  658. function zrl($s,$force = false) {
  659. if(! strlen($s))
  660. return $s;
  661. if((! strpos($s,'/profile/')) && (! $force))
  662. return $s;
  663. if($force && substr($s,-1,1) !== '/')
  664. $s = $s . '/';
  665. $achar = strpos($s,'?') ? '&' : '?';
  666. $mine = get_my_url();
  667. if($mine and ! link_compare($mine,$s))
  668. return $s . $achar . 'zrl=' . urlencode($mine);
  669. return $s;
  670. }
  671. /**
  672. * @brief Get the user ID of the page owner
  673. *
  674. * Used from within PCSS themes to set theme parameters. If there's a
  675. * puid request variable, that is the "page owner" and normally their theme
  676. * settings take precedence; unless a local user sets the "always_my_theme"
  677. * system pconfig, which means they don't want to see anybody else's theme
  678. * settings except their own while on this site.
  679. *
  680. * @return int user ID
  681. *
  682. * @note Returns local_user instead of user ID if "always_my_theme"
  683. * is set to true
  684. */
  685. function get_theme_uid() {
  686. $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
  687. if(local_user()) {
  688. if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))
  689. return local_user();
  690. }
  691. return $uid;
  692. }