Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
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.

settings.php 54KB

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