45d87a6abb42c8a5cb833d70963a52a8b9715c43
[squirrelmail.git] / templates / default / stylelink.tpl
1 <?php
2 /**
3 * stylelink.tpl
4 *
5 * Template for rendering the links to css sheets for the page
6 *
7 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 * @version $Id$
10 * @package squirrelmail
11 * @subpackage templates
12 */
13
14 /** add required includes */
15
16
17 /** extract variables */
18 extract($t);
19
20 //echo SM_PATH;
21 $base_css="css";
22
23 $template_css_file="templates/$templateid/$templateid.css";
24
25 /** Add URLs to the $css_files array to have them added as links before any theme css or style.php output **/
26 $css_files=array();
27
28 /** If in existance, add link to template css file named for template **/
29 if (is_file(SM_PATH.$template_css_file)) $css_files[]=$base_uri.$template_css_file;
30
31 $base_css_files=list_css_files(SM_PATH.$base_css,$base_uri.$base_css);
32
33 if (!$base_css_files) $base_css_files=array();
34
35 /** Add link to default.css in the css directory **/
36 $css_link_html='';
37 $css_url=$base_uri.$base_css."/default.css";
38 $css_link_html=css_link($css_url, null, false, 'all','');
39
40 /** Add links to all css files listed in the css_files collection **/
41 foreach ($css_files as $css_url) {
42 $css_link_html.=css_link($css_url, null, false, 'screen', '');
43 }
44
45 /** Add links to each of the .css files in the /css/ directory, making them as alternate if they are not named for the current theme **/
46 foreach ($base_css_files as $css_file=>$css_url) {
47 $css_file_theme=substr($css_file,0,-4);
48 // echo $css_file_theme;
49 $css_link_html.=css_link($css_url, $css_file_theme, ($css_file_theme!=$themeid), 'screen', '');
50 }
51
52 /** output CSS links **/
53 echo $css_link_html;
54
55 /**
56 * Function to list files within a css directory, used when querying for theme directories
57 *
58 **/
59 function list_css_files($cssdir,$cssroot) {
60 if (!$cssroot OR !$cssdir) return false;
61 $files=array();
62 if (is_dir($cssdir)) {
63 if ($dh = opendir($cssdir)) {
64 while (($file = readdir($dh)) !== false) {
65 if ((strlen($file)>3) AND strtolower(substr($file,strlen($file)-3,3))=='css') {
66 $files[$file]="$cssroot/$file";
67 }
68 }
69 }
70 closedir($dh);
71 }
72 if (count($files)>0) {
73 // sort($files);
74 return $files;
75 }
76 return false;
77 }
78
79 /**
80 * Function to create stylesheet links that will work for multiple browsers
81 *
82 **/
83 function css_link($url, $name = null, $alt = true, $mtype = 'screen', $xhtml_end='/') {
84 global $http_site_root;
85
86 if ( empty($url) )
87 return '';
88 // set to lower case to avoid errors
89 $browser_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
90
91 if (stristr($browser_user_agent, "msie 4"))
92 {
93 $browser = 'msie4';
94 $dom_browser = false;
95 $is_IE = true;
96 }
97 elseif (stristr($browser_user_agent, "msie"))
98 {
99 $browser = 'msie';
100 $dom_browser = true;
101 $is_IE = true;
102 }
103
104 if ((strpos($url, '-ie')!== false) and !$is_IE) {
105 //not IE, so don't render this sheet
106 return;
107 }
108
109 if ( strpos($url, 'print') !== false )
110 $mtype = 'print';
111
112 $href = 'href="'.$url.'" ';
113 $media = 'media="'.$mtype.'" ';
114
115 if ( empty($name) ) {
116 $title = '';
117 $rel = 'rel="stylesheet" ';
118 } else {
119 $title = empty($name) ? '' : 'title="'.$name.'" ';
120 $rel = 'rel="'.( $alt ? 'alternate ' : '' ).'stylesheet" ';
121 }
122
123 return ' <link '.$media.$title.$rel.'type="text/css" '.$href." $xhtml_end>\n";
124 }
125
126 /**
127 * $Log$
128 * Revision 1.2 2006/07/09 22:37:35 vanmer
129 * - added variable initalization and check on variable
130 *
131 * Revision 1.1 2006/07/09 22:23:03 vanmer
132 * - intial revision of a template to display CSS links at the top of the page
133 *
134 *
135 **/
136 ?>