Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: _Ziggy_ on November 13, 2009, 03:11:09 PM

Title: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 13, 2009, 03:11:09 PM
I am using AdSense on my forum.
The forum also has a "0 posts" membergroup who can see just 1 board, the "introduce yourself board".
Because there's only one board for those members, they get to see a lot of ads. This is very anoying so I want to exclude some of the ads for the "0 posts" membergroup.

What do I have to ad to my code, (the "0 posts" membergroup is membergroup 4).
This is the code that I am using for the ads:

echo '
  <div><br /><script type="text/javascript"><!--
google_ad_client = "pub-*************************";
/* 728x90, gemaakt 28-2-09 na infocenter */
google_ad_slot = "7162697257";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
  ';
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 14, 2009, 03:03:52 PM
I am using this code now:


if (in_array(0,1,2,3,4,5,6,7,8,9,10,11,12, $user_info['groups']))   
{
echo '
  <div><br /><script type="text/javascript"><!--
google_ad_client = "pub-*************************";
/* 728x90, gemaakt 28-2-09 na infocenter */
google_ad_slot = "7162697257";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
   ';   
   }
   else   
   {       
   echo 'geen advertentie!';
   }


I cannot figure out why the ads never show up.
I have a testaccount which is a member of post-related-group 4, but it stil shows 'geen advertentie" instead of the ad.
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 20, 2009, 05:40:42 AM
Try that first line as:
if (in_array(array(0,1,2,3,4,5,6,7,8,9,10,11,12), $user_info['groups']))

You might consider reducing that list; 1 = admin, 2 = global moderator.
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 20, 2009, 05:57:00 AM
Thanks for your very fast answer!

I have reduced the line (it is just a testforum).

Now it is like this:
if (in_array(array(2,3,4,5,6), $user_info['groups'])) 

The ad still doesn't show up to my test account which is in group 4.

Here is a larger part of the code from the index.template:
// Show the menu here, according to the menu sub template.
template_menu();

//Google Adsense
if (in_array(array(2,3,4,5,6), $user_info['groups'])) 
{
echo '
  <div><br /><script type="text/javascript"><!--
google_ad_client = "pub-0096549331063923";
/* Bluesforum.com 728x90, gemaakt 28-2-09 na infocenter */
google_ad_slot = "7162697257";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
   ';   
   }
   else   
   {       
   echo 'geen advertentie!';
   }
// Google Adsense

echo '
<br class="clear" />';

// Show the navigation tree.
theme_linktree();

echo '
</div></div>';

// The main content should go here.
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 20, 2009, 08:24:17 AM
OK, just for testing purposes, before the if(in_array())... add print_r($user_info['groups']) to see a list of what groups the user is allegedly part of.
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 01:42:07 PM
I have tried adding that, but the list doesn't show up.

This is the code now:

//Google Adsense
   print_r($user_info['groups']);
if (in_array(array(2,3,4,5,6), $user_info['groups'])) 
{
echo '
  <div><br /><script type="text/javascript"><!--
google_ad_client = "pub-0096549331063923";
/* Bluesforum.com 728x90, gemaakt 28-2-09 na infocenter */
google_ad_slot = "7162697257";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
   ';   
   }
   else   
   {   
   echo 'geen advertentie!!';
   }
// Einde Adsense
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 01:46:18 PM
Anything in the error log?
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 01:55:55 PM
Yes, a lot:

QuoteGuest
********************
    Today at 07:04:30 PM
b64d34ecb76604d1e37ebf4db37a7147
Type of error: General 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated2: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argumentFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Errors.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************
    Today at 07:04:30 PM
b64d34ecb76604d1e37ebf4db37a7147
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated8: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Errors.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************
    Today at 07:04:30 PM
b64d34ecb76604d1e37ebf4db37a7147
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated8: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Errors.template.php (body_above sub template - eval?)
Line: 322 
   Guest
******************** 
    Today at 07:04:28 PM
cff9ee7166a26a48bbf873cde30867d0
Type of error: General 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated2: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argumentFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Errors.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************
    Today at 07:04:28 PM
cff9ee7166a26a48bbf873cde30867d0
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated8: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Errors.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************
    Today at 07:04:28 PM
cff9ee7166a26a48bbf873cde30867d0
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated8: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Errors.template.php (body_above sub template - eval?)
Line: 322 
   Ziggy
********************
    Today at 07:04:27 PM
e38d5c8edd7bce7df4f311bf0e84f715
Type of error: General 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated2: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argumentFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/GenericMenu.template.php (body_above sub template - eval?)
Line: 323 
   Ziggy
