-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatisticsSocket.inc.php
executable file
·69 lines (56 loc) · 1.58 KB
/
StatisticsSocket.inc.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
<?php
/**
* @file StatisticsSocket.inc.php
*
* Copyright (c) 2003-2010 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class StatisticsSocket
* @ingroup plugins_generic_statisticsAggregation
*
* @brief A helper class to create a Socket to send data
*/
// $Id$
class StatisticsSocket {
var $socketUrl = 'warhammer.hil.unb.ca';
var $socketPort = 80;
var $socketTimeout = 10;
var $_statisticsAggregationSiteId;
var $_jsonString;
function StatisticsSocket() {
register_shutdown_function(array($this, 'send'));
}
function setSiteId($id) {
$this->_statisticsAggregationSiteId = $id;
}
function setJSONString($jsonString) {
$this->_jsonString = $jsonString;
}
function send() {
$code = $this->_statisticsAggregationSiteId;
$data = $this->_jsonString;
// a trap to prevent stats collection during plugin setup (since all hooks fire)
if ($code == '') {
return;
}
$_requestData = "code=" . urlencode($code) . "&data=" . urlencode($data);
$fp = fsockopen($this->socketUrl, $this->socketPort, $errno, $errstr, $this->socketTimeout);
if (!$fp) {
return false;
} else {
$content = "POST /index.php/track HTTP/1.1\r\n";
$content .= "Host: " . $this->socketUrl . "\r\n";
$content .= "Content-Type: application/x-www-form-urlencoded\r\n";
$content .= "Content-Length: " . strlen($_requestData) . "\r\n\r\n";
$content .= $_requestData;
fwrite($fp, $content);
$return = '';
while (($buffer = fgets($fp, 1)) !== false) {
$return .= $buffer;
}
fclose($fp);
return $return;
}
}
}
?>