Location: PHPKode > projects > Gnew > Gnew-2013.1/comments/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['COMMENTS_EDIT']);

// Comments in news enabled?
if ($settings['news_commenting'] == 0)
{
    error_template($lang['ERROR_COMMENTING_DISABLED']);
}
// From edit form?
elseif (isset($_POST['edit']) || isset($_POST['preview_edited']))
{
    $error = '';
    if (!trim($_POST['comment_subject']))
    {
        $error .= $lang['ERROR_NO_SUBJECT'];
    }
    if (!trim($_POST['comment_text']))
    {
        $error .= $lang['ERROR_NO_TEXT'];
    }
    // Story expiry
    if (!empty($_POST['story_id']))
    {
        $sql->query('SELECT MAX(comment_creation) AS last_comment
                     FROM ' . TABLE_COMMENTS . '
                     WHERE story_id = \'' . $_POST['story_id'] . '\'');
        $table_comments = $sql->fetch();
        if (($table_comments['last_comment'] + (60 * 60 * 24 * $settings['stories_expiry'])) < time())
        {
            $error .= sprintf($lang['ERROR_STORY_EXPIRY'], $settings['stories_expiry']);
        }
    }
    if ($error)
    {
        error_template($error);
    }
    else
    {
        $comment_subject = utf8_entities($_POST['comment_subject']);
        if ($settings['allow_html'])
        {
            $comment_text2 = do_html($_POST['comment_text']);
        }
        else
        {
            $comment_text2 = utf8_entities($_POST['comment_text']);
        }
        $comment_text = $comment_text2;
        $comment_text2 = make_clickable($comment_text2);
        $comment_text2 = do_bbcodes($comment_text2);
        if ($settings['allow_emoticons'])
        {
            $comment_text2 = do_emoticons($comment_text2);
        }
        // Preview form
        if (isset($_POST['preview_edited']))
        {
            // remove_form_data();
            $comment_text2 = undo_escape_sequences($comment_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_edited', 'comments/preview_edited.htpl');
            $template->set_var(array('COMMENT_CREATION' => $_POST['comment_creation'],
                                     'COMMENT_EDITED' => sprintf($lang['EDITED_BY'], $_SESSION['user_id'], $users['user_name'], format_date(time())),
                                     'COMMENT_ID' => $_POST['comment_id'],
                                     'COMMENT_POSTED' => sprintf($lang['POSTED_BY'], $_SESSION['user_id'], $users['user_name'], format_date($_POST['comment_creation'])),
                                     'COMMENT_SUBJECT' => $_POST['comment_subject'],
                                     'COMMENT_TEXT' => $comment_text,
                                     'COMMENT_TEXT2' => $comment_text2,
                                     'EMOTICONS_LIST' => get_emoticons_list(0),
                                     'HTML_SUPPORT' => $html_support,
                                     'NEWS_ID' => $_POST['news_id'],
                                     'STORY_ID' => $_POST['story_id'],
                                     'USER_AVATAR' => $users['user_avatar'],
                                     'USER_SIGNATURE' => $user_signature));
            $template->parse('preview_edited');
        }
        // Add form
        else
        {
            $sql->query('UPDATE ' . TABLE_COMMENTS . '
                         SET comment_subject = \'' . $comment_subject . '\', comment_text = \'' . $comment_text2 . '\', comment_edition = \'' . time() . '\', edition_id = \'' . $_SESSION['user_id'] . '\', edition_name = \'' . $users['user_name'] . '\'
                         WHERE comment_id = \'' . $_POST['comment_id'] . '\'');
            make_comments_feed();
            $GLOBALS['cache']->clean(TABLE_COMMENTS);
            success_template($lang['COMMENT_EDITED'], './../comments/index.php?news_id=' . $_POST['news_id'] . '&story_id=' . $_POST['story_id']);
        }
    }
}
// Edit form
else
{
    // Check query
    if (!empty($_GET['comment_id']) && string_is_int($_GET['comment_id']))
    {
        $sql->query('SELECT story_id, news_id, comment_subject, comment_text, comment_creation
                     FROM ' . TABLE_COMMENTS . '
                     WHERE comment_id = \'' . $_GET['comment_id'] . '\'
                     AND comment_active = \'1\'
                     AND user_id = \'' . $_SESSION['user_id'] . '\'');
        $table_comments = $sql->fetch();
        // Check comment
        if (!$table_comments['story_id'])
        {
            error_template($lang['ERROR_COMMENT_EDIT']);
        }
        else
        {
            if ($settings['allow_html'])
            {
                $html_support = $lang['HTML_ENABLED'];
            }
            else
            {
                $html_support = $lang['HTML_DISABLED'];
            }
            $comment_text = undo_emoticons($table_comments['comment_text']);
            $comment_text = undo_bbcodes($comment_text);
            $template->set_file('edit', 'comments/edit.htpl');
            $template->set_var(array('COMMENT_CREATION' => $table_comments['comment_creation'],
                                     'COMMENT_ID' => $_GET['comment_id'],
                                     'COMMENT_SUBJECT' => $table_comments['comment_subject'],
                                     'COMMENT_TEXT' => $comment_text,
                                     'EMOTICONS_LIST' => get_emoticons_list(0),
                                     'HTML_SUPPORT' => $html_support,
                                     'NEWS_ID' => $table_comments['news_id'],
                                     'STORY_ID' => $table_comments['story_id']));
            $template->parse('edit', null, false, array(TABLE_COMMENTS, TABLE_EMOTICONS));
        }
    }
    else
    {
        error_template($lang['ERROR_NO_DATA']);
    }
}

page_footer();

?>
Return current item: Gnew