API ShortcodeParser getter and extension points

This commit is contained in:
Jonathon Menz 2016-11-07 12:45:29 -08:00
parent 683bde6d82
commit ffd9938652

View File

@ -21,6 +21,13 @@ class ShortcodeParser extends Object {
// --------------------------------------------------------------------------------------------------------------
/**
* Registered shortcodes. Items follow this structure:
* [shortcode_name] => Array(
* [0] => class_containing_handler
* [1] => name_of_shortcode_handler_method
* )
*/
protected $shortcodes = array();
// --------------------------------------------------------------------------------------------------------------
@ -96,6 +103,15 @@ class ShortcodeParser extends Object {
if($this->registered($shortcode)) unset($this->shortcodes[$shortcode]);
}
/**
* Get an array containing information about registered shortcodes
*
* @return array
*/
public function getRegisteredShortcodes() {
return $this->shortcodes;
}
/**
* Remove all registered shortcodes.
*/
@ -540,15 +556,21 @@ class ShortcodeParser extends Object {
* @return string
*/
public function parse($content) {
$this->extend('onBeforeParse', $content);
$continue = true;
// If no shortcodes defined, don't try and parse any
if(!$this->shortcodes) return $content;
if(!$this->shortcodes) $continue = false;
// If no content, don't try and parse it
if (!trim($content)) return $content;
else if (!trim($content)) $continue = false;
// If no shortcode tag, don't try and parse it
if (strpos($content, '[') === false) return $content;
else if (strpos($content, '[') === false) $continue = false;
if ($continue) {
// First we operate in text mode, replacing any shortcodes with marker elements so that later we can
// use a proper DOM
list($content, $tags) = $this->replaceElementTagsWithMarkers($content);
@ -561,10 +583,12 @@ class ShortcodeParser extends Object {
user_error('Couldn\'t decode HTML when processing short codes', E_USER_ERRROR);
}
else {
return $content;
$continue = false;
}
}
}
if ($continue) {
// First, replace any shortcodes that are in attributes
$this->replaceAttributeTagsWithContent($htmlvalue);
@ -613,6 +637,9 @@ class ShortcodeParser extends Object {
},
$content
);
}
$this->extend('onAfterParse', $content);
return $content;
}