949 lines
26 KiB
PHP
949 lines
26 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/config.inc.php';
|
|
|
|
if (!isset($mainfile)) {
|
|
echo 'ERROR : $mainfile variable does not defined in config.inc.php'.PHP_EOL;
|
|
}
|
|
|
|
define('PROTECTOR_SKIP_DOS_CHECK', 1);
|
|
define('PROTECTOR_SKIP_FILESCHECKER', 1);
|
|
|
|
// disable query logger
|
|
define('XOOPS_LOGGER_ADDQUERY_DISABLED', true);
|
|
|
|
// ----
|
|
if ( ! file_exists( $mainfile ) ) {
|
|
echo 'ERROR : mainfile.php not found'.PHP_EOL;
|
|
exit(1);
|
|
}
|
|
$xoops_path='';
|
|
$xoops_url='';
|
|
|
|
foreach ( file( $mainfile ) as $line ) {
|
|
if ( preg_match( '/^\s*define\s*\(\s*[\'"]XOOPS_ROOT_PATH[\'"]\s*,\s*[\'"](.+)[\'"]\)\s*;\s*$/', $line, $matches ) ) {
|
|
$xoops_path = $matches[1];
|
|
}
|
|
if ( preg_match( '/^\s*define\s*\(\s*[\'"]XOOPS_URL[\'"]\s*,\s*[\'"](.+)[\'"]\)\s*;\s*$/', $line, $matches ) ) {
|
|
$xoops_url = $matches[1];
|
|
}
|
|
}
|
|
|
|
if ( isset( $method ) && strtoupper( $method ) == 'POST' ) {
|
|
$method = 'POST';
|
|
} else {
|
|
$method = 'GET';
|
|
}
|
|
$_SERVER['HTTP_USER_AGENT'] = 'php-cli';
|
|
$_SERVER['REQUEST_METHOD'] = $method;
|
|
$_ENV['HTTP_REFERER'] = $xoops_url.'/index.php';
|
|
$_SERVER['QUERY_STRING'] = '/index.php';
|
|
$_SERVER['REMOTE_ADDR'] = '192.168.0.1';
|
|
|
|
if ( file_exists( $xoops_path.'/modules/xoonips/include/common.inc.php' ) ) {
|
|
require_once $xoops_path.'/modules/xoonips/include/common.inc.php';
|
|
} else {
|
|
require_once $xoops_path.'/mainfile.php';
|
|
require_once $xoops_path.'/modules/xoonips/condefs.php';
|
|
require_once $xoops_path.'/modules/xoonips/include/functions.php';
|
|
}
|
|
|
|
if ( defined( 'XOOPS_DB_PROXY' ) && XOOPS_DB_PROXY == 1 && $method == 'POST' ) {
|
|
die( 'Error: not accept POST request'."\n" );
|
|
}
|
|
|
|
// ====================
|
|
|
|
$prefix = $xoopsDB->prefix();
|
|
|
|
// get public index with certified item count
|
|
$sql =<<< SQL
|
|
SELECT
|
|
`idx`.*,
|
|
`it`.`title`,
|
|
(SELECT COUNT(*)
|
|
FROM `${prefix}_xoonips_index_item_link` AS `iil`
|
|
INNER JOIN `${prefix}_xoonips_item_basic` AS `ib` ON `iil`.`item_id`=`ib`.`item_id`
|
|
WHERE `iil`.`index_id`=`idx`.`index_id` AND `iil`.`certify_state`=2
|
|
) AS `num_items`
|
|
FROM `${prefix}_xoonips_index` AS `idx`
|
|
INNER JOIN `${prefix}_xoonips_item_title` AS `it` ON `idx`.`index_id`=`it`.`item_id`
|
|
WHERE `it`.`title_id`=0
|
|
AND `idx`.`open_level`=1
|
|
SQL;
|
|
|
|
$limitItems = array();
|
|
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$tree = array();
|
|
$root = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
myDecode($row);
|
|
$tree[$row['index_id']] = $row;
|
|
$root[$row['parent_index_id']][$row['sort_number']] = $row['index_id'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
foreach ($root as &$node) {
|
|
ksort($node);
|
|
}
|
|
unset($node);
|
|
|
|
$data[] = getTreeNode($tree, $root, 3);
|
|
$json = json_encode($data);//, JSON_PRETTY_PRINT);
|
|
file_put_contents('tree.json', $json);
|
|
unset($json, $data, $root);
|
|
|
|
// get public items
|
|
//if (!is_dir(__DIR__.'/items/')) {
|
|
// mkdir(__DIR__.'/items/');
|
|
//}
|
|
$sql =<<< SQL
|
|
SELECT
|
|
`ib`.*,
|
|
`it`.`title`,
|
|
`ity`.`display_name` AS `item_type_display_name`,
|
|
`ity`.`name` AS `item_type_name`,
|
|
`u`.`uname`, `u`.`name`, `u`.`email`
|
|
FROM `${prefix}_xoonips_item_basic` AS `ib`
|
|
INNER JOIN `${prefix}_xoonips_item_title` AS `it` ON `ib`.`item_id`=`it`.`item_id`
|
|
INNER JOIN `${prefix}_xoonips_item_type` AS `ity` ON `ib`.`item_type_id`=`ity`.`item_type_id`
|
|
INNER JOIN `${prefix}_users` AS `u` ON `ib`.`uid`=`u`.`uid`
|
|
WHERE `it`.`title_id`=0 AND
|
|
`ity`.`display_name` != 'Index'
|
|
SQL;
|
|
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$items = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
myDecode($row);
|
|
convertToInt($row, array('item_id', 'item_type_id', 'uid', 'last_update_date', 'creation_date', 'publication_year', 'publication_month', 'publication_mday'));
|
|
$row['item_url'] = getItemUrl($row);
|
|
$row['index'] = getIndexes($tree, $row['item_id']);
|
|
if (0 === count($row['index'])) {
|
|
continue;
|
|
}
|
|
$row['changelog'] = getChangeLogs($row['item_id']);
|
|
$row['related_to'] = getRelatedTo($row['item_id']);
|
|
$row['keyword'] = getKeyword($row['item_id']);
|
|
$row['file'] = getFile($row['item_id']);
|
|
switch ($row['item_type_name']) {
|
|
case 'xnpbinder':
|
|
appendBinderInfo($row);
|
|
break;
|
|
case 'xnpfiles':
|
|
appendFilesInfo($row);
|
|
break;
|
|
case 'xnppaper':
|
|
appendPaperInfo($row);
|
|
break;
|
|
case 'xnpbook':
|
|
appendBookInfo($row);
|
|
break;
|
|
case 'xnpconference':
|
|
appendConferenceInfo($row);
|
|
break;
|
|
case 'xnpdata':
|
|
appendDataInfo($row);
|
|
break;
|
|
case 'xnptool':
|
|
appendToolInfo($row);
|
|
break;
|
|
case 'xnpmemo':
|
|
appendMemoInfo($row);
|
|
break;
|
|
case 'xnpmodel':
|
|
appendModelInfo($row);
|
|
break;
|
|
case 'xnppresentation':
|
|
appendPresentationInfo($row);
|
|
break;
|
|
case 'xnpstimulus':
|
|
appendStimulusInfo($row);
|
|
break;
|
|
case 'xnpsimulator':
|
|
appendSimulatorInfo($row);
|
|
break;
|
|
case 'xnpurl':
|
|
appendUrlInfo($row);
|
|
break;
|
|
case 'xnpnimgcenter':
|
|
appendNimgcenterInfo($row);
|
|
break;
|
|
default:
|
|
exit('Unsupported item type: '.$row['item_type_name']);
|
|
}
|
|
if (isset($row['attachment_dl_limit']) && $row['attachment_dl_limit']) {
|
|
$limitItems[] = array(
|
|
'uname' => $row['uname'],
|
|
'name' => $row['name'],
|
|
'email' => $row['email'],
|
|
'item_id' => $row['item_id'],
|
|
'doi' => $row['doi'],
|
|
);
|
|
}
|
|
unset($row['email']);
|
|
//$items[$row['item_id']] = $row;
|
|
$items[] = $row;
|
|
$json = json_encode($row);//, JSON_PRETTY_PRINT);
|
|
//file_put_contents(__DIR__.'/items/'.$row['item_id'].'.json', $json);
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$json = json_encode($items);//, JSON_PRETTY_PRINT);
|
|
file_put_contents(__DIR__.'/items.json', $json);
|
|
|
|
$fp = fopen(__DIR__.'/dl-limit-items.csv', 'w');
|
|
foreach ($limitItems as $row) {
|
|
$data = array(
|
|
$row['uname'],
|
|
$row['name'],
|
|
$row['email'],
|
|
getItemUrl($row),
|
|
);
|
|
fputcsv($fp, $data);
|
|
}
|
|
fclose($fp);
|
|
|
|
// get files
|
|
$fthandler = xoonips_getormhandler('xoonips', 'file_type');
|
|
$criteria = new Criteria('name', 'preview');
|
|
$ftobjs = $fthandler->getObjects($criteria);
|
|
$ftId = $ftobjs[0]->get('file_type_id');
|
|
$fhandler = xoonips_getormhandler('xoonips', 'file');
|
|
$join = new XooNIpsJoinCriteria('xoonips_item_basic', 'item_id', 'item_id', 'INNER', 'ib');
|
|
$join->cascade(new XooNIpsJoinCriteria('xoonips_index_item_link', 'item_id', 'item_id', 'INNER', 'iil'), 'ib', true);
|
|
$join->cascade(new XooNIpsJoinCriteria('xoonips_index', 'index_id', 'index_id', 'INNER', 'idx'), 'iil', true);
|
|
$criteria = new CriteriaCompo(new Criteria('is_deleted', 0));
|
|
// $criteria->add(new Criteria('file_type_id', $ftId));
|
|
$criteria->add(new Criteria('certify_state', 2));
|
|
$criteria->add(new Criteria('open_level', 1));
|
|
$res = $fhandler->open($criteria, '', false, $join);
|
|
$filesDir = __DIR__.'/file';
|
|
if (!is_dir($filesDir)) {
|
|
mkdir($filesDir);
|
|
}
|
|
$xconfig_handler = xoonips_getormhandler('xoonips', 'config');
|
|
$basePath = $xconfig_handler->getValue('upload_dir');
|
|
while ($obj = $fhandler->getNext($res)) {
|
|
$file_id = $obj->get('file_id');
|
|
$file_name = $obj->get('original_file_name');
|
|
$file_dir = $filesDir.'/'.$file_id;
|
|
if (!is_dir($file_dir)) {
|
|
@mkdir($file_dir);
|
|
}
|
|
if (!file_exists($file_dir.'/'.$file_name)) {
|
|
if (!copy($basePath.'/'.$file_id, $file_dir.'/'.$file_name)) {
|
|
echo 'failed to copy file: '.$basePath.'/'.$file_id. PHP_EOL;
|
|
}
|
|
$htaccess = $file_dir.'/.htaccess';
|
|
$data = "RewriteEngine On\nRewriteBase /database/file/$file_id\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule .* $file_name [R=301,L]\n";
|
|
file_put_contents($htaccess, $data);
|
|
}
|
|
if ($ftId == $obj->get('file_type_id')) {
|
|
// create preview thubmnails
|
|
createThumbnail($obj, $basePath, $filesDir);
|
|
}
|
|
}
|
|
$fhandler->close($res);
|
|
|
|
// functions
|
|
|
|
function getItemUrl($row) {
|
|
$url = XOONIPS_URL.'/detail.php?';
|
|
if ('' != $row['doi']) {
|
|
$url .= XNP_CONFIG_DOI_FIELD_PARAM_NAME.'='.$row['doi'];
|
|
} else {
|
|
$url .= 'item_id='.$row['item_id'];
|
|
}
|
|
return $url;
|
|
}
|
|
|
|
function getTreeNode($tree, $root, $index_id) {
|
|
$children = array();
|
|
if (isset($root[$index_id])) {
|
|
foreach ($root[$index_id] as $child_index_id) {
|
|
$children[] = getTreeNode($tree, $root, $child_index_id);
|
|
}
|
|
}
|
|
return array(
|
|
'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`.*
|
|
FROM `${prefix}_xoonips_index_item_link` AS `iil`
|
|
WHERE `iil`.`item_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$indexes = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
$index_id = $row['index_id'];
|
|
if (isset($tree[$index_id])) {
|
|
$idxes = array();
|
|
$idxes[] = $tree[$index_id]['title'];
|
|
$parent_id = $tree[$index_id]['parent_index_id'];
|
|
while ($parent_id != 1) {
|
|
$idxes[] = $tree[$parent_id]['title'];
|
|
$parent_id = $tree[$parent_id]['parent_index_id'];
|
|
}
|
|
$idxes[] = '';
|
|
$indexes[] = array(
|
|
'index_id' => (int) $index_id,
|
|
'title' => trim(implode(' / ', array_reverse($idxes))),
|
|
);
|
|
}
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
return $indexes;
|
|
}
|
|
|
|
function getChangeLogs($item_id) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql =<<< SQL
|
|
SELECT `log_date`, `log`
|
|
FROM `${prefix}_xoonips_changelog`
|
|
WHERE `item_id`=$item_id
|
|
ORDER BY `log_date` DESC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$ret = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
myDecode($row);
|
|
convertToInt($row, array('log_date'));
|
|
$ret[] = $row;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
return $ret;
|
|
}
|
|
|
|
function getRelatedTo($item_id) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql =<<< SQL
|
|
SELECT `item_id`
|
|
FROM `${prefix}_xoonips_related_to`
|
|
WHERE `parent_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$ret = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
$ret[] = (int) $row['item_id'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
return $ret;
|
|
}
|
|
|
|
function getKeyword($item_id) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xoonips_item_keyword`
|
|
WHERE `item_id`=$item_id
|
|
ORDER BY `keyword_id` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$ret = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
myDecode($row);
|
|
$ret[] = $row['keyword'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
return $ret;
|
|
}
|
|
|
|
function getFile($item_id) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$sql =<<< SQL
|
|
SELECT `f`.`file_id`, `f`.`original_file_name`, `f`.`mime_type`, `f`.`file_size`, `f`.`caption`, `f`.`timestamp`,
|
|
`ft`.`name` AS `file_type_name`, `ft`.`display_name` AS `file_type_display_name`
|
|
FROM `${prefix}_xoonips_file` AS `f`
|
|
INNER JOIN `${prefix}_xoonips_file_type` AS `ft` ON `f`.`file_type_id`=`ft`.`file_type_id`
|
|
WHERE `item_id`=$item_id
|
|
AND `is_deleted`=0
|
|
ORDER BY `ft`.`name` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$ret = array();
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
myDecode($row);
|
|
convertToInt($row, array('file_id', 'file_size'));
|
|
$ret[] = $row;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
return $ret;
|
|
}
|
|
|
|
function appendBinderInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpbinder_item_detail`
|
|
WHERE `binder_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('binder_id'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpbinder_binder_item_link`
|
|
WHERE `binder_id`=$item_id
|
|
ORDER BY `binder_item_link_id` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($link = $xoopsDB->fetchArray($res)) {
|
|
$row['link_item_ids'][] = (int) $link['item_id'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendFilesInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpfiles_item_detail`
|
|
WHERE `files_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('files_id'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendPaperInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnppaper_item_detail`
|
|
WHERE `paper_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('paper_id','volume','number'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnppaper_author`
|
|
WHERE `paper_id`=$item_id
|
|
ORDER BY `author_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['author'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['author'][] = $author['author'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendBookInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpbook_item_detail`
|
|
WHERE `book_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('book_id', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpbook_author`
|
|
WHERE `book_id`=$item_id
|
|
ORDER BY `author_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['author'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['author'][] = $author['author'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
|
|
function appendConferenceInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpconference_item_detail`
|
|
WHERE `conference_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('conference_id', 'conference_from_year', 'conference_from_month', 'conference_from_mday', 'conference_to_year', 'conference_to_month', 'conference_to_mday', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpconference_author`
|
|
WHERE `conference_id`=$item_id
|
|
ORDER BY `author_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['author'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['author'][] = $author['author'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendDataInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpdata_item_detail`
|
|
WHERE `data_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('data_id', 'use_cc', 'cc_commercial_use', 'cc_modification', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpdata_experimenter`
|
|
WHERE `data_id`=$item_id
|
|
ORDER BY `experimenter_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['experimenter'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['experimenter'][] = $author['experimenter'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendToolInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnptool_item_detail`
|
|
WHERE `tool_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('tool_id', 'use_cc', 'cc_commercial_use', 'cc_modification', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnptool_developer`
|
|
WHERE `tool_id`=$item_id
|
|
ORDER BY `developer_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['developer'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['developer'][] = $author['developer'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendMemoInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpmemo_item_detail`
|
|
WHERE `memo_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('memo_id'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendModelInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpmodel_item_detail`
|
|
WHERE `model_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('model_id', 'use_cc', 'cc_commercial_use', 'cc_modification', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpmodel_creator`
|
|
WHERE `model_id`=$item_id
|
|
ORDER BY `creator_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['creator'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['creator'][] = $author['creator'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendPresentationInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnppresentation_item_detail`
|
|
WHERE `presentation_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('presentation_id', 'use_cc', 'cc_commercial_use', 'cc_modification', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnppresentation_creator`
|
|
WHERE `presentation_id`=$item_id
|
|
ORDER BY `creator_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['creator'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['creator'][] = $author['creator'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendStimulusInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpstimulus_item_detail`
|
|
WHERE `stimulus_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('stimulus_id', 'use_cc', 'cc_commercial_use', 'cc_modification', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpstimulus_developer`
|
|
WHERE `stimulus_id`=$item_id
|
|
ORDER BY `developer_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['developer'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['developer'][] = $author['developer'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendSimulatorInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpsimulator_item_detail`
|
|
WHERE `simulator_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('simulator_id', 'use_cc', 'cc_commercial_use', 'cc_modification', 'attachment_dl_limit', 'attachment_dl_notify'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpsimulator_developer`
|
|
WHERE `simulator_id`=$item_id
|
|
ORDER BY `developer_order` ASC
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['developer'] = array();
|
|
while ($author = $xoopsDB->fetchArray($res)) {
|
|
myDecode($author);
|
|
$row['developer'][] = $author['developer'];
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendUrlInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpurl_item_detail`
|
|
WHERE `url_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
convertToInt($detail, array('url_id', 'url_count'));
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function appendNimgcenterInfo(&$row) {
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$item_id = $row['item_id'];
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpnimgcenter_item_detail`
|
|
WHERE `nimgcenter_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
while ($detail = $xoopsDB->fetchArray($res)) {
|
|
myDecode($detail);
|
|
$detail['coord_type_name'] = (0 === $detail['coord_type']) ? 'Talairach' : 'MNI';
|
|
$row += $detail;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
$sql =<<< SQL
|
|
SELECT *
|
|
FROM `${prefix}_xnpnimgcenter_talairach_list`
|
|
WHERE `nimgcenter_id`=$item_id
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);exit();
|
|
}
|
|
$row['coordinate'] = array();
|
|
while ($t = $xoopsDB->fetchArray($res)) {
|
|
$row['coordinate'][] = $t;
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
}
|
|
|
|
function myDecode(&$data){
|
|
$textutil = xoonips_getutility('text');
|
|
foreach ($data as $k => $v) {
|
|
$v = $textutil->html_numeric_entities($v);
|
|
$data[$k] = mb_decode_numericentity($v, array(0x0, 0x10000, 0, 0xfffff), 'UTF-8');
|
|
}
|
|
}
|
|
|
|
function convertToInt(&$data, $keys) {
|
|
foreach ($keys as $key) {
|
|
if (isset($data[$key])) {
|
|
$data[$key] = '' === $data[$key] ? null : (int) $data[$key];
|
|
}
|
|
}
|
|
}
|
|
|
|
function createThumbnail($obj, $basePath, $outputDir) {
|
|
$fileId = $obj->get('file_id');
|
|
$outputFile = $outputDir.'/'.$fileId.'.png';
|
|
$thumbnail_file = $obj->get('thumbnail_file');
|
|
$size = strlen($thumbnail_file);
|
|
if ($size > 0) {
|
|
file_put_contents($outputFile, $thumbnail_file);
|
|
return true;
|
|
}
|
|
$file_path = $basePath.'/'.$fileId;
|
|
$finfo = finfo_open(FILEINFO_NONE);
|
|
$label = finfo_file($finfo, $file_path);
|
|
finfo_close($finfo);
|
|
$mime_type = $obj->get('mime_type');
|
|
if (preg_match('/^([^\\/]*)\\/(.*)$/', $mime_type, $matches)) {
|
|
if ($matches[1] == 'audio') {
|
|
$img_type = 'audio';
|
|
} elseif ($matches[1] == 'image') {
|
|
$img_type = 'image';
|
|
} elseif ($matches[1] == 'video') {
|
|
$img_type = 'video';
|
|
} elseif ($matches[1] == 'text') {
|
|
$img_type = 'text';
|
|
} elseif ($matches[1] == 'application') {
|
|
$text_types = array('pdf', 'xml', 'msword', 'vnd.ms-excel');
|
|
$image_types = array('vnd.ms-powerpoint', 'postscript');
|
|
$audio_types = array('vnd.rn-realmedia');
|
|
if (in_array($matches[2], $text_types)) {
|
|
$img_type = 'text';
|
|
} elseif (in_array($matches[2], $audio_types)) {
|
|
$img_type = 'audio';
|
|
} elseif (in_array($matches[2], $image_types)) {
|
|
$img_type = 'image';
|
|
} else {
|
|
$img_type = 'application';
|
|
}
|
|
} else {
|
|
$img_type = 'unknown';
|
|
}
|
|
} else {
|
|
$img_type = 'unknown';
|
|
}
|
|
$img_file = XOOPS_ROOT_PATH.'/modules/xoonips/images/thumbnail_'.$img_type.'.png';
|
|
// create image resource
|
|
$w = 100;
|
|
$h = 100;
|
|
$im = imagecreatetruecolor($w, $h);
|
|
// label setting
|
|
$f = 2;
|
|
// font number
|
|
$lp = 5;
|
|
// label padding
|
|
$fw = imagefontwidth($f);
|
|
// font width
|
|
$fh = imagefontheight($f);
|
|
// font height
|
|
$fmaxlen = ($w - $lp * 2) / $fw;
|
|
// max label length
|
|
$labels = explode(',', $label);
|
|
$label = $labels[0];
|
|
$llen = strlen($label);
|
|
if ($llen > $fmaxlen) {
|
|
$label = substr($label, 0, $fmaxlen - 3);
|
|
$label .= '...';
|
|
$llen = strlen($label);
|
|
}
|
|
$lx = ($w - $llen * $fw) / 2;
|
|
$ly = $h - $fh - $lp;
|
|
// change alpha attributes and create transparent color
|
|
imageantialias($im, true);
|
|
imagealphablending($im, false);
|
|
imagesavealpha($im, true);
|
|
$transparent = imagecolorallocatealpha($im, 255, 255, 255, 0);
|
|
$col_white = imagecolorallocate($im, 255, 255, 255);
|
|
$col_gray = imagecolorallocate($im, 127, 127, 127);
|
|
$col_black = imagecolorallocate($im, 0, 0, 0);
|
|
// fill all area with transparent color
|
|
imagefill($im, 0, 0, $col_white);
|
|
imagealphablending($im, true);
|
|
$imicon = imagecreatefrompng($img_file);
|
|
imagecopy($im, $imicon, $w / 2 - 48 / 2, $h / 2 - 48 / 2, 0, 0, 48, 48);
|
|
imagepolygon($im, array(0, 0, $w - 1, 0, $w - 1, $h - 1, 0, $h - 1), 4, $col_gray);
|
|
if (strlen($label) != 0) {
|
|
imagestring($im, $f, $lx, $ly, $label, $black);
|
|
}
|
|
imagepng($im, $outputFile);
|
|
imagedestroy($imicon);
|
|
imagedestroy($im);
|
|
return true;
|
|
}
|
|
|