/** * Read the translation's file which hold informations about all translators * and put it into database. */ public function updateTranslatorInfo() { $ExistingLanguage = $this->getExistingLanguage(); $am = AccountManager::getInstance(); foreach ($ExistingLanguage as $lang) { $lang = $lang["code"]; $txml = false; // Path to find translation.xml file, set default values, // in case we can't find the translation file $translation_xml = new File($lang, '/translation.xml'); if (file_exists($translation_xml->full_path)) { // Else go on, and load in the file, replacing all // space type chars with one space $txml = preg_replace('/\\s+/', ' ', $translation_xml->read(true)); } if ($txml) { // Find all persons matching the pattern $matches = array(); if (preg_match_all('!<person (.+)/\\s?>!U', $txml, $matches)) { $default = array('vcs' => 'n/a', 'nick' => 'n/a', 'editor' => 'n/a', 'email' => 'n/a', 'name' => 'n/a'); $persons = $translation_xml->parseAttribute($matches[1]); $charset = $translation_xml->getEncoding($txml); foreach ($persons as $person) { if ($charset == 'utf-8') { $name = utf8_decode($person['name']); } else { $name = $person['name']; } $person = array_merge($default, $person); // We try to remove this record if it exist $query = 'DELETE FROM `translators` WHERE `project`="%s" AND `lang`="%s" AND `nick`="%s"'; $params = array($am->project, $lang, $person['nick']); $this->conn->query($query, $params); $query = 'INSERT INTO `translators` (`project`, `lang`, `nick`, `name`, `mail`, `vcs`, `editor`) VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s")'; $params = array($am->project, $lang, $person['nick'], $name, $person['email'], $person['vcs'], $person['editor']); $this->conn->query($query, $params); } } } } }