diff --git a/etc/common.inc.php b/etc/common.inc.php
deleted file mode 100644
index e072605..0000000
--- a/etc/common.inc.php
+++ /dev/null
@@ -1,190 +0,0 @@
- $v) {
- if (is_string($v)) {
- $v = html_entity_decode($v, ENT_QUOTES | ENT_HTML5);
- $v = mb_decode_numericentity($v, array(0x0, 0x10000, 0, 0xfffff), 'UTF-8');
- $data[$k] = \Normalizer::normalize(trim($v), \Normalizer::FORM_C);
- } elseif (null === $v) {
- $data[$k] = '';
- }
- }
- }
-
- public static function convertToInt(&$data, $keys, $zerofill = false)
- {
- foreach ($keys as $key) {
- if (isset($data[$key])) {
- $data[$key] = '' === $data[$key] ? ($zerofill ? 0 : null) : (int) $data[$key];
- }
- }
- }
-
- public static function dropColumn(&$data, $keys)
- {
- foreach ($keys as $key) {
- if (isset($data[$key])) {
- unset($data[$key]);
- }
- }
- }
-
- public static function fileCopy($from, $to)
- {
- system('rsync -aq '.escapeshellarg($from).' '.escapeshellarg($to), $ret);
-
- return 0 === $ret;
- }
-
- public static function fixHtml($text)
- {
- static $config = [
- //'clean' => true,
- 'hide-comments' => true,
- 'indent' => true,
- 'output-xhtml' => true,
- 'preserve-entities' => true,
- 'show-body-only' => true,
- 'wrap' => 0,
- 'input-encoding' => 'utf8',
- 'output-encoding' => 'utf8',
- 'output-bom' => false,
- ];
- $text = tidy_repair_string($text, $config);
- $text = preg_replace('/
]*)>((?:\s*]*>.*<\/caption>)?\s*)]*)>/Us', '\2', $text);
- $text = preg_replace('/<\/tr>(\s*)<\/table>/s', '
\1
', $text);
-
- return $text;
- }
-
- public static function tableExists($name)
- {
- global $xoopsDB;
- $prefix = $xoopsDB->prefix();
- $sql = <<< SQL
-SELECT 1
- FROM `${prefix}_${name}`
- LIMIT 1
-SQL;
- if (!($res = $xoopsDB->query($sql))) {
- return false;
- }
- $xoopsDB->freeRecordSet($res);
-
- return true;
- }
-
- public static function makeDirectory($dirname)
- {
- $path = MYDUMPTOOL_OUTPUTDIR.('' !== $dirname ? '/'.$dirname : '');
- if (!is_dir($path)) {
- if (!@mkdir($path)) {
- exit('Failed to create directory: '.$path.PHP_EOL);
- }
- }
- }
-
- public static function saveJson($fname, $data)
- {
- $path = MYDUMPTOOL_OUTPUTDIR.'/'.$fname;
- if (false === file_put_contents($path, json_encode($data, JSON_UNESCAPED_UNICODE))) {
- exit('Failed to save json file: '.$path.PHP_EOL);
- }
- }
-
- public static function fileDownload($url, $fpath)
- {
- $fp = fopen($fpath, 'w');
- if (false === $fp) {
- exit('Failed to open file: '.$fpath.PHP_EOL);
- }
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_AUTOREFERER, true);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FAILONERROR, true);
- curl_setopt($curl, CURLOPT_FILE, $fp);
- curl_setopt($curl, CURLOPT_TIMEOUT, 10);
- $ret = curl_exec($curl);
- fclose($fp);
- if (false === $ret) {
- exit('Failed to download file, unexpected error: '.$url.PHP_EOL);
- }
- $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- if (200 !== $code) {
- exit('Failed to download file, invalid status code('.$code.'): '.$url.PHP_EOL);
- }
- curl_close($curl);
-
- return true;
- }
-
- public static function getMimeType($fpath)
- {
- $finfo = finfo_open(FILEINFO_MIME);
- $mime = finfo_file($finfo, $fpath);
- finfo_close($finfo);
- $mime = preg_replace('/(;.*)$/', '', $mime);
-
- return $mime;
- }
-}
diff --git a/etc/config.inc.php b/etc/config.inc.php
deleted file mode 100644
index 0f33781..0000000
--- a/etc/config.inc.php
+++ /dev/null
@@ -1,7 +0,0 @@
-prefix();
- $table = $pico.'_contents';
- if (!MyDumpTool::tableExists($table)) {
- exit('pico('.$pico.') module not found'.PHP_EOL);
- }
- MyDumpTool::makeDirectory('public/'.$pico);
- MyDumpTool::makeDirectory('public/'.$pico.'/images');
- $moduleHandler = xoops_gethandler('module');
- $module = $moduleHandler->getByDirname($pico);
- $moduleConfigHandler = xoops_gethandler('config');
- $moduleConfig = $moduleConfigHandler->getConfigsByDirname($pico);
- $permObj = PicoPermission::getInstance();
- $perms = $permObj->getPermissions($pico);
- $categoryHandler = new PicoCategoryHandler($pico, $perms);
- $contentHandler = new PicoContentHandler($pico);
- $cats = $categoryHandler->getAllCategories();
- $confContents = [];
- $confCategories = [];
- foreach ($cats as $cat) {
- $catData = $cat->getData();
- $modConfig = $cat->getOverriddenModConfig();
- $link = pico_common_make_category_link4html($modConfig, $catData, $pico);
- MyDumpTool::decode($catData);
- $confCategories[] = [
- 'id' => $catData['id'],
- 'title' => $catData['cat_title'],
- 'desc' => (string) $catData['cat_desc'],
- 'pid' => (int) $catData['pid'],
- 'weight' => (int) $catData['cat_weight'],
- 'link' => $link,
- ];
- $contents = $contentHandler->getCategoryContents($cat);
- foreach ($contents as $content) {
- $data = $content->getData();
- $link = pico_common_make_content_link4html($modConfig, $data);
- MyDumpTool::decode($data);
- $content = MyDumpTool::fixHtml($data['body_cached']);
- $imageId = 1;
- $dataId = [];
- $content = preg_replace_callback('/
]*)src="(.*)"([^>]*)\/>/Us', function ($matches) use (&$imageId, $pico, $data, $link) {
- $url = $matches[2];
- if (!preg_match('/^http/', $url)) {
- if (preg_match('/^\//', $url)) {
- $url = XOOPS_URL.$url;
- } else {
- $xpath = dirname($link);
- $url = XOOPS_URL.'/modules/'.$pico.'/'.$xpath.'/'.$url;
- }
- }
- $fname = '/'.$pico.'/images/'.$data['id'].'_'.$imageId.'.dat';
- $fpath = MYDUMPTOOL_OUTPUTDIR.'/public'.$fname;
- MyDumpTool::fileDownload($url, $fpath);
- $mime = MyDumpTool::getMimeType($fpath);
- switch ($mime) {
- case 'image/gif':
- $fpath_ = preg_replace('/.dat$/', '.gif', $fpath);
- $fname = preg_replace('/.dat$/', '.gif', $fname);
- rename($fpath, $fpath_);
- $fpath = $fpath_;
- break;
- case 'image/png':
- $fpath_ = preg_replace('/.dat$/', '.png', $fpath);
- $fname = preg_replace('/.dat$/', '.png', $fname);
- rename($fpath, $fpath_);
- $fpath = $fpath_;
- break;
- case 'image/jpeg':
- $fpath_ = preg_replace('/.dat$/', '.jpeg', $fpath);
- $fname = preg_replace('/.dat$/', '.jpeg', $fname);
- rename($fpath, $fpath_);
- $fpath = $fpath_;
- break;
- default:
- exit('unknown mime type '.$mime.' found: '.$fname.' from '.$url.PHP_EOL);
- }
- ++$imageId;
-
- return '
';
- }, $content);
- $content = preg_replace_callback('/]*)href="([^"]+)"([^>]*)>/Us', function ($matches) use (&$dataId, $pico, $data, $link) {
- $url = $matches[2];
- if (preg_match('/^(.+)\/([^\/]+\.pdf)(\?.+)?$/', $url, $m)) {
- if (!isset($dataId[$m[1]])) {
- $dataId[$m[1]] = count($dataId) + 1;
- }
- $id = $dataId[$m[1]];
- $fname = '/'.$pico.'/data/'.$data['id'].'/'.$id.'/'.urldecode($m[2]);
- $fpath = MYDUMPTOOL_OUTPUTDIR.'/public'.$fname;
- if (!file_exists($fpath)) {
- MyDumpTool::makeDirectory('public/'.$pico.'/data');
- MyDumpTool::makeDirectory('public/'.$pico.'/data/'.$data['id']);
- MyDumpTool::makeDirectory('public/'.$pico.'/data/'.$data['id'].'/'.$id);
- if (preg_match('/^\//', $url)) {
- $url = XOOPS_URL.$url;
- }
- MyDumpTool::fileDownload($url, $fpath);
- }
- $url = '/'.$pico.'/data/'.$data['id'].'/'.$id.'/'.$m[2];
- }
-
- return '';
- }, $content);
- $item = [
- 'id' => $data['id'],
- 'title' => $data['subject_raw'],
- 'content' => $content,
- ];
- MyDumpTool::saveJson('public/'.$pico.'/'.$data['id'].'.json', $item);
- $confContents[] = [
- 'id' => $item['id'],
- 'title' => $data['subject_raw'],
- 'cat_id' => (int) $data['cat_id'],
- 'weight' => (int) $data['weight'],
- 'link' => $link,
- ];
- }
- }
- $moduleinfo = [
- 'name' => $module->get('name'),
- 'dirname' => $pico,
- 'message' => $moduleConfig['top_message'],
- 'show_menuinmoduletop' => (int) $moduleConfig['show_menuinmoduletop'],
- 'show_listasindex' => (int) $moduleConfig['show_listasindex'],
- 'show_breadcrumbs' => (int) $moduleConfig['show_breadcrumbs'],
- 'show_pagenavi' => (int) $moduleConfig['show_pagenavi'],
- ];
- MyDumpTool::decode($moduleinfo);
- $config[] = [
- 'module' => $moduleinfo,
- 'categories' => $confCategories,
- 'contents' => $confContents,
- ];
-}
diff --git a/etc/dumpXooNIps4.php b/etc/dumpXooNIps4.php
deleted file mode 100644
index 078b27e..0000000
--- a/etc/dumpXooNIps4.php
+++ /dev/null
@@ -1,837 +0,0 @@
-prefix();
-
-$table = 'xoonips_index';
-if (!MyDumpTool::tableExists($table)) {
- exit('xoonips module not found'.PHP_EOL);
-}
-MyDumpTool::makeDirectory('src/database');
-MyDumpTool::makeDirectory('src/database/assets');
-MyDumpTool::makeDirectory('public/database');
-MyDumpTool::makeDirectory('public/database/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 = array();
-$limitFiles = array();
-
-if (!($res = $xoopsDB->query($sql))) {
- var_dump($xoopsDB);
- exit();
-}
-$tree = array();
-$root = array();
-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/database/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 = array();
-$items = array();
-while ($row = $xoopsDB->fetchArray($res)) {
- MyDumpTool::decode($row);
- MyDumpTool::convertToInt($row, array('item_id', 'item_type_id', 'last_update_date', 'creation_date'));
- $item_id = $row['item_id'];
- $item_type = 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 = array(
- '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' => 'eng',
- 'title' => '',
- 'item_type_display_name' => $row['item_type_display_name'],
- 'item_type_name' => 'xnp'.$row['item_type_name'],
- 'uname' => $row['owner'][0]['uname'],
- 'name' => $row['owner'][0]['name'],
- 'item_url' => getItemUrl($row),
- 'index' => $row['index'],
- 'changelog' => array(),
- 'related_to' => array(),
- 'keyword' => array(),
- 'file' => array()
- );
- foreach ($row['detail'] as $gxml => $gdata) {
- foreach ($gdata as $fxml => $fdata) {
- if ('title' === $gxml && 'title' === $fxml) {
- $item['title'] = $fdata[0];
- }
- if ('langs' === $gxml && 'lang' === $fxml) {
- $item['lang'] = $fdata[0];
- }
- if ('changelogs' === $gxml && 'changelog' === $fxml) {
- foreach ($fdata as $value) {
- $item['changelog'][] = array(
- 'log_date' => (int) $value['log_date'],
- 'log' => $value['log'],
- );
- }
- }
- if ('links' === $gxml && 'link' === $fxml) {
- $item['related_to'] = $fdata;
- }
- if ('free_keywords' === $gxml && 'keyword' === $fxml) {
- $item['keyword'] = $fdata;
- }
- if (in_array($fxml, array('file', 'image'))) {
- foreach ($fdata as $value) {
- $item['file'][] = array(
- '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)))),
- );
- }
- }
- // binder
- if ('binder' === $item_type) {
- if ('research_areas' === $gxml && 'research_area' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one research_area in binder'.PHP_EOL);
- }
- $item['research_area'] = empty($fdata) ? '' : $fdata[0];
- }
- if ('species' === $gxml && 'species' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one species in binder'.PHP_EOL);
- }
- $item['species'] = empty($fdata) ? '' : $fdata[0];
- }
- if ('scales' === $gxml && 'scale' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one scale in binder'.PHP_EOL);
- }
- $item['scale'] = empty($fdata) ? '' : $fdata[0];
- }
- if ('methods' === $gxml && 'method' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one method in binder'.PHP_EOL);
- }
- $item['method'] = empty($fdata) ? '' : $fdata[0];
- }
- if ('summary' === $gxml && 'summary' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one summary in binder'.PHP_EOL);
- }
- $item['description'] = $fdata[0];
- }
- if ('agree' === $gxml && 'agree' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one agree in binder'.PHP_EOL);
- }
- $item['agree'] = (1 === $fdata[0] ? 'Agree' : 'Disagree');
- }
- if ('approver' === $gxml && 'approver' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one approver in binder'.PHP_EOL);
- }
- $item['referee'] = $fdata[0];
- }
- if ('guide_to_temporaryuser' === $gxml && 'guide_to_temporaryuser' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one guide_to_temporaryuser in binder'.PHP_EOL);
- }
- $item['guide_to_temporaryuser'] = ("1" === $fdata[0] ? '' : 'No');
- }
- }
- if ('data' === $item_type) {
- if ('date' === $gxml && 'date' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one date in presentation'.PHP_EOL);
- }
- $d = explode('/', date('Y/m/d', $fdata[0]));
- $item['publication_year'] = (int) $d[0];
- $item['publication_month'] = (int) $d[1];
- $item['publication_mday'] = (int) $d[2];
- }
- if ('outline' === $gxml && 'description' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one data_type in data'.PHP_EOL);
- }
- $item['description'] = $fdata[0];
- }
- if ('data_type' === $gxml && 'data_type' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one data_type in data'.PHP_EOL);
- }
- $item['data_type'] = $fdata[0];
- }
- if ('readme' === $gxml && 'readme' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one readme in data'.PHP_EOL);
- }
- $item['readme'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('rights' === $gxml && 'rights' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one rights in data'.PHP_EOL);
- }
- $item['rights'] = substr($fdata[0], 4);
- if (false === $item['rights']) {
- $item['rights'] = '';
- }
- $item['use_cc'] = (int) substr($fdata[0], 0, 1);
- $item['cc_commercial_use'] = (int) substr($fdata[0], 1, 1);
- $item['cc_modification'] = (int) substr($fdata[0], 2, 1);
- }
- if ('download_limitation' === $gxml && 'attachment_dl_limit' === $fxml) {
- if (1 != count($fdata)) {
- die('does\'nt support more than one attachment_dl_limit in data'.PHP_EOL);
- }
- $item['attachment_dl_limit'] = $fdata[0];
- }
- if ('download_notification' === $gxml && 'attachment_dl_notify' === $fxml) {
- if (1 != count($fdata)) {
- die('does\'nt support more than one attachment_dl_notify in data'.PHP_EOL);
- }
- $item['attachment_dl_notify'] = $fdata[0];
- }
- if ('experimenters' === $gxml && 'experimenter' === $fxml) {
- $item['experimenter'] = $fdata;
- }
- if ('approver' === $gxml && 'approver' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one approver in data'.PHP_EOL);
- }
- $item['referee'] = $fdata[0];
- }
- }
- if ('paper' === $item_type) {
- if ('publication_year' === $gxml && 'publication_year' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one publication year in paper'.PHP_EOL);
- }
- $item['publication_year'] = empty($fdata[0]) ? 0 : $fdata[0];
- }
- if ('journal' === $gxml && 'journal' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one journal in paper'.PHP_EOL);
- }
- $item['journal'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('volume' === $gxml && 'volume' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one volume in paper'.PHP_EOL);
- }
- $item['volume'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('number' === $gxml && 'number' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one jo in paper'.PHP_EOL);
- }
- $item['number'] = empty($fdata[0]) ? null : (int) $fdata[0];
- }
- if ('page' === $gxml && 'page' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one jo in paper'.PHP_EOL);
- }
- $item['page'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('abstract' === $gxml && 'description' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one description in paper'.PHP_EOL);
- }
- $item['abstract'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('pubmedid' === $gxml && 'pubmedid' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one pubmedid in paper'.PHP_EOL);
- }
- $item['pubmed_id'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('authors' === $gxml && 'name' === $fxml) {
- $item['author'] = $fdata;
- }
- if ('approver' === $gxml && 'approver' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one approver in paper'.PHP_EOL);
- }
- $item['referee'] = $fdata[0];
- }
- }
- if ('presentation' === $item_type) {
- if ('date' === $gxml && 'date' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one date in presentation'.PHP_EOL);
- }
- $d = explode('/', date('Y/m/d', $fdata[0]));
- $item['publication_year'] = (int) $d[0];
- $item['publication_month'] = (int) $d[1];
- $item['publication_mday'] = (int) $d[2];
- }
- if ('outline' === $gxml && 'description' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one data_type in data'.PHP_EOL);
- }
- $item['description'] = $fdata[0];
- }
- if ('presentation_type' === $gxml && 'presentation_type' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one presentation_type in presentation'.PHP_EOL);
- }
- $item['presentation_type'] = $fdata[0];
- }
- if ('readme' === $gxml && 'readme' === $fxml) {
- if (1 < count($fdata)) {
- die('does\'nt support more than one readme in presentation'.PHP_EOL);
- }
- $item['readme'] = empty($fdata[0]) ? '' : $fdata[0];
- }
- if ('rights' === $gxml && 'rights' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one rights in presentation'.PHP_EOL);
- }
- $item['rights'] = substr($fdata[0], 4);
- if (false === $item['rights']) {
- $item['rights'] = '';
- }
- $item['use_cc'] = (int) substr($fdata[0], 0, 1);
- $item['cc_commercial_use'] = (int) substr($fdata[0], 1, 1);
- $item['cc_modification'] = (int) substr($fdata[0], 2, 1);
- }
- if ('download_limitation' === $gxml && 'attachment_dl_limit' === $fxml) {
- if (1 != count($fdata)) {
- die('does\'nt support more than one attachment_dl_limit in presentation'.PHP_EOL);
- }
- $item['attachment_dl_limit'] = $fdata[0];
- }
- if ('download_notification' === $gxml && 'attachment_dl_notify' === $fxml) {
- if (1 != count($fdata)) {
- die('does\'nt support more than one attachment_dl_notify in presentation'.PHP_EOL);
- }
- $item['attachment_dl_notify'] = $fdata[0];
- }
- if ('creators' === $gxml && 'creator' === $fxml) {
- $item['creator'] = $fdata;
- }
- if ('approver' === $gxml && 'approver' === $fxml) {
- if (1 !== count($fdata)) {
- die('does\'nt support more than one approver in presentation'.PHP_EOL);
- }
- $item['referee'] = $fdata[0];
- }
- }
- if ('tool' === $item_type) {
- die('does\'nt support item type tool'.PHP_EOL);
- }
- }
- }
- if ('binder' === $item_type) {
- $item['extra'] = '';
- $item['item_link'] = $item['related_to'];
- $item['related_to'] = [];
- }
- if (isset($item['attachement_dl_limit']) && 1 === $item['attachement_dl_limit']) {
- $limitItems[] = array(
- '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'];
- }
- }
- }
- $items[] = $item;
-}
-$xoopsDB->freeRecordSet($res);
-MyDumpTool::saveJson('itemsRaw.json', $itemsRaw);
-MyDumpTool::saveJson('public/database/items.json', $items);
-
-$fp = fopen(MYDUMPTOOL_OUTPUTDIR.'/dl-limit-items.csv', 'w');
-foreach ($limitItems as $row) {
- $data = array(
- $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/database/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 /database/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 = 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`.`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 = 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 (1 != $parent_id) {
- $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 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 = array();
- while ($row = $xoopsDB->fetchArray($res)) {
- MyDumpTool::decode($row);
- MyDumpTool::convertToInt($row, array('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 = array();
- while ($row = $xoopsDB->fetchArray($res)) {
- MyDumpTool::decode($row);
- MyDumpTool::convertToInt($row, array('uid'));
- $uid = $row['uid'];
- $users[$uid] = array(
- '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 = array();
- while ($row = $xoopsDB->fetchArray($res)) {
- MyDumpTool::decode($row);
- MyDumpTool::convertToInt($row, array('item_type_id'));
- $item_type_id = $row['item_type_id'];
- $item_type = strtolower($row['name']);
- $item_types[$item_type] = array(
- '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`
- 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 = array();
- while ($row = $xoopsDB->fetchArray($res)) {
- MyDumpTool::decode($row);
- MyDumpTool::convertToInt($row, array('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']] = array(
- 'id' => $group_id,
- 'label' => $row['name'],
- '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 = array();
- while ($row = $xoopsDB->fetchArray($res)) {
- MyDumpTool::decode($row);
- MyDumpTool::convertToInt($row, array('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']] = array(
- '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'])
- );
- }
- $xoopsDB->freeRecordSet($res);
-
- return $ret;
-}
-function getSelectList($name) {
- global $xoopsDB;
- $prefix = $xoopsDB->prefix();
- $ret = array();
- 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 = array();
- foreach ($itemType['groups'] as $gxml => $gdata) {
- $gret = array();
- 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 = array();
- 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();
- }
-}