Skip to content

Commit

Permalink
[Imp] Better Pangu.PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
idawnlight committed Oct 21, 2017
1 parent 208259c commit ab41eda
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function() {
<?php
if($this->is('post')||$this->is('page')){
if (!empty($this->options->switch) && in_array('PanguPHP', $this->options->switch)) {
$html_source = ob_get_contents(); ob_clean(); print pangu::do($html_source); ob_end_flush();
$html_source = ob_get_contents(); ob_clean(); print pangu($html_source); ob_end_flush();
}
}
?>
Expand Down
26 changes: 26 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,29 @@ function tranMsg($eng, $chs, $l)
{
return ($l == "0") ? $eng : $chs ;
}

/**
* Pangu.PHP
* @param string html_source
* @return string 处理完的 html_source
*/
function pangu($html_source) {
$chunks = preg_split('/(<!--<nopangu>-->.*?<!--<\/nopangu>-->|<nopangu>.*?<\/nopangu>|<pre.*?\/pre>|<textarea.*?\/textarea>)/msi', $html_source, -1, PREG_SPLIT_DELIM_CAPTURE);
$result = '';
foreach ($chunks as $c) {
if (strtolower(substr($c, 0, 19)) == '<!--<nopangu>-->') {
$c = substr($c, 19, strlen($c) - 19 - 20);
$result .= $c;
continue;
} else if (strtolower(substr($c, 0, 12)) == '<nopangu>') {
$c = substr($c, 12, strlen($c) - 12 - 13);
$result .= $c;
continue;
} else if (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') {
$result .= $c;
continue;
}
$result .= pangu::do($c);
}
return $result;
}

0 comments on commit ab41eda

Please sign in to comment.