Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

678 lines
23 KiB

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