...

View Full Version : Trying to change the value of a constant based on screen resolution



canadianjameson
07-17-2008, 07:19 PM
Hi :)

My knowledge of PHP is infantile, however I believe that What I'm looking to do is not too difficult :D

I'm trying to modify this script:

<?php

define('VL_WALLPAPER_DIR', 'wallpapers/');
define('VL_THUMBNAIL_DIR', VL_WALLPAPER_DIR.'thumbs/');

function buildWallpaperArray() {
$wallpapers=array();
$wallpapers[ 'tiled' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR;
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'tiled' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . $f;
$wallpapers[ 'tiled' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
else {
// handle automatic thumbnailing
}
}
}
closedir($dir);

$wallpapers[ 'bottom-left' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR.'bottom-left/';
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'bottom-left' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . 'bottom-left/'. $f;
$wallpapers[ 'bottom-left' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
}
}
return $wallpapers;
}

$vl_wallpapers = buildWallpaperArray();

function switch_wallpaper() {
global $vl_wallpapers;
$i = 0;
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
if( isset( $_GET[ 'thumbnail'.$i ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_GET[ 'thumbnail'.$i ];
setcookie('vl_wallpaper', $_GET[ 'thumbnail'.$i ], time() + 7000 * 24 * 60 * 60, "/");
session_write_close();
$url = remove_query_arg('thumbnail'.$i, $_SERVER[ 'REQUEST_URI'] );
wp_redirect( $url );
exit;
}
++$i;
}
}
if( isset( $_COOKIE[ 'vl_wallpaper' ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_COOKIE[ 'vl_wallpaper' ];
session_write_close();
}
}
if( function_exists('add_action') ) {
add_action( 'init', 'switch_wallpaper' );
}

function spitOutWallpaperThumbs() {
global $vl_wallpapers;
global $vl_thumbpos;
$countwallpapers = '0';

?><div id="thumbs" class="<?php
if( $vl_thumbpos == "right" )
echo 'thumbright ';
else if( $vl_thumbpos == "sidebar" )
echo 'sidebar ';
else
echo 'thumbleft ';
if( vl_get_theme_option('framedthumbs') == 'image' )
echo ' framed';
?>"><?php
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
$id = $countwallpapers;
$title = basename( $wallpaper->thumbnail, ".jpg" );
$src = $wallpaper->thumbnail;
vl_display_thumbnail( $id, $title, $src );
$countwallpapers++;
}
}
if( vl_get_theme_option( 'randomthumb' ) == "show" ) {
$id = "-1";
$title = 'Random';
$src = 'images/random.png';
vl_display_thumbnail( $id, $title, $src );
}

?></div><?php
?><script type="text/javascript"><?php
?>document.getElementById("thumbs").style.display = "block";<?php
?></script><?php

}

function vl_display_thumbnail( $id, $title, $src ) {
?><a href="#" <?php
?>onclick="changebackground(this, '<?php echo $id; ?>'); return false;" <?php
?>onkeypress="if( event.keyCode == 13 ) { changebackground(this, '<?php echo $id; ?>'); return false; }" <?php
?>><img id="thumbnail<?php echo $id; ?>" src="<?php echo get_stylesheet_directory_uri() . '/' . $src; ?>" <?php
?>alt="<?php echo $title; ?>" <?php
if( wallpaper_selection() == $id ) {
?>class="selected"<?php
}
?>/></a><?php
}

?>
so that the variable define('VL_WALLPAPER_DIR', 'wallpapers/'); is not hardcoded as it is currently, but set by this script:
<script type="text/javascript">
var wallpaperLocation;

if (screen.width == 1600)
wallpaperLocation = 'wallpapers1600/';
else if (screen.width == 1280)
wallpaperLocation = 'wallpapers1280/';
else if (screen.width == 1152)
wallpaperLocation = 'wallpapers1152/';
else if (screen.width == 1024)
wallpaperLocation = 'wallpapers1024/';
else if (screen.width == 800)
wallpaperLocation = 'wallpapers800/';
</script>

