小发猫是一个AI伪原创系统,支持API调用,所以可以集成到火车头插件里面去。

这里分享一个插件的源码,和插件标签如何根据自己需求修改。

代码放最后面,这里先说说如何修改要伪原创的标签。

1、用文本编辑器打开伪原创插件的php文件,这里推荐用vscode编辑器,打开可以看到这样的代码:

这里的【内容】对应火车头里面的【内容】,如图:

2、如果你在火车头里不叫【内容】而是叫【详细信息】,那边对应插件代码也要改成【详细信息】,如图:

3、如果有其他问题,可以直接找小发猫售后的。

4、以下是我的火车头插件代码:

<?php


set_time_limit(270);
error_reporting(E_ERROR | E_WARNING | E_PARSE);

define('TITLE_SEPAR', 'xxx**xxx');
define('TITLE_SEPAR2', '262661');


$url = 'http://api.xiaofamao.com/api.php?json=0&v=1&key=你的KEY';

$content_tag_name = '详细信息';


$headdd = '';
$taill = '';

switch($LabelArray['PageType'])
{
    case 'List'://处理列表页,只能处理html
        break;
    case 'Pages'://处理多页,只能处理html
        break;
    case 'Content'://处理默认页,只能处理html
        break;
    case 'Save'://只有保存时是可以处理标签值的
        // 保存原文

    try {
    /**********************************************************************/
    // 这一步用来获取伪原创文章
    /**********************************************************************/
    $title = $LabelArray['标题'];
    $title = '标题:'.$title;

    $content = $LabelArray[$content_tag_name];
    #$content = str_replace('2020/', '2020_', $content);

    $article_src = compose_article($title, $content);
    $article_src_b = $article_src;

    $article_new = get_wyc_article($article_src);


    $title_wyc = trim($article_new[0]);
    $content_wyc = trim($article_new[1]);

    $content_wyc = fix_newline($content_wyc);
    $content_wyc = str_replace('标签:', '标签:', $content_wyc);
    $LabelArray[$content_tag_name] = $headdd. $content_wyc. $taill;

    $title_wyc = str_replace(array('。',',','%'), array(' ',' ',' '), $title_wyc);
    $LabelArray['标题'] = $title_wyc;
    }
    catch (Exception $e) {
        $LabelArray['标题'] .= $e->getMessage();
        $LabelArray[$content_tag_name] .= $e->getMessage();
    }
        break;
    default:
        //$LabelArray[$content_tag_name]=curl_request($url, array('wenzhang'=>$LabelArray[$content_tag_name] ));
}

echo serialize($LabelArray);



function compose_article($title, $content) {
    $separator = compose_separator();
    return $title.$separator.$content;
}

function compose_separator() {
    return PHP_EOL.'('.TITLE_SEPAR2.')'.PHP_EOL;
}


function fix_separator($article) {
    return $article;
}


function get_wyc_article($str) {
    global $url;
    $separator = compose_separator();
    $separator = str_replace(PHP_EOL, '', $separator);
    $wyc = curl_request($url, array('wenzhang'=>$str));

    $wyc_f = $wyc;
    $wyc = fix_separator($wyc);
    $wyc = explode($separator, $wyc);

    if (isset($wyc[0])){
        $wyc[0] = str_replace('标题:', '', $wyc[0]);
        $wyc[0] = str_replace('标题:', '', $wyc[0]);
        $wyc[0] = str_replace('目:', '', $wyc[0]);
        $wyc[0] = str_replace('目:', '', $wyc[0]);
        $wyc[0] = 'xx`xx'.$wyc[0];
        $wyc[0] = str_replace('xx`xx题', '', $wyc[0]);
        $wyc[0] = str_replace('xx`xx', '', $wyc[0]);
    }

    //if (isset($wyc[1])) $wyc[1] = trim($wyc[1]);
    //$wyc[1] = $wyc_f.'jjjjjjjj'.$wyc[1];
    return $wyc;
}


function get_wyc_title($str) {
    $title = get_wyc_article($str.PHP_EOL.PHP_EOL.PHP_EOL.$str.PHP_EOL.PHP_EOL.PHP_EOL.$str);
    $title = fix_newline($title);
    $title = explode(PHP_EOL, $title);
    return $title[0];
}

