Skip to content

Commit 1af920b

Browse files
authored
Merge pull request phacility#54 from skilld-labs/url
Use consitent URL generation
2 parents 5fb76fa + af178ab commit 1af920b

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

xhprof_lib/display/xhprof.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* Get the base URL path from the SCRIPT_NAME.
4444
*/
4545
$base_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
46-
46+
$base_url = htmlentities($_SERVER['SCRIPT_NAME']);
4747

4848
/**
4949
* Generate references to required stylesheets & javascript.
@@ -56,9 +56,10 @@
5656
*
5757
*/
5858
function xhprof_include_js_css($ui_dir_url_path = null) {
59+
global $base_path;
5960

6061
if (empty($ui_dir_url_path)) {
61-
$ui_dir_url_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
62+
$ui_dir_url_path = $base_path;
6263
}
6364

6465
// style sheets
@@ -453,7 +454,7 @@ function profiler_report ($url_params,
453454
global $stats;
454455
global $pc_stats;
455456
global $diff_mode;
456-
global $base_path;
457+
global $base_url;
457458

458459
// if we are reporting on a specific function, we can trim down
459460
// the report(s) to just stuff that is relevant to this function.
@@ -482,22 +483,22 @@ function profiler_report ($url_params,
482483
'symbol'),
483484
'all');
484485

485-
$top_link_query_string = "$base_path/?" . http_build_query($base_url_params);
486+
$top_link_query_string = "$base_url?" . http_build_query($base_url_params);
486487

487488
if ($diff_mode) {
488489
$diff_text = "Diff";
489490
$base_url_params = xhprof_array_unset($base_url_params, 'run1');
490491
$base_url_params = xhprof_array_unset($base_url_params, 'run2');
491492
$run1_link = xhprof_render_link('View Run #' . $run1,
492-
"$base_path/?" .
493+
"$base_url?" .
493494
http_build_query(xhprof_array_set($base_url_params,
494495
'run',
495496
$run1)));
496497
$run2_txt = sprintf("<b>Run #%s:</b> %s",
497498
$run2, $run2_desc);
498499

499500
$run2_link = xhprof_render_link('View Run #' . $run2,
500-
"$base_path/?" .
501+
"$base_url?" .
501502
http_build_query(xhprof_array_set($base_url_params,
502503
'run',
503504
$run2)));
@@ -519,7 +520,7 @@ function profiler_report ($url_params,
519520
$links [] = $run1_link;
520521
$links [] = $run2_link;
521522
$links [] = xhprof_render_link('Invert ' . $diff_text . ' Report',
522-
"$base_path/?".
523+
"$base_url?".
523524
http_build_query($inverted_params));
524525
}
525526

@@ -660,7 +661,7 @@ function print_function_info($url_params, $info, $sort, $run1, $run2) {
660661
global $metrics;
661662
global $format_cbk;
662663
global $display_calls;
663-
global $base_path;
664+
global $base_url;
664665

665666
// Toggle $odd_or_even
666667
$odd_even = 1 - $odd_even;
@@ -672,7 +673,7 @@ function print_function_info($url_params, $info, $sort, $run1, $run2) {
672673
print('<tr bgcolor="#e5e5e5">');
673674
}
674675

675-
$href = "$base_path/?" .
676+
$href = "$base_url?" .
676677
http_build_query(xhprof_array_set($url_params,
677678
'symbol', $info["fn"]));
678679

@@ -717,15 +718,15 @@ function print_flat_data($url_params, $title, $flat_data, $sort, $run1, $run2, $
717718
global $stats;
718719
global $sortable_columns;
719720
global $vwbar;
720-
global $base_path;
721+
global $base_url;
721722

722723
$size = count($flat_data);
723724
if (!$limit) { // no limit
724725
$limit = $size;
725726
$display_link = "";
726727
} else {
727728
$display_link = xhprof_render_link(" [ <b class=bubble>display all </b>]",
728-
"$base_path/?" .
729+
"$base_url?" .
729730
http_build_query(xhprof_array_set($url_params,
730731
'all', 1)));
731732
}
@@ -739,7 +740,7 @@ function print_flat_data($url_params, $title, $flat_data, $sort, $run1, $run2, $
739740
foreach ($stats as $stat) {
740741
$desc = stat_description($stat);
741742
if (array_key_exists($stat, $sortable_columns)) {
742-
$href = "$base_path/?"
743+
$href = "$base_url?"
743744
. http_build_query(xhprof_array_set($url_params, 'sort', $stat));
744745
$header = xhprof_render_link($desc, $href);
745746
} else {
@@ -791,6 +792,7 @@ function full_report($url_params, $symbol_tab, $sort, $run1, $run2) {
791792
global $format_cbk;
792793
global $display_calls;
793794
global $base_path;
795+
global $base_url;
794796

795797
$possible_metrics = xhprof_get_possible_metrics();
796798

@@ -799,10 +801,10 @@ function full_report($url_params, $symbol_tab, $sort, $run1, $run2) {
799801
$base_url_params = xhprof_array_unset(xhprof_array_unset($url_params,
800802
'run1'),
801803
'run2');
802-
$href1 = "$base_path/?" .
804+
$href1 = "$base_url?" .
803805
http_build_query(xhprof_array_set($base_url_params,
804806
'run', $run1));
805-
$href2 = "$base_path/?" .
807+
$href2 = "$base_url?" .
806808
http_build_query(xhprof_array_set($base_url_params,
807809
'run', $run2));
808810

@@ -961,7 +963,7 @@ function pc_info($info, $base_ct, $base_info, $parent) {
961963

962964
function print_pc_array($url_params, $results, $base_ct, $base_info, $parent,
963965
$run1, $run2) {
964-
global $base_path;
966+
global $base_url;
965967

966968
// Construct section title
967969
if ($parent) {
@@ -980,7 +982,7 @@ function print_pc_array($url_params, $results, $base_ct, $base_info, $parent,
980982

981983
$odd_even = 0;
982984
foreach ($results as $info) {
983-
$href = "$base_path/?" .
985+
$href = "$base_url?" .
984986
http_build_query(xhprof_array_set($url_params,
985987
'symbol', $info["fn"]));
986988

@@ -1051,6 +1053,7 @@ function symbol_report($url_params,
10511053
global $sort_col;
10521054
global $display_calls;
10531055
global $base_path;
1056+
global $base_url;
10541057

10551058
$possible_metrics = xhprof_get_possible_metrics();
10561059

@@ -1067,9 +1070,9 @@ function symbol_report($url_params,
10671070
$base_url_params = xhprof_array_unset(xhprof_array_unset($url_params,
10681071
'run1'),
10691072
'run2');
1070-
$href1 = "$base_path?"
1073+
$href1 = "$base_url?"
10711074
. http_build_query(xhprof_array_set($base_url_params, 'run', $run1));
1072-
$href2 = "$base_path?"
1075+
$href2 = "$base_url?"
10731076
. http_build_query(xhprof_array_set($base_url_params, 'run', $run2));
10741077

10751078
print("<h3 align=center>$regr_impr summary for $rep_symbol<br><br></h3>");
@@ -1157,7 +1160,7 @@ function symbol_report($url_params,
11571160
$desc = stat_description($stat);
11581161
if (array_key_exists($stat, $sortable_columns)) {
11591162

1160-
$href = "$base_path/?" .
1163+
$href = "$base_url?" .
11611164
http_build_query(xhprof_array_set($url_params,
11621165
'sort', $stat));
11631166
$header = xhprof_render_link($desc, $href);

0 commit comments

Comments
 (0)