PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/all.php

http://showslow.googlecode.com/
PHP | 246 lines | 217 code | 29 blank | 0 comment | 41 complexity | 0db31df25152107aa6445ea49fd6f58b MD5 | raw file
  1. <?php
  2. require_once(dirname(__FILE__).'/global.php');
  3. require_once(dirname(__FILE__).'/users/users.php');
  4. require_once(dirname(__FILE__).'/paginator.class.php');
  5. $TITLE = 'URLs measured';
  6. $SECTION = 'all';
  7. require_once(dirname(__FILE__).'/header.php');
  8. ?>
  9. <style>
  10. .current {
  11. text-decoration: none;
  12. font-weight: bold;
  13. color: black;
  14. }
  15. </style>
  16. <h1>URLs measured</h1>
  17. <?php
  18. $searchstring = null;
  19. if (array_key_exists('search', $_GET) && trim($_GET['search']) != '') {
  20. $searchstring = "urls.url LIKE '%".mysql_real_escape_string(trim($_GET['search']))."%'";
  21. }
  22. $current_group = array_key_exists('group', $_GET) ? $_GET['group'] : null;
  23. $subset = null;
  24. if (is_array($URLGroups) && count($URLGroups) > 0) {
  25. ?>
  26. <ul>
  27. <?php
  28. if (is_null($current_group)) {
  29. ?>
  30. <li><b>All URLs</b></li>
  31. <?php
  32. } else {
  33. ?>
  34. <li><a href="<?php echo $showslow_base.'all.php'.(is_null($searchstring) ? '' : '?search='.urlencode(trim($_GET['search'])))?>">All URLs</a></li>
  35. <?php
  36. }
  37. foreach ($URLGroups as $id => $group) {
  38. if ($current_group == $id) {
  39. $subset = $group['urls'];
  40. ?><li><b><?php echo $group['title']?></b></li><?php
  41. } else {
  42. ?><li><a href="<?php echo $showslow_base.'all.php?'.(is_null($searchstring) ? '' : 'search='.urlencode(trim($_GET['search'])).'&').'group='.$id; ?>"><?php echo $group['title']?></a></li><?php
  43. }
  44. }
  45. ?></ul>
  46. <hr size="1">
  47. <?php
  48. }
  49. ?>
  50. <style>
  51. .paginator {
  52. padding: 1em;
  53. }
  54. .paginator .paginate {
  55. padding: 2px 6px;
  56. border: 1px solid silver;
  57. text-decoration: none;
  58. }
  59. .paginator .current {
  60. padding: 2px 6px;
  61. border: 2px solid #7F6F26;
  62. background: #7F6F26;
  63. color: white;
  64. }
  65. .paginator .inactive {
  66. color: silver;
  67. padding: 2px 6px;
  68. }
  69. </style>
  70. <div style="width: 100%; overflow: hidden">
  71. <?php
  72. $perPage = 50;
  73. $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
  74. if ($page < 1) {
  75. $page = 1;
  76. }
  77. $offset = ($page - 1) * $perPage;
  78. $subsetstring = null;
  79. $first = true;
  80. if (is_array($subset)) {
  81. foreach ($subset as $url) {
  82. if ($first) {
  83. $first = false;
  84. } else {
  85. $subsetstring .= ' OR ';
  86. }
  87. $subsetstring .= "urls.url LIKE '".mysql_real_escape_string($url)."%'";
  88. }
  89. }
  90. $query = "SELECT count(*)
  91. FROM urls
  92. LEFT JOIN yslow2 ON urls.yslow2_last_id = yslow2.id
  93. LEFT JOIN pagespeed ON urls.pagespeed_last_id = pagespeed.id
  94. LEFT JOIN dynatrace ON urls.dynatrace_last_id = dynatrace.id
  95. WHERE last_update IS NOT NULL";
  96. if (!is_null($subsetstring)) {
  97. $query .= " AND ($subsetstring)";
  98. }
  99. if (!is_null($searchstring)) {
  100. $query .= " AND $searchstring";
  101. }
  102. $result = mysql_query($query);
  103. $row = mysql_fetch_row($result);
  104. $total = $row[0];
  105. $pages = new Paginator();
  106. $pages->items_total = $total;
  107. $pages->mid_range = 7;
  108. $pages->items_per_page = $perPage;
  109. $query = 'SELECT url, last_update,
  110. yslow2.o as o,
  111. pagespeed.o as ps_o,
  112. dynatrace.rank as dt_o
  113. FROM urls
  114. LEFT JOIN yslow2 ON urls.yslow2_last_id = yslow2.id
  115. LEFT JOIN pagespeed ON urls.pagespeed_last_id = pagespeed.id
  116. LEFT JOIN dynatrace ON urls.dynatrace_last_id = dynatrace.id
  117. WHERE last_update IS NOT NULL';
  118. if (!is_null($subsetstring)) {
  119. $query .= " AND ($subsetstring)";
  120. }
  121. if (!is_null($searchstring)) {
  122. $query .= " AND $searchstring";
  123. }
  124. $query .= sprintf(" ORDER BY url LIMIT %d OFFSET %d", $perPage, $offset);
  125. $result = mysql_query($query);
  126. if (!$result) {
  127. error_log(mysql_error());
  128. }
  129. $yslow = false;
  130. $pagespeed = false;
  131. $dynatrace = false;
  132. $rows = array();
  133. while ($row = mysql_fetch_assoc($result)) {
  134. $rows[] = $row;
  135. if (!$yslow && !is_null($row['o'])) {
  136. $yslow = true;
  137. }
  138. if (!$pagespeed && !is_null($row['ps_o'])) {
  139. $pagespeed = true;
  140. }
  141. if (!$dynatrace && !is_null($row['dt_o'])) {
  142. $dynatrace = true;
  143. }
  144. }
  145. ?>
  146. <form name="searchform" action="" method="GET">
  147. Search URLs:
  148. <input type="text" id="search" size="80" name="search" value="<?php echo is_null($searchstring) ? '' : htmlentities(trim($_GET['search']))?>"/>
  149. <input type="submit" value="search"/>
  150. <input type="button" value="clear" onclick="document.getElementById('search').value=''; document.searchform.submit()">
  151. <?php if (!is_null($subset)) {
  152. ?><input type="hidden" name="group" value="<?php echo htmlentities($_GET['group']) ?>"/><?php
  153. } ?>
  154. </form>
  155. <hr size="1">
  156. <?php
  157. if ($yslow || $pagespeed || $dynatrace) {
  158. ?>
  159. <div class="paginator">
  160. <?php
  161. $pages->paginate($showslow_base.'all.php');
  162. echo $pages->display_pages();
  163. ?>
  164. </div>
  165. <table>
  166. <tr><th>Timestamp</th>
  167. <?php if ($yslow) { ?><th colspan="2">YSlow grade</th><?php } ?>
  168. <?php if ($pagespeed) { ?><th colspan="2">Page Speed score</th><?php } ?>
  169. <?php if ($dynatrace) { ?><th colspan="2">dynaTrace rank</th><?php } ?>
  170. <th style="padding-left:10px; text-align: left">URL</th>
  171. </tr><?php
  172. foreach ($rows as $row) {
  173. ?><tr>
  174. <td><?php echo htmlentities($row['last_update'])?></td>
  175. <?php if (!$yslow) {?>
  176. <?php }else if (is_null($row['o'])) {?>
  177. <td class="score" style="color: silver" title="No data collected">no data</td>
  178. <td><div class="gbox" title="No data collected"><div class="bar"/></div></td>
  179. <?php }else{?>
  180. <td class="score" title="Current YSlow grade: <?php echo prettyScore($row['o'])?> (<?php echo $row['o']?>)"><?php echo prettyScore($row['o'])?> (<?php echo $row['o']?>)</td>
  181. <td title="Current YSlow grade: <?php echo prettyScore($row['o'])?> (<?php echo $row['o']?>)"><div class="gbox"><div style="width: <?php echo $row['o']+1?>px" class="bar c<?php echo scoreColorStep($row['o'])?>"/></div></td>
  182. <?php }?>
  183. <?php if (!$pagespeed) {?>
  184. <?php }else if (is_null($row['ps_o'])) {?>
  185. <td class="score" style="color: silver" title="No data collected">no data</td>
  186. <td><div class="gbox" title="No data collected"><div class="bar"/></div></td>
  187. <?php }else{?>
  188. <td class="score" title="Current Page Speed score: <?php echo prettyScore($row['ps_o'])?> (<?php echo $row['ps_o']?>)"><?php echo prettyScore($row['ps_o'])?> (<?php echo $row['ps_o']?>)</td>
  189. <td title="Current Page Speed score: <?php echo prettyScore($row['ps_o'])?> (<?php echo $row['ps_o']?>)"><div class="gbox"><div style="width: <?php echo $row['ps_o']+1?>px" class="bar c<?php echo scoreColorStep($row['ps_o'])?>"/></div></td>
  190. <?php }?>
  191. <?php if (!$dynatrace) {?>
  192. <?php }else if (is_null($row['dt_o'])) {?>
  193. <td class="score" style="color: silver" title="No data collected">no data</td>
  194. <td><div class="gbox" title="No data collected"><div class="bar"/></div></td>
  195. <?php }else{?>
  196. <td class="score" title="Current dynaTrace score: <?php echo prettyScore($row['dt_o'])?> (<?php echo $row['dt_o']?>)"><?php echo prettyScore($row['dt_o'])?> (<?php echo $row['dt_o']?>)</td>
  197. <td title="Current dynaTrace score: <?php echo prettyScore($row['dt_o'])?> (<?php echo $row['dt_o']?>)"><div class="gbox"><div style="width: <?php echo $row['dt_o']+1?>px" class="bar c<?php echo scoreColorStep($row['dt_o'])?>"/></div></td>
  198. <?php }?>
  199. <td class="url"><a href="details/?url=<?php echo urlencode($row['url'])?>"><?php echo htmlentities(substr($row['url'], 0, 100))?><?php if (strlen($row['url']) > 100) { ?>...<?php } ?></a></td>
  200. </tr><?php
  201. }
  202. mysql_free_result($result);
  203. ?>
  204. </table>
  205. <div class="paginator">
  206. <?php
  207. echo $pages->display_pages();
  208. ?>
  209. </div>
  210. <?php
  211. } else {
  212. ?><p>No data is gathered yet</p><?php
  213. }
  214. ?>
  215. </div>
  216. <?php
  217. require_once(dirname(__FILE__).'/footer.php');