|
1
|
|
|
<?php |
|
2
|
|
|
namespace PHPDaemon\SockJS\Methods; |
|
3
|
|
|
|
|
4
|
|
|
use PHPDaemon\Core\Daemon; |
|
5
|
|
|
use PHPDaemon\Core\Debug; |
|
6
|
|
|
use PHPDaemon\Utils\Crypt; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @package Libraries |
|
10
|
|
|
* @subpackage SockJS |
|
11
|
|
|
* @author Vasily Zorin <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Iframe extends Generic |
|
14
|
|
|
{ |
|
15
|
|
|
protected $version = '1.0.3'; |
|
16
|
|
|
protected $contentType = 'text/html'; |
|
17
|
|
|
protected $cacheable = true; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Constructor |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
|
|
public function init() |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
parent::init(); |
|
26
|
|
|
if (isset($this->attrs->version)) { |
|
27
|
|
|
$this->version = $this->attrs->version; |
|
28
|
|
|
} |
|
29
|
|
|
$this->header('Cache-Control: max-age=31536000, public, pre-check=0, post-check=0'); |
|
30
|
|
|
$this->header('Expires: '.date('r', strtotime('+1 year'))); |
|
31
|
|
|
$html = '<!DOCTYPE html> |
|
32
|
|
|
<html> |
|
33
|
|
|
<head> |
|
34
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
|
35
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
36
|
|
|
<script> |
|
37
|
|
|
document.domain = document.domain; |
|
38
|
|
|
_sockjs_onload = function(){SockJS.bootstrap_iframe();}; |
|
39
|
|
|
</script> |
|
40
|
|
|
<script src="https://cdn.jsdelivr.net/sockjs/' . htmlentities($this->version, ENT_QUOTES, 'UTF-8').'/sockjs.min.js"></script> |
|
|
|
|
|
|
41
|
|
|
</head> |
|
42
|
|
|
<body> |
|
43
|
|
|
<h2>Don\'t panic!</h2> |
|
44
|
|
|
<p>This is a SockJS hidden iframe. It\'s used for cross domain magic.</p> |
|
45
|
|
|
</body> |
|
46
|
|
|
</html>'; |
|
47
|
|
|
$etag = 'W/"'.sha1($html).'"'; |
|
48
|
|
|
$this->header('ETag: '.$etag); |
|
49
|
|
|
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { |
|
50
|
|
|
if ($_SERVER['HTTP_IF_NONE_MATCH'] === $etag) { |
|
51
|
|
|
$this->status(304); |
|
52
|
|
|
$this->removeHeader('Content-Type'); |
|
53
|
|
|
$this->finish(); |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
$this->header('Content-Length: '.mb_orig_strlen($html)); |
|
58
|
|
|
echo $html; |
|
59
|
|
|
$this->finish(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Called when request iterated |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
public function run() |
|
67
|
|
|
{ |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: