ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $this->type = "lngf";
72 parent::__construct($a_id, $a_call_by_reference);
73
74 // init language support
75 global $lng;
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 $lng;
100
101 $lng->loadLanguageModule("meta");
102
103 // set path to directory where lang-files reside
104 $d = dir($this->lang_path);
105 $tmpPath = getcwd();
106 chdir($this->lang_path);
107
108 // get available lang-files
109 while ($entry = $d->read()) {
110 if (is_file($entry) && (preg_match("~(^ilias_.{2}\.lang$)~", $entry))) {
111 $lang_key = substr($entry, 6, 2);
112 $languages[$lang_key] = ""; // long names will be set in class Out
113 }
114 }
115
116 // ensure that arrays are initiated when no lang file was found
117 if (!array($languages)) {
118 $language = array();
119 $tmp_array = array();
120 }
121
122 $tmp_array = array_keys($languages);
123 $lang_keys = array();
124
125 // now get languages from database
126 if ($lang_db = ilObject::_getObjectsByType("lng")) {
127 foreach ($lang_db as $lang) {
128 // set values
129 $lang_key = $lang["title"];
130 $languages[$lang_key] = $lang;
131 $lang_keys[] = $lang_key;
132
133 // determine default language and language of current user
134 if ($lang_key == $this->lang_user) {
135 $languages[$lang_key]["status"] = "in_use";
136 }
137
138 if ($lang_key == $this->lang_default) {
139 $languages[$lang_key]["status"] = "system_language";
140 }
141
142 // check if files are missing
143 if ((count($tmp_array) > 0) && (!in_array($lang_key, $tmp_array))) {
144 $languages[$lang_key]["info"] = "file_not_found";
145 }
146 }
147 }
148
149 // compute new languages
150 foreach ($languages as $lang_key => $lang_data) {
151 if (!in_array($lang_key, $lang_keys)) {
152 $languages[$lang_key] = array();
153 $languages[$lang_key]["info"] = "new_language";
154 //$languages[$lang_key]["desc"] = "not_installed";
155 }
156 }
157
158 chdir($tmpPath);
159
160 // Insert languages with files new found into table language
162
163 // Remove from array & db languages which are not installed and no lang-files
165
166 // setting language's full names
167 foreach ($languages as $lang_key => $lang_data) {
168 $languages[$lang_key]["name"] = $lng->txt("meta_l_" . $lang_key);
169 }
170
171 $this->languages = $languages;
172
173 return $this->languages;
174 }
175
186 public function addNewLanguages($a_languages)
187 {
188 if (count($a_languages) > 0) {
189 foreach ($a_languages as $lang_key => $lang_data) {
190 if ($lang_data["info"] == "new_language") {
191 include_once("./Services/Language/classes/class.ilObjLanguage.php");
192 $lngObj = new ilObjLanguage();
193 $lngObj->setTitle($lang_key);
194 $lngObj->setDescription("not_installed");
195 $lngObj->create();
196
197 // must get OOP through the whole class some time
198 // (no arrays with db fields! this class doesn't know anything about table object!)
199 $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
200 "type" => $lngObj->getType(),
201 "description" => $lngObj->getDescription(),
202 "desc" => $lngObj->getDescription(),
203 "owner" => $lngObj->getOwner(),
204 "create_date" => $lngObj->getCreateDate(),
205 "last_update" => $lngObj->getLastUpdateDate());
206
207 $a_languages[$lang_key]["info"] = "new_language";
208 unset($lngObj); // better: the objects should be resident in an member array of this class
209 }
210 }
211 }
212
213 return $a_languages;
214 }
215
226 public function removeLanguages($a_languages)
227 {
228 global $ilDB;
229
230 foreach ($a_languages as $lang_key => $lang_data) {
231 if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found") {
232 // update languages array
233 unset($a_languages[$lang_key]);
234
235 // update object_data table
236 $query = "DELETE FROM object_data " .
237 "WHERE type = " . $ilDB->quote("lng", "text") . " " .
238 "AND title = " . $ilDB->quote($lang_key, "text");
239 $ilDB->manipulate($query);
240 }
241 }
242
243 return $a_languages;
244 }
245
254 public function checkAllLanguages()
255 {
256 // TODO: lng object should not be used in this class
257 global $lng;
258
259 // set path to directory where lang-files reside
260 $d = dir($this->lang_path);
261 $tmpPath = getcwd();
262 chdir($this->lang_path);
263
264 // for giving a message when no lang-file was found
265 $found = false;
266
267 // get available lang-files
268 while ($entry = $d->read()) {
269 if (is_file($entry) && (preg_match("~(^ilias_.{2}\.lang$)~", $entry))) {
270 // textmeldung, wenn langfile gefunden wurde
271 $output .= "<br/><br/>" . $lng->txt("langfile_found") . ": " . $entry;
272 $content = file($entry);
273
274 $found = true;
275 $error = false;
276
277 if ($content = ilObjLanguage::cut_header($content)) {
278 foreach ($content as $key => $val) {
279 $separated = explode($this->separator, trim($val));
280 $num = count($separated);
281
282 if ($num != 3) {
283 $error = true;
284 $line = $key + 37;
285
286 $output .= "<br/><b/>" . $lng->txt("err_in_line") . " " . $line . " !</b>&nbsp;&nbsp;";
287 $output .= $lng->txt("module") . ": " . $separated[0];
288 $output .= ", " . $lng->txt("identifier") . ": " . $separated[1];
289 $output .= ", " . $lng->txt("value") . ": " . $separated[2];
290
291 switch ($num) {
292 case 1:
293 if (empty($separated[0])) {
294 $output .= "<br/>" . $lng->txt("err_no_param") . " " . $lng->txt("check_langfile");
295 } else {
296 $output .= "<br/>" . $lng->txt("err_1_param") . " " . $lng->txt("check_langfile");
297 }
298 break;
299
300 case 2:
301 $output .= "<br/>" . $lng->txt("err_2_param") . " " . $lng->txt("check_langfile");
302 break;
303
304 default:
305 $output .= "<br/>" . $lng->txt("err_over_3_param") . " " . $lng->txt("check_langfile");
306 break;
307 }
308 }
309 }
310
311 if ($error) {
312 $output .= "<br/>" . $lng->txt("file_not_valid") . " " . $lng->txt("err_count_param");
313 } else {
314 $output .= "<br/>" . $lng->txt("file_valid");
315 }
316 } else {
317 $output .= "<br/>" . $lng->txt("file_not_valid") . " " . $lng->txt("err_wrong_header");
318 }
319 }
320 }
321
322 $d->close();
323
324 if (!$found) {
325 $output .= "<br/>" . $lng->txt("err_no_langfile_found");
326 }
327
328 chdir($tmpPath);
329 return $output;
330 }
331} // 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.
$lang
Definition: consent.php:3
$key
Definition: croninfo.php:18
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
$query
global $ilDB