2009-03-06 03:20:46 +00:00
< ? php
class MD_Resolution
{
public $equScale ;
public $scaleDist ;
}
class MD_Keywords
{
public $keyword ;
public $keyTyp ;
public $thesaName ;
}
class MD_BrowseGraphic
{
public $bgFileName ;
public $bgFileDesc ;
public $bgFileType ;
}
class MD_Identification
{
public $idCitation ;
public $idAbs ;
public $idPurp ;
public $idCredit ;
public $idStatus ;
public $idPoc ;
public $resMaint ;
public $graphOver ;
public $dsFormat ;
public $descKeys ;
public $idSpecUse ;
public $resConst ;
public $aggrInfo ;
public $spatRpType ;
public $dataScale ;
public $dataLang ;
public $dataChar ;
public $tpCat ;
public $envirDesc ;
public $dataExt ;
public $suppInfo ;
public $SerIdent ;
}
class MD_Metadata
{
public $mdFileID ; //string
public $mdLang ; //conditional, string
public $mdChar ; //conditional, class
public $mdParentID ; //string
public $mdHrLv ; //class array
public $mdHrLvName ; //string array
public $mdContact ; //class array
public $mdDateSt ; //class,数据创建时间
public $mdStanName ; //string
public $mdStanVer ; //string
public $dataSetUri ; //string
public $spatRepInfo ; //array association
public $refSysInfo ; //array..
public $mdExtInfo ; //array..
public $dtaIdInfo ; //array...MD_Identification
public $contInfo ; //array ..
public $distInfo ; //association
public $dqInfo ; //array ..
public $porCatInfo ; //array..
public $mdConst ; //array..
public $appSchInfo ; //array..
public $mdMaint ; //association
}
/**
* 采用DOM实现, 需要PHP5
**/
class ISO19115
{
public $mdFileID ;
public $mdLang ;
public $mdChar ;
public $mdDateSt ;
public $mdStanName = 'ISO 19115' ;
public $mdStanVer = '19115:2003' ;
public $mdContact ;
public $uuid ;
2012-04-01 07:00:52 +00:00
public $doi = '' ;
2009-03-06 03:20:46 +00:00
/**
* 数据集标题
* 字符串
**/
public $resTitle ;
public $resAltTitle ;
/**
* 数据集简介
**/
public $idAbs ;
public $dataSetURI ;
public $bgFileName ;
/**
* 数据集序列信息
* 数组
**/
public $datasetSeries ; //array
/**
* 类别代码,数组
* 注意在geonetwork中的不是代码, 而是直接的类别值
**/
public $tpCat ;
/**
* 时间信息, start & end
* 注意: geonetwork中和国家元数据标准的代码不同
* ISO 19115 中好像没有看到相关信息
**/
public $timebegin ;
public $timeend ;
/**
* 空间信息
* 数组形式 [ 'w' ], s , e , n
**/
public $geoBox ;
public $thumbnail ;
public $graph ;
public $keyword ;
private $dom ;
public $keytypecode = array ( 1 => 'discipline' , 'place' , 'stratum' , 'temporal' , 'theme' );
2010-01-01 13:05:50 +00:00
public $author ;
2012-12-03 03:30:09 +00:00
public $error = array ();
2012-12-13 07:05:28 +00:00
public $xml ;
2009-03-06 03:20:46 +00:00
function __construct ()
{
$this -> dom = new DOMDocument ();
}
/**
* 从文件中读取元数据
**/
function load ( $file )
{
$this -> dom -> load ( $file );
$this -> parse ();
}
/**
* 从字符串中读取元数据
*/
function loadXML ( $str )
{
2012-12-12 04:22:05 +00:00
@ $this -> dom -> loadXML ( $str );
2012-12-13 07:05:28 +00:00
$this -> xml = $str ;
2009-03-06 03:20:46 +00:00
$this -> parse ();
}
/**
* 保存元数据到文件file中
*/
function save ( $file )
{
return $this -> dom -> save ( $file );
}
/**
* 根据xml中的node保存为xml
**/
function saveXML ( $node = " " )
{
return $this -> dom -> saveXML ( $node );
}
/**
* 根据UUID从数据库中提取元数据信息, 不需要进行parse () 操作
**/
function loadUUID ( $uuid )
{
}
2012-12-03 03:30:09 +00:00
function saveDB ( $db , $xml = '' )
2009-03-06 03:20:46 +00:00
{
2012-12-03 03:30:09 +00:00
if ( ! empty ( $xml )) $this -> loadXML ( $xml );
2012-04-01 06:25:56 +00:00
//先删除已有元数据,然后再插入新数据
2013-11-10 10:40:56 +00:00
$sql = " delete from en.metadata where uuid=? " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $this -> uuid ));
//删除所有未用到的responsible数据
2013-11-10 10:40:56 +00:00
$sql = " delete from en.responsible where id not in (select distinct(resid) from role) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql );
//if (!empty($this->doi)) $row->doi=$this->doi;
//生成空白统计数据, 可以转移到数据库端处理( todo)
try
{
2013-11-10 10:40:56 +00:00
//$sql="insert into mdstat (uuid) values(?)";
//$db->query($sql,array($this->uuid));
2012-04-01 06:25:56 +00:00
} catch ( Exception $e ) {
//do nothing.
//说明数据库中已存在该信息
}
2012-06-12 10:38:55 +00:00
$dbmode = $db -> getFetchMode ();
$db -> setFetchMode ( Zend_Db :: FETCH_OBJ );
2012-04-01 06:25:56 +00:00
//save metadata into database
try {
2013-05-20 06:56:50 +00:00
if ( $this -> refDate )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.metadata (uuid,title,title_en,description,citation,suppinfo,fileformat,projection,datatype,filesize,ts_created,
2013-05-20 06:56:50 +00:00
timebegin , timeend , west , south , north , east , doi , ts_published ) values ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) " ;
$db -> query ( $sql , array ( $this -> uuid , $this -> resTitle , $this -> resAltTitle , $this -> idAbs , $this -> citation , $this -> suppinfo , $this -> fileformat ,
$this -> projection , $this -> datatype , $this -> filesize , $this -> mdDateSt , $this -> timebegin , $this -> timeend , $this -> geoBox [ 'w' ],
$this -> geoBox [ 's' ], $this -> geoBox [ 'n' ], $this -> geoBox [ 'e' ], $this -> doi , $this -> refDate ));
} else {
2013-11-10 10:40:56 +00:00
$sql = " insert into en.metadata (uuid,title,title_en,description,citation,suppinfo,fileformat,projection,datatype,filesize,ts_created,
2013-05-20 06:56:50 +00:00
timebegin , timeend , west , south , north , east , doi ) values ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) " ;
$db -> query ( $sql , array ( $this -> uuid , $this -> resTitle , $this -> resAltTitle , $this -> idAbs , $this -> citation , $this -> suppinfo , $this -> fileformat ,
2012-04-01 06:25:56 +00:00
$this -> projection , $this -> datatype , $this -> filesize , $this -> mdDateSt , $this -> timebegin , $this -> timeend , $this -> geoBox [ 'w' ],
$this -> geoBox [ 's' ], $this -> geoBox [ 'n' ], $this -> geoBox [ 'e' ], $this -> doi ));
2013-05-20 06:56:50 +00:00
}
2013-11-10 10:40:56 +00:00
$id = $db -> lastInsertId ( 'en.metadata' , 'id' );
2012-04-01 06:25:56 +00:00
//处理在线资源
if ( $this -> onlineresource ) foreach ( $this -> onlineresource as $resource )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?) " ;
2014-05-08 13:25:27 +00:00
if ( ! isset ( $resource [ 'name' ])) $resource [ 'name' ] = '' ;
if ( ! isset ( $resource [ 'description' ])) $resource [ 'description' ] = '' ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $this -> uuid , $resource [ 'linkage' ], $resource [ 'protocol' ], $resource [ 'name' ], $resource [ 'description' ]));
}
//处理缩略图
if ( ! empty ( $this -> thumbnail )) {
2013-11-10 10:40:56 +00:00
$sql = " insert into en.thumbnail (id,data,filetype) values(?,?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $id , $this -> thumbnail , 'jpg' ));
} elseif ( $this -> graph ) {
//$trow->data=$this->graph['data'];
2013-11-10 10:40:56 +00:00
$sql = " select id as gid from en.geonetworkmetadata where uuid=? " ;
2012-04-01 06:25:56 +00:00
$r = $db -> fetchRow ( $sql , array ( $this -> uuid ));
if ( $r )
{
2014-05-08 13:25:27 +00:00
$geonetwork = 'http://' . $_SERVER [ 'HTTP_HOST' ] . '/geonetwork/' ;
2012-04-15 15:31:43 +00:00
$thumb = base64_encode ( file_get_contents ( $geonetwork . 'srv/cn/resources.get?access=public&id=' . $r -> gid . '&fname=' . urlencode ( $this -> graph [ 'filename' ])));
2013-11-10 10:40:56 +00:00
$sql = " insert into en.thumbnail (id,data,filetype,filedesc,filename) values(?,?,?,?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $id , $thumb , $this -> graph [ 'filetype' ], $this -> graph [ 'filedesc' ], $this -> graph [ 'filename' ]));
}
}
//处理关键词
//1:N relation
foreach ( $this -> keyword as $keytype => $keys )
{
foreach ( $keys as $key )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.keyword (id,keyword,keytype) values(?,?,?) " ;
2012-12-03 03:30:09 +00:00
try {
$db -> query ( $sql , array ( $id , $key , $keytype ));
} catch ( Exception $e ) {
//忽略关键词错误
}
2012-04-01 06:25:56 +00:00
}
}
//处理数据集序列
//M:N relation
2013-06-07 09:45:10 +00:00
if ( $this -> datasetSeries ) foreach ( $this -> datasetSeries as $ds ) if ( ! empty ( $ds [ 'seriesName' ]))
2012-04-01 06:25:56 +00:00
{
2013-11-10 10:40:56 +00:00
$sql = " select id from en.series where name=? " ;
2012-04-01 06:33:55 +00:00
$sth = $db -> prepare ( $sql );
2012-04-01 06:25:56 +00:00
$sth -> execute ( array ( $ds [ 'seriesName' ]));
$trow = $sth -> fetch ();
if ( $trow )
2012-04-01 07:00:52 +00:00
$sid = $trow -> id ;
2012-04-01 06:25:56 +00:00
else {
2013-11-10 10:40:56 +00:00
$sql = " insert into en.series (name) values(?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $ds [ 'seriesName' ]));
$sid = $db -> lastInsertId ( 'series' , 'id' );
}
2013-11-10 10:40:56 +00:00
$sql = " insert into en.dataseries (id,sid) values(?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $id , $sid ));
}
//处理数据分类
foreach ( $this -> tpCat as $cat ){
if ( is_numeric ( $cat )) {
2013-11-10 10:40:56 +00:00
$sql = " insert into en.category (id,code) values(?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $id ,( int ) $cat ));
} else {
//是字符串, geonetwork会采用这种模式
//从categorycode表中查找其对应的code
2013-11-10 10:40:56 +00:00
$sql = " insert into en.category (id,code) select ?,code from categorycode where name=? " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $id , trim ( $cat )));
}
}
//处理联系人信息
//先查询再进行处理
//若用户信息发生变化,则存在问题
//无法保证数据的更新状态
foreach ( $this -> author as $au )
{
$inds = explode ( " ; " , $au [ 'individual' ]);
foreach ( $inds as $ind )
{
2013-11-10 10:40:56 +00:00
$sql = " select id from en.responsible where individual=? and organisation=? " ;
2012-04-01 06:25:56 +00:00
$row = $db -> fetchRow ( $sql , array ( trim ( $ind ), trim ( $au [ 'organisation' ])));
if ( ! $row )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.responsible (individual,organisation,position,delivery,phone,email,city,country,administrative,postal) values(?,?,?,?,?,?,?,?,?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( trim ( $ind ), trim ( $au [ 'organisation' ]), trim ( $au [ 'position' ]), trim ( $au [ 'delivery' ]), trim ( $au [ 'phone' ]), trim ( $au [ 'email' ]), trim ( $au [ 'city' ]), trim ( $au [ 'country' ]), trim ( $au [ 'administrative' ]), trim ( $au [ 'postal' ])));
} elseif ( count ( $inds ) == 1 ) {
//deal email address
if (( $au [ 'email' ]) && empty ( $row -> email ))
{
2013-11-10 10:40:56 +00:00
$sql = " update en.responsible set email=? where id=? " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( trim ( $au [ 'email' ]), $row -> id ));
}
}
2013-11-10 10:40:56 +00:00
$sql = " select id from en.responsible where individual=? and organisation=? " ;
2012-04-01 06:25:56 +00:00
$row = $db -> fetchRow ( $sql , array ( trim ( $ind ), trim ( $au [ 'organisation' ])));
if ( $row -> id > 0 )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.role (resid,uuid,role) values(?,?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $row -> id , $this -> uuid , trim ( $au [ 'role' ])));
}
}
}
//处理数据限制信息
foreach ( $this -> limits as $uselimit )
{
2013-11-10 10:40:56 +00:00
$sql = " select id from en.uselimit where uselimit=? " ;
2012-04-01 06:25:56 +00:00
$row = $db -> fetchRow ( $sql , array ( $uselimit ));
if ( ! $row )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.uselimit (uselimit) values (?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $uselimit ));
}
2013-11-10 10:40:56 +00:00
$sql = " select id from en.uselimit where uselimit=? " ;
2012-04-01 06:25:56 +00:00
$row = $db -> fetchRow ( $sql , array ( $uselimit ));
if ( $row )
{
2013-11-10 10:40:56 +00:00
$sql = " insert into en.mdlimit (uuid,lid) values(?,?) " ;
2012-04-01 06:25:56 +00:00
$db -> query ( $sql , array ( $this -> uuid , $row -> id ));
}
}
$this -> save ( " ../data/import/ $this->uuid .xml " );
2012-12-13 06:42:42 +00:00
//处理XML入库
2012-12-13 07:05:28 +00:00
if ( ! empty ( $xml )) $this -> xml = $xml ;
2013-11-10 10:40:56 +00:00
$sql = " insert into en.xml (id,data) values(?,?) " ;
2012-12-13 07:05:28 +00:00
$db -> query ( $sql , array ( $id , $this -> xml ));
2012-04-01 06:25:56 +00:00
} catch ( Exception $e ) {
//数据重复插入,此处忽略所有错误
print $this -> uuid . ' has error: ' . $e -> getMessage () . '<br />' ;
2012-06-12 10:38:55 +00:00
}
$db -> setFetchMode ( $dbmode );
2009-03-06 03:20:46 +00:00
}
2012-12-03 03:30:09 +00:00
//检查元数据的错误信息
function validate ()
{
//uuid
if ( empty ( $this -> uuid )) $this -> error [] = '错误: 数据的UUID不能为空! ' ;
if ( empty ( $this -> resTitle )) $this -> error [] = '错误:数据标题不能为空!' ;
if ( ! is_numeric ( $this -> filesize )) $this -> error [] = '错误: 数据的大小( 传输量) 必须为数字, 单位为MB! ' ;
//空间范围
if ( ! is_numeric ( $this -> geoBox [ 'w' ]) || ! is_numeric ( $this -> geoBox [ 'e' ]) || ! is_numeric ( $this -> geoBox [ 's' ]) ||! is_numeric ( $this -> geoBox [ 'n' ]))
$this -> error [] = '错误:数据的空间范围必须为数字格式的经纬度!' ;
//时间范围
if ( ! empty ( $this -> timebegin ) && ! strtotime ( $this -> timebegin ))
$this -> error [] = '错误:数据的开始时间格式不正确!' ;
if ( ! empty ( $this -> timeend ) && ! strtotime ( $this -> timeend ))
$this -> error [] = '错误:数据的结束时间格式不正确!' ;
//关键词不能有空白(即使关键词类型不一样)
foreach ( $this -> keyword as $k1 => $keyt )
{
foreach ( $keyt as $k2 => $keyword )
{
if ( empty ( $keyword )) $this -> error [] = '错误:数据的关键词不能为空!' ;
}
}
//联系人必须有email地址?
//todo
//建议有缩略图
2012-12-11 10:12:32 +00:00
if ( empty ( $this -> graph )) $this -> error [] = '建议: 请提供一张能反应或代表数据的图片( 800像素以上) 。' ;
2012-12-03 03:30:09 +00:00
return count ( $this -> error );
}
2009-03-06 03:20:46 +00:00
function parse ()
{
$this -> resTitle = $this -> dom -> getElementsByTagName ( 'resTitle' ) -> item ( 0 ) -> nodeValue ;
2010-01-06 02:09:46 +00:00
$this -> resAltTitle = $this -> dom -> getElementsByTagName ( 'resAltTitle' ) -> item ( 0 ) -> nodeValue ;
2009-03-06 03:20:46 +00:00
$this -> idAbs = $this -> dom -> getElementsByTagName ( 'idAbs' ) -> item ( 0 ) -> nodeValue ;
$this -> mdFileID = $this -> dom -> getElementsByTagName ( 'mdFileID' ) -> item ( 0 ) -> nodeValue ;
$this -> mdDateSt = $this -> dom -> getElementsByTagName ( 'mdDateSt' ) -> item ( 0 ) -> nodeValue ;
@ $this -> dataSetURI = $this -> dom -> getElementsByTagName ( 'dataSetURI' ) -> item ( 0 ) -> nodeValue ;
//引用说明
@ $this -> citation = $this -> dom -> getElementsByTagName ( 'otherCitDet' ) -> item ( 0 ) -> nodeValue ;
2010-01-26 07:31:25 +00:00
//项目支持信息
@ $this -> suppinfo = $this -> dom -> getElementsByTagName ( 'suppInfo' ) -> item ( 0 ) -> nodeValue ;
2010-07-01 10:40:44 +00:00
//DOI, 自定义项
$cittype = $this -> dom -> getElementsByTagName ( 'citIdType' ) -> item ( 0 ) -> nodeValue ;
if ( $cittype == 'DOI' )
$this -> doi = $this -> dom -> getElementsByTagName ( 'citId' ) -> item ( 0 ) -> nodeValue ;
2009-03-06 03:20:46 +00:00
//数据大小, 以MB为单位
@ $this -> filesize = $this -> dom -> getElementsByTagName ( 'transSize' ) -> item ( 0 ) -> nodeValue ;
//数据格式,可以多个,但此处只用一个?
@ $this -> fileformat = $this -> dom -> getElementsByTagName ( 'formatName' ) -> item ( 0 ) -> nodeValue ;
//投影类型,可以多个,但只选一个
@ $this -> projection = $this -> dom -> getElementsByTagName ( 'identCode' ) -> item ( 0 ) -> nodeValue ;
2010-01-05 02:11:06 +00:00
//数据限制信息
$limits = $this -> dom -> getElementsByTagName ( 'useLimit' );
foreach ( $limits as $limit )
{
$this -> limits [] = $limit -> nodeValue ;
}
2009-03-06 03:20:46 +00:00
//数据作者
$authors = $this -> dom -> getElementsByTagName ( 'citRespParty' );
2010-01-01 13:05:50 +00:00
foreach ( $authors as $k => $author )
{
$this -> author [ $k ][ 'individual' ] = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'organisation' ] = $author -> getElementsByTagName ( 'rpOrgName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'position' ] = $author -> getElementsByTagName ( 'rpPosName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'delivery' ] = $author -> getElementsByTagName ( 'delPoint' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'phone' ] = $author -> getElementsByTagName ( 'voiceNum' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'email' ] = $author -> getElementsByTagName ( 'eMailAdd' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'postal' ] = $author -> getElementsByTagName ( 'postCode' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'city' ] = $author -> getElementsByTagName ( 'city' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'administrative' ] = $author -> getElementsByTagName ( 'adminArea' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $k ][ 'country' ] = $author -> getElementsByTagName ( 'country' ) -> item ( 0 ) -> nodeValue ;
2012-05-04 08:58:22 +00:00
@ $this -> author [ $k ][ 'role' ] = $author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue ;
2010-01-01 13:05:50 +00:00
}
2010-01-04 04:08:00 +00:00
$cnt = $k + 1 ;
2010-01-01 13:05:50 +00:00
$authors = $this -> dom -> getElementsByTagName ( 'mdContact' );
foreach ( $authors as $j => $author )
{
2010-01-04 04:08:00 +00:00
$this -> author [ $cnt + $j ][ 'individual' ] = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'organisation' ] = $author -> getElementsByTagName ( 'rpOrgName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'position' ] = $author -> getElementsByTagName ( 'rpPosName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'delivery' ] = $author -> getElementsByTagName ( 'delPoint' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'phone' ] = $author -> getElementsByTagName ( 'voiceNum' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'email' ] = $author -> getElementsByTagName ( 'eMailAdd' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'postal' ] = $author -> getElementsByTagName ( 'postCode' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'city' ] = $author -> getElementsByTagName ( 'city' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $j ][ 'administrative' ] = $author -> getElementsByTagName ( 'adminArea' ) -> item ( 0 ) -> nodeValue ;
2014-05-08 13:25:27 +00:00
@ $this -> author [ $cnt + $j ][ 'country' ] = $author -> getElementsByTagName ( 'country' ) -> item ( 0 ) -> nodeValue ;
2010-01-04 04:08:00 +00:00
$this -> author [ $cnt + $j ][ 'role' ] = $author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue ;
2010-01-01 13:05:50 +00:00
}
2010-01-04 04:08:00 +00:00
$cnt += $j + 1 ;
2010-01-01 13:05:50 +00:00
$authors = $this -> dom -> getElementsByTagName ( 'distorCont' );
foreach ( $authors as $m => $author )
{
2010-01-04 04:08:00 +00:00
$this -> author [ $cnt + $m ][ 'individual' ] = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'organisation' ] = $author -> getElementsByTagName ( 'rpOrgName' ) -> item ( 0 ) -> nodeValue ;
2014-05-08 13:25:27 +00:00
@ $this -> author [ $cnt + $m ][ 'position' ] = $author -> getElementsByTagName ( 'rpPosName' ) -> item ( 0 ) -> nodeValue ;
2010-01-04 04:08:00 +00:00
$this -> author [ $cnt + $m ][ 'delivery' ] = $author -> getElementsByTagName ( 'delPoint' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'phone' ] = $author -> getElementsByTagName ( 'voiceNum' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'email' ] = $author -> getElementsByTagName ( 'eMailAdd' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'postal' ] = $author -> getElementsByTagName ( 'postCode' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'city' ] = $author -> getElementsByTagName ( 'city' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'administrative' ] = $author -> getElementsByTagName ( 'adminArea' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'country' ] = $author -> getElementsByTagName ( 'country' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'role' ] = $author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue ;
2010-01-01 13:05:50 +00:00
}
2010-01-07 12:40:54 +00:00
$cnt += $m + 1 ;
$authors = $this -> dom -> getElementsByTagName ( 'idPoC' );
foreach ( $authors as $m => $author )
{
$this -> author [ $cnt + $m ][ 'individual' ] = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'organisation' ] = $author -> getElementsByTagName ( 'rpOrgName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'position' ] = $author -> getElementsByTagName ( 'rpPosName' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'delivery' ] = $author -> getElementsByTagName ( 'delPoint' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'phone' ] = $author -> getElementsByTagName ( 'voiceNum' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'email' ] = $author -> getElementsByTagName ( 'eMailAdd' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'postal' ] = $author -> getElementsByTagName ( 'postCode' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'city' ] = $author -> getElementsByTagName ( 'city' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'administrative' ] = $author -> getElementsByTagName ( 'adminArea' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'country' ] = $author -> getElementsByTagName ( 'country' ) -> item ( 0 ) -> nodeValue ;
$this -> author [ $cnt + $m ][ 'role' ] = $author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue ;
}
2010-01-01 13:05:50 +00:00
/*
2009-03-06 03:20:46 +00:00
foreach ( $authors as $author )
{
if ( $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> hasAttributes () &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " author " )
{
$this -> author = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
break ;
} elseif ( $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> hasAttributes () &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " originator " )
{
$this -> author = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
break ;
} elseif ( $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> hasAttributes () &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " owner " )
{
$this -> author = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
break ;
} elseif ( $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> hasAttributes () &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " processor " )
{
$this -> author = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
break ;
} elseif ( $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> hasAttributes () &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " publisher " )
{
$this -> author = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
break ;
} elseif ( $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> hasAttributes () &&
$author -> getElementsByTagName ( 'RoleCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " resourceProvider " )
{
$this -> author = $author -> getElementsByTagName ( 'rpIndName' ) -> item ( 0 ) -> nodeValue ;
break ;
}
}
2010-01-01 13:05:50 +00:00
*/
2009-03-06 03:20:46 +00:00
//数据类型,在线或离线
$this -> datatype = 0 ;
$onlinesrc = $this -> dom -> getElementsByTagName ( 'onLineSrc' );
foreach ( $onlinesrc as $k => $src )
{
if ( $src -> getElementsByTagName ( 'OnFunctCd' ) -> item ( 0 )
&& $src -> getElementsByTagName ( 'OnFunctCd' ) -> item ( 0 ) -> hasAttributes ()
&& $src -> getElementsByTagName ( 'OnFunctCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " offlineAccess " )
$this -> datatype = 1 ;
2011-12-03 09:05:58 +00:00
{
2009-03-06 03:20:46 +00:00
//在线资源
$this -> onlineresource [ $k ][ 'linkage' ] = $src -> getElementsByTagName ( 'linkage' ) -> item ( 0 ) -> nodeValue ;
if ( $src -> getElementsByTagName ( 'protocol' ) -> item ( 0 )) $this -> onlineresource [ $k ][ 'protocol' ] = $src -> getElementsByTagName ( 'protocol' ) -> item ( 0 ) -> nodeValue ;
if ( $src -> getElementsByTagName ( 'orName' ) -> item ( 0 )) $this -> onlineresource [ $k ][ 'name' ] = $src -> getElementsByTagName ( 'orName' ) -> item ( 0 ) -> nodeValue ;
$this -> onlineresource [ $k ][ 'description' ] = $src -> getElementsByTagName ( 'orDesc' ) -> item ( 0 ) -> nodeValue ;
}
}
$cats = $this -> dom -> getElementsByTagName ( 'tpCat' );
foreach ( $cats as $cat )
{
if ( $cat -> getElementsByTagName ( 'TopicCatCd' ) -> item ( 0 ) -> hasAttributes ())
$this -> tpCat [] = $cat -> getElementsByTagName ( 'TopicCatCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue ;
}
@ $this -> bgFileName = $this -> dom -> getElementsByTagName ( 'bgFileName' ) -> item ( 0 ) -> nodeValue ;
$keywords = $this -> dom -> getElementsByTagName ( 'descKeys' ); //Keywords? which one?
foreach ( $keywords as $keys )
{
if ( $keys -> getElementsByTagName ( 'KeyTypCd' ) -> item ( 0 ) && $keys -> getElementsByTagName ( 'KeyTypCd' ) -> item ( 0 ) -> hasAttributes ())
$k = $keys -> getElementsByTagName ( 'KeyTypCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue ;
if ( is_numeric ( $k ))
$kt = $this -> keytypecode [( int ) $k ];
else
$kt = $k ;
//如果没有找到类别,则默认为主题关键词
if ( ! $kt ) $kt = $this -> keytypecode [ 5 ];
$ks = $keys -> getElementsByTagName ( 'keyword' );
foreach ( $ks as $key )
{
//处理特殊情况:多关键词输入在一起,用一些符号来分割,如分号等。
$pos = strpos ( $key -> nodeValue , ';' );
if ( $pos === false )
$this -> keyword [ $kt ][] = $key -> nodeValue ;
else {
$str = explode ( ';' , $key -> nodeValue );
foreach ( $str as $s ){
$this -> keyword [ $kt ][] = $s ;
}
}
}
}
2013-05-20 06:56:50 +00:00
//resRefDate
2013-05-20 07:23:18 +00:00
$refdates = $this -> dom -> getElementsByTagName ( 'resRefDate' );
2013-05-20 06:56:50 +00:00
foreach ( $refdates as $refdate )
{
if ( $refdate -> getElementsByTagName ( 'DateTypCd' ) -> item ( 0 ) && $refdate -> getElementsByTagName ( 'DateTypCd' ) -> item ( 0 ) -> hasAttributes () && $refdate -> getElementsByTagName ( 'DateTypCd' ) -> item ( 0 ) -> attributes -> getNamedItem ( 'value' ) -> nodeValue == " publication " )
{
2013-05-20 07:23:18 +00:00
$this -> refDate = $refdate -> getElementsByTagName ( 'refDate' ) -> item ( 0 ) -> nodeValue ;
2013-05-20 06:56:50 +00:00
}
}
2009-03-06 03:20:46 +00:00
//in ISO 19115 draft.
2009-12-17 14:08:14 +00:00
$ds = $this -> dom -> getElementsByTagName ( 'datasetSeries' );
2009-03-06 03:20:46 +00:00
foreach ( $ds as $k => $dataset )
{
$this -> datasetSeries [ $k ][ 'seriesName' ] = $dataset -> getElementsByTagName ( 'seriesName' ) -> item ( 0 ) -> nodeValue ;
2014-05-08 13:25:27 +00:00
@ $this -> datasetSeries [ $k ][ 'issId' ] = $dataset -> getElementsByTagName ( 'issId' ) -> item ( 0 ) -> nodeValue ;
@ $this -> datasetSeries [ $k ][ 'artPage' ] = $dataset -> getElementsByTagName ( 'artPage' ) -> item ( 0 ) -> nodeValue ;
2009-03-06 03:20:46 +00:00
}
//unsure which one.
$ds = $this -> dom -> getElementsByTagName ( 'Series' );
foreach ( $ds as $k => $dataset )
{
$this -> datasetSeries [ $k ][ 'seriesName' ] = $dataset -> getElementsByTagName ( 'Name' ) -> item ( 0 ) -> nodeValue ;
$this -> datasetSeries [ $k ][ 'issId' ] = $dataset -> getElementsByTagName ( 'issId' ) -> item ( 0 ) -> nodeValue ;
$this -> datasetSeries [ $k ][ 'artPage' ] = $dataset -> getElementsByTagName ( 'artPage' ) -> item ( 0 ) -> nodeValue ;
}
//可能只适用于ESRI ARCCATELOG产生的元数据
$extent = $this -> dom -> getElementsByTagName ( 'geoBox' );
foreach ( $extent as $geo )
{
$this -> geoBox [ 'w' ] = $geo -> getElementsByTagName ( 'westBL' ) -> item ( 0 ) -> nodeValue ;
$this -> geoBox [ 's' ] = $geo -> getElementsByTagName ( 'southBL' ) -> item ( 0 ) -> nodeValue ;
$this -> geoBox [ 'e' ] = $geo -> getElementsByTagName ( 'eastBL' ) -> item ( 0 ) -> nodeValue ;
$this -> geoBox [ 'n' ] = $geo -> getElementsByTagName ( 'northBL' ) -> item ( 0 ) -> nodeValue ;
}
//提取ESRI格式中的UUID
if ( empty ( $this -> uuid ))
{
@ $this -> uuid = $this -> dom -> getElementsByTagName ( 'MetaID' ) -> item ( 0 ) -> nodeValue ;
//剔除前后大括号
$this -> uuid = trim ( $this -> uuid , '{' );
$this -> uuid = trim ( $this -> uuid , '}' );
}
//根据mdFileID来判断uuid
//如果mdFileID为uuid的组织形式, 则进行提取
2012-06-12 10:21:13 +00:00
if ( strlen ( trim ( $this -> mdFileID )) == 36 && empty ( $this -> uuid ))
$this -> uuid = trim ( $this -> mdFileID );
2009-03-06 03:20:46 +00:00
//仍然没有UUID信息, 则创建一个
if ( empty ( $this -> uuid ))
{
$this -> uuid = new uuid ();
$this -> uuid = $this -> uuid -> toString ();
//反馈回XML文件
$mdfile = $this -> dom -> getElementsByTagName ( 'mdFileID' );
if ( $mdfile -> length > 0 ) {
$this -> dom -> getElementsByTagName ( 'mdFileID' ) -> item ( 0 ) -> nodeValue = $this -> uuid ;
} else {
$mdfile = $this -> dom -> createElement ( 'mdFileID' , $this -> uuid );
$this -> dom -> getElementsByTagName ( 'Metadata' ) -> item ( 0 ) -> appendChild ( $mdfile );
}
}
//提取时间信息
$tm_period = $this -> dom -> getElementsByTagName ( 'TM_Period' );
foreach ( $tm_period as $period )
{
$this -> timebegin = $period -> getElementsByTagName ( 'begin' ) -> item ( 0 ) -> nodeValue ;
$this -> timeend = $period -> getElementsByTagName ( 'end' ) -> item ( 0 ) -> nodeValue ;
}
2010-01-14 05:10:52 +00:00
$tm_day = $this -> dom -> getElementsByTagName ( 'TM_CalDate' );
foreach ( $tm_day as $day )
{
$this -> timebegin = $day -> getElementsByTagName ( 'calDate' ) -> item ( 0 ) -> nodeValue ;
}
2009-03-06 03:20:46 +00:00
//Todo:处理缩略图,限制为一个。
//$thumb=$this->dom->getElementsByTagName('Thumbnail');
$xpath = new DOMXPath ( $this -> dom );
$query = '//metadata/Binary/Thumbnail/Data' ; //should be Metadata
$entries = $xpath -> query ( $query );
if ( $entries -> length > 0 )
$this -> thumbnail = $entries -> item ( 0 ) -> nodeValue ;
else {
$query = '//Metadata/Binary/Thumbnail/Data' ;
$entries = $xpath -> query ( $query );
@ $this -> thumbnail = $entries -> item ( 0 ) -> nodeValue ;
}
//如果是从GEONETWORK获取, 判断是否已有缩略图, 获取最小的缩略图
$graphs = $this -> dom -> getElementsByTagName ( 'graphOver' );
foreach ( $graphs as $g )
{
if ( $g -> getElementsByTagName ( 'bgFileDesc' ) -> item ( 0 ) -> nodeValue == 'thumbnail' ) {
$this -> graph [ 'filename' ] = $g -> getElementsByTagName ( 'bgFileName' ) -> item ( 0 ) -> nodeValue ;
$this -> graph [ 'filedesc' ] = 'thumbnail' ;
$this -> graph [ 'filetype' ] = $g -> getElementsByTagName ( 'bgFileType' ) -> item ( 0 ) -> nodeValue ;
}
}
}
}
?>