【phpcms-v9】phpcms-v9中復制采集節點功能(擴展:專題碎片的復制).
1.添加采集節點代碼:
- /**
- * add node
- */
- public function add() {
- header("Cache-control: private");
- //添加采集節點
- if(isset($_POST['dosubmit'])) {
- //采集節點表單數據
- $data = isset($_POST['data']) ? $_POST['data'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
- //自定義規則
- $customize_config = isset($_POST['customize_config']) ? $_POST['customize_config'] : '';
- //采集節點名稱
- if (!$data['name'] = trim($data['name'])) {
- showmessage(L('nodename').L('empty'), HTTP_REFERER);
- }
- //提示 節點已存在
- if ($this->db->get_one(array('name'=>$data['name']))) {
- showmessage(L('nodename').L('exists'), HTTP_REFERER);
- }
- //網址類型
- $data['urlpage'] = isset($_POST['urlpage'.$data['sourcetype']]) ? $_POST['urlpage'.$data['sourcetype']] : showmessage(L('illegal_parameters'), HTTP_REFERER);
- //站點id
- $data['siteid']= $this->get_siteid();
- //自定義規則
- $data['customize_config'] = array();
- if (is_array($customize_config)) foreach ($customize_config['en_name'] as $k => $v) {
- if (emptyempty($v) || emptyempty($customize_config['name'][$k])) continue;
- $data['customize_config'][] = array('name'=>$customize_config['name'][$k], 'en_name'=>$v, 'rule'=>$customize_config['rule'][$k], 'html_rule'=>$customize_config['html_rule'][$k]);
- }
- $data['customize_config'] = array2string($data['customize_config']);
- //采集節點信息入庫操作
- if ($this->db->insert($data)) {
- showmessage(L('operation_success'), '?m=collection&c=node&a=manage');
- } else {
- showmessage(L('operation_failure'), HTTP_REFERER);
- }
- } else {
- $show_dialog = $show_validator = true;
- //采集節點信息表單頁面
- include $this->admin_tpl('node_form');
- }
- }
2.復制采集節點信息
- //復制已有采集節點
- public function copy() {
- //采集節點id
- $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
- //查詢當前采集節點信息
- if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
- //是否確定復制當前采集節點信息
- if (isset($_POST['dosubmit'])) {
- //銷毀當前采集節點id
- unset($data['nodeid']);
- //新采集節點名稱
- $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
- //查詢數據庫中是否已存在該新采集節點名稱
- if ($this->db->get_one(array('name'=>$name), 'nodeid')) {
- showmessage(L('nodename').L('exists'), HTTP_REFERER);
- }
- //新采集節點名稱
- $data['name'] = $name;
- //在特殊字符前加反斜線
- $data = new_addslashes($data);
- //插入新采集節點到數據庫
- if ($this->db->insert($data)) {
- //插入成功
- showmessage(L('operation_success'), '', '', 'test');
- } else { //開源代碼Vevb.com
- showmessage(L('operation_failure'));
- }
- } else {
- $show_validator = $show_header = true;
- include $this->admin_tpl('node_copy');//添加采集節點頁面
- }
- } else {
- showmessage(L('notfound'));
- }
- }
新聞熱點
疑難解答