4images Forum & Community
4images Modifications / Modifikationen => Templates & Styles (Requests & Discussions) => Topic started by: ch€ri{Bi}² on September 20, 2005, 01:42:49 AM
-
Hello,
For all those who want to stop (like me) to juggle between several templates when installing a mod, and also for those who want to propose to their guests the possibility of choosing the colour of the site which they visit, :idea: I make a small modification which allows site administrator to keep a unique template (...thus I do not speak about already published mods allowing the visitors to choose between templates) while modifying its colours as the visitors will want.
You can see a demo here (http://patsgallery.free.fr/4images/) : :arrow: Choose a color in the left below random image and see how the color of the (same) template changes.
Last Update : 05 February 2006
- use the default style.css if user stylesheet is not present
v1.1(01 Oct 2005) :
- file send_design.php deleted
- no more javascript nor redirection
- rewrite of code : closer to 4images original code
v1.0(20 Sept 2005) :
- Fisrt release
Let's go for it!
>> 03 files to edit from 4images root (3 steps):
[change]/include/page_header.php
[change]/templates/<yourtemplate>/header.html
[change]/templates/<yourtemplate>/home.html
no new file 8)
First, backup your files.
------ Installation ------
STEP 1: (updated on 01 oct 2005)
open page_header.php
search :
//-----------------------------------------------------
//--- Category Dropdown -------------------------------
//-----------------------------------------------------
and add before:
//-------------------------------------------[ [MOD] multi-color site]
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
if (isset($HTTP_POST_VARS['design'])) {
$design = $HTTP_POST_VARS['design'];
$site_sess->set_session_var("design", $design);
$session_info['design'] = $design;
$cookie_expire = time() + 60 * 60 * 24 * 90;
setcookie($cookie_name.'design', serialize($design), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
} else {
$design = isset($HTTP_COOKIE_VARS[$cookie_name.'design']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'design'])) : "css_blue";
$site_sess->set_session_var("design", $design);
$session_info['design'] = $design;
}
$multi_color="";
$list_css = array();
$dir_name = TEMPLATE_PATH;
if (is_dir($dir_name)) {
$dir_path = opendir($dir_name);
$ext=".css";
$long_ext=strlen($ext);
while ($file_name = readdir($dir_path)) {
$long_file=strlen($file_name)-$long_ext;
if ($file_name != "." && $file_name != ".." && (substr($file_name,$long_file,$long_ext)==$ext)) {
$color = $file_name;
$color = ereg_replace('.css', '', $color);
$list_css[] = $color ;
}
}
}
//détermination de la feuille de style et du logo
//$mycss = $design.'.css';
$mycss = (in_array ($design, $list_css))? $design.'.css' : 'style.css';
$mylogo = 'logo_'.$design.'.gif';
//$frame_cat = 'cat_'.$design.'.gif'; // chamge this to whatever you need in your template but don't forget to register it in register_vars
$multi_color = "\n<form name=\"colorname\" method=\"post\" action=\"".$self_url."\"><select name=\"design\" >\n";
foreach ($list_css as $key => $val) {
$multi_color .= "<option value=\"$val\"";
if ($val == $design) {
$multi_color .= " selected=\"selected\"";
}
$multi_color .= ">".$val."</option>\n";
}
$multi_color .= "</select>\n
<INPUT type=\"submit\" value=\"".$lang['go']."\" class=\"button\" name=\"submit\" />
</form>\n";
$site_template->register_vars(array(
"mycss" => $mycss,
"mylogo" => $mylogo,
"multi_color" => $multi_color
));
//-------------------------------------------[/[MOD] multi-color site]
Note : don't forget change the value of css_blue to your default style without the extension.
STEP 2:
open /templates/<yourtemplate>/header.html
search and comment this line:
<link rel="stylesheet" href="{template_url}/style.css" />
replace by:
<link rel="stylesheet" href="{template_url}/{mycss}" />
STEP 3:
open /templates/<yourtemplate>/home.html
add this code above random picture :
<!-- ---[ [MOD] multi-color site] --->
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head2" height="20" > <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />Color of site</td>
</tr>
<tr>
<td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
<tr>
<td align="center" class="row1" >
<br>
{multi_color}
</td>
</tr>
<tr>
<td class="tablebgcolor" style="height:1px"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
</table>
<!-- ---[/[MOD] multi-color site] --->
------ END of Installation ------
Now you can try to copy any stylesheets ( 8) from other templates but don't forget to rename each stylesheet) in your unique template directory and let your guest choose a new color in your home page. their choice is recorded in a cookie. so if they keep it, they keep the color.
Note : to make it work correctly, your background images must be in the stylesheets (i mean : no hard-coded background pics :wink:).
Greetings.
-
oh wow! would be awsome!
nice
-
I like that alot!
one queston, does it store my choice anywhere? if i return tommorow will it be the same color i picked?
-
one queston, does it store my choice anywhere? if i return tommorow will it be the same color i picked?
yes... cookies based! Keep the cookie to keep the color :wink:
-
one queston, does it store my choice anywhere? if i return tommorow will it be the same color i picked?
yes... cookies based! Keep the cookie to keep the color :wink:
8) , cool thats what i wanted to hear , cant wait to see this mod :mrgreen:
-
This topic probally would have got more responce in the Mods & Plugins (Requests & Discussions) section.
u have 3 votes for people that like the mod so far , is that enough ? :mrgreen:
-
I think that in end of week we shall have more answers... :roll:
well, it is not really a mod but a small modification that concerns only the template and the style.
Furthermore it seemed to me that we could not open any more of topic directly in the Mods & Plugins (Requests & Discussions) section...
Now I can, but it not the problem...I have to find time to work on the publication even if it is not very complicated.... coming soon! :wink:
Regards.
-
by the way, in IE (and maybe in FF) you can swap stylesheets without refreshing the page, I think this would also be great addition to what you've done already ;)
-
by the way, in IE (and maybe in FF) you can swap stylesheets without refreshing the page
huuumm!!! :?: swap stylesheets without refreshing the page?
Can you tell me more about this ?
-
By using javascript:
http://www.howtocreate.co.uk/jslibs/htmlhigh/swapstyle.html
-
8) Oh yes, it is exactly the same thought!
But :? in my modification, I use PHP codes ( :arrow: post on the server) to validate the user's right... i think it is not possible without refresh (or post).
But theoretically, yes, the code you indicate can be used to offer this service to all guests without controlling their rights :wink:
-
let me explain the theory a little bit:
You dont need to change anything in you php code, all you need to do is make a JS code that would swap the stylesheet and update the cookie. ;)
The POST feature that php code handle should stay as it is, for best browser compability, in case javascript code failed :)
The current stylesheet also should be registered as a template tag, so JS code would know which style is currently selected.
Obviously it might sounds easy in theory, I dont know JS at all, so dont know how all this works :D
-
I tried this method ( :arrow: without refresh). it is very very interesting and it works but :( it does not answer my expectations.
when you use stylesheets whith pictures (for example with: background-image: url(images/navbar.gif); ), the change on HTML style works correctly but not on this type of element because the images will not have been loaded by the browser.
The solution would be to look for all the images in differents stylesheets and to load them by the browser in the opening of the page ... :? too much complicated!
To solve this problem, the only way (in my opinion) is to validate the new selected stylesheet by the server, which will involve a reloading of the entire page with the new style and all the images which correspond to the new style.
do not hesitate to say to me if there is a better solution :wink:
-
Any updates?
sorry i know i'm impatient :lol:
-
i found a way to reduce the number of modifiied files...
still optimizing the code :wink:
coming soon !
-
cool,
I found out how to do it using javascript , but that doesnt work for my needs as I need the page reresh to change the images called by the stye sheet.
so i will wait for cheribibi's code
-
You can find the light version of the mod in the first thread of this topic. :wink:
tell me if something is wrong.
have fun! 8)
-
Well i have tried it twice and i get the same result
Notice: Undefined variable: color in C:\..\send_design.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at C:\...\send_design.php:4) in C:\...\send_design.php on line 4
I hope this has nothing to do with this mod from Jan- [Mod] Different cat templates / Verschiedene Kategorie Templates- http://www.4homepages.de/forum/index.php?topic=1847.0
-
in send_design.php line:
setcookie("4images_DESIGN","$color",time()+$expire); //enregistrement du cookie au nom de DESIGN repris dans design.php
should be changed to:
setcookie("4images_DESIGN",((isset($_POST['color']) && !empty($_POST['color'])) ? $_POST['color'] : ((isset($_GET['color']) && !empty($_GET['color'])) ? $_GET['color'] : "style")),time()+$expire); //enregistrement du cookie au nom de DESIGN repris dans design.php
-
in send_design.php line:setcookie("4images_DESIGN","$color",time()+$expire); //enregistrement du cookie au nom de DESIGN repris dans design.php
should be changed to:
setcookie("4images_DESIGN",((isset($_POST['color']) && !empty($_POST['color'])) ? $_POST['color'] : ((isset($_GET['color']) && !empty($_GET['color'])) ? $_GET['color'] : "style")),time()+$expire); //enregistrement du cookie au nom de DESIGN repris dans design.php
That works to change the style sheet, but it gets hung up on send_design.php and doesnt go back to the refering page. after i hit back the sytle sheet has changed
-
yeah, it require HTTP_REFFERER variable to be set, anyways, IMO using an external script for this metter is not such good idea. All cookie set should be done in global.php instead.
-
yeah, it require HTTP_REFFERER variable to be set, anyways, IMO using an external script for this metter is not such good idea. All cookie set should be done in global.php instead.
is that something u set in 4images or php itself?
How can this code be done in global.php ?
any help would be greatly appreciated
-
hehe! when i said i was optimizing the codes... :roll:
i think it will be a good thing to (delete and) include the code in send_design.php in some existing file (i don't know, why not page_header.php or another)...
so the switch could be called by : http://domain_name/4images/index.php?send_design=some_color
@impss : what browser do you use?
:arrow: the code is tested with ie6 but i got problems with opera (redirect on HTTP_REFFERER don't work, i must refresh)
-
Im tested using both ie6 and firefox, same problem
I tested it on a new install also, same problem
-
:?: can you give a link to test your site (& your problem)? and what is your PHP version ?
because :
1 - i read somewhere the browser ou maybe a firewall can block HTTP_REFFERER...
2 - some older version of PHP got problems with getenv();
-
http://www.cusstom.com/4images/
PHP Version 4.3.8
-
:!: original post updated with correction from v@no 8)
yeah, it require HTTP_REFFERER variable to be set, anyways, IMO using an external script for this metter is not such good idea. All cookie set should be done in global.php instead.
@v@no, not sure to understand :
1 - what do you mean by IMO?
2 - and why all cookie set should be done in global.php : I did not see any cookie declared in my global.php file and i know that some mod uses cookies. is there a specific file where to declare the cookies?
@impss
you got this error on your page:
<b>Fatal error</b>: Call to undefined function: server() in <b>C:\CuSStom.com\www\4images\send_design.php</b> on line <b>7</b>
line 7 is about the page redirection ( :arrow: refresh )
so, forget JS : in send_design.php just comment the 2 lines with JS , and try to replace :
echo 'window.location="',getenv('HTTP_REFERER'),'"';
by
header("Location: ".$_SERVER['HTTP_REFERER']);
:?: can you tell me if the redirection works for you with this code?
-
IMO - in my opinion ... :wink:
-
cheribibi
If i understand you correctly, it should look like this now?
<?php
//-------------------------------------------[ [MOD PERSO] Site multi-couleurs]
$expire=365*24*3600; // 1 an - 1 year
setcookie("4images_DESIGN",((isset($_POST['color']) && !empty($_POST['color'])) ? $_POST['color'] : ((isset($_GET['color']) && !empty($_GET['color'])) ? $_GET['color'] : "style")),time()+$expire); //enregistrement du cookie au nom de DESIGN repris dans design.php
//echo "<script language=\"JavaScript\">\n";
//echo "alert('Nouvelle couleur de design sélectionnée : ".$color.". \\nN\'hésitez pas à rafraîchir la page si les couleurs n\'apparaissent pas.\\n---\\nNew selected colour : ".$color.". \\nPlease refresh the page if colours do not appear.');";
header("Location: ".$_SERVER['HTTP_REFERER']); //retour à la dernière page visitée du site avec les nouvelles couleurs
echo "</script>";
//-------------------------------------------[/[MOD PERSO] Site multi-couleurs]
?>
With the code above , it does get redirected back. but with out making the changes.
-
yes and the code above also works for me !! :roll:
ok now just to debug, try this code in send_design.php :
<?php
//-------------------------------------------[ [MOD PERSO] Site multi-couleurs]
$referer = getenv('HTTP_REFERER');
echo $referer;
$expire=365*24*3600; // 1 an - 1 year
setcookie("4images_DESIGN",((isset($_POST['color']) && !empty($_POST['color'])) ? $_POST['color'] : ((isset($_GET['color']) && !empty($_GET['color'])) ? $_GET['color'] : "style")),time()+$expire);
echo "<script language=\"JavaScript\">\n";
echo "alert('Nouvelle couleur de design sélectionnée : ".$color.". \\nN\'hésitez pas à rafraîchir la page si les couleurs n\'apparaissent pas.\\n---\\nNew selected colour : ".$color.". \\nPlease refresh the page if colours do not appear.');";
// echo 'window.location="'.getenv($_SERVER['HTTP_REFERER']).'"'; //retour à la dernière page visitée du site avec les nouvelles couleurs
// header("Location: ".$_SERVER['HTTP_REFERER']);
echo "</script>";
//-------------------------------------------[/[MOD PERSO] Site multi-couleurs]
?>
as you can see, i comment out the redirection and asked for the display of the HTTP_REFERER
:arrow: you should have a blanc page with your HTTP_REFERER
can you tell me what you see.
-
i get
http://www.cusstom.com/4images/
Warning: Cannot modify header information - headers already sent by (output started at C:\CuSStom.com\www\4images\send_design.php:4) in C:\CuSStom.com\www\4images\send_design.php on line 6
-
all these codes works for me :oops:
check that you let no space (or a new line) at the end of the file after ?>
-
@v@no, not sure to understand :
1 - what do you mean by IMO?
2 - and why all cookie set should be done in global.php : I did not see any cookie declared in my global.php file and i know that some mod uses cookies. is there a specific file where to declare the cookies?
1) IMO = In My Oppinion
2) global.php being executed by any 4images pages. That's why if you do all needed cookie set in global.php you can use $self_url in the form:$multi_color = "\n<form name=\"colorname\" method=\"post\" action=\"".$self_url."\"><select name=\"color\" >\n";
By doing that, it will "refresh" the current page no mwork on 9 pages out of 10. (some restrictions apply, such as $mode or such variable might not be avalable through $self_url)
-
@all : thanks for your answers 8) I usually do not speak English and there are subtleties which I do not know
@ impss
it seems you got problems with paramters in the url :?
try this 2 urls (COPY AND PASTE):
http://www.cusstom.com/4images/send_design.php?color=style
and after refresh your home page, style is applyed
then try:
http://www.cusstom.com/4images/send_design.php?color=style2
return to your home page and you will see the switch is working (style2 is applied) but still got JS errors (try to comment ALL lines with JS : everything should work with only PHP)
Note : I found why the code didn't work with my browser Opera :arrow: there is a menu to enable/disable referrer logging :wink:
-
Major update of original code
since there were problems with send_design.php file, I removed it.
no regrets :arrow: all the corresponding code is in the page_header.php file and now the code of the MOD is closer to 4images original code
no JS and no redirection 8)
-
Great job!!
Working Perfect now 8)
http://www.cusstom.com/4images/index.php
Now just gotta make come sytle sheets for my gallery
Thanks cheribibi, I appreciate the work!! :D
-
well don't forget change the following value to your default style without the extension:
$design = isset($HTTP_COOKIE_VARS[$cookie_name.'design']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'design'])) : "css_blue";
css_blue is my default stylesheet without the extension.
without that the visitors will have no stylesheet with their first visit until they choose a new style :roll:
have fun :wink:
-
well don't forget change the following value to your default style without the extension:
$design = isset($HTTP_COOKIE_VARS[$cookie_name.'design']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'design'])) : "css_blue";
without that the visitors will have no stylesheet with their first visit until they choose a new style :roll:
have fun :wink:
Yea i just did that, noticed it when i tested it out in Firefox and Opera
Thanks again
-
Hello,
a Great Mod but i have one Problem. I have installed this Mod (Cache Mod (http://www.4homepages.de/forum/index.php?topic=8476.0)) and when i change the color i can´t see it. The cache is active.
Is there a way to clear the cache before change the color???
I mean, i change the color and before it where load the cache where cleared...
And now i have another Problem. When i disable the CAche Mod this Mod works but now for the start Page. When i click to a categorie i have my standard style...
-
if (isset($HTTP_POST_VARS['design'])) {
$design = $HTTP_POST_VARS['design'];
$site_sess->set_session_var("design", $design);
$session_info['design'] = $design;
$cookie_expire = time() + 60 * 60 * 24 * 90;
setcookie($cookie_name.'design', serialize($design), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
@set_time_limit(0);
clear_cache();
}
Habe es nicht getestet aber versuche das doch mal...
-
Hi,
vielen Dank. Scheint zu funktionieren. Cache ist wieder an und ich kann das Style ändern. Leider habe ich aber immer noch mein 2tes Problem und natürlich mal wieder keine Ahnung woran das liegt.
Und zwar kann ich das Style ändern und es wird mir dann auf der Startseite angezeigt. Klicke ich jetzt aber auf eine Kategorie oder ein Bild dann habe ich plötzlich wieder mein Standard Style. Und auch wenn ich dann wieder zur Startseite gehe ist wieder der Standard drin.
Kannst du da vielleicht auch helfen???
--------------------------------------------------------
My Problem. When i change the color i see the start page in the new color but when i click a categorie now i have the standard......
-
Ich denke das ist ein Cookie Problem, haste die Cookie bei dir deaktiviert?
-
Ich denke das ist ein Cookie Problem, haste die Cookie bei dir deaktiviert?
Ne, Cookies sind eigentlich aktiviert. Bleibe ja auch eingeloggt wenn ich die Seite neu aufrufe nachdem ich den Browser geschlossen habe.
Das komische ist das sich nun etwas geändert hat. Wenn ich zur Startseite zurückkehre dann habe ich immer noch mein eingestelltes Style. Nur wenn ich halt irgendwas anderes aufrufe wird mir wieder der Standard angezeigt.
Teste es doch bitte mal kurz. Seite ist http://www.terraristik-galerie.de . Dort kannst du das Style ändern und dann klicke mal eine Kategorie. Dann siehst du was ich meine. Und wenn du dann wieder zum Start zurückkehrst ist das ausgewählte Style wieder da...
-
war das den auch schon der fall bevor wir das cache lerren eingebaut haben?
-
war das den auch schon der fall bevor wir das cache lerren eingebaut haben?
Ja, da war das selbe Problem. Hatte die Cache Funktion ja auch mal deaktiviert und da war das dann auch.
Habe eben mal in meinem Cookie Ordner geschaut und wie es scheint wird doch kein Cookie angelegt.
Wenn ich den Code richtig verstehe sollte ja ein Cookie mit dem Namen 4images_ angelegt werden.
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
Allerdings habe ich keinen Cookie der mit 4images_ anfängt....
-
also ich kwerde für heute schluss machen, wenn dir bis morgen niemand helfen konnt schaue ich nochmal...
-
Allerdings habe ich keinen Cookie der mit 4images_ anfängt....
I do not speak this language :oops: but according to what I understood (and what I saw on your site),it does not work for you and you don't find the cookie...
this code:
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
checks if the name of the cookie were already defined.
if it is true, the cookie will use this name ( => it's your case.)
if it is false, a new name (in this code 4images) is defined for a new the cookie.
:arrow: the problem is as follows: when you refresh or load a new page, it is not possible to know which style to use in your page because the information about the style is not stored in your cookie(you should find in your cookie an item called 4images_design, but...no trace )... then default style is used.
:?: can you reach the logs of your php server and if so, can you find errors about cookies creation (or writing) about the creation/update line?
-
hhmm, i have nothing about an error of a cookie in my log file.... :(
-
nicht in den access log schauen, du musst dann auch im error log schauen... (o:
Ist jetzt nur eine Vermutung...
-
nicht in den access log schauen, du musst dann auch im error log schauen... (o:
Ist jetzt nur eine Vermutung...
Hab ich doch. Kann bei meinem Anbieter in Logfiles gehen und dann das laufende Error Logfile ansehen oder die letzten 10 Error Logs.
Wie müsste denn die Fehlermeldung ungefähr aussehen???
-
hhmmm, no one can help me?!
I deinstall this Mod :(
-
cheribibi
Say someone has selected a Color, and they have it saved in there cookie. And you want to get rid of that template.
They next time they comeback to the site, it will be messed up , because the css is no longer there.
Is there a way so that the defualt shows , if the one they had seleted is no longer avaliable.
Thanks for your help, this is one of my favorite mods
This mod should be made a sticky
-
well, 2 things about it :
- if you are talking about a template modification :
don't worry about it since you did not make the modification in header.html file (see STEP 2) in the new template. the script will use the default value (style.css).
- now, if you speak about the removal of a stylesheet file :
:? thank you to point this dysfunction...
There is something which misses in the original publication in connection with the checking of the presence (or not) of the css file chosen by the user ( :arrow: if the stylesheet is not found, it shows no style, just html text... dirty page :evil:).
:idea: here the code to repair this:
In STEP 1, replace this code : $mycss = $design.'.css';
by this one :
$mycss = (in_array ($design, $list_css))? $design.'.css' : 'style.css'; //style.css is the default style in 4images : try to keep it unchanged in your tempalte directory
You should be sure that the style.css file is present in the directory :wink:
Original code updated.
-
THanks cheribibi
That did it 8)
-
Thanks for this nice colorfull MOD :-)
It works on my Website :-)
Greetings
Ingo
-
Hi Acidgod,
Es gibt ein Problem, wenn auf der Seite verschiedene Sprache instaliert sein!
Nämlich:
Die Seite kehrt immer auf default-Sprache zurück, wenn man Farb-Änderung b.z.w Style.css wechselt.
Hast du auch das Problem?
Danke dir im Voraus
m.a
nicht in den access log schauen, du musst dann auch im error log schauen... (o:
Ist jetzt nur eine Vermutung...