XML SiteMap

filters.php - An easy way to cleanup unwanted output.

Tired of tracing down where output was being created and keeping track of all changes to core modules, add-on components and other modules installed, I decided to just filter out the items after generation and just before page rendering.

This only requires one core hack, adding one line to index.php. [*UPDATE! I've moved all of this code into a plugin, there are no core hacks required.]

End of index.php just before the last line:

echo JResponse::toString($mainframe->getCfg('gzip'));

Add:

require('filters.php');

 Now create a file in the root called filters.php and copy this code in there: 

 filters.php

<?php
/* FILTER THE BODY BEFORE OUTPUT */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

//Get the body right before output
$body = JResponse::getBody();

/* Add your filters here */

//Add CoolIris Logo in menu
$body = str_replace('# Cooliris Galleries', '<img src="/images/coolirismenulogo.png" align="middle">Cooliris Galleries', $body);

/* End of added filters */

//Push our new body back in
JResponse::setBody($body);

Thats it!

I used the above filter to add the little CoolIris logo into the Photo's menu. The menu title is set to "# CoolIris Galleries' a unique name not used elsewhere in the site (otherwise it would get replaced by the image code!).

Now when your site is loaded your html output is filtered. You can remove "Powered By" tag lines, filter out bad words, etc.

If I had more than a couple things to filter out, I'd rewite things to use a few array's and clean up the amount of code needed per filter.

Hope its of some use to you, it was for me.