mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 03:51:59 +01:00
use the browsers language preferences instead of the settings page
This commit is contained in:
parent
3e0ad6da34
commit
d68ffad8a6
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
define('LANG', 'en');
|
define('DEFAULT_LANG', 'en');
|
||||||
define('THEME', 'default');
|
define('THEME', 'default');
|
||||||
|
|
||||||
define('SITE_NAME', 'demo.mailpiler.org');
|
define('SITE_NAME', 'demo.mailpiler.org');
|
||||||
|
@ -19,10 +19,10 @@ class ControllerUserSettings extends Controller {
|
|||||||
|
|
||||||
$this->document->title = $this->data['text_settings'];
|
$this->document->title = $this->data['text_settings'];
|
||||||
|
|
||||||
if(isset($this->request->post['pagelen']) && isset($this->request->post['lang']) && isset($this->request->post['theme'])) {
|
if(isset($this->request->post['pagelen']) && isset($this->request->post['theme'])) {
|
||||||
$this->model_user_prefs->set_user_preferences(Registry::get('username'), $this->request->post);
|
$this->model_user_prefs->set_user_preferences(Registry::get('username'), $this->request->post);
|
||||||
|
|
||||||
AUDIT(ACTION_CHANGE_USER_SETTINGS, '', '', '', 'lang:' . $this->request->post['lang'] . ', pagelen:' . $this->request->post['pagelen'] . ', theme:' . $this->request->post['theme']);
|
AUDIT(ACTION_CHANGE_USER_SETTINGS, '', '', '', 'pagelen:' . $this->request->post['pagelen'] . ', theme:' . $this->request->post['theme']);
|
||||||
|
|
||||||
Header("Location: settings.php");
|
Header("Location: settings.php");
|
||||||
return;
|
return;
|
||||||
|
@ -8,7 +8,6 @@ class ModelUserPrefs extends Model {
|
|||||||
$query = $this->db->query("SELECT * FROM " . TABLE_USER_SETTINGS . " WHERE username=?", array($username));
|
$query = $this->db->query("SELECT * FROM " . TABLE_USER_SETTINGS . " WHERE username=?", array($username));
|
||||||
|
|
||||||
if(isset($query->row['pagelen'])) { $_SESSION['pagelen'] = $query->row['pagelen']; } else { $_SESSION['pagelen'] = PAGE_LEN; }
|
if(isset($query->row['pagelen'])) { $_SESSION['pagelen'] = $query->row['pagelen']; } else { $_SESSION['pagelen'] = PAGE_LEN; }
|
||||||
if(isset($query->row['lang'])) { $_SESSION['lang'] = $query->row['lang']; } else { $_SESSION['lang'] = LANG; }
|
|
||||||
if(isset($query->row['theme'])) { $_SESSION['theme'] = $query->row['theme']; } else { $_SESSION['theme'] = THEME; }
|
if(isset($query->row['theme'])) { $_SESSION['theme'] = $query->row['theme']; } else { $_SESSION['theme'] = THEME; }
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -18,21 +17,19 @@ class ModelUserPrefs extends Model {
|
|||||||
public function set_user_preferences($username = '', $prefs = array() ) {
|
public function set_user_preferences($username = '', $prefs = array() ) {
|
||||||
|
|
||||||
if(!isset($prefs['pagelen']) || !is_numeric($prefs['pagelen']) || $prefs['pagelen'] < 10 || $prefs['pagelen'] > 100
|
if(!isset($prefs['pagelen']) || !is_numeric($prefs['pagelen']) || $prefs['pagelen'] < 10 || $prefs['pagelen'] > 100
|
||||||
|| !isset($prefs['lang']) || strlen($prefs['lang']) != 2 || !file_exists(DIR_LANGUAGE . $prefs['lang'])
|
|
||||||
|| !isset($prefs['theme']) || !preg_match("/^([a-zA-Z0-9\-\_]+)$/", $prefs['theme']) || !file_exists(DIR_THEME . $prefs['theme']) ) { return 1; }
|
|| !isset($prefs['theme']) || !preg_match("/^([a-zA-Z0-9\-\_]+)$/", $prefs['theme']) || !file_exists(DIR_THEME . $prefs['theme']) ) { return 1; }
|
||||||
|
|
||||||
$query = $this->db->query("SELECT COUNT(*) AS num FROM " . TABLE_USER_SETTINGS . " WHERE username=?", array($username));
|
$query = $this->db->query("SELECT COUNT(*) AS num FROM " . TABLE_USER_SETTINGS . " WHERE username=?", array($username));
|
||||||
|
|
||||||
if((int)@$query->row['num'] == 1) {
|
if((int)@$query->row['num'] == 1) {
|
||||||
$query = $this->db->query("UPDATE " . TABLE_USER_SETTINGS . " SET lang=?, pagelen=?, theme=? WHERE username=?", array($prefs['lang'], (int)@$prefs['pagelen'], $prefs['theme'], $username));
|
$query = $this->db->query("UPDATE " . TABLE_USER_SETTINGS . " SET pagelen=?, theme=? WHERE username=?", array((int)@$prefs['pagelen'], $prefs['theme'], $username));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = $this->db->query("INSERT INTO " . TABLE_USER_SETTINGS . " (username, pagelen, lang, theme) VALUES(?,?,?,?)", array($username, (int)@$prefs['pagelen'], $prefs['lang'], $prefs['theme']));
|
$query = $this->db->query("INSERT INTO " . TABLE_USER_SETTINGS . " (username, pagelen, theme) VALUES(?,?,?)", array($username, (int)@$prefs['pagelen'], $prefs['theme']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$_SESSION['pagelen'] = $prefs['pagelen'];
|
$_SESSION['pagelen'] = $prefs['pagelen'];
|
||||||
$_SESSION['lang'] = $prefs['lang'];
|
|
||||||
$_SESSION['theme'] = $prefs['theme'];
|
$_SESSION['theme'] = $prefs['theme'];
|
||||||
|
|
||||||
LOGGER("set user preference", $username);
|
LOGGER("set user preference", $username);
|
||||||
|
@ -5,13 +5,32 @@ class Language {
|
|||||||
|
|
||||||
|
|
||||||
public function __construct () {
|
public function __construct () {
|
||||||
|
global $langs;
|
||||||
|
|
||||||
|
$lang = '';
|
||||||
|
|
||||||
if(isset($_SESSION['lang'])) {
|
if(isset($_SESSION['lang'])) {
|
||||||
$file = DIR_LANGUAGE . $_SESSION['lang'] . '/messages.php';
|
$file = DIR_LANGUAGE . $_SESSION['lang'] . '/messages.php';
|
||||||
} else {
|
}
|
||||||
$file = DIR_LANGUAGE . LANG . '/messages.php';
|
else {
|
||||||
|
$pref_langs = $this->get_preferred_languages();
|
||||||
|
|
||||||
|
while(list($k, $v) = each($pref_langs)) {
|
||||||
|
if(in_array($v, $langs)) {
|
||||||
|
$lang = $v;
|
||||||
|
define('LANG', $lang);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lang == '') { $lang = DEFAULT_LANG; }
|
||||||
|
|
||||||
|
$_SESSION['lang'] = $lang;
|
||||||
|
|
||||||
|
$file = DIR_LANGUAGE . $lang . '/messages.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($file)) {
|
if(file_exists($file)) {
|
||||||
$_ = array();
|
$_ = array();
|
||||||
|
|
||||||
require($file);
|
require($file);
|
||||||
@ -25,6 +44,29 @@ class Language {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function get_preferred_languages() {
|
||||||
|
$langs = array();
|
||||||
|
|
||||||
|
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||||
|
|
||||||
|
$l = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
|
||||||
|
while(list($k, $v) = each($l)) {
|
||||||
|
$a = explode(",", $v);
|
||||||
|
|
||||||
|
if(isset($a[0]) && substr($a[0], 0, 2) != 'q=') {
|
||||||
|
array_push($langs, $a[0]);
|
||||||
|
}
|
||||||
|
if(isset($a[1])) { array_push($langs, $a[1]); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($langs, DEFAULT_LANG);
|
||||||
|
|
||||||
|
return $langs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function get($key) {
|
public function get($key) {
|
||||||
return (isset($this->data[$key]) ? $this->data[$key] : $key);
|
return (isset($this->data[$key]) ? $this->data[$key] : $key);
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="cell1"><?php print $text_language; ?>:</div>
|
|
||||||
<div class="cell2">
|
|
||||||
<select name="lang">
|
|
||||||
<?php foreach(Registry::get('langs') as $t) { ?>
|
|
||||||
<option value="<?php print $t; ?>"<?php if(isset($_SESSION['lang']) && $_SESSION['lang'] == $t) { ?> selected="selected"<?php } ?>><?php print $t; ?></option>
|
|
||||||
<?php } ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="cell1"><?php print $text_theme; ?>:</div>
|
<div class="cell1"><?php print $text_theme; ?>:</div>
|
||||||
<div class="cell2">
|
<div class="cell2">
|
||||||
|
Loading…
Reference in New Issue
Block a user