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.

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