/
test.php
304 lines (267 loc) · 7.6 KB
/
test.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
require_once '../lib/vuzit.php';
require_once 'geo_location.php';
require_once 'browser_info.php';
// GENERAL FUNCTIONS
// Returns the domain for use with the Javascript API global variables.
function domain()
{
$url = Vuzit_Service::getServiceUrl();
return substr($url, 7, strlen($url) - 7);
}
// Returns the parameter from the _GET array or null if it isn't present.
function get($key)
{
return array_key_exists($key, $_GET) ? $_GET[$key] : null;
}
// Exports a set of CSV fields into a line of CSV text. The function
// mirrors the PHP fputcsv function.
function csv_line($fields, $delimeter = ',', $enclosure = '"')
{
$result = '';
for($i = 0; $i < count($fields); $i++)
{
if($i != 0) {
$result .= $delimeter;
}
$result .= ($enclosure . str_replace('"', '""', $fields[$i]) . $enclosure);
}
return $result . "\r\n";
}
// Load the header
function header_load($doc = null)
{
$id = '';
$onload = '';
if($doc != null)
{
$timestamp = time();
$id = $doc->getId();
$sig = Vuzit_Service::signature("show", $doc->getId(), $timestamp);
$onload = "initialize()";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Vuzit <?php echo get("c") ?> Command Example</title>
<link href="<?php echo Vuzit_Service::getServiceUrl(); ?>/stylesheets/Vuzit-2.8.css"
rel="Stylesheet" type="text/css" />
<script src="<?php echo Vuzit_Service::getServiceUrl(); ?>/javascripts/Vuzit-2.8.js"
type="text/javascript"></script>
<script type="text/javascript">
// Called when the page is loaded.
function initialize() {
vuzit.Base.apiKeySet("<?php echo Vuzit_Service::getPublicKey(); ?>");
vuzit.Base.webServerSet({ host: '<?php echo domain(); ?>', port: '80' });
vuzit.Base.imageServerSet({ host: '<?php echo domain(); ?>', port: '80' });
var options = {signature: '<?php echo rawurlencode($sig); ?>',
timestamp: '<?php echo $timestamp ?>'}
var viewer = vuzit.Viewer.fromId("<?php echo $id; ?>", options);
viewer.display(document.getElementById("vuzit_viewer"), { zoom: 1 });
}
</script>
</head>
<body onload="<?php echo $onload; ?>">
<h2>Command: <?php echo get("c"); ?></h2>
<?php
}
// Prints the footer
function footer_load()
{
?>
</body>
</html>
<?php
}
// COMMAND FUNCTIONS
// Runs the load command
function load_command()
{
$options = array();
if(get("p") != null) {
$options["included_pages"] = get("p");
}
$doc = Vuzit_Document::findById(get("id"), $options);
header_load($doc);
$pdf_url = Vuzit_Document::downloadUrl($doc->getId(), "pdf");
// TODO: Grab the file type and use it to determine the other file
// to download?
?>
<h3>
Document - <?php echo $doc->getID(); ?>
</h3>
<ul>
<li>Title: <?php echo $doc->getTitle(); ?></li>
<li>Subject: <?php echo $doc->getSubject(); ?></li>
<li>Page count: <?php echo $doc->getPageCount(); ?></li>
<li>Width: <?php echo $doc->getPageWidth(); ?></li>
<li>Height: <?php echo $doc->getPageHeight(); ?></li>
<li>File size: <?php echo $doc->getFileSize(); ?></li>
<li><a href="<?php echo $pdf_url; ?>">PDF Download</a></li>
</ul>
<div id="vuzit_viewer" style="width: 650px; height: 500px;"></div>
<?php
footer_load();
}
// Runs the delete command
function delete_command()
{
header_load();
try
{
$id = get("id");
Vuzit_Document::destroy($id);
echo "Delete succeeded: " . $id;
}
catch(Vuzit_ClientException $ex)
{
echo "Delete of " . $id . " failed with code [" . $ex->getCode() . "], message: " . $ex->getMessage();
}
footer_load();
}
// Runs the upload command
function upload_command()
{
$options = array();
if(get("p") != null) {
$options["download_pdf"] = get("p");
}
if(get("d") != null) {
$options["download_document"] = get("d");
}
$doc = Vuzit_Document::upload(get("path"), $options);
header_load($doc);
?>
<h3>
Document - <?php echo $doc->getID(); ?>
</h3>
<div id="vuzit_viewer" style="width: 650px; height: 500px;"></div>
<?php
footer_load();
}
// Runs the event command
function event_command()
{
$options = array();
if(get("v") != null) {
$options["value"] = get("v");
}
if(get("e") != null) {
$options["event"] = get("e");
}
if(get("l") != null) {
$options["limit"] = get("l");
}
$list = Vuzit_Event::findAll(get("id"), $options);
switch(get("o"))
{
case "csv":
event_load_csv($list);
break;
default:
header_load();
event_load_html($list);
footer_load();
break;
}
}
// Loads the output of the event list as a CSV file.
function event_load_csv($list, $fileName = "events.csv")
{
$csv = '';
$csv .= csv_line(array("web_id", "requested_at", "duration", "event",
"page", "value", "remote_host", "referer",
"user_agent"));
foreach($list as $event)
{
$browser = new BrowserInfo($event->getUserAgent());
$fields = array($event->getWebId(),
date("m/d/y H:i", $event->getRequestedAt()),
$event->getDuration(),
$event->getEvent(),
$event->getPage(),
$event->getValue(),
$event->getRemoteHost(),
$event->getReferer(),
$browser->getName() . " " . $browser->getVersion()
);
$csv .= csv_line($fields);
}
header('Content-type: text/csv');
header("Content-Disposition: attachment; filename=\"" . $fileName . "\";");
echo $csv;
}
// Loads the output of the event list as HTML.
function event_load_html($list)
{
?>
<h3>
Document <?php echo $list[0]->getWebId(); ?>
</h3>
<p>
Total events: <?php echo count($list); ?>
</p>
<ol>
<?
$event = count($list);
for($i = 0; $i < count($list); $i++)
{
$item = $list[$i];
$event--;
$host = $item->getRemoteHost();
$browser = new BrowserInfo($item->getUserAgent());
?>
<li>
<?php
echo "[" . date("Y-d-m H:i:s", $item->getRequestedAt());
if($item->getEvent() == "page_view") {
echo " (" . $item->getDuration() . " s)";
}
echo "] ";
echo '"' . $item->getEvent() . '"';
echo " on page ". $item->getPage();
echo " (value: " . $item->getValue() . ")";
echo ' - <a href="' . $item->getReferer() . '">URL</a> - ';
echo ' Remote host: <a href="location.php?ip=' . $host . '">' . $host . "</a> - ";
echo $browser->getName() . " " . $browser->getVersion();
?>
</li>
<?php
}
echo "</ol>";
}
// MAIN EXECUTION
// Load and check the keys
$public_key = get("puk");
$private_key = get("prk");
if($public_key == null || $private_key == null)
{
echo "Please provide the public (puk) and private (prk) keys";
return;
}
$service_url = get("su");
if($service_url != null) {
Vuzit_Service::setServiceUrl($service_url);
}
Vuzit_Service::setPublicKey($public_key);
Vuzit_Service::setPrivateKey($private_key);
// Grab the command and execute
switch(get("c"))
{
case "load":
load_command();
break;
case "upload":
upload_command();
break;
case "delete":
delete_command();
break;
case "event":
event_command();
break;
}
?>