function get_keywords($title, $contents) {
    $url_kw = 'http://api-2.78tp.com/nlp/kws.php?appid=';
    $kws = curl_request($url_kw, array(
    'title'=>$title,
    'len'=>100,
    'text'=>$contents));

    return $kws;
}


function remove_alt($contents) {
    $contents = preg_replace('/alt=\"(.*)\"/', '', $contents);
    return $contents;
}


function fix_title($contents) {
    $punctuation_symbol = array('。', '?', ',', ':', ';', '、', '!',
                                '.',  '?',  ',',  ':',  ';', '!');

     $contents = str_replace($punctuation_symbol, '', $contents);
    return $contents;
}

function br2newline($contents) {
    $contents = str_replace('<br>', PHP_EOL, $contents);
    $contents = str_replace('<br/>', PHP_EOL, $contents);
    $contents = str_replace('<br />', PHP_EOL, $contents);
    $contents = str_replace('<BR/>', PHP_EOL, $contents);
    $contents = str_replace('<BR>', PHP_EOL, $contents);
    $contents = str_replace('<BR />', PHP_EOL, $contents);

    return $contents;
}

function newline2br($contnets) {
    $contnets = str_replace(PHP_EOL, "<br>", $contnets);
//    $contnets = str_replace('><br><', '><', $contnets);
    $contnets = str_replace('<p><br>', '<p>', $contnets);
    return $contnets;
}


function delete_newline($contents) {
    $contents = fix_newline($contents);
//    $contents = str_replace(PHP_EOL.PHP_EOL, PHP_EOL, $contents);
//    $contents = str_replace('>'.PHP_EOL, '>', $contents);
    return $contents;
}

function reset_newline_win($contents) {
    // 优化换行符
    $contents = str_replace("\r\n", "\n", $contents);
    $contents = str_replace("\r", "\n", $contents);
    $contents = str_replace("\n", PHP_EOL, $contents);

    return $contents;
}

function fix_newline($data) {
    $data = str_replace("\r", "\n", $data);
    while(strpos($data, "\n\n") !== false) {
        $data = str_replace("\n\n", "\n", $data);
    }
    $data = str_replace("\n", PHP_EOL, $data);

    return $data;
}

function clean_contents($contents) {
//    $str = preg_replace('#<([^>\s/]+)[^>]*>#','<$1>', $contents);
//    return $str;
    $sa = new cleanHtml;  
    $sa->allow = array( 'src' );    
    $sa->exceptions = array(  
    'img' => array( 'src', 'alt' ),  
    //'a' => array( 'href', 'title' ),  
    'iframe'=>array('src','frameborder'),  
    ); 
    $str = $sa->strip( $contents );   

    return $str;
}


function xfm_strong_str_replace_once($search, $replace, $subject) {
    $firstChar = strpos($subject, $search);
    if($firstChar !== false) {
        $beforeStr = substr($subject,0,$firstChar);
        $afterStr = substr($subject, $firstChar + strlen($search));
        return $beforeStr.$replace.$afterStr;
    } else {
        return $subject;
    }
}

//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
function curl_request($url,$post='',$cookie='', $returnCookie=0){
    if (! extension_loaded('curl')) {
        file_exists('./ext/php_curl.dll') && dl('php_curl.dll'); // 加载扩展
    }
    
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
    if (ini_get('open_basedir') == '' && strtolower(ini_get('safe_mode')) != 'on'){ 
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    }
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
        curl_setopt($curl, CURLOPT_REFERER, "http://XXX");
        if($post) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
        }
        if($cookie) {
            curl_setopt($curl, CURLOPT_COOKIE, $cookie);
        }
        curl_setopt($curl, CURLOPT_HEADER, $returnCookie);
        curl_setopt($curl, CURLOPT_TIMEOUT, 150);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($curl);
        if (curl_errno($curl)) {
            return curl_error($curl);
        }
        curl_close($curl);
        if($returnCookie){
            list($header, $body) = explode("\r\n\r\n", $data, 2);
            preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches);
            $info['cookie']  = substr($matches[1][0], 1);
            $info['content'] = $body;
            return $info;
        }else{
            return $data;
        }
}

//echo $tag;
// 计算中文字符串长度
function utf8_strlen($string = null) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
return count($match[0]);
}
?>
最后修改日期: 2021年4月15日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。