$v) { if (is_string($v)) { $v = $textutil->html_numeric_entities($v); $v = mb_decode_numericentity($v, array(0x0, 0x10000, 0, 0xfffff), 'UTF-8'); $data[$k] = \Normalizer::normalize(trim($v), \Normalizer::FORM_C); } elseif (null === $v) { $data[$k] = ''; } } } public static function convertToInt(&$data, $keys, $zerofill = false) { foreach ($keys as $key) { if (isset($data[$key])) { $data[$key] = '' === $data[$key] ? ($zerofill ? 0 : null) : (int) $data[$key]; } } } public static function dropColumn(&$data, $keys) { foreach ($keys as $key) { if (isset($data[$key])) { unset($data[$key]); } } } public static function fileCopy($from, $to) { system('rsync -aq '.escapeshellarg($from).' '.escapeshellarg($to), $ret); return 0 === $ret; } public static function fixHtml($text) { static $config = [ //'clean' => true, 'hide-comments' => true, 'indent' => true, 'output-xhtml' => true, 'preserve-entities' => true, 'show-body-only' => true, 'wrap' => 0, 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'output-bom' => false, ]; $text = tidy_repair_string($text, $config); $text = preg_replace('/]*)>((?:\s*]*>.*<\/caption>)?\s*)]*)>/Us', '\2', $text); $text = preg_replace('/<\/tr>(\s*)<\/table>/s', '\1', $text); return $text; } public static function tableExists($name) { global $xoopsDB; $prefix = $xoopsDB->prefix(); $sql = <<< SQL SELECT 1 FROM `${prefix}_${name}` LIMIT 1 SQL; if (!($res = $xoopsDB->query($sql))) { return false; } $xoopsDB->freeRecordSet($res); return true; } public static function makeDirectory($dirname) { $path = MYDUMPTOOL_OUTPUTDIR.('' !== $dirname ? '/'.$dirname : ''); if (!is_dir($path)) { if (!@mkdir($path)) { exit('Failed to create directory: '.$path.PHP_EOL); } } } public static function saveJson($fname, $data) { $path = MYDUMPTOOL_OUTPUTDIR.'/'.$fname; if (false === file_put_contents($path, json_encode($data, JSON_UNESCAPED_UNICODE))) { exit('Failed to save json file: '.$path.PHP_EOL); } } public static function fileDownload($url, $fpath) { $fp = fopen($fpath, 'w'); if (false === $fp) { exit('Failed to open file: '.$fpath.PHP_EOL); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_AUTOREFERER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_TIMEOUT, 10); $ret = curl_exec($curl); fclose($fp); if (false === $ret) { exit('Failed to download file, unexpected error: '.$url.PHP_EOL); } $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if (200 !== $code) { exit('Failed to download file, invalid status code('.$code.'): '.$url.PHP_EOL); } curl_close($curl); return true; } public static function getMimeType($fpath) { $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $fpath); finfo_close($finfo); $mime = preg_replace('/(;.*)$/', '', $mime); return $mime; } }