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