finishing touches for my project news. please help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



finishing touches for my project news. please help
the requirements are the following for the news.class.php:

1. In index page, it must display 5 contents per page and sorted in 
descending oder base on submitDate of the content. 

2. And the index page, must contain paging/ pagination at the lower 
right portion

here are the codes:
news.class.php
<?php
class news{
var $newsDir = "news";
var $newsList;
var $newsCount = -1;
function getNewsList( ){
$this->newslist = array();
if ($handle = @opendir($this- >newsDir) ) {
while ($file = readdir($handle) ) {
if (!is_dir($file) ) {
$this->newsList[ ] = $file;
}
}
}
rsort($this- >newsList) ;
return $this->newsList;
}
function getNewsCount( ){
}
function displayNews( ){
$list = $this->getNewsList( );
echo "<table class='newsList' >";
foreach($list as $value){
$newsData = file($this-
>newsDir.DIRECTORY_ SEPARATOR. $value);
$newsTitle = $newsData[0] ;
$submitDate = $newsData[1] ;
unset($newsData[ '0']);
unset($newsData[ '1']);
$newsContent = "";
foreach($newsData as $value){
$newsContent. =$value;
}
echo "<tr><th align='left' >$newsTitle< /th>";
echo "<tr><td 
colspan='2'> ".$newsContent. "<br/><td/ ></tr>";
echo "<th 
class='right' >$submitDate< /th></tr> ";
}
}
function displayAddForm( ){
?>
<script language="javascrip t" type="text/javascri pt" 
src="js/tiny_ mce.js">< /script>
<script language="javascrip t" type="text/javascri pt">
tinyMCE.init( {
mode : "textareas",
theme : "advanced",
theme_advanced_ buttons3 : "",
theme_advanced_ toolbar_align : "center",
theme_advanced_ toolbar_location : "top",
});
</script>
<form class="iform" action="<?php echo $_SERVER
['PHP_SELF'] ; ?>" method="post" >
News title: <br/>
<input type="text" name="title" size="40" /><br/><br/>
Content:<br/ >
<textarea name="newstext" rows="15" 
cols="67"></ textarea> <br/>
<center><input type="submit" name="submit" 
value="Save" ></center>
</form>
<?php
}
function insertNews() {
$newsTitle =isset($_POST[ 'title']) ? $_POST
['title'] : 'Untitled';
$submitDate = date('Y-m-d g:i:s A');
$newsContent = isset($_POST[ 'newstext' ])? $_POST
['newstext'] :'No content';
$filename = date('YmdHis' );
if(!file_exists( $this->newsDir) ){
mkdir($this- >newsDir) ;
}
$f = fopen($this-
>newsDir.DIRECTORY_ SEPARATOR. $filename. ".txt","w+ ");
fwrite($f,$newsTitl e."\n");
fwrite($f,$submitDa te."\n");
fwrite($f,$newsCont ent."\n") ;
fclose($f);
header('Location: index.php' );
}
}
?>


here is index.php:
<?php
	#Front End
?>
<?php
	require_once
	("news.class.php");
	$newsHandler = new news();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>News</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
	<div id="header"><div id="header_left"></div>
	<div id="header_main">News</div><div 
id="header_right"></div></div>
	<div id="content">
		<?php $newsHandler->displayNews();?>
	</div>
</div>
</body>
</html>
here is admin.php
<?php
	#News administrator panel
?>
<?php
	require_once("news.class.php");
	$newsHandler = new news();
	if (!isset($_POST['submit'])){
?>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD XHTML 1.0 Transitionla//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
	<meta http-equiv="Content-Type" content="text/html; 
charset=utf-8" />
	<title>News - Admin panel</title>
	<link href="style/style.css" rel="stylesheet" 
type="text/css" />
</head>

<body>
<div id="container">
	<div id="header"><div id="header_left"></div>
	<div id="header_main">News - Admin panel</div><div 
id="header_right"></div></div>
	<div id="content">
		<?php $newsHandler->displayAddForm();?>
	</div>
</div>
</body>
</html>

<?php
}else{
	$newsHandler->insertNews();
}
?>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux