29997535 |
1 | <?php |
62f9cbcc |
2 | |
29997535 |
3 | /** |
7695c5e2 |
4 | * general_util.php |
29997535 |
5 | * |
62f9cbcc |
6 | * This file is intended to contain helper functions for template sets |
7 | * that would like to use them. |
29997535 |
8 | * |
9 | * @copyright © 1999-2006 The SquirrelMail Project Team |
10 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
11 | * @version $Id$ |
12 | * @package squirrelmail |
29997535 |
13 | */ |
62f9cbcc |
14 | |
15 | |
16 | /** |
17 | * Create stylesheet links that will work for multiple browsers |
18 | * |
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 "/") |
26 | * |
27 | * @return string The full text of the stylesheet link. |
28 | * |
29 | */ |
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 |
34 | $xhtml_end=''; |
35 | |
36 | if (empty($uri)) { |
37 | return ''; |
38 | } |
39 | |
40 | // set to lower case to avoid errors |
41 | // |
42 | sqGetGlobalVar('HTTP_USER_AGENT', $browser_user_agent, SQ_SERVER); |
43 | $browser_user_agent = strtolower($browser_user_agent); |
44 | |
45 | if (stristr($browser_user_agent, "msie 4")) { |
46 | $browser = 'msie4'; |
47 | $dom_browser = false; |
48 | $is_IE = true; |
49 | } elseif (stristr($browser_user_agent, "msie") |
50 | && stristr($browser_user_agent, 'opera') === FALSE) { |
51 | $browser = 'msie'; |
52 | $dom_browser = true; |
53 | $is_IE = true; |
54 | } |
55 | |
56 | if ((strpos($uri, '-ie')!== false) and !$is_IE) { |
57 | //not IE, so don't render this sheet |
58 | return; |
59 | } |
60 | |
61 | if ( strpos($uri, 'print') !== false ) |
62 | $mtype = 'print'; |
63 | |
64 | $href = 'href="'.$uri.'" '; |
65 | $media = 'media="'.$mtype.'" '; |
66 | |
67 | if ( empty($name) ) { |
68 | $title = ''; |
69 | $rel = 'rel="stylesheet" '; |
70 | } else { |
71 | $title = 'title="'.$name.'" '; |
72 | $rel = 'rel="'.( $alt ? 'alternate ' : '' ).'stylesheet" '; |
73 | } |
74 | |
75 | return '<link '.$media.$title.$rel.'type="text/css" '.$href." $xhtml_end>\n"; |
76 | } |
77 | |
78 | |
29997535 |
79 | /** |
efb5bde8 |
80 | * Checks for an image icon and returns a complete image tag or a text |
29997535 |
81 | * string with the text icon based on what is found and user prefs. |
62f9cbcc |
82 | * |
29997535 |
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. |
89 | * @return string $icon String containing icon that can be echo'ed |
90 | * @author Steve Brown |
91 | * @since 1.5.2 |
92 | */ |
93 | function getIcon($icon_theme_path, $icon_name, $text_icon, $alt_text='', $w=NULL, $h=NULL) { |
94 | $icon = ''; |
95 | if (is_null($icon_theme_path)) { |
96 | $icon = $text_icon; |
97 | } else { |
7c8f16f3 |
98 | $icon_path = getIconPath($icon_theme_path, $icon_name); |
29997535 |
99 | |
29997535 |
100 | // If we found an icon, build an img tag to display it. If we didn't |
101 | // find an image, we will revert back to the text icon. |
7c8f16f3 |
102 | if (!is_null($icon_path)) { |
efb5bde8 |
103 | global $oTemplate; |
104 | $oTemplate->assign('src', $icon_path); |
105 | $oTemplate->assign('alt', $alt_text); |
106 | $oTemplate->assign('title', $alt_text); |
107 | $oTemplate->assign('width', $w); |
108 | $oTemplate->assign('height', $h); |
109 | |
110 | // blank other attributes because the template |
111 | // object might already contain values due to |
112 | // having been used to show another image before |
113 | // this one |
114 | // |
115 | $oTemplate->assign('onclick', ''); |
116 | $oTemplate->assign('align', ''); |
117 | $oTemplate->assign('border', ''); |
118 | $oTemplate->assign('hspace', ''); |
119 | $oTemplate->assign('vspace', ''); |
522a2253 |
120 | $oTemplate->assign('class', ''); |
121 | $oTemplate->assign('id', ''); |
efb5bde8 |
122 | |
123 | $icon = $oTemplate->fetch('image.tpl'); |
29997535 |
124 | } else { |
125 | $icon = $text_icon; |
126 | } |
127 | } |
62f9cbcc |
128 | return $icon; |
29997535 |
129 | } |
7c8f16f3 |
130 | |
62f9cbcc |
131 | |
7c8f16f3 |
132 | /** |
133 | * Gets the path to the specified icon or returns NULL if the image is not |
134 | * found. This has been separated from getIcon to allow the path to be fetched |
135 | * for use w/ third party packages, e.g. dTree. |
62f9cbcc |
136 | * |
7c8f16f3 |
137 | * @param string $icon_theme_path User's chosen icon set |
138 | * @param string $icon_name File name of the desired icon |
139 | * @return string $icon String containing path to icon that can be used in |
140 | * an IMG tag, or NULL if the image is not found. |
141 | * @author Steve Brown |
142 | * @since 1.5.2 |
143 | */ |
144 | function getIconPath ($icon_theme_path, $icon_name) { |
341fd984 |
145 | global $fallback_icon_theme_path; |
74db4ed2 |
146 | |
7c8f16f3 |
147 | if (is_null($icon_theme_path)) |
148 | return NULL; |
62f9cbcc |
149 | |
7c8f16f3 |
150 | // Desired icon exists in the current theme? |
151 | if (is_file($icon_theme_path . $icon_name)) { |
152 | return $icon_theme_path . $icon_name; |
62f9cbcc |
153 | |
341fd984 |
154 | // Icon not found, check for the admin-specified fallback |
155 | } elseif (!is_null($fallback_icon_theme_path) && is_file($fallback_icon_theme_path . $icon_name)) { |
156 | return $fallback_icon_theme_path . $icon_name; |
62f9cbcc |
157 | |
7c8f16f3 |
158 | // Icon not found, return the SQM default icon |
159 | } elseif (is_file(SM_PATH . 'images/themes/default/'.$icon_name)) { |
160 | return SM_PATH . 'images/themes/default/'.$icon_name; |
62f9cbcc |
161 | } |
162 | |
7c8f16f3 |
163 | return NULL; |
164 | } |
f6dccc95 |
165 | |
62f9cbcc |
166 | |
f6dccc95 |
167 | /** |
168 | * Display error messages for use in footer.tpl |
62f9cbcc |
169 | * |
f6dccc95 |
170 | * @author Steve Brown |
171 | * @since 1.5.2 |
172 | **/ |
173 | function displayErrors () { |
174 | global $oErrorHandler; |
62f9cbcc |
175 | |
e1603e71 |
176 | if ($oErrorHandler) { |
177 | $oErrorHandler->displayErrors(); |
178 | } |
179 | } |
180 | |
62f9cbcc |
181 | |
e1603e71 |
182 | /** |
183 | * Make the internal show_readable_size() function available to templates. |
62f9cbcc |
184 | //FIXME: I think this is needless since there is no reason templates cannot just call directly to show_readable_size |
185 | * |
e1603e71 |
186 | * @param int size to be converted to human-readable |
187 | * @return string human-readable form |
188 | * @since 1.5.2 |
189 | **/ |
190 | function humanReadableSize ($size) { |
191 | return show_readable_size($size); |
f6dccc95 |
192 | } |
e1603e71 |
193 | |
62f9cbcc |
194 | |