-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
338 lines (282 loc) · 15.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
<?php
session_name('Noot');
session_start();
if (!isset($_SESSION['entity'])) {
header('Location: landing.php');
}
require_once('functions.php');
require_once('tent-markdown.php');
?>
<html>
<head>
<title>Noot</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta charset="utf-8">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.leanModal.min.js"></script>
<script>
$(function() {
$('a[rel*=leanModal]').leanModal({ top : 200, closeButton: ".modal_close" });
});
</script>
</head>
<body>
<?php include('header.php'); ?>
<div class="container">
<!-- Notebook list column -->
<div class="column-1">
<div class='column-1-inner'>
<div style='padding: 5%; margin-top: 5px; border-bottom: 1px solid #ddd;'><a href="index.php"><b>All notebooks</b></a></div>
<?php
if ($notebooks['posts'] == '' OR $notebooks['posts'] == array()) {
echo "<p>No notebooks, create one!</p>";
?>
<form align="center" method="post" action="task_handler.php?type=notebook">
<input type="text" name="notebook_name" placeholder="Add new notebook" class="text" style="width: 70%"/>
<input type="submit" class="text" style="width: 20%;">
</form>
<?php
}
elseif (isset($posts['error'])) {
echo "<h3 style='color: red;'>Error: ".$posts['error']."</h3>";
}
else { ?>
<?php
echo "";
foreach ($notebooks['posts'] as $notebook) {
$content = $notebook['content'];
echo "";
if (!is_null($content['name'])) {
echo "<div style='width: 90%; padding: 5%;'><img src='img/notebook.png' style='width: 16px; margin-right: 5px; margin-bottom: -3px;'><a href='index.php?notebook=".$notebook['id']."'>".$content['name']."</a>";
echo "<a style='float: right;' href='edit.php?notebook=".$notebook['id']."'>Edit</a>";
echo "<a class='delete' href='task_handler.php?type=delete&id=".$notebook['id']."'><img src='img/delete.png' style='width: 8px; float: right; margin: 3px;'></a></div>";
}
}
echo "<form align='center' method='post' action='task_handler.php?type=notebook' style='margin-top: 30px;'>
<input type='text' name='notebook_name' placeholder='Add new notebook' class='text' style='width: 70%'/>
<input type='submit' class='text' style='width: 28%;'>
</form></div></div>";
}
?>
<!-- END Notebook list column -->
<!-- Note list column -->
<div class='column-2' style="height: 100%;">
<div class='column-2-inner'>
<div class="filters">
<div style="float: left;">
<b><?php
if(isset($_GET['notebook'])){
foreach ($notebooks['posts'] as $nb) {
if ($nb['id'] == $_GET['notebook']) {
echo $nb['content']['name'];
}
}
}
else {
echo "All Notes";
} ?></b>
</div>
<a class="javascript-nav" rel="leanModal" href="#new_post">Create new note +</a>
<a class="javaless-nav" href="new_post_page.php" style="font-size: 16px;">Create new note +</a>
</div>
<?php
if (!isset($_GET['notebook'])) {
unset($_SESSION['redirect_notebook']);
$mac = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts?types=http%3A%2F%2Fcacauu.de%2Fnoot%2Fnote%2Fv0.1', $entity_sub, '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$init = curl_init();
curl_setopt($init, CURLOPT_URL, $_SESSION['posts_feed_endpoint'].'?types=http%3A%2F%2Fcacauu.de%2Fnoot%2Fnote%2Fv0.1');
curl_setopt($init, CURLOPT_HTTPGET, 1);
curl_setopt($init, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($init, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac, time(), $nonce, $_SESSION['client_id']))); //Setting the HTTP header
$posts = curl_exec($init);
curl_close($init);
$posts = json_decode($posts, true);
echo "<table>";
foreach ($posts['posts'] as $note) {
$content = $note['content'];
echo "<td><a href='index.php?note=".$note['id']."'>".$content['title']."</a>";
echo "</tr>";
}
echo "</table></div></div>";
if (isset($_GET['note']) and !isset($_GET['edit'])) {
$_SESSION['redirect_notebook'] = "note=".$_GET['note'];
$id = $_GET['note'];
$nonce = uniqid('Noot_', true);
$entity_sub = substr_replace($_SESSION['entity'] ,"",-1);
//Getting the current version of the post
$current_url = str_replace("{entity}", urlencode($entity_sub), $_SESSION['single_post_endpoint']);
$current_url = str_replace("{post}", $id, $current_url);
$mac_current = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts/'.urlencode($entity_sub)."/".$id, $_SESSION['entity_sub'], '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$ch_current = curl_init();
curl_setopt($ch_current, CURLOPT_URL, $current_url);
curl_setopt($ch_current, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_current, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac_current, time(), $nonce, $_SESSION['client_id'])));
$current_note_json = curl_exec($ch_current);
curl_close($ch_current);
$current_note = json_decode($current_note_json, true);
?>
<!-- END Notebook list column -->
<!-- Display note from "All notebooks -->
<div class='column-3'>
<div class='column-3-inner'>
<div class="filters" style="max-width: 721px;">
<div style="float: left; font-weight: 800;"><?php echo $current_note['post']['content']['title']; ?></div><a href="index.php?note=<?php echo $current_note['post']['id']; ?>&edit=true">Edit</a> | <a href="task_handler.php?type=delete&id=<?php echo $current_note['post']['id']; ?>">Delete</a>
</div>
<div style="padding: 3%;">
<?php echo tent_markdown($current_note['post']['content']['body']); ?>
</div>
</div>
</div>
<!-- END Display note from "All notebooks -->
<!-- Edit note from "All notebooks -->
<?php
}
elseif (isset($_GET['edit']) and $_GET['edit'] == true) {
$_SESSION['redirect_notebook'] = "note=".$_GET['note'];
$id = $_GET['note'];
$nonce = uniqid('Noot_', true);
$entity_sub = substr_replace($_SESSION['entity'] ,"",-1);
//Getting the current version of the post
$current_url = str_replace("{entity}", urlencode($entity_sub), $_SESSION['single_post_endpoint']);
$current_url = str_replace("{post}", $id, $current_url);
$mac_current = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts/'.urlencode($entity_sub)."/".$id, $_SESSION['entity_sub'], '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$ch_current = curl_init();
curl_setopt($ch_current, CURLOPT_URL, $current_url);
curl_setopt($ch_current, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_current, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac_current, time(), $nonce, $_SESSION['client_id'])));
$current_note_json = curl_exec($ch_current);
curl_close($ch_current);
$current_note = json_decode($current_note_json, true);
?>
<div class='column-3'>
<div class='column-3-inner'>
<div class="filters" style="max-width: 721px;">
<div style="float: left; font-weight: 800;">
<form align="center" method="post" action="task_handler.php?type=update&parent=<?php echo $current_note['post']['version']['id']; ?>&id=<?php echo $current_note['post']['id']; ?>" method="post">
<input class="note_title" style="background: none; color: black; border: none; font-weight: 800;" type="text" name="title" value="<?php echo $current_note['post']['content']['title']; ?>" /></div>
<input type="submit" value="Save changes" /></div>
<p><textarea name="body" style="margin: auto;
height: 500px;
max-width: 100%;
width: 100%;
color: #000000;
border: none;
font-family: Open Sans;
padding: 3%;" class="note_body"><?php echo $current_note['post']['content']['body']; ?></textarea></p>
</form>
<?php }
}
elseif (isset($_GET['notebook'])) {
unset($_SESSION['redirect_notebook']);
if (!isset($_GET['note'])) {
$_SESSION['redirect_notebook'] = 'notebook='.$_GET['notebook'];
}
else {
$_SESSION['redirect_notebook'] = 'notebook='.$_GET['notebook']."&note=".$_GET['note'];
}
$id = $_GET['notebook'];
$entity_sub_notebook = substr_replace($_SESSION['entity'] ,"",-1);
$current_url = str_replace("{entity}", urlencode($entity_sub_notebook), $_SESSION['single_post_endpoint']);
$current_url = str_replace("{post}", $id, $current_url);
$mac_current = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts/'.urlencode($entity_sub_notebook)."/".$id, $_SESSION['entity_sub'], '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$ch_current = curl_init();
curl_setopt($ch_current, CURLOPT_URL, $current_url);
curl_setopt($ch_current, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_current, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac_current, time(), $nonce, $_SESSION['client_id'])));
$current_notebook = curl_exec($ch_current);
curl_close($ch_current);
$current_notebook = json_decode($current_notebook, true);
//Getting notes from the chosen notebook
$mac = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts?types=http%3A%2F%2Fcacauu.de%2Fnoot%2Fnote%2Fv0.1&mentions='.urlencode($_SESSION['entity_sub']).'+'.$_GET['notebook'], $entity_sub, '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$init = curl_init();
curl_setopt($init, CURLOPT_URL, $_SESSION['posts_feed_endpoint'].'?types=http%3A%2F%2Fcacauu.de%2Fnoot%2Fnote%2Fv0.1&mentions='.urlencode($_SESSION['entity_sub']).'+'.$_GET['notebook']);
curl_setopt($init, CURLOPT_HTTPGET, 1);
curl_setopt($init, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($init, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac, time(), $nonce, $_SESSION['client_id']))); //Setting the HTTP header
$posts = curl_exec($init);
curl_close($init);
$posts = json_decode($posts, true);
if ($posts['posts'] != array()) {
echo "<table>";
foreach ($posts['posts'] as $note) {
$content = $note['content'];
echo "<tr class='".$content['status']."'>";
echo "<td><a href='index.php?notebook=".$_GET['notebook']."¬e=".$note['id']."'>".$content['title']."</a>";
/* echo "<td style='color: #cd0d00;'><a class='delete' href='task_handler.php?type=delete&id=".$note['id']."'><img src='img/delete.png'></a></td>"; */
echo "</tr>";
}
echo "</table>";
}
else {
echo "<h2>No notes in \"".$current_notebook['post']['content']['name']."\"</h2>";
}
if (isset($_GET['note']) and !isset($_GET['edit'])) {
$_SESSION['redirect_notebook'] = "notebook=".$_GET['notebook']."¬e=".$_GET['note'];
$id = $_GET['note'];
$nonce = uniqid('Noot_', true);
$entity_sub = substr_replace($_SESSION['entity'] ,"",-1);
//Getting the current version of the post
$current_url = str_replace("{entity}", urlencode($entity_sub), $_SESSION['single_post_endpoint']);
$current_url = str_replace("{post}", $id, $current_url);
$mac_current = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts/'.urlencode($entity_sub)."/".$id, $_SESSION['entity_sub'], '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$ch_current = curl_init();
curl_setopt($ch_current, CURLOPT_URL, $current_url);
curl_setopt($ch_current, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_current, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac_current, time(), $nonce, $_SESSION['client_id'])));
$current_note_json = curl_exec($ch_current);
curl_close($ch_current);
$current_note = json_decode($current_note_json, true);
?>
</div>
</div>
<!-- END Edit note -->
<!-- Display note from selected notebook -->
<div class='column-3'>
<div class='column-3-inner'>
<div class="filters" style="max-width: 721px;">
<div style="float: left; font-weight: 800;"><?php echo $current_note['post']['content']['title']; ?></div>
<a href="index.php?notebook=<?php echo $_GET['notebook']; ?>¬e=<?php echo $current_note['post']['id']; ?>&edit=true">Edit</a> | <a href="task_handler.php?type=delete&id=<?php echo $current_note['post']['id']; ?>">Delete</a>
</div>
<div style="padding: 3%;"><?php echo tent_markdown($current_note['post']['content']['body']); ?></div>
</div>
<!-- END Display note from selected notebook -->
<!-- Edit note from selected notebook -->
<?php
}
elseif (isset($_GET['edit']) and $_GET['edit'] == true) {
$_SESSION['redirect_notebook'] = "notebook=".$_GET['notebook']."¬e=".$_GET['note'];
$id = $_GET['note'];
$nonce = uniqid('Noot_', true);
$entity_sub = substr_replace($_SESSION['entity'] ,"",-1);
//Getting the current version of the post
$current_url = str_replace("{entity}", urlencode($entity_sub), $_SESSION['single_post_endpoint']);
$current_url = str_replace("{post}", $id, $current_url);
$mac_current = generate_mac('hawk.1.header', time(), $nonce, 'GET', '/posts/'.urlencode($entity_sub)."/".$id, $_SESSION['entity_sub'], '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$ch_current = curl_init();
curl_setopt($ch_current, CURLOPT_URL, $current_url);
curl_setopt($ch_current, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_current, CURLOPT_HTTPHEADER, array(generate_auth_header($_SESSION['access_token'], $mac_current, time(), $nonce, $_SESSION['client_id'])));
$current_note_json = curl_exec($ch_current);
curl_close($ch_current);
$current_note = json_decode($current_note_json, true);
?>
</div>
<div class='column-3'>
<div class='column-3-inner'>
<form align="center" method="post" action="task_handler.php?type=update&parent=<?php echo $current_note['post']['version']['id']; ?>&id=<?php echo $current_note['post']['id']; ?>" method="post">
<p><input class="note_title" type="text" name="title" value="<?php echo $current_note['post']['content']['title']; ?>" /></p>
<p><textarea name="body" class="note_body"><?php echo $current_note['post']['content']['body']; ?></textarea></p>
<p><input type="submit" value="Save changes" /></p>
</form>
<?php }
}
?>
</div>
</div>
<!-- END Edit note from selected notebook -->
</div>
</div>
<?php include_once('footer.php') ?>
</body>
</html>