forked from adamwulf/jotbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
397 lines (342 loc) · 12.3 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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?
include "include.php";
require_once ('codebird-php/src/codebird.php');
$mysql = new MySQLConn(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD);
$db = new JSONtoMYSQL($mysql);
$app = new EasyApp($db);
\Codebird\Codebird::setConsumerKey(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
// start session for tracking logged in user
session_start();
//
// create list in our account if we're logged in,
// otherwise as an anonymous list
if(isset($_GET["create_list"])){
$list_id = $_GET["create_list"];
$list_id = str_replace(" ", "-", $list_id);
$list_id = preg_replace('/[^a-zA-Z0-9_\-]/', '', $list_id);
if(!$list_id){
header("Location: /");
exit;
}
if($app->isLoggedIn()){
header("Location: https://www.jotbook.net/" . $app->twitter()->screenname() . "/" . $list_id . "/");
}else{
header("Location: https://www.jotbook.net/list/" . $list_id . "/");
}
exit;
}
$list_id = readFormValue("list_id", $_REQUEST);
$owner_name = readFormValue("owner_name", $_REQUEST);
if(!strlen($owner_name)){
// default owner of lists is just public "list"
$owner_name = "list";
}
// figure out my username if i'm logged in, and default to anonymous "list" otherwise
$my_name = $app->isLoggedIn() ? $app->twitter()->screenname() : "list";
if($app->isLoggedIn() && isset($_GET["copy"])){
// copy the current list to the user's own account
$list_id = $app->copyList($owner_name, $list_id, $my_name);
header("Location: https://www.jotbook.net/" . $app->twitter()->screenname() . "/" . $list_id . "/");
exit;
}
// a list is invalid if it doesn't exist yet and it'd be created it someone else's account instead of ours
$invalid_list = !($owner_name == "list" || $owner_name == $my_name) && !$app->listExistsHuh($owner_name, $list_id);
$my_lists = array();
$not_my_lists = array();
if($app->isLoggedIn()){
$my_name = $app->twitter()->screenname();
$list_table = $db->table("accessed_lists");
$list_table->delete(array("twitter_id" => $app->twitter()->userId(), "list_id" => $list_id, "owner_name" => $owner_name));
if($list_id && !$invalid_list){
// don't save an accessed list if it doesn't exist in another user's account
$db->save(array("twitter_id" => $app->twitter()->userId(), "list_id" => $list_id, "owner_name" => $owner_name, "stamp" => time()), "accessed_lists");
}
if(isset($_GET["forget"])){
$list_id = readFormValue("list_id", $_REQUEST);
$list_table = $db->table("accessed_lists");
$list_table->delete(array("twitter_id" => $app->twitter()->userId(), "list_id" => $list_id, "owner_name" => $owner_name));
}
$list_table = $db->table("accessed_lists");
$result = $list_table->find(array("twitter_id" => $app->twitter()->userId()));
$mine = array();
$mine_key = array();
$theirs = array();
$theirs_key = array();
while($row = $result->fetch_array()){
if($row['owner_name'] == $my_name){
$mine_key[] = $row['list_id'] . "/" . $row['owner_name'];
$mine[] = $row;
}else{
$theirs_key[] = $row['list_id'] . "/" . $row['owner_name'];
$theirs[] = $row;
}
}
array_multisort($mine_key, SORT_ASC, $mine);
array_multisort($theirs_key, SORT_ASC, $theirs);
$my_lists = $mine;
$not_my_lists = $theirs;
}
if($app->isLoggedIn() && isset($_GET["forget"])){
if(count($my_lists)){
header('Location: ' . '/' . $my_lists[0]["owner_name"] . '/' . $my_lists[0]["list_id"] . '/');
}else if(count($not_my_lists)){
header('Location: ' . '/' . $not_my_lists[0]["owner_name"] . '/' . $not_my_lists[0]["list_id"] . '/');
}else{
header('Location: ' . '/');
}
die();
}else if(isset($_GET["logout"])){
$app->logout();
header('Location: ' . page_self_url());
die();
}else if(isset($_GET['twitter_login'])){
$current_url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url=strtok($current_url,'?');
$auth_url = $app->twitterLogin(array(
'oauth_callback' => 'https://www.jotbook.net/',
'true_callback' => $current_url,
'state' => 'twitter_login'
));
header('Location: ' . $auth_url);
die();
}else if (isset($_GET['oauth_verifier']) && isset($_SESSION['twitter_oauth_verify'])) {
$true_callback = $app->verifyLogin($_GET['oauth_verifier']);
// send to same URL, without oauth GET parameters
header('Location: ' . $true_callback);
die();
}
?>
<html>
<head>
<script>
if(typeof(console) == "undefined") console = {};
if(typeof(console.log) == "undefined") console.log = function(){}
</script>
<!-- <script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script> -->
<script src="/includes/jquery.js" type="text/javascript"></script>
<script src="/includes/bajax.js" type="text/javascript"></script>
<script src="/includes/model.js" type="text/javascript"></script>
<script src="/includes/util.js" type="text/javascript"></script>
<script src="/includes/devview.js" type="text/javascript"></script>
<script src="/includes/controller.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
var model = new $.Model();
var view = new $.View($("#interface"));
var controller = new $.Controller(model, view);
});
</script>
<style>
li .checkbox{
display: block;
position: absolute;
left: -8px;
top: 2px;
}
li span{
display: block;
padding:3px;
min-height: 14px;
font-size: 10pt;
}
li input.str{
width: 90%;
}
li.completed > input.str{
text-decoration: line-through;
}
li.completed > span{
text-decoration: line-through;
}
li{
background: url(/includes/bullet.png) no-repeat 1px 6px;
padding-left: 10px;
position: relative;
}
ul{
list-style: none;
}
#user{
width:200px;
float: right;
border-left: 1px solid black;
padding:20px;
min-height: 200px;
overflow: hidden;
}
#interface{
margin-right: 240px;
}
#users div img{
width:20px;
height:20px;
float:left;
margin-right:10px;
}
#users div{
line-height:20px;
height:20px;
margin-bottom:2px;
}
#user_box{
display: none;
}
</style>
</head>
<body>
<div id="user">
<?
if($app->isLoggedIn()){
echo "logged in as " . $app->twitter()->screenname() . "<br>";
echo "<img src='" . $app->twitter()->avatar() . "'/><br>";
echo "<a href='" . page_self_url() . "?logout" . "'>Log Out</a><br>";
echo "<br>";
echo "<div id='user_box'>";
echo "<b>Active People</b><br>";
echo "<div id='users'></div>";
echo "<br>";
echo "</div>";
if($list_id){
echo "<b>Make New List</b><br>";
echo "<form action=/ method=GET>";
echo "<input name=create_list type=text style='width:120px'><input type='submit' value='Go' style='width:40px;'/>";
echo "</form>";
}
echo "<b>My Lists</b><br>";
for($i=0;$i<count($my_lists);$i++){
if($my_lists[$i]["list_id"] != ""){
if($list_id == $my_lists[$i]["list_id"] && $owner_name == $my_lists[$i]["owner_name"]){
echo $list_id . "<br>";
}else{
echo "<a href='/" . $my_lists[$i]["owner_name"] . "/" . urlencode($my_lists[$i]["list_id"]) . "/'>" . $my_lists[$i]["list_id"] . "</a><br>";
}
}
}
if(count($not_my_lists)){
echo "<br><b>Other Lists</b><br>";
for($i=0;$i<count($not_my_lists);$i++){
if($not_my_lists[$i]["list_id"] != ""){
if($list_id == $not_my_lists[$i]["list_id"] && $owner_name == $not_my_lists[$i]["owner_name"]){
echo $list_id . "<br>";
}else{
echo "<a href='/" . $not_my_lists[$i]["owner_name"] . "/" . urlencode($not_my_lists[$i]["list_id"]) . "/'>" .
$not_my_lists[$i]["list_id"] .
"</a><br>";
}
}
}
}
echo "<br>";
if($owner_name != $my_name){
echo "<br>";
echo "<a href='?copy'>copy list to my account</a><br>";
}
echo "<br>";
echo "<a href='?forget'>forget this list</a><br>";
echo "(list won't be deleted, but will be removed from sidebar)<br>";
}else{
echo "<a href='" . page_self_url() . "?twitter_login" . "'>";
echo "<img src='" . page_self_url() . "images/sign-in-with-twitter-gray.png' border=0/>";
echo "</a>";
echo "<br>(optional)<br><br>";
echo "<div id='user_box'>";
echo "<b>Active People</b><br>";
echo "<div id='users'></div>";
echo "<br>";
echo "</div>";
if($list_id){
echo "<br><br>";
echo "<b>Make New List</b><br>";
echo "<form action=/ method=GET>";
echo "<input name=create_list type=text style='width:120px'><input type='submit' value='Go' style='width:40px;'/>";
echo "</form>";
}
}
if($list_id){
echo "<br><br>";
$url = "https://www.jotbook.net/" . $owner_name . "/" . $list_id;
echo "Access this list anytime at <a href='$url'>$url</a>.";
echo "<br><br>";
echo "Share this URL with others to edit this list together!";
}
?>
</div>
<?
if(!$list_id){
?>
<div style='padding:100px;margin-right:240px;'>
<b><a href='https://www.jotbook.net'>Jotbook.net</a></b> lets you easily create and edit lists with others.<br><br>
Each list is given a permanent URL. Share that URL with others to collaborate on your list! Anyone you give the URL to can edit the list with you!
<br><br>
<form action="/">
https://www.jotbook.net/<?=$my_name?>/<input type=text name=create_list size=30 placeholder="your list name"/>
<input type=submit value=Go>
</form>
<br><br><br><br><br><br><br><br>
Jotbook is open source - find it at <a href='https://github.com/adamwulf/jotbook'>https://github.com/adamwulf/jotbook</a>.
<br><br>
Jotbook was created by <a href='https://twitter.com/adamwulf'>Adam Wulf</a> and <a href='https://twitter.com/buckwilson'>Buck Wilson</a> many years ago
as a prototype for realtime list collaboration. What you see here is the first exploratory phase of building out the service, which we later
abandoned. As unrefined as it is, I've found it useful for quick note taking, so I've opened it up for wider use. Feel free to write some notes
and lists here, or download the source below to run on your own server or tinker with. Have fun!<br><br>
- Adam<br><br>
Jotbook development is supported by <a href='https://getlooseleaf.com'>Loose Leaf app</a> for iPad.<br><br>
</div>
<?
}else if($invalid_list){
// i can only add a list ot the anonymous url or to my username's url
?>
<div style='padding:100px;margin-right:240px;'>
<b><a href='https://www.jotbook.net'>Jotbook.net</a></b> lets you easily create and edit lists together with others.
<br><br>
<b>404</b> - The list "<?=$list_id?>" does not exist in <?=$owner_name?>'s account.<br><br>
Create this list at <a href='https://www.jotbook.net/list/?create_list=<?=$list_id?>'>https://www.jotbook.net/<?=$my_name?>/<?=$list_id?>/</a> instead.
<br><br><br><br><br><br><br><br>
Jotbook is open source - find it at <a href='https://github.com/adamwulf/jotbook'>https://github.com/adamwulf/jotbook</a>.
<br><br>
Jotbook was created by <a href='https://twitter.com/adamwulf'>Adam Wulf</a> and <a href='https://twitter.com/buckwilson'>Buck Wilson</a> many years ago
as a prototype for realtime list collaboration. What you see here is the first exploratory phase of building out the service, which we later
abandoned. As unrefined as it is, I've found it useful for quick note taking, so I've opened it up for wider use. Feel free to write some notes
and lists here, or download the source below to run on your own server or tinker with. Have fun!<br><br>
- Adam<br><br>
Jotbook development is supported by <a href='https://getlooseleaf.com'>Loose Leaf app</a> for iPad.<br><br>
</div>
<?
}else{
?>
<div id="interface">
</div>
<?
if($list_id){
?>
<br><br><br><br>
<div style='font-size:10pt'>
(Click a row to edit. Up/Down arrows to move between rows. Tab and Shift+Tab to indent, unindent. Enter to add new rows. Esc to finish editing.)
<? if($list_id){ ?>
<br><br>
Share <?="<a href='$url'>$url</a>"?> with anyone to edit it together.
<? } ?>
<br><br>
<a href='https://www.milestonemade.com/'>Milestone Made</a> © 2014 | Contact <a href='https://twitter.com/adamwulf'>@adamwulf</a> with
questions or comments about Jotbook.
</div>
<?
}
?>
<!--
<input type='button' value='stop' id='stopbutton'>
<input type='button' value='refresh' id='refreshbutton'>
-->
<?
}
?>
<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-180672-20', 'jotbook.net');
ga('send', 'pageview');
</script>
</body>
</html>