diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 2de371fb..020d1368 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -255,6 +255,95 @@ class ServiceController extends Zend_Controller_Action } + /* + * 转换元数据为WORD DOC格式 + */ + public function docAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + $review=$this->_request->getParam('review'); + if (!empty($uuid)) + { + $sql="select x.data,m.title,m.description,g.id,m.projection from xml x left join metadata m on m.id=x.id left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=".$this->db->quote($uuid); + $row=$this->db->fetchRow($sql); + $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=?"; + $sql=$this->db->quoteInto($sql,$uuid); + $ref=$this->db->fetchAll($sql); + $reference='
    '; + 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.=' + + '; + $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','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); + } /* * 转换元数据为PDF格式