(the setting of the variables there may not be syntactically correct, but i tried my best :/

Essentially I want to be able to have the script that switches backgrounds onclick (above) choose backgrounds from a specific directory based on what the users screen resolution is.

How hard would it be to integrate the mini script into the bigger one?
(p.s: if you need the rest of the script, let me know -- there's more but i figured that was the relevant part)

Thanks a lot :)

canadianjameson
07-17-2008, 07:24 PM
would it be something like this?

<?php

if (screen.width == 1600)
define('VL_WALLPAPER_DIR', 'wallpapers1600/');
else if (screen.width == 1280)
define('VL_WALLPAPER_DIR', 'wallpapers1280/');
else if (screen.width == 1152)
define('VL_WALLPAPER_DIR', 'wallpapers1152/');
else if (screen.width == 1024)
define('VL_WALLPAPER_DIR', 'wallpapers1024/');
else if (screen.width == 800)
define('VL_WALLPAPER_DIR', 'wallpapers800/');

define('VL_THUMBNAIL_DIR', VL_WALLPAPER_DIR.'thumbs/');

function buildWallpaperArray() {
$wallpapers=array();
$wallpapers[ 'tiled' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR;
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'tiled' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . $f;
$wallpapers[ 'tiled' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
else {
// handle automatic thumbnailing
}
}
}
closedir($dir);

$wallpapers[ 'bottom-left' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR.'bottom-left/';
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'bottom-left' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . 'bottom-left/'. $f;
$wallpapers[ 'bottom-left' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
}
}
return $wallpapers;
}

$vl_wallpapers = buildWallpaperArray();

function switch_wallpaper() {
global $vl_wallpapers;
$i = 0;
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
if( isset( $_GET[ 'thumbnail'.$i ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_GET[ 'thumbnail'.$i ];
setcookie('vl_wallpaper', $_GET[ 'thumbnail'.$i ], time() + 7000 * 24 * 60 * 60, "/");
session_write_close();
$url = remove_query_arg('thumbnail'.$i, $_SERVER[ 'REQUEST_URI'] );
wp_redirect( $url );
exit;
}
++$i;
}
}
if( isset( $_COOKIE[ 'vl_wallpaper' ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_COOKIE[ 'vl_wallpaper' ];
session_write_close();
}
}
if( function_exists('add_action') ) {
add_action( 'init', 'switch_wallpaper' );
}

function spitOutWallpaperThumbs() {
global $vl_wallpapers;
global $vl_thumbpos;
$countwallpapers = '0';

?><div id="thumbs" class="<?php
if( $vl_thumbpos == "right" )
echo 'thumbright ';
else if( $vl_thumbpos == "sidebar" )
echo 'sidebar ';
else
echo 'thumbleft ';
if( vl_get_theme_option('framedthumbs') == 'image' )
echo ' framed';
?>"><?php
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
$id = $countwallpapers;
$title = basename( $wallpaper->thumbnail, ".jpg" );
$src = $wallpaper->thumbnail;
vl_display_thumbnail( $id, $title, $src );
$countwallpapers++;
}
}
if( vl_get_theme_option( 'randomthumb' ) == "show" ) {
$id = "-1";
$title = 'Random';
$src = 'images/random.png';
vl_display_thumbnail( $id, $title, $src );
}

?></div><?php
?><script type="text/javascript"><?php
?>document.getElementById("thumbs").style.display = "block";<?php
?></script><?php

}

function vl_display_thumbnail( $id, $title, $src ) {
?><a href="#" <?php
?>onclick="changebackground(this, '<?php echo $id; ?>'); return false;" <?php
?>onkeypress="if( event.keyCode == 13 ) { changebackground(this, '<?php echo $id; ?>'); return false; }" <?php
?>><img id="thumbnail<?php echo $id; ?>" src="<?php echo get_stylesheet_directory_uri() . '/' . $src; ?>" <?php
?>alt="<?php echo $title; ?>" <?php
if( wallpaper_selection() == $id ) {
?>class="selected"<?php
}
?>/></a><?php
}

?>
Just a guess, lol :o

p4plus2
07-17-2008, 10:59 PM
the code above would fail because php can NOT detect browser screen resolution(side effect of server side) but why can you detect browsers then? that is because the information is sent to the with the request to the server while resolution is not. screen.width wll have no effect in php.

canadianjameson
07-18-2008, 02:58 AM
Good to know :)

so okay, then can I get the screen resolution using JS and somehow have the PHP script read the variable set in the JS and use its value to set the proper directory?

I know JS and PHP work together because thats how this script functions... so i presume that this is achievable, no?

p4plus2
07-18-2008, 04:14 AM
you could try to use ajax.....get screen size then....send it back to php page to get content...though it would be slow and possibly depending on how you code it, server intense.....

canadianjameson
07-18-2008, 02:59 PM
so then this is impossible?

p4plus2
07-18-2008, 03:18 PM
I didn't say that either, I would have to say that the best way to go would be JAVASCRIPT redirects and then in noscript tags put links to all the resolutions. that would be easiest way to do it

canadianjameson
07-18-2008, 03:53 PM
:)

Okay so detecting the resolution via JS is the way to go... but then what do i do with the background script I currently have going? Is there no way to set a PHP variable externally? (i.e read from another variable)

oesxyl
07-18-2008, 04:15 PM
:)

Okay so detecting the resolution via JS is the way to go... but then what do i do with the background script I currently have going? Is there no way to set a PHP variable externally? (i.e read from another variable)
what about sending as parameters, using js, as GET variable?

PS: I apologize if I misunderstand the problem.

regards

canadianjameson
07-18-2008, 04:28 PM
sweet! How do i do that? lol

Sorry man, my coding abilities are really bad :/

I'll go do a little research but i'm going to need some guidance :)

edit: alright, I think I see how I can get the value using JS.... but how do i then pass it to the PHP script to modify the variable in question?

oesxyl
07-18-2008, 04:44 PM
sweet! How do i do that? lol

Sorry man, my coding abilities are really bad :/

I'll go do a little research but i'm going to need some guidance :)

edit: alright, I think I see how I can get the value using JS.... but how do i then pass it to the PHP script to modify the variable in question?
reload and/or redirection to a url like mypage.php?w=1024&h=728

not so sure how to do this in js, probably:


windows.location = 'http://...../mypage.php?w=1024&h=728';


and in php you put:


$w = $_GET['w'];
$h = $_GET['h'];


regards

canadianjameson
07-18-2008, 04:49 PM
This seems like a good approach but there is one snag (and maybe it's because i really don't know PHP at all).

