1<?php
2# MantisBT - A PHP based bugtracking system
3
4# MantisBT is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 2 of the License, or
7# (at your option) any later version.
8#
9# MantisBT is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Icon API
19 *
20 * @package CoreAPI
21 * @subpackage IconAPI
22 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
23 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
24 * @link http://www.mantisbt.org
25 *
26 * @uses config_api.php
27 * @uses constant_inc.php
28 * @uses helper_api.php
29 * @uses utility_api.php
30 */
31
32require_api( 'config_api.php' );
33require_api( 'constant_inc.php' );
34require_api( 'helper_api.php' );
35require_api( 'utility_api.php' );
36
37/**
38 * Returns HTML to display an icon with optional title pop-up.
39 *
40 * @param string $p_icon       Fontawesome icon name (fa-xxx)
41 * @param string $p_classes    Optional additional CSS classes
42 * @param string $p_title      Optional pop-up text
43 * @param string $p_inner_html Optional html to insert with the icon.
44 *
45 * @return string
46 */
47function icon_get( $p_icon, $p_classes = '', $p_title = '', $p_inner_html = '' ) {
48	# Add 'fa-' prefix if missing
49	if( substr( $p_icon, 0, 3 ) != 'fa-' ) {
50		$p_icon = 'fa-' . $p_icon;
51	}
52
53	if( $p_title ) {
54		$p_title = 'title="' . $p_title . '"';
55	}
56
57	/** @noinspection HtmlUnknownAttribute */
58	return sprintf( '<i class="fa %s %s" %s>%s</i>', $p_icon, $p_classes, $p_title, $p_inner_html );
59}
60
61/**
62 * Prints an icon with optional title pop-up.
63 *
64 * @param string $p_icon    Fontawesome icon name (fa-xxx)
65 * @param string $p_classes Optional additional CSS classes
66 * @param string $p_title   Optional pop-up text
67 * @param string $p_inner_html Optional html to insert with the icon.
68 */
69function print_icon( $p_icon, $p_classes = '', $p_title = '', $p_inner_html = '' ) {
70	echo icon_get( $p_icon, $p_classes, $p_title, $p_inner_html );
71}
72
73/**
74 * gets the status icon
75 * @param string $p_icon Icon file name.
76 * @return string html img tag containing status icon
77 * @access public
78 */
79function icon_get_status_icon( $p_icon ) {
80	$t_status_icon_arr = config_get( 'status_icon_arr' );
81	$t_priotext = get_enum_element( 'priority', $p_icon );
82	if( isset( $t_status_icon_arr[$p_icon] ) && !is_blank( $t_status_icon_arr[$p_icon] ) ) {
83		return icon_get( $t_status_icon_arr[$p_icon], '', $t_priotext );
84	} else {
85		return '&#160;';
86	}
87}
88
89/**
90 * prints the status icon
91 * @param string $p_icon Icon file name.
92 * @return void
93 * @access public
94 */
95function print_status_icon( $p_icon ) {
96	echo icon_get_status_icon( $p_icon );
97}
98
99/**
100 * The input $p_dir is either ASC or DESC
101 * The inputs $p_sort_by and $p_field are compared to see if they match
102 * If the fields match then the sort icon is printed
103 * This is a convenience feature to push the comparison code into this function instead of in the
104 * page(s)
105 * $p_field is a constant and $p_sort_by is whatever the page happens to be sorting by at the moment
106 * Multiple sort keys are not supported
107 * @param integer $p_dir     Direction to sort by ( either ASC or DESC ).
108 * @param string  $p_sort_by Field.
109 * @param string  $p_field   Field to sort by.
110 * @return void
111 * @access public
112 */
113function print_sort_icon( $p_dir, $p_sort_by, $p_field ) {
114	$t_sort_icon_arr = config_get( 'sort_icon_arr' );
115
116	if( $p_sort_by != $p_field ) {
117		return;
118	}
119
120	if( ( 'DESC' == $p_dir ) || ( DESCENDING == $p_dir ) ) {
121		$t_dir = DESCENDING;
122	} else {
123		$t_dir = ASCENDING;
124	}
125
126	echo '&#160;';
127	if( !is_blank( $t_sort_icon_arr[$t_dir] ) ) {
128		echo icon_get( $t_sort_icon_arr[$t_dir], 'fa-lg blue' );
129	}
130}
131