]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Patch for PITS 00032, 00033, 00034
authormatthew.gregg <matthew.gregg@gmail.com>
Sat, 19 Jul 2008 00:34:17 +0000 (20:34 -0400)
committermatthew.gregg <matthew.gregg@gmail.com>
Sat, 19 Jul 2008 00:34:17 +0000 (20:34 -0400)
darcs-hash:20080719003417-982e4-7004f8a4dfb447f941457c30b0b2289eee5582e6.gz

actions/profilesettings.php
classes/User.php
db/laconica.sql
lib/common.php
lib/language.php [new file with mode: 0644]
lib/util.php

index b703c8b2b05980af0c3b559a46c5cfb2e14bfc20..04526a212281dd226d1158c7034129bff3999ecd 100644 (file)
@@ -52,8 +52,6 @@ class ProfilesettingsAction extends SettingsAction {
                common_input('location', _('Location'),
                                         ($this->arg('location')) ? $this->arg('location') : $profile->location,
                                         _('Where you are, like "City, State (or Region), Country"'));
-               common_checkbox('autosubscribe', _('Automatically subscribe to whoever subscribes to me (best for non-humans)'),
-                                               ($this->arg('autosubscribe')) ? $this->boolean('autosubscribe') : $user->autosubscribe);
                common_submit('submit', _('Save'));
                common_element_end('form');
                common_show_footer();
@@ -66,8 +64,7 @@ class ProfilesettingsAction extends SettingsAction {
                $homepage = $this->trimmed('homepage');
                $bio = $this->trimmed('bio');
                $location = $this->trimmed('location');
-               $autosubscribe = $this->boolean('autosubscribe');
-               
+
                # Some validation
 
                if (!Validate::string($nickname, array('min_length' => 1,
@@ -94,6 +91,8 @@ class ProfilesettingsAction extends SettingsAction {
                } else if ($this->nickname_exists($nickname)) {
                        $this->show_form(_('Nickname already in use. Try another one.'));
                        return;
+                } else if (!is_null($language) && strlen($language) > 50) {
+                        $this->show_form(_('Language is too long (max 50 chars).'));
                }
 
                $user = common_current_user();
@@ -117,6 +116,23 @@ class ProfilesettingsAction extends SettingsAction {
                                return;
                        }
                }
+               if ($user->language != $language) {
+
+                       common_debug('Updating user language from ' . $user->language . ' to ' . $language,
+                                                __FILE__);
+
+                       $original = clone($user);
+
+                       $user->language = $language;
+
+                       $result = $user->updateKeys($original);
+
+                       if ($result === FALSE) {
+                               common_log_db_error($user, 'UPDATE', __FILE__);
+                               common_server_error(_('Couldn\'t update user.'));
+                               return;
+                       }
+               }
 
                # XXX: XOR
                
index b6689761eec4159faf62fbd15da775fe02a2f197..515d32b2bb09a7717e55f329d07d897cd99b1b53 100644 (file)
@@ -79,7 +79,7 @@ class User extends DB_DataObject
 
        function updateKeys(&$orig) {
                $parts = array();
-               foreach (array('nickname', 'email', 'jabber', 'incomingemail', 'sms', 'carrier', 'smsemail') as $k) {
+               foreach (array('nickname', 'email', 'jabber', 'sms', 'carrier') as $k) {
                        if (strcmp($this->$k, $orig->$k) != 0) {
                                $parts[] = $k . ' = ' . $this->_quote($this->$k);
                        }
index 277b792e357fac23bbdbe05b53d931439562be2a..fe191804597d4433437f3843879d3d20f19c292c 100644 (file)
@@ -47,7 +47,6 @@ create table user (
     email varchar(255) unique key comment 'email address for password recovery etc.',
     incomingemail varchar(255) unique key comment 'email address for post-by-email',
     emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
-    emailpost tinyint default 1 comment 'Post by email',
     jabber varchar(255) unique key comment 'jabber ID for notices',
     jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
     jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
index 5181712491987df1f5dd2a5fad62d640c4c016aa..04242432c6d30b8aa9d9d5c2e43c701f1d9e0cd4 100644 (file)
@@ -36,6 +36,8 @@ require_once('PEAR.php');
 require_once('DB/DataObject.php');
 require_once('DB/DataObject/Cast.php'); # for dates
 
+require_once(INSTALLDIR.'/lib/language.php');
+
 // default configuration, overwritten in config.php
 
 $config =
@@ -46,6 +48,9 @@ $config =
                          'path' => '/',
                          'logfile' => NULL,
                          'fancy' => false,
+                          'locale_path' => './locale',
+                          'language' => 'en_US',
+                          'languages' => get_all_languages(),
                      'email' => 
                      array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
                          'broughtby' => NULL,
diff --git a/lib/language.php b/lib/language.php
new file mode 100644 (file)
index 0000000..c3532d7
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+
+
+function client_prefered_language($httplang) {
+        $client_langs = array();
+        $all_languages = get_all_languages();
+
+        preg_match_all('"(((\S\S)-?(\S\S)?)(;q=([0-9.]+))?)\s*(,\s*|$)"',strtolower($httplang),$httplang);
+        for ($i = 0; $i < count($httplang); $i++) {
+             if(!empty($httplang[2][$i])) {
+                    #if no q default to 1.0
+                    $client_langs[$httplang[2][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i] : 1.0);
+                }
+                if(!empty($httplang[3][$i]) && empty($client_langs[$httplang[3][$i]])) {
+                    #if a catchall default 0.01 lower
+                    $client_langs[$httplang[3][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i]-0.01 : 0.99);
+                }
+            }
+            #sort in decending q
+            arsort($client_langs);
+
+            foreach ($client_langs as $lang => $q) {
+                if (isset($all_languages[$lang])) {
+                    return($all_languages[$lang]['lang']);
+                }
+            }
+            return FALSE;
+}
+
+function get_nice_language_list() {
+        $nice_lang = array();
+        $all_languages = get_all_languages();
+        foreach ($all_languages as $lang) {
+                $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']);
+        }
+        return $nice_lang;
+}
+
+function get_all_languages() {
+        $all_languages = array('en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'),
+                            'en-nz' => array('q' => 1, 'lang' => 'en_NZ', 'name' => 'English (NZ)', 'direction' => 'ltr'),
+                            'en' => array('q' => 1, 'lang' => 'en', 'name' => 'English', 'direction' => 'ltr'),
+                            'fr-fr' => array('q' => 1, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'),
+                        );
+        return $all_languages;
+}
index 6d409f9436de14e633d7db4cdbb4277343ac3a10..af31a9bd4f14227d4273c89582d150f96e0b00cb 100644 (file)
@@ -137,6 +137,10 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
        global $config, $xw;
 
        $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL;
+        $language = common_language();
+        setlocale(LC_ALL, $language);
+        bindtextdomain("laconica", $config['site']['locale_path']);
+        textdomain("laconica");
 
        # XXX: allow content negotiation for RDF, RSS, or XRDS
 
@@ -157,8 +161,8 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
        # FIXME: correct language for interface
 
        common_element_start('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
-                                                                          'xml:lang' => 'en',
-                                                                          'lang' => 'en'));
+                                                                          'xml:lang' => $language,
+                                                                          'lang' => $language));
 
        common_element_start('head');
        common_element('title', NULL,
@@ -363,6 +367,26 @@ function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value
        common_element_end('p');
 }
 
+function common_dropdown($id, $label, $content, $instructions=NULL, $blank_select=FALSE, $selected=NULL) {
+        common_element_start('p');
+        common_element('label', array('for' => $id), $label);
+        common_element_start('select', array('id' => $id, 'name' => $id));
+        if ($blank_select) {
+                        common_element('option', array('value' => $value));
+        }
+        foreach ($content as $value => $option) {
+                if ($value == $selected) {
+                        common_element('option', array('value' => $value, 'selected' => $value), $option);
+                } else {
+                        common_element('option', array('value' => $value), $option);
+                }
+        }
+        common_element_end('select');
+       if ($instructions) {
+               common_element('span', 'input_instructions', $instructions);
+       }
+       common_element_end('p');
+}
 function common_hidden($id, $value) {
        common_element('input', array('name' => $id,
                                                                  'type' => 'hidden',
@@ -409,6 +433,27 @@ function common_textarea($id, $label, $content=NULL, $instructions=NULL) {
        common_element_end('p');
 }
 
+function common_language() {
+       $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL;
+        $language = array();
+        $user_language = FALSE;
+
+        if (common_logged_in()) {
+                $user = common_current_user();
+                $user_language = $user->language;
+        }
+
+        if ($user_language) {
+                return $user_language;
+        } else if (!empty($httplang)) {
+                $language = client_prefered_language($httplang);
+                if ($language) {
+                    return $language;
+                }
+        } else {
+                return $config['site']['language'];
+        }
+}
 # salted, hashed passwords are stored in the DB
 
 function common_munge_password($password, $id) {