nimg.neuroinf.jp/etc/dumpCredits.php
2022-06-20 17:51:03 +09:00

155 lines
4.8 KiB
PHP

<?php
require_once __DIR__.'/common.inc.php';
require_once __DIR__.'/extras.inc.php';
$prefix = $xoopsDB->prefix();
$table = 'nipfcredits_organization';
if (!MyDumpTool::tableExists($table)) {
exit('credits module not found'.PHP_EOL);
}
MyDumpTool::makeDirectory('public/modules/credits');
// module
$module = MyDumpTool::getModule('credits');
// 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'] = '[en]Neuroinformatics Unit, RIKEN Center for Brain Science[/en][ja]理化学研究所 脳神経科学研究センター 神経情報基盤ユニット[/ja]';
$organization['url'] = 'https://www.ni.riken.jp/';
$organization['email'] = 'office (at) ni.riken.jp';
$organization['address'] = '[en]Hirosawa 2-1, Wako, Saitama, 351-0198 Japan[/en][ja]埼玉県和光市広沢 2-1[/ja]';
$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, $module);
MyDumpTool::saveJson('public/modules/credits/0.json', $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 = normalizeHtml($content, '/modules/credits/index.php');
$content = preg_replace('/<a (?:[^>]*)href="(?:'.preg_quote(XOOPS_URL, '/').')?\/modules\/xoonips\/(?:register|edit|user)[^"]*"(?:[^>]*)>(.*)<\/a>/Usi', '<s>\1</s>(closed)', $content);
$row['content'] = $content;
MyDumpTool::dropColumn($row, ['weight']);
$pages[] = [
'id' => $row['pid'],
'title' => $row['title'],
];
MyDumpTool::saveJson('public/modules/credits/'.$row['pid'].'.json', $row);
}
$xoopsDB->freeRecordSet($res);
$pages[] = [
'id' => $opage['id'],
'title' => $opage['title'],
];
$data = [
'name' => $module['name'],
'pages' => $pages,
];
MyDumpTool::saveJson('public/modules/credits/index.json', $data);
function replaceOrganization($text, $org)
{
$map = [
'{COMMITTEE_NAME}' => htmlspecialchars($org['committee']),
//'{COMMITTEE_EMAIL}' => '<s>'.htmlspecialchars($org['com_email'], ENT_QUOTES).'</s>(committee email has been closed)',
'{COMMITTEE_EMAIL}' => htmlspecialchars($org['com_email'], ENT_QUOTES),
'{INSTITUTE_NAME}' => htmlspecialchars($org['institute'], ENT_QUOTES),
'{INSTITUTE_URL}' => htmlspecialchars($org['url'], ENT_QUOTES),
'{INSTITUTE_EMAIL}' => htmlspecialchars($org['email'], ENT_QUOTES),
'{INSTITUTE_ADDRESS}' => htmlspecialchars($org['address'], ENT_QUOTES),
'{INSTITUTE_TEL}' => htmlspecialchars($org['tel'], ENT_QUOTES),
'{PLATFORM_URL}' => XOOPS_URL,
];
return str_replace(array_keys($map), $map, $text);
}
function getOrganizationPage($org, $member, $module)
{
$members = [];
if (!empty($member)) {
$members[] = ' <li>[en]Members[/en][ja]委員一覧[/ja]';
$members[] = ' <ul>';
foreach ($member as $m) {
$members[] = ' <li>'.htmlspecialchars($m['name'].' : '.$m['division'], ENT_QUOTES).'</li>';
}
$members[] = ' </ul>';
$members[] = ' </li>';
}
$members = implode("\n", $members);
$committee = htmlspecialchars($org['committee'], ENT_QUOTES);
$institute = htmlspecialchars($org['institute'], ENT_QUOTES);
$address = htmlspecialchars($org['address'], ENT_QUOTES);
$url = htmlspecialchars($org['url'], ENT_QUOTES);
$email = htmlspecialchars($org['com_email'], ENT_QUOTES);
$html = <<< HTML
<h4>${committee}</h4>
<ul>
<li>E-Mail: <strike>${email}</strike></li>
${members}
</ul>
<h4>${institute}</h4>
<ul>
<li>[en]Address[/en][ja]所在地[/ja]: ${address}</li>
<li>URL: <a href="${url}" target="_blank" rel=”noopener noreferrer”>${url}</a></li>
</ul>
HTML;
return [
'id' => 0,
'title' => '[en]About Us[/en][ja]運用母体[/ja]',
'content' => $html,
'lastupdate' => 0,
];
}