********************
    Today at 07:04:27 PM
e38d5c8edd7bce7df4f311bf0e84f715
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated8: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/GenericMenu.template.php (body_above sub template - eval?)
Line: 323 
   Ziggy
********************
    Today at 07:04:27 PM
e38d5c8edd7bce7df4f311bf0e84f715
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;updated8: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/GenericMenu.template.php (body_above sub template - eval?)
Line: 322 
   Guest
********************
    Today at 07:04:12 PM
2a038db96779fd1f5e2da6fee96e3ff8
Type of error: General 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;u=12: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argumentFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Login.template.php (body_above sub template - eval?)
Line: 323 
   Guest
******************** 
    Today at 07:04:12 PM
2a038db96779fd1f5e2da6fee96e3ff8
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;u=18: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Login.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************
    Today at 07:04:12 PM
2a038db96779fd1f5e2da6fee96e3ff8
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;u=18: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Login.template.php (body_above sub template - eval?)
Line: 322 
   Guest
********************
    Today at 07:04:10 PM
1d0aad0ce027b4c3293b63987d200214
Type of error: General 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;u=12: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argumentFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Login.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************
    Today at 07:04:10 PM
1d0aad0ce027b4c3293b63987d200214
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;u=18: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Login.template.php (body_above sub template - eval?)
Line: 323 
   Guest
********************   
    Today at 07:04:10 PM
1d0aad0ce027b4c3293b63987d200214
Type of error: Undefined 
http://www.bluesforum.com/testforum2.0rc1/index.php?action=profile;area=account;u=18: Undefined variable: user_infoFile: /chroot/home/bluesfor/bluesforum.com/html/testforum2.0rc1/Themes/default/Login.template.php (body_above sub template - eval?)
Line: 322 
  Check all 
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 02:00:16 PM
What's all the references to Bestand ?
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 02:06:43 PM
"Bestand" is Dutch for "File".
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 02:09:07 PM
Hmm, curious then. Seems to be saying that $user_info['groups'] isn't an array, which is very weird indeed, since it should ALWAYS be an array with at least two items in.
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 02:11:28 PM
I have switched the forumlanguage to English and added a new error log to the post above.
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 02:28:22 PM
Ahhhhh.

Add global $user_info; above the code in question.
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 02:37:09 PM
Ok!!!!

With my test-account I see this:
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 02:47:42 PM
Hm.

What happens if you make that print_r into var_dump, i.e. var_dump($user_info['groups']) ?
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 02:53:10 PM
Now there's this result for my test-account:
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 03:05:02 PM
So there's no type juggling.

Hmm, weird, very weird, unless I'm misreading what the description of in_array is supposed to do when matching an array (since I rarely use that function)

Should be doable with: (rearranging and tweaking for performance)
if (in_array(4, $user_info['groups']) || in_array(2, $user_info['groups']) || in_array(5, $user_info['groups']) || in_array(6, $user_info['groups']))

You could have it apply to 0 first actually since that's all regular members (including all post count groups); only those who don't have an assigned primary group (like admin, global moderator) would have 0 as a group. Also group 3 isn't a real group.
Title: Re: Do not show ads to post-related membergroup.
Post by: Marsh on November 21, 2009, 03:19:11 PM
Quote from: Arantor on November 21, 2009, 03:05:02 PM
So there's no type juggling.

Hmm, weird, very weird, unless I'm misreading what the description of in_array is supposed to do when matching an array (since I rarely use that function)

Should be doable with: (rearranging and tweaking for performance)
if (in_array(4, $user_info['groups']) || in_array(2, $user_info['groups']) || in_array(5, $user_info['groups']) || in_array(6, $user_info['groups']))

You could have it apply to 0 first actually since that's all regular members (including all post count groups); only those who don't have an assigned primary group (like admin, global moderator) would have 0 as a group. Also group 3 isn't a real group.

Worked great for me, thanks.
Title: Re: Do not show ads to post-related membergroup.
Post by: _Ziggy_ on November 21, 2009, 03:21:52 PM
That did the job!!!!!!!!!!

Thanks for solving the problem. (http://www.bluesforum.nl/smf/Smileys/classic/thumbsup.gif)(http://www.bluesforum.nl/smf/Smileys/classic/thumbsup.gif)
Title: Re: Do not show ads to post-related membergroup.
Post by: Arantor on November 21, 2009, 03:25:21 PM
You can take the var_dump line out now we figured out the problem :)

Good to see it's working though.