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