182 lines
6.2 KiB
PHP
182 lines
6.2 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('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);
|
|
//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('/<img ([^>]*)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 = '/modules/credits/images/'.$row['pid'].'/'.$id.'/'.urldecode($m[2]);
|
|
$fpath = MYDUMPTOOL_OUTPUTDIR.'/public'.$fname;
|
|
if (!file_exists($fpath)) {
|
|
MyDumpTool::makeDirectory('public/modules/credits/images');
|
|
MyDumpTool::makeDirectory('public/modules/credits/images/'.$row['pid']);
|
|
MyDumpTool::makeDirectory('public/modules/credits/images/'.$row['pid'].'/'.$id);
|
|
if (preg_match('/^\//', $url)) {
|
|
$url = XOOPS_URL.$url;
|
|
}
|
|
MyDumpTool::fileDownload($url, $fpath);
|
|
}
|
|
$url = 'images/'.$row['pid'].'/'.$id.'/'.$m[2];
|
|
}
|
|
|
|
return '<img '.$matches[1].'src="'.$url.'"'.$matches[3].'/>';
|
|
}, $content);
|
|
$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);
|
|
//var_dump($pages);
|
|
|
|
$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)
|
|
{
|
|
$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, $module)
|
|
{
|
|
$textutil = xoonips_getutility('text');
|
|
$members = [];
|
|
if (!empty($member)) {
|
|
$members[] = ' <li>[en]Members[/en][ja]委員一覧[/ja]';
|
|
$members[] = ' <ul>';
|
|
foreach ($member as $m) {
|
|
$members[] = ' <li>'.$textutil->html_special_chars($m['name'].' : '.$m['division']).'</li>';
|
|
}
|
|
$members[] = ' </ul>';
|
|
$members[] = ' </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']);
|
|
$email = $textutil->html_special_chars($org['com_email']);
|
|
$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]Organization[/en][ja]運用母体[/ja]',
|
|
'content' => $html,
|
|
'lastupdate' => 0,
|
|
];
|
|
}
|