]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
Rewrite Proxy module
[friendica.git] / mod / profiles.php
1 <?php
2 /**
3  * @file mod/profiles.php
4  */
5
6 use Friendica\App;
7 use Friendica\BaseModule;
8 use Friendica\Content\ContactSelector;
9 use Friendica\Content\Feature;
10 use Friendica\Content\Nav;
11 use Friendica\Core\Addon;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Core\PConfig;
15 use Friendica\Core\Renderer;
16 use Friendica\Core\System;
17 use Friendica\Core\Worker;
18 use Friendica\Database\DBA;
19 use Friendica\Model\Contact;
20 use Friendica\Model\GContact;
21 use Friendica\Model\Profile;
22 use Friendica\Module\Login;
23 use Friendica\Network\Probe;
24 use Friendica\Util\DateTimeFormat;
25 use Friendica\Util\Strings;
26 use Friendica\Util\Temporal;
27
28 function profiles_init(App $a) {
29
30         Nav::setSelected('profiles');
31
32         if (! local_user()) {
33                 return;
34         }
35
36         if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
37                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
38                         intval($a->argv[2]),
39                         intval(local_user())
40                 );
41                 if (! DBA::isResult($r)) {
42                         notice(L10n::t('Profile not found.') . EOL);
43                         $a->internalRedirect('profiles');
44                         return; // NOTREACHED
45                 }
46
47                 BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_drop', 't');
48
49                 // move every contact using this profile as their default to the user default
50
51                 $r = q("UPDATE `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
52                         intval(local_user()),
53                         intval($a->argv[2]),
54                         intval(local_user())
55                 );
56                 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d",
57                         intval($a->argv[2]),
58                         intval(local_user())
59                 );
60                 if (DBA::isResult($r)) {
61                         info(L10n::t('Profile deleted.').EOL);
62                 }
63
64                 $a->internalRedirect('profiles');
65                 return; // NOTREACHED
66         }
67
68         if (($a->argc > 1) && ($a->argv[1] === 'new')) {
69
70                 BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_new', 't');
71
72                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
73                         intval(local_user()));
74
75                 $num_profiles = (DBA::isResult($r0) ? count($r0) : 0);
76
77                 $name = L10n::t('Profile-') . ($num_profiles + 1);
78
79                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
80                         intval(local_user()));
81
82                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
83                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
84                         intval(local_user()),
85                         DBA::escape($name),
86                         DBA::escape($r1[0]['name']),
87                         DBA::escape($r1[0]['photo']),
88                         DBA::escape($r1[0]['thumb'])
89                 );
90
91                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
92                         intval(local_user()),
93                         DBA::escape($name)
94                 );
95
96                 info(L10n::t('New profile created.') . EOL);
97                 if (DBA::isResult($r3) && count($r3) == 1) {
98                         $a->internalRedirect('profiles/' . $r3[0]['id']);
99                 }
100
101                 $a->internalRedirect('profiles');
102         }
103
104         if (($a->argc > 2) && ($a->argv[1] === 'clone')) {
105
106                 BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_clone', 't');
107
108                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
109                         intval(local_user()));
110
111                 $num_profiles = (DBA::isResult($r0) ? count($r0) : 0);
112
113                 $name = L10n::t('Profile-') . ($num_profiles + 1);
114                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
115                         intval(local_user()),
116                         intval($a->argv[2])
117                 );
118                 if(! DBA::isResult($r1)) {
119                         notice(L10n::t('Profile unavailable to clone.') . EOL);
120                         killme();
121                         return;
122                 }
123                 unset($r1[0]['id']);
124                 $r1[0]['is-default'] = 0;
125                 $r1[0]['publish'] = 0;
126                 $r1[0]['net-publish'] = 0;
127                 $r1[0]['profile-name'] = DBA::escape($name);
128
129                 DBA::insert('profile', $r1[0]);
130
131                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
132                         intval(local_user()),
133                         DBA::escape($name)
134                 );
135                 info(L10n::t('New profile created.') . EOL);
136                 if ((DBA::isResult($r3)) && (count($r3) == 1)) {
137                         $a->internalRedirect('profiles/'.$r3[0]['id']);
138                 }
139
140                 $a->internalRedirect('profiles');
141
142                 return; // NOTREACHED
143         }
144
145
146         if (($a->argc > 1) && (intval($a->argv[1]))) {
147                 $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
148                         intval($a->argv[1]),
149                         intval(local_user())
150                 );
151                 if (! DBA::isResult($r)) {
152                         notice(L10n::t('Profile not found.') . EOL);
153                         killme();
154                         return;
155                 }
156
157                 Profile::load($a, $a->user['nickname'], $r[0]['id']);
158         }
159 }
160
161 function profile_clean_keywords($keywords)
162 {
163         $keywords = str_replace(",", " ", $keywords);
164         $keywords = explode(" ", $keywords);
165
166         $cleaned = [];
167         foreach ($keywords as $keyword) {
168                 $keyword = trim(strtolower($keyword));
169                 $keyword = trim($keyword, "#");
170                 if ($keyword != "") {
171                         $cleaned[] = $keyword;
172                 }
173         }
174
175         $keywords = implode(", ", $cleaned);
176
177         return $keywords;
178 }
179
180 function profiles_post(App $a) {
181
182         if (! local_user()) {
183                 notice(L10n::t('Permission denied.') . EOL);
184                 return;
185         }
186
187         $namechanged = false;
188
189         Addon::callHooks('profile_post', $_POST);
190
191         if (($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
192                 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
193                         intval($a->argv[1]),
194                         intval(local_user())
195                 );
196                 if (! DBA::isResult($orig)) {
197                         notice(L10n::t('Profile not found.') . EOL);
198                         return;
199                 }
200
201                 BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_edit');
202
203                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
204
205                 $profile_name = Strings::escapeTags(trim($_POST['profile_name']));
206                 if (! strlen($profile_name)) {
207                         notice(L10n::t('Profile Name is required.') . EOL);
208                         return;
209                 }
210
211                 $dob = $_POST['dob'] ? Strings::escapeHtml(trim($_POST['dob'])) : '0000-00-00';
212
213                 $y = substr($dob, 0, 4);
214                 if ((! ctype_digit($y)) || ($y < 1900)) {
215                         $ignore_year = true;
216                 } else {
217                         $ignore_year = false;
218                 }
219                 if (!in_array($dob, ['0000-00-00', DBA::NULL_DATE])) {
220                         if (strpos($dob, '0000-') === 0 || strpos($dob, '0001-') === 0) {
221                                 $ignore_year = true;
222                                 $dob = substr($dob, 5);
223                         }
224
225                         if ($ignore_year) {
226                                 $dob = '0000-' . DateTimeFormat::utc('1900-' . $dob, 'm-d');
227                         } else {
228                                 $dob = DateTimeFormat::utc($dob, 'Y-m-d');
229                         }
230                 }
231
232                 $name = Strings::escapeTags(trim($_POST['name']));
233
234                 if (! strlen($name)) {
235                         $name = '[No Name]';
236                 }
237
238                 if ($orig[0]['name'] != $name) {
239                         $namechanged = true;
240                 }
241
242                 $pdesc = Strings::escapeTags(trim($_POST['pdesc']));
243                 $gender = Strings::escapeTags(trim($_POST['gender']));
244                 $address = Strings::escapeTags(trim($_POST['address']));
245                 $locality = Strings::escapeTags(trim($_POST['locality']));
246                 $region = Strings::escapeTags(trim($_POST['region']));
247                 $postal_code = Strings::escapeTags(trim($_POST['postal_code']));
248                 $country_name = Strings::escapeTags(trim($_POST['country_name']));
249                 $pub_keywords = profile_clean_keywords(Strings::escapeTags(trim($_POST['pub_keywords'])));
250                 $prv_keywords = profile_clean_keywords(Strings::escapeTags(trim($_POST['prv_keywords'])));
251                 $marital = Strings::escapeTags(trim($_POST['marital']));
252                 $howlong = Strings::escapeTags(trim($_POST['howlong']));
253
254                 $with = (!empty($_POST['with']) ? Strings::escapeTags(trim($_POST['with'])) : '');
255
256                 if (! strlen($howlong)) {
257                         $howlong = DBA::NULL_DATETIME;
258                 } else {
259                         $howlong = DateTimeFormat::convert($howlong, 'UTC', date_default_timezone_get());
260                 }
261                 // linkify the relationship target if applicable
262
263                 $withchanged = false;
264
265                 if (strlen($with)) {
266                         if ($with != strip_tags($orig[0]['with'])) {
267                                 $withchanged = true;
268                                 $prf = '';
269                                 $lookup = $with;
270                                 if (strpos($lookup, '@') === 0) {
271                                         $lookup = substr($lookup, 1);
272                                 }
273                                 $lookup = str_replace('_',' ', $lookup);
274                                 if (strpos($lookup, '@') || (strpos($lookup, 'http://'))) {
275                                         $newname = $lookup;
276                                         $links = @Probe::lrdd($lookup);
277                                         if (count($links)) {
278                                                 foreach ($links as $link) {
279                                                         if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
280                                                                 $prf = $link['@attributes']['href'];
281                                                         }
282                                                 }
283                                         }
284                                 } else {
285                                         $newname = $lookup;
286
287                                         $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
288                                                 DBA::escape($newname),
289                                                 intval(local_user())
290                                         );
291                                         if (! DBA::isResult($r)) {
292                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
293                                                         DBA::escape($lookup),
294                                                         intval(local_user())
295                                                 );
296                                         }
297                                         if (DBA::isResult($r)) {
298                                                 $prf = $r[0]['url'];
299                                                 $newname = $r[0]['name'];
300                                         }
301                                 }
302
303                                 if ($prf) {
304                                         $with = str_replace($lookup, '<a href="' . $prf . '">' . $newname . '</a>', $with);
305                                         if (strpos($with, '@') === 0) {
306                                                 $with = substr($with, 1);
307                                         }
308                                 }
309                         } else {
310                                 $with = $orig[0]['with'];
311                         }
312                 }
313
314                 /// @TODO Not flexible enough for later expansion, let's have more OOP here
315                 $sexual = Strings::escapeTags(trim($_POST['sexual']));
316                 $xmpp = Strings::escapeTags(trim($_POST['xmpp']));
317                 $homepage = Strings::escapeTags(trim($_POST['homepage']));
318                 if ((strpos($homepage, 'http') !== 0) && (strlen($homepage))) {
319                         // neither http nor https in URL, add them
320                         $homepage = 'http://'.$homepage;
321                 }
322                 $hometown = Strings::escapeTags(trim($_POST['hometown']));
323                 $politic = Strings::escapeTags(trim($_POST['politic']));
324                 $religion = Strings::escapeTags(trim($_POST['religion']));
325
326                 $likes = Strings::escapeHtml(trim($_POST['likes']));
327                 $dislikes = Strings::escapeHtml(trim($_POST['dislikes']));
328
329                 $about = Strings::escapeHtml(trim($_POST['about']));
330                 $interest = Strings::escapeHtml(trim($_POST['interest']));
331                 $contact = Strings::escapeHtml(trim($_POST['contact']));
332                 $music = Strings::escapeHtml(trim($_POST['music']));
333                 $book = Strings::escapeHtml(trim($_POST['book']));
334                 $tv = Strings::escapeHtml(trim($_POST['tv']));
335                 $film = Strings::escapeHtml(trim($_POST['film']));
336                 $romance = Strings::escapeHtml(trim($_POST['romance']));
337                 $work = Strings::escapeHtml(trim($_POST['work']));
338                 $education = Strings::escapeHtml(trim($_POST['education']));
339
340                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
341
342                 PConfig::set(local_user(), 'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0));
343
344                 $changes = [];
345                 $value = '';
346                 if ($is_default) {
347                         if ($marital != $orig[0]['marital']) {
348                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . L10n::t('Marital Status');
349                                 $value = $marital;
350                         }
351                         if ($withchanged) {
352                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . L10n::t('Romantic Partner');
353                                 $value = strip_tags($with);
354                         }
355                         if ($likes != $orig[0]['likes']) {
356                                 $changes[] = L10n::t('Likes');
357                                 $value = $likes;
358                         }
359                         if ($dislikes != $orig[0]['dislikes']) {
360                                 $changes[] = L10n::t('Dislikes');
361                                 $value = $dislikes;
362                         }
363                         if ($work != $orig[0]['work']) {
364                                 $changes[] = L10n::t('Work/Employment');
365                         }
366                         if ($religion != $orig[0]['religion']) {
367                                 $changes[] = L10n::t('Religion');
368                                 $value = $religion;
369                         }
370                         if ($politic != $orig[0]['politic']) {
371                                 $changes[] = L10n::t('Political Views');
372                                 $value = $politic;
373                         }
374                         if ($gender != $orig[0]['gender']) {
375                                 $changes[] = L10n::t('Gender');
376                                 $value = $gender;
377                         }
378                         if ($sexual != $orig[0]['sexual']) {
379                                 $changes[] = L10n::t('Sexual Preference');
380                                 $value = $sexual;
381                         }
382                         if ($xmpp != $orig[0]['xmpp']) {
383                                 $changes[] = L10n::t('XMPP');
384                                 $value = $xmpp;
385                         }
386                         if ($homepage != $orig[0]['homepage']) {
387                                 $changes[] = L10n::t('Homepage');
388                                 $value = $homepage;
389                         }
390                         if ($interest != $orig[0]['interest']) {
391                                 $changes[] = L10n::t('Interests');
392                                 $value = $interest;
393                         }
394                         if ($address != $orig[0]['address']) {
395                                 $changes[] = L10n::t('Address');
396                                 // New address not sent in notifications, potential privacy issues
397                                 // in case this leaks to unintended recipients. Yes, it's in the public
398                                 // profile but that doesn't mean we have to broadcast it to everybody.
399                         }
400                         if ($locality != $orig[0]['locality'] || $region != $orig[0]['region']
401                                 || $country_name != $orig[0]['country-name']) {
402                                 $changes[] = L10n::t('Location');
403                                 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
404                                 $comma2 = (($region && $country_name) ? ', ' : '');
405                                 $value = $locality . $comma1 . $region . $comma2 . $country_name;
406                         }
407                 }
408
409                 $r = q("UPDATE `profile`
410                         SET `profile-name` = '%s',
411                         `name` = '%s',
412                         `pdesc` = '%s',
413                         `gender` = '%s',
414                         `dob` = '%s',
415                         `address` = '%s',
416                         `locality` = '%s',
417                         `region` = '%s',
418                         `postal-code` = '%s',
419                         `country-name` = '%s',
420                         `marital` = '%s',
421                         `with` = '%s',
422                         `howlong` = '%s',
423                         `sexual` = '%s',
424                         `xmpp` = '%s',
425                         `homepage` = '%s',
426                         `hometown` = '%s',
427                         `politic` = '%s',
428                         `religion` = '%s',
429                         `pub_keywords` = '%s',
430                         `prv_keywords` = '%s',
431                         `likes` = '%s',
432                         `dislikes` = '%s',
433                         `about` = '%s',
434                         `interest` = '%s',
435                         `contact` = '%s',
436                         `music` = '%s',
437                         `book` = '%s',
438                         `tv` = '%s',
439                         `film` = '%s',
440                         `romance` = '%s',
441                         `work` = '%s',
442                         `education` = '%s',
443                         `hide-friends` = %d
444                         WHERE `id` = %d AND `uid` = %d",
445                         DBA::escape($profile_name),
446                         DBA::escape($name),
447                         DBA::escape($pdesc),
448                         DBA::escape($gender),
449                         DBA::escape($dob),
450                         DBA::escape($address),
451                         DBA::escape($locality),
452                         DBA::escape($region),
453                         DBA::escape($postal_code),
454                         DBA::escape($country_name),
455                         DBA::escape($marital),
456                         DBA::escape($with),
457                         DBA::escape($howlong),
458                         DBA::escape($sexual),
459                         DBA::escape($xmpp),
460                         DBA::escape($homepage),
461                         DBA::escape($hometown),
462                         DBA::escape($politic),
463                         DBA::escape($religion),
464                         DBA::escape($pub_keywords),
465                         DBA::escape($prv_keywords),
466                         DBA::escape($likes),
467                         DBA::escape($dislikes),
468                         DBA::escape($about),
469                         DBA::escape($interest),
470                         DBA::escape($contact),
471                         DBA::escape($music),
472                         DBA::escape($book),
473                         DBA::escape($tv),
474                         DBA::escape($film),
475                         DBA::escape($romance),
476                         DBA::escape($work),
477                         DBA::escape($education),
478                         intval($hide_friends),
479                         intval($a->argv[1]),
480                         intval(local_user())
481                 );
482
483                 /// @TODO decide to use DBA::isResult() here and check $r
484                 if ($r) {
485                         info(L10n::t('Profile updated.') . EOL);
486                 }
487
488                 if ($is_default) {
489                         if ($namechanged) {
490                                 $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
491                                         DBA::escape($name),
492                                         intval(local_user())
493                                 );
494                         }
495
496                         Contact::updateSelfFromUserID(local_user());
497
498                         // Update global directory in background
499                         $url = $_SESSION['my_url'];
500                         if ($url && strlen(Config::get('system', 'directory'))) {
501                                 Worker::add(PRIORITY_LOW, "Directory", $url);
502                         }
503
504                         Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
505
506                         // Update the global contact for the user
507                         GContact::updateForUser(local_user());
508                 }
509         }
510 }
511
512 function profiles_content(App $a) {
513
514         if (! local_user()) {
515                 notice(L10n::t('Permission denied.') . EOL);
516                 return Login::form();
517         }
518
519         $o = '';
520
521         if (($a->argc > 1) && (intval($a->argv[1]))) {
522                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
523                         intval($a->argv[1]),
524                         intval(local_user())
525                 );
526                 if (! DBA::isResult($r)) {
527                         notice(L10n::t('Profile not found.') . EOL);
528                         return;
529                 }
530
531                 $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('profed_head.tpl'), [
532                         '$baseurl' => System::baseUrl(true),
533                 ]);
534
535                 $opt_tpl = Renderer::getMarkupTemplate("profile-hide-friends.tpl");
536                 $hide_friends = Renderer::replaceMacros($opt_tpl,[
537                         '$yesno' => [
538                                 'hide-friends', //Name
539                                 L10n::t('Hide contacts and friends:'), //Label
540                                 !!$r[0]['hide-friends'], //Value
541                                 '', //Help string
542                                 [L10n::t('No'), L10n::t('Yes')] //Off - On strings
543                         ],
544                         '$desc' => L10n::t('Hide your contact/friend list from viewers of this profile?'),
545                         '$yes_str' => L10n::t('Yes'),
546                         '$no_str' => L10n::t('No'),
547                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
548                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
549                 ]);
550
551                 $personal_account = !(in_array($a->user["page-flags"],
552                                         [Contact::PAGE_COMMUNITY, Contact::PAGE_PRVGROUP]));
553
554                 $detailled_profile = (PConfig::get(local_user(), 'system', 'detailled_profile') AND $personal_account);
555
556                 $is_default = (($r[0]['is-default']) ? 1 : 0);
557                 $tpl = Renderer::getMarkupTemplate("profile_edit.tpl");
558                 $o .= Renderer::replaceMacros($tpl, [
559                         '$personal_account' => $personal_account,
560                         '$detailled_profile' => $detailled_profile,
561
562                         '$details' => [
563                                 'detailled_profile', //Name
564                                 L10n::t('Show more profile fields:'), //Label
565                                 $detailled_profile, //Value
566                                 '', //Help string
567                                 [L10n::t('No'), L10n::t('Yes')] //Off - On strings
568                         ],
569
570                         '$multi_profiles'               => Feature::isEnabled(local_user(), 'multi_profiles'),
571                         '$form_security_token'          => BaseModule::getFormSecurityToken("profile_edit"),
572                         '$form_security_token_photo'    => BaseModule::getFormSecurityToken("profile_photo"),
573                         '$profile_clone_link'           => ((Feature::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . BaseModule::getFormSecurityToken("profile_clone") : ""),
574                         '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . BaseModule::getFormSecurityToken("profile_drop"),
575
576                         '$profile_action' => L10n::t('Profile Actions'),
577                         '$banner'       => L10n::t('Edit Profile Details'),
578                         '$submit'       => L10n::t('Submit'),
579                         '$profpic'      => L10n::t('Change Profile Photo'),
580                         '$profpiclink'  => '/photos/' . $a->user['nickname'],
581                         '$viewprof'     => L10n::t('View this profile'),
582                         '$viewallprof'  => L10n::t('View all profiles'),
583                         '$editvis'      => L10n::t('Edit visibility'),
584                         '$cr_prof'      => L10n::t('Create a new profile using these settings'),
585                         '$cl_prof'      => L10n::t('Clone this profile'),
586                         '$del_prof'     => L10n::t('Delete this profile'),
587
588                         '$lbl_basic_section' => L10n::t('Basic information'),
589                         '$lbl_picture_section' => L10n::t('Profile picture'),
590                         '$lbl_location_section' => L10n::t('Location'),
591                         '$lbl_preferences_section' => L10n::t('Preferences'),
592                         '$lbl_status_section' => L10n::t('Status information'),
593                         '$lbl_about_section' => L10n::t('Additional information'),
594                         '$lbl_interests_section' => L10n::t('Interests'),
595                         '$lbl_personal_section' => L10n::t('Personal'),
596                         '$lbl_relation_section' => L10n::t('Relation'),
597                         '$lbl_miscellaneous_section' => L10n::t('Miscellaneous'),
598
599                         '$lbl_profile_photo' => L10n::t('Upload Profile Photo'),
600                         '$lbl_gender' => L10n::t('Your Gender:'),
601                         '$lbl_marital' => L10n::t('<span class="heart">&hearts;</span> Marital Status:'),
602                         '$lbl_sexual' => L10n::t('Sexual Preference:'),
603                         '$lbl_ex2' => L10n::t('Example: fishing photography software'),
604
605                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
606                         '$baseurl' => System::baseUrl(true),
607                         '$profile_id' => $r[0]['id'],
608                         '$profile_name' => ['profile_name', L10n::t('Profile Name:'), $r[0]['profile-name'], L10n::t('Required'), '*'],
609                         '$is_default'   => $is_default,
610                         '$default' => (($is_default) ? '<p id="profile-edit-default-desc">' . L10n::t('This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.') . '</p>' : ""),
611                         '$name' => ['name', L10n::t('Your Full Name:'), $r[0]['name']],
612                         '$pdesc' => ['pdesc', L10n::t('Title/Description:'), $r[0]['pdesc']],
613                         '$dob' => Temporal::getDateofBirthField($r[0]['dob']),
614                         '$hide_friends' => $hide_friends,
615                         '$address' => ['address', L10n::t('Street Address:'), $r[0]['address']],
616                         '$locality' => ['locality', L10n::t('Locality/City:'), $r[0]['locality']],
617                         '$region' => ['region', L10n::t('Region/State:'), $r[0]['region']],
618                         '$postal_code' => ['postal_code', L10n::t('Postal/Zip Code:'), $r[0]['postal-code']],
619                         '$country_name' => ['country_name', L10n::t('Country:'), $r[0]['country-name']],
620                         '$age' => ((intval($r[0]['dob'])) ? '(' . L10n::t('Age: ') . Temporal::getAgeByTimezone($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
621                         '$gender' => ContactSelector::gender($r[0]['gender']),
622                         '$marital' => ['selector' => ContactSelector::maritalStatus($r[0]['marital']), 'value' => $r[0]['marital']],
623                         '$with' => ['with', L10n::t("Who: \x28if applicable\x29"), strip_tags($r[0]['with']), L10n::t('Examples: cathy123, Cathy Williams, cathy@example.com')],
624                         '$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= DBA::NULL_DATETIME ? '' : DateTimeFormat::local($r[0]['howlong']))],
625                         '$sexual' => ['selector' => ContactSelector::sexualPreference($r[0]['sexual']), 'value' => $r[0]['sexual']],
626                         '$about' => ['about', L10n::t('Tell us about yourself...'), $r[0]['about']],
627                         '$xmpp' => ['xmpp', L10n::t("XMPP \x28Jabber\x29 address:"), $r[0]['xmpp'], L10n::t("The XMPP address will be propagated to your contacts so that they can follow you.")],
628                         '$homepage' => ['homepage', L10n::t('Homepage URL:'), $r[0]['homepage']],
629                         '$hometown' => ['hometown', L10n::t('Hometown:'), $r[0]['hometown']],
630                         '$politic' => ['politic', L10n::t('Political Views:'), $r[0]['politic']],
631                         '$religion' => ['religion', L10n::t('Religious Views:'), $r[0]['religion']],
632                         '$pub_keywords' => ['pub_keywords', L10n::t('Public Keywords:'), $r[0]['pub_keywords'], L10n::t("\x28Used for suggesting potential friends, can be seen by others\x29")],
633                         '$prv_keywords' => ['prv_keywords', L10n::t('Private Keywords:'), $r[0]['prv_keywords'], L10n::t("\x28Used for searching profiles, never shown to others\x29")],
634                         '$likes' => ['likes', L10n::t('Likes:'), $r[0]['likes']],
635                         '$dislikes' => ['dislikes', L10n::t('Dislikes:'), $r[0]['dislikes']],
636                         '$music' => ['music', L10n::t('Musical interests'), $r[0]['music']],
637                         '$book' => ['book', L10n::t('Books, literature'), $r[0]['book']],
638                         '$tv' => ['tv', L10n::t('Television'), $r[0]['tv']],
639                         '$film' => ['film', L10n::t('Film/dance/culture/entertainment'), $r[0]['film']],
640                         '$interest' => ['interest', L10n::t('Hobbies/Interests'), $r[0]['interest']],
641                         '$romance' => ['romance', L10n::t('Love/romance'), $r[0]['romance']],
642                         '$work' => ['work', L10n::t('Work/employment'), $r[0]['work']],
643                         '$education' => ['education', L10n::t('School/education'), $r[0]['education']],
644                         '$contact' => ['contact', L10n::t('Contact information and Social Networks'), $r[0]['contact']],
645                 ]);
646
647                 $arr = ['profile' => $r[0], 'entry' => $o];
648                 Addon::callHooks('profile_edit', $arr);
649
650                 return $o;
651         } else {
652                 // If we don't support multi profiles, don't display this list.
653                 if (!Feature::isEnabled(local_user(), 'multi_profiles')) {
654                         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
655                                 local_user()
656                         );
657                         if (DBA::isResult($r)) {
658                                 //Go to the default profile.
659                                 $a->internalRedirect('profiles/' . $r[0]['id']);
660                         }
661                 }
662
663                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
664                         local_user());
665
666                 if (DBA::isResult($r)) {
667
668                         $tpl = Renderer::getMarkupTemplate('profile_entry.tpl');
669
670                         $profiles = '';
671                         foreach ($r as $rr) {
672                                 $profiles .= Renderer::replaceMacros($tpl, [
673                                         '$photo'        => $a->removeBaseURL($rr['thumb']),
674                                         '$id'           => $rr['id'],
675                                         '$alt'          => L10n::t('Profile Image'),
676                                         '$profile_name' => $rr['profile-name'],
677                                         '$visible'      => (($rr['is-default']) ? '<strong>' . L10n::t('visible to everybody') . '</strong>'
678                                                 : '<a href="'.'profperm/'.$rr['id'].'" />' . L10n::t('Edit visibility') . '</a>')
679                                 ]);
680                         }
681
682                         $tpl_header = Renderer::getMarkupTemplate('profile_listing_header.tpl');
683                         $o .= Renderer::replaceMacros($tpl_header,[
684                                 '$header'      => L10n::t('Edit/Manage Profiles'),
685                                 '$chg_photo'   => L10n::t('Change profile photo'),
686                                 '$cr_new'      => L10n::t('Create New Profile'),
687                                 '$cr_new_link' => 'profiles/new?t=' . BaseModule::getFormSecurityToken("profile_new"),
688                                 '$profiles'    => $profiles
689                         ]);
690                 }
691                 return $o;
692         }
693
694 }