westdc-zf1/application/admin/controllers/WatermdController.php

442 lines
15 KiB
PHP
Raw Normal View History

<?php
class Admin_WatermdController extends Zend_Controller_Action
{
function preDispatch()
{
$this->db=Zend_Registry::get('db');
$this->view->config = Zend_Registry::get('config');
$this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages();
$this->_helper->layout->setLayout('administry');
2012-03-26 09:00:38 +00:00
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
2011-10-18 05:02:55 +00:00
set_time_limit(0);
}
function postDispatch()
{
$this->view->messages = $this->messenger->getMessages();
}
function indexAction()
{
//其他连接
}
function replaceAction()
{
//use preg_replace to replace the string
$form=new ReplaceForm();
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$pattern=$formdata["pattern"];
$form->populate($formdata);
if (substr($pattern,0,1)!='/')
{
$pattern='/'.$pattern.'/m';
}
$replace=$formdata["replace"];
if (isset($formdata["test"]))
{
$this->view->test=preg_replace($pattern,$replace,$formdata["source"]);
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
2011-10-26 02:50:09 +00:00
$this->view->deal=array();
foreach($rows as $k=>$row)
2011-10-23 10:49:56 +00:00
{
//do the replace
$new_data=preg_replace($pattern,$replace,$row['data']);
//防止正则错误
if (!empty($new_data))
{
2011-10-23 11:20:17 +00:00
$sql="update metadata set data=? where uuid='".$row['uuid']."'";
if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
2011-10-23 10:49:56 +00:00
$dom = new DOMDocument();
2011-10-23 11:20:17 +00:00
$dom->loadXML($row['data']);
2011-10-23 10:49:56 +00:00
$title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
2011-10-26 02:50:09 +00:00
$deal['uuid']=$row['uuid'];
2011-10-23 10:49:56 +00:00
$deal['title']=$title;
$this->view->deal[]=$deal;
2011-10-23 11:20:17 +00:00
}
2011-10-23 10:49:56 +00:00
}
}
}
}
$this->view->form=$form;
}
//替换关键词
function keywordAction()
{
//use preg_replace to replace the string
$form=new ReplaceForm();
$form->pattern->setLabel('原关键词');
$form->replace->setLabel('替换关键词');
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$pattern=$formdata["pattern"];
$form->populate($formdata);
//if (substr($pattern,0,1)!='/')
{
$pattern='/\<keyword\>'.$pattern.'\<\/keyword\>/m';
}
$replace='<keyword>'.$formdata["replace"].'</keyword>';
if (isset($formdata["test"]))
{
$this->view->test=preg_replace($pattern,$replace,$formdata["source"]);
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
2011-10-23 11:20:17 +00:00
$this->view->deal=array();
2011-10-23 10:49:56 +00:00
foreach($rows as $k=>$row)
{
//do the replace
$new_data=preg_replace($pattern,$replace,$row['data']);
//防止正则错误
if (!empty($new_data))
{
2011-10-23 11:20:17 +00:00
$sql="update metadata set data=? where uuid='".$row['uuid']."'";
if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
$dom = new DOMDocument();
2011-10-23 11:20:17 +00:00
$dom->loadXML($row['data']);
$title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
2011-10-23 11:20:17 +00:00
}
}
}
}
}
$this->view->form=$form;
}
//替换标题和英文标题到数据引用中,以标题为准
function citetitleAction()
{
$form=new ReplaceForm();
$form->setElements(array($form->source,$form->test,$form->submit));
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$form->populate($formdata);
if (isset($formdata["test"]))
{
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$title_en_path=$xpath->query("//Metadata/dataIdInfo/idCitation/resAltTitle");
$title_en=$title_en_path->item(0)->nodeValue;
$otherCitDet=$xpath->query("//Metadata/dataIdInfo/idCitation/otherCitDet");
$other=$otherCitDet->item(0)->nodeValue;
$other_cn=mb_strstr($other,'[',true);
$title_o=mb_strstr($other_cn,'.',false);
$title_ol=substr($title_o,1,-4);
$title_old=mb_strstr($title_ol,'.',true);
$other_eng=mb_strstr($other,'[',false);
$titlen_o=mb_strstr($other_eng,'.',false);
$titlen_ol=substr($titlen_o,1,-4);
$titlen_old=mb_strstr($titlen_ol,',',true);
$new_other=str_replace(array($title_old,$titlen_old),array($title,$title_en),$other);
$otherCitDet->item(0)->nodeValue=$new_other;
$this->view->test= $dom->saveXML($root->item(0));
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
2011-10-23 11:20:17 +00:00
$this->view->deal=array();
foreach($rows as $k=>$row)
{
//do the replace
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$uuid = $row['uuid'];
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$title_en_path=$xpath->query("//Metadata/dataIdInfo/idCitation/resAltTitle");
$title_en=$title_en_path->item(0)->nodeValue;
$otherCitDet=$xpath->query("//Metadata/dataIdInfo/idCitation/otherCitDet");
$other=$otherCitDet->item(0)->nodeValue;
$other_cn=mb_strstr($other,'[',true);
$title_o=mb_strstr($other_cn,'.',false);
$title_ol=substr($title_o,1,-4);
$title_old=mb_strstr($title_ol,'.',true);
$other_eng=mb_strstr($other,'[',false);
$titlen_o=mb_strstr($other_eng,'.',false);
$titlen_ol=substr($titlen_o,1,-4);
$titlen_old=mb_strstr($titlen_ol,',',true);
$new_other=str_replace(array($title_old,$titlen_old),array($title,$title_en),$other);
$otherCitDet->item(0)->nodeValue=$new_other;
$new_data = $dom->saveXML($root->item(0));
//防止错误
if (!empty($new_data))
{
2011-10-23 11:20:17 +00:00
$sql="update metadata set data=? where uuid='".$row['uuid']."'";
if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
2011-10-23 11:20:17 +00:00
}
}
}
}
}
$this->view->form=$form;
}
//文件大小处理
function filesizeAction()
{
$form=new ReplaceForm();
$form->pattern->setLabel('文件大小');
$form->setElements(array($form->pattern,$form->source,$form->test,$form->submit));
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$form->populate($formdata);
if (isset($formdata["test"]))
{
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$transize_path=$xpath->query("//Metadata/distInfo/distTranOps/transSize");
$transize_path->item(0)->nodeValue=$formdata['pattern'];
$this->view->test= $dom->saveXML($root->item(0));
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
2011-10-20 06:56:01 +00:00
$this->view->deal=array();
$sql="select update_filesize();";
$this->db->exec($sql);
foreach($rows as $k=>$row)
{
//do the replace
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$root = $dom->getElementsByTagName('Metadata');
$uuid = $row['uuid'];
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$transize_path=$xpath->query("//Metadata/distInfo/distTranOps/transSize");
2011-10-20 06:56:01 +00:00
$sql="select filesize from metadata where uuid = ?";
$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
$row=$this->db->fetchRow($sql,array($uuid));
2011-10-20 06:56:01 +00:00
$transize_path->item(0)->nodeValue=$row->filesize;
$new_data = $dom->saveXML();
//防止错误
if (!empty($new_data))
{
2011-10-20 06:56:01 +00:00
$sql="update metadata set data=? where uuid='$uuid'";
if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
2011-10-20 06:56:01 +00:00
}
}
}
}
}
$this->view->form=$form;
}
//修改限制使用说明
//useLimit可以是多项的
function uselimitAction()
{
$form=new ReplaceForm();
$form->pattern->setLabel('使用声明');
$form->setElements(array($form->pattern,$form->source,$form->test,$form->submit));
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$form->populate($formdata);
$limit_text=$formdata['pattern'];
if (isset($formdata["test"]))
{
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$uselimits=$xpath->query("//Metadata/dataIdInfo/resConst/Consts/useLimit");
$do_uselimit=1;
foreach($uselimits as $limit)
{
//已经有声明,则不需要处理
if ($limit->nodeValue==$limit_text || (strlen($limit->nodeValue)>3))
$do_uselimit=0;
}
if ($do_uselimit==1)
{
$new_uselimit=$dom->createElement('useLimit',$limit_text);
$new_resconst=$dom->createElement('resConst');
$new_const=$dom->createElement('Consts');
$new_const->appendChild($new_uselimit);
$new_resconst->appendChild($new_const);
$desckey=$xpath->query("//Metadata/dataIdInfo/descKeys")->item(0);
$resconst=$xpath->query("//Metadata/dataIdInfo/resConst")->item(0);
if ($resconst)
$resconst->parentNode->insertBefore($new_resconst,$resconst);
else
$desckey->parentNode->insertBefore($new_resconst,$desckey);
$new_data=$dom->saveXML();
}
$this->view->test= $new_data;
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
2011-10-23 11:20:17 +00:00
$this->view->deal=array();
foreach($rows as $k=>$row)
{
//do the replace
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$root = $dom->getElementsByTagName('Metadata');
$uuid = $row['uuid'];
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$uselimits=$xpath->query("//Metadata/dataIdInfo/resConst/Consts/useLimit");
$do_uselimit=1;
foreach($uselimits as $limit)
{
//已经有声明,则不需要处理
if ($limit->nodeValue==$limit_text || (strlen($limit->nodeValue)>3))
$do_uselimit=0;
}
if ($do_uselimit==1)
{
$new_uselimit=$dom->createElement('useLimit',$limit_text);
$new_resconst=$dom->createElement('resConst');
$new_const=$dom->createElement('Consts');
$new_const->appendChild($new_uselimit);
$new_resconst->appendChild($new_const);
$desckey=$xpath->query("//Metadata/dataIdInfo/descKeys")->item(0);
$resconst=$xpath->query("//Metadata/dataIdInfo/resConst")->item(0);
if ($resconst)
$resconst->parentNode->insertBefore($new_resconst,$resconst);
else
$desckey->parentNode->insertBefore($new_resconst,$desckey);
$new_data=$dom->saveXML();
//防止错误
if (!empty($new_data))
{
2011-10-23 11:20:17 +00:00
$sql="update metadata set data=? where uuid='".$row['uuid']."'";
if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
2011-10-23 11:20:17 +00:00
}
}
}
}
}
}
$this->view->form=$form;
}
2011-10-17 16:56:45 +00:00
//联系人信息替换
function contactAction()
{
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
if (isset($formdata["test"]))
{
$this->view->test=$this->contactReplace($formdata["testxml"],$formdata);
} elseif (isset($formdata["submit"]))
{
2011-10-18 05:02:55 +00:00
$sql="select uuid,data from metadata where istemplate = 'n' and data like '%".$formdata['oldname']."%'";
2011-10-17 16:56:45 +00:00
$rows=$this->wdb->fetchAll($sql);
2011-10-18 05:02:55 +00:00
$this->view->deal=array();
foreach($rows as $row)
2011-10-17 16:56:45 +00:00
{
//do the replace
$new_data=$this->contactReplace($row["data"],$formdata);
2011-10-18 05:02:55 +00:00
//防止错误
2011-10-17 16:56:45 +00:00
if (!empty($new_data))
{
2011-10-18 05:02:55 +00:00
$sql="update metadata set data=? where uuid='".$row['uuid']."'";
if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
2011-10-17 16:56:45 +00:00
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
2011-10-18 05:02:55 +00:00
$deal['uuid']=$row['uuid'];
2011-10-17 16:56:45 +00:00
$deal['title']=$title;
$this->view->deal[]=$deal;
2011-10-18 05:02:55 +00:00
}
2011-10-17 16:56:45 +00:00
}
}
}
$this->view->formdata=$formdata;
}
}
private function contactReplace($xml,$replace)
{
$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXpath($dom);
$contacts=$xpath->query('//rpIndName');
foreach($contacts as $contact)
{
if ($contact->nodeValue==$replace['oldname'])
{
$newrpIndName=$dom->createElement('rpIndName',$replace['name']);
$newrpOrgName=$dom->createElement('rpOrgName',$replace['unit']);
$newrpCntInfo=$dom->createElement('rpCntInfo');
$newcntPhone=$dom->createElement('cntPhone');
$newrpCntInfo->appendChild($newcntPhone);
$newvoiceNum=$dom->createElement('voiceNum',$replace['voicenum']);
$newcntPhone->appendChild($newvoiceNum);
$newcntAddress=$dom->createElement('cntAddress');
$newrpCntInfo->appendChild($newcntAddress);
$newdelPoint=$dom->createElement('delPoint',$replace['delpoint']);
$newcntAddress->appendChild($newdelPoint);
2011-10-17 17:10:34 +00:00
$newcity=$dom->createElement('city',$replace['city']);
$newcntAddress->appendChild($newcity);
$newarea=$dom->createElement('adminArea',$replace['adminarea']);
$newcntAddress->appendChild($newarea);
2011-10-17 16:56:45 +00:00
$newpostCode=$dom->createElement('postCode',$replace['postcode']);
$newcntAddress->appendChild($newpostCode);
2011-10-17 17:10:34 +00:00
$newcountry=$dom->createElement('country',$replace['country']);
$newcntAddress->appendChild($newcountry);
2011-10-17 16:56:45 +00:00
$neweMailAdd=$dom->createElement('eMailAdd',$replace['email']);
$newcntAddress->appendChild($neweMailAdd);
$rporg=$xpath->query('rpOrgName',$contact->parentNode);
$contact->parentNode->removeChild($rporg->item(0));
$rpcnt=$xpath->query('rpCntInfo',$contact->parentNode);
$contact->parentNode->removeChild($rpcnt->item(0));
$contact->parentNode->insertBefore($newrpIndName,$contact);
$contact->parentNode->insertBefore($newrpOrgName,$contact);
$contact->parentNode->insertBefore($newrpCntInfo,$contact);
$contact->parentNode->removeChild($contact);
}
}
return $dom->saveXML();
}
}