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.
 
 
 
 
 
 

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