Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

1274 wiersze
56 KiB

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