I have a custom theme based on Andreas, which is visually nice and quiet.

I have also enabled the Pushbutton theme for its accessibility properties.

Andreas will be my default theme, but I want to have an Acessability block on the main page which allows users with impairments to switch across to the Pushbutton theme with a single click, and toggle back if they've clicked accidentally.

I want this to work for non-authorised users, not just registered users.

The theme switching I've seen in the forum seems to relate to pre-phpTemplate implementations.

Would something like:
$GLOBALS['custom_theme'] = 'mytheme/admin';

from this post
Be the place to start?

Thanks for any and all suggestions,
Tys.

Comments

Anonymous’s picture

What about the Switchtheme Module?

krisvannest’s picture

FYI I was looking for a similar solution today and came across this post-- just started using Switchtheme module and it's exactly what I needed (thanx all).

markhope’s picture

Hi Tyswan,

I posted a similar question just a few days ago...
http://drupal.org/node/86058

I had a few thoughts how to do this but would like to go one stage further and remove all images - producing a text only site.

I'd like to get some thoughts together for producing a text only version of an existing site, and wondered if this is best done with an alternative theme, or maybe another service outside of drupal.

I'm thinking of using the theme switcher module to produce a low graphic/text only version of the site and using the theme template to strip out any images (is this possible with PHPtemplate?) The theme switcher uses a dropdown menu that allows anonymous users to switch themes. I'm hoping that the submit form can be changed to allow a 'text only' text link to be used to submit the form.

The other thought I had was to setup a subdomain say text.example.com with a seperate site installed linking to the same DB, but with its own theme

BTW what is it that pushbutton has that makes it better for accessibility? I see it has priority 3.

ufku’s picture

in genetik.ufku.com i use a custom module for changing things in drupal. in this module's hook_init function i use theme switch according to theme name coming from $_GET;

  //switch theme
  if (($tema=$_GET['tema']) && $tema!=$_SESSION['tema']) {//if it isnt the current theme.
    $themes = list_themes();// get avaliable themes.
    if ($themes[$tema]) {//theme is valid.
      $_SESSION['tema'] = $tema;
    }
  }
  //set theme
  if ($_SESSION['tema'] && $_SESSION['tema']!=$GLOBALS['user']->theme) {
    $GLOBALS['custom_theme'] = $_SESSION['tema'];
  }

and in my theme files i create links having '&tema=themename' string at the end, to make one-click switch.

$switch = $GLOBALS['theme']=='mavi' ? 'yesil' : 'mavi';//get the theme which is not in use.
$uri = str_replace('&tema='.$GLOBALS['theme'], '', request_uri());//clean uri to prevent multiple tema=... strings
$tema = '<a href="'.$uri.'&tema='.$switch.'" title="'.t('select different theme').'"><div style="background: url('.$base_path.'modules/zzhack/'.$switch.'.png) no-repeat 50% 50%; width: 20px;">&nbsp;</div></a>';
@array_unshift($primary_links, $tema);

note: this code is for adding switch between two themes named mavi and yesil. additionally it adds the link to primary links.

--
Geneticists from METU

markhope’s picture

Thanks ufku,

Is the first block of code the Module? So just save the code as something.module? I've not created a module before.

Has anybody got any ideas about a Text besed themes, removing images from posts? Could this be done with template.php in the text theme?

Mark

ufku’s picture

put the first block of code inside something_init() {} function and save it as something.module.

--
Geneticists from METU

markhope’s picture

Thanks ufku,

I'll give it a go.

Mark

markhope’s picture

Somebody contacted me to ask about this code, and how to get it working. I've made some changes, more for my own benefit such as changing $tema to $style etc.

Thanks to ufku for his original example code.

The code that goes inside the module, called access_theme.module
Call it whatever you want but match the function names in the module too.

<?php
// $Id$
/**
 * Implementation of hook_help().
 */
function access_theme_help($section) {
  switch ($section) {
    case 'admin/help#access_theme':
      return t('This module enables the switching of a theme for non authenticated users. It can be used to present an accessible theme (text only?) as a text link.');
    case 'admin/modules#description':
      return t('A module to easily switch themes');
    // OPTIONAL: Add additional cases for other paths that should display help text.
  }
}

