_request->getParam('title'); $filePath="http://wiki.westgis.ac.cn/api.php?format=php&action=query&prop=revisions&titles=$title&rvprop=content&redirects"; $wikifp=fopen($filePath,'r'); while (!feof($wikifp)) { $wikiLines=fgets($wikifp); $yuchuli=array('";}}}}}}','**','*'); $chulihou=array('',' ·','·'); $wikiLine=str_replace($yuchuli,$chulihou,$wikiLines); if(substr($wikiLine,0,2)=='a:') { if(strpos($wikiLine,'==')!== false){ $wikititle=mb_strstr($wikiLine,'==',false); $this->wikitransform($wikititle,$content); } }else { $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->config = Zend_Registry::get('config'); } //transform mediawiki text to local text function wikitransform($text,&$result) { if(strpos($text,'=====')!== false&&substr($text,0,1)=='=') { $wikiFont=str_replace('=====','',$text); $result.="
$wikiFont
"; }elseif(strpos($text,'====')!== false&&substr($text,0,1)=='=') { $wikiFont=str_replace('====','',$text); $result.="

$wikiFont

"; }elseif(strpos($text,'===')!== false&&substr($text,0,1)=='=') { $wikiFont=str_replace('===','',$text); $result.="

$wikiFont

"; }elseif(strpos($text,'==')!== false&&substr($text,0,1)=='=') { $wikiFont=str_replace('==','',$text); $result.="

$wikiFont

"; }elseif(strpos($text,'[[image:')!== false||strpos($text,'[[Image:')!== false) { $wimag=array('[[image:',']]','[[Image:','
','
'); $imag=str_replace($wimag,'',$text); $imag=str_replace(' ','_',$imag); $fname="http://wiki.westgis.ac.cn/api.php?format=php&action=query&prop=imageinfo&titles=image:".$imag."&iiprop=url"; $image1=unserialize(file_get_contents($fname)); $image1_keys=array_keys($image1['query']['pages']); $image2=$image1['query']['pages'][$image1_keys[count($image1_keys)-1]]; $imagurl=@$image2['imageinfo'][0]['url']; $result.=""; //$result.=print_r($image1); }elseif(substr($text,0,3)=='·[['||substr($text,0,4)=='· [['||substr($text,0,2)=='[[') { $wikia=array('·[[','· [[','[[',']]'); $wikiname=str_replace($wikia,'',$text); $result.='

'.$wikiname.'

'; }elseif(strpos($text,'[[')!== false) { $a=array('[[',']]'); $b=array('',''); $test=str_replace($a,$b,$text); preg_match_all("|<[^>]+>(.*)]+>|U",$test,$out,PREG_PATTERN_ORDER); $name=$out[1][0];//还有问题,测试遇到再解决! $alink=''; $c=array($alink,''); $result.='

'.str_replace($a,$c,$text).'

'; }elseif(strpos($text,'[http://')!== false||strpos($text,'[ http://')!== false){ $a=array('[',']'); $b=array('',''); $test=str_replace($a,$b,$text); preg_match_all("|<[^>]+>(.*)]+>|U",$test,$out,PREG_PATTERN_ORDER); $name=$out[1][0];//还有问题,测试遇到再解决! $href=''; $value=mb_strstr($name,' ',false).''; $result.=str_replace($name,$href.$value,$test); }elseif(strpos($text,'{|')!== false) { $wikitable=str_replace("{|",''; }elseif(strpos($text,'colspan')) { if(substr($text,-2)=='| '||substr($text,-2)==' |') { $wikicolspan=array(' |','| '); $colspan=array('>',''; }elseif(strpos($text,'!!')!== false||substr($text,0,1)=='!') { $thh=str_replace("!!",''; }elseif(strpos($text,'||')!== false||substr($text,0,1)=='|'&&substr($text,0,2)!=='||'&&substr($text,0,2)!=='|+'&&substr($text,0,2)!=='|-'&&substr($text,0,2)!=='|}') { $tdd=str_replace('||',''; }elseif(substr($text,0,2)=='|-') { $wikitrr=str_replace('|-','',$text); $result.=$wikitrr; }elseif(substr($text,0,2)=='|}') { $wikitables=str_replace("|}",'
',''; } }elseif(strpos($text,'|+ ')!== false) { $wikitr=str_replace('|+ ','
',$text); $result.= $wikitr.'
',$text); $wikith=str_replace('!','',$thh); $result.= $wikith.'',$text); $wikitd=str_replace('|','',$tdd); $result.= $wikitd.'
',$text); $result.= $wikitables; }elseif(substr($text,0,1)=='#') { $result.= str_replace('#',' ',$text); }elseif(strpos($text,"'''")!==false) { $result.= str_replace("'''",'',$text); }elseif(substr($text,0,1)=="*") { $result.= str_replace('*','',$text); }else { $result.= "

$text

"; } } }