/** * Check - charset enabledor not * * @return boolean */ protected function isCharsetEnabled() { return \XLite\Core\Iconv::getInstance()->isValid(); }
/** * Initialize * * @return void */ protected function initialize() { $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->getOptions()->dir); // Unpack foreach ($this->getOptions()->files as $path) { if (\XLite\Core\Archive::getInstance()->isArchive($path)) { \XLite\Core\Archive::getInstance()->unpack($path, $dir, true); $this->getOptions()->linkedFiles[$path] = \XLite\Core\Archive::getInstance()->getList($path); } } // Delete all logs \XLite\Core\Database::getRepo('XLite\\Model\\ImportLog')->clearAll(); // Convert charsets if (static::DEFAULT_CHARSET != $this->getOptions()->charset) { $iconv = \XLite\Core\Iconv::getInstance(); foreach ($this->getCSVList() as $file) { $iconv->convertFile($this->getOptions()->charset, static::DEFAULT_CHARSET, $file->getPathname()); } } // Preprocess import data if ($this->preprocessImport()) { // Save import options if they were changed $record = \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventState('import'); $record['state'] = \XLite\Core\EventTask::STATE_IN_PROGRESS; $record['options'] = $this->getOptions()->getArrayCopy(); \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->setEventState('import', $record); } }
/** * Convert charset * * @param array $row Row * * @return array */ protected function convertCharset(array $row) { if (static::DEFAULT_CHARSET != $this->generator->getOptions()->charset && \XLite\Core\Iconv::getInstance()->isValid()) { $iconv = \XLite\Core\Iconv::getInstance(); foreach ($row as $k => $v) { $row[$k] = $iconv->convert(static::DEFAULT_CHARSET, $this->generator->getOptions()->charset, $v); } } return $row; }
/** * Get strftime() with specified format and timestamp value * * @param string $format Format string * @param integer $base UNIX time stamp OPTIONAL * * @return string */ protected static function getStrftime($format, $base = null) { static::setLocaleToUTF8(); $win = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; if ($win) { $format = str_replace('%e', '%#d', $format); } $date = null !== $base ? strftime($format, $base) : strftime($format); if ($win) { $locale = setlocale(LC_TIME, 0); if (preg_match('/(([^_]+)_?([^.]*))\\.?(.*)?/', $locale, $match) && preg_match('/^.+_.+\\.(\\d+)$/', $match[0], $match) && \XLite\Core\Iconv::getInstance()->isValid()) { $date = \XLite\Core\Iconv::getInstance()->convert('WINDOWS-' . $match[1], 'UTF-8', $date) ?: $date; } elseif (!empty(static::$charsetsTable[$locale])) { $date = \XLite\Core\Iconv::getInstance()->convert(static::$charsetsTable[$locale], 'UTF-8', $date) ?: $date; } } return $date; }
/** * Get default options * * @return array */ protected function getDefaultOptions() { return \XLite\Core\Iconv::getInstance()->getCharsets(); }