/**
 * Implementation of hook_init().
 */
function access_theme_init() {
//switch theme
if (($style=$_GET['style']) && $style!=$_SESSION['style']) {//if it isnt the current theme.
  $themes = list_themes();// get avaliable themes.
  if ($themes[$style]) {//theme is valid.
    $_SESSION['style'] = $style;
  }
}
//set theme
if ($_SESSION['style'] && $_SESSION['style']!=$GLOBALS['user']->theme) {
  $GLOBALS['custom_theme'] = $_SESSION['style'];
}
}

Put it in your module folder and enable it.

I then created a custom block because I needed to hard code some access keys. It does the job for me.
I created a new block (input type php), inserted the code below. I enabled the block in a region in this case a custom region called 'support links'.

<ul id="navlist">
<li><a href="/" title="Home" accesskey="1">Home</a></li>
	<?php
	//'clubmark' is the name of the graphic theme I created
	//'text_only' is the name of the errrrrr text only theme I created
	//I use nofollow on the theme switcher links to prevent indexing of duplicate pages for text only (just a thought)
	$switch = $GLOBALS['theme']=='clubmark' ? 'text_only' : 'clubmark';//get the theme which is not in use.
	$uri = str_replace('&style='.$GLOBALS['theme'], '', request_uri());//clean uri to prevent multiple style=... strings
	if ( $GLOBALS['theme']=='text_only' )
	{
		$style = '<a href="'.$uri.'&style='.$switch.'" title="'.t('select graphic theme').'" rel="nofollow">Graphic Version</a>';
	}
	else
	{
		$style = '<a href="'.$uri.'&style='.$switch.'" title="'.t('select text only theme').'" rel="nofollow">Text Only Version</a>';
	}
	?>
<li><?php print $style; ?></li>
<li><a href="/accessibility" title="Accessibility options for this site" accesskey="0">Accessibility</a></li>
<li><a href="/search" title="Advanced search options" accesskey="4">Search</a></li>
<li><a href="/contact-us" title="Contact Clubmark or give feedback on this site" accesskey="9">Contact Us</a></li>
<li><a href="/faq" title="Frequently Asked Questions about Clubmark Accreditation" accesskey="5">FAQ</a></li>
<li><a href="/sitemap" title="Sitemap links for this site" accesskey="3">Sitemap</a></li>
<li><a href="/terms-and-conditions" title="Terms and conditions for using clubmark.org.uk" accesskey="8">Terms &amp; Conditions</a></li>
</ul>

Alternatively you can place the following code somewhere in each theme page.tpl.php
This puts the link in the Primary Nav, but it doesn't change the text link - should be easy enough to adapt though, using the if else statement from above.

<?php 
$switch = $GLOBALS['theme']=='clubmark' ? 'text_only' : 'clubmark';//get the theme which is not in use.
$uri = str_replace('&style='.$GLOBALS['theme'], '', request_uri());//clean uri to prevent multiple style=... strings
$style = '<a href="'.$uri.'&style='.$switch.'" title="'.t('select different theme').'"><div style="background: url('.$base_path.'modules/zzhack/'.$switch.'.png) no-repeat 50% 50%; width: 20px;">swiitch style</div></a>';
@array_unshift($primary_links, $style);
?>

The text only module is basically a duplication of my graphic theme with some preg_replace to strip out images and replace with the alt text.

eg. in block.tpl.php

<h2><?php print $block->subject; ?></h2>
<div class="content">
<?php
$pattern = '/<img[^>]*?((alt="(.*?)".*?>)|>)/i';
$replacement = '(Image: $3)';
print preg_replace($pattern, $replacement, $block->content);
?>
</div>

In use on a site:
http://www.clubmark.org.uk

Mark

caprenter’s picture

This is really good, but I had a few problems implementing this, so I thought I'd document how I dealt with them here.

First, for modules in Drupal 5.1 there needs to be a (modulename).info file included as well (see http://drupal.org/node/82936).

This is pretty easy to do, so you'll need to make a folder/directory and put the .info file and the .module file (from Mark's post above) in there, and upload the whole folder to your site (sites/all/modules)

Here's my .info file

; $Id$
name = Access Module 
description = "Helps create a text only vesion of the site."

