class news extends functions { function read(){ $page=cms::fetch("SELECT text,name FROM `news` WHERE `url_name` = '".cms::$get[1]."'"); TPL::add('TEXT',$page['text']); TPL::add('NAME',$page['name']); } function display(){ $select = cms::query("SELECT text,name,url_name,date FROM `news` ORDER BY date DESC"); $loop = new TPLLoop('anews'); while($news = cms::fetchit($select)){ $item = new TPLLoopItem(); $item->add('name',$news['name']); $item->add('url_name',$news['url_name']); $item->add('text',$this->max_length(preg_replace('#<(.*?)>#s','',$news['text']),400)); $item->add('date',date('d.m.Y',$news['date'])); $loop->append($item); } $loop->pack(); } function manage(){ if(cms::$get[1]=="Delete"){ cms::query("DELETE FROM `news` WHERE `id` = '".cms::$get[2]."'"); cms::error('Novinka byla smazána',"k"); } $loop = new TPLLoop('news'); $select=cms::query("SELECT * FROM `news` ORDER BY date DESC ".$this->pageset('news',30,'id'," ORDER BY date DESC ").''); while($news = cms::fetchit($select)){ $item = new TPLLoopItem(); $item->add('name',$news['name']); $item->add('text',$this->max_length(preg_replace('#<(.*?)>#s','',$news['text']),80)); $item->add('date',date('d.m.Y',$news['date'])); $item->add('id',$news['id']); $loop->append($item); } $loop->pack(); } function add(){ include('lib/form.php'); $form = new form(); TPL::cond('FINISH',false); if(isset($_POST['name'])){ $form->empty_item('name'); $form->empty_item('text'); if($form->go===TRUE){ cms::query("INSERT INTO `news` (`name`, `url_name`, `text`, `date`) VALUES ('".$_POST['name']."', '".$this->url_name($_POST['name'])."', '".$_POST['text']."', '".time()."')"); TPL::cond('FINISH',true); cms::error('Novinka byla přidána',"k"); } } TPL::add('NTEXT',$_POST['text']); $form->pack(); } function edit(){ include('lib/form.php'); $form = new form(); if(isset($_POST['text'])){ $form->empty_item('text'); $form->empty_item('name'); if($form->go!=FALSE){ cms::query("UPDATE `news` SET `name` = '".$_POST['name']."', `url_name` = '".$this->url_name($_POST['name'])."', `text` = '".$_POST['text']."' WHERE `id` = '".cms::$get[1]."'"); cms::error('Novinka byla upravena',"k"); } } $news=cms::fetch("SELECT text,name FROM `news` WHERE `id` = '".cms::$get[1]."'"); TPL::add('NTEXT',$news['text']); TPL::add('NNAME',$news['name']); $form->pack(); } } ?>