-
Notifications
You must be signed in to change notification settings - Fork 42
/
desktop.php
215 lines (201 loc) · 9.69 KB
/
desktop.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
<?php
$id = "";
if(!isset($_COOKIE["pushid"])) {
$validId = false;
while($validId == false) {
$id = substr(number_format(time() * rand(),0,'',''),0,4);
$r = mysqli_do("SELECT * FROM push WHERE id='$id'");
if(mysqli_num_rows($r) == 0) {
$validId = true;
break;
}
}
setcookie("pushid", $id, time()+60*60*24*30);
}
else {
$id = $_COOKIE["pushid"];
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Safari Push Notification Demo</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<style type="text/css">
body {
margin: 0;
padding: 0;
background: #EDEDED;
font-family: "Avenir Next", "Helvetica Neue", Helvetica, sans-serif;
}
.box {
border-radius: 8px;
background: #fff;
width: 600px;
height: 300px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -300px;
margin-top: -150px;
border: 1px solid #CECECE;
box-shadow: rgba(255,255,255,0.7) 0 1px 0, inset rgba(0,0,0,0.1) 0 1px 2px;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript">
var token = "";
var id = "<?php echo $id; ?>";
window.onload = function() {
if(window.navigator.userAgent.indexOf('7.0 Safari') > -1) {
checkPerms();
}
else {
document.getElementById("old").style.display = "";
if(window.navigator.userAgent.indexOf("Firefox") > -1) {
document.getElementById("firefoxlol").style.display = "";
}
}
};
function checkPerms() {
document.getElementById("reqperm").style.display = "none";
document.getElementById("granted").style.display = "none";
document.getElementById("denied").style.display = "none";
var pResult = window.safari.pushNotification.permission('web.net.kandutech');
if(pResult.permission === 'default') {
//request permission
document.getElementById("reqperm").style.display = "";
requestPermissions();
}
else if(pResult.permission === 'granted') {
document.getElementById("granted").style.display = "";
token = pResult.deviceToken;
}
else if(pResult.permission === 'denied') {
document.getElementById("denied").style.display = "";
}
}
function requestPermissions() {
window.safari.pushNotification.requestPermission('https://kandutech.net', 'web.net.kandutech', {"id": id}, function(c) {
if(c.permission === 'granted') {
document.getElementById("reqperm").style.display = "none";
document.getElementById("granted").style.display = "";
token = c.deviceToken;
}
else if(c.permission === 'denied') {
document.getElementById("reqperm").style.display = "none";
document.getElementById("denied").style.display = "";
}
});
}
function do_push() {
var checksOut = true;
$("#form input").each(function(index, element) {
$(this).parents(".control-group").removeClass("error");
if(element.value == "") {
$(this).parents(".control-group").addClass("error");
checksOut = false;
}
});
if(checksOut == true) {
$.post("https://kandutech.net/v1/push/"+id, {"title": document.getElementById("not_title").value, "body": document.getElementById("not_body").value, "button": document.getElementById("not_button").value});
$("#form input").val("");
$("#modal_scrim").fadeOut(300);
}
}
</script>
</head>
<body>
<div style="background: rgba(0,0,0,0.8); position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: none; z-index: 899;" id="modal_scrim">
<div class="modal">
<div class="modal-header">
<button type="button" class="close" onClick="$('#modal_scrim').fadeOut(300);" aria-hidden="true">×</button>
<h3>Create Push Notification</h3>
</div>
<div class="modal-body form-horizontal" id="form">
<div class="control-group">
<label class="control-label" for="not_title">Title</label>
<div class="controls">
<input type="text" id="not_title">
</div>
</div>
<div class="control-group">
<label class="control-label" for="not_title">Body</label>
<div class="controls">
<input type="text" id="not_body">
</div>
</div>
<div class="control-group">
<label class="control-label" for="not_title">Button Label</label>
<div class="controls">
<input type="text" id="not_button">
</div>
</div>
</div>
<div class="modal-footer">
<div class="btn btn-primary btn-small" onClick="do_push();">Push!</div>
</div>
</div>
</div>
<div class="box">
<div style="font-weight: 500; font-size: 20px; margin: 10px;">Safari Push Notification Demo</div>
<!-- old safari lolz -->
<div style="margin-top: 100px; text-align: center; display: none;" id="old">
You need Safari 7.0 on OS X Mavericks to run this demo!
<div id="firefoxlol" style="display: none; font-size: 11px; margin-top: 20px;">u serious with firefox right now tho? maybe don't.</div>
</div>
<!-- checking permissions -->
<div style="margin-top: 100px; text-align: center; display: none;" id="reqperm">
<img src="loader.gif">
<div>Requesting permission...</div>
</div>
<!-- denied permissions -->
<div style="margin-top: 100px; text-align: center; display: none;" id="denied">
<div>You have denied this website permission to send push notifications.</div>
<div class="btn btn-primary btn-small" onClick="checkPerms();">I've changed my mind...</div>
</div>
<!-- granted permissions -->
<div style="margin-top: 20px; text-align: center; display: none;" id="granted">
<div class="btn btn-primary" onClick="$('#modal_scrim').fadeIn(300); document.getElementById('not_title').focus();">Create New Push Notification</div>
<hr>
<div style="position: absolute; margin-top: -30px; text-align: center; width: 100%; color: #CCC;">OR</div>
<div style="overflow: auto;">
<div style="border-radius: 8px; box-shadow: inset rgba(0,0,0,0.3) 0 1px 2px; border: 1px solid #A0A0A0; height: 50px; width: 50px; font-size: 50px; float: left; margin: 20px; margin-top: 15px; margin-left: 135px; text-align: center; padding-top: 30px;"><?php echo substr($id, 0, 1); ?></div>
<div style="border-radius: 8px; box-shadow: inset rgba(0,0,0,0.3) 0 1px 2px; border: 1px solid #A0A0A0; height: 50px; width: 50px; font-size: 50px; float: left; margin: 20px; margin-top: 15px; text-align: center; padding-top: 30px;"><?php echo substr($id, 1, 1); ?></div>
<div style="border-radius: 8px; box-shadow: inset rgba(0,0,0,0.3) 0 1px 2px; border: 1px solid #A0A0A0; height: 50px; width: 50px; font-size: 50px; float: left; margin: 20px; margin-top: 15px; text-align: center; padding-top: 30px;"><?php echo substr($id, 2, 1); ?></div>
<div style="border-radius: 8px; box-shadow: inset rgba(0,0,0,0.3) 0 1px 2px; border: 1px solid #A0A0A0; height: 50px; width: 50px; font-size: 50px; float: left; margin: 20px; margin-top: 15px; text-align: center; padding-top: 30px;"><?php echo substr($id, 3, 1); ?></div>
</div>
<div>
Type in this code at http://kandutech.net on a mobile device.
<div style="font-size: 11px;">(You can close safari now if you want.)</div>
</div>
</div>
</div>
<div style="position: absolute; top: 50%; margin-top: 170px; left: 50%; width: 600px; text-align: center; margin-left: -300px; text-shadow: #fff 0 1px 0;">
<a href="https://twitter.com/mynamesconnor" class="twitter-follow-button" data-show-count="false">Follow @mynamesconnor</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="https://kandutech.net" data-via="mynamesconnor" data-related="mynamesconnor">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-size="medium" data-href="https://kandutech.net"></div>
<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script><br><div style="font-size: 12px;">Idea thanks to: <a href="http://9to5mac.com/2013/06/26/demo-of-the-first-public-website-using-safaris-new-native-push-notifications-feature-video/" target="_blank">9to5mac.com</a></div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42055607-1', 'kandutech.net');
ga('send', 'pageview');
</script>
</body>
</html>