-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHttpIO.php
126 lines (92 loc) · 3.52 KB
/
HttpIO.php
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
//http://localhost/MobileMink/index.php?url=http://www.google.com/
function getMementoHTML($urlToRead, $n) {
ini_set('max_execution_time', 100);
//$url = "http://mementoproxy.cs.odu.edu/aggr/timemap/link/1/" . $urlToRead;
$url = "http://labs.mementoweb.org/timemap/link/" . $urlToRead;
//echo $url . ": <br>";
// create curl resource
$ch = curl_init();
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/*----------GET ALL TIMEMAPS----------*/
curl_setopt($ch, CURLOPT_URL, $url); // set url
$data = curl_exec($ch);
if(strpos($data, ';rel="memento"') === false) {
/*----------If List of TimeMaps----------*/
// JFB: get initial indexed list:
$data = array();
$data = curl_exec($ch);
$tempArray = explode(',', $data);
$tmArray = array(); //our array of URI-Ts to hit
/**
print("the temp array\n\n");
print_r($tempArray);
print("\n\n");
/**/
//for every line in our returned representation...
for($i = 0; $i < count($tempArray); $i++)
{
//find all the timemap lines
if(strpos($tempArray[$i],"rel=\"timemap\"") !== false)
{
//then strip out all of the junk to get the URI-T
$tempArr2 = explode(';', $tempArray[$i]);
$toPush = $tempArr2[0];
$toPush = str_replace("<", '', $toPush);
$toPush = str_replace(">", '', $toPush);
//and add the URI-T to our array of URI-Ts
array_push($tmArray, trim($toPush));
}
}
//Print all TimeMaps
// print("Justin has the following URI-Ts for $urlToRead\n<br><br>");
// print_r($tmArray);
// exit();
/*----------Aggregate TimeMaps----------*/
if($n == null) //if a max number of TimeMaps is NOT given start from the begining of the array
$TMn = 0;
else { //else start n from the end of the array to the end of the array
if($n < count($tmArray))
$TMn = count($tmArray) - $n;
else
$TMn = 0;
}
$output_tm = null;
for($i = $TMn; $i < count($tmArray); $i++) //for each TimeMap starting at $TMn (changes depending on # of TimeMaps asked for) to the end
{
//file_put_contents('TMInversionService.log', $output_tm->log(), FILE_APPEND); //Add an entry to the log for this runthrough
curl_setopt($ch, CURLOPT_URL, $tmArray[$i]); // set url
$data = curl_exec($ch); //recieve TimeMap
if($output_tm == null) //If this is the first TimeMap create a new TimeMap object
$output_tm = new TimeMap($data, $tmArray[$i]);
else //Else agregate with the original TimeMap
$output_tm->combine($data, $tmArray[$i]);
$output_tm->combine($data, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
}
}
/*-----------Without TimeMap------------*/
else {
$output_tm = null;
$n = 0;
do {
curl_setopt($ch, CURLOPT_URL, $url); // set url
// $output contains the output string
$data = curl_exec($ch);
if($output_tm == null)
$output_tm = new TimeMap($data, $urlToRead);
else
$output_tm->combine($data, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
$n++;
$url = $output_tm->nextMap();
echo $output_tm->nextMap();
}while($output_tm->nextMap() != false);
}
/** end TM gathering **/
file_put_contents('TMInversionService.log', $output_tm->log(), FILE_APPEND); //Add an entry to the log for this runthrough
$output_tm->printText(); //Print Final aggregated and paginated TimeMap
curl_close($ch);
}
?>