fix ticket #144, 实现元数据到word的转换

This commit is contained in:
wlx 2011-09-21 09:13:33 +00:00
parent b5e86bbd37
commit 6a6d968e97
2 changed files with 69 additions and 3 deletions

View File

@ -1263,8 +1263,74 @@ class DataController extends Zend_Controller_Action
print "<br>";
}
}
}
/*
* 转换元数据为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','<a href="$1">$2</a>',$abs);
$abs=str_replace(array("\r\n", "\n", "\r"),'</p><p>',$abs);
$abs=str_replace("'","&apos;",$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='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
$content.='<title>'.$row['title'].'</title>';
$content.='<style>
body{MARGIN-RIGHT: auto;MARGIN-LEFT: auto;font-size:14px;line-height:22px;}
span{font-size:14px;}
div{clear: both;margin: 0 auto;width:100%;vertical-align:baseline;}
#uuid{text-align: right;}
h3{font-size: 18px;}
img {border:0 none;}
a, a:visited {color:Blue;text-decoration:none;}
a:hover{text-decoration:underline;}
ul{list-style: none;margin: 0;}
ul li{list-style:none;}
#etitle{font-size:16px;margin-left:10px;}
span{font-weight:bolder;}
#content{padding:5px 0 10px 0;border:1px solid #BF5008;}
#divFooter {background-color:#BF5008;color:White;font-size:12px;padding:5px 15px;}
#divFooter a:link, #divFooter a:visited, #divFooter a:active {color:White;font-family:Arial,Serif;text-decoration:none;}
</style>
</head>
<body>';
$content.=$xslt->transformToXML($dom);
$content.="</body></html>";
$this->getResponse()->setHeader('Content-Type', 'application/vnd.ms-doc')
->setHeader('Content-Disposition','attachment; filename="'.$row['title'].'.doc"')
->setHeader('Content-Length', strlen($content))
->setHeader('Content-Type','application/force-download')
->setHeader('Content-Type','application/download')
->setHeader('Content-Description','File Transfer')
->setHeader('Content-Transfer-Encoding','binary')
->setHeader('Expires',0)
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
->setHeader('Pragma','public')
->setBody($content);
}
/**
* parse the wiki syntax used to render tables, code modified from mediawiki
*

View File

@ -139,7 +139,7 @@ endforeach;
</ul>
<hr />
<ul>
<li>元数据更新时间:<?php print date('Y-m-d',strtotime($md->ts_created)); ?> <a href="/data/xml/uuid/<?php echo $md->uuid;?>"><img src="/images/xml.gif" alt="查看XML源文件"></a></li>
<li>元数据更新时间:<?php print date('Y-m-d',strtotime($md->ts_created)); ?> <a href="/data/xml/uuid/<?php echo $md->uuid;?>"><img src="/images/xml.gif" alt="查看XML源文件"></a><a href="/data/doc/uuid/<?php echo $md->uuid; ?>"><img src="/images/doc-icon.png" alt="Word doc格式"></a></li>
<!--<li><a href="/data/detail/id/<?php echo $md->id;?>">详细元数据</a></li>-->
</ul>
</div>