updating error_box() function calls. second argument was modified.
[squirrelmail.git] / templates / util_global.php
1 <?php
2 /**
3 * util_global.php
4 *
5 * Utility functions for use with all templates. Do not echo output here!
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 /**
15 * Checks for an image icon and returns a complete HTML img tag or a text
16 * string with the text icon based on what is found and user prefs.
17 *
18 * @param string $icon_theme_path User's chosen icon set
19 * @param string $icon_name File name of the desired icon
20 * @param string $text_icon Text-based icon to display if desired
21 * @param string $alt_text Optional. Text for alt/title attribute of image
22 * @param integer $w Optional. Width of requested image.
23 * @param integer $h Optional. Height of requested image.
24 * @return string $icon String containing icon that can be echo'ed
25 * @author Steve Brown
26 * @since 1.5.2
27 */
28 function getIcon($icon_theme_path, $icon_name, $text_icon, $alt_text='', $w=NULL, $h=NULL) {
29 $icon = '';
30 if (is_null($icon_theme_path)) {
31 $icon = $text_icon;
32 } else {
33 $icon_path = getIconPath($icon_theme_path, $icon_name);
34
35 // If we found an icon, build an img tag to display it. If we didn't
36 // find an image, we will revert back to the text icon.
37 if (!is_null($icon_path)) {
38 $icon = '<img src="'.$icon_path.'" ' .
39 (!empty($alt_text) ? 'alt="'.$alt_text.'" title="'.$alt_text.'" ' : '') .
40 (!is_null($w) ? 'width="'.$w.'" ' : '') .
41 (!is_null($h) ? 'height="'.$h.'" ' : '') .
42 ' />';
43 } else {
44 $icon = $text_icon;
45 }
46 }
47 return $icon;
48 }
49
50 /**
51 * Gets the path to the specified icon or returns NULL if the image is not
52 * found. This has been separated from getIcon to allow the path to be fetched
53 * for use w/ third party packages, e.g. dTree.
54 *
55 * @param string $icon_theme_path User's chosen icon set
56 * @param string $icon_name File name of the desired icon
57 * @return string $icon String containing path to icon that can be used in
58 * an IMG tag, or NULL if the image is not found.
59 * @author Steve Brown
60 * @since 1.5.2
61 */
62 function getIconPath ($icon_theme_path, $icon_name) {
63 if (is_null($icon_theme_path))
64 return NULL;
65
66 // Desired icon exists in the current theme?
67 if (is_file($icon_theme_path . $icon_name)) {
68 return $icon_theme_path . $icon_name;
69
70 // Icon not found, return the SQM default icon
71 } elseif (is_file(SM_PATH . 'images/themes/default/'.$icon_name)) {
72 return SM_PATH . 'images/themes/default/'.$icon_name;
73 }
74
75 return NULL;
76 }
77 ?>