2011-11-07 06:22:51 +00:00
< ? php
class ServiceController extends Zend_Controller_Action
{
private $limit = 10 ;
function __call ( $id , $arguments )
{
$this -> _helper -> viewRenderer -> setNoRender ();
$this -> _helper -> layout -> disableLayout ();
}
function preDispatch ()
{
$this -> db = Zend_Registry :: get ( 'db' );
2011-11-07 13:23:40 +00:00
$this -> config = Zend_Registry :: get ( 'config' );
2011-11-07 06:22:51 +00:00
$this -> messenger = $this -> _helper -> getHelper ( 'FlashMessenger' );
$this -> view -> messages = $this -> messenger -> getMessages ();
}
/*
* 返回XML源文件
*/
function xmlAction ()
{
$uuid = $this -> _request -> getParam ( 'uuid' );
$row = $this -> db -> fetchRow ( " select xml.data from xml left join metadata on xml.id=metadata.id where metadata.uuid=? " , array ( $uuid ));
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$this -> getResponse () -> setHeader ( 'Content-Type' , 'text/xml' )
-> setBody ( $row [ 'data' ]);
}
/*
* 查看数据缩略图
*/
function thumbAction ()
{
$id = ( int ) $this -> _request -> getParam ( 'id' );
2011-10-26 09:27:11 +00:00
if ( empty ( $id )) {
$uuid = $this -> _request -> getParam ( 'uuid' );
if ( empty ( $uuid )) $this -> _redirect ( '/data' );
2011-11-02 14:07:49 +00:00
$where = $this -> db -> quoteInto ( 'm.uuid = ?' , $uuid );
2011-10-26 09:27:11 +00:00
} else {
2011-11-02 14:07:49 +00:00
$where = $this -> db -> quoteInto ( 'm.id = ?' , $id );
2011-11-07 06:22:51 +00:00
}
2011-11-02 14:07:49 +00:00
$sql = " select t.* from thumbnail t left join metadata m on t.id=m.id where " . $where ;
2011-10-26 09:27:11 +00:00
$thumb = $this -> db -> fetchRow ( $sql );
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
if ( empty ( $thumb [ 'data' ])) {
header ( " Content-Type:image/png " );
header ( " Content-Length: " . filesize ( " images/nothumb.png " ));
$file = fopen ( " images/nothumb.png " , 'r' );
fpassthru ( $file );
exit ;
} else {
header ( " Content-Type:image/ " . $thumb [ 'filetype' ]);
print base64_decode ( $thumb [ 'data' ]);
2011-11-07 06:22:51 +00:00
}
}
/*
* 查看数据缩略大图
*/
function bigthumbAction ()
{
$id = ( int ) $this -> _request -> getParam ( 'id' );
2011-10-28 09:40:00 +00:00
if ( empty ( $id )) {
$uuid = $this -> _request -> getParam ( 'uuid' );
if ( empty ( $uuid )) $this -> _redirect ( '/data' );
$where = $this -> db -> quoteInto ( 'm.uuid = ?' , $uuid );
} else {
$where = $this -> db -> quoteInto ( 'm.id = ?' , $id );
2011-11-07 06:22:51 +00:00
}
2011-10-28 09:40:00 +00:00
$sql = " select g.id as gid,t.filename,t.filetype from geonetworkmetadata g left join metadata m on g.uuid=m.uuid left join thumbnail t on t.id=m.id where " . $where ;
$thumb = $this -> db -> fetchRow ( $sql );
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
if ( empty ( $thumb [ 'filename' ])) {
header ( " Content-Type:image/png " );
header ( " Content-Length: " . filesize ( " images/nothumb.png " ));
$file = fopen ( " images/nothumb.png " , 'r' );
fpassthru ( $file );
exit ;
2011-11-07 06:22:51 +00:00
} else {
2011-11-07 13:23:40 +00:00
$url = $this -> config -> bigthumb -> path . sprintf ( '%05d' , floor (( $thumb [ 'gid' ] + 0.1 ) / 100 ) * 100 ) . '-' . sprintf ( '%05d' , ceil (( $thumb [ 'gid' ] + 0.1 ) / 100 ) * 100 - 1 ) . " / " . $thumb [ 'gid' ];
2011-10-28 09:40:00 +00:00
$url .= '/public/' . str_replace ( '_s.' , '.' , $thumb [ 'filename' ]);
header ( " Content-Type:image/ " . $thumb [ 'filetype' ]);
$file = fopen ( $url , 'r' );
fpassthru ( $file );
exit ;
2011-11-07 06:22:51 +00:00
}
}
/*
* 搜索 , no page , json output
*/
function searchAction ()
{
$this -> view -> addHelperPath ( 'helper' , 'Zend_View_Helper_' );
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
//$page=(int)$this->_request->getParam('page');
//if (empty($page)) $page=1;
//$offset=$this->limit*($page-1);
$key = $this -> _request -> getParam ( 'q' );
$n = ( int ) $this -> _request -> getParam ( 'n' );
$s = ( int ) $this -> _request -> getParam ( 's' );
$e = ( int ) $this -> _request -> getParam ( 'e' );
$w = ( int ) $this -> _request -> getParam ( 'w' );
if ( ! ( empty ( $n ) && empty ( $key ))) {
if ( empty ( $n )) $n = 90 ;
if ( empty ( $s )) $s =- 90 ;
if ( empty ( $e )) $e = 180 ;
if ( empty ( $w )) $w =- 180 ;
//$start=$this->_request->getParam('start');
//$end=$this->_request->getParam('end');
$sql = " select id,title,uuid,description,filesize,fileformat from metadata where east<? and west>? and north<? and south>? " ;
if ( ! empty ( $key )) {
$sql .= " and (title ilike ? or description ilike ?) " ;
$sql .= " order by title " ;
$rows = $this -> db -> fetchAll ( $sql , array ( $e , $w , $n , $s , '%' . $key . '%' , '%' . $key . '%' ));
} else {
$sql .= " order by title " ;
$rows = $this -> db -> fetchAll ( $sql , array ( $e , $w , $n , $s ));
}
$this -> _helper -> json ( $rows );
}
}
/*
* 产生geojson数据
*/
function jsonAction ()
{
$md = new MetadataTable ();
$db = $md -> getAdapter ();
$id = ( int ) $this -> _request -> getParam ( 'id' );
$where = '' ;
if ( ! empty ( $id )) { $where = ' where id=' . $id ; }
$sql = 'select id,uuid,west,south,north,east,title from metadata' . $where ;
$state = $db -> query ( $sql );
$rows = $state -> fetchAll ();
$geomd = new GeoMetaData ();
foreach ( $rows as $row ){
if ( $id )
$box = new GeoBox ( $row [ 'west' ], $row [ 'south' ], $row [ 'east' ], $row [ 'north' ]);
else
$box = new GeoBoxLine ( $row [ 'west' ], $row [ 'south' ], $row [ 'east' ], $row [ 'north' ]);
$feature = new Geofeature ();
$feature -> id = $row [ 'id' ];
$feature -> addProperties ( 'title' , $row [ 'title' ]);
$feature -> addProperties ( 'uuid' , $row [ 'uuid' ]);
$feature -> addProperties ( 'id' , $row [ 'id' ]);
$feature -> geometry = $box ;
$geomd -> addFeature ( $feature );
}
$this -> _helper -> json ( $geomd );
}
function detailAction ()
{
$id = ( int ) $this -> _request -> getParam ( 'id' );
$xml = new XmlTable ();
$db = $xml -> getAdapter ();
$where = $db -> quoteInto ( 'id=?' , $id );
$order = 'id desc' ;
$row = $xml -> fetchRow ( $where , $order );
// Load the XML source
$xml = new DOMDocument ;
$xml -> loadXML ( $row -> data );
$xsl = new DOMDocument ;
2011-11-07 13:23:40 +00:00
$xsl -> load ( $this -> config -> westdc -> xsl );
2011-11-07 06:22:51 +00:00
// Configure the transformer
$proc = new XSLTProcessor ;
$proc -> importStyleSheet ( $xsl ); // attach the xsl rules
$this -> view -> xml = $proc -> transformToXML ( $xml );
//$this->_helper->layout->disableLayout();
//$this->_helper->viewRenderer->setNoRender();
//$this->getResponse()->setHeader('Content-Type', 'text/html')
// ->setBody($proc->transformToXML($xml));
}
function feedAction ()
{
$feedArray = array (
'title' => '中国西部环境与生态科学数据中心' ,
'link' => 'http://' . $_SERVER [ 'SERVER_NAME' ] . '/data/feed' ,
'description' => '共享西部计划产生的数据' ,
'language' => 'zh-CN' ,
'charset' => 'utf-8' ,
'published' => time (),
//'generator' => 'Zend Framework Zend_Feed',
'entries' => array ()
);
$sql = " select * from metadata order by ts_created desc " ;
$rs = $this -> db -> fetchAll ( $sql );
$feedArray [ 'published' ] = strtotime ( $rs [ 0 ][ 'ts_created' ]);
foreach ( $rs as $r )
{
$feedArray [ 'entries' ][] = array (
'title' => $r [ 'title' ],
'link' => 'http://' . $_SERVER [ 'SERVER_NAME' ] . '/data/' . $r [ 'uuid' ],
'guid' => 'http://' . $_SERVER [ 'SERVER_NAME' ] . '/data/' . $r [ 'uuid' ],
//'content'=>$r['description'],
'description' => $r [ 'description' ],
'lastUpdate' => strtotime ( $r [ 'ts_created' ])
);
}
$feed = Zend_Feed :: importArray ( $feedArray , 'rss' );
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$feed -> send ();
}
public function pingbackAction ()
{
$this -> _helper -> ViewRenderer -> setNoRender ();
$this -> _helper -> layout -> disableLayout ();
$server = new Zend_XmlRpc_Server ();
$server -> setClass ( 'PingbackRpc' , 'pingback' );
echo $server -> handle ();
}
public function pingtestAction ()
{
$this -> _helper -> ViewRenderer -> setNoRender ();
$this -> _helper -> layout -> disableLayout ();
$client = new Zend_XmlRpc_Client ( 'http://test.westgis.ac.cn/data/pingback' );
$arg1 = 'http://wlx.westgis.ac.cn/567/' ;
$arg2 = 'http://test.westgis.ac.cn/data/487591d0-d437-4114-b810-cbef7c4ee4b2' ;
//$result = $client->call('pingback.ping', array($arg1, $arg2));
$test = $client -> getProxy ( 'pingback' );
$test -> ping ( $arg1 , $arg2 );
//var_dump($result);
}
public function outputAction ()
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$sql = " select title,datatype,filesize,id from metadata " ;
$md = $this -> db -> fetchAll ( $sql );
foreach ( $md as $m )
{
print $m [ " title " ] . " , " ;
print ( $m [ " datatype " ] ? " 内部 " : " 公开 " ) . " , " ;
print ( $m [ " filesize " ] == 1 ? " " : $m [ " filesize " ]) . " , " ;
$sql1 = " select keyword from keyword where id= " . $m [ " id " ] . " and keytype='place' " ;
$kd = $this -> db -> fetchAll ( $sql1 );
foreach ( $kd as $p ) print $p [ " keyword " ] . " " ;
print " , " ;
$sql1 = " select keyword from keyword where id= " . $m [ " id " ] . " and keytype='temporal' " ;
$kd = $this -> db -> fetchAll ( $sql1 );
foreach ( $kd as $p ) print $p [ " keyword " ] . " " ;
print " , " ;
print " <br> " ;
}
}
2011-11-03 02:37:24 +00:00
/*
* 转换元数据为WORD DOC格式
*/
public function docAction ()
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
$review = $this -> _request -> getParam ( 'review' );
if ( ! empty ( $uuid ))
{
$sql = " select x.data,m.title,m.description,g.id,m.projection from xml x left join metadata m on m.id=x.id left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid= " . $this -> db -> quote ( $uuid );
$row = $this -> db -> fetchRow ( $sql );
$sql = " select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? " ;
$sql = $this -> db -> quoteInto ( $sql , $uuid );
$ref = $this -> db -> fetchAll ( $sql );
$reference = '<ol>' ;
foreach ( $ref as $refer )
{
$reference .= '<li>' . $refer [ 'reference' ] . '</li>' ;
}
$reference .= '</ol>' ;
if ( is_numeric ( $row [ 'projection' ]))
{
$sql = " select proj4text from spatial_ref_sys where auth_srid=? " ;
$rs = $this -> db -> fetchRow ( $sql , array ( $row [ 'projection' ]));
if ( $rs ) $projection = $rs [ 'proj4text' ];
}
if ( empty ( $projection )) $projection = $row [ 'projection' ];
} else
$projection = '' ;
$dom = new DOMDocument ();
$dom -> loadXML ( $row [ 'data' ]);
//提前对表格进行预处理
$wiki = new WikiFormat ();
$abs = $wiki -> parseTable ( $this -> view -> escape ( $row [ " description " ]));
//处理外部链接
$abs = preg_replace ( '/\[\s*(http:\/\/.+?)\s+(.*?)\]/m' , '<a href="$1">$2</a>' , $abs );
$abs = str_replace ( array ( " \r \n " , " \n " , " \r " ), '</p><p>' , $abs );
$abs = str_replace ( " ' " , " ' " , $abs ); //not needed?
$id = $row [ 'id' ];
$thumburl = sprintf ( '%05d' , floor (( $id + 0.1 ) / 100 ) * 100 ) . '-' . sprintf ( '%05d' , ceil (( $id + 0.1 ) / 100 ) * 100 - 1 ) . " / " . $id ;
$xslt = new XSLTProcessor ();
$xslt -> registerPHPFunctions ();
$xslt -> setParameter ( '' , 'thumburl' , $thumburl );
$xslt -> setParameter ( '' , 'abstract' , $abs );
$xslt -> setParameter ( '' , 'projection' , $projection );
$xslt -> setParameter ( '' , 'reference' , $reference );
$XSL = new DOMDocument ();
$XSL -> load ( '../data/doc.xsl' , LIBXML_NOCDATA );
$xslt -> importStylesheet ( $XSL );
$content = ' <! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN " >
< html >< head >< meta http - equiv = " Content-Type " content = " text/html; charset=UTF-8 " > ' ;
$content .= '<title>' . $row [ 'title' ] . '</title>' ;
$content .= ' < style >
body { MARGIN - RIGHT : auto ; MARGIN - LEFT : auto ; font - size : 14 px ; line - height : 22 px ; font - family : 宋体 , Arial ;}
span { font - size : 14 px ;}
div { clear : both ; margin : 0 auto ; width : 100 % ; vertical - align : baseline ;}
#uuid{text-align: right;}
h3 { font - size : 18 px ;}
img { border : 0 none ;}
a , a : visited { color : Blue ; text - decoration : none ;}
a : hover { text - decoration : underline ;}
ul { list - style : none ; margin : 0 ;}
ul li { list - style : none ;}
#etitle{font-size:16px;margin-left:10px;}
span { font - weight : bolder ;}
#content{padding:5px 0 10px 0;border:1px solid #BF5008;}
#divFooter {background-color:#BF5008;color:White;font-size:12px;padding:5px 15px;}
#divFooter a:link, #divFooter a:visited, #divFooter a:active {color:White;font-family:Arial,Serif;text-decoration:none;}
</ style >
</ head >
< body > ' ;
$content .= $xslt -> transformToXML ( $dom );
if ( $review == 1 ) $content .= file_get_contents ( '../data/review-table.htm' , true );
$content .= " </body></html> " ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/vnd.ms-doc' )
-> setHeader ( 'Content-Disposition' , 'attachment; filename="' . $row [ 'title' ] . '.doc"' )
-> setHeader ( 'Content-Length' , strlen ( $content ))
-> setHeader ( 'Content-Type' , 'application/force-download' )
-> setHeader ( 'Content-Type' , 'application/download' )
-> setHeader ( 'Content-Description' , 'File Transfer' )
-> setHeader ( 'Content-Transfer-Encoding' , 'binary' )
-> setHeader ( 'Expires' , 0 )
-> setHeader ( 'Cache-Control' , 'must-revalidate, post-check=0, pre-check=0' )
-> setHeader ( 'Pragma' , 'public' )
-> setBody ( $content );
2011-11-07 06:22:51 +00:00
}
2011-11-02 14:07:49 +00:00
/*
* 转换元数据为PDF格式
*/
public function pdfAction ()
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
2011-11-07 06:22:51 +00:00
$review = $this -> _request -> getParam ( 'review' );
2011-11-02 14:07:49 +00:00
error_reporting ( 1 );
if ( ! empty ( $uuid ))
{
2011-11-07 06:22:51 +00:00
$sql = " select x.data,m.title,m.citation,m.suppinfo,m.doi,m.filesize,m.fileformat,m.south,m.east,m.west,m.north,m.timebegin,m.timeend,m.title_en,m.uuid,m.description,g.id,m.projection,t.filetype,
cc . name as category , cc . name_zh as category_zh
from xml x left join metadata m on m . id = x . id left join thumbnail t on x . id = t . id
left join category c on c . id = m . id left join categorycode cc on c . code = cc . code
2011-11-02 14:07:49 +00:00
left join geonetworkmetadata g on g . uuid = m . uuid where m . uuid = " . $this->db ->quote( $uuid );
$row = $this -> db -> fetchRow ( $sql );
$sql = " select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? " ;
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$ref = $this -> db -> fetchAll ( $sql );
2011-11-02 14:07:49 +00:00
$reference = " " ;
foreach ( $ref as $k => $refer )
{
$reference .= ( $k + 1 ) . '. ' . str_replace ( array ( " \r \n " , " \n " , " \r " ), '' , $refer [ 'reference' ]) . " \r \n " ;
2011-11-07 06:22:51 +00:00
}
$row [ 'reference' ] = $reference ;
$sql = " select u.uselimit from mdlimit ml left join metadata m on ml.uuid=m.uuid left join uselimit u on ml.lid=u.id where m.uuid=? " ;
2011-11-02 14:07:49 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$limits = $this -> db -> fetchAll ( $sql );
2011-11-02 14:07:49 +00:00
$uselimits = " " ;
foreach ( $limits as $k => $limit )
{
2011-11-07 06:22:51 +00:00
//$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
2011-11-02 14:07:49 +00:00
$uselimits .= ( $k + 1 ) . '. ' . str_replace ( array ( " \r \n " , " \n " , " \r " ), '' , $limit [ 'uselimit' ]) . " \r \n " ;
2011-11-07 06:22:51 +00:00
}
$row [ 'uselimits' ] = $uselimits ;
$sql = " select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=? " ;
2011-11-02 14:07:49 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$row [ 'resources' ] = $this -> db -> fetchAll ( $sql );
$sql = " select r.role,s.* from role r left join responsible s on r.resid=s.id left join metadata m on m.uuid=r.uuid where m.uuid=? order by r.role,r.id " ;
2011-11-02 14:07:49 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$row [ 'contacts' ] = $this -> db -> fetchAll ( $sql );
$sql = " select k.keyword, k.keytype from keyword k left join metadata m on k.id=m.id where m.uuid=? order by k.keytype " ;
2011-11-02 14:07:49 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$keys = $this -> db -> fetchAll ( $sql );
$keyword = array ();
foreach ( $keys as $key )
{
@ $keyword [ $key [ 'keytype' ]] .= $key [ 'keyword' ] . ', ' ;
}
2011-11-02 14:07:49 +00:00
$row [ 'keyword' ] = $keyword ;
if ( is_numeric ( $row [ 'projection' ]))
{
$sql = " select proj4text from spatial_ref_sys where auth_srid=? " ;
$rs = $this -> db -> fetchRow ( $sql , array ( $row [ 'projection' ]));
if ( $rs ) $projection = $rs [ 'proj4text' ];
}
if ( ! empty ( $projection )) $row [ 'projection' ] = $projection ;
} else
$projection = '' ;
$dom = new DOMDocument ();
2011-11-07 06:22:51 +00:00
$dom -> loadXML ( $row [ 'data' ]);
2011-11-03 15:32:33 +00:00
$xpath = new DOMXpath ( $dom );
2011-11-07 06:22:51 +00:00
$row [ 'rfdenom' ] =@ $dom -> getElementsByTagName ( 'rfDenom' ) -> item ( 0 ) -> nodeValue ;
$row [ 'resolution' ] =@ $xpath -> query ( '//scaleDist/value/Real' ) -> item ( 0 ) -> nodeValue ;
$row [ 'resolution' ] .=@ $dom -> getElementsByTagName ( 'uomName' ) -> item ( 0 ) -> nodeValue ;
2011-11-04 09:58:43 +00:00
//提前对表格进行预处理
/* $wiki = new WikiFormat ();
2011-11-07 06:22:51 +00:00
$row [ 'description' ] = $wiki -> parseTable ( $row [ " description " ]);
preg_match_all ( '/<table>[\s\S]*?<\/table>/im' , $row [ 'description' ], $tables );
foreach ( $tables as $k => $table )
{
2011-11-07 17:14:34 +00:00
$row [ 'description' ] =@ str_replace ( $tables [ $k ], " \n 【表格内容暂不支持,请访问网站查看,此处请忽略】 \n " , $row [ 'description' ]);
2011-11-07 06:22:51 +00:00
} */
$pdf = new MetadataPDF ();
$pdf -> metadata = $row ;
$pdf -> Draw ();
$pdf -> setTitle ( $row [ 'title' ], true );
$pdf -> setAuthor ( '中国西部环境与生态科学数据中心' , true );
2011-11-02 14:07:49 +00:00
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/pdf' );
2011-11-07 06:22:51 +00:00
//->setHeader('Content-Disposition','inline; filename="'.$row['title'].'.pdf"');
2011-11-02 14:07:49 +00:00
$pdf -> Output ( $row [ 'title' ] . '.pdf' , 'I' );
//die();
2011-11-07 06:22:51 +00:00
}
public function odtAction ()
{
2011-11-03 15:32:33 +00:00
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
2011-11-07 06:22:51 +00:00
$review = $this -> _request -> getParam ( 'review' );
//error_reporting(1);
2011-11-03 15:32:33 +00:00
if ( ! empty ( $uuid ))
{
2011-11-07 06:22:51 +00:00
$sql = " select x.data,m.title,m.citation,m.suppinfo,m.doi,m.filesize,m.fileformat,m.south,m.east,m.west,m.north,m.timebegin,m.timeend,m.title_en,m.uuid,m.description,g.id,m.projection,t.filetype,
cc . name as category , cc . name_zh as category_zh
from xml x left join metadata m on m . id = x . id left join thumbnail t on x . id = t . id
left join category c on c . id = m . id left join categorycode cc on c . code = cc . code
2011-11-03 15:32:33 +00:00
left join geonetworkmetadata g on g . uuid = m . uuid where m . uuid = " . $this->db ->quote( $uuid );
$row = $this -> db -> fetchRow ( $sql );
$sql = " select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? " ;
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$ref = $this -> db -> fetchAll ( $sql );
2011-11-03 15:32:33 +00:00
$reference = " " ;
foreach ( $ref as $k => $refer )
{
$reference .= ( $k + 1 ) . '. ' . str_replace ( array ( " \r \n " , " \n " , " \r " ), '' , $refer [ 'reference' ]) . " \r \n " ;
2011-11-07 06:22:51 +00:00
}
$row [ 'reference' ] = $reference ;
$sql = " select u.uselimit from mdlimit ml left join metadata m on ml.uuid=m.uuid left join uselimit u on ml.lid=u.id where m.uuid=? " ;
2011-11-03 15:32:33 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$limits = $this -> db -> fetchAll ( $sql );
2011-11-03 15:32:33 +00:00
$uselimits = " " ;
foreach ( $limits as $k => $limit )
{
2011-11-07 06:22:51 +00:00
//$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
2011-11-03 15:32:33 +00:00
$uselimits .= ( $k + 1 ) . '. ' . str_replace ( array ( " \r \n " , " \n " , " \r " ), '' , $limit [ 'uselimit' ]) . " \r \n " ;
2011-11-07 06:22:51 +00:00
}
$row [ 'uselimits' ] = $uselimits ;
$sql = " select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=? " ;
2011-11-03 15:32:33 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$res = $this -> db -> fetchAll ( $sql );
$resource = " " ;
foreach ( $res as $k => $r )
{
$resource .= ( $k + 1 ) . " . " . $r [ 'name' ] . ' ' . $r [ 'linkage' ] . " \n " ;
}
$row [ 'resources' ] = $resource ;
$sql = " select r.role,s.* from role r left join responsible s on r.resid=s.id left join metadata m on m.uuid=r.uuid where m.uuid=? order by r.role,r.id " ;
2011-11-03 15:32:33 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$contact = $this -> db -> fetchAll ( $sql );
$contacts = " " ;
$party_zh = array ( 'resourceProvider' => '资源提供者' , 'custodian' => '维护者' , 'owner' => '拥有者' , 'user' => '用户' , 'distributor' => '数据服务联系人' , 'originator' => '创建者' , 'pointOfContact' => '联系人' , 'principalInvestigator' => '数据调查与处理者' , 'processor' => '处理者' , 'publisher' => '元数据发布者' , 'author' => '元数据作者' );
foreach ( $contact as $k => $c )
{
@ $contacts .= ( $k + 1 ) . " . " . $party_zh [ $c [ 'role' ]] . " \n " ;
@ $contacts .= $c [ 'individual' ] . ' 单位:' . $c [ 'organisation' ] . " \n " ;
@ $contacts .= '地址:' . $c [ 'country' ] . ' ' . $c [ 'administractive' ] . ' ' . $c [ 'city' ] . ' ' . $c [ 'delivery' ] . " \n " ;
@ $contacts .= '邮编:' . $c [ 'postal' ] . ' 电话:' . $c [ 'phone' ] . ' 邮件:' . $c [ 'email' ] . " \n \n " ;
}
$row [ 'contacts' ] = $contacts ;
$sql = " select k.keyword, k.keytype from keyword k left join metadata m on k.id=m.id where m.uuid=? order by k.keytype " ;
2011-11-03 15:32:33 +00:00
$sql = $this -> db -> quoteInto ( $sql , $uuid );
2011-11-07 06:22:51 +00:00
$keys = $this -> db -> fetchAll ( $sql );
$keyword = array ();
foreach ( $keys as $key )
{
@ $keyword [ $key [ 'keytype' ]] .= $key [ 'keyword' ] . ', ' ;
}
2011-11-03 15:32:33 +00:00
$row [ 'keyword' ] = $keyword ;
if ( is_numeric ( $row [ 'projection' ]))
{
$sql = " select proj4text from spatial_ref_sys where auth_srid=? " ;
$rs = $this -> db -> fetchRow ( $sql , array ( $row [ 'projection' ]));
if ( $rs ) $projection = $rs [ 'proj4text' ];
}
if ( ! empty ( $projection )) $row [ 'projection' ] = $projection ;
} else
$projection = '' ;
$dom = new DOMDocument ();
2011-11-07 06:22:51 +00:00
$dom -> loadXML ( $row [ 'data' ]);
2011-11-03 15:32:33 +00:00
$xpath = new DOMXpath ( $dom );
2011-11-07 06:22:51 +00:00
$row [ 'rfdenom' ] =@ $dom -> getElementsByTagName ( 'rfDenom' ) -> item ( 0 ) -> nodeValue ;
$row [ 'resolution' ] =@ $xpath -> query ( '//scaleDist/value/Real' ) -> item ( 0 ) -> nodeValue ;
$row [ 'resolution' ] .=@ $dom -> getElementsByTagName ( 'uomName' ) -> item ( 0 ) -> nodeValue ;
2011-11-04 09:58:43 +00:00
//提前对表格进行预处理
$wiki = new WikiFormat ();
2011-11-07 06:22:51 +00:00
$row [ 'description' ] = $wiki -> parseTable ( $row [ " description " ]);
preg_match_all ( '/<table>[\s\S]*?<\/table>/im' , $row [ 'description' ], $tables );
$search = array ();
$replace = array ();
foreach ( $tables as $k => $table )
{
/* $search [] = " <table> " ;
$replace [] = '<table:table table:name="Table 3">' . str_repeat ( '<table:table-column />' , substr_count ( $table [ 0 ], '<th>' ));
$search [] = " <tr> " ;
$replace [] = " <table:table-row> " ;
$search [] = " <td> " ;
$replace [] = " <table:table-cell><text:p> " ;
$search [] = " <th> " ;
$replace [] = " <table:table-cell><text:p> " ;
$search [] = " </td> " ;
$replace [] = " </text:p></table:table-cell> " ;
$search [] = " </th> " ;
$replace [] = " </text:p></table:table-cell> " ;
$search [] = " </tr> " ;
$replace [] = " </table:table-row> " ;
$search [] = " </table> " ;
$replace [] = " </table:table> " ;
$table = str_replace ( $search , $replace , $table [ 0 ]); */
2011-11-07 17:14:34 +00:00
$row [ 'description' ] =@ str_replace ( $tables [ $k ][ 0 ], " \n 【表格内容暂不支持,请访问网站查看,此处请忽略】 \n " , $row [ 'description' ]);
2011-11-07 06:22:51 +00:00
}
require_once ( 'odtphp/library/odf.php' );
$config [ " PATH_TO_TMP " ] = " /tmp/zip " ;
$config [ " ZIP_PROXY " ] = " ZipArchive " ;
$odf = new Odf ( " ../data/metadata-template.odt " , $config );
$odf -> setVars ( 'title' , $row [ 'title' ], true , 'utf-8' );
@ $odf -> setVars ( 'title_en' , $row [ 'title_en' ], true , 'utf-8' );
$odf -> setVars ( 'uuid' , $row [ 'uuid' ], true , 'utf-8' );
$odf -> setVars ( 'datetime' , date ( 'Y-m-d' ));
$odf -> setVars ( 'abstract' , $row [ 'description' ], true , 'utf-8' );
@ $odf -> setVars ( 'theme_keyword' , $row [ 'keyword' ][ 'theme' ], true , 'utf-8' );
@ $odf -> setVars ( 'place_keyword' , $row [ 'keyword' ][ 'place' ], true , 'utf-8' );
@ $odf -> setVars ( 'temporal_keyword' , empty ( $row [ 'keyword' ][ 'temporal' ]) ? '' : $row [ 'keyword' ][ 'temporal' ], true , 'utf-8' );
@ $odf -> setVars ( 'discipline_keyword' , $row [ 'keyword' ][ 'discipline' ], true , 'utf-8' );
@ $odf -> setVars ( 'stratum_keyword' , $row [ 'keyword' ][ 'stratum' ], true , 'utf-8' );
@ $odf -> setVars ( 'category' , $row [ 'category' ] . ' ' . $row [ 'category_zh' ], true , 'utf-8' );
@ $odf -> setVars ( 'rfdenom' , $row [ 'rfdenom' ], true , 'utf-8' );
@ $odf -> setVars ( 'resolution' , $row [ 'resolution' ], true , 'utf-8' );
@ $odf -> setVars ( 'projection' , $row [ 'projection' ], true , 'utf-8' );
@ $odf -> setVars ( 'filesize' , $row [ 'filesize' ], true , 'utf-8' );
@ $odf -> setVars ( 'fileformat' , $row [ 'fileformat' ], true , 'utf-8' );
@ $odf -> setVars ( 'timebegin' , $row [ 'timebegin' ], true , 'utf-8' );
@ $odf -> setVars ( 'timeend' , $row [ 'timeend' ], true , 'utf-8' );
@ $odf -> setVars ( 'citation' , $row [ 'citation' ], true , 'utf-8' );
@ $odf -> setVars ( 'reference' , $row [ 'reference' ], true , 'utf-8' );
@ $odf -> setVars ( 'doi' , $row [ 'doi' ], true , 'utf-8' );
@ $odf -> setVars ( 'suppinfo' , $row [ 'suppinfo' ], true , 'utf-8' );
@ $odf -> setVars ( 'uselimits' , $row [ 'uselimits' ], true , 'utf-8' );
@ $odf -> setVars ( 'resources' , $row [ 'resources' ], true , 'utf-8' );
@ $odf -> setVars ( 'contacts' , $row [ 'contacts' ], true , 'utf-8' );
@ $odf -> setVars ( 'north' , $row [ 'north' ], true , 'utf-8' );
@ $odf -> setVars ( 'south' , $row [ 'south' ], true , 'utf-8' );
@ $odf -> setVars ( 'west' , $row [ 'west' ], true , 'utf-8' );
@ $odf -> setVars ( 'east' , $row [ 'east' ], true , 'utf-8' );
$odf -> setImage ( 'bigthumb' , 'http://test.westgis.ac.cn/service/bigthumb/uuid/' . $row [ 'uuid' ]);
$odf -> setImage ( 'thumb' , 'http://test.westgis.ac.cn/service/thumb/uuid/' . $row [ 'uuid' ]);
$odf -> exportAsAttachedFile ( $row [ 'title' ] . '.odt' );
}
function uploadAction (){
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
try {
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
}
if ( empty ( $userid ) ||! is_numeric ( $userid )){
$msg [ 'error' ] = " 请先登录 " ;
echo Zend_Json :: encode ( $msg );
exit ();
}
$files = new files ();
2011-11-07 13:23:40 +00:00
$msg = $files -> upload ( $this -> config -> upload , $_FILES [ 'Filedata' ], 'reviewatt' );
2011-11-07 06:22:51 +00:00
if ( empty ( $msg [ 'error' ]))
{
$msg [ 'error' ] = " " ;
$filename = $msg [ 'db_path' ];
$filesize = $msg [ 'file_size' ];
$filedesc = $this -> _request -> getParam ( 'filedesc' );
$filetype = $this -> _request -> getParam ( 'dir' );
$realname = $msg [ 'realname' ];
2011-11-25 08:57:46 +00:00
$fileurl = $msg [ 'file_url' ];
2011-11-07 06:22:51 +00:00
$sql = " insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values (' $filename ','reviewatt',' $filedesc ',' $userid ',' $filesize ',' $realname ') RETURNING id " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$att = $sth -> fetch ( PDO :: FETCH_ASSOC );
$msg [ 'attid' ] = $attid = $att [ 'id' ];
2011-11-25 08:57:46 +00:00
include_once ( 'files.php' );
$imgct = files :: getImageType ( $this -> config -> upload . $filename );
if ( ! isset ( $imgct [ 'error' ])) $preview = '<img src="/service/attpreview/id/' . $attid . '" style="display:block;" />' ;
else $preview = " " ;
$msg [ 'html' ] = $preview . $realname . '[已完成]<input type="hidden" name="atts[]" value="' . $attid . '" /><div class="cancel"><a href="javascript:;" id="deletebtn_' . $attid . '"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>' ;
$msg [ 'preview' ] = " /service/attpreview/id/ " . $attid ;
2011-11-07 06:22:51 +00:00
echo Zend_Json :: encode ( $msg );
exit ();
} else {
$msg [ 'error' ] = '附件上传失败:' . $msg [ 'error' ];
@ unlink ( $filename );
echo Zend_Json :: encode ( $msg );
exit ();
}
} catch ( Exception $e ){
$msg [ 'error' ] = " 错误: " . $e -> getMessage ();
echo Zend_Json :: encode ( $msg );
exit ();
}
2011-11-08 06:11:13 +00:00
}
2011-11-25 09:10:20 +00:00
function getattsAction (){
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = $this -> _request -> getParam ( 'id' );
if ( $id != '' )
{
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
$sql = " select att.realname,att.id,att.filename from attachments att
left join mdreviewattach ratt on att . id = ratt . attachid
where ratt . reviewid = $id and att . userid = $userid " ;
$rs = $this -> db -> query ( $sql );
$atts = $rs -> fetchAll ();
include_once ( 'files.php' );
foreach ( $atts as $k => $v )
{
$imgct = files :: getImageType ( $this -> config -> upload . $v [ 'filename' ]);
if ( ! isset ( $imgct [ 'error' ])) $preview = '<img src="/service/attpreview/id/' . $v [ 'id' ] . '" style="display:block;" />' ;
else $preview = " " ;
$atts [ $k ][ 'html' ] = $preview . $v [ 'realname' ] . '[已完成]<input type="hidden" name="atts[]" value="' . $v [ 'id' ] . '" /><div class="cancel"><a href="javascript:;" id="deletebtn_' . $v [ 'id' ] . '"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>' ;
}
echo Zend_Json :: encode ( $atts );
exit ();
} else
{
exit ();
}
} else {
exit ();
}
//不输出错误
} //获取附件
2011-11-08 06:11:13 +00:00
function filelistAction ()
{
$uuid = $this -> _request -> getParam ( 'uuid' );
$sql = " select f.filename,f.id,s.uuid,f.depth from datafile f,dataset s where s.id=f.dsid and s.uuid=? and f.depth=1 and f.filename<>'/uuid.txt' order by f.isdir desc,f.filename " ;
$files = $this -> db -> fetchAll ( $this -> db -> quoteInto ( $sql , $uuid ));
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
echo Zend_Json :: encode ( $files );
}
function subfilelistAction ()
{
$uuid = $this -> _request -> getParam ( 'uuid' );
$subpath = ( int ) $this -> _request -> getParam ( 'subpath' );
$depth = ( int ) $this -> _request -> getParam ( 'depth' );
$depth ++ ;
$sql = " select f.filename,f.id,s.uuid,f.depth from datafile f,dataset s where s.id=f.dsid and s.uuid=? and f.depth= " . $depth . " and f.filename<>'/uuid.txt' and f.filename ilike (select filename from datafile where id= " . $subpath . " )||'%' order by f.isdir desc,f.filename " ;
$files = $this -> db -> fetchAll ( $this -> db -> quoteInto ( $sql , $uuid ));
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
echo Zend_Json :: encode ( $files );
}
2011-11-07 13:23:40 +00:00
/*
* 附件下载
*/
2011-11-08 06:11:13 +00:00
function attachAction ()
2011-11-07 13:23:40 +00:00
{
2011-11-08 06:11:13 +00:00
$zipuuid = $this -> _request -> getParam ( 'zip' );
2011-11-07 13:23:40 +00:00
$id = ( int ) $this -> _request -> getParam ( 'id' );
$this -> _helper -> layout -> disableLayout ();
2011-11-25 08:57:46 +00:00
$this -> _helper -> viewRenderer -> setNoRender ();
2011-11-07 13:23:40 +00:00
if ( ! empty ( $zipuuid ))
{
$sql = $this -> db -> quoteInto ( " select a.*,md.title from mdattach m left join metadata md on m.uuid=md.uuid left join attachments a on m.id=a.id where m.uuid=? order by a.ts_created desc " , $zipuuid );
2011-11-08 06:11:13 +00:00
$atts = $this -> db -> fetchAll ( $sql );
2011-11-07 13:23:40 +00:00
$title = $atts [ 0 ][ 'title' ];
2011-11-08 06:11:13 +00:00
$zip = new ZipArchive ();
$url = tempnam ( $this -> config -> temp -> path , $zipuuid ); //创建临时文件
$last_update = strtotime ( $atts [ 0 ][ 'ts_created' ]);
if ( ! file_exists ( $url ) || ( filemtime ( $fn ) < $last_update ))
2011-11-07 13:23:40 +00:00
{
2011-11-08 06:11:13 +00:00
if ( $zip -> open ( $url , ZIPARCHIVE :: CREATE | ZIPARCHIVE :: OVERWRITE ) !== true )
2011-11-07 13:23:40 +00:00
{
throw new Exception ( " cannot open { $url } for writing. " );
}
$updates = array (); //统计被下载的附件ID
foreach ( $atts as $k => $v )
{
if ( file_exists ( $this -> config -> upload . $v [ 'filename' ])) {
$updates [] = $v [ 'id' ];
$zip -> addFile ( $this -> config -> upload . $v [ 'filename' ], '/' . basename ( $v [ 'realname' ]));
}
}
$zip -> close ();
}
//更新统计
$ids = join ( ',' , $updates );
$sql = " update attachments set downtimes=downtimes+1 where id in ( $ids ) " ;
@ $this -> db -> exec ( $sql );
//输出下载
$content = file_get_contents ( $url );
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/octet-stream' )
-> setHeader ( 'Content-Disposition' , 'attachment; filename="' . basename ( $title ) . '-文档.zip"' )
-> setHeader ( 'Content-Length' , strlen ( $content ))
-> setHeader ( 'Content-Type' , 'application/force-download' )
-> setHeader ( 'Content-Type' , 'application/download' )
-> setHeader ( 'Content-Type' , 'application/zip' )
-> setHeader ( 'Content-Description' , 'File Transfer' )
-> setHeader ( 'Content-Transfer-Encoding' , 'binary' )
-> setHeader ( 'Expires' , 0 )
-> setHeader ( 'Cache-Control' , 'must-revalidate, post-check=0, pre-check=0' )
-> setHeader ( 'Pragma' , 'public' )
-> setBody ( $content );
2011-11-08 06:11:13 +00:00
}
elseif ( $id > 0 )
{
//下载单个附件
2011-11-08 08:57:13 +00:00
$sql = $this -> db -> quoteInto ( " select a.* from attachments a where a.id=? order by a.ts_created desc " , $id );
2011-11-08 06:11:13 +00:00
$atts = $this -> db -> fetchRow ( $sql );
2011-11-07 13:23:40 +00:00
$updates = array (); //统计被下载的附件ID
//更新统计
$sql = " update attachments set downtimes=downtimes+1 where id in ( $id ) " ;
@ $this -> db -> exec ( $sql );
//输出下载
$content = file_get_contents ( $this -> config -> upload . $atts [ 'filename' ]);
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/octet-stream' )
-> setHeader ( 'Content-Disposition' , 'attachment; filename="' . $atts [ 'realname' ] . '"' )
-> setHeader ( 'Content-Length' , strlen ( $content ))
-> setHeader ( 'Content-Type' , 'application/force-download' )
-> setHeader ( 'Content-Type' , 'application/download' )
//->setHeader('Content-Type','application/zip')
-> setHeader ( 'Content-Description' , 'File Transfer' )
-> setHeader ( 'Content-Transfer-Encoding' , 'binary' )
-> setHeader ( 'Expires' , 0 )
-> setHeader ( 'Cache-Control' , 'must-revalidate, post-check=0, pre-check=0' )
-> setHeader ( 'Pragma' , 'public' )
2011-11-08 06:11:13 +00:00
-> setBody ( $content );
2011-11-07 13:23:40 +00:00
}
else
{
throw new Exception ( '发生严重意外!您确认链接正确?' );
}
2011-11-25 08:57:46 +00:00
}
2011-12-01 02:51:54 +00:00
function delreviewattAction (){
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = $this -> _request -> getParam ( 'id' );
$basepath = $this -> view -> config -> upload ;
$info = $this -> getFileinfo ( $id );
$filepath = $basepath . $info [ 'filename' ];
try {
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
$sql = " delete from attachments where id=' $id ' and userid=' $userid ' " ;
if ( $this -> db -> exec ( $sql ) > 0 )
{
@ unlink ( $filepath );
}
}
} catch ( Exception $e ){}
//不输出任何错误
} //删除评审附件
2011-11-25 08:57:46 +00:00
function attpreviewAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = ( int ) $this -> _request -> getParam ( 'id' );
include_once ( 'files.php' );
$info = files :: getOne ( $this -> db , $id );
if ( ! empty ( $info [ 'error' ]))
{
exit ( $info [ 'error' ]);
}
else
{
try {
$filename = $this -> config -> upload . $info [ 'filename' ];
$imgct = files :: getImageType ( $filename );
if ( isset ( $imgct [ 'error' ])) exit ( " Error " );
//var_dump($imgct);exit();
$src = $imgct [ 'creatfunc' ]( $filename );
list ( $width_orig , $height_orig ) = getimagesize ( $filename );
if ( $width_orig > 300 )
{
$width = 300 ;
$ratio = $width_orig / 300 ;
$height = $height_orig / $ratio ;
} else {
$width = $width_orig ;
$height = $height_orig ;
}
// 重置图片尺寸
$image_p = imagecreatetruecolor ( $width , $height );
$white = imagecolorallocate ( $image_p , 255 , 255 , 255 );
imagefilledrectangle ( $image_p , 0 , 0 , $width , $height , $white );
imagecopyresampled ( $image_p , $src , 0 , 0 , 0 , 0 , $width , $height , $width_orig , $height_orig );
header ( " Content-type: image/jpeg " );
imagejpeg ( $image_p );
imagedestroy ( $src );
imagedestroy ( $image_p );
exit ;
} catch ( Exception $e ){
echo $e -> getMessage ();
}
}
2011-11-07 13:23:40 +00:00
2011-11-14 02:30:23 +00:00
}
2011-11-09 02:47:52 +00:00
function mdjsonAction ()
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2011-11-14 02:30:23 +00:00
$num = ( int ) $this -> _request -> getParam ( 'num' );
$source = $this -> _request -> getParam ( 'source' );
if ( empty ( $num )) $num = 3 ;
$sql = " select m.uuid,m.title,m.id,substring(m.description from 0 for 200) as description from normalmetadata m left join thumbnail t on m.id=t.id where " ;
if ( ! empty ( $source ))
$sql .= $this -> db -> quoteInto ( " m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code=?) and " , $source );
2011-11-09 02:47:52 +00:00
$sql .= " length(t.data)>2 order by random() limit $num " ;
2011-11-14 02:30:23 +00:00
$rows = $this -> db -> fetchAll ( $sql );
2011-11-09 02:47:52 +00:00
echo Zend_Json :: encode ( $rows );
2011-11-14 02:30:23 +00:00
}
function googlesearchAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$q = $this -> _request -> getParam ( 'q' );
$rez = $this -> google_search_api ( array (
'q' => $q , // 查询内容
'key' => $this -> config -> google -> maps -> api ,
'userip' => $_SERVER [ 'REMOTE_ADDR' ],
2011-11-22 03:12:15 +00:00
'rsz' => 5
2011-11-14 02:30:23 +00:00
));
print_r ( $rez );
exit ();
}
function google_search_api ( $args , $referer = 'http://westdc.westgis.ac.cn/' , $endpoint = 'web' ){
$url = " http://ajax.googleapis.com/ajax/services/search/ " . $endpoint ;
if ( ! array_key_exists ( 'v' , $args ) )
$args [ 'v' ] = '1.0' ;
$url .= '?' . http_build_query ( $args , '' , '&' );
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_REFERER , $referer );
$body = curl_exec ( $ch );
curl_close ( $ch );
return $body ;
2011-11-22 03:12:15 +00:00
} // google 搜索
function bingsearchAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$q = $this -> _request -> getParam ( 'q' );
$rez = $this -> bing_search ( $q );
print_r ( $rez );
exit ();
}
function bing_search ( $keyword , $referer = 'http://westdc.westgis.ac.cn/' ){
$keyword = urlencode ( $keyword );
$url = " http://api.bing.net/json.aspx?AppId= " . $this -> config -> bing -> api
. " &Query= " . $keyword
. " &Sources=Web "
. " &Version=2.0 "
2011-11-28 14:57:40 +00:00
. " &Market=zh-cn "
2011-11-22 03:12:15 +00:00
. " &Adult=Moderate "
2011-11-28 14:57:40 +00:00
//."&Options=EnableHighlighting"
2011-11-22 03:12:15 +00:00
. " &Web.Count=5 "
. " &Web.Offset=0 "
. " &Web.Options=DisableHostCollapsing+DisableQueryAlterations " ;
//&JsonType=callback&JsonCallback=SearchCompleted
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_REFERER , $referer );
$body = curl_exec ( $ch );
curl_close ( $ch );
return $body ;
} //bing 搜索
function cnkisearchAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$q = $this -> _request -> getParam ( 'q' );
$rez = $this -> cnki_search ( $q );
print_r ( $rez );
exit ();
}
function cnki_search ( $keyword , $referer = 'http://westdc.westgis.ac.cn/' ){
$keyword = urlencode ( $keyword );
$url = " http://search.cnki.net/search.aspx?q= $keyword " ;
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_REFERER , $referer );
$body = curl_exec ( $ch );
curl_close ( $ch );
$rev = array ();
2011-12-01 02:51:54 +00:00
$max = 5 ;
$error = '' ;
if ( preg_match_all ( " #<a \ sclass= \" acticle \" href= \" (.+?) \" .*?>(.+?)< \ /a>#im " , $body , $matchs , PREG_PATTERN_ORDER ))
{
foreach ( $matchs [ 2 ] as $k => $v ){
if ( $k < $max ) $rev [ $k ][ 'title' ] = $v ;
}
foreach ( $matchs [ 1 ] as $k => $v ){
if ( $k < $max ) $rev [ $k ][ 'url' ] = $v ;
}
} else {
$error = " 无搜索结果 " ;
}
if ( preg_match_all ( " #<span class= \" search_result_snap \" >(.+?)< \ /span>#im " , $body , $matchs , PREG_PATTERN_ORDER ))
{
foreach ( $matchs [ 1 ] as $k => $v ){
if ( $k < $max ) $rev [ $k ][ 'content' ] = $v ;
}
}
$response = array ( " result " => $rev , " count " => $max , " morelink " => 'http://search.cnki.net/search.aspx?q=' . $keyword , " error " => $error );
$rev = Zend_Json :: encode ( $response );
return $rev ;
} //cnki 搜索
function scholarsearchAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$q = $this -> _request -> getParam ( 'q' );
$rez = $this -> scholar_search ( $q );
print_r ( $rez );
exit ();
}
function scholar_search ( $keyword , $referer = 'http://westdc.westgis.ac.cn/' ){
$keyword = urlencode ( $keyword );
$url = " http://scholar.google.com/scholar?q= $keyword " ;
2011-12-02 09:32:27 +00:00
$url .= " &hl=en&btnG=搜索&lr= " ;
2011-12-01 02:51:54 +00:00
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_REFERER , $referer );
2011-12-02 09:32:27 +00:00
$html = curl_exec ( $ch );
2011-12-01 02:51:54 +00:00
curl_close ( $ch );
$rev = array ();
$max = 5 ;
2011-11-28 14:43:37 +00:00
$error = '' ;
2011-12-02 09:32:27 +00:00
if ( preg_match_all ( " #<h3>(.+?)< \ /h3>#im " , $html , $matchs , PREG_PATTERN_ORDER ))
2011-11-22 03:12:15 +00:00
{
2011-12-02 09:32:27 +00:00
foreach ( $matchs [ 0 ] as $k => $v ){
if ( $k < $max ) $rev [ $k ][ 'title' ] = utf8_encode ( $v );
2011-11-22 03:12:15 +00:00
}
2011-11-28 02:41:26 +00:00
} else {
$error = " 无搜索结果 " ;
2011-11-22 03:12:15 +00:00
}
2011-12-03 05:48:15 +00:00
if ( preg_match_all ( " !<span class=gs_a>(.*?)< \ /span>!im " , $html , $matchs , PREG_PATTERN_ORDER ))
2011-11-22 03:12:15 +00:00
{
2011-12-02 09:32:27 +00:00
foreach ( $matchs [ 0 ] as $k => $v ){
if ( $k < $max ) $rev [ $k ][ 'content' ] = utf8_encode ( $v );
2011-11-22 03:12:15 +00:00
}
}
2011-12-02 09:32:27 +00:00
//var_dump($rev);
//exit();
$response = array ( " result " => $rev , " count " => $max , " morelink " => 'http://scholar.google.com/scholar?hl=zh-CN&btnG=搜索&lr=&q=' . $keyword , " error " => $error );
2011-11-22 03:12:15 +00:00
$rev = Zend_Json :: encode ( $response );
return $rev ;
2011-12-02 09:32:27 +00:00
} //scholar 搜索
function recommendAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
$sql = " select d.uuid,count(distinct(d.userid)) as downtimes,m.title from dataorder d left join metadata m on d.uuid=m.uuid where d.userid in (
select distinct ( userid ) from dataorder where uuid = ? and status in ( 0 , 5 )
) and d . uuid <> ? and length ( m . title ) > 2 group by d . uuid , m . title order by count ( distinct ( d . userid )) desc " ;
$rows = $this -> db -> fetchAll ( $sql , array ( $uuid , $uuid ));
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
2011-12-03 07:06:23 +00:00
$paginator -> setItemCountPerPage ( 5 );
2011-12-02 09:32:27 +00:00
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'data/pagination_recommend.phtml' );
if ( $paginator )
2011-12-05 07:12:52 +00:00
{
2011-12-03 07:06:23 +00:00
echo '<div class="paginator">' . $paginator . '</div>' ;
2011-12-02 09:32:27 +00:00
foreach ( $paginator as $c )
{
2011-12-03 07:06:23 +00:00
print '<li><a target="_blank" href="/data/' . $c [ 'uuid' ] . '"><span class="title">' . $c [ 'title' ] . '</span><img src="/service/thumb/uuid/' . $c [ 'uuid' ] . '" alt="' . $c [ 'title' ] . '" title="' . $c [ 'title' ] . '(推荐指数:' . $c [ 'downtimes' ] . ') "/></a></li>' ;
}
2011-12-05 07:12:52 +00:00
} else {
echo '<p>暂无相关数据</p>' ;
2011-12-02 09:32:27 +00:00
}
} //相关下载
function relatedAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
$sql = " select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid
left join thumbnail t on t . id = m . id left join geonetworkmetadata g on m . uuid = g . uuid where " ;
$where = $this -> db -> quoteInto ( 'm.uuid = ?' , $uuid );
$sql .= $where ;
$row = $this -> db -> fetchRow ( $sql );
if ( ! $row ) exit ( " 读取信息错误 " );
$id = $row [ 'id' ];
//相关元数据,根据同名关键词实现
2011-12-03 12:11:58 +00:00
$sql = " select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where length(md.title)>2 and kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>? " ;
2011-12-02 09:32:27 +00:00
$rows = $this -> db -> fetchAll ( $sql , array ( $id , $id ));
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'data/pagination_related.phtml' );
if ( $paginator )
{
foreach ( $paginator as $c )
{
print '<li><a target="_blank" href="/data/' . $c [ 'uuid' ] . '">' . $c [ 'title' ] . " </a></li> \r \n " ;
}
echo '<div class="paginator">' . $paginator . '</div>' ;
}
} //相关数据
function literatureAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
$sql = " select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid
left join thumbnail t on t . id = m . id left join geonetworkmetadata g on m . uuid = g . uuid where " ;
$where = $this -> db -> quoteInto ( 'm.uuid = ?' , $uuid );
$sql .= $where ;
$row = $this -> db -> fetchRow ( $sql );
if ( ! $row ) exit ( " 读取信息错误 " );
$id = $row [ 'id' ];
$keys = $this -> db -> fetchAll ( " select * from keyword where id=? order by keytype,ts_created " , array ( $id ));
$wheresql = array ();
foreach ( $keys as $k => $v )
{
if ( $v [ 'keytype' ] == " theme " )
$wheresql [] = " a.title like '% " . $v [ 'keyword' ] . " %' " ;
}
$wheresql [] = " 1<>1 " ;
$wheresql = join ( " or " , $wheresql );
$sql = " select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ( $wheresql ) order by a.ts_created desc " ;
$rows = $this -> db -> fetchAll ( $sql );
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'data/pagination_literature.phtml' );
if ( $paginator )
{
foreach ( $paginator as $c )
{
$u = parse_url ( $c [ 'url' ]);
if ( @ $u [ 'host' ] == 'hdl.handle.net' ) $c [ 'url' ] = $this -> config -> seekspace -> handleurl . $u [ 'path' ];
print '<li><a target="_blank" href="' . $c [ 'url' ] . '">' . $c [ 'title' ] . '</a>【' . $c [ 'author' ] . ' ' . $c [ 'publisher' ] . ' ' . $c [ 'ts_issued' ] . " 】</li> " ;
}
echo '<div class="paginator">' . $paginator . '</div>' ;
}
} //相关文献
2011-12-05 07:12:52 +00:00
function refdatalistAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = $this -> _request -> getParam ( 'id' );
$sql = " select md.title,md.uuid from mdref mr
left join metadata md on md . uuid = mr . uuid
where mr . refid = $id " ;
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
print '<ul>' ;
foreach ( $rows as $c )
{
print '<li><a href="/data/' . $c [ 'uuid' ] . '">' . $c [ 'title' ] . '</a></li>' ;
}
print '</ul>' ;
/*
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'review/pagination_refdatalist.phtml' );
if ( $paginator )
{
foreach ( $paginator as $c )
{
print '<li><a href="/data/' . $c [ 'uuid' ] . '">' . $c [ 'title' ] . '</a></li>' ;
}
echo '<div class="paginator">' . $paginator . '</div>' ;
}
*/
}
}