Spoiler filter
git-svn-id: file:///home/shish/svn/shimmie2/trunk@287 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
11a7e6dca4
commit
c8186776a4
1 changed files with 37 additions and 0 deletions
37
contrib/spoiler/main.php
Normal file
37
contrib/spoiler/main.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Name: Spoiler Filter
|
||||||
|
* Author: Shish <webmaster@shishnet.org>
|
||||||
|
* Link: http://trac.shishnet.org/shimmie2/
|
||||||
|
* License: GPLv2
|
||||||
|
* Description: Adds a [spoiler] tag to rot13 text inside it
|
||||||
|
*/
|
||||||
|
class Spoiler extends Extension {
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'TextFormattingEvent')) {
|
||||||
|
$event->formatted = $this->filter($event->formatted);
|
||||||
|
$event->stripped = $this->filter($event->stripped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function filter($text) {
|
||||||
|
$l1 = strlen("[spoiler]");
|
||||||
|
$l2 = strlen("[/spoiler]");
|
||||||
|
while(true) {
|
||||||
|
$start = strpos($text, "[spoiler]");
|
||||||
|
if($start === false) break;
|
||||||
|
|
||||||
|
$end = strpos($text, "[/spoiler]");
|
||||||
|
if($end === false) break;
|
||||||
|
|
||||||
|
$beginning = substr($text, 0, $start);
|
||||||
|
$middle = str_rot13(substr($text, $start+$l1, ($end-$start-$l1)));
|
||||||
|
$ending = substr($text, $end + $l2, (strlen($text)-$end+$l2));
|
||||||
|
|
||||||
|
$text = $beginning . $middle . $ending;
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_event_listener(new Spoiler(), 45); // before bbcode, so before <br>s are inserted
|
||||||
|
?>
|
Reference in a new issue