1 | <?php
|
---|
2 | /**
|
---|
3 | *
|
---|
4 | * @package phpBB3
|
---|
5 | * @version $Id: functions_posting.php 9166 2008-12-03 16:40:53Z acydburn $
|
---|
6 | * @copyright (c) 2005 phpBB Group
|
---|
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * @ignore
|
---|
13 | */
|
---|
14 | if (!defined('IN_PHPBB'))
|
---|
15 | {
|
---|
16 | exit;
|
---|
17 | }
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Fill smiley templates (or just the variables) with smilies, either in a window or inline
|
---|
21 | */
|
---|
22 | function generate_smilies($mode, $forum_id)
|
---|
23 | {
|
---|
24 | global $auth, $db, $user, $config, $template;
|
---|
25 | global $phpEx, $phpbb_root_path;
|
---|
26 |
|
---|
27 | if ($mode == 'window')
|
---|
28 | {
|
---|
29 | if ($forum_id)
|
---|
30 | {
|
---|
31 | $sql = 'SELECT forum_style
|
---|
32 | FROM ' . FORUMS_TABLE . "
|
---|
33 | WHERE forum_id = $forum_id";
|
---|
34 | $result = $db->sql_query_limit($sql, 1);
|
---|
35 | $row = $db->sql_fetchrow($result);
|
---|
36 | $db->sql_freeresult($result);
|
---|
37 |
|
---|
38 | $user->setup('posting', (int) $row['forum_style']);
|
---|
39 | }
|
---|
40 | else
|
---|
41 | {
|
---|
42 | $user->setup('posting');
|
---|
43 | }
|
---|
44 |
|
---|
45 | page_header($user->lang['SMILIES']);
|
---|
46 |
|
---|
47 | $template->set_filenames(array(
|
---|
48 | 'body' => 'posting_smilies.html')
|
---|
49 | );
|
---|
50 | }
|
---|
51 |
|
---|
52 | $display_link = false;
|
---|
53 | if ($mode == 'inline')
|
---|
54 | {
|
---|
55 | $sql = 'SELECT smiley_id
|
---|
56 | FROM ' . SMILIES_TABLE . '
|
---|
57 | WHERE display_on_posting = 0';
|
---|
58 | $result = $db->sql_query_limit($sql, 1, 0, 3600);
|
---|
59 |
|
---|
60 | if ($row = $db->sql_fetchrow($result))
|
---|
61 | {
|
---|
62 | $display_link = true;
|
---|
63 | }
|
---|
64 | $db->sql_freeresult($result);
|
---|
65 | }
|
---|
66 |
|
---|
67 | $last_url = '';
|
---|
68 |
|
---|
69 | $sql = 'SELECT *
|
---|
70 | FROM ' . SMILIES_TABLE .
|
---|
71 | (($mode == 'inline') ? ' WHERE display_on_posting = 1 ' : '') . '
|
---|
72 | ORDER BY smiley_order';
|
---|
73 | $result = $db->sql_query($sql, 3600);
|
---|
74 |
|
---|
75 | $smilies = array();
|
---|
76 | while ($row = $db->sql_fetchrow($result))
|
---|
77 | {
|
---|
78 | if (empty($smilies[$row['smiley_url']]))
|
---|
79 | {
|
---|
80 | $smilies[$row['smiley_url']] = $row;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | $db->sql_freeresult($result);
|
---|
84 |
|
---|
85 | if (sizeof($smilies))
|
---|
86 | {
|
---|
87 | foreach ($smilies as $row)
|
---|
88 | {
|
---|
89 | $template->assign_block_vars('smiley', array(
|
---|
90 | 'SMILEY_CODE' => $row['code'],
|
---|
91 | 'A_SMILEY_CODE' => addslashes($row['code']),
|
---|
92 | 'SMILEY_IMG' => $phpbb_root_path . $config['smilies_path'] . '/' . $row['smiley_url'],
|
---|
93 | 'SMILEY_WIDTH' => $row['smiley_width'],
|
---|
94 | 'SMILEY_HEIGHT' => $row['smiley_height'],
|
---|
95 | 'SMILEY_DESC' => $row['emotion'])
|
---|
96 | );
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | if ($mode == 'inline' && $display_link)
|
---|
101 | {
|
---|
102 | $template->assign_vars(array(
|
---|
103 | 'S_SHOW_SMILEY_LINK' => true,
|
---|
104 | 'U_MORE_SMILIES' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id))
|
---|
105 | );
|
---|
106 | }
|
---|
107 |
|
---|
108 | if ($mode == 'window')
|
---|
109 | {
|
---|
110 | page_footer();
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Update last post information
|
---|
116 | * Should be used instead of sync() if only the last post information are out of sync... faster
|
---|
117 | *
|
---|
118 | * @param string $type Can be forum|topic
|
---|
119 | * @param mixed $ids topic/forum ids
|
---|
120 | * @param bool $return_update_sql true: SQL query shall be returned, false: execute SQL
|
---|
121 | */
|
---|
122 | function update_post_information($type, $ids, $return_update_sql = false)
|
---|
123 | {
|
---|
124 | global $db;
|
---|
125 |
|
---|
126 | if (empty($ids))
|
---|
127 | {
|
---|
128 | return;
|
---|
129 | }
|
---|
130 | if (!is_array($ids))
|
---|
131 | {
|
---|
132 | $ids = array($ids);
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | $update_sql = $empty_forums = $not_empty_forums = array();
|
---|
137 |
|
---|
138 | if ($type != 'topic')
|
---|
139 | {
|
---|
140 | $topic_join = ', ' . TOPICS_TABLE . ' t';
|
---|
141 | $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1';
|
---|
142 | }
|
---|
143 | else
|
---|
144 | {
|
---|
145 | $topic_join = '';
|
---|
146 | $topic_condition = '';
|
---|
147 | }
|
---|
148 |
|
---|
149 | if (sizeof($ids) == 1)
|
---|
150 | {
|
---|
151 | $sql = 'SELECT MAX(p.post_id) as last_post_id
|
---|
152 | FROM ' . POSTS_TABLE . " p $topic_join
|
---|
153 | WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . "
|
---|
154 | $topic_condition
|
---|
155 | AND p.post_approved = 1";
|
---|
156 | }
|
---|
157 | else
|
---|
158 | {
|
---|
159 | $sql = 'SELECT p.' . $type . '_id, MAX(p.post_id) as last_post_id
|
---|
160 | FROM ' . POSTS_TABLE . " p $topic_join
|
---|
161 | WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . "
|
---|
162 | $topic_condition
|
---|
163 | AND p.post_approved = 1
|
---|
164 | GROUP BY p.{$type}_id";
|
---|
165 | }
|
---|
166 | $result = $db->sql_query($sql);
|
---|
167 |
|
---|
168 | $last_post_ids = array();
|
---|
169 | while ($row = $db->sql_fetchrow($result))
|
---|
170 | {
|
---|
171 | if (sizeof($ids) == 1)
|
---|
172 | {
|
---|
173 | $row[$type . '_id'] = $ids[0];
|
---|
174 | }
|
---|
175 |
|
---|
176 | if ($type == 'forum')
|
---|
177 | {
|
---|
178 | $not_empty_forums[] = $row['forum_id'];
|
---|
179 |
|
---|
180 | if (empty($row['last_post_id']))
|
---|
181 | {
|
---|
182 | $empty_forums[] = $row['forum_id'];
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | $last_post_ids[] = $row['last_post_id'];
|
---|
187 | }
|
---|
188 | $db->sql_freeresult($result);
|
---|
189 |
|
---|
190 | if ($type == 'forum')
|
---|
191 | {
|
---|
192 | $empty_forums = array_merge($empty_forums, array_diff($ids, $not_empty_forums));
|
---|
193 |
|
---|
194 | foreach ($empty_forums as $void => $forum_id)
|
---|
195 | {
|
---|
196 | $update_sql[$forum_id][] = 'forum_last_post_id = 0';
|
---|
197 | $update_sql[$forum_id][] = "forum_last_post_subject = ''";
|
---|
198 | $update_sql[$forum_id][] = 'forum_last_post_time = 0';
|
---|
199 | $update_sql[$forum_id][] = 'forum_last_poster_id = 0';
|
---|
200 | $update_sql[$forum_id][] = "forum_last_poster_name = ''";
|
---|
201 | $update_sql[$forum_id][] = "forum_last_poster_colour = ''";
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | if (sizeof($last_post_ids))
|
---|
206 | {
|
---|
207 | $sql = 'SELECT p.' . $type . '_id, p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
|
---|
208 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
209 | WHERE p.poster_id = u.user_id
|
---|
210 | AND ' . $db->sql_in_set('p.post_id', $last_post_ids);
|
---|
211 | $result = $db->sql_query($sql);
|
---|
212 |
|
---|
213 | while ($row = $db->sql_fetchrow($result))
|
---|
214 | {
|
---|
215 | $update_sql[$row["{$type}_id"]][] = $type . '_last_post_id = ' . (int) $row['post_id'];
|
---|
216 | $update_sql[$row["{$type}_id"]][] = "{$type}_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
|
---|
217 | $update_sql[$row["{$type}_id"]][] = $type . '_last_post_time = ' . (int) $row['post_time'];
|
---|
218 | $update_sql[$row["{$type}_id"]][] = $type . '_last_poster_id = ' . (int) $row['poster_id'];
|
---|
219 | $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
|
---|
220 | $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'";
|
---|
221 | }
|
---|
222 | $db->sql_freeresult($result);
|
---|
223 | }
|
---|
224 | unset($empty_forums, $ids, $last_post_ids);
|
---|
225 |
|
---|
226 | if ($return_update_sql || !sizeof($update_sql))
|
---|
227 | {
|
---|
228 | return $update_sql;
|
---|
229 | }
|
---|
230 |
|
---|
231 | $table = ($type == 'forum') ? FORUMS_TABLE : TOPICS_TABLE;
|
---|
232 |
|
---|
233 | foreach ($update_sql as $update_id => $update_sql_ary)
|
---|
234 | {
|
---|
235 | $sql = "UPDATE $table
|
---|
236 | SET " . implode(', ', $update_sql_ary) . "
|
---|
237 | WHERE {$type}_id = $update_id";
|
---|
238 | $db->sql_query($sql);
|
---|
239 | }
|
---|
240 |
|
---|
241 | return;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Generate Topic Icons for display
|
---|
246 | */
|
---|
247 | function posting_gen_topic_icons($mode, $icon_id)
|
---|
248 | {
|
---|
249 | global $phpbb_root_path, $config, $template, $cache;
|
---|
250 |
|
---|
251 | // Grab icons
|
---|
252 | $icons = $cache->obtain_icons();
|
---|
253 |
|
---|
254 | if (!$icon_id)
|
---|
255 | {
|
---|
256 | $template->assign_var('S_NO_ICON_CHECKED', ' checked="checked"');
|
---|
257 | }
|
---|
258 |
|
---|
259 | if (sizeof($icons))
|
---|
260 | {
|
---|
261 | foreach ($icons as $id => $data)
|
---|
262 | {
|
---|
263 | if ($data['display'])
|
---|
264 | {
|
---|
265 | $template->assign_block_vars('topic_icon', array(
|
---|
266 | 'ICON_ID' => $id,
|
---|
267 | 'ICON_IMG' => $phpbb_root_path . $config['icons_path'] . '/' . $data['img'],
|
---|
268 | 'ICON_WIDTH' => $data['width'],
|
---|
269 | 'ICON_HEIGHT' => $data['height'],
|
---|
270 |
|
---|
271 | 'S_CHECKED' => ($id == $icon_id) ? true : false,
|
---|
272 | 'S_ICON_CHECKED' => ($id == $icon_id) ? ' checked="checked"' : '')
|
---|
273 | );
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | return true;
|
---|
278 | }
|
---|
279 |
|
---|
280 | return false;
|
---|
281 | }
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Build topic types able to be selected
|
---|
285 | */
|
---|
286 | function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)
|
---|
287 | {
|
---|
288 | global $auth, $user, $template, $topic_type;
|
---|
289 |
|
---|
290 | $toggle = false;
|
---|
291 |
|
---|
292 | $topic_types = array(
|
---|
293 | 'sticky' => array('const' => POST_STICKY, 'lang' => 'POST_STICKY'),
|
---|
294 | 'announce' => array('const' => POST_ANNOUNCE, 'lang' => 'POST_ANNOUNCEMENT'),
|
---|
295 | 'global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL')
|
---|
296 | );
|
---|
297 |
|
---|
298 | $topic_type_array = array();
|
---|
299 |
|
---|
300 | foreach ($topic_types as $auth_key => $topic_value)
|
---|
301 | {
|
---|
302 | // We do not have a special post global announcement permission
|
---|
303 | $auth_key = ($auth_key == 'global') ? 'announce' : $auth_key;
|
---|
304 |
|
---|
305 | if ($auth->acl_get('f_' . $auth_key, $forum_id))
|
---|
306 | {
|
---|
307 | $toggle = true;
|
---|
308 |
|
---|
309 | $topic_type_array[] = array(
|
---|
310 | 'VALUE' => $topic_value['const'],
|
---|
311 | 'S_CHECKED' => ($cur_topic_type == $topic_value['const'] || ($forum_id == 0 && $topic_value['const'] == POST_GLOBAL)) ? ' checked="checked"' : '',
|
---|
312 | 'L_TOPIC_TYPE' => $user->lang[$topic_value['lang']]
|
---|
313 | );
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | if ($toggle)
|
---|
318 | {
|
---|
319 | $topic_type_array = array_merge(array(0 => array(
|
---|
320 | 'VALUE' => POST_NORMAL,
|
---|
321 | 'S_CHECKED' => ($topic_type == POST_NORMAL) ? ' checked="checked"' : '',
|
---|
322 | 'L_TOPIC_TYPE' => $user->lang['POST_NORMAL'])),
|
---|
323 |
|
---|
324 | $topic_type_array
|
---|
325 | );
|
---|
326 |
|
---|
327 | foreach ($topic_type_array as $array)
|
---|
328 | {
|
---|
329 | $template->assign_block_vars('topic_type', $array);
|
---|
330 | }
|
---|
331 |
|
---|
332 | $template->assign_vars(array(
|
---|
333 | 'S_TOPIC_TYPE_STICKY' => ($auth->acl_get('f_sticky', $forum_id)),
|
---|
334 | 'S_TOPIC_TYPE_ANNOUNCE' => ($auth->acl_get('f_announce', $forum_id)))
|
---|
335 | );
|
---|
336 | }
|
---|
337 |
|
---|
338 | return $toggle;
|
---|
339 | }
|
---|
340 |
|
---|
341 | //
|
---|
342 | // Attachment related functions
|
---|
343 | //
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * Upload Attachment - filedata is generated here
|
---|
347 | * Uses upload class
|
---|
348 | */
|
---|
349 | function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false)
|
---|
350 | {
|
---|
351 | global $auth, $user, $config, $db, $cache;
|
---|
352 | global $phpbb_root_path, $phpEx;
|
---|
353 |
|
---|
354 | $filedata = array(
|
---|
355 | 'error' => array()
|
---|
356 | );
|
---|
357 |
|
---|
358 | include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
|
---|
359 | $upload = new fileupload();
|
---|
360 |
|
---|
361 | if ($config['check_attachment_content'])
|
---|
362 | {
|
---|
363 | $upload->set_disallowed_content(explode('|', $config['mime_triggers']));
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (!$local)
|
---|
367 | {
|
---|
368 | $filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false;
|
---|
369 | }
|
---|
370 | else
|
---|
371 | {
|
---|
372 | $filedata['post_attach'] = true;
|
---|
373 | }
|
---|
374 |
|
---|
375 | if (!$filedata['post_attach'])
|
---|
376 | {
|
---|
377 | $filedata['error'][] = $user->lang['NO_UPLOAD_FORM_FOUND'];
|
---|
378 | return $filedata;
|
---|
379 | }
|
---|
380 |
|
---|
381 | $extensions = $cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id));
|
---|
382 | $upload->set_allowed_extensions(array_keys($extensions['_allowed_']));
|
---|
383 |
|
---|
384 | $file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name);
|
---|
385 |
|
---|
386 | if ($file->init_error)
|
---|
387 | {
|
---|
388 | $filedata['post_attach'] = false;
|
---|
389 | return $filedata;
|
---|
390 | }
|
---|
391 |
|
---|
392 | $cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE;
|
---|
393 |
|
---|
394 | // Make sure the image category only holds valid images...
|
---|
395 | if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image())
|
---|
396 | {
|
---|
397 | $file->remove();
|
---|
398 |
|
---|
399 | // If this error occurs a user tried to exploit an IE Bug by renaming extensions
|
---|
400 | // Since the image category is displaying content inline we need to catch this.
|
---|
401 | trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);
|
---|
402 | }
|
---|
403 |
|
---|
404 | // Do we have to create a thumbnail?
|
---|
405 | $filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0;
|
---|
406 |
|
---|
407 | // Check Image Size, if it is an image
|
---|
408 | if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id) && $cat_id == ATTACHMENT_CATEGORY_IMAGE)
|
---|
409 | {
|
---|
410 | $file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
|
---|
411 | }
|
---|
412 |
|
---|
413 | // Admins and mods are allowed to exceed the allowed filesize
|
---|
414 | if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id))
|
---|
415 | {
|
---|
416 | if (!empty($extensions[$file->get('extension')]['max_filesize']))
|
---|
417 | {
|
---|
418 | $allowed_filesize = $extensions[$file->get('extension')]['max_filesize'];
|
---|
419 | }
|
---|
420 | else
|
---|
421 | {
|
---|
422 | $allowed_filesize = ($is_message) ? $config['max_filesize_pm'] : $config['max_filesize'];
|
---|
423 | }
|
---|
424 |
|
---|
425 | $file->upload->set_max_filesize($allowed_filesize);
|
---|
426 | }
|
---|
427 |
|
---|
428 | $file->clean_filename('unique', $user->data['user_id'] . '_');
|
---|
429 |
|
---|
430 | // Are we uploading an image *and* this image being within the image category? Only then perform additional image checks.
|
---|
431 | $no_image = ($cat_id == ATTACHMENT_CATEGORY_IMAGE) ? false : true;
|
---|
432 |
|
---|
433 | $file->move_file($config['upload_path'], false, $no_image);
|
---|
434 |
|
---|
435 | if (sizeof($file->error))
|
---|
436 | {
|
---|
437 | $file->remove();
|
---|
438 | $filedata['error'] = array_merge($filedata['error'], $file->error);
|
---|
439 | $filedata['post_attach'] = false;
|
---|
440 |
|
---|
441 | return $filedata;
|
---|
442 | }
|
---|
443 |
|
---|
444 | $filedata['filesize'] = $file->get('filesize');
|
---|
445 | $filedata['mimetype'] = $file->get('mimetype');
|
---|
446 | $filedata['extension'] = $file->get('extension');
|
---|
447 | $filedata['physical_filename'] = $file->get('realname');
|
---|
448 | $filedata['real_filename'] = $file->get('uploadname');
|
---|
449 | $filedata['filetime'] = time();
|
---|
450 |
|
---|
451 | // Check our complete quota
|
---|
452 | if ($config['attachment_quota'])
|
---|
453 | {
|
---|
454 | if ($config['upload_dir_size'] + $file->get('filesize') > $config['attachment_quota'])
|
---|
455 | {
|
---|
456 | $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
|
---|
457 | $filedata['post_attach'] = false;
|
---|
458 |
|
---|
459 | $file->remove();
|
---|
460 |
|
---|
461 | return $filedata;
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 | // Check free disk space
|
---|
466 | if ($free_space = @disk_free_space($phpbb_root_path . $config['upload_path']))
|
---|
467 | {
|
---|
468 | if ($free_space <= $file->get('filesize'))
|
---|
469 | {
|
---|
470 | $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
|
---|
471 | $filedata['post_attach'] = false;
|
---|
472 |
|
---|
473 | $file->remove();
|
---|
474 |
|
---|
475 | return $filedata;
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 | // Create Thumbnail
|
---|
480 | if ($filedata['thumbnail'])
|
---|
481 | {
|
---|
482 | $source = $file->get('destination_file');
|
---|
483 | $destination = $file->get('destination_path') . '/thumb_' . $file->get('realname');
|
---|
484 |
|
---|
485 | if (!create_thumbnail($source, $destination, $file->get('mimetype')))
|
---|
486 | {
|
---|
487 | $filedata['thumbnail'] = 0;
|
---|
488 | }
|
---|
489 | }
|
---|
490 |
|
---|
491 | return $filedata;
|
---|
492 | }
|
---|
493 |
|
---|
494 | /**
|
---|
495 | * Calculate the needed size for Thumbnail
|
---|
496 | */
|
---|
497 | function get_img_size_format($width, $height)
|
---|
498 | {
|
---|
499 | global $config;
|
---|
500 |
|
---|
501 | // Maximum Width the Image can take
|
---|
502 | $max_width = ($config['img_max_thumb_width']) ? $config['img_max_thumb_width'] : 400;
|
---|
503 |
|
---|
504 | if ($width > $height)
|
---|
505 | {
|
---|
506 | return array(
|
---|
507 | round($width * ($max_width / $width)),
|
---|
508 | round($height * ($max_width / $width))
|
---|
509 | );
|
---|
510 | }
|
---|
511 | else
|
---|
512 | {
|
---|
513 | return array(
|
---|
514 | round($width * ($max_width / $height)),
|
---|
515 | round($height * ($max_width / $height))
|
---|
516 | );
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | /**
|
---|
521 | * Return supported image types
|
---|
522 | */
|
---|
523 | function get_supported_image_types($type = false)
|
---|
524 | {
|
---|
525 | if (@extension_loaded('gd'))
|
---|
526 | {
|
---|
527 | $format = imagetypes();
|
---|
528 | $new_type = 0;
|
---|
529 |
|
---|
530 | if ($type !== false)
|
---|
531 | {
|
---|
532 | // Type is one of the IMAGETYPE constants - it is fetched from getimagesize()
|
---|
533 | // We do not use the constants here, because some were not available in PHP 4.3.x
|
---|
534 | switch ($type)
|
---|
535 | {
|
---|
536 | // GIF
|
---|
537 | case 1:
|
---|
538 | $new_type = ($format & IMG_GIF) ? IMG_GIF : false;
|
---|
539 | break;
|
---|
540 |
|
---|
541 | // JPG, JPC, JP2
|
---|
542 | case 2:
|
---|
543 | case 9:
|
---|
544 | case 10:
|
---|
545 | case 11:
|
---|
546 | case 12:
|
---|
547 | $new_type = ($format & IMG_JPG) ? IMG_JPG : false;
|
---|
548 | break;
|
---|
549 |
|
---|
550 | // PNG
|
---|
551 | case 3:
|
---|
552 | $new_type = ($format & IMG_PNG) ? IMG_PNG : false;
|
---|
553 | break;
|
---|
554 |
|
---|
555 | // WBMP
|
---|
556 | case 15:
|
---|
557 | $new_type = ($format & IMG_WBMP) ? IMG_WBMP : false;
|
---|
558 | break;
|
---|
559 | }
|
---|
560 | }
|
---|
561 | else
|
---|
562 | {
|
---|
563 | $new_type = array();
|
---|
564 | $go_through_types = array(IMG_GIF, IMG_JPG, IMG_PNG, IMG_WBMP);
|
---|
565 |
|
---|
566 | foreach ($go_through_types as $check_type)
|
---|
567 | {
|
---|
568 | if ($format & $check_type)
|
---|
569 | {
|
---|
570 | $new_type[] = $check_type;
|
---|
571 | }
|
---|
572 | }
|
---|
573 | }
|
---|
574 |
|
---|
575 | return array(
|
---|
576 | 'gd' => ($new_type) ? true : false,
|
---|
577 | 'format' => $new_type,
|
---|
578 | 'version' => (function_exists('imagecreatetruecolor')) ? 2 : 1
|
---|
579 | );
|
---|
580 | }
|
---|
581 |
|
---|
582 | return array('gd' => false);
|
---|
583 | }
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * Create Thumbnail
|
---|
587 | */
|
---|
588 | function create_thumbnail($source, $destination, $mimetype)
|
---|
589 | {
|
---|
590 | global $config;
|
---|
591 |
|
---|
592 | $min_filesize = (int) $config['img_min_thumb_filesize'];
|
---|
593 | $img_filesize = (file_exists($source)) ? @filesize($source) : false;
|
---|
594 |
|
---|
595 | if (!$img_filesize || $img_filesize <= $min_filesize)
|
---|
596 | {
|
---|
597 | return false;
|
---|
598 | }
|
---|
599 |
|
---|
600 | $dimension = @getimagesize($source);
|
---|
601 |
|
---|
602 | if ($dimension === false)
|
---|
603 | {
|
---|
604 | return false;
|
---|
605 | }
|
---|
606 |
|
---|
607 | list($width, $height, $type, ) = $dimension;
|
---|
608 |
|
---|
609 | if (empty($width) || empty($height))
|
---|
610 | {
|
---|
611 | return false;
|
---|
612 | }
|
---|
613 |
|
---|
614 | list($new_width, $new_height) = get_img_size_format($width, $height);
|
---|
615 |
|
---|
616 | // Do not create a thumbnail if the resulting width/height is bigger than the original one
|
---|
617 | if ($new_width > $width && $new_height > $height)
|
---|
618 | {
|
---|
619 | return false;
|
---|
620 | }
|
---|
621 |
|
---|
622 | $used_imagick = false;
|
---|
623 |
|
---|
624 | // Only use imagemagick if defined and the passthru function not disabled
|
---|
625 | if ($config['img_imagick'] && function_exists('passthru'))
|
---|
626 | {
|
---|
627 | if (substr($config['img_imagick'], -1) !== '/')
|
---|
628 | {
|
---|
629 | $config['img_imagick'] .= '/';
|
---|
630 | }
|
---|
631 |
|
---|
632 | @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');
|
---|
633 |
|
---|
634 | if (file_exists($destination))
|
---|
635 | {
|
---|
636 | $used_imagick = true;
|
---|
637 | }
|
---|
638 | }
|
---|
639 |
|
---|
640 | if (!$used_imagick)
|
---|
641 | {
|
---|
642 | $type = get_supported_image_types($type);
|
---|
643 |
|
---|
644 | if ($type['gd'])
|
---|
645 | {
|
---|
646 | // If the type is not supported, we are not able to create a thumbnail
|
---|
647 | if ($type['format'] === false)
|
---|
648 | {
|
---|
649 | return false;
|
---|
650 | }
|
---|
651 |
|
---|
652 | switch ($type['format'])
|
---|
653 | {
|
---|
654 | case IMG_GIF:
|
---|
655 | $image = @imagecreatefromgif($source);
|
---|
656 | break;
|
---|
657 |
|
---|
658 | case IMG_JPG:
|
---|
659 | $image = @imagecreatefromjpeg($source);
|
---|
660 | break;
|
---|
661 |
|
---|
662 | case IMG_PNG:
|
---|
663 | $image = @imagecreatefrompng($source);
|
---|
664 | break;
|
---|
665 |
|
---|
666 | case IMG_WBMP:
|
---|
667 | $image = @imagecreatefromwbmp($source);
|
---|
668 | break;
|
---|
669 | }
|
---|
670 |
|
---|
671 | if ($type['version'] == 1)
|
---|
672 | {
|
---|
673 | $new_image = imagecreate($new_width, $new_height);
|
---|
674 |
|
---|
675 | if ($new_image === false)
|
---|
676 | {
|
---|
677 | return false;
|
---|
678 | }
|
---|
679 |
|
---|
680 | imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
---|
681 | }
|
---|
682 | else
|
---|
683 | {
|
---|
684 | $new_image = imagecreatetruecolor($new_width, $new_height);
|
---|
685 |
|
---|
686 | if ($new_image === false)
|
---|
687 | {
|
---|
688 | return false;
|
---|
689 | }
|
---|
690 |
|
---|
691 | // Preserve alpha transparency (png for example)
|
---|
692 | @imagealphablending($new_image, false);
|
---|
693 | @imagesavealpha($new_image, true);
|
---|
694 |
|
---|
695 | imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
---|
696 | }
|
---|
697 |
|
---|
698 | // If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
|
---|
699 | if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on')
|
---|
700 | {
|
---|
701 | @touch($destination);
|
---|
702 | }
|
---|
703 |
|
---|
704 | switch ($type['format'])
|
---|
705 | {
|
---|
706 | case IMG_GIF:
|
---|
707 | imagegif($new_image, $destination);
|
---|
708 | break;
|
---|
709 |
|
---|
710 | case IMG_JPG:
|
---|
711 | imagejpeg($new_image, $destination, 90);
|
---|
712 | break;
|
---|
713 |
|
---|
714 | case IMG_PNG:
|
---|
715 | imagepng($new_image, $destination);
|
---|
716 | break;
|
---|
717 |
|
---|
718 | case IMG_WBMP:
|
---|
719 | imagewbmp($new_image, $destination);
|
---|
720 | break;
|
---|
721 | }
|
---|
722 |
|
---|
723 | imagedestroy($new_image);
|
---|
724 | }
|
---|
725 | else
|
---|
726 | {
|
---|
727 | return false;
|
---|
728 | }
|
---|
729 | }
|
---|
730 |
|
---|
731 | if (!file_exists($destination))
|
---|
732 | {
|
---|
733 | return false;
|
---|
734 | }
|
---|
735 |
|
---|
736 | phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);
|
---|
737 |
|
---|
738 | return true;
|
---|
739 | }
|
---|
740 |
|
---|
741 | /**
|
---|
742 | * Assign Inline attachments (build option fields)
|
---|
743 | */
|
---|
744 | function posting_gen_inline_attachments(&$attachment_data)
|
---|
745 | {
|
---|
746 | global $template;
|
---|
747 |
|
---|
748 | if (sizeof($attachment_data))
|
---|
749 | {
|
---|
750 | $s_inline_attachment_options = '';
|
---|
751 |
|
---|
752 | foreach ($attachment_data as $i => $attachment)
|
---|
753 | {
|
---|
754 | $s_inline_attachment_options .= '<option value="' . $i . '">' . basename($attachment['real_filename']) . '</option>';
|
---|
755 | }
|
---|
756 |
|
---|
757 | $template->assign_var('S_INLINE_ATTACHMENT_OPTIONS', $s_inline_attachment_options);
|
---|
758 |
|
---|
759 | return true;
|
---|
760 | }
|
---|
761 |
|
---|
762 | return false;
|
---|
763 | }
|
---|
764 |
|
---|
765 | /**
|
---|
766 | * Generate inline attachment entry
|
---|
767 | */
|
---|
768 | function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true)
|
---|
769 | {
|
---|
770 | global $template, $config, $phpbb_root_path, $phpEx, $user, $auth;
|
---|
771 |
|
---|
772 | // Some default template variables
|
---|
773 | $template->assign_vars(array(
|
---|
774 | 'S_SHOW_ATTACH_BOX' => $show_attach_box,
|
---|
775 | 'S_HAS_ATTACHMENTS' => sizeof($attachment_data),
|
---|
776 | 'FILESIZE' => $config['max_filesize'],
|
---|
777 | 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '',
|
---|
778 | ));
|
---|
779 |
|
---|
780 | if (sizeof($attachment_data))
|
---|
781 | {
|
---|
782 | // We display the posted attachments within the desired order.
|
---|
783 | ($config['display_order']) ? krsort($attachment_data) : ksort($attachment_data);
|
---|
784 |
|
---|
785 | foreach ($attachment_data as $count => $attach_row)
|
---|
786 | {
|
---|
787 | $hidden = '';
|
---|
788 | $attach_row['real_filename'] = basename($attach_row['real_filename']);
|
---|
789 |
|
---|
790 | foreach ($attach_row as $key => $value)
|
---|
791 | {
|
---|
792 | $hidden .= '<input type="hidden" name="attachment_data[' . $count . '][' . $key . ']" value="' . $value . '" />';
|
---|
793 | }
|
---|
794 |
|
---|
795 | $download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&id=' . (int) $attach_row['attach_id'], true, ($attach_row['is_orphan']) ? $user->session_id : false);
|
---|
796 |
|
---|
797 | $template->assign_block_vars('attach_row', array(
|
---|
798 | 'FILENAME' => basename($attach_row['real_filename']),
|
---|
799 | 'A_FILENAME' => addslashes(basename($attach_row['real_filename'])),
|
---|
800 | 'FILE_COMMENT' => $attach_row['attach_comment'],
|
---|
801 | 'ATTACH_ID' => $attach_row['attach_id'],
|
---|
802 | 'S_IS_ORPHAN' => $attach_row['is_orphan'],
|
---|
803 | 'ASSOC_INDEX' => $count,
|
---|
804 |
|
---|
805 | 'U_VIEW_ATTACHMENT' => $download_link,
|
---|
806 | 'S_HIDDEN' => $hidden)
|
---|
807 | );
|
---|
808 | }
|
---|
809 | }
|
---|
810 |
|
---|
811 | return sizeof($attachment_data);
|
---|
812 | }
|
---|
813 |
|
---|
814 | //
|
---|
815 | // General Post functions
|
---|
816 | //
|
---|
817 |
|
---|
818 | /**
|
---|
819 | * Load Drafts
|
---|
820 | */
|
---|
821 | function load_drafts($topic_id = 0, $forum_id = 0, $id = 0)
|
---|
822 | {
|
---|
823 | global $user, $db, $template, $auth;
|
---|
824 | global $phpbb_root_path, $phpEx;
|
---|
825 |
|
---|
826 | $topic_ids = $forum_ids = $draft_rows = array();
|
---|
827 |
|
---|
828 | // Load those drafts not connected to forums/topics
|
---|
829 | // If forum_id == 0 AND topic_id == 0 then this is a PM draft
|
---|
830 | if (!$topic_id && !$forum_id)
|
---|
831 | {
|
---|
832 | $sql_and = ' AND d.forum_id = 0 AND d.topic_id = 0';
|
---|
833 | }
|
---|
834 | else
|
---|
835 | {
|
---|
836 | $sql_and = '';
|
---|
837 | $sql_and .= ($forum_id) ? ' AND d.forum_id = ' . (int) $forum_id : '';
|
---|
838 | $sql_and .= ($topic_id) ? ' AND d.topic_id = ' . (int) $topic_id : '';
|
---|
839 | }
|
---|
840 |
|
---|
841 | $sql = 'SELECT d.*, f.forum_id, f.forum_name
|
---|
842 | FROM ' . DRAFTS_TABLE . ' d
|
---|
843 | LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = d.forum_id)
|
---|
844 | WHERE d.user_id = ' . $user->data['user_id'] . "
|
---|
845 | $sql_and
|
---|
846 | ORDER BY d.save_time DESC";
|
---|
847 | $result = $db->sql_query($sql);
|
---|
848 |
|
---|
849 | while ($row = $db->sql_fetchrow($result))
|
---|
850 | {
|
---|
851 | if ($row['topic_id'])
|
---|
852 | {
|
---|
853 | $topic_ids[] = (int) $row['topic_id'];
|
---|
854 | }
|
---|
855 | $draft_rows[] = $row;
|
---|
856 | }
|
---|
857 | $db->sql_freeresult($result);
|
---|
858 |
|
---|
859 | if (!sizeof($draft_rows))
|
---|
860 | {
|
---|
861 | return;
|
---|
862 | }
|
---|
863 |
|
---|
864 | $topic_rows = array();
|
---|
865 | if (sizeof($topic_ids))
|
---|
866 | {
|
---|
867 | $sql = 'SELECT topic_id, forum_id, topic_title
|
---|
868 | FROM ' . TOPICS_TABLE . '
|
---|
869 | WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
|
---|
870 | $result = $db->sql_query($sql);
|
---|
871 |
|
---|
872 | while ($row = $db->sql_fetchrow($result))
|
---|
873 | {
|
---|
874 | $topic_rows[$row['topic_id']] = $row;
|
---|
875 | }
|
---|
876 | $db->sql_freeresult($result);
|
---|
877 | }
|
---|
878 | unset($topic_ids);
|
---|
879 |
|
---|
880 | $template->assign_var('S_SHOW_DRAFTS', true);
|
---|
881 |
|
---|
882 | foreach ($draft_rows as $draft)
|
---|
883 | {
|
---|
884 | $link_topic = $link_forum = $link_pm = false;
|
---|
885 | $insert_url = $view_url = $title = '';
|
---|
886 |
|
---|
887 | if (isset($topic_rows[$draft['topic_id']])
|
---|
888 | && (
|
---|
889 | ($topic_rows[$draft['topic_id']]['forum_id'] && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
|
---|
890 | ||
|
---|
891 | (!$topic_rows[$draft['topic_id']]['forum_id'] && $auth->acl_getf_global('f_read'))
|
---|
892 | ))
|
---|
893 | {
|
---|
894 | $topic_forum_id = ($topic_rows[$draft['topic_id']]['forum_id']) ? $topic_rows[$draft['topic_id']]['forum_id'] : $forum_id;
|
---|
895 |
|
---|
896 | $link_topic = true;
|
---|
897 | $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_forum_id . '&t=' . $draft['topic_id']);
|
---|
898 | $title = $topic_rows[$draft['topic_id']]['topic_title'];
|
---|
899 |
|
---|
900 | $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_forum_id . '&t=' . $draft['topic_id'] . '&mode=reply&d=' . $draft['draft_id']);
|
---|
901 | }
|
---|
902 | else if ($draft['forum_id'] && $auth->acl_get('f_read', $draft['forum_id']))
|
---|
903 | {
|
---|
904 | $link_forum = true;
|
---|
905 | $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
|
---|
906 | $title = $draft['forum_name'];
|
---|
907 |
|
---|
908 | $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']);
|
---|
909 | }
|
---|
910 | else
|
---|
911 | {
|
---|
912 | // Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
|
---|
913 | $link_pm = true;
|
---|
914 | $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&d={$draft['draft_id']}");
|
---|
915 | }
|
---|
916 |
|
---|
917 | $template->assign_block_vars('draftrow', array(
|
---|
918 | 'DRAFT_ID' => $draft['draft_id'],
|
---|
919 | 'DATE' => $user->format_date($draft['save_time']),
|
---|
920 | 'DRAFT_SUBJECT' => $draft['draft_subject'],
|
---|
921 |
|
---|
922 | 'TITLE' => $title,
|
---|
923 | 'U_VIEW' => $view_url,
|
---|
924 | 'U_INSERT' => $insert_url,
|
---|
925 |
|
---|
926 | 'S_LINK_PM' => $link_pm,
|
---|
927 | 'S_LINK_TOPIC' => $link_topic,
|
---|
928 | 'S_LINK_FORUM' => $link_forum)
|
---|
929 | );
|
---|
930 | }
|
---|
931 | }
|
---|
932 |
|
---|
933 | /**
|
---|
934 | * Topic Review
|
---|
935 | */
|
---|
936 | function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true)
|
---|
937 | {
|
---|
938 | global $user, $auth, $db, $template, $bbcode, $cache;
|
---|
939 | global $config, $phpbb_root_path, $phpEx;
|
---|
940 |
|
---|
941 | // Go ahead and pull all data for this topic
|
---|
942 | $sql = 'SELECT p.post_id
|
---|
943 | FROM ' . POSTS_TABLE . ' p' . "
|
---|
944 | WHERE p.topic_id = $topic_id
|
---|
945 | " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . '
|
---|
946 | ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '
|
---|
947 | ORDER BY p.post_time ';
|
---|
948 | $sql .= ($mode == 'post_review') ? 'ASC' : 'DESC';
|
---|
949 | $result = $db->sql_query_limit($sql, $config['posts_per_page']);
|
---|
950 |
|
---|
951 | $post_list = array();
|
---|
952 |
|
---|
953 | while ($row = $db->sql_fetchrow($result))
|
---|
954 | {
|
---|
955 | $post_list[] = $row['post_id'];
|
---|
956 | }
|
---|
957 |
|
---|
958 | $db->sql_freeresult($result);
|
---|
959 |
|
---|
960 | if (!sizeof($post_list))
|
---|
961 | {
|
---|
962 | return false;
|
---|
963 | }
|
---|
964 |
|
---|
965 | $sql = $db->sql_build_query('SELECT', array(
|
---|
966 | 'SELECT' => 'u.username, u.user_id, u.user_colour, p.*',
|
---|
967 |
|
---|
968 | 'FROM' => array(
|
---|
969 | USERS_TABLE => 'u',
|
---|
970 | POSTS_TABLE => 'p',
|
---|
971 | ),
|
---|
972 |
|
---|
973 | 'WHERE' => $db->sql_in_set('p.post_id', $post_list) . '
|
---|
974 | AND u.user_id = p.poster_id'
|
---|
975 | ));
|
---|
976 |
|
---|
977 | $result = $db->sql_query($sql);
|
---|
978 |
|
---|
979 | $bbcode_bitfield = '';
|
---|
980 | $rowset = array();
|
---|
981 | $has_attachments = false;
|
---|
982 | while ($row = $db->sql_fetchrow($result))
|
---|
983 | {
|
---|
984 | $rowset[$row['post_id']] = $row;
|
---|
985 | $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
|
---|
986 |
|
---|
987 | if ($row['post_attachment'])
|
---|
988 | {
|
---|
989 | $has_attachments = true;
|
---|
990 | }
|
---|
991 | }
|
---|
992 | $db->sql_freeresult($result);
|
---|
993 |
|
---|
994 | // Instantiate BBCode class
|
---|
995 | if (!isset($bbcode) && $bbcode_bitfield !== '')
|
---|
996 | {
|
---|
997 | include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
|
---|
998 | $bbcode = new bbcode(base64_encode($bbcode_bitfield));
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | // Grab extensions
|
---|
1002 | $extensions = $attachments = array();
|
---|
1003 | if ($has_attachments && $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
|
---|
1004 | {
|
---|
1005 | $extensions = $cache->obtain_attach_extensions($forum_id);
|
---|
1006 |
|
---|
1007 | // Get attachments...
|
---|
1008 | $sql = 'SELECT *
|
---|
1009 | FROM ' . ATTACHMENTS_TABLE . '
|
---|
1010 | WHERE ' . $db->sql_in_set('post_msg_id', $post_list) . '
|
---|
1011 | AND in_message = 0
|
---|
1012 | ORDER BY filetime DESC, post_msg_id ASC';
|
---|
1013 | $result = $db->sql_query($sql);
|
---|
1014 |
|
---|
1015 | while ($row = $db->sql_fetchrow($result))
|
---|
1016 | {
|
---|
1017 | $attachments[$row['post_msg_id']][] = $row;
|
---|
1018 | }
|
---|
1019 | $db->sql_freeresult($result);
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
|
---|
1023 | {
|
---|
1024 | // A non-existing rowset only happens if there was no user present for the entered poster_id
|
---|
1025 | // This could be a broken posts table.
|
---|
1026 | if (!isset($rowset[$post_list[$i]]))
|
---|
1027 | {
|
---|
1028 | continue;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | $row =& $rowset[$post_list[$i]];
|
---|
1032 |
|
---|
1033 | $poster_id = $row['user_id'];
|
---|
1034 | $post_subject = $row['post_subject'];
|
---|
1035 | $message = censor_text($row['post_text']);
|
---|
1036 |
|
---|
1037 | $decoded_message = false;
|
---|
1038 |
|
---|
1039 | if ($show_quote_button && $auth->acl_get('f_reply', $forum_id))
|
---|
1040 | {
|
---|
1041 | $decoded_message = $message;
|
---|
1042 | decode_message($decoded_message, $row['bbcode_uid']);
|
---|
1043 |
|
---|
1044 | $decoded_message = bbcode_nl2br($decoded_message);
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | if ($row['bbcode_bitfield'])
|
---|
1048 | {
|
---|
1049 | $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | $message = bbcode_nl2br($message);
|
---|
1053 | $message = smiley_text($message, !$row['enable_smilies']);
|
---|
1054 |
|
---|
1055 | if (!empty($attachments[$row['post_id']]))
|
---|
1056 | {
|
---|
1057 | $update_count = array();
|
---|
1058 | parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | $post_subject = censor_text($post_subject);
|
---|
1062 |
|
---|
1063 | $template->assign_block_vars($mode . '_row', array(
|
---|
1064 | 'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
|
---|
1065 | 'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
|
---|
1066 | 'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
|
---|
1067 | 'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
|
---|
1068 |
|
---|
1069 | 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
|
---|
1070 |
|
---|
1071 | 'POST_SUBJECT' => $post_subject,
|
---|
1072 | 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
|
---|
1073 | 'POST_DATE' => $user->format_date($row['post_time']),
|
---|
1074 | 'MESSAGE' => $message,
|
---|
1075 | 'DECODED_MESSAGE' => $decoded_message,
|
---|
1076 | 'POST_ID' => $row['post_id'],
|
---|
1077 | 'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'],
|
---|
1078 | 'U_MCP_DETAILS' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=post_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '',
|
---|
1079 | 'POSTER_QUOTE' => ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) ? addslashes(get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username'])) : '')
|
---|
1080 | );
|
---|
1081 |
|
---|
1082 | // Display not already displayed Attachments for this post, we already parsed them. ;)
|
---|
1083 | if (!empty($attachments[$row['post_id']]))
|
---|
1084 | {
|
---|
1085 | foreach ($attachments[$row['post_id']] as $attachment)
|
---|
1086 | {
|
---|
1087 | $template->assign_block_vars($mode . '_row.attachment', array(
|
---|
1088 | 'DISPLAY_ATTACHMENT' => $attachment)
|
---|
1089 | );
|
---|
1090 | }
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | unset($rowset[$i]);
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | if ($mode == 'topic_review')
|
---|
1097 | {
|
---|
1098 | $template->assign_var('QUOTE_IMG', $user->img('icon_post_quote', $user->lang['REPLY_WITH_QUOTE']));
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | return true;
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | /**
|
---|
1105 | * User Notification
|
---|
1106 | */
|
---|
1107 | function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id)
|
---|
1108 | {
|
---|
1109 | global $db, $user, $config, $phpbb_root_path, $phpEx, $auth;
|
---|
1110 |
|
---|
1111 | $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false;
|
---|
1112 | $forum_notification = ($mode == 'post') ? true : false;
|
---|
1113 |
|
---|
1114 | if (!$topic_notification && !$forum_notification)
|
---|
1115 | {
|
---|
1116 | trigger_error('WRONG_NOTIFICATION_MODE');
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify']))
|
---|
1120 | {
|
---|
1121 | return;
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | $topic_title = ($topic_notification) ? $topic_title : $subject;
|
---|
1125 | $topic_title = censor_text($topic_title);
|
---|
1126 |
|
---|
1127 | // Get banned User ID's
|
---|
1128 | $sql = 'SELECT ban_userid
|
---|
1129 | FROM ' . BANLIST_TABLE . '
|
---|
1130 | WHERE ban_userid <> 0
|
---|
1131 | AND ban_exclude <> 1';
|
---|
1132 | $result = $db->sql_query($sql);
|
---|
1133 |
|
---|
1134 | $sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id'];
|
---|
1135 | while ($row = $db->sql_fetchrow($result))
|
---|
1136 | {
|
---|
1137 | $sql_ignore_users .= ', ' . (int) $row['ban_userid'];
|
---|
1138 | }
|
---|
1139 | $db->sql_freeresult($result);
|
---|
1140 |
|
---|
1141 | $notify_rows = array();
|
---|
1142 |
|
---|
1143 | // -- get forum_userids || topic_userids
|
---|
1144 | $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber
|
---|
1145 | FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u
|
---|
1146 | WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . "
|
---|
1147 | AND w.user_id NOT IN ($sql_ignore_users)
|
---|
1148 | AND w.notify_status = 0
|
---|
1149 | AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')
|
---|
1150 | AND u.user_id = w.user_id';
|
---|
1151 | $result = $db->sql_query($sql);
|
---|
1152 |
|
---|
1153 | while ($row = $db->sql_fetchrow($result))
|
---|
1154 | {
|
---|
1155 | $notify_rows[$row['user_id']] = array(
|
---|
1156 | 'user_id' => $row['user_id'],
|
---|
1157 | 'username' => $row['username'],
|
---|
1158 | 'user_email' => $row['user_email'],
|
---|
1159 | 'user_jabber' => $row['user_jabber'],
|
---|
1160 | 'user_lang' => $row['user_lang'],
|
---|
1161 | 'notify_type' => ($topic_notification) ? 'topic' : 'forum',
|
---|
1162 | 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify',
|
---|
1163 | 'method' => $row['user_notify_type'],
|
---|
1164 | 'allowed' => false
|
---|
1165 | );
|
---|
1166 | }
|
---|
1167 | $db->sql_freeresult($result);
|
---|
1168 |
|
---|
1169 | // forum notification is sent to those not already receiving topic notifications
|
---|
1170 | if ($topic_notification)
|
---|
1171 | {
|
---|
1172 | if (sizeof($notify_rows))
|
---|
1173 | {
|
---|
1174 | $sql_ignore_users .= ', ' . implode(', ', array_keys($notify_rows));
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber
|
---|
1178 | FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u
|
---|
1179 | WHERE fw.forum_id = $forum_id
|
---|
1180 | AND fw.user_id NOT IN ($sql_ignore_users)
|
---|
1181 | AND fw.notify_status = 0
|
---|
1182 | AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')
|
---|
1183 | AND u.user_id = fw.user_id';
|
---|
1184 | $result = $db->sql_query($sql);
|
---|
1185 |
|
---|
1186 | while ($row = $db->sql_fetchrow($result))
|
---|
1187 | {
|
---|
1188 | $notify_rows[$row['user_id']] = array(
|
---|
1189 | 'user_id' => $row['user_id'],
|
---|
1190 | 'username' => $row['username'],
|
---|
1191 | 'user_email' => $row['user_email'],
|
---|
1192 | 'user_jabber' => $row['user_jabber'],
|
---|
1193 | 'user_lang' => $row['user_lang'],
|
---|
1194 | 'notify_type' => 'forum',
|
---|
1195 | 'template' => 'forum_notify',
|
---|
1196 | 'method' => $row['user_notify_type'],
|
---|
1197 | 'allowed' => false
|
---|
1198 | );
|
---|
1199 | }
|
---|
1200 | $db->sql_freeresult($result);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | if (!sizeof($notify_rows))
|
---|
1204 | {
|
---|
1205 | return;
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | // Make sure users are allowed to read the forum
|
---|
1209 | foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary)
|
---|
1210 | {
|
---|
1211 | foreach ($forum_ary as $auth_option => $user_ary)
|
---|
1212 | {
|
---|
1213 | foreach ($user_ary as $user_id)
|
---|
1214 | {
|
---|
1215 | $notify_rows[$user_id]['allowed'] = true;
|
---|
1216 | }
|
---|
1217 | }
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 |
|
---|
1221 | // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;)
|
---|
1222 | $msg_users = $delete_ids = $update_notification = array();
|
---|
1223 | foreach ($notify_rows as $user_id => $row)
|
---|
1224 | {
|
---|
1225 | if (!$row['allowed'] || !trim($row['user_email']))
|
---|
1226 | {
|
---|
1227 | $delete_ids[$row['notify_type']][] = $row['user_id'];
|
---|
1228 | }
|
---|
1229 | else
|
---|
1230 | {
|
---|
1231 | $msg_users[] = $row;
|
---|
1232 | $update_notification[$row['notify_type']][] = $row['user_id'];
|
---|
1233 | }
|
---|
1234 | }
|
---|
1235 | unset($notify_rows);
|
---|
1236 |
|
---|
1237 | // Now, we are able to really send out notifications
|
---|
1238 | if (sizeof($msg_users))
|
---|
1239 | {
|
---|
1240 | include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
---|
1241 | $messenger = new messenger();
|
---|
1242 |
|
---|
1243 | $msg_list_ary = array();
|
---|
1244 | foreach ($msg_users as $row)
|
---|
1245 | {
|
---|
1246 | $pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]);
|
---|
1247 |
|
---|
1248 | $msg_list_ary[$row['template']][$pos]['method'] = $row['method'];
|
---|
1249 | $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email'];
|
---|
1250 | $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber'];
|
---|
1251 | $msg_list_ary[$row['template']][$pos]['name'] = $row['username'];
|
---|
1252 | $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang'];
|
---|
1253 | $msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id'];
|
---|
1254 | }
|
---|
1255 | unset($msg_users);
|
---|
1256 |
|
---|
1257 | foreach ($msg_list_ary as $email_template => $email_list)
|
---|
1258 | {
|
---|
1259 | foreach ($email_list as $addr)
|
---|
1260 | {
|
---|
1261 | $messenger->template($email_template, $addr['lang']);
|
---|
1262 |
|
---|
1263 | $messenger->to($addr['email'], $addr['name']);
|
---|
1264 | $messenger->im($addr['jabber'], $addr['name']);
|
---|
1265 |
|
---|
1266 | $messenger->assign_vars(array(
|
---|
1267 | 'USERNAME' => htmlspecialchars_decode($addr['name']),
|
---|
1268 | 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title),
|
---|
1269 | 'FORUM_NAME' => htmlspecialchars_decode($forum_name),
|
---|
1270 |
|
---|
1271 | 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id",
|
---|
1272 | 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id",
|
---|
1273 | 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id",
|
---|
1274 | 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic",
|
---|
1275 | 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum",
|
---|
1276 | ));
|
---|
1277 |
|
---|
1278 | $messenger->send($addr['method']);
|
---|
1279 | }
|
---|
1280 | }
|
---|
1281 | unset($msg_list_ary);
|
---|
1282 |
|
---|
1283 | $messenger->save_queue();
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | // Handle the DB updates
|
---|
1287 | $db->sql_transaction('begin');
|
---|
1288 |
|
---|
1289 | if (!empty($update_notification['topic']))
|
---|
1290 | {
|
---|
1291 | $sql = 'UPDATE ' . TOPICS_WATCH_TABLE . "
|
---|
1292 | SET notify_status = 1
|
---|
1293 | WHERE topic_id = $topic_id
|
---|
1294 | AND " . $db->sql_in_set('user_id', $update_notification['topic']);
|
---|
1295 | $db->sql_query($sql);
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | if (!empty($update_notification['forum']))
|
---|
1299 | {
|
---|
1300 | $sql = 'UPDATE ' . FORUMS_WATCH_TABLE . "
|
---|
1301 | SET notify_status = 1
|
---|
1302 | WHERE forum_id = $forum_id
|
---|
1303 | AND " . $db->sql_in_set('user_id', $update_notification['forum']);
|
---|
1304 | $db->sql_query($sql);
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | // Now delete the user_ids not authorised to receive notifications on this topic/forum
|
---|
1308 | if (!empty($delete_ids['topic']))
|
---|
1309 | {
|
---|
1310 | $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . "
|
---|
1311 | WHERE topic_id = $topic_id
|
---|
1312 | AND " . $db->sql_in_set('user_id', $delete_ids['topic']);
|
---|
1313 | $db->sql_query($sql);
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | if (!empty($delete_ids['forum']))
|
---|
1317 | {
|
---|
1318 | $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . "
|
---|
1319 | WHERE forum_id = $forum_id
|
---|
1320 | AND " . $db->sql_in_set('user_id', $delete_ids['forum']);
|
---|
1321 | $db->sql_query($sql);
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | $db->sql_transaction('commit');
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | //
|
---|
1328 | // Post handling functions
|
---|
1329 | //
|
---|
1330 |
|
---|
1331 | /**
|
---|
1332 | * Delete Post
|
---|
1333 | */
|
---|
1334 | function delete_post($forum_id, $topic_id, $post_id, &$data)
|
---|
1335 | {
|
---|
1336 | global $db, $user, $auth;
|
---|
1337 | global $config, $phpEx, $phpbb_root_path;
|
---|
1338 |
|
---|
1339 | // Specify our post mode
|
---|
1340 | $post_mode = 'delete';
|
---|
1341 | if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && $data['topic_replies_real'] == 0)
|
---|
1342 | {
|
---|
1343 | $post_mode = 'delete_topic';
|
---|
1344 | }
|
---|
1345 | else if ($data['topic_first_post_id'] == $post_id)
|
---|
1346 | {
|
---|
1347 | $post_mode = 'delete_first_post';
|
---|
1348 | }
|
---|
1349 | else if ($data['topic_last_post_id'] == $post_id)
|
---|
1350 | {
|
---|
1351 | $post_mode = 'delete_last_post';
|
---|
1352 | }
|
---|
1353 | $sql_data = array();
|
---|
1354 | $next_post_id = false;
|
---|
1355 |
|
---|
1356 | include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
---|
1357 |
|
---|
1358 | $db->sql_transaction('begin');
|
---|
1359 |
|
---|
1360 | // we must make sure to update forums that contain the shadow'd topic
|
---|
1361 | if ($post_mode == 'delete_topic')
|
---|
1362 | {
|
---|
1363 | $shadow_forum_ids = array();
|
---|
1364 |
|
---|
1365 | $sql = 'SELECT forum_id
|
---|
1366 | FROM ' . TOPICS_TABLE . '
|
---|
1367 | WHERE ' . $db->sql_in_set('topic_moved_id', $topic_id);
|
---|
1368 | $result = $db->sql_query($sql);
|
---|
1369 | while ($row = $db->sql_fetchrow($result))
|
---|
1370 | {
|
---|
1371 | if (!isset($shadow_forum_ids[(int) $row['forum_id']]))
|
---|
1372 | {
|
---|
1373 | $shadow_forum_ids[(int) $row['forum_id']] = 1;
|
---|
1374 | }
|
---|
1375 | else
|
---|
1376 | {
|
---|
1377 | $shadow_forum_ids[(int) $row['forum_id']]++;
|
---|
1378 | }
|
---|
1379 | }
|
---|
1380 | $db->sql_freeresult($result);
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | if (!delete_posts('post_id', array($post_id), false, false))
|
---|
1384 | {
|
---|
1385 | // Try to delete topic, we may had an previous error causing inconsistency
|
---|
1386 | if ($post_mode == 'delete_topic')
|
---|
1387 | {
|
---|
1388 | delete_topics('topic_id', array($topic_id), false);
|
---|
1389 | }
|
---|
1390 | trigger_error('ALREADY_DELETED');
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | $db->sql_transaction('commit');
|
---|
1394 |
|
---|
1395 | // Collect the necessary information for updating the tables
|
---|
1396 | $sql_data[FORUMS_TABLE] = '';
|
---|
1397 | switch ($post_mode)
|
---|
1398 | {
|
---|
1399 | case 'delete_topic':
|
---|
1400 |
|
---|
1401 | foreach ($shadow_forum_ids as $updated_forum => $topic_count)
|
---|
1402 | {
|
---|
1403 | // counting is fun! we only have to do sizeof($forum_ids) number of queries,
|
---|
1404 | // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum)
|
---|
1405 | $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_topics_real = forum_topics_real - ' . $topic_count . ', forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum);
|
---|
1406 | update_post_information('forum', $updated_forum);
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | delete_topics('topic_id', array($topic_id), false);
|
---|
1410 |
|
---|
1411 | if ($data['topic_type'] != POST_GLOBAL)
|
---|
1412 | {
|
---|
1413 | $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1';
|
---|
1414 | $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : '';
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | $update_sql = update_post_information('forum', $forum_id, true);
|
---|
1418 | if (sizeof($update_sql))
|
---|
1419 | {
|
---|
1420 | $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
|
---|
1421 | $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
|
---|
1422 | }
|
---|
1423 | break;
|
---|
1424 |
|
---|
1425 | case 'delete_first_post':
|
---|
1426 | $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username, u.user_colour
|
---|
1427 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
|
---|
1428 | WHERE p.topic_id = $topic_id
|
---|
1429 | AND p.poster_id = u.user_id
|
---|
1430 | ORDER BY p.post_time ASC";
|
---|
1431 | $result = $db->sql_query_limit($sql, 1);
|
---|
1432 | $row = $db->sql_fetchrow($result);
|
---|
1433 | $db->sql_freeresult($result);
|
---|
1434 |
|
---|
1435 | if ($data['topic_type'] != POST_GLOBAL)
|
---|
1436 | {
|
---|
1437 | $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'";
|
---|
1441 |
|
---|
1442 | // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
|
---|
1443 | $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
|
---|
1444 |
|
---|
1445 | $next_post_id = (int) $row['post_id'];
|
---|
1446 | break;
|
---|
1447 |
|
---|
1448 | case 'delete_last_post':
|
---|
1449 | if ($data['topic_type'] != POST_GLOBAL)
|
---|
1450 | {
|
---|
1451 | $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';
|
---|
1452 | }
|
---|
1453 |
|
---|
1454 | $update_sql = update_post_information('forum', $forum_id, true);
|
---|
1455 | if (sizeof($update_sql))
|
---|
1456 | {
|
---|
1457 | $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
|
---|
1458 | $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 | $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
|
---|
1462 |
|
---|
1463 | $update_sql = update_post_information('topic', $topic_id, true);
|
---|
1464 | if (sizeof($update_sql))
|
---|
1465 | {
|
---|
1466 | $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]);
|
---|
1467 | $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]);
|
---|
1468 | }
|
---|
1469 | else
|
---|
1470 | {
|
---|
1471 | $sql = 'SELECT MAX(post_id) as last_post_id
|
---|
1472 | FROM ' . POSTS_TABLE . "
|
---|
1473 | WHERE topic_id = $topic_id " .
|
---|
1474 | ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '');
|
---|
1475 | $result = $db->sql_query($sql);
|
---|
1476 | $row = $db->sql_fetchrow($result);
|
---|
1477 | $db->sql_freeresult($result);
|
---|
1478 |
|
---|
1479 | $next_post_id = (int) $row['last_post_id'];
|
---|
1480 | }
|
---|
1481 | break;
|
---|
1482 |
|
---|
1483 | case 'delete':
|
---|
1484 | $sql = 'SELECT post_id
|
---|
1485 | FROM ' . POSTS_TABLE . "
|
---|
1486 | WHERE topic_id = $topic_id " .
|
---|
1487 | ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . '
|
---|
1488 | AND post_time > ' . $data['post_time'] . '
|
---|
1489 | ORDER BY post_time ASC';
|
---|
1490 | $result = $db->sql_query_limit($sql, 1);
|
---|
1491 | $row = $db->sql_fetchrow($result);
|
---|
1492 | $db->sql_freeresult($result);
|
---|
1493 |
|
---|
1494 | if ($data['topic_type'] != POST_GLOBAL)
|
---|
1495 | {
|
---|
1496 | $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 | $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
|
---|
1500 | $next_post_id = (int) $row['post_id'];
|
---|
1501 | break;
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 | // $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
|
---|
1505 |
|
---|
1506 | $db->sql_transaction('begin');
|
---|
1507 |
|
---|
1508 | $where_sql = array(
|
---|
1509 | FORUMS_TABLE => "forum_id = $forum_id",
|
---|
1510 | TOPICS_TABLE => "topic_id = $topic_id",
|
---|
1511 | USERS_TABLE => 'user_id = ' . $data['poster_id']
|
---|
1512 | );
|
---|
1513 |
|
---|
1514 | foreach ($sql_data as $table => $update_sql)
|
---|
1515 | {
|
---|
1516 | if ($update_sql)
|
---|
1517 | {
|
---|
1518 | $db->sql_query("UPDATE $table SET $update_sql WHERE " . $where_sql[$table]);
|
---|
1519 | }
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | // Adjust posted info for this user by looking for a post by him/her within this topic...
|
---|
1523 | if ($post_mode != 'delete_topic' && $config['load_db_track'] && $data['poster_id'] != ANONYMOUS)
|
---|
1524 | {
|
---|
1525 | $sql = 'SELECT poster_id
|
---|
1526 | FROM ' . POSTS_TABLE . '
|
---|
1527 | WHERE topic_id = ' . $topic_id . '
|
---|
1528 | AND poster_id = ' . $data['poster_id'];
|
---|
1529 | $result = $db->sql_query_limit($sql, 1);
|
---|
1530 | $poster_id = (int) $db->sql_fetchfield('poster_id');
|
---|
1531 | $db->sql_freeresult($result);
|
---|
1532 |
|
---|
1533 | // The user is not having any more posts within this topic
|
---|
1534 | if (!$poster_id)
|
---|
1535 | {
|
---|
1536 | $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
|
---|
1537 | WHERE topic_id = ' . $topic_id . '
|
---|
1538 | AND user_id = ' . $data['poster_id'];
|
---|
1539 | $db->sql_query($sql);
|
---|
1540 | }
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 | $db->sql_transaction('commit');
|
---|
1544 |
|
---|
1545 | if ($data['post_reported'] && ($post_mode != 'delete_topic'))
|
---|
1546 | {
|
---|
1547 | sync('topic_reported', 'topic_id', array($topic_id));
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | return $next_post_id;
|
---|
1551 | }
|
---|
1552 |
|
---|
1553 | /**
|
---|
1554 | * Submit Post
|
---|
1555 | */
|
---|
1556 | function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
|
---|
1557 | {
|
---|
1558 | global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path;
|
---|
1559 |
|
---|
1560 | // We do not handle erasing posts here
|
---|
1561 | if ($mode == 'delete')
|
---|
1562 | {
|
---|
1563 | return false;
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | $current_time = time();
|
---|
1567 |
|
---|
1568 | if ($mode == 'post')
|
---|
1569 | {
|
---|
1570 | $post_mode = 'post';
|
---|
1571 | $update_message = true;
|
---|
1572 | }
|
---|
1573 | else if ($mode != 'edit')
|
---|
1574 | {
|
---|
1575 | $post_mode = 'reply';
|
---|
1576 | $update_message = true;
|
---|
1577 | }
|
---|
1578 | else if ($mode == 'edit')
|
---|
1579 | {
|
---|
1580 | $post_mode = ($data['topic_replies_real'] == 0) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit'));
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | // First of all make sure the subject and topic title are having the correct length.
|
---|
1584 | // To achieve this without cutting off between special chars we convert to an array and then count the elements.
|
---|
1585 | $subject = truncate_string($subject);
|
---|
1586 | $data['topic_title'] = truncate_string($data['topic_title']);
|
---|
1587 |
|
---|
1588 | // Collect some basic information about which tables and which rows to update/insert
|
---|
1589 | $sql_data = $topic_row = array();
|
---|
1590 | $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id'];
|
---|
1591 |
|
---|
1592 | // Retrieve some additional information if not present
|
---|
1593 | if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false))
|
---|
1594 | {
|
---|
1595 | $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved
|
---|
1596 | FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
|
---|
1597 | WHERE t.topic_id = p.topic_id
|
---|
1598 | AND p.post_id = ' . $data['post_id'];
|
---|
1599 | $result = $db->sql_query($sql);
|
---|
1600 | $topic_row = $db->sql_fetchrow($result);
|
---|
1601 | $db->sql_freeresult($result);
|
---|
1602 |
|
---|
1603 | $data['topic_approved'] = $topic_row['topic_approved'];
|
---|
1604 | $data['post_approved'] = $topic_row['post_approved'];
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 | // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval
|
---|
1608 | $post_approval = 1;
|
---|
1609 |
|
---|
1610 | // Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
|
---|
1611 | if ((($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts']) || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id']))
|
---|
1612 | {
|
---|
1613 | $post_approval = 0;
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | // Start the transaction here
|
---|
1617 | $db->sql_transaction('begin');
|
---|
1618 |
|
---|
1619 | // Collect Information
|
---|
1620 | switch ($post_mode)
|
---|
1621 | {
|
---|
1622 | case 'post':
|
---|
1623 | case 'reply':
|
---|
1624 | $sql_data[POSTS_TABLE]['sql'] = array(
|
---|
1625 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
|
---|
1626 | 'poster_id' => (int) $user->data['user_id'],
|
---|
1627 | 'icon_id' => $data['icon_id'],
|
---|
1628 | 'poster_ip' => $user->ip,
|
---|
1629 | 'post_time' => $current_time,
|
---|
1630 | 'post_approved' => $post_approval,
|
---|
1631 | 'enable_bbcode' => $data['enable_bbcode'],
|
---|
1632 | 'enable_smilies' => $data['enable_smilies'],
|
---|
1633 | 'enable_magic_url' => $data['enable_urls'],
|
---|
1634 | 'enable_sig' => $data['enable_sig'],
|
---|
1635 | 'post_username' => (!$user->data['is_registered']) ? $username : '',
|
---|
1636 | 'post_subject' => $subject,
|
---|
1637 | 'post_text' => $data['message'],
|
---|
1638 | 'post_checksum' => $data['message_md5'],
|
---|
1639 | 'post_attachment' => (!empty($data['attachment_data'])) ? 1 : 0,
|
---|
1640 | 'bbcode_bitfield' => $data['bbcode_bitfield'],
|
---|
1641 | 'bbcode_uid' => $data['bbcode_uid'],
|
---|
1642 | 'post_postcount' => ($auth->acl_get('f_postcount', $data['forum_id'])) ? 1 : 0,
|
---|
1643 | 'post_edit_locked' => $data['post_edit_locked']
|
---|
1644 | );
|
---|
1645 | break;
|
---|
1646 |
|
---|
1647 | case 'edit_first_post':
|
---|
1648 | case 'edit':
|
---|
1649 |
|
---|
1650 | case 'edit_last_post':
|
---|
1651 | case 'edit_topic':
|
---|
1652 |
|
---|
1653 | // If edit reason is given always display edit info
|
---|
1654 |
|
---|
1655 | // If editing last post then display no edit info
|
---|
1656 | // If m_edit permission then display no edit info
|
---|
1657 | // If normal edit display edit info
|
---|
1658 |
|
---|
1659 | // Display edit info if edit reason given or user is editing his post, which is not the last within the topic.
|
---|
1660 | if ($data['post_edit_reason'] || (!$auth->acl_get('m_edit', $data['forum_id']) && ($post_mode == 'edit' || $post_mode == 'edit_first_post')))
|
---|
1661 | {
|
---|
1662 | $data['post_edit_reason'] = truncate_string($data['post_edit_reason'], 255, 255, false);
|
---|
1663 |
|
---|
1664 | $sql_data[POSTS_TABLE]['sql'] = array(
|
---|
1665 | 'post_edit_time' => $current_time,
|
---|
1666 | 'post_edit_reason' => $data['post_edit_reason'],
|
---|
1667 | 'post_edit_user' => (int) $data['post_edit_user'],
|
---|
1668 | );
|
---|
1669 |
|
---|
1670 | $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
|
---|
1671 | }
|
---|
1672 | else if (!$data['post_edit_reason'] && $mode == 'edit' && $auth->acl_get('m_edit', $data['forum_id']))
|
---|
1673 | {
|
---|
1674 | $sql_data[POSTS_TABLE]['sql'] = array(
|
---|
1675 | 'post_edit_reason' => '',
|
---|
1676 | );
|
---|
1677 | }
|
---|
1678 |
|
---|
1679 | // If the person editing this post is different to the one having posted then we will add a log entry stating the edit
|
---|
1680 | // Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods
|
---|
1681 | if ($user->data['user_id'] != $poster_id)
|
---|
1682 | {
|
---|
1683 | $log_subject = ($subject) ? $subject : $data['topic_title'];
|
---|
1684 | add_log('mod', $data['forum_id'], $data['topic_id'], 'LOG_POST_EDITED', $log_subject, (!empty($username)) ? $username : $user->lang['GUEST']);
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 | if (!isset($sql_data[POSTS_TABLE]['sql']))
|
---|
1688 | {
|
---|
1689 | $sql_data[POSTS_TABLE]['sql'] = array();
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
|
---|
1693 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
|
---|
1694 | 'poster_id' => $data['poster_id'],
|
---|
1695 | 'icon_id' => $data['icon_id'],
|
---|
1696 | 'post_approved' => (!$post_approval) ? 0 : $data['post_approved'],
|
---|
1697 | 'enable_bbcode' => $data['enable_bbcode'],
|
---|
1698 | 'enable_smilies' => $data['enable_smilies'],
|
---|
1699 | 'enable_magic_url' => $data['enable_urls'],
|
---|
1700 | 'enable_sig' => $data['enable_sig'],
|
---|
1701 | 'post_username' => ($username && $data['poster_id'] == ANONYMOUS) ? $username : '',
|
---|
1702 | 'post_subject' => $subject,
|
---|
1703 | 'post_checksum' => $data['message_md5'],
|
---|
1704 | 'post_attachment' => (!empty($data['attachment_data'])) ? 1 : 0,
|
---|
1705 | 'bbcode_bitfield' => $data['bbcode_bitfield'],
|
---|
1706 | 'bbcode_uid' => $data['bbcode_uid'],
|
---|
1707 | 'post_edit_locked' => $data['post_edit_locked'])
|
---|
1708 | );
|
---|
1709 |
|
---|
1710 | if ($update_message)
|
---|
1711 | {
|
---|
1712 | $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message'];
|
---|
1713 | }
|
---|
1714 |
|
---|
1715 | break;
|
---|
1716 | }
|
---|
1717 |
|
---|
1718 | $post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved'];
|
---|
1719 | $topic_row = array();
|
---|
1720 |
|
---|
1721 | // And the topic ladies and gentlemen
|
---|
1722 | switch ($post_mode)
|
---|
1723 | {
|
---|
1724 | case 'post':
|
---|
1725 | $sql_data[TOPICS_TABLE]['sql'] = array(
|
---|
1726 | 'topic_poster' => (int) $user->data['user_id'],
|
---|
1727 | 'topic_time' => $current_time,
|
---|
1728 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
|
---|
1729 | 'icon_id' => $data['icon_id'],
|
---|
1730 | 'topic_approved' => $post_approval,
|
---|
1731 | 'topic_title' => $subject,
|
---|
1732 | 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
|
---|
1733 | 'topic_first_poster_colour' => $user->data['user_colour'],
|
---|
1734 | 'topic_type' => $topic_type,
|
---|
1735 | 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
|
---|
1736 | 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : 0,
|
---|
1737 | );
|
---|
1738 |
|
---|
1739 | if (isset($poll['poll_options']) && !empty($poll['poll_options']))
|
---|
1740 | {
|
---|
1741 | $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
|
---|
1742 | 'poll_title' => $poll['poll_title'],
|
---|
1743 | 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
|
---|
1744 | 'poll_max_options' => $poll['poll_max_options'],
|
---|
1745 | 'poll_length' => ($poll['poll_length'] * 86400),
|
---|
1746 | 'poll_vote_change' => $poll['poll_vote_change'])
|
---|
1747 | );
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : '');
|
---|
1751 |
|
---|
1752 | if ($topic_type != POST_GLOBAL)
|
---|
1753 | {
|
---|
1754 | if ($post_approval)
|
---|
1755 | {
|
---|
1756 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
|
---|
1757 | }
|
---|
1758 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : '');
|
---|
1759 | }
|
---|
1760 | break;
|
---|
1761 |
|
---|
1762 | case 'reply':
|
---|
1763 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');
|
---|
1764 | $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : '');
|
---|
1765 |
|
---|
1766 | if ($post_approval && $topic_type != POST_GLOBAL)
|
---|
1767 | {
|
---|
1768 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
|
---|
1769 | }
|
---|
1770 | break;
|
---|
1771 |
|
---|
1772 | case 'edit_topic':
|
---|
1773 | case 'edit_first_post':
|
---|
1774 |
|
---|
1775 | $sql_data[TOPICS_TABLE]['sql'] = array(
|
---|
1776 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
|
---|
1777 | 'icon_id' => $data['icon_id'],
|
---|
1778 | 'topic_approved' => (!$post_approval) ? 0 : $data['topic_approved'],
|
---|
1779 | 'topic_title' => $subject,
|
---|
1780 | 'topic_first_poster_name' => $username,
|
---|
1781 | 'topic_type' => $topic_type,
|
---|
1782 | 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
|
---|
1783 | 'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '',
|
---|
1784 | 'poll_start' => (isset($poll['poll_options'])) ? (($poll['poll_start']) ? $poll['poll_start'] : $current_time) : 0,
|
---|
1785 | 'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,
|
---|
1786 | 'poll_length' => (isset($poll['poll_options'])) ? ($poll['poll_length'] * 86400) : 0,
|
---|
1787 | 'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,
|
---|
1788 |
|
---|
1789 | 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0),
|
---|
1790 | );
|
---|
1791 |
|
---|
1792 | // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved
|
---|
1793 | if (!$post_approval && $data['topic_approved'])
|
---|
1794 | {
|
---|
1795 | // Do we need to grab some topic informations?
|
---|
1796 | if (!sizeof($topic_row))
|
---|
1797 | {
|
---|
1798 | $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved
|
---|
1799 | FROM ' . TOPICS_TABLE . '
|
---|
1800 | WHERE topic_id = ' . $data['topic_id'];
|
---|
1801 | $result = $db->sql_query($sql);
|
---|
1802 | $topic_row = $db->sql_fetchrow($result);
|
---|
1803 | $db->sql_freeresult($result);
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | // If this is the only post remaining we do not need to decrement topic_replies.
|
---|
1807 | // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again.
|
---|
1808 |
|
---|
1809 | // If this is an edited topic or the first post the topic gets completely disapproved later on...
|
---|
1810 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1';
|
---|
1811 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);
|
---|
1812 |
|
---|
1813 | set_config('num_topics', $config['num_topics'] - 1, true);
|
---|
1814 | set_config('num_posts', $config['num_posts'] - ($topic_row['topic_replies'] + 1), true);
|
---|
1815 |
|
---|
1816 | // Only decrement this post, since this is the one non-approved now
|
---|
1817 | if ($auth->acl_get('f_postcount', $data['forum_id']))
|
---|
1818 | {
|
---|
1819 | $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
|
---|
1820 | }
|
---|
1821 | }
|
---|
1822 |
|
---|
1823 | break;
|
---|
1824 |
|
---|
1825 | case 'edit':
|
---|
1826 | case 'edit_last_post':
|
---|
1827 |
|
---|
1828 | // Correctly set back the topic replies and forum posts... but only if the post was approved before.
|
---|
1829 | if (!$post_approval && $data['post_approved'])
|
---|
1830 | {
|
---|
1831 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1';
|
---|
1832 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
|
---|
1833 |
|
---|
1834 | set_config('num_posts', $config['num_posts'] - 1, true);
|
---|
1835 |
|
---|
1836 | if ($auth->acl_get('f_postcount', $data['forum_id']))
|
---|
1837 | {
|
---|
1838 | $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
|
---|
1839 | }
|
---|
1840 | }
|
---|
1841 |
|
---|
1842 | break;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 | // Submit new topic
|
---|
1846 | if ($post_mode == 'post')
|
---|
1847 | {
|
---|
1848 | $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' .
|
---|
1849 | $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']);
|
---|
1850 | $db->sql_query($sql);
|
---|
1851 |
|
---|
1852 | $data['topic_id'] = $db->sql_nextid();
|
---|
1853 |
|
---|
1854 | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
|
---|
1855 | 'topic_id' => $data['topic_id'])
|
---|
1856 | );
|
---|
1857 | unset($sql_data[TOPICS_TABLE]['sql']);
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | // Submit new post
|
---|
1861 | if ($post_mode == 'post' || $post_mode == 'reply')
|
---|
1862 | {
|
---|
1863 | if ($post_mode == 'reply')
|
---|
1864 | {
|
---|
1865 | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
|
---|
1866 | 'topic_id' => $data['topic_id'])
|
---|
1867 | );
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']);
|
---|
1871 | $db->sql_query($sql);
|
---|
1872 | $data['post_id'] = $db->sql_nextid();
|
---|
1873 |
|
---|
1874 | if ($post_mode == 'post')
|
---|
1875 | {
|
---|
1876 | $sql_data[TOPICS_TABLE]['sql'] = array(
|
---|
1877 | 'topic_first_post_id' => $data['post_id'],
|
---|
1878 | 'topic_last_post_id' => $data['post_id'],
|
---|
1879 | 'topic_last_post_time' => $current_time,
|
---|
1880 | 'topic_last_poster_id' => (int) $user->data['user_id'],
|
---|
1881 | 'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
|
---|
1882 | 'topic_last_poster_colour' => $user->data['user_colour'],
|
---|
1883 | 'topic_last_post_subject' => (string) $subject,
|
---|
1884 | );
|
---|
1885 | }
|
---|
1886 |
|
---|
1887 | unset($sql_data[POSTS_TABLE]['sql']);
|
---|
1888 | }
|
---|
1889 |
|
---|
1890 | $make_global = false;
|
---|
1891 |
|
---|
1892 | // Are we globalising or unglobalising?
|
---|
1893 | if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic')
|
---|
1894 | {
|
---|
1895 | if (!sizeof($topic_row))
|
---|
1896 | {
|
---|
1897 | $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved, topic_last_post_id
|
---|
1898 | FROM ' . TOPICS_TABLE . '
|
---|
1899 | WHERE topic_id = ' . $data['topic_id'];
|
---|
1900 | $result = $db->sql_query($sql);
|
---|
1901 | $topic_row = $db->sql_fetchrow($result);
|
---|
1902 | $db->sql_freeresult($result);
|
---|
1903 | }
|
---|
1904 |
|
---|
1905 | // globalise/unglobalise?
|
---|
1906 | if (($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) || ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL))
|
---|
1907 | {
|
---|
1908 | if (!empty($sql_data[FORUMS_TABLE]['stat']) && implode('', $sql_data[FORUMS_TABLE]['stat']))
|
---|
1909 | {
|
---|
1910 | $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET ' . implode(', ', $sql_data[FORUMS_TABLE]['stat']) . ' WHERE forum_id = ' . $data['forum_id']);
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | $make_global = true;
|
---|
1914 | $sql_data[FORUMS_TABLE]['stat'] = array();
|
---|
1915 | }
|
---|
1916 |
|
---|
1917 | // globalise
|
---|
1918 | if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL)
|
---|
1919 | {
|
---|
1920 | // Decrement topic/post count
|
---|
1921 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies_real'] + 1);
|
---|
1922 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . (($topic_row['topic_approved']) ? ', forum_topics = forum_topics - 1' : '');
|
---|
1923 |
|
---|
1924 | // Update forum_ids for all posts
|
---|
1925 | $sql = 'UPDATE ' . POSTS_TABLE . '
|
---|
1926 | SET forum_id = 0
|
---|
1927 | WHERE topic_id = ' . $data['topic_id'];
|
---|
1928 | $db->sql_query($sql);
|
---|
1929 | }
|
---|
1930 | // unglobalise
|
---|
1931 | else if ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL)
|
---|
1932 | {
|
---|
1933 | // Increment topic/post count
|
---|
1934 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($topic_row['topic_replies_real'] + 1);
|
---|
1935 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($topic_row['topic_approved']) ? ', forum_topics = forum_topics + 1' : '');
|
---|
1936 |
|
---|
1937 | // Update forum_ids for all posts
|
---|
1938 | $sql = 'UPDATE ' . POSTS_TABLE . '
|
---|
1939 | SET forum_id = ' . $data['forum_id'] . '
|
---|
1940 | WHERE topic_id = ' . $data['topic_id'];
|
---|
1941 | $db->sql_query($sql);
|
---|
1942 | }
|
---|
1943 | }
|
---|
1944 |
|
---|
1945 | // Update the topics table
|
---|
1946 | if (isset($sql_data[TOPICS_TABLE]['sql']))
|
---|
1947 | {
|
---|
1948 | $sql = 'UPDATE ' . TOPICS_TABLE . '
|
---|
1949 | SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . '
|
---|
1950 | WHERE topic_id = ' . $data['topic_id'];
|
---|
1951 | $db->sql_query($sql);
|
---|
1952 | }
|
---|
1953 |
|
---|
1954 | // Update the posts table
|
---|
1955 | if (isset($sql_data[POSTS_TABLE]['sql']))
|
---|
1956 | {
|
---|
1957 | $sql = 'UPDATE ' . POSTS_TABLE . '
|
---|
1958 | SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . '
|
---|
1959 | WHERE post_id = ' . $data['post_id'];
|
---|
1960 | $db->sql_query($sql);
|
---|
1961 | }
|
---|
1962 |
|
---|
1963 | // Update Poll Tables
|
---|
1964 | if (isset($poll['poll_options']) && !empty($poll['poll_options']))
|
---|
1965 | {
|
---|
1966 | $cur_poll_options = array();
|
---|
1967 |
|
---|
1968 | if ($poll['poll_start'] && $mode == 'edit')
|
---|
1969 | {
|
---|
1970 | $sql = 'SELECT *
|
---|
1971 | FROM ' . POLL_OPTIONS_TABLE . '
|
---|
1972 | WHERE topic_id = ' . $data['topic_id'] . '
|
---|
1973 | ORDER BY poll_option_id';
|
---|
1974 | $result = $db->sql_query($sql);
|
---|
1975 |
|
---|
1976 | $cur_poll_options = array();
|
---|
1977 | while ($row = $db->sql_fetchrow($result))
|
---|
1978 | {
|
---|
1979 | $cur_poll_options[] = $row;
|
---|
1980 | }
|
---|
1981 | $db->sql_freeresult($result);
|
---|
1982 | }
|
---|
1983 |
|
---|
1984 | $sql_insert_ary = array();
|
---|
1985 |
|
---|
1986 | for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++)
|
---|
1987 | {
|
---|
1988 | if (strlen(trim($poll['poll_options'][$i])))
|
---|
1989 | {
|
---|
1990 | if (empty($cur_poll_options[$i]))
|
---|
1991 | {
|
---|
1992 | // If we add options we need to put them to the end to be able to preserve votes...
|
---|
1993 | $sql_insert_ary[] = array(
|
---|
1994 | 'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary),
|
---|
1995 | 'topic_id' => (int) $data['topic_id'],
|
---|
1996 | 'poll_option_text' => (string) $poll['poll_options'][$i]
|
---|
1997 | );
|
---|
1998 | }
|
---|
1999 | else if ($poll['poll_options'][$i] != $cur_poll_options[$i])
|
---|
2000 | {
|
---|
2001 | $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "
|
---|
2002 | SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "'
|
---|
2003 | WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . '
|
---|
2004 | AND topic_id = ' . $data['topic_id'];
|
---|
2005 | $db->sql_query($sql);
|
---|
2006 | }
|
---|
2007 | }
|
---|
2008 | }
|
---|
2009 |
|
---|
2010 | $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);
|
---|
2011 |
|
---|
2012 | if (sizeof($poll['poll_options']) < sizeof($cur_poll_options))
|
---|
2013 | {
|
---|
2014 | $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
|
---|
2015 | WHERE poll_option_id > ' . sizeof($poll['poll_options']) . '
|
---|
2016 | AND topic_id = ' . $data['topic_id'];
|
---|
2017 | $db->sql_query($sql);
|
---|
2018 | }
|
---|
2019 |
|
---|
2020 | // If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option
|
---|
2021 | if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options))
|
---|
2022 | {
|
---|
2023 | $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']);
|
---|
2024 | $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']);
|
---|
2025 | }
|
---|
2026 | }
|
---|
2027 |
|
---|
2028 | // Submit Attachments
|
---|
2029 | if (!empty($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit')))
|
---|
2030 | {
|
---|
2031 | $space_taken = $files_added = 0;
|
---|
2032 | $orphan_rows = array();
|
---|
2033 |
|
---|
2034 | foreach ($data['attachment_data'] as $pos => $attach_row)
|
---|
2035 | {
|
---|
2036 | $orphan_rows[(int) $attach_row['attach_id']] = array();
|
---|
2037 | }
|
---|
2038 |
|
---|
2039 | if (sizeof($orphan_rows))
|
---|
2040 | {
|
---|
2041 | $sql = 'SELECT attach_id, filesize, physical_filename
|
---|
2042 | FROM ' . ATTACHMENTS_TABLE . '
|
---|
2043 | WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . '
|
---|
2044 | AND is_orphan = 1
|
---|
2045 | AND poster_id = ' . $user->data['user_id'];
|
---|
2046 | $result = $db->sql_query($sql);
|
---|
2047 |
|
---|
2048 | $orphan_rows = array();
|
---|
2049 | while ($row = $db->sql_fetchrow($result))
|
---|
2050 | {
|
---|
2051 | $orphan_rows[$row['attach_id']] = $row;
|
---|
2052 | }
|
---|
2053 | $db->sql_freeresult($result);
|
---|
2054 | }
|
---|
2055 |
|
---|
2056 | foreach ($data['attachment_data'] as $pos => $attach_row)
|
---|
2057 | {
|
---|
2058 | if ($attach_row['is_orphan'] && !isset($orphan_rows[$attach_row['attach_id']]))
|
---|
2059 | {
|
---|
2060 | continue;
|
---|
2061 | }
|
---|
2062 |
|
---|
2063 | if (!$attach_row['is_orphan'])
|
---|
2064 | {
|
---|
2065 | // update entry in db if attachment already stored in db and filespace
|
---|
2066 | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
|
---|
2067 | SET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "'
|
---|
2068 | WHERE attach_id = " . (int) $attach_row['attach_id'] . '
|
---|
2069 | AND is_orphan = 0';
|
---|
2070 | $db->sql_query($sql);
|
---|
2071 | }
|
---|
2072 | else
|
---|
2073 | {
|
---|
2074 | // insert attachment into db
|
---|
2075 | if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
|
---|
2076 | {
|
---|
2077 | continue;
|
---|
2078 | }
|
---|
2079 |
|
---|
2080 | $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize'];
|
---|
2081 | $files_added++;
|
---|
2082 |
|
---|
2083 | $attach_sql = array(
|
---|
2084 | 'post_msg_id' => $data['post_id'],
|
---|
2085 | 'topic_id' => $data['topic_id'],
|
---|
2086 | 'is_orphan' => 0,
|
---|
2087 | 'poster_id' => $poster_id,
|
---|
2088 | 'attach_comment' => $attach_row['attach_comment'],
|
---|
2089 | );
|
---|
2090 |
|
---|
2091 | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . '
|
---|
2092 | WHERE attach_id = ' . $attach_row['attach_id'] . '
|
---|
2093 | AND is_orphan = 1
|
---|
2094 | AND poster_id = ' . $user->data['user_id'];
|
---|
2095 | $db->sql_query($sql);
|
---|
2096 | }
|
---|
2097 | }
|
---|
2098 |
|
---|
2099 | if ($space_taken && $files_added)
|
---|
2100 | {
|
---|
2101 | set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
|
---|
2102 | set_config('num_files', $config['num_files'] + $files_added, true);
|
---|
2103 | }
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 | // we need to update the last forum information
|
---|
2107 | // only applicable if the topic is not global and it is approved
|
---|
2108 | // we also check to make sure we are not dealing with globaling the latest topic (pretty rare but still needs to be checked)
|
---|
2109 | if ($topic_type != POST_GLOBAL && !$make_global && ($post_approved || !$data['post_approved']))
|
---|
2110 | {
|
---|
2111 | // the last post makes us update the forum table. This can happen if...
|
---|
2112 | // We make a new topic
|
---|
2113 | // We reply to a topic
|
---|
2114 | // We edit the last post in a topic and this post is the latest in the forum (maybe)
|
---|
2115 | // We edit the only post in the topic
|
---|
2116 | // We edit the first post in the topic and all the other posts are not approved
|
---|
2117 | if (($post_mode == 'post' || $post_mode == 'reply') && $post_approved)
|
---|
2118 | {
|
---|
2119 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id'];
|
---|
2120 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'";
|
---|
2121 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time;
|
---|
2122 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id'];
|
---|
2123 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'";
|
---|
2124 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'";
|
---|
2125 | }
|
---|
2126 | else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))
|
---|
2127 | {
|
---|
2128 | // this does not _necessarily_ mean that we must update the info again,
|
---|
2129 | // it just means that we might have to
|
---|
2130 | $sql = 'SELECT forum_last_post_id, forum_last_post_subject
|
---|
2131 | FROM ' . FORUMS_TABLE . '
|
---|
2132 | WHERE forum_id = ' . (int) $data['forum_id'];
|
---|
2133 | $result = $db->sql_query($sql);
|
---|
2134 | $row = $db->sql_fetchrow($result);
|
---|
2135 | $db->sql_freeresult($result);
|
---|
2136 |
|
---|
2137 | // this post is the latest post in the forum, better update
|
---|
2138 | if ($row['forum_last_post_id'] == $data['post_id'])
|
---|
2139 | {
|
---|
2140 | // If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows
|
---|
2141 | if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS))
|
---|
2142 | {
|
---|
2143 | // the post's subject changed
|
---|
2144 | if ($row['forum_last_post_subject'] !== $subject)
|
---|
2145 | {
|
---|
2146 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\'';
|
---|
2147 | }
|
---|
2148 |
|
---|
2149 | // Update the user name if poster is anonymous... just in case an admin changed it
|
---|
2150 | if ($data['poster_id'] == ANONYMOUS)
|
---|
2151 | {
|
---|
2152 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'";
|
---|
2153 | }
|
---|
2154 | }
|
---|
2155 | else if ($data['post_approved'] !== $post_approved)
|
---|
2156 | {
|
---|
2157 | // we need a fresh change of socks, everything has become invalidated
|
---|
2158 | $sql = 'SELECT MAX(topic_last_post_id) as last_post_id
|
---|
2159 | FROM ' . TOPICS_TABLE . '
|
---|
2160 | WHERE forum_id = ' . (int) $data['forum_id'] . '
|
---|
2161 | AND topic_approved = 1';
|
---|
2162 | $result = $db->sql_query($sql);
|
---|
2163 | $row = $db->sql_fetchrow($result);
|
---|
2164 | $db->sql_freeresult($result);
|
---|
2165 |
|
---|
2166 | // any posts left in this forum?
|
---|
2167 | if (!empty($row['last_post_id']))
|
---|
2168 | {
|
---|
2169 | $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
|
---|
2170 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
2171 | WHERE p.poster_id = u.user_id
|
---|
2172 | AND p.post_id = ' . (int) $row['last_post_id'];
|
---|
2173 | $result = $db->sql_query($sql);
|
---|
2174 | $row = $db->sql_fetchrow($result);
|
---|
2175 | $db->sql_freeresult($result);
|
---|
2176 |
|
---|
2177 | // salvation, a post is found! jam it into the forums table
|
---|
2178 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id'];
|
---|
2179 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
|
---|
2180 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time'];
|
---|
2181 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id'];
|
---|
2182 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'";
|
---|
2183 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
|
---|
2184 | }
|
---|
2185 | else
|
---|
2186 | {
|
---|
2187 | // just our luck, the last topic in the forum has just been turned unapproved...
|
---|
2188 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0';
|
---|
2189 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''";
|
---|
2190 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0';
|
---|
2191 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0';
|
---|
2192 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''";
|
---|
2193 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''";
|
---|
2194 | }
|
---|
2195 | }
|
---|
2196 | }
|
---|
2197 | }
|
---|
2198 | }
|
---|
2199 | else if ($make_global)
|
---|
2200 | {
|
---|
2201 | // somebody decided to be a party pooper, we must recalculate the whole shebang (maybe)
|
---|
2202 | $sql = 'SELECT forum_last_post_id
|
---|
2203 | FROM ' . FORUMS_TABLE . '
|
---|
2204 | WHERE forum_id = ' . (int) $data['forum_id'];
|
---|
2205 | $result = $db->sql_query($sql);
|
---|
2206 | $forum_row = $db->sql_fetchrow($result);
|
---|
2207 | $db->sql_freeresult($result);
|
---|
2208 |
|
---|
2209 | // we made a topic global, go get new data
|
---|
2210 | if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL && $forum_row['forum_last_post_id'] == $topic_row['topic_last_post_id'])
|
---|
2211 | {
|
---|
2212 | // we need a fresh change of socks, everything has become invalidated
|
---|
2213 | $sql = 'SELECT MAX(topic_last_post_id) as last_post_id
|
---|
2214 | FROM ' . TOPICS_TABLE . '
|
---|
2215 | WHERE forum_id = ' . (int) $data['forum_id'] . '
|
---|
2216 | AND topic_approved = 1';
|
---|
2217 | $result = $db->sql_query($sql);
|
---|
2218 | $row = $db->sql_fetchrow($result);
|
---|
2219 | $db->sql_freeresult($result);
|
---|
2220 |
|
---|
2221 | // any posts left in this forum?
|
---|
2222 | if (!empty($row['last_post_id']))
|
---|
2223 | {
|
---|
2224 | $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
|
---|
2225 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
2226 | WHERE p.poster_id = u.user_id
|
---|
2227 | AND p.post_id = ' . (int) $row['last_post_id'];
|
---|
2228 | $result = $db->sql_query($sql);
|
---|
2229 | $row = $db->sql_fetchrow($result);
|
---|
2230 | $db->sql_freeresult($result);
|
---|
2231 |
|
---|
2232 | // salvation, a post is found! jam it into the forums table
|
---|
2233 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id'];
|
---|
2234 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
|
---|
2235 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time'];
|
---|
2236 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id'];
|
---|
2237 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'";
|
---|
2238 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
|
---|
2239 | }
|
---|
2240 | else
|
---|
2241 | {
|
---|
2242 | // just our luck, the last topic in the forum has just been globalized...
|
---|
2243 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0';
|
---|
2244 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''";
|
---|
2245 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0';
|
---|
2246 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0';
|
---|
2247 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''";
|
---|
2248 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''";
|
---|
2249 | }
|
---|
2250 | }
|
---|
2251 | else if ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL && $forum_row['forum_last_post_id'] < $topic_row['topic_last_post_id'])
|
---|
2252 | {
|
---|
2253 | // this post has a higher id, it is newer
|
---|
2254 | $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
|
---|
2255 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
2256 | WHERE p.poster_id = u.user_id
|
---|
2257 | AND p.post_id = ' . (int) $topic_row['topic_last_post_id'];
|
---|
2258 | $result = $db->sql_query($sql);
|
---|
2259 | $row = $db->sql_fetchrow($result);
|
---|
2260 | $db->sql_freeresult($result);
|
---|
2261 |
|
---|
2262 | // salvation, a post is found! jam it into the forums table
|
---|
2263 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id'];
|
---|
2264 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
|
---|
2265 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time'];
|
---|
2266 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id'];
|
---|
2267 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'";
|
---|
2268 | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
|
---|
2269 | }
|
---|
2270 | }
|
---|
2271 |
|
---|
2272 | // topic sync time!
|
---|
2273 | // simply, we update if it is a reply or the last post is edited
|
---|
2274 | if ($post_approved)
|
---|
2275 | {
|
---|
2276 | // reply requires the whole thing
|
---|
2277 | if ($post_mode == 'reply')
|
---|
2278 | {
|
---|
2279 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $data['post_id'];
|
---|
2280 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $user->data['user_id'];
|
---|
2281 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'";
|
---|
2282 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . (($user->data['user_id'] != ANONYMOUS) ? $db->sql_escape($user->data['user_colour']) : '') . "'";
|
---|
2283 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'";
|
---|
2284 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $current_time;
|
---|
2285 | }
|
---|
2286 | else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))
|
---|
2287 | {
|
---|
2288 | // only the subject can be changed from edit
|
---|
2289 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'";
|
---|
2290 |
|
---|
2291 | // Maybe not only the subject, but also changing anonymous usernames. ;)
|
---|
2292 | if ($data['poster_id'] == ANONYMOUS)
|
---|
2293 | {
|
---|
2294 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'";
|
---|
2295 | }
|
---|
2296 | }
|
---|
2297 | }
|
---|
2298 | else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])))
|
---|
2299 | {
|
---|
2300 | // like having the rug pulled from under us
|
---|
2301 | $sql = 'SELECT MAX(post_id) as last_post_id
|
---|
2302 | FROM ' . POSTS_TABLE . '
|
---|
2303 | WHERE topic_id = ' . (int) $data['topic_id'] . '
|
---|
2304 | AND post_approved = 1';
|
---|
2305 | $result = $db->sql_query($sql);
|
---|
2306 | $row = $db->sql_fetchrow($result);
|
---|
2307 | $db->sql_freeresult($result);
|
---|
2308 |
|
---|
2309 | // any posts left in this forum?
|
---|
2310 | if (!empty($row['last_post_id']))
|
---|
2311 | {
|
---|
2312 | $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
|
---|
2313 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
2314 | WHERE p.poster_id = u.user_id
|
---|
2315 | AND p.post_id = ' . (int) $row['last_post_id'];
|
---|
2316 | $result = $db->sql_query($sql);
|
---|
2317 | $row = $db->sql_fetchrow($result);
|
---|
2318 | $db->sql_freeresult($result);
|
---|
2319 |
|
---|
2320 | // salvation, a post is found! jam it into the topics table
|
---|
2321 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $row['post_id'];
|
---|
2322 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
|
---|
2323 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $row['post_time'];
|
---|
2324 | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $row['poster_id'];
|
---|
2325 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'";
|
---|
2326 | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
|
---|
2327 | }
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | // Update total post count, do not consider moderated posts/topics
|
---|
2331 | if ($post_approval)
|
---|
2332 | {
|
---|
2333 | if ($post_mode == 'post')
|
---|
2334 | {
|
---|
2335 | set_config('num_topics', $config['num_topics'] + 1, true);
|
---|
2336 | set_config('num_posts', $config['num_posts'] + 1, true);
|
---|
2337 | }
|
---|
2338 |
|
---|
2339 | if ($post_mode == 'reply')
|
---|
2340 | {
|
---|
2341 | set_config('num_posts', $config['num_posts'] + 1, true);
|
---|
2342 | }
|
---|
2343 | }
|
---|
2344 |
|
---|
2345 | // Update forum stats
|
---|
2346 | $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id);
|
---|
2347 |
|
---|
2348 | foreach ($sql_data as $table => $update_ary)
|
---|
2349 | {
|
---|
2350 | if (isset($update_ary['stat']) && implode('', $update_ary['stat']))
|
---|
2351 | {
|
---|
2352 | $sql = "UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table];
|
---|
2353 | $db->sql_query($sql);
|
---|
2354 | }
|
---|
2355 | }
|
---|
2356 |
|
---|
2357 | // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
|
---|
2358 | if ($make_global)
|
---|
2359 | {
|
---|
2360 | $sql = 'DELETE FROM ' . TOPICS_TABLE . '
|
---|
2361 | WHERE topic_moved_id = ' . $data['topic_id'];
|
---|
2362 | $db->sql_query($sql);
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 | // Committing the transaction before updating search index
|
---|
2366 | $db->sql_transaction('commit');
|
---|
2367 |
|
---|
2368 | // Delete draft if post was loaded...
|
---|
2369 | $draft_id = request_var('draft_loaded', 0);
|
---|
2370 | if ($draft_id)
|
---|
2371 | {
|
---|
2372 | $sql = 'DELETE FROM ' . DRAFTS_TABLE . "
|
---|
2373 | WHERE draft_id = $draft_id
|
---|
2374 | AND user_id = {$user->data['user_id']}";
|
---|
2375 | $db->sql_query($sql);
|
---|
2376 | }
|
---|
2377 |
|
---|
2378 | // Index message contents
|
---|
2379 | if ($update_message && $data['enable_indexing'])
|
---|
2380 | {
|
---|
2381 | // Select the search method and do some additional checks to ensure it can actually be utilised
|
---|
2382 | $search_type = basename($config['search_type']);
|
---|
2383 |
|
---|
2384 | if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
|
---|
2385 | {
|
---|
2386 | trigger_error('NO_SUCH_SEARCH_MODULE');
|
---|
2387 | }
|
---|
2388 |
|
---|
2389 | if (!class_exists($search_type))
|
---|
2390 | {
|
---|
2391 | include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
|
---|
2392 | }
|
---|
2393 |
|
---|
2394 | $error = false;
|
---|
2395 | $search = new $search_type($error);
|
---|
2396 |
|
---|
2397 | if ($error)
|
---|
2398 | {
|
---|
2399 | trigger_error($error);
|
---|
2400 | }
|
---|
2401 |
|
---|
2402 | $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']);
|
---|
2403 | }
|
---|
2404 |
|
---|
2405 | // Topic Notification, do not change if moderator is changing other users posts...
|
---|
2406 | if ($user->data['user_id'] == $poster_id)
|
---|
2407 | {
|
---|
2408 | if (!$data['notify_set'] && $data['notify'])
|
---|
2409 | {
|
---|
2410 | $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id)
|
---|
2411 | VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')';
|
---|
2412 | $db->sql_query($sql);
|
---|
2413 | }
|
---|
2414 | else if ($data['notify_set'] && !$data['notify'])
|
---|
2415 | {
|
---|
2416 | $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
|
---|
2417 | WHERE user_id = ' . $user->data['user_id'] . '
|
---|
2418 | AND topic_id = ' . $data['topic_id'];
|
---|
2419 | $db->sql_query($sql);
|
---|
2420 | }
|
---|
2421 | }
|
---|
2422 |
|
---|
2423 | if ($mode == 'post' || $mode == 'reply' || $mode == 'quote')
|
---|
2424 | {
|
---|
2425 | // Mark this topic as posted to
|
---|
2426 | markread('post', $data['forum_id'], $data['topic_id'], $data['post_time']);
|
---|
2427 | }
|
---|
2428 |
|
---|
2429 | // Mark this topic as read
|
---|
2430 | // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
|
---|
2431 | markread('topic', $data['forum_id'], $data['topic_id'], time());
|
---|
2432 |
|
---|
2433 | //
|
---|
2434 | if ($config['load_db_lastread'] && $user->data['is_registered'])
|
---|
2435 | {
|
---|
2436 | $sql = 'SELECT mark_time
|
---|
2437 | FROM ' . FORUMS_TRACK_TABLE . '
|
---|
2438 | WHERE user_id = ' . $user->data['user_id'] . '
|
---|
2439 | AND forum_id = ' . $data['forum_id'];
|
---|
2440 | $result = $db->sql_query($sql);
|
---|
2441 | $f_mark_time = (int) $db->sql_fetchfield('mark_time');
|
---|
2442 | $db->sql_freeresult($result);
|
---|
2443 | }
|
---|
2444 | else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
---|
2445 | {
|
---|
2446 | $f_mark_time = false;
|
---|
2447 | }
|
---|
2448 |
|
---|
2449 | if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered'])
|
---|
2450 | {
|
---|
2451 | // Update forum info
|
---|
2452 | $sql = 'SELECT forum_last_post_time
|
---|
2453 | FROM ' . FORUMS_TABLE . '
|
---|
2454 | WHERE forum_id = ' . $data['forum_id'];
|
---|
2455 | $result = $db->sql_query($sql);
|
---|
2456 | $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
|
---|
2457 | $db->sql_freeresult($result);
|
---|
2458 |
|
---|
2459 | update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false);
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | // Send Notifications
|
---|
2463 | if ($mode != 'edit' && $mode != 'delete' && $post_approval)
|
---|
2464 | {
|
---|
2465 | user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']);
|
---|
2466 | }
|
---|
2467 |
|
---|
2468 | $params = $add_anchor = '';
|
---|
2469 |
|
---|
2470 | if ($post_approval)
|
---|
2471 | {
|
---|
2472 | $params .= '&t=' . $data['topic_id'];
|
---|
2473 |
|
---|
2474 | if ($mode != 'post')
|
---|
2475 | {
|
---|
2476 | $params .= '&p=' . $data['post_id'];
|
---|
2477 | $add_anchor = '#p' . $data['post_id'];
|
---|
2478 | }
|
---|
2479 | }
|
---|
2480 | else if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic')
|
---|
2481 | {
|
---|
2482 | $params .= '&t=' . $data['topic_id'];
|
---|
2483 | }
|
---|
2484 |
|
---|
2485 | $url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx";
|
---|
2486 | $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;
|
---|
2487 |
|
---|
2488 | return $url;
|
---|
2489 | }
|
---|
2490 |
|
---|
2491 | ?>
|
---|