-
Notifications
You must be signed in to change notification settings - Fork 4
/
save_post.php
278 lines (244 loc) · 9.65 KB
/
save_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
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
<?php
/**
*
* @category modules
* @package news_img
* @author WBCE Community
* @copyright 2004-2009, Ryan Djurovich
* @copyright 2009-2010, Website Baker Org. e.V.
* @copyright 2019-, WBCE Community
* @link https://www.wbce.org/
* @license http://www.gnu.org/licenses/gpl.html
* @platform WBCE
*
*/
global $page_id, $section_id, $post_id, $allowed_suffixes;
require_once __DIR__.'/functions.inc.php';
// Get id
if (!isset($_POST['post_id']) or !is_numeric($_POST['post_id'])) {
header("Location: ".ADMIN_URL."/pages/index.php");
exit(0);
} else {
$id = intval($_POST['post_id']);
$post_id = $id;
}
// Include WB admin wrapper script
$update_when_modified = true; // Tells script to update when this page was last updated
$admin_header = FALSE;
// Include WB admin wrapper script
require WB_PATH.'/modules/admin.php';
if(!defined('CAT_PATH')) {
if (!$admin->checkFTAN()) {
$admin->print_header();
$admin->print_error(
$MESSAGE['GENERIC_SECURITY_ACCESS']
.' (FTAN) '.__FILE__.':'.__LINE__,
ADMIN_URL.'/pages/index.php'
);
$admin->print_footer();
exit();
} else {
$admin->print_header();
}
}
if(!defined('CAT_PATH')) {
include __DIR__.'/config/wbce_config.php';
} else {
include __DIR__.'/config/bc_config.php';
}
$group = '';
$block2 = '';
// Validate all fields
if ($admin->get_post('title') == '' and $admin->get_post('url') == '') {
$post_id_key = $admin->getIDKEY($id);
if (defined('WB_VERSION') && (version_compare(WB_VERSION, '2.8.3', '>'))) {
$post_id_key = $id;
}
$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], WB_URL.'/modules/news_img/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$post_id_key);
} else {
$settings = mod_nwi_settings_get($section_id);
$title = mod_nwi_escapeString($admin->get_post('title'));
$link = mod_nwi_escapeString($admin->get_post('link'));
$short = mod_nwi_escapeString($admin->get_post('short'));
$long = mod_nwi_escapeString($admin->get_post('long'));
if ($settings['use_second_block']=='Y') {
$block2 = mod_nwi_escapeString($admin->get_post('block2'));
}
$image = mod_nwi_escapeString($admin->get_post('image'));
$active = mod_nwi_escapeString($admin->get_post('active'));
$group = mod_nwi_escapeString($admin->get_post('group'));
$tags = $admin->get_post('tags');
}
if ($link=='') {
$link = page_filename($title);
}
$group_id = 0;
$old_section_id = $section_id;
$old_page_id = $page_id;
if (!empty($group)) {
$gid_value = urldecode($group);
$values = unserialize($gid_value);
if (!isset($values['s']) or !isset($values['g']) or !isset($values['p'])) {
header("Location: ".ADMIN_URL."/pages/index.php");
exit(0);
}
if (intval($values['p'])!=0) {
$group_id = intval($values['g']);
$section_id = intval($values['s']);
$page_id = intval($values['p']);
}
}
// Get page link URL
$query_page = $database->query("SELECT `level`,`link` FROM `".TABLE_PREFIX."pages` WHERE `page_id` = '$page_id'");
$page = $query_page->fetchRow();
$page_level = $page['level'];
$page_link = $page['link'];
// get old link
$query_post = $database->query("SELECT `link` FROM `".TABLE_PREFIX."mod_news_img_posts` WHERE `post_id`='$post_id'");
$post = $query_post->fetchRow();
$old_link = $post['link'];
// potential new link
$post_link = '/posts/'.page_filename($link);
// make sure to have the post_id as suffix; this will make the link unique (hopefully...)
if (substr_compare($post_link, $post_id, -(strlen($post_id)), strlen($post_id))!=0) {
$post_link .= PAGE_SPACER.$post_id;
}
// Make sure the post link is set and exists
// Make news post access files dir
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
$file_create_time = '';
if (!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/')) {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
} elseif (($old_link != $post_link) or !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION) or $page_id != $old_page_id or $section_id != $old_section_id) {
// We need to create a new file
// First, delete old file if it exists
if (file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION)) {
$file_create_time = filemtime(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
unlink(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
}
if ($page_id != $old_page_id or $section_id != $old_section_id) {
$file_create_time = '';
}
// Specify the filename
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
mod_nwi_create_file($filename, $file_create_time, null, null);
}
list($publishedwhen, $publisheduntil) = mod_nwi_get_dates();
// post images (gallery images)
$imageErrorMessage = '';
if (isset($_FILES["foto"])) {
$imageErrorMessage = mod_nwi_img_upload($post_id);
}
// ----- post (preview) picture; shown on overview page ----------------------------------
if (isset($_FILES["postfoto"]) && $_FILES["postfoto"]["name"] != "") {
$imageErrorMessage .= mod_nwi_img_upload($post_id, true);
}
// strip HTML from title
$title = strip_tags($title);
$position="";
// if we are moving posts across section borders we have to update the order of the posts
if ($old_section_id!=$section_id) {
// Get new order
$order = new order(TABLE_PREFIX.'mod_news_img_posts', 'position', 'post_id', 'section_id');
$position = "`position` = '".$order->get_new($section_id)."',";
}
// Update row
$database->query(
"UPDATE `".TABLE_PREFIX."mod_news_img_posts`"
. " SET `section_id` = '$section_id',"
. " $position"
. " `group_id` = '$group_id',"
. " `title` = '$title',"
. " `link` = '$post_link',"
. " `content_short` = '$short',"
. " `content_long` = '$long',"
. " `content_block2` = '$block2',"
. " `active` = '$active',"
. " `published_when` = '$publishedwhen',"
. " `published_until` = '$publisheduntil',"
. " `posted_when` = '".time()."',"
. " `posted_by` = '".$admin->get_user_id()."'"
. " WHERE `post_id` = '$post_id'"
);
// when no error has occurred go ahead and update the image descriptions
if (!($database->is_error())) {
//update Bildbeschreibungen der tabelle mod_news_img_img
$images = mod_nwi_img_get_by_post($post_id,false);
if (count($images) > 0) {
foreach ($images as $row) {
$row_id = $row['id'];
$picdesc = isset($_POST['picdesc'][$row_id])
? mod_nwi_escapeString(strip_tags($_POST['picdesc'][$row_id]))
: '';
$database->query("UPDATE `".TABLE_PREFIX."mod_news_img_img` SET `picdesc` = '$picdesc' WHERE id = '$row_id'");
}
}
}
$pageQuery = "SELECT * from `".TABLE_PREFIX."sections` WHERE `section_id`=".$section_id;
$query_page = $database->query($pageQuery);
if ($query_page->numRows() > 0) {
$page = $query_page->fetchRow();
}
if (!isset($active) || $active != 1) { $active=0; }
if ($publishedwhen != 0 && $publishedwhen > time()) {$active = 0;}
if ($publisheduntil != 0 && $publisheduntil < time()) {$active = 0;}
if ($active != 1 ) {
if(is_writable(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION)) {
unlink(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION);
}
} else{
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
mod_nwi_create_file($filename, '', $post_id, $section_id, $page['page_id']);
}
// if this went fine so far and we are moving posts across section borders we still have to reorder
if ((!($database->is_error()))&&($old_section_id!=$section_id)) {
// Clean up ordering
$order = new order(TABLE_PREFIX.'mod_news_img_posts', 'position', 'post_id', 'section_id');
$order->clean($old_section_id);
}
// remove current tags
$database->query(sprintf(
"DELETE FROM `%smod_news_img_tags_posts` WHERE `post_id`=$post_id",
TABLE_PREFIX
));
// re-add marked tags
if (is_array($tags) && count($tags)>0) {
$existing = mod_nwi_get_tags($section_id);
foreach (array_values($tags) as $t) {
$t = intval($t);
if (array_key_exists($t, $existing)) {
$database->query(sprintf(
"INSERT IGNORE INTO `%smod_news_img_tags_posts` VALUES('$post_id','$t')",
TABLE_PREFIX
));
}
}
}
// Check result
if ($database->is_error()) {
$post_id_key = $admin->getIDKEY($id);
if (defined('WB_VERSION') && (version_compare(WB_VERSION, '2.8.3', '>'))) {
$post_id_key = $id;
}
$admin->print_error($database->get_error(), WB_URL.'/modules/news_img/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$post_id_key);
} else {
if ($imageErrorMessage!='') {
$post_id_key = $admin->getIDKEY($id);
if (defined('WB_VERSION') && (version_compare(WB_VERSION, '2.8.3', '>'))) {
$post_id_key = $id;
}
$admin->print_error($MOD_NEWS_IMG['GENERIC_IMAGE_ERROR'].'<br />'.$imageErrorMessage, WB_URL.'/modules/news_img/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$post_id_key);
} else {
if (isset($_POST['savegoback']) && $_POST['savegoback']=='1') {
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
} else {
$post_id_key = $admin->getIDKEY($id);
if (defined('WB_VERSION') && (version_compare(WB_VERSION, '2.8.3', '>'))) {
$post_id_key = $id;
}
$admin->print_success($TEXT['SUCCESS'], WB_URL.'/modules/news_img/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$post_id_key);
}
}
}
// Print admin footer
$admin->print_footer();