Poll

What do you think about this  hack ?

Great! i want the same at home.
I like the idea.
I like the idea but not the realization.
I do not like this idea.
It is very bad.

Author Topic: [HACK] Many More colors with only ONE template  (Read 60098 times)

0 Members and 2 Guests are viewing this topic.

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
[HACK] Many More colors with only ONE template
« 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: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 :
Code: [Select]
//-----------------------------------------------------
//--- Category Dropdown -------------------------------
//-----------------------------------------------------

and add before:
Code: [Select]
//-------------------------------------------[ [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:
Code: [Select]
<link rel="stylesheet" href="{template_url}/style.css" />

replace by:
Code: [Select]
<link rel="stylesheet" href="{template_url}/{mycss}" />


STEP 3:

open /templates/<yourtemplate>/home.html
add this code above random picture :
Code: [Select]
<!-- ---[ [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.
ch€ri{Bi}²


Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: [HACK] Many More colors with only ONE template
« Reply #1 on: September 20, 2005, 02:10:10 AM »
oh wow! would be awsome!
nice

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: [HACK] Many More colors with only ONE template
« Reply #2 on: September 20, 2005, 02:26:36 AM »
I like that alot!

one queston, does it store my choice anywhere? if i return tommorow will it be the same color i picked?


Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [HACK] Many More colors with only ONE template
« Reply #3 on: September 20, 2005, 09:35:56 AM »
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:
ch€ri{Bi}²


Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: [HACK] Many More colors with only ONE template
« Reply #4 on: September 20, 2005, 02:53:55 PM »
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:

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: [HACK] Many More colors with only ONE template
« Reply #5 on: September 21, 2005, 04:46:58 PM »
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:

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [HACK] Many More colors with only ONE template
« Reply #6 on: September 21, 2005, 05:20:56 PM »
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.
ch€ri{Bi}²


Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: [HACK] Many More colors with only ONE template
« Reply #7 on: September 22, 2005, 12:51:52 AM »
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 ;)

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [HACK] Many More colors with only ONE template
« Reply #8 on: September 22, 2005, 01:06:00 AM »
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 ?
ch€ri{Bi}²


Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: [HACK] Many More colors with only ONE template
« Reply #9 on: September 22, 2005, 01:12:08 AM »

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [HACK] Many More colors with only ONE template
« Reply #10 on: September 22, 2005, 02:16:54 AM »
 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:

ch€ri{Bi}²


Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: [HACK] Many More colors with only ONE template
« Reply #11 on: September 22, 2005, 02:39:22 AM »
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


Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [HACK] Many More colors with only ONE template
« Reply #12 on: September 22, 2005, 06:17:07 PM »
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:
ch€ri{Bi}²


Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: [HACK] Many More colors with only ONE template
« Reply #13 on: September 27, 2005, 01:51:49 AM »
Any updates?

sorry i know i'm impatient  :lol:

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [HACK] Many More colors with only ONE template
« Reply #14 on: September 28, 2005, 12:21:02 PM »
i found a way to reduce the number of modifiied files...
still optimizing the code  :wink:
coming soon !
ch€ri{Bi}²