2 # MantisBT - A PHP based bugtracking system
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.
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.
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/>.
20 * Handles preparation of strings prior to be printed or stored.
23 * @subpackage PrepareAPI
24 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
25 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
26 * @link http://www.mantisbt.org
28 * @uses access_api.php
29 * @uses config_api.php
30 * @uses constant_inc.php
31 * @uses string_api.php
33 * @uses version_api.php
36 require_api( 'access_api.php' );
37 require_api( 'config_api.php' );
38 require_api( 'constant_inc.php' );
39 require_api( 'string_api.php' );
40 require_api( 'user_api.php' );
41 require_api( 'version_api.php' );
44 * return the mailto: href string link
45 * @param string $p_email
46 * @param string $p_text
49 function prepare_email_link( $p_email, $p_text ) {
50 if( !access_has_project_level( config_get( 'show_user_email_threshold' ) ) ) {
51 return string_display_line( $p_text );
54 # If we apply string_url() to the whole mailto: link then the @
55 # gets turned into a %40 and you can't right click in browsers to
56 # do Copy Email Address.
57 $t_mailto = string_attribute( 'mailto:' . $p_email );
58 $p_text = string_display_line( $p_text );
60 return '<a href="' . $t_mailto . '">' . $p_text . '</a>';
64 * prepares the name of the user given the id. also makes it an email link.
65 * @param int $p_user_id
68 function prepare_user_name( $p_user_id ) {
69 # Catch a user_id of NO_USER (like when a handler hasn't been assigned)
70 if( NO_USER
== $p_user_id ) {
74 $t_username = user_get_name( $p_user_id );
75 if( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) {
76 $t_username = string_display_line( $t_username );
77 return '<a href="' . string_sanitize_url( 'view_user_page.php?id=' . $p_user_id, true ) . '">' . $t_username . '</a>';
79 $t_result = '<font STYLE="text-decoration: line-through">';
80 $t_result .= string_display_line( $t_username );
81 $t_result .= '</font>';
87 * A function that prepares the version string for outputting to the user on view / print issue pages.
88 * This function would add the version date, if appropriate.
90 * @param integer $p_project_id The project id.
91 * @param integer $p_version_id The version id. If false then this method will return an empty string.
92 * @return The formatted version string.
94 function prepare_version_string( $p_project_id, $p_version_id ) {
95 if ( $p_version_id === false ) {
99 $t_version_text = version_full_name( $p_version_id, /* showProject */ null, $p_project_id );
101 if ( access_has_project_level( config_get( 'show_version_dates_threshold' ), $p_project_id ) ) {
102 $t_short_date_format = config_get( 'short_date_format' );
104 $t_version = version_get( $p_version_id );
105 $t_version_text .= ' (' . date( $t_short_date_format, $t_version->date_order
) . ')';
108 return $t_version_text;