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.

1368 lines
54KB

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