I'm using wordpress, so I don't know how much that hamstrings me in terms of selecting which page I redirect to because I cannot have multiple URLs for the same posts... :(

is there any way to do this without affecting a change of the location?

oesxyl
07-18-2008, 05:02 PM
This seems like a good approach but there is one snag (and maybe it's because i really don't know PHP at all).

I'm using wordpress, so I don't know how much that hamstrings me in terms of selecting which page I redirect to because I cannot have multiple URLs for the same posts... :(

is there any way to do this without affecting a change of the location?
because php is server side, any change is effective only if you make a new request to the server.

don't know how this can be used in wordpress, because I don't know how wordpress work, :), but:

- you can use $_SERVER['PHP_SELF'] to to find what is the current page.
- also $_SERVER['HTTP_REFERER'] to find where the request come from.

http://www.php.net/manual/en/reserved.variables.server.php

regards

canadianjameson
07-18-2008, 05:06 PM
Okay, Thanks -- I'm going to go and look through that link and try to figure this out; I'll be back in a few hours

canadianjameson
07-18-2008, 05:46 PM
Okay I think you're on to something here. Here's how I see it going down -- please correct me if my syntax or logic is flawed (it usually is, in fact I usually speak backwards and in tongues :)

Alright, here's my setup: before wordpress is engaged we have a language selection page which provides us with the perfect opportunity here:

I will have two buttons: English and French, coded as such (bottom)


<script type="text/javascript">
if (screen.width >= 1600)
{
document.getElementById('english').href="http://www.mysite.com?w=1600";
document.getElementById('french').href="http://www.mysite.com?w=1600";
}
else if (screen.width == 1280)
{
document.getElementById('english').href="http://www.mysite.com?w=1280";
document.getElementById('french').href="http://www.mysite.com?w=1280";
}

else if (screen.width == 1152)
{
document.getElementById('english').href="http://www.mysite.com?w=1152";
document.getElementById('french').href="http://www.mysite.com?w=1152";
}

else if (screen.width == 1024)
{
document.getElementById('english').href="http://www.mysite.com?w=1024";
document.getElementById('french').href="http://www.mysite.com?w=1024";
}

else if (screen.width == 800)
{
document.getElementById('english').href="http://www.mysite.com?w=800";
document.getElementById('french').href="http://www.mysite.com?w=800";
}

</script>

<body>
<a href="http://www.mysite.com" id="english">English</a> | <a href="http://www.mysite.com" id="french">French</a>


now I think that using that script above, if my understanding of what you said is correct, I could simply do the following:


<?php

define('VL_WALLPAPER_DIR', $_GET['w'];);

how am I doing so far?

p4plus2
07-18-2008, 09:13 PM
The javascript is awesome, it will do the job you need perfectly just be sure to style the page :)

oesxyl
07-19-2008, 01:45 AM
you have two state from the language point of view, english and french, and 5 states from the width screen point of view:
1. >= 1600
2. == 1280
3. == 1152
4. == 1024
5. == 800
and you must pass to php 2 parameters, lang and w. you can compute the 'resolution state' using js or pass the screen width to php and compute there.

js code:


function nextpage(currlang){
var url = 'http://www.mysite.com?lang=' + currlang + '&w=' + screen.width;
window.location.href = url;
var newwin = window.location.href, oldwin = window;
window.open(newwin);
oldwin.close();
}


html:


<a href="#" onclick="nextpage('en')">English</a> |
<a href="#" onclick="nextpage('fr')">French</a>


in php code you must have something like this:


/* I pass directly the GET to the variables but you must check
* first if are safe using some code you want. For example I
* would restrict $lang to be only 'fr' and 'en' and w to be a positive non-zero integer
*/
$lang = $_GET['lang'];
$w = $_GET['w'];
// and now select the apropriate dir for your resolution
// first the default, for unexpected values of $w
$wpdir = 'wallpapers';
if($w == 800){
$wpdir .= '800';
}elseif($w == 1024){
$wpdir .= '1024';
// ...
}
// here $wpdir will be 'wallpapers800' for example

// this is off topic but I guess will avoid next problem, language content selection
if($lang == 'en'){
$wpdir .= 'en';
}elseif($lang == 'fr'){
$wpdir .= 'fr';
}
// here $wpdir will be 'wallpapers800en' for example
$wpdir .= '/';

// constant are really constant, :) so you must define the dirs
// where you have the wallpapers as constant
define('VL_WALLPAPER_DIR', $wpdir);

// .... rest of the code


regards

p4plus2
07-19-2008, 02:14 AM
That way also works(and is much more efficient tbh)
don't forget noscript tags too

canadianjameson
07-19-2008, 03:35 AM
That is perfect!

I am going to have to see, and unfortunately I am leaving for the weekend so I can only test this on Monday, what approaches I have at my disposal regarding language selection in WordPress because depending on the selection i have to direct users accordingly and I don't know if wordpress allows that sort of thing :(

Thank you so much for all your help, I really appreciate it. I will implement this Monday and get back to you :D:D

Cheers

canadianjameson
07-21-2008, 06:37 PM
Hey

Okay, I'm back.

I tried to change the script a little bit because while i do have 10 possibilities, the background images are the same for english and french, so we're back to having 5 possibilities.

