diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 28a1d412..15400ead 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1263,8 +1263,74 @@ class DataController extends Zend_Controller_Action print "
"; } - } - + } + /* + * 转换元数据为WORD DOC格式 + */ + public function docAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $ua = $_SERVER["HTTP_USER_AGENT"]; + $uuid=$this->_request->getParam('uuid'); + if (!empty($uuid)) + { + $sql="select x.data,m.title,m.description,g.id from xml x left join metadata m on m.id=x.id left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=".$this->db->quote($uuid); + $row=$this->db->fetchRow($sql); + } + + $dom = new DOMDocument(); + $dom->loadXML($row['data']); + //提前对表格进行预处理 + $abs=$this->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']; + $xslt = new XSLTProcessor(); + $xslt->registerPHPFunctions(); + $xslt->setParameter('', 'id', $id); + $xslt->setParameter('', 'abstract', $abs); + $XSL = new DOMDocument(); + $XSL->load( '../data/doc.xsl', LIBXML_NOCDATA); + $xslt->importStylesheet($XSL); + $content=' +'; + $content.=''.$row['title'].''; + $content.=' + + '; + $content.=$xslt->transformToXML($dom); + $content.=""; + $this->getResponse()->setHeader('Content-Type', 'application/vnd.ms-doc') + ->setHeader('Content-Disposition','attachment; filename="'.$row['title'].'.doc"') + ->setHeader('Content-Length', strlen($content)) + ->setHeader('Content-Type','application/force-download') + ->setHeader('Content-Type','application/download') + ->setHeader('Content-Description','File Transfer') + ->setHeader('Content-Transfer-Encoding','binary') + ->setHeader('Expires',0) + ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0') + ->setHeader('Pragma','public') + ->setBody($content); + } /** * parse the wiki syntax used to render tables, code modified from mediawiki * diff --git a/application/default/views/scripts/data/view.phtml b/application/default/views/scripts/data/view.phtml index 31af2d62..991d6633 100755 --- a/application/default/views/scripts/data/view.phtml +++ b/application/default/views/scripts/data/view.phtml @@ -139,7 +139,7 @@ endforeach;