]> git.mxchange.org Git - friendica.git/blobdiff - mod/settings.php
Merge branch 'develop' into rewrites/dbm_is_result
[friendica.git] / mod / settings.php
index 37498a0ddaed8ff3d716e21d6cd001b132c970ea..9aa7c57624381219bf2e12b46ff7b5ee0a86374d 100644 (file)
@@ -16,9 +16,9 @@ function get_theme_config_file($theme){
        return null;
 }
 
-function settings_init(&$a) {
+function settings_init(App &$a) {
 
-       if(! local_user()) {
+       if (! local_user()) {
                notice( t('Permission denied.') . EOL );
                return;
        }
@@ -116,33 +116,35 @@ function settings_init(&$a) {
 }
 
 
-function settings_post(&$a) {
+function settings_post(App &$a) {
 
-       if(! local_user())
+       if (! local_user()) {
                return;
+       }
 
-       if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
+       if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
                return;
+       }
 
-       if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
+       if (count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
                notice( t('Permission denied.') . EOL);
                return;
        }
 
        $old_page_flags = $a->user['page-flags'];
 
-       if(($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')){
+       if (($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')) {
                check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
 
                $key = $_POST['remove'];
                q("DELETE FROM tokens WHERE id='%s' AND uid=%d",
                        dbesc($key),
                        local_user());
-               goaway($a->get_baseurl(true)."/settings/oauth/");
+               goaway(App::get_baseurl(true)."/settings/oauth/");
                return;
        }
 
-       if(($a->argc > 2) && ($a->argv[1] === 'oauth')  && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) {
+       if (($a->argc > 2) && ($a->argv[1] === 'oauth')  && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) {
 
                check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
 
@@ -183,7 +185,7 @@ function settings_post(&$a) {
                                                local_user());
                        }
                }
-               goaway($a->get_baseurl(true)."/settings/oauth/");
+               goaway(App::get_baseurl(true)."/settings/oauth/");
                return;
        }
 
@@ -225,7 +227,7 @@ function settings_post(&$a) {
                                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
                                        intval(local_user())
                                );
-                               if(! count($r)) {
+                               if (! dbm::is_result($r)) {
                                        q("INSERT INTO `mailacct` (`uid`) VALUES (%d)",
                                                intval(local_user())
                                        );
@@ -255,7 +257,7 @@ function settings_post(&$a) {
                                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
                                        intval(local_user())
                                );
-                               if(count($r)) {
+                               if (dbm::is_result($r)) {
                                        $eacct = $r[0];
                                        require_once('include/email.php');
                                        $mb = construct_mailbox_name($eacct);
@@ -279,7 +281,7 @@ function settings_post(&$a) {
                return;
        }
 
-       if(($a->argc > 1) && ($a->argv[1] === 'features')) {
+       if (($a->argc > 1) && ($a->argv[1] === 'features')) {
                check_form_security_token_redirectOnErr('/settings/features', 'settings_features');
                foreach($_POST as $k => $v) {
                        if(strpos($k,'feature_') === 0) {
@@ -290,49 +292,52 @@ function settings_post(&$a) {
                return;
        }
 
-       if(($a->argc > 1) && ($a->argv[1] === 'display')) {
-
+       if (($a->argc > 1) && ($a->argv[1] === 'display')) {
                check_form_security_token_redirectOnErr('/settings/display', 'settings_display');
 
-               $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme']))  : $a->user['theme']);
-               $mobile_theme = ((x($_POST,'mobile_theme')) ? notags(trim($_POST['mobile_theme']))  : '');
-               $nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile'])  : 0);
-               $first_day_of_week = ((x($_POST,'first_day_of_week')) ? intval($_POST['first_day_of_week'])  : 0);
-               $noinfo = ((x($_POST,'noinfo')) ? intval($_POST['noinfo'])  : 0);
-               $infinite_scroll = ((x($_POST,'infinite_scroll')) ? intval($_POST['infinite_scroll'])  : 0);
-               $no_auto_update = ((x($_POST,'no_auto_update')) ? intval($_POST['no_auto_update'])  : 0);
-               $browser_update   = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0);
+               $theme             = x($_POST, 'theme')             ? notags(trim($_POST['theme']))        : $a->user['theme'];
+               $mobile_theme      = x($_POST, 'mobile_theme')      ? notags(trim($_POST['mobile_theme'])) : '';
+               $nosmile           = x($_POST, 'nosmile')           ? intval($_POST['nosmile'])            : 0;
+               $first_day_of_week = x($_POST, 'first_day_of_week') ? intval($_POST['first_day_of_week'])  : 0;
+               $noinfo            = x($_POST, 'noinfo')            ? intval($_POST['noinfo'])             : 0;
+               $infinite_scroll   = x($_POST, 'infinite_scroll')   ? intval($_POST['infinite_scroll'])    : 0;
+               $no_auto_update    = x($_POST, 'no_auto_update')    ? intval($_POST['no_auto_update'])     : 0;
+               $bandwidth_saver   = x($_POST, 'bandwidth_saver')   ? intval($_POST['bandwidth_saver'])    : 0;
+               $nowarn_insecure   = x($_POST, 'nowarn_insecure')   ? intval($_POST['nowarn_insecure'])    : 0;
+               $browser_update    = x($_POST, 'browser_update')    ? intval($_POST['browser_update'])     : 0;
                if ($browser_update != -1) {
-                       $browser_update   = $browser_update * 1000;
+                       $browser_update = $browser_update * 1000;
                        if ($browser_update < 10000)
                                $browser_update = 10000;
                }
 
-               $itemspage_network   = ((x($_POST,'itemspage_network')) ? intval($_POST['itemspage_network']) : 40);
-               if($itemspage_network > 100)
+               $itemspage_network = x($_POST,'itemspage_network')  ? intval($_POST['itemspage_network'])  : 40;
+               if ($itemspage_network > 100) {
                        $itemspage_network = 100;
-               $itemspage_mobile_network   = ((x($_POST,'itemspage_mobile_network')) ? intval($_POST['itemspage_mobile_network']) : 20);
-               if($itemspage_mobile_network > 100)
+               }
+               $itemspage_mobile_network = x($_POST,'itemspage_mobile_network') ? intval($_POST['itemspage_mobile_network']) : 20;
+               if ($itemspage_mobile_network > 100) {
                        $itemspage_mobile_network = 100;
-
+               }
 
                if($mobile_theme !== '') {
                        set_pconfig(local_user(),'system','mobile_theme',$mobile_theme);
                }
 
-               set_pconfig(local_user(),'system','update_interval', $browser_update);
-               set_pconfig(local_user(),'system','itemspage_network', $itemspage_network);
-               set_pconfig(local_user(),'system','itemspage_mobile_network', $itemspage_mobile_network);
-               set_pconfig(local_user(),'system','no_smilies',$nosmile);
-               set_pconfig(local_user(),'system','first_day_of_week',$first_day_of_week);
-               set_pconfig(local_user(),'system','ignore_info',$noinfo);
-               set_pconfig(local_user(),'system','infinite_scroll',$infinite_scroll);
-               set_pconfig(local_user(),'system','no_auto_update',$no_auto_update);
-
-
-               if ($theme == $a->user['theme']){
+               set_pconfig(local_user(), 'system', 'nowarn_insecure'         , $nowarn_insecure);
+               set_pconfig(local_user(), 'system', 'update_interval'         , $browser_update);
+               set_pconfig(local_user(), 'system', 'itemspage_network'       , $itemspage_network);
+               set_pconfig(local_user(), 'system', 'itemspage_mobile_network', $itemspage_mobile_network);
+               set_pconfig(local_user(), 'system', 'no_smilies'              , $nosmile);
+               set_pconfig(local_user(), 'system', 'first_day_of_week'       , $first_day_of_week);
+               set_pconfig(local_user(), 'system', 'ignore_info'             , $noinfo);
+               set_pconfig(local_user(), 'system', 'infinite_scroll'         , $infinite_scroll);
+               set_pconfig(local_user(), 'system', 'no_auto_update'          , $no_auto_update);
+               set_pconfig(local_user(), 'system', 'bandwidth_saver'         , $bandwidth_saver);
+
+               if ($theme == $a->user['theme']) {
                        // call theme_post only if theme has not been changed
-                       if( ($themeconfigfile = get_theme_config_file($theme)) != null){
+                       if (($themeconfigfile = get_theme_config_file($theme)) != null) {
                                require_once($themeconfigfile);
                                theme_post($a);
                        }
@@ -625,8 +630,9 @@ function settings_post(&$a) {
        if(($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) {
                // Update global directory in background
                $url = $_SESSION['my_url'];
-               if($url && strlen(get_config('system','directory')))
+               if ($url && strlen(get_config('system','directory'))) {
                        proc_run(PRIORITY_LOW, "include/directory.php", $url);
+               }
        }
 
        require_once('include/profile_update.php');
@@ -648,17 +654,17 @@ function settings_post(&$a) {
 }
 
 
-function settings_content(&$a) {
+function settings_content(App &$a) {
 
        $o = '';
        nav_set_selected('settings');
 
-       if(! local_user()) {
+       if (! local_user()) {
                #notice( t('Permission denied.') . EOL );
                return;
        }
 
-       if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
+       if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
                notice( t('Permission denied.') . EOL );
                return;
        }
@@ -688,7 +694,7 @@ function settings_content(&$a) {
                                        dbesc($a->argv[3]),
                                        local_user());
 
-                       if (!count($r)){
+                       if (!dbm::is_result($r)){
                                notice(t("You can't edit this application."));
                                return;
                        }
@@ -715,7 +721,7 @@ function settings_content(&$a) {
                        $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
                                        dbesc($a->argv[3]),
                                        local_user());
-                       goaway($a->get_baseurl(true)."/settings/oauth/");
+                       goaway(App::get_baseurl(true)."/settings/oauth/");
                        return;
                }
 
@@ -731,7 +737,7 @@ function settings_content(&$a) {
                $tpl = get_markup_template("settings_oauth.tpl");
                $o .= replace_macros($tpl, array(
                        '$form_security_token' => get_form_security_token("settings_oauth"),
-                       '$baseurl'      => $a->get_baseurl(true),
+                       '$baseurl'      => App::get_baseurl(true),
                        '$title'        => t('Connected Apps'),
                        '$add'          => t('Add application'),
                        '$edit'         => t('Edit'),
@@ -749,8 +755,9 @@ function settings_content(&$a) {
                $settings_addons = "";
 
                $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
-               if(! count($r))
+               if (! dbm::is_result($r)) {
                        $settings_addons = t('No Plugin settings configured');
+               }
 
                call_hooks('plugin_settings', $settings_addons);
 
@@ -818,8 +825,10 @@ function settings_content(&$a) {
 
                $settings_connectors .= mini_group_select(local_user(), $default_group, t("Default group for OStatus contacts"));
 
-               if ($legacy_contact != "")
-                       $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
+               /// @TODO Found to much different usage to test empty/non-empty strings (e.g. empty(), trim() == '' ) which is wanted?
+               if ($legacy_contact != "") {
+                       $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
+               }
 
                $settings_connectors .= '<div id="legacy-contact-wrapper" class="field input">';
                $settings_connectors .= '<label id="legacy-contact-label" for="snautofollow-checkbox">'. t('Your legacy GNU Social account'). '</label>';
@@ -827,7 +836,7 @@ function settings_content(&$a) {
                $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>';
                $settings_connectors .= '</div>';
 
-               $settings_connectors .= '<p><a href="'.$a->get_baseurl().'/repair_ostatus">'.t("Repair OStatus subscriptions").'</a></p>';
+               $settings_connectors .= '<p><a href="'.App::get_baseurl().'/repair_ostatus">'.t("Repair OStatus subscriptions").'</a></p>';
 
                $settings_connectors .= '<div class="settings-submit-wrapper" ><input type="submit" name="general-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
 
@@ -856,15 +865,15 @@ function settings_content(&$a) {
                        $r = null;
                }
 
-               $mail_server       = ((count($r)) ? $r[0]['server'] : '');
-               $mail_port         = ((count($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
-               $mail_ssl          = ((count($r)) ? $r[0]['ssltype'] : '');
-               $mail_user         = ((count($r)) ? $r[0]['user'] : '');
-               $mail_replyto      = ((count($r)) ? $r[0]['reply_to'] : '');
-               $mail_pubmail      = ((count($r)) ? $r[0]['pubmail'] : 0);
-               $mail_action       = ((count($r)) ? $r[0]['action'] : 0);
-               $mail_movetofolder = ((count($r)) ? $r[0]['movetofolder'] : '');
-               $mail_chk          = ((count($r)) ? $r[0]['last_check'] : '0000-00-00 00:00:00');
+               $mail_server       = ((dbm::is_result($r)) ? $r[0]['server'] : '');
+               $mail_port         = ((dbm::is_result($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
+               $mail_ssl          = ((dbm::is_result($r)) ? $r[0]['ssltype'] : '');
+               $mail_user         = ((dbm::is_result($r)) ? $r[0]['user'] : '');
+               $mail_replyto      = ((dbm::is_result($r)) ? $r[0]['reply_to'] : '');
+               $mail_pubmail      = ((dbm::is_result($r)) ? $r[0]['pubmail'] : 0);
+               $mail_action       = ((dbm::is_result($r)) ? $r[0]['action'] : 0);
+               $mail_movetofolder = ((dbm::is_result($r)) ? $r[0]['movetofolder'] : '');
+               $mail_chk          = ((dbm::is_result($r)) ? $r[0]['last_check'] : '0000-00-00 00:00:00');
 
 
                $tpl = get_markup_template("settings_connectors.tpl");
@@ -950,6 +959,8 @@ function settings_content(&$a) {
                $theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']);
                $mobile_theme_selected = (!x($_SESSION,'mobile-theme')? $default_mobile_theme : $_SESSION['mobile-theme']);
 
+               $nowarn_insecure = intval(get_pconfig(local_user(), 'system', 'nowarn_insecure'));
+
                $browser_update = intval(get_pconfig(local_user(), 'system','update_interval'));
                if (intval($browser_update) != -1)
                        $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
@@ -975,8 +986,11 @@ function settings_content(&$a) {
                $no_auto_update = get_pconfig(local_user(),'system','no_auto_update');
                $no_auto_update = (($no_auto_update===false)? '0': $no_auto_update); // default if not set: 0
 
+               $bandwidth_saver = get_pconfig(local_user(), 'system', 'bandwidth_saver');
+               $bandwidth_saver = (($bandwidth_saver === false) ? '0' : $bandwidth_saver); // default if not set: 0
+
                $theme_config = "";
-               if( ($themeconfigfile = get_theme_config_file($theme_selected)) != null){
+               if (($themeconfigfile = get_theme_config_file($theme_selected)) != null) {
                        require_once($themeconfigfile);
                        $theme_config = theme_content($a);
                }
@@ -986,11 +1000,12 @@ function settings_content(&$a) {
                        '$ptitle'       => t('Display Settings'),
                        '$form_security_token' => get_form_security_token("settings_display"),
                        '$submit'       => t('Save Settings'),
-                       '$baseurl' => $a->get_baseurl(true),
+                       '$baseurl' => App::get_baseurl(true),
                        '$uid' => local_user(),
 
                        '$theme'        => array('theme', t('Display Theme:'), $theme_selected, '', $themes, true),
                        '$mobile_theme' => array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, false),
+                       '$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.")),
                        '$ajaxint'   => array('browser_update',  t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds. Enter -1 to disable it.')),
                        '$itemspage_network'   => array('itemspage_network',  t("Number of items to display per page:"), $itemspage_network, t('Maximum of 100 items')),
                        '$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')),
@@ -1000,6 +1015,7 @@ function settings_content(&$a) {
                        '$noinfo'       => array('noinfo', t("Don't show notices"), $noinfo, ''),
                        '$infinite_scroll'      => array('infinite_scroll', t("Infinite scroll"), $infinite_scroll, ''),
                        '$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.'),
+                       '$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.')),
 
                        '$d_tset' => t('General Theme Settings'),
                        '$d_ctset' => t('Custom Theme Settings'),
@@ -1207,7 +1223,7 @@ function settings_content(&$a) {
        $tpl_addr = get_markup_template("settings_nick_set.tpl");
 
        $prof_addr = replace_macros($tpl_addr,array(
-               '$desc' => sprintf(t("Your Identity Address is <strong>'%s'</strong> or '%s'."), $nickname.'@'.$a->get_hostname().$a->get_path(), $a->get_baseurl().'/profile/'.$nickname),
+               '$desc' => sprintf(t("Your Identity Address is <strong>'%s'</strong> or '%s'."), $nickname.'@'.$a->get_hostname().$a->get_path(), App::get_baseurl().'/profile/'.$nickname),
                '$basepath' => $a->get_hostname()
        ));
 
@@ -1246,13 +1262,13 @@ function settings_content(&$a) {
                $public_post_link = '&public=1';
 
        /* Installed langs */
-       $lang_choices = get_avaiable_languages();
+       $lang_choices = get_available_languages();
 
        $o .= replace_macros($stpl, array(
                '$ptitle'       => t('Account Settings'),
 
                '$submit'       => t('Save Settings'),
-               '$baseurl' => $a->get_baseurl(true),
+               '$baseurl' => App::get_baseurl(true),
                '$uid' => local_user(),
                '$form_security_token' => get_form_security_token("settings"),
                '$nickname_block' => $prof_addr,
@@ -1347,4 +1363,3 @@ function settings_content(&$a) {
        return $o;
 
 }
-