Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once "class.ilObject.php";
00025
00035 class ilObjLanguage extends ilObject
00036 {
00044 var $separator;
00045 var $comment_separator;
00046 var $lang_default;
00047 var $lang_user;
00048 var $lang_path;
00049
00050 var $key;
00051 var $status;
00052
00053
00061 function ilObjLanguage($a_id = 0, $a_call_by_reference = false)
00062 {
00063 global $lng;
00064
00065 $this->type = "lng";
00066 $this->ilObject($a_id,$a_call_by_reference);
00067
00068 $this->type = "lng";
00069 $this->key = $this->title;
00070 $this->status = $this->desc;
00071 $this->lang_default = $lng->lang_default;
00072 $this->lang_user = $lng->lang_user;
00073 $this->lang_path = $lng->lang_path;
00074 $this->separator = $lng->separator;
00075 $this->comment_separator = $lng->comment_separator;
00076 }
00077
00083 function getKey()
00084 {
00085 return $this->key;
00086 }
00087
00093 function getStatus()
00094 {
00095 return $this->status;
00096 }
00097
00101 function isSystemLanguage()
00102 {
00103 if ($this->key == $this->lang_default)
00104 return true;
00105 else
00106 return false;
00107 }
00108
00112 function isUserLanguage()
00113 {
00114 if ($this->key == $this->lang_user)
00115 {
00116 return true;
00117 }
00118 else
00119 {
00120 return false;
00121 }
00122 }
00123
00124
00130 function isInstalled()
00131 {
00132 if (substr($this->getStatus(), 0, 9) == "installed")
00133 {
00134 return true;
00135 }
00136 else
00137 {
00138 return false;
00139 }
00140 }
00141
00148 function isLocal()
00149 {
00150 if (substr($this->getStatus(), 10) == "local")
00151 {
00152 return true;
00153 }
00154 else
00155 {
00156 return false;
00157 }
00158 }
00159
00166 function install($scope = '')
00167 {
00168 if (!empty($scope))
00169 {
00170 if ($scope == 'global')
00171 {
00172 $scope = '';
00173 }
00174 else
00175 {
00176 $scopeExtension = '.' . $scope;
00177 }
00178 }
00179
00180 if (($this->isInstalled() == false) ||
00181 ($this->isInstalled() == true && $this->isLocal() == false && !empty($scope)))
00182 {
00183 if ($this->check($scope))
00184 {
00185
00186 if (empty($scope))
00187 {
00188 $this->flush();
00189 }
00190
00191
00192 $this->insert($scope);
00193
00194
00195 if (empty($scope))
00196 {
00197 $newDesc = 'installed';
00198 }
00199 else if ($scope == 'local')
00200 {
00201 $newDesc = 'installed_local';
00202 }
00203 $this->setDescription($newDesc);
00204 $this->update();
00205 $this->optimizeData();
00206 return $this->getKey();
00207 }
00208 }
00209 return "";
00210 }
00211
00212
00218 function uninstall()
00219 {
00220 if ((substr($this->status, 0, 9) == "installed") && ($this->key != $this->lang_default) && ($this->key != $this->lang_user))
00221 {
00222 $this->flush();
00223 $this->setTitle($this->key);
00224 $this->setDescription("not_installed");
00225 $this->update();
00226 $this->resetUserLanguage($this->key);
00227
00228 return $this->key;
00229 }
00230 return "";
00231 }
00232
00233
00237 function flush()
00238 {
00239 $query = "DELETE FROM lng_data WHERE lang_key='".$this->key."'";
00240 $this->ilias->db->query($query);
00241 }
00242
00243
00249 function insert($scope = '')
00250 {
00251 if (!empty($scope))
00252 {
00253 if ($scope == 'global')
00254 {
00255 $scope = '';
00256 }
00257 else
00258 {
00259 $scopeExtension = '.' . $scope;
00260 }
00261 }
00262
00263 $tmpPath = getcwd();
00264 chdir($this->lang_path);
00265
00266 $lang_file = "ilias_" . $this->key . ".lang" . $scopeExtension;
00267
00268 if ($lang_file)
00269 {
00270
00271 if ($content = $this->cut_header(file($lang_file)))
00272 {
00273 foreach ($content as $key => $val)
00274 {
00275 $separated = explode($this->separator,trim($val));
00276
00277
00278 $pos = strpos($separated[2], $this->comment_separator);
00279
00280 if ($pos !== false)
00281 {
00282
00283 $separated[2] = substr($separated[2] , 0 , $pos);
00284 }
00285
00286 if (empty($scope))
00287 {
00288 $query = "INSERT INTO lng_data " .
00289 "(module, identifier, lang_key, value) " .
00290 "VALUES " .
00291 "('" . $separated[0] . "','" . $separated[1] . "','" . $this->key . "','" . addslashes($separated[2]) . "')";
00292 }
00293 else if ($scope == 'local')
00294 {
00295
00296 $query = "UPDATE lng_data SET ".
00297 "module = '" . $separated[0] . "', " .
00298 "identifier = '" . $separated[1] . "', " .
00299 "lang_key = '" . $this->key . "', " .
00300 "value = '" . addslashes($separated[2]) . "' " .
00301 "WHERE module = '" . $separated[0] . "' " .
00302 "AND identifier = '" . $separated[1] . "' " .
00303 "AND lang_key = '" . $this->key . "'";
00304 }
00305 $this->ilias->db->query($query);
00306 }
00307
00308 if (empty($scope))
00309 {
00310 $query = "UPDATE object_data SET " .
00311 "description = 'installed', " .
00312 "last_update = now() " .
00313 "WHERE title = '".$this->key."' " .
00314 "AND type = 'lng'";
00315 }
00316 else if ($scope == 'local')
00317 {
00318 $query = "UPDATE object_data SET " .
00319 "description = 'installed_local', " .
00320 "last_update = now() " .
00321 "WHERE title = '".$this->key."' " .
00322 "AND type = 'lng'";
00323 }
00324 $this->ilias->db->query($query);
00325 }
00326 }
00327
00328 chdir($tmpPath);
00329 }
00330
00337 function resetUserLanguage($lang_key)
00338 {
00339 $query = "UPDATE usr_pref SET " .
00340 "value = '" . $this->lang_default."' " .
00341 "WHERE keyword = 'language' " .
00342 "AND value = '" . $lang_key . "'";
00343 $this->ilias->db->query($query);
00344 }
00345
00354 function cut_header($content)
00355 {
00356 foreach ($content as $key => $val)
00357 {
00358 if (trim($val) == "<!-- language file start -->")
00359 {
00360 return array_slice($content,$key +1);
00361 }
00362 }
00363
00364 return false;
00365 }
00366
00372 function optimizeData()
00373 {
00374
00375 $query = "OPTIMIZE TABLE lng_data";
00376 $this->ilias->db->query($query);
00377
00378 return true;
00379 }
00380
00390 function check($scope = '')
00391 {
00392 if (!empty($scope))
00393 {
00394 if ($scope == 'global')
00395 {
00396 $scope = '';
00397 }
00398 else
00399 {
00400 $scopeExtension = '.' . $scope;
00401 }
00402 }
00403
00404 $tmpPath = getcwd();
00405 chdir($this->lang_path);
00406
00407
00408 $lang_file = "ilias_" . $this->key . ".lang" . $scopeExtension;
00409
00410
00411 if (!is_file($lang_file))
00412 {
00413 $this->ilias->raiseError("File not found: ".$lang_file,$this->ilias->error_obj->MESSAGE);
00414 }
00415
00416
00417 if (!$content = $this->cut_header(file($lang_file)))
00418 {
00419 $this->ilias->raiseError("Wrong Header in ".$lang_file,$this->ilias->error_obj->MESSAGE);
00420 }
00421
00422
00423 $line = 0;
00424 foreach ($content as $key => $val)
00425 {
00426 $separated = explode($this->separator, trim($val));
00427 $num = count($separated);
00428 ++$n;
00429 if ($num != 3)
00430 {
00431 $line = $n + 36;
00432 $this->ilias->raiseError("Wrong parameter count in ".$lang_file." in line $line (Value: $val)! Please check your language file!",$this->ilias->error_obj->MESSAGE);
00433 }
00434 }
00435
00436 chdir($tmpPath);
00437
00438
00439 return true;
00440 }
00441 }
00442 ?>