Location: PHPKode > projects > Gnew > Gnew-2013.1/posts/edit.php
<?php
// -----------------------------------------------------------------------------
// $Id: edit.php 682 2013-03-28 14:17:41Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

include('./../includes/common.php');

page_header($lang['POSTS_EDIT']);

// From edit form?
if (isset($_POST['edit']) || isset($_POST['preview_edited']))
{
    $error = '';
    if (!trim($_POST['post_text']))
    {
        $error .= $lang['ERROR_NO_TEXT'];
    }
    // Thread expiry
    if (!empty($_POST['thread_id']))
    {
        $sql->query('SELECT MAX(post_creation) AS last_post
                     FROM ' . TABLE_POSTS . '
                     WHERE thread_id = \'' . $_POST['thread_id'] . '\'');
        $table_posts = $sql->fetch();
        if (($table_posts['last_post'] + (60 * 60 * 24 * $settings['threads_expiry'])) < time())
        {
            $error .= sprintf($lang['ERROR_THREAD_EXPIRY'], $settings['threads_expiry']);
        }
    }
    if ($error)
    {
        error_template($error);
    }
    else
    {
        if ($settings['allow_html'])
        {
            $post_text2 = do_html($_POST['post_text']);
        }
        else
        {
            $post_text2 = utf8_entities($_POST['post_text']);
        }
        $post_text = $post_text2;
        $post_text2 = make_clickable($post_text2);
        $post_text2 = do_bbcodes($post_text2);
        if ($settings['allow_emoticons'])
        {
            $post_text2 = do_emoticons($post_text2);
        }
        // Preview form
        if (isset($_POST['preview_edited']))
        {
            // remove_form_data();
            $post_text2 = undo_escape_sequences($post_text2);
            if ($settings['allow_html'])
            {
                $html_support = $lang['HTML_ENABLED'];
            }
            else
            {
                $html_support = $lang['HTML_DISABLED'];
            }
            if (!empty($users['user_signature']))
            {
                $user_signature = '<br />&#45;&#45;<br />' . $users['user_signature'];
            }
            else
            {
                $user_signature = '';
            }
            $template->set_file('preview', 'posts/preview_edited.htpl');
            $template->set_var(array('CATEGORY_ID' => $_POST['category_id'],
                                     'EMOTICONS_LIST' => get_emoticons_list(0),
                                     'HTML_SUPPORT' => $html_support,
                                     'POST_CREATION' => $_POST['post_creation'],
                                     'POST_EDITED' => sprintf($lang['EDITED_BY'], $_SESSION['user_id'], $users['user_name'], format_date(time())),
                                     'POST_ID' => $_POST['post_id'],
                                     'POST_POSTED' => sprintf($lang['POSTED_BY'], $_SESSION['user_id'], $users['user_name'], format_date($_POST['post_creation'])),
                                     'POST_SUBJECT' => $_POST['post_subject'],
                                     'POST_TEXT' => $post_text,
                                     'POST_TEXT2' => $post_text2,
                                     'THREAD_ID' => $_POST['thread_id'],
                                     'USER_AVATAR' => $users['user_avatar'],
                                     'USER_SIGNATURE' => $user_signature));
            $template->parse('preview');
        }
        else
        {
            $sql->query('UPDATE ' . TABLE_POSTS . '
                         SET post_text = \'' . $post_text2 . '\', post_edition = \'' . time() . '\', edition_id = \'' . $_SESSION['user_id'] . '\', edition_name = \'' . $users['user_name'] . '\'
                         WHERE post_id = \'' . $_POST['post_id'] . '\'');
            make_posts_feed();
            $GLOBALS['cache']->clean(TABLE_POSTS);
            success_template($lang['POST_EDITED'], './../posts/read.php?category_id=' . $_POST['category_id'] . '&thread_id=' . $_POST['thread_id']);
        }
    }
}
// Edit form
else
{
    // Check query
    if (!empty($_GET['post_id']) && string_is_int($_GET['post_id']))
    {
        $sql->query('SELECT thread_id, category_id, post_active, post_subject, post_text, post_creation
                     FROM ' . TABLE_POSTS . '
                     WHERE post_id = \'' . $_GET['post_id'] . '\'
                     AND user_id = \'' . $_SESSION['user_id'] . '\'');
        $table_posts = $sql->fetch();
        // Check author
        if (!$table_posts['thread_id'])
        {
            error_template($lang['ERROR_POST_EDIT']);
        }
        else
        {
            // Closed thread?
            if ($table_posts['post_active'] == 0)
            {
                error_template($lang['ERROR_THREAD_CLOSED']);
            }
            else
            {
                if ($settings['allow_html'])
                {
                    $html_support = $lang['HTML_ENABLED'];
                }
                else
                {
                    $html_support = $lang['HTML_DISABLED'];
                }
                $post_text = undo_emoticons($table_posts['post_text']);
                $post_text = undo_bbcodes($post_text);
                $template->set_file('edit', 'posts/edit.htpl');
                $template->set_var(array('CATEGORY_ID' => $table_posts['category_id'],
                                         'EMOTICONS_LIST' => get_emoticons_list(0),
                                         'HTML_SUPPORT' => $html_support,
                                         'POST_CREATION' => $table_posts['post_creation'],
                                         'POST_ID' => $_GET['post_id'],
                                         'POST_SUBJECT' => $table_posts['post_subject'],
                                         'POST_TEXT' => $post_text,
                                         'THREAD_ID' => $table_posts['thread_id']));
                $template->parse('edit', null, false, array(TABLE_POSTS, TABLE_EMOTICONS));
            }
        }
    }
    else
    {
        error_template($lang['ERROR_NO_DATA']);
    }
}

page_footer();

?>
Return current item: Gnew