• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Language/classes/class.ilObjLanguageFolder.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00036 require_once "./classes/class.ilObject.php";
00037 
00038 class ilObjLanguageFolder extends ilObject
00039 {
00046         var $lang_default;
00047 
00056         var $lang_user;
00057 
00066         var $lang_path;
00067 
00073         var $separator;
00074 
00081         var $languages;
00082 
00089         function ilObjLanguageFolder($a_id,$a_call_by_reference = true)
00090         {
00091                 $this->type = "lngf";
00092                 $this->ilObject($a_id,$a_call_by_reference);
00093 
00094                 // init language support
00095                 global $lng;
00096 
00097                 $this->lang_path = $lng->lang_path;
00098                 $this->lang_default = $lng->lang_default;
00099                 $this->lang_user = $lng->lang_user;
00100                 $this->separator = $lng->separator;
00101         }
00102 
00117         function getLanguages ()
00118         {
00119                 global $lng;
00120                 
00121                 $lng->loadLanguageModule("meta");
00122 
00123                 // set path to directory where lang-files reside
00124                 $d = dir($this->lang_path);
00125                 $tmpPath = getcwd();
00126                 chdir ($this->lang_path);
00127 
00128                 // get available lang-files
00129                 while ($entry = $d->read())
00130                 {
00131                         if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
00132                         {
00133                                 $lang_key = substr($entry,6,2);
00134                                 $languages[$lang_key] = ""; // long names will be set in class Out
00135                         }
00136                 }
00137 
00138                 // ensure that arrays are initiated when no lang file was found
00139                 if (!array($languages))
00140                 {
00141                         $language = array();
00142                         $tmp_array = array();
00143                 }
00144 
00145                 $tmp_array = array_keys($languages);
00146                 $lang_keys = array();
00147 
00148                 // now get languages from database
00149                 if ($lang_db = ilObject::_getObjectsByType("lng"))
00150                 {
00151                         foreach ($lang_db as $lang)
00152                         {
00153                                 // set values
00154                                 $lang_key = $lang["title"];
00155                                 $languages[$lang_key] = $lang;
00156                                 $lang_keys[] = $lang_key;
00157 
00158                                 // determine default language and language of current user
00159                                 if ($lang_key == $this->lang_user)
00160                                 {
00161                                         $languages[$lang_key]["status"] = "in_use";
00162                                 }
00163 
00164                                 if ($lang_key == $this->lang_default)
00165                                 {
00166                                         $languages[$lang_key]["status"] = "system_language";
00167                                 }
00168 
00169                                 // check if files are missing
00170                                 if ((count($tmp_array) > 0) && (!in_array($lang_key,$tmp_array)))
00171                                 {
00172                                         $languages[$lang_key]["info"] = "file_not_found";
00173                                 }
00174                         }
00175                 }
00176 
00177                 // compute new languages
00178                 foreach ($languages as $lang_key => $lang_data)
00179                 {
00180                         if (!in_array($lang_key,$lang_keys))
00181                         {
00182                                 $languages[$lang_key]["info"] = "new_language";
00183                                 //$languages[$lang_key]["desc"] = "not_installed";
00184                         }
00185                 }
00186 
00187                 chdir($tmpPath);
00188                 
00189                 // Insert languages with files new found into table language
00190                 $languages = $this->addNewLanguages($languages);
00191 
00192                 // Remove from array & db languages which are not installed and no lang-files
00193                 $languages = $this->removeLanguages($languages);
00194 
00195                 // setting language's full names
00196                 foreach ($languages as $lang_key => $lang_data)
00197                 {
00198                         $languages[$lang_key]["name"] = $lng->txt("meta_l_".$lang_key);
00199                 }
00200 
00201                 $this->languages = $languages;
00202 
00203                 return $this->languages;
00204         }
00205 
00216         function addNewLanguages($a_languages)
00217         {
00218                 if (count($a_languages) > 0)
00219                 {
00220                         foreach ($a_languages as $lang_key => $lang_data)
00221                         {
00222                                 if ($lang_data["info"] == "new_language")
00223                                 {
00224                                         include_once("./Services/Language/classes/class.ilObjLanguage.php");
00225                                         $lngObj =& new ilObjLanguage();
00226                                         $lngObj->setTitle($lang_key);
00227                                         $lngObj->setDescription("not_installed");
00228                                         $lngObj->create();
00229 
00230                                         // must get OOP through the whole class some time
00231                                         // (no arrays with db fields! this class doesn't know anything about table object!)
00232                                         $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
00233                                                                                                         "type" => $lngObj->getType(),
00234                                                                                                         "description" => $lngObj->getDescription(),
00235                                                                                                         "desc" => $lngObj->getDescription(),
00236                                                                                                         "owner" => $lngObj->getOwner(),
00237                                                                                                         "create_date" => $lngObj->getCreateDate(),
00238                                                                                                         "last_update" => $lngObj->getLastUpdateDate());
00239 
00240                                         $a_languages[$lang_key]["info"] = "new_language";
00241                                         unset($lngObj);                 // better: the objects should be resident in an member array of this class
00242                                 }
00243                         }
00244                 }
00245 
00246                 return $a_languages;
00247         }
00248 
00259         function removeLanguages($a_languages)
00260         {
00261                 global $ilDB;
00262                 
00263                 foreach ($a_languages as $lang_key => $lang_data)
00264                 {
00265                         if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found")
00266                         {
00267                                 // update languages array
00268                                 unset($a_languages[$lang_key]);
00269 
00270                                 // update object_data table
00271                                 $query = "DELETE FROM object_data ".
00272                                                  "WHERE type = 'lng' ".
00273                                                  "AND title = ".$ilDB->quote($lang_key);
00274                                 $this->ilias->db->query($query);
00275                         }
00276                 }
00277 
00278                 return $a_languages;
00279         }
00280 
00289         function checkAllLanguages()
00290         {
00291                 // TODO: lng object should not be used in this class
00292                 global $lng;
00293 
00294                 // set path to directory where lang-files reside
00295                 $d = dir($this->lang_path);
00296                 $tmpPath = getcwd();
00297                 chdir ($this->lang_path);
00298 
00299                 // for giving a message when no lang-file was found
00300                 $found = false;
00301 
00302                 // get available lang-files
00303                 while ($entry = $d->read())
00304                 {
00305                         if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
00306                         {
00307                                 // textmeldung, wenn langfile gefunden wurde
00308                                 $output .= "<br/><br/>".$lng->txt("langfile_found").": ".$entry;
00309                                 $content = file ($entry);
00310 
00311                                 $found = true;
00312                                 $error = false;
00313 
00314                                 if ($content = ilObjLanguage::cut_header($content))
00315                                 {
00316                                         foreach ($content as $key => $val)
00317                                         {
00318                                                 $separated = explode ($this->separator,trim($val));
00319                                                 $num = count($separated);
00320 
00321                                                 if ($num != 3)
00322                                                 {
00323                                                         $error = true;
00324                                                         $line = $key + 37;
00325 
00326                                 $output .= "<br/><b/>".$lng->txt("err_in_line")." ".$line." !</b>&nbsp;&nbsp;";
00327                                 $output .= $lng->txt("module").": ".$separated[0];
00328                                 $output .= ", ".$lng->txt("identifier").": ".$separated[1];
00329                                 $output .= ", ".$lng->txt("value").": ".$separated[2];
00330 
00331                                                         switch ($num)
00332                                                         {
00333                                                                 case 1:
00334                                                                         if (empty($separated[0]))
00335                                                                         {
00336                                                                                 $output .= "<br/>".$lng->txt("err_no_param")." ".$lng->txt("check_langfile");
00337                                                                         }
00338                                                                         else
00339                                                                         {
00340                                                                                 $output .= "<br/>".$lng->txt("err_1_param")." ".$lng->txt("check_langfile");
00341                                                                         }
00342                                                                 break;
00343 
00344                                                                 case 2:
00345                                                                         $output .= "<br/>".$lng->txt("err_2_param")." ".$lng->txt("check_langfile");
00346                                                                 break;
00347 
00348                                                                 default:
00349                                                                         $output .= "<br/>".$lng->txt("err_over_3_param")." ".$lng->txt("check_langfile");
00350                                                                 break;
00351                                                         }
00352                                                 }
00353                                         }
00354 
00355                                         if ($error) {
00356                                                 $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_count_param");
00357                                         }
00358                                         else {
00359                                                 $output .= "<br/>".$lng->txt("file_valid");
00360                                         }
00361                                 }
00362                                 else {
00363                                         $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_wrong_header");
00364                                 }
00365                         }
00366                 }
00367 
00368                 $d->close();
00369 
00370                 if (!$found) {
00371                         $output .= "<br/>".$lng->txt("err_no_langfile_found");
00372                 }
00373 
00374                 chdir($tmpPath);
00375                 return $output;
00376         }
00377 } // END class.LanguageFolderObject
00378 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1