Note to fix naive user agent sniffing
[squirrelmail.git] / functions / template.php
1 <?php
2
3 /**
4 * template.php
5 *
6 * This file is intended to contain helper functions for template sets
7 * that would like to use them.
8 FIXME: potentially create a separate directory and separate functions into different files?
9 *
10 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16
17 /**
18 * Create stylesheet links that will work for multiple browsers
19 *
20 * @param string $uri The URI to the linked stylesheet.
21 * @param string $name The title of the stylesheet (optional; default empty).
22 * @param boolean $alt Whether or not this is an alternate
23 * stylesheet (optional; default TRUE).
24 * @param string $mtype The target media display type (optional; default "screen").
25 * @param string $xhtml_end The XHTML-compliant close tag syntax to
26 * use (optional; default "/")
27 *
28 * @return string The full text of the stylesheet link.
29 *
30 */
31 function create_css_link($uri, $name='', $alt=TRUE, $mtype='screen', $xhtml_end='/') {
32 // FIXME: Add closing / to link and meta elements only after
33 // switching to xhtml 1.0 Transitional.
34 // It is not compatible with html 4.01 Transitional
35 $xhtml_end='';
36
37 if (empty($uri)) {
38 return '';
39 }
40
41 // set to lower case to avoid errors
42 //
43 sqGetGlobalVar('HTTP_USER_AGENT', $browser_user_agent, SQ_SERVER);
44 $browser_user_agent = strtolower($browser_user_agent);
45
46 if (stristr($browser_user_agent, "msie 4")) {
47 $browser = 'msie4';
48 $dom_browser = false;
49 $is_IE = true;
50 //FIXME: this fails for Opera because its user agent also contains MSIE
51 } elseif (stristr($browser_user_agent, "msie")) {
52 $browser = 'msie';
53 $dom_browser = true;
54 $is_IE = true;
55 }
56
57 if ((strpos($uri, '-ie')!== false) and !$is_IE) {
58 //not IE, so don't render this sheet
59 return;
60 }
61
62 if ( strpos($uri, 'print') !== false )
63 $mtype = 'print';
64
65 $href = 'href="'.$uri.'" ';
66 $media = 'media="'.$mtype.'" ';
67
68 if ( empty($name) ) {
69 $title = '';
70 $rel = 'rel="stylesheet" ';
71 } else {
72 $title = 'title="'.$name.'" ';
73 $rel = 'rel="'.( $alt ? 'alternate ' : '' ).'stylesheet" ';
74 }
75
76 return '<link '.$media.$title.$rel.'type="text/css" '.$href." $xhtml_end>\n";
77 }
78
79