connect.php 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406
  1. <?php
  2. error_reporting(E_ALL ^ E_NOTICE);
  3. define('InEmpireCMS',TRUE);
  4. define('ECMS_PATH',substr(dirname(__FILE__),0,-7));
  5. define('MAGIC_QUOTES_GPC',function_exists('get_magic_quotes_gpc')&&get_magic_quotes_gpc());
  6. define('STR_IREPLACE',function_exists('str_ireplace'));
  7. define('ECMS_PNO',EcmsGetProgramNo());
  8. $ecms_config=array();
  9. $ecms_adminloginr=array();
  10. $ecms_hashur=array();
  11. $emoreport_r=array();
  12. $public_r=array();
  13. $public_diyr=array();
  14. $emod_pubr=array();
  15. $etable_r=array();
  16. $emod_r=array();
  17. $notcj_r=array();
  18. $fun_r=array();
  19. $message_r=array();
  20. $qmessage_r=array();
  21. $enews_r=array();
  22. $class_r=array();
  23. $class_zr=array();
  24. $class_tr=array();
  25. $eyh_r=array();
  26. $schalltb_r=array();
  27. $level_r=array();
  28. $aglevel_r=array();
  29. $iglevel_r=array();
  30. $r=array();
  31. $addr=array();
  32. $paddr=array();
  33. $search='';
  34. $start=0;
  35. $addgethtmlpath='';
  36. $string='';
  37. $notcjnum=0;
  38. $editor=0;
  39. $ecms_gr=array();
  40. $navinfor=array();
  41. $pagefunr=array();
  42. $navclassid='';
  43. $navnewsid='';
  44. $cjnewsurl='';
  45. $formattxt='';
  46. $link='';
  47. $linkrd='';
  48. $empire='';
  49. $dbtbpre='';
  50. $efileftp='';
  51. $efileftp_fr=array();
  52. $efileftp_dr=array();
  53. $doetran=0;
  54. $ecmsvar_mbr=array();
  55. $ecms_tofunr=array();
  56. $ecms_topager=array();
  57. $ecms_topagesetr=array();
  58. $ecms_toboxr=array();
  59. $add='';
  60. $ecms_config['sets']['selfmoreportid']=0;
  61. $ecms_config['sets']['mainportpath']='';
  62. $ecms_config['sets']['pagemustdt']=0;
  63. $emoreport_r[1]['ppath']='';
  64. require_once ECMS_PATH.'e/config/config.php';
  65. if(!defined('EmpireCMSConfig'))
  66. {
  67. exit();
  68. }
  69. if($ecms_config['sets']['webdebug']==0)
  70. {
  71. error_reporting(0);
  72. }
  73. //超时设置
  74. if(defined('EmpireCMSAdmin'))
  75. {
  76. if($public_r['php_adminouttime'])
  77. {
  78. @set_time_limit($public_r['php_adminouttime']);
  79. }
  80. }
  81. else
  82. {
  83. if($public_r['php_outtime'])
  84. {
  85. @set_time_limit($public_r['php_outtime']);
  86. }
  87. }
  88. //页面编码
  89. if($ecms_config['sets']['setpagechar']==1)
  90. {
  91. if($ecms_config['sets']['pagechar']=='gb2312'||$ecms_config['sets']['pagechar']=='big5'||$ecms_config['sets']['pagechar']=='utf-8')
  92. {
  93. @header('Content-Type: text/html; charset='.$ecms_config['sets']['pagechar']);
  94. }
  95. }
  96. //时区
  97. if(function_exists('date_default_timezone_set'))
  98. {
  99. @date_default_timezone_set($ecms_config['sets']['timezone']);
  100. }
  101. if($ecms_config['db']['usedb']=='mysqli')
  102. {
  103. include(ECMS_PATH.'e/class/db/db_mysqli.php');
  104. }
  105. else
  106. {
  107. include(ECMS_PATH.'e/class/db/db_mysql.php');
  108. }
  109. //禁止IP
  110. eCheckAccessIp(0);
  111. DoSafeCheckFromurl();
  112. if(defined('EmpireCMSAdmin'))
  113. {
  114. eCheckAccessIp(1);//禁止IP
  115. EcmsCheckUserAgent($ecms_config['esafe']['ckhuseragent']);
  116. //FireWall
  117. if(!empty($ecms_config['fw']['eopen']))
  118. {
  119. DoEmpireCMSFireWall();
  120. }
  121. if(!empty($ecms_config['esafe']['ckhsession']))
  122. {
  123. session_start();
  124. define('EmpireCMSDefSession',TRUE);
  125. }
  126. }
  127. else
  128. {
  129. if(!empty($public_r['closeqdt']))
  130. {
  131. echo $public_r['closeqdtmsg'];
  132. exit();
  133. }
  134. }
  135. if($ecms_config['sets']['selfmoreportid']>1)
  136. {
  137. EcmsDefMoreport($ecms_config['sets']['selfmoreportid']);
  138. }
  139. //--------------- 数据库 ---------------
  140. function db_connect(){
  141. global $ecms_config;
  142. $dblink=do_dbconnect($ecms_config['db']['dbserver'],$ecms_config['db']['dbport'],$ecms_config['db']['dbusername'],$ecms_config['db']['dbpassword'],$ecms_config['db']['dbname']);
  143. return $dblink;
  144. }
  145. function return_dblink($query){
  146. $dblink=$GLOBALS['link'];
  147. return $dblink;
  148. }
  149. //设置编码
  150. function DoSetDbChar($dbchar){
  151. global $link;
  152. if($dbchar&&$dbchar!='auto')
  153. {
  154. do_DoSetDbChar($dbchar,$link);
  155. }
  156. }
  157. function db_close(){
  158. global $link;
  159. do_dbclose($link);
  160. }
  161. //--------------- 公共 ---------------
  162. //设置COOKIE
  163. function esetcookie($var,$val,$life=0,$ecms=0){
  164. global $ecms_config;
  165. //secure属性
  166. $cksecure=$ecms_config['cks']['cksecure'];
  167. if(!empty($cksecure))
  168. {
  169. $secure=0;
  170. if($cksecure==2)//开启
  171. {
  172. $secure=1;
  173. }
  174. elseif($cksecure==3)//后台开启
  175. {
  176. if(defined('EmpireCMSAdmin'))
  177. {
  178. $secure=1;
  179. }
  180. }
  181. elseif($cksecure==4)//前台开启
  182. {
  183. if(!defined('EmpireCMSAdmin'))
  184. {
  185. $secure=1;
  186. }
  187. }
  188. else
  189. {}
  190. }
  191. else
  192. {
  193. $secure=eCheckUseHttps();
  194. }
  195. //httponly属性
  196. $ckhttponly=$ecms_config['cks']['ckhttponly'];
  197. $httponly=0;
  198. if(!empty($ckhttponly))
  199. {
  200. if($ckhttponly==1)//开启
  201. {
  202. $httponly=1;
  203. }
  204. elseif($ckhttponly==2)//后台开启
  205. {
  206. if(defined('EmpireCMSAdmin'))
  207. {
  208. $httponly=1;
  209. }
  210. }
  211. elseif($ckhttponly==3)//前台开启
  212. {
  213. if(!defined('EmpireCMSAdmin'))
  214. {
  215. $httponly=1;
  216. }
  217. }
  218. else
  219. {}
  220. }
  221. //设置
  222. $varpre=empty($ecms)?$ecms_config['cks']['ckvarpre']:$ecms_config['cks']['ckadminvarpre'];
  223. $ckpath=$ecms_config['cks']['ckpath'];
  224. if(PHP_VERSION<'5.2.0')
  225. {
  226. if($httponly)
  227. {
  228. $ckpath.='; HttpOnly';
  229. }
  230. return setcookie($varpre.$var,$val,$life,$ckpath,$ecms_config['cks']['ckdomain'],$secure);
  231. }
  232. else
  233. {
  234. return setcookie($varpre.$var,$val,$life,$ckpath,$ecms_config['cks']['ckdomain'],$secure,$httponly);
  235. }
  236. }
  237. //返回cookie
  238. function getcvar($var,$ecms=0){
  239. global $ecms_config;
  240. $tvar=empty($ecms)?$ecms_config['cks']['ckvarpre'].$var:$ecms_config['cks']['ckadminvarpre'].$var;
  241. return $_COOKIE[$tvar];
  242. }
  243. //错误提示
  244. function printerror($error="",$gotourl="",$ecms=0,$noautourl=0,$novar=0){
  245. global $empire,$editor,$public_r,$ecms_config;
  246. if($editor==1){$a="../";}
  247. elseif($editor==2){$a="../../";}
  248. elseif($editor==3){$a="../../../";}
  249. else{$a="";}
  250. if($ecms==1||$ecms==9)
  251. {
  252. $a=ECMS_PATH.'e/data/';
  253. }
  254. if(strstr($gotourl,"(")||empty($gotourl))
  255. {
  256. if(strstr($gotourl,"(-2"))
  257. {
  258. $gotourl_js="history.go(-2)";
  259. $gotourl="javascript:history.go(-2)";
  260. }
  261. else
  262. {
  263. $gotourl_js="history.go(-1)";
  264. $gotourl="javascript:history.go(-1)";
  265. }
  266. }
  267. else
  268. {$gotourl_js="self.location.href='$gotourl';";}
  269. if(empty($error))
  270. {$error="DbError";}
  271. if($ecms==9)//前台弹出对话框
  272. {
  273. @include $a.LoadLang("pub/q_message.php");
  274. $error=empty($novar)?$qmessage_r[$error]:$error;
  275. echo"<script>alert('".$error."');".$gotourl_js."</script>";
  276. db_close();
  277. $empire=null;
  278. exit();
  279. }
  280. elseif($ecms==8)//后台弹出对话框
  281. {
  282. @include $a.LoadLang("pub/message.php");
  283. $error=empty($novar)?$message_r[$error]:$error;
  284. echo"<script>alert('".$error."');".$gotourl_js."</script>";
  285. db_close();
  286. $empire=null;
  287. exit();
  288. }
  289. elseif($ecms==7)//前台弹出对话框并关闭窗口
  290. {
  291. @include $a.LoadLang("pub/q_message.php");
  292. $error=empty($novar)?$qmessage_r[$error]:$error;
  293. echo"<script>alert('".$error."');window.close();</script>";
  294. db_close();
  295. $empire=null;
  296. exit();
  297. }
  298. elseif($ecms==6)//后台弹出对话框并关闭窗口
  299. {
  300. @include $a.LoadLang("pub/message.php");
  301. $error=empty($novar)?$message_r[$error]:$error;
  302. echo"<script>alert('".$error."');window.close();</script>";
  303. db_close();
  304. $empire=null;
  305. exit();
  306. }
  307. elseif($ecms==0)
  308. {
  309. @include $a.LoadLang("pub/message.php");
  310. $error=empty($novar)?$message_r[$error]:$error;
  311. @include($a."message.php");
  312. }
  313. else
  314. {
  315. @include $a.LoadLang("pub/q_message.php");
  316. $error=empty($novar)?$qmessage_r[$error]:$error;
  317. @include($a."../message/index.php");
  318. }
  319. db_close();
  320. $empire=null;
  321. exit();
  322. }
  323. //错误提示2:直接文字
  324. function printerror2($error='',$gotourl='',$ecms=0,$noautourl=0){
  325. global $empire,$public_r;
  326. if(strstr($gotourl,"(")||empty($gotourl))
  327. {
  328. if(strstr($gotourl,"(-2"))
  329. {
  330. $gotourl_js="history.go(-2)";
  331. $gotourl="javascript:history.go(-2)";
  332. }
  333. else
  334. {
  335. $gotourl_js="history.go(-1)";
  336. $gotourl="javascript:history.go(-1)";
  337. }
  338. }
  339. else
  340. {$gotourl_js="self.location.href='$gotourl';";}
  341. if($ecms==9)//弹出对话框
  342. {
  343. echo"<script>alert('".$error."');".$gotourl_js."</script>";
  344. }
  345. elseif($ecms==7)//弹出对话框并关闭窗口
  346. {
  347. echo"<script>alert('".$error."');window.close();</script>";
  348. }
  349. else
  350. {
  351. @include(ECMS_PATH.'e/message/index.php');
  352. }
  353. db_close();
  354. exit();
  355. }
  356. //ajax错误提示
  357. function ajax_printerror($result='',$ajaxarea='ajaxarea',$error='',$ecms=0,$novar=0){
  358. global $empire,$editor,$public_r,$ecms_config;
  359. if($editor==1){$a="../";}
  360. elseif($editor==2){$a="../../";}
  361. elseif($editor==3){$a="../../../";}
  362. else{$a="";}
  363. if($ecms==1)
  364. {
  365. $a=ECMS_PATH.'e/data/';
  366. }
  367. if($ecms==0)
  368. {
  369. @include $a.LoadLang("pub/message.php");
  370. $error=empty($novar)?$message_r[$error]:$error;
  371. }
  372. else
  373. {
  374. @include $a.LoadLang("pub/q_message.php");
  375. $error=empty($novar)?$qmessage_r[$error]:$error;
  376. }
  377. if(empty($ajaxarea))
  378. {
  379. $ajaxarea='ajaxarea';
  380. }
  381. $ajaxarea=ehtmlspecialchars($ajaxarea,ENT_QUOTES);
  382. $string=$result.'|'.$ajaxarea.'|'.$error;
  383. echo $string;
  384. db_close();
  385. $empire=null;
  386. exit();
  387. }
  388. //直接转向
  389. function printerrortourl($gotourl='',$error='',$sec=0){
  390. global $empire,$editor,$public_r,$ecms_config;
  391. echo'<meta http-equiv="refresh" content="'.$sec.';url='.$gotourl.'">'.$error;
  392. db_close();
  393. $empire=null;
  394. exit();
  395. }
  396. //编码转换
  397. function DoIconvVal($code,$targetcode,$str,$inc=0){
  398. global $editor;
  399. if($editor==1){$a="../";}
  400. elseif($editor==2){$a="../../";}
  401. elseif($editor==3){$a="../../../";}
  402. else{$a="";}
  403. if($inc)
  404. {
  405. @include_once(ECMS_PATH."e/class/doiconv.php");
  406. }
  407. $iconv=new Chinese($a);
  408. $str=$iconv->Convert($code,$targetcode,$str);
  409. return $str;
  410. }
  411. //初始化访问端
  412. function EcmsDefMoreport($pid){
  413. global $public_r,$ecms_config,$emoreport_r;
  414. if(empty($public_r['ckhavemoreport']))
  415. {
  416. exit();
  417. }
  418. $pid=(int)$pid;
  419. if($pid<=1||!$emoreport_r[$pid]['pid'])
  420. {
  421. exit();
  422. }
  423. if($emoreport_r[$pid]['isclose'])
  424. {
  425. echo'This visit port is close!';
  426. exit();
  427. }
  428. //关闭后台
  429. if(defined('EmpireCMSAdmin')&&$emoreport_r[$pid]['openadmin'])
  430. {
  431. if($emoreport_r[$pid]['openadmin']==1)
  432. {
  433. if(defined('EmpireCMSAPage'))
  434. {
  435. //echo'Admin close!';
  436. exit();
  437. }
  438. }
  439. else
  440. {
  441. //echo'Admin close!';
  442. exit();
  443. }
  444. }
  445. $ecms_config['sets']['deftempid']=$emoreport_r[$pid]['tempgid'];
  446. $ecms_config['sets']['pagemustdt']=$emoreport_r[$pid]['mustdt'];
  447. $ecms_config['sets']['mainportpath']=$emoreport_r[1]['ppath'];
  448. if($emoreport_r[$pid]['closeadd'])
  449. {
  450. $public_r['addnews_ok']=$emoreport_r[$pid]['closeadd'];
  451. }
  452. }
  453. //重置为主访问端模板组ID
  454. function Moreport_ResetMainTempGid(){
  455. global $ecms_config,$public_r,$emoreport_r;
  456. $pid=(int)$ecms_config['sets']['selfmoreportid'];
  457. if($pid<=1||!$emoreport_r[$pid]['pid'])
  458. {
  459. return '';
  460. }
  461. $ecms_config['sets']['deftempid']=$public_r['deftempid']?$public_r['deftempid']:1;
  462. }
  463. //转向访问端目录
  464. function Moreport_eSetSelfPath($pid,$ecms=0){
  465. global $empire,$dbtbpre,$public_r,$ecms_config;
  466. $pid=(int)$pid;
  467. $defpr=array();
  468. $defpr['ppath']='';
  469. if($pid<=1)
  470. {
  471. $pid=1;
  472. }
  473. $pr=$empire->fetch1("select * from {$dbtbpre}enewsmoreport where pid='$pid'");
  474. if(!$pr['ppath']||!file_exists($pr['ppath'].'e/config/config.php'))
  475. {
  476. return $defpr;
  477. }
  478. define('ECMS_SELFPATH',$pr['ppath']);
  479. $ecms_config['sets']['deftempid']=$pr['tempgid'];
  480. //缓存模板
  481. if($ecms==1)
  482. {
  483. $tr=$empire->fetch1("select downsofttemp,onlinemovietemp,listpagetemp from ".GetTemptb("enewspubtemp")." limit 1");
  484. $public_r['downsofttemp']=addslashes(stripSlashes($tr['downsofttemp']));
  485. $public_r['onlinemovietemp']=addslashes(stripSlashes($tr['onlinemovietemp']));
  486. $public_r['listpagetemp']=addslashes(stripSlashes($tr['listpagetemp']));
  487. }
  488. return $pr;
  489. }
  490. //autodo
  491. function eAutodo_AddDo($dotype,$classid,$id,$tid,$userid,$pid,$fname='',$ckdoall=1){
  492. return '';
  493. }
  494. //返回是否强制动态页
  495. function Moreport_ReturnMustDt(){
  496. global $ecms_config;
  497. return $ecms_config['sets']['pagemustdt'];
  498. }
  499. //返回是否强制动态页(加状态)
  500. function Moreport_ReturnMustDtAnd(){
  501. global $ecms_config;
  502. if(defined('ECMS_SELFPATH')&&$ecms_config['sets']['pagemustdt'])
  503. {
  504. return 1;
  505. }
  506. else
  507. {
  508. return 0;
  509. }
  510. }
  511. //返回强制动态页状态
  512. function Moreport_ReturnDtStatus($dt){
  513. global $ecms_config;
  514. if($ecms_config['sets']['pagemustdt'])
  515. {
  516. return 1;
  517. }
  518. else
  519. {
  520. return $dt;
  521. }
  522. }
  523. //返回内容页地址(访问端)
  524. function Moreport_ReturnTitleUrl($classid,$id){
  525. $rewriter=eReturnRewriteInfoUrl($classid,$id,1);
  526. $titleurl=$rewriter['pageurl'];
  527. return $titleurl;
  528. }
  529. //返回栏目页地址(访问端)
  530. function Moreport_ReturnClassUrl($classid){
  531. global $public_r,$class_r;
  532. if($class_r[$classid]['wburl'])
  533. {
  534. $classurl=$class_r[$classid]['wburl'];
  535. }
  536. else
  537. {
  538. $rewriter=eReturnRewriteClassUrl($classid,1);
  539. $classurl=$rewriter['pageurl'];
  540. }
  541. return $classurl;
  542. }
  543. //返回标题分类页地址(访问端)
  544. function Moreport_ReturnInfoTypeUrl($typeid){
  545. $rewriter=eReturnRewriteTitleTypeUrl($typeid,1);
  546. $url=$rewriter['pageurl'];
  547. return $url;
  548. }
  549. //返回首页地址(访问端)
  550. function Moreport_ReturnIndexUrl(){
  551. global $public_r;
  552. $file=$public_r['newsurl'].'index.php';
  553. return $file;
  554. }
  555. //根据编号返回模板表名
  556. function eTnoGetTempTbname($no){
  557. if($no==1)//标签模板
  558. {
  559. $temptb='enewsbqtemp';
  560. }
  561. elseif($no==2)//JS模板
  562. {
  563. $temptb='enewsjstemp';
  564. }
  565. elseif($no==3)//列表模板
  566. {
  567. $temptb='enewslisttemp';
  568. }
  569. elseif($no==4)//内容模板
  570. {
  571. $temptb='enewsnewstemp';
  572. }
  573. elseif($no==5)//公共模板
  574. {
  575. $temptb='enewspubtemp';
  576. }
  577. elseif($no==6)//搜索模板
  578. {
  579. $temptb='enewssearchtemp';
  580. }
  581. elseif($no==7)//模板变量
  582. {
  583. $temptb='enewstempvar';
  584. }
  585. elseif($no==8)//投票模板
  586. {
  587. $temptb='enewsvotetemp';
  588. }
  589. elseif($no==9)//封面模板
  590. {
  591. $temptb='enewsclasstemp';
  592. }
  593. elseif($no==10)//评论模板
  594. {
  595. $temptb='enewspltemp';
  596. }
  597. elseif($no==11)//打印模板
  598. {
  599. $temptb='enewsprinttemp';
  600. }
  601. elseif($no==12)//自定义页面模板
  602. {
  603. $temptb='enewspagetemp';
  604. }
  605. else
  606. {
  607. $temptb='';
  608. }
  609. return $temptb;
  610. }
  611. //模板表转换
  612. function GetTemptb($temptb){
  613. global $public_r,$ecms_config,$dbtbpre;
  614. if(!empty($ecms_config['sets']['deftempid']))
  615. {
  616. $tempid=$ecms_config['sets']['deftempid'];
  617. }
  618. else
  619. {
  620. $tempid=$public_r['deftempid'];
  621. }
  622. if(!empty($tempid)&&$tempid!=1)
  623. {
  624. $en="_".$tempid;
  625. }
  626. return $dbtbpre.$temptb.$en;
  627. }
  628. //返回操作模板表
  629. function GetDoTemptb($temptb,$gid){
  630. global $dbtbpre;
  631. if(!empty($gid)&&$gid!=1)
  632. {
  633. $en="_".$gid;
  634. }
  635. return $dbtbpre.$temptb.$en;
  636. }
  637. //返回当前使用模板组ID
  638. function GetDoTempGid(){
  639. global $ecms_config,$public_r;
  640. if($ecms_config['sets']['deftempid'])
  641. {
  642. $gid=$ecms_config['sets']['deftempid'];
  643. }
  644. elseif($public_r['deftempid'])
  645. {
  646. $gid=$public_r['deftempid'];
  647. }
  648. else
  649. {
  650. $gid=1;
  651. }
  652. return $gid;
  653. }
  654. //导入语言包
  655. function LoadLang($file){
  656. global $ecms_config;
  657. return "../data/language/".$ecms_config['sets']['elang']."/".$file;
  658. }
  659. //取得IP
  660. function egetip(){
  661. global $ecms_config;
  662. if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown'))
  663. {
  664. $ip=getenv('HTTP_CLIENT_IP');
  665. }
  666. elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown'))
  667. {
  668. $ip=getenv('HTTP_X_FORWARDED_FOR');
  669. }
  670. elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown'))
  671. {
  672. $ip=getenv('REMOTE_ADDR');
  673. }
  674. elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown'))
  675. {
  676. $ip=$_SERVER['REMOTE_ADDR'];
  677. }
  678. if($ecms_config['sets']['getiptype']>0)
  679. {
  680. $ip=egetipadd();
  681. }
  682. $ip=RepPostVar(preg_replace("/^([\d\.]+).*/","\\1",$ip));
  683. return $ip;
  684. }
  685. //取得IP附加
  686. function egetipadd(){
  687. global $ecms_config;
  688. if($ecms_config['sets']['getiptype']==2)
  689. {
  690. $ip=getenv('HTTP_X_FORWARDED_FOR');
  691. }
  692. elseif($ecms_config['sets']['getiptype']==3)
  693. {
  694. $ip=getenv('HTTP_CLIENT_IP');
  695. }
  696. else
  697. {
  698. $ip=getenv('REMOTE_ADDR');
  699. }
  700. return $ip;
  701. }
  702. //取得端口
  703. function egetipport(){
  704. $ipport=(int)$_SERVER['REMOTE_PORT'];
  705. return $ipport;
  706. }
  707. //检查地址
  708. function ecms_eCheckNotUrl($str){
  709. if(stristr($str,'/')||stristr($str,':')||stristr($str,"\\")||stristr($str,'&')||stristr($str,'?')||stristr($str,'#')||stristr($str,'@')||stristr($str,'"')||stristr($str,"'")||stristr($str,'%'))
  710. {
  711. exit();
  712. }
  713. return $str;
  714. }
  715. //返回来源地址
  716. function EcmsGetReturnUrl(){
  717. global $public_r;
  718. $from=$_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:$public_r['newsurl'];
  719. return RepPostStrUrl($from);
  720. }
  721. //checkdomain
  722. function eToCheckThisDomain($url){
  723. $domain=eReturnDomain();
  724. if(!stristr($url,$domain))
  725. {
  726. exit();
  727. }
  728. if(eCheckHaveReStr($url,'://'))
  729. {
  730. exit();
  731. }
  732. }
  733. //checkotherurl
  734. function eCheckOtherViewUrl($url,$havevar=0,$ecms=0){
  735. //fromurl
  736. if($ecms==1)
  737. {
  738. $fromurl=$_SERVER['HTTP_REFERER'];
  739. if(!$fromurl)
  740. {
  741. exit();
  742. }
  743. eToCheckThisDomain($fromurl);
  744. }
  745. if(!$url)
  746. {
  747. exit();
  748. }
  749. $url=RepPostStrUrl($url);
  750. if(!$havevar)
  751. {
  752. if(stristr($url,'?')||stristr($url,'&')||stristr($url,'#'))
  753. {
  754. exit();
  755. }
  756. }
  757. //url
  758. if(stristr($url,'://'))
  759. {
  760. eToCheckThisDomain($url);
  761. }
  762. else
  763. {
  764. if(stristr($str,':')||stristr($str,"\\")||stristr($str,'"')||stristr($str,"'"))
  765. {
  766. exit();
  767. }
  768. }
  769. }
  770. //checkrestr
  771. function eCheckHaveReStr($str,$exp){
  772. $r=explode($exp,$str);
  773. if(count($r)>2)
  774. {
  775. return 1;
  776. }
  777. return 0;
  778. }
  779. //checkurl
  780. function eToCheckIsUrl($url){
  781. $r=explode('://',$url);
  782. return eCheckStrType(2,$r[0],0);
  783. }
  784. //checkurl2
  785. function eToCheckIsUrl2($url){
  786. if(substr($url,0,4)=='http')
  787. {
  788. return 1;
  789. }
  790. return 0;
  791. }
  792. //checkstrtype
  793. function eCheckStrType($type,$str,$doing=0){
  794. $ret=0;
  795. if($type==1)//数字
  796. {
  797. if(preg_match('/^[0-9]+$/',$str))
  798. {
  799. $ret=1;
  800. }
  801. }
  802. elseif($type==2)//字母
  803. {
  804. if(preg_match('/^[A-Za-z]+$/',$str))
  805. {
  806. $ret=1;
  807. }
  808. }
  809. elseif($type==3)//字母+数字
  810. {
  811. if(preg_match('/^[A-Za-z0-9]+$/',$str))
  812. {
  813. $ret=1;
  814. }
  815. }
  816. elseif($type==4)//字母+数字+下划线
  817. {
  818. if(preg_match('/^[A-Za-z0-9_]+$/',$str))
  819. {
  820. $ret=1;
  821. }
  822. }
  823. elseif($type==5)//字母+数字+下划线+点
  824. {
  825. if(preg_match('/^[A-Za-z0-9\-\._]+$/',$str))
  826. {
  827. $ret=1;
  828. }
  829. }
  830. else
  831. {
  832. $ret=0;
  833. }
  834. if($doing)
  835. {
  836. if($ret<1)
  837. {
  838. exit();
  839. }
  840. }
  841. return $ret;
  842. }
  843. //返回地址
  844. function DoingReturnUrl($url,$from=''){
  845. if(empty($from))
  846. {
  847. return RepPostStrUrl($url);
  848. }
  849. elseif($from==9)
  850. {
  851. $from=$_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:$url;
  852. }
  853. return RepPostStrUrl($from);
  854. }
  855. //htmlspecialchars处理
  856. function ehtmlspecialchars($val,$flags=ENT_COMPAT){
  857. global $ecms_config;
  858. if(PHP_VERSION>='5.4.0')
  859. {
  860. if($ecms_config['sets']['pagechar']=='utf-8')
  861. {
  862. $char='UTF-8';
  863. }
  864. else
  865. {
  866. $char='ISO-8859-1';
  867. }
  868. $val=htmlspecialchars($val,$flags,$char);
  869. }
  870. else
  871. {
  872. $val=htmlspecialchars($val,$flags);
  873. }
  874. return $val;
  875. }
  876. //addslashes处理
  877. function eaddslashes($val,$ckmq=1){
  878. if($ckmq==1&&MAGIC_QUOTES_GPC)
  879. {
  880. return $val;
  881. }
  882. $val=addslashes($val);
  883. return $val;
  884. }
  885. //addslashes处理
  886. function eaddslashes2($val,$ckmq=1){
  887. if($ckmq==1&&MAGIC_QUOTES_GPC)
  888. {
  889. return addslashes($val);
  890. }
  891. $val=addslashes(addslashes($val));
  892. return $val;
  893. }
  894. //stripSlashes处理
  895. function estripSlashes($val,$ckmq=1){
  896. if($ckmq==1&&!MAGIC_QUOTES_GPC)
  897. {
  898. return $val;
  899. }
  900. $val=stripSlashes($val);
  901. return $val;
  902. }
  903. //stripSlashes处理
  904. function estripSlashes2($val,$ckmq=1){
  905. if($ckmq==1&&!MAGIC_QUOTES_GPC)
  906. {
  907. return stripSlashes($val);
  908. }
  909. $val=stripSlashes(stripSlashes($val));
  910. return $val;
  911. }
  912. //变量正数型处理
  913. function RepPIntvar($val){
  914. $val=intval($val);
  915. if($val<0)
  916. {
  917. $val=0;
  918. }
  919. return $val;
  920. }
  921. //参数处理函数
  922. function RepPostVar($val){
  923. if($val!=addslashes($val))
  924. {
  925. exit();
  926. }
  927. CkPostStrChar($val);
  928. $val=str_replace("%","",$val);
  929. $val=str_replace(" ","",$val);
  930. $val=str_replace("`","",$val);
  931. $val=str_replace("\t","",$val);
  932. $val=str_replace("%20","",$val);
  933. $val=str_replace("%27","",$val);
  934. $val=str_replace("*","",$val);
  935. $val=str_replace("'","",$val);
  936. $val=str_replace("\"","",$val);
  937. $val=str_replace("/","",$val);
  938. $val=str_replace(";","",$val);
  939. $val=str_replace("#","",$val);
  940. $val=str_replace("--","",$val);
  941. $val=RepPostStr($val,1);
  942. $val=addslashes($val);
  943. //FireWall
  944. FWClearGetText($val);
  945. return $val;
  946. }
  947. //参数处理函数2
  948. function RepPostVar2($val){
  949. if($val!=addslashes($val))
  950. {
  951. exit();
  952. }
  953. CkPostStrChar($val);
  954. $val=str_replace("%","",$val);
  955. $val=str_replace("`","",$val);
  956. $val=str_replace("\t","",$val);
  957. $val=str_replace("%20","",$val);
  958. $val=str_replace("%27","",$val);
  959. $val=str_replace("*","",$val);
  960. $val=str_replace("'","",$val);
  961. $val=str_replace("\"","",$val);
  962. $val=str_replace("/","",$val);
  963. $val=str_replace(";","",$val);
  964. $val=str_replace("#","",$val);
  965. $val=str_replace("--","",$val);
  966. $val=RepPostStr($val,1);
  967. $val=addslashes($val);
  968. //FireWall
  969. FWClearGetText($val);
  970. return $val;
  971. }
  972. //参数处理函数3
  973. function RepPostVar3($val){
  974. if($val!=addslashes($val))
  975. {
  976. exit();
  977. }
  978. CkPostStrChar($val);
  979. $val=str_replace("%","",$val);
  980. $val=str_replace("`","",$val);
  981. $val=str_replace("\t","",$val);
  982. $val=str_replace("%20","",$val);
  983. $val=str_replace("%27","",$val);
  984. $val=str_replace("*","",$val);
  985. $val=str_replace("'","",$val);
  986. $val=str_replace("\"","",$val);
  987. //$val=str_replace("/","",$val);
  988. $val=str_replace(";","",$val);
  989. $val=str_replace("#","",$val);
  990. $val=str_replace("--","",$val);
  991. $val=RepPostStr($val,1);
  992. $val=addslashes($val);
  993. //FireWall
  994. FWClearGetText($val);
  995. return $val;
  996. }
  997. //验证编码字符
  998. function CkPostStrCharYh($val){
  999. if($val!=addslashes($val))
  1000. {
  1001. exit();
  1002. }
  1003. return $val;
  1004. }
  1005. //处理提交字符
  1006. function RepPostStr($val,$ecms=0,$phck=0){
  1007. if($phck==1)
  1008. {
  1009. CkPostStrCharYh($val);
  1010. }
  1011. $val=ehtmlspecialchars($val,ENT_QUOTES);
  1012. if($ecms==0)
  1013. {
  1014. CkPostStrChar($val);
  1015. $val=AddAddsData($val);
  1016. //FireWall
  1017. FWClearGetText($val);
  1018. }
  1019. return $val;
  1020. }
  1021. //处理提交字符2
  1022. function RepPostStr2($val,$phck=0){
  1023. if($phck==1)
  1024. {
  1025. CkPostStrCharYh($val);
  1026. }
  1027. CkPostStrChar($val);
  1028. $val=AddAddsData($val);
  1029. //FireWall
  1030. FWClearGetText($val);
  1031. return $val;
  1032. }
  1033. //处理地址
  1034. function RepPostStrUrl($val,$phck=0){
  1035. $val=str_replace('&amp;','&',RepPostStr($val,1,$phck));
  1036. return $val;
  1037. }
  1038. //保存数据处理
  1039. function dgdb_tosave($val,$phck=0){
  1040. $val=RepPostStr($val,0,$phck);
  1041. $val=addslashes($val);
  1042. return $val;
  1043. }
  1044. //保存数据处理(url)
  1045. function dgdb_tosaveurl($val,$phck=0){
  1046. $val=RepPostStr($val,0,$phck);
  1047. $val=str_replace('&amp;','&',$val);
  1048. $val=addslashes($val);
  1049. return $val;
  1050. }
  1051. //数据显示
  1052. function dgdb_toshow($val){
  1053. $val=stripSlashes($val);
  1054. return $val;
  1055. }
  1056. //处理显示字符
  1057. function eDoRepShowStr($val,$isurl=0){
  1058. $val=ehtmlspecialchars($val,ENT_QUOTES);
  1059. if($isurl==1)
  1060. {
  1061. $val=str_replace('&amp;','&',$val);
  1062. }
  1063. return $val;
  1064. }
  1065. //处理普通字符
  1066. function eDoRepPostComStr($val,$isurl=0){
  1067. $val=ehtmlspecialchars($val,ENT_QUOTES);
  1068. if($isurl==1)
  1069. {
  1070. $val=str_replace('&amp;','&',$val);
  1071. }
  1072. return $val;
  1073. }
  1074. //处理提交字符
  1075. function hRepPostStr($val,$ecms=0,$phck=0){
  1076. if($phck==1)
  1077. {
  1078. CkPostStrCharYh($val);
  1079. }
  1080. if($ecms==1)
  1081. {
  1082. $val=ehtmlspecialchars($val,ENT_QUOTES);
  1083. }
  1084. CkPostStrChar($val);
  1085. $val=AddAddsData($val);
  1086. return $val;
  1087. }
  1088. //处理提交字符2
  1089. function hRepPostStr2($val,$phck=0){
  1090. if($phck==1)
  1091. {
  1092. CkPostStrCharYh($val);
  1093. }
  1094. CkPostStrChar($val);
  1095. $val=AddAddsData($val);
  1096. return $val;
  1097. }
  1098. //处理编码字符
  1099. function CkPostStrChar($val){
  1100. if(substr($val,-1)=="\\")
  1101. {
  1102. exit();
  1103. }
  1104. }
  1105. //返回转义
  1106. function egetzy($n='2'){
  1107. if($n=='rn')
  1108. {
  1109. $str="\r\n";
  1110. }
  1111. elseif($n=='n')
  1112. {
  1113. $str="\n";
  1114. }
  1115. elseif($n=='r')
  1116. {
  1117. $str="\r";
  1118. }
  1119. elseif($n=='t')
  1120. {
  1121. $str="\t";
  1122. }
  1123. elseif($n=='syh')
  1124. {
  1125. $str="\\\"";
  1126. }
  1127. elseif($n=='dyh')
  1128. {
  1129. $str="\'";
  1130. }
  1131. else
  1132. {
  1133. for($i=0;$i<$n;$i++)
  1134. {
  1135. $str.="\\";
  1136. }
  1137. }
  1138. return $str;
  1139. }
  1140. //验证字符是否空
  1141. function CheckValEmpty($val){
  1142. return strlen($val)==0?1:0;
  1143. }
  1144. //返回ID列表
  1145. function eReturnInids($ids){
  1146. if(empty($ids))
  1147. {
  1148. return 0;
  1149. }
  1150. $dh='';
  1151. $retids='';
  1152. $r=explode(',',$ids);
  1153. $count=count($r);
  1154. for($i=0;$i<$count;$i++)
  1155. {
  1156. $id=(int)$r[$i];
  1157. if(!$id)
  1158. {
  1159. continue;
  1160. }
  1161. $retids.=$dh.$id;
  1162. $dh=',';
  1163. }
  1164. if(empty($retids))
  1165. {
  1166. return 0;
  1167. }
  1168. return $retids;
  1169. }
  1170. //数组返回ID列表
  1171. function eArrayReturnInids($r){
  1172. $count=count($r);
  1173. if(!$count)
  1174. {
  1175. return 0;
  1176. }
  1177. $dh='';
  1178. $retids='';
  1179. for($i=0;$i<$count;$i++)
  1180. {
  1181. $id=(int)$r[$i];
  1182. if(!$id)
  1183. {
  1184. continue;
  1185. }
  1186. $retids.=$dh.$id;
  1187. $dh=',';
  1188. }
  1189. if(empty($retids))
  1190. {
  1191. return 0;
  1192. }
  1193. return $retids;
  1194. }
  1195. //返回父栏目ID列表
  1196. function eReturnInFcids($featherclass){
  1197. if(!$featherclass||$featherclass=='|')
  1198. {
  1199. return 0;
  1200. }
  1201. $cids='';
  1202. $cdh='';
  1203. $fcr=explode('|',$featherclass);
  1204. $fcount=count($fcr);
  1205. for($fi=1;$fi<$fcount-1;$fi++)
  1206. {
  1207. $fcr[$fi]=(int)$fcr[$fi];
  1208. if(!$fcr[$fi])
  1209. {
  1210. continue;
  1211. }
  1212. $cids.=$cdh.$fcr[$fi];
  1213. $cdh=',';
  1214. }
  1215. if(empty($cids))
  1216. {
  1217. return 0;
  1218. }
  1219. return $cids;
  1220. }
  1221. //返回组列表
  1222. function eReturnSetGroups($groupid,$isnum=1){
  1223. $count=count($groupid);
  1224. if($count==0)
  1225. {
  1226. return '';
  1227. }
  1228. $ids=',';
  1229. for($i=0;$i<$count;$i++)
  1230. {
  1231. if($isnum==1)
  1232. {
  1233. $groupid[$i]=(int)$groupid[$i];
  1234. }
  1235. $ids.=$groupid[$i].',';
  1236. }
  1237. return $ids;
  1238. }
  1239. //取得表里的模型ID
  1240. function eGetTableModids($tid,$tbname){
  1241. global $empire,$dbtbpre;
  1242. $mids='';
  1243. $where=$tid?"tid='$tid'":"tbname='$tbname'";
  1244. $sql=$empire->query("select mid from {$dbtbpre}enewsmod where ".$where);
  1245. while($r=$empire->fetch($sql))
  1246. {
  1247. $mids.=$dh.$r['mid'];
  1248. $dh=',';
  1249. }
  1250. if(empty($mids))
  1251. {
  1252. $mids=0;
  1253. }
  1254. return $mids;
  1255. }
  1256. //替换模板变量字符
  1257. function RepTempvarPostStr($val){
  1258. $val=str_replace('[!--','[!---',$val);
  1259. return $val;
  1260. }
  1261. //替换模板变量字符
  1262. function RepTempvarPostStrT($val,$ispagef=0){
  1263. if($ispagef==1)
  1264. {
  1265. $val=str_replace('[!--empirenews.page--]','[!!!-empirecms.page-!!]',$val);
  1266. }
  1267. $val=str_replace('[!--','&#091;!--',$val);
  1268. if($ispagef==1)
  1269. {
  1270. $val=str_replace('[!!!-empirecms.page-!!]','[!--empirenews.page--]',$val);
  1271. }
  1272. return $val;
  1273. }
  1274. //取得文件扩展名
  1275. function GetFiletype($filename){
  1276. $filer=explode(".",$filename);
  1277. $count=count($filer)-1;
  1278. return strtolower(".".RepGetFiletype($filer[$count]));
  1279. }
  1280. function RepGetFiletype($filetype){
  1281. $filetype=str_replace('|','_',$filetype);
  1282. $filetype=str_replace(',','_',$filetype);
  1283. $filetype=str_replace('.','_',$filetype);
  1284. return $filetype;
  1285. }
  1286. //取得文件名
  1287. function GetFilename($filename){
  1288. if(strstr($filename,"\\"))
  1289. {
  1290. $exp="\\";
  1291. }
  1292. else
  1293. {
  1294. $exp='/';
  1295. }
  1296. $filer=explode($exp,$filename);
  1297. $count=count($filer)-1;
  1298. return $filer[$count];
  1299. }
  1300. //返回目录函数
  1301. function eReturnCPath($path,$ypath=''){
  1302. if(strstr($path,'..')||strstr($path,"\\")||strstr($path,'%')||strstr($path,':'))
  1303. {
  1304. return $ypath;
  1305. }
  1306. return $path;
  1307. }
  1308. //验证文件名格式函数
  1309. function eReturnCkCFile($path){
  1310. if(strstr($path,'..')||strstr($path,"\\")||strstr($path,'/')||strstr($path,'%')||strstr($path,':'))
  1311. {
  1312. return 0;
  1313. }
  1314. return 1;
  1315. }
  1316. //字符截取函数
  1317. function sub($string,$start=0,$length,$mode=false,$dot='',$rephtml=0){
  1318. global $ecms_config;
  1319. $strlen=strlen($string);
  1320. if($strlen<=$length)
  1321. {
  1322. return $string;
  1323. }
  1324. if($rephtml==0)
  1325. {
  1326. $string = str_replace(array('&nbsp;','&amp;','&quot;','&lt;','&gt;','&#039;'), array(' ','&','"','<','>',"'"), $string);
  1327. }
  1328. $strcut = '';
  1329. if(strtolower($ecms_config['sets']['pagechar']) == 'utf-8') {
  1330. $n = $tn = $noc = 0;
  1331. while($n < $strlen) {
  1332. $t = ord($string[$n]);
  1333. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  1334. $tn = 1; $n++; $noc++;
  1335. } elseif(194 <= $t && $t <= 223) {
  1336. $tn = 2; $n += 2; $noc += 2;
  1337. } elseif(224 <= $t && $t < 239) {
  1338. $tn = 3; $n += 3; $noc += 2;
  1339. } elseif(240 <= $t && $t <= 247) {
  1340. $tn = 4; $n += 4; $noc += 2;
  1341. } elseif(248 <= $t && $t <= 251) {
  1342. $tn = 5; $n += 5; $noc += 2;
  1343. } elseif($t == 252 || $t == 253) {
  1344. $tn = 6; $n += 6; $noc += 2;
  1345. } else {
  1346. $n++;
  1347. }
  1348. if($noc >= $length) {
  1349. break;
  1350. }
  1351. }
  1352. if($noc > $length) {
  1353. $n -= $tn;
  1354. }
  1355. $strcut = substr($string, 0, $n);
  1356. } else {
  1357. for($i = 0; $i < $length; $i++) {
  1358. $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  1359. }
  1360. }
  1361. if($rephtml==0)
  1362. {
  1363. $strcut = str_replace(array('&','"','<','>',"'"), array('&amp;','&quot;','&lt;','&gt;','&#039;'), $strcut);
  1364. }
  1365. return $strcut.$dot;
  1366. }
  1367. //截取字数
  1368. function esub($string,$length,$dot='',$rephtml=0){
  1369. return sub($string,0,$length,false,$dot,$rephtml);
  1370. }
  1371. //取得随机数
  1372. function make_password($pw_length){
  1373. $low_ascii_bound=48;
  1374. $upper_ascii_bound=122;
  1375. $notuse=array(58,59,60,61,62,63,64,91,92,93,94,95,96);
  1376. while($i<$pw_length)
  1377. {
  1378. if(PHP_VERSION<'4.2.0')
  1379. {
  1380. mt_srand((double)microtime()*1000000);
  1381. }
  1382. mt_srand();
  1383. $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  1384. if(!in_array($randnum,$notuse))
  1385. {
  1386. $password1=$password1.chr($randnum);
  1387. $i++;
  1388. }
  1389. }
  1390. return $password1;
  1391. }
  1392. //取得随机数(数字)
  1393. function no_make_password($pw_length){
  1394. $low_ascii_bound=48;
  1395. $upper_ascii_bound=57;
  1396. $notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
  1397. while($i<$pw_length)
  1398. {
  1399. if(PHP_VERSION<'4.2.0')
  1400. {
  1401. mt_srand((double)microtime()*1000000);
  1402. }
  1403. mt_srand();
  1404. $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  1405. if(!in_array($randnum,$notuse))
  1406. {
  1407. $password1=$password1.chr($randnum);
  1408. $i++;
  1409. }
  1410. }
  1411. return $password1;
  1412. }
  1413. //取得随机数(字母)
  1414. function abc_make_password($pw_length){
  1415. $low_ascii_bound=65;
  1416. $upper_ascii_bound=122;
  1417. $notuse=array(91,92,93,94,95,96);
  1418. while($i<$pw_length)
  1419. {
  1420. if(PHP_VERSION<'4.2.0')
  1421. {
  1422. mt_srand((double)microtime()*1000000);
  1423. }
  1424. mt_srand();
  1425. $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  1426. if(!in_array($randnum,$notuse))
  1427. {
  1428. $password1=$password1.chr($randnum);
  1429. $i++;
  1430. }
  1431. }
  1432. return $password1;
  1433. }
  1434. //programno
  1435. function EcmsGetProgramNo(){
  1436. $r=explode(' ',microtime());
  1437. $pno=$r[1].$r[0];
  1438. return $pno;
  1439. }
  1440. //随机数字
  1441. function EcmsRandInt($min=0,$max=0,$ecms=0){
  1442. mt_srand();
  1443. if($max)
  1444. {
  1445. $rnd=mt_rand($min,$max);
  1446. }
  1447. else
  1448. {
  1449. $rnd=mt_rand();
  1450. }
  1451. return $rnd;
  1452. }
  1453. //颜色转RGB
  1454. function ToReturnRGB($rgb){
  1455. $rgb=str_replace('#','',ehtmlspecialchars($rgb));
  1456. return array(
  1457. base_convert(substr($rgb,0,2),16,10),
  1458. base_convert(substr($rgb,2,2),16,10),
  1459. base_convert(substr($rgb,4,2),16,10)
  1460. );
  1461. }
  1462. //验证页码是否有效
  1463. function eCheckListPageNo($page,$line,$totalnum){
  1464. $page=(int)$page;
  1465. $line=(int)$line;
  1466. $totalnum=(int)$totalnum;
  1467. if(!$page)
  1468. {
  1469. return '';
  1470. }
  1471. if(!$line)
  1472. {
  1473. return '';
  1474. }
  1475. $totalpage=ceil($totalnum/$line);
  1476. if($page>=$totalpage)
  1477. {
  1478. printerror('ErrorUrl','history.go(-1)',1);
  1479. }
  1480. }
  1481. //前台分页
  1482. function page1($num,$line,$page_line,$start,$page,$search){
  1483. global $fun_r;
  1484. $num=(int)$num;
  1485. $line=(int)$line;
  1486. $page_line=(int)$page_line;
  1487. $start=(int)$start;
  1488. $page=(int)$page;
  1489. if($num<=$line)
  1490. {
  1491. return '';
  1492. }
  1493. $search=RepPostStr($search,1);
  1494. $url=eReturnSelfPage(0).'?page';
  1495. $snum=2;//最小页数
  1496. $totalpage=ceil($num/$line);//取得总页数
  1497. $firststr='<li class="previous disabled"><a href="'.$url.'=0'.$search.'">'.$fun_r['startpage'].'</a></li>';
  1498. //上一页
  1499. if($page<>0)
  1500. {
  1501. //$toppage='<li class="previous disabled"><a href="'.$url.'=0'.$search.'">'.$fun_r['startpage'].'</a></li>';
  1502. $pagepr=$page-1;
  1503. $prepage='<li class="previous disabled"><a href="'.$url.'='.$pagepr.$search.'">'.$fun_r['pripage'].'</a></li>';
  1504. }
  1505. //下一页
  1506. if($page!=$totalpage-1)
  1507. {
  1508. $pagenex=$page+1;
  1509. $nextpage='<li class="next"><a href="'.$url.'='.$pagenex.$search.'">'.$fun_r['nextpage'].'</a></li>';
  1510. $lastpage='<li class="next"><a href="'.$url.'='.($totalpage-1).$search.'">'.$fun_r['lastpage'].'</a></li>';
  1511. }
  1512. $starti=$page-$snum<0?0:$page-$snum;
  1513. $no=0;
  1514. for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
  1515. {
  1516. $no++;
  1517. if($page==$i)
  1518. {
  1519. $is_1="<li class=\"disabled active\"><a>";
  1520. $is_2="</a></li>";
  1521. }
  1522. else
  1523. {
  1524. $is_1='<li><a href="'.$url.'='.$i.$search.'">';
  1525. $is_2="</a></li>";
  1526. }
  1527. $pagenum=$i+1;
  1528. $returnstr.="".$is_1.$pagenum.$is_2;
  1529. }
  1530. $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
  1531. return $returnstr;
  1532. }
  1533. //---------- 伪静态 ----------
  1534. //返回内容伪静态
  1535. function eReturnRewriteInfoUrl($classid,$id,$ecms=0){
  1536. global $public_r;
  1537. if(empty($public_r['rewriteinfo']))
  1538. {
  1539. $r['pageurl']=$public_r['newsurl']."e/action/ShowInfo.php?classid=$classid&id=$id";
  1540. $r['rewrite']=0;
  1541. }
  1542. else
  1543. {
  1544. if($ecms==1)
  1545. {
  1546. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--classid--]','[!--id--]','[!--page--]'),array($classid,$id,0),$public_r['rewriteinfo']);
  1547. }
  1548. else
  1549. {
  1550. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--classid--]','[!--id--]'),array($classid,$id),$public_r['rewriteinfo']);
  1551. }
  1552. $r['rewrite']=1;
  1553. }
  1554. return $r;
  1555. }
  1556. //返回栏目列表伪静态
  1557. function eReturnRewriteClassUrl($classid,$ecms=0){
  1558. global $public_r;
  1559. if(empty($public_r['rewriteclass']))
  1560. {
  1561. $r['pageurl']=$public_r['newsurl']."e/action/ListInfo/?classid=$classid";
  1562. $r['rewrite']=0;
  1563. }
  1564. else
  1565. {
  1566. if($ecms==1)
  1567. {
  1568. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--classid--]','[!--page--]'),array($classid,0),$public_r['rewriteclass']);
  1569. }
  1570. else
  1571. {
  1572. $r['pageurl']=$public_r['newsurl'].str_replace('[!--classid--]',$classid,$public_r['rewriteclass']);
  1573. }
  1574. $r['rewrite']=1;
  1575. }
  1576. return $r;
  1577. }
  1578. //返回标题分类列表伪静态
  1579. function eReturnRewriteTitleTypeUrl($ttid,$ecms=0){
  1580. global $public_r;
  1581. if(empty($public_r['rewriteinfotype']))
  1582. {
  1583. $r['pageurl']=$public_r['newsurl']."e/action/InfoType/?ttid=$ttid";
  1584. $r['rewrite']=0;
  1585. }
  1586. else
  1587. {
  1588. if($ecms==1)
  1589. {
  1590. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--ttid--]','[!--page--]'),array($ttid,0),$public_r['rewriteinfotype']);
  1591. }
  1592. else
  1593. {
  1594. $r['pageurl']=$public_r['newsurl'].str_replace('[!--ttid--]',$ttid,$public_r['rewriteinfotype']);
  1595. }
  1596. $r['rewrite']=1;
  1597. }
  1598. return $r;
  1599. }
  1600. //返回TAGS列表伪静态
  1601. function eReturnRewriteTagsUrl($tagid,$tagname,$ecms=0){
  1602. global $public_r;
  1603. $tagname=urlencode($tagname);
  1604. if(empty($public_r['rewritetags']))
  1605. {
  1606. $r['pageurl']=$public_r['newsurl']."e/tags/?tagname=".$tagname;
  1607. $r['rewrite']=0;
  1608. }
  1609. else
  1610. {
  1611. if($ecms==1)
  1612. {
  1613. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--tagname--]','[!--page--]'),array($tagname,0),$public_r['rewritetags']);
  1614. }
  1615. else
  1616. {
  1617. $r['pageurl']=$public_r['newsurl'].str_replace('[!--tagname--]',$tagname,$public_r['rewritetags']);
  1618. }
  1619. $r['rewrite']=1;
  1620. }
  1621. return $r;
  1622. }
  1623. //返回评论列表伪静态
  1624. function eReturnRewritePlUrl($classid,$id,$doaction='doinfo',$myorder=0,$tempid=0,$ecms=0){
  1625. global $public_r;
  1626. if(empty($public_r['rewritepl']))
  1627. {
  1628. if($doaction=='dozt')
  1629. {
  1630. $r['pageurl']=$public_r['plurl']."?doaction=dozt&classid=$classid".($myorder?'&myorder='.$myorder:'').($tempid?'&tempid='.$tempid:'');
  1631. }
  1632. else
  1633. {
  1634. $r['pageurl']=$public_r['plurl']."?classid=$classid&id=$id".($myorder?'&myorder='.$myorder:'').($tempid?'&tempid='.$tempid:'');
  1635. }
  1636. $r['rewrite']=0;
  1637. }
  1638. else
  1639. {
  1640. if($ecms==1)
  1641. {
  1642. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--doaction--]','[!--classid--]','[!--id--]','[!--page--]','[!--myorder--]','[!--tempid--]'),array($doaction,$classid,$id,0,$myorder,$tempid),$public_r['rewritepl']);
  1643. }
  1644. else
  1645. {
  1646. $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--doaction--]','[!--classid--]','[!--id--]','[!--myorder--]','[!--tempid--]'),array($doaction,$classid,$id,$myorder,$tempid),$public_r['rewritepl']);
  1647. }
  1648. $r['rewrite']=1;
  1649. }
  1650. return $r;
  1651. }
  1652. //伪静态链接地址中转
  1653. function eReturnRewriteLink($type,$classid,$id){
  1654. if($type=='infopage')//信息页
  1655. {
  1656. $url=eReturnRewriteInfoUrl($classid,$id);
  1657. }
  1658. elseif($type=='ttpage')//标题分类页
  1659. {
  1660. $url=eReturnRewriteTitleTypeUrl($classid);
  1661. }
  1662. elseif($type=='tagspage')//Tags列表页
  1663. {
  1664. $url=eReturnRewriteTagsUrl($classid,$id);
  1665. }
  1666. else//栏目页
  1667. {
  1668. $url=eReturnRewriteClassUrl($classid);
  1669. }
  1670. return $url;
  1671. }
  1672. //伪静态替换分页号
  1673. function eReturnRewritePageLink($r,$page){
  1674. //动静
  1675. $truepage=$page+1;
  1676. if($r['repagenum']&&$truepage<=$r['repagenum'])
  1677. {
  1678. //文件名
  1679. if(empty($r['dofile']))
  1680. {
  1681. $r['dofile']='index';
  1682. }
  1683. $url=$r['dolink'].$r['dofile'].($truepage==1?'':'_'.$truepage).$r['dotype'];
  1684. return $url;
  1685. }
  1686. if($r['rewrite']==1)
  1687. {
  1688. $url=str_replace('[!--page--]',$page,$r['pageurl']);
  1689. }
  1690. else
  1691. {
  1692. $url=$r['pageurl'].'&page='.$page;
  1693. }
  1694. return $url;
  1695. }
  1696. //伪静态替换分页号(静态)
  1697. function eReturnRewritePageLink2($r,$page){
  1698. if($r['rewrite']==1)
  1699. {
  1700. $url=str_replace('[!--page--]',$page-1,$r['pageurl']);
  1701. }
  1702. else
  1703. {
  1704. $url=$r['pageurl'].'&page='.($page-1);
  1705. }
  1706. return $url;
  1707. }
  1708. //前台分页(伪静态)
  1709. function InfoUsePage($num,$line,$page_line,$start,$page,$search,$add){
  1710. global $fun_r;
  1711. $num=(int)$num;
  1712. $line=(int)$line;
  1713. $page_line=(int)$page_line;
  1714. $start=(int)$start;
  1715. $page=(int)$page;
  1716. if($num<=$line)
  1717. {
  1718. return '';
  1719. }
  1720. $search=RepPostStr($search,1);
  1721. $snum=2;//最小页数
  1722. $totalpage=ceil($num/$line);//取得总页数
  1723. $firststr='<a title="'.$fun_r['trecord'].'">&nbsp;<b>'.$num.'</b> </a>&nbsp;&nbsp;';
  1724. //上一页
  1725. if($page<>0)
  1726. {
  1727. $toppage='<a href="'.eReturnRewritePageLink($add,0).'">'.$fun_r['startpage'].'</a>&nbsp;';
  1728. $pagepr=$page-1;
  1729. $prepage='<a href="'.eReturnRewritePageLink($add,$pagepr).'">'.$fun_r['pripage'].'</a>';
  1730. }
  1731. //下一页
  1732. if($page!=$totalpage-1)
  1733. {
  1734. $pagenex=$page+1;
  1735. $nextpage='&nbsp;<a href="'.eReturnRewritePageLink($add,$pagenex).'">'.$fun_r['nextpage'].'</a>';
  1736. $lastpage='&nbsp;<a href="'.eReturnRewritePageLink($add,$totalpage-1).'">'.$fun_r['lastpage'].'</a>';
  1737. }
  1738. $starti=$page-$snum<0?0:$page-$snum;
  1739. $no=0;
  1740. for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
  1741. {
  1742. $no++;
  1743. if($page==$i)
  1744. {
  1745. $is_1="<b>";
  1746. $is_2="</b>";
  1747. }
  1748. else
  1749. {
  1750. $is_1='<a href="'.eReturnRewritePageLink($add,$i).'">';
  1751. $is_2="</a>";
  1752. }
  1753. $pagenum=$i+1;
  1754. $returnstr.="&nbsp;".$is_1.$pagenum.$is_2;
  1755. }
  1756. $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
  1757. return $returnstr;
  1758. }
  1759. //时间转换函数
  1760. function to_time($datetime){
  1761. if(strlen($datetime)==10)
  1762. {
  1763. $datetime.=" 00:00:00";
  1764. }
  1765. $r=explode(" ",$datetime);
  1766. $t=explode("-",$r[0]);
  1767. $k=explode(":",$r[1]);
  1768. $dbtime=@mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
  1769. return intval($dbtime);
  1770. }
  1771. //时期转日期
  1772. function date_time($time,$format="Y-m-d H:i:s"){
  1773. $threadtime=date($format,$time);
  1774. return $threadtime;
  1775. }
  1776. //格式化日期
  1777. function format_datetime($newstime,$format){
  1778. if($newstime=="0000-00-00 00:00:00")
  1779. {return $newstime;}
  1780. $time=is_numeric($newstime)?$newstime:to_time($newstime);
  1781. $newdate=date_time($time,$format);
  1782. return $newdate;
  1783. }
  1784. //时间转换函数
  1785. function to_date($date){
  1786. $date.=" 00:00:00";
  1787. $r=explode(" ",$date);
  1788. $t=explode("-",$r[0]);
  1789. $k=explode(":",$r[1]);
  1790. $dbtime=@mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
  1791. return intval($dbtime);
  1792. }
  1793. //选择时间
  1794. function ToChangeTime($time,$day){
  1795. $truetime=$time-$day*24*3600;
  1796. $date=date_time($truetime,"Y-m-d");
  1797. return $date;
  1798. }
  1799. //删除文件
  1800. function DelFiletext($filename){
  1801. @unlink($filename);
  1802. }
  1803. //取得文件内容
  1804. function ReadFiletext($filepath){
  1805. $filepath=trim($filepath);
  1806. $ishttp=0;
  1807. if(strstr($filepath,'://'))
  1808. {
  1809. if(!eToCheckIsUrl2($filepath))
  1810. {
  1811. return '';
  1812. }
  1813. $ishttp=1;
  1814. }
  1815. $htmlfp=@fopen($filepath,"r");
  1816. //远程
  1817. if($ishttp==1)
  1818. {
  1819. while($data=@fread($htmlfp,500000))
  1820. {
  1821. $string.=$data;
  1822. }
  1823. }
  1824. //本地
  1825. else
  1826. {
  1827. $string=@fread($htmlfp,@filesize($filepath));
  1828. }
  1829. @fclose($htmlfp);
  1830. return $string;
  1831. }
  1832. //写文件
  1833. function WriteFiletext($filepath,$string){
  1834. global $public_r;
  1835. $string=stripSlashes($string);
  1836. $fp=@fopen($filepath,"w");
  1837. @fputs($fp,$string);
  1838. @fclose($fp);
  1839. if(empty($public_r[filechmod]))
  1840. {
  1841. @chmod($filepath,0777);
  1842. }
  1843. }
  1844. //写文件
  1845. function WriteFiletext_n($filepath,$string){
  1846. global $public_r;
  1847. $fp=@fopen($filepath,"w");
  1848. @fputs($fp,$string);
  1849. @fclose($fp);
  1850. if(empty($public_r[filechmod]))
  1851. {
  1852. @chmod($filepath,0777);
  1853. }
  1854. }
  1855. //标题属性后
  1856. function DoTitleFont($titlefont,$title){
  1857. if(empty($titlefont))
  1858. {
  1859. return $title;
  1860. }
  1861. $r=explode(',',$titlefont);
  1862. if(!empty($r[0]))
  1863. {
  1864. $title="<font color='".$r[0]."'>".$title."</font>";
  1865. }
  1866. if(empty($r[1]))
  1867. {return $title;}
  1868. //粗体
  1869. if(strstr($r[1],"b"))
  1870. {$title="<strong>".$title."</strong>";}
  1871. //斜体
  1872. if(strstr($r[1],"i"))
  1873. {$title="<i>".$title."</i>";}
  1874. //删除线
  1875. if(strstr($r[1],"s"))
  1876. {$title="<s>".$title."</s>";}
  1877. return $title;
  1878. }
  1879. //返回头条级别名称权限
  1880. function ReturnFirsttitleNameCkLevel($r,$groupid,$classid){
  1881. if(defined('EmpireCMSAdmin'))
  1882. {
  1883. if($r['groupid'])
  1884. {
  1885. if(!strstr($r['groupid'],','.$groupid.','))
  1886. {
  1887. return 0;
  1888. }
  1889. }
  1890. }
  1891. if($classid)
  1892. {
  1893. if($r['showcid'])
  1894. {
  1895. if(!strstr($r['showcid'],','.$classid.','))
  1896. {
  1897. return 0;
  1898. }
  1899. }
  1900. if($r['hiddencid'])
  1901. {
  1902. if(strstr($r['hiddencid'],','.$classid.','))
  1903. {
  1904. return 0;
  1905. }
  1906. }
  1907. }
  1908. else
  1909. {
  1910. if($r['showall']==1)
  1911. {
  1912. return 0;
  1913. }
  1914. }
  1915. return 1;
  1916. }
  1917. //返回头条级别名称
  1918. function ReturnFirsttitleNameList($firsttitle,$isgood){
  1919. global $empire,$dbtbpre,$lur,$classid,$class_r;
  1920. $classid=(int)$classid;
  1921. if($classid&&!$class_r[$classid]['islast'])
  1922. {
  1923. $classid=0;
  1924. }
  1925. $groupid=(int)$lur['groupid'];
  1926. $first_r=array();//头条
  1927. $ftn='';
  1928. $good_r=array();//推荐
  1929. $gn='';
  1930. $sql=$empire->query("select tname,ttype,levelid,groupid,showall,showcid,hiddencid from {$dbtbpre}enewsgoodtype order by myorder desc,levelid");
  1931. while($r=$empire->fetch($sql))
  1932. {
  1933. if($r['ttype']==1)//头条
  1934. {
  1935. $first_r[$r['levelid']]=$r['tname'];
  1936. $selected='';
  1937. if($r['levelid']==$firsttitle)
  1938. {
  1939. $selected=' selected';
  1940. }
  1941. if(ReturnFirsttitleNameCkLevel($r,$groupid,$classid))
  1942. {
  1943. $ftn.='<option value="'.$r['levelid'].'"'.$selected.'>'.$r['tname'].'</option>';
  1944. }
  1945. }
  1946. else//推荐
  1947. {
  1948. $good_r[$r['levelid']]=$r['tname'];
  1949. $selected='';
  1950. if($r['levelid']==$isgood)
  1951. {
  1952. $selected=' selected';
  1953. }
  1954. if(ReturnFirsttitleNameCkLevel($r,$groupid,$classid))
  1955. {
  1956. $gn.='<option value="'.$r['levelid'].'"'.$selected.'>'.$r['tname'].'</option>';
  1957. }
  1958. }
  1959. }
  1960. $ret_r['ftname']=$ftn;
  1961. $ret_r['ftr']=$first_r;
  1962. $ret_r['igname']=$gn;
  1963. $ret_r['igr']=$good_r;
  1964. return $ret_r;
  1965. }
  1966. //替换全角逗号
  1967. function DoReplaceQjDh($text){
  1968. return str_replace(',',',',$text);
  1969. }
  1970. //半角转全角
  1971. function eDoBjToQj($text){
  1972. $text=str_replace(array('&','"','\'','<','>'),array('&','”','’','<','>'),$text);
  1973. return $text;
  1974. }
  1975. //给信息字段转全角
  1976. function eDoInfoTbfToQj($tbname,$f,$fval,$qjf){
  1977. global $public_r;
  1978. if(empty($qjf))
  1979. {
  1980. return $fval;
  1981. }
  1982. if(!stristr('|'.$qjf.'|','|'.$tbname.'.'.$f.'|'))
  1983. {
  1984. return $fval;
  1985. }
  1986. $fval=eDoBjToQj($fval);
  1987. return $fval;
  1988. }
  1989. //建立目录函数
  1990. function DoMkdir($path){
  1991. global $public_r;
  1992. //不存在则建立
  1993. if(!file_exists($path))
  1994. {
  1995. //安全模式
  1996. if($public_r[phpmode])
  1997. {
  1998. $pr[0]=$path;
  1999. FtpMkdir($ftpid,$pr,0777);
  2000. $mk=1;
  2001. }
  2002. else
  2003. {
  2004. $mk=@mkdir($path,0777);
  2005. @chmod($path,0777);
  2006. }
  2007. if(empty($mk))
  2008. {
  2009. echo Ecms_eReturnShowMkdir($path);
  2010. printerror("CreatePathFail","history.go(-1)");
  2011. }
  2012. }
  2013. return true;
  2014. }
  2015. //建立上级目录
  2016. function DoFileMkDir($file){
  2017. $path=dirname($file.'empirecms.txt');
  2018. DoMkdir($path);
  2019. }
  2020. //设置上传文件权限
  2021. function DoChmodFile($file){
  2022. global $public_r;
  2023. if($public_r['filechmod']!=1)
  2024. {
  2025. @chmod($file,0777);
  2026. }
  2027. }
  2028. //替换斜扛
  2029. function DoRepFileXg($file){
  2030. $file=str_replace("\\","/",$file);
  2031. return $file;
  2032. }
  2033. //返回栏目链接字符串
  2034. function ReturnClassLink($classid){
  2035. global $class_r,$public_r,$fun_r;
  2036. if(empty($class_r[$classid][featherclass]))
  2037. {$class_r[$classid][featherclass]="|";}
  2038. $r=explode("|",$class_r[$classid][featherclass].$classid."|");
  2039. $string="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";
  2040. for($i=1;$i<count($r)-1;$i++)
  2041. {
  2042. //moreport
  2043. if(Moreport_ReturnMustDt())
  2044. {
  2045. $class_r[$r[$i]][listdt]=1;
  2046. }
  2047. //静态列表
  2048. if(empty($class_r[$r[$i]][listdt]))
  2049. {
  2050. //无绑定域名
  2051. if(empty($class_r[$r[$i]][classurl]))
  2052. {$url=$public_r[newsurl].$class_r[$r[$i]][classpath]."/";}
  2053. else
  2054. {$url=$class_r[$r[$i]][classurl];}
  2055. }
  2056. else
  2057. {
  2058. $rewriter=eReturnRewriteClassUrl($r[$i],1);
  2059. $url=$rewriter['pageurl'];
  2060. }
  2061. $string.="&nbsp;".$public_r[navfh]."&nbsp;<a href=\"".$url."\">".$class_r[$r[$i]][classname]."</a>";
  2062. }
  2063. return $string;
  2064. }
  2065. //返回专题链接字符串
  2066. function ReturnZtLink($ztid){
  2067. global $class_zr,$public_r,$fun_r;
  2068. $string="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";
  2069. //无绑定域名
  2070. if(empty($class_zr[$ztid][zturl]))
  2071. {$url=$public_r[newsurl].$class_zr[$ztid][ztpath]."/";}
  2072. else
  2073. {$url=$class_zr[$ztid][zturl];}
  2074. $string.="&nbsp;".$public_r[navfh]."&nbsp;<a href=\"".$url."\">".$class_zr[$ztid][ztname]."</a>";
  2075. return $string;
  2076. }
  2077. //返回标题分类链接字符串
  2078. function ReturnInfoTypeLink($typeid){
  2079. global $class_tr,$public_r,$fun_r;
  2080. $string="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";
  2081. //moreport
  2082. if(Moreport_ReturnMustDt())
  2083. {
  2084. $class_tr[$typeid]['listdt']=1;
  2085. }
  2086. if($class_tr[$typeid]['listdt'])
  2087. {
  2088. $rewriter=eReturnRewriteTitleTypeUrl($typeid,1);
  2089. $url=$rewriter['pageurl'];
  2090. }
  2091. else
  2092. {
  2093. $url=$public_r[newsurl].$class_tr[$typeid][tpath]."/";
  2094. }
  2095. $string.="&nbsp;".$public_r[navfh]."&nbsp;<a href=\"".$url."\">".$class_tr[$typeid][tname]."</a>";
  2096. return $string;
  2097. }
  2098. //返回单页链接字符串
  2099. function ReturnUserPLink($title,$titleurl){
  2100. global $public_r,$fun_r;
  2101. $string='<a href="'.ReturnSiteIndexUrl().'">'.$fun_r['index'].'</a>&nbsp;'.$public_r[navfh].'&nbsp;'.$title;
  2102. return $string;
  2103. }
  2104. //返回标题链接(静态)
  2105. function sys_ReturnBqTitleLink($r){
  2106. global $public_r;
  2107. if(empty($r['isurl']))
  2108. {
  2109. //moreport
  2110. if(Moreport_ReturnMustDt())
  2111. {
  2112. return Moreport_ReturnTitleUrl($r['classid'],$r['id']);
  2113. }
  2114. return $r['titleurl'];
  2115. }
  2116. else
  2117. {
  2118. if($public_r['opentitleurl'])
  2119. {
  2120. $titleurl=$r['titleurl'];
  2121. }
  2122. else
  2123. {
  2124. $titleurl=$public_r['newsurl'].'e/public/jump/?classid='.$r['classid'].'&id='.$r['id'];
  2125. }
  2126. return $titleurl;
  2127. }
  2128. }
  2129. //返回标题链接(动态)
  2130. function sys_ReturnBqTitleLinkDt($r){
  2131. global $public_r,$class_r;
  2132. if(empty($r['isurl']))
  2133. {
  2134. if($class_r[$r[classid]][showdt]==1)//动态生成
  2135. {
  2136. $titleurl=$public_r[newsurl]."e/action/ShowInfo/?classid=$r[classid]&id=$r[id]";
  2137. return $titleurl;
  2138. }
  2139. elseif($class_r[$r[classid]][showdt]==2)
  2140. {
  2141. $rewriter=eReturnRewriteInfoUrl($r['classid'],$r['id'],1);
  2142. $titleurl=$rewriter['pageurl'];
  2143. return $titleurl;
  2144. }
  2145. if($class_r[$r[classid]][filename]==3)
  2146. {
  2147. $filename=ReturnInfoSPath($r[filename]);
  2148. }
  2149. else
  2150. {
  2151. $filetype=$r[groupid]?'.php':$class_r[$r[classid]][filetype];
  2152. $filename=$r[filename].$filetype;
  2153. }
  2154. $iclasspath=ReturnSaveInfoPath($r[classid],$r[id]);
  2155. $newspath=empty($r[newspath])?'':$r[newspath]."/";
  2156. if($class_r[$r[classid]][classurl]&&$class_r[$r[classid]][ipath]=='')//域名
  2157. {
  2158. $titleurl=$class_r[$r[classid]][classurl]."/".$newspath.$filename;
  2159. }
  2160. else
  2161. {
  2162. $titleurl=$public_r[newsurl].$iclasspath.$newspath.$filename;
  2163. }
  2164. }
  2165. else
  2166. {
  2167. $titleurl=$r['titleurl'];
  2168. }
  2169. return addslashes($titleurl);
  2170. }
  2171. //中转取得信息地址
  2172. function GotoGetTitleUrl($classid,$id,$newspath,$filename,$groupid,$isurl,$titleurl){
  2173. $r['classid']=$classid;
  2174. $r['id']=$id;
  2175. $r['newspath']=$newspath;
  2176. $r['filename']=$filename;
  2177. $r['groupid']=$groupid;
  2178. $r['isurl']=$isurl;
  2179. $r['titleurl']=$titleurl;
  2180. $infourl=sys_ReturnBqTitleLinkDt($r);
  2181. return $infourl;
  2182. }
  2183. //返回标题链接(触发)
  2184. function sys_ReturnBqAutoTitleLink($r){
  2185. global $public_r,$class_r;
  2186. if(empty($r['isurl']))
  2187. {
  2188. if($class_r[$r[classid]][showdt]==2)
  2189. {
  2190. $rewriter=eReturnRewriteInfoUrl($r['classid'],$r['id'],1);
  2191. $titleurl=$rewriter['pageurl'];
  2192. return $titleurl;
  2193. }
  2194. if($class_r[$r[classid]][filename]==3)
  2195. {
  2196. $filename=ReturnInfoSPath($r[filename]);
  2197. }
  2198. else
  2199. {
  2200. $filetype=$r[groupid]?'.php':$class_r[$r[classid]][filetype];
  2201. $filename=$r[filename].$filetype;
  2202. }
  2203. $iclasspath=ReturnSaveInfoPath($r[classid],$r[id]);
  2204. $newspath=empty($r[newspath])?'':$r[newspath]."/";
  2205. if($class_r[$r[classid]][classurl]&&$class_r[$r[classid]][ipath]=='')//域名
  2206. {
  2207. $titleurl=$class_r[$r[classid]][classurl]."/".$newspath.$filename;
  2208. }
  2209. else
  2210. {
  2211. $titleurl=$public_r[newsurl].$iclasspath.$newspath.$filename;
  2212. }
  2213. }
  2214. else
  2215. {
  2216. if($public_r['opentitleurl'])
  2217. {
  2218. $titleurl=$r['titleurl'];
  2219. }
  2220. else
  2221. {
  2222. $titleurl=$public_r['newsurl']."e/public/jump/?classid=".$r['classid']."&id=".$r['id'];
  2223. }
  2224. }
  2225. return $titleurl;
  2226. }
  2227. //返回内容页地址前缀
  2228. function ReturnInfoPageQz($r){
  2229. global $public_r,$class_r;
  2230. $ret_r['titleurl']='';
  2231. $ret_r['filetype']='';
  2232. $ret_r['nametype']=0;
  2233. //动态页面
  2234. if($class_r[$r[classid]][showdt]==2)
  2235. {
  2236. $rewriter=eReturnRewriteInfoUrl($r['classid'],$r['id'],0);
  2237. $ret_r['pageurl']=$rewriter['pageurl'];
  2238. $ret_r['rewrite']=$rewriter['rewrite'];
  2239. $ret_r['titleurl']=$rewriter['pageurl'];
  2240. $ret_r['filetype']='';
  2241. $ret_r['nametype']=1;
  2242. return $ret_r;
  2243. }
  2244. //静态页面
  2245. $ret_r['filetype']=$r[groupid]?'.php':$class_r[$r[classid]][filetype];
  2246. $filename=$r[filename];
  2247. $iclasspath=ReturnSaveInfoPath($r[classid],$r[id]);
  2248. $newspath=empty($r[newspath])?'':$r[newspath]."/";
  2249. if($class_r[$r[classid]][classurl]&&$class_r[$r[classid]][ipath]=='')//域名
  2250. {
  2251. $ret_r['titleurl']=$class_r[$r[classid]][classurl]."/".$newspath.$filename;
  2252. }
  2253. else
  2254. {
  2255. $ret_r['titleurl']=$public_r[newsurl].$iclasspath.$newspath.$filename;
  2256. }
  2257. return $ret_r;
  2258. }
  2259. //返回栏目链接
  2260. function sys_ReturnBqClassname($r,$have_class=0){
  2261. global $public_r,$class_r;
  2262. if($have_class)
  2263. {
  2264. //moreport
  2265. if(Moreport_ReturnMustDt())
  2266. {
  2267. $class_r[$r[classid]][listdt]=1;
  2268. }
  2269. //外部栏目
  2270. if($class_r[$r[classid]][wburl])
  2271. {
  2272. $classurl=$class_r[$r[classid]][wburl];
  2273. }
  2274. //动态列表
  2275. elseif($class_r[$r[classid]][listdt])
  2276. {
  2277. $rewriter=eReturnRewriteClassUrl($r['classid'],1);
  2278. $classurl=$rewriter['pageurl'];
  2279. }
  2280. elseif($class_r[$r[classid]][classurl])
  2281. {
  2282. $classurl=$class_r[$r[classid]][classurl];
  2283. }
  2284. else
  2285. {
  2286. $classurl=$public_r[newsurl].$class_r[$r[classid]][classpath]."/";
  2287. }
  2288. if(empty($class_r[$r[classid]][bname]))
  2289. {$classname=$class_r[$r[classid]][classname];}
  2290. else
  2291. {$classname=$class_r[$r[classid]][bname];}
  2292. $myadd="[<a href=".$classurl.">".$classname."</a>]";
  2293. //只返回链接
  2294. if($have_class==9)
  2295. {$myadd=$classurl;}
  2296. }
  2297. else
  2298. {$myadd="";}
  2299. return $myadd;
  2300. }
  2301. //返回专题链接
  2302. function sys_ReturnBqZtname($r){
  2303. global $public_r,$class_zr;
  2304. if($class_zr[$r[ztid]][zturl])
  2305. {
  2306. $zturl=$class_zr[$r[ztid]][zturl];
  2307. }
  2308. else
  2309. {
  2310. $zturl=$public_r[newsurl].$class_zr[$r[ztid]][ztpath]."/";
  2311. }
  2312. return $zturl;
  2313. }
  2314. //返回标题分类链接
  2315. function sys_ReturnBqInfoTypeUrl($typeid){
  2316. global $public_r,$class_tr;
  2317. //moreport
  2318. if(Moreport_ReturnMustDt())
  2319. {
  2320. $class_tr[$typeid]['listdt']=1;
  2321. }
  2322. if($class_tr[$typeid]['listdt'])
  2323. {
  2324. $rewriter=eReturnRewriteTitleTypeUrl($typeid,1);
  2325. $url=$rewriter['pageurl'];
  2326. }
  2327. else
  2328. {
  2329. $url=$public_r['newsurl'].$class_tr[$typeid]['tpath']."/";
  2330. }
  2331. return $url;
  2332. }
  2333. //文件大小格式转换
  2334. function ChTheFilesize($size){
  2335. if($size>=1024*1024)//MB
  2336. {
  2337. $filesize=number_format($size/(1024*1024),2,'.','')." MB";
  2338. }
  2339. elseif($size>=1024)//KB
  2340. {
  2341. $filesize=number_format($size/1024,2,'.','')." KB";
  2342. }
  2343. else
  2344. {
  2345. $filesize=$size." Bytes";
  2346. }
  2347. return $filesize;
  2348. }
  2349. //取得表记录
  2350. function eGetTableRowNum($tbname){
  2351. global $empire,$dbtbpre;
  2352. $total_r=$empire->fetch1("SHOW TABLE STATUS LIKE '".$tbname."';");
  2353. return $total_r['Rows'];
  2354. }
  2355. //更新栏目信息数
  2356. function AddClassInfos($classid,$addallstr,$addstr,$checked=1){
  2357. global $empire,$dbtbpre;
  2358. $updatestr='';
  2359. $dh='';
  2360. if($addallstr)
  2361. {
  2362. $updatestr.='allinfos=allinfos'.$addallstr;
  2363. $dh=',';
  2364. }
  2365. if($addstr)
  2366. {
  2367. if($checked)
  2368. {
  2369. $updatestr.=$dh.'infos=infos'.$addstr;
  2370. }
  2371. }
  2372. if(empty($updatestr))
  2373. {
  2374. return '';
  2375. }
  2376. $empire->query("update {$dbtbpre}enewsclass set ".$updatestr." where classid='$classid' limit 1");
  2377. }
  2378. //返回栏目信息数
  2379. function ReturnClassInfoNum($cr,$ecms=0){
  2380. global $empire,$dbtbpre,$class_r;
  2381. if($cr['islast'])
  2382. {
  2383. $num=$ecms==0?$cr['infos']:$cr['allinfos'];
  2384. }
  2385. else
  2386. {
  2387. $f=$ecms==0?'infos':'allinfos';
  2388. $num=$empire->gettotal("select sum(".$f.") as total from {$dbtbpre}enewsclass where ".ReturnClass($class_r[$cr[classid]][sonclass]));
  2389. $num=(int)$num;
  2390. }
  2391. return $num;
  2392. }
  2393. //重置栏目信息数
  2394. function ResetClassInfos($classid){
  2395. global $empire,$dbtbpre,$class_r;
  2396. $infos=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid]['tbname']." where classid='$classid'");
  2397. $checkinfos=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid]['tbname']."_check where classid='$classid'");
  2398. $allinfos=$infos+$checkinfos;
  2399. $empire->query("update {$dbtbpre}enewsclass set allinfos='$allinfos',infos='$infos' where classid='$classid' limit 1");
  2400. }
  2401. //单信息评论数
  2402. function UpdateSingleInfoPlnum($classid,$id,$checked=1){
  2403. global $empire,$dbtbpre,$class_r;
  2404. $tbname=$class_r[$classid]['tbname'];
  2405. if(empty($tbname))
  2406. {
  2407. return '';
  2408. }
  2409. $infotb=ReturnInfoMainTbname($tbname,$checked);
  2410. $r=$empire->fetch1("select id,restb,plnum from ".$infotb." where id='$id' limit 1");
  2411. if(empty($r['restb']))
  2412. {
  2413. return '';
  2414. }
  2415. $pubid=ReturnInfoPubid($classid,$id);
  2416. $plnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewspl_".$r['restb']." where pubid='$pubid' limit 1");
  2417. if($plnum==$r['plnum'])
  2418. {
  2419. return '';
  2420. }
  2421. $empire->query("update ".$infotb." set plnum='$plnum' where id='$id' limit 1");
  2422. }
  2423. //信息数统计加1
  2424. function DoUpdateAddDataNum($type='info',$stb,$addnum=1){
  2425. global $empire,$dbtbpre;
  2426. if($type=='info')//信息
  2427. {
  2428. $lasttimef='lasttimeinfo';
  2429. $lastnumf='lastnuminfo';
  2430. $lastnumtbf='lastnuminfotb';
  2431. $todaytimef='todaytimeinfo';
  2432. $todaynumf='todaynuminfo';
  2433. $yesterdaynumf='yesterdaynuminfo';
  2434. $sqladdf=',todaytimeinfo,todaytimepl,todaynuminfo,todaynumpl';
  2435. }
  2436. elseif($type=='pl')//评论
  2437. {
  2438. $lasttimef='lasttimepl';
  2439. $lastnumf='lastnumpl';
  2440. $lastnumtbf='lastnumpltb';
  2441. $todaytimef='todaytimepl';
  2442. $todaynumf='todaynumpl';
  2443. $yesterdaynumf='yesterdaynumpl';
  2444. $sqladdf=',todaytimepl,todaytimeinfo,todaynuminfo,todaynumpl';
  2445. }
  2446. else
  2447. {
  2448. return '';
  2449. }
  2450. $sqladdupdate='';
  2451. $time=time();
  2452. $pur=$empire->fetch1("select ".$lasttimef.",".$lastnumtbf.$sqladdf." from {$dbtbpre}enewspublic_up limit 1");
  2453. if($stb)
  2454. {
  2455. if(empty($pur[$lastnumtbf]))
  2456. {
  2457. $pur[$lastnumtbf]='|';
  2458. }
  2459. if(strstr($pur[$lastnumtbf],'|'.$stb.','))
  2460. {
  2461. $numr=explode('|'.$stb.',',$pur[$lastnumtbf]);
  2462. $numrt=explode('|',$numr[1]);
  2463. $newnum=$numrt[0]+$addnum;
  2464. $tbnums=str_replace('|'.$stb.','.$numrt[0].'|','|'.$stb.','.$newnum.'|',$pur[$lastnumtbf]);
  2465. }
  2466. else
  2467. {
  2468. $tbnums=$pur[$lastnumtbf].$stb.','.$addnum.'|';
  2469. }
  2470. $sqladdupdate.=",".$lastnumtbf."='".$tbnums."'";
  2471. }
  2472. //今日统计
  2473. if($sqladdf)
  2474. {
  2475. $todaydate=date('Y-m-d');
  2476. if($todaydate<>date('Y-m-d',$pur['todaytimeinfo'])||$todaydate<>date('Y-m-d',$pur['todaytimepl']))
  2477. {
  2478. if($type=='info')
  2479. {
  2480. $todaynuminfo=$addnum;
  2481. $todaynumpl=0;
  2482. }
  2483. else
  2484. {
  2485. $todaynuminfo=0;
  2486. $todaynumpl=$addnum;
  2487. }
  2488. $yesterdaynuminfo=$pur['todaynuminfo'];
  2489. $yesterdaynumpl=$pur['todaynumpl'];
  2490. if($todaydate<>date('Y-m-d',$pur['todaytimeinfo']+24*3600))
  2491. {
  2492. $yesterdaynuminfo=0;
  2493. }
  2494. if($todaydate<>date('Y-m-d',$pur['todaytimepl']+24*3600))
  2495. {
  2496. $yesterdaynumpl=0;
  2497. }
  2498. $sqladdupdate.=",todaytimeinfo='$time',todaytimepl='$time',todaynuminfo='$todaynuminfo',todaynumpl='$todaynumpl',yesterdaynuminfo='$yesterdaynuminfo',yesterdaynumpl='$yesterdaynumpl'";
  2499. }
  2500. else
  2501. {
  2502. $sqladdupdate.=",".$todaynumf."=".$todaynumf."+".$addnum;
  2503. }
  2504. }
  2505. $empire->query("update {$dbtbpre}enewspublic_up set ".$lastnumf."=".$lastnumf."+".$addnum.$sqladdupdate." limit 1");
  2506. }
  2507. //重置信息数统计
  2508. function DoResetAddDataNum($type='info'){
  2509. global $empire,$dbtbpre;
  2510. if($type=='info')//信息
  2511. {
  2512. $lasttimef='lasttimeinfo';
  2513. $lastnumf='lastnuminfo';
  2514. $lastnumtbf='lastnuminfotb';
  2515. }
  2516. elseif($type=='pl')//评论
  2517. {
  2518. $lasttimef='lasttimepl';
  2519. $lastnumf='lastnumpl';
  2520. $lastnumtbf='lastnumpltb';
  2521. }
  2522. else
  2523. {
  2524. return '';
  2525. }
  2526. $time=time();
  2527. $empire->query("update {$dbtbpre}enewspublic_up set ".$lasttimef."='$time',".$lastnumf."=0,".$lastnumtbf."='' limit 1");
  2528. }
  2529. //更新昨日信息数统计
  2530. function DoUpdateYesterdayAddDataNum(){
  2531. global $empire,$dbtbpre;
  2532. $pur=$empire->fetch1("select * from {$dbtbpre}enewspublic_up limit 1");
  2533. $todaydate=date('Y-m-d');
  2534. if($todaydate==date('Y-m-d',$pur['todaytimeinfo'])&&$todaydate==date('Y-m-d',$pur['todaytimepl']))
  2535. {
  2536. return '';
  2537. }
  2538. $yesterdaynuminfo=$pur['todaynuminfo'];
  2539. $yesterdaynumpl=$pur['todaynumpl'];
  2540. if($todaydate<>date('Y-m-d',$pur['todaytimeinfo']+24*3600))
  2541. {
  2542. $yesterdaynuminfo=0;
  2543. }
  2544. if($todaydate<>date('Y-m-d',$pur['todaytimepl']+24*3600))
  2545. {
  2546. $yesterdaynumpl=0;
  2547. }
  2548. $time=time();
  2549. $empire->query("update {$dbtbpre}enewspublic_up set todaytimeinfo='$time',todaytimepl='$time',todaynuminfo=0,yesterdaynuminfo='$yesterdaynuminfo',todaynumpl=0,yesterdaynumpl='$yesterdaynumpl' limit 1");
  2550. }
  2551. //返回栏目自定义字段内容
  2552. function ReturnClassAddField($classid,$f){
  2553. global $empire,$dbtbpre,$navclassid;
  2554. if(empty($classid))
  2555. {
  2556. $classid=$navclassid;
  2557. }
  2558. $fr=$empire->fetch1("select ".$f." from {$dbtbpre}enewsclassadd where classid='$classid' limit 1");
  2559. if(strstr($f,','))
  2560. {
  2561. return $fr;
  2562. }
  2563. else
  2564. {
  2565. return $fr[$f];
  2566. }
  2567. }
  2568. //返回专题自定义字段内容
  2569. function ReturnZtAddField($classid,$f){
  2570. global $empire,$dbtbpre,$navclassid;
  2571. if(empty($classid))
  2572. {
  2573. $classid=$navclassid;
  2574. }
  2575. $fr=$empire->fetch1("select ".$f." from {$dbtbpre}enewsztadd where ztid='$classid' limit 1");
  2576. if(strstr($f,','))
  2577. {
  2578. return $fr;
  2579. }
  2580. else
  2581. {
  2582. return $fr[$f];
  2583. }
  2584. }
  2585. //返回扩展变量值
  2586. function ReturnPublicAddVar($myvar){
  2587. global $empire,$dbtbpre;
  2588. if(strstr($myvar,','))
  2589. {
  2590. $myvr=explode(',',$myvar);
  2591. $count=count($myvr);
  2592. for($i=0;$i<$count;$i++)
  2593. {
  2594. $v=$myvr[$i];
  2595. $vr=$empire->fetch1("select varvalue from {$dbtbpre}enewspubvar where myvar='$v' limit 1");
  2596. $ret_vr[$v]=$vr['varvalue'];
  2597. }
  2598. return $ret_vr;
  2599. }
  2600. else
  2601. {
  2602. $vr=$empire->fetch1("select varvalue from {$dbtbpre}enewspubvar where myvar='$myvar' limit 1");
  2603. return $vr['varvalue'];
  2604. }
  2605. }
  2606. //返回排序字段
  2607. function ReturnDoOrderF($mid,$orderby,$myorder){
  2608. global $emod_r;
  2609. $orderby=str_replace(',','',$orderby);
  2610. $orderf=',newstime,id,onclick,totaldown,plnum';
  2611. if(!empty($emod_r[$mid]['orderf']))
  2612. {
  2613. $orderf.=$emod_r[$mid]['orderf'];
  2614. }
  2615. else
  2616. {
  2617. $orderf.=',';
  2618. }
  2619. if(strstr($orderf,','.$orderby.','))
  2620. {
  2621. $rr['returnorder']=$orderby;
  2622. $rr['returnf']=$orderby;
  2623. }
  2624. else
  2625. {
  2626. $rr['returnorder']='newstime';
  2627. $rr['returnf']='newstime';
  2628. }
  2629. if(empty($myorder))
  2630. {
  2631. $rr['returnorder'].=' desc';
  2632. }
  2633. return $rr;
  2634. }
  2635. //返回置顶
  2636. function ReturnSetTopSql($ecms){
  2637. global $public_r;
  2638. if(empty($public_r['settop']))
  2639. {
  2640. return '';
  2641. }
  2642. $top='istop desc,';
  2643. if($ecms=='list')
  2644. {
  2645. if($public_r['settop']==1||$public_r['settop']==4||$public_r['settop']==5||$public_r['settop']==6)
  2646. {
  2647. return $top;
  2648. }
  2649. }
  2650. elseif($ecms=='bq')
  2651. {
  2652. if($public_r['settop']==2||$public_r['settop']==4||$public_r['settop']==5||$public_r['settop']==7)
  2653. {
  2654. return $top;
  2655. }
  2656. }
  2657. elseif($ecms=='js')
  2658. {
  2659. if($public_r['settop']==3||$public_r['settop']==4||$public_r['settop']==6||$public_r['settop']==7)
  2660. {
  2661. return $top;
  2662. }
  2663. }
  2664. return '';
  2665. }
  2666. //返回优化方案SQL
  2667. function ReturnYhSql($yhid,$yhvar,$ecms=0){
  2668. global $eyh_r;
  2669. if(empty($yhid))
  2670. {
  2671. return '';
  2672. }
  2673. $query='';
  2674. if($eyh_r[$yhid][$yhvar])
  2675. {
  2676. $t=time()-($eyh_r[$yhid][$yhvar]*86400);
  2677. $query='newstime>'.$t.(empty($ecms)?'':' and ');
  2678. }
  2679. return $query;
  2680. }
  2681. //返回优化+条件SQL
  2682. function ReturnYhAndSql($yhadd,$where,$ecms=0){
  2683. if($yhadd.$where=='')
  2684. {
  2685. return '';
  2686. }
  2687. elseif($yhadd&&$where)
  2688. {
  2689. return $ecms==1?' where '.$yhadd.$where:' where '.$yhadd.' and '.$where;
  2690. }
  2691. elseif($yhadd&&!$where)
  2692. {
  2693. return ' where '.$yhadd;
  2694. }
  2695. else
  2696. {
  2697. return $ecms==1?' where '.substr($where,5):' where '.$where;
  2698. }
  2699. }
  2700. //返回列表查询字段
  2701. function ReturnSqlListF($mid){
  2702. global $emod_r;
  2703. if(empty($mid))
  2704. {
  2705. return '*';
  2706. }
  2707. $f='id,classid,ttid,onclick,plnum,totaldown,newspath,filename,userid,username,firsttitle,isgood,ispic,istop,isqf,ismember,isurl,truetime,lastdotime,havehtml,groupid,userfen,titlefont,titleurl,stb,fstb,restb,keyboard,eckuid'.substr($emod_r[$mid]['listtempf'],0,-1);
  2708. return $f;
  2709. }
  2710. //返回内容查询字段
  2711. function ReturnSqlTextF($mid,$ecms=0){
  2712. global $emod_r;
  2713. if(empty($mid))
  2714. {
  2715. return '*';
  2716. }
  2717. $f=($ecms==0?'id,classid,':'').'ttid,onclick,plnum,totaldown,newspath,filename,userid,username,firsttitle,isgood,ispic,istop,isqf,ismember,isurl,truetime,lastdotime,havehtml,groupid,userfen,titlefont,titleurl,stb,fstb,restb,keyboard,eckuid'.substr($emod_r[$mid]['tbmainf'],0,-1);
  2718. return $f;
  2719. }
  2720. //返回内容副表查询字段
  2721. function ReturnSqlFtextF($mid){
  2722. global $emod_r;
  2723. if(empty($mid))
  2724. {
  2725. return '*';
  2726. }
  2727. $f='keyid,dokey,newstempid,closepl,infotags'.substr($emod_r[$mid]['tbdataf'],0,-1);
  2728. return $f;
  2729. }
  2730. //返回信息表
  2731. function ReturnInfoTbname($tbname,$checked=1,$stb=1){
  2732. global $dbtbpre;
  2733. if(empty($checked))//待审核
  2734. {
  2735. $r['tbname']=$dbtbpre.'ecms_'.$tbname.'_check';
  2736. $r['datatbname']=$dbtbpre.'ecms_'.$tbname.'_check_data';
  2737. }
  2738. else//已审核
  2739. {
  2740. $r['tbname']=$dbtbpre.'ecms_'.$tbname;
  2741. $r['datatbname']=$dbtbpre.'ecms_'.$tbname.'_data_'.$stb;
  2742. }
  2743. return $r;
  2744. }
  2745. //返回信息主表
  2746. function ReturnInfoMainTbname($tbname,$checked=1){
  2747. global $dbtbpre;
  2748. return empty($checked)?$dbtbpre.'ecms_'.$tbname.'_check':$dbtbpre.'ecms_'.$tbname;
  2749. }
  2750. //返回信息副表
  2751. function ReturnInfoDataTbname($tbname,$checked=1,$stb=1){
  2752. global $dbtbpre;
  2753. return empty($checked)?$dbtbpre.'ecms_'.$tbname.'_check_data':$dbtbpre.'ecms_'.$tbname.'_data_'.$stb;
  2754. }
  2755. //主表信息
  2756. function ReturnIndexTableInfo($tbname,$f,$classid,$id){
  2757. global $dbtbpre;
  2758. $r=$empire->fetch1("select ".$f." from {$dbtbpre}ecms_".$tbname."_index where id='$id' limit 1");
  2759. return $r;
  2760. }
  2761. //返回评论表名
  2762. function eReturnRestb($restb){
  2763. global $public_r,$dbtbpre;
  2764. $restb=(int)$restb;
  2765. if(!strstr($public_r['pldatatbs'],','.$restb.','))
  2766. {
  2767. $restb=$public_r['pldeftb'];
  2768. }
  2769. return $dbtbpre.'enewspl_'.$restb;
  2770. }
  2771. //返回附件表名
  2772. function eReturnFstb($fstb){
  2773. global $public_r,$dbtbpre;
  2774. $fstb=(int)$fstb;
  2775. if(!strstr($public_r['filedatatbs'],','.$fstb.','))
  2776. {
  2777. $fstb=$public_r['filedeftb'];
  2778. }
  2779. return $dbtbpre.'enewsfile_'.$fstb;
  2780. }
  2781. //返回公共表索引ID
  2782. function ReturnInfoPubid($classid,$id,$tid=0){
  2783. global $class_r;
  2784. $classid=(int)$classid;
  2785. $id=(int)$id;
  2786. if(empty($tid))
  2787. {
  2788. $tid=$class_r[$classid]['tid'];
  2789. }
  2790. $tid=(int)$tid;
  2791. $pubid='1'.ReturnAllInt($tid,5).ReturnAllInt($id,10);
  2792. return $pubid;
  2793. }
  2794. //是否内部表
  2795. function InfoIsInTable($tbname){
  2796. global $etable_r;
  2797. return $etable_r[$tbname]['intb']==1?true:false;
  2798. }
  2799. //检验字段是否存在
  2800. function eCheckTbHaveField($tid,$tbname,$f){
  2801. global $empire,$dbtbpre;
  2802. $where=$tid?"tid='$tid' and ":"tbname='$tbname' and ";
  2803. if(strstr($f,','))
  2804. {
  2805. $fr=explode(',',$f);
  2806. $where.="f='".$fr[0]."' or f='".$fr[1]."'";
  2807. }
  2808. else
  2809. {
  2810. $where.="f='$f'";
  2811. }
  2812. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where ".$where." limit 1");
  2813. return $num;
  2814. }
  2815. //验证模板是否开启动态使用
  2816. function DtTempIsClose($tempid,$type='listtemp'){
  2817. global $public_r;
  2818. if($type=='listtemp')//列表模板
  2819. {
  2820. if($public_r['closelisttemp']&&strstr(','.$public_r['closelisttemp'].',',','.$tempid.','))
  2821. {
  2822. echo'ListTempID='.$tempid.' is close.';
  2823. exit();
  2824. }
  2825. }
  2826. }
  2827. //补零
  2828. function ReturnAllInt($val,$num){
  2829. $len=strlen($val);
  2830. $zeronum=$num-$len;
  2831. if($zeronum==1)
  2832. {
  2833. $val='0'.$val;
  2834. }
  2835. elseif($zeronum==2)
  2836. {
  2837. $val='00'.$val;
  2838. }
  2839. elseif($zeronum==3)
  2840. {
  2841. $val='000'.$val;
  2842. }
  2843. elseif($zeronum==4)
  2844. {
  2845. $val='0000'.$val;
  2846. }
  2847. elseif($zeronum==5)
  2848. {
  2849. $val='00000'.$val;
  2850. }
  2851. elseif($zeronum==6)
  2852. {
  2853. $val='000000'.$val;
  2854. }
  2855. elseif($zeronum==7)
  2856. {
  2857. $val='0000000'.$val;
  2858. }
  2859. elseif($zeronum==8)
  2860. {
  2861. $val='00000000'.$val;
  2862. }
  2863. elseif($zeronum==9)
  2864. {
  2865. $val='000000000'.$val;
  2866. }
  2867. elseif($zeronum==10)
  2868. {
  2869. $val='0000000000'.$val;
  2870. }
  2871. return $val;
  2872. }
  2873. //返回替换列表
  2874. function ReturnReplaceListF($mid){
  2875. global $emod_r;
  2876. $r['mid']=$mid;
  2877. $r['fr']=explode(',',$emod_r[$mid]['listtempf']);
  2878. $r['fcount']=count($r['fr'])-1;
  2879. return $r;
  2880. }
  2881. //返回替换内容
  2882. function ReturnReplaceTextF($mid){
  2883. global $emod_r;
  2884. $r['mid']=$mid;
  2885. $r['fr']=explode(',',$emod_r[$mid]['tempf']);
  2886. $r['fcount']=count($r['fr'])-1;
  2887. return $r;
  2888. }
  2889. //替换列表模板/标签模板/搜索模板
  2890. function ReplaceListVars($no,$listtemp,$subnews,$subtitle,$formatdate,$url,$haveclass=0,$r,$field,$docode=0){
  2891. global $empire,$public_r,$class_r,$class_zr,$fun_r,$dbtbpre,$emod_r,$class_tr,$level_r,$navclassid,$etable_r;
  2892. if($haveclass)
  2893. {
  2894. $add=sys_ReturnBqClassname($r,$haveclass);
  2895. }
  2896. if(empty($r[oldtitle]))
  2897. {
  2898. $r[oldtitle]=$r[title];
  2899. }
  2900. if($docode==1)
  2901. {
  2902. $listtemp=stripSlashes($listtemp);
  2903. eval($listtemp);
  2904. }
  2905. $ylisttemp=$listtemp;
  2906. $mid=$field['mid'];
  2907. $fr=$field['fr'];
  2908. $fcount=$field['fcount'];
  2909. for($i=1;$i<$fcount;$i++)
  2910. {
  2911. $f=$fr[$i];
  2912. $value=$r[$f];
  2913. $spf=0;
  2914. if($f=='title')//标题
  2915. {
  2916. if(!empty($subtitle))//截取字符
  2917. {
  2918. $value=sub($value,0,$subtitle,false);
  2919. }
  2920. $value=DoTitleFont($r[titlefont],$value);
  2921. $spf=1;
  2922. }
  2923. elseif($f=='newstime')//时间
  2924. {
  2925. //$value=date($formatdate,$value);
  2926. $value=format_datetime($value,$formatdate);
  2927. $spf=1;
  2928. }
  2929. elseif($f=='titlepic')//标题图片
  2930. {
  2931. if(empty($value))
  2932. {
  2933. $value=$public_r[newsurl].'e/data/images/notimg.gif';
  2934. }
  2935. $spf=1;
  2936. }
  2937. elseif(strstr($emod_r[$mid]['smalltextf'],','.$f.','))//简介
  2938. {
  2939. if(!empty($subnews))//截取字符
  2940. {
  2941. $value=sub($value,0,$subnews,false);
  2942. }
  2943. }
  2944. elseif($f=='befrom')//信息来源
  2945. {
  2946. $spf=1;
  2947. }
  2948. elseif($f=='writer')//作者
  2949. {
  2950. $spf=1;
  2951. }
  2952. if($spf==0&&!strstr($emod_r[$mid]['editorf'],','.$f.','))
  2953. {
  2954. if(strstr($emod_r[$mid]['tobrf'],','.$f.','))//加br
  2955. {
  2956. $value=nl2br($value);
  2957. }
  2958. if(!strstr($emod_r[$mid]['dohtmlf'],','.$f.','))//去除html
  2959. {
  2960. $value=RepFieldtextNbsp(ehtmlspecialchars($value));
  2961. }
  2962. }
  2963. $listtemp=str_replace('[!--'.$f.'--]',$value,$listtemp);
  2964. }
  2965. $titleurl=sys_ReturnBqTitleLink($r);//链接
  2966. $listtemp=str_replace('[!--id--]',$r[id],$listtemp);
  2967. $listtemp=str_replace('[!--classid--]',$r[classid],$listtemp);
  2968. $listtemp=str_replace('[!--class.name--]',$add,$listtemp);
  2969. $listtemp=str_replace('[!--ttid--]',$r[ttid],$listtemp);
  2970. $listtemp=str_replace('[!--tt.name--]',$class_tr[$r[ttid]][tname],$listtemp);
  2971. $listtemp=str_replace('[!--tt.url--]',sys_ReturnBqInfoTypeUrl($r['ttid']),$listtemp);
  2972. $listtemp=str_replace('[!--userfen--]',$r[userfen],$listtemp);
  2973. $listtemp=str_replace('[!--titleurl--]',$titleurl,$listtemp);
  2974. $listtemp=str_replace('[!--no.num--]',$no,$listtemp);
  2975. $listtemp=str_replace('[!--plnum--]',$r[plnum],$listtemp);
  2976. $listtemp=str_replace('[!--userid--]',$r[userid],$listtemp);
  2977. $listtemp=str_replace('[!--username--]',$r[username],$listtemp);
  2978. $listtemp=str_replace('[!--onclick--]',$r[onclick],$listtemp);
  2979. $listtemp=str_replace('[!--oldtitle--]',$r[oldtitle],$listtemp);
  2980. $listtemp=str_replace('[!--totaldown--]',$r[totaldown],$listtemp);
  2981. //栏目链接
  2982. if(strstr($ylisttemp,'[!--this.classlink--]'))
  2983. {
  2984. $thisclasslink=sys_ReturnBqClassname($r,9);
  2985. $listtemp=str_replace('[!--this.classlink--]',$thisclasslink,$listtemp);
  2986. }
  2987. $thisclassname=$class_r[$r[classid]][bname]?$class_r[$r[classid]][bname]:$class_r[$r[classid]][classname];
  2988. $listtemp=str_replace('[!--this.classname--]',$thisclassname,$listtemp);
  2989. return $listtemp;
  2990. }
  2991. //加上防复制字符
  2992. function AddNotCopyRndStr($text){
  2993. global $public_r;
  2994. if($public_r['opencopytext'])
  2995. {
  2996. $rnd=make_password(3).$public_r['sitename'];
  2997. $text=str_replace("<br />","<span style=\"display:none\">".$rnd."</span><br />",$text);
  2998. $text=str_replace("</p>","<span style=\"display:none\">".$rnd."</span></p>",$text);
  2999. }
  3000. return $text;
  3001. }
  3002. //替换信息来源
  3003. function ReplaceBefrom($befrom){
  3004. global $empire,$dbtbpre;
  3005. if(empty($befrom))
  3006. {return $befrom;}
  3007. $befrom=addslashes($befrom);
  3008. $r=$empire->fetch1("select befromid,sitename,siteurl from {$dbtbpre}enewsbefrom where sitename='$befrom' limit 1");
  3009. if(empty($r[befromid]))
  3010. {return $befrom;}
  3011. $return_befrom="<a href='".$r[siteurl]."' target=_blank>".$r[sitename]."</a>";
  3012. return $return_befrom;
  3013. }
  3014. //替换作者
  3015. function ReplaceWriter($writer){
  3016. global $empire,$dbtbpre;
  3017. if(empty($writer))
  3018. {return $writer;}
  3019. $writer=addslashes($writer);
  3020. $r=$empire->fetch1("select wid,writer,email from {$dbtbpre}enewswriter where writer='$writer' limit 1");
  3021. if(empty($r[wid])||empty($r[email]))
  3022. {
  3023. return $writer;
  3024. }
  3025. $return_writer="<a href='".$r[email]."'>".$r[writer]."</a>";
  3026. return $return_writer;
  3027. }
  3028. //备份下载记录
  3029. function BakDown($classid,$id,$pathid,$userid,$username,$title,$cardfen,$online=0){
  3030. global $empire,$dbtbpre;
  3031. $truetime=time();
  3032. $id=(int)$id;
  3033. $pathid=(int)$pathid;
  3034. $userid=(int)$userid;
  3035. $cardfen=(int)$cardfen;
  3036. $classid=(int)$classid;
  3037. $username=RepPostVar($username);
  3038. $title=RepPostStr($title);
  3039. $online=addslashes(RepPostStr($online));
  3040. $sql=$empire->query("insert into {$dbtbpre}enewsdownrecord(id,pathid,userid,username,title,cardfen,truetime,classid,online) values($id,$pathid,$userid,'$username','".addslashes($title)."',$cardfen,$truetime,$classid,'$online');");
  3041. }
  3042. //备份充值记录
  3043. function BakBuy($userid,$username,$buyname,$userfen,$money,$userdate,$type=0){
  3044. global $empire,$dbtbpre;
  3045. $buytime=date("y-m-d H:i:s");
  3046. $buyname=addslashes(RepPostStr($buyname));
  3047. $userid=(int)$userid;
  3048. $username=RepPostVar($username);
  3049. $userfen=addslashes(RepPostStr($userfen));
  3050. $money=addslashes(RepPostStr($money));
  3051. $userdate=addslashes(RepPostStr($userdate));
  3052. $type=addslashes(RepPostStr($type));
  3053. $empire->query("insert into {$dbtbpre}enewsbuybak(userid,username,card_no,cardfen,money,buytime,userdate,type) values('$userid','$username','$buyname','$userfen','$money','$buytime','$userdate','$type');");
  3054. }
  3055. //发送短消息
  3056. function eSendMsg($title,$msgtext,$to_username,$from_userid,$from_username,$isadmin,$issys,$ecms=0){
  3057. global $empire,$dbtbpre;
  3058. $tbname=$ecms==1?$dbtbpre.'enewshmsg':$dbtbpre.'enewsqmsg';
  3059. $to_username=RepPostVar($to_username);
  3060. $from_userid=(int)$from_userid;
  3061. $from_username=RepPostVar($from_username);
  3062. $isadmin=(int)$isadmin;
  3063. $issys=(int)$issys;
  3064. $msgtime=date("Y-m-d H:i:s");
  3065. $empire->query("insert into ".$tbname."(title,msgtext,haveread,msgtime,to_username,from_userid,from_username,isadmin,issys) values('$title','$msgtext',0,'$msgtime','$to_username','$from_userid','$from_username','$isadmin','$issys');");
  3066. //消息状态
  3067. $userr=$empire->fetch1("select ".eReturnSelectMemberF('userid,havemsg')." from ".eReturnMemberTable()." where ".egetmf('username')."='$to_username' limit 1");
  3068. if(!$userr['havemsg'])
  3069. {
  3070. $newhavemsg=eReturnSetHavemsg($userr['havemsg'],0);
  3071. $empire->query("update ".eReturnMemberTable()." set ".egetmf('havemsg')."='$newhavemsg' where ".egetmf('userid')."='".$userr['userid']."' limit 1");
  3072. }
  3073. }
  3074. //发送通知
  3075. function eSendNotice($title,$msgtext,$to_username,$from_userid,$from_username,$ecms=0){
  3076. global $empire,$dbtbpre;
  3077. $tbname=$ecms==1?$dbtbpre.'enewshnotice':$dbtbpre.'enewsnotice';
  3078. $to_username=RepPostVar($to_username);
  3079. $from_userid=(int)$from_userid;
  3080. $from_username=RepPostVar($from_username);
  3081. $msgtime=date("Y-m-d H:i:s");
  3082. $empire->query("insert into ".$tbname."(title,msgtext,haveread,msgtime,to_username,from_userid,from_username) values('".$title."','".$msgtext."',0,'$msgtime','$to_username','$from_userid','$from_username');");
  3083. }
  3084. //截取简介
  3085. function SubSmalltextVal($value,$len){
  3086. if(empty($len))
  3087. {
  3088. return '';
  3089. }
  3090. $value=str_replace(array("\r\n","<br />","<br>","&nbsp;","[!--empirenews.page--]","[/!--empirenews.page--]"),array("","\r\n","\r\n"," ","",""),$value);
  3091. $value=strip_tags($value);
  3092. if($len)
  3093. {
  3094. $value=sub($value,0,$len,false);
  3095. }
  3096. $value=trim($value,"\r\n");
  3097. $value=str_replace('&amp;ldquo;','&ldquo;',$value);
  3098. $value=str_replace('&amp;rdquo;','&rdquo;',$value);
  3099. $value=str_replace('&amp;mdash;','&mdash;',$value);
  3100. return $value;
  3101. }
  3102. //全站搜索简介
  3103. function SubSchallSmalltext($value,$len){
  3104. $value=str_replace(array("\r\n","&nbsp;","[!--empirenews.page--]","[/!--empirenews.page--]"),array("","","",""),$value);
  3105. $value=strip_tags($value);
  3106. if($len)
  3107. {
  3108. $value=sub($value,0,$len,false);
  3109. }
  3110. $value=trim($value,"\r\n");
  3111. return $value;
  3112. }
  3113. //加红替换
  3114. function DoReplaceFontRed($text,$key){
  3115. return str_replace($key,'<font color="red">'.$key.'</font>',$text);
  3116. }
  3117. //返回不生成html的栏目
  3118. function ReturnNreInfoWhere(){
  3119. global $public_r;
  3120. if(empty($public_r['nreinfo'])||$public_r['nreinfo']==',')
  3121. {
  3122. return '';
  3123. }
  3124. $cids=substr($public_r['nreinfo'],1,strlen($public_r['nreinfo'])-2);
  3125. $where=' and classid not in ('.$cids.')';
  3126. return $where;
  3127. }
  3128. //返回标签不调用栏目
  3129. function ReturnNottoBqWhere(){
  3130. global $public_r;
  3131. if(empty($public_r['nottobq'])||$public_r['nottobq']==',')
  3132. {
  3133. return '';
  3134. }
  3135. $cids=substr($public_r['nottobq'],1,strlen($public_r['nottobq'])-2);
  3136. $where='classid not in ('.$cids.')';
  3137. return $where;
  3138. }
  3139. //返回文件名及扩展名
  3140. function ReturnCFiletype($file){
  3141. $r=explode('.',$file);
  3142. $count=count($r)-1;
  3143. $re['filetype']=strtolower($r[$count]);
  3144. $re['filename']=substr($file,0,strlen($file)-strlen($re['filetype'])-1);
  3145. return $re;
  3146. }
  3147. //返回栏目目录
  3148. function ReturnSaveClassPath($classid,$f=0){
  3149. global $class_r;
  3150. $classpath=$class_r[$classid][classpath];
  3151. if($f==1){
  3152. $classpath.="/index".$class_r[$classid][classtype];
  3153. }
  3154. return $classpath;
  3155. }
  3156. //返回专题目录
  3157. function ReturnSaveZtPath($classid,$f=0){
  3158. global $class_zr;
  3159. $classpath=$class_zr[$classid][ztpath];
  3160. if($f==1){
  3161. $classpath.="/index".$class_zr[$classid][zttype];
  3162. }
  3163. return $classpath;
  3164. }
  3165. //返回标题分类目录
  3166. function ReturnSaveInfoTypePath($classid,$f=0){
  3167. global $class_tr;
  3168. $classpath=$class_tr[$classid]['tpath'];
  3169. if($f==1){
  3170. $classpath.='/index'.$class_tr[$classid]['ttype'];
  3171. }
  3172. return $classpath;
  3173. }
  3174. //返回首页文件
  3175. function ReturnSaveIndexFile(){
  3176. global $public_r;
  3177. $file='index'.$public_r[indextype];
  3178. return $file;
  3179. }
  3180. //返回首页地址
  3181. function ReturnSiteIndexUrl(){
  3182. global $public_r;
  3183. if(empty($public_r['indexaddpage']))
  3184. {
  3185. return $public_r['newsurl'];
  3186. }
  3187. if($public_r['indexpagedt']||Moreport_ReturnMustDt())//moreport
  3188. {
  3189. $public_r['indextype']='.php';
  3190. }
  3191. $file=$public_r['newsurl'].'index'.$public_r['indextype'];
  3192. return $file;
  3193. }
  3194. //返回内容页存放目录
  3195. function ReturnSaveInfoPath($classid,$id){
  3196. global $class_r;
  3197. if($class_r[$classid][ipath]==''){
  3198. $path=$class_r[$classid][classpath].'/';
  3199. }
  3200. else{
  3201. $path=$class_r[$classid][ipath]=='/'?'':$class_r[$classid][ipath].'/';
  3202. }
  3203. return $path;
  3204. }
  3205. //返回内容页文件名
  3206. function GetInfoFilename($classid,$id){
  3207. global $empire,$dbtbpre,$public_r,$class_r;
  3208. $infor=$empire->fetch1("select isurl,groupid,classid,newspath,filename,id from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' limit 1");
  3209. if(!$infor['id']||$infor['isurl'])
  3210. {
  3211. return '';
  3212. }
  3213. $filetype=$infor['groupid']?'.php':$class_r[$classid]['filetype'];
  3214. $iclasspath=ReturnSaveInfoPath($classid,$id);
  3215. $doclasspath=eReturnTrueEcmsPath().$iclasspath;//moreport
  3216. $newspath='';
  3217. if($infor['newspath'])
  3218. {
  3219. $newspath=$infor['newspath'].'/';
  3220. }
  3221. $file=$doclasspath.$newspath.$infor['filename'].$filetype;
  3222. return $file;
  3223. }
  3224. //格式化信息目录
  3225. function FormatPath($classid,$mynewspath,$enews=0){
  3226. global $class_r;
  3227. if($enews)
  3228. {
  3229. $newspath=$mynewspath;
  3230. }
  3231. else
  3232. {
  3233. $newspath=date($class_r[$classid][newspath]);
  3234. }
  3235. if(empty($newspath))
  3236. {
  3237. return "";
  3238. }
  3239. $path=eReturnTrueEcmsPath().ReturnSaveInfoPath($classid,$id);
  3240. if(file_exists($path.$newspath))
  3241. {
  3242. return $newspath;
  3243. }
  3244. $returnpath="";
  3245. $r=explode("/",$newspath);
  3246. $count=count($r);
  3247. for($i=0;$i<$count;$i++){
  3248. if($i>0)
  3249. {
  3250. $returnpath.="/".$r[$i];
  3251. }
  3252. else
  3253. {
  3254. $returnpath.=$r[$i];
  3255. }
  3256. $createpath=$path.$returnpath;
  3257. $mk=DoMkdir($createpath);
  3258. if(empty($mk))
  3259. {
  3260. printerror("CreatePathFail","");
  3261. }
  3262. }
  3263. return $returnpath;
  3264. }
  3265. //返回内容页目录
  3266. function ReturnInfoSPath($filename){
  3267. return str_replace('/index','',$filename);
  3268. }
  3269. //返回根目录
  3270. function ReturnAbsEcmsPath(){
  3271. $ecmspath=str_replace("\\","/",ECMS_PATH);
  3272. return $ecmspath;
  3273. }
  3274. //返回当前根目录
  3275. function eReturnTrueEcmsPath(){
  3276. if(defined('ECMS_SELFPATH'))
  3277. {
  3278. return ECMS_SELFPATH;
  3279. }
  3280. else
  3281. {
  3282. return ECMS_PATH;
  3283. }
  3284. }
  3285. //返回主端根目录
  3286. function eReturnEcmsMainPortPath(){
  3287. global $ecms_config;
  3288. if($ecms_config['sets']['mainportpath'])
  3289. {
  3290. return $ecms_config['sets']['mainportpath'];
  3291. }
  3292. else
  3293. {
  3294. return ECMS_PATH;
  3295. }
  3296. }
  3297. //------------- 附件 -------------
  3298. //返回附件分表
  3299. function eReturnFileStb($fstb){
  3300. global $public_r;
  3301. $fstb=(int)$fstb;
  3302. if(!strstr($public_r['filedatatbs'],','.$fstb.','))
  3303. {
  3304. $fstb=$public_r['filedeftb'];
  3305. }
  3306. return $fstb;
  3307. }
  3308. //返回附件表
  3309. function eReturnFileTable($modtype,$fstb){
  3310. global $dbtbpre;
  3311. if($modtype==0)//信息
  3312. {
  3313. $fstb=eReturnFileStb($fstb);
  3314. $table=$dbtbpre.'enewsfile_'.$fstb;
  3315. }
  3316. elseif($modtype==5)//公共
  3317. {
  3318. $table=$dbtbpre.'enewsfile_public';
  3319. }
  3320. elseif($modtype==6)//会员
  3321. {
  3322. $table=$dbtbpre.'enewsfile_member';
  3323. }
  3324. else//其他
  3325. {
  3326. $table=$dbtbpre.'enewsfile_other';
  3327. }
  3328. return $table;
  3329. }
  3330. //查询附件表
  3331. function eSelectFileTable($modtype,$fstb,$selectf,$where){
  3332. global $dbtbpre;
  3333. $query="select {$selectf} from ".eReturnFileTable($modtype,$fstb)." where ".$where;
  3334. return $query;
  3335. }
  3336. //写入附件记录
  3337. function eInsertFileTable($filename,$filesize,$path,$adduser,$classid,$no,$type,$id,$cjid,$fpath,$pubid,$modtype=0,$fstb=1){
  3338. global $empire,$dbtbpre,$public_r;
  3339. $filetime=time();
  3340. $filesize=(int)$filesize;
  3341. $classid=(int)$classid;
  3342. $id=(int)$id;
  3343. $cjid=(int)$cjid;
  3344. $fpath=(int)$fpath;
  3345. $type=(int)$type;
  3346. $modtype=(int)$modtype;
  3347. $filename=addslashes(RepPostStr($filename));
  3348. $no=addslashes(RepPostStr($no));
  3349. $adduser=RepPostVar($adduser);
  3350. $path=addslashes(RepPostStr($path));
  3351. $pubid=RepPostVar($pubid);
  3352. $fstb=(int)$fstb;
  3353. if($modtype==0)//信息
  3354. {
  3355. $fstb=eReturnFileStb($fstb);
  3356. $sql=$empire->query("insert into {$dbtbpre}enewsfile_".$fstb."(pubid,filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$pubid','$filename','$filesize','$adduser','$path','$filetime','$classid','$no','$type','$id','$cjid',0,'$fpath');");
  3357. }
  3358. elseif($modtype==5)//公共
  3359. {
  3360. $sql=$empire->query("insert into {$dbtbpre}enewsfile_public(filename,filesize,adduser,path,filetime,modtype,no,type,id,cjid,onclick,fpath) values('$filename','$filesize','$adduser','$path','$filetime',0,'$no','$type','$id','$cjid',0,'$fpath');");
  3361. }
  3362. elseif($modtype==6)//会员
  3363. {
  3364. $sql=$empire->query("insert into {$dbtbpre}enewsfile_member(filename,filesize,adduser,path,filetime,no,type,id,cjid,onclick,fpath) values('$filename','$filesize','$adduser','$path','$filetime','$no','$type','$id','$cjid',0,'$fpath');");
  3365. }
  3366. else//其他
  3367. {
  3368. $sql=$empire->query("insert into {$dbtbpre}enewsfile_other(filename,filesize,adduser,path,filetime,modtype,no,type,id,cjid,onclick,fpath) values('$filename','$filesize','$adduser','$path','$filetime','$modtype','$no','$type','$id','$cjid',0,'$fpath');");
  3369. }
  3370. return $sql;
  3371. }
  3372. //更新相应的附件(非信息)
  3373. function UpdateTheFileOther($modtype,$id,$checkpass,$tb='other'){
  3374. global $empire,$dbtbpre;
  3375. if(empty($id)||empty($checkpass))
  3376. {
  3377. return "";
  3378. }
  3379. $id=(int)$id;
  3380. $checkpass=(int)$checkpass;
  3381. $where='';
  3382. if($tb=='other')
  3383. {
  3384. $where=" and modtype='$modtype'";
  3385. }
  3386. $sql=$empire->query("update {$dbtbpre}enewsfile_{$tb} set id='$id',cjid=0 where cjid='$checkpass'".$where);
  3387. }
  3388. //修改时更新附件(非信息)
  3389. function UpdateTheFileEditOther($modtype,$id,$tb='other'){
  3390. global $empire,$dbtbpre;
  3391. $where='';
  3392. if($tb=='other')
  3393. {
  3394. $where=" and modtype='$modtype'";
  3395. }
  3396. $sql=$empire->query("update {$dbtbpre}enewsfile_{$tb} set cjid=0 where id='$id'".$where);
  3397. }
  3398. //返回filepass
  3399. function ReturnTranFilepass(){
  3400. $filepass=time();
  3401. return $filepass;
  3402. }
  3403. //返回附件域名地址
  3404. function eReturnFileUrl($ecms=0){
  3405. global $public_r;
  3406. if($ecms==1)
  3407. {
  3408. return $public_r['fileurl'];
  3409. }
  3410. $fileurl=$public_r['openfileserver']?$public_r['fs_purl']:$public_r['fileurl'];
  3411. return $fileurl;
  3412. }
  3413. //返回附件目录
  3414. function ReturnFileSavePath($classid,$fpath=''){
  3415. global $public_r,$class_r;
  3416. $fpath=$fpath||strstr(','.$fpath.',',',0,')?$fpath:$public_r['fpath'];
  3417. $efileurl=eReturnFileUrl();
  3418. if($fpath==1)//p目录
  3419. {
  3420. $r['filepath']='d/file/p/';
  3421. $r['fileurl']=$efileurl.'p/';
  3422. }
  3423. elseif($fpath==2)//file目录
  3424. {
  3425. $r['filepath']='d/file/';
  3426. $r['fileurl']=$efileurl;
  3427. }
  3428. else
  3429. {
  3430. if(empty($classid))
  3431. {
  3432. $r['filepath']='d/file/p/';
  3433. $r['fileurl']=$efileurl.'p/';
  3434. }
  3435. else
  3436. {
  3437. $r['filepath']='d/file/'.$class_r[$classid][classpath].'/';
  3438. $r['fileurl']=$efileurl.$class_r[$classid][classpath].'/';
  3439. }
  3440. }
  3441. return $r;
  3442. }
  3443. //格式化附件目录
  3444. function FormatFilePath($classid,$mynewspath,$enews=0){
  3445. global $public_r;
  3446. if($enews)
  3447. {
  3448. $newspath=$mynewspath;
  3449. }
  3450. else
  3451. {
  3452. $newspath=date($public_r['filepath']);
  3453. }
  3454. if(empty($newspath))
  3455. {
  3456. return "";
  3457. }
  3458. $fspath=ReturnFileSavePath($classid);
  3459. $path=eReturnEcmsMainPortPath().$fspath['filepath'];//moreport
  3460. if(file_exists($path.$newspath))
  3461. {
  3462. return $newspath;
  3463. }
  3464. $returnpath="";
  3465. $r=explode("/",$newspath);
  3466. $count=count($r);
  3467. for($i=0;$i<$count;$i++){
  3468. if($i>0){
  3469. $returnpath.="/".$r[$i];
  3470. }
  3471. else{
  3472. $returnpath.=$r[$i];
  3473. }
  3474. $createpath=$path.$returnpath;
  3475. $mk=DoMkdir($createpath);
  3476. if(empty($mk)){
  3477. printerror("CreatePathFail","");
  3478. }
  3479. }
  3480. return $returnpath;
  3481. }
  3482. //返回上传文件名
  3483. function ReturnDoTranFilename($file_name,$classid){
  3484. $filename=md5(uniqid(microtime()).EcmsRandInt());
  3485. return $filename;
  3486. }
  3487. //上传文件
  3488. function DoTranFile($file,$file_name,$file_type,$file_size,$classid,$ecms=0){
  3489. global $public_r,$class_r,$doetran,$efileftp_fr;
  3490. $classid=(int)$classid;
  3491. //文件类型
  3492. $r[filetype]=GetFiletype($file_name);
  3493. //文件名
  3494. $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
  3495. $r[filename]=$r[insertfile].$r[filetype];
  3496. //日期目录
  3497. $r[filepath]=FormatFilePath($classid,$mynewspath,0);
  3498. $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
  3499. //存放目录
  3500. $fspath=ReturnFileSavePath($classid);
  3501. $r[savepath]=eReturnEcmsMainPortPath().$fspath['filepath'].$filepath;//moreport
  3502. //附件地址
  3503. $r[url]=$fspath['fileurl'].$filepath.$r[filename];
  3504. //缩图文件
  3505. $r[name]=$r[savepath]."small".$r[insertfile];
  3506. //附件文件
  3507. $r[yname]=$r[savepath].$r[filename];
  3508. $r[tran]=1;
  3509. //验证类型
  3510. if(CheckSaveTranFiletype($r[filetype]))
  3511. {
  3512. if($doetran)
  3513. {
  3514. $r[tran]=0;
  3515. return $r;
  3516. }
  3517. else
  3518. {
  3519. printerror('TranFail','',$ecms);
  3520. }
  3521. }
  3522. //上传文件
  3523. $cp=@move_uploaded_file($file,$r[yname]);
  3524. if(empty($cp))
  3525. {
  3526. if($doetran)
  3527. {
  3528. $r[tran]=0;
  3529. return $r;
  3530. }
  3531. else
  3532. {
  3533. printerror('TranFail','',$ecms);
  3534. }
  3535. }
  3536. DoChmodFile($r[yname]);
  3537. $r[filesize]=(int)$file_size;
  3538. //FileServer
  3539. if($public_r['openfileserver'])
  3540. {
  3541. $efileftp_fr[]=$r['yname'];
  3542. }
  3543. return $r;
  3544. }
  3545. //远程保存忽略地址
  3546. function CheckNotSaveUrl($url){
  3547. global $public_r;
  3548. if(empty($public_r['notsaveurl']))
  3549. {
  3550. return 0;
  3551. }
  3552. $r=explode("\r\n",$public_r['notsaveurl']);
  3553. $count=count($r);
  3554. $re=0;
  3555. for($i=0;$i<$count;$i++)
  3556. {
  3557. if(empty($r[$i]))
  3558. {continue;}
  3559. if(stristr($url,$r[$i]))
  3560. {
  3561. $re=1;
  3562. break;
  3563. }
  3564. }
  3565. return $re;
  3566. }
  3567. //远程保存
  3568. function DoTranUrl($url,$classid){
  3569. global $public_r,$class_r,$ecms_config,$efileftp_fr;
  3570. $classid=(int)$classid;
  3571. //处理地址
  3572. $url=trim($url);
  3573. $url=str_replace(" ","%20",$url);
  3574. $r[tran]=1;
  3575. //附件地址
  3576. $r[url]=$url;
  3577. //文件类型
  3578. $r[filetype]=GetFiletype($url);
  3579. if(CheckSaveTranFiletype($r[filetype]))
  3580. {
  3581. $r[tran]=0;
  3582. return $r;
  3583. }
  3584. //是否已上传的文件
  3585. $havetr=CheckNotSaveUrl($url);
  3586. if($havetr)
  3587. {
  3588. $r[tran]=0;
  3589. return $r;
  3590. }
  3591. //是否地址
  3592. if(!strstr($url,'://'))
  3593. {
  3594. $r[tran]=0;
  3595. return $r;
  3596. }
  3597. if(!eToCheckIsUrl2($url))
  3598. {
  3599. $r[tran]=0;
  3600. return $r;
  3601. }
  3602. $string=ReadFiletext($url);
  3603. if(empty($string))//读取不了
  3604. {
  3605. $r[tran]=0;
  3606. return $r;
  3607. }
  3608. //文件名
  3609. $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
  3610. $r[filename]=$r[insertfile].$r[filetype];
  3611. //日期目录
  3612. $r[filepath]=FormatFilePath($classid,$mynewspath,0);
  3613. $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
  3614. //存放目录
  3615. $fspath=ReturnFileSavePath($classid);
  3616. $r[savepath]=eReturnEcmsMainPortPath().$fspath['filepath'].$filepath;//moreport
  3617. //附件地址
  3618. $r[url]=$fspath['fileurl'].$filepath.$r[filename];
  3619. //缩图文件
  3620. $r[name]=$r[savepath]."small".$r[insertfile];
  3621. //附件文件
  3622. $r[yname]=$r[savepath].$r[filename];
  3623. WriteFiletext_n($r[yname],$string);
  3624. $r[filesize]=@filesize($r[yname]);
  3625. //返回类型
  3626. if(strstr($ecms_config['sets']['tranflashtype'],','.$r[filetype].','))
  3627. {
  3628. $r[type]=2;
  3629. }
  3630. elseif(strstr($ecms_config['sets']['tranpicturetype'],','.$r[filetype].','))
  3631. {
  3632. $r[type]=1;
  3633. }
  3634. elseif(strstr($ecms_config['sets']['mediaplayertype'],','.$r[filetype].',')||strstr($ecms_config['sets']['realplayertype'],','.$r[filetype].','))//多媒体
  3635. {
  3636. $r[type]=3;
  3637. }
  3638. else
  3639. {
  3640. $r[type]=0;
  3641. }
  3642. //FileServer
  3643. if($public_r['openfileserver'])
  3644. {
  3645. $efileftp_fr[]=$r['yname'];
  3646. }
  3647. return $r;
  3648. }
  3649. //删除附件
  3650. function DoDelFile($r){
  3651. global $class_r,$public_r,$efileftp_dr;
  3652. $path=$r['path']?$r['path'].'/':$r['path'];
  3653. $fspath=ReturnFileSavePath($r[classid],$r[fpath]);
  3654. $delfile=eReturnEcmsMainPortPath().$fspath['filepath'].$path.$r['filename'];//moreport
  3655. DelFiletext($delfile);
  3656. //FileServer
  3657. if($public_r['openfileserver'])
  3658. {
  3659. $efileftp_dr[]=$delfile;
  3660. }
  3661. }
  3662. //替换表前缀
  3663. function RepSqlTbpre($sql){
  3664. global $dbtbpre;
  3665. $sql=str_replace('[!db.pre!]',$dbtbpre,$sql);
  3666. return $sql;
  3667. }
  3668. //反替换表前缀
  3669. function ReRepSqlTbpre($sql){
  3670. global $dbtbpre;
  3671. $sql=str_replace($dbtbpre,'***_',$sql);
  3672. return $sql;
  3673. }
  3674. //验证表是否存在
  3675. function eCheckTbname($tbname){
  3676. global $empire,$dbtbpre;
  3677. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
  3678. return $num;
  3679. }
  3680. //时间转换
  3681. function ToChangeUseTime($time){
  3682. global $fun_r;
  3683. $usetime=time()-$time;
  3684. if($usetime<60)
  3685. {
  3686. $tstr=$usetime.$fun_r['TimeSecond'];
  3687. }
  3688. else
  3689. {
  3690. $usetime=round($usetime/60);
  3691. $tstr=$usetime.$fun_r['TimeMinute'];
  3692. }
  3693. return $tstr;
  3694. }
  3695. //返回栏目集合
  3696. function ReturnClass($sonclass){
  3697. if($sonclass==''||$sonclass=='|'){
  3698. return 'classid=0';
  3699. }
  3700. $where='classid in ('.RepSonclassSql($sonclass).')';
  3701. return $where;
  3702. }
  3703. //替换子栏目子
  3704. function RepSonclassSql($sonclass){
  3705. if($sonclass==''||$sonclass=='|'){
  3706. return 0;
  3707. }
  3708. $sonclass=substr($sonclass,1,strlen($sonclass)-2);
  3709. $sonclass=str_replace('|',',',$sonclass);
  3710. return $sonclass;
  3711. }
  3712. //返回多栏目
  3713. function sys_ReturnMoreClass($sonclass,$son=0){
  3714. global $class_r;
  3715. $r=explode(',',$sonclass);
  3716. $count=count($r);
  3717. $return_r[0]=intval($r[0]);
  3718. $where='';
  3719. $or='';
  3720. for($i=0;$i<$count;$i++)
  3721. {
  3722. $r[$i]=intval($r[$i]);
  3723. if($son==1)
  3724. {
  3725. if($class_r[$r[$i]]['tbname']&&!$class_r[$r[$i]]['islast'])
  3726. {
  3727. $where.=$or."classid in (".RepSonclassSql($class_r[$r[$i]]['sonclass']).")";
  3728. }
  3729. else
  3730. {
  3731. $where.=$or."classid='".$r[$i]."'";
  3732. }
  3733. }
  3734. else
  3735. {
  3736. $where.=$or."classid='".$r[$i]."'";
  3737. }
  3738. $or=' or ';
  3739. }
  3740. $return_r[1]=$where;
  3741. return $return_r;
  3742. }
  3743. //返回多专题
  3744. function sys_ReturnMoreZt($zt,$ecms=0){
  3745. $f=$ecms==1?'ztid':'cid';
  3746. $r=explode(',',$zt);
  3747. $count=count($r);
  3748. $return_r[0]=intval($r[0]);
  3749. $ids='';
  3750. $dh='';
  3751. for($i=0;$i<$count;$i++)
  3752. {
  3753. $r[$i]=intval($r[$i]);
  3754. $ids.=$dh.$r[$i];
  3755. $dh=',';
  3756. }
  3757. $return_r[1]=$f.' in ('.$ids.')';
  3758. return $return_r;
  3759. }
  3760. //返回多标题分类
  3761. function sys_ReturnMoreTT($tt){
  3762. $r=explode(',',$tt);
  3763. $count=count($r);
  3764. $return_r[0]=intval($r[0]);
  3765. $ids='';
  3766. $dh='';
  3767. for($i=0;$i<$count;$i++)
  3768. {
  3769. $r[$i]=intval($r[$i]);
  3770. $ids.=$dh.$r[$i];
  3771. $dh=',';
  3772. }
  3773. $return_r[1]='ttid in ('.$ids.')';
  3774. return $return_r;
  3775. }
  3776. //验证是否包含栏目
  3777. function CheckHaveInClassid($cr,$checkclass){
  3778. global $class_r;
  3779. if($cr['islast'])
  3780. {
  3781. $chclass='|'.$cr['classid'].'|';
  3782. }
  3783. else
  3784. {
  3785. $chclass=$cr['sonclass'];
  3786. }
  3787. $return=0;
  3788. $r=explode('|',$chclass);
  3789. $count=count($r);
  3790. for($i=1;$i<$count-1;$i++)
  3791. {
  3792. if(strstr($checkclass,'|'.$r[$i].'|'))
  3793. {
  3794. $return=1;
  3795. break;
  3796. }
  3797. }
  3798. return $return;
  3799. }
  3800. //返回加前缀的下载地址
  3801. function ReturnDownQzPath($path,$urlid){
  3802. global $empire,$dbtbpre;
  3803. $urlid=(int)$urlid;
  3804. if(empty($urlid))
  3805. {
  3806. $re['repath']=$path;
  3807. $re['downtype']=0;
  3808. }
  3809. else
  3810. {
  3811. $r=$empire->fetch1("select urlid,url,downtype from {$dbtbpre}enewsdownurlqz where urlid='$urlid'");
  3812. if($r['urlid'])
  3813. {
  3814. $re['repath']=$r['url'].$path;
  3815. }
  3816. else
  3817. {
  3818. $re['repath']=$path;
  3819. }
  3820. $re['downtype']=$r['downtype'];
  3821. }
  3822. return $re;
  3823. }
  3824. //返回带防盗链的绝对地址
  3825. function ReturnDSofturl($downurl,$qz,$path='../../',$isdown=0){
  3826. $urlr=ReturnDownQzPath(stripSlashes($downurl),$qz);
  3827. $url=$urlr['repath'];
  3828. @include_once(ECMS_PATH."e/DownSys/class/enpath.php");//防盗链
  3829. if($isdown)
  3830. {
  3831. $url=DoEnDownpath($url);
  3832. }
  3833. else
  3834. {
  3835. $url=DoEnOnlinepath($url);
  3836. }
  3837. return $url;
  3838. }
  3839. //验证提交来源
  3840. function CheckCanPostUrl(){
  3841. global $public_r;
  3842. if($public_r['canposturl'])
  3843. {
  3844. $r=explode("\r\n",$public_r['canposturl']);
  3845. $count=count($r);
  3846. $b=0;
  3847. for($i=0;$i<$count;$i++)
  3848. {
  3849. if(strstr($_SERVER['HTTP_REFERER'],$r[$i]))
  3850. {
  3851. $b=1;
  3852. break;
  3853. }
  3854. }
  3855. if($b==0)
  3856. {
  3857. printerror('NotCanPostUrl','',1);
  3858. }
  3859. }
  3860. }
  3861. //adminpath
  3862. function eGetSelfAdminPath(){
  3863. $selfpath=eReturnSelfPage(0);
  3864. $selfpath=str_replace("\\","/",$selfpath);
  3865. if(strstr($selfpath,'//'))
  3866. {
  3867. exit();
  3868. }
  3869. $pr=explode('/e/',$selfpath);
  3870. $pr2=explode('/',$pr[1]);
  3871. $adminpath=$pr2[0];
  3872. if(empty($adminpath))
  3873. {
  3874. exit();
  3875. }
  3876. return $adminpath;
  3877. }
  3878. //特殊来源验证
  3879. function hCheckSpFromUrl(){
  3880. if(defined('EmpireCMSSpFromUrl'))
  3881. {
  3882. return '';
  3883. }
  3884. $spurl=',AddNews.php,ShowInfo.php,ShowWfInfo.php,EditCjNews.php,infoeditor,';
  3885. $r=explode(',',$spurl);
  3886. $count=count($r);
  3887. $fromurl=$_SERVER['HTTP_REFERER'];
  3888. for($i=1;$i<$count;$i++)
  3889. {
  3890. if(empty($r[$i]))
  3891. {
  3892. continue;
  3893. }
  3894. if(stristr($fromurl,$r[$i]))
  3895. {
  3896. printerror("FailHash","history.go(-1)");
  3897. }
  3898. }
  3899. }
  3900. //设定特殊来源
  3901. function hSetSpFromUrl(){
  3902. define('EmpireCMSSpFromUrl',TRUE);
  3903. }
  3904. //验证来源
  3905. function DoSafeCheckFromurl(){
  3906. global $ecms_config;
  3907. if($ecms_config['esafe']['ckfromurl']==0||defined('EmpireCMSNFPage'))//不启用
  3908. {
  3909. return '';
  3910. }
  3911. $fromurl=$_SERVER['HTTP_REFERER'];
  3912. if(!$fromurl)
  3913. {
  3914. return '';
  3915. }
  3916. $domain=eReturnDomain();
  3917. if($ecms_config['esafe']['ckfromurl']==1)//全部启用
  3918. {
  3919. if(!stristr($fromurl,$domain))
  3920. {
  3921. echo"";
  3922. exit();
  3923. }
  3924. }
  3925. elseif($ecms_config['esafe']['ckfromurl']==2)//后台启用
  3926. {
  3927. if(defined('EmpireCMSAdmin')&&!stristr($fromurl,$domain.'/'))
  3928. {
  3929. echo"";
  3930. exit();
  3931. }
  3932. }
  3933. elseif($ecms_config['esafe']['ckfromurl']==3)//前台启用
  3934. {
  3935. if(!defined('EmpireCMSAdmin')&&!stristr($fromurl,$domain))
  3936. {
  3937. echo"";
  3938. exit();
  3939. }
  3940. }
  3941. elseif($ecms_config['esafe']['ckfromurl']==4)//全部启用(严格)
  3942. {
  3943. if(!stristr($fromurl,$domain))
  3944. {
  3945. echo"";
  3946. exit();
  3947. }
  3948. if(defined('EmpireCMSAdmin'))
  3949. {
  3950. $adminpath=eGetSelfAdminPath();
  3951. if(!stristr($fromurl,'/e/'.$adminpath.'/'))
  3952. {
  3953. echo"";
  3954. exit();
  3955. }
  3956. }
  3957. }
  3958. elseif($ecms_config['esafe']['ckfromurl']==5)//后台启用(严格)
  3959. {
  3960. if(defined('EmpireCMSAdmin'))
  3961. {
  3962. if(!stristr($fromurl,$domain.'/'))
  3963. {
  3964. echo"";
  3965. exit();
  3966. }
  3967. $adminpath=eGetSelfAdminPath();
  3968. if(!stristr($fromurl,'/e/'.$adminpath.'/'))
  3969. {
  3970. echo"";
  3971. exit();
  3972. }
  3973. }
  3974. }
  3975. elseif($ecms_config['esafe']['ckfromurl']==6)//前台启用(严格)
  3976. {
  3977. if(!defined('EmpireCMSAdmin')&&!stristr($fromurl,$domain))
  3978. {
  3979. echo"";
  3980. exit();
  3981. }
  3982. }
  3983. }
  3984. //验证agent信息
  3985. function EcmsCheckUserAgent($ckstr){
  3986. if(empty($ckstr))
  3987. {
  3988. return '';
  3989. }
  3990. $userinfo=$_SERVER['HTTP_USER_AGENT'];
  3991. $cr=explode('||',$ckstr);
  3992. $count=count($cr);
  3993. for($i=0;$i<$count;$i++)
  3994. {
  3995. if(empty($cr[$i]))
  3996. {
  3997. continue;
  3998. }
  3999. if(!strstr($userinfo,$cr[$i]))
  4000. {
  4001. //echo'Userinfo Error';
  4002. exit();
  4003. }
  4004. }
  4005. }
  4006. //验证IP
  4007. function eCheckAccessIp($ecms=0){
  4008. global $public_r;
  4009. $userip=egetip();
  4010. if($ecms)//后台
  4011. {
  4012. //允许IP
  4013. if($public_r['hopenip'])
  4014. {
  4015. $close=1;
  4016. foreach(explode("\n",$public_r['hopenip']) as $ctrlip)
  4017. {
  4018. if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
  4019. {
  4020. $close=0;
  4021. break;
  4022. }
  4023. }
  4024. if($close==1)
  4025. {
  4026. echo"Ip<font color='#cccccc'>(".$userip.")</font> be prohibited.";
  4027. exit();
  4028. }
  4029. }
  4030. }
  4031. else
  4032. {
  4033. //允许IP
  4034. if($public_r['openip'])
  4035. {
  4036. $close=1;
  4037. foreach(explode("\n",$public_r['openip']) as $ctrlip)
  4038. {
  4039. if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
  4040. {
  4041. $close=0;
  4042. break;
  4043. }
  4044. }
  4045. if($close==1)
  4046. {
  4047. echo"Ip<font color='#cccccc'>(".$userip.")</font> be prohibited.";
  4048. exit();
  4049. }
  4050. }
  4051. //禁止IP
  4052. if($public_r['closeip'])
  4053. {
  4054. foreach(explode("\n",$public_r['closeip']) as $ctrlip)
  4055. {
  4056. if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
  4057. {
  4058. echo"Ip<font color='#cccccc'>(".$userip.")</font> be prohibited.";
  4059. exit();
  4060. }
  4061. }
  4062. }
  4063. }
  4064. }
  4065. //验证提交IP
  4066. function eCheckAccessDoIp($doing){
  4067. global $public_r,$empire,$dbtbpre;
  4068. $pr=$empire->fetch1("select opendoip,closedoip,doiptype from {$dbtbpre}enewspublic limit 1");
  4069. if(!strstr($pr['doiptype'],','.$doing.','))
  4070. {
  4071. return '';
  4072. }
  4073. $userip=egetip();
  4074. //允许IP
  4075. if($pr['opendoip'])
  4076. {
  4077. $close=1;
  4078. foreach(explode("\n",$pr['opendoip']) as $ctrlip)
  4079. {
  4080. if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
  4081. {
  4082. $close=0;
  4083. break;
  4084. }
  4085. }
  4086. if($close==1)
  4087. {
  4088. printerror('NotCanPostIp','history.go(-1)',1);
  4089. }
  4090. }
  4091. //禁止IP
  4092. if($pr['closedoip'])
  4093. {
  4094. foreach(explode("\n",$pr['closedoip']) as $ctrlip)
  4095. {
  4096. if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
  4097. {
  4098. printerror('NotCanPostIp','history.go(-1)',1);
  4099. }
  4100. }
  4101. }
  4102. }
  4103. //验证是否关闭相关模块
  4104. function eCheckCloseMods($mod){
  4105. global $public_r;
  4106. if(strstr($public_r['closemods'],','.$mod.','))
  4107. {
  4108. echo $mod.' is close';
  4109. exit();
  4110. }
  4111. }
  4112. //验证操作时间
  4113. function eCheckTimeCloseDo($ecms){
  4114. global $public_r;
  4115. if(stristr($public_r['timeclosedo'],','.$ecms.','))
  4116. {
  4117. $h=date('G');
  4118. if(strstr($public_r['timeclose'],','.$h.','))
  4119. {
  4120. printerror('ThisTimeCloseDo','history.go(-1)',1);
  4121. }
  4122. }
  4123. }
  4124. //验证外部登录是否开启
  4125. function eCheckCloseMemberConnect(){
  4126. global $public_r;
  4127. if(!$public_r['memberconnectnum'])
  4128. {
  4129. printerror('NotOpenMemberConnect','history.go(-1)',1);
  4130. }
  4131. }
  4132. //过滤
  4133. function ClearNewsBadCode($text){
  4134. $text=preg_replace(array('!<script!i','!</script>!i','!<link!i','!<iframe!i','!</iframe>!i','!<meta!i','!<body!i','!<style!i','!</style>!i','! onerror!i','!<marquee!i','!</marquee>!i','/<!--/','! onload!i','! onmouse!i','!<frame!i','!<frameset!i'),array('&lt;script','&lt;/script&gt;','&lt;link','&lt;iframe','&lt;/iframe&gt;','&lt;meta','&lt;body','&lt;style','&lt;/style&gt;',' one rror','&lt;marquee','&lt;/marquee&gt;','<!---ecms ',' onl oad',' onm ouse','&lt;frame','&lt;frameset'),$text);
  4135. return $text;
  4136. }
  4137. //验证包含字符
  4138. function toCheckCloseWord($word,$closestr,$mess){
  4139. if($closestr&&$closestr!='|')
  4140. {
  4141. $checkr=explode('|',$closestr);
  4142. $ckcount=count($checkr);
  4143. for($i=0;$i<$ckcount;$i++)
  4144. {
  4145. if($checkr[$i])
  4146. {
  4147. if(stristr($checkr[$i],'##'))//多字
  4148. {
  4149. $morer=explode('##',$checkr[$i]);
  4150. if(stristr($word,$morer[0])&&stristr($word,$morer[1]))
  4151. {
  4152. printerror($mess,"history.go(-1)",1);
  4153. }
  4154. }
  4155. else
  4156. {
  4157. if(stristr($word,$checkr[$i]))
  4158. {
  4159. printerror($mess,"history.go(-1)",1);
  4160. }
  4161. }
  4162. }
  4163. }
  4164. }
  4165. }
  4166. //替换评论表情
  4167. function RepPltextFace($text){
  4168. global $public_r;
  4169. if(empty($public_r['plface'])||$public_r['plface']=='||')
  4170. {
  4171. return $text;
  4172. }
  4173. $facer=explode('||',$public_r['plface']);
  4174. $count=count($facer);
  4175. for($i=1;$i<$count-1;$i++)
  4176. {
  4177. $r=explode('##',$facer[$i]);
  4178. $text=str_replace($r[0],"<img src='".$public_r['newsurl']."e/data/face/".$r[1]."' border=0>",$text);
  4179. }
  4180. return $text;
  4181. }
  4182. //替换空格
  4183. function RepFieldtextNbsp($text){
  4184. return str_replace(array("\t",' ',' '),array('&nbsp; &nbsp; &nbsp; &nbsp; ','&nbsp; &nbsp;','&nbsp;&nbsp;'),$text);
  4185. }
  4186. //保留扩展名验证
  4187. function CheckSaveTranFiletype($filetype){
  4188. $savetranfiletype=',.php,.php3,.php4,.php5,.php6,.asp,.aspx,.jsp,.cgi,.phtml,.asa,.asax,.fcgi,.pl,.ascx,.ashx,.cer,.cdx,.pht,.shtml,.shtm,.stm,';
  4189. if(stristr($savetranfiletype,','.$filetype.','))
  4190. {
  4191. return true;
  4192. }
  4193. return false;
  4194. }
  4195. //设置验证码
  4196. function ecmsSetShowKey($varname,$val,$ecms=0,$isadmin=0){
  4197. global $public_r;
  4198. $pubkeyrnd=$isadmin==1?$public_r['hkeyrnd']:$public_r['keyrnd'];
  4199. $time=time();
  4200. $checkpass=md5('d!i#g?o-d-'.md5(md5($varname.'E.C#M!S^e-'.$val).'-E?m!P.i#R-e'.$time).$pubkeyrnd.'P#H!o,m^e-e');
  4201. $key=$time.','.$checkpass.',EmpireCMS';
  4202. esetcookie($varname,$key,0,$ecms);
  4203. }
  4204. //检查验证码
  4205. function ecmsCheckShowKey($varname,$postval,$dopr,$ecms=0,$isadmin=0){
  4206. global $public_r;
  4207. $postval=trim($postval);
  4208. if($isadmin==1)
  4209. {
  4210. $pubkeytime=$public_r['hkeytime'];
  4211. $pubkeyrnd=$public_r['hkeyrnd'];
  4212. }
  4213. else
  4214. {
  4215. $pubkeytime=$public_r['keytime'];
  4216. $pubkeyrnd=$public_r['keyrnd'];
  4217. }
  4218. $r=explode(',',getcvar($varname,$ecms));
  4219. $cktime=(int)$r[0];
  4220. $pass=$r[1];
  4221. $val=$r[2];
  4222. $time=time();
  4223. if($cktime>$time||$time-$cktime>$pubkeytime)
  4224. {
  4225. printerror('OutKeytime','',$dopr);
  4226. }
  4227. if(empty($postval))
  4228. {
  4229. printerror('FailKey','',$dopr);
  4230. }
  4231. $checkpass=md5('d!i#g?o-d-'.md5(md5($varname.'E.C#M!S^e-'.$postval).'-E?m!P.i#R-e'.$cktime).$pubkeyrnd.'P#H!o,m^e-e');
  4232. if('dg'.$checkpass<>'dg'.$pass)
  4233. {
  4234. printerror('FailKey','',$dopr);
  4235. }
  4236. }
  4237. //清空验证码
  4238. function ecmsEmptyShowKey($varname,$ecms=0,$isadmin=0){
  4239. esetcookie($varname,'',0,$ecms);
  4240. }
  4241. //设置提交码
  4242. function DoSetActionPass($userid,$username,$rnd,$other,$ecms=0){
  4243. global $ecms_config;
  4244. $varname='actionepass';
  4245. $date=date("Y-m-d-H");
  4246. $pass=md5(md5($rnd.'-'.$userid.'-'.$date.'-'.$other).$ecms_config['cks']['ckrnd'].$username);
  4247. esetcookie($varname,$pass,0,$ecms);
  4248. }
  4249. //清除提交码
  4250. function DoEmptyActionPass($ecms=0){
  4251. $varname='actionepass';
  4252. esetcookie($varname,'',0,$ecms);
  4253. }
  4254. //检测提交码
  4255. function DoCheckActionPass($userid,$username,$rnd,$other,$ecms=0){
  4256. global $ecms_config;
  4257. $varname='actionepass';
  4258. $date=date("Y-m-d-H");
  4259. $checkpass=md5(md5($rnd.'-'.$userid.'-'.$date.'-'.$other).$ecms_config['cks']['ckrnd'].$username);
  4260. $pass=getcvar($varname,$ecms);
  4261. if('dg'.$checkpass<>'dg'.$pass)
  4262. {
  4263. exit();
  4264. }
  4265. }
  4266. //返回字段标识
  4267. function toReturnFname($tbname,$f){
  4268. global $empire,$dbtbpre;
  4269. $r=$empire->fetch1("select fname from {$dbtbpre}enewsf where f='$f' and tbname='$tbname' limit 1");
  4270. return $r[fname];
  4271. }
  4272. //返回拼音
  4273. function ReturnPinyinFun($hz){
  4274. global $ecms_config;
  4275. include_once(ECMS_PATH.'e/class/epinyin.php');
  4276. //编码
  4277. if($ecms_config['sets']['pagechar']!='gb2312')
  4278. {
  4279. include_once(ECMS_PATH.'e/class/doiconv.php');
  4280. $iconv=new Chinese('');
  4281. $char=$ecms_config['sets']['pagechar']=='big5'?'BIG5':'UTF8';
  4282. $targetchar='GB2312';
  4283. $hz=$iconv->Convert($char,$targetchar,$hz);
  4284. }
  4285. return c($hz);
  4286. }
  4287. //取得字母
  4288. function GetInfoZm($hz){
  4289. if(!trim($hz))
  4290. {
  4291. return '';
  4292. }
  4293. $py=ReturnPinyinFun($hz);
  4294. $zm=substr($py,0,1);
  4295. return strtoupper($zm);
  4296. }
  4297. //返回加密后的IP
  4298. function ToReturnXhIp($ip,$n=1){
  4299. $newip='';
  4300. $ipr=explode(".",$ip);
  4301. $ipnum=count($ipr);
  4302. for($i=0;$i<$ipnum;$i++)
  4303. {
  4304. if($i!=0)
  4305. {$d=".";}
  4306. if($i==$ipnum-1)
  4307. {
  4308. $ipr[$i]="*";
  4309. }
  4310. if($n==2)
  4311. {
  4312. if($i==$ipnum-2)
  4313. {
  4314. $ipr[$i]="*";
  4315. }
  4316. }
  4317. $newip.=$d.$ipr[$i];
  4318. }
  4319. return $newip;
  4320. }
  4321. //验证是否使用https
  4322. function eCheckUseHttps(){
  4323. if($_SERVER['HTTPS']&&strtolower($_SERVER['HTTPS'])!='off')
  4324. {
  4325. return 1;
  4326. }
  4327. else
  4328. {
  4329. return 0;
  4330. }
  4331. }
  4332. //返回http类型
  4333. function eReturnHttpType(){
  4334. global $public_r;
  4335. if($public_r['httptype'])
  4336. {
  4337. if($public_r['httptype']==1)
  4338. {
  4339. return 'http://';
  4340. }
  4341. elseif($public_r['httptype']==2)
  4342. {
  4343. return 'https://';
  4344. }
  4345. elseif($public_r['httptype']==3)
  4346. {
  4347. if(defined('EmpireCMSAdmin'))
  4348. {
  4349. return 'https://';
  4350. }
  4351. else
  4352. {
  4353. return 'http://';
  4354. }
  4355. }
  4356. elseif($public_r['httptype']==4)
  4357. {
  4358. if(defined('EmpireCMSAdmin'))
  4359. {
  4360. return 'http://';
  4361. }
  4362. else
  4363. {
  4364. return 'https://';
  4365. }
  4366. }
  4367. }
  4368. return eCheckUseHttps()==1?'https://':'http://';
  4369. }
  4370. //返回当前域名2
  4371. function eReturnTrueDomain(){
  4372. $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
  4373. if(empty($domain))
  4374. {
  4375. return '';
  4376. }
  4377. return $domain;
  4378. }
  4379. //返回当前域名
  4380. function eReturnDomain(){
  4381. $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
  4382. if(empty($domain))
  4383. {
  4384. return '';
  4385. }
  4386. return eReturnHttpType().$domain;
  4387. }
  4388. //返回域名网站地址
  4389. function eReturnDomainSiteUrl(){
  4390. global $public_r;
  4391. $PayReturnUrlQz=$public_r['newsurl'];
  4392. if(!stristr($public_r['newsurl'],'://'))
  4393. {
  4394. $PayReturnUrlQz=eReturnDomain().$public_r['newsurl'];
  4395. }
  4396. return $PayReturnUrlQz;
  4397. }
  4398. //返回当前地址
  4399. function eReturnSelfPage($ecms=0){
  4400. if(empty($ecms))
  4401. {
  4402. $page=$_SERVER['PHP_SELF'];
  4403. }
  4404. else
  4405. {
  4406. $page=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
  4407. }
  4408. $page=str_replace('&amp;','&',RepPostStr($page,1));
  4409. return $page;
  4410. }
  4411. //验证当前会员权限
  4412. function sys_CheckMemberGroup($groupid){
  4413. if(!defined('InEmpireCMSUser'))
  4414. {
  4415. include_once ECMS_PATH.'e/member/class/user.php';
  4416. }
  4417. $r=qCheckLoginAuthstr();
  4418. if(!$r['islogin'])
  4419. {
  4420. return 0;
  4421. }
  4422. if(!strstr(','.$groupid.',',','.$r['groupid'].','))
  4423. {
  4424. return -1;
  4425. }
  4426. return 1;
  4427. }
  4428. //EMAIL地址检查
  4429. function chemail($email){
  4430. $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
  4431. if (strpos($email, '@') !== false && strpos($email, '.') !== false)
  4432. {
  4433. if (preg_match($chars, $email))
  4434. {
  4435. return true;
  4436. }
  4437. else
  4438. {
  4439. return false;
  4440. }
  4441. }
  4442. else
  4443. {
  4444. return false;
  4445. }
  4446. }
  4447. //去除adds
  4448. function ClearAddsData($data){
  4449. if(MAGIC_QUOTES_GPC)
  4450. {
  4451. $data=stripSlashes($data);
  4452. }
  4453. return $data;
  4454. }
  4455. //增加adds
  4456. function AddAddsData($data){
  4457. if(!MAGIC_QUOTES_GPC)
  4458. {
  4459. $data=addslashes($data);
  4460. }
  4461. return $data;
  4462. }
  4463. //原字符adds
  4464. function StripAddsData($data){
  4465. $data=addslashes(stripSlashes($data));
  4466. return $data;
  4467. }
  4468. //反增加adds
  4469. function fAddAddsData($data){
  4470. if(MAGIC_QUOTES_GPC)
  4471. {
  4472. $data=addslashes($data);
  4473. }
  4474. return $data;
  4475. }
  4476. //------- 存文本 -------
  4477. //读取文本字段内容
  4478. function GetTxtFieldText($pagetexturl){
  4479. global $ecms_config;
  4480. if(empty($pagetexturl))
  4481. {
  4482. return '';
  4483. }
  4484. $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
  4485. $text=ReadFiletext($file);
  4486. $text=substr($text,12);//去除exit
  4487. return $text;
  4488. }
  4489. //取得文本地址
  4490. function GetTxtFieldTextUrl($pagetexturl){
  4491. global $ecms_config;
  4492. $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
  4493. return $file;
  4494. }
  4495. //修改文本字段内容
  4496. function EditTxtFieldText($pagetexturl,$pagetext){
  4497. global $ecms_config;
  4498. $pagetext="<? exit();?>".$pagetext;
  4499. $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
  4500. WriteFiletext_n($file,$pagetext);
  4501. }
  4502. //删除文本字段内容
  4503. function DelTxtFieldText($pagetexturl){
  4504. global $ecms_config;
  4505. if(empty($pagetexturl))
  4506. {
  4507. return '';
  4508. }
  4509. $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
  4510. DelFiletext($file);
  4511. }
  4512. //取得随机数
  4513. function GetFileMd5(){
  4514. $p=md5(uniqid(microtime()).EcmsRandInt());
  4515. return $p;
  4516. }
  4517. //建立存放目录
  4518. function MkDirTxtFile($date,$file){
  4519. global $ecms_config;
  4520. $r=explode("/",$date);
  4521. $path=$ecms_config['sets']['txtpath'].$r[0];
  4522. DoMkdir($path);
  4523. $path=$ecms_config['sets']['txtpath'].$date;
  4524. DoMkdir($path);
  4525. $returnpath=$date."/".$file;
  4526. return $returnpath;
  4527. }
  4528. //替换公共标记
  4529. function ReplaceSvars($temp,$url,$classid,$title,$key,$des,$add,$repvar=1){
  4530. global $public_r,$class_r,$class_zr;
  4531. if($repvar==1)//全局模板变量
  4532. {
  4533. $temp=ReplaceTempvar($temp);
  4534. }
  4535. $temp=str_replace('[!--class.menu--]',$public_r['classnavs'],$temp);//栏目导航
  4536. $temp=str_replace('[!--newsnav--]',$url,$temp);//位置导航
  4537. $temp=str_replace('[!--pagetitle--]',$title,$temp);
  4538. $temp=str_replace('[!--pagekey--]',$key,$temp);
  4539. $temp=str_replace('[!--pagedes--]',$des,$temp);
  4540. $temp=str_replace('[!--self.classid--]',0,$temp);
  4541. $temp=str_replace('[!--news.url--]',$public_r['newsurl'],$temp);
  4542. return $temp;
  4543. }
  4544. //返回数组组合字符
  4545. function eReturnRDataStr($r){
  4546. $count=count($r);
  4547. if(!$count)
  4548. {
  4549. return '';
  4550. }
  4551. $str=',';
  4552. for($i=0;$i<$count;$i++)
  4553. {
  4554. $str.=$r[$i].',';
  4555. }
  4556. return $str;
  4557. }
  4558. //------- firewall -------
  4559. //提示
  4560. function FWShowMsg($msg){
  4561. //echo $msg;
  4562. exit();
  4563. }
  4564. //防火墙
  4565. function DoEmpireCMSFireWall(){
  4566. global $ecms_config;
  4567. if(!empty($ecms_config['fw']['adminloginurl']))
  4568. {
  4569. $usehost=FWeReturnDomain();
  4570. if($usehost!=$ecms_config['fw']['adminloginurl'])
  4571. {
  4572. FWShowMsg('Login Url');
  4573. }
  4574. }
  4575. if($ecms_config['fw']['adminhour']!=='')
  4576. {
  4577. $h=date('G');
  4578. if(!strstr(','.$ecms_config['fw']['adminhour'].',',','.$h.','))
  4579. {
  4580. FWShowMsg('Admin Hour');
  4581. }
  4582. }
  4583. if($ecms_config['fw']['adminweek']!=='')
  4584. {
  4585. $w=date('w');
  4586. if(!strstr(','.$ecms_config['fw']['adminweek'].',',','.$w.','))
  4587. {
  4588. FWShowMsg('Admin Week');
  4589. }
  4590. }
  4591. if(!defined('EmpireCMSAPage')&&$ecms_config['fw']['adminckpassvar']&&$ecms_config['fw']['adminckpassval'])
  4592. {
  4593. FWCheckPassword();
  4594. }
  4595. }
  4596. //返回当前域名
  4597. function FWeReturnDomain(){
  4598. $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
  4599. if(empty($domain))
  4600. {
  4601. return '';
  4602. }
  4603. return eReturnHttpType().$domain;
  4604. }
  4605. //检查敏感字符
  4606. function FWClearGetText($str){
  4607. global $ecms_config;
  4608. if(empty($ecms_config['fw']['eopen']))
  4609. {
  4610. return '';
  4611. }
  4612. if(empty($ecms_config['fw']['cleargettext']))
  4613. {
  4614. return '';
  4615. }
  4616. $r=explode(',',$ecms_config['fw']['cleargettext']);
  4617. $count=count($r);
  4618. for($i=0;$i<$count;$i++)
  4619. {
  4620. if(stristr($r[$i],'##'))//多字
  4621. {
  4622. $morer=explode('##',$r[$i]);
  4623. if(stristr($str,$morer[0])&&stristr($str,$morer[1]))
  4624. {
  4625. FWShowMsg('Post String');
  4626. }
  4627. }
  4628. else
  4629. {
  4630. if(stristr($str,$r[$i]))
  4631. {
  4632. FWShowMsg('Post String');
  4633. }
  4634. }
  4635. }
  4636. }
  4637. //后台防火墙密码
  4638. function FWSetPassword(){
  4639. global $ecms_config;
  4640. if(!$ecms_config['fw']['eopen']||!$ecms_config['fw']['adminckpassvar']||!$ecms_config['fw']['adminckpassval'])
  4641. {
  4642. return '';
  4643. }
  4644. $ip=$ecms_config['esafe']['ckhloginip']==0?'127.0.0.1':egetip();
  4645. $ecmsckpass=md5(md5($ecms_config['fw']['adminckpassval'].'-empirecms-'.$ecms_config['fw']['epass']).'-'.$ip.'-'.$ecms_config['fw']['adminckpassval'].'-phome.net-');
  4646. esetcookie($ecms_config['fw']['adminckpassvar'],$ecmsckpass,0,1);
  4647. }
  4648. function FWCheckPassword(){
  4649. global $ecms_config;
  4650. if(!$ecms_config['fw']['eopen']||!$ecms_config['fw']['adminckpassvar']||!$ecms_config['fw']['adminckpassval'])
  4651. {
  4652. return '';
  4653. }
  4654. $ip=$ecms_config['esafe']['ckhloginip']==0?'127.0.0.1':egetip();
  4655. $ecmsckpass=md5(md5($ecms_config['fw']['adminckpassval'].'-empirecms-'.$ecms_config['fw']['epass']).'-'.$ip.'-'.$ecms_config['fw']['adminckpassval'].'-phome.net-');
  4656. if('dg'.$ecmsckpass<>'dg'.getcvar($ecms_config['fw']['adminckpassvar'],1))
  4657. {
  4658. FWShowMsg('Password');
  4659. }
  4660. }
  4661. function FWEmptyPassword(){
  4662. global $ecms_config;
  4663. esetcookie($ecms_config['fw']['adminckpassvar'],'',0,1);
  4664. }
  4665. //--------------- 缓存 ---------------
  4666. //取最后一两级目录
  4667. function Ecms_eReturnShowMkdir($path){
  4668. global $ecms_config;
  4669. if(!$ecms_config['sets']['webdebug'])
  4670. {
  4671. return '';
  4672. }
  4673. if(!stristr($path,'/'))
  4674. {
  4675. return '';
  4676. }
  4677. $path=str_replace(eReturnTrueEcmsPath(),'/',$path);
  4678. $r=explode('/',$path);
  4679. $count=count($r);
  4680. if($count<2)
  4681. {
  4682. return '';
  4683. }
  4684. else
  4685. {
  4686. return '/'.$r[$count-1];
  4687. }
  4688. }
  4689. //建立目录(普通)
  4690. function Ecms_eMkdir($path){
  4691. if(!file_exists($path))
  4692. {
  4693. $mk=@mkdir($path,0777);
  4694. @chmod($path,0777);
  4695. if(empty($mk))
  4696. {
  4697. echo 'Create path fail: '.Ecms_eReturnShowMkdir($path);
  4698. exit();
  4699. }
  4700. }
  4701. return true;
  4702. }
  4703. //递级建立目录
  4704. function Ecms_eMoreMkdir($basepath,$path){
  4705. if(empty($path))
  4706. {
  4707. return '';
  4708. }
  4709. if(file_exists($basepath.$path))
  4710. {
  4711. return $path;
  4712. }
  4713. $returnpath='';
  4714. $r=explode('/',$path);
  4715. $count=count($r);
  4716. for($i=0;$i<$count;$i++)
  4717. {
  4718. if(empty($r[$i]))
  4719. {
  4720. continue;
  4721. }
  4722. if($returnpath)
  4723. {
  4724. $returnpath.='/'.$r[$i];
  4725. }
  4726. else
  4727. {
  4728. $returnpath.=$r[$i];
  4729. }
  4730. $createpath=$basepath.$returnpath;
  4731. $mk=Ecms_eMkdir($createpath);
  4732. }
  4733. return $returnpath;
  4734. }
  4735. //取得文件内容(可锁定)
  4736. function Ecms_ReadFiletext($filepath,$dolock=0){
  4737. $filepath=trim($filepath);
  4738. $htmlfp=@fopen($filepath,"r");
  4739. if($dolock==1)
  4740. {
  4741. flock($htmlfp,LOCK_SH);
  4742. }
  4743. $string=@fread($htmlfp,@filesize($filepath));
  4744. if($dolock==1)
  4745. {
  4746. flock($htmlfp,LOCK_UN);
  4747. }
  4748. @fclose($htmlfp);
  4749. return $string;
  4750. }
  4751. //写文件(可锁定)
  4752. function Ecms_WriteFiletext($filepath,$string,$dolock=0,$strip=0){
  4753. global $public_r;
  4754. if($strip==1)
  4755. {
  4756. $string=stripSlashes($string);
  4757. }
  4758. $fp=@fopen($filepath,"w");
  4759. if($dolock==1)
  4760. {
  4761. flock($fp,LOCK_EX);
  4762. }
  4763. @fputs($fp,$string);
  4764. if($dolock==1)
  4765. {
  4766. flock($fp,LOCK_UN);
  4767. }
  4768. @fclose($fp);
  4769. if(empty($public_r['filechmod']))
  4770. {
  4771. @chmod($filepath,0777);
  4772. }
  4773. }
  4774. //返回文件修改时间
  4775. function Ecms_GetFileEditTime($filepath){
  4776. return file_exists($filepath)?intval(filemtime($filepath)):0;
  4777. }
  4778. //ID返回动态缓存目录
  4779. function ePagenoGetPageCache($cpage){
  4780. $r=array();
  4781. if($cpage==1)//首页
  4782. {
  4783. $r['esyspath']='empirecms';
  4784. $r['cpath']='cindex';
  4785. }
  4786. elseif($cpage==2)//封面
  4787. {
  4788. $r['esyspath']='empirecms';
  4789. $r['cpath']='cpage';
  4790. }
  4791. elseif($cpage==3)//列表
  4792. {
  4793. $r['esyspath']='empirecms';
  4794. $r['cpath']='clist';
  4795. }
  4796. elseif($cpage==4)//内容
  4797. {
  4798. $r['esyspath']='empirecms';
  4799. $r['cpath']='ctext';
  4800. }
  4801. elseif($cpage==5)//标题分类
  4802. {
  4803. $r['esyspath']='empirecms';
  4804. $r['cpath']='cinfotype';
  4805. }
  4806. elseif($cpage==6)//TAGS
  4807. {
  4808. $r['esyspath']='empirecms';
  4809. $r['cpath']='ctags';
  4810. }
  4811. elseif($cpage==10000)//ALLECMS
  4812. {
  4813. $r['esyspath']='empirecms';
  4814. $r['cpath']='';
  4815. }
  4816. else
  4817. {
  4818. $r['esyspath']='';
  4819. $r['cpath']='no';
  4820. }
  4821. return $r;
  4822. }
  4823. //返回缓存文件名
  4824. function Ecms_eCacheReturnFile($cachetype,$ids,$datepath,$path='empirecms'){
  4825. global $ecms_config,$public_r;
  4826. $filer['basepath']=$ecms_config['sets']['ecmscachepath'].$path.'/';
  4827. $filer['cpath']=$datepath;
  4828. $filer['cfile']=md5($cachetype.'!-'.$ids.'-,'.$public_r['ctimernd'].'-!'.$path).$ecms_config['sets']['ecmscachefiletype'];
  4829. $filer['ctruefile']=$filer['basepath'].$filer['cpath'].'/'.$filer['cfile'];
  4830. return $filer;
  4831. }
  4832. //输出缓存
  4833. function Ecms_eCacheOut($cr,$usedo=0){
  4834. $cachetime=abs($cr['cachetime'])*60;
  4835. $filer=Ecms_eCacheReturnFile($cr['cachetype'],$cr['cacheids'],$cr['cachedatepath'],$cr['cachepath']);
  4836. $cachefile=$filer['ctruefile'];
  4837. $filetime=Ecms_GetFileEditTime($cachefile);
  4838. if(!$filetime)
  4839. {
  4840. return 0;
  4841. }
  4842. $time=time();
  4843. if($time-$filetime>$cachetime)
  4844. {
  4845. return 0;
  4846. }
  4847. $cr['cachelastedit']=(int)$cr['cachelastedit'];
  4848. if($cr['cachelastedit']&&$cr['cachelastedit']>$filetime)
  4849. {
  4850. return 0;
  4851. }
  4852. if($cr['cachelasttime']>=$filetime)
  4853. {
  4854. return 0;
  4855. }
  4856. echo Ecms_ReadFiletext($cachefile);
  4857. if($usedo==0)
  4858. {
  4859. db_close();
  4860. $empire=null;
  4861. exit();
  4862. }
  4863. elseif($usedo==1)
  4864. {
  4865. exit();
  4866. }
  4867. else
  4868. {}
  4869. return 1;
  4870. }
  4871. //写入缓存
  4872. function Ecms_eCacheIn($cr,$cachetext){
  4873. $filer=Ecms_eCacheReturnFile($cr['cachetype'],$cr['cacheids'],$cr['cachedatepath'],$cr['cachepath']);
  4874. $cachefile=$filer['ctruefile'];
  4875. Ecms_eMoreMkdir($filer['basepath'],$filer['cpath']);
  4876. Ecms_WriteFiletext($cachefile,$cachetext,1);
  4877. echo $cachetext;
  4878. }
  4879. //验证是否启用缓存
  4880. function Ecms_eCacheCheckOpen($cachetime){
  4881. global $ecms_config,$public_r,$ecms_tofunr;
  4882. if(empty($public_r['ctimeopen']))
  4883. {
  4884. return 0;
  4885. }
  4886. if($cachetime>0)
  4887. {
  4888. $open=1;
  4889. }
  4890. elseif($cachetime<0)
  4891. {
  4892. $open=1;
  4893. $userid=(int)getcvar('mluserid');
  4894. if($userid)
  4895. {
  4896. $open=0;
  4897. }
  4898. }
  4899. else
  4900. {
  4901. $open=0;
  4902. }
  4903. if($public_r['ctimegids'])
  4904. {
  4905. $groupid=(int)getcvar('mlgroupid');
  4906. if($groupid&&strstr(','.$public_r['ctimegids'].',',','.$groupid.','))
  4907. {
  4908. $open=0;
  4909. }
  4910. }
  4911. if($public_r['ctimecids']&&$ecms_tofunr['cacheselfcid'])
  4912. {
  4913. $selfcid=(int)$ecms_tofunr['cacheselfcid'];
  4914. if($selfcid&&strstr(','.$public_r['ctimecids'].',',','.$selfcid.','))
  4915. {
  4916. $open=0;
  4917. }
  4918. }
  4919. return $open;
  4920. }
  4921. //设置更新缓存
  4922. function eDoUpCache($id,$tname,$ecms=0,$ck=0){
  4923. global $empire,$dbtbpre,$public_r;
  4924. if(empty($public_r['ctimeopen']))
  4925. {
  4926. return '';
  4927. }
  4928. $time=time();
  4929. $uptime=$time-2;
  4930. $addwhere='';
  4931. $addwhere_index=' where fclastindex<'.$uptime;
  4932. if($ck==1)
  4933. {
  4934. $addwhere=' and fclast<'.$uptime;
  4935. $addwhere_index=' where fclastindex<'.$uptime;
  4936. }
  4937. if($ecms==1)//栏目
  4938. {
  4939. if(!$id)
  4940. {
  4941. return '';
  4942. }
  4943. $empire->query("update {$dbtbpre}enewsclass set fclast='$time' where classid in (".$id.")".$addwhere);
  4944. }
  4945. elseif($ecms==2)//标题分类
  4946. {
  4947. if(!$id)
  4948. {
  4949. return '';
  4950. }
  4951. $empire->query("update {$dbtbpre}enewsinfotype set fclast='$time' where typeid in (".$id.")".$addwhere);
  4952. }
  4953. elseif($ecms==3)//内容页
  4954. {
  4955. if(!$id||!$tname)
  4956. {
  4957. return '';
  4958. }
  4959. $empire->query("update {$dbtbpre}ecms_".$tname." set lastdotime='$time' where id in (".$id.")");
  4960. }
  4961. elseif($ecms==4)//TAGS
  4962. {
  4963. if(!$id&&!$tname)
  4964. {
  4965. return '';
  4966. }
  4967. if($tname)
  4968. {
  4969. $tr=explode(',',$tname);
  4970. $tcount=count($tr);
  4971. $where='';
  4972. $or='';
  4973. for($ti=0;$ti<$tcount;$ti++)
  4974. {
  4975. $tr[$ti]=RepPostVar($tr[$ti]);
  4976. if(!$tr[$ti])
  4977. {
  4978. continue;
  4979. }
  4980. $where.=$or."tagname='".$tr[$ti]."'";
  4981. $or=' or ';
  4982. }
  4983. if(!$where)
  4984. {
  4985. return '';
  4986. }
  4987. }
  4988. else
  4989. {
  4990. $where="tagid in (".$id.")";
  4991. }
  4992. $empire->query("update {$dbtbpre}enewstags set fclast='$time' where ".$where.$addwhere);
  4993. }
  4994. else//首页
  4995. {
  4996. $empire->query("update {$dbtbpre}enewspublic_fc set fclastindex='$time'".$addwhere_index." limit 1");
  4997. }
  4998. }
  4999. //设置更新缓存
  5000. function eUpCacheInfo($ecms,$classid,$id,$pid,$ttid,$tagid,$tagname,$oldclassid=0,$oldttid=0,$ck=0){
  5001. global $empire,$dbtbpre,$public_r,$class_r;
  5002. if(empty($public_r['ctimeopen']))
  5003. {
  5004. return '';
  5005. }
  5006. $ctimeaddre=$ecms==1?$public_r['ctimeaddre']:$public_r['ctimeqaddre'];
  5007. if(!$ctimeaddre)
  5008. {
  5009. return '';
  5010. }
  5011. $classid=(int)$classid;
  5012. $id=(int)$id;
  5013. $pid=(int)$pid;
  5014. $ttid=(int)$ttid;
  5015. $oldclassid=(int)$oldclassid;
  5016. $oldttid=(int)$oldttid;
  5017. //首页
  5018. if($ctimeaddre==2||$ctimeaddre==4||$ctimeaddre==6||$ctimeaddre==7||$ctimeaddre==8)
  5019. {
  5020. eDoUpCache(0,'',0,$ck);
  5021. }
  5022. //栏目
  5023. if($ctimeaddre!=2)
  5024. {
  5025. if(!empty($classid))
  5026. {
  5027. $cids='';
  5028. if($ctimeaddre==1)//当前
  5029. {
  5030. $cids=$classid;
  5031. if($oldclassid&&$oldclassid!=$classid)
  5032. {
  5033. $cids.=','.$oldclassid;
  5034. }
  5035. }
  5036. else
  5037. {
  5038. $featherclass=$class_r[$classid]['featherclass'];
  5039. if($ctimeaddre>=5)
  5040. {
  5041. if(empty($featherclass))
  5042. {
  5043. $featherclass='|';
  5044. }
  5045. $featherclass.=$classid.'|';
  5046. if($oldclassid&&$oldclassid!=$classid)
  5047. {
  5048. $featherclass.=$oldclassid.'|';
  5049. }
  5050. }
  5051. $cids=eReturnInFcids($featherclass);
  5052. }
  5053. if(empty($cids))
  5054. {
  5055. return '';
  5056. }
  5057. eDoUpCache($cids,'',1,$ck);
  5058. }
  5059. }
  5060. //标题分类
  5061. if($ctimeaddre>=7)
  5062. {
  5063. if(!empty($ttid))
  5064. {
  5065. if($oldttid&&$oldttid!=$ttid)
  5066. {
  5067. $ttid.=','.$oldttid;
  5068. }
  5069. eDoUpCache($ttid,'',2,$ck);
  5070. }
  5071. }
  5072. //TAGS
  5073. if($ctimeaddre>=8)
  5074. {
  5075. eDoUpCache('',$tagname,4,$ck);
  5076. }
  5077. //信息
  5078. if($id||$pid)
  5079. {
  5080. $tbname=$class_r[$classid]['tbname'];
  5081. if(!empty($tbname))
  5082. {
  5083. $ids='';
  5084. $iddh='';
  5085. if($id)
  5086. {
  5087. $ids.=$id;
  5088. $iddh=',';
  5089. }
  5090. if($pid)
  5091. {
  5092. $ids.=$iddh.$pid;
  5093. $iddh=',';
  5094. }
  5095. eDoUpCache($ids,$tbname,3,$ck);
  5096. }
  5097. }
  5098. }
  5099. ?>