Welcome to WebmasterWorld Guest from 54.167.216.239

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

CSS Colour Detection

     
4:04 pm on Oct 2, 2006 (gmt 0)

New User

10+ Year Member

joined:Oct 2, 2006
posts:2
votes: 0


I host a lot of Invision 1.3 forums. Often enough, members change the colors of the board, and then the google adsense code remains the same, with the same old colors (causing for a poorer EPM). I was wondering if there was a code that could detect the main CSS colors of the board and use them. If it helps, this is the code for phpBB:

<script type="text/javascript"><!--
google_ad_client = "pub-#*$!#*$!#*$!#*$!#*$!xx";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="";
google_color_border = "<?php echo $theme['body_bgcolor'];?>";
google_color_bg = "<?php echo $theme['body_tr'];?>";
google_color_link = "<?php echo $theme['body_link'];?>";
google_color_url = "<?php echo $theme['body_text'];?>";
google_color_text = "<?php echo $theme['body_text'];?>";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

6:32 pm on Oct 2, 2006 (gmt 0)

New User

10+ Year Member

joined:Sept 23, 2006
posts:21
votes: 0


I'm sure it's possible to think around this one. On my site for example, I create xml files dynamically using php. The way I do this is to include a files directive in an .htaccess file so that php will parse an .xml file extension as if it were php. For example the following will parse news.xml as if it were news.php

<Files news.xml>
ForceType application/x-httpd-php
</Files>

What I'm driving at here is that it will also be possible to do the same for css files so that the attributes etc. can be variables.

Maybe there's a clue to solving your problem there?

6:58 pm on Oct 2, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


you could check for a colour other than your default colour and then set those vars to something else

//initailize some vars
$google_color_border = '';
$google_color_bg = '';
$google_color_link = '';
$google_color_url = '';
$google_color_text = '';

// check if the user changed the theme
if ($theme['body_bgcolor'] == 'some hex colour') {
$google_color_border = $theme['body_bgcolor'];
$google_color_bg = $theme['body_tr'];
$google_color_link = $theme['body_link'];
$google_color_url = $theme['body_text'];
$google_color_text = $theme['body_text'];
} else {
// set the above vars to the default colours in this chunk
}

then echo the new vars

google_color_border = "<?php echo $google_color_border;?>";
google_color_bg = "<?php echo $google_color_bg;?>";
google_color_link = "<?php echo $google_color_link;?>";
google_color_url = "<?php echo $google_color_url;?>";
google_color_text = "<?php echo $google_color_text;?>";

I obviously don't know what colours you want to use or test for but the theory here would work

7:21 pm on Oct 2, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


...
if ($theme['body_bgcolor'] == 'some hex colour') {
...

That should be:

...
if ($theme['body_bgcolor'] != 'some hex colour') {
...
7:23 pm on Oct 2, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


ah, I see, I was thinking the theme came from the board

if they have changed it from the default board colours, then use other default ad colour

8:14 pm on Oct 2, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


No, I think you were thinking right ... But shouldn't the code check if the default is not used, and if so use the current theme colors? If, on the other hand, the default is used (the
else
part), the default ad colors should also be used.
8:27 pm on Oct 2, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


I would put the most common occurence in the if condition, whichever it is
3:02 am on Oct 4, 2006 (gmt 0)

New User

10+ Year Member

joined:Oct 2, 2006
posts:2
votes: 0


Yeah, but I've got to have a code where I don't have to specify the colours, as anyone can pick any background colour they want. I need a code like the initial code I listed (the adsense code for phpBB), where it'll automatically obtain the colours without any configuration.
4:10 am on Oct 4, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Apr 30, 2006
posts:298
votes: 0


I don't think you can check the color easily with php unless their option is stored in a database.

You could try javascript (on page load) to check the value of color and play with it from there. It would be easy enough. Google "getElementById" and css properties in javascript and you'll be good to go.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members