[Solved]: Adding Adsense, but only on content based pages [Solved]: Adding Adsense, but only on content based pages
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

[Solved]: Adding Adsense, but only on content based pages

Started by twistedcain, May 08, 2008, 09:48:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

twistedcain

I already have the template modified to fit the ads, I need help in showing alternative content on pages that don't fit the Adsense guidelines.

Adsense Program Policies,
"No Google ad may be placed on any non-content-based pages." (error pages, search page, login, messages, while I'm logged in as admin, and so on)

I have two ways to go about this, select which pages are allowed to show ads or select which pages to not allow ads. Whichever is easier preferably. I'm hoping someone has already been through this, I searched this board for about a half hour and couldn't seem to find anything. I apologize if my question has already been answered.

I was considering using $_SERVER['PHP_SELF'] to check for "index.php", "thumbnails.php", and "displayimage.php", but this creates a problem with "No image to display" pages. Is there a variable I can check that will tell me if a page has no image to display? Also, whats the best variable to check for so I can disable ads when I am in admin mode?

One more question, Adsense policies are a little fuzzy when it comes to search results, should I show ads during CPG search result pages on my site? If not, this creates another issue as the search results are from "thumbnails.php", so I would need an additional variable check. If so, what variable would tell me that I am in search results?

Joachim Müller

Edit themes/yourtheme/theme.php and inject adsense code there into the proper locations for files that will be visible for the general public only then.

twistedcain

Thanks for the reply. I was originally going to do just that but decided I wanted to put the ads in a side column and the particular theme didn't include any columns in the template. I found a solution that seems to work, in case anyone else is trying to do the same thing. I'm not a good coder, so anyone feel free to clean it up.


if (empty($_POST) && !GALLERY_ADMIN_MODE && ($_SERVER['PHP_SELF'] == 'index.php' || $_SERVER['PHP_SELF'] == 'thumbnails.php' || $_SERVER['PHP_SELF'] == 'displayimage.php' )) {
  $adsense = '{insert adsense code}';
}
else {
  $adsense = '{insert alternate code}';
}


Checking $_POST will stop the ads from showing on the search results page, or any other page that uses the post variable, which is probably a good idea anyway.

Checking for GALLERY_ADMIN_MODE seems to work, although I am not sure if this is the best method.

I have buddy lists, private messaging, members, and most other options disabled, so I don't know if those pages use "thumbnails.php" or "displayimage.php", but if you don't allow members to your gallery, then you'll be alright.


twistedcain

I forgot to check for "No image to display" and other message/error pages.

I have added the column with adsense to the "$template_sub_menu" variable on "themes.php". The problem I'm having is that both "themes.php" and "themes.inc.php" have already been parsed before any variables have been set to designate that a page has no images to display.

"thumbnails.php" includes "init.inc.php" which then includes the theme, but if the theme was included at the end of "thumbnails.php", I could modify the theme according to the variables set in "thumbnails.php". This is very frustrating because I don't know if the page has no images until the output is essentially finished. I have a feeling this is going to get complicated for me.

twistedcain

I found a solution, but it's a slapped together hack. I'll post it just so someone trying to do the same thing at least knows it's possible.

What I have been trying to do is place an Adsense block in a left-hand column using the mac_ox_x theme. If I had placed the block in the right-hand column I wouldn't have had any issues, but I am stubborn. If I were to place the block in the right-hand column, the variables for the page content (or lack thereof) would have been parsed and available to check for the Adsense column, but trying to place the ads before the info was available created an unique problem. This problem will also exist for those trying to place an Adsense block as a custom header.

Having ads not display on the search page, search results page, login pages, and while in admin mode consisted of checking some predefined variables,

empty( $_POST ) // the post variable will be passed on a search result, so if it is empty, show the ads
GALLERY_ADMIN_MODE // determines whether or not you are in admin mode, this way you can check ad content by simply switching to user mode
$_SERVER['PHP_SELF'] == 'index.php' // show ads on index.php page
$_SERVER['PHP_SELF'] == 'thumbnails.php' // show ads on thumbnails.php pages
$_SERVER['PHP_SELF'] == 'displayimage.php' // show ads on displayimage.php pages

This didn't stop ads from showing on "No image to display", message, or error pages.

---

Warning, this is how I did it, the implementation is terrible and just thrown together. It's just a reference for those curious as to how I did it.

---

init.inc.php - added the $adsense variable and set it to "0"

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg375.imageshack.us%2Fimg375%2F3892%2Fstep1vl8.gif&hash=98a21fdd3c356b2385af9a1c83a9b218c811a204)

functions.inc.php - First make $adsense variable global for function. If the "display_thumbnails" function calls the "theme_display_thumbnails" function, set $adsense variable to 1.

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg148.imageshack.us%2Fimg148%2F1329%2Fstep2ow1.gif&hash=72b4b745f85fabb650ebebb6731c34d4848f51cd)

displayimage.php - Set adsense to 1, set it back to 0 if there is any error in the next step.

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg502.imageshack.us%2Fimg502%2F2150%2Fstep3bp7.gif&hash=84f362a76d66f30f75873b443e804370d973d355)

functions.inc.php - Make the $adsense variable global, and set it to 0 if the cpg_die function is called. This should disable the ads for any errors that might happen when viewing "displayimage.php".

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg404.imageshack.us%2Fimg404%2F5659%2Fstep4ut0.gif&hash=32221d017de0e89404ee6e7db10bf5f532987f73)

themes.inc.php - Make $adsense global. Check previously mentioned conditions + check to see if $adsense variable is equal to 1. Add $adsense into template array.

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg166.imageshack.us%2Fimg166%2F8308%2Fstep5wy8.gif&hash=7330fc7726a971270f154654812444fa7afc26d4)

template.html - Define ADSENSE_COLUMN variable above </head>. Reference ADSENSE_COLUMN variable in empty div. Add javascript above </body> that will modify the javascript ADSENSE_COLUMN variable with whatever code you inserted into the php $adsense variable.

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg87.imageshack.us%2Fimg87%2F8125%2Fstep6ep2.gif&hash=327ec431bbe1cf0629a0a5b23b5b6adcfc281e98)

Do not add the slashes (\) in the docuemnt.getElementById line, I used php for my template and had to escape the '.

Joachim Müller

Thanks for posting your solution. In the future, please don't hotlink images taken as snapshot from your editor, but use the [ c o d e ]-tags (bbcode), which will allow others to use copy'n paste.