prefix();
$table = 'nipfcredits_organization';
if (!MyDumpTool::tableExists($table)) {
exit('credits module not found'.PHP_EOL);
}
MyDumpTool::makeDirectory('src/credits');
MyDumpTool::makeDirectory('src/credits/assets');
// organization
$organization = [];
$sql = <<< SQL
SELECT
`o`.*
FROM `${prefix}_nipfcredits_organization` AS `o`
SQL;
if (!($res = $xoopsDB->query($sql))) {
var_dump($xoopsDB);
exit();
}
while ($row = $xoopsDB->fetchArray($res)) {
MyDumpTool::decode($row);
$organization = $row;
}
$xoopsDB->freeRecordSet($res);
$organization['com_email'] = str_replace('@', ' (at) ', $organization['com_email']);
$organization['com_url'] = XOOPS_URL;
$organization['institute'] = 'Neuroinformatics Unit, RIKEN Center for Brain Science';
$organization['url'] = 'https://www.ni.riken.jp/';
$organization['email'] = 'office (at) ni.riken.jp';
$organization['address'] = 'Hirosawa 2-1, Wako, Saitama, 351-0198 Japan';
$organization['tel'] = '+81 48 (462) 1111';
// member
$member = [];
$sql = <<< SQL
SELECT
`m`.*
FROM `${prefix}_nipfcredits_member` AS `m`
ORDER BY `m`.`weight`
SQL;
if (!($res = $xoopsDB->query($sql))) {
var_dump($xoopsDB);
exit();
}
while ($row = $xoopsDB->fetchArray($res)) {
MyDumpTool::decode($row);
$member[] = $row;
}
$xoopsDB->freeRecordSet($res);
$opage = getOrganizationPage($organization, $member);
//var_dump($opage);
// pages
$pages = [];
$sql = <<< SQL
SELECT
`p`.*
FROM `${prefix}_nipfcredits_page` AS `p`
ORDER BY `p`.`weight`
SQL;
if (!($res = $xoopsDB->query($sql))) {
var_dump($xoopsDB);
exit();
}
while ($row = $xoopsDB->fetchArray($res)) {
MyDumpTool::decode($row);
myDumpTool::convertToInt($row, ['pid', 'weight', 'lastupdate']);
$content = replaceOrganization($row['content'], $organization);
$content = MyDumpTool::fixHtml($content);
$content = preg_replace('/href="(?:\.\/|'.preg_quote(XOOPS_URL, '/').'\/modules\/credits\/)?index\.php\?id=(\d+)"/', 'href="/credits/\1"', $content);
$imageUrl = [];
$content = preg_replace_callback('/
]*)src="([^"]+)"([^>]*)\/>/Usi', function ($matches) use (&$imageUrl, $row) {
$url = $matches[2];
if (preg_match('/^(.+)\/([^\/]+\.(:?png|jpg|gif|svg))(\?.+)?$/i', $url, $m)) {
if (!isset($imageUrl[$m[1]])) {
$imageUrl[$m[1]] = count($imageUrl) + 1;
}
$id = $imageUrl[$m[1]];
$fname = '/credits/images/'.$row['pid'].'/'.$id.'/'.urldecode($m[2]);
$fpath = MYDUMPTOOL_OUTPUTDIR.'/public'.$fname;
if (!file_exists($fpath)) {
MyDumpTool::makeDirectory('public/credits');
MyDumpTool::makeDirectory('public/credits/images');
MyDumpTool::makeDirectory('public/credits/images/'.$row['pid']);
MyDumpTool::makeDirectory('public/credits/images/'.$row['pid'].'/'.$id);
if (preg_match('/^\//', $url)) {
$url = XOOPS_URL.$url;
}
MyDumpTool::fileDownload($url, $fpath);
}
$url = '/credits/images/'.$row['pid'].'/'.$id.'/'.$m[2];
}
return '
';
}, $content);
$content = preg_replace('/]*)href="(?:'.preg_quote(XOOPS_URL, '/').')?\/modules\/xoonips\/(?:register|edit|user)[^"]*"(?:[^>]*)>(.*)<\/a>/Usi', '\1(closed)', $content);
$row['content'] = $content;
MyDumpTool::dropColumn($row, ['weight']);
$pages[] = $row;
}
$xoopsDB->freeRecordSet($res);
//var_dump($pages);
$data = [
'organization' => $opage,
'pages' => $pages,
];
MyDumpTool::saveJson('src/credits/assets/credits.json', $data);
function replaceOrganization($text, $org)
{
$textutil = xoonips_getutility('text');
$map = [
'{COMMITTEE_NAME}' => $textutil->html_special_chars($org['committee']),
'{COMMITTEE_EMAIL}' => ''.$textutil->html_special_chars($org['com_email']).'(committee email has been closed)',
'{INSTITUTE_NAME}' => $textutil->html_special_chars($org['institute']),
'{INSTITUTE_URL}' => $textutil->html_special_chars($org['url']),
'{INSTITUTE_EMAIL}' => $textutil->html_special_chars($org['email']),
'{INSTITUTE_ADDRESS}' => $textutil->html_special_chars($org['address']),
'{INSTITUTE_TEL}' => $textutil->html_special_chars($org['tel']),
'{PLATFORM_URL}' => XOOPS_URL,
];
return str_replace(array_keys($map), $map, $text);
}
function getOrganizationPage($org, $member)
{
$textutil = xoonips_getutility('text');
$members = [];
foreach ($member as $m) {
$members[] = ' '.$textutil->html_special_chars($m['name'].' : '.$m['division']).'';
}
$members = implode("\n", $members);
$committee = $textutil->html_special_chars($org['committee']);
$institute = $textutil->html_special_chars($org['institute']);
$address = $textutil->html_special_chars($org['address']);
$url = $textutil->html_special_chars($org['url']);
$html = <<< HTML
${committee}
HTML;
return $html;
}