业务经理

微信扫描以上二维码

028-61286886

技术咨询

采集入库,允许标题和内容重复

迅睿框架 更新 2020-08-26 17:17:40 老铁666

火车头采集入库的话,允许标题和内容重复的话,需要屏蔽掉里边的哪一段代码?


<?php


$this->_module_init('news'); // news 是模块目录

if ($_GET['action'] == 'category') {
    // 显示栏目

    foreach ($this->module['category'] as $t) {
        if ($t['child'] == 0 && $t['tid'] == 1) {
            echo '<h1>'.$t['name'].'<=>'.$t['id'].'</h1>'.PHP_EOL;
        }
    }

} else {
    // 入库数据

    $data = $_REQUEST;

    // 发布者id 1
    $data['uid'] = 1;

    // 发布者账号 admin
    $data['author'] = 'admin';

    // 主表字段
    $fields[1] = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR));
    $cache = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_category_data'));
    $cache && $fields[1] = array_merge($fields[1], $cache);

    // 附表字段
    $fields[0] = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_data_0'));
    $cache = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_category_data_0'));
    $cache && $fields[0] = array_merge($fields[0], $cache);

    // 去重复
    $fields[0] = array_unique($fields[0]);
    $fields[1] = array_unique($fields[1]);

    $save = [];

    // 主表附表归类
    foreach ($fields as $ismain => $field) {
        foreach ($field as $name) {
            isset($data[$name]) && $save[$ismain][$name] = $data[$name];
        }
    }
        if (!$data['catid']) {
            exit('栏目为空');
        }

    $save[1]['uid'] = $save[0]['uid'] = $data['uid'];
    $save[1]['catid'] = $save[0]['catid'] = $data['catid'];
    $imgs = dr_get_content_img($save[0]['content']);
    $save[1]['thumb'] = (string)$imgs[0];
    $save[1]['url'] = '';
    $save[1]['status'] = 9; //9表示正常发布,1表示审核里面
    $save[1]['hits'] = 0;
    $save[1]['displayorder'] = 0;
    $save[1]['link_id'] = 0;
    $save[1]['comments'] = 0;
    $save[1]['avgsort'] = 0;
    $save[1]['inputtime'] = $save[1]['updatetime'] = SYS_TIME + rand(0, 7200);
    $save[1]['inputip'] = '127.0.0.1';

    // 验证标题重复
    if ($this->content_model->table(SITE_ID.'_'.MOD_DIR)->where('title', $save[1]['title'])->counts()) {
        echo '重复';exit;
    }


    $rt = $this->content_model->save(0, $save);

    if ($rt['code']) {
        exit('成功');
    } else {
        exit('失败');
    }

}

exit;


