diff options
Diffstat (limited to 'phpBB/includes/functions_posting.php')
-rw-r--r-- | phpBB/includes/functions_posting.php | 150 |
1 files changed, 104 insertions, 46 deletions
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d9f395efb3..2cce77e092 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -114,7 +114,7 @@ function generate_smilies($mode, $forum_id) } $db->sql_freeresult($result); - if (sizeof($smilies)) + if (count($smilies)) { $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_path_helper->get_web_root_path(); @@ -200,13 +200,15 @@ function update_post_information($type, $ids, $return_update_sql = false) $topic_condition = ''; } - if (sizeof($ids) == 1) + if (count($ids) == 1) { - $sql = 'SELECT MAX(p.post_id) as last_post_id + $sql = 'SELECT p.post_id as last_post_id FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_visibility = " . ITEM_APPROVED; + AND p.post_visibility = " . ITEM_APPROVED . " + ORDER BY p.post_id DESC"; + $result = $db->sql_query_limit($sql, 1); } else { @@ -216,13 +218,13 @@ function update_post_information($type, $ids, $return_update_sql = false) $topic_condition AND p.post_visibility = " . ITEM_APPROVED . " GROUP BY p.{$type}_id"; + $result = $db->sql_query($sql); } - $result = $db->sql_query($sql); $last_post_ids = array(); while ($row = $db->sql_fetchrow($result)) { - if (sizeof($ids) == 1) + if (count($ids) == 1) { $row[$type . '_id'] = $ids[0]; } @@ -256,7 +258,7 @@ function update_post_information($type, $ids, $return_update_sql = false) } } - if (sizeof($last_post_ids)) + if (count($last_post_ids)) { $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 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u @@ -277,7 +279,7 @@ function update_post_information($type, $ids, $return_update_sql = false) } unset($empty_forums, $ids, $last_post_ids); - if ($return_update_sql || !sizeof($update_sql)) + if ($return_update_sql || !count($update_sql)) { return $update_sql; } @@ -310,7 +312,7 @@ function posting_gen_topic_icons($mode, $icon_id) $template->assign_var('S_NO_ICON_CHECKED', ' checked="checked"'); } - if (sizeof($icons)) + if (count($icons)) { $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; @@ -519,7 +521,7 @@ function get_supported_image_types($type = false) */ function create_thumbnail($source, $destination, $mimetype) { - global $config, $phpbb_filesystem; + global $config, $phpbb_filesystem, $phpbb_dispatcher; $min_filesize = (int) $config['img_min_thumb_filesize']; $img_filesize = (file_exists($source)) ? @filesize($source) : false; @@ -551,25 +553,31 @@ function create_thumbnail($source, $destination, $mimetype) return false; } - $used_imagick = false; - - // Only use ImageMagick if defined and the passthru function not disabled - if ($config['img_imagick'] && function_exists('passthru')) - { - if (substr($config['img_imagick'], -1) !== '/') - { - $config['img_imagick'] .= '/'; - } - - @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"'); + $thumbnail_created = false; - if (file_exists($destination)) - { - $used_imagick = true; - } - } + /** + * Create thumbnail event to replace GD thumbnail creation with for example ImageMagick + * + * @event core.thumbnail_create_before + * @var string source Image source path + * @var string destination Thumbnail destination path + * @var string mimetype Image mime type + * @var float new_width Calculated thumbnail width + * @var float new_height Calculated thumbnail height + * @var bool thumbnail_created Set to true to skip default GD thumbnail creation + * @since 3.2.4 + */ + $vars = array( + 'source', + 'destination', + 'mimetype', + 'new_width', + 'new_height', + 'thumbnail_created', + ); + extract($phpbb_dispatcher->trigger_event('core.thumbnail_create_before', compact($vars))); - if (!$used_imagick) + if (!$thumbnail_created) { $type = get_supported_image_types($type); @@ -690,7 +698,7 @@ function posting_gen_inline_attachments(&$attachment_data) { global $template; - if (sizeof($attachment_data)) + if (count($attachment_data)) { $s_inline_attachment_options = ''; @@ -717,20 +725,21 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a // Some default template variables $template->assign_vars(array( 'S_SHOW_ATTACH_BOX' => $show_attach_box, - 'S_HAS_ATTACHMENTS' => sizeof($attachment_data), + 'S_HAS_ATTACHMENTS' => count($attachment_data), 'FILESIZE' => $config['max_filesize'], 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '', )); - if (sizeof($attachment_data)) + if (count($attachment_data)) { // We display the posted attachments within the desired order. ($config['display_order']) ? krsort($attachment_data) : ksort($attachment_data); + $attachrow_template_vars = []; + foreach ($attachment_data as $count => $attach_row) { $hidden = ''; - $attachrow_template_vars = array(); $attach_row['real_filename'] = utf8_basename($attach_row['real_filename']); foreach ($attach_row as $key => $value) @@ -768,7 +777,7 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a $template->assign_block_vars_array('attach_row', $attachrow_template_vars); } - return sizeof($attachment_data); + return count($attachment_data); } // @@ -816,13 +825,13 @@ function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $ms } $db->sql_freeresult($result); - if (!sizeof($draft_rows)) + if (!count($draft_rows)) { return; } $topic_rows = array(); - if (sizeof($topic_ids)) + if (count($topic_ids)) { $sql = 'SELECT topic_id, forum_id, topic_title, topic_poster FROM ' . TOPICS_TABLE . ' @@ -935,7 +944,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $db->sql_freeresult($result); - if (!sizeof($post_list)) + if (!count($post_list)) { return false; } @@ -969,6 +978,30 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id AND u.user_id = p.poster_id', ); + /** + * Event to modify the SQL query for topic reviews + * + * @event core.topic_review_modify_sql_ary + * @var int topic_id The topic ID that is being reviewed + * @var int forum_id The topic's forum ID + * @var string mode The topic review mode + * @var int cur_post_id Post offset ID + * @var bool show_quote_button Flag indicating if the quote button should be displayed + * @var array post_list Array with the post IDs + * @var array sql_ary Array with the SQL query + * @since 3.2.8-RC1 + */ + $vars = array( + 'topic_id', + 'forum_id', + 'mode', + 'cur_post_id', + 'show_quote_button', + 'post_list', + 'sql_ary', + ); + extract($phpbb_dispatcher->trigger_event('core.topic_review_modify_sql_ary', compact($vars))); + $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -1030,7 +1063,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id ); extract($phpbb_dispatcher->trigger_event('core.topic_review_modify_post_list', compact($vars))); - for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) + for ($i = 0, $end = count($post_list); $i < $end; ++$i) { // A non-existing rowset only happens if there was no user present for the entered poster_id // This could be a broken posts table. @@ -1257,7 +1290,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ foreach ($shadow_forum_ids as $updated_forum => $topic_count) { - // counting is fun! we only have to do sizeof($forum_ids) number of queries, + // counting is fun! we only have to do count($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) $sql = 'UPDATE ' . FORUMS_TABLE . ' SET forum_topics_approved = forum_topics_approved - ' . $topic_count . ' @@ -1275,9 +1308,10 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ delete_topics('topic_id', array($topic_id), false); $phpbb_content_visibility->remove_topic_from_statistic($data, $sql_data); + $config->increment('num_posts', -1, false); $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) + if (count($update_sql)) { $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); @@ -1326,7 +1360,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { // Update last post information when hard deleting. Soft delete already did that by itself. $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) + if (count($update_sql)) { $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]); } @@ -1968,7 +2002,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data $sql_insert_ary = array(); - for ($i = 0, $size = sizeof($poll_ary['poll_options']); $i < $size; $i++) + for ($i = 0, $size = count($poll_ary['poll_options']); $i < $size; $i++) { if (strlen(trim($poll_ary['poll_options'][$i]))) { @@ -1976,7 +2010,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data { // If we add options we need to put them to the end to be able to preserve votes... $sql_insert_ary[] = array( - 'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary), + 'poll_option_id' => (int) count($cur_poll_options) + 1 + count($sql_insert_ary), 'topic_id' => (int) $data_ary['topic_id'], 'poll_option_text' => (string) $poll_ary['poll_options'][$i] ); @@ -1994,16 +2028,16 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary); - if (sizeof($poll_ary['poll_options']) < sizeof($cur_poll_options)) + if (count($poll_ary['poll_options']) < count($cur_poll_options)) { $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' - WHERE poll_option_id > ' . sizeof($poll_ary['poll_options']) . ' + WHERE poll_option_id > ' . count($poll_ary['poll_options']) . ' AND topic_id = ' . $data_ary['topic_id']; $db->sql_query($sql); } // 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 - if ($mode == 'edit' && sizeof($poll_ary['poll_options']) != sizeof($cur_poll_options)) + if ($mode == 'edit' && count($poll_ary['poll_options']) != count($cur_poll_options)) { $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data_ary['topic_id']); $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data_ary['topic_id']); @@ -2021,7 +2055,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data $orphan_rows[(int) $attach_row['attach_id']] = array(); } - if (sizeof($orphan_rows)) + if (count($orphan_rows)) { $sql = 'SELECT attach_id, filesize, physical_filename FROM ' . ATTACHMENTS_TABLE . ' @@ -2045,6 +2079,11 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data continue; } + if (preg_match('/[\x{10000}-\x{10FFFF}]/u', $attach_row['attach_comment'])) + { + trigger_error('ATTACH_COMMENT_NO_EMOJIS'); + } + if (!$attach_row['is_orphan']) { // update entry in db if attachment already stored in db and filespace @@ -2281,6 +2320,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data 'post_subject' => $subject, )); + /** + * This event allows you to modify the notification data upon submission + * + * @event core.modify_submit_notification_data + * @var array notification_data The notification data to be inserted in to the database + * @var array data_ary The data array with a lot of the post submission data + * @var string mode The posting mode + * @var int poster_id The poster id + * @since 3.2.4-RC1 + */ + $vars = array('notification_data', 'data_ary', 'mode', 'poster_id'); + extract($phpbb_dispatcher->trigger_event('core.modify_submit_notification_data', compact($vars))); + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); @@ -2308,8 +2360,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data case 'edit_first_post': case 'edit': case 'edit_last_post': + if ($user->data['user_id'] == $poster_id) + { + $phpbb_notifications->update_notifications(array( + 'notification.type.quote', + ), $notification_data); + } + $phpbb_notifications->update_notifications(array( - 'notification.type.quote', 'notification.type.bookmark', 'notification.type.topic', 'notification.type.post', |