| 1 | <?php |
| 2 | /** |
| 3 | * util_global.php |
| 4 | * |
| 5 | * Utility functions for use with all templates. Do not echo output here! |
| 6 | * |
| 7 | * @copyright © 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 | 'alt="'.$alt_text.'" '. |
| 40 | (!empty($alt_text) ? 'title="'.$alt_text.'" ' : '') . |
| 41 | (!is_null($w) ? 'width="'.$w.'" ' : '') . |
| 42 | (!is_null($h) ? 'height="'.$h.'" ' : '') . |
| 43 | ' />'; |
| 44 | } else { |
| 45 | $icon = $text_icon; |
| 46 | } |
| 47 | } |
| 48 | return $icon; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Gets the path to the specified icon or returns NULL if the image is not |
| 53 | * found. This has been separated from getIcon to allow the path to be fetched |
| 54 | * for use w/ third party packages, e.g. dTree. |
| 55 | * |
| 56 | * @param string $icon_theme_path User's chosen icon set |
| 57 | * @param string $icon_name File name of the desired icon |
| 58 | * @return string $icon String containing path to icon that can be used in |
| 59 | * an IMG tag, or NULL if the image is not found. |
| 60 | * @author Steve Brown |
| 61 | * @since 1.5.2 |
| 62 | */ |
| 63 | function getIconPath ($icon_theme_path, $icon_name) { |
| 64 | global $default_icon_theme; |
| 65 | |
| 66 | if (is_null($icon_theme_path)) |
| 67 | return NULL; |
| 68 | |
| 69 | // Desired icon exists in the current theme? |
| 70 | if (is_file($icon_theme_path . $icon_name)) { |
| 71 | return $icon_theme_path . $icon_name; |
| 72 | |
| 73 | // Icon not found, check for the admin-specified default |
| 74 | } elseif (!is_null($default_icon_theme) && is_file($default_icon_theme . $icon_name)) { |
| 75 | return $default_icon_theme . $icon_name; |
| 76 | |
| 77 | // Icon not found, return the SQM default icon |
| 78 | } elseif (is_file(SM_PATH . 'images/themes/default/'.$icon_name)) { |
| 79 | return SM_PATH . 'images/themes/default/'.$icon_name; |
| 80 | } |
| 81 | |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Display error messages for use in footer.tpl |
| 87 | * |
| 88 | * @author Steve Brown |
| 89 | * @since 1.5.2 |
| 90 | **/ |
| 91 | function displayErrors () { |
| 92 | global $oErrorHandler; |
| 93 | |
| 94 | if ($oErrorHandler) { |
| 95 | $oErrorHandler->displayErrors(); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Make the internal show_readable_size() function available to templates. |
| 101 | * |
| 102 | * @param int size to be converted to human-readable |
| 103 | * @return string human-readable form |
| 104 | * @since 1.5.2 |
| 105 | **/ |
| 106 | function humanReadableSize ($size) { |
| 107 | return show_readable_size($size); |
| 108 | } |
| 109 | |