-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_post.php
137 lines (124 loc) · 4.11 KB
/
send_post.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
<?php
session_start();
if (!isset($_SESSION['entity'])) {
$error = "You're not logged in!";
header('Location: index.php?error='.urlencode($error));
}
require_once('functions.php');
?>
<html>
<head>
<title>New Post - Tasky</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="body_wrap">
<h2 class="page_heading">Tasky</h2>
<?php
if (isset($_GET['type'])) {
switch ($_GET['type']) {
case 'status':
//$type =
break;
case 'essay':
//Create an essay
break;
case 'notebook':
if (isset($_GET['description'])) {
$description = $_GET['description'];
}
else {
$description = '';
}
$type = 'http://cacauu.de/noot/notebook/v0.1';
$post_raw = array(
'type' => 'http://cacauu.de/noot/notebook/v0.1#',
'permissions' => array(
'public' => false,
),
'content' => array(
'name' => $_GET['title'],
'description' => $description,
)
);
break;
case 'delete':
//Delete a post
break;
default:
//Create a note
}
}
elseif (isset($_POST['title']) && isset($_POST['priority'])) {
$type = 'http://cacauu.de/noot/note/v0.1';
$post_raw = array(
'type' => 'http://cacauu.de/noot/note/v0.1#todo',
'permissions' => array(
'public' => false,
),
'content' => array(
'title' => $_POST['title'],
'priority' => $_POST['priority'],
'note' => $_POST['notes'],
'notebook' => $_POST['notebook'],
'status' => 'To Do',
),
'mentions' => array(
array(
'post' => $_POST['notebook'],
),
),
);
}
echo "<p><b>Type: </b>".$type."</p>";
$post_data = json_encode($post_raw);
echo $post_data;
$time = time();
$nonce = uniqid('Noot_', true); //Generating the nonce TODO: Use a PHP library to do that more secure
//Generating the MAC for the request
$entity = $_SESSION['entity'];
$entity_sub = $_SESSION['entity_sub'];
echo "<p><b>Sub: </b>".$entity_sub."</p>";
echo "<h2>Posting</h2>";
$mac_send = generate_mac('hawk.1.header', $time, $nonce, 'POST', '/posts', $entity_sub, '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_SESSION['new_post_endpoint']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Hawk id="'.$_SESSION['access_token'].'", mac="'.$mac_send.'", ts="'.$time.'", nonce="'.$nonce.'", app="'.$_SESSION['client_id'].'"'."\n".'Content-Type: application/vnd.tent.post.v0+json; type="'.$type.'#todo"')); //Setting the HTTP header
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$send = curl_exec($ch);
curl_close($ch);
$send = json_decode($send, true);
if (isset($send['error'])) {
echo "<p><b>Auth-Error: </b>".$send['error']."</p>";
}
else {
var_export($send);
}
echo "<hr />";
echo "<h2>Reading</h2>";
$mac_posts = generate_mac('hawk.1.header', $time, $nonce, 'GET', '/posts?types='.$type, $entity_sub, '80', $_SESSION['client_id'], $_SESSION['hawk_key'], false);
$init = curl_init();
curl_setopt($init, CURLOPT_URL, $_SESSION['posts_feed_endpoint'].'?types='.$type);
curl_setopt($init, CURLOPT_HTTPGET, 1);
curl_setopt($init, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($init, CURLOPT_HTTPHEADER, array('Authorization: Hawk id="'.$_SESSION['access_token'].'", mac="'.$mac_posts.'", ts="'.$time.'", nonce="'.$nonce.'", app="'.$_SESSION['client_id'].'" Content-Type: application/vnd.tent.post.v0+json; type="'.$type.'"')); //Setting the HTTP header
$posts = curl_exec($init);
curl_close($init);
$posts = json_decode($posts, true);
if (isset($posts['error'])) { //Auth-Errors go here
echo "<p><b>Auth-Error: </b>".$posts['error']."</p>";
}
else {
var_export($posts['posts']);
}
?>
</div>
<footer><h3>Created by <a href="https://cacauu.tent.is">^Cacauu</a></h3>
<h3><a href="developer.php">Developer Resources</a></h3>
<?php
?>
</footer>
</body>
</html>