From 36f914df7e68bc1fdeb20ab2ef7da73df7c2e394 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 27 May 2013 08:59:42 +0000 Subject: [PATCH 01/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/ServiceController.php | 2988 +++++++++-------- .../default/views/scripts/data/map.phtml | 282 +- application/models/data/Metadata.php | 37 + 3 files changed, 1742 insertions(+), 1565 deletions(-) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 77723fda..7cff15a4 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1,1481 +1,1507 @@ -_helper->viewRenderer->setNoRender(); - $this->_helper->layout->disableLayout(); - } - - function preDispatch() - { - $this->db=Zend_Registry::get('db'); - $this->view->config = $this->config = Zend_Registry::get('config'); - //$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'); - 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); - } - $sql="select t.* from thumbnail t left join metadata m on t.id=m.id where ".$where; - $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']); - } - } - - /* - * 查看数据缩略大图 - */ - function bigthumbAction() - { - $id = (int)$this->_request->getParam('id'); - 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); - } - $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; - } else { - $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']; - $url.='/public/'.str_replace('_s.','.',$thumb['filename']); - header("Content-Type:image/".$thumb['filetype']); - $file=fopen($url,'r'); - fpassthru($file); - exit; - } - } - /* - * 搜索, 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,substring(description for 400) as description,filesize,fileformat from normalmetadata where east? and north?"; - if (!empty($key)) { - $search=new SimpleSearch($key); - $where=$search->sql_expr(array("title","description")); - $sql.= " and ".$where; - $sql.= " order by title"; - $rows=$this->db->fetchAll($sql,array($e,$w,$n,$s)); - } else { - $sql.= " order by title limit 10"; - $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; - $xsl->load($this->config->westdc->xsl); - // 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 normalmetadata 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 uuid,title,datatype,filesize,id from normalmetadata"; - $md=$this->db->fetchAll($sql); - foreach($md as $m) - { - print $m["uuid"].","; - 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 "
"; - } - - } - - /* - * 转换元数据为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 g.data,m.title,m.description,g.id,m.projection from metadata m left join xml x 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='
    '; - foreach($ref as $refer) - { - $reference.='
  1. '.$refer['reference'].'
  2. '; - } - $reference.='
'; - 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','$2',$abs); - $abs=str_replace(array("\r\n", "\n", "\r"),'

',$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=' -'; - $content.=''.$row['title'].''; - $content.=' - - '; - - $dispostion = 'attachment; filename*="utf8\' \''.urlencode($row['title']).'.doc"'; - - $ua = $_SERVER["HTTP_USER_AGENT"]; - - if (preg_match("/MSIE/", $ua)) { - $dispostion = 'attachment; filename="'.urlencode($row['title']).'.doc"'; - } else if (preg_match("/Firefox/", $ua)) { - //$dispostion; - } else { - $dispostion = 'attachment; filename="'.$row['title'].'.doc"'; - } - - $content.=$xslt->transformToXML($dom); - if ($review==1) $content.=file_get_contents('../data/review-table.htm',true); - $content.=""; - $this->getResponse()->setHeader('Content-Type', 'application/vnd.ms-doc') - ->setHeader('Content-Disposition',$dispostion) - ->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); - } - - /* - * 转换元数据为PDF格式 - */ - public function pdfAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid=$this->_request->getParam('uuid'); - $review=$this->_request->getParam('review'); - error_reporting(1); - if (!empty($uuid)) - { - $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 metadata m left join xml x 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 - 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=""; - foreach($ref as $k=>$refer) - { - $reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n"; - } - $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=?"; - $sql=$this->db->quoteInto($sql,$uuid); - $limits=$this->db->fetchAll($sql); - $uselimits=""; - foreach($limits as $k=>$limit) - { - //$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; - $uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; - } - $row['uselimits']=$uselimits; - $sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?"; - $sql=$this->db->quoteInto($sql,$uuid); - $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"; - $sql=$this->db->quoteInto($sql,$uuid); - $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"; - $sql=$this->db->quoteInto($sql,$uuid); - $keys=$this->db->fetchAll($sql); - $keyword=array(); - foreach($keys as $key) - { - @$keyword[$key['keytype']].=$key['keyword'].','; - } - $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(); - $dom->loadXML($row['data']); - $xpath = new DOMXpath($dom); - $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; - //提前对表格进行预处理 - /*$wiki=new WikiFormat(); - $row['description']=$wiki->parseTable($row["description"]); - preg_match_all('/[\s\S]*?<\/table>/im', $row['description'],$tables); - foreach($tables as $k=>$table) - { - $row['description']=@str_replace($tables[$k],"\n 【表格内容暂不支持,请访问网站查看,此处请忽略】\n",$row['description']); - }*/ - $pdf=new MetadataPDF(); - $pdf->metadata=$row; - $pdf->Draw(); - $pdf->setTitle($row['title'],true); - $pdf->setAuthor('寒区旱区科学数据中心',true); - $this->getResponse()->setHeader('Content-Type', 'application/pdf'); - //->setHeader('Content-Disposition','inline; filename="'.$row['title'].'.pdf"'); - $pdf->Output($row['title'].'.pdf','I'); - //die(); - } - public function odtAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid=$this->_request->getParam('uuid'); - $review=$this->_request->getParam('review'); - //error_reporting(1); - if (!empty($uuid)) - { - $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 - 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=""; - foreach($ref as $k=>$refer) - { - $reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n"; - } - $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=?"; - $sql=$this->db->quoteInto($sql,$uuid); - $limits=$this->db->fetchAll($sql); - $uselimits=""; - foreach($limits as $k=>$limit) - { - //$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; - $uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; - } - $row['uselimits']=$uselimits; - $sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?"; - $sql=$this->db->quoteInto($sql,$uuid); - $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"; - $sql=$this->db->quoteInto($sql,$uuid); - $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"; - $sql=$this->db->quoteInto($sql,$uuid); - $keys=$this->db->fetchAll($sql); - $keyword=array(); - foreach($keys as $key) - { - @$keyword[$key['keytype']].=$key['keyword'].','; - } - $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(); - $dom->loadXML($row['data']); - $xpath = new DOMXpath($dom); - $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; - //提前对表格进行预处理 - $wiki=new WikiFormat(); - $row['description']=$wiki->parseTable($row["description"]); - preg_match_all('/
[\s\S]*?<\/table>/im', $row['description'],$tables); - $search=array(); - $replace=array(); - foreach($tables as $k=>$table) - { - /*$search[]="
"; - $replace[]=''.str_repeat('',substr_count($table[0],'"; - $replace[]=""; - $search[]=""; - $replace[]=""; - $search[]=""; - $replace[]=""; - $search[]="
')); - $search[]="
"; - $replace[]=""; - $search[]=""; - $replace[]=""; - $search[]=""; - $replace[]=""; - $search[]="
"; - $replace[]=""; - $table=str_replace($search,$replace,$table[0]);*/ - $row['description']=@str_replace($tables[$k][0],"\n 【表格内容暂不支持,请访问网站查看,此处请忽略】\n",$row['description']); - } - - 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://westdc.westgis.ac.cn/service/bigthumb/uuid/'.$row['uuid']); - $odf->setImage('thumb', 'http://westdc.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(); - $msg = $files -> upload($this->config->upload,$_FILES['Filedata'],'reviewatt'); - - 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']; - $fileurl = $msg['file_url']; - - $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']; - - include_once('files.php'); - $imgct = files::getImageType($this->config->upload.$filename); - - if(!isset($imgct['error'])) $preview = ''; - else $preview = ""; - - $msg['html'] = $preview.$realname.'[已完成]

'; - $msg['preview'] = "/service/attpreview/id/".$attid; - 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(); - } - } - - 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 = ''; - else $preview = ""; - - $atts[$k]['html']= $preview.$v['realname'].'[已完成]
'; - } - - echo Zend_Json::encode($atts); - exit(); - }else - { - exit(); - } - }else{ - exit(); - } - //不输出错误 - }//获取附件 - - 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); - } - - /* - * 附件下载 - */ - function attachAction() - { - $zipuuid = $this->_request->getParam('zip'); - $id=(int)$this->_request->getParam('id'); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - 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); - $atts = $this->db->fetchAll($sql); - $title=$atts[0]['title']; - $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)) - { - if( $zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true ) - { - 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); - } - elseif ($id>0) - { - //下载单个附件 - $sql=$this->db->quoteInto("select a.* from attachments a where a.id=? order by a.ts_created desc",$id); - $atts = $this->db->fetchRow($sql); - $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') - ->setBody($content); - } - else - { - throw new Exception('发生严重意外!您确认链接正确?'); - } - } - - 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){} - //不输出任何错误 - }//删除评审附件 - - 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(); - files::thumb($filename,300,0); - exit; - }catch(Exception $e){ - echo $e->getMessage(); - exit(); - } - } - - } - - function mdjsonAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $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); - $sql.=" length(t.data)>2 order by random() limit $num"; - $rows=$this->db->fetchAll($sql); - echo Zend_Json::encode($rows); - } - - 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'], - 'rsz' => 5 - )); - 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; - }// 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" - ."&Market=zh-cn" - ."&Adult=Moderate" - //."&Options=EnableHighlighting" - ."&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(); - $max = 5; - $error=''; - if(preg_match_all("#(.+?)<\/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>#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"; - $url .= "&hl=en&btnG=搜索&lr="; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_REFERER, $referer); - $html = curl_exec($ch); - curl_close($ch); - - $rev = array(); - $max = 5; - $error=''; - - if(preg_match_all("#(.+?)<\/h3>#im",$html,$matchs,PREG_PATTERN_ORDER)) - { - foreach ($matchs[0] as $k=>$v){ - if($k < $max) $rev[$k]['title']=utf8_encode($v); - } - }else{ - $error = "无搜索结果"; - } - - if(preg_match_all('!
(.*?)<\/div>!im',$html,$matchs,PREG_PATTERN_ORDER)) - { - foreach ($matchs[0] as $k=>$v){ - if($k < $max) $rev[$k]['content']=utf8_encode($v); - } - } - - //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); - - $rev = Zend_Json::encode($response); - return $rev; - }//scholar 搜索 - - function recommendAction(){ - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_request->getParam('uuid'); - $page = $this->_getParam('page'); - $pageSize = 5;//每页容量 - $pre=''; - $next=''; - - $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"; - - $pagnation=""; - if(isset($page)) - { - $page=intval($page); - if($page<0) - { - $page=0; - } - $re = $this->db->query($sql,array($uuid,$uuid)); - $rows = $re->fetchAll(); - $num = count($rows); - if( $num > $pageSize) - { - if($page > 0) - { - $pre = '
  • Prev
  • '; - } - if($num > $pageSize*($page+1)) - { - $next = '
  • Next
  • '; - } - } - $sql .=" limit $pageSize offset ".$page*$pageSize; - } - else - { - $sql .=" limit $pageSize"; - } - $re = $this->db->query($sql,array($uuid,$uuid)); - $rows = $re->fetchAll(); - if(count($rows>0)) - { - - echo '
      '; - foreach($rows as $c) - { - echo - '
    • - '.$c['title'].' -

      '.$c['title'].'

      -
      推荐指数:'.$c['downtimes'].'
      -
    • '; - } - echo '
    '; - echo ''; - }else - { - echo "暂无相关数据"; - } - }//相关下载 给我推荐 - - 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']; - - //相关元数据,根据同名关键词实现 - $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<>?"; - $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 '
  • '.$c['title']."
  • \r\n"; - } - echo '
    '.$paginator.'
    '; - } - } //相关数据 - - 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 '
  • '.$c['title'].'【'.$c['author'].' '.$c['publisher'].' '.$c['ts_issued']."】
  • "; - } - echo '
    '.$paginator.'
    '; - } - }//相关文献 - - function refdatalistAction(){ - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_request->getParam('id'); - $page = $this->_getParam('page'); - - $pageSize = 10;//每页容量 - - $sql = "select md.title,md.uuid from mdref mr - left join metadata md on md.uuid=mr.uuid - where mr.refid=$id"; - $pagnation=""; - if(isset($page)) - { - $page=intval($page); - if($page<0) - { - $page=0; - } - $re = $this->db->query($sql); - $rows = $re->fetchAll(); - $num = count($rows); - if( $num > $pageSize) - { - if($page <= 0) - { - $pre = '<'; - }else{ - $pre = '<'; - } - if($num <= $pageSize*($page+1)) - { - $next = '>'; - }else{ - $next = ">"; - } - - $pagnation = '
    '.$pre.$next.'共 '.$num.' 条
    '; - } - $sql .="limit $pageSize offset ".$page*$pageSize; - } - else - { - $sql .="limit $pageSize"; - } - $re = $this->db->query($sql); - $rows = $re->fetchAll(); - - echo ''; - echo $pagnation; - }//文档页面相关数据 - - function tagdatalistAction(){ - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_request->getParam('id'); - $page = $this->_getParam('page'); - - $pageSize = 10;//每页容量 - $keys=$this->db->fetchAll("select keyword from knl_keyword where item_id=$id"); - $wheresql = array(); - $where2sql=array(); - foreach ($keys as $k=>$v) - { - //split chinese keyword and english keyword - $k1=explode('(',$v['keyword']); - if (is_array($k1) && count($k1)>1) - { - $k2=substr($k1[1],0,-1); - $wheresql[] = " a.keyword like '%".$k2."%' "; - $where2sql[] = " title like '%".$k2."%' "; - $where2sql[] = " description like '%".$k2."%' "; - } - $wheresql[] = " a.keyword like '%".$k1[0]."%' "; - $where2sql[] = " title like '%".$k1[0]."%' "; - $where2sql[] = " description like '%".$k1[0]."%' "; - } - $wheresql[] = " 1<>1 "; - $wheresql = join(" or ",$wheresql); - $where2sql[] = " 1<>1 "; - $where2sql = join(" or ",$where2sql); - - $sql = "select m.title,m.uuid from normalmetadata m where id in (select distinct id from keyword a where $wheresql) or $where2sql"; - $pagnation=""; - if(isset($page)) - { - $page=intval($page); - if($page<0) - { - $page=0; - } - $re = $this->db->query($sql); - $rows = $re->fetchAll(); - $num = count($rows); - if( $num > $pageSize) - { - if($page <= 0) - { - $pre = '<'; - }else{ - $pre = '<'; - } - if($num <= $pageSize*($page+1)) - { - $next = '>'; - }else{ - $next = ">"; - } - - $pagnation = '
    '.$pre.$next.'共 '.$num.' 条
    '; - } - $sql .="limit $pageSize offset ".$page*$pageSize; - } - else - { - $sql .="limit $pageSize"; - } - $re = $this->db->query($sql); - $rows = $re->fetchAll(); - - echo '数据和文献存在一定的相关性,仅供参考。
      '; - foreach($rows as $c) - { - echo '
    • '.$c['title'].'
    • '; - } - if (!$rows) echo '
    • 很抱歉,未找到相关的数据
    • '; - echo '
    '; - echo $pagnation; - }//利用关键词查找的相关数据 - - function geonetworkAction() - { - //$this->_helper->viewRenderer->setNoRender(); - //$this->_helper->layout->disableLayout(); - $auth = Zend_Auth::getInstance(); - $url = $this->config->geonetwork->url.'/srv/cn/'.urldecode($this->_request->getParam('url')); - if (!$auth->hasIdentity()) - { - //$this->_redirect('/account/login?href=/service/geonetwork?url='.$url); - $url = '/account/login?href=/service/geonetwork?url='.$url; - }else{ - $user = $auth->getIdentity(); - //need to get pwd from database - $sql='select username,md5(password) as pwd from users where id='.$user->id; - $this->db->setFetchMode(Zend_Db::FETCH_OBJ); - $row=$this->db->fetchRow($sql); - $this->view->login=$this->config->geonetwork->url.'srv/en/xml.user.login?username='.$row->username.'&password='.$row->pwd; - } - $this->view->url = $url; - - } - - /* - 输出验证码 - */ - public function imgcodeAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - include_once('ImgCode.php'); - $imagecode=new Custom_Controller_Plugin_ImgCode(); - $imagecode->image2(); - } - - //header output - function headerAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $header=file_get_contents('../application/default/views/scripts/header.phtml'); - $content=''; - $content.=eval('?>'.$header); - $content.=''; - $this->getResponse()->setHeader('Content-Type', 'text/html') - ->setBody($content); - } - - //footer output - function footerAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $footer=file_get_contents('../application/default/views/scripts/footer.phtml'); - $this->getResponse()->setHeader('Content-Type', 'text/html') - ->setBody($footer); - } - - - //RIS format convert - function risAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid=$this->_request->getParam('uuid'); - $lang=$this->_request->getParam('lang'); - $ris=''; - if ($lang=='cn' && !empty($uuid)) - { - $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; - $row=$this->db->fetchRow($sql); - $authors=explode(',',str_replace('"','',substr($row['authors'],1,-1))); - $ris.='TY - JOUR'."\r\n"; - $ris.='T1 - '.$row['title']."\r\n"; - foreach($authors as $a) - { - $ris.='A1 - '.$a."\r\n"; - } - $ris.='Y1 - '.(empty($row['publish_year'])?date('Y/m/d',strtotime($row['ts_published'])):date('Y/m/d',strtotime($row['publish_year'])))."\r\n"; - $ris.='JF - '.$row['publisher']."\r\n"; - $ris.='JA - '.$row['publisher']."\r\n"; - $ris.='UR - http://dx.doi.org/'.$row['doi']."\r\n"; - $ris.='PB - '.$row['publisher']."\r\n"; - $ris.='M3 - doi:'.$row['doi']."\r\n"; - $ris.='DO - doi:'.$row['doi']."\r\n"; - $ris.='ER -'."\r\n"; - } - else if ($lang=='en' && !empty($uuid)) - { - $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; - $row=$this->db->fetchRow($sql); - $authors=explode(',',str_replace('"','',substr($row['author_en'],1,-1))); - $ris.='TY - JOUR'."\r\n"; - $ris.='T1 - '.$row['title_en']."\r\n"; - foreach($authors as $a) - { - $ris.='A1 - '.$a."\r\n"; - } - $ris.='Y1 - '.(empty($row['publish_year'])?date('Y/m/d',strtotime($row['ts_published'])):date('Y/m/d',strtotime($row['publish_year'])))."\r\n"; - $ris.='JF - '.$row['publisher_en']."\r\n"; - $ris.='JA - '.$row['publisher_en']."\r\n"; - $ris.='UR - http://dx.doi.org/'.$row['doi']."\r\n"; - $ris.='PB - '.$row['publisher_en']."\r\n"; - $ris.='M3 - doi:'.$row['doi']."\r\n"; - $ris.='DO - doi:'.$row['doi']."\r\n"; - $ris.='ER -'."\r\n"; - } - if (!empty($ris)) - { - $this->getResponse()->setHeader('Content-Type', 'application/x-Research-Info-Systems')->setHeader('Content-Disposition','attachment; filename="'.$uuid.'.ris"') - //->setHeader('Content-Type','application/force-download') - ->setBody($ris); - } - } - - //Bibtex format convert - function bibtexAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid=$this->_request->getParam('uuid'); - $lang=$this->_request->getParam('lang'); - $bib=''; - if ($lang=='cn' && !empty($uuid)) - { - $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; - $row=$this->db->fetchRow($sql); - $bib.='@article{'.$row['doi'].",\r\n"; - $bib.=' author = '.str_replace('"','',str_replace(',',' and ',$row['authors'])).",\r\n"; - $bib.=' journal = {'.$row['publisher']."},\r\n"; - $bib.=' publisher = {'.$row['publisher']."},\r\n"; - $bib.=' title = {'.$row['title']."},\r\n"; - $bib.=' year = {'.(empty($row['publish_year'])?date('Y',strtotime($row['ts_published'])):date('Y',strtotime($row['publish_year'])))."},\r\n"; - $bib.=' month = {'.(empty($row['publish_year'])?date('m',strtotime($row['ts_published'])):date('m',strtotime($row['publish_year'])))."},\r\n"; - $bib.=' url = {http://dx.doi.org/'.$row['doi']."},\r\n"; - $bib.=' doi = {'.$row['doi']."}\r\n"; - $bib.="}\r\n"; - } - else if ($lang=='en' && !empty($uuid)) - { - $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; - $row=$this->db->fetchRow($sql); - $bib.='@article{'.$row['doi'].",\r\n"; - $bib.=' author = '.str_replace('"','',str_replace(',',' and ',$row['author_en'])).",\r\n"; - $bib.=' journal = {'.$row['publisher_en']."},\r\n"; - $bib.=' publisher = {'.$row['publisher_en']."},\r\n"; - $bib.=' title = {'.$row['title']."},\r\n"; - $bib.=' year = {'.(empty($row['publish_year'])?date('Y',strtotime($row['ts_published'])):date('Y',strtotime($row['publish_year'])))."},\r\n"; - $bib.=' month = {'.(empty($row['publish_year'])?date('m',strtotime($row['ts_published'])):date('m',strtotime($row['publish_year'])))."},\r\n"; - $bib.=' url = {http://dx.doi.org/'.$row['doi']."},\r\n"; - $bib.=' doi = {'.$row['doi']."}\r\n"; - $bib.="}\r\n"; - } - if (!empty($bib)) - { - $this->getResponse()->setHeader('Content-Type', 'application/x-Bibtex')->setHeader('Content-Disposition','attachment; filename="'.$uuid.'.bib"') - //->setHeader('Content-Type','application/force-download') - ->setBody($bib); - } - } -} +_helper->viewRenderer->setNoRender(); + $this->_helper->layout->disableLayout(); + } + + function preDispatch() + { + $this->db=Zend_Registry::get('db'); + $this->view->config = $this->config = Zend_Registry::get('config'); + //$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'); + 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); + } + $sql="select t.* from thumbnail t left join metadata m on t.id=m.id where ".$where; + $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']); + } + } + + /* + * 查看数据缩略大图 + */ + function bigthumbAction() + { + $id = (int)$this->_request->getParam('id'); + 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); + } + $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; + } else { + $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']; + $url.='/public/'.str_replace('_s.','.',$thumb['filename']); + header("Content-Type:image/".$thumb['filetype']); + $file=fopen($url,'r'); + fpassthru($file); + exit; + } + } + /* + * 搜索, 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,substring(description for 400) as description,filesize,fileformat from normalmetadata where east? and north?"; + if (!empty($key)) { + $search=new SimpleSearch($key); + $where=$search->sql_expr(array("title","description")); + $sql.= " and ".$where; + $sql.= " order by title"; + $rows=$this->db->fetchAll($sql,array($e,$w,$n,$s)); + } else { + $sql.= " order by title limit 10"; + $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; + $xsl->load($this->config->westdc->xsl); + // 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 normalmetadata 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 uuid,title,datatype,filesize,id from normalmetadata"; + $md=$this->db->fetchAll($sql); + foreach($md as $m) + { + print $m["uuid"].","; + 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 "
    "; + } + + } + + /* + * 转换元数据为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 g.data,m.title,m.description,g.id,m.projection from metadata m left join xml x 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='
      '; + foreach($ref as $refer) + { + $reference.='
    1. '.$refer['reference'].'
    2. '; + } + $reference.='
    '; + 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','$2',$abs); + $abs=str_replace(array("\r\n", "\n", "\r"),'

    ',$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=' +'; + $content.=''.$row['title'].''; + $content.=' + + '; + + $dispostion = 'attachment; filename*="utf8\' \''.urlencode($row['title']).'.doc"'; + + $ua = $_SERVER["HTTP_USER_AGENT"]; + + if (preg_match("/MSIE/", $ua)) { + $dispostion = 'attachment; filename="'.urlencode($row['title']).'.doc"'; + } else if (preg_match("/Firefox/", $ua)) { + //$dispostion; + } else { + $dispostion = 'attachment; filename="'.$row['title'].'.doc"'; + } + + $content.=$xslt->transformToXML($dom); + if ($review==1) $content.=file_get_contents('../data/review-table.htm',true); + $content.=""; + $this->getResponse()->setHeader('Content-Type', 'application/vnd.ms-doc') + ->setHeader('Content-Disposition',$dispostion) + ->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); + } + + /* + * 转换元数据为PDF格式 + */ + public function pdfAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + $review=$this->_request->getParam('review'); + error_reporting(1); + if (!empty($uuid)) + { + $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 metadata m left join xml x 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 + 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=""; + foreach($ref as $k=>$refer) + { + $reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n"; + } + $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=?"; + $sql=$this->db->quoteInto($sql,$uuid); + $limits=$this->db->fetchAll($sql); + $uselimits=""; + foreach($limits as $k=>$limit) + { + //$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; + $uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; + } + $row['uselimits']=$uselimits; + $sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?"; + $sql=$this->db->quoteInto($sql,$uuid); + $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"; + $sql=$this->db->quoteInto($sql,$uuid); + $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"; + $sql=$this->db->quoteInto($sql,$uuid); + $keys=$this->db->fetchAll($sql); + $keyword=array(); + foreach($keys as $key) + { + @$keyword[$key['keytype']].=$key['keyword'].','; + } + $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(); + $dom->loadXML($row['data']); + $xpath = new DOMXpath($dom); + $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; + //提前对表格进行预处理 + /*$wiki=new WikiFormat(); + $row['description']=$wiki->parseTable($row["description"]); + preg_match_all('/[\s\S]*?<\/table>/im', $row['description'],$tables); + foreach($tables as $k=>$table) + { + $row['description']=@str_replace($tables[$k],"\n 【表格内容暂不支持,请访问网站查看,此处请忽略】\n",$row['description']); + }*/ + $pdf=new MetadataPDF(); + $pdf->metadata=$row; + $pdf->Draw(); + $pdf->setTitle($row['title'],true); + $pdf->setAuthor('寒区旱区科学数据中心',true); + $this->getResponse()->setHeader('Content-Type', 'application/pdf'); + //->setHeader('Content-Disposition','inline; filename="'.$row['title'].'.pdf"'); + $pdf->Output($row['title'].'.pdf','I'); + //die(); + } + public function odtAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + $review=$this->_request->getParam('review'); + //error_reporting(1); + if (!empty($uuid)) + { + $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 + 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=""; + foreach($ref as $k=>$refer) + { + $reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n"; + } + $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=?"; + $sql=$this->db->quoteInto($sql,$uuid); + $limits=$this->db->fetchAll($sql); + $uselimits=""; + foreach($limits as $k=>$limit) + { + //$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; + $uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n"; + } + $row['uselimits']=$uselimits; + $sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?"; + $sql=$this->db->quoteInto($sql,$uuid); + $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"; + $sql=$this->db->quoteInto($sql,$uuid); + $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"; + $sql=$this->db->quoteInto($sql,$uuid); + $keys=$this->db->fetchAll($sql); + $keyword=array(); + foreach($keys as $key) + { + @$keyword[$key['keytype']].=$key['keyword'].','; + } + $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(); + $dom->loadXML($row['data']); + $xpath = new DOMXpath($dom); + $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; + //提前对表格进行预处理 + $wiki=new WikiFormat(); + $row['description']=$wiki->parseTable($row["description"]); + preg_match_all('/
    [\s\S]*?<\/table>/im', $row['description'],$tables); + $search=array(); + $replace=array(); + foreach($tables as $k=>$table) + { + /*$search[]="
    "; + $replace[]=''.str_repeat('',substr_count($table[0],'"; + $replace[]=""; + $search[]=""; + $replace[]=""; + $search[]=""; + $replace[]=""; + $search[]="
    ')); + $search[]="
    "; + $replace[]=""; + $search[]=""; + $replace[]=""; + $search[]=""; + $replace[]=""; + $search[]="
    "; + $replace[]=""; + $table=str_replace($search,$replace,$table[0]);*/ + $row['description']=@str_replace($tables[$k][0],"\n 【表格内容暂不支持,请访问网站查看,此处请忽略】\n",$row['description']); + } + + 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://westdc.westgis.ac.cn/service/bigthumb/uuid/'.$row['uuid']); + $odf->setImage('thumb', 'http://westdc.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(); + $msg = $files -> upload($this->config->upload,$_FILES['Filedata'],'reviewatt'); + + 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']; + $fileurl = $msg['file_url']; + + $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']; + + include_once('files.php'); + $imgct = files::getImageType($this->config->upload.$filename); + + if(!isset($imgct['error'])) $preview = ''; + else $preview = ""; + + $msg['html'] = $preview.$realname.'[已完成]

    '; + $msg['preview'] = "/service/attpreview/id/".$attid; + 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(); + } + } + + 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 = ''; + else $preview = ""; + + $atts[$k]['html']= $preview.$v['realname'].'[已完成]
    '; + } + + echo Zend_Json::encode($atts); + exit(); + }else + { + exit(); + } + }else{ + exit(); + } + //不输出错误 + }//获取附件 + + 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); + } + + /* + * 附件下载 + */ + function attachAction() + { + $zipuuid = $this->_request->getParam('zip'); + $id=(int)$this->_request->getParam('id'); + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + 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); + $atts = $this->db->fetchAll($sql); + $title=$atts[0]['title']; + $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)) + { + if( $zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true ) + { + 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); + } + elseif ($id>0) + { + //下载单个附件 + $sql=$this->db->quoteInto("select a.* from attachments a where a.id=? order by a.ts_created desc",$id); + $atts = $this->db->fetchRow($sql); + $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') + ->setBody($content); + } + else + { + throw new Exception('发生严重意外!您确认链接正确?'); + } + } + + 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){} + //不输出任何错误 + }//删除评审附件 + + 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(); + files::thumb($filename,300,0); + exit; + }catch(Exception $e){ + echo $e->getMessage(); + exit(); + } + } + + } + + function mdjsonAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $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); + $sql.=" length(t.data)>2 order by random() limit $num"; + $rows=$this->db->fetchAll($sql); + echo Zend_Json::encode($rows); + } + + 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'], + 'rsz' => 5 + )); + 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; + }// 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" + ."&Market=zh-cn" + ."&Adult=Moderate" + //."&Options=EnableHighlighting" + ."&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(); + $max = 5; + $error=''; + if(preg_match_all("#(.+?)<\/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>#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"; + $url .= "&hl=en&btnG=搜索&lr="; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, $referer); + $html = curl_exec($ch); + curl_close($ch); + + $rev = array(); + $max = 5; + $error=''; + + if(preg_match_all("#(.+?)<\/h3>#im",$html,$matchs,PREG_PATTERN_ORDER)) + { + foreach ($matchs[0] as $k=>$v){ + if($k < $max) $rev[$k]['title']=utf8_encode($v); + } + }else{ + $error = "无搜索结果"; + } + + if(preg_match_all('!
    (.*?)<\/div>!im',$html,$matchs,PREG_PATTERN_ORDER)) + { + foreach ($matchs[0] as $k=>$v){ + if($k < $max) $rev[$k]['content']=utf8_encode($v); + } + } + + //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); + + $rev = Zend_Json::encode($response); + return $rev; + }//scholar 搜索 + + function recommendAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $uuid = $this->_request->getParam('uuid'); + $page = $this->_getParam('page'); + $pageSize = 5;//每页容量 + $pre=''; + $next=''; + + $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"; + + $pagnation=""; + if(isset($page)) + { + $page=intval($page); + if($page<0) + { + $page=0; + } + $re = $this->db->query($sql,array($uuid,$uuid)); + $rows = $re->fetchAll(); + $num = count($rows); + if( $num > $pageSize) + { + if($page > 0) + { + $pre = '
  • Prev
  • '; + } + if($num > $pageSize*($page+1)) + { + $next = '
  • Next
  • '; + } + } + $sql .=" limit $pageSize offset ".$page*$pageSize; + } + else + { + $sql .=" limit $pageSize"; + } + $re = $this->db->query($sql,array($uuid,$uuid)); + $rows = $re->fetchAll(); + if(count($rows>0)) + { + + echo '
      '; + foreach($rows as $c) + { + echo + '
    • + '.$c['title'].' +

      '.$c['title'].'

      +
      推荐指数:'.$c['downtimes'].'
      +
    • '; + } + echo '
    '; + echo ''; + }else + { + echo "暂无相关数据"; + } + }//相关下载 给我推荐 + + 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']; + + //相关元数据,根据同名关键词实现 + $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<>?"; + $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 '
  • '.$c['title']."
  • \r\n"; + } + echo '
    '.$paginator.'
    '; + } + } //相关数据 + + 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 '
  • '.$c['title'].'【'.$c['author'].' '.$c['publisher'].' '.$c['ts_issued']."】
  • "; + } + echo '
    '.$paginator.'
    '; + } + }//相关文献 + + function refdatalistAction(){ + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_request->getParam('id'); + $page = $this->_getParam('page'); + + $pageSize = 10;//每页容量 + + $sql = "select md.title,md.uuid from mdref mr + left join metadata md on md.uuid=mr.uuid + where mr.refid=$id"; + $pagnation=""; + if(isset($page)) + { + $page=intval($page); + if($page<0) + { + $page=0; + } + $re = $this->db->query($sql); + $rows = $re->fetchAll(); + $num = count($rows); + if( $num > $pageSize) + { + if($page <= 0) + { + $pre = '<'; + }else{ + $pre = '<'; + } + if($num <= $pageSize*($page+1)) + { + $next = '>'; + }else{ + $next = ">"; + } + + $pagnation = '
    '.$pre.$next.'共 '.$num.' 条
    '; + } + $sql .="limit $pageSize offset ".$page*$pageSize; + } + else + { + $sql .="limit $pageSize"; + } + $re = $this->db->query($sql); + $rows = $re->fetchAll(); + + echo ''; + echo $pagnation; + }//文档页面相关数据 + + function tagdatalistAction(){ + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_request->getParam('id'); + $page = $this->_getParam('page'); + + $pageSize = 10;//每页容量 + $keys=$this->db->fetchAll("select keyword from knl_keyword where item_id=$id"); + $wheresql = array(); + $where2sql=array(); + foreach ($keys as $k=>$v) + { + //split chinese keyword and english keyword + $k1=explode('(',$v['keyword']); + if (is_array($k1) && count($k1)>1) + { + $k2=substr($k1[1],0,-1); + $wheresql[] = " a.keyword like '%".$k2."%' "; + $where2sql[] = " title like '%".$k2."%' "; + $where2sql[] = " description like '%".$k2."%' "; + } + $wheresql[] = " a.keyword like '%".$k1[0]."%' "; + $where2sql[] = " title like '%".$k1[0]."%' "; + $where2sql[] = " description like '%".$k1[0]."%' "; + } + $wheresql[] = " 1<>1 "; + $wheresql = join(" or ",$wheresql); + $where2sql[] = " 1<>1 "; + $where2sql = join(" or ",$where2sql); + + $sql = "select m.title,m.uuid from normalmetadata m where id in (select distinct id from keyword a where $wheresql) or $where2sql"; + $pagnation=""; + if(isset($page)) + { + $page=intval($page); + if($page<0) + { + $page=0; + } + $re = $this->db->query($sql); + $rows = $re->fetchAll(); + $num = count($rows); + if( $num > $pageSize) + { + if($page <= 0) + { + $pre = '<'; + }else{ + $pre = '<'; + } + if($num <= $pageSize*($page+1)) + { + $next = '>'; + }else{ + $next = ">"; + } + + $pagnation = '
    '.$pre.$next.'共 '.$num.' 条
    '; + } + $sql .="limit $pageSize offset ".$page*$pageSize; + } + else + { + $sql .="limit $pageSize"; + } + $re = $this->db->query($sql); + $rows = $re->fetchAll(); + + echo '数据和文献存在一定的相关性,仅供参考。
      '; + foreach($rows as $c) + { + echo '
    • '.$c['title'].'
    • '; + } + if (!$rows) echo '
    • 很抱歉,未找到相关的数据
    • '; + echo '
    '; + echo $pagnation; + }//利用关键词查找的相关数据 + + function geonetworkAction() + { + //$this->_helper->viewRenderer->setNoRender(); + //$this->_helper->layout->disableLayout(); + $auth = Zend_Auth::getInstance(); + $url = $this->config->geonetwork->url.'/srv/cn/'.urldecode($this->_request->getParam('url')); + if (!$auth->hasIdentity()) + { + //$this->_redirect('/account/login?href=/service/geonetwork?url='.$url); + $url = '/account/login?href=/service/geonetwork?url='.$url; + }else{ + $user = $auth->getIdentity(); + //need to get pwd from database + $sql='select username,md5(password) as pwd from users where id='.$user->id; + $this->db->setFetchMode(Zend_Db::FETCH_OBJ); + $row=$this->db->fetchRow($sql); + $this->view->login=$this->config->geonetwork->url.'srv/en/xml.user.login?username='.$row->username.'&password='.$row->pwd; + } + $this->view->url = $url; + + } + + /* + 输出验证码 + */ + public function imgcodeAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + include_once('ImgCode.php'); + $imagecode=new Custom_Controller_Plugin_ImgCode(); + $imagecode->image2(); + } + + //header output + function headerAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $header=file_get_contents('../application/default/views/scripts/header.phtml'); + $content=''; + $content.=eval('?>'.$header); + $content.=''; + $this->getResponse()->setHeader('Content-Type', 'text/html') + ->setBody($content); + } + + //footer output + function footerAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $footer=file_get_contents('../application/default/views/scripts/footer.phtml'); + $this->getResponse()->setHeader('Content-Type', 'text/html') + ->setBody($footer); + } + + + //RIS format convert + function risAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + $lang=$this->_request->getParam('lang'); + $ris=''; + if ($lang=='cn' && !empty($uuid)) + { + $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; + $row=$this->db->fetchRow($sql); + $authors=explode(',',str_replace('"','',substr($row['authors'],1,-1))); + $ris.='TY - JOUR'."\r\n"; + $ris.='T1 - '.$row['title']."\r\n"; + foreach($authors as $a) + { + $ris.='A1 - '.$a."\r\n"; + } + $ris.='Y1 - '.(empty($row['publish_year'])?date('Y/m/d',strtotime($row['ts_published'])):date('Y/m/d',strtotime($row['publish_year'])))."\r\n"; + $ris.='JF - '.$row['publisher']."\r\n"; + $ris.='JA - '.$row['publisher']."\r\n"; + $ris.='UR - http://dx.doi.org/'.$row['doi']."\r\n"; + $ris.='PB - '.$row['publisher']."\r\n"; + $ris.='M3 - doi:'.$row['doi']."\r\n"; + $ris.='DO - doi:'.$row['doi']."\r\n"; + $ris.='ER -'."\r\n"; + } + else if ($lang=='en' && !empty($uuid)) + { + $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; + $row=$this->db->fetchRow($sql); + $authors=explode(',',str_replace('"','',substr($row['author_en'],1,-1))); + $ris.='TY - JOUR'."\r\n"; + $ris.='T1 - '.$row['title_en']."\r\n"; + foreach($authors as $a) + { + $ris.='A1 - '.$a."\r\n"; + } + $ris.='Y1 - '.(empty($row['publish_year'])?date('Y/m/d',strtotime($row['ts_published'])):date('Y/m/d',strtotime($row['publish_year'])))."\r\n"; + $ris.='JF - '.$row['publisher_en']."\r\n"; + $ris.='JA - '.$row['publisher_en']."\r\n"; + $ris.='UR - http://dx.doi.org/'.$row['doi']."\r\n"; + $ris.='PB - '.$row['publisher_en']."\r\n"; + $ris.='M3 - doi:'.$row['doi']."\r\n"; + $ris.='DO - doi:'.$row['doi']."\r\n"; + $ris.='ER -'."\r\n"; + } + if (!empty($ris)) + { + $this->getResponse()->setHeader('Content-Type', 'application/x-Research-Info-Systems')->setHeader('Content-Disposition','attachment; filename="'.$uuid.'.ris"') + //->setHeader('Content-Type','application/force-download') + ->setBody($ris); + } + } + + //Bibtex format convert + function bibtexAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + $lang=$this->_request->getParam('lang'); + $bib=''; + if ($lang=='cn' && !empty($uuid)) + { + $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; + $row=$this->db->fetchRow($sql); + $bib.='@article{'.$row['doi'].",\r\n"; + $bib.=' author = '.str_replace('"','',str_replace(',',' and ',$row['authors'])).",\r\n"; + $bib.=' journal = {'.$row['publisher']."},\r\n"; + $bib.=' publisher = {'.$row['publisher']."},\r\n"; + $bib.=' title = {'.$row['title']."},\r\n"; + $bib.=' year = {'.(empty($row['publish_year'])?date('Y',strtotime($row['ts_published'])):date('Y',strtotime($row['publish_year'])))."},\r\n"; + $bib.=' month = {'.(empty($row['publish_year'])?date('m',strtotime($row['ts_published'])):date('m',strtotime($row['publish_year'])))."},\r\n"; + $bib.=' url = {http://dx.doi.org/'.$row['doi']."},\r\n"; + $bib.=' doi = {'.$row['doi']."}\r\n"; + $bib.="}\r\n"; + } + else if ($lang=='en' && !empty($uuid)) + { + $sql="select d.*,m.description,m.ts_published as publish_year from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; + $row=$this->db->fetchRow($sql); + $bib.='@article{'.$row['doi'].",\r\n"; + $bib.=' author = '.str_replace('"','',str_replace(',',' and ',$row['author_en'])).",\r\n"; + $bib.=' journal = {'.$row['publisher_en']."},\r\n"; + $bib.=' publisher = {'.$row['publisher_en']."},\r\n"; + $bib.=' title = {'.$row['title']."},\r\n"; + $bib.=' year = {'.(empty($row['publish_year'])?date('Y',strtotime($row['ts_published'])):date('Y',strtotime($row['publish_year'])))."},\r\n"; + $bib.=' month = {'.(empty($row['publish_year'])?date('m',strtotime($row['ts_published'])):date('m',strtotime($row['publish_year'])))."},\r\n"; + $bib.=' url = {http://dx.doi.org/'.$row['doi']."},\r\n"; + $bib.=' doi = {'.$row['doi']."}\r\n"; + $bib.="}\r\n"; + } + if (!empty($bib)) + { + $this->getResponse()->setHeader('Content-Type', 'application/x-Bibtex')->setHeader('Content-Disposition','attachment; filename="'.$uuid.'.bib"') + //->setHeader('Content-Type','application/force-download') + ->setBody($bib); + } + } + + + + function mapsearchAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + include_once("data/Metadata.php"); + $md = new Metadata($this->db); + + $options = $this->_getParam('opt'); + if(isset($options['east'])) + $options['east'] = (float)$options['east']; + if(isset($options['west'])) + $options['west'] = (float)$options['west']; + if(isset($options['north'])) + $options['north'] = (float)$options['north']; + if(isset($options['south'])) + $options['south'] = (float)$options['south']; + + $data = $md->mapview($options); + + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); + return true; + } + +} diff --git a/application/default/views/scripts/data/map.phtml b/application/default/views/scripts/data/map.phtml index 91db830d..90e9210a 100755 --- a/application/default/views/scripts/data/map.phtml +++ b/application/default/views/scripts/data/map.phtml @@ -1,88 +1,202 @@ headTitle($this->config->title->site); - $this->headTitle($this->config->title->data); - $this->headTitle("空间浏览"); - $this->headTitle()->setSeparator(' - '); - $this->headLink()->appendStylesheet('/css/metadata.css'); -$this->headScript()->appendFile('http://maps.google.com/maps/api/js?sensor=false'); - $this->headScript()->appendFile('/js/OpenLayers.js'); - $this->headLink()->appendStylesheet('/js/theme/default/style.css'); +$this->headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle("空间浏览"); +$this->headTitle()->setSeparator(' - '); +$this->theme->AppendPlus($this,'jquery_ui'); +//$this->theme->AppendPlus($this,'google_map_v3'); +$this->theme->AppendPlus($this,'colorbox'); +$this->headLink()->appendStylesheet('/js/theme/default/style.css'); $this->nav[] = array('link'=>"/data/map",'title'=>'空间导航'); - ?> -
    -render('breadcrumbs.phtml'); ?> -partial('data/tools.phtml'); ?> -
    -
    - - diff --git a/application/models/data/Metadata.php b/application/models/data/Metadata.php index af1e0e03..10f24b9f 100644 --- a/application/models/data/Metadata.php +++ b/application/models/data/Metadata.php @@ -17,4 +17,41 @@ class Metadata $rs = $this->db->query($sql); return $rs->fetch(); } + + function mapview($options) + { + $wheresql = array(); + + if(isset($options['east'])) + { + $wheresql[] = " md.east < ".$options['east']; + } + + if(isset($options['west'])) + { + $wheresql[] = " md.west > ".$options['west']; + } + + if(isset($options['north'])) + { + $wheresql[] = " md.north < ".$options['north']; + } + + if(isset($options['south'])) + { + $wheresql[] = " md.south > ".$options['south']; + } + + if(count($wheresql)>0) + { + $wheresql = " WHERE ".join(" AND ",$wheresql); + }else{ + $wheresql = ""; + } + + $sql = "SELECT md.* FROM ".$this->tbl_metadata." md $wheresql"; + + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } } From 492e5a25e017cebbe275073d79e53dcc4092a067 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 27 May 2013 09:03:11 +0000 Subject: [PATCH 02/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9data/view=E4=B8=AD?= =?UTF-8?q?=E5=8D=95=E4=B8=AA=E7=82=B9=E6=98=BE=E7=A4=BA=E4=B8=BA=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=B0=8F=E9=BB=91=E5=9D=97=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/js/metadata-view.js | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/htdocs/js/metadata-view.js b/htdocs/js/metadata-view.js index ab1c6fa7..d61ff2f9 100644 --- a/htdocs/js/metadata-view.js +++ b/htdocs/js/metadata-view.js @@ -259,20 +259,31 @@ function initialize() { function setRectangle(east,west,south,north){ - bounds = new google.maps.LatLngBounds( - new google.maps.LatLng(south,west), - new google.maps.LatLng(north,east) - ); + if(east.toFixed(1) != west.toFixed(1) && south.toFixed(1)!= north.toFixed(1) ){ + RemoveRectangle(); + + bounds = new google.maps.LatLngBounds( + new google.maps.LatLng(south,west), + new google.maps.LatLng(north,east) + ); + + rectangle = new google.maps.Rectangle({ + bounds: bounds, + editable: false + }); + + rectangle.setMap(map); + }else{ + RemoveRectangle(); + + var position = new google.maps.LatLng(south,east); + + var marker = new google.maps.Marker({ + position: position, + map: map, + }); + + markers.push(marker); + } - rectangle = new google.maps.Rectangle({ - bounds: bounds, - editable: false - }); - - rectangle.setMap(map); - - var bounds = new google.maps.LatLngBounds(); - bounds.extend(new google.maps.LatLng(south, west)); - bounds.extend(new google.maps.LatLng(north,east)); - map.fitBounds(bounds); } \ No newline at end of file From 6f2beb0c70b127669354de5bdf2d01e768379a44 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 27 May 2013 15:25:13 +0000 Subject: [PATCH 03/18] add js to adjuest height --- application/admin/views/scripts/stat/awstatsftp.phtml | 7 +++++-- application/admin/views/scripts/stat/awstatsftp2.phtml | 7 +++++-- application/admin/views/scripts/stat/awstatsweb.phtml | 7 +++++-- application/admin/views/scripts/stat/awstatsweb2.phtml | 7 +++++-- application/admin/views/scripts/stat/webalizer.phtml | 7 +++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/application/admin/views/scripts/stat/awstatsftp.phtml b/application/admin/views/scripts/stat/awstatsftp.phtml index 0dba3890..2d80de38 100644 --- a/application/admin/views/scripts/stat/awstatsftp.phtml +++ b/application/admin/views/scripts/stat/awstatsftp.phtml @@ -11,5 +11,8 @@ partial('stat/left.phtml'); ?>
    - -
    \ No newline at end of file + +
    + \ No newline at end of file diff --git a/application/admin/views/scripts/stat/awstatsftp2.phtml b/application/admin/views/scripts/stat/awstatsftp2.phtml index 3f79a716..39195b06 100644 --- a/application/admin/views/scripts/stat/awstatsftp2.phtml +++ b/application/admin/views/scripts/stat/awstatsftp2.phtml @@ -11,5 +11,8 @@ partial('stat/left.phtml'); ?>
    - -
    \ No newline at end of file + + + \ No newline at end of file diff --git a/application/admin/views/scripts/stat/awstatsweb.phtml b/application/admin/views/scripts/stat/awstatsweb.phtml index 8621a407..fe5e21ed 100644 --- a/application/admin/views/scripts/stat/awstatsweb.phtml +++ b/application/admin/views/scripts/stat/awstatsweb.phtml @@ -11,5 +11,8 @@ partial('stat/left.phtml'); ?>
    - -
    \ No newline at end of file + + + \ No newline at end of file diff --git a/application/admin/views/scripts/stat/awstatsweb2.phtml b/application/admin/views/scripts/stat/awstatsweb2.phtml index 19d9c60f..346eb40f 100644 --- a/application/admin/views/scripts/stat/awstatsweb2.phtml +++ b/application/admin/views/scripts/stat/awstatsweb2.phtml @@ -11,5 +11,8 @@ partial('stat/left.phtml'); ?>
    - -
    \ No newline at end of file + + + \ No newline at end of file diff --git a/application/admin/views/scripts/stat/webalizer.phtml b/application/admin/views/scripts/stat/webalizer.phtml index 719706a5..ac1fa9ac 100644 --- a/application/admin/views/scripts/stat/webalizer.phtml +++ b/application/admin/views/scripts/stat/webalizer.phtml @@ -11,5 +11,8 @@ partial('stat/left.phtml'); ?>
    - -
    \ No newline at end of file + + + \ No newline at end of file From 1889b06b29cf96d463a27e13bfd0241dd5a29a03 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 28 May 2013 03:32:53 +0000 Subject: [PATCH 04/18] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=81=A2=E5=A4=8D=E6=9F=A5=E7=9C=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/SysController.php | 156 +++++++++++++++++- .../admin/views/scripts/sys/left.phtml | 4 +- .../admin/views/scripts/sys/recovery.phtml | 43 +++++ 3 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 application/admin/views/scripts/sys/recovery.phtml diff --git a/application/admin/controllers/SysController.php b/application/admin/controllers/SysController.php index f5f5d46e..d473ae20 100644 --- a/application/admin/controllers/SysController.php +++ b/application/admin/controllers/SysController.php @@ -332,6 +332,160 @@ class Admin_SysController extends Zend_Controller_Action } }//end - }//getmessageAction() 获取站内消息 + }//getmessageAction() 获取站内消息 + + //ftp测试 + function ftptestAction() + { + } + + function recoveryAction() + { + $pages=20; + $ac=$this->_request->getParam('ac'); + if ($ac=='' || $ac=='online') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + where s.status>4 and m.datatype=0 and ds.host='ftp1.westgis.ac.cn' + ORDER BY m.id DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + } else if ($ac=='heihe') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + left join datasource on datasource.uuid=m.uuid + left join source on datasource.sourceid=source.id + where s.status>4 and m.datatype=1 and ds.host='ftp1.westgis.ac.cn' and source.code='heihe' + ORDER BY m.id DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + } else if ($ac=='water') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + left join datasource on datasource.uuid=m.uuid + left join source on datasource.sourceid=source.id + where s.status>4 and m.datatype=1 and ds.host='ftp1.westgis.ac.cn' and source.code='water' + ORDER BY m.id DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + } else if ($ac=='heihe1') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + left join datasource on datasource.uuid=m.uuid + left join source on datasource.sourceid=source.id + where s.status in (2,3,4) and ds.host='ftp1.westgis.ac.cn' and source.code='heihe' + ORDER BY m.title DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + } else if ($ac=='hiwater') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + left join datasource on datasource.uuid=m.uuid + left join source on datasource.sourceid=source.id + where ds.host='ftp1.westgis.ac.cn' and source.code='hiwater' + ORDER BY m.title DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + }else if ($ac=='westee') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + where ds.host='ftp1.westgis.ac.cn' and m.uuid in (select uuid from westeemd) + ORDER BY m.title DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + }else if ($ac=='other') + { + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + (select floor(sum(filesize)/1024/1024*100)/100 from datafile where dsid=ds.id) as filesize, + (select count(id) from datafile where dsid=ds.id) as filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + where ds.host='ftp1.westgis.ac.cn' and m.uuid not in (select uuid from datasource) and m.uuid not in (select uuid from westeemd) + ORDER BY m.title DESC"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage($pages); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + } + } + } diff --git a/application/admin/views/scripts/sys/left.phtml b/application/admin/views/scripts/sys/left.phtml index f68e5f0d..4340d407 100644 --- a/application/admin/views/scripts/sys/left.phtml +++ b/application/admin/views/scripts/sys/left.phtml @@ -2,5 +2,7 @@
  • 系统管理
  • 邮件模板管理
  • 文献平台同步
  • -
  • 管理消息
  • +
  • 管理消息
  • +
  • 数据FTP测试
  • +
  • 数据恢复进展
  • \ No newline at end of file diff --git a/application/admin/views/scripts/sys/recovery.phtml b/application/admin/views/scripts/sys/recovery.phtml new file mode 100644 index 00000000..26e73bdc --- /dev/null +++ b/application/admin/views/scripts/sys/recovery.phtml @@ -0,0 +1,43 @@ +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); +?> +
    +partial('sys/left.phtml'); ?> +
    + +
    + 在线数据 + 黑河专题数据 + WATER + 西部计划 + Hiwater + 黑河计划未发布数据 + 其他数据 + + + + + + + + +paginator)): + $autoindex=0; + foreach ($this->paginator as $item): + $autoindex++;?> + + + + + + + + + +
    数据标题UUIDFTP主机路径大小文件数
    + +
    \ No newline at end of file From 9f24d22e6b37cfc1004132ba8270e0dad690cdd0 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 28 May 2013 03:53:57 +0000 Subject: [PATCH 05/18] style change --- .../admin/controllers/SysController.php | 1 + .../admin/views/scripts/down/offlineapp.phtml | 2 +- .../admin/views/scripts/sys/recovery.phtml | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/application/admin/controllers/SysController.php b/application/admin/controllers/SysController.php index d473ae20..62addfa3 100644 --- a/application/admin/controllers/SysController.php +++ b/application/admin/controllers/SysController.php @@ -485,6 +485,7 @@ class Admin_SysController extends Zend_Controller_Action Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); $this->view->paginator=$paginator; } + $this->view->activeID="btn-".$ac; } } diff --git a/application/admin/views/scripts/down/offlineapp.phtml b/application/admin/views/scripts/down/offlineapp.phtml index 91088f2b..a8bf43ed 100644 --- a/application/admin/views/scripts/down/offlineapp.phtml +++ b/application/admin/views/scripts/down/offlineapp.phtml @@ -39,7 +39,7 @@
      -
    • +
    diff --git a/application/admin/views/scripts/sys/recovery.phtml b/application/admin/views/scripts/sys/recovery.phtml index 26e73bdc..1495b6e3 100644 --- a/application/admin/views/scripts/sys/recovery.phtml +++ b/application/admin/views/scripts/sys/recovery.phtml @@ -9,13 +9,13 @@
    - 在线数据 - 黑河专题数据 - WATER - 西部计划 - Hiwater - 黑河计划未发布数据 - 其他数据 + 在线数据 + 黑河专题数据 + WATER + 西部计划 + Hiwater + 黑河计划未发布数据 + 其他数据 @@ -40,4 +40,7 @@ if (count($this->paginator)):
    数据标题 UUID
    -
    \ No newline at end of file + +activeID)) : ?> + + \ No newline at end of file From ccef383b1447d5687e36a4ce06b6276e010b9421 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 28 May 2013 03:55:51 +0000 Subject: [PATCH 06/18] style change --- htdocs/css/admin.css | 75 -------------------------------------------- 1 file changed, 75 deletions(-) diff --git a/htdocs/css/admin.css b/htdocs/css/admin.css index 730e6568..c8052cc4 100644 --- a/htdocs/css/admin.css +++ b/htdocs/css/admin.css @@ -3,11 +3,6 @@ * 2011/9/13 15:48 */ -*{padding:0px;margin:0px;} -html {background:#FFF;} -body {font:12px Tahoma, Geneva, sans-serif;} -a {text-decoration:none;cursor:hand;} -od,ul,li,ul li{list-style:none;} input,select,button{font:12px Tahoma, Geneva, sans-serif;vertical-align:middle;} input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;} body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0px;padding:0px;} @@ -299,77 +294,7 @@ fieldset small { font-size:11px; display: block; } -.btn { - display: inline-block; - padding: 5px 10px; - color: #777 !important; - text-decoration: none; - font-weight: bold; - font-size: 12px; - font-family: Tahoma, Arial, sans-serif; - -moz-border-radius: 4px; - -webkit-border-radius: 4px; - border-radius: 4px; - text-shadow: 0 1px 1px rgba(255,255,255,0.9); - position: relative; - cursor: pointer; - border:1px solid #ccc !important; - background:#fff url("../images/btn-overlay.png") repeat-x !important; -} -.btn:hover, .btn:focus, .btn:active { - outline:medium none; - border:1px solid #329ECC !important; - opacity:0.9; - -khtml-opacity: .9; - -moz-opacity: 0.9; - -moz-box-shadow:0 0 5px rgba(82, 168, 236, 0.5); - -webkit-box-shadow: 0 0 5px rgba(82, 168, 236, 0.5); - box-shadow: 0 0 5px rgba(82, 168, 236, 0.5); -} -.btn-green { - color: #fff !important; - text-shadow: 0 1px 1px rgba(0,0,0,0.25); - border:1px solid #749217 !important; - background-color: #6AB620 !important; -} -.btn-green:hover, .btn-green:focus, .btn-green:active { - -moz-box-shadow:0 0 5px rgba(116, 146, 23, 0.9); - -webkit-box-shadow: 0 0 5px rgba(116, 146, 23, 0.9); - box-shadow: 0 0 5px rgba(116, 146, 23, 0.9); - border:1px solid #749217 !important; -} -.btn-blue { - color: #fff !important; - text-shadow: 0 1px 1px rgba(0,0,0,0.25); - border:1px solid #2D69AC !important; - background-color: #3C6ED1 !important; -} -.btn-blue:hover, .btn-blue:focus, .btn-blue:active { - -moz-box-shadow:0 0 5px rgba(71, 131, 243, 0.9); - -webkit-box-shadow:0 0 5px rgba(71, 131, 243, 0.9); - box-shadow: 0 0 5px rgba(71, 131, 243, 0.9); - border:1px solid #2D69AC !important; -} - -.btn-red { - color: #fff !important; - text-shadow: 0 1px 1px rgba(0,0,0,0.25); - border:1px solid #AE2B2B !important; - background-color: #D22A2A !important; - background-image:none; -} -.btn-red:hover, .btn-red:focus, .btn-red:active { - -moz-box-shadow:0 0 5px rgba(174, 43, 43, 0.9); - -webkit-box-shadow:0 0 5px rgba(174, 43, 43, 0.9); - box-shadow: 0 0 5px rgba(174, 43, 43, 0.9); - border:1px solid #AE2B2B !important; -} - -.btn-special { - font-size:110%; - width: 210px; -} .tables{width:320px;float:left;} .tables .stitle{width:100%;font-size:16px;font-weight:bold;} From 73dac5540db6aab027c7464b54c4759fb91199ab Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 28 May 2013 04:20:36 +0000 Subject: [PATCH 07/18] change navi --- .../default/controllers/HiwaterController.php | 6 +++--- .../default/views/scripts/hiwater/navi.phtml | 21 +++++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/application/default/controllers/HiwaterController.php b/application/default/controllers/HiwaterController.php index 424388fe..24435780 100644 --- a/application/default/controllers/HiwaterController.php +++ b/application/default/controllers/HiwaterController.php @@ -29,7 +29,7 @@ class HiwaterController extends DataController { $this->view->pageIn = "collapse5"; } - else if(in_array($acName,array("fund","tag","timeline","timemap",'author','organization'))) + else if(in_array($acName,array("browse","thumb","fund","tag","timeline","timemap",'author','organization'))) { $this->view->pageIn = "collapse10"; } @@ -107,12 +107,12 @@ class HiwaterController extends DataController } function lidarAction() { - $this->getmd(array('','Lidar')); + $this->getmd(array('LIDAR','Lidar')); $this->_helper->viewRenderer('base'); } function widasAction() { - $this->getmd(array('','WiDAS')); + $this->getmd(array('WIDAS','WiDAS')); $this->_helper->viewRenderer('base'); } function nearvisAction() diff --git a/application/default/views/scripts/hiwater/navi.phtml b/application/default/views/scripts/hiwater/navi.phtml index 0e789169..d25cf67b 100644 --- a/application/default/views/scripts/hiwater/navi.phtml +++ b/application/default/views/scripts/hiwater/navi.phtml @@ -6,20 +6,7 @@ - - +
    activeID)) : ?> - \ No newline at end of file + + \ No newline at end of file From 68ad754db0965ff31d8c6c5106c4dd8d094c8052 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 29 May 2013 07:36:44 +0000 Subject: [PATCH 14/18] =?UTF-8?q?#465=20=E6=95=B0=E6=8D=AE=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E6=89=93=E5=BC=80=E9=A1=B5=E9=9D=A2=E6=97=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=98=BE=E7=A4=BA=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AuthorController.php | 69 +++++++----------- .../default/controllers/DataController.php | 8 +- .../default/views/scripts/author/apply.phtml | 73 ++++++++++++------- application/models/data/Review.php | 4 +- 4 files changed, 83 insertions(+), 71 deletions(-) diff --git a/application/default/controllers/AuthorController.php b/application/default/controllers/AuthorController.php index f1c0de4e..362bd9ae 100644 --- a/application/default/controllers/AuthorController.php +++ b/application/default/controllers/AuthorController.php @@ -709,42 +709,33 @@ class AuthorController extends Zend_Controller_Action */ function applyAction() { - $ac = $this->_request->getParam('ac'); - + $ac = $this->_request->getParam('ac'); + + if($ac == "mydata") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + include_once('helper/view.php'); + $email = view::User('email'); + + $sql = "SELECT m.uuid,m.title,m.description,a.status,a.userid FROM normalmetadata m + LEFT JOIN mdauthor a ON m.uuid=a.uuid + LEFT JOIN role r ON r.uuid=m.uuid + LEFT JOIN responsible re ON r.resid = re.id + WHERE re.email LIKE '%$email%'"; + + $rs = $this->db->query($sql); + $this->jsonexit($rs->fetchAll()); + return true; + }//首页 + //搜索动作 if($ac == "search") { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); - //要输出的Json对象 - //过程中如果没有处理,则不包含任何返回信息,由前台定义提示信息,如: - /* - $.ajax({ - 'type':"POST", - 'url':'/author/apply', - 'data':'ac=search&q='+$('#keyword').val(), - 'success':function(data){ - if (typeof(data)=='object') //如果服务器端的响应为Json对象 - { - if(typeof(data.error)!='undefined') //服务器端响应的错误消息 - { - alert(data.error); - }else{ //服务器端无错误消息则为成功的响应 - alert(data.length); - } - }else{ //服务器端响应了非JSON对象或者为空 - alert('无搜索结果'); - } - }, - 'beforeSend':function(){ - //请求发送前 - } - }); - - 错误消息的键名必须为error,不包含JS脚本,如: - $data['error'] = '服务器忙!'; - */ $data = ""; //防止通过其它方式访问,先判断是否是登录用户,如果不是,抛出消息后强制用户退出 @@ -792,7 +783,7 @@ class AuthorController extends Zend_Controller_Action } }catch(Exception $e){ - //如果上面的程序已经发送出提示,就不发送抛出的错误 + if(empty($data['error'])) { if($this->debug==0) @@ -803,14 +794,10 @@ class AuthorController extends Zend_Controller_Action } } } - // >>>>>>>>>>> F + - //截获响应对象,并修改头部和内容 - //不管有没有数据存在,都将返回Json数据,前台有判断机制来分析数据 - - $this ->getResponse() - ->setHeader('Content-Type', 'application/json') - ->appendBody(Zend_Json::encode($data)); + $this->jsonexit($data); + return true; }// search @@ -3816,7 +3803,7 @@ class AuthorController extends Zend_Controller_Action if($ac=='index' || empty($ac)) { - $uuid = $this->_getParam('uuid'); + $uuid = $this->_getParam('uuid'); $this->view->q=$this->_getParam('q'); if(empty($uuid)) { @@ -3963,7 +3950,7 @@ class AuthorController extends Zend_Controller_Action } } - $mfid = $this->_getParam('mfid'); + $mfid = $this->_getParam('mfid'); $this->view->q=$this->_getParam('q'); if(!empty($mfid)) @@ -3978,7 +3965,7 @@ class AuthorController extends Zend_Controller_Action } $rows = $fund->fetch($uuid,true,0); }else{ - $this->view->ct = "ct"; + $this->view->ct = "ct"; $rows = $fund->fetch($uuid,false,0,$this->_getParam('q')); } diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 0d0a72f7..83e9fc02 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -688,6 +688,7 @@ class DataController extends Zend_Controller_Action LEFT JOIN users u ON v.userid=u.id WHERE v.uuid=? AND v.changelog IS NOT NULL ORDER BY v.ts_created DESC"; + $sth = $this->db->prepare($sql); $sth->execute(array($uuid)); $rows = $sth->fetchAll(); @@ -1283,7 +1284,7 @@ class DataController extends Zend_Controller_Action function downloadAction() { $uuid=$this->_request->getParam('uuid'); - $onlineappid=$this->_request->getParam('onlineappid'); + $onlineappid=$this->_request->getParam('onlineappid'); $this->view->pageID = "account-dataorder"; if (empty($uuid)) $this->_redirect('/data'); @@ -1330,8 +1331,8 @@ class DataController extends Zend_Controller_Action $updateftp=$updateftp1=false; $this->view->md=$data; $this->view->userpass=md5('westdc'.rand(1000,9999)); - $this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week')); - $sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid); + $this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week')); + $sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid); $row=$this->db->fetchRow($sql); $datacount=$row['datacount']; if ($data['host']=='ftp.westgis.ac.cn') @@ -2001,5 +2002,6 @@ class DataController extends Zend_Controller_Action } } } + } diff --git a/application/default/views/scripts/author/apply.phtml b/application/default/views/scripts/author/apply.phtml index 6d47e87a..09711c18 100644 --- a/application/default/views/scripts/author/apply.phtml +++ b/application/default/views/scripts/author/apply.phtml @@ -30,32 +30,13 @@ $this->breadcrumb()->setSeparator(' > ');