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.

1278 lines
53KB

  1. <?php
  2. /**
  3. * @file mod/settings.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Content\Feature;
  7. use Friendica\Content\Nav;
  8. use Friendica\Core\ACL;
  9. use Friendica\Core\Addon;
  10. use Friendica\Core\Config;
  11. use Friendica\Core\L10n;
  12. use Friendica\Core\PConfig;
  13. use Friendica\Core\System;
  14. use Friendica\Core\Theme;
  15. use Friendica\Core\Worker;
  16. use Friendica\Database\DBM;
  17. use Friendica\Model\Contact;
  18. use Friendica\Model\GContact;
  19. use Friendica\Model\Group;
  20. use Friendica\Model\User;
  21. use Friendica\Protocol\Email;
  22. use Friendica\Util\Network;
  23. use Friendica\Util\Temporal;
  24. function get_theme_config_file($theme)
  25. {
  26. $a = get_app();
  27. $base_theme = $a->theme_info['extends'];
  28. if (file_exists("view/theme/$theme/config.php")) {
  29. return "view/theme/$theme/config.php";
  30. }
  31. if (file_exists("view/theme/$base_theme/config.php")) {
  32. return "view/theme/$base_theme/config.php";
  33. }
  34. return null;
  35. }
  36. function settings_init(App $a)
  37. {
  38. if (!local_user()) {
  39. notice(L10n::t('Permission denied.') . EOL);
  40. return;
  41. }
  42. // These lines provide the javascript needed by the acl selector
  43. $tpl = get_markup_template('settings/head.tpl');
  44. $a->page['htmlhead'] .= replace_macros($tpl, [
  45. '$ispublic' => L10n::t('everybody')
  46. ]);
  47. $tabs = [
  48. [
  49. 'label' => L10n::t('Account'),
  50. 'url' => 'settings',
  51. 'selected' => (($a->argc == 1) && ($a->argv[0] === 'settings')?'active':''),
  52. 'accesskey' => 'o',
  53. ],
  54. ];
  55. if (Feature::get()) {
  56. $tabs[] = [
  57. 'label' => L10n::t('Additional features'),
  58. 'url' => 'settings/features',
  59. 'selected' => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
  60. 'accesskey' => 't',
  61. ];
  62. }
  63. $tabs[] = [
  64. 'label' => L10n::t('Display'),
  65. 'url' => 'settings/display',
  66. 'selected' => (($a->argc > 1) && ($a->argv[1] === 'display')?'active':''),
  67. 'accesskey' => 'i',
  68. ];
  69. $tabs[] = [
  70. 'label' => L10n::t('Social Networks'),
  71. 'url' => 'settings/connectors',
  72. 'selected' => (($a->argc > 1) && ($a->argv[1] === 'connectors')?'active':''),
  73. 'accesskey' => 'w',
  74. ];
  75. $tabs[] = [
  76. 'label' => L10n::t('Addons'),
  77. 'url' => 'settings/addon',
  78. 'selected' => (($a->argc > 1) && ($a->argv[1] === 'addon')?'active':''),
  79. 'accesskey' => 'l',
  80. ];
  81. $tabs[] = [
  82. 'label' => L10n::t('Delegations'),
  83. 'url' => 'delegate',
  84. 'selected' => (($a->argc == 1) && ($a->argv[0] === 'delegate')?'active':''),
  85. 'accesskey' => 'd',
  86. ];
  87. $tabs[] = [
  88. 'label' => L10n::t('Connected apps'),
  89. 'url' => 'settings/oauth',
  90. 'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth')?'active':''),
  91. 'accesskey' => 'b',
  92. ];
  93. $tabs[] = [
  94. 'label' => L10n::t('Export personal data'),
  95. 'url' => 'uexport',
  96. 'selected' => (($a->argc == 1) && ($a->argv[0] === 'uexport')?'active':''),
  97. 'accesskey' => 'e',
  98. ];
  99. $tabs[] = [
  100. 'label' => L10n::t('Remove account'),
  101. 'url' => 'removeme',
  102. 'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme')?'active':''),
  103. 'accesskey' => 'r',
  104. ];
  105. $tabtpl = get_markup_template("generic_links_widget.tpl");
  106. $a->page['aside'] = replace_macros($tabtpl, [
  107. '$title' => L10n::t('Settings'),
  108. '$class' => 'settings-widget',
  109. '$items' => $tabs,
  110. ]);
  111. }
  112. function settings_post(App $a)
  113. {
  114. if (!local_user()) {
  115. return;
  116. }
  117. if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
  118. return;
  119. }
  120. if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) {
  121. notice(L10n::t('Permission denied.') . EOL);
  122. return;
  123. }
  124. $old_page_flags = $a->user['page-flags'];
  125. if (($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST, 'remove')) {
  126. check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
  127. $key = $_POST['remove'];
  128. dba::delete('tokens', ['id' => $key, 'uid' => local_user()]);
  129. goaway(System::baseUrl(true)."/settings/oauth/");
  130. return;
  131. }
  132. if (($a->argc > 2) && ($a->argv[1] === 'oauth') && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST, 'submit')) {
  133. check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
  134. $name = defaults($_POST, 'name' , '');
  135. $key = defaults($_POST, 'key' , '');
  136. $secret = defaults($_POST, 'secret' , '');
  137. $redirect = defaults($_POST, 'redirect', '');
  138. $icon = defaults($_POST, 'icon' , '');
  139. if ($name == "" || $key == "" || $secret == "") {
  140. notice(L10n::t("Missing some important data!"));
  141. } else {
  142. if ($_POST['submit'] == L10n::t("Update")) {
  143. q("UPDATE clients SET
  144. client_id='%s',
  145. pw='%s',
  146. name='%s',
  147. redirect_uri='%s',
  148. icon='%s',
  149. uid=%d
  150. WHERE client_id='%s'",
  151. dbesc($key),
  152. dbesc($secret),
  153. dbesc($name),
  154. dbesc($redirect),
  155. dbesc($icon),
  156. local_user(),
  157. dbesc($key)
  158. );
  159. } else {
  160. q("INSERT INTO clients
  161. (client_id, pw, name, redirect_uri, icon, uid)
  162. VALUES ('%s', '%s', '%s', '%s', '%s',%d)",
  163. dbesc($key),
  164. dbesc($secret),
  165. dbesc($name),
  166. dbesc($redirect),
  167. dbesc($icon),
  168. local_user()
  169. );
  170. }
  171. }
  172. goaway(System::baseUrl(true)."/settings/oauth/");
  173. return;
  174. }
  175. if (($a->argc > 1) && ($a->argv[1] == 'addon')) {
  176. check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon');
  177. Addon::callHooks('addon_settings_post', $_POST);
  178. return;
  179. }
  180. if (($a->argc > 1) && ($a->argv[1] == 'connectors')) {
  181. check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors');
  182. if (x($_POST, 'general-submit')) {
  183. PConfig::set(local_user(), 'system', 'disable_cw', intval($_POST['disable_cw']));
  184. PConfig::set(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
  185. PConfig::set(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
  186. PConfig::set(local_user(), 'ostatus', 'default_group', $_POST['group-selection']);
  187. PConfig::set(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']);
  188. } elseif (x($_POST, 'imap-submit')) {
  189. $mail_server = ((x($_POST, 'mail_server')) ? $_POST['mail_server'] : '');
  190. $mail_port = ((x($_POST, 'mail_port')) ? $_POST['mail_port'] : '');
  191. $mail_ssl = ((x($_POST, 'mail_ssl')) ? strtolower(trim($_POST['mail_ssl'])) : '');
  192. $mail_user = ((x($_POST, 'mail_user')) ? $_POST['mail_user'] : '');
  193. $mail_pass = ((x($_POST, 'mail_pass')) ? trim($_POST['mail_pass']) : '');
  194. $mail_action = ((x($_POST, 'mail_action')) ? trim($_POST['mail_action']) : '');
  195. $mail_movetofolder = ((x($_POST, 'mail_movetofolder')) ? trim($_POST['mail_movetofolder']) : '');
  196. $mail_replyto = ((x($_POST, 'mail_replyto')) ? $_POST['mail_replyto'] : '');
  197. $mail_pubmail = ((x($_POST, 'mail_pubmail')) ? $_POST['mail_pubmail'] : '');
  198. $mail_disabled = ((function_exists('imap_open') && (!Config::get('system', 'imap_disabled'))) ? 0 : 1);
  199. if (Config::get('system', 'dfrn_only')) {
  200. $mail_disabled = 1;
  201. }
  202. if (!$mail_disabled) {
  203. $failed = false;
  204. $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
  205. intval(local_user())
  206. );
  207. if (!DBM::is_result($r)) {
  208. dba::insert('mailacct', ['uid' => local_user()]);
  209. }
  210. if (strlen($mail_pass)) {
  211. $pass = '';
  212. openssl_public_encrypt($mail_pass, $pass, $a->user['pubkey']);
  213. dba::update('mailacct', ['pass' => bin2hex($pass)], ['uid' => local_user()]);
  214. }
  215. $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',
  216. `action` = %d, `movetofolder` = '%s',
  217. `mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d",
  218. dbesc($mail_server),
  219. intval($mail_port),
  220. dbesc($mail_ssl),
  221. dbesc($mail_user),
  222. intval($mail_action),
  223. dbesc($mail_movetofolder),
  224. dbesc($mail_replyto),
  225. intval($mail_pubmail),
  226. intval(local_user())
  227. );
  228. logger("mail: updating mailaccount. Response: ".print_r($r, true));
  229. $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
  230. intval(local_user())
  231. );
  232. if (DBM::is_result($r)) {
  233. $eacct = $r[0];
  234. $mb = Email::constructMailboxName($eacct);
  235. if (strlen($eacct['server'])) {
  236. $dcrpass = '';
  237. openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']);
  238. $mbox = Email::connect($mb, $mail_user, $dcrpass);
  239. unset($dcrpass);
  240. if (!$mbox) {
  241. $failed = true;
  242. notice(L10n::t('Failed to connect with email account using the settings provided.') . EOL);
  243. }
  244. }
  245. }
  246. if (!$failed) {
  247. info(L10n::t('Email settings updated.') . EOL);
  248. }
  249. }
  250. }
  251. Addon::callHooks('connector_settings_post', $_POST);
  252. return;
  253. }
  254. if (($a->argc > 1) && ($a->argv[1] === 'features')) {
  255. check_form_security_token_redirectOnErr('/settings/features', 'settings_features');
  256. foreach ($_POST as $k => $v) {
  257. if (strpos($k, 'feature_') === 0) {
  258. PConfig::set(local_user(), 'feature', substr($k, 8), ((intval($v)) ? 1 : 0));
  259. }
  260. }
  261. info(L10n::t('Features updated') . EOL);
  262. return;
  263. }
  264. if (($a->argc > 1) && ($a->argv[1] === 'display')) {
  265. check_form_security_token_redirectOnErr('/settings/display', 'settings_display');
  266. $theme = x($_POST, 'theme') ? notags(trim($_POST['theme'])) : $a->user['theme'];
  267. $mobile_theme = x($_POST, 'mobile_theme') ? notags(trim($_POST['mobile_theme'])) : '';
  268. $nosmile = x($_POST, 'nosmile') ? intval($_POST['nosmile']) : 0;
  269. $first_day_of_week = x($_POST, 'first_day_of_week') ? intval($_POST['first_day_of_week']) : 0;
  270. $noinfo = x($_POST, 'noinfo') ? intval($_POST['noinfo']) : 0;
  271. $infinite_scroll = x($_POST, 'infinite_scroll') ? intval($_POST['infinite_scroll']) : 0;
  272. $no_auto_update = x($_POST, 'no_auto_update') ? intval($_POST['no_auto_update']) : 0;
  273. $bandwidth_saver = x($_POST, 'bandwidth_saver') ? intval($_POST['bandwidth_saver']) : 0;
  274. $smart_threading = x($_POST, 'smart_threading') ? intval($_POST['smart_threading']) : 0;
  275. $nowarn_insecure = x($_POST, 'nowarn_insecure') ? intval($_POST['nowarn_insecure']) : 0;
  276. $browser_update = x($_POST, 'browser_update') ? intval($_POST['browser_update']) : 0;
  277. if ($browser_update != -1) {
  278. $browser_update = $browser_update * 1000;
  279. if ($browser_update < 10000) {
  280. $browser_update = 10000;
  281. }
  282. }
  283. $itemspage_network = x($_POST, 'itemspage_network') ? intval($_POST['itemspage_network']) : 40;
  284. if ($itemspage_network > 100) {
  285. $itemspage_network = 100;
  286. }
  287. $itemspage_mobile_network = x($_POST, 'itemspage_mobile_network') ? intval($_POST['itemspage_mobile_network']) : 20;
  288. if ($itemspage_mobile_network > 100) {
  289. $itemspage_mobile_network = 100;
  290. }
  291. if ($mobile_theme !== '') {
  292. PConfig::set(local_user(), 'system', 'mobile_theme', $mobile_theme);
  293. }
  294. PConfig::set(local_user(), 'system', 'nowarn_insecure' , $nowarn_insecure);
  295. PConfig::set(local_user(), 'system', 'update_interval' , $browser_update);
  296. PConfig::set(local_user(), 'system', 'itemspage_network' , $itemspage_network);
  297. PConfig::set(local_user(), 'system', 'itemspage_mobile_network', $itemspage_mobile_network);
  298. PConfig::set(local_user(), 'system', 'no_smilies' , $nosmile);
  299. PConfig::set(local_user(), 'system', 'first_day_of_week' , $first_day_of_week);
  300. PConfig::set(local_user(), 'system', 'ignore_info' , $noinfo);
  301. PConfig::set(local_user(), 'system', 'infinite_scroll' , $infinite_scroll);
  302. PConfig::set(local_user(), 'system', 'no_auto_update' , $no_auto_update);
  303. PConfig::set(local_user(), 'system', 'bandwidth_saver' , $bandwidth_saver);
  304. PConfig::set(local_user(), 'system', 'smart_threading' , $smart_threading);
  305. if ($theme == $a->user['theme']) {
  306. // call theme_post only if theme has not been changed
  307. if (($themeconfigfile = get_theme_config_file($theme)) !== null) {
  308. require_once $themeconfigfile;
  309. theme_post($a);
  310. }
  311. }
  312. Theme::install($theme);
  313. $r = q("UPDATE `user` SET `theme` = '%s' WHERE `uid` = %d",
  314. dbesc($theme),
  315. intval(local_user())
  316. );
  317. Addon::callHooks('display_settings_post', $_POST);
  318. goaway('settings/display');
  319. return; // NOTREACHED
  320. }
  321. check_form_security_token_redirectOnErr('/settings', 'settings');
  322. if (x($_POST,'resend_relocate')) {
  323. Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', local_user());
  324. info(L10n::t("Relocate message has been send to your contacts"));
  325. goaway('settings');
  326. }
  327. Addon::callHooks('settings_post', $_POST);
  328. if (x($_POST, 'password') || x($_POST, 'confirm')) {
  329. $newpass = $_POST['password'];
  330. $confirm = $_POST['confirm'];
  331. $err = false;
  332. if ($newpass != $confirm) {
  333. notice(L10n::t('Passwords do not match. Password unchanged.') . EOL);
  334. $err = true;
  335. }
  336. if (!x($newpass) || !x($confirm)) {
  337. notice(L10n::t('Empty passwords are not allowed. Password unchanged.') . EOL);
  338. $err = true;
  339. }
  340. if (!Config::get('system', 'disable_password_exposed', false) && User::isPasswordExposed($newpass)) {
  341. notice(L10n::t('The new password has been exposed in a public data dump, please choose another.') . EOL);
  342. $err = true;
  343. }
  344. // check if the old password was supplied correctly before changing it to the new value
  345. if (!User::authenticate(intval(local_user()), $_POST['opassword'])) {
  346. notice(L10n::t('Wrong password.') . EOL);
  347. $err = true;
  348. }
  349. if (!$err) {
  350. $result = User::updatePassword(local_user(), $newpass);
  351. if (DBM::is_result($result)) {
  352. info(L10n::t('Password changed.') . EOL);
  353. } else {
  354. notice(L10n::t('Password update failed. Please try again.') . EOL);
  355. }
  356. }
  357. }
  358. $username = ((x($_POST, 'username')) ? notags(trim($_POST['username'])) : '');
  359. $email = ((x($_POST, 'email')) ? notags(trim($_POST['email'])) : '');
  360. $timezone = ((x($_POST, 'timezone')) ? notags(trim($_POST['timezone'])) : '');
  361. $language = ((x($_POST, 'language')) ? notags(trim($_POST['language'])) : '');
  362. $defloc = ((x($_POST, 'defloc')) ? notags(trim($_POST['defloc'])) : '');
  363. $openid = ((x($_POST, 'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
  364. $maxreq = ((x($_POST, 'maxreq')) ? intval($_POST['maxreq']) : 0);
  365. $expire = ((x($_POST, 'expire')) ? intval($_POST['expire']) : 0);
  366. $def_gid = ((x($_POST, 'group-selection')) ? intval($_POST['group-selection']) : 0);
  367. $expire_items = ((x($_POST, 'expire_items')) ? intval($_POST['expire_items']) : 0);
  368. $expire_notes = ((x($_POST, 'expire_notes')) ? intval($_POST['expire_notes']) : 0);
  369. $expire_starred = ((x($_POST, 'expire_starred')) ? intval($_POST['expire_starred']) : 0);
  370. $expire_photos = ((x($_POST, 'expire_photos'))? intval($_POST['expire_photos']) : 0);
  371. $expire_network_only = ((x($_POST, 'expire_network_only'))? intval($_POST['expire_network_only']) : 0);
  372. $allow_location = (((x($_POST, 'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
  373. $publish = (((x($_POST, 'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
  374. $net_publish = (((x($_POST, 'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
  375. $old_visibility = (((x($_POST, 'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
  376. $account_type = (((x($_POST, 'account-type')) && (intval($_POST['account-type']))) ? intval($_POST['account-type']) : 0);
  377. $page_flags = (((x($_POST, 'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
  378. $blockwall = (((x($_POST, 'blockwall')) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted!
  379. $blocktags = (((x($_POST, 'blocktags')) && (intval($_POST['blocktags']) == 1)) ? 0: 1); // this setting is inverted!
  380. $unkmail = (((x($_POST, 'unkmail')) && (intval($_POST['unkmail']) == 1)) ? 1: 0);
  381. $cntunkmail = ((x($_POST, 'cntunkmail')) ? intval($_POST['cntunkmail']) : 0);
  382. $suggestme = ((x($_POST, 'suggestme')) ? intval($_POST['suggestme']) : 0);
  383. $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
  384. $hidewall = (($_POST['hidewall'] == 1) ? 1: 0);
  385. $email_textonly = (($_POST['email_textonly'] == 1) ? 1 : 0);
  386. $detailed_notif = (($_POST['detailed_notif'] == 1) ? 1 : 0);
  387. $notify = 0;
  388. if (x($_POST, 'notify1')) {
  389. $notify += intval($_POST['notify1']);
  390. }
  391. if (x($_POST, 'notify2')) {
  392. $notify += intval($_POST['notify2']);
  393. }
  394. if (x($_POST, 'notify3')) {
  395. $notify += intval($_POST['notify3']);
  396. }
  397. if (x($_POST, 'notify4')) {
  398. $notify += intval($_POST['notify4']);
  399. }
  400. if (x($_POST, 'notify5')) {
  401. $notify += intval($_POST['notify5']);
  402. }
  403. if (x($_POST, 'notify6')) {
  404. $notify += intval($_POST['notify6']);
  405. }
  406. if (x($_POST, 'notify7')) {
  407. $notify += intval($_POST['notify7']);
  408. }
  409. if (x($_POST, 'notify8')) {
  410. $notify += intval($_POST['notify8']);
  411. }
  412. // Adjust the page flag if the account type doesn't fit to the page flag.
  413. if (($account_type == ACCOUNT_TYPE_PERSON) && !in_array($page_flags, [PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE])) {
  414. $page_flags = PAGE_NORMAL;
  415. } elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) && !in_array($page_flags, [PAGE_SOAPBOX])) {
  416. $page_flags = PAGE_SOAPBOX;
  417. } elseif (($account_type == ACCOUNT_TYPE_NEWS) && !in_array($page_flags, [PAGE_SOAPBOX])) {
  418. $page_flags = PAGE_SOAPBOX;
  419. } elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) && !in_array($page_flags, [PAGE_COMMUNITY, PAGE_PRVGROUP])) {
  420. $page_flags = PAGE_COMMUNITY;
  421. }
  422. $email_changed = false;
  423. $err = '';
  424. if ($username != $a->user['username']) {
  425. if (strlen($username) > 40) {
  426. $err .= L10n::t(' Please use a shorter name.');
  427. }
  428. if (strlen($username) < 3) {
  429. $err .= L10n::t(' Name too short.');
  430. }
  431. }
  432. if ($email != $a->user['email']) {
  433. $email_changed = true;
  434. // check for the correct password
  435. if (!User::authenticate(intval(local_user()), $_POST['mpassword'])) {
  436. $err .= L10n::t('Wrong Password') . EOL;
  437. $email = $a->user['email'];
  438. }
  439. // check the email is valid
  440. if (!valid_email($email)) {
  441. $err .= L10n::t('Invalid email.');
  442. }
  443. // ensure new email is not the admin mail
  444. //if ((x($a->config, 'admin_email')) && (strcasecmp($email, $a->config['admin_email']) == 0)) {
  445. if (x($a->config, 'admin_email')) {
  446. $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email'])));
  447. if (in_array(strtolower($email), $adminlist)) {
  448. $err .= L10n::t('Cannot change to that email.');
  449. $email = $a->user['email'];
  450. }
  451. }
  452. }
  453. if (strlen($err)) {
  454. notice($err . EOL);
  455. return;
  456. }
  457. if (($timezone != $a->user['timezone']) && strlen($timezone)) {
  458. date_default_timezone_set($timezone);
  459. }
  460. $str_group_allow = perms2str($_POST['group_allow']);
  461. $str_contact_allow = perms2str($_POST['contact_allow']);
  462. $str_group_deny = perms2str($_POST['group_deny']);
  463. $str_contact_deny = perms2str($_POST['contact_deny']);
  464. $openidserver = $a->user['openidserver'];
  465. //$openid = normalise_openid($openid);
  466. // If openid has changed or if there's an openid but no openidserver, try and discover it.
  467. if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) {
  468. if (Network::isUrlValid($openid)) {
  469. logger('updating openidserver');
  470. $open_id_obj = new LightOpenID($a->get_hostname());
  471. $open_id_obj->identity = $openid;
  472. $openidserver = $open_id_obj->discover($open_id_obj->identity);
  473. } else {
  474. $openidserver = '';
  475. }
  476. }
  477. PConfig::set(local_user(), 'expire', 'items', $expire_items);
  478. PConfig::set(local_user(), 'expire', 'notes', $expire_notes);
  479. PConfig::set(local_user(), 'expire', 'starred', $expire_starred);
  480. PConfig::set(local_user(), 'expire', 'photos', $expire_photos);
  481. PConfig::set(local_user(), 'expire', 'network_only', $expire_network_only);
  482. PConfig::set(local_user(), 'system', 'suggestme', $suggestme);
  483. PConfig::set(local_user(), 'system', 'email_textonly', $email_textonly);
  484. PConfig::set(local_user(), 'system', 'detailed_notif', $detailed_notif);
  485. if ($page_flags == PAGE_PRVGROUP) {
  486. $hidewall = 1;
  487. if (!$str_contact_allow && !$str_group_allow && !$str_contact_deny && !$str_group_deny) {
  488. if ($def_gid) {
  489. info(L10n::t('Private forum has no privacy permissions. Using default privacy group.'). EOL);
  490. $str_group_allow = '<' . $def_gid . '>';
  491. } else {
  492. notice(L10n::t('Private forum has no privacy permissions and no default privacy group.') . EOL);
  493. }
  494. }
  495. }
  496. $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s',
  497. `openid` = '%s', `timezone` = '%s',
  498. `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s',
  499. `notify-flags` = %d, `page-flags` = %d, `account-type` = %d, `default-location` = '%s',
  500. `allow_location` = %d, `maxreq` = %d, `expire` = %d, `openidserver` = '%s',
  501. `def_gid` = %d, `blockwall` = %d, `hidewall` = %d, `blocktags` = %d,
  502. `unkmail` = %d, `cntunkmail` = %d, `language` = '%s'
  503. WHERE `uid` = %d",
  504. dbesc($username),
  505. dbesc($email),
  506. dbesc($openid),
  507. dbesc($timezone),
  508. dbesc($str_contact_allow),
  509. dbesc($str_group_allow),
  510. dbesc($str_contact_deny),
  511. dbesc($str_group_deny),
  512. intval($notify),
  513. intval($page_flags),
  514. intval($account_type),
  515. dbesc($defloc),
  516. intval($allow_location),
  517. intval($maxreq),
  518. intval($expire),
  519. dbesc($openidserver),
  520. intval($def_gid),
  521. intval($blockwall),
  522. intval($hidewall),
  523. intval($blocktags),
  524. intval($unkmail),
  525. intval($cntunkmail),
  526. dbesc($language),
  527. intval(local_user())
  528. );
  529. if (DBM::is_result($r)) {
  530. info(L10n::t('Settings updated.') . EOL);
  531. }
  532. // clear session language
  533. unset($_SESSION['language']);
  534. $r = q("UPDATE `profile`
  535. SET `publish` = %d,
  536. `name` = '%s',
  537. `net-publish` = %d,
  538. `hide-friends` = %d
  539. WHERE `is-default` = 1 AND `uid` = %d",
  540. intval($publish),
  541. dbesc($username),
  542. intval($net_publish),
  543. intval($hide_friends),
  544. intval(local_user())
  545. );
  546. Contact::updateSelfFromUserID(local_user());
  547. if (($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) {
  548. // Update global directory in background
  549. $url = $_SESSION['my_url'];
  550. if ($url && strlen(Config::get('system', 'directory'))) {
  551. Worker::add(PRIORITY_LOW, "Directory", $url);
  552. }
  553. }
  554. Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
  555. // Update the global contact for the user
  556. GContact::updateForUser(local_user());
  557. goaway('settings');
  558. return; // NOTREACHED
  559. }
  560. function settings_content(App $a)
  561. {
  562. $o = '';
  563. Nav::setSelected('settings');
  564. if (!local_user()) {
  565. //notice(L10n::t('Permission denied.') . EOL);
  566. return;
  567. }
  568. if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
  569. notice(L10n::t('Permission denied.') . EOL);
  570. return;
  571. }
  572. if (($a->argc > 1) && ($a->argv[1] === 'oauth')) {
  573. if (($a->argc > 2) && ($a->argv[2] === 'add')) {
  574. $tpl = get_markup_template('settings/oauth_edit.tpl');
  575. $o .= replace_macros($tpl, [
  576. '$form_security_token' => get_form_security_token("settings_oauth"),
  577. '$title' => L10n::t('Add application'),
  578. '$submit' => L10n::t('Save Settings'),
  579. '$cancel' => L10n::t('Cancel'),
  580. '$name' => ['name', L10n::t('Name'), '', ''],
  581. '$key' => ['key', L10n::t('Consumer Key'), '', ''],
  582. '$secret' => ['secret', L10n::t('Consumer Secret'), '', ''],
  583. '$redirect' => ['redirect', L10n::t('Redirect'), '', ''],
  584. '$icon' => ['icon', L10n::t('Icon url'), '', ''],
  585. ]);
  586. return $o;
  587. }
  588. if (($a->argc > 3) && ($a->argv[2] === 'edit')) {
  589. $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d",
  590. dbesc($a->argv[3]),
  591. local_user());
  592. if (!DBM::is_result($r)) {
  593. notice(L10n::t("You can't edit this application."));
  594. return;
  595. }
  596. $app = $r[0];
  597. $tpl = get_markup_template('settings/oauth_edit.tpl');
  598. $o .= replace_macros($tpl, [
  599. '$form_security_token' => get_form_security_token("settings_oauth"),
  600. '$title' => L10n::t('Add application'),
  601. '$submit' => L10n::t('Update'),
  602. '$cancel' => L10n::t('Cancel'),
  603. '$name' => ['name', L10n::t('Name'), $app['name'] , ''],
  604. '$key' => ['key', L10n::t('Consumer Key'), $app['client_id'], ''],
  605. '$secret' => ['secret', L10n::t('Consumer Secret'), $app['pw'], ''],
  606. '$redirect' => ['redirect', L10n::t('Redirect'), $app['redirect_uri'], ''],
  607. '$icon' => ['icon', L10n::t('Icon url'), $app['icon'], ''],
  608. ]);
  609. return $o;
  610. }
  611. if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
  612. check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
  613. dba::delete('clients', ['client_id' => $a->argv[3], 'uid' => local_user()]);
  614. goaway(System::baseUrl(true)."/settings/oauth/");
  615. return;
  616. }
  617. /// @TODO validate result with DBM::is_result()
  618. $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my
  619. FROM clients
  620. LEFT JOIN tokens ON clients.client_id=tokens.client_id
  621. WHERE clients.uid IN (%d, 0)",
  622. local_user(),
  623. local_user());
  624. $tpl = get_markup_template('settings/oauth.tpl');
  625. $o .= replace_macros($tpl, [
  626. '$form_security_token' => get_form_security_token("settings_oauth"),
  627. '$baseurl' => System::baseUrl(true),
  628. '$title' => L10n::t('Connected Apps'),
  629. '$add' => L10n::t('Add application'),
  630. '$edit' => L10n::t('Edit'),
  631. '$delete' => L10n::t('Delete'),
  632. '$consumerkey' => L10n::t('Client key starts with'),
  633. '$noname' => L10n::t('No name'),
  634. '$remove' => L10n::t('Remove authorization'),
  635. '$apps' => $r,
  636. ]);
  637. return $o;
  638. }
  639. if (($a->argc > 1) && ($a->argv[1] === 'addon')) {
  640. $settings_addons = "";
  641. $r = q("SELECT * FROM `hook` WHERE `hook` = 'addon_settings' ");
  642. if (!DBM::is_result($r)) {
  643. $settings_addons = L10n::t('No Addon settings configured');
  644. }
  645. Addon::callHooks('addon_settings', $settings_addons);
  646. $tpl = get_markup_template('settings/addons.tpl');
  647. $o .= replace_macros($tpl, [
  648. '$form_security_token' => get_form_security_token("settings_addon"),
  649. '$title' => L10n::t('Addon Settings'),
  650. '$settings_addons' => $settings_addons
  651. ]);
  652. return $o;
  653. }
  654. if (($a->argc > 1) && ($a->argv[1] === 'features')) {
  655. $arr = [];
  656. $features = Feature::get();
  657. foreach ($features as $fname => $fdata) {
  658. $arr[$fname] = [];
  659. $arr[$fname][0] = $fdata[0];
  660. foreach (array_slice($fdata,1) as $f) {
  661. $arr[$fname][1][] = ['feature_' .$f[0], $f[1],((intval(Feature::isEnabled(local_user(), $f[0]))) ? "1" : ''), $f[2],[L10n::t('Off'), L10n::t('On')]];
  662. }
  663. }
  664. $tpl = get_markup_template('settings/features.tpl');
  665. $o .= replace_macros($tpl, [
  666. '$form_security_token' => get_form_security_token("settings_features"),
  667. '$title' => L10n::t('Additional Features'),
  668. '$features' => $arr,
  669. '$submit' => L10n::t('Save Settings'),
  670. ]);
  671. return $o;
  672. }
  673. if (($a->argc > 1) && ($a->argv[1] === 'connectors')) {
  674. $disable_cw = intval(PConfig::get(local_user(), 'system', 'disable_cw'));
  675. $no_intelligent_shortening = intval(PConfig::get(local_user(), 'system', 'no_intelligent_shortening'));
  676. $ostatus_autofriend = intval(PConfig::get(local_user(), 'system', 'ostatus_autofriend'));
  677. $default_group = PConfig::get(local_user(), 'ostatus', 'default_group');
  678. $legacy_contact = PConfig::get(local_user(), 'ostatus', 'legacy_contact');
  679. if (x($legacy_contact)) {
  680. /// @todo Isn't it supposed to be a goaway() call?
  681. $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . System::baseUrl().'/ostatus_subscribe?url=' . urlencode($legacy_contact) . '">';
  682. }
  683. $settings_connectors = '';
  684. Addon::callHooks('connector_settings', $settings_connectors);
  685. if (is_site_admin()) {
  686. $diasp_enabled = L10n::t('Built-in support for %s connectivity is %s', L10n::t('Diaspora'), ((Config::get('system', 'diaspora_enabled')) ? L10n::t('enabled') : L10n::t('disabled')));
  687. $ostat_enabled = L10n::t('Built-in support for %s connectivity is %s', L10n::t("GNU Social \x28OStatus\x29"), ((Config::get('system', 'ostatus_disabled')) ? L10n::t('disabled') : L10n::t('enabled')));
  688. } else {
  689. $diasp_enabled = "";
  690. $ostat_enabled = "";
  691. }
  692. $mail_disabled = ((function_exists('imap_open') && (!Config::get('system', 'imap_disabled'))) ? 0 : 1);
  693. if (Config::get('system', 'dfrn_only')) {
  694. $mail_disabled = 1;
  695. }
  696. if (!$mail_disabled) {
  697. $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
  698. local_user()
  699. );
  700. } else {
  701. $r = null;
  702. }
  703. $mail_server = ((DBM::is_result($r)) ? $r[0]['server'] : '');
  704. $mail_port = ((DBM::is_result($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
  705. $mail_ssl = ((DBM::is_result($r)) ? $r[0]['ssltype'] : '');
  706. $mail_user = ((DBM::is_result($r)) ? $r[0]['user'] : '');
  707. $mail_replyto = ((DBM::is_result($r)) ? $r[0]['reply_to'] : '');
  708. $mail_pubmail = ((DBM::is_result($r)) ? $r[0]['pubmail'] : 0);
  709. $mail_action = ((DBM::is_result($r)) ? $r[0]['action'] : 0);
  710. $mail_movetofolder = ((DBM::is_result($r)) ? $r[0]['movetofolder'] : '');
  711. $mail_chk = ((DBM::is_result($r)) ? $r[0]['last_check'] : NULL_DATE);
  712. $tpl = get_markup_template('settings/connectors.tpl');
  713. $mail_disabled_message = (($mail_disabled) ? L10n::t('Email access is disabled on this site.') : '');
  714. $o .= replace_macros($tpl, [
  715. '$form_security_token' => get_form_security_token("settings_connectors"),
  716. '$title' => L10n::t('Social Networks'),
  717. '$diasp_enabled' => $diasp_enabled,
  718. '$ostat_enabled' => $ostat_enabled,
  719. '$general_settings' => L10n::t('General Social Media Settings'),
  720. '$disable_cw' => ['disable_cw', L10n::t('Disable Content Warning'), $disable_cw, L10n::t('Users on networks like Mastodon or Pleroma are able to set a content warning field which collapse their post by default. This disables the automatic collapsing and sets the content warning as the post title. Doesn\'t affect any other content filtering you eventually set up.')],
  721. '$no_intelligent_shortening' => ['no_intelligent_shortening', L10n::t('Disable intelligent shortening'), $no_intelligent_shortening, L10n::t('Normally the system tries to find the best link to add to shortened posts. If this option is enabled then every shortened post will always point to the original friendica post.')],
  722. '$ostatus_autofriend' => ['snautofollow', L10n::t("Automatically follow any GNU Social \x28OStatus\x29 followers/mentioners"), $ostatus_autofriend, L10n::t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.')],
  723. '$default_group' => Group::displayGroupSelection(local_user(), $default_group, L10n::t("Default group for OStatus contacts")),
  724. '$legacy_contact' => ['legacy_contact', L10n::t('Your legacy GNU Social account'), $legacy_contact, L10n::t("If you enter your old GNU Social/Statusnet account name here \x28in the format user@domain.tld\x29, your contacts will be added automatically. The field will be emptied when done.")],
  725. '$repair_ostatus_url' => System::baseUrl() . '/repair_ostatus',
  726. '$repair_ostatus_text' => L10n::t('Repair OStatus subscriptions'),
  727. '$settings_connectors' => $settings_connectors,
  728. '$h_imap' => L10n::t('Email/Mailbox Setup'),
  729. '$imap_desc' => L10n::t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
  730. '$imap_lastcheck' => ['imap_lastcheck', L10n::t('Last successful email check:'), $mail_chk, ''],
  731. '$mail_disabled' => $mail_disabled_message,
  732. '$mail_server' => ['mail_server', L10n::t('IMAP server name:'), $mail_server, ''],
  733. '$mail_port' => ['mail_port', L10n::t('IMAP port:'), $mail_port, ''],
  734. '$mail_ssl' => ['mail_ssl', L10n::t('Security:'), strtoupper($mail_ssl), '', ['notls'=>L10n::t('None'), 'TLS'=>'TLS', 'SSL'=>'SSL']],
  735. '$mail_user' => ['mail_user', L10n::t('Email login name:'), $mail_user, ''],
  736. '$mail_pass' => ['mail_pass', L10n::t('Email password:'), '', ''],
  737. '$mail_replyto' => ['mail_replyto', L10n::t('Reply-to address:'), $mail_replyto, 'Optional'],
  738. '$mail_pubmail' => ['mail_pubmail', L10n::t('Send public posts to all email contacts:'), $mail_pubmail, ''],
  739. '$mail_action' => ['mail_action', L10n::t('Action after import:'), $mail_action, '', [0=>L10n::t('None'), /*1=>L10n::t('Delete'),*/ 2=>L10n::t('Mark as seen'), 3=>L10n::t('Move to folder')]],
  740. '$mail_movetofolder' => ['mail_movetofolder', L10n::t('Move to folder:'), $mail_movetofolder, ''],
  741. '$submit' => L10n::t('Save Settings'),
  742. ]);
  743. Addon::callHooks('display_settings', $o);
  744. return $o;
  745. }
  746. /*
  747. * DISPLAY SETTINGS
  748. */
  749. if (($a->argc > 1) && ($a->argv[1] === 'display')) {
  750. $default_theme = Config::get('system', 'theme');
  751. if (!$default_theme) {
  752. $default_theme = 'default';
  753. }
  754. $default_mobile_theme = Config::get('system', 'mobile-theme');
  755. if (!$default_mobile_theme) {
  756. $default_mobile_theme = 'none';
  757. }
  758. $allowed_themes_str = Config::get('system', 'allowed_themes');
  759. $allowed_themes_raw = explode(',', $allowed_themes_str);
  760. $allowed_themes = [];
  761. if (count($allowed_themes_raw)) {
  762. foreach ($allowed_themes_raw as $x) {
  763. if (strlen(trim($x)) && is_dir("view/theme/$x")) {
  764. $allowed_themes[] = trim($x);
  765. }
  766. }
  767. }
  768. $themes = [];
  769. $mobile_themes = ["---" => L10n::t('No special theme for mobile devices')];
  770. if ($allowed_themes) {
  771. foreach ($allowed_themes as $theme) {
  772. $is_experimental = file_exists('view/theme/' . $theme . '/experimental');
  773. $is_unsupported = file_exists('view/theme/' . $theme . '/unsupported');
  774. $is_mobile = file_exists('view/theme/' . $theme . '/mobile');
  775. if (!$is_experimental || ($is_experimental && (Config::get('experimentals', 'exp_themes')==1 || is_null(Config::get('experimentals', 'exp_themes'))))) {
  776. $theme_name = ucfirst($theme);
  777. if ($is_unsupported) {
  778. $theme_name = L10n::t("%s - \x28Unsupported\x29", $theme_name);
  779. } elseif ($is_experimental) {
  780. $theme_name = L10n::t("%s - \x28Experimental\x29", $theme_name);
  781. }
  782. if ($is_mobile) {
  783. $mobile_themes[$theme] = $theme_name;
  784. } else {
  785. $themes[$theme] = $theme_name;
  786. }
  787. }
  788. }
  789. }
  790. $theme_selected = defaults($_SESSION, 'theme' , $default_theme);
  791. $mobile_theme_selected = defaults($_SESSION, 'mobile-theme', $default_mobile_theme);
  792. $nowarn_insecure = intval(PConfig::get(local_user(), 'system', 'nowarn_insecure'));
  793. $browser_update = intval(PConfig::get(local_user(), 'system', 'update_interval'));
  794. if (intval($browser_update) != -1) {
  795. $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
  796. }
  797. $itemspage_network = intval(PConfig::get(local_user(), 'system', 'itemspage_network'));
  798. $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : 40); // default if not set: 40 items
  799. $itemspage_mobile_network = intval(PConfig::get(local_user(), 'system', 'itemspage_mobile_network'));
  800. $itemspage_mobile_network = (($itemspage_mobile_network > 0 && $itemspage_mobile_network < 101) ? $itemspage_mobile_network : 20); // default if not set: 20 items
  801. $nosmile = PConfig::get(local_user(), 'system', 'no_smilies', 0);
  802. $first_day_of_week = PConfig::get(local_user(), 'system', 'first_day_of_week', 0);
  803. $weekdays = [0 => L10n::t("Sunday"), 1 => L10n::t("Monday")];
  804. $noinfo = PConfig::get(local_user(), 'system', 'ignore_info', 0);
  805. $infinite_scroll = PConfig::get(local_user(), 'system', 'infinite_scroll', 0);
  806. $no_auto_update = PConfig::get(local_user(), 'system', 'no_auto_update', 0);
  807. $bandwidth_saver = PConfig::get(local_user(), 'system', 'bandwidth_saver', 0);
  808. $smart_threading = PConfig::get(local_user(), 'system', 'smart_threading', 0);
  809. $theme_config = "";
  810. if (($themeconfigfile = get_theme_config_file($theme_selected)) !== null) {
  811. require_once $themeconfigfile;
  812. $theme_config = theme_content($a);
  813. }
  814. $tpl = get_markup_template('settings/display.tpl');
  815. $o = replace_macros($tpl, [
  816. '$ptitle' => L10n::t('Display Settings'),
  817. '$form_security_token' => get_form_security_token("settings_display"),
  818. '$submit' => L10n::t('Save Settings'),
  819. '$baseurl' => System::baseUrl(true),
  820. '$uid' => local_user(),
  821. '$theme' => ['theme', L10n::t('Display Theme:'), $theme_selected, '', $themes, true],
  822. '$mobile_theme' => ['mobile_theme', L10n::t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, false],
  823. '$nowarn_insecure' => ['nowarn_insecure', L10n::t('Suppress warning of insecure networks'), $nowarn_insecure, L10n::t("Should the system suppress the warning that the current group contains members of networks that can't receive non public postings.")],
  824. '$ajaxint' => ['browser_update', L10n::t("Update browser every xx seconds"), $browser_update, L10n::t('Minimum of 10 seconds. Enter -1 to disable it.')],
  825. '$itemspage_network' => ['itemspage_network', L10n::t("Number of items to display per page:"), $itemspage_network, L10n::t('Maximum of 100 items')],
  826. '$itemspage_mobile_network' => ['itemspage_mobile_network', L10n::t("Number of items to display per page when viewed from mobile device:"), $itemspage_mobile_network, L10n::t('Maximum of 100 items')],
  827. '$nosmile' => ['nosmile', L10n::t("Don't show emoticons"), $nosmile, ''],
  828. '$calendar_title' => L10n::t('Calendar'),
  829. '$first_day_of_week' => ['first_day_of_week', L10n::t('Beginning of week:'), $first_day_of_week, '', $weekdays, false],
  830. '$noinfo' => ['noinfo', L10n::t("Don't show notices"), $noinfo, ''],
  831. '$infinite_scroll' => ['infinite_scroll', L10n::t("Infinite scroll"), $infinite_scroll, ''],
  832. '$no_auto_update' => ['no_auto_update', L10n::t("Automatic updates only at the top of the network page"), $no_auto_update, L10n::t('When disabled, the network page is updated all the time, which could be confusing while reading.')],
  833. '$bandwidth_saver' => ['bandwidth_saver', L10n::t('Bandwidth Saver Mode'), $bandwidth_saver, L10n::t('When enabled, embedded content is not displayed on automatic updates, they only show on page reload.')],
  834. '$smart_threading' => ['smart_threading', L10n::t('Smart Threading'), $smart_threading, L10n::t('When enabled, suppress extraneous thread indentation while keeping it where it matters. Only works if threading is available and enabled.')],
  835. '$d_tset' => L10n::t('General Theme Settings'),
  836. '$d_ctset' => L10n::t('Custom Theme Settings'),
  837. '$d_cset' => L10n::t('Content Settings'),
  838. 'stitle' => L10n::t('Theme settings'),
  839. '$theme_config' => $theme_config,
  840. ]);
  841. $tpl = get_markup_template('settings/display_end.tpl');
  842. $a->page['end'] .= replace_macros($tpl, [
  843. '$theme' => ['theme', L10n::t('Display Theme:'), $theme_selected, '', $themes]
  844. ]);
  845. return $o;
  846. }
  847. /*
  848. * ACCOUNT SETTINGS
  849. */
  850. $profile = dba::selectFirst('profile', [], ['is-default' => true, 'uid' => local_user()]);
  851. if (!DBM::is_result($profile)) {
  852. notice(L10n::t('Unable to find your profile. Please contact your admin.') . EOL);
  853. return;
  854. }
  855. $username = $a->user['username'];
  856. $email = $a->user['email'];
  857. $nickname = $a->user['nickname'];
  858. $timezone = $a->user['timezone'];
  859. $language = $a->user['language'];
  860. $notify = $a->user['notify-flags'];
  861. $defloc = $a->user['default-location'];
  862. $openid = $a->user['openid'];
  863. $maxreq = $a->user['maxreq'];
  864. $expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
  865. $unkmail = $a->user['unkmail'];
  866. $cntunkmail = $a->user['cntunkmail'];
  867. $expire_items = PConfig::get(local_user(), 'expire', 'items', true);
  868. $expire_notes = PConfig::get(local_user(), 'expire', 'notes', true);
  869. $expire_starred = PConfig::get(local_user(), 'expire', 'starred', true);
  870. $expire_photos = PConfig::get(local_user(), 'expire', 'photos', false);
  871. $expire_network_only = PConfig::get(local_user(), 'expire', 'network_only', false);
  872. $suggestme = PConfig::get(local_user(), 'system', 'suggestme', false);
  873. // nowarn_insecure
  874. if (!strlen($a->user['timezone'])) {
  875. $timezone = date_default_timezone_get();
  876. }
  877. // Set the account type to "Community" when the page is a community page but the account type doesn't fit
  878. // This is only happening on the first visit after the update
  879. if (in_array($a->user['page-flags'], [PAGE_COMMUNITY, PAGE_PRVGROUP]) &&
  880. ($a->user['account-type'] != ACCOUNT_TYPE_COMMUNITY))
  881. $a->user['account-type'] = ACCOUNT_TYPE_COMMUNITY;
  882. $pageset_tpl = get_markup_template('settings/pagetypes.tpl');
  883. $pagetype = replace_macros($pageset_tpl, [
  884. '$account_types' => L10n::t("Account Types"),
  885. '$user' => L10n::t("Personal Page Subtypes"),
  886. '$community' => L10n::t("Community Forum Subtypes"),
  887. '$account_type' => $a->user['account-type'],
  888. '$type_person' => ACCOUNT_TYPE_PERSON,
  889. '$type_organisation' => ACCOUNT_TYPE_ORGANISATION,
  890. '$type_news' => ACCOUNT_TYPE_NEWS,
  891. '$type_community' => ACCOUNT_TYPE_COMMUNITY,
  892. '$account_person' => ['account-type', L10n::t('Personal Page'), ACCOUNT_TYPE_PERSON,
  893. L10n::t('Account for a personal profile.'),
  894. ($a->user['account-type'] == ACCOUNT_TYPE_PERSON)],
  895. '$account_organisation' => ['account-type', L10n::t('Organisation Page'), ACCOUNT_TYPE_ORGANISATION,
  896. L10n::t('Account for an organisation that automatically approves contact requests as "Followers".'),
  897. ($a->user['account-type'] == ACCOUNT_TYPE_ORGANISATION)],
  898. '$account_news' => ['account-type', L10n::t('News Page'), ACCOUNT_TYPE_NEWS,
  899. L10n::t('Account for a news reflector that automatically approves contact requests as "Followers".'),
  900. ($a->user['account-type'] == ACCOUNT_TYPE_NEWS)],
  901. '$account_community' => ['account-type', L10n::t('Community Forum'), ACCOUNT_TYPE_COMMUNITY,
  902. L10n::t('Account for community discussions.'),
  903. ($a->user['account-type'] == ACCOUNT_TYPE_COMMUNITY)],
  904. '$page_normal' => ['page-flags', L10n::t('Normal Account Page'), PAGE_NORMAL,
  905. L10n::t('Account for a regular personal profile that requires manual approval of "Friends" and "Followers".'),
  906. ($a->user['page-flags'] == PAGE_NORMAL)],
  907. '$page_soapbox' => ['page-flags', L10n::t('Soapbox Page'), PAGE_SOAPBOX,
  908. L10n::t('Account for a public profile that automatically approves contact requests as "Followers".'),
  909. ($a->user['page-flags'] == PAGE_SOAPBOX)],
  910. '$page_community' => ['page-flags', L10n::t('Public Forum'), PAGE_COMMUNITY,
  911. L10n::t('Automatically approves all contact requests.'),
  912. ($a->user['page-flags'] == PAGE_COMMUNITY)],
  913. '$page_freelove' => ['page-flags', L10n::t('Automatic Friend Page'), PAGE_FREELOVE,
  914. L10n::t('Account for a popular profile that automatically approves contact requests as "Friends".'),
  915. ($a->user['page-flags'] == PAGE_FREELOVE)],
  916. '$page_prvgroup' => ['page-flags', L10n::t('Private Forum [Experimental]'), PAGE_PRVGROUP,
  917. L10n::t('Requires manual approval of contact requests.'),
  918. ($a->user['page-flags'] == PAGE_PRVGROUP)],
  919. ]);
  920. $noid = Config::get('system', 'no_openid');
  921. if ($noid) {
  922. $openid_field = false;
  923. } else {
  924. $openid_field = ['openid_url', L10n::t('OpenID:'), $openid, L10n::t("\x28Optional\x29 Allow this OpenID to login to this account."), "", "", "url"];
  925. }
  926. $opt_tpl = get_markup_template("field_yesno.tpl");
  927. if (Config::get('system', 'publish_all')) {
  928. $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
  929. } else {
  930. $profile_in_dir = replace_macros($opt_tpl, [
  931. '$field' => ['profile_in_directory', L10n::t('Publish your default profile in your local site directory?'), $profile['publish'], L10n::t('Your profile will be published in this node\'s <a href="%s">local directory</a>. Your profile details may be publicly visible depending on the system settings.', System::baseUrl().'/directory'), [L10n::t('No'), L10n::t('Yes')]]
  932. ]);
  933. }
  934. if (strlen(Config::get('system', 'directory'))) {
  935. $profile_in_net_dir = replace_macros($opt_tpl, [
  936. '$field' => ['profile_in_netdirectory', L10n::t('Publish your default profile in the global social directory?'), $profile['net-publish'], L10n::t('Your profile will be published in the global friendica directories (e.g. <a href="%s">%s</a>). Your profile will be visible in public.', Config::get('system', 'directory'), Config::get('system', 'directory')), [L10n::t('No'), L10n::t('Yes')]]
  937. ]);
  938. } else {
  939. $profile_in_net_dir = '';
  940. }
  941. $hide_friends = replace_macros($opt_tpl, [
  942. '$field' => ['hide-friends', L10n::t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], L10n::t('Your contact list won\'t be shown in your default profile page. You can decide to show your contact list separately for each additional profile you create'), [L10n::t('No'), L10n::t('Yes')]],
  943. ]);
  944. $hide_wall = replace_macros($opt_tpl, [
  945. '$field' => ['hidewall', L10n::t('Hide your profile details from anonymous viewers?'), $a->user['hidewall'], L10n::t('Anonymous visitors will only see your profile picture, your display name and the nickname you are using on your profile page. Your public posts and replies will still be accessible by other means.'), [L10n::t('No'), L10n::t('Yes')]],
  946. ]);
  947. $blockwall = replace_macros($opt_tpl, [
  948. '$field' => ['blockwall', L10n::t('Allow friends to post to your profile page?'), (intval($a->user['blockwall']) ? '0' : '1'), L10n::t('Your contacts may write posts on your profile wall. These posts will be distributed to your contacts'), [L10n::t('No'), L10n::t('Yes')]],
  949. ]);
  950. $blocktags = replace_macros($opt_tpl, [
  951. '$field' => ['blocktags', L10n::t('Allow friends to tag your posts?'), (intval($a->user['blocktags']) ? '0' : '1'), L10n::t('Your contacts can add additional tags to your posts.'), [L10n::t('No'), L10n::t('Yes')]],
  952. ]);
  953. $suggestme = replace_macros($opt_tpl, [
  954. '$field' => ['suggestme', L10n::t('Allow us to suggest you as a potential friend to new members?'), $suggestme, L10n::t('If you like, Friendica may suggest new members to add you as a contact.'), [L10n::t('No'), L10n::t('Yes')]],
  955. ]);
  956. $unkmail = replace_macros($opt_tpl, [
  957. '$field' => ['unkmail', L10n::t('Permit unknown people to send you private mail?'), $unkmail, L10n::t('Friendica network users may send you private messages even if they are not in your contact list.'), [L10n::t('No'), L10n::t('Yes')]],
  958. ]);
  959. if (!$profile['publish'] && !$profile['net-publish']) {
  960. info(L10n::t('Profile is <strong>not published</strong>.') . EOL);
  961. }
  962. $tpl_addr = get_markup_template('settings/nick_set.tpl');
  963. $prof_addr = replace_macros($tpl_addr,[
  964. '$desc' => L10n::t("Your Identity Address is <strong>'%s'</strong> or '%s'.", $nickname . '@' . $a->get_hostname() . $a->get_path(), System::baseUrl() . '/profile/' . $nickname),
  965. '$basepath' => $a->get_hostname()
  966. ]);
  967. $stpl = get_markup_template('settings/settings.tpl');
  968. $expire_arr = [
  969. 'days' => ['expire', L10n::t("Automatically expire posts after this many days:"), $expire, L10n::t('If empty, posts will not expire. Expired posts will be deleted')],
  970. 'advanced' => L10n::t('Advanced expiration settings'),
  971. 'label' => L10n::t('Advanced Expiration'),
  972. 'items' => ['expire_items', L10n::t("Expire posts:"), $expire_items, '', [L10n::t('No'), L10n::t('Yes')]],
  973. 'notes' => ['expire_notes', L10n::t("Expire personal notes:"), $expire_notes, '', [L10n::t('No'), L10n::t('Yes')]],
  974. 'starred' => ['expire_starred', L10n::t("Expire starred posts:"), $expire_starred, '', [L10n::t('No'), L10n::t('Yes')]],
  975. 'photos' => ['expire_photos', L10n::t("Expire photos:"), $expire_photos, '', [L10n::t('No'), L10n::t('Yes')]],
  976. 'network_only' => ['expire_network_only', L10n::t("Only expire posts by others:"), $expire_network_only, '', [L10n::t('No'), L10n::t('Yes')]],
  977. ];
  978. $group_select = Group::displayGroupSelection(local_user(), $a->user['def_gid']);
  979. // Private/public post links for the non-JS ACL form
  980. $private_post = 1;
  981. if ($_REQUEST['public']) {
  982. $private_post = 0;
  983. }
  984. $query_str = $a->query_string;
  985. if (strpos($query_str, 'public=1') !== false) {
  986. $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
  987. }
  988. // I think $a->query_string may never have ? in it, but I could be wrong
  989. // It looks like it's from the index.php?q=[etc] rewrite that the web
  990. // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
  991. if (strpos($query_str, '?') === false) {
  992. $public_post_link = '?public=1';
  993. } else {
  994. $public_post_link = '&public=1';
  995. }
  996. /* Installed langs */
  997. $lang_choices = L10n::getAvailableLanguages();
  998. /// @TODO Fix indending (or so)
  999. $o .= replace_macros($stpl, [
  1000. '$ptitle' => L10n::t('Account Settings'),
  1001. '$submit' => L10n::t('Save Settings'),
  1002. '$baseurl' => System::baseUrl(true),
  1003. '$uid' => local_user(),
  1004. '$form_security_token' => get_form_security_token("settings"),
  1005. '$nickname_block' => $prof_addr,
  1006. '$h_pass' => L10n::t('Password Settings'),
  1007. '$password1'=> ['password', L10n::t('New Password:'), '', ''],
  1008. '$password2'=> ['confirm', L10n::t('Confirm:'), '', L10n::t('Leave password fields blank unless changing')],
  1009. '$password3'=> ['opassword', L10n::t('Current Password:'), '', L10n::t('Your current password to confirm the changes')],
  1010. '$password4'=> ['mpassword', L10n::t('Password:'), '', L10n::t('Your current password to confirm the changes')],
  1011. '$oid_enable' => (!Config::get('system', 'no_openid')),
  1012. '$openid' => $openid_field,
  1013. '$h_basic' => L10n::t('Basic Settings'),
  1014. '$username' => ['username', L10n::t('Full Name:'), $username, ''],
  1015. '$email' => ['email', L10n::t('Email Address:'), $email, '', '', '', 'email'],
  1016. '$timezone' => ['timezone_select' , L10n::t('Your Timezone:'), Temporal::getTimezoneSelect($timezone), ''],
  1017. '$language' => ['language', L10n::t('Your Language:'), $language, L10n::t('Set the language we use to show you friendica interface and to send you emails'), $lang_choices],
  1018. '$defloc' => ['defloc', L10n::t('Default Post Location:'), $defloc, ''],
  1019. '$allowloc' => ['allow_location', L10n::t('Use Browser Location:'), ($a->user['allow_location'] == 1), ''],
  1020. '$h_prv' => L10n::t('Security and Privacy Settings'),
  1021. '$maxreq' => ['maxreq', L10n::t('Maximum Friend Requests/Day:'), $maxreq , L10n::t("\x28to prevent spam abuse\x29")],
  1022. '$permissions' => L10n::t('Default Post Permissions'),
  1023. '$permdesc' => L10n::t("\x28click to open/close\x29"),
  1024. '$visibility' => $profile['net-publish'],
  1025. '$aclselect' => ACL::getFullSelectorHTML($a->user),
  1026. '$suggestme' => $suggestme,
  1027. '$blockwall'=> $blockwall, // array('blockwall', L10n::t('Allow friends to post to your profile page:'), !$blockwall, ''),
  1028. '$blocktags'=> $blocktags, // array('blocktags', L10n::t('Allow friends to tag your posts:'), !$blocktags, ''),
  1029. // ACL permissions box
  1030. '$group_perms' => L10n::t('Show to Groups'),
  1031. '$contact_perms' => L10n::t('Show to Contacts'),
  1032. '$private' => L10n::t('Default Private Post'),
  1033. '$public' => L10n::t('Default Public Post'),
  1034. '$is_private' => $private_post,
  1035. '$return_path' => $query_str,
  1036. '$public_link' => $public_post_link,
  1037. '$settings_perms' => L10n::t('Default Permissions for New Posts'),
  1038. '$group_select' => $group_select,
  1039. '$expire' => $expire_arr,
  1040. '$profile_in_dir' => $profile_in_dir,
  1041. '$profile_in_net_dir' => $profile_in_net_dir,
  1042. '$hide_friends' => $hide_friends,
  1043. '$hide_wall' => $hide_wall,
  1044. '$unkmail' => $unkmail,
  1045. '$cntunkmail' => ['cntunkmail', L10n::t('Maximum private messages per day from unknown people:'), $cntunkmail , L10n::t("\x28to prevent spam abuse\x29")],
  1046. '$h_not' => L10n::t('Notification Settings'),
  1047. '$lbl_not' => L10n::t('Send a notification email when:'),
  1048. '$notify1' => ['notify1', L10n::t('You receive an introduction'), ($notify & NOTIFY_INTRO), NOTIFY_INTRO, ''],
  1049. '$notify2' => ['notify2', L10n::t('Your introductions are confirmed'), ($notify & NOTIFY_CONFIRM), NOTIFY_CONFIRM, ''],
  1050. '$notify3' => ['notify3', L10n::t('Someone writes on your profile wall'), ($notify & NOTIFY_WALL), NOTIFY_WALL, ''],
  1051. '$notify4' => ['notify4', L10n::t('Someone writes a followup comment'), ($notify & NOTIFY_COMMENT), NOTIFY_COMMENT, ''],
  1052. '$notify5' => ['notify5', L10n::t('You receive a private message'), ($notify & NOTIFY_MAIL), NOTIFY_MAIL, ''],
  1053. '$notify6' => ['notify6', L10n::t('You receive a friend suggestion'), ($notify & NOTIFY_SUGGEST), NOTIFY_SUGGEST, ''],
  1054. '$notify7' => ['notify7', L10n::t('You are tagged in a post'), ($notify & NOTIFY_TAGSELF), NOTIFY_TAGSELF, ''],
  1055. '$notify8' => ['notify8', L10n::t('You are poked/prodded/etc. in a post'), ($notify & NOTIFY_POKE), NOTIFY_POKE, ''],
  1056. '$desktop_notifications' => ['desktop_notifications', L10n::t('Activate desktop notifications') , false, L10n::t('Show desktop popup on new notifications')],
  1057. '$email_textonly' => ['email_textonly', L10n::t('Text-only notification emails'),
  1058. PConfig::get(local_user(), 'system', 'email_textonly'),
  1059. L10n::t('Send text only notification emails, without the html part')],
  1060. '$detailed_notif' => ['detailed_notif', L10n::t('Show detailled notifications'),
  1061. PConfig::get(local_user(), 'system', 'detailed_notif'),
  1062. L10n::t('Per default, notifications are condensed to a single notification per item. When enabled every notification is displayed.')],
  1063. '$h_advn' => L10n::t('Advanced Account/Page Type Settings'),
  1064. '$h_descadvn' => L10n::t('Change the behaviour of this account for special situations'),
  1065. '$pagetype' => $pagetype,
  1066. '$relocate' => L10n::t('Relocate'),
  1067. '$relocate_text' => L10n::t("If you have moved this profile from another server, and some of your contacts don't receive your updates, try pushing this button."),
  1068. '$relocate_button' => L10n::t("Resend relocate message to contacts"),
  1069. ]);
  1070. Addon::callHooks('settings_form', $o);
  1071. $o .= '</form>' . "\r\n";
  1072. return $o;
  1073. }