$v) {
if (is_string($v)) {
$v = html_entity_decode($v, ENT_QUOTES | ENT_HTML5);
$v = mb_decode_numericentity($v, [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,
'drop-proprietary-attributes' => true,
'logical-emphasis' => 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);
$text = tidy_repair_string($text, $config);
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, 0755, true)) {
exit('Failed to create directory: '.$path.PHP_EOL);
}
}
}
public static function saveJson($fname, $data)
{
$path = MYDUMPTOOL_OUTPUTDIR.'/'.$fname;
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
if (false === $data) {
echo json_last_error_msg().PHP_EOL;
exit('Failed to encode json data: '.$path.PHP_EOL);
}
if (false === file_put_contents($path, $data)) {
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) {
unlink($fpath);
echo 'Failed to download file, unexpected error: '.$url.PHP_EOL;
return false;
}
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (200 !== $code) {
unlink($fpath);
echo 'Failed to download file, invalid status code('.$code.'): '.$url.PHP_EOL;
return false;
}
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;
}
public static function getModule($dirname)
{
$moduleHandler = xoops_gethandler('module');
$moduleObj = $moduleHandler->getByDirname($dirname);
return [
'id' => (int) $moduleObj->get('mid'),
'name' => $moduleObj->get('name'),
'dirname' => $moduleObj->get('dirname'),
'version' => (int) $moduleObj->get('version'),
'lastupdate' => (int) $moduleObj->get('last_update'),
];
}
public static function canModuleRead($dirname, $uid)
{
$moduleHandler = xoops_gethandler('module');
$moduleObj = $moduleHandler->getByDirname($dirname);
$moduleId = (int) $moduleObj->get('mid');
$memberHandler = xoops_gethandler('member');
$groupIds = 0 === $uid ? [XOOPS_GROUP_ANONYMOUS] : $memberHandler->getGroupsByUser($uid);
$groupPermHandler = xoops_gethandler('groupperm');
$ret = $groupPermHandler->checkRight('module_read', $moduleId, $groupIds);
return $ret;
}
public static function mlang($s, $url, $lang)
{
if (!defined('CUBE_UTILS_ML_LANGS')) {
exit('Error: cubeUtils is not loaded'.PHP_EOL);
}
$mLanguage = $lang;
$mLanguages = explode(',', CUBE_UTILS_ML_LANGS);
$mLanguageNames = explode(',', CUBE_UTILS_ML_LANGNAMES);
// escape brackets inside of
$s = preg_replace_callback('/(\]*)(\>)/isU', 'self::mlang_escapeBracketTextBox', $s);
// escape brackets inside of
$s = preg_replace_callback('/(\