Skip to content

Instantly share code, notes, and snippets.

@ringmaster
Created July 23, 2012 19:31
Show Gist options
  • Save ringmaster/3165682 to your computer and use it in GitHub Desktop.
Save ringmaster/3165682 to your computer and use it in GitHub Desktop.
Habari shorttags
public static function filter_post_content_out_7( $content, $post )
{
$regex = '%\[(\w+?)(?:\s+(.+?))?/\]|\[(\w+?)(?:\s+(.+?))?(?<!/)](?:(.*?)\[/(\w+?)])%si';
if(preg_match($regex, $content, $matches)) {
$matches = array_pad($matches, 6, '');
$code = $matches[1] . $matches[3];
$attrs = $matches[2] . $matches[4];
$code_contents = $matches[5];
preg_match_all('#(\w+)\s*=\s*(?:(["\'])?(.*?)\2|(\S+))#i', $attrs, $attr_match, PREG_SET_ORDER);
$attrs = array();
foreach($attr_match as $attr) {
$attrs[$attr[1]] = $attr[3] . $attr[4];
}
$replacement = Plugins::filter('shortcode_' . $code, $matches[0], $code, $attrs, $code_contents, $post);
$content = str_replace($matches[0], $replacement, $content);
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment