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('<pre>', '<pre class="prettyprint">', $page['content']);
});

???

XSS Testing <script>alert('HIYAA!!!');</script>

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('<pre>', '<pre class="prettyprint">', $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:

<?php Morfy::factory()->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();
    array_pop($path);
    // Get post data
    $post = Morfy::factory()->getPage(Morfy::factory()->getUrl());
    $tags = array();
    if( ! empty($post['tags'])) {
        foreach(explode(',', $post['tags']) as $tag) {
            $tags[] = '<a class="' . $config['classes']['tag'] . '" href="' . rtrim(Morfy::$config['site_url'], '/') . '/' . implode('/', $path) . '?' . $config['param'] . '=' . preg_replace('/\s+/', '+', trim($tag)) . '">' . trim($tag) . '</a>';
        }
    }
    sort($tags);
    // Rewrite the `$post['tags']` data
    // change the results into clickable links
    // BUT NOT WORKING!!!
    $post['tags'] = implode($config['separator'], $tags);
    // nor this! :(
    global $page;
    $page['tags'] = implode($config['separator'], $tags);
});
XSS Testing <script>alert('HIYAA!!!');</script>

tovic's Website