PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/MantisBT/core/prepare_api.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 94 lines | 36 code | 12 blank | 46 comment | 8 complexity | 8c37e8a06b1aaff3bdae31879b47ca7d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. # MantisBT - a php based bugtracking system
  3. # MantisBT is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # MantisBT is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * this file handles preparing of strings like to be printed
  17. * or stored. print_api.php will gradually be replaced by
  18. * think calls to echo the results of functions implemented here.
  19. * @package CoreAPI
  20. * @subpackage PrepareAPI
  21. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  22. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  23. * @link http://www.mantisbt.org
  24. */
  25. /**
  26. * return the mailto: href string link
  27. * @param string $p_email
  28. * @param string $p_text
  29. * @return string
  30. */
  31. function prepare_email_link( $p_email, $p_text ) {
  32. if( !access_has_project_level( config_get( 'show_user_email_threshold' ) ) ) {
  33. return string_display_line( $p_text );
  34. }
  35. # If we apply string_url() to the whole mailto: link then the @
  36. # gets turned into a %40 and you can't right click in browsers to
  37. # do Copy Email Address.
  38. $t_mailto = string_attribute( 'mailto:' . $p_email );
  39. $p_text = string_display_line( $p_text );
  40. return '<a href="' . $t_mailto . '">' . $p_text . '</a>';
  41. }
  42. /**
  43. * prepares the name of the user given the id. also makes it an email link.
  44. * @param int $p_user_id
  45. * @return string
  46. */
  47. function prepare_user_name( $p_user_id ) {
  48. # Catch a user_id of NO_USER (like when a handler hasn't been assigned)
  49. if( NO_USER == $p_user_id ) {
  50. return '';
  51. }
  52. $t_username = user_get_name( $p_user_id );
  53. if( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) {
  54. $t_username = string_display_line( $t_username );
  55. return '<a href="' . string_sanitize_url( 'view_user_page.php?id=' . $p_user_id, true ) . '">' . $t_username . '</a>';
  56. } else {
  57. $t_result = '<font STYLE="text-decoration: line-through">';
  58. $t_result .= string_display_line( $t_username );
  59. $t_result .= '</font>';
  60. return $t_result;
  61. }
  62. }
  63. /**
  64. * A function that prepares the version string for outputting to the user on view / print issue pages.
  65. * This function would add the version date, if appropriate.
  66. *
  67. * @param integer $p_project_id The project id.
  68. * @param integer $p_version_id The version id. If false then this method will return an empty string.
  69. * @return The formatted version string.
  70. */
  71. function prepare_version_string( $p_project_id, $p_version_id ) {
  72. if ( $p_version_id === false ) {
  73. return '';
  74. }
  75. $t_version_text = version_full_name( $p_version_id, /* showProject */ null, $p_project_id );
  76. if ( access_has_project_level( config_get( 'show_version_dates_threshold' ), $p_project_id ) ) {
  77. $t_short_date_format = config_get( 'short_date_format' );
  78. $t_version = version_get( $p_version_id );
  79. $t_version_text .= ' (' . date( $t_short_date_format, $t_version->date_order ) . ')';
  80. }
  81. return $t_version_text;
  82. }