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
00035 require_once "class.ilObject.php";
00036
00037 class ilObjLanguage extends ilObject
00038 {
00046 var $separator;
00047 var $comment_separator;
00048 var $lang_default;
00049 var $lang_user;
00050 var $lang_path;
00051
00052 var $key;
00053 var $status;
00054
00055
00062 function ilObjLanguage($a_id = 0, $a_call_by_reference = false)
00063 {
00064 global $lng;
00065
00066 $this->type = "lng";
00067 $this->ilObject($a_id,$a_call_by_reference);
00068
00069 $this->type = "lng";
00070 $this->key = $this->title;
00071 $this->status = $this->desc;
00072 $this->lang_default = $lng->lang_default;
00073 $this->lang_user = $lng->lang_user;
00074 $this->lang_path = $lng->lang_path;
00075 $this->separator = $lng->separator;
00076 $this->comment_separator = $lng->comment_separator;
00077 }
00078
00084 function getKey()
00085 {
00086 return $this->key;
00087 }
00088
00094 function getStatus()
00095 {
00096 return $this->status;
00097 }
00098
00102 function isSystemLanguage()
00103 {
00104 if ($this->key == $this->lang_default)
00105 return true;
00106 else
00107 return false;
00108 }
00109
00113 function isUserLanguage()
00114 {
00115 if ($this->key == $this->lang_user)
00116 {
00117 return true;
00118 }
00119 else
00120 {
00121 return false;
00122 }
00123 }
00124
00125
00131 function install ()
00132 {
00133 if ($this->getStatus() != "installed")
00134 {
00135 if ($this->check())
00136 {
00137
00138 $this->flush();
00139
00140 $this->insert();
00141
00142 $this->setDescription("installed");
00143 $this->update();
00144 $this->optimizeData();
00145 return $this->getKey();
00146 }
00147 }
00148 return "";
00149 }
00150
00151
00157 function uninstall ()
00158 {
00159 if (($this->status == "installed") && ($this->key != $this->lang_default) && ($this->key != $this->lang_user))
00160 {
00161 $this->flush();
00162 $this->setTitle($this->key);
00163 $this->setDescription("not_installed");
00164 $this->update();
00165 $this->resetUserLanguage($this->key);
00166
00167 return $this->key;
00168 }
00169 return "";
00170 }
00171
00172
00176 function flush()
00177 {
00178 $query = "DELETE FROM lng_data WHERE lang_key='".$this->key."'";
00179 $this->ilias->db->query($query);
00180 }
00181
00182
00186 function insert ()
00187 {
00188 $tmpPath = getcwd();
00189 chdir($this->lang_path);
00190
00191 $lang_file = "ilias_".$this->key.".lang";
00192
00193 if ($lang_file)
00194 {
00195
00196 if ($content = $this->cut_header(file($lang_file)))
00197 {
00198 foreach ($content as $key => $val)
00199 {
00200 $separated = explode ($this->separator,trim($val));
00201
00202
00203 $pos = strpos($separated[2], $this->comment_separator);
00204
00205 if ($pos !== false)
00206 {
00207
00208 $separated[2] = substr($separated[2] , 0 , $pos);
00209 }
00210
00211
00212 $num = count($separated);
00213
00214 $query = "INSERT INTO lng_data ".
00215 "(module,identifier,lang_key,value) ".
00216 "VALUES ".
00217 "('".$separated[0]."','".$separated[1]."','".$this->key."','".addslashes($separated[2])."')";
00218 $this->ilias->db->query($query);
00219 }
00220 $query = "UPDATE object_data SET ".
00221 "last_update = now() ".
00222 "WHERE title = '".$this->key."' ".
00223 "AND type = 'lng'";
00224 $this->ilias->db->query($query);
00225 }
00226 }
00227
00228 chdir($tmpPath);
00229 }
00230
00237 function resetUserLanguage($lang_key)
00238 {
00239 $q = "UPDATE usr_pref SET ".
00240 "value = '".$this->lang_default."' ".
00241 "WHERE keyword = 'language' ".
00242 "AND value = '".$lang_key."'";
00243 $this->ilias->db->query($q);
00244 }
00245
00255 function cut_header ($content)
00256 {
00257 foreach ($content as $key => $val)
00258 {
00259 if (trim($val) == "<!-- language file start -->")
00260 {
00261 return array_slice($content,$key +1);
00262 }
00263 }
00264
00265 return false;
00266 }
00267
00273 function optimizeData ()
00274 {
00275
00276 $q = "OPTIMIZE TABLE lng_data";
00277 $this->ilias->db->query($q);
00278
00279 return true;
00280 }
00281
00291 function check ()
00292 {
00293 $tmpPath = getcwd();
00294 chdir ($this->lang_path);
00295
00296
00297 $lang_file = "ilias_".$this->key.".lang";
00298
00299
00300 if (!is_file($lang_file))
00301 {
00302 $this->ilias->raiseError("File not found: ".$lang_file,$this->ilias->error_obj->MESSAGE);
00303 }
00304
00305
00306 if (!$content = $this->cut_header(file($lang_file)))
00307 {
00308 $this->ilias->raiseError("Wrong Header in ".$lang_file,$this->ilias->error_obj->MESSAGE);
00309 }
00310
00311
00312 foreach ($content as $key => $val)
00313 {
00314 $separated = explode ($this->separator,trim($val));
00315 $num = count($separated);
00316
00317 if ($num != 3)
00318 {
00319 $this->ilias->raiseError("Wrong parameter count in ".$lang_file."! Please check your language file!",$this->ilias->error_obj->MESSAGE);
00320 }
00321 }
00322
00323 chdir($tmpPath);
00324
00325
00326 return true;
00327 }
00328 }
00329 ?>