The js didn't seem to work too well, so I'll post my code and you can see what i did (wrong, lol)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #663300;
height:100&#37;;

}
a img {
border:0;
}
#main {
display:table;
height:100%;
text-align:center;
width:100%;
}
#mainhold {
display:table-cell;
position:relative;
vertical-align:middle;
}
#pageContainer {
height:500px;
margin:auto;
position:relative;
width:600px;
top: 50%
}

-->
</style><!--[if IE]>
<style type="text/css">
#mainhold {
position:absolute;
top:50%;
left:0;
}
#pageContainer {
top:-50%;
}
</style>
<![endif]-->
<script type="text/javascript">
function nextpage(currlang){
var url = 'http://www.mysite.com?&w= + screen.width;'
window.location.href = url;
var newwin = window.location.href, oldwin = window;
window.open(newwin);
oldwin.close();
}
</script>

</head>

<body>
<div id="main">
<div id="mainhold">

<div id="pageContainer">
<img src="logo.gif" />
<br><a href="#" onclick="nextpage('en')">English</a> |
<a href="#" onclick="nextpage('fr')">French</a></div></div></div>
</body>
</html>


the new URL ended up looking like this: http://www.mysite.com/?&w=%20+%20screen.width; so obviously something went wrong somewhere :D also, it opened up a second window which just reloaded this page, and in the original window the new page was loaded

the PHP was as follows:

/* I pass directly the GET to the variables but you must check
* first if are safe using some code you want. For example I
* would restrict $lang to be only 'fr' and 'en' and w to be a positive non-zero integer
*/

$w = $_GET['w'];
// and now select the apropriate dir for your resolution
// first the default, for unexpected values of $w
$wpdir = 'wallpapers';
if($w == 800){
$wpdir .= '800';
}elseif($w == 1024){
$wpdir .= '1024';
}elseif($w == 1152){
$wpdir .= '1152';
}elseif($w == 1280){
$wpdir .= '1280';
}elseif($w >= 1600){
$wpdir .= '1600';
}

// here $wpdir will be 'wallpapers800' for example

$wpdir .= '/';

// constant are really constant, :) so you must define the dirs
// where you have the wallpapers as constant
define('VL_WALLPAPER_DIR', $wpdir);



any idea what happened?

oesxyl
07-21-2008, 06:46 PM
<script type="text/javascript">
function nextpage(currlang){
var url = 'http://www.mysite.com?&w=' + screen.width;
window.location.href = url;
var newwin = window.location.href, oldwin = window;
window.open(newwin);
oldwin.close();
}
</script>

remove ' after screen.width and put one exactly after =.

regards

canadianjameson
07-21-2008, 07:15 PM
Hey,

Cool, so that solved that! Now i got this error

session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mnt/local/home/gryphondor/gryphondor.com/wp-content/themes/vistered-little/wallpaper_functions.php:53) in /mnt/local/home/gryphondor/gryphondor.com/wp-content/themes/vistered-little/wallpaper_functions.php on line 86

:( What happened?

here's the PHP

<?php

/* I pass directly the GET to the variables but you must check
* first if are safe using some code you want. For example I
* would restrict $lang to be only 'fr' and 'en' and w to be a positive non-zero integer
*/

$w = $_GET['w'];
// and now select the apropriate dir for your resolution
// first the default, for unexpected values of $w
$wpdir = 'wallpapers';
if($w == 800){
$wpdir .= '800';
}elseif($w == 1024){
$wpdir .= '1024';
}elseif($w == 1152){
$wpdir .= '1152';
}elseif($w == 1280){
$wpdir .= '1280';
}elseif($w == 1600){
$wpdir .= '1600';
}
// here $wpdir will be 'wallpapers800' for example

$wpdir .= '/';

// constant are really constant, :) so you must define the dirs
// where you have the wallpapers as constant
define('VL_WALLPAPER_DIR', $wpdir);
define('VL_THUMBNAIL_DIR', VL_WALLPAPER_DIR.'thumbs/');

function buildWallpaperArray() {
$wallpapers=array();
$wallpapers[ 'tiled' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR;
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'tiled' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . $f;
$wallpapers[ 'tiled' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
else {
// handle automatic thumbnailing
}
}
}
closedir($dir);

$wallpapers[ 'bottom-left' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR.'bottom-left/';
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'bottom-left' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . 'bottom-left/'. $f;
$wallpapers[ 'bottom-left' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
}
}
return $wallpapers;
}

$vl_wallpapers = buildWallpaperArray();

function switch_wallpaper() {
global $vl_wallpapers;
$i = 0;
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
if( isset( $_GET[ 'thumbnail'.$i ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_GET[ 'thumbnail'.$i ];
setcookie('vl_wallpaper', $_GET[ 'thumbnail'.$i ], time() + 7000 * 24 * 60 * 60, "/");
session_write_close();
$url = remove_query_arg('thumbnail'.$i, $_SERVER[ 'REQUEST_URI'] );
wp_redirect( $url );
exit;
}
++$i;
}
}
if( isset( $_COOKIE[ 'vl_wallpaper' ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_COOKIE[ 'vl_wallpaper' ];
session_write_close();
}
}
if( function_exists('add_action') ) {
add_action( 'init', 'switch_wallpaper' );
}

function spitOutWallpaperThumbs() {
global $vl_wallpapers;
global $vl_thumbpos;
$countwallpapers = '0';

?><div id="thumbs" class="<?php
if( $vl_thumbpos == "right" )
echo 'thumbright ';
else if( $vl_thumbpos == "sidebar" )
echo 'sidebar ';
else
echo 'thumbleft ';
if( vl_get_theme_option('framedthumbs') == 'image' )
echo ' framed';
?>"><?php
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
$id = $countwallpapers;
$title = basename( $wallpaper->thumbnail, ".jpg" );
$src = $wallpaper->thumbnail;
vl_display_thumbnail( $id, $title, $src );
$countwallpapers++;
}
}
if( vl_get_theme_option( 'randomthumb' ) == "show" ) {
$id = "-1";
$title = 'Random';
$src = 'images/random.png';
vl_display_thumbnail( $id, $title, $src );
}

?></div><?php
?><script type="text/javascript"><?php
?>document.getElementById("thumbs").style.display = "block";<?php
?></script><?php

}

function vl_display_thumbnail( $id, $title, $src ) {
?><a href="#" <?php
?>onclick="changebackground(this, '<?php echo $id; ?>'); return false;" <?php
?>onkeypress="if( event.keyCode == 13 ) { changebackground(this, '<?php echo $id; ?>'); return false; }" <?php
?>><img id="thumbnail<?php echo $id; ?>" src="<?php echo get_stylesheet_directory_uri() . '/' . $src; ?>" <?php
?>alt="<?php echo $title; ?>" <?php
if( wallpaper_selection() == $id ) {
?>class="selected"<?php
}
?>/></a><?php
}

?>

oesxyl
07-21-2008, 07:25 PM
Hey,

Cool, so that solved that! Now i got this error

session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mnt/local/home/gryphondor/gryphondor.com/wp-content/themes/vistered-little/wallpaper_functions.php:53) in /mnt/local/home/gryphondor/gryphondor.com/wp-content/themes/vistered-little/wallpaper_functions.php on line 86

