XOOPS RMCommon Utilities
2.1.8.91RC
|
Public Member Functions | |
add ($tag, $func) | |
atts ($pairs, $atts) | |
doCode ($content) | |
doTag ($m) | |
getRegex () | |
parseAtts ($text) | |
remove ($tag) | |
removeAll () | |
strip ($content) | |
stripTag ($m) | |
Static Public Member Functions | |
static | get () |
Private Attributes | |
$custom_codes = array() | |
This code is a modified fragment toaken from Wordpress. The idea is to provide the functionallity of shortcodes directly on XOOPS using rmcommon
Definition at line 8 of file customcode.php.
RMCustomCode::add | ( | $tag, | |
$func | |||
) |
Add hook for customcode tag.
There can only be one hook for each customcode. Which means that if another plugin has a similar customcode, it will override yours or yours will override theirs depending on which order the plugins are included and/or ran.
Simplest example of a customcode tag using the API:
// [footag foo="bar"] function footag_func($atts) { return "foo = {$atts[foo]}"; } add_customcode('footag', 'footag_func');
Example with nice attribute defaults:
// [bartag foo="bar"] function bartag_func($atts) { extract(customcode_atts(array( 'foo' => 'no foo', 'baz' => 'default baz', ), $atts));
return "foo = {$foo}"; } add_customcode('bartag', 'bartag_func');
Example with enclosed content:
// [baztag]content[/baztag] function baztag_func($atts, $content='') { return "content = $content"; } add_customcode('baztag', 'baztag_func');
string | $tag | customcode tag to be searched in post content. |
callable | $func | Hook to run when customcode is found. |
Definition at line 73 of file customcode.php.
RMCustomCode::atts | ( | $pairs, | |
$atts | |||
) |
Combine user attributes with known attributes and fill in defaults when needed.
The pairs should be considered to be all of the attributes which are supported by the caller and given as a list. The returned attributes will only contain the attributes in the $pairs list.
If the $atts list has unsupported attributes, then they will be ignored and removed from the final returned list.
array | $pairs | Entire list of supported attributes and their defaults. |
array | $atts | User defined attributes in customcode tag. |
Definition at line 271 of file customcode.php.
RMCustomCode::doCode | ( | $content | ) |
Search content for customcodes and filter customcodes through their hooks.
If there are no customcode tags defined, then the content will be returned without any filtering. This might cause issues when plugins are disabled but the customcode will still show up in the post or content.
string | $content | Content to search for customcodes |
Definition at line 123 of file customcode.php.
References $content, and getRegex().
RMCustomCode::doTag | ( | $m | ) |
Regular Expression callable for do_customcode() for calling customcode hook.
array | $m | Regular expression match array |
Definition at line 201 of file customcode.php.
References parseAtts().
|
static |
Definition at line 15 of file customcode.php.
RMCustomCode::getRegex | ( | ) |
Retrieve the customcode regular expression for searching.
The regular expression combines the customcode tags in the regular expression in a regex class.
The regular expression contains 6 different sub matches to help with parsing.
1 - An extra [ to allow for escaping customcodes with double [[]] 2 - The customcode name 3 - The customcode argument list 4 - The self closing / 5 - The content of a customcode when it wraps some content. 6 - An extra ] to allow for escaping customcodes with double [[]]
Definition at line 152 of file customcode.php.
Referenced by doCode(), and strip().
RMCustomCode::parseAtts | ( | $text | ) |
Retrieve all attributes from the customcodes tag.
The attributes list has the attribute name as the key and the value of the attribute as the value in the key/value pair. This allows for easier retrieval of the attributes, since all attributes have to be known.
string | $text |
Definition at line 232 of file customcode.php.
References elseif().
Referenced by doTag().
RMCustomCode::remove | ( | $tag | ) |
Removes hook for customcode.
string | $tag | customcode tag to remove hook for. |
Definition at line 88 of file customcode.php.
RMCustomCode::removeAll | ( | ) |
Clear all customcodes.
This function is simple, it clears all of the customcode tags by replacing the customcodes global by a empty array. This is actually a very efficient method for removing all customcodes.
Definition at line 103 of file customcode.php.
RMCustomCode::strip | ( | $content | ) |
Remove all customcode tags from the given content.
string | $content | Content to remove customcode tags. |
Definition at line 292 of file customcode.php.
References $content, and getRegex().
RMCustomCode::stripTag | ( | $m | ) |
Definition at line 302 of file customcode.php.
|
private |
Contains all custom codes registered
Definition at line 13 of file customcode.php.