107 lines
2.9 KiB
PHP
107 lines
2.9 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/common.inc.php';
|
|
|
|
$data = dumpXwords();
|
|
|
|
MyDumpTool::makeDirectory('public/modules/xwords');
|
|
MyDumpTool::saveJson('public/modules/xwords/index.json', $data);
|
|
|
|
function dumpXwords()
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
|
|
// module
|
|
$module = MyDumpTool::getModule('xwords');
|
|
|
|
// category
|
|
$category = [];
|
|
$sql = <<< SQL
|
|
SELECT
|
|
*
|
|
FROM `${prefix}_xwords_cat`
|
|
ORDER BY `weight` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['categoryID', 'total', 'weight']);
|
|
$category[] = [
|
|
'id' => $row['categoryID'],
|
|
'name' => $row['name'],
|
|
'total' => $row['total'],
|
|
];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
// entry
|
|
$entry = [];
|
|
$sql = <<< SQL
|
|
SELECT
|
|
*
|
|
FROM `${prefix}_xwords_ent`
|
|
WHERE `offline` = 0
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['entryID', 'categoryID', 'datesub', 'counter']);
|
|
$procs = explode(',', $row['proc']);
|
|
$term = $row['term'];
|
|
$yomi = $procs[1];
|
|
$initTerm = mb_substr($term, 0, 1, 'UTF-8');
|
|
$initTerm = mb_convert_kana($initTerm, 'asHc', 'UTF-8');
|
|
$initTerm = strtoupper($initTerm);
|
|
$initYomi = mb_substr($yomi, 0, 1, 'UTF-8');
|
|
$initYomi = mb_convert_kana($initYomi, 'asHc', 'UTF-8');
|
|
$initYomi = strtoupper($initYomi);
|
|
$kana = [
|
|
'01' => '[あ-お]',
|
|
'02' => '[か-こが-ご]',
|
|
'03' => '[さ-そざ-ぞ]',
|
|
'04' => '[た-とだ-ど]',
|
|
'05' => '[な-の]',
|
|
'06' => '[は-ほば-ぼぱ-ぽ]',
|
|
'07' => '[ま-も]',
|
|
'08' => '[や-よ]',
|
|
'09' => '[ら-ろ]',
|
|
'10' => '[わ-ん]',
|
|
'11' => '.*',
|
|
];
|
|
if (preg_match('/^[A-Z]$/', $initTerm)) {
|
|
$init = $initTerm;
|
|
} else {
|
|
foreach ($kana as $index => $pattern) {
|
|
if (preg_match('/^'.$pattern.'/u', $initYomi)) {
|
|
$init = $index;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$entry[] = [
|
|
'id' => $row['entryID'],
|
|
'cat_id' => $row['categoryID'],
|
|
'term' => $row['term'],
|
|
'yomi' => $yomi,
|
|
'initial' => $init,
|
|
'definition' => $row['definition'],
|
|
'timestamp' => $row['datesub'],
|
|
'counter' => $row['counter'],
|
|
];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return [
|
|
'name' => $module['name'],
|
|
'category' => $category,
|
|
'entry' => $entry,
|
|
];
|
|
}
|