I then created a block using similar code to that used by Mark above (I'd already set up an alternate theme to switch to and uploaded and enabled that)

All worked well, except on the home page, where the switching didn't work at all. I could switch themes on the other pages and navigate to home and have it show as text only/graphic version, but on the home page, the link to switch would not work at all.

I think my problem was not having clean URLs. So on the home page the GET function would pull only '/' from the current page URL and the 'view text only version' link would return http://www.mysite.com/&style=text-only

Now without clean urls, this has no effect, I needed to make the 'view text only version' link have a '?q=' in it.

I always enable the rename URL module on my sites and then assign a particular page as the home page in site settings, so my home page is something like:
http://www.mysite.com/index.php?q=home

So to get the code in my block to generate this I add:

if ($uri=='/') {
$uri ='?q=home';
}

immediately after the line:

    $uri = str_replace('&style='.$GLOBALS['theme'], '', request_uri());//clean uri to prevent multiple style=... strings

All this does is say: If we're on the home page then make the $uri variable '?q=home' instead of '/' so that the ' 'view text only version' link will return http://www.mysite.com/?q=home&style=text-only (If you're wondering 'What about the 'index.php' part of the url?' - as far as I know, it's not necessary to include that )

NOTE: This actually diverts you away from the home page to the node that you have set as the home page. There is a difference, so you may need a bit of experimenting to get it right.

I hope that is of use to someone!

P.S. Accessibility note: When validating this over at the w3c validator I got the 'Ampersands (&'s) in URLs' problem (see http://www.htmlhelp.com/tools/validator/problems.html#amp). Because we are passing '&style' to the URL we should use

&amp;style

instead.

anotherdave’s picture

I've tried to use the code you have outlined above (Mark) using the custom block to place the link.

The theme will switch for me fine once, from one theme to another. When I'm in the second theme however, the link source changes from www.example.com/node&style=text_only to www.example.com/node&style=text_only&style=text_only.

Clicking on this link has no visible effect, other than adding an extra '&style=text_only' to the URL in the address bar.

At first I thought my problem lay with the changes I made to your code. After much fiddling, I even copied and pasted your code exactly and renamed my themes to "clubmark" and "text_only", but to no further luck.

I'd appreciate any help on this. Please let me know if I can give any other relevant information.

Thanks,
Dave

markhope’s picture

Hi Dave,

Are you developing on a local server? Post a few details about the setup and names of the modules.
The module was created for 4.7 and it was quite a while ago. I think I remember initially having a similar problem.

The block output is commented...

//clean uri to prevent multiple style=... strings

Might be something to do with that but I'm not sure without knowing a bit more about your setup.

Mark

anotherdave’s picture

Hi Mark,

thanks a million for your help. I've managed to get this working now though.

I was using two themes, based off the one page template, with seperate css files. When it changed for me once (but not back again) I knew it was working to some degree. I decided to output variables to my page until I found one that always matched the theme I was using.

I'm not too sure on the variables still (still learning php/Drupal), but thought the problem might lie with:
if ( $GLOBALS['theme']=='text_only' )

so I changed this line to:

if ($_SESSION['style']=='text_only')

which seemed to work OK. Couple more changes to the site & I've ended up with seperate page template files for the two themes. So rather than any variables I've just inserted the following code into each template:

<a href="'.$uri.'&style=[THEME_NOT_IN_USE]" rel="nofollow">[TEXT FOR LINK]</a>

Cheers again for the code & for your help!

Dave

tyswan’s picture

Hey, glad you guys have come up with the answers whilst I've been asleep for the last couple of days (*yawn*).

Gumgum and Mark, thanks for the tip on the SwitchTheme module. I've read those module lists 100 times, but it changes so fast, and there are so many of them that I missed that. Looks exactly what I need - I'll check it out.

ufku, your solution looks more complex than my needs, but thanks for contributing. It looks like you've been able to help out Mark, and I'll come back to your suggestion if SwitchTheme doesn't do it for me.

Mark, I think that the template.php is the correct place to supress images. I haven't looked at a text only site option yet. The other option is to do something with the images in the CSS, but that maybe not quite what you need. And I'm glad this thread is helping you out.

Cheers and thanks to everyone,
--
tys