Created
April 4, 2012 10:39
-
-
Save mlebkowski/2300252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nassau_dice_filter($o) { | |
$preg = '/\[dice=(?<num>\d*)[kd](?<dice>\d+)\]((?<res>[^\[]*)\[\/dice\])?/i'; | |
$o->Msg = preg_replace_callback($preg, 'nassau_dice_parse', $o->Msg); | |
} | |
function nassau_dice_parse($m) { | |
if (false == empty($m['res'])) return $m[0]; | |
$dice = $m['dice']; | |
$num = $m['num'] ? $m['num'] : 1; | |
$sum = array (); | |
foreach (range(1, $num) as $_) $sum[] = rand(1, $dice); | |
$sum = implode(', ', $sum) . ' » ' . array_sum($sum); | |
return sprintf('[dice=%dd%d]%s[/dice]', $num, $dice, $sum); | |
} | |
function nassau_dice_format(&$data) { | |
$msg = $data['message']; | |
$rep = preg_replace('/\[dice=(\d*[kd]\d+)\]([^\[]+)\[\/dice\]/i', | |
'<span style="background:#0080FF;color:white;padding:1px 4px;border-radius:6px;">Rolled [$1]: $2</span>', | |
$msg); | |
$data['message'] = $rep; | |
} | |
UnbRegisterHook('post.beforeadd', 'nassau_dice_filter'); | |
UnbRegisterHook('post.beforechange', 'nassau_dice_filter'); | |
UnbRegisterHook('post.postparse', 'nassau_dice_format'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ grep -A 5 -B 5 post.before post.lib.php | |
$this->AttachDLCount = 0; | |
$this->IP = $_SERVER['REMOTE_ADDR']; | |
$this->Hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); | |
$this->SpamRating = $SpamRating; | |
UnbCallHook('post.beforeadd', $this); | |
$ok = $this->db->AddRecord(array( | |
'ID' => $this->ID, | |
'Thread' => $this->Thread, | |
'ReplyTo' => $this->ReplyTo, | |
-- | |
$this->EditCount++; | |
} | |
$this->EditReason = $EditReason; // always store edit reason, but maybe not always show it | |
} | |
UnbCallHook('post.beforechange', $this); | |
$arr = array('Subject' => $this->Subject, | |
'Msg' => $this->Msg, | |
'Options' => $this->Options, | |
'SpamRating' => $this->SpamRating); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment