-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-your-projects.php
executable file
·198 lines (177 loc) · 11 KB
/
add-your-projects.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
<?php
/*
* Template Name: Add Your Projects Template
* @package WordPress
* @subpackage Code_for_Freedom
* @since Code for Freedom 1.0
*/
get_header();
// Include the featured content template.
get_template_part('front-banner');
?>
<div id="main" class="container"><!-- #main container -->
<div class="main-content col-xs-12 col-sm-8">
<div class="add-new-project frontPost row">
<div class="title">Add Your Projects</div>
<div class="content">
<?php
if (!('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == "new_project")) {
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif;
}
?>
</div>
<div id="postbox" class="row">
<?php
if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == "new_project") {
$validate = true;
if (isset ($_POST['leader_name']) && $_POST['leader_name'] != '') {
$name = $_POST['leader_name'];
} else {
echo '<div class="alert alert-danger" role="alert">Please enter "Your name"</div>';
$validate = false;
}
if (isset ($_POST['leader_surname']) && $_POST['leader_surname'] != '') {
$surname = $_POST['leader_surname'];
} else {
echo '<div class="alert alert-danger" role="alert">Please enter "Your surname"</div>';
$validate = false;
}
if (isset ($_POST['email']) && $_POST['email'] != '') {
$email = $_POST['email'];
} else {
echo '<div class="alert alert-danger" role="alert">Please enter "Your e-mail"</div>';
$validate = false;
}
if (isset ($_POST['title']) && $_POST['title'] != '') {
$title = $_POST['title'];
} else {
echo '<div class="alert alert-danger" role="alert">Please enter "Title of the project"</div>';
$validate = false;
}
if (isset ($_POST['description']) && $_POST['description'] != '') {
$description = $_POST['description'];
} else {
echo '<div class="alert alert-danger" role="alert">Please enter "Description of the project"</div>';
$validate = false;
}
if (!isset ($_POST['rules'])) {
echo '<div class="alert alert-danger" role="alert">Please accept rules</div>';
$validate = false;
}
}
if (isset($validate) && $validate == true) {
?>
<?php // Add the content of the form to $post as an array
$new_project = array(
'post_title' => $title,
'post_content' => $description,
'post_category' => array(get_cat_ID('Projects')), // Usable for custom taxonomies too
'post_status' => 'pending', // Choose: publish, preview, future, draft, etc.
'post_type' => 'post' //'post',page' or use a custom post type if you want to
);
//save the new post
$pid = wp_insert_post($new_project);
add_post_meta($pid, 'autor', $name . ' ' . $surname);
add_post_meta($pid, 'email', $email);
if (isset($_FILES['logo']) && !empty($_FILES['logo']['name'])) {
$uploadDir = wp_upload_dir();
$file = $_POST['logo'];
$uploadFile = $uploadDir['path'] . '/' . basename($file);
$upload = wp_upload_bits($_FILES['logo']['name'], null, file_get_contents($_FILES['logo']['tmp_name']));
if (isset($upload['error']) && $upload['error'] != 0) {
?>
<div id="new_project" class="error">
<?php echo 'There was an error uploading your file. The error is: ' . $upload['error'] ?>
</div>
<?php
} else {
$filename = $upload['file'];
$wp_fileType = wp_check_filetype(basename($filename), null);
$attachment = array(
'guid' => $uploadDir['url'] . '/' . basename($filename),
'post_mime_type' => $wp_fileType['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => 'Project ' . $title,
'post_status' => 'inherit'
);
// Insert the attachment.
$attach_id = wp_insert_attachment($attachment, $filename, $pid);
// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Generate the metadata for the attachment, and update the database record.
$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
wp_update_attachment_metadata($attach_id, $attach_data);
// Add thumbnail to post
set_post_thumbnail($pid, $attach_id);
}
}
?>
<div id="new_project" class="congrats">
Thank you for sending your project to us!
</div>
<?php } else { ?>
<form id="new_project" name="new_project" method="POST" action=""
enctype="multipart/form-data">
<span class="col-xs-12 col-sm-6">
<label for="leader_name">Your name<span class="require">*</span></label><br/>
<input type="text" id="leader_name" class="goodlook" value="" tabindex="1"
size="255"
required="required" name="leader_name"/>
</span>
<span class="col-xs-12 col-sm-6">
<label for="leader_surname">Your surname<span class="require">*</span></label><br/>
<input type="text" id="leader_surname" class="goodlook" value="" tabindex="1"
size="255"
required="required" name="leader_surname"/>
</span>
<span class="col-xs-12 col-sm-6 separate">
<label for="email">Your e-mail<span class="require">*</span></label><br/>
<input type="email" id="email" class="goodlook" value="" tabindex="1" size="255"
required="required" name="email"/>
</span>
<span class="col-xs-12 col-sm-6">
<label for="title">Title of your project<span class="require">*</span></label><br/>
<input type="text" id="title" class="goodlook" value="" tabindex="1" size="255"
required="required" name="title"/>
</span>
<span class="col-xs-12 col-sm-6">
<label for="description">Description of your project<span
class="require">*</span></label><br/>
<textarea id="description" tabindex="3" name="description" cols="50"
required="required" rows="6"></textarea>
</span>
<span class="col-xs-12 col-sm-6 logo">
<label for="logo">Logo of the project (Optionally)</label><br/>
<input type="file" name="logo" id="logo">
</span>
<span class="col-xs-12 col-sm-12 rulesBlock">
<label>Consent for processing of personal data<span class="require">*</span></label><br/>
<input type="checkbox" name="rules" id="rules" required="required">
<label for="rules" class="smallOne">I agree for publishing this information on
<a href="www.codeforfreedom.org" target="_self">www.codeforfreedom.org</a> and I
agree that the event organizers will use my email
to contact me regarding this event and not for any marketing purpose. I'm aware
that I can withdraw my permission anytime by contacting the organizers at
<a href="mailto:[email protected]" target="_blank">[email protected]</a></label>
</span>
<span class="col-xs-12 col-sm-12">
<button type="submit" id="submit" name="submit">
<span>submit</span>
<div class="arrow">→</div>
</button>
</span>
<input type="hidden" name="action" value="new_project"/>
<?php wp_nonce_field('new_project'); ?>
</form>
<?php } ?>
</div>
</div>
</div>
<div class="main-sidebar col-xs-12 col-sm-3 col-sm-offset-1">
<?php get_sidebar('front'); ?>
</div>
</div>
<?php
get_footer();