5 * Template for rendering the links to css sheets for the page
7 * @copyright © 1999-2006 The SquirrelMail Project Team
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @package squirrelmail
11 * @subpackage templates
14 /** add required includes */
17 /** extract variables */
23 $template_css_file="templates/$templateid/$templateid.css";
25 /** Add URLs to the $css_files array to have them added as links before any theme css or style.php output **/
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;
31 $base_css_files=list_css_files(SM_PATH.$base_css,$base_uri.$base_css);
33 if (!$base_css_files) $base_css_files=array();
35 /** Add link to default.css in the css directory **/
37 $css_url=$base_uri.$base_css."/default.css";
38 $css_link_html=css_link($css_url, null, false, 'all','');
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', '');
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', '');
52 /** output CSS links **/
56 * Function to list files within a css directory, used when querying for theme directories
59 function list_css_files($cssdir,$cssroot) {
60 if (!$cssroot OR !$cssdir) return false;
61 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";
80 * Function to create stylesheet links that will work for multiple browsers
83 function css_link($url, $name = null, $alt = true, $mtype = 'screen', $xhtml_end='/') {
84 global $http_site_root;
88 // set to lower case to avoid errors
89 $browser_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
91 if (stristr($browser_user_agent, "msie 4"))
97 elseif (stristr($browser_user_agent, "msie"))
104 if ((strpos($url, '-ie')!== false) and !$is_IE) {
105 //not IE, so don't render this sheet
109 if ( strpos($url, 'print') !== false )
112 $href = 'href="'.$url.'" ';
113 $media = 'media="'.$mtype.'" ';
115 if ( empty($name) ) {
117 $rel = 'rel="stylesheet" ';
119 $title = empty($name) ? '' : 'title="'.$name.'" ';
120 $rel = 'rel="'.( $alt ? 'alternate ' : '' ).'stylesheet" ';
123 return ' <link '.$media.$title.$rel.'type="text/css" '.$href." $xhtml_end>\n";
128 * Revision 1.1 2006/07/09 22:23:03 vanmer
129 * - intial revision of a template to display CSS links at the top of the page