Location: PHPKode > projects > Gnew > Gnew-2013.1/articles/index.php
<?php
// -----------------------------------------------------------------------------
// $Id: index.php 676 2013-03-27 13:38:34Z 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['ARTICLES_INDEX']);

// Query string - ?category_id=&page=&list=
if (!empty($_GET['category_id']) && string_is_int($_GET['category_id']))
{
    $clause = 'WHERE t1.category_id = \'' . $_GET['category_id'] . '\'';
    $query = 'category_id=' . $_GET['category_id'] . '&amp;';
}
else
{
    $clause = '';
    $query = '';
}

// Pages list creation - start
if (empty($_GET['page']) || !string_is_int($_GET['page']))
{
    $_GET['page'] = 1;
}
$articles_offset = ($_GET['page'] - 1) * $settings['articles_per_page'];

$template->set_file('index', 'articles/index.htpl');
$template->set_block('index', 'ARTICLES_BLOCK', 'articles');
$sql->query('SELECT t1.article_id, t1.category_id, t1.article_subject, t1.article_creation, t1.article_edition, t2.category_name
             FROM ' . TABLE_ARTICLES . ' AS t1
             INNER JOIN ' . TABLE_CATEGORIES . ' AS t2
                         ON (t2.category_id = t1.category_id AND t2.category_level IN (\'1\', \'4\'))
             ' . $clause . '
             ORDER BY ' . $settings['articles_sorting'] . ' ' . $settings['articles_order'] . '
             LIMIT ' . $settings['articles_per_page'] . ' OFFSET ' . $articles_offset);
while ($table_articles = $sql->fetch())
{
    if (!empty($_GET['category_id']) && string_is_int($_GET['category_id']))
    {
        $categories_header = '&lt; <a href="./../articles/index.php" title="' . $lang['CATEGORIES'] . '">' . $lang['CATEGORIES'] . '</a>';
        $category_name = $table_articles['category_name'];
    }
    else
    {
        $categories_header = $lang['CATEGORIES'];
        $category_name = '<a href="./../articles/index.php?category_id=' . $table_articles['category_id'] . '" title="' . $table_articles['category_name'] . '">' . $table_articles['category_name'] . '</a>';
    }
    if ($table_articles['article_edition'])
    {
        $article_edition = format_date($table_articles['article_edition']);
    }
    else
    {
        $article_edition = '';
    }
    $template->set_var(array('ARTICLE_CREATION' => format_date($table_articles['article_creation']),
                             'ARTICLE_EDITION' => $article_edition,
                             'ARTICLE_ID' => $table_articles['article_id'],
                             'ARTICLE_SUBJECT' => $table_articles['article_subject'],
                             'CATEGORIES_HEADER' => $categories_header,
                             'CATEGORY_NAME' => $category_name));
    $template->parse('ARTICLES_BLOCK', 'articles', true);
    $articles_exist = true;
}

if (isset($articles_exist))
{
    // Pages list creation - end
    $sql->query('SELECT t1.article_id
                 FROM ' . TABLE_ARTICLES . ' AS t1
                 INNER JOIN ' . TABLE_CATEGORIES . ' AS t2
                             ON (t2.category_id = t1.category_id AND t2.category_level IN (\'1\', \'4\'))
                 ' . $clause);
    $num_articles = $sql->num_rows();
    $num_pages = ceil($num_articles / $settings['articles_per_page']);
    $pages_list = get_pages_list('./../articles/index.php?' . $query, $num_pages);

    $template->set_var('PAGES', sprintf($lang['PAGES'], $pages_list));
    $template->parse('index', null, false, array(TABLE_ARTICLES, TABLE_CATEGORIES));
}
else
{
    error_template($lang['ERROR_NO_ARTICLE']);
}

page_footer();

?>
Return current item: Gnew