| [ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: string_api.php,v 1.92.2.1 2007-10-13 22:35:43 giallu Exp $ 22 # -------------------------------------------------------- 23 24 $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR; 25 26 require_once ( $t_core_dir . 'bug_api.php' ); 27 require_once ( $t_core_dir . 'user_pref_api.php' ); 28 29 ### String Processing API ### 30 31 ### -------------------- 32 # Preserve spaces at beginning of lines. 33 # Lines must be separated by \n rather than <br /> 34 function string_preserve_spaces_at_bol( $p_string ) { 35 $lines = explode( "\n", $p_string ); 36 $line_count = count( $lines ); 37 for ( $i = 0; $i < $line_count; $i++ ) { 38 $count = 0; 39 $prefix = ''; 40 41 $t_char = substr( $lines[$i], $count, 1 ); 42 $spaces = 0; 43 while ( ( $t_char == ' ' ) || ( $t_char == "\t" ) ) { 44 if ( $t_char == ' ' ) 45 $spaces++; 46 else 47 $spaces += 4; // 1 tab = 4 spaces, can be configurable. 48 49 $count++; 50 $t_char = substr( $lines[$i], $count, 1 ); 51 } 52 53 for ( $j = 0; $j < $spaces; $j++ ) { 54 $prefix .= ' '; 55 } 56 57 $lines[$i] = $prefix . substr( $lines[$i], $count ); 58 } 59 return implode( "\n", $lines ); 60 } 61 # -------------------- 62 # Prepare a string to be printed without being broken into multiple lines 63 function string_no_break( $p_string ) { 64 if ( strpos( $p_string, ' ' ) !== false ) { 65 return '<span class="nowrap">' . $p_string . "</span>"; 66 } else { 67 return $p_string; 68 } 69 } 70 71 # -------------------- 72 # Similar to nl2br, but fixes up a problem where new lines are doubled between 73 # <pre> tags. 74 # additionally, wrap the text an $p_wrap character intervals if the config is set 75 function string_nl2br( $p_string, $p_wrap = 100 ) { 76 $p_string = nl2br( $p_string ); 77 78 # fix up eols within <pre> tags (#1146) 79 $pre2 = array(); 80 preg_match_all("/<pre[^>]*?>(.|\n)*?<\/pre>/", $p_string, $pre1); 81 for ( $x = 0; $x < count($pre1[0]); $x++ ) { 82 $pre2[$x] = preg_replace("/<br[^>]*?>/", "", $pre1[0][$x]); 83 # @@@ thraxisp - this may want to be replaced by html_entity_decode (or equivalent) 84 # if other encoded characters are a problem 85 $pre2[$x] = preg_replace("/ /", " ", $pre2[$x]); 86 if ( ON == config_get( 'wrap_in_preformatted_text' ) ) { 87 $pre2[$x] = preg_replace("/([^\n]{".$p_wrap."})(?!<\/pre>)/", "$1\n", $pre2[$x]); 88 } 89 $pre1[0][$x] = "/" . preg_quote($pre1[0][$x], "/") . "/"; 90 } 91 92 return preg_replace( $pre1[0], $pre2, $p_string ); 93 } 94 95 # -------------------- 96 # Prepare a multiple line string for display to HTML 97 function string_display( $p_string ) { 98 $p_string = string_strip_hrefs( $p_string ); 99 $p_string = string_html_specialchars( $p_string ); 100 $p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true ); 101 $p_string = string_preserve_spaces_at_bol( $p_string ); 102 $p_string = string_nl2br( $p_string ); 103 104 return $p_string; 105 } 106 107 # -------------------- 108 # Prepare a single line string for display to HTML 109 function string_display_line( $p_string ) { 110 $p_string = string_strip_hrefs( $p_string ); 111 $p_string = string_html_specialchars( $p_string ); 112 $p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ false ); 113 114 return $p_string; 115 } 116 117 # -------------------- 118 # Prepare a string for display to HTML and add href anchors for URLs, emails, 119 # bug references, and cvs references 120 function string_display_links( $p_string ) { 121 $p_string = string_display( $p_string ); 122 $p_string = string_insert_hrefs( $p_string ); 123 $p_string = string_process_bug_link( $p_string ); 124 $p_string = string_process_bugnote_link( $p_string ); 125 $p_string = string_process_cvs_link( $p_string ); 126 127 return $p_string; 128 } 129 130 # -------------------- 131 # Prepare a single line string for display to HTML and add href anchors for 132 # URLs, emails, bug references, and cvs references 133 function string_display_line_links( $p_string ) { 134 $p_string = string_display_line( $p_string ); 135 $p_string = string_insert_hrefs( $p_string ); 136 $p_string = string_process_bug_link( $p_string ); 137 $p_string = string_process_bugnote_link( $p_string ); 138 $p_string = string_process_cvs_link( $p_string ); 139 140 return $p_string; 141 } 142 143 # -------------------- 144 # Prepare a string for display in rss 145 function string_rss_links( $p_string ) { 146 # rss can not start with which spaces will be replaced into by string_display(). 147 $t_string = trim( $p_string ); 148 149 # same steps as string_display_links() without the preservation of spaces since is undefined in XML. 150 $t_string = string_strip_hrefs( $t_string ); 151 $t_string = string_html_specialchars( $t_string ); 152 $t_string = string_restore_valid_html_tags( $t_string ); 153 $t_string = string_nl2br( $t_string ); 154 $t_string = string_insert_hrefs( $t_string ); 155 $t_string = string_process_bug_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true ); 156 $t_string = string_process_bugnote_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true ); 157 $t_string = string_process_cvs_link( $t_string ); 158 159 # another escaping to escape the special characters created by the generated links 160 $t_string = string_html_specialchars( $t_string ); 161 162 return $t_string; 163 } 164 165 # -------------------- 166 # Prepare a string for plain text display in email 167 function string_email( $p_string ) { 168 $p_string = string_strip_hrefs( $p_string ); 169 170 return $p_string; 171 } 172 173 # -------------------- 174 # Prepare a string for plain text display in email and add URLs for bug 175 # links and cvs links 176 function string_email_links( $p_string ) { 177 $p_string = string_email( $p_string ); 178 $p_string = string_process_bug_link( $p_string, false ); 179 $p_string = string_process_bugnote_link( $p_string, false ); 180 $p_string = string_process_cvs_link( $p_string, false ); 181 182 return $p_string; 183 } 184 185 186 187 # -------------------- 188 # Process a string for display in a textarea box 189 function string_textarea( $p_string ) { 190 $p_string = string_html_specialchars( $p_string ); 191 192 return $p_string; 193 } 194 195 # -------------------- 196 # Process a string for display in a text box 197 function string_attribute( $p_string ) { 198 $p_string = string_html_specialchars( $p_string ); 199 200 return $p_string; 201 } 202 203 # -------------------- 204 # Process a string for inclusion in a URL as a GET parameter 205 function string_url( $p_string ) { 206 $p_string = rawurlencode( $p_string ); 207 208 return $p_string; 209 } 210 211 # -------------------- 212 # validate the url as part of this site before continuing 213 function string_sanitize_url( $p_url ) { 214 $t_url = strip_tags( urldecode( $p_url ) ); 215 if ( preg_match( '?http(s)*://?', $t_url ) > 0 ) { 216 // no embedded addresses 217 if ( preg_match( '?^' . config_get( 'path' ) . '?', $t_url ) == 0 ) { 218 // url is ok if it begins with our path, if not, replace it 219 $t_url = 'index.php'; 220 } 221 } 222 if ( $t_url == '' ) { 223 $t_url = 'index.php'; 224 } 225 226 // split and encode parameters 227 if ( strpos( $t_url, '?' ) !== FALSE ) { 228 list( $t_path, $t_param ) = split( '\?', $t_url, 2 ); 229 if ( !is_blank($t_param ) ) { 230 $t_vals = array(); 231 parse_str( html_entity_decode( $t_param ), $t_vals ); 232 $t_param = ''; 233 foreach( $t_vals as $k => $v ) { 234 if ( $t_param != '' ) { 235 $t_param .= '&'; 236 } 237 if ( is_array( $v ) ) { 238 for ( $i = 0, $t_size = sizeof( $v ); $i < $t_size; $i++ ) { 239 $t_param .= $k . urlencode( '[]' ) . '=' . urlencode( strip_tags( urldecode( $v[$i] ) ) ); 240 $t_param .= ( $i != $t_size - 1 ) ? '&' : ''; 241 } 242 } else { 243 $t_param .= "$k=" . urlencode( strip_tags( urldecode( $v ) ) ); 244 } 245 } 246 return $t_path . '?' . $t_param; 247 } else { 248 return $t_path; 249 } 250 } else { 251 return $t_url; 252 } 253 } 254 255 # -------------------- 256 # process the $p_string and convert filenames in the format 257 # cvs:filename.ext or cvs:filename.ext:n.nn to a html link 258 # if $p_include_anchor is true, include an <a href="..."> tag, 259 # otherwise, just insert the URL as text 260 function string_process_cvs_link( $p_string, $p_include_anchor=true ) { 261 $t_cvs_web = config_get( 'cvs_web' ); 262 263 if ( $p_include_anchor ) { 264 $t_replace_with = '[CVS] <a href="'.$t_cvs_web.'\\1?rev=\\4" target="_new">\\1</a>\\5'; 265 } else { 266 $t_replace_with = '[CVS] '.$t_cvs_web.'\\1?rev=\\4\\5'; 267 } 268 269 return preg_replace( '/cvs:([^\.\s:,\?!<]+(\.[^\.\s:,\?!<]+)*)(:)?(\d\.[\d\.]+)?([\W\s])?/i', 270 $t_replace_with, 271 $p_string ); 272 } 273 274 # -------------------- 275 # Process $p_string, looking for bug ID references and creating bug view 276 # links for them. 277 # 278 # Returns the processed string. 279 # 280 # If $p_include_anchor is true, include the href tag, otherwise just insert 281 # the URL 282 # 283 # The bug tag ('#' by default) must be at the beginning of the string or 284 # preceeded by a character that is not a letter, a number or an underscore 285 # 286 # if $p_include_anchor = false, $p_fqdn is ignored and assumed to true. 287 function string_process_bug_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) { 288 $t_tag = config_get( 'bug_link_tag' ); 289 # bail if the link tag is blank 290 if ( '' == $t_tag || $p_string == '' ) { 291 return $p_string; 292 } 293 294 if ($p_include_anchor) { 295 $callback = create_function('$p_array',' 296 if (bug_exists( (int)$p_array[2] ) ) { 297 return $p_array[1] . string_get_bug_view_link( $p_array[2], null, ' . ($p_detail_info ? 'true' : 'false') . ', ' . ($p_fqdn ? 'true' : 'false') . '); 298 } else { 299 return $p_array[0]; 300 } 301 '); 302 } else { 303 $callback = create_function('$p_array',' 304 # We might as well create the link here even if the bug 305 # doesnt exist. In the case above we dont want to do 306 # the summary lookup on a non-existant bug. But here, we 307 # can create the link and by the time it is clicked on, the 308 # bug may exist. 309 return $p_array[1] . string_get_bug_view_url_with_fqdn( $p_array[2], null ); 310 '); 311 } 312 313 $p_string = preg_replace_callback( '/(^|[^\w&])' . preg_quote($t_tag, '/') . '(\d+)\b/', $callback, $p_string); 314 return $p_string; 315 } 316 317 # -------------------- 318 # Process $p_string, looking for bugnote ID references and creating bug view 319 # links for them. 320 # 321 # Returns the processed string. 322 # 323 # If $p_include_anchor is true, include the href tag, otherwise just insert 324 # the URL 325 # 326 # The bugnote tag ('~' by default) must be at the beginning of the string or 327 # preceeded by a character that is not a letter, a number or an underscore 328 # 329 # if $p_include_anchor = false, $p_fqdn is ignored and assumed to true. 330 function string_process_bugnote_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) { 331 $t_tag = config_get( 'bugnote_link_tag' ); 332 333 # bail if the link tag is blank 334 if ( '' == $t_tag || $p_string == '' ) { 335 return $p_string; 336 } 337 if ($p_include_anchor) { 338 $callback = create_function('$p_array',' 339 if ( bugnote_exists( (int)$p_array[2] ) ) { 340 $t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' ); 341 if ( bug_exists( $t_bug_id ) ) { 342 return $p_array[1] . string_get_bugnote_view_link( $t_bug_id, (int)$p_array[2], null, ' . ($p_detail_info ? 'true' : 'false') . ', ' . ($p_fqdn ? 'true' : 'false') . ' ); 343 } else { 344 return $p_array[0]; 345 } 346 } else { 347 return $p_array[0]; 348 } 349 '); 350 } else { 351 $callback = create_function('$p_array',' 352 # We might as well create the link here even if the bug 353 # doesnt exist. In the case above we dont want to do 354 # the summary lookup on a non-existant bug. But here, we 355 # can create the link and by the time it is clicked on, the 356 # bug may exist. 357 $t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' ); 358 if ( bug_exists( $t_bug_id ) ) { 359 return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null ); 360 } else { 361 return $p_array[0]; 362 } 363 '); 364 } 365 $p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote($t_tag, '/') .'(\d+)\b/', $callback, $p_string); 366 return $p_string; 367 } 368 369 #=================================== 370 # Tag Processing 371 #=================================== 372 373 # -------------------- 374 # Detect URLs and email addresses in the string and replace them with href anchors 375 function string_insert_hrefs( $p_string ) { 376 if ( !config_get( 'html_make_links' ) ) { 377 return $p_string; 378 } 379 380 $t_change_quotes = false; 381 if( ini_get_bool( 'magic_quotes_sybase' ) ) { 382 $t_change_quotes = true; 383 ini_set( 'magic_quotes_sybase', false ); 384 } 385 386 # Find any URL in a string and replace it by a clickable link 387 $p_string = preg_replace( '/(([[:alpha:]][-+.[:alnum:]]*):\/\/(%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\/?%^\\\\:@&={\|}+$#\(\),\[\][:alnum:]])+)/se', 388 "'<a href=\"'.rtrim('\\1','.').'\">\\1</a> [<a href=\"'.rtrim('\\1','.').'\" target=\"_blank\">^</a>]'", 389 $p_string); 390 if( $t_change_quotes ) { 391 ini_set( 'magic_quotes_sybase', true ); 392 } 393 394 $p_string = preg_replace( '/\b' . email_regex_simple() . '\b/i', 395 '<a href="mailto:\0">\0</a>', 396 $p_string); 397 398 return $p_string; 399 } 400 401 # -------------------- 402 # Detect href anchors in the string and replace them with URLs and email addresses 403 function string_strip_hrefs( $p_string ) { 404 # First grab mailto: hrefs. We don't care whether the URL is actually 405 # correct - just that it's inside an href attribute. 406 $p_string = preg_replace( '/<a\s[^\>]*href="mailto:([^\"]+)"[^\>]*>[^\<]*<\/a>/si', 407 '\1', 408 $p_string); 409 410 # Then grab any other href 411 $p_string = preg_replace( '/<a\s[^\>]*href="([^\"]+)"[^\>]*>[^\<]*<\/a>/si', 412 '\1', 413 $p_string); 414 return $p_string; 415 } 416 417 # -------------------- 418 # This function looks for text with htmlentities 419 # like <b> and converts is into corresponding 420 # html <b> based on the configuration presets 421 function string_restore_valid_html_tags( $p_string, $p_multiline = true ) { 422 $t_html_valid_tags = config_get( $p_multiline ? 'html_valid_tags' : 'html_valid_tags_single_line' ); 423 424 if ( OFF === $t_html_valid_tags || is_blank( $t_html_valid_tags ) ) { 425 return $p_string; 426 } 427 428 $tags = explode( ',', $t_html_valid_tags ); 429 foreach ($tags as $key => $value) { 430 if ( !is_blank( $value ) ) { 431 $tags[$key] = trim($value); 432 } 433 } 434 $tags = implode( '|', $tags); 435 436 $p_string = eregi_replace( '<(' . $tags . ')[[:space:]]*>', '<\\1>', $p_string ); 437 $p_string = eregi_replace( '<\/(' .$tags . ')[[:space:]]*>', '</\\1>', $p_string ); 438 $p_string = eregi_replace( '<(' . $tags . ')[[:space:]]*\/>', '<\\1 />', $p_string ); 439 440 return $p_string; 441 } 442 443 444 #=================================== 445 # Advanced/Simple page selection 446 #=================================== 447 448 # -------------------- 449 # return the name of a bug page for the user 450 # account for the user preference and site override 451 # 452 # $p_action should be something like 'view', 'update', or 'report' 453 # If $p_user_id is null or not specified, use the current user 454 function string_get_bug_page( $p_action, $p_user_id=null ) { 455 if ( null === $p_user_id ) { 456 if ( auth_is_user_authenticated() ) { 457 $p_user_id = auth_get_current_user_id(); 458 } 459 } 460 461 $g_show_action = config_get( 'show_' . $p_action ); 462 switch ( $g_show_action ) { 463 case BOTH: 464 if ( ( null !== $p_user_id ) && 465 ( ON == user_pref_get_pref( $p_user_id, 'advanced_' . $p_action ) ) ) { 466 return 'bug_' . $p_action . '_advanced_page.php'; 467 } else { 468 return 'bug_' . $p_action . '_page.php'; 469 } 470 case SIMPLE_ONLY: 471 return 'bug_' . $p_action . '_page.php'; 472 case ADVANCED_ONLY: 473 return 'bug_' . $p_action . '_advanced_page.php'; 474 } 475 } 476 477 # -------------------- 478 # return an href anchor that links to a bug VIEW page for the given bug 479 # account for the user preference and site override 480 function string_get_bug_view_link( $p_bug_id, $p_user_id = null, $p_detail_info = true, $p_fqdn = false ) { 481 if ( bug_exists( $p_bug_id ) ) { 482 $t_link = '<a href="'; 483 if ( $p_fqdn ) { 484 $t_link .= config_get( 'path' ); 485 } 486 $t_link .= string_get_bug_view_url( $p_bug_id, $p_user_id ) . '"'; 487 if ( $p_detail_info ) { 488 $t_summary = string_attribute( bug_get_field( $p_bug_id, 'summary' ) ); 489 $t_status = string_attribute( get_enum_element( 'status', bug_get_field( $p_bug_id, 'status' ) ) ); 490 $t_link .= ' title="[' . $t_status . '] ' . $t_summary . '"'; 491 } 492 $t_link .= '>' . bug_format_id( $p_bug_id ) . '</a>'; 493 } else { 494 $t_link = bug_format_id( $p_bug_id ); 495 } 496 497 return $t_link; 498 } 499 500 # -------------------- 501 # return an href anchor that links to a bug VIEW page for the given bug 502 # account for the user preference and site override 503 function string_get_bugnote_view_link( $p_bug_id, $p_bugnote_id, $p_user_id = null, $p_detail_info = true, $p_fqdn = false ) { 504 if ( bug_exists( $p_bug_id ) && bugnote_exists( $p_bugnote_id ) ) { 505 $t_link = '<a href="'; 506 if ( $p_fqdn ) { 507 $t_link .= config_get( 'path' ); 508 } 509 510 $t_link .= string_get_bugnote_view_url( $p_bug_id, $p_bugnote_id, $p_user_id ) . '"'; 511 if ( $p_detail_info ) { 512 $t_reporter = string_attribute( user_get_name ( bugnote_get_field( $p_bugnote_id, 'reporter_id' ) ) ); 513 $t_update_date = string_attribute( date( config_get( 'normal_date_format' ), ( db_unixtimestamp( bugnote_get_field( $p_bugnote_id, 'last_modified' ) ) ) ) ); 514 $t_link .= ' title="[' . $t_update_date . '] ' . $t_reporter . '"'; 515 } 516 $t_link .= '>' . lang_get( 'bugnote' ) . ': ' . bugnote_format_id( $p_bugnote_id) . '</a>'; 517 } else { 518 $t_link = lang_get( 'bugnote' ) . ': ' . bugnote_format_id( $p_bugnote_id); 519 } 520 521 return $t_link; 522 } 523 524 # -------------------- 525 # return the name and GET parameters of a bug VIEW page for the given bug 526 # account for the user preference and site override 527 function string_get_bug_view_url( $p_bug_id, $p_user_id = null ) { 528 return 'view.php?id=' . $p_bug_id; 529 } 530 531 # -------------------- 532 # return the name and GET parameters of a bug VIEW page for the given bug 533 # account for the user preference and site override 534 function string_get_bugnote_view_url( $p_bug_id, $p_bugnote_id, $p_user_id = null ) { 535 return 'view.php?id=' . $p_bug_id . '#c'. $p_bugnote_id; 536 } 537 538 # -------------------- 539 # return the name and GET parameters of a bug VIEW page for the given bug 540 # account for the user preference and site override 541 # The returned url includes the fully qualified domain, hence it is suitable to be included 542 # in emails. 543 function string_get_bugnote_view_url_with_fqdn( $p_bug_id, $p_bugnote_id, $p_user_id = null ) { 544 return config_get( 'path' ) . string_get_bug_view_url( $p_bug_id, $p_user_id ).'#'.$p_bugnote_id; 545 } 546 547 # -------------------- 548 # return the name and GET parameters of a bug VIEW page for the given bug 549 # account for the user preference and site override 550 # The returned url includes the fully qualified domain, hence it is suitable to be included 551 # in emails. 552 function string_get_bug_view_url_with_fqdn( $p_bug_id, $p_user_id = null ) { 553 return config_get( 'path' ) . string_get_bug_view_url( $p_bug_id, $p_user_id ); 554 } 555 556 # -------------------- 557 # return the name of a bug VIEW page for the user 558 # account for the user preference and site override 559 function string_get_bug_view_page( $p_user_id = null ) { 560 return string_get_bug_page( 'view', $p_user_id ); 561 } 562 563 # -------------------- 564 # return an href anchor that links to a bug UPDATE page for the given bug 565 # account for the user preference and site override 566 function string_get_bug_update_link( $p_bug_id, $p_user_id = null ) { 567 $t_summary = string_attribute( bug_get_field( $p_bug_id, 'summary' ) ); 568 return '<a href="' . string_get_bug_update_url( $p_bug_id, $p_user_id ) . '" title="' . $t_summary . '">' . bug_format_id( $p_bug_id ) . '</a>'; 569 } 570 571 # -------------------- 572 # return the name and GET parameters of a bug UPDATE page for the given bug 573 # account for the user preference and site override 574 function string_get_bug_update_url( $p_bug_id, $p_user_id = null ) { 575 return string_get_bug_update_page( $p_user_id ) . '?bug_id=' . $p_bug_id; 576 } 577 578 # -------------------- 579 # return the name of a bug UPDATE page for the user 580 # account for the user preference and site override 581 function string_get_bug_update_page( $p_user_id = null ) { 582 return string_get_bug_page( 'update', $p_user_id ); 583 } 584 585 # -------------------- 586 # return an href anchor that links to a bug REPORT page for the given bug 587 # account for the user preference and site override 588 function string_get_bug_report_link( $p_user_id = null ) { 589 return '<a href="' . string_get_bug_report_url( $p_user_id ) . '">' . lang_get( 'report_bug_link' ) . '</a>'; 590 } 591 592 # -------------------- 593 # return the name and GET parameters of a bug REPORT page for the given bug 594 # account for the user preference and site override 595 function string_get_bug_report_url( $p_user_id = null ) { 596 return string_get_bug_report_page( $p_user_id ); 597 } 598 599 # -------------------- 600 # return the name of a bug REPORT page for the user 601 # account for the user preference and site override 602 function string_get_bug_report_page( $p_user_id = null ) { 603 return string_get_bug_page( 'report', $p_user_id ); 604 } 605 606 # -------------------- 607 # return the complete url link to checkin using the confirm_hash 608 function string_get_confirm_hash_url( $p_user_id, $p_confirm_hash ) { 609 $t_path = config_get( 'path' ); 610 return $t_path . "verify.php?id=" . string_url( $p_user_id ) . "&confirm_hash=" . string_url( $p_confirm_hash ); 611 } 612 613 # -------------------- 614 # Return a string with the $p_character pattern repeated N times. 615 # $p_character - pattern to repeat 616 # $p_repeats - number of times to repeat. 617 function string_repeat_char( $p_character, $p_repeats ) { 618 return str_pad( '', $p_repeats, $p_character ); 619 } 620 621 # -------------------- 622 # Format date for display 623 function string_format_complete_date( $p_date ) { 624 return date( config_get( 'complete_date_format' ), $p_date ); 625 } 626 627 # -------------------- 628 # Shorten a string for display on a dropdown to prevent the page rendering too wide 629 # ref issues #4630, #5072, #5131 630 631 function string_shorten( $p_string ) { 632 $t_max = config_get( 'max_dropdown_length' ); 633 if ( ( strlen( $p_string ) > $t_max ) && ( $t_max > 0 ) ){ 634 $t_pattern = '/([\s|.|,|\-|_|\/|\?]+)/'; 635 $t_bits = preg_split( $t_pattern, $p_string, -1, PREG_SPLIT_DELIM_CAPTURE ); 636 637 $t_string = ''; 638 $t_last = $t_bits[ count( $t_bits ) - 1 ]; 639 $t_last_len = strlen( $t_last ); 640 641 foreach ( $t_bits as $t_bit ) { 642 if ( ( strlen( $t_string ) + strlen( $t_bit ) + $t_last_len + 3 <= $t_max ) 643 || ( strpos( $t_bit, '.,-/?' ) > 0 ) ) { 644 $t_string .= $t_bit; 645 } else { 646 break; 647 } 648 } 649 $t_string .= '...' . $t_last; 650 return $t_string; 651 } else { 652 return $p_string; 653 } 654 } 655 656 # -------------------- 657 # remap a field name to a string name (for sort filter) 658 659 function string_get_field_name( $p_string ) { 660 661 $t_map = array( 662 'last_updated' => 'last_update', 663 'id' => 'email_bug' 664 ); 665 666 $t_string = $p_string; 667 if ( isset( $t_map[ $p_string ] ) ) { 668 $t_string = $t_map[ $p_string ]; 669 } 670 return lang_get_defaulted( $t_string ); 671 } 672 673 # -------------------- 674 # Calls htmlentities on the specified string, passing along 675 # the current charset. 676 function string_html_entities( $p_string ) { 677 return htmlentities( $p_string, ENT_COMPAT, lang_get( 'charset' ) ); 678 } 679 680 # -------------------- 681 # Calls htmlspecialchars on the specified string, passing along 682 # the current charset, if the current PHP version supports it. 683 function string_html_specialchars( $p_string ) { 684 # achumakov: @ added to avoid warning output in unsupported codepages 685 # e.g. 8859-2, windows-1257, Korean, which are treated as 8859-1. 686 # This is VERY important for Eastern European, Baltic and Korean languages 687 return preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;", @htmlspecialchars( $p_string, ENT_COMPAT, lang_get( 'charset' ) ) ); 688 } 689 690 # -------------------- 691 # Prepares a string to be used as part of header(). 692 function string_prepare_header( $p_string ) { 693 $t_string = $p_string; 694 695 $t_truncate_pos = strpos($p_string, "\n"); 696 if ($t_truncate_pos !== false ) { 697 $t_string = substr($t_string, 0, $t_truncate_pos); 698 } 699 700 $t_truncate_pos = strpos($p_string, "\r"); 701 if ($t_truncate_pos !== false ) { 702 $t_string = substr($t_string, 0, $t_truncate_pos); 703 } 704 705 return $t_string; 706 } 707 708 # -------------------- 709 # Checks the supplied string for scripting characters, if it contains any, then return true, otherwise return false. 710 function string_contains_scripting_chars( $p_string ) { 711 if ( ( strstr( $p_string, '<' ) !== false ) || ( strstr( $p_string, '>' ) !== false ) ) { 712 return true; 713 } 714 715 return false; 716 } 717 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
|