Código:
<!-- (c) 2003 PHPNews - http://newsphp.sourceforge.net/ -->
<?php
error_reporting (E_ALL ^ E_NOTICE);
/*********************************************
* ------------ *
* | News.php | *
* ------------ *
* PHPNews - Beta 1.2.0 *
* Open Source Project started by Pierce Ward *
* *
* Software Distributed at: *
* http://newsphp.sourceforge.net *
* ========================================== *
* (c) 2003 Pierce Ward (Big P) *
* All rights reserved. *
* ========================================== *
* This program has been written under the *
* terms of the GNU General Public Licence as *
* published by the Free Software Foundation. *
* *
* The GNU GPL can be found in gpl.txt *
*********************************************/
/* Get the absolute path for including files */
$path = __FILE__;
$path = str_replace('news.php', '', $path);
include_once($path . 'settings.php');
/* Don't edit - Connects to DB */
$dbcon = mysql_connect($db_server, $db_user, $db_passwd);
mysql_select_db($db_name);
/* Grabs Settings and puts it in an Array */
$result = mysql_query('SELECT variable,value FROM ' . $db_prefix . 'settings');
$Settings = array();
while ($row = mysql_fetch_array($result))
{
$Settings[$row['0']] = $row['1'];
}
$lang = $Settings['language'];
/* Opens language file */
if(!file_exists($path . 'languages/' . $lang . '.news.lng'))
{
include_once($path . 'languages/en_GB.news.lng');
}
else
{
include_once($path . 'languages/' . $lang . '.news.lng');
}
$language = $lng;
if(!isset($_GET['action']))
{
news();
}
else if($_GET['action'] == 'fullnews')
{
fullNews();
}
else if($_GET['action'] == 'post')
{
post();
}
else if($_GET['action'] == 'showcat' && isset($_GET['catid']))
{
showCat();
}
function news()
{
global $Settings, $language, $_SERVER, $path, $db_prefix;
/* Prints JavaScript for Send to Friend Link */
if ($Settings['enablestf'] == 1)
{
?>
<script type="text/javascript">
<!--
function sendtof(desktopURL)
{
desktop = window.open(desktopURL, "SendToFriend", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=400,height=275,resizable=no");
}
// -->
</script>
<?
}
/* Set up Previous/Next links if enabled */
if ($Settings['enableprevnext'] == 1)
{
/* If we're on the first page set defaults */
if (!isset($_GET['prevnext']) || $_GET['prevnext'] == 0)
{
$_GET['prevnext'] = 0;
$nextpage = $_GET['prevnext'] + $Settings['numtoshow'];
$previouspage = $_GET['prevnext'];
/* Find total number of News Posts */
$numPosts = mysql_query('SELECT count(*) as total FROM ' . $db_prefix . 'news');
$var = mysql_fetch_assoc($numPosts);
if ($var['total'] > $Settings['numtoshow'])
{
$include = 1;
}
}
/* Otherwise calculate prev/next links */
else if (isset($_GET['prevnext']) && is_Numeric($_GET['prevnext']))
{
$previouspage = $_GET['prevnext'] - $Settings['numtoshow'];
/* Find total number of News Posts */
$numPosts = mysql_query('SELECT count(*) as total FROM ' . $db_prefix . 'news');
$var = mysql_fetch_assoc($numPosts);
/* If the number of posts is greater, there's enough room for another page */
if ($var['total'] > ($_GET['prevnext'] + $Settings['numtoshow']))
{
$nextpage = $_GET['prevnext'] + $Settings['numtoshow'];
}
else
{
$nextpage = 0;
}
/* Include Previous/Next Template */
$include = 1;
}
}
else
{
$_GET['prevnext'] = 0;
}
/* Get information about the News Post */
$SQL_query = mysql_query('SELECT n.id,n.posterid,n.postername,n.time,n.subject,n.titletext,n.maintext,n.catid,p.username,p.email,p.avatar,c.catname,c.caticon'
. ' FROM ' . $db_prefix . 'news AS n'
. ' LEFT JOIN ' . $db_prefix . 'posters AS p ON(n.posterid=p.id)'
. ' LEFT JOIN ' . $db_prefix . 'categories AS c ON(n.catid=c.id)'
. ' WHERE n.trusted = 1'
. ' ORDER by n.id DESC'
. ' LIMIT ' . $_GET['prevnext'] . ', ' . $Settings['numtoshow'] . '');
while($news = mysql_fetch_assoc($SQL_query))
{
/* Set Variables */
$time = strftime($Settings['timeformat'], $news['time']);
$subject = stripslashes($news['subject']);
$titletext = stripslashes($news['titletext']);
$maintext = stripslashes($news['maintext']);
/* Print Comments if enabled */
if ($Settings['enablecomments'] == 1)
{
$query2 = mysql_query('SELECT count(*) as total FROM ' . $db_prefix . 'comments WHERE mid = ' . $news['id'] . '');
$var = mysql_fetch_assoc($query2);
$comments = '<a href="' . $_SERVER['PHP_SELF'] . '?action=fullnews&showcomments=1&id=' . $news['id'] . '">' . $language['CONTENT_NEWSCOMMENTS'] . ' (' . $var['total'] . ')</a>';
}
/* If Categories are enabled... */
if ($Settings['enablecats'] == 1)
{
if ($news['catid'] != 0)
{
if ($news['catname'] != '')
{
$category = '<a href="' . $_SERVER['PHP_SELF'] . '?action=showcat&catid=' . $news['catid'] . '">' . $news['catname'] . '</a>';
}
if ($news['caticon'] != '')
{
$caticon = '<img src="' . $news['caticon'] . '" border="0" alt="' . $news['catname'] . '" />';
}
}
}
/* Set the News Posters Username */
$username = $news['username'];
if (!$username)
{
$username = $news['postername'];
}
/* Get the Posters Avatar */
if ($Settings['enableavatars'] == 1)
{
if($news['avatar'] != '')
{
$avatar = '<img src="' . $news['avatar'] . '" border="0" alt="' . $username . '\'s avatar" />';
}
else
{
$avatar = '';
}
}
/* Set an email address? Apply it to the Username */
if ($news['email'] != '')
{
$username = '<a href="mailto:' . $news['email'] . '">' . $username . '</a>';
}
else
{
$username = $username;
}
/* Display link to show comments & news if enabled */
if ($maintext != '' && $Settings['showcominnews'] == 1 && $Settings['enablecomments'] == 1)
{
$maintext = '<a href="' . $_SERVER['PHP_SELF'] . '?action=fullnews&showcomments=1&id=' . $news['id'] . '">' . $language['CONTENT_NEWSFULLSTORY'] . '</a>';
}
else if ($maintext != '')
{
$maintext = '<a href="' . $_SERVER['PHP_SELF'] . '?action=fullnews&id=' . $news['id'] . '">' . $language['CONTENT_NEWSFULLSTORY'] . '</a>';
}
else
{
$maintext = '';
}
if ($Settings['enablestf'] == 1)
{
$sendtofriend = '<a href="javascript:sendtof(\'' . $Settings['phpnewsurl'] . 'sendtofriend.php?mid=' . $news['id'] . '\')">' . $language['CONTENT_NEWSSTFLINK'] . '</a>';
}
/* Parse the code / smilies */
$maintext = parseCode($maintext);
$titletext = parseCode($titletext);
include($path . 'templates/news_temp.php');
echo "\n";
/* Clear Variables */
$category = '';
$caticon = '';
}
/* If previous/next links are enabled */
if ($Settings['enableprevnext'] == 1 && $include == 1)
{
echo '<br />' , "\n";
/* Show Previous Page link? */
if($_GET['prevnext'] != NULL && $_GET['prevnext'] != 0)
{
echo '<span style="margin-right:5px;"><a href="' , $_SERVER['PHP_SELF'] , '?prevnext=' , $previouspage , '">' , $language['CONTENT_PREVIOUS'] , '</a></span>';
echo "\n";
}

