public function readLanguage($aModuleConfig) { $sPath = BX_INSTALL_DIR_MODULES . $aModuleConfig['home_dir'] . 'data/langs/system/' . $aModuleConfig['home_uri'] . '.xml'; if (!file_exists($sPath)) { return array(); } $oXmlParser = BxDolXmlParser::getInstance(); $sXmlContent = file_get_contents($sPath); return $oXmlParser->getValues($sXmlContent, 'string'); }
protected function _restoreLanguageByModule($aLanguage, $sPath, $mixedModule) { $oXmlParser = BxDolXmlParser::getInstance(); $aModule = $mixedModule; if (!is_array($mixedModule)) { $sMethod = is_string($mixedModule) && !is_numeric($mixedModule) ? 'getModuleByUri' : 'getModuleById'; $aModule = BxDolModuleQuery::getInstance()->{$sMethod}($mixedModule); } if (empty($aModule) || !is_array($aModule) || !$aModule['uri'] || !$aModule['lang_category']) { return true; } $sPath = $sPath . $aModule['uri'] . '.xml'; if (!file_exists($sPath) && isset($aModule['path'])) { $sPath = BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'install/langs/' . $aLanguage['name'] . '.xml'; if (!file_exists($sPath)) { return true; } } $aLanguageInfo = $this->readLanguage($sPath); if (empty($aLanguageInfo['name']) || empty($aLanguageInfo['strings']) || $aLanguageInfo['name'] != $aLanguage['name']) { return false; } $aCategory = array(); $this->oDb->getCategoriesBy(array('type' => 'by_name', 'value' => $aModule['lang_category']), $aCategory, false); $iCategoryId = 0; if (empty($aCategory) || !is_array($aCategory)) { $iCategoryId = $this->addLanguageCategory($aModule['lang_category']); if (empty($iCategoryId)) { return false; } } else { $iCategoryId = $aCategory['id']; } $bDeleteStringsByKey = !$this->oDb->deleteStringsBy(array('type' => 'by_cat_and_lang', 'category_id' => $iCategoryId, 'language_id' => $aLanguage['id'])); $bResult = true; foreach ($aLanguageInfo['strings'] as $sKey => $sValue) { if ($sKey != '') { if ($bDeleteStringsByKey) { $this->oDb->deleteStringsBy(array('type' => 'by_key_and_lang', 'key' => $sKey, 'language_id' => $aLanguage['id'])); } $bResult &= $this->addLanguageString($sKey, $sValue, $aLanguage['id'], $iCategoryId, false) > 0; } } return $bResult; }
public function main() { $a = getopt('hqsm:l:i:f:u:'); if (isset($a['h'])) { $this->finish(0, $this->getHelp()); } if (isset($a['q'])) { $this->_bQuiet = true; } if (isset($a['s'])) { $this->_bSortOutput = true; } if (isset($a['m'])) { $this->_sModule = $a['m']; } if (isset($a['l'])) { $this->_iLimit = (int) $a['l']; } if (isset($a['i'])) { $this->_sInputFile = $a['i']; } if (!$this->_sInputFile || !file_exists($this->_sInputFile)) { $this->finish(2, 'Input file not exist - ' . $this->_sInputFile); } if (isset($a['f'])) { $this->_sOutputFoundFile = $a['f']; } if (isset($a['u'])) { $this->_sOutputUnusedFile = $a['u']; } $aOptions = $this->_sModule ? $this->prepareModuleConfig($this->_aOptionsModule) : $this->_aOptionsSystem; $iTimeStart = microtime(); $this->output('Processing ' . ($this->_iLimit > 0 ? "first {$this->_iLimit} strings of " : '') . $this->_sInputFile . ' ' . ($this->_sModule ? 'module(' . $this->_sModule . ')' : 'system') . ' language file...'); $this->output(''); $oXmlParser = BxDolXmlParser::getInstance(); $sXmlContent = file_get_contents($this->_sInputFile); $LANG = $oXmlParser->getValues($sXmlContent, 'string'); $LANG_FOUND = array(); $LANG_LOST = array(); $iCount = 1; foreach ($LANG as $sKey => $sString) { if ($this->findLangKey($sKey, $aOptions)) { $LANG_FOUND[$sKey] = $sString; } else { $LANG_LOST[$sKey] = $sString; } if (++$iCount > $this->_iLimit && $this->_iLimit > 0) { break; } } if (!$this->_bQuiet) { $this->output('Found language strings:'); $this->output('-----------------------'); empty($LANG_FOUND) ? $this->output('Empty') : $this->output($this->xmlExport($LANG_FOUND), false); $this->output(''); } if ($this->_bSortOutput) { ksort($LANG_FOUND); } if ($this->_sOutputFoundFile && !empty($LANG_FOUND)) { file_put_contents($this->_sOutputFoundFile, $this->xmlExport($LANG_FOUND)); } if (!$this->_bQuiet) { $this->output('Unused language strings:'); $this->output('------------------------'); empty($LANG_LOST) ? $this->output('Empty') : $this->output($this->xmlExport($LANG_LOST), false); $this->output(''); } if ($this->_bSortOutput) { ksort($LANG_LOST); } if ($this->_sOutputUnusedFile && !empty($LANG_LOST)) { file_put_contents($this->_sOutputUnusedFile, $this->xmlExport($LANG_LOST)); } $i1 = explode(' ', microtime()); $i2 = explode(' ', $iTimeStart); $iSec = round($i1[0] + $i1[1] - ($i2[0] + $i2[1]), 3); $this->output("Time ({$iCount}): " . $iSec . ' sec'); if ($this->_iLimit > 0) { $iTotalSec = round(count($LANG) / $iCount * ($i1[0] + $i1[1] - ($i2[0] + $i2[1])), 3); $this->output("Estimated Total Time (" . count($LANG) . "): " . $iTotalSec . ' sec (' . round($iTotalSec / 60.0, 3) . ' min)'); } $this->finish(empty($LANG_LOST) ? 0 : 1); }