Location: PHPKode > projects > GENU > GENU-2012.3/comments/whatsnew.php
<?php
// -----------------------------------------------------------------------
//
// $Id: whatsnew.php 177 2012-03-30 15:09:49Z raoul $
//
// Copyright (C) 2003-2012 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.
//
// -----------------------------------------------------------------------

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

page_header($lang['COMMENTS_WHATSNEW_TITLE']);

// User logged ?
if ($_SESSION['user_id'] != 0)
{
    $clause = '';
    $num_comments = $num_news = 0;
    $sql->query('SELECT COUNT(*) AS num_comments, news_id
                 FROM ' . TABLE_COMMENTS . '
                 WHERE comment_creation > ' . $users['user_lastvisit'] . '
                 GROUP BY news_id
                 ORDER BY news_id');
    while ($table_comments = $sql->fetch())
    {
        $num_comments += $table_comments['num_comments'];
        $num_news++;
        if ($num_news == 1)
        {
            $clause .= 'AND ' . TABLE_NEWS . '.news_id IN (\'' . $table_comments['news_id'] . '\'';
        }
        else
        {
            $clause .= ', \'' . $table_comments['news_id'] . '\'';
        }
    }
    $clause .= ')';
    // New comment(s) ?
    if ($num_comments > 0)
    {
        $date_format = get_date_format();
        $date_offset = get_date_offset();
        $template->set_file('whatsnew', 'comments/whatsnew.htpl');
        $template->set_block('whatsnew', 'NEWS_BLOCK', 'news');
        $sql->query('SELECT ' . TABLE_CATEGORIES . '.category_id, ' . TABLE_CATEGORIES . '.category_image, ' . TABLE_CATEGORIES . '.category_name, ' . TABLE_NEWS . '.news_comments, ' . TABLE_NEWS . '.news_date, ' . TABLE_NEWS . '.news_id, ' . TABLE_NEWS . '.news_source, ' . TABLE_NEWS . '.news_subject, ' . TABLE_NEWS . '.news_text, ' . TABLE_USERS . '.user_id, ' . TABLE_USERS . '.user_name
                     FROM ' . TABLE_CATEGORIES . ', ' . TABLE_NEWS . ', ' . TABLE_USERS . '
                     WHERE ' . TABLE_CATEGORIES . '.category_id = ' . TABLE_NEWS . '.category_id
                     AND ' . TABLE_CATEGORIES . '.category_level IN (\'0\', \'2\')
                     ' . $clause . '
                     AND ' . TABLE_NEWS . '.news_active = \'1\'
                     AND ' . TABLE_NEWS . '.user_id = ' . TABLE_USERS . '.user_id
                     ORDER BY ' . $settings['news_order'] . ' DESC');
        while ($table_news = $sql->fetch())
        {
            $news_date = date($date_format, ($table_news['news_date'] + $date_offset));
            if ($table_news['news_source'])
            {
                $news_source = undo_escape_sequences($table_news['news_source']);
                $news_source = sprintf($lang['NEWS_INDEX_SOURCE'], $news_source);
            }
            else
            {
                $news_source = '<!-- empty -->';
            }
            $news_text = undo_escape_sequences($table_news['news_text']);
            $news_text = cut_text($news_text, './../news/index.php?news_id=' . $table_news['news_id']);
            $template->set_var(array('CATEGORY_ID' => $table_news['category_id'],
                                     'CATEGORY_IMAGE' => $table_news['category_image'],
                                     'CATEGORY_NAME' => $table_news['category_name'],
                                     'NEWS_COMMENTS' => $table_news['news_comments'],
                                     'NEWS_ID' => $table_news['news_id'],
                                     'NEWS_INDEX_COMMENT' => $lang['NEWS_INDEX_COMMENT'],
                                     'NEWS_INDEX_SEND' => $lang['NEWS_INDEX_SEND'],
                                     'NEWS_RELEASE' => sprintf($lang['NEWS_INDEX_RELEASE'], $table_news['user_id'], $table_news['user_name'], $news_date),
                                     'NEWS_SOURCE' => $news_source,
                                     'NEWS_SUBJECT' => $table_news['news_subject'],
                                     'NEWS_TEXT' => $news_text));
            $template->parse('NEWS_BLOCK', 'news', true);
        }
        $template->set_var(array('BACK_HOME' => $lang['BACK_HOME'],
                                 'COMMENTS_WHATSNEW_HEADER' => sprintf($lang['COMMENTS_WHATSNEW_HEADER'], $num_comments, $num_news)));
        $template->parse('whatsnew');
    }
    else
    {
        error_template($lang['COMMENTS_WHATSNEW_ERROR1']);
    }
}
else
{
    error_template($lang['COMMENTS_WHATSNEW_ERROR2']);
}

page_footer();

?>
Return current item: GENU