So with today's updated to the Forum, I also pushed out a new change to how "text formatters" work (think all the smarty template modifiers that we normally tack on to the end of say a blog post text, for converting HTML, for expanding embed tags, etc.). I built a new module feature setup for "format_string" that modules can setup in their init() and let the core know that they want to be involved in text formatting.
An example will help - so here's the new setup in jrEmbed:
// Watch for [embed] strings inside text
$_tmp = array(
'wl' => 'embed',
'label' => 'Convert Embed Tags',
'help' => 'If active, Embed Tags will be converted to the proper HTML to show the embedded item.'
);
jrCore_register_module_feature('jrCore', 'format_string', 'jrEmbed', 'jrEmbed_format_string_embed_tags', $_tmp);
Basically this registers a new function (jrEmbed_format_string_embed_tags) which gets called when the jrCore_format_string smarty variable modifier is called, and that gives it a chance to do it's work on the text and return it:
/**
* Registered core string formatter - Embed Tags
* @param string $string String to format
* @param int $quota_id Quota ID for Profile ID
* @return string
*/
function jrEmbed_format_string_embed_tags($string, $quota_id = 0)
{
// find any [jrEmbed mode="jrAudio" id="30"] and ask the module to replace it
if (strpos(' '. $string, '[')) {
$pattern = '#\[jrEmbed(([\s|=].*?)*?)\]#i';
$string = preg_replace_callback($pattern, 'jrEmbed_replace_tag', $string);
}
return $string;
}
So ALL the format options now work this way. This allows module and skin designers to simply do something like:
{$item.blog_text|jrCore_format_string:$profile_quota_id}
and then all the text formatting features (HTML, BBCode, Embed, expand @ tags, etc.) will be called by the jrCore_format_string. Modules can then add in new text features (i.e. smilies) and no changes are needed to templates.
This also allows the admin to control which formatting features are active, as they can turn each on/off at the quota level.
Let me know what you guys think.
Thanks!
--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
updated by @brian: 06/28/16 07:26:41AM