-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_posts_admin.php
More file actions
73 lines (59 loc) · 1.76 KB
/
sample_posts_admin.php
File metadata and controls
73 lines (59 loc) · 1.76 KB
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
<?php
include("vendor/autoload.php");
$postID = intval($_GET['post_id']);
$path = "data/post_{$postID}.json";
if(isset($_POST['title'])) {
$post = [
'id' => $postID,
'title' => $_POST['title'],
'body' => $_POST['body']
];
$raw = json_encode($post);
file_put_contents($path, $raw);
$client = new \WebSocket\Client("ws://192.168.10.1:8080/");
$client->send(json_encode([
'event' => 'post_update',
'post' => $post,
'token' => 'my_secret_token'
]));
}
$raw = file_exists($path) ?
file_get_contents($path) :
json_encode(['id' => $postID, 'title' => '', 'body' => '']);
$post = json_decode($raw);
?>
<!doctype html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<form class="col-md-12" name="editPost" method="POST">
<div class="panel panel-info">
<div class="panel-heading clearfix">
Editar post
</div>
<?php if(isset($_POST['title'])) { ?>
<div class="alert alert-success">Post salvo com sucesso!</div>
<?php } ?>
<div class="panel-body" id="messages">
<div class="form-group">
<label class="control-label" for="fld-title">Título:</label>
<input class="form-control" type="text" name="title" id="fld-title" value="<?= $post->title ?>" />
</div>
<div class="form-group">
<label class="control-label" for="fld-body">Post:</label>
<textarea class="form-control" style="height: 500px" name="body" id="fld-body"><?= $post->body ?></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Salvar</button>
</div>
</div>
</div>
</form>
</div>
</body>
</html>