-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.php
More file actions
150 lines (129 loc) · 5.64 KB
/
Copy pathPost.php
File metadata and controls
150 lines (129 loc) · 5.64 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
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
<?php require_once 'Include/Load.php';
$session = App::getSession();
$link = App::getDatabase();
$user = App::getUser();
$validator = App::getValidator();
$user->restrict();
if ($user->has('id')) {
$post_id = App::get('id');
$post = $link->query('SELECT * FROM posts WHERE id = :id', ['id' => $post_id])->fetch();
if ($session->getKey('user_infos')->id !== $post->user_id){
App::redirect('Posts.php');
}
}
if ($validator->isPosted()){
if ($user->has('id')){
$post_id = App::get('id');
$post = $link->query('SELECT * FROM posts WHERE id = :id', ['id' => $post_id])->fetch();
$validator->isTooLong('title', 50, 'The Title must not be more than 50 Characters long');
if (!empty($_POST['description'])) {
$validator->isTooLong('description', 100, 'The Description must not be more than 100 Characters long');
}
if ($validator->isValid()){
if (!empty($_FILES['postPic']['name'])){
if ($_FILES['postPic']['error'] == 0){
if ($user->upLoadFile($_FILES['postPic'], 5242880, ['jpg', 'jpeg', 'gif', 'png'])){
$user->modifyPost($_POST['title'], $_POST['description'], $_POST['content'], $post_id, $post, basename($_FILES['postPic']['name']));
} else {
if (is_bool($user->upLoadFile($_FILES['postPic'], 5242880, ['jpg', 'jpeg', 'gif', 'png']))) {
$session->setFlash('alert', 'Allowed File Extensions are: jpg, jpeg, gif, png');
} else {
$session->setFlash('alert', 'The File must not be more than 5Mo');
}
$user->modifyPost($_POST['title'], $_POST['description'], $_POST['content'], $post_id, $post);
}
} else {
$user->modifyPost($_POST['title'], $_POST['description'], $_POST['content'], $post_id, $post);
}
} else {
$user->modifyPost($_POST['title'], $_POST['description'], $_POST['content'], $post_id, $post, NULL, false);
}
$session->setFlash('success', 'The Post has been successfully modified');
App::redirect('Posts.php');
} else {
$errors = $validator->getErrors();
}
} else {
$user_id = $session->getKey('user_infos')->id;
$validator->isTooLong('title', 50, 'The Title must not be more than 50 Characters long');
if (!empty($_POST['description'])) {
$validator->isTooLong('description', 100, 'The Description must not be more than 100 Characters long');
}
if ($validator->isValid()) {
if (!empty($_FILES['postPic'])) {
if ($_FILES['postPic']['error'] == 0) {
if ($user->upLoadFile($_FILES['postPic'], 5242880, ['jpg', 'jpeg', 'gif', 'png'])) {
$user->makePost($_POST['title'], $_POST['description'], $_POST['content'], $user_id, basename($_FILES['postPic']['name']));
} else {
if (is_bool($user->upLoadFile($_FILES['postPic'], 5242880, ['jpg', 'jpeg', 'gif', 'png']))) {
$session->setFlash('alert', 'Allowed File Extensions are: jpg, jpeg, gif, png');
} else {
$session->setFlash('alert', 'The File must not be more than 5Mo');
}
$user->makePost($_POST['title'], $_POST['description'], $_POST['content'], $user_id);
}
} else {
$user->makePost($_POST['title'], $_POST['description'], $_POST['content'], $user_id);
}
} else {
$user->makePost($_POST['title'], $_POST['description'], $_POST['content'], $user_id);
}
$session->setFlash('success', 'The Post has successfully published');
} else {
$errors = $validator->getErrors();
}
}
}
?>
<?php require_once 'Include/Header.php'; ?>
<?php if (!empty($errors)): ?>
<div class="error-msg">
<p>The Information were not filled correctly. These are the possible errors:</p>
<ul>
<?php foreach ($errors as $error): ?>
<li><?= $error ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<style>
.login-box .user-box textarea{
background: none;
color: white;
width: 100%;
padding: 5px;
}
.login-box .user-box #description{
height: 40px;
margin-bottom: 30px;
overflow: auto;
}
.login-box .user-box #content{
height: 300px;
overflow: auto;
}
</style>
<div class="login-box">
<h2>Post</h2>
<form action="" method="post" enctype="multipart/form-data">
<div class="user-box">
<input type="text" name="title" required="" value="<?= isset($post) ? $post->title : ''; ?>">
<label>Title</label>
</div>
<div class="user-box">
<textarea name="description" id="description" placeholder="Description (Less than 100 characters)
(Not Required)"><?= isset($post) ? $post->description : ''; ?></textarea>
</div>
<div class="user-box">
<textarea name="content" id="content" placeholder="Content" required><?= isset($post) ? $post->content : ''; ?></textarea>
</div>
<div class="user-box">
<input type="file" name="postPic">
<label></label>
</div>
<button type="submit">Submit</button>
</form>
</div>
<?php include_once 'Include/Mode.php' ?>
</body>
</html>