well, I know the message but I don't know the cure because I never use wordpress.
wp_redirect is probably involved here. The idea is that you can't output anything before sending headers, including session cache limiter in this case.

maybe p4plus2 or somebody else who have experience with wp could help. I look over posted code but I don't have any clue.
regards

canadianjameson
07-21-2008, 08:27 PM
Thanks for everything :)

I will wait for a wordpress person to help

oesxyl
07-21-2008, 08:34 PM
Thanks for everything :)

I will wait for a wordpress person to help
you are welcome, :)

I will watch the thread and if I can I will try to help.

regards

p4plus2
07-21-2008, 08:53 PM
well, I know the message but I don't know the cure because I never use wordpress.
wp_redirect is probably involved here. The idea is that you can't output anything before sending headers, including session cache limiter in this case.

maybe p4plus2 or somebody else who have experience with wp could help. I look over posted code but I don't have any clue.
regards
Sorry I can not help, I know very little of word press other than minor things from people asking me or telling me.

scoop_987
07-21-2008, 10:10 PM
Hmm... Session headers already sent? erm... looked over the posted code and see multiple session_start();

but i dont understand this? WP is confusing...

but ill look even more and see what i can find

Edit:
Just had a look at that script you posted, and looks like session_start(); is being called later on in the script that we cant see, so can you post all the pages that this inculdes or this is included into?

canadianjameson
07-22-2008, 08:37 PM
Can I! :D:D

Okay, the simplest way for me to do this is a two-step approach:
firstly: http://themes.wordpress.net/columns/1-column/701/vistered-little-1/ this is where the theme can be downloaded and it contains all of the relevant files :D (it's small)

now the files which I have modified are as follows:
wallpaper_functions.php

<?php

/* I pass directly the GET to the variables but you must check
* first if are safe using some code you want. For example I
* would restrict $lang to be only 'fr' and 'en' and w to be a positive non-zero integer
*/

$w = $_GET['w'];
// and now select the apropriate dir for your resolution
// first the default, for unexpected values of $w
$wpdir = 'wallpapers';
if($w == 800){
$wpdir .= '800';
}elseif($w == 1024){
$wpdir .= '1024';
}elseif($w == 1152){
$wpdir .= '1152';
}elseif($w == 1280){
$wpdir .= '1280';
}elseif($w == 1600){
$wpdir .= '1600';
}
// here $wpdir will be 'wallpapers800' for example

$wpdir .= '/';

// constant are really constant, :) so you must define the dirs
// where you have the wallpapers as constant
define('VL_WALLPAPER_DIR', $wpdir);
define('VL_THUMBNAIL_DIR', VL_WALLPAPER_DIR.'thumbs/');

function buildWallpaperArray() {
$wallpapers=array();
$wallpapers[ 'tiled' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR;
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'tiled' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . $f;
$wallpapers[ 'tiled' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
else {
// handle automatic thumbnailing
}
}
}
closedir($dir);

$wallpapers[ 'bottom-left' ] = array();
$d=dirname(__FILE__).'/'.VL_WALLPAPER_DIR.'bottom-left/';
$dir = opendir($d);
while ($f = readdir($dir)) {
$matches = null;
if (eregi("(.*)\.jpg",$f,$matches)) {
if( file_exists( dirname(__FILE__).'/'.VL_THUMBNAIL_DIR . $f ) ) {
$wallpapers[ 'bottom-left' ][$matches[1]]->wallpaper = VL_WALLPAPER_DIR . 'bottom-left/'. $f;
$wallpapers[ 'bottom-left' ][$matches[1]]->thumbnail = VL_THUMBNAIL_DIR . $f;
}
}
}
return $wallpapers;
}

