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,
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 :
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.htmlno new file
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 (
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 ).
Greetings.