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 (empty($v) || empty($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 { showmessage(L('operation_failure')); } } else { $show_validator = $show_header = true; include $this->admin_tpl('node_copy');//添加采集节点页面 } } else { showmessage(L('notfound')); } }