Så, nu i testet version 1.1 :)
Der er nu to steder, du skal rette, i starten af hver klase !
Husk, at hver klasse bør være i sin egen inkludefil !
<?php
class arraydumper {
var $filename="/www/sk/kracon.dk/html/myfile.dat";
// dont touch the data behind this point !
var $data=array();
function load() {
if (file_exists($this->filename)) {
$temp_fp=fopen($this->filename,"r");
flock($temp_fp, LOCK_SH);
$temp_data=join ('', file ($this->filename));
flock($temp_fp, LOCK_UN);
fclose($temp_fp);
$this->data=unserialize($temp_data);
} else {
$this->data=array();
}
}
function save() {
$temp_fp=fopen($this->filename,"w");
flock($temp_fp, LOCK_EX);
ftruncate($temp_fp,0);
fseek($temp_fp,0);
fputs($temp_fp,serialize($this->data));
flock($temp_fp, LOCK_UN);
fclose($temp_fp);
}
function addbefore($before,$item) {
$elementcount=count($this->data);
if ($elementcount != 0) {
for ($i=0; $i<$elementcount;$i++) {
if ($i==$before) {
$temp_array[]=$item;
}
$temp_array[]=$this->data[$i];
}
} else {
$temp_array[]=$item;
}
$this->data=$temp_array;
}
function delete($number) {
$elementcount=count($this->data);
for ($i=0; $i<$elementcount;$i++) {
if ($i!=$number) $temp_array[]=$this->data[$i];
}
$this->data=$temp_array;
}
}
class headlinenews extends arraydumper {
var $max_elements=3;
// dont touch the data behind this point !
function cutdown($elements) {
if ($this->get_news_count() <= $elements) return true;
for ($i=0; $i<$elements; $i++) {
$temp_array[]=$this->data[$i];
}
$this->data=$temp_array;
}
function headlinenews() {
$this->load();
}
function add_news($headline, $body,$submitter,$date=null) {
$temp_newsitem["headline"]=$headline;
$temp_newsitem["body"]=$body;
if ($date==null) {
$temp_newsitem["date"]=date("Y-m-d H:i:s");
} else {
$temp_newsitem["date"]=$date;
}
$temp_newsitem["submitter"]=$submitter;
$this->addbefore(0, $temp_newsitem);
$this->cutdown($this->max_elements);
$this->save();
}
function get_headline($number) {
return $this->data[$number]["headline"];
}
function get_body($number) {
return $this->data[$number]["body"];
}
function get_date($number) {
return $this->data[$number]["date"];
}
function get_submitter($number) {
return $this->data[$number]["submitter"];
}
function get_news_count() {
return count($this->data);
}
}
// eksempel
$n=new headlinenews;
$n->add_news("Test","Denne funktion skulle virke - men er ikke
testet.","Svenne");
$n->add_news("Test","Men nu er det testet.","Svenne","2002-02-22
00:00:00");
for ($i=0; $i< $n->get_news_count(); $i++) {
echo "Titel : " . $n->get_headline($i) . "<br>";
echo "Brødtekst : " . $n->get_body($i) . "<br>";
echo "Forfatter : " . $n->get_submitter($i) . "<br>";
echo "Tid : " . $n->get_date($i) . "<br>";
echo "<br>";
}
?>
--
Job-offerings with more than a googolplex* USD a year are instantly accepted.
* =
http://www.fpx.de/fp/Fun/Googolplex/