Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Dio on July 19, 2005, 06:48:41 PM

Title: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on July 19, 2005, 06:48:41 PM
Help For A PHP Luddite reuired, to stay inside the Adsense TOS.

I've got thus far. Its fair to say I know very little on PHP - well nothing in fact.

I've dredged through old threads where I found adding this would help to keep the adsense code off the Admin Pages and the Login Page:



if (!isset($context['admin_areas']) && $context['sub_template'] != 'login')
echo '<div align="center" class="tborder">
<script type="text/javascript"><!--
google_ad_client = "pub-0691188711472327";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="8678466755";
google_color_border = "FFCCFF";
google_color_bg = "FFCCFF";
google_color_link = "333333";
google_color_url = "333333";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>';



Which works a treat. I want to expand that somewhat so it doesn't appear on post pages and any member profile pages. I'm guessing its something to do with this bit of the code.



$context['sub_template'] != 'login')



And was wondering what the syntax would be to make that for multiple site bits like post - profile etc. Any help appreciated, this is my first ever forum, and its been a breeze so far!
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on July 21, 2005, 06:31:46 AM
!in_array($context['sub_template'], array('x', 'y', 'z'))

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on July 21, 2005, 07:23:59 AM
Can I just confirm, instead of :

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login')

I use


if (!isset($context['admin_areas']) &&  !in_array($context['sub_template'], array('x', 'y', 'z')))


in which case, x y z - is there a list of sub template names I can use there?

I already have 'login' - would it be like 'profile', 'post' ?

Thanks for the help so far
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on July 26, 2005, 09:11:52 AM
Yes.  There's no list on hand, but if you tell me what areas you want removed, I can tell you what you can use to remove them.

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on July 26, 2005, 05:36:34 PM
Awsome - basically, any user profile pages, personal message pages and the post a reply/topic page. I got admin and login covered. ;)
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on July 28, 2005, 03:29:52 AM
!in_array('profile', $context['template_layers']) && !isset($context['post_errors'])

Would be the simplest ways to check for those.

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on July 28, 2005, 04:26:42 AM
Yeah - that's got it suckered. I can stay with in the Adsesne TOS now. Sending a virtual pint or three your way now. :D
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: icfsindia on August 07, 2005, 05:07:21 AM
Thanks for all the postings of  yours.

What I understand,

Quoteif (!isset($context['admin_areas']) && $context['sub_template'] != 'login')

This will disable google adsense code from functioning in admin pages and login page.
The code is pasted after this statement with a echo' command.


Quote!in_array('profile', $context['template_layers']) &&
!isset($context['post_errors'])

This will  enable you to collect the various sub_template names like login for
login template etc.

But how and where to use this and how to obtain the list of templates.  I did
not understand..


Quoteif (!isset($context['admin_areas']) &&  !in_array($context['sub_template'],
array('x', 'y', 'z')))

This is the code that is to be used to disable the code from more than one
pages, where x, y and z are to be replaced with the relevant names of the
templates related to the pages in which the ads are to be disabled.

Please help me out

Regards
Ratnakar
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Gargoyle on August 07, 2005, 11:02:18 AM
Could you please post the entire code for this check that you and [unknown] have done such a good job at figuring for the rest of us to use Dio ?

I have been struggling with this as well and your code would make my life a ton easier.
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: icfsindia on August 07, 2005, 12:00:16 PM


   // Show the menu here, according to the menu sub template.
   template_menu();

   echo '
         </td>
      </tr>';

// Show ads only in non-mod/admin areas

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login' )
~~~~~Actual content switched off/on by the if() condition~~~~~

   echo '
<tr><td align="center" colspan="2" height="100" valign="bottom" bgcolor="#d0d0d0">

<script type="text/javascript">
google_ad_client = "pub-XXXXXXXXXXX";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="XXXXXXX";
google_color_border = "d0d0d0";
google_color_bg = "FFFFFF";
google_color_link = "000080";
google_color_url = "005177";
google_color_text = "000000";
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

</td></tr>';
~~~~~End Actual content switched off/on by the if() condition~~~~~

   // Show a random news item? (or you could pick one from news_lines...)
   if (!empty($settings['enable_news']))
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on August 07, 2005, 12:39:18 PM
That's about it - but you can use a div align and a set class as well if you like, to add the content in the style of the block the ad appears in.

However, something is going wrong somewhere for me - I'm now getting the code showing in admin areas and login pages, but not in PM and those areas. I wish I knew PHP :(
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Gargoyle on August 07, 2005, 12:46:52 PM
Very good! I am off to a great start now!

I am still confused by this one though....
!in_array('profile', $context['template_layers']) && !isset($context['post_errors'])

I tried to implement it but I get errors when I do. I must be missing something.
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on August 07, 2005, 01:37:51 PM
Quote from: Gargoyle on August 07, 2005, 12:46:52 PM
Very good! I am off to a great start now!

