3 commits - lib/kolab_api_controller.php lib/kolab_client_task.php public_html/js
Aleksander Machniak
machniak at kolabsys.com
Thu Feb 23 11:48:38 CET 2012
lib/kolab_api_controller.php | 67 ++++++++++++++++++++++--------
lib/kolab_client_task.php | 93 ++++++++++++++++++++++++++----------------
public_html/js/kolab_admin.js | 8 +--
3 files changed, 111 insertions(+), 57 deletions(-)
New commits:
commit 4bf2d1c7d09bd20bccc0b6449486804899e53b91
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Feb 23 11:45:08 2012 +0100
Added system.configure action
diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index 87cdbc2..b9885ca 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -256,6 +256,8 @@ class kolab_api_controller
*
* @param array GET request parameters
* @param array POST data
+ *
+ * @param array|false Authentication result
*/
private function authenticate($request, $postdata)
{
@@ -308,7 +310,8 @@ class kolab_api_controller
$domain_name = is_array($domain) ? $domain['associateddomain'] : $domain;
// define our very own capabilities
$actions = array(
- 'system.quit' => array('type' => 'w'),
+ 'system.quit' => array('type' => 'w'),
+ 'system.configure' => array('type' => 'w'),
);
foreach ($this->services as $sname => $handler) {
@@ -350,6 +353,36 @@ class kolab_api_controller
}
}
+ /**
+ * Configure current user session parameters
+ *
+ * @param array $request GET request parameters
+ * @param array $postdata POST data
+ *
+ * @return array|false
+ */
+ private function configure($request, $postdata)
+ {
+ if (!$this->session_validate($postdata)) {
+ return false;
+ }
+
+ $result = array();
+
+ foreach ($postdata as $key => $value) {
+ switch ($key) {
+ case 'language':
+ if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $value)) {
+ $_SESSION['language'] = $value;
+ $result[$key] = $value;
+ }
+ break;
+ }
+ }
+
+ return $result;
+ }
+
/* ======== Utility functions ======== */
@@ -358,24 +391,22 @@ class kolab_api_controller
*/
private function locale_init()
{
- // @TODO: read language from logged user data
$lang = 'en_US';
- if ($lang != 'en_US' && file_exists(INSTALL_PATH . "/locale/$lang.api.php")) {
- $language = $lang;
+ // @TODO: read language of logged user in authenticate?
+ if (!empty($_SESSION['language'])) {
+ $lang = $_SESSION['language'];
}
$LANG = array();
@include INSTALL_PATH . '/locale/en_US.api.php';
- if (isset($language)) {
+ if ($lang != 'en_US' && file_exists(INSTALL_PATH . "/locale/$lang.api.php")) {
@include INSTALL_PATH . "/locale/$language.api.php";
- setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
- }
- else {
- setlocale(LC_ALL, 'en_US.utf8');
}
+ setlocale(LC_ALL, $lang . '.utf8', 'en_US.utf8');
+
self::$translation = $LANG;
}
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 5f9505d..7cc8863 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -63,48 +63,21 @@ class kolab_client_task
*/
private function locale_init()
{
- $aliases = array(
- 'de' => 'de_DE',
- 'en' => 'en_US',
- 'pl' => 'pl_PL',
- );
-
- // UI language
- $langs = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
- $langs = explode(',', $langs);
+ $language = $this->get_language();
+ $LANG = array();
- if (!empty($_SESSION['user']) && !empty($_SESSION['user']['language'])) {
- array_unshift($langs, $_SESSION['user']['language']);
+ if (!$language) {
+ $language = 'en_US';
}
- while ($lang = array_shift($langs)) {
- $lang = explode(';', $lang);
- $lang = $lang[0];
- $lang = str_replace('-', '_', $lang);
-
- if (file_exists(INSTALL_PATH . "/locale/$lang.php")) {
- $language = $lang;
- break;
- }
- if (isset($aliases[$lang]) && ($alias = $aliases[$lang])
- && file_exists(INSTALL_PATH . "/locale/$alias.php")
- ) {
- $language = $alias;
- break;
- }
- }
-
- $LANG = array();
@include INSTALL_PATH . '/locale/en_US.php';
- if (!empty($language) && $language != 'en_US') {
+ if ($language != 'en_US') {
@include INSTALL_PATH . "/locale/$language.php";
- setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
- }
- else {
- setlocale(LC_ALL, 'en_US.utf8');
}
+ setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
+
self::$translation = $LANG;
}
@@ -143,6 +116,46 @@ class kolab_client_task
}
/**
+ * Returns system language (locale) setting.
+ *
+ * @return string Language code
+ */
+ private function get_language()
+ {
+ $aliases = array(
+ 'de' => 'de_DE',
+ 'en' => 'en_US',
+ 'pl' => 'pl_PL',
+ );
+
+ // UI language
+ $langs = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
+ $langs = explode(',', $langs);
+
+ if (!empty($_SESSION['user']) && !empty($_SESSION['user']['language'])) {
+ array_unshift($langs, $_SESSION['user']['language']);
+ }
+
+ while ($lang = array_shift($langs)) {
+ $lang = explode(';', $lang);
+ $lang = $lang[0];
+ $lang = str_replace('-', '_', $lang);
+
+ if (file_exists(INSTALL_PATH . "/locale/$lang.php")) {
+ return $lang;
+ }
+
+ if (isset($aliases[$lang]) && ($alias = $aliases[$lang])
+ && file_exists(INSTALL_PATH . "/locale/$alias.php")
+ ) {
+ return $alias;
+ }
+ }
+
+ return null;
+ }
+
+ /**
* User authentication (and authorization).
*/
private function auth()
@@ -171,7 +184,19 @@ class kolab_client_task
$user['fullname'] = $m[1];
}
+ // Save user data
$_SESSION['user'] = $user;
+
+ if (($language = $this->get_language()) && $language != 'en_US') {
+ $_SESSION['user']['language'] = $language;
+ $session_config['language'] = $language;
+ }
+
+ // Configure API session
+ if (!empty($session_config)) {
+ $this->api->post('system.configure', null, $session_config);
+ }
+
header('Location: ?');
die;
}
commit 9585885a269813009c3c3fb540e306a0be98b9b5
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Feb 23 11:42:18 2012 +0100
Improved API reponse handler
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 89ee9ec..f2271ba 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -349,14 +349,12 @@ function kolab_admin()
this.api_response = function(response)
{
- if (!response)
- return false;
-
this.update_request_time();
this.set_busy(false);
- if (response.status == 'ERROR') {
- this.display_message(response.reason, 'error');
+ if (!response || response.status != 'OK') {
+ var msg = response && response.reason ? response.reason : this.t('servererror');
+ this.display_message(msg, 'error');
return false;
}
commit 14f2d3b76c1c4a07c84a2d4bd7406f65b12adb27
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Feb 23 09:18:18 2012 +0100
Fixed indentation
diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index 09118b0..87cdbc2 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -188,19 +188,19 @@ class kolab_api_controller
$request->setHeader('X-Session-Token', kolab_utils::get_request_header('X-Session-Token'));
if ($method == 'GET') {
- parse_str($_SERVER['QUERY_STRING'], $query);
- unset($query['service']);
- unset($query['method']);
-
- $query = array_map('urldecode', $query);
- $get = array_merge($query, $get);
- }
- else {
+ parse_str($_SERVER['QUERY_STRING'], $query);
+ unset($query['service']);
+ unset($query['method']);
+
+ $query = array_map('urldecode', $query);
+ $get = array_merge($query, $get);
+ }
+ else {
$request->setBody($postdata);
}
try {
- $url->setQueryVariables($get);
+ $url->setQueryVariables($get);
$request->setUrl($url);
$response = $request->send();
}
More information about the commits
mailing list