├── README.md ├── ta-article-setting.php ├── ta-functions.php └── targetany.php /README.md: -------------------------------------------------------------------------------- 1 | # newcrawler-wordpress 2 | NewCrawler Wordpress Plugin 3 | 4 | 1.Download Plugin 5 | 6 | >Clone or download > Download ZIP 7 | 8 | 2.Install Plugin 9 | 10 | >Wordpress > Plugins > Add New > Upload Plugin > (Select file)Install Now 11 | -------------------------------------------------------------------------------- /ta-article-setting.php: -------------------------------------------------------------------------------- 1 | 13 | 20 | 21 |

更新成功!

'; 28 | } 29 | ?> 30 |
31 |

鸟巢采集器

32 |
33 | 34 | 35 |
36 |
37 |

发布设置

38 |
39 | 40 | 41 | 42 | 43 | 44 | ( https://github.com/speed/newcrawler-wordpress ) 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 57 | 58 | 59 | 60 | 63 | 64 | 65 | 68 | 71 | 72 |
插件版本:鸟巢采集器WordPress发布插件 v3.1.3
官网地址:www.newcrawler.com
发布密码: 55 | ( 建议修改成自己的常用密码,并填入鸟巢采集器导出到 WordPress 选项中的发布密码输入框内 ) 56 |
您网站访问地址为: 61 | ( 此地址为您网站访问地址,您可以复制该链接并填入鸟巢采集器导出到 WordPress 发布接口配置中的发布网址输入框内) 62 |
66 | 67 | 69 | 70 |
73 |
74 | 75 |
76 |
-------------------------------------------------------------------------------- /ta-functions.php: -------------------------------------------------------------------------------- 1 | $result, "data" => $data, "message" => urlencode($message)))); 19 | } 20 | 21 | // Get Real Url for 302 URL 22 | function ta_redirect_url($url) { 23 | if (empty($url)) { 24 | return false; 25 | } 26 | if(stripos($url, "static.newcrawler.com") === false){ 27 | //if not hosted by newcrawler 28 | return array('realurl' => $url, 'referer' => ""); 29 | } 30 | $result = ta_curl_headers($url.'-dl'); 31 | if ($result !== false && strpos($result, "302 Moved Temporarily")) { 32 | $headers = preg_split("/\r\n+/", $result); 33 | if (is_array($headers)) { 34 | $real_url = null; 35 | $referer = ''; 36 | $suffix = ''; 37 | foreach ($headers as $header) { 38 | $header = trim($header); 39 | $locpos = stripos($header, "location"); 40 | $refererpos = stripos($header, "X-Referer"); 41 | if ($locpos === 0) { 42 | $pp = strpos($header, ":"); 43 | $real_url = trim(substr($header, $pp + 1)); 44 | }else if ($refererpos === 0) { 45 | $pp = strpos($header, ":"); 46 | $referer = trim(substr($header, $pp + 1)); 47 | } 48 | } 49 | if (!empty($real_url) && stripos($real_url, "http") === 0) { 50 | return array('realurl' => $real_url, 'referer' => $referer); 51 | } 52 | } 53 | } 54 | return false; 55 | } 56 | 57 | function ta_curl_headers($url) { 58 | // 初始化Curl 59 | $ch = curl_init(); 60 | // 开启header显示 61 | curl_setopt($ch, CURLOPT_HEADER, true); 62 | // 不输出网页内容 63 | curl_setopt($ch, CURLOPT_NOBODY, true); 64 | // 禁止自动输出内容 65 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 66 | // 自动跳转 67 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 68 | // 跳转时自动设置来源地址 69 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); 70 | // 超时时间 71 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); 72 | // 设置URL 73 | curl_setopt($ch, CURLOPT_URL, $url); 74 | // 关闭SSL证书验证 75 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 76 | // 返回结果 77 | return curl_exec($ch); 78 | } 79 | 80 | function ta_log($data) { 81 | if ($data && (is_array($data) || is_object($data))) { 82 | if (method_exists($data, 'jsonSerialize')) { 83 | $data = $data->jsonSerialize(); 84 | } 85 | $str = json_encode($data); 86 | } else { 87 | $str = $data; 88 | } 89 | $myfile = fopen("ta_log.txt", "a") or die("Unable to open file!"); 90 | fwrite($myfile, $str); 91 | fclose($myfile); 92 | } 93 | 94 | function ta_random_ip(){ 95 | $ip_long = array( 96 | array('607649792', '608174079'), //36.56.0.0-36.63.255.255 97 | array('1038614528', '1039007743'), //61.232.0.0-61.237.255.255 98 | array('1783627776', '1784676351'), //106.80.0.0-106.95.255.255 99 | array('2035023872', '2035154943'), //121.76.0.0-121.77.255.255 100 | array('2078801920', '2079064063'), //123.232.0.0-123.235.255.255 101 | array('-1950089216', '-1948778497'), //139.196.0.0-139.215.255.255 102 | array('-1425539072', '-1425014785'), //171.8.0.0-171.15.255.255 103 | array('-1236271104', '-1235419137'), //182.80.0.0-182.92.255.255 104 | array('-770113536', '-768606209'), //210.25.0.0-210.47.255.255 105 | array('-569376768', '-564133889'), //222.16.0.0-222.95.255.255 106 | ); 107 | $rand_key = mt_rand(0, 9); 108 | $ip = long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1])); 109 | return $ip; 110 | } 111 | -------------------------------------------------------------------------------- /targetany.php: -------------------------------------------------------------------------------- 1 | $postPassword, 69 | 'post_status' => $postStatus, 70 | 'post_author' => 1 71 | ); 72 | if (!empty($title)) { 73 | $my_post['post_title'] = htmlspecialchars_decode($title); 74 | } 75 | if (!empty($content)) { 76 | $my_post['post_content'] = htmlspecialchars_decode($content); 77 | } 78 | 79 | 80 | $publish_time = intval($_POST["article_publish_time"]); 81 | if (!empty($publish_time)) { 82 | $my_post['post_date'] = date("Y-m-d", $publish_time); 83 | } else { 84 | $my_post['post_date'] = date("Y-m-d", time()); 85 | } 86 | 87 | $author = htmlspecialchars_decode($_POST["article_author"]); 88 | 89 | if (!empty($author)) { 90 | $md5author = substr(md5($author), 8, 16); 91 | $user_id = username_exists($md5author); 92 | if (!$user_id) { 93 | $random_password = wp_generate_password(); 94 | $userdata = array( 95 | 'user_login' => $md5author, 96 | 'user_pass' => $random_password, 97 | 'display_name' => $author, 98 | ); 99 | 100 | $user_id = wp_insert_user($userdata); 101 | if (is_wp_error($user_id)) { 102 | $user_id = 0; 103 | } 104 | } 105 | if ($user_id) { 106 | $my_post['post_author'] = $user_id; 107 | } 108 | } 109 | $article_categories = $_POST["article_categories"]; 110 | if (!empty($article_categories)) { 111 | $rawCates = stripslashes($article_categories); 112 | $cates = json_decode($rawCates); 113 | if (is_array($cates)) { 114 | $post_cates = array(); 115 | foreach ($cates as $cate) { 116 | $term = term_exists($cate, "category"); 117 | 118 | if ($term === 0 || $term === null) { 119 | $term = wp_insert_term($cate, "category"); 120 | } 121 | if ($term !== 0 && $term !== null) { 122 | array_push($post_cates, intval($term["term_id"])); 123 | } 124 | } 125 | if (count($post_cates) > 0) { 126 | $my_post['post_category'] = $post_cates; 127 | } 128 | } 129 | } 130 | 131 | $article_topics = $_POST["article_topics"]; 132 | if (!empty($article_topics)) { 133 | $rawTags = stripslashes($article_topics); 134 | $tags = json_decode($rawTags); 135 | 136 | if (is_array($tags)) { 137 | $post_tags = array(); 138 | $term = null; 139 | foreach ($tags as $tag) { 140 | $term = term_exists($tag, "post_tag"); 141 | 142 | if ($term === 0 || $term === null) { 143 | $term = wp_insert_term($tag, "post_tag"); 144 | } 145 | if ($term !== 0 && $term !== null) { 146 | array_push($post_tags, intval($term["term_id"])); 147 | } 148 | } 149 | if (count($post_tags) > 0) { 150 | $my_post['tags_input'] = $post_tags; 151 | } 152 | } 153 | } 154 | 155 | // Insert the post into the database 156 | kses_remove_filters(); 157 | $post_id = wp_insert_post($my_post); //wp_insert_user wp_insert_comment wp_insert_category 158 | kses_init_filters(); 159 | 160 | if (empty($post_id)) { 161 | ta_fail(TA_ERROR_ERROR, "Empty Post ID", "插入系统失败"); 162 | } 163 | 164 | if(!empty($_POST["article_thumbnail"])){ 165 | $image_url = ta_redirect_url($_POST["article_thumbnail"]); // Define the image URL here 166 | //创建thumbnail 167 | // Add Featured Image to Post 168 | if ($image_url !== false && !empty($post_id)) { 169 | $upload_dir = wp_upload_dir(); // Set upload folder 170 | $image_data = file_get_contents($image_url['realurl']); // Get image data 171 | $suffix = "jpg"; 172 | $filename = md5($image_url['realurl']) . ".". $suffix; // Create image file name 173 | // Check folder permission and define file location 174 | if (wp_mkdir_p($upload_dir['path'])) { 175 | $file = $upload_dir['path'] . '/' . $filename; 176 | } else { 177 | $file = $upload_dir['basedir'] . '/' . $filename; 178 | } 179 | 180 | // Create the image file on the server 181 | file_put_contents($file, $image_data); 182 | if (file_exists($file)) { 183 | //文件存在 在做插入 184 | // Check image file type 185 | $wp_filetype = wp_check_filetype($filename, null); 186 | 187 | // Set attachment data 188 | $attachment = array( 189 | 'post_mime_type' => $wp_filetype['type'], 190 | 'post_title' => sanitize_file_name($filename), 191 | 'post_content' => '', 192 | 'post_status' => 'inherit' 193 | ); 194 | 195 | // Create the attachment 196 | $attach_id = wp_insert_attachment($attachment, $file, $post_id); 197 | 198 | // Include image.php 199 | require_once(ABSPATH . 'wp-admin/includes/image.php'); 200 | 201 | // Define attachment metadata 202 | $attach_data = wp_generate_attachment_metadata($attach_id, $file); 203 | 204 | // Assign metadata to attachment 205 | wp_update_attachment_metadata($attach_id, $attach_data); 206 | 207 | // And finally assign featured image to post 208 | set_post_thumbnail($post_id, $attach_id); 209 | } 210 | } 211 | } 212 | 213 | //插入评论 214 | $comment_json = preg_replace("/[\r\n\t]/", '', $_POST['article_comment']); 215 | //ta_fail(TA_ERROR_ERROR, "DEBUG", "".$comment_json); 216 | $article_comment = json_decode(stripslashes($comment_json), true); 217 | 218 | if($article_comment != null && is_array($article_comment)){ 219 | foreach($article_comment as $comment){ 220 | $content = $comment["article_comment_content"]; 221 | if(!empty($content)){ 222 | //内容不是空 223 | 224 | $pub_time = $comment["article_comment_publish_time"]; 225 | if(empty($pub_time)){ 226 | $pub_time = time(); 227 | } 228 | 229 | $cdata = array( 230 | 'comment_post_ID' => $post_id, 231 | 'comment_content' => $content, 232 | 'comment_type' => '', 233 | 'comment_parent' => 0, 234 | 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)', 235 | 'comment_date' => date("Y-m-d H:i:s",$pub_time), 236 | 'comment_approved' => 1, 237 | ); 238 | 239 | $cauthor = $comment["article_comment_author"]; 240 | 241 | if (!empty($cauthor)) { 242 | $cmd5author = substr(md5($cauthor), 8, 16); 243 | $cuser_id = username_exists($cmd5author); 244 | if (!$cuser_id) { 245 | $random_password = wp_generate_password(); 246 | $cuserdata = array( 247 | 'user_login' => $cmd5author, 248 | 'user_pass' => $random_password, 249 | 'display_name' => $cauthor, 250 | ); 251 | 252 | $cuser_id = wp_insert_user($cuserdata); 253 | if (is_wp_error($cuser_id)) { 254 | $cuser_id = 0; 255 | } 256 | } 257 | if($cuser_id != 0){ 258 | $cdata["user_id"] = $cuser_id; 259 | } 260 | $cdata["comment_author"] = $cauthor; 261 | $cdata['comment_author_IP'] = ta_random_ip(); 262 | } 263 | 264 | wp_insert_comment($cdata); 265 | } 266 | } 267 | } 268 | 269 | 270 | 271 | ta_success(array("url" => get_home_url() . "/?p=" . $post_id)); 272 | } else if ($_GET["__ta"] == "details") { 273 | if (empty($_POST['__sign']) || $_POST['__sign'] != $ta_password) { 274 | ta_fail(TA_ERROR_INVALID_PWD, "password is wrong", "发布密码填写错误"); 275 | } 276 | $ret = array(array("value" => "", "text" => urlencode("爬取到的分类"))); 277 | 278 | if ($_POST["type"] === "cate") { 279 | $cates = get_terms('category', 'orderby=count&hide_empty=0'); 280 | 281 | foreach ($cates as $cate) { 282 | array_push($ret, array("value" => urlencode($cate->name), "text" => urlencode($cate->name))); 283 | } 284 | } 285 | 286 | ta_success($ret); 287 | } else if ($_GET["__ta"] == "version") { 288 | global $wp_version; 289 | if (empty($_POST['__sign']) || $_POST['__sign'] != $ta_password) { 290 | ta_fail(TA_ERROR_INVALID_PWD, "password is wrong", "发布密码填写错误"); 291 | } 292 | $info = array( 293 | 'protocol' => '1', 294 | 'protocolVersion' => '1', 295 | 'supportStdVersion' => array( 296 | 'article' => '1.0.0', 297 | 'question' => '1.0.0' 298 | ), 299 | 'php' => PHP_VERSION, 300 | 'supportVersion' => 'wp 4.5.1', 301 | 'version' => '3.1.3', 302 | 'pubVersion' => '3.1.3', 303 | 'versionDetail' => array('wp' => $wp_version), 304 | 'otherInfo' => array() 305 | ); 306 | ta_success($info); 307 | } 308 | } --------------------------------------------------------------------------------