1063 lines
37 KiB
PHP
1063 lines
37 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/common.inc.php';
|
|
|
|
$METADATA = json_decode(file_get_contents(__DIR__.'/metadata.json'), true);
|
|
|
|
$prefix = $xoopsDB->prefix();
|
|
|
|
$table = 'xoonips_index';
|
|
if (!MyDumpTool::tableExists($table)) {
|
|
exit('xoonips module not found'.PHP_EOL);
|
|
}
|
|
MyDumpTool::makeDirectory('src/xoonips/assets');
|
|
MyDumpTool::makeDirectory('public/modules/xoonips/file');
|
|
|
|
// get public index with certified item count
|
|
$sql = <<< SQL
|
|
SELECT
|
|
`idx`.*,
|
|
(SELECT COUNT(*)
|
|
FROM `${prefix}_xoonips_index_item_link` AS `iil`
|
|
INNER JOIN `${prefix}_xoonips_item` AS `item` ON `iil`.`item_id`=`item`.`item_id`
|
|
WHERE `iil`.`index_id`=`idx`.`index_id` AND `iil`.`certify_state`=2
|
|
) AS `num_items`
|
|
FROM `${prefix}_xoonips_index` AS `idx`
|
|
WHERE `idx`.`open_level`=1
|
|
SQL;
|
|
|
|
$limitItems = [];
|
|
$limitFiles = [];
|
|
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$tree = [];
|
|
$root = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
$tree[$row['index_id']] = $row;
|
|
$root[$row['parent_index_id']][$row['weight']] = $row['index_id'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
foreach ($root as &$node) {
|
|
ksort($node);
|
|
}
|
|
unset($node);
|
|
|
|
$data[] = getTreeNode($tree, $root, 2);
|
|
MyDumpTool::saveJson('src/xoonips/assets/tree.json', $data);
|
|
unset($data, $root);
|
|
|
|
// get item types
|
|
$itemTypes = getItemTypes();
|
|
MyDumpTool::saveJson('itemTypes.json', $itemTypes);
|
|
|
|
// get public items
|
|
$sql = <<< SQL
|
|
SELECT
|
|
`item`.*,
|
|
`ity`.`name` AS `item_type_display_name`
|
|
FROM `${prefix}_xoonips_item` AS `item`
|
|
INNER JOIN `${prefix}_xoonips_item_type` AS `ity` ON `item`.`item_type_id`=`ity`.`item_type_id`
|
|
INNER JOIN `${prefix}_xoonips_index_item_link` AS `iil` ON `item`.`item_id`=`iil`.`item_id`
|
|
INNER JOIN `${prefix}_xoonips_index` AS `idx` ON `iil`.`index_id`=`idx`.`index_id`
|
|
WHERE `iil`.`certify_state`=2
|
|
AND `idx`.`open_level`=1
|
|
GROUP BY `item`.`item_id`
|
|
ORDER BY `item`.`item_id` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$itemsRaw = [];
|
|
$items = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['item_id', 'item_type_id', 'last_update_date', 'creation_date']);
|
|
$item_id = $row['item_id'];
|
|
$item_type = str_replace(' ', '_', strtolower($row['item_type_display_name']));
|
|
$row['item_type_name'] = $item_type;
|
|
$row['owner'] = getUsers($item_id);
|
|
$row['index'] = getIndexes($tree, $row['item_id']);
|
|
if (0 === count($row['index'])) {
|
|
// no public indexes found.
|
|
continue;
|
|
}
|
|
$row['detail'] = getItemDetail($item_id, $item_type);
|
|
$itemsRaw[] = $row;
|
|
if (1 !== count($row['owner'])) {
|
|
die('does\'nt suuport more than one item owner'.PHP_EOL);
|
|
}
|
|
$item = [
|
|
'item_id' => $item_id,
|
|
'doi' => $row['doi'],
|
|
'description' => '',
|
|
'last_update_date' => $row['last_update_date'],
|
|
'creation_date' => $row['creation_date'],
|
|
'publication_year' => 0,
|
|
'publication_month' => 0,
|
|
'publication_mday' => 0,
|
|
'lang' => '',
|
|
'title' => '',
|
|
'item_type_display_name' => $row['item_type_display_name'],
|
|
'item_type_name' => $row['item_type_name'],
|
|
'uname' => $row['owner'][0]['uname'],
|
|
'name' => $row['owner'][0]['name'],
|
|
'item_url' => getItemUrl($row),
|
|
'index' => $row['index'],
|
|
'changelog' => [],
|
|
'related_to' => [],
|
|
'keyword' => [],
|
|
'file' => [],
|
|
];
|
|
$itemType = $itemTypes[$item_type];
|
|
foreach ($row['detail'] as $gxml => $gdata) {
|
|
$ginfo = $itemType['groups'][$gxml];
|
|
foreach ($gdata as $fxml => $fdata) {
|
|
$finfo = $ginfo['fields'][$fxml];
|
|
if (1 === $finfo['required'] && empty($fdata)) {
|
|
die('broken data found item id: '.$item_id.' '.$gxml.':'.$fxml.PHP_EOL);
|
|
}
|
|
if (0 === $ginfo['repeatable'] && !in_array($finfo['view_type'], ['relation item', 'file upload', 'preview', 'change log'])) {
|
|
$fdata = !empty($fdata) ? $fdata[0] : '';
|
|
}
|
|
switch ($finfo['view_type']) {
|
|
case 'id':
|
|
case 'last update':
|
|
case 'create date':
|
|
case 'create user':
|
|
case 'index':
|
|
// ignore predefined
|
|
break;
|
|
case 'relation item':
|
|
$item['related_to'] = $fdata;
|
|
break;
|
|
case 'file upload':
|
|
case 'preview':
|
|
foreach ($fdata as $value) {
|
|
$item['file'][] = [
|
|
'file_id' => (int) $value['file_id'],
|
|
'original_file_name' => $value['original_file_name'],
|
|
'mime_type' => $value['mime_type'],
|
|
'file_size' => (int) $value['file_size'],
|
|
'caption' => $value['caption'],
|
|
'timestamp' => (int) $value['timestamp'],
|
|
'file_type_name' => preg_replace('/_files$/', '_file', $gxml),
|
|
'file_type_display_name' => preg_replace('/Files$/', 'File', ucwords(str_replace('_', ' ', strtolower($gxml)))),
|
|
];
|
|
}
|
|
break;
|
|
case 'change log':
|
|
foreach ($fdata as $value) {
|
|
$item['changelog'][] = [
|
|
'log_date' => (int) $value['log_date'],
|
|
'log' => rtrim(preg_replace('/(.*) を変更$/', 'Modified; $1', $value['log']), '.'),
|
|
];
|
|
}
|
|
break;
|
|
case 'rights':
|
|
$item['rights'] = substr($fdata, 4);
|
|
if (false === $item['rights']) {
|
|
$item['rights'] = '';
|
|
}
|
|
$item['use_cc'] = (int) substr($fdata, 0, 1);
|
|
$item['cc_commercial_use'] = (int) substr($fdata, 1, 1);
|
|
$item['cc_modification'] = (int) substr($fdata, 2, 1);
|
|
if (1 === $item['use_cc']) {
|
|
$item['rights'] = '';
|
|
}
|
|
break;
|
|
case 'download limit':
|
|
$item['attachment_dl_limit'] = $fdata;
|
|
break;
|
|
case 'download notify':
|
|
$item['attachment_dl_notify'] = $fdata;
|
|
break;
|
|
case 'title':
|
|
$item['title'] = $fdata;
|
|
break;
|
|
case 'keyword':
|
|
$item['keyword'] = $fdata;
|
|
break;
|
|
case 'readme':
|
|
$item['readme'] = $fdata;
|
|
break;
|
|
case 'select':
|
|
case 'textarea':
|
|
case 'text':
|
|
case 'file type':
|
|
case 'date(yyyy mm dd)':
|
|
// ignore
|
|
break;
|
|
default:
|
|
die('unsupported view type found: '.$finfo['view_type'].PHP_EOL);
|
|
}
|
|
$xmlkey = $gxml.':'.$fxml;
|
|
switch ($item_type) {
|
|
case 'file':
|
|
$xmlkeys = [
|
|
'langs:language' => 'lang',
|
|
'outline:description' => 'description',
|
|
];
|
|
if (isset($xmlkeys[$xmlkey])) {
|
|
$item[$xmlkeys[$xmlkey]] = $fdata;
|
|
}
|
|
break;
|
|
case 'document':
|
|
$xmlkeys = [
|
|
'langs:language' => 'lang',
|
|
'outline:description' => 'description',
|
|
'essential_date:essential_date' => 'date',
|
|
'presentation_type:presentation_type' => 'presentation_type',
|
|
'presentation_creators:creators_name' => 'creator',
|
|
];
|
|
if (isset($xmlkeys[$xmlkey])) {
|
|
$item[$xmlkeys[$xmlkey]] = $fdata;
|
|
}
|
|
break;
|
|
case 'journal':
|
|
$xmlkeys = [
|
|
'journal_name:journal_name' => 'journal',
|
|
'journal_pub_year:journal_pub_year' => 'publication_year',
|
|
'journal_pub_month:journal_pub_month' => 'publication_month',
|
|
'journal_publisher:journal_publisher' => 'publisher',
|
|
'journal_publisher_location:journal_publisher_location' => 'publisher_location',
|
|
'journal_language:journal_language' => 'lang',
|
|
'journal_volume:journal_volume' => 'volume',
|
|
'journal_release_date:journal_release_date' => 'date',
|
|
];
|
|
if (isset($xmlkeys[$xmlkey])) {
|
|
$item[$xmlkeys[$xmlkey]] = $fdata;
|
|
}
|
|
break;
|
|
case 'article':
|
|
$xmlkeys = [
|
|
'article_author_name:article_author_name' => 'author',
|
|
'article_author_affiliation:article_author_affiliation' => 'affiliation',
|
|
'article_language:article_language' => 'lang',
|
|
'article_journal:article_journal_publisher' => 'journal_publisher',
|
|
'article_journal:article_journal_name' => 'journal_name',
|
|
'article_journal:article_journal_volume' => 'journal_volume',
|
|
'article_journal:article_journal_page' => 'journal_page',
|
|
'article_journal:article_journal_pub_year' => 'publication_year',
|
|
'article_journal:article_journal_pub_month' => 'publication_month',
|
|
'article_meeting:article_meeting_name' => 'meeting_name',
|
|
'article_meeting:article_meeting_place' => 'meeting_place',
|
|
'article_meeting:article_meeting_program_no' => 'meeting_program_no',
|
|
'article_meeting:article_meeting_date_from' => 'meeting_date_from',
|
|
'article_meeting:article_meeting_date_to' => 'meeting_date_to',
|
|
'article_release_date:article_release_date' => 'date',
|
|
];
|
|
if (isset($xmlkeys[$xmlkey])) {
|
|
$item[$xmlkeys[$xmlkey]] = $fdata;
|
|
}
|
|
break;
|
|
case 'general_data_and_documents':
|
|
$xmlkeys = [
|
|
'generaldata_description:generaldata_description' => 'description',
|
|
'generaldata_language:generaldata_language' => 'lang',
|
|
'generaldata_creator:generaldata_creator' => 'creator',
|
|
'generaldata_affiliation:generaldata_affiliation' => 'affiliation',
|
|
'generaldata_publisher:generaldata_publisher' => 'publisher',
|
|
'generaldata_edition:generaldata_edition_version' => 'version',
|
|
'generaldata_edition:generaldata_edition_format' => 'format',
|
|
'generaldata_edition:generaldata_edition_variation' => 'variation',
|
|
'generaldata_relation:generaldata_relation' => 'relation',
|
|
];
|
|
if (isset($xmlkeys[$xmlkey])) {
|
|
$item[$xmlkeys[$xmlkey]] = $fdata;
|
|
}
|
|
if ('generaldata_publication_date:generaldata_publication_date' === $xmlkey) {
|
|
$item['publication_year'] = (int) date('Y', $fdata);
|
|
$item['publication_month'] = (int) date('n', $fdata);
|
|
$item['publication_mday'] = (int) date('j', $fdata);
|
|
}
|
|
break;
|
|
default:
|
|
die('does\'nt support item type '.$item_type.PHP_EOL);
|
|
}
|
|
}
|
|
}
|
|
if ('ja' === $item['lang']) {
|
|
$item['lang'] = 'jpn';
|
|
} elseif ('en' === $item['lang']) {
|
|
$item['lang'] = 'eng';
|
|
}
|
|
if (isset($item['attachement_dl_limit']) && 1 === $item['attachement_dl_limit']) {
|
|
$limitItems[] = [
|
|
'item_id' => $item['item_id'],
|
|
'uname' => $item['uname'],
|
|
'uname' => $item['name'],
|
|
'email' => $row['owner'][0]['email'],
|
|
];
|
|
foreach ($item['file'] as $file) {
|
|
if ('preview' !== $file['file_type_name']) {
|
|
$limitFiles[] = $file['file_id'];
|
|
}
|
|
}
|
|
}
|
|
// item type conversion
|
|
if ('aini2012' === $item['doi']) {
|
|
// file -> journal - doi:aini2012
|
|
$item = file2journal($item);
|
|
} elseif ('aini2014' === $item['doi']) {
|
|
// document -> journal - doi:aini2014
|
|
$item = document2journal($item);
|
|
} elseif ('aini2015' === $item['doi']) {
|
|
// document -> journal - doi:aini2015
|
|
$item = document2journal($item);
|
|
} elseif ('file' === $item['item_type_name']) {
|
|
// file -> gdata
|
|
$item = file2gdata($item);
|
|
} elseif ('document' === $item['item_type_name']) {
|
|
if ('' === $item['doi']) {
|
|
// document -> gdata
|
|
$item = document2gdata($item);
|
|
} else {
|
|
// document -> article
|
|
$item = document2article($item);
|
|
}
|
|
}
|
|
// override journal rights to cc-by-nd
|
|
if ('journal' === $item['item_type_name']) {
|
|
$item['rights'] = '';
|
|
$item['use_cc'] = 1;
|
|
$item['cc_commercial_use'] = 1;
|
|
$item['cc_modification'] = 0;
|
|
}
|
|
// update last_update_date
|
|
if (!empty($item['changelog'])) {
|
|
if ($item['last_update_date'] < $item['changelog'][0]['log_date']) {
|
|
//echo 'Update last update date:'.$item['item_id'].PHP_EOL;
|
|
$item['last_update_date'] = $item['changelog'][0]['log_date'];
|
|
}
|
|
}
|
|
if ('general_data_and_documents' === $item['item_type_name']) {
|
|
$item['item_type_name'] = 'generaldata';
|
|
}
|
|
$items[] = $item;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
MyDumpTool::saveJson('itemsRaw.json', $itemsRaw);
|
|
MyDumpTool::saveJson('public/modules/xoonips/items.json', $items);
|
|
|
|
$fp = fopen(MYDUMPTOOL_OUTPUTDIR.'/dl-limit-items.csv', 'w');
|
|
foreach ($limitItems as $row) {
|
|
$data = [
|
|
$row['item_id'],
|
|
$row['uname'],
|
|
$row['name'],
|
|
$row['email'],
|
|
getItemUrl($row),
|
|
];
|
|
fputcsv($fp, $data);
|
|
}
|
|
fclose($fp);
|
|
|
|
// files
|
|
$basePath = XOOPS_TRUST_PATH.'/uploads/xoonips/item';
|
|
$filesDir = MYDUMPTOOL_OUTPUTDIR.'/public/modules/xoonips/file';
|
|
foreach ($items as $item) {
|
|
$item_id = $item['item_id'];
|
|
foreach ($item['file'] as $file) {
|
|
$file_id = $file['file_id'];
|
|
$file_name = $file['original_file_name'];
|
|
$file_type = $file['file_type_name'];
|
|
$mime_type = $file['mime_type'];
|
|
if (in_array($file_id, $limitFiles)) {
|
|
echo "download limit file found.. skip to copy.. item_id:$item_id, file_id:$file_id".PHP_EOL;
|
|
continue;
|
|
}
|
|
$file_dir = $filesDir.'/'.$file_id;
|
|
$src_file = $basePath.'/'.$item_id.'/'.$file_id;
|
|
if (!is_dir($file_dir)) {
|
|
@mkdir($file_dir);
|
|
}
|
|
//if (!file_exists($file_dir.'/'.$file_name)) {
|
|
if (!MyDumpTool::fileCopy($src_file, $file_dir.'/'.$file_name)) {
|
|
echo 'failed to copy file: '.$basePath.'/'.$file_id.PHP_EOL;
|
|
}
|
|
$htaccess = $file_dir.'/.htaccess';
|
|
$xfilename = str_replace(' ', '\\ ', $file_name);
|
|
$data = "RewriteEngine On\nRewriteBase /modules/xoonips/file/$file_id\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule .* $xfilename [R=301,L]\n";
|
|
file_put_contents($htaccess, $data);
|
|
if ('preview' == $file_type) {
|
|
$thumbnail_file = $file_dir.'.png';
|
|
if (!file_exists($thumbnail_file)) {
|
|
createThumbnail($src_file, $mime_type, $thumbnail_file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// functions
|
|
function getItemUrl($row)
|
|
{
|
|
$url = XOOPS_URL.'/modules/xoonips/detail.php?';
|
|
if ('' != $row['doi']) {
|
|
$url .= 'id='.$row['doi'];
|
|
} else {
|
|
$url .= 'item_id='.$row['item_id'];
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
function getTreeNode($tree, $root, $index_id)
|
|
{
|
|
$children = [];
|
|
if (isset($root[$index_id])) {
|
|
foreach ($root[$index_id] as $child_index_id) {
|
|
$children[] = getTreeNode($tree, $root, $child_index_id);
|
|
}
|
|
}
|
|
|
|
return [
|
|
'id' => (int) $tree[$index_id]['index_id'],
|
|
'title' => $tree[$index_id]['title'],
|
|
'num_of_items' => (int) $tree[$index_id]['num_items'],
|
|
'children' => $children,
|
|
];
|
|
}
|
|
|
|
function getIndexes($tree, $item_id)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql = <<< SQL
|
|
SELECT
|
|
`iil`.`index_id`
|
|
FROM `${prefix}_xoonips_index_item_link` AS `iil`
|
|
WHERE `iil`.`item_id`=$item_id
|
|
ORDER BY `iil`.`index_id`
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$indexes = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
$index_id = $row['index_id'];
|
|
if (isset($tree[$index_id])) {
|
|
$idxes = [];
|
|
$idxes[] = $tree[$index_id]['title'];
|
|
$parent_id = $tree[$index_id]['parent_index_id'];
|
|
while (1 != $parent_id) {
|
|
$idxes[] = $tree[$parent_id]['title'];
|
|
$parent_id = $tree[$parent_id]['parent_index_id'];
|
|
}
|
|
$idxes[] = '';
|
|
$indexes[] = [
|
|
'index_id' => (int) $index_id,
|
|
'title' => trim(implode(' / ', array_reverse($idxes))),
|
|
];
|
|
}
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $indexes;
|
|
}
|
|
|
|
function getUsers($item_id)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
static $users = false;
|
|
if (false === $users) {
|
|
$users = loadUsers();
|
|
}
|
|
$sql = <<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xoonips_item_users_link`
|
|
WHERE `item_id`=$item_id
|
|
ORDER BY `weight`
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$owners = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['item_id', 'uid', 'weight']);
|
|
$uid = $row['uid'];
|
|
$owners[] = $users[$uid];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $owners;
|
|
}
|
|
|
|
function loadUsers()
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql = <<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_users`
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$users = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['uid']);
|
|
$uid = $row['uid'];
|
|
$users[$uid] = [
|
|
'uid' => $uid,
|
|
'uname' => $row['uname'],
|
|
'name' => $row['name'],
|
|
];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $users;
|
|
}
|
|
|
|
function getItemTypes()
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql = <<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xoonips_item_type`
|
|
WHERE `released`=1
|
|
ORDER BY `weight` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$item_types = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['item_type_id']);
|
|
$item_type_id = $row['item_type_id'];
|
|
$item_type = str_replace(' ', '_', strtolower($row['name']));
|
|
$item_types[$item_type] = [
|
|
'id' => $item_type_id,
|
|
'name' => $row['name'],
|
|
'description' => $row['description'],
|
|
'groups' => getItemFieldGroups($item_type_id),
|
|
];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $item_types;
|
|
}
|
|
function getItemFieldGroups($item_type_id)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql = <<< SQL
|
|
SELECT `itfgl`.*,
|
|
`ifg`.`name`, `ifg`.`xml`, `ifg`.`occurrence`
|
|
FROM `${prefix}_xoonips_item_type_field_group_link` AS `itfgl`
|
|
INNER JOIN `${prefix}_xoonips_item_field_group` AS `ifg` ON `itfgl`.`group_id`=`ifg`.`group_id`
|
|
WHERE `itfgl`.`item_type_id`=$item_type_id
|
|
AND `itfgl`.`released`=1
|
|
AND `ifg`.`released`=1
|
|
ORDER BY `itfgl`.`weight` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$ret = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['item_type_id', 'group_id', 'occurrence']);
|
|
$xml = $row['xml'];
|
|
$group_id = $row['group_id'];
|
|
if (isset($ret[$xml])) {
|
|
die('Duplicated field group xml found in '.$item_type_id.':'.$group_id.PHP_EOL);
|
|
}
|
|
$ret[$row['xml']] = [
|
|
'id' => $group_id,
|
|
'label' => $row['name'],
|
|
'repeatable' => (int) $row['occurrence'],
|
|
'fields' => getItemFieldDetails($group_id),
|
|
];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $ret;
|
|
}
|
|
|
|
function getItemFieldDetails($group_id)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql = <<< SQL
|
|
SELECT `ifgfdl`.`group_id`,
|
|
`ifd`.*,
|
|
`dt`.`name` AS `data_type_name`,
|
|
`vt`.`name` AS `view_type_name`
|
|
FROM `${prefix}_xoonips_item_field_group_field_detail_link` AS `ifgfdl`
|
|
INNER JOIN `${prefix}_xoonips_item_field_detail` AS `ifd` ON `ifgfdl`.`item_field_detail_id`=`ifd`.`item_field_detail_id`
|
|
INNER JOIN `${prefix}_xoonips_data_type` AS `dt` ON `ifd`.`data_type_id`=`dt`.`data_type_id`
|
|
INNER JOIN `${prefix}_xoonips_view_type` AS `vt` ON `ifd`.`view_type_id`=`vt`.`view_type_id`
|
|
WHERE `ifgfdl`.`group_id`=$group_id
|
|
AND `ifgfdl`.`released`=1
|
|
AND `ifd`.`released`=1
|
|
AND `ifd`.`detail_display`=1
|
|
ORDER BY `ifgfdl`.`weight` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$ret = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['group_id', 'item_field_detail_id']);
|
|
$xml = $row['xml'];
|
|
$item_field_detail_id = $row['item_field_detail_id'];
|
|
if (isset($ret[$xml])) {
|
|
die('Duplicated field detail xml found in '.$group_id.':'.$item_field_id.PHP_EOL);
|
|
}
|
|
$ret[$row['xml']] = [
|
|
'id' => $item_field_detail_id,
|
|
'label' => $row['name'],
|
|
'table' => $row['table_name'],
|
|
'column' => $row['column_name'],
|
|
'data_type' => $row['data_type_name'],
|
|
'view_type' => $row['view_type_name'],
|
|
'list' => getSelectList($row['list']),
|
|
'required' => (int) $row['essential'],
|
|
];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $ret;
|
|
}
|
|
function getSelectList($name)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$ret = [];
|
|
if ('' === $name) {
|
|
return $ret;
|
|
}
|
|
$sql = <<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xoonips_item_field_value_set`
|
|
WHERE `select_name`='$name'
|
|
ORDER BY `weight` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
$ret[$row['title_id']] = $row['title'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
|
|
return $ret;
|
|
}
|
|
|
|
function getItemDetail($item_id, $item_type)
|
|
{
|
|
global $xoopsDB;
|
|
global $itemTypes;
|
|
$prefix = $xoopsDB->prefix();
|
|
$itemType = $itemTypes[$item_type];
|
|
$ret = [];
|
|
foreach ($itemType['groups'] as $gxml => $gdata) {
|
|
$gret = [];
|
|
foreach ($gdata['fields'] as $fxml => $fdata) {
|
|
//var_dump($gxml.':'.$fxml);
|
|
$table = $fdata['table'];
|
|
$sql = <<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_${table}` AS `t`
|
|
WHERE `item_id`=$item_id
|
|
SQL;
|
|
switch ($table) {
|
|
case 'xoonips_item':
|
|
break;
|
|
case 'xoonips_item_title':
|
|
$sql .= ' AND `item_field_detail_id`='.$fdata['id'];
|
|
$sql .= ' ORDER BY `title_id` ASC';
|
|
break;
|
|
case 'xoonips_item_keyword':
|
|
$sql .= ' ORDER BY `keyword_id` ASC';
|
|
break;
|
|
case 'xoonips_item_users_link':
|
|
$sql .= ' ORDER BY `weight` ASC';
|
|
break;
|
|
case 'xoonips_item_changelog':
|
|
$sql .= ' ORDER BY `log_date` DESC';
|
|
break;
|
|
case 'xoonips_item_related_to':
|
|
break;
|
|
case 'xoonips_item_file':
|
|
$sql .= ' AND `group_id`='.$gdata['id'];
|
|
break;
|
|
case 'xoonips_index_item_link':
|
|
$sql .= ' AND `certify_state`=2';
|
|
break;
|
|
default:
|
|
if (preg_match('/^xoonips_item_extend/', $table)) {
|
|
$sql .= ' AND `group_id`='.$gdata['id'];
|
|
} else {
|
|
die('unsupported table'.PHP_EOL);
|
|
}
|
|
}
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
$fret = [];
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
$value = $row[$fdata['column']];
|
|
switch ($fdata['data_type']) {
|
|
case 'int':
|
|
$value = (int) $value;
|
|
break;
|
|
}
|
|
switch ($fdata['view_type']) {
|
|
case 'preview':
|
|
case 'file upload':
|
|
case 'change log':
|
|
$value = $row;
|
|
break;
|
|
}
|
|
$fret[] = $value;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$gret[$fxml] = $fret;
|
|
}
|
|
$ret[$gxml] = $gret;
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
function createThumbnail($inputFile, $mimeType, $outputFile)
|
|
{
|
|
switch ($mimeType) {
|
|
case 'image/jpeg':
|
|
$srcImage = imagecreatefromjpeg($inputFile);
|
|
break;
|
|
case 'image/gif':
|
|
$srcImage = imagecreatefromgif($inputFile);
|
|
break;
|
|
case 'image/png':
|
|
$srcImage = imagecreatefrompng($inputFile);
|
|
break;
|
|
default:
|
|
die('unknown image format found'.PHP_EOL);
|
|
}
|
|
list($srcWidth, $srcHeight) = getimagesize($inputFile);
|
|
$maxWidth = 120;
|
|
$maxHeight = 120;
|
|
$width = $srcWidth;
|
|
$height = $srcHeight;
|
|
if ($width > $maxWidth) {
|
|
$height = intval($height * $maxWidth / $width);
|
|
$width = $maxWidth;
|
|
}
|
|
if ($height > $maxHeight) {
|
|
$width = intval($width * $maxHeight / $height);
|
|
$height = $maxHeight;
|
|
}
|
|
$image = imagecreatetruecolor($width, $height);
|
|
imagecopyresampled($image, $srcImage, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
|
|
imagepng($image, $outputFile);
|
|
imagedestroy($srcImage);
|
|
imagedestroy($image);
|
|
if (!file_exists($outputFile)) {
|
|
var_dump($outputFile);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
function file2journal($item)
|
|
{
|
|
$file = $item['file'][0];
|
|
$file['file_type_name'] = 'journal_fulltext_file';
|
|
$file['file_type_display_name'] = 'Journal Fulltext File';
|
|
$changelog = $item['changelog'];
|
|
array_unshift($changelog, [
|
|
'log_date' => 1589422864, // 2020/05/14 11:21:04
|
|
'log' => 'Modified; [ja]アイテムタイプ[/ja][en]Item Type[/en]',
|
|
]);
|
|
|
|
return [
|
|
'item_id' => $item['item_id'],
|
|
'doi' => $item['doi'],
|
|
'description' => $item['description'],
|
|
'last_update_date' => $item['last_update_date'],
|
|
'creation_date' => $item['creation_date'],
|
|
'publication_year' => 2017,
|
|
'publication_month' => 5,
|
|
'publication_mday' => 0,
|
|
'lang' => $item['lang'],
|
|
'title' => $item['title'],
|
|
'item_type_display_name' => 'Journal',
|
|
'item_type_name' => 'journal',
|
|
'uname' => $item['uname'],
|
|
'name' => $item['name'],
|
|
'item_url' => $item['item_url'],
|
|
'index' => $item['index'],
|
|
'changelog' => $changelog,
|
|
'related_to' => $item['related_to'],
|
|
'keyword' => $item['keyword'],
|
|
'file' => [$file],
|
|
'journal' => 'Advances in Neuroinformatics',
|
|
'volume' => 'I',
|
|
'publisher' => 'Neuroinformatics Japan Center, RIKEN Brain Science Institute',
|
|
'publisher_location' => 'JPN',
|
|
'rights' => '',
|
|
'use_cc' => 1,
|
|
'cc_commercial_use' => 1,
|
|
'cc_modification' => 0,
|
|
'date' => 1496242800, // 2017/6/1 00:00:00 JST
|
|
];
|
|
}
|
|
|
|
function document2journal($item)
|
|
{
|
|
$file = $item['file'][0];
|
|
$file['file_type_name'] = 'journal_fulltext_file';
|
|
$file['file_type_display_name'] = 'Journal Fulltext File';
|
|
$volumes = [
|
|
'aini2014' => 'II',
|
|
'aini2015' => 'III',
|
|
];
|
|
$changelog = $item['changelog'];
|
|
array_unshift($changelog, [
|
|
'log_date' => 1589422864, // 2020/05/14 11:21:04
|
|
'log' => 'Modified; [ja]アイテムタイプ[/ja][en]Item Type[/en]',
|
|
]);
|
|
|
|
return [
|
|
'item_id' => $item['item_id'],
|
|
'doi' => $item['doi'],
|
|
'description' => $item['readme'],
|
|
'last_update_date' => $item['last_update_date'],
|
|
'creation_date' => $item['creation_date'],
|
|
'publication_year' => 2017,
|
|
'publication_month' => 5,
|
|
'publication_mday' => 0,
|
|
'lang' => $item['lang'],
|
|
'title' => $item['title'],
|
|
'item_type_display_name' => 'Journal',
|
|
'item_type_name' => 'journal',
|
|
'uname' => $item['uname'],
|
|
'name' => $item['name'],
|
|
'item_url' => $item['item_url'],
|
|
'index' => $item['index'],
|
|
'changelog' => $changelog,
|
|
'related_to' => $item['related_to'],
|
|
'keyword' => $item['keyword'],
|
|
'file' => [$file],
|
|
'journal' => 'Advances in Neuroinformatics',
|
|
'volume' => $volumes[$item['doi']],
|
|
'publisher' => 'Neuroinformatics Japan Center, RIKEN Brain Science Institute',
|
|
'publisher_location' => 'JPN',
|
|
'rights' => '',
|
|
'use_cc' => 1,
|
|
'cc_commercial_use' => 1,
|
|
'cc_modification' => 0,
|
|
'date' => 1496242800, // 2017/6/1 00:00:00 JST
|
|
];
|
|
}
|
|
|
|
function file2gdata($item)
|
|
{
|
|
$file = $item['file'][0];
|
|
$file['file_type_name'] = 'generaldata_file';
|
|
$file['file_type_display_name'] = 'Generaldata File';
|
|
$changelog = $item['changelog'];
|
|
array_unshift($changelog, [
|
|
'log_date' => 1589422864, // 2020/05/14 11:21:04
|
|
'log' => 'Modified; [ja]アイテムタイプ[/ja][en]Item Type[/en]',
|
|
]);
|
|
$date = strtotime(date('Y/m/d', $item['creation_date']));
|
|
if (1522508400 < $date) {
|
|
$creator = 'Neuroinformatics Unit';
|
|
$affiliation = 'RIKEN Center for Brain Science';
|
|
$publisher = 'Neuroinformatics Unit, RIKEN Center for Brain Science';
|
|
} else {
|
|
$creator = 'Neuroinformatics Japan Center';
|
|
$affiliation = 'RIKEN Brain Science Institute';
|
|
$publisher = 'Neuroinformatics Japan Center, RIKEN Brain Science Institute';
|
|
}
|
|
|
|
return [
|
|
'item_id' => $item['item_id'],
|
|
'doi' => $item['doi'],
|
|
'description' => $item['description'],
|
|
'last_update_date' => $item['last_update_date'],
|
|
'creation_date' => $item['creation_date'],
|
|
'publication_year' => (int) date('Y', $item['creation_date']),
|
|
'publication_month' => (int) date('n', $item['creation_date']),
|
|
'publication_mday' => (int) date('j', $item['creation_date']),
|
|
'lang' => $item['lang'],
|
|
'title' => $item['title'],
|
|
'item_type_display_name' => 'General Data and Documents',
|
|
'item_type_name' => 'general_data_and_documents',
|
|
'uname' => $item['uname'],
|
|
'name' => $item['name'],
|
|
'item_url' => $item['item_url'],
|
|
'index' => $item['index'],
|
|
'changelog' => $changelog,
|
|
'related_to' => $item['related_to'],
|
|
'keyword' => $item['keyword'],
|
|
'file' => [$file],
|
|
'rights' => '',
|
|
'use_cc' => 1,
|
|
'cc_commercial_use' => 1,
|
|
'cc_modification' => 0,
|
|
'creator' => [$creator],
|
|
'affiliation' => [$affiliation],
|
|
'date' => $date,
|
|
'publisher' => $publisher,
|
|
'version' => '',
|
|
'format' => $file['mime_type'],
|
|
'variation' => '',
|
|
'relation' => [],
|
|
];
|
|
}
|
|
|
|
function document2gdata($item)
|
|
{
|
|
if (1 !== count($item['file'])) {
|
|
die('unsupported file found: '.$item['item_id'].PHP_EOL);
|
|
}
|
|
$file = $item['file'][0];
|
|
$file['file_type_name'] = 'generaldata_file';
|
|
$file['file_type_display_name'] = 'Generaldata File';
|
|
$changelog = $item['changelog'];
|
|
array_unshift($changelog, [
|
|
'log_date' => 1589422864, // 2020/05/14 11:21:04
|
|
'log' => 'Modified; [ja]アイテムタイプ[/ja][en]Item Type[/en]',
|
|
]);
|
|
$date = strtotime(date('Y/m/d', $item['creation_date']));
|
|
if (1522508400 < $date) {
|
|
$creator = 'Neuroinformatics Unit';
|
|
$affiliation = 'RIKEN Center for Brain Science';
|
|
$publisher = 'Neuroinformatics Unit, RIKEN Center for Brain Science';
|
|
} else {
|
|
$creator = 'Neuroinformatics Japan Center';
|
|
$affiliation = 'RIKEN Brain Science Institute';
|
|
$publisher = 'Neuroinformatics Japan Center, RIKEN Brain Science Institute';
|
|
}
|
|
|
|
return [
|
|
'item_id' => $item['item_id'],
|
|
'doi' => $item['doi'],
|
|
'description' => $item['description'],
|
|
'last_update_date' => $item['last_update_date'],
|
|
'creation_date' => $item['creation_date'],
|
|
'publication_year' => (int) date('Y', $item['creation_date']),
|
|
'publication_month' => (int) date('n', $item['creation_date']),
|
|
'publication_mday' => (int) date('j', $item['creation_date']),
|
|
'lang' => $item['lang'],
|
|
'title' => $item['title'],
|
|
'item_type_display_name' => 'General Data and Documents',
|
|
'item_type_name' => 'general_data_and_documents',
|
|
'uname' => $item['uname'],
|
|
'name' => $item['name'],
|
|
'item_url' => $item['item_url'],
|
|
'index' => $item['index'],
|
|
'changelog' => $changelog,
|
|
'related_to' => $item['related_to'],
|
|
'keyword' => $item['keyword'],
|
|
'file' => [$file],
|
|
'rights' => '',
|
|
'use_cc' => 1,
|
|
'cc_commercial_use' => 1,
|
|
'cc_modification' => 0,
|
|
'creator' => [$creator],
|
|
'affiliation' => [$affiliation],
|
|
'publisher' => $publisher,
|
|
'version' => '',
|
|
'format' => $file['mime_type'],
|
|
'variation' => '',
|
|
'relation' => [],
|
|
];
|
|
}
|
|
|
|
function document2article($item)
|
|
{
|
|
global $METADATA;
|
|
if (1 !== count($item['file'])) {
|
|
die('unsupported file found: '.$item['doi'].PHP_EOL);
|
|
}
|
|
$type = false !== strpos('2014', $item['doi']) ? 'aini2014' : 'aini2015';
|
|
$extra = [
|
|
'aini2014' => ['year' => 2014, 'month' => 11],
|
|
'aini2015' => ['year' => 2016, 'month' => 2],
|
|
];
|
|
$file = $item['file'][0];
|
|
$file['file_type_name'] = 'article_fulltext_file';
|
|
$file['file_type_display_name'] = 'Article Fulltext File';
|
|
$changelog = $item['changelog'];
|
|
array_unshift($changelog, [
|
|
'log_date' => 1589422864, // 2020/05/14 11:21:04
|
|
'log' => 'Modified; [ja]アイテムタイプ[/ja][en]Item Type[/en]',
|
|
]);
|
|
$date = strtotime(date('Y/m/d', $item['creation_date']));
|
|
$doi = $item['doi'];
|
|
if (1522508400 < $date) {
|
|
$creator = 'Neuroinformatics Unit';
|
|
$affiliation = 'RIKEN Center for Brain Science';
|
|
$publisher = 'Neuroinformatics Unit, RIKEN Center for Brain Science';
|
|
} else {
|
|
$creator = 'Neuroinformatics Japan Center';
|
|
$affiliation = 'RIKEN Brain Science Institute';
|
|
$publisher = 'Neuroinformatics Japan Center, RIKEN Brain Science Institute';
|
|
}
|
|
|
|
return [
|
|
'item_id' => $item['item_id'],
|
|
'doi' => $item['doi'],
|
|
'description' => '',
|
|
'last_update_date' => $item['last_update_date'],
|
|
'creation_date' => $item['creation_date'],
|
|
'publication_year' => $extra[$type]['year'],
|
|
'publication_month' => $extra[$type]['month'],
|
|
'publication_mday' => 0,
|
|
'lang' => $item['lang'],
|
|
'title' => $item['title'],
|
|
'item_type_display_name' => 'Article',
|
|
'item_type_name' => 'article',
|
|
'uname' => $item['uname'],
|
|
'name' => $item['name'],
|
|
'item_url' => $item['item_url'],
|
|
'index' => $item['index'],
|
|
'changelog' => $changelog,
|
|
'related_to' => $item['related_to'],
|
|
'keyword' => $item['keyword'],
|
|
'file' => [$file],
|
|
'author' => $METADATA[$doi]['author'],
|
|
'affiliation' => $METADATA[$doi]['affiliation'],
|
|
'journal_name' => $METADATA[$doi]['journal_name'],
|
|
'journal_volume' => $METADATA[$doi]['journal_volume'],
|
|
'journal_page' => $METADATA[$doi]['journal_page'],
|
|
'journal_page' => $METADATA[$doi]['journal_page'],
|
|
'journal_publisher' => $METADATA[$doi]['journal_publisher'],
|
|
'meeting_name' => $METADATA[$doi]['meeting_name'],
|
|
'meeting_place' => $METADATA[$doi]['meeting_place'],
|
|
'meeting_date_from' => $METADATA[$doi]['meeting_date_from'],
|
|
'meeting_date_to' => $METADATA[$doi]['meeting_date_to'],
|
|
'meeting_program_no' => $METADATA[$doi]['meeting_program_no'],
|
|
'rights' => '',
|
|
'use_cc' => 1,
|
|
'cc_commercial_use' => 1,
|
|
'cc_modification' => 0,
|
|
'date' => $METADATA[$doi]['date'],
|
|
];
|
|
}
|