I am still confused by this one though....
!in_array('profile', $context['template_layers']) && !isset($context['post_errors'])

I tried to implement it but I get errors when I do. I must be missing something.

Instead of:

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login')

Use:

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login' && !in_array('profile', $context['template_layers']) && !isset($context['post_errors']))

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Gargoyle on August 07, 2005, 02:05:29 PM
Very good... Thank-you. ;D
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on August 07, 2005, 03:15:44 PM
I figured out why it had stopped working for me, and all is fine now (using old verison of the page).  :-X

Except for one last place that I'd like to remove it from. The register pages. Any ideas how? Is there one final switch to add to the above code or is it just causing more nightmares. :)

Then finally I can relax about having adsense on the forum. :)
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on August 07, 2005, 06:27:20 PM
For the registration page:

isset($context['require_agreement'])

There are other methods, but that's probably going to stand up best to upgrades.

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on August 07, 2005, 06:49:05 PM
Thanks once again. I am finally sorted this time... I promise. As far as I can see I'm now totally within the AdSense TOS. :)

I'm sure this info will be of use to quite a few people like myself - thanks for taking the time to help out a newb. :)
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: icfsindia on August 08, 2005, 12:55:41 AM
Quoteisset($context['require_agreement'])

The above code removed the ads from the search page.

A summary of what I understood.

Quoteif
(!isset($context['admin_areas'])
          --> Specifies all pages accessible only to the admin
$context['sub_template'] != 'login'
          --> Specifies login page
!in_array('profile', $context['template_layers'])
          --> Specifies profile page
!isset($context['post_errors'])
          --> Specifies postage error page
isset($context['require_agreement']))
          --> Specifies search page

What is the code for removing the ads from agreement page.  I think that is the only area that is left to be handled.

I did not read through the google TOS clearly.  Is it a requirement that we eliminate the code from the search page.

Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: icfsindia on August 08, 2005, 01:00:34 AM
Quoteif (!isset($context['admin_areas']) && $context['sub_template'] != 'login' && !in_array('profile', $context['template_layers']) && !isset($context['post_errors']) && isset($context['require_agreement']))

Hi all the code seems to have removed the ads from the calendar page also.

I want the ads to appear on the calendar page.  Is it in any way a violation of googles TOS to make ads appear on the calendar page!!!

Is my analysis that
Quote!in_array('profile', $context['template_layers'])
removes ads from calender, etc correct!!!
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: icfsindia on August 08, 2005, 01:13:55 AM
Google AdSense Program Policies
Ad Placement
Google AdSenseTM Online Standard Terms and Conditions


(v) display any Ad(s) or Link(s) on any error page, on any registration or "thank you" page (e.g., a page that thanks a user after he/she has registered with the applicable Web site), on any chat page, in any email, or on any Web page or any Web site that contains any pornographic, hate-related, violent, or illegal content;

Conclusions

Do not display ads on login, error, registration, thankyou pages.
Where was the restriction relating to displaying ads on admin pages.
however since clicking on ads by the web site publisher himself would amount to fraud, may be it would be convenient to eliminate ads appearing on admin pages.
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: icfsindia on August 08, 2005, 01:28:15 AM
Quoteif (!isset($context['admin_areas']) && $context['sub_template'] != 'login' && !in_array('profile', $context['template_layers']) && !isset($context['post_errors']) && isset($context['require_agreement']))

