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