{"id":557,"date":"2023-02-27T06:16:11","date_gmt":"2023-02-26T22:16:11","guid":{"rendered":"https:\/\/me.spacelite.top\/?p=557"},"modified":"2023-02-27T06:17:04","modified_gmt":"2023-02-26T22:17:04","slug":"wordpress%e5%ae%9e%e7%8e%b0%e6%96%87%e7%ab%a0%e4%b8%ad%e8%bf%9c%e7%a8%8b%e5%a4%96%e9%93%be%e5%9b%be%e7%89%87%e8%87%aa%e5%8a%a8%e6%9c%ac%e5%9c%b0%e5%8c%96%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/me.spacelite.top\/?p=557","title":{"rendered":"WordPress\u5b9e\u73b0\u6587\u7ae0\u4e2d\u8fdc\u7a0b(\u5916\u94fe)\u56fe\u7247\u81ea\u52a8\u672c\u5730\u5316\u7684\u65b9\u6cd5"},"content":{"rendered":"<div class=\"\">\n<p>\u590d\u5236\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u7136\u540e\u7c98\u8d34\u5230\u4f60\u5f53\u524dWordPress \u4e3b\u9898\u7684\u6a21\u7248\u51fd\u6570(functions.php)\u6587\u4ef6\u4e2d\u4fdd\u5b58\u5373\u53ef\u3002<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-group\">\n<div class=\"wp-block-group__inner-container\">\n<div class=\"enlighter-default enlighter-v-standard enlighter-t-dracula enlighter-hover enlighter-overflow-scroll\">\n<div class=\"enlighter\">\n<div class=\"\">\n<pre class=\"enlighter-clipboard\"><code>\/\/\u81ea\u52a8\u672c\u5730\u5316\u5916\u94fe\u56fe\u7247\r\nadd_filter('content_save_pre', 'auto_save_image');\r\nfunction auto_save_image($content) {\r\n$upload_path = '';\r\n$upload_url_path = get_bloginfo('url');\r\n\/\/\u4e0a\u4f20\u76ee\u5f55\r\nif (($var = get_option('upload_path')) !=''){\r\n$upload_path = $var;\r\n} else {\r\n$upload_path = 'wp-content\/uploads';\r\n}\r\nif(get_option('uploads_use_yearmonth_folders')) {\r\n$upload_path .= '\/'.date(\"Y\",time()).'\/'.date(\"m\",time());\r\n}\r\n\/\/\u6587\u4ef6\u5730\u5740\r\nif(($var = get_option('upload_url_path')) != '') {\r\n$upload_url_path = $var;\r\n} else {\r\n$upload_url_path = bloginfo('url');\r\n}\r\nif(get_option('uploads_use_yearmonth_folders')) {\r\n$upload_url_path .= '\/'.date(\"Y\",time()).'\/'.date(\"m\",time());\r\n}\r\nrequire_once (\"..\/wp-includes\/class-snoopy.php\");\r\n$snoopy_Auto_Save_Image = new Snoopy;\r\n$img = array();\r\n\/\/\u4ee5\u6587\u7ae0\u7684\u6807\u9898\u4f5c\u4e3a\u56fe\u7247\u7684\u6807\u9898\r\nif ( !empty( $_REQUEST['post_title'] ) )\r\n$post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));\r\n$text = stripslashes($content);\r\nif (get_magic_quotes_gpc()) $text = stripslashes($text);\r\npreg_match_all(\"\/ src=(\\\"|\\'){0,}(http:\\\/\\\/(.+?))(\\\"|\\'|\\s)\/is\",$text,$img);\r\n$img = array_unique(dhtmlspecialchars($img[2]));\r\nforeach ($img as $key =&gt; $value){\r\nset_time_limit(180); \/\/\u6bcf\u4e2a\u56fe\u7247\u6700\u957f\u5141\u8bb8\u4e0b\u8f7d\u65f6\u95f4,\u79d2\r\nif(str_replace(get_bloginfo('url'),\"\",$value)==$value&amp;&amp;str_replace(get_bloginfo('home'),\"\",$value)==$value){\r\n\/\/\u5224\u65ad\u662f\u5426\u662f\u672c\u5730\u56fe\u7247\uff0c\u5982\u679c\u4e0d\u662f\uff0c\u5219\u4fdd\u5b58\u5230\u670d\u52a1\u5668\r\n$fileext = substr(strrchr($value,'.'),1);\r\n$fileext = strtolower($fileext);\r\nif($fileext==\"\"||strlen($fileext)&gt;4)\r\n$fileext = \"jpg\";\r\n$savefiletype = array('jpg','gif','png','bmp');\r\nif (in_array($fileext, $savefiletype)){\r\nif($snoopy_Auto_Save_Image-&gt;fetch($value)){\r\n$get_file = $snoopy_Auto_Save_Image-&gt;results;\r\n}else{\r\necho \"error fetching file: \".$snoopy_Auto_Save_Image-&gt;error.\"&lt;br&gt;\";\r\necho \"error url: \".$value;\r\ndie();\r\n}\r\n$filetime = time();\r\n$filepath = \"\/\".$upload_path;\/\/\u56fe\u7247\u4fdd\u5b58\u7684\u8def\u5f84\u76ee\u5f55\r\n!is_dir(\"..\".$filepath) ? mkdirs(\"..\".$filepath) : null;\r\n\/\/$filename = date(\"His\",$filetime).random(3);\r\n$filename = substr($value,strrpos($value,'\/'),strrpos($value,'.')-strrpos($value,'\/'));\r\n\/\/$e = '..\/'.$filepath.$filename.'.'.$fileext;\r\n\/\/if(!is_file($e)) {\r\n\/\/ copy(htmlspecialchars_decode($value),$e);\r\n\/\/}\r\n$fp = @fopen(\"..\".$filepath.$filename.\".\".$fileext,\"w\");\r\n@fwrite($fp,$get_file);\r\nfclose($fp);\r\n$wp_filetype = wp_check_filetype( $filename.\".\".$fileext, false );\r\n$type = $wp_filetype['type'];\r\n$post_id = (int)$_POST['temp_ID2'];\r\n$title = $post_title;\r\n$url = $upload_url_path.$filename.\".\".$fileext;\r\n$file = $_SERVER['DOCUMENT_ROOT'].$filepath.$filename.\".\".$fileext;\r\n\/\/\u6dfb\u52a0\u6570\u636e\u5e93\u8bb0\u5f55\r\n$attachment = array(\r\n'post_type' =&gt; 'attachment',\r\n'post_mime_type' =&gt; $type,\r\n'guid' =&gt; $url,\r\n'post_parent' =&gt; $post_id,\r\n'post_title' =&gt; $title,\r\n'post_content' =&gt; '',\r\n);\r\n$id = wp_insert_attachment($attachment, $file, $post_parent);\r\n$text = str_replace($value,$url,$text); \/\/\u66ff\u6362\u6587\u7ae0\u91cc\u9762\u7684\u56fe\u7247\u5730\u5740\r\n}\r\n}\r\n}\r\n$content = AddSlashes($text);\r\nremove_filter('content_save_pre', 'auto_save_image');\r\nreturn $content;\r\n}\r\nfunction mkdirs($dir)\r\n{\r\nif(!is_dir($dir))\r\n{\r\nmkdirs(dirname($dir));\r\nmkdir($dir);\r\n}\r\nreturn ;\r\n}\r\nfunction dhtmlspecialchars($string) {\r\nif(is_array($string)) {\r\nforeach($string as $key =&gt; $val) {\r\n$string[$key] = dhtmlspecialchars($val);\r\n}\r\n}else{\r\n$string = str_replace('&amp;', '&amp;', $string);\r\n$string = str_replace('\"', '\"', $string);\r\n$string = str_replace('&lt;', '&lt;', $string);\r\n$string = str_replace('&gt;', '&gt;', $string);\r\n$string = preg_replace('\/&amp;(#\\d;)\/', '&amp;\\1', $string);\r\n}\r\nreturn $string;\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u590d\u5236\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u7136\u540e\u7c98\u8d34\u5230\u4f60\u5f53\u524dWordPress \u4e3b\u9898\u7684\u6a21\u7248\u51fd\u6570(functions.php)\u6587\u4ef6&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-557","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/me.spacelite.top\/index.php?rest_route=\/wp\/v2\/posts\/557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/me.spacelite.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/me.spacelite.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/me.spacelite.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/me.spacelite.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=557"}],"version-history":[{"count":2,"href":"https:\/\/me.spacelite.top\/index.php?rest_route=\/wp\/v2\/posts\/557\/revisions"}],"predecessor-version":[{"id":559,"href":"https:\/\/me.spacelite.top\/index.php?rest_route=\/wp\/v2\/posts\/557\/revisions\/559"}],"wp:attachment":[{"href":"https:\/\/me.spacelite.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/me.spacelite.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/me.spacelite.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}