方案

  • 曼德拉的铅笔 #1 · 2020-08-26 15:43:37
    还要回复才能看到内容帮你,谁有那么闲啊
  • 老铁666 #2 · 2020-08-26 15:46:37
    曼德拉的铅笔
    <?php
    
    
    $this->_module_init('news'); // news 是模块目录
    
    if ($_GET['action'] == 'category') {
        // 显示栏目
    
        foreach ($this->module['category'] as $t) {
            if ($t['child'] == 0 && $t['tid'] == 1) {
                echo '<h1>'.$t['name'].'<=>'.$t['id'].'</h1>'.PHP_EOL;
            }
        }
    
    } else {
        // 入库数据
    
        $data = $_REQUEST;
    
        // 发布者id 1
        $data['uid'] = 1;
    
        // 发布者账号 admin
        $data['author'] = 'admin';
    
        // 主表字段
        $fields[1] = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR));
        $cache = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_category_data'));
        $cache && $fields[1] = array_merge($fields[1], $cache);
    
        // 附表字段
        $fields[0] = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_data_0'));
        $cache = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_category_data_0'));
        $cache && $fields[0] = array_merge($fields[0], $cache);
    
        // 去重复
        $fields[0] = array_unique($fields[0]);
        $fields[1] = array_unique($fields[1]);
    
        $save = [];
    
        // 主表附表归类
        foreach ($fields as $ismain => $field) {
            foreach ($field as $name) {
                isset($data[$name]) && $save[$ismain][$name] = $data[$name];
            }
        }
            if (!$data['catid']) {
                exit('栏目为空');
            }
    
        $save[1]['uid'] = $save[0]['uid'] = $data['uid'];
        $save[1]['catid'] = $save[0]['catid'] = $data['catid'];
        $imgs = dr_get_content_img($save[0]['content']);
        $save[1]['thumb'] = (string)$imgs[0];
        $save[1]['url'] = '';
        $save[1]['status'] = 9; //9表示正常发布,1表示审核里面
        $save[1]['hits'] = 0;
        $save[1]['displayorder'] = 0;
        $save[1]['link_id'] = 0;
        $save[1]['comments'] = 0;
        $save[1]['avgsort'] = 0;
        $save[1]['inputtime'] = $save[1]['updatetime'] = SYS_TIME + rand(0, 7200);
        $save[1]['inputip'] = '127.0.0.1';
    
        // 验证标题重复
        if ($this->content_model->table(SITE_ID.'_'.MOD_DIR)->where('title', $save[1]['title'])->counts()) {
            echo '重复';exit;
        }
    
    
        $rt = $this->content_model->save(0, $save);
    
        if ($rt['code']) {
            exit('成功');
        } else {
            exit('失败');
        }
    
    }
    
    exit;
  • 老铁666 #3 · 2020-08-26 15:47:13
    可能点错地方了,居然需要回复
  • 秋冬 #4 · 2020-08-26 15:47:33
    回复看看,你在求助嘛你把代码别弄成回复可见啊
  • 老铁666 #5 · 2020-08-26 15:48:20
    秋冬 粘贴了,可能点错地方了。
    <?php
    
    
    $this->_module_init('news'); // news 是模块目录
    
    if ($_GET['action'] == 'category') {
        // 显示栏目
    
        foreach ($this->module['category'] as $t) {
            if ($t['child'] == 0 && $t['tid'] == 1) {
                echo '<h1>'.$t['name'].'<=>'.$t['id'].'</h1>'.PHP_EOL;
            }
        }
    
    } else {
        // 入库数据
    
        $data = $_REQUEST;
    
        // 发布者id 1
        $data['uid'] = 1;
    
        // 发布者账号 admin
        $data['author'] = 'admin';
    
        // 主表字段
        $fields[1] = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR));
        $cache = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_category_data'));
        $cache && $fields[1] = array_merge($fields[1], $cache);
    
        // 附表字段
        $fields[0] = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_data_0'));
        $cache = $this->get_cache('table-'.SITE_ID, $this->content_model->dbprefix(SITE_ID.'_'.MOD_DIR.'_category_data_0'));
        $cache && $fields[0] = array_merge($fields[0], $cache);
    
        // 去重复
        $fields[0] = array_unique($fields[0]);
        $fields[1] = array_unique($fields[1]);
    
        $save = [];
    
        // 主表附表归类
        foreach ($fields as $ismain => $field) {
            foreach ($field as $name) {
                isset($data[$name]) && $save[$ismain][$name] = $data[$name];
            }
        }
            if (!$data['catid']) {
                exit('栏目为空');
            }
    
        $save[1]['uid'] = $save[0]['uid'] = $data['uid'];
        $save[1]['catid'] = $save[0]['catid'] = $data['catid'];
        $imgs = dr_get_content_img($save[0]['content']);
        $save[1]['thumb'] = (string)$imgs[0];
        $save[1]['url'] = '';
        $save[1]['status'] = 9; //9表示正常发布,1表示审核里面
        $save[1]['hits'] = 0;
        $save[1]['displayorder'] = 0;
        $save[1]['link_id'] = 0;
        $save[1]['comments'] = 0;
        $save[1]['avgsort'] = 0;
        $save[1]['inputtime'] = $save[1]['updatetime'] = SYS_TIME + rand(0, 7200);
        $save[1]['inputip'] = '127.0.0.1';
    
        // 验证标题重复
        if ($this->content_model->table(SITE_ID.'_'.MOD_DIR)->where('title', $save[1]['title'])->counts()) {
            echo '重复';exit;
        }
    
    
        $rt = $this->content_model->save(0, $save);
    
        if ($rt['code']) {
            exit('成功');
        } else {
            exit('失败');
        }
    
    }
    
    exit;
  • 何先生 #6 · 2020-08-26 15:48:35
    满意答案
    删除这句话就可以不验证标题重复了
        // 验证标题重复
        //if ($this->content_model->table(SITE_ID.'_'.MOD_DIR)->where('title', $save[1]['title'])->counts()) {
           // echo '重复';exit;
        //}
  • 海南岛 #7 · 2020-08-26 15:49:32
    // 验证标题重复
        if ($this->content_model->table(SITE_ID.'_'.MOD_DIR)->where('title', $save[1]['title'])->counts()) {
            echo '重复';exit;
        }
    删除这句应该就允许重复了吧,虽然我不太懂代码,你这个已经中文标注了,一眼就看出来了
  • 老铁666 #8 · 2020-08-26 17:17:40
    @何先生:我也是这么觉得

迅睿系统漏洞

图片格式转化
图片格式转化(2026-10-17)
修复百度编辑器里的内容图片没有转换为webp格式 历史文章列表不显...
站群分站系统
站群分站系统(2026-10-15)
子站域名新增llms.txt访问
图书阅读系统
图书阅读系统(2026-10-14)
全站移动端样式适配 首页分类 Tab 横滑容器,左右渐变滚动提示 ...
GEO系统
GEO系统(2026-10-14)
修复下载zip空白地址问题 修复流量复刻和任务队列错误
GeoSeo收录宝
GeoSeo收录宝(2026-10-14)
新增 站长工具箱 前端首页自动调用meta 数据
滑块验证码 Gocaptcha
滑块验证码 Gocaptcha(2026-10-13)
基于开源项目 go-captcha 的行为验证码插件,滑动拼图、区域...
GeoSeo工具箱
GeoSeo工具箱(2026-10-13)
优化巡检任务
GeoSeo排名助手
GeoSeo排名助手(2026-10-11)
加入大模型自定义
SEO聚合关键字
SEO聚合关键字(2026-10-11)
优化关键字列表页最多支持1万篇文章,过多会导致服务器扛不住;