$vl_wallpapers = buildWallpaperArray();

function switch_wallpaper() {
global $vl_wallpapers;
$i = 0;
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
if( isset( $_GET[ 'thumbnail'.$i ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_GET[ 'thumbnail'.$i ];
setcookie('vl_wallpaper', $_GET[ 'thumbnail'.$i ], time() + 7000 * 24 * 60 * 60, "/");
session_write_close();
$url = remove_query_arg('thumbnail'.$i, $_SERVER[ 'REQUEST_URI'] );
wp_redirect( $url );
exit;
}
++$i;
}
}
if( isset( $_COOKIE[ 'vl_wallpaper' ] ) ) {
session_start();
$_SESSION[ 'vl_wallpaper'] = $_COOKIE[ 'vl_wallpaper' ];
session_write_close();
}
}
if( function_exists('add_action') ) {
add_action( 'init', 'switch_wallpaper' );
}

function spitOutWallpaperThumbs() {
global $vl_wallpapers;
global $vl_thumbpos;
$countwallpapers = '0';

?><div id="thumbs" class="<?php
if( $vl_thumbpos == "right" )
echo 'thumbright ';
else if( $vl_thumbpos == "sidebar" )
echo 'sidebar ';
else
echo 'thumbleft ';
if( vl_get_theme_option('framedthumbs') == 'image' )
echo ' framed';
?>"><?php
foreach($vl_wallpapers as $pos => $wallpapers ) {
foreach( $wallpapers as $key => $wallpaper ) {
$id = $countwallpapers;
$title = basename( $wallpaper->thumbnail, ".jpg" );
$src = $wallpaper->thumbnail;
vl_display_thumbnail( $id, $title, $src );
$countwallpapers++;
}
}
if( vl_get_theme_option( 'randomthumb' ) == "show" ) {
$id = "-1";
$title = 'Random';
$src = 'images/random.png';
vl_display_thumbnail( $id, $title, $src );
}

?></div><?php
?><script type="text/javascript"><?php
?>document.getElementById("thumbs").style.display = "block";<?php
?></script><?php

}

function vl_display_thumbnail( $id, $title, $src ) {
?><a href="#" <?php
?>onclick="changebackground(this, '<?php echo $id; ?>'); return false;" <?php
?>onkeypress="if( event.keyCode == 13 ) { changebackground(this, '<?php echo $id; ?>'); return false; }" <?php
?>><img id="thumbnail<?php echo $id; ?>" src="<?php echo get_stylesheet_directory_uri() . '/' . $src; ?>" <?php
?>alt="<?php echo $title; ?>" <?php
if( wallpaper_selection() == $id ) {
?>class="selected"<?php
}
?>/></a><?php
}

?>

index.php

<?php get_header(); ?>

<div id="contentcontainer">

<?php
if ( have_posts() ) :
$post_count = 0;
while ( have_posts() ) :
++$post_count;
if( $post_count == 2 ) {
if ( vl_widget_count(__('2nd Banner', VL_DOMAIN)) > 0 ) {
?><div class="blogbefore"><?php
?><div class="left"></div><?php
?><div class="right"></div><?php
?><div class="middle"></div><?php
?></div><?php
dynamic_sidebar(__('2nd Banner', VL_DOMAIN));
?><div class="blogafter"><?php
?><div class="left"></div><?php
?><div class="right"></div><?php
?><div class="middle"></div><?php
?></div><?php
}
}
else if( $post_count == 5 ) {
if ( vl_widget_count(__('3rd Banner', VL_DOMAIN)) > 0 ) {
?><div class="blogbefore"><?php
?><div class="left"></div><?php
?><div class="right"></div><?php
?><div class="middle"></div><?php
?></div><?php
dynamic_sidebar(__('3rd Banner', VL_DOMAIN));
?><div class="blogafter"><?php
?><div class="left"></div><?php
?><div class="right"></div><?php
?><div class="middle"></div><?php
?></div><?php
}
}
the_post(); ?>

<div class="blogbefore">
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</div>
<div class="post"><div style="overflow: hidden;">
<!-- google_ad_section_start -->
<?php
if( is_page() ) {
?>
<h1><a href="<?php the_permalink(); ?>" title="<?php _e('Permalink for', VL_DOMAIN);?> <?php the_title(); ?>"><?php the_title(); ?></a></h1>

<?php
if( function_exists('smart_pages') ) {
$links = smart_pages();
if( isset( $links[ 'back' ] ) ) echo $links[ 'back' ];
}
}
else { ?>
<h1><a href="<?php the_permalink(); ?>" title="<?php _e('Permalink for', VL_DOMAIN);?> <?php the_title(); ?>"><?php the_title(); ?></a></h1>
<?php
}
the_content();
?>

<?php

