2 // plugin needs to work on Nucleus versions <=2.0 as well
3 if (!function_exists('removeBreaks')){
4 function removeBreaks($var) { return preg_replace("/<br \/>([\r\n])/","$1",$var); }
7 class NP_HighlightSource extends NucleusPlugin {
9 function getName() { return 'HighlightSource'; }
10 function getAuthor() { return 'nakahara21'; }
11 function getURL() { return 'http://xx.nakahara21.net'; }
12 function getVersion() { return '0.8'; }
13 function getDescription() { return 'HighlightSource'; }
14 function supportsFeature($what) {
16 case 'SqlTablePrefix':
23 $this->createOption("Li", "Show line number?", "yesno", "no");
26 function getEventList() { return array('PreItem'); }
28 function event_PreItem($data){
29 $this->currentItem = &$data["item"];
30 $this->currentItem->more = preg_replace("/(<\/hs>)<br \/>\r\n/","$1",$this->currentItem->more);
31 $this->currentItem->body = preg_replace_callback('#<hs>(.*?)<\/hs>#s', array(&$this, 'phpHighlight'), $this->currentItem->body);
32 $this->currentItem->more = preg_replace_callback('#<hs>(.*?)<\/hs>#s', array(&$this, 'phpHighlight'), $this->currentItem->more);
35 function phpHighlight($matches){
36 ini_set('highlight.string', '#CC0000'); //#CC0000 default
37 ini_set('highlight.comment', '#FF9900'); //#FF9900 default
38 ini_set('highlight.keyword', '#006600'); //#006600 default
39 ini_set('highlight.bg', '#dddddd'); //#dddddd default
40 ini_set('highlight.default', '#0000CC'); //#0000CC default
41 ini_set('highlight.html', '#000000'); //#000000 default
43 $code = trim(removeBreaks($matches[1]), "\r,\n");
45 if(substr(trim($code),0,2) != "<?"){
46 $code = "<?php\n".$code;
49 if(substr(trim($code),-2,2) != "?>"){
54 // $code = stripslashes($code);
55 $code = highlight_string($code, true);
57 $source = explode('<br />', $code);
58 for($i=0;$i<count($source);$i++){
59 $precode = $source[$i];
60 $source[$i] = $precolor.trim($source[$i])."</font>";
61 $source[$i] = preg_replace("/<font color\=\"#([a-z|A-Z|0-9]+)\"><\/font>/s"," ",$source[$i]);
62 $ppp = preg_match_all("/<font color\=\"#([a-z|A-Z|0-9]+)\">/s",$precode,$pmat,PREG_SET_ORDER);
64 $las = count($pmat) - 1;
65 $pcolor = $pmat[$las][1];
67 $precolor = '<font color="#'.$pcolor.'">';
69 $code = @join("<br />\n", $source) ;
72 $code = ereg_replace("(<code><font color\=\"#[a-z|A-Z|0-9]+\">)([\r\n])(<font color\=\"#[a-z|A-Z|0-9]+\">)<\?php<br />\n</font>", '\\1<!--hss-->', $code);
74 $code = ereg_replace("(<code><font color\=\"#[a-z|A-Z|0-9]+\">)([\r\n])", '\\1<!--hss-->', $code);
77 $code = ereg_replace("<br />\n</font><font color\=\"#([a-z|A-Z|0-9]+)\">\?></font>\n</font>\n</code>", "</font><!--hss--></font></code>", $code);
79 $code = ereg_replace("</font>\n</font>\n</code>", "</font><!--hss--></font></code>", $code);
81 if($this->getOption('Li') == 'no')
82 return '<div class="code">'.$code.'</div>';
84 $code = explode('<!--hss-->', $code);
85 $source = explode('<br />', $code[1]);
86 for($i=0;$i<count($source);$i++){
87 $source[$i] = '<li>'.trim($source[$i]).'</li>';
89 $text = '<div class="code">';
91 $text .= "<ol>". @join('', $source) . "\n</ol>";