-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
117 lines (95 loc) · 3.63 KB
/
index.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
<?php
//NOTE: DO NOT INCLUDE ANYTHING REGARDING A CHATROOM HERE.
/* What?
* When you go to chirped.it/ (with or without a #topic) we send down some javascript that reads the #topic, and makes a GET for chatroom.php?topic=theTopic or homepage.php. Then I take the response and set it to the innerHTML of the <body>
Thing is we can't read beyond the # in a url
*/
require('lib/header.php');
date_default_timezone_set('America/Los_Angeles');
?>
<style>
iframe, html, body {
height: 100%;
width: 100%;
}
iframe {
border: none;
}
</style>
</head>
<body>
<iframe id="theIframe"></iframe>
<h1 id="message" style="margin-top:60px;"></h1>
<!-- body needs to be replaced with.. either the chatroom or the homepage.. -->
<script type="text/javascript">
<?php
if ( isset($_REQUEST['topic'])) {
echo 'window.history.pushState("Chirp chat on #'.$_REQUEST['topic'].'", "Chirped.it chat on #'.$_REQUEST['topic'].'", "/#'.$_REQUEST['topic'].'");';
}
?>
window.url = window.location.href;
function watchUrl() {
if (window.location.href !== url) {
url = window.location.href;
runPage();
} else {
setTimeout(function(){
watchUrl();
}, 50);
}
}
watchUrl();
function runPage() {
console.error(url);
window.topic = 'no-topic'; //default
if (url.indexOf('/#') > 0) {
topic = url.substr(url.indexOf('/#') + 2, url.length);
console.error('fetching chatroom #' + topic);
function requireJS(src) {
var pageJS = document.createElement('script');
pageJS.src = src;
doc.body.appendChild(pageJS);
}
function chatroomResponse(resp) {
console.error('got response on ' + topic);
doc.body.innerHTML = resp;
requireJS('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
requireJS('/js/tweet.js');
requireJS('/js/chatroom.js');
}
var pos = doc.createElement('style');
pos.innerText = 'html {position:fixed;}';
doc.head.appendChild(pos);
if (topic !== 'devin') {
var iframeUrl = '/chatroom.php'+
'?twtusername='+encodeURIComponent( '<?php echo $_REQUEST['twtusername']; ?>')+
'&twtname='+encodeURIComponent( '<?php echo $_REQUEST['twtname']; ?>')+
'&twtprofilepic='+encodeURIComponent( '<?php echo $_REQUEST['twtprofilepic']; ?>')+
'&topic='+topic;
console.error('the iframe url' + iframeUrl);
d.id('theIframe').setAttribute('src', iframeUrl);
//d.id('theIframe').setAttribute('src', 'http://chat.chirped.it/chatroom.php?topic='+topic);
//GET('/chatroom.php?topic=' + topic, chatroomResponse);
} else {
d.id('theIframe').setAttribute('src', 'http://chat.chirped.it/chatroom.php?topic='+topic);
//GET('/chatroom.devin.php?topic=' + topic, chatroomResponse);
}
} else {
console.error('fetching homepage!');
GET('/new_homepage.php?fresh'+Date.now(), function(resp) {
console.error('homepage rolling in!');
doc.body.innerHTML = resp;
requireJS('/js/homepage.js');
});
}
if (topic === 'no-topic') {
var end = 'If you\'re reading this it probably isn\'t loading. Email Devin: [email protected]';
d.id('message').innerText = 'loading an awesome homepage..' + end;
} else {
d.id('message').innerText = 'loading an awesome chat on #' + topic + end;
}
}
runPage();
</script>
</body>
</html>