?><div class="footeritems"><?php
if( !function_exists('dynamic_sidebar') || !dynamic_sidebar( __('End Of Post', VL_DOMAIN) ) ) {
$widget_args = array(
'before_widget' => '<div class="footer-item">',
'after_widget' => '<div>'
);

if(function_exists('vl_miniwidget_print')) {
vl_miniwidget_print($widget_args);
}
if( function_exists( 'vl_miniwidget_sociable' ) ) {
vl_miniwidget_sociable($widget_args);
}
if( function_exists( 'vl_miniwidget_jeromes_keywords' ) ) {
vl_miniwidget_jeromes_keywords($widget_args);
}
if( function_exists( 'vl_miniwidget_bunny_tags' ) ) {
vl_miniwidget_bunny_tags($widget_args);
}
if( function_exists('vl_miniwidget_utw_primary')) {
vl_miniwidget_utw_primary($widget_args);
}
if( function_exists('vl_miniwidget_utw_related')) {
vl_miniwidget_utw_related($widget_args);
}
if( function_exists( 'vl_miniwidget_morefromgoogle' ) ) {
vl_miniwidget_morefromgoogle($widget_args);
}
}
?><div class="editButton"><?php edit_post_link('edit.'); ?></div><?php ?></div><?php
?><p class="postlinks"><?php
next_post_link('&#37;link', '<span class="right">%title &raquo;</span>');
previous_post_link('%link', '<span class="left">&laquo; %title</span>');
?></p>
</div></div>

<div class="blogafter">
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</div>
<?php
if( function_exists( 'yatcp_comments_template' ) ) {
yatcp_comments_template();
}
else {
comments_template();
}
?>

<?php endwhile; else: ?>

<div class="blogbefore">
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</div>
<div class="post">
<h3><?php _e('There are no posts relating to your query.', VL_DOMAIN); ?></h3>
</div>

<?php endif; ?>