this removed ads from all my pages!!!!!!!!!!
Title: Getting It Off Multiple Site Pages - A solution!!!!
Post by: icfsindia on August 08, 2005, 03:29:12 AM
Quote
if (!isset($context['admin_areas'])
&& $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement']))

If       Context is not admin_areas
and   sub_template is not 'login'
and   template_layers is not 'profile'
and   Context is not post_errors
and   Context is not require_agreement

Then do the code below or move away to the next statement.

This worked fine for me for the login, admin, agreement, post and post error pages.

I think that much is what we want

Thank you all for sharing your knowledge.


If someone finds this not functioning, please post the message, since i can also modify my code to enable it to function properly.

regards
ratnakar



Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on August 08, 2005, 05:08:58 AM
That's it - just to expand it slightly for people



// Show the menu here, according to the menu sub template.
template_menu();

echo '
</div>';

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement']))

echo 'html / adsense code here';



As for it not being in Admin areas, they would be termed as non-content. Now, The only thing I'm missing now, after I believed I had it all... Is to get it off the search pages. :D
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on August 08, 2005, 12:02:57 PM
!isset($context['search_params'])

Is that what you want?

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on August 08, 2005, 03:15:57 PM
That didn't work for me, however, it made me go and look in the search template and try this:

!isset($context['simple_search'])

which did work - do you foresee any problem with that? If I knew anything about PHP I could maybe see the potential for making a mod to help with this stuff - tick what pages you want it on etc. I wouldn't know where to start though :(

Thanks again for the help!
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on August 08, 2005, 03:18:48 PM
I guess the only danger is that that may not show in search administration, where you don't want it to show anyway :P.

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Dio on August 08, 2005, 04:37:12 PM
Haha - nice one, just as well, as well :)
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Gargoyle on August 08, 2005, 07:43:00 PM
Dio could you please post your finished code. Thank-you
Title: Adsense: Getting It Off Multiple Site Pages
Post by: icfsindia on August 09, 2005, 01:03:12 AM
Quoteif (!isset($context['admin_areas'])
&& $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

If       Context is not admin_areas
and   sub_template is not 'login'
and   template_layers is not 'profile'
and   Context is not post_errors
and   Context is not require_agreement
and   Context is not search page     [Only search form and not results]

Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: bjp on August 19, 2005, 01:58:18 PM
It's working, but this gives mes errors

8: Undefined index: sub_template
Fichier: /var/www/html/site/smf/Themes/default/index.template.php
Ligne: 274

The line 274 is : && $context['sub_template'] != 'login'


with this code :

      // Show the menu here, according to the menu sub template.
      template_menu();

   echo '
   </div>';
if (!isset($context['admin_areas'])
&& $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement']))

echo '
            <br /><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-1232486685154xxx";
google_alternate_color = "f9f9f9";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="0560275031";
google_color_border = "f9f9f9";
google_color_bg = "f9f9f9";
google_color_link = "660000";
google_color_url = "000000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
            </div></td>
  </tr>
</table>';
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: bjp on August 19, 2005, 02:17:07 PM
And is it possible to deseable adsense on a private section ?
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on August 19, 2005, 09:11:56 PM
Instead of:

&& $context['sub_template'] != 'login'

Use:

&& isset($context['sub_template']) && $context['sub_template'] != 'login'

Private section as in a certain board?  Add:

&& (empty($context['current_board']) || $context['current_board'] != ###)

Where ### is the board's id.

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: bjp on August 21, 2005, 11:30:28 AM
Thank you very mutch !
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: -Scott on August 21, 2005, 11:31:43 AM
After changing this && $context['sub_template'] != 'login' (which was causing an error in the log) to this && isset($context['sub_template']) && $context['sub_template'] != 'login' it won't show on any page  now???



-Scott
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: [Unknown] on August 21, 2005, 03:19:35 PM
Sorry, you want:

&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')

Then.

-[Unknown]
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: bjp on December 11, 2005, 01:25:25 AM
I use this code not to display adsense on some part of my board, i'ts ok

if (!isset($context['admin_areas'])
&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')
&& (empty($context['current_board']) || $context['current_board'] != 4.0)
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

I do not want to display adsense on boardindex. How to do this ?
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: Sledgemoto on December 31, 2005, 04:06:19 PM
This should be a sticky. For top and bottom inclusion for 1.1 RC 2


Quote// Show the menu here, according to the menu sub template.
   template_menu();


   // The main content should go here.
   echo '
   <div id="bodyarea" style="padding: 1ex 0px 2ex 0px;">';
   if (!isset($context['admin_areas'])
&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')
&& (empty($context['current_board']) || $context['current_board'] != 4.0)
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

echo '
            <br /><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-1053276976865774";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel ="9826615372";
google_color_border = "000000";
google_color_bg = "F0F0F0";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
            </div></td>
  </tr>
</table>';
}

function template_main_below()
{
   global $context, $settings, $options, $scripturl, $txt;

    echo '
   </div>';
if (!isset($context['admin_areas'])
&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')
&& (empty($context['current_board']) || $context['current_board'] != 4.0)
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

echo '
            <br /><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-1053276976865774";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel ="9826615372";
google_color_border = "000000";
google_color_bg = "F0F0F0";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
            </div></td>
  </tr>
</table>';
   

   // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!
   echo '



as seen here http://talkingautosurfs.com
Title: Re: Adsense issues - Getting It Off Multiple Site Pages
Post by: SteveWh on October 04, 2007, 06:08:52 AM
Sorry to resurrect such an old topic, but it's exactly what my question is about.

Instead of specifying a long list of pages where AdSense should not be put, I made a very short list of the pages were I do want it:

Only Board indexes and Topic display pages.

After examining the code, here's the test I came up with:

[Edited: Added 2nd line to eliminate ads from the Modify Message, New Topic, and any error page.]

if ((isset($context['current_topic']) || isset($context['current_board']))
    && !isset($context['message']) && !isset($context['post_errors']))...

It does seem to be accomplishing what it's supposed to, but is there anything about it that is bad?

I'm trying to add the main forum index page to the list without adding anything else, but haven't found a way yet.