3 J9 T) y* @7 X) M2 K: x- <?php
7 } s9 M: T8 i" t0 F! W+ p - //數據庫參數( c/ o2 u0 Z) O7 C( U
- $$dbuser='';
, x" a7 J6 ^! L7 F5 A! \ - $$dbpwd='';
9 h- H7 U1 O4 Z0 E - $$dbname='';0 E$ l7 c2 S3 e: B: x
- $$dbhost='';; ]2 ` W' k$ V6 I" i% d! M' e, A
- $$dbtable='';
# ?. Q2 B' U3 z: W
) @0 |, T9 X3 C, I% b C& ?; {- //設置讀取路徑
9 C% K/ k- l; ]" Z, [$ g - $$rdcontent='xxxx.txt';: l( v: C5 ?; [, ?) U& S) k
- $$rdtitle='xxxxtitle.txt';1 p3 D: z6 Z6 R2 C4 t4 o
- $$rdlink='xxxxlink.txt';' c! x1 D( D/ M$ l
9 ]; N( r+ Z; X' ]7 b# X4 A: @, J- //讀取插入鏈接,並設置發佈概率$ i1 [7 l4 o' e3 E: L" G9 ?! x
- function gen_link($$rdlink){5 n9 R) N. y1 c. h( H7 S; a) f
- $$data2 = file($$rdlink);8 @# o, a4 W" Q3 [' e) {
- $$num2 = count($$data2);1 z/ q/ F) X& B+ l% g9 C
- $$id2= mt_rand(0,$$num2-1);4 s0 a7 @- I5 }
- $$random= mt_rand(0,10);6 c: ?' i/ i! C# a
- if($$random<5)
4 o, `& g3 y7 |: _& v7 h, ^ - $$link= trim($$data2[$$id2]);
8 A# f0 w. ~# J# Z$ G) f: [+ K - else
8 A9 w8 |6 U7 q* G' m; p: V' a, _ - $$link="";% Q, ^3 d7 B5 |$ E
- return $$link;
2 j" {# T" l- s" z* K" o - }
( R! t& ?- c5 l0 u/ X- b( J; y! |6 F6 G - + C, j2 J. d6 o/ c* g) i
- //生成文章, B* z, E( Y& Y& ]9 h% w, X7 _
- $$str = "";; B( T4 \: i/ t8 x4 h1 |9 x
- $$title = "";+ I$ ^" k1 u4 T" C
, Q+ A4 j5 S/ j: v' ?6 }' ~- $$data2 = file($$rdtitle);+ E& G |+ r( \* i% m P2 }
- $$num2 = count($$data2);, b7 t+ C$ C5 D; o7 @* f. A ]% i
- $$id2 = mt_rand(0,$$num2-1);. v( }" K4 ?0 l; X6 K# `% i# t
- $$title = $$data2[$$id2];- Z0 R x* L) l; |
. ^' P H6 D8 f% E2 F1 P- $$data = file($$rdcontent);
4 J3 J' Z3 R/ q5 _' z - $$num = count($$data);! {+ w3 U' I: l
- ) M& |2 F' }' h& L! y
- for($$i=0;$$i<25;$$i++){
) E" `& I9 D+ w- S% \3 D1 \ - $$temp=" ";
/ {. L; |* Y4 z- v) w& k& [9 u1 Y - if(($$i%5)==0)) P, T) P8 f2 [% E$ r% ~
- $$temp="
! m8 q2 V3 M" r( t - \n";2 B2 m3 _) T& h$ Z
- elseif(($$i==7)|($$i==21)){ \+ G8 R5 U* B. z$ a) s
- $$links=gen_link($$rdlink);
; o1 c( e, c* ] - $$str=$$str." ".$$links." ";
: s7 M4 Y$ b6 V2 {- o4 g - }/ d2 a1 K4 S8 G* x( b$ X
- $$id = mt_rand(0, $$num-1);. I/ Z7 S2 r, {1 c3 S
- $$line = trim($$data[$$id]);& Z b! H7 F& U8 Z% e
- $$str=$$str.$$temp.$$line;, D+ C* K7 F# N9 z
- }0 u: u* \4 V* o& T
) M/ P. @% t4 k1 T& o( @. n$ \- //生成slug5 m* U k7 B( O! ~8 h
- function generate_slug($$len){
" \ t( s& l( L; l - $$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';, H& z) {+ y& ?$ L+ x5 U4 \" U
- $$slug="";7 A( t; i5 A) K/ X6 K# ^
- for($$j=0;$$j<$$len;$$j++){
; c% L* Q R: q$ M3 X8 a - $$slug .= $$chars[ mt_rand(0, strlen($$chars) - 1) ];; P- a1 d5 `$ Y; I. M E! @% x
- }
" `# @) p/ d& ?0 @) h2 M7 o" e - return $$slug;- f( ^6 q" I7 ?2 r" @) R7 l
- }! B8 r, x2 t/ p1 Y8 j4 r$ L6 z
- $$slug = generate_slug(17);
' m, @2 M3 P0 G7 s" f& r1 t
( @/ K) X. u0 ?5 }" e( M; z7 ~- //獲取發佈時間2 A* h. t+ j4 Z0 ]/ G/ q @
- $$datetime= date("Y-m-d H:i:s");
- W! L0 S% v+ B# R! G' c& f2 d
3 P6 J" f: w: e- |3 U8 q/ L" X- $$sql= "INSERT INTO `$$dbtable` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '1', '$$datetime', '$$datetime','$$str','$$title', '', 'publish', 'open', 'open', '', '$$slug', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', '0', '', '0', 'post', '', '0')";3 |+ d% j2 F9 t# N
- " y5 g: w5 {- T& C( j0 I8 f
- //連接數據庫並處理數據 {1 F6 v2 C8 I! O) m
- $$con = mysql_connect($$dbhost,$$dbuser,$$dbpwd);! H' K4 l; }2 P0 T6 G: U0 x& ~
- if(!$$con){: E3 ^- j: G3 C) b
- die('Failed to connect to database! '.mysql_error());5 A; q7 i- v2 c( D2 |
- }else+ ]4 @5 x' g2 c& `
- echo "Suscess to connect to database!, d) q4 i7 X& Z1 v( W( L" ^# ~, }% L
- \n";
! T: q) Y% k6 T0 x; D
2 l {' y* {! F& b* m2 {- mysql_select_db($$dbname,$$con);& N4 C/ M9 K8 l$ ~
- " [3 k2 w; e; G- y' h# M
- $$result=mysql_query($$sql);
! n1 T! z: s2 @# |2 n) j5 a - , w' I# o( n O3 ?
- ) I" x1 d: ]$ M) d, I
- //前面已經插入,獲取插入id! g2 v) Q+ r! U
- $$insert_id = mysql_insert_id();% y/ h, l% x! C3 }9 G# b! w
8 x. a: r# d+ S" p1 y$ J7 `- //繼續插入wp_term_relationship表
) k( q& s v+ q' L; r# ^ - if($$insert_id > 0 ){7 E; M6 K4 f, `0 f* P' J* |
- $$sql= "INSERT INTO `$$dbtable` (`object_id`, `term_taxonomy_id`, `term_order`) VALUES (NULL, '$$insert_id', NULL)";
( u+ d h2 R2 H H$ t/ ]
% a( a; `/ o5 ~0 b# g- $$result=mysql_query($$sql);( O: M, ^+ m9 `! L
- }4 l+ r' `8 Q8 y2 ]
- //關閉數據庫連接8 z3 @6 M: V4 k2 X; u& ^/ N; X0 t
- mysql_close($$con);2 k. w/ ]/ a6 u4 C1 e8 l2 `# m
' j# W, ]5 E0 {* l2 n! M
4 A& Q9 [# c9 d
+ c% E% t& ~( o" s8 C# M. l D- if(!$$result){+ ~0 [ |# f& v3 o# T3 T
- echo $$result;5 z: P5 @4 `, n3 J
- die('Failed to post article! '.mysql_error());. `) }# |) p& z) \
- }else
7 l, W& @ \8 W& [6 Y - echo "Suscess to post article!\n";
4 p1 y- P4 }) U3 P: |3 ], p - / J+ Q+ W6 s3 b5 ]1 Q* J; ?
- echo $$dbname." is done";- n8 ?4 t+ L; D. t6 E+ ]; Y
! ?3 W& h, n& p/ j' z- ?>3 S3 ?/ U4 U4 e. k
' o$ e. W: u! s/ s
: [& T1 n( e/ X1 G9 N) b! p3 `
8 M& v8 U* Y) S3 p, D- 2 Z1 h% [% j7 a- X- g
複製代碼 代碼給你改了下,wp_term_relationship表插入的值,你應該還需要改一下,因為我已經忘了這幾個表的關係了,剩下你的分享很好,我們一般使用付費cronjob,因為這種東西穩定性很重要,可以搜索setcronjob
- T2 o7 T2 F- ]
) m; U1 U, Q# Y h6 v4 u' W. Z
1 X2 r3 _+ V5 o3 s, z( Z! F+ R如果你需要第1次插入的某些值,你需要在if($insert_id > 0 )下面再增加一個select的查詢# O& W- j( j, Y
前面既然都是插入的內容,那麼插入的內容事先就已經知道的,所以沒有必要做這個select查詢
& T7 S% e: Y) @" r* J; _( ]# [ |7 J% v5 z
|