Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/functions_posting.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_posting.php 9166 2008-12-03 16:40:53Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2525        global $phpEx, $phpbb_root_path;
    2626
     27        $start = request_var('start', 0);
     28
    2729        if ($mode == 'window')
    2830        {
     
    4547                page_header($user->lang['SMILIES']);
    4648
     49                $sql = 'SELECT COUNT(smiley_id) AS item_count
     50                        FROM ' . SMILIES_TABLE . '
     51                        GROUP BY smiley_url';
     52                $result = $db->sql_query($sql, 3600);
     53
     54                $smiley_count = 0;
     55                while ($row = $db->sql_fetchrow($result))
     56                {
     57                        ++$smiley_count;
     58                }
     59                $db->sql_freeresult($result);
     60
    4761                $template->set_filenames(array(
    4862                        'body' => 'posting_smilies.html')
     63                );
     64
     65                $template->assign_var('PAGINATION',
     66                        generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id),
     67                                $smiley_count, $config['smilies_per_page'], $start, true)
    4968                );
    5069        }
     
    6584        }
    6685
    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);
     86        if ($mode == 'window')
     87        {
     88                $sql = 'SELECT smiley_url, MIN(emotion) as emotion, MIN(code) AS code, smiley_width, smiley_height
     89                        FROM ' . SMILIES_TABLE . '
     90                        GROUP BY smiley_url, smiley_width, smiley_height
     91                        ORDER BY MIN(smiley_order)';
     92                $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $start, 3600);
     93        }
     94        else
     95        {
     96                $sql = 'SELECT *
     97                        FROM ' . SMILIES_TABLE . '
     98                        WHERE display_on_posting = 1
     99                        ORDER BY smiley_order';
     100                $result = $db->sql_query($sql, 3600);
     101        }
    74102
    75103        $smilies = array();
     
    85113        if (sizeof($smilies))
    86114        {
     115                $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;
     116
    87117                foreach ($smilies as $row)
    88118                {
     
    90120                                'SMILEY_CODE'   => $row['code'],
    91121                                'A_SMILEY_CODE' => addslashes($row['code']),
    92                                 'SMILEY_IMG'    => $phpbb_root_path . $config['smilies_path'] . '/' . $row['smiley_url'],
     122                                'SMILEY_IMG'    => $root_path . $config['smilies_path'] . '/' . $row['smiley_url'],
    93123                                'SMILEY_WIDTH'  => $row['smiley_width'],
    94124                                'SMILEY_HEIGHT' => $row['smiley_height'],
     
    615645
    616646        // Do not create a thumbnail if the resulting width/height is bigger than the original one
    617         if ($new_width > $width && $new_height > $height)
     647        if ($new_width >= $width && $new_height >= $height)
    618648        {
    619649                return false;
     
    630660                }
    631661
    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) . '"');
     662                @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) . '"');
    633663
    634664                if (file_exists($destination))
     
    657687
    658688                                case IMG_JPG:
     689                                        @ini_set('gd.jpeg_ignore_warning', 1);
    659690                                        $image = @imagecreatefromjpeg($source);
    660691                                break;
     
    667698                                        $image = @imagecreatefromwbmp($source);
    668699                                break;
     700                        }
     701
     702                        if (empty($image))
     703                        {
     704                                return false;
    669705                        }
    670706
     
    752788                foreach ($attachment_data as $i => $attachment)
    753789                {
    754                         $s_inline_attachment_options .= '<option value="' . $i . '">' . basename($attachment['real_filename']) . '</option>';
     790                        $s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>';
    755791                }
    756792
     
    786822                {
    787823                        $hidden = '';
    788                         $attach_row['real_filename'] = basename($attach_row['real_filename']);
     824                        $attach_row['real_filename'] = utf8_basename($attach_row['real_filename']);
    789825
    790826                        foreach ($attach_row as $key => $value)
     
    796832
    797833                        $template->assign_block_vars('attach_row', array(
    798                                 'FILENAME'                      => basename($attach_row['real_filename']),
    799                                 'A_FILENAME'            => addslashes(basename($attach_row['real_filename'])),
     834                                'FILENAME'                      => utf8_basename($attach_row['real_filename']),
     835                                'A_FILENAME'            => addslashes(utf8_basename($attach_row['real_filename'])),
    800836                                'FILE_COMMENT'          => $attach_row['attach_comment'],
    801837                                'ATTACH_ID'                     => $attach_row['attach_id'],
     
    819855* Load Drafts
    820856*/
    821 function load_drafts($topic_id = 0, $forum_id = 0, $id = 0)
     857function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $msg_id = 0)
    822858{
    823859        global $user, $db, $template, $auth;
     
    912948                        // Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
    913949                        $link_pm = true;
    914                         $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d={$draft['draft_id']}");
     950                        $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d={$draft['draft_id']}" . (($pm_action) ? "&amp;action=$pm_action" : '') . (($msg_id) ? "&amp;p=$msg_id" : ''));
    915951                }
    916952
     
    945981                        " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . '
    946982                        ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '
     983                        ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . '
    947984                ORDER BY p.post_time ';
    948985        $sql .= ($mode == 'post_review') ? 'ASC' : 'DESC';
     
    9631000        }
    9641001
     1002        // Handle 'post_review_edit' like 'post_review' from now on
     1003        if ($mode == 'post_review_edit')
     1004        {
     1005                $mode = 'post_review';
     1006        }
     1007
    9651008        $sql = $db->sql_build_query('SELECT', array(
    966                 'SELECT'        => 'u.username, u.user_id, u.user_colour, p.*',
     1009                'SELECT'        => 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe',
    9671010
    9681011                'FROM'          => array(
    9691012                        USERS_TABLE             => 'u',
    9701013                        POSTS_TABLE             => 'p',
     1014                ),
     1015
     1016                'LEFT_JOIN'     => array(
     1017                        array(
     1018                                'FROM'  => array(ZEBRA_TABLE => 'z'),
     1019                                'ON'    => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
     1020                        )
    9711021                ),
    9721022
     
    10611111                $post_subject = censor_text($post_subject);
    10621112
     1113                $post_anchor = ($mode == 'post_review') ? 'ppr' . $row['post_id'] : 'pr' . $row['post_id'];
     1114                $u_show_post = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, "f=$forum_id&amp;t=$topic_id&amp;p={$row['post_id']}&amp;view=show#p{$row['post_id']}");
     1115
    10631116                $template->assign_block_vars($mode . '_row', array(
    10641117                        'POST_AUTHOR_FULL'              => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
     
    10681121
    10691122                        'S_HAS_ATTACHMENTS'     => (!empty($attachments[$row['post_id']])) ? true : false,
     1123                        'S_FRIEND'                      => ($row['friend']) ? true : false,
     1124                        'S_IGNORE_POST'         => ($row['foe']) ? true : false,
     1125                        'L_IGNORE_POST'         => ($row['foe']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), "<a href=\"{$u_show_post}\" onclick=\"dE('{$post_anchor}', 1); return false;\">", '</a>') : '',
    10701126
    10711127                        'POST_SUBJECT'          => $post_subject,
     
    11141170        if (!$topic_notification && !$forum_notification)
    11151171        {
    1116                 trigger_error('WRONG_NOTIFICATION_MODE');
     1172                trigger_error('NO_MODE');
    11171173        }
    11181174
     
    15021558        }
    15031559
     1560        if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post'))
     1561        {
     1562                $sql = 'SELECT 1 AS has_attachments
     1563                        FROM ' . ATTACHMENTS_TABLE . '
     1564                        WHERE topic_id = ' . $topic_id;
     1565                $result = $db->sql_query_limit($sql, 1);
     1566                $has_attachments = (int) $db->sql_fetchfield('has_attachments');
     1567                $db->sql_freeresult($result);
     1568
     1569                if (!$has_attachments)
     1570                {
     1571                        $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0';
     1572                }
     1573        }
     1574
    15041575//      $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
    15051576
     
    15531624/**
    15541625* Submit Post
     1626* @todo Split up and create lightweight, simple API for this.
    15551627*/
    1556 function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
     1628function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true)
    15571629{
    15581630        global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path;
     
    16061678
    16071679        // 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
     1680        // The variable name should be $post_approved, because it indicates if the post is approved or not
    16081681        $post_approval = 1;
    16091682
    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         {
     1683        // Check the permissions for post approval. Moderators are not affected.
     1684        if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']))
     1685        {
     1686                // Post not approved, but in queue
    16131687                $post_approval = 0;
     1688        }
     1689
     1690        // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved
     1691        if (isset($data['force_approved_state']))
     1692        {
     1693                $post_approval = ($data['force_approved_state']) ? 1 : 0;
    16141694        }
    16151695
     
    17261806                                'topic_poster'                          => (int) $user->data['user_id'],
    17271807                                'topic_time'                            => $current_time,
     1808                                'topic_last_view_time'          => $current_time,
    17281809                                'forum_id'                                      => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
    17291810                                'icon_id'                                       => $data['icon_id'],
     
    17391820                        if (isset($poll['poll_options']) && !empty($poll['poll_options']))
    17401821                        {
     1822                                $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time;
     1823                                $poll_length = $poll['poll_length'] * 86400;
     1824                                if ($poll_length < 0)
     1825                                {
     1826                                        $poll_start = $poll_start + $poll_length;
     1827                                        if ($poll_start < 0)
     1828                                        {
     1829                                                $poll_start = 0;
     1830                                        }
     1831                                        $poll_length = 1;
     1832                                }
     1833
    17411834                                $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
    17421835                                        'poll_title'            => $poll['poll_title'],
    1743                                         'poll_start'            => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
     1836                                        'poll_start'            => $poll_start,
    17441837                                        'poll_max_options'      => $poll['poll_max_options'],
    1745                                         'poll_length'           => ($poll['poll_length'] * 86400),
     1838                                        'poll_length'           => $poll_length,
    17461839                                        'poll_vote_change'      => $poll['poll_vote_change'])
    17471840                                );
     
    17611854
    17621855                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' : '');
     1856                        $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ',
     1857                                topic_replies_real = topic_replies_real + 1,
     1858                                topic_bumped = 0,
     1859                                topic_bumper = 0' .
     1860                                (($post_approval) ? ', topic_replies = topic_replies + 1' : '') .
     1861                                ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');
     1862
    17641863                        $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' : '');
    17651864
     
    17721871                case 'edit_topic':
    17731872                case 'edit_first_post':
     1873                        if (isset($poll['poll_options']) && !empty($poll['poll_options']))
     1874                        {
     1875                                $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time;
     1876                                $poll_length = $poll['poll_length'] * 86400;
     1877                                if ($poll_length < 0)
     1878                                {
     1879                                        $poll_start = $poll_start + $poll_length;
     1880                                        if ($poll_start < 0)
     1881                                        {
     1882                                                $poll_start = 0;
     1883                                        }
     1884                                        $poll_length = 1;
     1885                                }
     1886                        }
    17741887
    17751888                        $sql_data[TOPICS_TABLE]['sql'] = array(
     
    17821895                                'topic_time_limit'                      => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
    17831896                                '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,
     1897                                'poll_start'                            => (isset($poll['poll_options'])) ? $poll_start : 0,
    17851898                                'poll_max_options'                      => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,
    1786                                 'poll_length'                           => (isset($poll['poll_options'])) ? ($poll['poll_length'] * 86400) : 0,
     1899                                'poll_length'                           => (isset($poll['poll_options'])) ? $poll_length : 0,
    17871900                                'poll_vote_change'                      => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,
     1901                                'topic_last_view_time'          => $current_time,
    17881902
    17891903                                'topic_attachment'                      => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0),
     
    18111925                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);
    18121926
    1813                                 set_config('num_topics', $config['num_topics'] - 1, true);
    1814                                 set_config('num_posts', $config['num_posts'] - ($topic_row['topic_replies'] + 1), true);
     1927                                set_config_count('num_topics', -1, true);
     1928                                set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true);
    18151929
    18161930                                // Only decrement this post, since this is the one non-approved now
     
    18291943                        if (!$post_approval && $data['post_approved'])
    18301944                        {
    1831                                 $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1';
     1945                                $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
    18321946                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
    18331947
    1834                                 set_config('num_posts', $config['num_posts'] - 1, true);
     1948                                set_config_count('num_posts', -1, true);
    18351949
    18361950                                if ($auth->acl_get('f_postcount', $data['forum_id']))
     
    20732187                        {
    20742188                                // insert attachment into db
    2075                                 if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
     2189                                if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
    20762190                                {
    20772191                                        continue;
     
    20992213                if ($space_taken && $files_added)
    21002214                {
    2101                         set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
    2102                         set_config('num_files', $config['num_files'] + $files_added, true);
     2215                        set_config_count('upload_dir_size', $space_taken, true);
     2216                        set_config_count('num_files', $files_added, true);
    21032217                }
    21042218        }
     
    23332447                if ($post_mode == 'post')
    23342448                {
    2335                         set_config('num_topics', $config['num_topics'] + 1, true);
    2336                         set_config('num_posts', $config['num_posts'] + 1, true);
     2449                        set_config_count('num_topics', 1, true);
     2450                        set_config_count('num_posts', 1, true);
    23372451                }
    23382452
    23392453                if ($post_mode == 'reply')
    23402454                {
    2341                         set_config('num_posts', $config['num_posts'] + 1, true);
     2455                        set_config_count('num_posts', 1, true);
    23422456                }
    23432457        }
     
    23772491
    23782492        // Index message contents
    2379         if ($update_message && $data['enable_indexing'])
     2493        if ($update_search_index && $data['enable_indexing'])
    23802494        {
    23812495                // Select the search method and do some additional checks to ensure it can actually be utilised
     
    24122526                        $db->sql_query($sql);
    24132527                }
    2414                 else if ($data['notify_set'] && !$data['notify'])
     2528                else if (($config['email_enable'] || $config['jab_enable']) && $data['notify_set'] && !$data['notify'])
    24152529                {
    24162530                        $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
     
    24292543        // Mark this topic as read
    24302544        // 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());
     2545        markread('topic', (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $data['topic_id'], time());
    24322546
    24332547        //
     
    24372551                        FROM ' . FORUMS_TRACK_TABLE . '
    24382552                        WHERE user_id = ' . $user->data['user_id'] . '
    2439                                 AND forum_id = ' . $data['forum_id'];
     2553                                AND forum_id = ' . (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']);
    24402554                $result = $db->sql_query($sql);
    24412555                $f_mark_time = (int) $db->sql_fetchfield('mark_time');
     
    24502564        {
    24512565                // Update forum info
    2452                 $sql = 'SELECT forum_last_post_time
    2453                         FROM ' . FORUMS_TABLE . '
    2454                         WHERE forum_id = ' . $data['forum_id'];
     2566                if ($topic_type == POST_GLOBAL)
     2567                {
     2568                        $sql = 'SELECT MAX(topic_last_post_time) as forum_last_post_time
     2569                                FROM ' . TOPICS_TABLE . '
     2570                                WHERE forum_id = 0';
     2571                }
     2572                else
     2573                {
     2574                        $sql = 'SELECT forum_last_post_time
     2575                                FROM ' . FORUMS_TABLE . '
     2576                                WHERE forum_id = ' . $data['forum_id'];
     2577                }
    24552578                $result = $db->sql_query($sql);
    24562579                $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
    24572580                $db->sql_freeresult($result);
    24582581
    2459                 update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false);
     2582                update_forum_tracking_info((($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $forum_last_post_time, $f_mark_time, false);
    24602583        }
    24612584
Note: See TracChangeset for help on using the changeset viewer.