该文件夹下有三个文件夹(没有扩展名的皆为文件夹) model --announce_model.class.php modules --announce --classes --announce_tag.class.php --install --languages --zh-cn --announce.lang.php --templates --announce.sql --config.inc.php --extention.inc.php --index.html --model.php --module.sql --templates --announce_add.tpl.php --announce_edit.tpl.php --announce_list.tpl.php --uninstall --announce.sql --extention.inc.php --index.html --model.php --admin_announce.php --index.php templates--default --announce --show.html --show2.html 所有文件内容,按从上到下顺序 announce_model.class.php: <?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_sys_class('model', '', 0); class announce_model extends model { public $table_name; public function __construct() { $this->db_config = pc_base::load_config('database'); $this->db_setting = 'default'; $this->table_name = 'announce'; parent::__construct(); } } ?> announce_tag.class.php: <?php /** * * 公告类 * */ defined('IN_PHPCMS') or exit('No permission resources.'); class announce_tag { private $db; public function __construct() { $this->db = pc_base::load_model('announce_model'); } /** * 公告列表方法 * @param array $data 传递过来的参数 * @param return array 数据库中取出的数据数组 */ public function lists($data) { $where = '1'; $siteid = $data['siteid'] ? intval($data['siteid']) : get_siteid(); if ($siteid) $where .= " AND `siteid`='".$siteid."'"; $where .= ' AND `passed`=\'1\' AND (`endtime` >= \''.date('Y-m-d').'\' or `endtime`=\'0000-00-00\')'; return $this->db->select($where, '*', $data['limit'], 'aid DESC'); } public function count() { } /** * pc标签初始方法 */ public function pc_tag() { //获取站点 $sites = pc_base::load_app_class('sites','admin'); $sitelist = $sites->pc_tag_list(); $result = getcache('special', 'commons'); if(is_array($result)) { $specials = array(L('please_select', '', 'announce')); foreach($result as $r) { if($r['siteid']!=get_siteid()) continue; $specials[$r['id']] = $r['title']; } } return array( 'action'=>array('lists'=>L('lists', '', 'announce')), 'lists'=>array( 'siteid'=>array('name'=>L('sitename', '', 'announce'),'htmltype'=>'input_select', 'defaultvalue'=>get_siteid(), 'data'=>$sitelist), ), ); } } ?> announce.lang.php: <?php /*Language Format: Add a new file(.lang.php) with your module name at /phpcms/languages/ translation save at the array:$LANG */ $LANG['announce'] = '公告'; $LANG['announce_manage'] = '公告管理'; $LANG['announce_list'] = '公告列表'; $LANG['announce_add'] = '添加公告'; $LANG['announce_title'] = '公告标题:'; $LANG['title_cannot_empty'] = '公告标题不能为空'; $LANG['announcements_cannot_be_empty'] = '公告内容不能为空'; $LANG['announcement_successful_added'] = '公告添加成功'; $LANG['announced_a'] = '公告修改成功'; $LANG['announce_passed'] = '公告批量通过完成!'; $LANG['announce_deleted'] = '公告批量删除完成!'; $LANG['startdate'] = '起始日期'; $LANG['enddate'] = '截止日期'; $LANG['announce_content'] = '公告内容:'; $LANG['announce_status'] = '公告状态:'; $LANG['edit_announce'] = '编辑公告'; $LANG['inputer'] = '录入者'; $LANG['check_annonuce'] = '审核公告'; $LANG['preview'] = '前台预览'; $LANG['index'] = '前台'; $LANG['cancel_all_selected'] = '取消批准选定的公告'; $LANG['pass_all_selected'] = '通过选定的公告'; $LANG['remove_all_selected'] = '删除选定的公告'; $LANG['overdue_announce'] = '过期公告'; $LANG['no_pass_announce'] = '未审核公告'; $LANG['no_exists'] = '此公告不存在或已删除!'; $LANG['affirm_delete'] = '您确定要删除吗?'; $LANG['input_announce_title'] = '请输入公告标题!'; $LANG['title_min_3_chars'] = '公告标题至少3个汉字以上'; $LANG['right'] = '输入正确!'; $LANG['server_no_data'] = '服务器没有返回数据,可能服务器忙,请重试'; $LANG['announce_exist'] = '该公告已存在'; $LANG['checking'] = '正进行合法性校验...'; $LANG['select_stardate'] = '请选择开始时间!'; $LANG['right_all'] = '正确!'; $LANG['select_downdate'] = '请选择下线时间!'; $LANG['select_style'] = '请选择风格!'; $LANG['available_style'] = '可用风格'; $LANG['lists'] = '列表'; $LANG['sitename'] = '站点'; ?> announce.sql: DROP TABLE IF EXISTS `phpcms_announce`; CREATE TABLE IF NOT EXISTS `phpcms_announce` ( `aid` smallint(4) unsigned NOT NULL AUTO_INCREMENT, `siteid` smallint(5) unsigned NOT NULL DEFAULT '0', `title` char(80) NOT NULL, `content` text NOT NULL, `starttime` date NOT NULL DEFAULT '0000-00-00', `endtime` date NOT NULL DEFAULT '0000-00-00', `username` varchar(40) NOT NULL, `addtime` int(10) unsigned NOT NULL DEFAULT '0', `hits` smallint(5) unsigned NOT NULL DEFAULT '0', `passed` tinyint(1) unsigned NOT NULL DEFAULT '0', `style` char(15) NOT NULL , `show_template` char(30) NOT NULL, PRIMARY KEY (`aid`), KEY `siteid` (`siteid`,`passed`,`endtime`) ) TYPE=MyISAM ; config.inc.php: <?php defined('IN_PHPCMS') or exit('Access Denied'); defined('INSTALL') or exit('Access Denied'); $module = 'announce'; $modulename = '公告'; $introduce = '独立模块'; $author = 'phpcms Team'; $authorsite = 'http://www.phpcms.cn'; $authoremail = ''; ?> extention.inc.php: <?php defined('IN_PHPCMS') or exit('Access Denied'); defined('INSTALL') or exit('Access Denied'); $parentid = $menu_db->insert(array('name'=>'announce', 'parentid'=>29, 'm'=>'announce', 'c'=>'admin_announce', 'a'=>'init', 'data'=>'s=1', 'listorder'=>0, 'display'=>'1'), true); $menu_db->insert(array('name'=>'announce_add', 'parentid'=>$parentid, 'm'=>'announce', 'c'=>'admin_announce', 'a'=>'add', 'data'=>'', 'listorder'=>0, 'display'=>'0')); $menu_db->insert(array('name'=>'edit_announce', 'parentid'=>$parentid, 'm'=>'announce', 'c'=>'admin_announce', 'a'=>'edit', 'data'=>'s=1', 'listorder'=>0, 'display'=>'0')); $menu_db->insert(array('name'=>'check_announce', 'parentid'=>$parentid, 'm'=>'announce', 'c'=>'admin_announce', 'a'=>'init', 'data'=>'s=2', 'listorder'=>0, 'display'=>'1')); $menu_db->insert(array('name'=>'overdue', 'parentid'=>$parentid, 'm'=>'announce', 'c'=>'admin_announce', 'a'=>'init', 'data'=>'s=3', 'listorder'=>0, 'display'=>'1')); $menu_db->insert(array('name'=>'del_announce', 'parentid'=>$parentid, 'm'=>'announce', 'c'=>'admin_announce', 'a'=>'delete', 'data'=>'', 'listorder'=>0, 'display'=>'0')); $language = array('announce'=>'公告', 'announce_add'=>'添加公告', 'edit_announce'=>'编辑公告', 'check_announce'=>'审核公告', 'overdue'=>'过期公告', 'del_announce'=>'删除公告'); ?> index.html: model.php: <?php defined('IN_PHPCMS') or exit('Access Denied'); defined('INSTALL') or exit('Access Denied'); return array('announce'); ?> module.sql: INSERT INTO `phpcms_module` (`module`, `name`, `url`, `iscore`, `version`, `description`, `setting`, `listorder`, `disabled`, `installdate`, `updatedate`) VALUES ('announce', '公告', 'announce/', 0, '1.0', '公告', '', 0, 0, '2010-9-05', '2010-9-05'); announce_add.tpl.php: <?php defined('IN_ADMIN') or exit('No permission resources.'); include $this->admin_tpl('header', 'admin'); ?> <div class="pad-10"> <form method="post" action="?m=announce&c=admin_announce&a=add" name="myform" id="myform"> <table class="table_form" width="100%" cellspacing="0"> <tbody> <tr> <th width="80"><strong><?php echo L('announce_title')?></strong></th> <td><input name="announce[title]" id="title" class="input-text" type="text" size="50" ></td> </tr> <tr> <th><strong><?php echo L('startdate')?>:</strong></th> <td><?php echo form::date('announce[starttime]', date('Y-m-d H:i:s'), 1)?></td> </tr> <tr> <th><strong><?php echo L('enddate')?>:</strong></th> <td><?php echo form::date('announce[endtime]', $an_info['endtime'], 1);?></td> </tr> <tr> <th><strong><?php echo L('announce_content')?></strong></th> <td><textarea name="announce[content]" id="content"></textarea><?php echo form::editor('content');?></td> </tr> <tr> <th><strong><?php echo L('available_style')?>:</strong></th> <td> <?php echo form::select($template_list, $info['default_style'], 'name="announce[style]" id="style" onchange="load_file_list(this.value)"', L('please_select'))?> </td> </tr> <tr> <th><strong><?php echo L('template_select')?>:</strong></th> <td id="show_template"><script type="text/javascript">$.getJSON('?m=admin&c=category&a=public_tpl_file_list&style=<?php echo $info['default_style']?>&module=announce&templates=show&name=announce&pc_hash='+pc_hash, function(data){$('#show_template').html(data.show_template);});</script></td> </tr> <tr> <th><strong><?php echo L('announce_status')?></strong></th> <td><input name="announce[passed]" type="radio" value="1" checked> <?php echo L('pass')?> <input name="announce[passed]" type="radio" value="0"> <?php echo L('unpass')?></td> </tr> </tbody> </table> <input type="submit" name="dosubmit" id="dosubmit" value=" <?php echo L('ok')?> " class="dialog"> <input type="reset" class="dialog" value=" <?php echo L('clear')?> "> </form> </div> </body> </html> <script type="text/javascript"> function load_file_list(id) { if (id=='') return false; $.getJSON('?m=admin&c=category&a=public_tpl_file_list&style='+id+'&module=announce&templates=show&name=announce&pc_hash='+pc_hash, function(data){$('#show_template').html(data.show_template);}); } $(document).ready(function(){ $.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,'220',height:'70'}, function(){this.close();$(obj).focus();})}}); $('#title').formValidator({onshow:"<?php echo L('input_announce_title')?>",onfocus:"<?php echo L('title_min_3_chars')?>",oncorrect:"<?php echo L('right')?>"}).inputValidator({min:1,onerror:"<?php echo L('title_cannot_empty')?>"}).ajaxValidator({type:"get",url:"",data:"m=announce&c=admin_announce&a=public_check_title",datatype:"html",cached:false,async:'true',success : function(data) { if( data == "1" ) { return true; } else { return false; } }, error: function(){alert("<?php echo L('server_no_data')?>");}, onerror : "<?php echo L('announce_exist')?>", onwait : "<?php echo L('checking')?>" }); $('#starttime').formValidator({onshow:"<?php echo L('select_stardate')?>",onfocus:"<?php echo L('select_stardate')?>",oncorrect:"<?php echo L('right_all')?>"}); $('#endtime').formValidator({onshow:"<?php echo L('select_downdate')?>",onfocus:"<?php echo L('select_downdate')?>",oncorrect:"<?php echo L('right_all')?>"}); $("#content").formValidator({autotip:true,onshow:"",onfocus:"<?php echo L('announcements_cannot_be_empty')?>"}).functionValidator({ fun:function(val,elem){ //获取编辑器中的内容 var oEditor = CKEDITOR.instances.content; var data = oEditor.getData(); if(data==''){ return "<?php echo L('announcements_cannot_be_empty')?>" } else { return true; } } }); $('#style').formValidator({onshow:"<?php echo L('select_style')?>",onfocus:"<?php echo L('select_style')?>",oncorrect:"<?php echo L('right_all')?>"}).inputValidator({min:1,onerror:"<?php echo L('select_style')?>"}); }); </script> announce_edit.tpl.php: <?php defined('IN_ADMIN') or exit('No permission resources.'); include $this->admin_tpl('header', 'admin'); ?> <div class="pad-10"> <form method="post" action="?m=announce&c=admin_announce&a=edit&aid=<?php echo $_GET['aid']?>" name="myform" id="myform"> <table class="table_form" width="100%"> <tbody> <tr> <th width="80"><?php echo L('announce_title')?></th> <td><input name="announce[title]" id="title" value="<?php echo htmlspecialchars($an_info['title'])?>" class="input-text" type="text" size="50" ></td> </tr> <tr> <th><?php echo L('startdate')?>:</th> <td><?php echo form::date('announce[starttime]', $an_info['starttime'], 1)?></td> </tr> <tr> <th><?php echo L('enddate')?>:</th> <td><?php $an_info['endtime'] = $an_info['endtime']=='0000-00-00' ? '' : $an_info['endtime']; echo form::date('announce[endtime]', $an_info['endtime'], 1);?></td> </tr> <tr> <th><?php echo L('announce_content')?></th> <td > <textarea name="announce[content]" id="content"><?php echo $an_info['content']?></textarea> <?php echo form::editor('content','basic');?> </td> </tr> <tr> <th><strong><?php echo L('available_style')?>:</strong></th> <td><?php echo form::select($template_list, $an_info['style'], 'name="announce[style]" id="style" onchange="load_file_list(this.value)"', L('please_select'))?></td> </tr> <tr> <th><?php echo L('template_select')?>:</th> <td id="show_template"><?php if ($an_info['style']) echo '<script type="text/javascript">$.getJSON(\'?m=admin&c=category&a=public_tpl_file_list&style='.$an_info['style'].'&id='.$an_info['show_template'].'&module=announce&templates=show&name=announce&pc_hash=\'+pc_hash, function(data){$(\'#show_template\').html(data.show_template);});</script>'?></td> </tr> <tr> <th><?php echo L('announce_status')?></th> <td><input name="announce[passed]" type="radio" value="1" <?php if($an_info['passed']==1) {?>checked<?php }?>></input> <?php echo L('pass')?> <input name="announce[passed]" type="radio" value="0" <?php if($an_info['passed']==0) {?>checked<?php }?>> <?php echo L('unpass')?></td> </tr> </tbody> </table> <input type="submit" name="dosubmit" id="dosubmit" value=" <?php echo L('ok')?> " class="dialog"> <input type="reset" class="dialog" value=" <?php echo L('clear')?> "> </form> </div> </body> </html> <script type="text/javascript"> function load_file_list(id) { $.getJSON('?m=admin&c=category&a=public_tpl_file_list&style='+id+'&module=announce&templates=show&name=announce&pc_hash='+pc_hash, function(data){$('#show_template').html(data.show_template);}); } $(document).ready(function(){ $.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,'220',height:'70'}, function(){this.close();$(obj).focus();})}}); $('#title').formValidator({onshow:"<?php echo L('input_announce_title')?>",onfocus:"<?php echo L('title_min_3_chars')?>",oncorrect:"<?php echo L('right')?>"}).inputValidator({min:1,onerror:"<?php echo L('title_cannot_empty')?>"}).ajaxValidator({type:"get",url:"",data:"m=announce&c=admin_announce&a=public_check_title&aid=<?php echo $_GET['aid']?>",datatype:"html",cached:false,async:'true',success : function(data) { if( data == "1" ) { return true; } else { return false; } }, error: function(){alert("<?php echo L('server_no_data')?>");}, onerror : "<?php echo L('announce_exist')?>", onwait : "<?php echo L('checking')?>" }).defaultPassed(); $('#starttime').formValidator({onshow:"<?php echo L('select_stardate')?>",onfocus:"<?php echo L('select_stardate')?>",oncorrect:"<?php echo L('right_all')?>"}).defaultPassed(); $('#endtime').formValidator({onshow:"<?php echo L('select_downdate')?>",onfocus:"<?php echo L('select_downdate')?>",oncorrect:"<?php echo L('right_all')?>"}).defaultPassed(); $("#content").formValidator({autotip:true,onshow:"",onfocus:"<?php echo L('announcements_cannot_be_empty')?>"}).functionValidator({ fun:function(val,elem){ //获取编辑器中的内容 var oEditor = CKEDITOR.instances.content; var data = oEditor.getData(); if(data==''){ return "<?php echo L('announcements_cannot_be_empty')?>" } else { return true; } } }).defaultPassed(); $('#style').formValidator({onshow:"<?php echo L('select_style')?>",onfocus:"<?php echo L('select_style')?>",oncorrect:"<?php echo L('right_all')?>"}).inputValidator({min:1,onerror:"<?php echo L('select_style')?>"}).defaultPassed(); }); </script> announce_list.tpl.php: <?php defined('IN_ADMIN') or exit('No permission resources.'); include $this->admin_tpl('header', 'admin'); ?> <div class="pad-lr-10"> <form name="myform" action="?m=announce&c=admin_announce&a=listorder" method="post"> <div class="table-list"> <table width="100%" cellspacing="0"> <thead> <tr> <th width="35" align="center"><input type="checkbox" value="" id="check_box" onclick="selectall('aid[]');"></th> <th align="center"><?php echo L('title')?></th> <th width="68" align="center"><?php echo L('startdate')?></th> <th width='68' align="center"><?php echo L('enddate')?></th> <th width='68' align="center"><?php echo L('inputer')?></th> <th width="50" align="center"><?php echo L('hits')?></th> <th width="120" align="center"><?php echo L('inputtime')?></th> <th width="69" align="center"><?php echo L('operations_manage')?></th> </tr> </thead> <tbody> <?php if(is_array($data)){ foreach($data as $announce){ ?> <tr> <td align="center"> <input type="checkbox" name="aid[]" value="<?php echo $announce['aid']?>"> </td> <td><?php echo $announce['title']?></td> <td align="center"><?php echo $announce['starttime']?></td> <td align="center"><?php echo $announce['endtime']?></td> <td align="center"><?php echo $announce['username']?></td> <td align="center"><?php echo $announce['hits']?></td> <td align="center"><?php echo date('Y-m-d H:i:s', $announce['addtime'])?></td> <td align="center"> <?php if ($_GET['s']==1) {?><a href="?m=announce&c=index&a=show&aid=<?php echo $announce['aid']?>" title="<?php echo L('preview')?>" target="_blank"><?php }?><?php echo L('index')?><?php if ($_GET['s']==1) {?></a><?php }?> | <a href="javascript:edit('<?php echo $announce['aid']?>', '<?php echo safe_replace($announce['title'])?>');void(0);"><?php echo L('edit')?></a> </td> </tr> <?php } } ?> </tbody> </table> <div class="btn"><label for="check_box"><?php echo L('selected_all')?>/<?php echo L('cancel')?></label> <?php if($_GET['s']==1) {?><input name='submit' type='submit' class="button" value='<?php echo L('cancel_all_selected')?>' onClick="document.myform.action='?m=announce&c=admin_announce&a=public_approval&passed=0'"><?php } elseif($_GET['s']==2) {?><input name='submit' type='submit' class="button" value='<?php echo L('pass_all_selected')?>' onClick="document.myform.action='?m=announce&c=admin_announce&a=public_approval&passed=1'"><?php }?> <input name="submit" type="submit" class="button" value="<?php echo L('remove_all_selected')?>" onClick="document.myform.action='?m=announce&c=admin_announce&a=delete';return confirm('<?php echo L('affirm_delete')?>')"> </div> </div> <div id="pages"><?php echo $this->db->pages;?></div> </form> </div> </body> </html> <script type="text/javascript"> function edit(id, title) { window.top.art.dialog({id:'edit'}).close(); window.top.art.dialog({title:'<?php echo L('edit_announce')?>--'+title, id:'edit', iframe:'?m=announce&c=admin_announce&a=edit&aid='+id ,'700px',height:'500px'}, function(){var d = window.top.art.dialog({id:'edit'}).data.iframe; var form = d.document.getElementById('dosubmit');form.click();return false;}, function(){window.top.art.dialog({id:'edit'}).close()}); } </script> announce.sql: DROP TABLE IF EXISTS `phpcms_announce`; extention.inc.php: <?php defined('IN_PHPCMS') or exit('Access Denied'); defined('UNINSTALL') or exit('Access Denied'); ?> index.html: model.php: <?php defined('IN_PHPCMS') or exit('Access Denied'); defined('UNINSTALL') or exit('Access Denied'); return array('announce'); ?> admin_announce.php: <?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_app_class('admin','admin',0); class admin_announce extends admin { private $db; public $username; public function __construct() { parent::__construct(); //if (!module_exists(ROUTE_M)) showmessage(L('module_not_exists')); $this->username = param::get_cookie('admin_username'); $this->db = pc_base::load_model('announce_model'); } public function init() { //公告列表 $sql = ''; $_GET['status'] = $_GET['status'] ? intval($_GET['status']) : 1; $sql = '`siteid`=\''.$this->get_siteid().'\''; switch($_GET['s']) { case '1': $sql .= ' AND `passed`=\'1\' AND (`endtime` >= \''.date('Y-m-d').'\' or `endtime`=\'0000-00-00\')'; break; case '2': $sql .= ' AND `passed`=\'0\''; break; case '3': $sql .= ' AND `passed`=\'1\' AND `endtime`!=\'0000-00-00\' AND `endtime` <\''.date('Y-m-d').'\' '; break; } $page = max(intval($_GET['page']), 1); $data = $this->db->listinfo($sql, '`aid` DESC', $page); $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=announce&c=admin_announce&a=add\', title:\''.L('announce_add').'\', \'700\', height:\'500\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('announce_add')); include $this->admin_tpl('announce_list'); } /** * 添加公告 */ public function add() { if(isset($_POST['dosubmit'])) { $_POST['announce'] = $this->check($_POST['announce']); if($this->db->insert($_POST['announce'])) showmessage(L('announcement_successful_added'), HTTP_REFERER, '', 'add'); } else { //获取站点模板信息 pc_base::load_app_func('global', 'admin'); $siteid = $this->get_siteid(); $template_list = template_list($siteid, 0); $site = pc_base::load_app_class('sites','admin'); $info = $site->get_by_id($siteid); foreach ($template_list as $k=>$v) { $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname']; unset($template_list[$k]); } $show_header = $show_validator = $show_scroll = 1; pc_base::load_sys_class('form', '', 0); include $this->admin_tpl('announce_add'); } } /** * 修改公告 */ public function edit() { $_GET['aid'] = intval($_GET['aid']); if(!$_GET['aid']) showmessage(L('illegal_operation')); if(isset($_POST['dosubmit'])) { $_POST['announce'] = $this->check($_POST['announce'], 'edit'); if($this->db->update($_POST['announce'], array('aid' => $_GET['aid']))) showmessage(L('announced_a'), HTTP_REFERER, '', 'edit'); } else { $where = array('aid' => $_GET['aid']); $an_info = $this->db->get_one($where); pc_base::load_sys_class('form', '', 0); //获取站点模板信息 pc_base::load_app_func('global', 'admin'); $template_list = template_list($this->siteid, 0); foreach ($template_list as $k=>$v) { $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname']; unset($template_list[$k]); } $show_header = $show_validator = $show_scroll = 1; include $this->admin_tpl('announce_edit'); } } /** * ajax检测公告标题是否重复 */ public function public_check_title() { if (!$_GET['title']) exit(0); if (CHARSET=='gbk') { $_GET['title'] = iconv('UTF-8', 'GBK', $_GET['title']); } $title = $_GET['title']; if ($_GET['aid']) { $r = $this->db->get_one(array('aid' => $_GET['aid'])); if ($r['title'] == $title) { exit('1'); } } $r = $this->db->get_one(array('siteid' => $this->get_siteid(), 'title' => $title), 'aid'); if($r['aid']) { exit('0'); } else { exit('1'); } } /** * 批量修改公告状态 使其成为审核、未审核状态 */ public function public_approval($aid = 0) { if((!isset($_POST['aid']) || empty($_POST['aid'])) && !$aid) { showmessage(L('illegal_operation')); } else { if(is_array($_POST['aid']) && !$aid) { array_map(array($this, 'public_approval'), $_POST['aid']); showmessage(L('announce_passed'), HTTP_REFERER); } elseif($aid) { $aid = intval($aid); $this->db->update(array('passed' => $_GET['passed']), array('aid' => $aid)); return true; } } } /** * 批量删除公告 */ public function delete($aid = 0) { if((!isset($_POST['aid']) || empty($_POST['aid'])) && !$aid) { showmessage(L('illegal_operation')); } else { if(is_array($_POST['aid']) && !$aid) { array_map(array($this, 'delete'), $_POST['aid']); showmessage(L('announce_deleted'), HTTP_REFERER); } elseif($aid) { $aid = intval($aid); $this->db->delete(array('aid' => $aid)); } } } /** * 验证表单数据 * @param array $data 表单数组数据 * @param string $a 当表单为添加数据时,自动补上缺失的数据。 * @return array 验证后的数据 */ private function check($data = array(), $a = 'add') { if($data['title']=='') showmessage(L('title_cannot_empty')); if($data['content']=='') showmessage(L('announcements_cannot_be_empty')); $r = $this->db->get_one(array('title' => $data['title'])); if (strtotime($data['endtime'])<strtotime($data['starttime'])) { $data['endtime'] = ''; } if ($a=='add') { if (is_array($r) && !empty($r)) { showmessage(L('announce_exist'), HTTP_REFERER); } $data['siteid'] = $this->get_siteid(); $data['addtime'] = SYS_TIME; $data['username'] = $this->username; if ($data['starttime'] == '') $announce['starttime'] = date('Y-m-d'); } else { if ($r['aid'] && ($r['aid']!=$_GET['aid'])) { showmessage(L('announce_exist'), HTTP_REFERER); } } return $data; } } ?> index.php: <?php defined('IN_PHPCMS') or exit('No permission resources.'); class index { function __construct() { $this->db = pc_base::load_model('announce_model'); } public function init() { } /** * 展示公告 */ public function show() { if(!isset($_GET['aid'])) { showmessage(L('illegal_operation')); } $_GET['aid'] = intval($_GET['aid']); $where = ''; $where .= "`aid`='".$_GET['aid']."'"; $where .= " AND `passed`='1' AND (`endtime` >= '".date('Y-m-d')."' or `endtime`='0000-00-00')"; $r = $this->db->get_one($where); if($r['aid']) { $this->db->update(array('hits'=>'+=1'), array('aid'=>$r['aid'])); $template = $r['show_template'] ? $r['show_template'] : 'show'; extract($r); $SEO = seo(get_siteid(), '', $title); include template('announce', $template, $r['style']); } else { showmessage(L('no_exists')); } } } ?> show.html: {template 'content', 'header'} <!--main--> <div class="main"> <div class="col-left"> <div class="crumbs"><a href="">首页</a><span> > </span><a href="">公告</a></div> <div id="Article"> <h1>{$title}<br /> <span></span></h1> <div class="content"> {$content} </div> </div> </div> <div class="col-auto"> <div class="box pd_b0"> {pc:comment action="bang" cache="3600"} <ul class="itemli"> {loop $data $r} <li><a href="{$r[url]}" target="_blank">{str_cut($r[title], 26)}</a></li> {/loop} </ul> {/pc} </div> </div> </div> {template 'content', 'footer'} show2.html:代码和show.html同