PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/details/index.php

http://showslow.googlecode.com/
PHP | 434 lines | 372 code | 55 blank | 7 comment | 56 complexity | 863a05e92a6417d3c03fffc7b579061d MD5 | raw file
  1. <?php
  2. require_once(dirname(dirname(__FILE__)).'/global.php');
  3. require_once(dirname(dirname(__FILE__)).'/users/users.php');
  4. if (!array_key_exists('url', $_GET) || ($url = filter_var($_GET['url'], FILTER_VALIDATE_URL)) === false) {
  5. ?><html>
  6. <head>
  7. <title>Error - no URL specified</title>
  8. </head>
  9. <body>
  10. <h1>Error - no URL specified</h1>
  11. <p><a href="../">Go back</a> and pick the URL</p>
  12. </body></html>
  13. <?php
  14. return;
  15. }
  16. # building a query to select all beacon data in one swoop
  17. $query = "SELECT urls.id AS url_id, UNIX_TIMESTAMP(last_update) AS t, last_event_update, yslow2.details AS yslow_details";
  18. foreach ($all_metrics as $provider_name => $provider) {
  19. $query .= ",\n\t".$provider['table'].'_last_id, UNIX_TIMESTAMP('.$provider['table'].'.timestamp) AS '.$provider_name.'_timestamp';
  20. foreach ($provider['metrics'] as $section_name => $section) {
  21. foreach ($section as $metric) {
  22. $query .= ",\n\t\t".$provider['table'].'.'.$metric[1].' AS '.$provider_name.'_'.$metric[1];
  23. }
  24. }
  25. }
  26. $query .= "\nFROM urls";
  27. foreach ($all_metrics as $provider_name => $provider) {
  28. $query .= "\n\tLEFT JOIN ".$provider['table'].' ON urls.'.$provider['table'].'_last_id = '.$provider['table'].'.id';
  29. }
  30. $query .= "\nWHERE urls.url = '".mysql_real_escape_string($url)."'";
  31. #echo $query; exit;
  32. $result = mysql_query($query);
  33. if (!$result) {
  34. error_log(mysql_error());
  35. }
  36. $row = mysql_fetch_assoc($result);
  37. $lastupdate = $row['t'];
  38. $eventupdate = $row['last_event_update'];
  39. $urlid = $row['url_id'];
  40. $yslow2_last_id = $row['yslow2_last_id'];
  41. $pagespeed_last_id = $row['pagespeed_last_id'];
  42. $dynatrace_last_id = $row['dynatrace_last_id'];
  43. mysql_free_result($result);
  44. header('Last-modified: '.date(DATE_RFC2822, $lastupdate));
  45. if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER) && ($lastupdate <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))) {
  46. header('HTTP/1.0 304 Not Modified');
  47. exit;
  48. }
  49. $TITLE = 'Details for '.htmlentities($url);
  50. $SCRIPTS = array(
  51. $showslow_base.'ajax/simile-ajax-api.js?bundle=true',
  52. $showslow_base.'timeline/timeline-api.js?bundle=true',
  53. $showslow_base.'timeplot/timeplot-api.js?bundle=true',
  54. 'http://yui.yahooapis.com/combo?2.8.1/build/yahoo/yahoo-min.js&2.8.1/build/event/event-min.js&2.8.1/build/yuiloader/yuiloader-min.js',
  55. assetURL('details/details.js')
  56. );
  57. $SECTION = 'all';
  58. require_once(dirname(dirname(__FILE__)).'/header.php');
  59. ?>
  60. <script>
  61. <?php
  62. echo 'var metrics = '.json_encode($metrics);
  63. ?>
  64. </script>
  65. <style>
  66. .yslow1 {
  67. color: #55009D;
  68. }
  69. .yslow2 {
  70. color: #2175D9;
  71. }
  72. .details {
  73. cursor: help;
  74. }
  75. .sectionname {
  76. padding-top: 1em;
  77. }
  78. .breakdowntitle {
  79. clear: both;
  80. margin-bottom: 0;
  81. }
  82. .titlecol {
  83. padding: 0 2em;
  84. }
  85. .value {
  86. font-weight: bold;
  87. }
  88. </style>
  89. <h1 style="margin-bottom: 0">Details for <a href="<?php echo htmlentities($url)?>" rel="nofollow"><?php echo htmlentities(ellipsis($url, 31)) ?></a></h1>
  90. <?php if (!is_null($addThisProfile)) {?>
  91. <!-- AddThis Button BEGIN -->
  92. <div class="addthis_toolbox addthis_default_style" style="margin-right: 10px;">
  93. <a href="http://www.addthis.com/bookmark.php?v=250&amp;username=<?php echo urlencode($addThisProfile)?>" class="addthis_button_compact">Share</a>
  94. <span class="addthis_separator">|</span>
  95. <a class="addthis_button_twitter"></a>
  96. <a class="addthis_button_facebook"></a>
  97. <a class="addthis_button_google"></a>
  98. <a class="addthis_button_delicious"></a>
  99. <a class="addthis_button_stumbleupon"></a>
  100. <a class="addthis_button_reddit"></a>
  101. <span class="addthis_separator">|</span>
  102. <a class="addthis_button_favorites"></a>
  103. <a class="addthis_button_print"></a>
  104. <a class="addthis_button_email"></a>
  105. </div>
  106. <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=<?php echo urlencode($addThisProfile)?>"></script>
  107. <!-- AddThis Button END -->
  108. <?php
  109. }
  110. // checking if there is har data
  111. $query = sprintf("SELECT har.timestamp as t, har.id as id, har.link as link FROM har WHERE har.url_id = '%d' ORDER BY timestamp DESC",
  112. mysql_real_escape_string($urlid)
  113. );
  114. $result = mysql_query($query);
  115. if (!$result) {
  116. error_log(mysql_error());
  117. }
  118. $har = array();
  119. while ($har_row = mysql_fetch_assoc($result)) {
  120. $har[] = $har_row;
  121. }
  122. // checking if there were PageTest tests ran
  123. $query = sprintf("SELECT pagetest.timestamp as t, test_url, location FROM pagetest WHERE pagetest.url_id = '%d' ORDER BY timestamp DESC",
  124. mysql_real_escape_string($urlid)
  125. );
  126. $result = mysql_query($query);
  127. if (!$result) {
  128. error_log(mysql_error());
  129. }
  130. $pagetest = array();
  131. while ($pagetest_row = mysql_fetch_assoc($result)) {
  132. $pagetest[] = $pagetest_row;
  133. }
  134. mysql_free_result($result);
  135. if ($row && !(is_null($row['yslow_timestamp'])
  136. && is_null($row['pagespeed_timestamp'])
  137. && is_null($row['dynatrace_timestamp']))
  138. )
  139. {
  140. ?>
  141. <table cellpadding="15" cellspacing="5"><tr>
  142. <?php
  143. foreach ($all_metrics as $provider_name => $provider) {
  144. $score = $row[$provider_name.'_'.$provider['score_column']];
  145. if (!is_null($score)) {
  146. $pretty_score = prettyScore($score);
  147. ?>
  148. <td valign="top" align="center" class="<?php echo $provider_name ?>">
  149. <img src="http://chart.apis.google.com/chart?chs=225x108&cht=gom&chd=t:<?php echo urlencode($score)?>&chl=<?php echo urlencode($pretty_score.' ('.$score.')') ?>" alt="<?php echo $pretty_score ?> (<?php echo htmlentities($score)?>)" title="Current <?php echo $provider['title'] ?> <?php echo $provider['score_name'] ?>: <?php echo $pretty_score ?> (<?php echo htmlentities($score)?>)"/>
  150. <div>Current <a target="_blank" href="<?php echo $provider['url'] ?>"><?php echo $provider['title'] ?></a> <?php echo $provider['score_name'] ?>: <b><?php echo $pretty_score ?> (<i><?php echo htmlentities($score)?></i>)</b></div>
  151. </td>
  152. <?php
  153. }
  154. }
  155. ?>
  156. </tr></table>
  157. <?php
  158. }
  159. // fetching locations only when needed
  160. getPageTestLocations();
  161. if (!is_null($webPageTestBase) && !is_null($webPageTestKey)) { ?>
  162. <a name="pagetest"/><h2>Run a test using <a href="<?php echo htmlentities($webPageTestBase)?>" target="_blank">WebPageTest</a> and store the results</h2>
  163. <form action="<?php echo htmlentities($showslow_base)?>pagetest.php" method="GET" target="_blank">
  164. <input type="hidden" name="url" size="40" value="<?php echo htmlentities($url)?>"/>
  165. Location: <select name="location">
  166. <?php foreach ($webPageTestLocations as $location) {
  167. if ($location['tests'] > 50) {
  168. continue;
  169. }
  170. ?>
  171. <option <?php echo htmlentities($location['default']) ? 'selected ' : ''?>value="<?php echo htmlentities($location['id'])?>"><?php echo htmlentities($location['title'])?></option>
  172. <?php } ?></select>
  173. <input type="checkbox" name="private" id="wpt_private" value="1"<?php if ($webPageTestPrivateByDefault) {?> checked="true"<?php } ?>/><label for="wpt_private">Private</label>
  174. <input type="checkbox" name="fvonly" id="wpt_fvonly" value="1"<?php if ($webPageTestFirstRunOnlyByDefault) {?> checked="true"<?php } ?>/><label for="wpt_fvonly">First View Only</label>
  175. <input type="submit" style="font-weight: bold" value="start test &gt;&gt;"/>
  176. <?php if (count($pagetest) > 0) {?><a href="#pagetest-table">See test history below</a><?php } ?>
  177. </form>
  178. <?php
  179. }
  180. if ($row && is_null($row['yslow_timestamp'])
  181. && is_null($row['pagespeed_timestamp'])
  182. && is_null($row['dynatrace_timestamp']))
  183. {
  184. ?>
  185. <a name="graph"/><h2 style="clear: both">Measurements over time</h2>
  186. <table width="100%" height="250px" style="border: 1px solid silver"><tr>
  187. <td align="center" valign="middle">
  188. <table cellpadding="3px">
  189. <tr>
  190. <td><img src="<?php echo assetURL('clock.png')?>"/></td>
  191. <td style="font-size: larger">Data is being collected</td>
  192. </tr>
  193. <tr><td colspan="2" align="center"><div class="gbox"><div class="bar ccol"></div></td></tr>
  194. </table>
  195. </td>
  196. </tr></table>
  197. <?php
  198. } else if (!$row) {
  199. ?><div style="padding: 2em">No data is collected for this URL</div><?php
  200. }
  201. if ($row && !(is_null($row['yslow_timestamp'])
  202. && is_null($row['pagespeed_timestamp'])
  203. && is_null($row['dynatrace_timestamp']))
  204. )
  205. {
  206. // Graph
  207. ?>
  208. <script>
  209. url = '<?php echo htmlentities($url)?>';
  210. ydataversion = '<?php echo urlencode($row['yslow_timestamp'])?>';
  211. psdataversion = '<?php echo urlencode($row['pagespeed_timestamp'])?>';
  212. dtdataversion = '<?php echo urlencode($row['dynatrace_timestamp'])?>';
  213. eventversion = '<?php echo urlencode($eventupdate)?>';
  214. </script>
  215. <a name="graph"/><h2 style="clear: both">Measurements over time</h2>
  216. <div id="my-timeplot" style="height: 250px;"></div>
  217. <div style="font-size: 0.9em">
  218. <?php
  219. if (!is_null($row['yslow_timestamp']))
  220. {
  221. ?>
  222. <span style="color: #D0A825">Page Size</span> (in bytes);
  223. <span style="color: purple">Page Load time (YSlow)</span> (in ms);
  224. <span style="color: #75CF74">Total Requests</span>;
  225. <span class="yslow2">YSlow Grade</span> (0-100);
  226. <?php
  227. }
  228. if (!is_null($row['pagespeed_timestamp']))
  229. {
  230. ?>
  231. <span style="color: #6F4428">Page Speed Grade</span> (0-100);
  232. <span style="color: #EE4F00">Page Load time (Page Speed)</span> (in ms);
  233. <?php
  234. }
  235. if (!is_null($row['dynatrace_timestamp']))
  236. {
  237. ?>
  238. <span style="color: #AB0617">dynaTrace rank</span> (0-100);
  239. <?php
  240. }
  241. foreach ($metrics as $name => $metric)
  242. {
  243. ?><span title="<?php echo htmlentities($metric['description'])?>" style="color: <?php echo array_key_exists('color', $metric) ? $metric['color'] : 'black' ?>"><?php echo htmlentities($metric['title'])?></span> (<a href="data_metric.php?metric=<?php echo urlencode($name);?>&url=<?php echo urlencode($url);?>">csv</a>);
  244. <?php
  245. }
  246. ?>
  247. </div>
  248. <?php
  249. $details = json_decode($row['yslow_details'], true);
  250. ?>
  251. <script>
  252. <?php
  253. $comps = array();
  254. if (is_array($details) && array_key_exists('g', $details)) {
  255. foreach ($details['g'] as $n => $y) {
  256. if (is_array($y) && array_key_exists('components', $y)) {
  257. $comps['yslow_'.$n] = $y['components'];
  258. }
  259. }
  260. }
  261. ?>
  262. var details = <?php echo json_encode($comps)?>;
  263. </script>
  264. <?php
  265. // Breakdowns for each provider
  266. foreach ($all_metrics as $provider_name => $provider) {
  267. if (!is_null($row[$provider_name.'_timestamp']))
  268. {
  269. ?>
  270. <a name="<?php echo $provider_name ?>"/><h2 class="breakdowntitle"><?php echo $provider['title']?> breakdown</h2>
  271. <table>
  272. <?php
  273. foreach ($provider['metrics'] as $section_name => $metrics)
  274. {
  275. ?><tr><td colspan="6" class="sectionname"><b><?php echo $section_name ?></b></td></tr><?php
  276. $odd = true;
  277. foreach ($metrics as $metric) {
  278. if ($odd) { ?><tr><?php }
  279. if (isset($metric[3])) {
  280. ?><td class="titlecol"><a target="_blank" href="<?php echo $metric[3]?>"><?php echo $metric[0]?></a></td><?php
  281. }else{
  282. ?><td class="titlecol"><?php echo $metric[0]?></td><?php
  283. }
  284. $value = $row[$provider_name.'_'.$metric[1]];
  285. if (is_null($value)) {
  286. ?><td colspan="3" class="na">n/a</td><?php
  287. } else {
  288. if ($metric[2] == PERCENTS){
  289. $pretty_score = prettyScore($value);
  290. ?>
  291. <td class="value"><?php echo $pretty_score?> (<i><?php echo htmlentities($value)?></i>%)</td>
  292. <td><span id="details_<?php echo $provider_name.'_'.$metric[1] ?>" class="details"></span></td>
  293. <td><div class="gbox" title="Current <?php echo $provider['score_name']?>: <?php echo $pretty_score?> (<?php echo $value?>%)"><div class="bar c<?php echo scoreColorStep($value)?>" style="width: <?php echo $value+1?>px"/></div></td>
  294. <?php
  295. } else {
  296. ?><td colspan="3" class="value"><?php echo $value.$metric_types[$metric[2]]['units'] ?></td><?php
  297. }
  298. }
  299. if (!$odd) { ?></tr><?php }
  300. $odd = !$odd;
  301. }
  302. ?>
  303. </tr>
  304. <?php
  305. }
  306. ?>
  307. </table>
  308. <?php
  309. }
  310. }
  311. }
  312. if (!is_null($row['yslow_timestamp'])) {
  313. ?>
  314. <a name="yslow-table"/><h2>YSlow measurements history (<a href="data.php?ver=<?php echo urlencode($row['yslow_timestamp'])?>&url=<?php echo urlencode($url)?>">csv</a>)</h2>
  315. <div id="measurementstable"></div>
  316. <?php
  317. }
  318. if (!is_null($row['pagespeed_timestamp'])) {
  319. ?>
  320. <a name="pagespeed-table"/><h2>Page Speed measurements history (<a href="data_pagespeed.php?ver=<?php echo urlencode($row['pagespeed_timestamp'])?>&url=<?php echo urlencode($url)?>">csv</a>)</h2>
  321. <div id="ps_measurementstable"></div>
  322. <?php
  323. }
  324. if (!is_null($row['dynatrace_timestamp'])) {
  325. ?>
  326. <a name="dynatrace-table"/><h2>dynaTrace measurements history (<a href="data_dynatrace.php?ver=<?php echo urlencode($row['dynatrace_timestamp'])?>&url=<?php echo urlencode($url)?>">csv</a>)</h2>
  327. <div id="dt_measurementstable"></div>
  328. <?php
  329. }
  330. if (count($pagetest) > 0) {
  331. ?>
  332. <a name="pagetest-table"/><h2>WebPageTest data collected</h2>
  333. <p>You can see latest <a href="<?php echo htmlentities($pagetest[0]['test_url']) ?>" target="_blank">PageTest report for <?php echo htmlentities($url)?></a> or check the archive:</p>
  334. <table cellpadding="5" cellspacing="0" border="1">
  335. <tr>
  336. <th>Time</th>
  337. <th>Location</th>
  338. <th>PageTest</th>
  339. </tr>
  340. <?php
  341. foreach ($pagetest as $pagetestentry) {
  342. $location = array_key_exists($pagetestentry['location'], $webPageTestLocationsById) ?
  343. $webPageTestLocationsById[$pagetestentry['location']]['title'] :
  344. $pagetestentry['location'];
  345. ?>
  346. <tr>
  347. <td><?php echo htmlentities($pagetestentry['t'])?></td>
  348. <td><?php echo htmlentities($location)?></td>
  349. <td><a href="<?php echo htmlentities($pagetestentry['test_url'])?>" target="_blank">view PageTest report</a></td>
  350. </tr>
  351. <?php
  352. }
  353. ?>
  354. </table>
  355. <?php
  356. }
  357. if (count($har) > 0) {
  358. $har_url = is_null($har[0]['link']) ?
  359. $showslow_base.'details/har.php?id='.urlencode($har[0]['id']).'callback=onInputData'
  360. : $har[0]['link'];
  361. ?>
  362. <a name="har-table"/><h2>HAR data collected</h2>
  363. <p>You can see latest HAR data in the viewer here: <a href="<?php echo htmlentities($HARViewerBase)?>?inputUrl=<?php echo urlencode($har_url) ?>" target="_blank">HAR for <?php echo htmlentities($url)?></a>.</p>
  364. <table cellpadding="5" cellspacing="0" border="1">
  365. <tr><th>Time</th><th>HAR</th></tr>
  366. <?php
  367. foreach ($har as $harentry) {
  368. $har_url = is_null($harentry['link']) ?
  369. $showslow_base.'details/har.php?id='.urlencode($harentry['id']).'callback=onInputData'
  370. : $harentry['link'];
  371. ?>
  372. <tr><td><?php echo htmlentities($harentry['t'])?></td><td><a href="<?php echo htmlentities($HARViewerBase)?>?inputUrl=<?php echo urlencode($har_url) ?>" target="_blank">view in HAR viewer</a></td></tr>
  373. <?php
  374. }
  375. ?>
  376. </table>
  377. <?php
  378. }
  379. require_once(dirname(dirname(__FILE__)).'/footer.php');