6 * This file is intended to contain helper functions for template sets
7 * that would like to use them.
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
17 * Create stylesheet links that will work for multiple browsers
19 * @param string $uri The URI to the linked stylesheet.
20 * @param string $name The title of the stylesheet (optional; default empty).
21 * @param boolean $alt Whether or not this is an alternate
22 * stylesheet (optional; default TRUE).
23 * @param string $mtype The target media display type (optional; default "screen").
24 * @param string $xhtml_end The XHTML-compliant close tag syntax to
25 * use (optional; default "/")
27 * @return string The full text of the stylesheet link.
30 function create_css_link($uri, $name='', $alt=TRUE, $mtype='screen', $xhtml_end='/') {
31 // FIXME: Add closing / to link and meta elements only after
32 // switching to xhtml 1.0 Transitional.
33 // It is not compatible with html 4.01 Transitional
40 // set to lower case to avoid errors
42 sqGetGlobalVar('HTTP_USER_AGENT', $browser_user_agent, SQ_SERVER
);
43 $browser_user_agent = strtolower($browser_user_agent);
45 if (stristr($browser_user_agent, "msie 4")) {
49 } elseif (stristr($browser_user_agent, "msie")
50 && stristr($browser_user_agent, 'opera') === FALSE) {
56 if ((strpos($uri, '-ie')!== false) and !$is_IE) {
57 //not IE, so don't render this sheet
61 if ( strpos($uri, 'print') !== false )
64 $href = 'href="'.$uri.'" ';
65 $media = 'media="'.$mtype.'" ';
69 $rel = 'rel="stylesheet" ';
71 $title = 'title="'.$name.'" ';
72 $rel = 'rel="'.( $alt ?
'alternate ' : '' ).'stylesheet" ';
75 return '<link '.$media.$title.$rel.'type="text/css" '.$href." $xhtml_end>\n";
80 * Checks for an image icon and returns a complete image tag or a text
81 * string with the text icon based on what is found and user prefs.
83 * @param string $icon_theme_path User's chosen icon set
84 * @param string $icon_name File name of the desired icon
85 * @param string $text_icon Text-based icon to display if desired
86 * @param string $alt_text Optional. Text for alt/title attribute of image
87 * @param integer $w Optional. Width of requested image.
88 * @param integer $h Optional. Height of requested image.
90 * @return string $icon String containing icon that can be echo'ed
96 function getIcon($icon_theme_path, $icon_name, $text_icon, $alt_text='', $w=NULL, $h=NULL) {
98 if (is_null($icon_theme_path)) {
101 $icon_path = getIconPath($icon_theme_path, $icon_name);
103 // If we found an icon, build an img tag to display it. If we didn't
104 // find an image, we will revert back to the text icon.
105 if (!is_null($icon_path)) {
106 $icon = create_image($icon_path, $alt_text, $w, $h, '', '', '',
107 '', $alt_text, '', '', '', $text_icon);
117 * Gets the path to the specified icon or returns NULL if the image is not
118 * found. This has been separated from getIcon to allow the path to be fetched
119 * for use w/ third party packages, e.g. dTree.
121 * @param string $icon_theme_path User's chosen icon set
122 * @param string $icon_name File name of the desired icon
124 * @return string $icon String containing path to icon that can be used in
125 * an IMG tag, or NULL if the image is not found.
127 * @author Steve Brown
131 function getIconPath ($icon_theme_path, $icon_name) {
132 global $fallback_icon_theme_path;
134 if (is_null($icon_theme_path))
137 // Desired icon exists in the current theme?
138 if (is_file($icon_theme_path . $icon_name)) {
139 return $icon_theme_path . $icon_name;
141 // Icon not found, check for the admin-specified fallback
142 } elseif (!is_null($fallback_icon_theme_path) && is_file($fallback_icon_theme_path . $icon_name)) {
143 return $fallback_icon_theme_path . $icon_name;
145 // Icon not found, return the SQM default icon
146 } elseif (is_file(SM_PATH
. 'images/themes/default/'.$icon_name)) {
147 return SM_PATH
. 'images/themes/default/'.$icon_name;
155 * Display error messages for use in footer.tpl
157 * @author Steve Brown
160 function displayErrors () {
161 global $oErrorHandler;
163 if ($oErrorHandler) {
164 $oErrorHandler->displayErrors();
170 * Make the internal show_readable_size() function available to templates.
171 //FIXME: I think this is needless since there is no reason templates cannot just call directly to show_readable_size
173 * @param int size to be converted to human-readable
174 * @return string human-readable form
177 function humanReadableSize ($size) {
178 return show_readable_size($size);