1 2014-03-04 02:35:34

Topic: Manipulate Post Content Before Rendering

Is it possible to manipulate the post content before rendering? If possible, then how is the proper way to do something like this?

Morfy::factory()->addAction('before_render', function() {
    $page['content'] = str_replace('
', '
', $page['content']);


XSS Testing

tovic's Website

Re: Manipulate Post Content Before Rendering

Try to use filters for "content".

Because Murphy already applied filters for "content"
https://github.com/Awilum/morfy-cms/blo … #L497-L502

Monstra Loves You! Give some love back!

3 (edited by tovic 2014-03-04 16:32:42)

Re: Manipulate Post Content Before Rendering

Yep. I can do that this way:

Morfy::factory()->addFilter('content', function($content) {
    return str_replace('
', '
', $content);

But what about the other data? I have a plan to change the $page['tags'] results into links automatically once the tags plugin is installed. Currently, at my tags plugin, I use this way that will forces the user to rewrite their tags list in their template:

runAction('tags_links'); ?>

I want Morfy to have some ability to do something like this:

Morfy::factory()->addAction('before_render', function() {
    // Configuration data
    $config = Morfy::$config['tags_config'];
    // Get current URI segments
    $path = Morfy::factory()->getUriSegments();
    // Get post data
    $post = Morfy::factory()->getPage(Morfy::factory()->getUrl());
    $tags = array();
    if( ! empty($post['tags'])) {
        foreach(explode(',', $post['tags']) as $tag) {
            $tags[] = '' . trim($tag) . '';
    // Rewrite the `$post['tags']` data
    // change the results into clickable links
    $post['tags'] = implode($config['separator'], $tags);
    // nor this! :(
    global $page;
    $page['tags'] = implode($config['separator'], $tags);
XSS Testing

tovic's Website