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.
 
 
 
 
 
 

771 lines
24 KiB

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