add purge link when folder contains subfolders.
[squirrelmail.git] / templates / util_global.php
CommitLineData
29997535 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 */
28function 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 {
7c8f16f3 33 $icon_path = getIconPath($icon_theme_path, $icon_name);
29997535 34
29997535 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.
7c8f16f3 37 if (!is_null($icon_path)) {
29997535 38 $icon = '<img src="'.$icon_path.'" ' .
38469948 39 'alt="'.$alt_text.'" '.
40 (!empty($alt_text) ? 'title="'.$alt_text.'" ' : '') .
29997535 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}
7c8f16f3 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 */
63function getIconPath ($icon_theme_path, $icon_name) {
64 if (is_null($icon_theme_path))
65 return NULL;
66
67 // Desired icon exists in the current theme?
68 if (is_file($icon_theme_path . $icon_name)) {
69 return $icon_theme_path . $icon_name;
70
71 // Icon not found, return the SQM default icon
72 } elseif (is_file(SM_PATH . 'images/themes/default/'.$icon_name)) {
73 return SM_PATH . 'images/themes/default/'.$icon_name;
74 }
75
76 return NULL;
77}