June 21, 2005

Mambo Island Ads

Mambo / Joomla — Sarah King

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:
  1. // show/hides the intro text
  2. if ( $params->get( 'introtext'  ) ) {
  3.     $row->text = $row->introtext. ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext);
  4. } else {
  5.     $row->text = $row->fulltext;
  6. }

and change it to

PHP:
  1. // show/hides the intro text
  2. $row->fulltext = '{island}' . $row->fulltext;
  3. if ( $params->get( 'introtext'  ) ) {
  4.     $row->text = $row->introtext. ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext);
  5. } else {
  6.     $row->text = $row->fulltext;
  7. }

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:
  1. <?php
  2.  
  3. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  4.  
  5. $_MAMBOTS->registerFunction( 'onBeforeDisplayContent', 'replaceIsland' );
  6.  
  7. /**
  8. * replace the Island Ad using the island mambot
  9. *
  10. * <b>Usage:</b>
  11. * <code>{island}</code>
  12. *
  13. */
  14. function replaceIsland( &$row, &$params, $page )
  15. {
  16.   $regex = "#{island}#";
  17.    
  18.   $row->text = preg_replace_callback($regex, 'island_replacer', $row->text);
  19.  
  20.   return true;
  21. }
  22.  
  23. function island_replacer( &$matches)
  24. {
  25.     global $mosConfig_absolute_path;
  26.     global $sectionName;
  27.    
  28.      require_once($mosConfig_absolute_path.'/includes/domit/xml_saxy_lite_parser.php');
  29.      
  30.       $parser = & new SAXY_Lite_Parser();
  31.       $attribs = $parser->parseAttributes($matches[2]);
  32.      
  33.  
  34.    
  35.     //code pinched from mod_maxmediamanager
  36.     if (!isset($sectionName)) $sectionName = 'global';
  37.  
  38.     require_once($mosConfig_absolute_path .'/administrator/max/phpadsnew.inc.php');
  39.     if (!isset($phpAds_context)) $phpAds_context = array();
  40.     //zone is hard coded
  41.     $phpAds_raw = view_raw ('zone:2', 0, '_blank', $sectionName, '0', $phpAds_context);
  42.    
  43.     //sub out the bad words
  44.     $str = str_replace('adclick.php', 'max.php', $phpAds_raw['html']);
  45.     $str = str_replace('adimage.php', 'image.php', $str);
  46.    
  47.     return "<div id='island_outer'>{$str}</div>";
  48. }
  49. ?>

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.

Also on this site

2 Comments »

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

    Comment by Moi — September 23, 2005 @ 7:23 am

  2. 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.

    Comment by sarahk — September 23, 2005 @ 9:51 am

Leave a comment

RSS feed for comments on this post. TrackBack URI

Search

Pages

Categories:

Other Resources

Subscribe in NewsGator Online
GeoURL