修改wiki文档查看功能,修复跳转问题及图片问题

This commit is contained in:
wlx 2012-05-18 08:39:41 +00:00
parent dac47e7469
commit d8e93e9e1a
2 changed files with 19 additions and 11 deletions

View File

@ -3,7 +3,7 @@ class MetainfoController extends Zend_Controller_Action {
function indexAction() { function indexAction() {
$title=$this->_request->getParam('title'); $title=$this->_request->getParam('title');
$filePath="http://wiki.westgis.ac.cn/api.php?format=php&action=query&prop=revisions&titles=$title&rvprop=content&redirects"; $filePath="http://wiki.westgis.ac.cn/api.php?format=php&action=query&prop=revisions&titles=$title&rvprop=content&redirects";
$wikifp=fopen($filePath,r); $wikifp=fopen($filePath,'r');
while (!feof($wikifp)) { while (!feof($wikifp)) {
$wikiLines=fgets($wikifp); $wikiLines=fgets($wikifp);
$yuchuli=array('";}}}}}}','**','*'); $yuchuli=array('";}}}}}}','**','*');
@ -17,7 +17,13 @@ class MetainfoController extends Zend_Controller_Action {
}else { }else {
$this->wikitransform($wikiLine,$content); $this->wikitransform($wikiLine,$content);
} }
} }
/*$wikicontent=unserialize(file_get_contents($filePath));
$wiki_keys=array_keys($wikicontent['query']['pages']);
$content= $wikicontent['query']['pages'][$wiki_keys[0]];
$this->view->title=$content['title'];
$c1=explode('\n',$content['revisions'][0]['*']);
foreach ($c1 as $c2) $this->wikitransform($c2,$tcontent);*/
$this->view->content=$content; $this->view->content=$content;
$this->view->config = Zend_Registry::get('config'); $this->view->config = Zend_Registry::get('config');
} }
@ -37,25 +43,27 @@ class MetainfoController extends Zend_Controller_Action {
$wikiFont=str_replace('==','',$text); $wikiFont=str_replace('==','',$text);
$result.="<h2>$wikiFont</h2>"; $result.="<h2>$wikiFont</h2>";
}elseif(strpos($text,'[[image:')!== false||strpos($text,'[[Image:')!== false) { }elseif(strpos($text,'[[image:')!== false||strpos($text,'[[Image:')!== false) {
$wimag=array('[[image:',']]','[[Image:'); $wimag=array('[[image:',']]','[[Image:','<center>','</center>');
$imag=str_replace($wimag,'',$text); $imag=str_replace($wimag,'',$text);
$fname="http://wiki.westgis.ac.cn/api.php?format=php&action=query&prop=imageinfo&titles=image:$imag&iiprop=url&redirects"; $imag=str_replace(' ','_',$imag);
$imagfp=fopen($fname,r); $fname="http://wiki.westgis.ac.cn/api.php?format=php&action=query&prop=imageinfo&titles=image:".$imag."&iiprop=url";
$imagfiles=fread($imagfp,1024); $image1=unserialize(file_get_contents($fname));
$imagfile=strstr($imagfiles,'http'); $image1_keys=array_keys($image1['query']['pages']);
$imagurl=mb_strstr($imagfile,'"',true); $image2=$image1['query']['pages'][$image1_keys[count($image1_keys)-1]];
$imagurl=@$image2['imageinfo'][0]['url'];
$result.="<img src=$imagurl>"; $result.="<img src=$imagurl>";
//$result.=print_r($image1);
}elseif(substr($text,0,3)=='·[['||substr($text,0,4)=='· [['||substr($text,0,2)=='[[') { }elseif(substr($text,0,3)=='·[['||substr($text,0,4)=='· [['||substr($text,0,2)=='[[') {
$wikia=array('·[[','· [[','[[',']]'); $wikia=array('·[[','· [[','[[',']]');
$wikiname=str_replace($wikia,'',$text); $wikiname=str_replace($wikia,'',$text);
$result.='<p><a href="/metainfo/'.urlencode($wikiname).'">'.$wikiname.'</a></p>'; $result.='<p><a href="/data/wiki/'.urlencode($wikiname).'">'.$wikiname.'</a></p>';
}elseif(strpos($text,'[[')!== false) { }elseif(strpos($text,'[[')!== false) {
$a=array('[[',']]'); $a=array('[[',']]');
$b=array('<b>','</b>'); $b=array('<b>','</b>');
$test=str_replace($a,$b,$text); $test=str_replace($a,$b,$text);
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",$test,$out,PREG_PATTERN_ORDER); preg_match_all("|<[^>]+>(.*)</[^>]+>|U",$test,$out,PREG_PATTERN_ORDER);
$name=$out[1][0];//还有问题,测试遇到再解决! $name=$out[1][0];//还有问题,测试遇到再解决!
$alink='<a href="/metainfo/'.urlencode($name).'">'; $alink='<a href="/data/wiki/'.urlencode($name).'">';
$c=array($alink,'</a>'); $c=array($alink,'</a>');
$result.='<p>'.str_replace($a,$c,$text).'</p>'; $result.='<p>'.str_replace($a,$c,$text).'</p>';
}elseif(strpos($text,'[http://')!== false||strpos($text,'[ http://')!== false){ }elseif(strpos($text,'[http://')!== false||strpos($text,'[ http://')!== false){

View File

@ -86,7 +86,7 @@ else
<li id="datadoc"><a href="<?php $wikiTitle = $this->doc; <li id="datadoc"><a href="<?php $wikiTitle = $this->doc;
if(strpos($wikiTitle,'http://wiki.westgis.ac.cn/index.php/')!==false){ if(strpos($wikiTitle,'http://wiki.westgis.ac.cn/index.php/')!==false){
$title=str_replace('http://wiki.westgis.ac.cn/index.php/','',$wikiTitle); $title=str_replace('http://wiki.westgis.ac.cn/index.php/','',$wikiTitle);
echo "/metainfo/$title"; echo "/data/wiki/$title";
}else{ }else{
echo $this->doc; echo $this->doc;
}?>">数据说明文档</a></li> }?>">数据说明文档</a></li>