ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
16 require_once "./Services/Object/classes/class.ilObject.php";
17 
19 {
27 
37 
47 
54 
62 
69  function ilObjLanguageFolder($a_id,$a_call_by_reference = true)
70  {
71  $this->type = "lngf";
72  $this->ilObject($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  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  {
111  if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
112  {
113  $lang_key = substr($entry,6,2);
114  $languages[$lang_key] = ""; // long names will be set in class Out
115  }
116  }
117 
118  // ensure that arrays are initiated when no lang file was found
119  if (!array($languages))
120  {
121  $language = array();
122  $tmp_array = array();
123  }
124 
125  $tmp_array = array_keys($languages);
126  $lang_keys = array();
127 
128  // now get languages from database
129  if ($lang_db = ilObject::_getObjectsByType("lng"))
130  {
131  foreach ($lang_db as $lang)
132  {
133  // set values
134  $lang_key = $lang["title"];
135  $languages[$lang_key] = $lang;
136  $lang_keys[] = $lang_key;
137 
138  // determine default language and language of current user
139  if ($lang_key == $this->lang_user)
140  {
141  $languages[$lang_key]["status"] = "in_use";
142  }
143 
144  if ($lang_key == $this->lang_default)
145  {
146  $languages[$lang_key]["status"] = "system_language";
147  }
148 
149  // check if files are missing
150  if ((count($tmp_array) > 0) && (!in_array($lang_key,$tmp_array)))
151  {
152  $languages[$lang_key]["info"] = "file_not_found";
153  }
154  }
155  }
156 
157  // compute new languages
158  foreach ($languages as $lang_key => $lang_data)
159  {
160  if (!in_array($lang_key,$lang_keys))
161  {
162  $languages[$lang_key]["info"] = "new_language";
163  //$languages[$lang_key]["desc"] = "not_installed";
164  }
165  }
166 
167  chdir($tmpPath);
168 
169  // Insert languages with files new found into table language
171 
172  // Remove from array & db languages which are not installed and no lang-files
174 
175  // setting language's full names
176  foreach ($languages as $lang_key => $lang_data)
177  {
178  $languages[$lang_key]["name"] = $lng->txt("meta_l_".$lang_key);
179  }
180 
181  $this->languages = $languages;
182 
183  return $this->languages;
184  }
185 
196  function addNewLanguages($a_languages)
197  {
198  if (count($a_languages) > 0)
199  {
200  foreach ($a_languages as $lang_key => $lang_data)
201  {
202  if ($lang_data["info"] == "new_language")
203  {
204  include_once("./Services/Language/classes/class.ilObjLanguage.php");
205  $lngObj =& new ilObjLanguage();
206  $lngObj->setTitle($lang_key);
207  $lngObj->setDescription("not_installed");
208  $lngObj->create();
209 
210  // must get OOP through the whole class some time
211  // (no arrays with db fields! this class doesn't know anything about table object!)
212  $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
213  "type" => $lngObj->getType(),
214  "description" => $lngObj->getDescription(),
215  "desc" => $lngObj->getDescription(),
216  "owner" => $lngObj->getOwner(),
217  "create_date" => $lngObj->getCreateDate(),
218  "last_update" => $lngObj->getLastUpdateDate());
219 
220  $a_languages[$lang_key]["info"] = "new_language";
221  unset($lngObj); // better: the objects should be resident in an member array of this class
222  }
223  }
224  }
225 
226  return $a_languages;
227  }
228 
239  function removeLanguages($a_languages)
240  {
241  global $ilDB;
242 
243  foreach ($a_languages as $lang_key => $lang_data)
244  {
245  if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found")
246  {
247  // update languages array
248  unset($a_languages[$lang_key]);
249 
250  // update object_data table
251  $query = "DELETE FROM object_data ".
252  "WHERE type = ".$ilDB->quote("lng", "text")." ".
253  "AND title = ".$ilDB->quote($lang_key, "text");
254  $ilDB->manipulate($query);
255  }
256  }
257 
258  return $a_languages;
259  }
260 
269  function checkAllLanguages()
270  {
271  // TODO: lng object should not be used in this class
272  global $lng;
273 
274  // set path to directory where lang-files reside
275  $d = dir($this->lang_path);
276  $tmpPath = getcwd();
277  chdir ($this->lang_path);
278 
279  // for giving a message when no lang-file was found
280  $found = false;
281 
282  // get available lang-files
283  while ($entry = $d->read())
284  {
285  if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
286  {
287  // textmeldung, wenn langfile gefunden wurde
288  $output .= "<br/><br/>".$lng->txt("langfile_found").": ".$entry;
289  $content = file ($entry);
290 
291  $found = true;
292  $error = false;
293 
294  if ($content = ilObjLanguage::cut_header($content))
295  {
296  foreach ($content as $key => $val)
297  {
298  $separated = explode ($this->separator,trim($val));
299  $num = count($separated);
300 
301  if ($num != 3)
302  {
303  $error = true;
304  $line = $key + 37;
305 
306  $output .= "<br/><b/>".$lng->txt("err_in_line")." ".$line." !</b>&nbsp;&nbsp;";
307  $output .= $lng->txt("module").": ".$separated[0];
308  $output .= ", ".$lng->txt("identifier").": ".$separated[1];
309  $output .= ", ".$lng->txt("value").": ".$separated[2];
310 
311  switch ($num)
312  {
313  case 1:
314  if (empty($separated[0]))
315  {
316  $output .= "<br/>".$lng->txt("err_no_param")." ".$lng->txt("check_langfile");
317  }
318  else
319  {
320  $output .= "<br/>".$lng->txt("err_1_param")." ".$lng->txt("check_langfile");
321  }
322  break;
323 
324  case 2:
325  $output .= "<br/>".$lng->txt("err_2_param")." ".$lng->txt("check_langfile");
326  break;
327 
328  default:
329  $output .= "<br/>".$lng->txt("err_over_3_param")." ".$lng->txt("check_langfile");
330  break;
331  }
332  }
333  }
334 
335  if ($error) {
336  $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_count_param");
337  }
338  else {
339  $output .= "<br/>".$lng->txt("file_valid");
340  }
341  }
342  else {
343  $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_wrong_header");
344  }
345  }
346  }
347 
348  $d->close();
349 
350  if (!$found) {
351  $output .= "<br/>".$lng->txt("err_no_langfile_found");
352  }
353 
354  chdir($tmpPath);
355  return $output;
356  }
357 } // END class.LanguageFolderObject
358 ?>