Welcome to Geeklog, Anonymous Tuesday, April 23 2024 @ 04:15 pm EDT

Geeklog Forums

Geeklog.fr with style switcher


Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Someone was looking for a style switcher (font size for example). You can see one in action on geeklog.fr.

To make it work on your site :

Create a switch.php file like this one

Text Formatted Code
<?php
  $validite = time() + 60 * 60 * 24 * 31 * 2; // deux mois en secondes
  $validite1 = time() + 60 * 60 * 24 * 31 * 2; // deux mois en secondes
 
      // on considère que register_globals est désactivée, ainsi ce script fonctionnera quelle que soit la configuration
  if (isset($_GET['size'])) {
    /* le style a été passé en méthode GET, dans l'URL */
    $size = $_GET['size'];
  }
  else if (isset($_POST['size'])) {
    /* le style a été passé en méthode POST, dans les en-têtes HTTP */
    $size = $_POST['size'];
  }
 
  // protection contre les petits malins qui tenteraient de pirater le site
  // le nom du style ne peut contenir que des caractères alpha-numériques et les caractères _ et -
  $size = preg_replace('#[^a-zA-Z0-9_-]#', '', $size);
 
  // on considère que register_globals est désactivée, ainsi ce script fonctionnera quelle que soit la configuration
  if (isset($_GET['style'])) {
    /* le style a été passé en méthode GET, dans l'URL */
    $style = $_GET['style'];
  }
  else if (isset($_POST['style'])) {
    /* le style a été passé en méthode POST, dans les en-têtes HTTP */
    $style = $_POST['style'];
  }

  // protection contre les petits malins qui tenteraient de pirater le site
  // le nom du style ne peut contenir que des caractères alpha-numériques et les caractères _ et -
  $style = preg_replace('#[^a-zA-Z0-9_-]#', '', $style);
 
  if (isset($_GET['redirection'])) {
    /* l'adresse de la page en cours est passée en méthode GET, dans l'URL */
    $redirection = $_GET['redirection'];
  }
  else if (isset($_POST['redirection'])) {
    /* l'adresse de la page en cours a été passée en méthode POST, dans les en-têtes HTTP */
    $redirection = $_POST['redirection'];
  }
 
  // on vérifie qu'il s'agit bien d'un lien interne
  // il doit commencer par http://monsite.com/
  if (strpos($redirection, 'http://'.$_SERVER['SERVER_NAME'].'/cms') === false || strpos($redirection, 'http://'.$_SERVER['SERVER_NAME'].'/cms') != 0) {
    /* tentative de piratage ? on remplace par la racine du site */
    $redirection = 'http://'.$_SERVER['SERVER_NAME'].'/cms';
  }

  setcookie('Style', $style, $validite, '/', $_SERVER['SERVER_NAME'], 0);
  setcookie('Size', $size, $validite1, '/', $_SERVER['SERVER_NAME'], 0);

  // on n'utilise pas le HTTP_REFERER car ce n'est pas fiable et les proxy ne l'envoyent pas
  header("Location: $redirection");
?>


in your header.thtml add

Text Formatted Code

<style type="text/css" media="screen">
  @import url({layout_url}/<?php echo (isset($_COOKIE['Style'])) ? $_COOKIE['Style'] : 'normal' ; ?>.css);
  @import url({layout_url}/<?php echo (isset($_COOKIE['Size'])) ? $_COOKIE['Size'] : 'big' ; ?>.css);
</style>

 



The links can be made with images like this :

Text Formatted Code
<a href="size.php?size=small&redirection=http://<?php echo $_SERVER['SERVER_NAME'].str_replace('&', '&amp;', $_SERVER['REQUEST_URI']); ?>"><img src="http://www.geeklog.fr/cms/images/small12.gif" order="0" alt="small" width="12" height="12"></a>&nbsp;
<a href="size.php?size=big&redirection=http://<?php echo $_SERVER['SERVER_NAME'].str_replace('&', '&amp;', $_SERVER['REQUEST_URI']); ?>"><img src="http://www.geeklog.fr/cms/images/big12.gif" order="0" alt="big" width="12" height="12"></a>&nbsp;
<a href="size.php?size=extra&redirection=http://<?php echo $_SERVER['SERVER_NAME'].str_replace('&', '&amp;', $_SERVER['REQUEST_URI']); ?>"><img src="http://www.geeklog.fr/cms/images/extra12.gif" order="0" alt="extra" width="12" height="12"></a>&nbsp;
 <a href="style.php?style=large&redirection=http://<?php echo $_SERVER['SERVER_NAME'].str_replace('&', '&amp;', $_SERVER['REQUEST_URI']); ?>"><img src="http://www.geeklog.fr/cms/images/large12.gif" order="0" alt="large" width="12" height="12"></a>&nbsp;
 <a href="style.php?style=normal&redirection=http://<?php echo $_SERVER['SERVER_NAME'].str_replace('&', '&amp;', $_SERVER['REQUEST_URI']); ?>"><img src="http://www.geeklog.fr/cms/images/normal12.gif" order="0" alt="normal" width="12" height="12"></a>

or replace images by words.

Make your modifications in new files call small.css and large.css.


How it is working?

style.css is still the main css and small.css or large.css overwrite the class to make the effect.


::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

samstone

Forum User
Full Member
Registered: 09/29/02
Posts: 820
Can't find the sample in action on geeklog.fr.

Sounds like a good idea. At first I thought it would switch entire style.css files.

Sam
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hi Sam

The links are in the header on the top right (Small A, normal A, big A, a rectangle and a square).

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

samstone

Forum User
Full Member
Registered: 09/29/02
Posts: 820
OK, now I see when I use FireFox, but does not appear on IE7.

------ Edited -----------

Oops! Actually, I had my default theme set up to Garden in the preference. When I use FireFox, I wasn't automatically logged in, so it gave me the pro theme, where these style choices exist.

Thanks.

Sam

 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Yes sorry for the confusion, it's only available for the pro_french theme witch is the defaut theme.

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EDT. The time is now 04:15 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content