Files
visiome.neuroinf.jp/etc/dumpCredits.php
T

130 lines
3.6 KiB
PHP

<?php
require_once __DIR__.'/common.inc.php';
$prefix = $xoopsDB->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);
$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}' => '<s>'.$textutil->html_special_chars($org['com_email']).'</s>(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[] = ' <li>'.$textutil->html_special_chars($m['name'].' : '.$m['division']).'</li>';
}
$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
<h4>${committee}</h4>
<ul>
<li>Members
<ul>
${members}
</ul>
</li>
</ul>
HTML;
return $html;
}