forked from HTTPArchive/legacy.httparchive.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchwork.js
73 lines (65 loc) · 2.39 KB
/
patchwork.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
require_once("ui.inc");
require_once("utils.inc");
require_once("dbapi.inc");
// Return an array of frame times for each page.
$gNumUrls = getParam('n');
$gLabel1 = getParam('l1');
if ( ! $gNumUrls || ! $gLabel1 ) {
exit();
}
$gLabel2 = getParam('l2');
$gCallback = getParam('callback');
$wptServer = wptServer(false);
$msMax = 0;
// Find the topmost URLs in both crawls:
$limitgoogle = "(url = 'http://www.google.com/' OR url not like '%://www.google.%')"; // There are 10+ sites that all look the same from Google intl sites
$maxRank = 5 * $gNumUrls; // we get back MORE results than needed so we can filter out adult content
$query = "select url, count(*) as num from $gPagesTable, $gUrlsTable as u where (label = '$gLabel1' or label = '$gLabel2') and url=urlOrig and u.rank > 0 and u.rank < $maxRank and $limitgoogle group by url having num=2 order by u.rank asc;";
$result = doQuery($query);
$i = 0;
$sUrls = "";
while ($row = mysqli_fetch_assoc($result)) {
$url = $row['url'];
if ( ! isAdultContent($url) ) {
$sUrls .= ", '$url'";
$i++;
if ( $i >= $gNumUrls ) {
break;
}
}
}
$sUrls = substr($sUrls, 1); // remove leading ","
mysqli_free_result($result);
echoInfo($gLabel1, $sUrls);
echoInfo($gLabel2, $sUrls);
echo "\nmsMax = $msMax;\n" .
( $gCallback ? "$gCallback();\n" : "" );
function echoInfo($label, $sUrls) {
global $gPagesTable, $gUrlsTable, $msMax, $maxRank, $wptServer;
// Echo the frame times, wptid, and wptrun info for the pages in JS format.
$query = "select pageid, url, wptid, wptrun from $gPagesTable, $gUrlsTable as u where label='$label' and urlOrig=url and u.rank > 0 and u.rank <= $maxRank and url in ($sUrls) order by u.rank asc;";
$result = doQuery($query);
while ($row = mysqli_fetch_assoc($result)) {
$url = $row['url'];
$pageid = $row['pageid'];
$wptid = $row['wptid'];
$wptrun = $row['wptrun'];
$xmlurl = "{$wptServer}xmlResult.php?test=$wptid";
$xmlstr = fetchUrl($xmlurl);
$xml = new SimpleXMLElement($xmlstr);
$frames = $xml->data->run[($wptrun - 1)]->firstView->videoFrames;
if ( $frames->frame ) {
$sJS = "";
foreach($frames->frame as $frame) {
$ms = floatval($frame->time) * 1000;
$msMax = max($msMax, $ms);
$sJS .= ( $sJS ? ", " : "" ) . "$ms: 1"; // must NOT end with a comma - poop
}
echo "hPages[$pageid] = {" . $sJS . "};\n" .
"hPageInfo[$pageid] = ['$wptid', $wptrun];\n";
}
}
mysqli_free_result($result);
}
?>