1.添加專題:
- /**
- * 添加專題
- */
- public function add() {
- //添加專題
- if (isset($_POST['dosubmit']) && !emptyempty($_POST['dosubmit'])) {
- //添加專題頁面表單數組
- $special = $this->check($_POST['special']);
- //插入專題,返回專題id
- $id = $this->db->insert($special, true);
- //如果插入專題成功
- if ($id) {
- $this->special_api->_update_type($id, $_POST['type']);
- if ($special['siteid']>1) {
- $site = pc_base::load_app_class('sites', 'admin');
- $site_info = $site->get_by_id($special['siteid']);
- if ($special['ishtml']) {
- $url = $site_info['domain'].'special/'.$special['filename'].'/';
- } else {
- $url = $site_info['domain'].'index.php?m=special&c=index&id='.$id;
- }
- } else {
- //專題的url路徑,$special['filename']-代表專題生成的目錄
- $url = $special['ishtml'] ? APP_PATH.substr(pc_base::load_config('system', 'html_root'), 1).'/special/'.$special['filename'].'/' : APP_PATH.'index.php?m=special&c=index&id='.$id;
- }
- //更新專題的url
- $this->db->update(array('url'=>$url), array('id'=>$id, 'siteid'=>$this->get_siteid()));
- //是否生成靜態,調用生成靜態類
- if ($special['ishtml']) {
- $html = pc_base::load_app_class('html', 'special'); //專用于生成靜態的類庫文件
- //生成專題首頁:參數1-專題id 參數2-每頁的個數 參數3-最大更新個數 成功后返回生成文件的大小
- $html->_index($id, 20, 5);
- }
- //更新附件狀態
- if(pc_base::load_config('system','attachment_stat')) {
- $this->attachment_db = pc_base::load_model('attachment_model');//附件表
- //更新附件表
- $this->attachment_db->api_update(array($special['thumb'], $special['banner']),'special-'.$id, 1);
- }
- //專題緩存,緩存所有開放中的專題到緩存目錄
- $this->special_cache();
- }
- //添加專題成功的提示信息
- showmessage(L('add_special_success'), HTTP_REFERER);
- } else {
- //獲取站點模板信息
- pc_base::load_app_func('global', 'admin');
- //站點id
- $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]);
- }
- include $this->admin_tpl('special_add');
- }
- }
2.對從添加專題頁面提交過來的表單數據進行驗證:
- /**
- * 表單驗證
- * @param array $data 表單傳遞的值
- * @param string $a add/edit添加操作時,自動加上默認值
- */
- private function check($data, $a = 'add') {
- // 專題名稱不能為空
- if(!$data['title']) showmessage(L('title_cannot_empty'), HTTP_REFERER);
- //專題橫幅不能為空
- if(!$data['banner']) showmessage(L('banner_no_empty'), HTTP_REFERER);
- //專題縮略圖不能為空
- if(!$data['thumb']) showmessage(L('thumb_no_empty'), HTTP_REFERER);
- //一般為空
- if(is_array($data['catids']) && !emptyempty($data['catids'])) {
- $data['catids'] = ','.implode(',', $data['catids']).',';
- }
- if($a=='add') {
- //專題首頁模板
- if(!$data['index_template']) $data['index_template'] = 'index';
- //站點
- $data['siteid'] = $this->get_siteid();
- //創建時間
- $data['createtime'] = SYS_TIME;
- //用戶名
- $data['username'] = param::get_cookie('admin_username');
- //用戶id
- $data['userid'] = $_SESSION['userid'];
- }
- //投票標題
- if ($data['voteid']) {
- //選擇已有投票
- if (strpos($data['voteid'], '|')===false) {
- $vote_db = pc_base::load_model('vote_subject_model');//屬于專題的投票表
- //根據投票標題獲取當前專題的投票記錄
- $r = $vote_db->get_one(array('subject'=>$data['voteid'], 'siteid'=>$this->get_siteid()), 'subjectid, subject', 'addtime DESC');
- if ($r) { //開源軟件:Vevb.com
- //格式如下:vote|投票id|投票標題
- $data['voteid'] = 'vote|'.$r['subjectid'].'|'.$r['subject'];
- }
- }
- }
- return $data;
- }
- }
新聞熱點
疑難解答