4require_once
"./Services/Object/classes/class.ilObject.php";
40 public function __construct($a_id = 0, $a_call_by_reference =
false)
51 $this->lang_default =
$lng->lang_default;
52 $this->lang_user =
$lng->lang_user;
53 $this->lang_path =
$lng->lang_path;
54 $this->cust_lang_path =
$lng->cust_lang_path;
55 $this->separator =
$lng->separator;
56 $this->comment_separator =
$lng->comment_separator;
68 foreach ($languages as
$lang) {
70 if ($langObj->isInstalled()) {
71 $objects[] = $langObj;
105 if ($this->key == $this->lang_default) {
117 if ($this->key == $this->lang_user) {
132 if (substr($this->
getStatus(), 0, 9) ==
"installed") {
147 if (substr($this->
getStatus(), 10) ==
"local") {
162 if (!empty($scope)) {
163 if ($scope ==
'global') {
166 $scopeExtension =
'.' . $scope;
172 if ($this->
check($scope)) {
175 $this->
flush(
'keep_local');
183 $newDesc =
'installed';
184 } elseif ($scope ==
'local') {
185 $newDesc =
'installed_local';
203 if ((substr($this->status, 0, 9) ==
"installed") && ($this->key != $this->lang_default) && ($this->key != $this->lang_user)) {
223 if ($this->
check()) {
224 $this->
flush(
'keep_local');
230 if ($this->
isLocal() ==
true) {
231 if ($this->
check(
'local')) {
250 $refreshed = array();
252 foreach ($languages as
$lang) {
254 if ($langObj->refresh()) {
255 $refreshed[] = $langObj->getKey();
271 $ilPluginAdmin =
$DIC[
'ilPluginAdmin'];
274 include_once(
"./Services/Component/classes/class.ilPluginSlot.php");
276 foreach ($slots as $slot) {
277 $act_plugins = $ilPluginAdmin->getActivePluginsForSlot(
278 $slot[
"component_type"],
279 $slot[
"component_name"],
282 foreach ($act_plugins as
$plugin) {
283 include_once(
"./Services/Component/classes/class.ilPlugin.php");
285 $slot[
"component_type"],
286 $slot[
"component_name"],
290 if (is_object($pl)) {
291 $pl->updateLanguages($a_lang_keys);
308 if (!$a_keep_local_change) {
309 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
310 $ilDB->quote($a_lang_key,
"text"));
312 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
313 $ilDB->quote($a_lang_key,
"text") .
314 " AND local_change IS NULL");
322 public function flush($a_mode =
'all')
329 if ($a_mode ==
'all') {
330 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
331 $ilDB->quote($this->key,
"text"));
347 if ($a_min_date ==
"") {
348 $a_min_date =
"1980-01-01 00:00:00";
350 if ($a_max_date ==
"") {
351 $a_max_date =
"2200-01-01 00:00:00";
355 "SELECT * FROM lng_data WHERE lang_key = %s " .
356 "AND local_change >= %s AND local_change <= %s",
357 $ilDB->quote($this->key,
"text"),
358 $ilDB->quote($a_min_date,
"timestamp"),
359 $ilDB->quote($a_max_date,
"timestamp")
365 $changes[$row[
"module"]][$row[
"identifier"]] = $row[
"value"];
382 "SELECT MAX(local_change) last_change FROM lng_data " .
383 "WHERE lang_key = %s AND local_change IS NOT NULL",
384 $ilDB->quote($a_key,
"text")
389 return $row[
'last_change'];
409 "SELECT * FROM lng_data WHERE lang_key = %s AND module = %s AND local_change IS NOT NULL",
410 array(
'text',
'text'),
411 array($a_key, $a_module)
415 $changes[$row[
'identifier']] = $row[
'value'];
430 $scopeExtension =
"";
431 if (!empty($scope)) {
432 if ($scope ==
'global') {
435 $scopeExtension =
'.' . $scope;
440 if ($scope ==
"local") {
441 $path = $this->cust_lang_path;
444 $lang_file = $path .
"/ilias_" . $this->key .
".lang" . $scopeExtension;
446 if (is_file($lang_file)) {
448 $lang_array = array();
449 $lang_array[
"common"] = array();
452 if ($content = self::cut_header(file($lang_file))) {
453 $local_changes =
null;
457 } elseif ($scope ==
'local') {
460 $min_date = date(
"Y-m-d H:i:s", filemtime($lang_file));
464 $lang_array = $dbAccess->insertLangEntries($lang_file);
465 $dbAccess->replaceLangModules($lang_array);
473 final public static function replaceLangModule($a_key, $a_module, $a_array)
481 $ilDB->manipulate(sprintf(
482 "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
483 $ilDB->quote($a_key,
"text"),
484 $ilDB->quote($a_module,
"text")
491 $ilDB->insert(
"lng_modules", array(
492 "lang_key" => array(
"text", $a_key),
493 "module" => array(
"text", $a_module),
494 "lang_array" => array(
"clob", serialize((array) $a_array))
500 "SELECT lang_array FROM lng_modules WHERE lang_key = %s AND module = %s",
501 array(
'text',
'text'),
502 array($a_key, $a_module)
506 $unserialied = unserialize($row[
'lang_array']);
507 if (!is_array($unserialied)) {
511 "Data for module '" . $a_module .
"' of language '" . $a_key .
"' is not correctly saved. " .
512 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
526 $a_local_change =
null,
535 if (isset($a_remarks)) {
536 $a_remarks = substr($a_remarks, 0, 250);
538 if ($a_remarks ==
'') {
542 if (isset($a_value)) {
543 $a_value = substr($a_value, 0, 4000);
545 if ($a_value ==
'') {
552 'module' => array(
'text',$a_module),
553 'identifier' => array(
'text',$a_identifier),
554 'lang_key' => array(
'text',$a_lang_key)
557 'value' => array(
'text',$a_value),
558 'local_change' => array(
'timestamp',$a_local_change),
559 'remarks' => array(
'text', $a_remarks)
588 $a_local_change =
null,
594 if (isset($a_remarks)) {
595 $a_remarks = substr($a_remarks, 0, 250);
597 if ($a_remarks ==
'') {
601 if (isset($a_value)) {
602 $a_value = substr($a_value, 0, 4000);
604 if ($a_value ==
'') {
608 $ilDB->manipulate(sprintf(
610 "SET value = %s, local_change = %s, remarks = %s " .
611 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
612 $ilDB->quote($a_value,
"text"),
613 $ilDB->quote($a_local_change,
"timestamp"),
614 $ilDB->quote($a_remarks,
"text"),
615 $ilDB->quote($a_module,
"text"),
616 $ilDB->quote($a_identifier,
"text"),
617 $ilDB->quote($a_lang_key,
"text")
630 $ilDB->manipulate(sprintf(
631 "DELETE FROM lng_data " .
632 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
633 $ilDB->quote($a_module,
"text"),
634 $ilDB->quote($a_identifier,
"text"),
635 $ilDB->quote($a_lang_key,
"text")
653 $query =
"UPDATE usr_pref SET " .
654 "value = " .
$ilDB->quote($this->lang_default,
"text") .
" " .
655 "WHERE keyword = " .
$ilDB->quote(
'language',
"text") .
" " .
656 "AND value = " .
$ilDB->quote($lang_key,
"text");
670 foreach ($content as
$key => $val) {
671 if (trim($val) ==
"<!-- language file start -->") {
672 return array_slice($content,
$key + 1);
702 include_once(
"./Services/Utilities/classes/class.ilStr.php");
704 if (!empty($scope)) {
705 if ($scope ==
'global') {
708 $scopeExtension =
'.' . $scope;
713 if ($scope ==
"local") {
714 $path = $this->cust_lang_path;
720 if (!is_dir($path)) {
721 $this->
ilias->raiseError(
"Directory not found: " . $path, $this->
ilias->error_obj->MESSAGE);
727 $lang_file =
"ilias_" . $this->key .
".lang" . $scopeExtension;
730 if (!is_file($lang_file)) {
731 $this->
ilias->raiseError(
"File not found: " . $lang_file, $this->
ilias->error_obj->MESSAGE);
735 $content = $this->
cut_header(file($lang_file));
736 if ($content ===
false) {
737 $this->
ilias->raiseError(
"Wrong Header in " . $lang_file, $this->
ilias->error_obj->MESSAGE);
742 foreach ($content as
$key => $val) {
743 $separated = explode($this->separator, trim($val));
744 $num = count($separated);
748 $this->
ilias->raiseError(
"Wrong parameter count in " . $lang_file .
" in line $line (Value: $val)! Please check your language file!", $this->
ilias->error_obj->MESSAGE);
751 $this->
ilias->raiseError(
"Non UTF8 character found in " . $lang_file .
" in line $line (Value: $val)! Please check your language file!", $this->
ilias->error_obj->MESSAGE);
770 $set =
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud JOIN usr_pref up" .
771 " ON ud.usr_id = up.usr_id " .
772 " WHERE up.value = " .
$ilDB->quote($a_lang,
"text") .
773 " AND up.keyword = " .
$ilDB->quote(
"language",
"text"));
774 $rec =
$ilDB->fetchAssoc($set);
777 if ($a_lang ==
$lng->lang_default) {
778 $set2 =
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud LEFT JOIN usr_pref up" .
779 " ON (ud.usr_id = up.usr_id AND up.keyword = " .
$ilDB->quote(
"language",
"text") .
")" .
780 " WHERE up.value IS NULL ");
781 $rec2 =
$ilDB->fetchAssoc($set2);
784 return (
int) $rec[
"cnt"] + (int) $rec2[
"cnt"];
An exception for terminatinating execution or to throw for unit testing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static refreshPlugins($a_lang_keys=null)
static _deleteLangData($a_lang_key, $a_keep_local_change=false)
Delete languge data.
static _getLocalChangesByModule($a_key, $a_module)
Get the local changes of a language module.
static updateLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
static deleteLangEntry($a_module, $a_identifier, $a_lang_key)
Delete lang entry.
static refreshAll()
Refresh all installed languages.
isInstalled()
Check language object status, and return true if language is installed.
uninstall()
uninstall current language
getStatus()
get language status
isLocal()
Check language object status, and return true if a local language file is installed.
static getInstalledLanguages()
Get the language objects of the installed languages.
static countUsers($a_lang)
Count number of users that use a language.
resetUserLanguage($lang_key)
search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to d...
install($scope='')
install current language
isSystemLanguage()
check if language is system language
isUserLanguage()
check if language is system language
flush($a_mode='all')
remove language data from database
insert($scope='')
insert language data from file into database
static cut_header($content)
remove lang-file haeder information from '$content' This function seeks for a special keyword where t...
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
__construct($a_id=0, $a_call_by_reference=false)
Constructor.
refresh()
refresh current language
getLocalChanges($a_min_date="", $a_max_date="")
get locally changed language entries
optimizeData()
optimizes the db-table langdata
check($scope='')
Validate the logical structure of a lang file.
static _getLastLocalChange($a_key)
get the date of the last local change
Class ilObject Basic functions for all objects.
update()
update object in db
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
setTitle($a_title)
set object title
setDescription($a_desc)
set object description
static getAllSlots()
Get all plugin slots.
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
static isUtf8($a_str)
Check whether string is utf-8.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)