示例#1
0
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
define('IMSCP_SETUP', true);
$guiRootDir = rtrim('{GUI_ROOT_DIR}', '/');
if (strpos($guiRootDir, 'GUI_ROOT_DIR') === false) {
    require_once "{$guiRootDir}/library/imscp-lib.php";
    unset($guiRootDir);
    try {
        if (!iMSCP_Update_Database::getInstance()->applyUpdates()) {
            fwrite(STDERR, sprintf("[ERROR] %s\n", iMSCP_Update_Database::getInstance()->getError()));
            exit(1);
        }
        i18n_buildLanguageIndex();
    } catch (Exception $e) {
        fwrite(STDERR, sprintf("[ERROR] %s \n\nStack trace:\n\n%s\n", $e->getMessage(), $e->getTraceAsString()));
        exit(1);
    }
} else {
    fwrite(STDERR, '[ERROR] The GUI root directory is not defined');
    exit(1);
}
示例#2
0
/**
 * Import Machine object file in languages directory
 *
 * @return bool TRUE on success, FALSE otherwise
 */
function i18n_importMachineObjectFile()
{
    // closure that is run before move_uploaded_file() function - See the Utils_UploadFile() function for further
    // information about implementation details
    $beforeMove = function () {
        /** @var $cfg iMSCP_Config_Handler_File */
        $cfg = iMSCP_Registry::get('config');
        $localesDirectory = $cfg->GUI_ROOT_DIR . '/i18n/locales';
        $filePath = $_FILES['languageFile']['tmp_name'];
        if (!is_readable($filePath)) {
            set_page_message(tr('File is not readable.'), 'error');
            return false;
        }
        try {
            $parser = new iMSCP_I18n_Parser_Gettext($filePath);
            $encoding = $parser->getContentType();
            $locale = $parser->getLanguage();
            $revision = $parser->getPoRevisionDate();
            $translationTable = $parser->getTranslationTable();
        } catch (iMSCP_Exception $e) {
            set_page_message(tr('Only gettext Machine Object files (MO files) are accepted.'), 'error');
            return false;
        }
        if (isset($translationTable['_: Localised language'])) {
            $language = $translationTable['_: Localised language'];
        } else {
            $language = '';
        }
        if (empty($encoding) || empty($locale) || empty($revision) || empty($lastTranslator) || empty($language)) {
            set_page_message(tr("%s is not a valid i-MSCP language file.", tohtml($_FILES['languageFile']['name'])), 'error');
            return false;
        }
        if (!is_dir("{$localesDirectory}/{$locale}")) {
            if (!@mkdir("{$localesDirectory}/{$locale}", 0700)) {
                set_page_message(tr("Unable to create '%s' directory for language file.", tohtml($locale)), 'error');
                return false;
            }
        }
        if (!is_dir("{$localesDirectory}/{$locale}/LC_MESSAGES")) {
            if (!@mkdir("{$localesDirectory}/{$locale}/LC_MESSAGES", 0700)) {
                set_page_message(tr("Unable to create 'LC_MESSAGES' directory for language file."), 'error');
                return false;
            }
        }
        // Return destination file path
        return "{$localesDirectory}/{$locale}/LC_MESSAGES/{$locale}.mo";
    };
    if (utils_uploadFile('languageFile', array($beforeMove)) === false) {
        return false;
    }
    // Rebuild language index
    i18n_buildLanguageIndex();
    return true;
}