Code:
<?
/* copywrited @EasyPHPNews , davehusk.com */
$max_posts = "5";
$news_dir = 'news_articles';
$news_post_summary = 'news_dynamic_summary.html';
//after adding new news attemp to load page name? if none will, show add again.
$_PAGE = '';
//ones below, blank if no, , use ?admin=news to add news
$max_posts_button = '';
$show_add_link = '';
$password = '';
$rempass = '1';
//coment out to not use the paging...or take out the 1
$paging = '1';
$paging_add_link_top = '1';
$paging_add_link_bottom = '1';
// end config, templates below, aprox line 51, 52
if (!is_dir($news_dir)){
echo "The dir <b>\"$news_dir\"</b> does not exist, make and chmod to 0777";
exit;
}
if(!isset($_SERVER['REQUEST_URI'])) {
if(isset($_SERVER['SCRIPT_NAME']))
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
else
$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']){
$_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
}
}
if ($_POST['Add']){
$c_passwd = eregi_replace("[^A-Z,0-9,_]", '', $_POST['passwd']);
if($c_passwd == $password){
$news_post_id = date("Y-m-d-H")."_".time(true);
$news_post_url = $news_post_id.".html";
$PostedBy = stripslashes($_POST['PostedBy']);
$news_body = preg_replace("/\\\'/","'",$_POST['news_body']);
$bs = "\\";
$f = "/$bs$bs$bs$bs/";
$r = $bs;
$news_body = stripslashes(preg_replace($f,$r,$news_body));
$summary = stripslashes($_POST['summary']);
$subject = stripslashes($_POST['subject']);
//templates
$summary_page = "<b><a href='SERVER_REQUEST_URI&view_news=$news_post_id'>$subject</a></b> <font size=1>($PostedBy)</font><br><font size=1>Summary: </font> $summary \n\n<br><BR>";
$news_post_body = "<table border='0' width='100%' cellPadding='0' cellSpacing='1' style='border:#ff0066 1px solid; margin:15px 0px'><tr><td style='padding:0px'><h1 style='margin:0px'>$subject</h1><div style='postition:absolute; width:877px; //width:884px; text-align:right; margin-top:-21px; color:white'>Published: $PostedBy</div></td></tr><tr><td style='padding:10px 15px'><!-- #BeginSnippet name='$PostedBy' -->$news_body<!-- #EndSnippet --></td></tr><tr><td align='center'><div style='width:100%; height:100%; border-top:1px solid #ff0066; padding:5px'><? echo pullRating('$news_post_id',true,false,true); ?></div></td></tr></table><br>";
function add_news_post($news_filename, $news){
global $subject, $date, $summary, $summaryp, $news_post_id, $news_body, $news_post_summary;
if(file_exists($news_filename)){
$fp = @fopen($news_filename, "r") or die ("Unable to open File $news_filename , check permissions");
$old_news = @fread($fp, filesize($news_filename)) or die ("Directory or File $news_filename not readable");
@fclose($fp);
}
$fp = @fopen($news_filename, "w");
@fwrite($fp, "<!--news_post-->\r\n$news\r\n$old_news") or die ("Directory or File $news_filename not writeable");
@fclose($fp);
}
if($subject != ""){
add_news_post("$news_dir/$news_post_summary", $summary_page);
add_news_post("$news_dir/$news_post_url", $news_post_body);
if($_PAGE) print '<html><head><META http-equiv="refresh" content="0;URL='.$_PAGE.'"></head><body></body></html>';
print 'Your News Article has been added. Please <B><A href="'.$_SERVER['PHP_SELF'].'" target="_top">Refresh</A></B> the page.<br><br> ';
}
} else {
echo '<p><b> Password is wrong! </b><br><br>';
}
}
if($_GET['admin']=="news") {
if($rempass)
$rempass2 = 'value="'.$_POST['passwd'].'"';
?>
<b>Add A News Article</b><br><br>
<form action="<?=$_SERVER['REQUST_URI'];?>" method="post">
<table border=0>
<input type=hidden name='passwd' <?=$rempass2?> size=50>
<tr> <td align="right"> <b>News Headline:</b> </td><td> <input type=text name="subject" size=50> </td></tr>
<tr> <td align="right"> <b>Date Published:</b> </td><td> <input size="50" name='PostedBy' value="<? echo date("F jS\, Y"); ?>"> </td></tr>
<tr> <td align="right" valign="top"> <b>News Summary:</b> </td><td> <textarea name="summary" rows=5 cols=50 wrap=soft></textarea> </td></tr>
<tr> <td align="right" valign="top"> <b>News Article:</b> </td><td> <textarea name="news_body" rows=15 cols=50></textarea> </td></tr>
<tr> <td align="right"> <b> </b> </td><td align="center"> <input type=submit name=Add value=Add News Article> </td></tr>
</table>
</form><br>
<?
} else
if (is_numeric($_POST['posts_max']))
$max_posts = $_POST['posts_max'];
elseif(is_numeric($_GET['pmax']))
$max_posts = $_GET['pmax'];
if($max_posts)
$pmax = 'pmax='.$max_posts;
print '<table width=100% border=0 cellspacing=1 cellpadding=1>';
$news_summaryf = $news_dir.'/'.$news_post_summary;
if(is_file($news_summaryf)){
$fh = @fopen($news_summaryf, "r") or die('Unable to open summary page...');
$old_news = @fread($fh, filesize($news_summaryf)) or die('Unable to read summary page...');
@fclose($fh);
$news_posts = explode("<!--news_post-->", $old_news);
$idv = 0;
$Page = $max_posts;
if($paging){
$pmax .= '&';
$Counted = count($news_posts);
$TotalPages = ceil( ($Counted - 1) / $max_posts);
//what page are we on?
if (is_numeric($_GET['P']) > 0)
$CurrentPage = $_GET['P'];
else
$CurrentPage = 1;
unset($Page_Numbers);
if($CurrentPage > 1)
$Page_Numbers = " <a href=\"?".$pmax."P=". ($CurrentPage - 1) ."\">« Previous</a> ";
for($x=1; $x < $TotalPages + 1; $x++) {
if ($x == $CurrentPage && $CurrentPage > 0)
$Page_Numbers .= ' <b> ' . $x . ' </b> | ';
else
$Page_Numbers .= ' <a href="?'.$pmax.'P='.$x.'">'.$x.'</a> | ';
}
if($CurrentPage < $TotalPages )
$Page_Numbers .= " <a href=\"?".$pmax."P=". ($CurrentPage + 1) ."\">Next »</a>\r\n ";
else $Page_Numbers = rtrim($Page_Numbers," |");
//echo 'Total:'. ($Counted - 1) .' <br>';
if($paging_add_link_top && $Page_Numbers)
echo '<tr><td colspan=2><font size=-3>Page(s): '.$Page_Numbers.'</font><br><br></td></tr>';
if($CurrentPage > 1)
$Page = ($CurrentPage) * $max_posts;
else
$Page = $max_posts;
$idv = $Page - $max_posts +1;
}
if(is_numeric($_GET['P']))
$P = 'P='.$_GET['P'];
echo '<tr><td valign="top" width=100%>';
for ($i = $idv; $max_posts; $i++) {
if ($i > $Page) {
break;
}
//SERVER_REQUEST_URI
$_SERVER_REQUST_URI = '?'.$pmax.$P;
$news_post = str_replace("SERVER_REQUEST_URI",$_SERVER_REQUST_URI,$news_posts[$i]);
echo $news_post;
unset($news_post);
}
// echo '</td>';
} else echo 'Summary page not found ' . $news_summary;
echo '</td></tr><tr><td width="100%" valign="top">';
if($_GET['view_news'])
if (!@include ($news_dir . '/' .$_GET['view_news']. '.html')) echo 'News not found';
echo '</td></tr>';
if($paging_add_link_bottom && $paging && $Page_Numbers)
echo '<tr><td colspan=2><font size=-3>Page(s): '.$Page_Numbers.'</font></td></tr>';
if ($max_posts_button)
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post"><tr><td width=20%><input name=posts_max size=3 value=5><input type=submit name=posts value=Posts></td></tr></form>';
if ($show_add_link)
echo '<tr><td width=20%><br><a href=?admin=news>Add A News Article</a></td></tr>';
?>
</tr>
</table>
<!---------------@EasyPHPNews , easyphpscripts.com------------------>
Bookmarks