header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php
if( function_exists( 'is_tag' ) && is_tag() ) {
UTW_ShowCurrentTagSet('tagsettextonly');
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
else if( is_category() || is_month() || is_day() || is_year() || is_author() ) {
wp_title('',true);
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
else if (is_search()) {
echo( htmlspecialchars( stripslashes( $_GET['s'] ) ) );
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
else if ( is_page() ) {
$id = 0;
$parent;
for( $parent = &get_post($id); $parent->post_parent != 0; $parent = &get_post($parent->post_parent) ) {
echo $parent->post_title . ' &laquo; ';
}
echo $parent->post_title;
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
else if (is_single() || is_page() || is_archive()) {
wp_title('',true);
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
else if (is_404()) {
_e('Page not found', VL_DOMAIN );
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
else if( is_home() ) {
bloginfo('name'); echo(' &raquo; '); bloginfo('description');
}
else {
if( function_exists('g2_init')) {
if (!defined('G2INIT')) {
g2_init();
}
$g2data = GalleryEmbed::handleRequest();
if( !empty( $g2data[ 'themeData' ]) ) {
echo $g2data[ 'themeData' ][ 'item' ][ 'title' ];
for( $i = count( $g2data[ 'themeData' ][ 'parents' ] ); $i > 0; --$i ) {
if( $g2data[ 'themeData' ][ 'item' ][ 'id' ] != $g2data[ 'themeData' ][ 'parents' ][ $i-1 ][ 'id'] ) {
?> &laquo; <?php
echo $g2data[ 'themeData' ][ 'parents' ][$i- 1 ][ 'title' ];
}
}
echo ' ' . __('@', VL_DOMAIN) . ' ';
bloginfo('name');
}
GalleryEmbed::done();
}
else {
bloginfo('name'); echo(' &raquo; '); bloginfo('description');
}
}
?></title><?php
?><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /><?php
vl_bloglogostyle();
if( !function_exists( 'blogskinstyles' ) ) {
$url = get_stylesheet_directory_uri() . '/skins/default/style.css.php';
$ieurl = get_stylesheet_directory_uri() . '/skins/default/style-ie.css.php?skin=default';
if( function_exists( 'add_presentationtoolkit_skin_query' ) ) {
$url = add_presentationtoolkit_skin_query( 'Default', $url );
$ieurl = add_presentationtoolkit_skin_query( 'Default', $ieurl );
}
?>
<link rel="stylesheet" href="<?php echo $url; ?>" type="text/css" media="screen" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="<?php echo $ieurl; ?>" type="text/css" media="screen" />
<![endif]-->
<?php
}

if( menu_position_stylesheet_url() ) { ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); print menu_position_stylesheet_url(); ?>" type="text/css" media="screen" />
<?php } ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/wallpaper.css.php" type="text/css" media="screen" />
<?php
if( function_exists('g2_init') ) {
?><link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/wpg2.css" type="text/css" media="screen" /><?php
?><link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/siriux.css" type="text/css" media="screen" /><?php
}?>
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php
$theme = get_current_theme();
$ct = get_theme($theme);
?>
<meta name="generator" content="WordPress <?php echo $wp_version; ?>" />
<meta name="generator-version" content="<?php echo $wp_version; ?>" />
<meta name="theme" content="<?php echo $ct[ 'Title' ]; ?>" />
<meta name="theme-version" content="<?php echo $ct[ 'Version' ]; ?>" />
<?php
if( !function_exists('get_theme_option') || get_theme_option('headcredits') != 'remove' ) {
?><link rel='theme' title='Vistered Little Theme' href='http://windyroad.org/software/wordpress/vistered-little-theme' /><?php
}
?>
<script type="text/javascript">
var vl_wallpaper_count = <?php global $vl_wallpapers; echo count( array_merge( $vl_wallpapers[ 'tiled'], $vl_wallpapers['bottom-left'] ) ); ?>;
var vl_wallpaper_current = <?php echo wallpaper_selection(); ?>;
var search_phrase = "<?php echo __('Search', VL_DOMAIN) . '...'; ?>";
var search_label = "<?php _e('Type and press enter.', VL_DOMAIN); ?>";
</script>
<script src="<?php bloginfo('template_directory'); ?>/scripts/behaviour.js" type="text/javascript"></script>

<?php
wp_get_archives('type=monthly&format=link');
wp_head();
?>

</head>
<body id="<?php echo wallpaper_class();?>" class="<?php
if( !function_exists( 'get_theme_option' )
|| get_theme_option('headerposition') != "normal" )
{
echo " headerfixed";
}
if( function_exists( 'get_theme_option' )
&& ( get_theme_option( 'thumbpos' ) == "sidebar"
|| get_theme_option( 'thumbpos' ) == "none" )
&& ( vl_get_bloglogodir() == null ) ) {
echo " plainheader";
}
if( function_exists('get_theme_option') && get_theme_option('quadpossidebar') == 'quad' ) {
echo " quadbar";
}
?>" style='font-family: <?php
echo vl_get_theme_option('font-family', '"verdana", sans-serif' );
?>; font-size: <?php
echo vl_get_theme_option('font-size', '14px');
?>'><?php
?><div id="header"><?php
?><div class="header_content"><?php
if( !function_exists('get_theme_option')
|| get_theme_option( 'headersearch' ) != "hide" )
{
?>
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<p class="right" id="search">
<input type="text" value="<?php echo __('Search', VL_DOMAIN) . '...'; ?>" name="s" id="s" alt="Search"/><br />

<?php
if( function_exists( 'mfg_search_inputs' ) )
mfg_search_inputs();
?>
</p>
</form>
<?php
}
if( is_single() || is_page() ) {
?><div class="blogtitle" <?php
}
else {
?><h1 <?php
}
?>style='font-family: <?php
echo vl_get_theme_option('title-font-family', '"Trebuchet MS", sans-serif' );
?>; font-size: <?php
echo vl_get_theme_option('font-size', '20px');
?>'><?php
?><a href="<?php bloginfo('url'); ?>" title="<?php _e( 'View recent news', VL_DOMAIN); ?>" onclick="changebackground(this, '1');"><?php bloginfo('title'); ?></a><br />
<?php
if( is_single() || is_page() ) {
echo '</div>';
}
else {
echo '</h1>';
}

if( headerThumbs() ) ?>
<div id="shortbreadLink">Also Visit <a href="http://www.shortbreadbygryphon.com">shortbreadbygryphon.com</a></div>

<div id="gryphonLinks">
<a href="http://www.gryphondor.com/weekly-menu/" onclick="changebackground(this, '1');">Weekly Menu</a>
<a href="http://www.gryphondor.com/afternoon-tea/" onclick="changebackground(this, '1');">Afternoon Tea</a>
<a href="http://www.gryphondor.com/bakery-goods/" onclick="changebackground(this, '2');">Bakery Goods</a>
<a href="http://www.gryphondor.com/catering/" onclick="changebackground(this, '0');">Catering</a>
<a href="http://www.gryphondor.com/special-events/">Special Events</a>
<a href="http://www.gryphondor.com/contact-us/">Contact Us</a>
</div>
<div style="clear: both;"></div>
</div>
<div class="header_bottom">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
<div id="bodyowner">

<?php
if( function_exists('dynamic_sidebar') ) {
if ( vl_widget_count(__('Banner', VL_DOMAIN)) > 0 ) {
?><div class="banner">
<div class="blogbefore">
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</div><?php
dynamic_sidebar(__('Banner', VL_DOMAIN));
?><div class="blogafter">
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</div>
</div><?php
}
}
?>


and the site, if you want to see it, is www.gryphondor.com.

I was just thinking... current I have the code being passed via the url to the next page... however if it would be easier I could just include the screen.width detection in the header.php to avoid that altogether, although that would prevent me from employing my postload script to remove the download delay on the backgrounds

anyways, whatever works best :):)

Thanks again

p.s: the postload script i just spoke of is this:

//<![CDATA[
function postLoadImages(){
if(!window.name.match(/preLoad.complete/gi)){
var images = new Array('images/logoButtons/bottom_text.gif',
'images/logoButtons/top_text.gif',
'images/topWave.jpg');
//I was going to use the screen detection here to select the dir to postload from

var loader = new Array();
for(var i=0; i<images.length; i++){
loader[i] = new Image();
loader[i].src = images[i];
}
window.name = 'preLoad.complete';
}
}
//]]>
and I was going to use it to load the first background before allowing the users to go to the main page so that there would be no delay with a blank BG while it loaded.... but if this is not possible it's fine :)

canadianjameson
07-24-2008, 02:23 AM
Hey,

I'm sorry guys I think I overcomplicated things :/

alright, synopsis:

If it's much easier to do, lets transfer the detection from the language selection page to the actual index.php and that way avoid needing to pass the variables via the URL


I dunno, i guess just lemme know if that provides a very much simplified approach :/

And thanks again for all of the help :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum