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.

796 lines
24 KiB

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