Mambo Island Ads

I’ve just read How to code a Mambot? and written my very first Mambot.

The code is to place an island ad into a story on a Mambo site.

I’ve totally mucked about the file called components/com_content/content.php but look for the function show and find this code
[php]// show/hides the intro text
if ( $params->get( ‘introtext’ ) ) {
$row->text = $row->introtext. ( $params->get( ‘intro_only’ ) ? ” : chr(13) . chr(13) . $row->fulltext);
} else {
$row->text = $row->fulltext;
}[/php]

and change it to

[php]// show/hides the intro text
$row->fulltext = ‘{island}’ . $row->fulltext;
if ( $params->get( ‘introtext’ ) ) {
$row->text = $row->introtext. ( $params->get( ‘intro_only’ ) ? ” : chr(13) . chr(13) . $row->fulltext);
} else {
$row->text = $row->fulltext;
}[/php]

Now if you view your articles you’ll see that they have {island} in the middle. Now it’s time to write the Mambot.

First up there is a simple XML file which you can pick up from the attached zip file and the mambot itself.

[php]< ?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); $_MAMBOTS->registerFunction( ‘onBeforeDisplayContent’, ‘replaceIsland’ );

/**
* replace the Island Ad using the island mambot
*
* Usage:
* {island}
*
*/
function replaceIsland( &$row, &$params, $page )
{
$regex = “#{island}#”;

$row->text = preg_replace_callback($regex, ‘island_replacer’, $row->text);

return true;
}

function island_replacer( &$matches)
{
global $mosConfig_absolute_path;
global $sectionName;

require_once($mosConfig_absolute_path.’/includes/domit/xml_saxy_lite_parser.php’);

$parser = & new SAXY_Lite_Parser();
$attribs = $parser->parseAttributes($matches[2]);

//code pinched from mod_maxmediamanager
if (!isset($sectionName)) $sectionName = ‘global’;

require_once($mosConfig_absolute_path .’/administrator/max/phpadsnew.inc.php’);
if (!isset($phpAds_context)) $phpAds_context = array();
//zone is hard coded
$phpAds_raw = view_raw (‘zone:2’, 0, ‘_blank’, $sectionName, ‘0’, $phpAds_context);

//sub out the bad words
$str = str_replace(‘adclick.php’, ‘max.php’, $phpAds_raw[‘html’]);
$str = str_replace(‘adimage.php’, ‘image.php’, $str);

return “

{$str}

“;
}
?>[/php]
I’m using phpAdsNew to manage the ads and stripping out bad strings, hard coding the zone etc when infact the zone can be parameters.

All that’s needed then is to install it – and publish it.

Categories

Recent Comments

Tags

2 Comments

  1. Moi
    September 23, 2005

    A simple example might be a good idea, no?
    Got a link?

  2. September 23, 2005

    This was implemented over at PropertyTalk but isn’t available right now. When I posted this it was pre-release and was live for a bit. Then the content component was swapped for one that allows comments. I need to reapply this hack.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.