ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjLanguageFolder.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
16require_once "./Services/Object/classes/class.ilObject.php";
17
19{
27
36 public $lang_user;
37
46 public $lang_path;
47
53 public $separator;
54
61 public $languages;
62
69 public function __construct($a_id, $a_call_by_reference = true)
70 {
71 global $DIC;
72 $lng = $DIC->language();
73
74 $this->type = "lngf";
75 parent::__construct($a_id, $a_call_by_reference);
76
77 $this->lang_path = $lng->lang_path;
78 $this->lang_default = $lng->lang_default;
79 $this->lang_user = $lng->lang_user;
80 $this->separator = $lng->separator;
81 }
82
97 public function getLanguages()
98 {
99 global $DIC;
100 $lng = $DIC->language();
101
102 $lng->loadLanguageModule("meta");
103
104 // set path to directory where lang-files reside
105 $d = dir($this->lang_path);
106 $tmpPath = getcwd();
107 chdir($this->lang_path);
108
109 // get available lang-files
110 while ($entry = $d->read()) {
111 if (is_file($entry) && (preg_match("~(^ilias_.{2}\.lang$)~", $entry))) {
112 $lang_key = substr($entry, 6, 2);
113 $languages[$lang_key] = ""; // long names will be set in class Out
114 }
115 }
116
117 // ensure that arrays are initiated when no lang file was found
118 if (!array($languages)) {
119 $language = array();
120 $tmp_array = array();
121 }
122
123 $tmp_array = array_keys($languages);
124 $lang_keys = array();
125
126 // now get languages from database
127 if ($lang_db = ilObject::_getObjectsByType("lng")) {
128 foreach ($lang_db as $lang) {
129 // set values
130 $lang_key = $lang["title"];
131 $languages[$lang_key] = $lang;
132 $lang_keys[] = $lang_key;
133
134 // determine default language and language of current user
135 if ($lang_key == $this->lang_user) {
136 $languages[$lang_key]["status"] = "in_use";
137 }
138
139 if ($lang_key == $this->lang_default) {
140 $languages[$lang_key]["status"] = "system_language";
141 }
142
143 // check if files are missing
144 if ((count($tmp_array) > 0) && (!in_array($lang_key, $tmp_array))) {
145 $languages[$lang_key]["info"] = "file_not_found";
146 }
147 }
148 }
149
150 // compute new languages
151 foreach ($languages as $lang_key => $lang_data) {
152 if (!in_array($lang_key, $lang_keys)) {
153 $languages[$lang_key] = array();
154 $languages[$lang_key]["info"] = "new_language";
155 //$languages[$lang_key]["desc"] = "not_installed";
156 }
157 }
158
159 chdir($tmpPath);
160
161 // Insert languages with files new found into table language
163
164 // Remove from array & db languages which are not installed and no lang-files
166
167 // setting language's full names
168 foreach ($languages as $lang_key => $lang_data) {
169 $languages[$lang_key]["name"] = $lng->txt("meta_l_" . $lang_key);
170 }
171
172 $this->languages = $languages;
173
174 return $this->languages;
175 }
176
187 public function addNewLanguages($a_languages)
188 {
189 if (count($a_languages) > 0) {
190 foreach ($a_languages as $lang_key => $lang_data) {
191 if ($lang_data["info"] == "new_language") {
192 include_once("./Services/Language/classes/class.ilObjLanguage.php");
193 $lngObj = new ilObjLanguage();
194 $lngObj->setTitle($lang_key);
195 $lngObj->setDescription("not_installed");
196 $lngObj->create();
197
198 // must get OOP through the whole class some time
199 // (no arrays with db fields! this class doesn't know anything about table object!)
200 $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
201 "type" => $lngObj->getType(),
202 "description" => $lngObj->getDescription(),
203 "desc" => $lngObj->getDescription(),
204 "owner" => $lngObj->getOwner(),
205 "create_date" => $lngObj->getCreateDate(),
206 "last_update" => $lngObj->getLastUpdateDate());
207
208 $a_languages[$lang_key]["info"] = "new_language";
209 unset($lngObj); // better: the objects should be resident in an member array of this class
210 }
211 }
212 }
213
214 return $a_languages;
215 }
216
227 public function removeLanguages($a_languages)
228 {
229 global $DIC;
230 $ilDB = $DIC->database();
231
232 foreach ($a_languages as $lang_key => $lang_data) {
233 if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found") {
234 // update languages array
235 unset($a_languages[$lang_key]);
236
237 // update object_data table
238 $query = "DELETE FROM object_data " .
239 "WHERE type = " . $ilDB->quote("lng", "text") . " " .
240 "AND title = " . $ilDB->quote($lang_key, "text");
241 $ilDB->manipulate($query);
242 }
243 }
244
245 return $a_languages;
246 }
247
256 public function checkAllLanguages()
257 {
258 global $DIC;
259 // TODO: lng object should not be used in this class
260 $lng = $DIC->language();
261
262 // set path to directory where lang-files reside
263 $d = dir($this->lang_path);
264 $tmpPath = getcwd();
265 chdir($this->lang_path);
266
267 // for giving a message when no lang-file was found
268 $found = false;
269
270 // get available lang-files
271 while ($entry = $d->read()) {
272 if (is_file($entry) && (preg_match("~(^ilias_.{2}\.lang$)~", $entry))) {
273 // textmeldung, wenn langfile gefunden wurde
274 $output .= "<br/><br/>" . $lng->txt("langfile_found") . ": " . $entry;
275 $content = file($entry);
276
277 $found = true;
278 $error = false;
279
280 if ($content = ilObjLanguage::cut_header($content)) {
281 foreach ($content as $key => $val) {
282 $separated = explode($this->separator, trim($val));
283 $num = count($separated);
284
285 if ($num != 3) {
286 $error = true;
287 $line = $key + 37;
288
289 $output .= "<br/><b/>" . $lng->txt("err_in_line") . " " . $line . " !</b>&nbsp;&nbsp;";
290 $output .= $lng->txt("module") . ": " . $separated[0];
291 $output .= ", " . $lng->txt("identifier") . ": " . $separated[1];
292 $output .= ", " . $lng->txt("value") . ": " . $separated[2];
293
294 switch ($num) {
295 case 1:
296 if (empty($separated[0])) {
297 $output .= "<br/>" . $lng->txt("err_no_param") . " " . $lng->txt("check_langfile");
298 } else {
299 $output .= "<br/>" . $lng->txt("err_1_param") . " " . $lng->txt("check_langfile");
300 }
301 break;
302
303 case 2:
304 $output .= "<br/>" . $lng->txt("err_2_param") . " " . $lng->txt("check_langfile");
305 break;
306
307 default:
308 $output .= "<br/>" . $lng->txt("err_over_3_param") . " " . $lng->txt("check_langfile");
309 break;
310 }
311 }
312 }
313
314 if ($error) {
315 $output .= "<br/>" . $lng->txt("file_not_valid") . " " . $lng->txt("err_count_param");
316 } else {
317 $output .= "<br/>" . $lng->txt("file_valid");
318 }
319 } else {
320 $output .= "<br/>" . $lng->txt("file_not_valid") . " " . $lng->txt("err_wrong_header");
321 }
322 }
323 }
324
325 $d->close();
326
327 if (!$found) {
328 $output .= "<br/>" . $lng->txt("err_no_langfile_found");
329 }
330
331 chdir($tmpPath);
332 return $output;
333 }
334} // END class.LanguageFolderObject
An exception for terminatinating execution or to throw for unit testing.
Class ilObjLanguageFolder contains all function to manage language support for ILIAS3 install,...
__construct($a_id, $a_call_by_reference=true)
Constructor @access public.
checkAllLanguages()
validate the logical structure of a lang-file
getLanguages()
gather all information about available languages
removeLanguages($a_languages)
remove languages which are not installed AND has no lang-file
addNewLanguages($a_languages)
add new languages
Class ilObjLanguage.
static cut_header($content)
remove lang-file haeder information from '$content' This function seeks for a special keyword where t...
Class ilObject Basic functions for all objects.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
global $ilDB
$lang
Definition: xapiexit.php:8