Jump to content

Recommended Posts

Hello:

 

While checking my site error logs, I've noticed one repetitive error that fills the log file. The error is "PHP Notice:  Undefined variable: adHTML in /.../bot_jrheader.php on line 61". The code does what it's intended to do, and this error has existed nearly a year, but it's probably time to clean up the code and minimize the log file growth. I'm a novice at coding, but have a grasp of the the absolute basics. Any assistance would be appreciated.

 

Line 61 is "$adHTML .=  $adHTML_1;"

The entire file consists of the following code:

 

<?php

defined('_VALID_MOS') or die('Direct Access to this location is not allowed.') ;

$_MAMBOTS->registerFunction('onPrepareContent', 'head') ;

function head($published, &$row, &$mosParams, $page=0)

{

global $database, $mosConfig_live_site, $params;

$linksSuffix = '' ;

$query = "SELECT id FROM #__mambots WHERE element = 'bot_jrheader' AND folder = 'content'";

$database->setQuery( $query );

$id = $database->loadResult();

$mambot = new mosMambot( $database );

$mambot->load( $id );

$params =& new mosParameters( $mambot->params );

$rotate=$params->get('ad_rotate');

if ($rotate==1 ) {$rotate="true";}

else {$rotate="false";}

$adHTML_1 = "<script type=\"text/javascript\">\r\n"

. "<!--\r\n"

. "ad_ext_path = \"" . $params->get('ad_ext_path') . "\"; \r\n"

. "ad_partner = \"" . $params->get('ad_partner') . "\"; \r\n"

. "ad_width = \"" . $params->get('ad_width') . "\"; \r\n"

. "ad_height = \"" . $params->get('ad_height') . "\"; \r\n"

. "ad_max_stores = \"" . $params->get('ad_max_stores') . "\"; \r\n"

. "ad_shrink_iframe = \"" . $params->get('ad_shrink_iframe') . "\"; \r\n"

. "ad_expand_iframe = \"" . $params->get('ad_expand_iframe') . "\"; \r\n"

. "ad_style = \"" . $params->get('ad_style') . "\"; \r\n"

. "ad_topcat_id = \"" . $params->get('ad_topcat_id') . "\"; \r\n"

. "ad_prefer_multiple = \"" . $params->get('ad_prefer_multiple') . "\"; \r\n"

. "ad_channel = \"" . $params->get('ad_channel') . "\"; \r\n"

. "ad_transparent = \"" . $params->get('ad_transparent') . "\"; \r\n"

. "ad_rotate = \"" . $rotate . "\"; \r\n"

. "ad_target = \"" . $params->get('ad_target') . "\"; \r\n"

. "ad_alternate_color = \"" . $params->get('ad_alternate_color') . "\"; \r\n"

. "ad_alternate_url = \"" . $params->get('ad_alternate_url') . "\"; \r\n";

$adHTML_3 = "//--> \r\n"

. "</script>\r\n"

. "<script src=\"http://ads.justrelevant.com/show_ad.js\" type=\"text/javascript\"></script>\r\n";

$regex = "/{(Mosjrheader)\s*(.*?)}/i" ;

$GLOBALS['botNewadHTML1'] = $adHTML_1 ;

$GLOBALS['botNewadHTML3'] = $adHTML_3 ;

$GLOBALS['botMosjrheaderKeywords'] = $params->get('ad_keywords') ;

$row->text = preg_replace_callback( $regex, 'botMosjrheader_replacer', $row->text );

unset($GLOBALS['botNewadHTML1']);

unset($GLOBALS['botNewadHTML3']);

unset($GLOBALS['botMosjrheaderKeywords']);

return true ;

}

function botMosjrheader_replacer( &$matches ) {

global $params;

$NewadParams = explode("|", $matches[2]) ;

if (sizeof($NewadParams) > 0) {

$mykeyword= $NewadParams[0];

$defkey = $NewadParams[1];

$align = $NewadParams[2];

}

if ($mykeyword==""){$mykeyword= $params->get('ad_keywords');}

if ($defkey==""){$defkey = $params->get('ad_default_keywords');}

if ($align==""){$align = "center";}

$adHTML_1 = $GLOBALS['botNewadHTML1'];

$adHTML_3 = $GLOBALS['botNewadHTML3'];

$adHTML .=  $adHTML_1;

$adHTML .= "ad_keywords = Array(\"" . $mykeyword . "\"); \r\n";

$adHTML .= "ad_default_keywords = Array(\"" . $defkey . "\"); \r\n";

$adHTML .=  $adHTML_3;

$margin=0;

return botMosjrheader_align($align, $margin, $adHTML);

}

function botMosjrheader_align($align, $margin, $relevantAd)

{

if ($align == "none")

return "<div>".$relevantAd."</div>" ;

if ($align != "center"){

return "<div style='float:".$align."; margin-top:".$margin."px ; margin-left:".$margin."px ; margin-right:".$margin."px ; margin-bottom:".$margin."px ;'>".$relevantAd."</div>" ;}

return "<div align='center' style='margin-top:".$margin."px ; margin-bottom:".$margin."px ;'>".$relevantAd."</div>" ;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/178236-solved-undefined-variable-adhtml/
Share on other sites

Thank you for the prompt reply, Nightslyr!  Since I was given the code by a colleague at least a year ago, he has since stopped work on the project (it worked, after all).  My understanding of php code is minimal, at best, so an example entry and line number would be very helpful to me.  Thank you in advance.

Adding

if(!isset($adHTML)) $adHTML = '';

before line 61 should fix this.

 

Many thanks! That fixed this particular undefined variable, but I see another that should be addressed as well "$align = $NewadParams[2];".

 

This certainly get's me started in the right direction! Thank you both very much.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.