diff --git a/application/admin/controllers/WatermdController.php b/application/admin/controllers/WatermdController.php index cc2e8c67..687ba855 100644 --- a/application/admin/controllers/WatermdController.php +++ b/application/admin/controllers/WatermdController.php @@ -60,6 +60,51 @@ class Admin_WatermdController extends Zend_Controller_Action } $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='/\'.$pattern.'\<\/keyword\>/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); + foreach($rows as $k=>$row) + { + //do the replace + $new_data=preg_replace($pattern,$replace,$row['data']); + //防止正则错误 + if (!empty($new_data)) + { + $sql="update metadata set data=? where uuid=?"; + $this->wdb->query($sql,array($new_data,$uuid)); + $dom = new DOMDocument(); + $dom->loadXML($formdata['source']); + $title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue; + $deal['uuid']=$uuid; + $deal['title']=$title; + $this->view->deal[]=$deal; + } + } + } + } + $this->view->form=$form; + } //替换标题和英文标题到数据引用中,以标题为准 function citetitleAction() diff --git a/application/admin/views/scripts/watermd/index.phtml b/application/admin/views/scripts/watermd/index.phtml index 75af8159..ae56742d 100644 --- a/application/admin/views/scripts/watermd/index.phtml +++ b/application/admin/views/scripts/watermd/index.phtml @@ -13,8 +13,20 @@ partial('watermd/left.phtml'); ?>
-

此页面的所有功能都是对元数据进行直接处理!

-

请小心使用!

-

不要多次刷新!

+

此页面的所有功能都是对元数据库进行直接处理!请小心使用!不要多次刷新!

+
+ +

正则替换使用说明

+

+正则表达式有很强的功能,在使用前一定要进行测试。
+如替换元数据中联系地址时,正则表达式PATTERN可以设置为: + + +

+\<delPoint\>兰州市东岗西路320号\<\/delPoint\>
+
+ +替换表达式可以设置为:Donggang West Road 320 +

\ No newline at end of file diff --git a/application/admin/views/scripts/watermd/keyword.phtml b/application/admin/views/scripts/watermd/keyword.phtml new file mode 100644 index 00000000..82acea8a --- /dev/null +++ b/application/admin/views/scripts/watermd/keyword.phtml @@ -0,0 +1,45 @@ +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('后台首页'); + $this->breadcrumb('WATER元数据工具'); + $this->breadcrumb('关键词替换'); + $this->breadcrumb()->setSeparator(' > '); +?> +
+partial('watermd/left.phtml'); ?> +
+
+msg or $this->messages) :?> +
+msg) : ?> +

msg; ?>

+messages): foreach($this->messages as $msg): ?> +

+ +
+ + +form; ?> + +deal) : ?> +
+已处理数据: +deal as $deal): ?> +
    +
  • UUID:
  • +
  • +
+ +
+ + +test) : ?> +
测试结果:
+escape($this->test) ?> +
+ +
\ No newline at end of file diff --git a/application/admin/views/scripts/watermd/left.phtml b/application/admin/views/scripts/watermd/left.phtml index 7acfeb0d..3c0f9cb7 100644 --- a/application/admin/views/scripts/watermd/left.phtml +++ b/application/admin/views/scripts/watermd/left.phtml @@ -4,4 +4,5 @@
  • 文件大小处理
  • 使用声明处理
  • 联系人替换
  • +
  • 关键词替换
  • \ No newline at end of file