123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406 |
- <?php
- error_reporting(E_ALL ^ E_NOTICE);
- define('InEmpireCMS',TRUE);
- define('ECMS_PATH',substr(dirname(__FILE__),0,-7));
- define('MAGIC_QUOTES_GPC',function_exists('get_magic_quotes_gpc')&&get_magic_quotes_gpc());
- define('STR_IREPLACE',function_exists('str_ireplace'));
- define('ECMS_PNO',EcmsGetProgramNo());
- $ecms_config=array();
- $ecms_adminloginr=array();
- $ecms_hashur=array();
- $emoreport_r=array();
- $public_r=array();
- $public_diyr=array();
- $emod_pubr=array();
- $etable_r=array();
- $emod_r=array();
- $notcj_r=array();
- $fun_r=array();
- $message_r=array();
- $qmessage_r=array();
- $enews_r=array();
- $class_r=array();
- $class_zr=array();
- $class_tr=array();
- $eyh_r=array();
- $schalltb_r=array();
- $level_r=array();
- $aglevel_r=array();
- $iglevel_r=array();
- $r=array();
- $addr=array();
- $paddr=array();
- $search='';
- $start=0;
- $addgethtmlpath='';
- $string='';
- $notcjnum=0;
- $editor=0;
- $ecms_gr=array();
- $navinfor=array();
- $pagefunr=array();
- $navclassid='';
- $navnewsid='';
- $cjnewsurl='';
- $formattxt='';
- $link='';
- $linkrd='';
- $empire='';
- $dbtbpre='';
- $efileftp='';
- $efileftp_fr=array();
- $efileftp_dr=array();
- $doetran=0;
- $ecmsvar_mbr=array();
- $ecms_tofunr=array();
- $ecms_topager=array();
- $ecms_topagesetr=array();
- $ecms_toboxr=array();
- $add='';
- $ecms_config['sets']['selfmoreportid']=0;
- $ecms_config['sets']['mainportpath']='';
- $ecms_config['sets']['pagemustdt']=0;
- $emoreport_r[1]['ppath']='';
- require_once ECMS_PATH.'e/config/config.php';
- if(!defined('EmpireCMSConfig'))
- {
- exit();
- }
- if($ecms_config['sets']['webdebug']==0)
- {
- error_reporting(0);
- }
- //超时设置
- if(defined('EmpireCMSAdmin'))
- {
- if($public_r['php_adminouttime'])
- {
- @set_time_limit($public_r['php_adminouttime']);
- }
- }
- else
- {
- if($public_r['php_outtime'])
- {
- @set_time_limit($public_r['php_outtime']);
- }
- }
- //页面编码
- if($ecms_config['sets']['setpagechar']==1)
- {
- if($ecms_config['sets']['pagechar']=='gb2312'||$ecms_config['sets']['pagechar']=='big5'||$ecms_config['sets']['pagechar']=='utf-8')
- {
- @header('Content-Type: text/html; charset='.$ecms_config['sets']['pagechar']);
- }
- }
- //时区
- if(function_exists('date_default_timezone_set'))
- {
- @date_default_timezone_set($ecms_config['sets']['timezone']);
- }
- if($ecms_config['db']['usedb']=='mysqli')
- {
- include(ECMS_PATH.'e/class/db/db_mysqli.php');
- }
- else
- {
- include(ECMS_PATH.'e/class/db/db_mysql.php');
- }
- //禁止IP
- eCheckAccessIp(0);
- DoSafeCheckFromurl();
- if(defined('EmpireCMSAdmin'))
- {
- eCheckAccessIp(1);//禁止IP
- EcmsCheckUserAgent($ecms_config['esafe']['ckhuseragent']);
- //FireWall
- if(!empty($ecms_config['fw']['eopen']))
- {
- DoEmpireCMSFireWall();
- }
- if(!empty($ecms_config['esafe']['ckhsession']))
- {
- session_start();
- define('EmpireCMSDefSession',TRUE);
- }
- }
- else
- {
- if(!empty($public_r['closeqdt']))
- {
- echo $public_r['closeqdtmsg'];
- exit();
- }
- }
- if($ecms_config['sets']['selfmoreportid']>1)
- {
- EcmsDefMoreport($ecms_config['sets']['selfmoreportid']);
- }
- //--------------- 数据库 ---------------
- function db_connect(){
- global $ecms_config;
- $dblink=do_dbconnect($ecms_config['db']['dbserver'],$ecms_config['db']['dbport'],$ecms_config['db']['dbusername'],$ecms_config['db']['dbpassword'],$ecms_config['db']['dbname']);
- return $dblink;
- }
- function return_dblink($query){
- $dblink=$GLOBALS['link'];
- return $dblink;
- }
- //设置编码
- function DoSetDbChar($dbchar){
- global $link;
- if($dbchar&&$dbchar!='auto')
- {
- do_DoSetDbChar($dbchar,$link);
- }
- }
- function db_close(){
- global $link;
- do_dbclose($link);
- }
- //--------------- 公共 ---------------
- //设置COOKIE
- function esetcookie($var,$val,$life=0,$ecms=0){
- global $ecms_config;
- //secure属性
- $cksecure=$ecms_config['cks']['cksecure'];
- if(!empty($cksecure))
- {
- $secure=0;
- if($cksecure==2)//开启
- {
- $secure=1;
- }
- elseif($cksecure==3)//后台开启
- {
- if(defined('EmpireCMSAdmin'))
- {
- $secure=1;
- }
- }
- elseif($cksecure==4)//前台开启
- {
- if(!defined('EmpireCMSAdmin'))
- {
- $secure=1;
- }
- }
- else
- {}
- }
- else
- {
- $secure=eCheckUseHttps();
- }
- //httponly属性
- $ckhttponly=$ecms_config['cks']['ckhttponly'];
- $httponly=0;
- if(!empty($ckhttponly))
- {
- if($ckhttponly==1)//开启
- {
- $httponly=1;
- }
- elseif($ckhttponly==2)//后台开启
- {
- if(defined('EmpireCMSAdmin'))
- {
- $httponly=1;
- }
- }
- elseif($ckhttponly==3)//前台开启
- {
- if(!defined('EmpireCMSAdmin'))
- {
- $httponly=1;
- }
- }
- else
- {}
- }
- //设置
- $varpre=empty($ecms)?$ecms_config['cks']['ckvarpre']:$ecms_config['cks']['ckadminvarpre'];
- $ckpath=$ecms_config['cks']['ckpath'];
- if(PHP_VERSION<'5.2.0')
- {
- if($httponly)
- {
- $ckpath.='; HttpOnly';
- }
- return setcookie($varpre.$var,$val,$life,$ckpath,$ecms_config['cks']['ckdomain'],$secure);
- }
- else
- {
- return setcookie($varpre.$var,$val,$life,$ckpath,$ecms_config['cks']['ckdomain'],$secure,$httponly);
- }
- }
- //返回cookie
- function getcvar($var,$ecms=0){
- global $ecms_config;
- $tvar=empty($ecms)?$ecms_config['cks']['ckvarpre'].$var:$ecms_config['cks']['ckadminvarpre'].$var;
- return $_COOKIE[$tvar];
- }
- //错误提示
- function printerror($error="",$gotourl="",$ecms=0,$noautourl=0,$novar=0){
- global $empire,$editor,$public_r,$ecms_config;
- if($editor==1){$a="../";}
- elseif($editor==2){$a="../../";}
- elseif($editor==3){$a="../../../";}
- else{$a="";}
- if($ecms==1||$ecms==9)
- {
- $a=ECMS_PATH.'e/data/';
- }
- if(strstr($gotourl,"(")||empty($gotourl))
- {
- if(strstr($gotourl,"(-2"))
- {
- $gotourl_js="history.go(-2)";
- $gotourl="javascript:history.go(-2)";
- }
- else
- {
- $gotourl_js="history.go(-1)";
- $gotourl="javascript:history.go(-1)";
- }
- }
- else
- {$gotourl_js="self.location.href='$gotourl';";}
- if(empty($error))
- {$error="DbError";}
- if($ecms==9)//前台弹出对话框
- {
- @include $a.LoadLang("pub/q_message.php");
- $error=empty($novar)?$qmessage_r[$error]:$error;
- echo"<script>alert('".$error."');".$gotourl_js."</script>";
- db_close();
- $empire=null;
- exit();
- }
- elseif($ecms==8)//后台弹出对话框
- {
- @include $a.LoadLang("pub/message.php");
- $error=empty($novar)?$message_r[$error]:$error;
- echo"<script>alert('".$error."');".$gotourl_js."</script>";
- db_close();
- $empire=null;
- exit();
- }
- elseif($ecms==7)//前台弹出对话框并关闭窗口
- {
- @include $a.LoadLang("pub/q_message.php");
- $error=empty($novar)?$qmessage_r[$error]:$error;
- echo"<script>alert('".$error."');window.close();</script>";
- db_close();
- $empire=null;
- exit();
- }
- elseif($ecms==6)//后台弹出对话框并关闭窗口
- {
- @include $a.LoadLang("pub/message.php");
- $error=empty($novar)?$message_r[$error]:$error;
- echo"<script>alert('".$error."');window.close();</script>";
- db_close();
- $empire=null;
- exit();
- }
- elseif($ecms==0)
- {
- @include $a.LoadLang("pub/message.php");
- $error=empty($novar)?$message_r[$error]:$error;
- @include($a."message.php");
- }
- else
- {
- @include $a.LoadLang("pub/q_message.php");
- $error=empty($novar)?$qmessage_r[$error]:$error;
- @include($a."../message/index.php");
- }
- db_close();
- $empire=null;
- exit();
- }
- //错误提示2:直接文字
- function printerror2($error='',$gotourl='',$ecms=0,$noautourl=0){
- global $empire,$public_r;
- if(strstr($gotourl,"(")||empty($gotourl))
- {
- if(strstr($gotourl,"(-2"))
- {
- $gotourl_js="history.go(-2)";
- $gotourl="javascript:history.go(-2)";
- }
- else
- {
- $gotourl_js="history.go(-1)";
- $gotourl="javascript:history.go(-1)";
- }
- }
- else
- {$gotourl_js="self.location.href='$gotourl';";}
- if($ecms==9)//弹出对话框
- {
- echo"<script>alert('".$error."');".$gotourl_js."</script>";
- }
- elseif($ecms==7)//弹出对话框并关闭窗口
- {
- echo"<script>alert('".$error."');window.close();</script>";
- }
- else
- {
- @include(ECMS_PATH.'e/message/index.php');
- }
- db_close();
- exit();
- }
- //ajax错误提示
- function ajax_printerror($result='',$ajaxarea='ajaxarea',$error='',$ecms=0,$novar=0){
- global $empire,$editor,$public_r,$ecms_config;
- if($editor==1){$a="../";}
- elseif($editor==2){$a="../../";}
- elseif($editor==3){$a="../../../";}
- else{$a="";}
- if($ecms==1)
- {
- $a=ECMS_PATH.'e/data/';
- }
- if($ecms==0)
- {
- @include $a.LoadLang("pub/message.php");
- $error=empty($novar)?$message_r[$error]:$error;
- }
- else
- {
- @include $a.LoadLang("pub/q_message.php");
- $error=empty($novar)?$qmessage_r[$error]:$error;
- }
- if(empty($ajaxarea))
- {
- $ajaxarea='ajaxarea';
- }
- $ajaxarea=ehtmlspecialchars($ajaxarea,ENT_QUOTES);
- $string=$result.'|'.$ajaxarea.'|'.$error;
- echo $string;
- db_close();
- $empire=null;
- exit();
- }
- //直接转向
- function printerrortourl($gotourl='',$error='',$sec=0){
- global $empire,$editor,$public_r,$ecms_config;
- echo'<meta http-equiv="refresh" content="'.$sec.';url='.$gotourl.'">'.$error;
- db_close();
- $empire=null;
- exit();
- }
- //编码转换
- function DoIconvVal($code,$targetcode,$str,$inc=0){
- global $editor;
- if($editor==1){$a="../";}
- elseif($editor==2){$a="../../";}
- elseif($editor==3){$a="../../../";}
- else{$a="";}
- if($inc)
- {
- @include_once(ECMS_PATH."e/class/doiconv.php");
- }
- $iconv=new Chinese($a);
- $str=$iconv->Convert($code,$targetcode,$str);
- return $str;
- }
- //初始化访问端
- function EcmsDefMoreport($pid){
- global $public_r,$ecms_config,$emoreport_r;
- if(empty($public_r['ckhavemoreport']))
- {
- exit();
- }
- $pid=(int)$pid;
- if($pid<=1||!$emoreport_r[$pid]['pid'])
- {
- exit();
- }
- if($emoreport_r[$pid]['isclose'])
- {
- echo'This visit port is close!';
- exit();
- }
- //关闭后台
- if(defined('EmpireCMSAdmin')&&$emoreport_r[$pid]['openadmin'])
- {
- if($emoreport_r[$pid]['openadmin']==1)
- {
- if(defined('EmpireCMSAPage'))
- {
- //echo'Admin close!';
- exit();
- }
- }
- else
- {
- //echo'Admin close!';
- exit();
- }
- }
- $ecms_config['sets']['deftempid']=$emoreport_r[$pid]['tempgid'];
- $ecms_config['sets']['pagemustdt']=$emoreport_r[$pid]['mustdt'];
- $ecms_config['sets']['mainportpath']=$emoreport_r[1]['ppath'];
- if($emoreport_r[$pid]['closeadd'])
- {
- $public_r['addnews_ok']=$emoreport_r[$pid]['closeadd'];
- }
- }
- //重置为主访问端模板组ID
- function Moreport_ResetMainTempGid(){
- global $ecms_config,$public_r,$emoreport_r;
- $pid=(int)$ecms_config['sets']['selfmoreportid'];
- if($pid<=1||!$emoreport_r[$pid]['pid'])
- {
- return '';
- }
- $ecms_config['sets']['deftempid']=$public_r['deftempid']?$public_r['deftempid']:1;
- }
- //转向访问端目录
- function Moreport_eSetSelfPath($pid,$ecms=0){
- global $empire,$dbtbpre,$public_r,$ecms_config;
- $pid=(int)$pid;
- $defpr=array();
- $defpr['ppath']='';
- if($pid<=1)
- {
- $pid=1;
- }
- $pr=$empire->fetch1("select * from {$dbtbpre}enewsmoreport where pid='$pid'");
- if(!$pr['ppath']||!file_exists($pr['ppath'].'e/config/config.php'))
- {
- return $defpr;
- }
- define('ECMS_SELFPATH',$pr['ppath']);
- $ecms_config['sets']['deftempid']=$pr['tempgid'];
- //缓存模板
- if($ecms==1)
- {
- $tr=$empire->fetch1("select downsofttemp,onlinemovietemp,listpagetemp from ".GetTemptb("enewspubtemp")." limit 1");
- $public_r['downsofttemp']=addslashes(stripSlashes($tr['downsofttemp']));
- $public_r['onlinemovietemp']=addslashes(stripSlashes($tr['onlinemovietemp']));
- $public_r['listpagetemp']=addslashes(stripSlashes($tr['listpagetemp']));
- }
- return $pr;
- }
- //autodo
- function eAutodo_AddDo($dotype,$classid,$id,$tid,$userid,$pid,$fname='',$ckdoall=1){
- return '';
- }
- //返回是否强制动态页
- function Moreport_ReturnMustDt(){
- global $ecms_config;
- return $ecms_config['sets']['pagemustdt'];
- }
- //返回是否强制动态页(加状态)
- function Moreport_ReturnMustDtAnd(){
- global $ecms_config;
- if(defined('ECMS_SELFPATH')&&$ecms_config['sets']['pagemustdt'])
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- //返回强制动态页状态
- function Moreport_ReturnDtStatus($dt){
- global $ecms_config;
- if($ecms_config['sets']['pagemustdt'])
- {
- return 1;
- }
- else
- {
- return $dt;
- }
- }
- //返回内容页地址(访问端)
- function Moreport_ReturnTitleUrl($classid,$id){
- $rewriter=eReturnRewriteInfoUrl($classid,$id,1);
- $titleurl=$rewriter['pageurl'];
- return $titleurl;
- }
- //返回栏目页地址(访问端)
- function Moreport_ReturnClassUrl($classid){
- global $public_r,$class_r;
- if($class_r[$classid]['wburl'])
- {
- $classurl=$class_r[$classid]['wburl'];
- }
- else
- {
- $rewriter=eReturnRewriteClassUrl($classid,1);
- $classurl=$rewriter['pageurl'];
- }
- return $classurl;
- }
- //返回标题分类页地址(访问端)
- function Moreport_ReturnInfoTypeUrl($typeid){
- $rewriter=eReturnRewriteTitleTypeUrl($typeid,1);
- $url=$rewriter['pageurl'];
- return $url;
- }
- //返回首页地址(访问端)
- function Moreport_ReturnIndexUrl(){
- global $public_r;
- $file=$public_r['newsurl'].'index.php';
- return $file;
- }
- //根据编号返回模板表名
- function eTnoGetTempTbname($no){
- if($no==1)//标签模板
- {
- $temptb='enewsbqtemp';
- }
- elseif($no==2)//JS模板
- {
- $temptb='enewsjstemp';
- }
- elseif($no==3)//列表模板
- {
- $temptb='enewslisttemp';
- }
- elseif($no==4)//内容模板
- {
- $temptb='enewsnewstemp';
- }
- elseif($no==5)//公共模板
- {
- $temptb='enewspubtemp';
- }
- elseif($no==6)//搜索模板
- {
- $temptb='enewssearchtemp';
- }
- elseif($no==7)//模板变量
- {
- $temptb='enewstempvar';
- }
- elseif($no==8)//投票模板
- {
- $temptb='enewsvotetemp';
- }
- elseif($no==9)//封面模板
- {
- $temptb='enewsclasstemp';
- }
- elseif($no==10)//评论模板
- {
- $temptb='enewspltemp';
- }
- elseif($no==11)//打印模板
- {
- $temptb='enewsprinttemp';
- }
- elseif($no==12)//自定义页面模板
- {
- $temptb='enewspagetemp';
- }
- else
- {
- $temptb='';
- }
- return $temptb;
- }
- //模板表转换
- function GetTemptb($temptb){
- global $public_r,$ecms_config,$dbtbpre;
- if(!empty($ecms_config['sets']['deftempid']))
- {
- $tempid=$ecms_config['sets']['deftempid'];
- }
- else
- {
- $tempid=$public_r['deftempid'];
- }
- if(!empty($tempid)&&$tempid!=1)
- {
- $en="_".$tempid;
- }
- return $dbtbpre.$temptb.$en;
- }
- //返回操作模板表
- function GetDoTemptb($temptb,$gid){
- global $dbtbpre;
- if(!empty($gid)&&$gid!=1)
- {
- $en="_".$gid;
- }
- return $dbtbpre.$temptb.$en;
- }
- //返回当前使用模板组ID
- function GetDoTempGid(){
- global $ecms_config,$public_r;
- if($ecms_config['sets']['deftempid'])
- {
- $gid=$ecms_config['sets']['deftempid'];
- }
- elseif($public_r['deftempid'])
- {
- $gid=$public_r['deftempid'];
- }
- else
- {
- $gid=1;
- }
- return $gid;
- }
- //导入语言包
- function LoadLang($file){
- global $ecms_config;
- return "../data/language/".$ecms_config['sets']['elang']."/".$file;
- }
- //取得IP
- function egetip(){
- global $ecms_config;
- if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown'))
- {
- $ip=getenv('HTTP_CLIENT_IP');
- }
- elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown'))
- {
- $ip=getenv('HTTP_X_FORWARDED_FOR');
- }
- elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown'))
- {
- $ip=getenv('REMOTE_ADDR');
- }
- elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown'))
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- if($ecms_config['sets']['getiptype']>0)
- {
- $ip=egetipadd();
- }
- $ip=RepPostVar(preg_replace("/^([\d\.]+).*/","\\1",$ip));
- return $ip;
- }
- //取得IP附加
- function egetipadd(){
- global $ecms_config;
- if($ecms_config['sets']['getiptype']==2)
- {
- $ip=getenv('HTTP_X_FORWARDED_FOR');
- }
- elseif($ecms_config['sets']['getiptype']==3)
- {
- $ip=getenv('HTTP_CLIENT_IP');
- }
- else
- {
- $ip=getenv('REMOTE_ADDR');
- }
- return $ip;
- }
- //取得端口
- function egetipport(){
- $ipport=(int)$_SERVER['REMOTE_PORT'];
- return $ipport;
- }
- //检查地址
- function ecms_eCheckNotUrl($str){
- if(stristr($str,'/')||stristr($str,':')||stristr($str,"\\")||stristr($str,'&')||stristr($str,'?')||stristr($str,'#')||stristr($str,'@')||stristr($str,'"')||stristr($str,"'")||stristr($str,'%'))
- {
- exit();
- }
- return $str;
- }
- //返回来源地址
- function EcmsGetReturnUrl(){
- global $public_r;
- $from=$_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:$public_r['newsurl'];
- return RepPostStrUrl($from);
- }
- //checkdomain
- function eToCheckThisDomain($url){
- $domain=eReturnDomain();
- if(!stristr($url,$domain))
- {
- exit();
- }
- if(eCheckHaveReStr($url,'://'))
- {
- exit();
- }
- }
- //checkotherurl
- function eCheckOtherViewUrl($url,$havevar=0,$ecms=0){
- //fromurl
- if($ecms==1)
- {
- $fromurl=$_SERVER['HTTP_REFERER'];
- if(!$fromurl)
- {
- exit();
- }
- eToCheckThisDomain($fromurl);
- }
- if(!$url)
- {
- exit();
- }
- $url=RepPostStrUrl($url);
- if(!$havevar)
- {
- if(stristr($url,'?')||stristr($url,'&')||stristr($url,'#'))
- {
- exit();
- }
- }
- //url
- if(stristr($url,'://'))
- {
- eToCheckThisDomain($url);
- }
- else
- {
- if(stristr($str,':')||stristr($str,"\\")||stristr($str,'"')||stristr($str,"'"))
- {
- exit();
- }
- }
- }
- //checkrestr
- function eCheckHaveReStr($str,$exp){
- $r=explode($exp,$str);
- if(count($r)>2)
- {
- return 1;
- }
- return 0;
- }
- //checkurl
- function eToCheckIsUrl($url){
- $r=explode('://',$url);
- return eCheckStrType(2,$r[0],0);
- }
- //checkurl2
- function eToCheckIsUrl2($url){
- if(substr($url,0,4)=='http')
- {
- return 1;
- }
- return 0;
- }
- //checkstrtype
- function eCheckStrType($type,$str,$doing=0){
- $ret=0;
- if($type==1)//数字
- {
- if(preg_match('/^[0-9]+$/',$str))
- {
- $ret=1;
- }
- }
- elseif($type==2)//字母
- {
- if(preg_match('/^[A-Za-z]+$/',$str))
- {
- $ret=1;
- }
- }
- elseif($type==3)//字母+数字
- {
- if(preg_match('/^[A-Za-z0-9]+$/',$str))
- {
- $ret=1;
- }
- }
- elseif($type==4)//字母+数字+下划线
- {
- if(preg_match('/^[A-Za-z0-9_]+$/',$str))
- {
- $ret=1;
- }
- }
- elseif($type==5)//字母+数字+下划线+点
- {
- if(preg_match('/^[A-Za-z0-9\-\._]+$/',$str))
- {
- $ret=1;
- }
- }
- else
- {
- $ret=0;
- }
- if($doing)
- {
- if($ret<1)
- {
- exit();
- }
- }
- return $ret;
- }
- //返回地址
- function DoingReturnUrl($url,$from=''){
- if(empty($from))
- {
- return RepPostStrUrl($url);
- }
- elseif($from==9)
- {
- $from=$_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:$url;
- }
- return RepPostStrUrl($from);
- }
- //htmlspecialchars处理
- function ehtmlspecialchars($val,$flags=ENT_COMPAT){
- global $ecms_config;
- if(PHP_VERSION>='5.4.0')
- {
- if($ecms_config['sets']['pagechar']=='utf-8')
- {
- $char='UTF-8';
- }
- else
- {
- $char='ISO-8859-1';
- }
- $val=htmlspecialchars($val,$flags,$char);
- }
- else
- {
- $val=htmlspecialchars($val,$flags);
- }
- return $val;
- }
- //addslashes处理
- function eaddslashes($val,$ckmq=1){
- if($ckmq==1&&MAGIC_QUOTES_GPC)
- {
- return $val;
- }
- $val=addslashes($val);
- return $val;
- }
- //addslashes处理
- function eaddslashes2($val,$ckmq=1){
- if($ckmq==1&&MAGIC_QUOTES_GPC)
- {
- return addslashes($val);
- }
- $val=addslashes(addslashes($val));
- return $val;
- }
- //stripSlashes处理
- function estripSlashes($val,$ckmq=1){
- if($ckmq==1&&!MAGIC_QUOTES_GPC)
- {
- return $val;
- }
- $val=stripSlashes($val);
- return $val;
- }
- //stripSlashes处理
- function estripSlashes2($val,$ckmq=1){
- if($ckmq==1&&!MAGIC_QUOTES_GPC)
- {
- return stripSlashes($val);
- }
- $val=stripSlashes(stripSlashes($val));
- return $val;
- }
- //变量正数型处理
- function RepPIntvar($val){
- $val=intval($val);
- if($val<0)
- {
- $val=0;
- }
- return $val;
- }
- //参数处理函数
- function RepPostVar($val){
- if($val!=addslashes($val))
- {
- exit();
- }
- CkPostStrChar($val);
- $val=str_replace("%","",$val);
- $val=str_replace(" ","",$val);
- $val=str_replace("`","",$val);
- $val=str_replace("\t","",$val);
- $val=str_replace("%20","",$val);
- $val=str_replace("%27","",$val);
- $val=str_replace("*","",$val);
- $val=str_replace("'","",$val);
- $val=str_replace("\"","",$val);
- $val=str_replace("/","",$val);
- $val=str_replace(";","",$val);
- $val=str_replace("#","",$val);
- $val=str_replace("--","",$val);
- $val=RepPostStr($val,1);
- $val=addslashes($val);
- //FireWall
- FWClearGetText($val);
- return $val;
- }
- //参数处理函数2
- function RepPostVar2($val){
- if($val!=addslashes($val))
- {
- exit();
- }
- CkPostStrChar($val);
- $val=str_replace("%","",$val);
- $val=str_replace("`","",$val);
- $val=str_replace("\t","",$val);
- $val=str_replace("%20","",$val);
- $val=str_replace("%27","",$val);
- $val=str_replace("*","",$val);
- $val=str_replace("'","",$val);
- $val=str_replace("\"","",$val);
- $val=str_replace("/","",$val);
- $val=str_replace(";","",$val);
- $val=str_replace("#","",$val);
- $val=str_replace("--","",$val);
- $val=RepPostStr($val,1);
- $val=addslashes($val);
- //FireWall
- FWClearGetText($val);
- return $val;
- }
- //参数处理函数3
- function RepPostVar3($val){
- if($val!=addslashes($val))
- {
- exit();
- }
- CkPostStrChar($val);
- $val=str_replace("%","",$val);
- $val=str_replace("`","",$val);
- $val=str_replace("\t","",$val);
- $val=str_replace("%20","",$val);
- $val=str_replace("%27","",$val);
- $val=str_replace("*","",$val);
- $val=str_replace("'","",$val);
- $val=str_replace("\"","",$val);
- //$val=str_replace("/","",$val);
- $val=str_replace(";","",$val);
- $val=str_replace("#","",$val);
- $val=str_replace("--","",$val);
- $val=RepPostStr($val,1);
- $val=addslashes($val);
- //FireWall
- FWClearGetText($val);
- return $val;
- }
- //验证编码字符
- function CkPostStrCharYh($val){
- if($val!=addslashes($val))
- {
- exit();
- }
- return $val;
- }
- //处理提交字符
- function RepPostStr($val,$ecms=0,$phck=0){
- if($phck==1)
- {
- CkPostStrCharYh($val);
- }
- $val=ehtmlspecialchars($val,ENT_QUOTES);
- if($ecms==0)
- {
- CkPostStrChar($val);
- $val=AddAddsData($val);
- //FireWall
- FWClearGetText($val);
- }
- return $val;
- }
- //处理提交字符2
- function RepPostStr2($val,$phck=0){
- if($phck==1)
- {
- CkPostStrCharYh($val);
- }
- CkPostStrChar($val);
- $val=AddAddsData($val);
- //FireWall
- FWClearGetText($val);
- return $val;
- }
- //处理地址
- function RepPostStrUrl($val,$phck=0){
- $val=str_replace('&','&',RepPostStr($val,1,$phck));
- return $val;
- }
- //保存数据处理
- function dgdb_tosave($val,$phck=0){
- $val=RepPostStr($val,0,$phck);
- $val=addslashes($val);
- return $val;
- }
- //保存数据处理(url)
- function dgdb_tosaveurl($val,$phck=0){
- $val=RepPostStr($val,0,$phck);
- $val=str_replace('&','&',$val);
- $val=addslashes($val);
- return $val;
- }
- //数据显示
- function dgdb_toshow($val){
- $val=stripSlashes($val);
- return $val;
- }
- //处理显示字符
- function eDoRepShowStr($val,$isurl=0){
- $val=ehtmlspecialchars($val,ENT_QUOTES);
- if($isurl==1)
- {
- $val=str_replace('&','&',$val);
- }
- return $val;
- }
- //处理普通字符
- function eDoRepPostComStr($val,$isurl=0){
- $val=ehtmlspecialchars($val,ENT_QUOTES);
- if($isurl==1)
- {
- $val=str_replace('&','&',$val);
- }
- return $val;
- }
- //处理提交字符
- function hRepPostStr($val,$ecms=0,$phck=0){
- if($phck==1)
- {
- CkPostStrCharYh($val);
- }
- if($ecms==1)
- {
- $val=ehtmlspecialchars($val,ENT_QUOTES);
- }
- CkPostStrChar($val);
- $val=AddAddsData($val);
- return $val;
- }
- //处理提交字符2
- function hRepPostStr2($val,$phck=0){
- if($phck==1)
- {
- CkPostStrCharYh($val);
- }
- CkPostStrChar($val);
- $val=AddAddsData($val);
- return $val;
- }
- //处理编码字符
- function CkPostStrChar($val){
- if(substr($val,-1)=="\\")
- {
- exit();
- }
- }
- //返回转义
- function egetzy($n='2'){
- if($n=='rn')
- {
- $str="\r\n";
- }
- elseif($n=='n')
- {
- $str="\n";
- }
- elseif($n=='r')
- {
- $str="\r";
- }
- elseif($n=='t')
- {
- $str="\t";
- }
- elseif($n=='syh')
- {
- $str="\\\"";
- }
- elseif($n=='dyh')
- {
- $str="\'";
- }
- else
- {
- for($i=0;$i<$n;$i++)
- {
- $str.="\\";
- }
- }
- return $str;
- }
- //验证字符是否空
- function CheckValEmpty($val){
- return strlen($val)==0?1:0;
- }
- //返回ID列表
- function eReturnInids($ids){
- if(empty($ids))
- {
- return 0;
- }
- $dh='';
- $retids='';
- $r=explode(',',$ids);
- $count=count($r);
- for($i=0;$i<$count;$i++)
- {
- $id=(int)$r[$i];
- if(!$id)
- {
- continue;
- }
- $retids.=$dh.$id;
- $dh=',';
- }
- if(empty($retids))
- {
- return 0;
- }
- return $retids;
- }
- //数组返回ID列表
- function eArrayReturnInids($r){
- $count=count($r);
- if(!$count)
- {
- return 0;
- }
- $dh='';
- $retids='';
- for($i=0;$i<$count;$i++)
- {
- $id=(int)$r[$i];
- if(!$id)
- {
- continue;
- }
- $retids.=$dh.$id;
- $dh=',';
- }
- if(empty($retids))
- {
- return 0;
- }
- return $retids;
- }
- //返回父栏目ID列表
- function eReturnInFcids($featherclass){
- if(!$featherclass||$featherclass=='|')
- {
- return 0;
- }
- $cids='';
- $cdh='';
- $fcr=explode('|',$featherclass);
- $fcount=count($fcr);
- for($fi=1;$fi<$fcount-1;$fi++)
- {
- $fcr[$fi]=(int)$fcr[$fi];
- if(!$fcr[$fi])
- {
- continue;
- }
- $cids.=$cdh.$fcr[$fi];
- $cdh=',';
- }
- if(empty($cids))
- {
- return 0;
- }
- return $cids;
- }
- //返回组列表
- function eReturnSetGroups($groupid,$isnum=1){
- $count=count($groupid);
- if($count==0)
- {
- return '';
- }
- $ids=',';
- for($i=0;$i<$count;$i++)
- {
- if($isnum==1)
- {
- $groupid[$i]=(int)$groupid[$i];
- }
- $ids.=$groupid[$i].',';
- }
- return $ids;
- }
- //取得表里的模型ID
- function eGetTableModids($tid,$tbname){
- global $empire,$dbtbpre;
- $mids='';
- $where=$tid?"tid='$tid'":"tbname='$tbname'";
- $sql=$empire->query("select mid from {$dbtbpre}enewsmod where ".$where);
- while($r=$empire->fetch($sql))
- {
- $mids.=$dh.$r['mid'];
- $dh=',';
- }
- if(empty($mids))
- {
- $mids=0;
- }
- return $mids;
- }
- //替换模板变量字符
- function RepTempvarPostStr($val){
- $val=str_replace('[!--','[!---',$val);
- return $val;
- }
- //替换模板变量字符
- function RepTempvarPostStrT($val,$ispagef=0){
- if($ispagef==1)
- {
- $val=str_replace('[!--empirenews.page--]','[!!!-empirecms.page-!!]',$val);
- }
- $val=str_replace('[!--','[!--',$val);
- if($ispagef==1)
- {
- $val=str_replace('[!!!-empirecms.page-!!]','[!--empirenews.page--]',$val);
- }
- return $val;
- }
- //取得文件扩展名
- function GetFiletype($filename){
- $filer=explode(".",$filename);
- $count=count($filer)-1;
- return strtolower(".".RepGetFiletype($filer[$count]));
- }
- function RepGetFiletype($filetype){
- $filetype=str_replace('|','_',$filetype);
- $filetype=str_replace(',','_',$filetype);
- $filetype=str_replace('.','_',$filetype);
- return $filetype;
- }
- //取得文件名
- function GetFilename($filename){
- if(strstr($filename,"\\"))
- {
- $exp="\\";
- }
- else
- {
- $exp='/';
- }
- $filer=explode($exp,$filename);
- $count=count($filer)-1;
- return $filer[$count];
- }
- //返回目录函数
- function eReturnCPath($path,$ypath=''){
- if(strstr($path,'..')||strstr($path,"\\")||strstr($path,'%')||strstr($path,':'))
- {
- return $ypath;
- }
- return $path;
- }
- //验证文件名格式函数
- function eReturnCkCFile($path){
- if(strstr($path,'..')||strstr($path,"\\")||strstr($path,'/')||strstr($path,'%')||strstr($path,':'))
- {
- return 0;
- }
- return 1;
- }
- //字符截取函数
- function sub($string,$start=0,$length,$mode=false,$dot='',$rephtml=0){
- global $ecms_config;
- $strlen=strlen($string);
- if($strlen<=$length)
- {
- return $string;
- }
- if($rephtml==0)
- {
- $string = str_replace(array(' ','&','"','<','>','''), array(' ','&','"','<','>',"'"), $string);
- }
- $strcut = '';
- if(strtolower($ecms_config['sets']['pagechar']) == 'utf-8') {
- $n = $tn = $noc = 0;
- while($n < $strlen) {
- $t = ord($string[$n]);
- if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
- $tn = 1; $n++; $noc++;
- } elseif(194 <= $t && $t <= 223) {
- $tn = 2; $n += 2; $noc += 2;
- } elseif(224 <= $t && $t < 239) {
- $tn = 3; $n += 3; $noc += 2;
- } elseif(240 <= $t && $t <= 247) {
- $tn = 4; $n += 4; $noc += 2;
- } elseif(248 <= $t && $t <= 251) {
- $tn = 5; $n += 5; $noc += 2;
- } elseif($t == 252 || $t == 253) {
- $tn = 6; $n += 6; $noc += 2;
- } else {
- $n++;
- }
- if($noc >= $length) {
- break;
- }
- }
- if($noc > $length) {
- $n -= $tn;
- }
- $strcut = substr($string, 0, $n);
- } else {
- for($i = 0; $i < $length; $i++) {
- $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
- }
- }
- if($rephtml==0)
- {
- $strcut = str_replace(array('&','"','<','>',"'"), array('&','"','<','>','''), $strcut);
- }
- return $strcut.$dot;
- }
- //截取字数
- function esub($string,$length,$dot='',$rephtml=0){
- return sub($string,0,$length,false,$dot,$rephtml);
- }
- //取得随机数
- function make_password($pw_length){
- $low_ascii_bound=48;
- $upper_ascii_bound=122;
- $notuse=array(58,59,60,61,62,63,64,91,92,93,94,95,96);
- while($i<$pw_length)
- {
- if(PHP_VERSION<'4.2.0')
- {
- mt_srand((double)microtime()*1000000);
- }
- mt_srand();
- $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
- if(!in_array($randnum,$notuse))
- {
- $password1=$password1.chr($randnum);
- $i++;
- }
- }
- return $password1;
- }
- //取得随机数(数字)
- function no_make_password($pw_length){
- $low_ascii_bound=48;
- $upper_ascii_bound=57;
- $notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
- while($i<$pw_length)
- {
- if(PHP_VERSION<'4.2.0')
- {
- mt_srand((double)microtime()*1000000);
- }
- mt_srand();
- $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
- if(!in_array($randnum,$notuse))
- {
- $password1=$password1.chr($randnum);
- $i++;
- }
- }
- return $password1;
- }
- //取得随机数(字母)
- function abc_make_password($pw_length){
- $low_ascii_bound=65;
- $upper_ascii_bound=122;
- $notuse=array(91,92,93,94,95,96);
- while($i<$pw_length)
- {
- if(PHP_VERSION<'4.2.0')
- {
- mt_srand((double)microtime()*1000000);
- }
- mt_srand();
- $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
- if(!in_array($randnum,$notuse))
- {
- $password1=$password1.chr($randnum);
- $i++;
- }
- }
- return $password1;
- }
- //programno
- function EcmsGetProgramNo(){
- $r=explode(' ',microtime());
- $pno=$r[1].$r[0];
- return $pno;
- }
- //随机数字
- function EcmsRandInt($min=0,$max=0,$ecms=0){
- mt_srand();
- if($max)
- {
- $rnd=mt_rand($min,$max);
- }
- else
- {
- $rnd=mt_rand();
- }
- return $rnd;
- }
- //颜色转RGB
- function ToReturnRGB($rgb){
- $rgb=str_replace('#','',ehtmlspecialchars($rgb));
- return array(
- base_convert(substr($rgb,0,2),16,10),
- base_convert(substr($rgb,2,2),16,10),
- base_convert(substr($rgb,4,2),16,10)
- );
- }
- //验证页码是否有效
- function eCheckListPageNo($page,$line,$totalnum){
- $page=(int)$page;
- $line=(int)$line;
- $totalnum=(int)$totalnum;
- if(!$page)
- {
- return '';
- }
- if(!$line)
- {
- return '';
- }
- $totalpage=ceil($totalnum/$line);
- if($page>=$totalpage)
- {
- printerror('ErrorUrl','history.go(-1)',1);
- }
- }
- //前台分页
- function page1($num,$line,$page_line,$start,$page,$search){
- global $fun_r;
- $num=(int)$num;
- $line=(int)$line;
- $page_line=(int)$page_line;
- $start=(int)$start;
- $page=(int)$page;
- if($num<=$line)
- {
- return '';
- }
- $search=RepPostStr($search,1);
- $url=eReturnSelfPage(0).'?page';
- $snum=2;//最小页数
- $totalpage=ceil($num/$line);//取得总页数
- $firststr='<li class="previous disabled"><a href="'.$url.'=0'.$search.'">'.$fun_r['startpage'].'</a></li>';
- //上一页
- if($page<>0)
- {
- //$toppage='<li class="previous disabled"><a href="'.$url.'=0'.$search.'">'.$fun_r['startpage'].'</a></li>';
- $pagepr=$page-1;
- $prepage='<li class="previous disabled"><a href="'.$url.'='.$pagepr.$search.'">'.$fun_r['pripage'].'</a></li>';
- }
- //下一页
- if($page!=$totalpage-1)
- {
- $pagenex=$page+1;
- $nextpage='<li class="next"><a href="'.$url.'='.$pagenex.$search.'">'.$fun_r['nextpage'].'</a></li>';
- $lastpage='<li class="next"><a href="'.$url.'='.($totalpage-1).$search.'">'.$fun_r['lastpage'].'</a></li>';
- }
- $starti=$page-$snum<0?0:$page-$snum;
- $no=0;
- for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
- {
- $no++;
- if($page==$i)
- {
- $is_1="<li class=\"disabled active\"><a>";
- $is_2="</a></li>";
- }
- else
- {
- $is_1='<li><a href="'.$url.'='.$i.$search.'">';
- $is_2="</a></li>";
- }
- $pagenum=$i+1;
- $returnstr.="".$is_1.$pagenum.$is_2;
- }
- $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
- return $returnstr;
- }
- //---------- 伪静态 ----------
- //返回内容伪静态
- function eReturnRewriteInfoUrl($classid,$id,$ecms=0){
- global $public_r;
- if(empty($public_r['rewriteinfo']))
- {
- $r['pageurl']=$public_r['newsurl']."e/action/ShowInfo.php?classid=$classid&id=$id";
- $r['rewrite']=0;
- }
- else
- {
- if($ecms==1)
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--classid--]','[!--id--]','[!--page--]'),array($classid,$id,0),$public_r['rewriteinfo']);
- }
- else
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--classid--]','[!--id--]'),array($classid,$id),$public_r['rewriteinfo']);
- }
- $r['rewrite']=1;
- }
- return $r;
- }
- //返回栏目列表伪静态
- function eReturnRewriteClassUrl($classid,$ecms=0){
- global $public_r;
- if(empty($public_r['rewriteclass']))
- {
- $r['pageurl']=$public_r['newsurl']."e/action/ListInfo/?classid=$classid";
- $r['rewrite']=0;
- }
- else
- {
- if($ecms==1)
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--classid--]','[!--page--]'),array($classid,0),$public_r['rewriteclass']);
- }
- else
- {
- $r['pageurl']=$public_r['newsurl'].str_replace('[!--classid--]',$classid,$public_r['rewriteclass']);
- }
- $r['rewrite']=1;
- }
- return $r;
- }
- //返回标题分类列表伪静态
- function eReturnRewriteTitleTypeUrl($ttid,$ecms=0){
- global $public_r;
- if(empty($public_r['rewriteinfotype']))
- {
- $r['pageurl']=$public_r['newsurl']."e/action/InfoType/?ttid=$ttid";
- $r['rewrite']=0;
- }
- else
- {
- if($ecms==1)
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--ttid--]','[!--page--]'),array($ttid,0),$public_r['rewriteinfotype']);
- }
- else
- {
- $r['pageurl']=$public_r['newsurl'].str_replace('[!--ttid--]',$ttid,$public_r['rewriteinfotype']);
- }
- $r['rewrite']=1;
- }
- return $r;
- }
- //返回TAGS列表伪静态
- function eReturnRewriteTagsUrl($tagid,$tagname,$ecms=0){
- global $public_r;
- $tagname=urlencode($tagname);
- if(empty($public_r['rewritetags']))
- {
- $r['pageurl']=$public_r['newsurl']."e/tags/?tagname=".$tagname;
- $r['rewrite']=0;
- }
- else
- {
- if($ecms==1)
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--tagname--]','[!--page--]'),array($tagname,0),$public_r['rewritetags']);
- }
- else
- {
- $r['pageurl']=$public_r['newsurl'].str_replace('[!--tagname--]',$tagname,$public_r['rewritetags']);
- }
- $r['rewrite']=1;
- }
- return $r;
- }
- //返回评论列表伪静态
- function eReturnRewritePlUrl($classid,$id,$doaction='doinfo',$myorder=0,$tempid=0,$ecms=0){
- global $public_r;
- if(empty($public_r['rewritepl']))
- {
- if($doaction=='dozt')
- {
- $r['pageurl']=$public_r['plurl']."?doaction=dozt&classid=$classid".($myorder?'&myorder='.$myorder:'').($tempid?'&tempid='.$tempid:'');
- }
- else
- {
- $r['pageurl']=$public_r['plurl']."?classid=$classid&id=$id".($myorder?'&myorder='.$myorder:'').($tempid?'&tempid='.$tempid:'');
- }
- $r['rewrite']=0;
- }
- else
- {
- if($ecms==1)
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--doaction--]','[!--classid--]','[!--id--]','[!--page--]','[!--myorder--]','[!--tempid--]'),array($doaction,$classid,$id,0,$myorder,$tempid),$public_r['rewritepl']);
- }
- else
- {
- $r['pageurl']=$public_r['newsurl'].str_replace(array('[!--doaction--]','[!--classid--]','[!--id--]','[!--myorder--]','[!--tempid--]'),array($doaction,$classid,$id,$myorder,$tempid),$public_r['rewritepl']);
- }
- $r['rewrite']=1;
- }
- return $r;
- }
- //伪静态链接地址中转
- function eReturnRewriteLink($type,$classid,$id){
- if($type=='infopage')//信息页
- {
- $url=eReturnRewriteInfoUrl($classid,$id);
- }
- elseif($type=='ttpage')//标题分类页
- {
- $url=eReturnRewriteTitleTypeUrl($classid);
- }
- elseif($type=='tagspage')//Tags列表页
- {
- $url=eReturnRewriteTagsUrl($classid,$id);
- }
- else//栏目页
- {
- $url=eReturnRewriteClassUrl($classid);
- }
- return $url;
- }
- //伪静态替换分页号
- function eReturnRewritePageLink($r,$page){
- //动静
- $truepage=$page+1;
- if($r['repagenum']&&$truepage<=$r['repagenum'])
- {
- //文件名
- if(empty($r['dofile']))
- {
- $r['dofile']='index';
- }
- $url=$r['dolink'].$r['dofile'].($truepage==1?'':'_'.$truepage).$r['dotype'];
- return $url;
- }
- if($r['rewrite']==1)
- {
- $url=str_replace('[!--page--]',$page,$r['pageurl']);
- }
- else
- {
- $url=$r['pageurl'].'&page='.$page;
- }
- return $url;
- }
- //伪静态替换分页号(静态)
- function eReturnRewritePageLink2($r,$page){
- if($r['rewrite']==1)
- {
- $url=str_replace('[!--page--]',$page-1,$r['pageurl']);
- }
- else
- {
- $url=$r['pageurl'].'&page='.($page-1);
- }
- return $url;
- }
- //前台分页(伪静态)
- function InfoUsePage($num,$line,$page_line,$start,$page,$search,$add){
- global $fun_r;
- $num=(int)$num;
- $line=(int)$line;
- $page_line=(int)$page_line;
- $start=(int)$start;
- $page=(int)$page;
- if($num<=$line)
- {
- return '';
- }
- $search=RepPostStr($search,1);
- $snum=2;//最小页数
- $totalpage=ceil($num/$line);//取得总页数
- $firststr='<a title="'.$fun_r['trecord'].'"> <b>'.$num.'</b> </a> ';
- //上一页
- if($page<>0)
- {
- $toppage='<a href="'.eReturnRewritePageLink($add,0).'">'.$fun_r['startpage'].'</a> ';
- $pagepr=$page-1;
- $prepage='<a href="'.eReturnRewritePageLink($add,$pagepr).'">'.$fun_r['pripage'].'</a>';
- }
- //下一页
- if($page!=$totalpage-1)
- {
- $pagenex=$page+1;
- $nextpage=' <a href="'.eReturnRewritePageLink($add,$pagenex).'">'.$fun_r['nextpage'].'</a>';
- $lastpage=' <a href="'.eReturnRewritePageLink($add,$totalpage-1).'">'.$fun_r['lastpage'].'</a>';
- }
- $starti=$page-$snum<0?0:$page-$snum;
- $no=0;
- for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
- {
- $no++;
- if($page==$i)
- {
- $is_1="<b>";
- $is_2="</b>";
- }
- else
- {
- $is_1='<a href="'.eReturnRewritePageLink($add,$i).'">';
- $is_2="</a>";
- }
- $pagenum=$i+1;
- $returnstr.=" ".$is_1.$pagenum.$is_2;
- }
- $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
- return $returnstr;
- }
- //时间转换函数
- function to_time($datetime){
- if(strlen($datetime)==10)
- {
- $datetime.=" 00:00:00";
- }
- $r=explode(" ",$datetime);
- $t=explode("-",$r[0]);
- $k=explode(":",$r[1]);
- $dbtime=@mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
- return intval($dbtime);
- }
- //时期转日期
- function date_time($time,$format="Y-m-d H:i:s"){
- $threadtime=date($format,$time);
- return $threadtime;
- }
- //格式化日期
- function format_datetime($newstime,$format){
- if($newstime=="0000-00-00 00:00:00")
- {return $newstime;}
- $time=is_numeric($newstime)?$newstime:to_time($newstime);
- $newdate=date_time($time,$format);
- return $newdate;
- }
- //时间转换函数
- function to_date($date){
- $date.=" 00:00:00";
- $r=explode(" ",$date);
- $t=explode("-",$r[0]);
- $k=explode(":",$r[1]);
- $dbtime=@mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
- return intval($dbtime);
- }
- //选择时间
- function ToChangeTime($time,$day){
- $truetime=$time-$day*24*3600;
- $date=date_time($truetime,"Y-m-d");
- return $date;
- }
- //删除文件
- function DelFiletext($filename){
- @unlink($filename);
- }
- //取得文件内容
- function ReadFiletext($filepath){
- $filepath=trim($filepath);
- $ishttp=0;
- if(strstr($filepath,'://'))
- {
- if(!eToCheckIsUrl2($filepath))
- {
- return '';
- }
- $ishttp=1;
- }
- $htmlfp=@fopen($filepath,"r");
- //远程
- if($ishttp==1)
- {
- while($data=@fread($htmlfp,500000))
- {
- $string.=$data;
- }
- }
- //本地
- else
- {
- $string=@fread($htmlfp,@filesize($filepath));
- }
- @fclose($htmlfp);
- return $string;
- }
- //写文件
- function WriteFiletext($filepath,$string){
- global $public_r;
- $string=stripSlashes($string);
- $fp=@fopen($filepath,"w");
- @fputs($fp,$string);
- @fclose($fp);
- if(empty($public_r[filechmod]))
- {
- @chmod($filepath,0777);
- }
- }
- //写文件
- function WriteFiletext_n($filepath,$string){
- global $public_r;
- $fp=@fopen($filepath,"w");
- @fputs($fp,$string);
- @fclose($fp);
- if(empty($public_r[filechmod]))
- {
- @chmod($filepath,0777);
- }
- }
- //标题属性后
- function DoTitleFont($titlefont,$title){
- if(empty($titlefont))
- {
- return $title;
- }
- $r=explode(',',$titlefont);
- if(!empty($r[0]))
- {
- $title="<font color='".$r[0]."'>".$title."</font>";
- }
- if(empty($r[1]))
- {return $title;}
- //粗体
- if(strstr($r[1],"b"))
- {$title="<strong>".$title."</strong>";}
- //斜体
- if(strstr($r[1],"i"))
- {$title="<i>".$title."</i>";}
- //删除线
- if(strstr($r[1],"s"))
- {$title="<s>".$title."</s>";}
- return $title;
- }
- //返回头条级别名称权限
- function ReturnFirsttitleNameCkLevel($r,$groupid,$classid){
- if(defined('EmpireCMSAdmin'))
- {
- if($r['groupid'])
- {
- if(!strstr($r['groupid'],','.$groupid.','))
- {
- return 0;
- }
- }
- }
- if($classid)
- {
- if($r['showcid'])
- {
- if(!strstr($r['showcid'],','.$classid.','))
- {
- return 0;
- }
- }
- if($r['hiddencid'])
- {
- if(strstr($r['hiddencid'],','.$classid.','))
- {
- return 0;
- }
- }
- }
- else
- {
- if($r['showall']==1)
- {
- return 0;
- }
- }
- return 1;
- }
- //返回头条级别名称
- function ReturnFirsttitleNameList($firsttitle,$isgood){
- global $empire,$dbtbpre,$lur,$classid,$class_r;
- $classid=(int)$classid;
- if($classid&&!$class_r[$classid]['islast'])
- {
- $classid=0;
- }
- $groupid=(int)$lur['groupid'];
- $first_r=array();//头条
- $ftn='';
- $good_r=array();//推荐
- $gn='';
- $sql=$empire->query("select tname,ttype,levelid,groupid,showall,showcid,hiddencid from {$dbtbpre}enewsgoodtype order by myorder desc,levelid");
- while($r=$empire->fetch($sql))
- {
- if($r['ttype']==1)//头条
- {
- $first_r[$r['levelid']]=$r['tname'];
- $selected='';
- if($r['levelid']==$firsttitle)
- {
- $selected=' selected';
- }
- if(ReturnFirsttitleNameCkLevel($r,$groupid,$classid))
- {
- $ftn.='<option value="'.$r['levelid'].'"'.$selected.'>'.$r['tname'].'</option>';
- }
- }
- else//推荐
- {
- $good_r[$r['levelid']]=$r['tname'];
- $selected='';
- if($r['levelid']==$isgood)
- {
- $selected=' selected';
- }
- if(ReturnFirsttitleNameCkLevel($r,$groupid,$classid))
- {
- $gn.='<option value="'.$r['levelid'].'"'.$selected.'>'.$r['tname'].'</option>';
- }
- }
- }
- $ret_r['ftname']=$ftn;
- $ret_r['ftr']=$first_r;
- $ret_r['igname']=$gn;
- $ret_r['igr']=$good_r;
- return $ret_r;
- }
- //替换全角逗号
- function DoReplaceQjDh($text){
- return str_replace(',',',',$text);
- }
- //半角转全角
- function eDoBjToQj($text){
- $text=str_replace(array('&','"','\'','<','>'),array('&','”','’','<','>'),$text);
- return $text;
- }
- //给信息字段转全角
- function eDoInfoTbfToQj($tbname,$f,$fval,$qjf){
- global $public_r;
- if(empty($qjf))
- {
- return $fval;
- }
- if(!stristr('|'.$qjf.'|','|'.$tbname.'.'.$f.'|'))
- {
- return $fval;
- }
- $fval=eDoBjToQj($fval);
- return $fval;
- }
- //建立目录函数
- function DoMkdir($path){
- global $public_r;
- //不存在则建立
- if(!file_exists($path))
- {
- //安全模式
- if($public_r[phpmode])
- {
- $pr[0]=$path;
- FtpMkdir($ftpid,$pr,0777);
- $mk=1;
- }
- else
- {
- $mk=@mkdir($path,0777);
- @chmod($path,0777);
- }
- if(empty($mk))
- {
- echo Ecms_eReturnShowMkdir($path);
- printerror("CreatePathFail","history.go(-1)");
- }
- }
- return true;
- }
- //建立上级目录
- function DoFileMkDir($file){
- $path=dirname($file.'empirecms.txt');
- DoMkdir($path);
- }
- //设置上传文件权限
- function DoChmodFile($file){
- global $public_r;
- if($public_r['filechmod']!=1)
- {
- @chmod($file,0777);
- }
- }
- //替换斜扛
- function DoRepFileXg($file){
- $file=str_replace("\\","/",$file);
- return $file;
- }
- //返回栏目链接字符串
- function ReturnClassLink($classid){
- global $class_r,$public_r,$fun_r;
- if(empty($class_r[$classid][featherclass]))
- {$class_r[$classid][featherclass]="|";}
- $r=explode("|",$class_r[$classid][featherclass].$classid."|");
- $string="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";
- for($i=1;$i<count($r)-1;$i++)
- {
- //moreport
- if(Moreport_ReturnMustDt())
- {
- $class_r[$r[$i]][listdt]=1;
- }
- //静态列表
- if(empty($class_r[$r[$i]][listdt]))
- {
- //无绑定域名
- if(empty($class_r[$r[$i]][classurl]))
- {$url=$public_r[newsurl].$class_r[$r[$i]][classpath]."/";}
- else
- {$url=$class_r[$r[$i]][classurl];}
- }
- else
- {
- $rewriter=eReturnRewriteClassUrl($r[$i],1);
- $url=$rewriter['pageurl'];
- }
- $string.=" ".$public_r[navfh]." <a href=\"".$url."\">".$class_r[$r[$i]][classname]."</a>";
- }
- return $string;
- }
- //返回专题链接字符串
- function ReturnZtLink($ztid){
- global $class_zr,$public_r,$fun_r;
- $string="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";
- //无绑定域名
- if(empty($class_zr[$ztid][zturl]))
- {$url=$public_r[newsurl].$class_zr[$ztid][ztpath]."/";}
- else
- {$url=$class_zr[$ztid][zturl];}
- $string.=" ".$public_r[navfh]." <a href=\"".$url."\">".$class_zr[$ztid][ztname]."</a>";
- return $string;
- }
- //返回标题分类链接字符串
- function ReturnInfoTypeLink($typeid){
- global $class_tr,$public_r,$fun_r;
- $string="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";
- //moreport
- if(Moreport_ReturnMustDt())
- {
- $class_tr[$typeid]['listdt']=1;
- }
- if($class_tr[$typeid]['listdt'])
- {
- $rewriter=eReturnRewriteTitleTypeUrl($typeid,1);
- $url=$rewriter['pageurl'];
- }
- else
- {
- $url=$public_r[newsurl].$class_tr[$typeid][tpath]."/";
- }
- $string.=" ".$public_r[navfh]." <a href=\"".$url."\">".$class_tr[$typeid][tname]."</a>";
- return $string;
- }
- //返回单页链接字符串
- function ReturnUserPLink($title,$titleurl){
- global $public_r,$fun_r;
- $string='<a href="'.ReturnSiteIndexUrl().'">'.$fun_r['index'].'</a> '.$public_r[navfh].' '.$title;
- return $string;
- }
- //返回标题链接(静态)
- function sys_ReturnBqTitleLink($r){
- global $public_r;
- if(empty($r['isurl']))
- {
- //moreport
- if(Moreport_ReturnMustDt())
- {
- return Moreport_ReturnTitleUrl($r['classid'],$r['id']);
- }
- return $r['titleurl'];
- }
- else
- {
- if($public_r['opentitleurl'])
- {
- $titleurl=$r['titleurl'];
- }
- else
- {
- $titleurl=$public_r['newsurl'].'e/public/jump/?classid='.$r['classid'].'&id='.$r['id'];
- }
- return $titleurl;
- }
- }
- //返回标题链接(动态)
- function sys_ReturnBqTitleLinkDt($r){
- global $public_r,$class_r;
- if(empty($r['isurl']))
- {
- if($class_r[$r[classid]][showdt]==1)//动态生成
- {
- $titleurl=$public_r[newsurl]."e/action/ShowInfo/?classid=$r[classid]&id=$r[id]";
- return $titleurl;
- }
- elseif($class_r[$r[classid]][showdt]==2)
- {
- $rewriter=eReturnRewriteInfoUrl($r['classid'],$r['id'],1);
- $titleurl=$rewriter['pageurl'];
- return $titleurl;
- }
- if($class_r[$r[classid]][filename]==3)
- {
- $filename=ReturnInfoSPath($r[filename]);
- }
- else
- {
- $filetype=$r[groupid]?'.php':$class_r[$r[classid]][filetype];
- $filename=$r[filename].$filetype;
- }
- $iclasspath=ReturnSaveInfoPath($r[classid],$r[id]);
- $newspath=empty($r[newspath])?'':$r[newspath]."/";
- if($class_r[$r[classid]][classurl]&&$class_r[$r[classid]][ipath]=='')//域名
- {
- $titleurl=$class_r[$r[classid]][classurl]."/".$newspath.$filename;
- }
- else
- {
- $titleurl=$public_r[newsurl].$iclasspath.$newspath.$filename;
- }
- }
- else
- {
- $titleurl=$r['titleurl'];
- }
- return addslashes($titleurl);
- }
- //中转取得信息地址
- function GotoGetTitleUrl($classid,$id,$newspath,$filename,$groupid,$isurl,$titleurl){
- $r['classid']=$classid;
- $r['id']=$id;
- $r['newspath']=$newspath;
- $r['filename']=$filename;
- $r['groupid']=$groupid;
- $r['isurl']=$isurl;
- $r['titleurl']=$titleurl;
- $infourl=sys_ReturnBqTitleLinkDt($r);
- return $infourl;
- }
- //返回标题链接(触发)
- function sys_ReturnBqAutoTitleLink($r){
- global $public_r,$class_r;
- if(empty($r['isurl']))
- {
- if($class_r[$r[classid]][showdt]==2)
- {
- $rewriter=eReturnRewriteInfoUrl($r['classid'],$r['id'],1);
- $titleurl=$rewriter['pageurl'];
- return $titleurl;
- }
- if($class_r[$r[classid]][filename]==3)
- {
- $filename=ReturnInfoSPath($r[filename]);
- }
- else
- {
- $filetype=$r[groupid]?'.php':$class_r[$r[classid]][filetype];
- $filename=$r[filename].$filetype;
- }
- $iclasspath=ReturnSaveInfoPath($r[classid],$r[id]);
- $newspath=empty($r[newspath])?'':$r[newspath]."/";
- if($class_r[$r[classid]][classurl]&&$class_r[$r[classid]][ipath]=='')//域名
- {
- $titleurl=$class_r[$r[classid]][classurl]."/".$newspath.$filename;
- }
- else
- {
- $titleurl=$public_r[newsurl].$iclasspath.$newspath.$filename;
- }
- }
- else
- {
- if($public_r['opentitleurl'])
- {
- $titleurl=$r['titleurl'];
- }
- else
- {
- $titleurl=$public_r['newsurl']."e/public/jump/?classid=".$r['classid']."&id=".$r['id'];
- }
- }
- return $titleurl;
- }
- //返回内容页地址前缀
- function ReturnInfoPageQz($r){
- global $public_r,$class_r;
- $ret_r['titleurl']='';
- $ret_r['filetype']='';
- $ret_r['nametype']=0;
- //动态页面
- if($class_r[$r[classid]][showdt]==2)
- {
- $rewriter=eReturnRewriteInfoUrl($r['classid'],$r['id'],0);
- $ret_r['pageurl']=$rewriter['pageurl'];
- $ret_r['rewrite']=$rewriter['rewrite'];
- $ret_r['titleurl']=$rewriter['pageurl'];
- $ret_r['filetype']='';
- $ret_r['nametype']=1;
- return $ret_r;
- }
- //静态页面
- $ret_r['filetype']=$r[groupid]?'.php':$class_r[$r[classid]][filetype];
- $filename=$r[filename];
- $iclasspath=ReturnSaveInfoPath($r[classid],$r[id]);
- $newspath=empty($r[newspath])?'':$r[newspath]."/";
- if($class_r[$r[classid]][classurl]&&$class_r[$r[classid]][ipath]=='')//域名
- {
- $ret_r['titleurl']=$class_r[$r[classid]][classurl]."/".$newspath.$filename;
- }
- else
- {
- $ret_r['titleurl']=$public_r[newsurl].$iclasspath.$newspath.$filename;
- }
- return $ret_r;
- }
- //返回栏目链接
- function sys_ReturnBqClassname($r,$have_class=0){
- global $public_r,$class_r;
- if($have_class)
- {
- //moreport
- if(Moreport_ReturnMustDt())
- {
- $class_r[$r[classid]][listdt]=1;
- }
- //外部栏目
- if($class_r[$r[classid]][wburl])
- {
- $classurl=$class_r[$r[classid]][wburl];
- }
- //动态列表
- elseif($class_r[$r[classid]][listdt])
- {
- $rewriter=eReturnRewriteClassUrl($r['classid'],1);
- $classurl=$rewriter['pageurl'];
- }
- elseif($class_r[$r[classid]][classurl])
- {
- $classurl=$class_r[$r[classid]][classurl];
- }
- else
- {
- $classurl=$public_r[newsurl].$class_r[$r[classid]][classpath]."/";
- }
- if(empty($class_r[$r[classid]][bname]))
- {$classname=$class_r[$r[classid]][classname];}
- else
- {$classname=$class_r[$r[classid]][bname];}
- $myadd="[<a href=".$classurl.">".$classname."</a>]";
- //只返回链接
- if($have_class==9)
- {$myadd=$classurl;}
- }
- else
- {$myadd="";}
- return $myadd;
- }
- //返回专题链接
- function sys_ReturnBqZtname($r){
- global $public_r,$class_zr;
- if($class_zr[$r[ztid]][zturl])
- {
- $zturl=$class_zr[$r[ztid]][zturl];
- }
- else
- {
- $zturl=$public_r[newsurl].$class_zr[$r[ztid]][ztpath]."/";
- }
- return $zturl;
- }
- //返回标题分类链接
- function sys_ReturnBqInfoTypeUrl($typeid){
- global $public_r,$class_tr;
- //moreport
- if(Moreport_ReturnMustDt())
- {
- $class_tr[$typeid]['listdt']=1;
- }
- if($class_tr[$typeid]['listdt'])
- {
- $rewriter=eReturnRewriteTitleTypeUrl($typeid,1);
- $url=$rewriter['pageurl'];
- }
- else
- {
- $url=$public_r['newsurl'].$class_tr[$typeid]['tpath']."/";
- }
- return $url;
- }
- //文件大小格式转换
- function ChTheFilesize($size){
- if($size>=1024*1024)//MB
- {
- $filesize=number_format($size/(1024*1024),2,'.','')." MB";
- }
- elseif($size>=1024)//KB
- {
- $filesize=number_format($size/1024,2,'.','')." KB";
- }
- else
- {
- $filesize=$size." Bytes";
- }
- return $filesize;
- }
- //取得表记录
- function eGetTableRowNum($tbname){
- global $empire,$dbtbpre;
- $total_r=$empire->fetch1("SHOW TABLE STATUS LIKE '".$tbname."';");
- return $total_r['Rows'];
- }
- //更新栏目信息数
- function AddClassInfos($classid,$addallstr,$addstr,$checked=1){
- global $empire,$dbtbpre;
- $updatestr='';
- $dh='';
- if($addallstr)
- {
- $updatestr.='allinfos=allinfos'.$addallstr;
- $dh=',';
- }
- if($addstr)
- {
- if($checked)
- {
- $updatestr.=$dh.'infos=infos'.$addstr;
- }
- }
- if(empty($updatestr))
- {
- return '';
- }
- $empire->query("update {$dbtbpre}enewsclass set ".$updatestr." where classid='$classid' limit 1");
- }
- //返回栏目信息数
- function ReturnClassInfoNum($cr,$ecms=0){
- global $empire,$dbtbpre,$class_r;
- if($cr['islast'])
- {
- $num=$ecms==0?$cr['infos']:$cr['allinfos'];
- }
- else
- {
- $f=$ecms==0?'infos':'allinfos';
- $num=$empire->gettotal("select sum(".$f.") as total from {$dbtbpre}enewsclass where ".ReturnClass($class_r[$cr[classid]][sonclass]));
- $num=(int)$num;
- }
- return $num;
- }
- //重置栏目信息数
- function ResetClassInfos($classid){
- global $empire,$dbtbpre,$class_r;
- $infos=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid]['tbname']." where classid='$classid'");
- $checkinfos=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid]['tbname']."_check where classid='$classid'");
- $allinfos=$infos+$checkinfos;
- $empire->query("update {$dbtbpre}enewsclass set allinfos='$allinfos',infos='$infos' where classid='$classid' limit 1");
- }
- //单信息评论数
- function UpdateSingleInfoPlnum($classid,$id,$checked=1){
- global $empire,$dbtbpre,$class_r;
- $tbname=$class_r[$classid]['tbname'];
- if(empty($tbname))
- {
- return '';
- }
- $infotb=ReturnInfoMainTbname($tbname,$checked);
- $r=$empire->fetch1("select id,restb,plnum from ".$infotb." where id='$id' limit 1");
- if(empty($r['restb']))
- {
- return '';
- }
- $pubid=ReturnInfoPubid($classid,$id);
- $plnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewspl_".$r['restb']." where pubid='$pubid' limit 1");
- if($plnum==$r['plnum'])
- {
- return '';
- }
- $empire->query("update ".$infotb." set plnum='$plnum' where id='$id' limit 1");
- }
- //信息数统计加1
- function DoUpdateAddDataNum($type='info',$stb,$addnum=1){
- global $empire,$dbtbpre;
- if($type=='info')//信息
- {
- $lasttimef='lasttimeinfo';
- $lastnumf='lastnuminfo';
- $lastnumtbf='lastnuminfotb';
- $todaytimef='todaytimeinfo';
- $todaynumf='todaynuminfo';
- $yesterdaynumf='yesterdaynuminfo';
- $sqladdf=',todaytimeinfo,todaytimepl,todaynuminfo,todaynumpl';
- }
- elseif($type=='pl')//评论
- {
- $lasttimef='lasttimepl';
- $lastnumf='lastnumpl';
- $lastnumtbf='lastnumpltb';
- $todaytimef='todaytimepl';
- $todaynumf='todaynumpl';
- $yesterdaynumf='yesterdaynumpl';
- $sqladdf=',todaytimepl,todaytimeinfo,todaynuminfo,todaynumpl';
- }
- else
- {
- return '';
- }
- $sqladdupdate='';
- $time=time();
- $pur=$empire->fetch1("select ".$lasttimef.",".$lastnumtbf.$sqladdf." from {$dbtbpre}enewspublic_up limit 1");
- if($stb)
- {
- if(empty($pur[$lastnumtbf]))
- {
- $pur[$lastnumtbf]='|';
- }
- if(strstr($pur[$lastnumtbf],'|'.$stb.','))
- {
- $numr=explode('|'.$stb.',',$pur[$lastnumtbf]);
- $numrt=explode('|',$numr[1]);
- $newnum=$numrt[0]+$addnum;
- $tbnums=str_replace('|'.$stb.','.$numrt[0].'|','|'.$stb.','.$newnum.'|',$pur[$lastnumtbf]);
- }
- else
- {
- $tbnums=$pur[$lastnumtbf].$stb.','.$addnum.'|';
- }
- $sqladdupdate.=",".$lastnumtbf."='".$tbnums."'";
- }
- //今日统计
- if($sqladdf)
- {
- $todaydate=date('Y-m-d');
- if($todaydate<>date('Y-m-d',$pur['todaytimeinfo'])||$todaydate<>date('Y-m-d',$pur['todaytimepl']))
- {
- if($type=='info')
- {
- $todaynuminfo=$addnum;
- $todaynumpl=0;
- }
- else
- {
- $todaynuminfo=0;
- $todaynumpl=$addnum;
- }
- $yesterdaynuminfo=$pur['todaynuminfo'];
- $yesterdaynumpl=$pur['todaynumpl'];
- if($todaydate<>date('Y-m-d',$pur['todaytimeinfo']+24*3600))
- {
- $yesterdaynuminfo=0;
- }
- if($todaydate<>date('Y-m-d',$pur['todaytimepl']+24*3600))
- {
- $yesterdaynumpl=0;
- }
- $sqladdupdate.=",todaytimeinfo='$time',todaytimepl='$time',todaynuminfo='$todaynuminfo',todaynumpl='$todaynumpl',yesterdaynuminfo='$yesterdaynuminfo',yesterdaynumpl='$yesterdaynumpl'";
- }
- else
- {
- $sqladdupdate.=",".$todaynumf."=".$todaynumf."+".$addnum;
- }
- }
- $empire->query("update {$dbtbpre}enewspublic_up set ".$lastnumf."=".$lastnumf."+".$addnum.$sqladdupdate." limit 1");
- }
- //重置信息数统计
- function DoResetAddDataNum($type='info'){
- global $empire,$dbtbpre;
- if($type=='info')//信息
- {
- $lasttimef='lasttimeinfo';
- $lastnumf='lastnuminfo';
- $lastnumtbf='lastnuminfotb';
- }
- elseif($type=='pl')//评论
- {
- $lasttimef='lasttimepl';
- $lastnumf='lastnumpl';
- $lastnumtbf='lastnumpltb';
- }
- else
- {
- return '';
- }
- $time=time();
- $empire->query("update {$dbtbpre}enewspublic_up set ".$lasttimef."='$time',".$lastnumf."=0,".$lastnumtbf."='' limit 1");
- }
- //更新昨日信息数统计
- function DoUpdateYesterdayAddDataNum(){
- global $empire,$dbtbpre;
- $pur=$empire->fetch1("select * from {$dbtbpre}enewspublic_up limit 1");
- $todaydate=date('Y-m-d');
- if($todaydate==date('Y-m-d',$pur['todaytimeinfo'])&&$todaydate==date('Y-m-d',$pur['todaytimepl']))
- {
- return '';
- }
- $yesterdaynuminfo=$pur['todaynuminfo'];
- $yesterdaynumpl=$pur['todaynumpl'];
- if($todaydate<>date('Y-m-d',$pur['todaytimeinfo']+24*3600))
- {
- $yesterdaynuminfo=0;
- }
- if($todaydate<>date('Y-m-d',$pur['todaytimepl']+24*3600))
- {
- $yesterdaynumpl=0;
- }
- $time=time();
- $empire->query("update {$dbtbpre}enewspublic_up set todaytimeinfo='$time',todaytimepl='$time',todaynuminfo=0,yesterdaynuminfo='$yesterdaynuminfo',todaynumpl=0,yesterdaynumpl='$yesterdaynumpl' limit 1");
- }
- //返回栏目自定义字段内容
- function ReturnClassAddField($classid,$f){
- global $empire,$dbtbpre,$navclassid;
- if(empty($classid))
- {
- $classid=$navclassid;
- }
- $fr=$empire->fetch1("select ".$f." from {$dbtbpre}enewsclassadd where classid='$classid' limit 1");
- if(strstr($f,','))
- {
- return $fr;
- }
- else
- {
- return $fr[$f];
- }
- }
- //返回专题自定义字段内容
- function ReturnZtAddField($classid,$f){
- global $empire,$dbtbpre,$navclassid;
- if(empty($classid))
- {
- $classid=$navclassid;
- }
- $fr=$empire->fetch1("select ".$f." from {$dbtbpre}enewsztadd where ztid='$classid' limit 1");
- if(strstr($f,','))
- {
- return $fr;
- }
- else
- {
- return $fr[$f];
- }
- }
- //返回扩展变量值
- function ReturnPublicAddVar($myvar){
- global $empire,$dbtbpre;
- if(strstr($myvar,','))
- {
- $myvr=explode(',',$myvar);
- $count=count($myvr);
- for($i=0;$i<$count;$i++)
- {
- $v=$myvr[$i];
- $vr=$empire->fetch1("select varvalue from {$dbtbpre}enewspubvar where myvar='$v' limit 1");
- $ret_vr[$v]=$vr['varvalue'];
- }
- return $ret_vr;
- }
- else
- {
- $vr=$empire->fetch1("select varvalue from {$dbtbpre}enewspubvar where myvar='$myvar' limit 1");
- return $vr['varvalue'];
- }
- }
- //返回排序字段
- function ReturnDoOrderF($mid,$orderby,$myorder){
- global $emod_r;
- $orderby=str_replace(',','',$orderby);
- $orderf=',newstime,id,onclick,totaldown,plnum';
- if(!empty($emod_r[$mid]['orderf']))
- {
- $orderf.=$emod_r[$mid]['orderf'];
- }
- else
- {
- $orderf.=',';
- }
- if(strstr($orderf,','.$orderby.','))
- {
- $rr['returnorder']=$orderby;
- $rr['returnf']=$orderby;
- }
- else
- {
- $rr['returnorder']='newstime';
- $rr['returnf']='newstime';
- }
- if(empty($myorder))
- {
- $rr['returnorder'].=' desc';
- }
- return $rr;
- }
- //返回置顶
- function ReturnSetTopSql($ecms){
- global $public_r;
- if(empty($public_r['settop']))
- {
- return '';
- }
- $top='istop desc,';
- if($ecms=='list')
- {
- if($public_r['settop']==1||$public_r['settop']==4||$public_r['settop']==5||$public_r['settop']==6)
- {
- return $top;
- }
- }
- elseif($ecms=='bq')
- {
- if($public_r['settop']==2||$public_r['settop']==4||$public_r['settop']==5||$public_r['settop']==7)
- {
- return $top;
- }
- }
- elseif($ecms=='js')
- {
- if($public_r['settop']==3||$public_r['settop']==4||$public_r['settop']==6||$public_r['settop']==7)
- {
- return $top;
- }
- }
- return '';
- }
- //返回优化方案SQL
- function ReturnYhSql($yhid,$yhvar,$ecms=0){
- global $eyh_r;
- if(empty($yhid))
- {
- return '';
- }
- $query='';
- if($eyh_r[$yhid][$yhvar])
- {
- $t=time()-($eyh_r[$yhid][$yhvar]*86400);
- $query='newstime>'.$t.(empty($ecms)?'':' and ');
- }
- return $query;
- }
- //返回优化+条件SQL
- function ReturnYhAndSql($yhadd,$where,$ecms=0){
- if($yhadd.$where=='')
- {
- return '';
- }
- elseif($yhadd&&$where)
- {
- return $ecms==1?' where '.$yhadd.$where:' where '.$yhadd.' and '.$where;
- }
- elseif($yhadd&&!$where)
- {
- return ' where '.$yhadd;
- }
- else
- {
- return $ecms==1?' where '.substr($where,5):' where '.$where;
- }
- }
- //返回列表查询字段
- function ReturnSqlListF($mid){
- global $emod_r;
- if(empty($mid))
- {
- return '*';
- }
- $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);
- return $f;
- }
- //返回内容查询字段
- function ReturnSqlTextF($mid,$ecms=0){
- global $emod_r;
- if(empty($mid))
- {
- return '*';
- }
- $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);
- return $f;
- }
- //返回内容副表查询字段
- function ReturnSqlFtextF($mid){
- global $emod_r;
- if(empty($mid))
- {
- return '*';
- }
- $f='keyid,dokey,newstempid,closepl,infotags'.substr($emod_r[$mid]['tbdataf'],0,-1);
- return $f;
- }
- //返回信息表
- function ReturnInfoTbname($tbname,$checked=1,$stb=1){
- global $dbtbpre;
- if(empty($checked))//待审核
- {
- $r['tbname']=$dbtbpre.'ecms_'.$tbname.'_check';
- $r['datatbname']=$dbtbpre.'ecms_'.$tbname.'_check_data';
- }
- else//已审核
- {
- $r['tbname']=$dbtbpre.'ecms_'.$tbname;
- $r['datatbname']=$dbtbpre.'ecms_'.$tbname.'_data_'.$stb;
- }
- return $r;
- }
- //返回信息主表
- function ReturnInfoMainTbname($tbname,$checked=1){
- global $dbtbpre;
- return empty($checked)?$dbtbpre.'ecms_'.$tbname.'_check':$dbtbpre.'ecms_'.$tbname;
- }
- //返回信息副表
- function ReturnInfoDataTbname($tbname,$checked=1,$stb=1){
- global $dbtbpre;
- return empty($checked)?$dbtbpre.'ecms_'.$tbname.'_check_data':$dbtbpre.'ecms_'.$tbname.'_data_'.$stb;
- }
- //主表信息
- function ReturnIndexTableInfo($tbname,$f,$classid,$id){
- global $dbtbpre;
- $r=$empire->fetch1("select ".$f." from {$dbtbpre}ecms_".$tbname."_index where id='$id' limit 1");
- return $r;
- }
- //返回评论表名
- function eReturnRestb($restb){
- global $public_r,$dbtbpre;
- $restb=(int)$restb;
- if(!strstr($public_r['pldatatbs'],','.$restb.','))
- {
- $restb=$public_r['pldeftb'];
- }
- return $dbtbpre.'enewspl_'.$restb;
- }
- //返回附件表名
- function eReturnFstb($fstb){
- global $public_r,$dbtbpre;
- $fstb=(int)$fstb;
- if(!strstr($public_r['filedatatbs'],','.$fstb.','))
- {
- $fstb=$public_r['filedeftb'];
- }
- return $dbtbpre.'enewsfile_'.$fstb;
- }
- //返回公共表索引ID
- function ReturnInfoPubid($classid,$id,$tid=0){
- global $class_r;
- $classid=(int)$classid;
- $id=(int)$id;
- if(empty($tid))
- {
- $tid=$class_r[$classid]['tid'];
- }
- $tid=(int)$tid;
- $pubid='1'.ReturnAllInt($tid,5).ReturnAllInt($id,10);
- return $pubid;
- }
- //是否内部表
- function InfoIsInTable($tbname){
- global $etable_r;
- return $etable_r[$tbname]['intb']==1?true:false;
- }
- //检验字段是否存在
- function eCheckTbHaveField($tid,$tbname,$f){
- global $empire,$dbtbpre;
- $where=$tid?"tid='$tid' and ":"tbname='$tbname' and ";
- if(strstr($f,','))
- {
- $fr=explode(',',$f);
- $where.="f='".$fr[0]."' or f='".$fr[1]."'";
- }
- else
- {
- $where.="f='$f'";
- }
- $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where ".$where." limit 1");
- return $num;
- }
- //验证模板是否开启动态使用
- function DtTempIsClose($tempid,$type='listtemp'){
- global $public_r;
- if($type=='listtemp')//列表模板
- {
- if($public_r['closelisttemp']&&strstr(','.$public_r['closelisttemp'].',',','.$tempid.','))
- {
- echo'ListTempID='.$tempid.' is close.';
- exit();
- }
- }
- }
- //补零
- function ReturnAllInt($val,$num){
- $len=strlen($val);
- $zeronum=$num-$len;
- if($zeronum==1)
- {
- $val='0'.$val;
- }
- elseif($zeronum==2)
- {
- $val='00'.$val;
- }
- elseif($zeronum==3)
- {
- $val='000'.$val;
- }
- elseif($zeronum==4)
- {
- $val='0000'.$val;
- }
- elseif($zeronum==5)
- {
- $val='00000'.$val;
- }
- elseif($zeronum==6)
- {
- $val='000000'.$val;
- }
- elseif($zeronum==7)
- {
- $val='0000000'.$val;
- }
- elseif($zeronum==8)
- {
- $val='00000000'.$val;
- }
- elseif($zeronum==9)
- {
- $val='000000000'.$val;
- }
- elseif($zeronum==10)
- {
- $val='0000000000'.$val;
- }
- return $val;
- }
- //返回替换列表
- function ReturnReplaceListF($mid){
- global $emod_r;
- $r['mid']=$mid;
- $r['fr']=explode(',',$emod_r[$mid]['listtempf']);
- $r['fcount']=count($r['fr'])-1;
- return $r;
- }
- //返回替换内容
- function ReturnReplaceTextF($mid){
- global $emod_r;
- $r['mid']=$mid;
- $r['fr']=explode(',',$emod_r[$mid]['tempf']);
- $r['fcount']=count($r['fr'])-1;
- return $r;
- }
- //替换列表模板/标签模板/搜索模板
- function ReplaceListVars($no,$listtemp,$subnews,$subtitle,$formatdate,$url,$haveclass=0,$r,$field,$docode=0){
- global $empire,$public_r,$class_r,$class_zr,$fun_r,$dbtbpre,$emod_r,$class_tr,$level_r,$navclassid,$etable_r;
- if($haveclass)
- {
- $add=sys_ReturnBqClassname($r,$haveclass);
- }
- if(empty($r[oldtitle]))
- {
- $r[oldtitle]=$r[title];
- }
- if($docode==1)
- {
- $listtemp=stripSlashes($listtemp);
- eval($listtemp);
- }
- $ylisttemp=$listtemp;
- $mid=$field['mid'];
- $fr=$field['fr'];
- $fcount=$field['fcount'];
- for($i=1;$i<$fcount;$i++)
- {
- $f=$fr[$i];
- $value=$r[$f];
- $spf=0;
- if($f=='title')//标题
- {
- if(!empty($subtitle))//截取字符
- {
- $value=sub($value,0,$subtitle,false);
- }
- $value=DoTitleFont($r[titlefont],$value);
- $spf=1;
- }
- elseif($f=='newstime')//时间
- {
- //$value=date($formatdate,$value);
- $value=format_datetime($value,$formatdate);
- $spf=1;
- }
- elseif($f=='titlepic')//标题图片
- {
- if(empty($value))
- {
- $value=$public_r[newsurl].'e/data/images/notimg.gif';
- }
- $spf=1;
- }
- elseif(strstr($emod_r[$mid]['smalltextf'],','.$f.','))//简介
- {
- if(!empty($subnews))//截取字符
- {
- $value=sub($value,0,$subnews,false);
- }
- }
- elseif($f=='befrom')//信息来源
- {
- $spf=1;
- }
- elseif($f=='writer')//作者
- {
- $spf=1;
- }
- if($spf==0&&!strstr($emod_r[$mid]['editorf'],','.$f.','))
- {
- if(strstr($emod_r[$mid]['tobrf'],','.$f.','))//加br
- {
- $value=nl2br($value);
- }
- if(!strstr($emod_r[$mid]['dohtmlf'],','.$f.','))//去除html
- {
- $value=RepFieldtextNbsp(ehtmlspecialchars($value));
- }
- }
- $listtemp=str_replace('[!--'.$f.'--]',$value,$listtemp);
- }
- $titleurl=sys_ReturnBqTitleLink($r);//链接
- $listtemp=str_replace('[!--id--]',$r[id],$listtemp);
- $listtemp=str_replace('[!--classid--]',$r[classid],$listtemp);
- $listtemp=str_replace('[!--class.name--]',$add,$listtemp);
- $listtemp=str_replace('[!--ttid--]',$r[ttid],$listtemp);
- $listtemp=str_replace('[!--tt.name--]',$class_tr[$r[ttid]][tname],$listtemp);
- $listtemp=str_replace('[!--tt.url--]',sys_ReturnBqInfoTypeUrl($r['ttid']),$listtemp);
- $listtemp=str_replace('[!--userfen--]',$r[userfen],$listtemp);
- $listtemp=str_replace('[!--titleurl--]',$titleurl,$listtemp);
- $listtemp=str_replace('[!--no.num--]',$no,$listtemp);
- $listtemp=str_replace('[!--plnum--]',$r[plnum],$listtemp);
- $listtemp=str_replace('[!--userid--]',$r[userid],$listtemp);
- $listtemp=str_replace('[!--username--]',$r[username],$listtemp);
- $listtemp=str_replace('[!--onclick--]',$r[onclick],$listtemp);
- $listtemp=str_replace('[!--oldtitle--]',$r[oldtitle],$listtemp);
- $listtemp=str_replace('[!--totaldown--]',$r[totaldown],$listtemp);
- //栏目链接
- if(strstr($ylisttemp,'[!--this.classlink--]'))
- {
- $thisclasslink=sys_ReturnBqClassname($r,9);
- $listtemp=str_replace('[!--this.classlink--]',$thisclasslink,$listtemp);
- }
- $thisclassname=$class_r[$r[classid]][bname]?$class_r[$r[classid]][bname]:$class_r[$r[classid]][classname];
- $listtemp=str_replace('[!--this.classname--]',$thisclassname,$listtemp);
- return $listtemp;
- }
- //加上防复制字符
- function AddNotCopyRndStr($text){
- global $public_r;
- if($public_r['opencopytext'])
- {
- $rnd=make_password(3).$public_r['sitename'];
- $text=str_replace("<br />","<span style=\"display:none\">".$rnd."</span><br />",$text);
- $text=str_replace("</p>","<span style=\"display:none\">".$rnd."</span></p>",$text);
- }
- return $text;
- }
- //替换信息来源
- function ReplaceBefrom($befrom){
- global $empire,$dbtbpre;
- if(empty($befrom))
- {return $befrom;}
- $befrom=addslashes($befrom);
- $r=$empire->fetch1("select befromid,sitename,siteurl from {$dbtbpre}enewsbefrom where sitename='$befrom' limit 1");
- if(empty($r[befromid]))
- {return $befrom;}
- $return_befrom="<a href='".$r[siteurl]."' target=_blank>".$r[sitename]."</a>";
- return $return_befrom;
- }
- //替换作者
- function ReplaceWriter($writer){
- global $empire,$dbtbpre;
- if(empty($writer))
- {return $writer;}
- $writer=addslashes($writer);
- $r=$empire->fetch1("select wid,writer,email from {$dbtbpre}enewswriter where writer='$writer' limit 1");
- if(empty($r[wid])||empty($r[email]))
- {
- return $writer;
- }
- $return_writer="<a href='".$r[email]."'>".$r[writer]."</a>";
- return $return_writer;
- }
- //备份下载记录
- function BakDown($classid,$id,$pathid,$userid,$username,$title,$cardfen,$online=0){
- global $empire,$dbtbpre;
- $truetime=time();
- $id=(int)$id;
- $pathid=(int)$pathid;
- $userid=(int)$userid;
- $cardfen=(int)$cardfen;
- $classid=(int)$classid;
- $username=RepPostVar($username);
- $title=RepPostStr($title);
- $online=addslashes(RepPostStr($online));
- $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');");
- }
- //备份充值记录
- function BakBuy($userid,$username,$buyname,$userfen,$money,$userdate,$type=0){
- global $empire,$dbtbpre;
- $buytime=date("y-m-d H:i:s");
- $buyname=addslashes(RepPostStr($buyname));
- $userid=(int)$userid;
- $username=RepPostVar($username);
- $userfen=addslashes(RepPostStr($userfen));
- $money=addslashes(RepPostStr($money));
- $userdate=addslashes(RepPostStr($userdate));
- $type=addslashes(RepPostStr($type));
- $empire->query("insert into {$dbtbpre}enewsbuybak(userid,username,card_no,cardfen,money,buytime,userdate,type) values('$userid','$username','$buyname','$userfen','$money','$buytime','$userdate','$type');");
- }
- //发送短消息
- function eSendMsg($title,$msgtext,$to_username,$from_userid,$from_username,$isadmin,$issys,$ecms=0){
- global $empire,$dbtbpre;
- $tbname=$ecms==1?$dbtbpre.'enewshmsg':$dbtbpre.'enewsqmsg';
- $to_username=RepPostVar($to_username);
- $from_userid=(int)$from_userid;
- $from_username=RepPostVar($from_username);
- $isadmin=(int)$isadmin;
- $issys=(int)$issys;
- $msgtime=date("Y-m-d H:i:s");
- $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');");
- //消息状态
- $userr=$empire->fetch1("select ".eReturnSelectMemberF('userid,havemsg')." from ".eReturnMemberTable()." where ".egetmf('username')."='$to_username' limit 1");
- if(!$userr['havemsg'])
- {
- $newhavemsg=eReturnSetHavemsg($userr['havemsg'],0);
- $empire->query("update ".eReturnMemberTable()." set ".egetmf('havemsg')."='$newhavemsg' where ".egetmf('userid')."='".$userr['userid']."' limit 1");
- }
- }
- //发送通知
- function eSendNotice($title,$msgtext,$to_username,$from_userid,$from_username,$ecms=0){
- global $empire,$dbtbpre;
- $tbname=$ecms==1?$dbtbpre.'enewshnotice':$dbtbpre.'enewsnotice';
- $to_username=RepPostVar($to_username);
- $from_userid=(int)$from_userid;
- $from_username=RepPostVar($from_username);
- $msgtime=date("Y-m-d H:i:s");
- $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');");
- }
- //截取简介
- function SubSmalltextVal($value,$len){
- if(empty($len))
- {
- return '';
- }
- $value=str_replace(array("\r\n","<br />","<br>"," ","[!--empirenews.page--]","[/!--empirenews.page--]"),array("","\r\n","\r\n"," ","",""),$value);
- $value=strip_tags($value);
- if($len)
- {
- $value=sub($value,0,$len,false);
- }
- $value=trim($value,"\r\n");
- $value=str_replace('&ldquo;','“',$value);
- $value=str_replace('&rdquo;','”',$value);
- $value=str_replace('&mdash;','—',$value);
- return $value;
- }
- //全站搜索简介
- function SubSchallSmalltext($value,$len){
- $value=str_replace(array("\r\n"," ","[!--empirenews.page--]","[/!--empirenews.page--]"),array("","","",""),$value);
- $value=strip_tags($value);
- if($len)
- {
- $value=sub($value,0,$len,false);
- }
- $value=trim($value,"\r\n");
- return $value;
- }
- //加红替换
- function DoReplaceFontRed($text,$key){
- return str_replace($key,'<font color="red">'.$key.'</font>',$text);
- }
- //返回不生成html的栏目
- function ReturnNreInfoWhere(){
- global $public_r;
- if(empty($public_r['nreinfo'])||$public_r['nreinfo']==',')
- {
- return '';
- }
- $cids=substr($public_r['nreinfo'],1,strlen($public_r['nreinfo'])-2);
- $where=' and classid not in ('.$cids.')';
- return $where;
- }
- //返回标签不调用栏目
- function ReturnNottoBqWhere(){
- global $public_r;
- if(empty($public_r['nottobq'])||$public_r['nottobq']==',')
- {
- return '';
- }
- $cids=substr($public_r['nottobq'],1,strlen($public_r['nottobq'])-2);
- $where='classid not in ('.$cids.')';
- return $where;
- }
- //返回文件名及扩展名
- function ReturnCFiletype($file){
- $r=explode('.',$file);
- $count=count($r)-1;
- $re['filetype']=strtolower($r[$count]);
- $re['filename']=substr($file,0,strlen($file)-strlen($re['filetype'])-1);
- return $re;
- }
- //返回栏目目录
- function ReturnSaveClassPath($classid,$f=0){
- global $class_r;
- $classpath=$class_r[$classid][classpath];
- if($f==1){
- $classpath.="/index".$class_r[$classid][classtype];
- }
- return $classpath;
- }
- //返回专题目录
- function ReturnSaveZtPath($classid,$f=0){
- global $class_zr;
- $classpath=$class_zr[$classid][ztpath];
- if($f==1){
- $classpath.="/index".$class_zr[$classid][zttype];
- }
- return $classpath;
- }
- //返回标题分类目录
- function ReturnSaveInfoTypePath($classid,$f=0){
- global $class_tr;
- $classpath=$class_tr[$classid]['tpath'];
- if($f==1){
- $classpath.='/index'.$class_tr[$classid]['ttype'];
- }
- return $classpath;
- }
- //返回首页文件
- function ReturnSaveIndexFile(){
- global $public_r;
- $file='index'.$public_r[indextype];
- return $file;
- }
- //返回首页地址
- function ReturnSiteIndexUrl(){
- global $public_r;
- if(empty($public_r['indexaddpage']))
- {
- return $public_r['newsurl'];
- }
- if($public_r['indexpagedt']||Moreport_ReturnMustDt())//moreport
- {
- $public_r['indextype']='.php';
- }
- $file=$public_r['newsurl'].'index'.$public_r['indextype'];
- return $file;
- }
- //返回内容页存放目录
- function ReturnSaveInfoPath($classid,$id){
- global $class_r;
- if($class_r[$classid][ipath]==''){
- $path=$class_r[$classid][classpath].'/';
- }
- else{
- $path=$class_r[$classid][ipath]=='/'?'':$class_r[$classid][ipath].'/';
- }
- return $path;
- }
- //返回内容页文件名
- function GetInfoFilename($classid,$id){
- global $empire,$dbtbpre,$public_r,$class_r;
- $infor=$empire->fetch1("select isurl,groupid,classid,newspath,filename,id from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' limit 1");
- if(!$infor['id']||$infor['isurl'])
- {
- return '';
- }
- $filetype=$infor['groupid']?'.php':$class_r[$classid]['filetype'];
- $iclasspath=ReturnSaveInfoPath($classid,$id);
- $doclasspath=eReturnTrueEcmsPath().$iclasspath;//moreport
- $newspath='';
- if($infor['newspath'])
- {
- $newspath=$infor['newspath'].'/';
- }
- $file=$doclasspath.$newspath.$infor['filename'].$filetype;
- return $file;
- }
- //格式化信息目录
- function FormatPath($classid,$mynewspath,$enews=0){
- global $class_r;
- if($enews)
- {
- $newspath=$mynewspath;
- }
- else
- {
- $newspath=date($class_r[$classid][newspath]);
- }
- if(empty($newspath))
- {
- return "";
- }
- $path=eReturnTrueEcmsPath().ReturnSaveInfoPath($classid,$id);
- if(file_exists($path.$newspath))
- {
- return $newspath;
- }
- $returnpath="";
- $r=explode("/",$newspath);
- $count=count($r);
- for($i=0;$i<$count;$i++){
- if($i>0)
- {
- $returnpath.="/".$r[$i];
- }
- else
- {
- $returnpath.=$r[$i];
- }
- $createpath=$path.$returnpath;
- $mk=DoMkdir($createpath);
- if(empty($mk))
- {
- printerror("CreatePathFail","");
- }
- }
- return $returnpath;
- }
- //返回内容页目录
- function ReturnInfoSPath($filename){
- return str_replace('/index','',$filename);
- }
- //返回根目录
- function ReturnAbsEcmsPath(){
- $ecmspath=str_replace("\\","/",ECMS_PATH);
- return $ecmspath;
- }
- //返回当前根目录
- function eReturnTrueEcmsPath(){
- if(defined('ECMS_SELFPATH'))
- {
- return ECMS_SELFPATH;
- }
- else
- {
- return ECMS_PATH;
- }
- }
- //返回主端根目录
- function eReturnEcmsMainPortPath(){
- global $ecms_config;
- if($ecms_config['sets']['mainportpath'])
- {
- return $ecms_config['sets']['mainportpath'];
- }
- else
- {
- return ECMS_PATH;
- }
- }
- //------------- 附件 -------------
- //返回附件分表
- function eReturnFileStb($fstb){
- global $public_r;
- $fstb=(int)$fstb;
- if(!strstr($public_r['filedatatbs'],','.$fstb.','))
- {
- $fstb=$public_r['filedeftb'];
- }
- return $fstb;
- }
- //返回附件表
- function eReturnFileTable($modtype,$fstb){
- global $dbtbpre;
- if($modtype==0)//信息
- {
- $fstb=eReturnFileStb($fstb);
- $table=$dbtbpre.'enewsfile_'.$fstb;
- }
- elseif($modtype==5)//公共
- {
- $table=$dbtbpre.'enewsfile_public';
- }
- elseif($modtype==6)//会员
- {
- $table=$dbtbpre.'enewsfile_member';
- }
- else//其他
- {
- $table=$dbtbpre.'enewsfile_other';
- }
- return $table;
- }
- //查询附件表
- function eSelectFileTable($modtype,$fstb,$selectf,$where){
- global $dbtbpre;
- $query="select {$selectf} from ".eReturnFileTable($modtype,$fstb)." where ".$where;
- return $query;
- }
- //写入附件记录
- function eInsertFileTable($filename,$filesize,$path,$adduser,$classid,$no,$type,$id,$cjid,$fpath,$pubid,$modtype=0,$fstb=1){
- global $empire,$dbtbpre,$public_r;
- $filetime=time();
- $filesize=(int)$filesize;
- $classid=(int)$classid;
- $id=(int)$id;
- $cjid=(int)$cjid;
- $fpath=(int)$fpath;
- $type=(int)$type;
- $modtype=(int)$modtype;
- $filename=addslashes(RepPostStr($filename));
- $no=addslashes(RepPostStr($no));
- $adduser=RepPostVar($adduser);
- $path=addslashes(RepPostStr($path));
- $pubid=RepPostVar($pubid);
- $fstb=(int)$fstb;
- if($modtype==0)//信息
- {
- $fstb=eReturnFileStb($fstb);
- $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');");
- }
- elseif($modtype==5)//公共
- {
- $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');");
- }
- elseif($modtype==6)//会员
- {
- $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');");
- }
- else//其他
- {
- $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');");
- }
- return $sql;
- }
- //更新相应的附件(非信息)
- function UpdateTheFileOther($modtype,$id,$checkpass,$tb='other'){
- global $empire,$dbtbpre;
- if(empty($id)||empty($checkpass))
- {
- return "";
- }
- $id=(int)$id;
- $checkpass=(int)$checkpass;
- $where='';
- if($tb=='other')
- {
- $where=" and modtype='$modtype'";
- }
- $sql=$empire->query("update {$dbtbpre}enewsfile_{$tb} set id='$id',cjid=0 where cjid='$checkpass'".$where);
- }
- //修改时更新附件(非信息)
- function UpdateTheFileEditOther($modtype,$id,$tb='other'){
- global $empire,$dbtbpre;
- $where='';
- if($tb=='other')
- {
- $where=" and modtype='$modtype'";
- }
- $sql=$empire->query("update {$dbtbpre}enewsfile_{$tb} set cjid=0 where id='$id'".$where);
- }
- //返回filepass
- function ReturnTranFilepass(){
- $filepass=time();
- return $filepass;
- }
- //返回附件域名地址
- function eReturnFileUrl($ecms=0){
- global $public_r;
- if($ecms==1)
- {
- return $public_r['fileurl'];
- }
- $fileurl=$public_r['openfileserver']?$public_r['fs_purl']:$public_r['fileurl'];
- return $fileurl;
- }
- //返回附件目录
- function ReturnFileSavePath($classid,$fpath=''){
- global $public_r,$class_r;
- $fpath=$fpath||strstr(','.$fpath.',',',0,')?$fpath:$public_r['fpath'];
- $efileurl=eReturnFileUrl();
- if($fpath==1)//p目录
- {
- $r['filepath']='d/file/p/';
- $r['fileurl']=$efileurl.'p/';
- }
- elseif($fpath==2)//file目录
- {
- $r['filepath']='d/file/';
- $r['fileurl']=$efileurl;
- }
- else
- {
- if(empty($classid))
- {
- $r['filepath']='d/file/p/';
- $r['fileurl']=$efileurl.'p/';
- }
- else
- {
- $r['filepath']='d/file/'.$class_r[$classid][classpath].'/';
- $r['fileurl']=$efileurl.$class_r[$classid][classpath].'/';
- }
- }
- return $r;
- }
- //格式化附件目录
- function FormatFilePath($classid,$mynewspath,$enews=0){
- global $public_r;
- if($enews)
- {
- $newspath=$mynewspath;
- }
- else
- {
- $newspath=date($public_r['filepath']);
- }
- if(empty($newspath))
- {
- return "";
- }
- $fspath=ReturnFileSavePath($classid);
- $path=eReturnEcmsMainPortPath().$fspath['filepath'];//moreport
- if(file_exists($path.$newspath))
- {
- return $newspath;
- }
- $returnpath="";
- $r=explode("/",$newspath);
- $count=count($r);
- for($i=0;$i<$count;$i++){
- if($i>0){
- $returnpath.="/".$r[$i];
- }
- else{
- $returnpath.=$r[$i];
- }
- $createpath=$path.$returnpath;
- $mk=DoMkdir($createpath);
- if(empty($mk)){
- printerror("CreatePathFail","");
- }
- }
- return $returnpath;
- }
- //返回上传文件名
- function ReturnDoTranFilename($file_name,$classid){
- $filename=md5(uniqid(microtime()).EcmsRandInt());
- return $filename;
- }
- //上传文件
- function DoTranFile($file,$file_name,$file_type,$file_size,$classid,$ecms=0){
- global $public_r,$class_r,$doetran,$efileftp_fr;
- $classid=(int)$classid;
- //文件类型
- $r[filetype]=GetFiletype($file_name);
- //文件名
- $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
- $r[filename]=$r[insertfile].$r[filetype];
- //日期目录
- $r[filepath]=FormatFilePath($classid,$mynewspath,0);
- $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
- //存放目录
- $fspath=ReturnFileSavePath($classid);
- $r[savepath]=eReturnEcmsMainPortPath().$fspath['filepath'].$filepath;//moreport
- //附件地址
- $r[url]=$fspath['fileurl'].$filepath.$r[filename];
- //缩图文件
- $r[name]=$r[savepath]."small".$r[insertfile];
- //附件文件
- $r[yname]=$r[savepath].$r[filename];
- $r[tran]=1;
- //验证类型
- if(CheckSaveTranFiletype($r[filetype]))
- {
- if($doetran)
- {
- $r[tran]=0;
- return $r;
- }
- else
- {
- printerror('TranFail','',$ecms);
- }
- }
- //上传文件
- $cp=@move_uploaded_file($file,$r[yname]);
- if(empty($cp))
- {
- if($doetran)
- {
- $r[tran]=0;
- return $r;
- }
- else
- {
- printerror('TranFail','',$ecms);
- }
- }
- DoChmodFile($r[yname]);
- $r[filesize]=(int)$file_size;
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_fr[]=$r['yname'];
- }
- return $r;
- }
- //远程保存忽略地址
- function CheckNotSaveUrl($url){
- global $public_r;
- if(empty($public_r['notsaveurl']))
- {
- return 0;
- }
- $r=explode("\r\n",$public_r['notsaveurl']);
- $count=count($r);
- $re=0;
- for($i=0;$i<$count;$i++)
- {
- if(empty($r[$i]))
- {continue;}
- if(stristr($url,$r[$i]))
- {
- $re=1;
- break;
- }
- }
- return $re;
- }
- //远程保存
- function DoTranUrl($url,$classid){
- global $public_r,$class_r,$ecms_config,$efileftp_fr;
- $classid=(int)$classid;
- //处理地址
- $url=trim($url);
- $url=str_replace(" ","%20",$url);
- $r[tran]=1;
- //附件地址
- $r[url]=$url;
- //文件类型
- $r[filetype]=GetFiletype($url);
- if(CheckSaveTranFiletype($r[filetype]))
- {
- $r[tran]=0;
- return $r;
- }
- //是否已上传的文件
- $havetr=CheckNotSaveUrl($url);
- if($havetr)
- {
- $r[tran]=0;
- return $r;
- }
- //是否地址
- if(!strstr($url,'://'))
- {
- $r[tran]=0;
- return $r;
- }
- if(!eToCheckIsUrl2($url))
- {
- $r[tran]=0;
- return $r;
- }
- $string=ReadFiletext($url);
- if(empty($string))//读取不了
- {
- $r[tran]=0;
- return $r;
- }
- //文件名
- $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
- $r[filename]=$r[insertfile].$r[filetype];
- //日期目录
- $r[filepath]=FormatFilePath($classid,$mynewspath,0);
- $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
- //存放目录
- $fspath=ReturnFileSavePath($classid);
- $r[savepath]=eReturnEcmsMainPortPath().$fspath['filepath'].$filepath;//moreport
- //附件地址
- $r[url]=$fspath['fileurl'].$filepath.$r[filename];
- //缩图文件
- $r[name]=$r[savepath]."small".$r[insertfile];
- //附件文件
- $r[yname]=$r[savepath].$r[filename];
- WriteFiletext_n($r[yname],$string);
- $r[filesize]=@filesize($r[yname]);
- //返回类型
- if(strstr($ecms_config['sets']['tranflashtype'],','.$r[filetype].','))
- {
- $r[type]=2;
- }
- elseif(strstr($ecms_config['sets']['tranpicturetype'],','.$r[filetype].','))
- {
- $r[type]=1;
- }
- elseif(strstr($ecms_config['sets']['mediaplayertype'],','.$r[filetype].',')||strstr($ecms_config['sets']['realplayertype'],','.$r[filetype].','))//多媒体
- {
- $r[type]=3;
- }
- else
- {
- $r[type]=0;
- }
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_fr[]=$r['yname'];
- }
- return $r;
- }
- //删除附件
- function DoDelFile($r){
- global $class_r,$public_r,$efileftp_dr;
- $path=$r['path']?$r['path'].'/':$r['path'];
- $fspath=ReturnFileSavePath($r[classid],$r[fpath]);
- $delfile=eReturnEcmsMainPortPath().$fspath['filepath'].$path.$r['filename'];//moreport
- DelFiletext($delfile);
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_dr[]=$delfile;
- }
- }
- //替换表前缀
- function RepSqlTbpre($sql){
- global $dbtbpre;
- $sql=str_replace('[!db.pre!]',$dbtbpre,$sql);
- return $sql;
- }
- //反替换表前缀
- function ReRepSqlTbpre($sql){
- global $dbtbpre;
- $sql=str_replace($dbtbpre,'***_',$sql);
- return $sql;
- }
- //验证表是否存在
- function eCheckTbname($tbname){
- global $empire,$dbtbpre;
- $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
- return $num;
- }
- //时间转换
- function ToChangeUseTime($time){
- global $fun_r;
- $usetime=time()-$time;
- if($usetime<60)
- {
- $tstr=$usetime.$fun_r['TimeSecond'];
- }
- else
- {
- $usetime=round($usetime/60);
- $tstr=$usetime.$fun_r['TimeMinute'];
- }
- return $tstr;
- }
- //返回栏目集合
- function ReturnClass($sonclass){
- if($sonclass==''||$sonclass=='|'){
- return 'classid=0';
- }
- $where='classid in ('.RepSonclassSql($sonclass).')';
- return $where;
- }
- //替换子栏目子
- function RepSonclassSql($sonclass){
- if($sonclass==''||$sonclass=='|'){
- return 0;
- }
- $sonclass=substr($sonclass,1,strlen($sonclass)-2);
- $sonclass=str_replace('|',',',$sonclass);
- return $sonclass;
- }
- //返回多栏目
- function sys_ReturnMoreClass($sonclass,$son=0){
- global $class_r;
- $r=explode(',',$sonclass);
- $count=count($r);
- $return_r[0]=intval($r[0]);
- $where='';
- $or='';
- for($i=0;$i<$count;$i++)
- {
- $r[$i]=intval($r[$i]);
- if($son==1)
- {
- if($class_r[$r[$i]]['tbname']&&!$class_r[$r[$i]]['islast'])
- {
- $where.=$or."classid in (".RepSonclassSql($class_r[$r[$i]]['sonclass']).")";
- }
- else
- {
- $where.=$or."classid='".$r[$i]."'";
- }
- }
- else
- {
- $where.=$or."classid='".$r[$i]."'";
- }
- $or=' or ';
- }
- $return_r[1]=$where;
- return $return_r;
- }
- //返回多专题
- function sys_ReturnMoreZt($zt,$ecms=0){
- $f=$ecms==1?'ztid':'cid';
- $r=explode(',',$zt);
- $count=count($r);
- $return_r[0]=intval($r[0]);
- $ids='';
- $dh='';
- for($i=0;$i<$count;$i++)
- {
- $r[$i]=intval($r[$i]);
- $ids.=$dh.$r[$i];
- $dh=',';
- }
- $return_r[1]=$f.' in ('.$ids.')';
- return $return_r;
- }
- //返回多标题分类
- function sys_ReturnMoreTT($tt){
- $r=explode(',',$tt);
- $count=count($r);
- $return_r[0]=intval($r[0]);
- $ids='';
- $dh='';
- for($i=0;$i<$count;$i++)
- {
- $r[$i]=intval($r[$i]);
- $ids.=$dh.$r[$i];
- $dh=',';
- }
- $return_r[1]='ttid in ('.$ids.')';
- return $return_r;
- }
- //验证是否包含栏目
- function CheckHaveInClassid($cr,$checkclass){
- global $class_r;
- if($cr['islast'])
- {
- $chclass='|'.$cr['classid'].'|';
- }
- else
- {
- $chclass=$cr['sonclass'];
- }
- $return=0;
- $r=explode('|',$chclass);
- $count=count($r);
- for($i=1;$i<$count-1;$i++)
- {
- if(strstr($checkclass,'|'.$r[$i].'|'))
- {
- $return=1;
- break;
- }
- }
- return $return;
- }
- //返回加前缀的下载地址
- function ReturnDownQzPath($path,$urlid){
- global $empire,$dbtbpre;
- $urlid=(int)$urlid;
- if(empty($urlid))
- {
- $re['repath']=$path;
- $re['downtype']=0;
- }
- else
- {
- $r=$empire->fetch1("select urlid,url,downtype from {$dbtbpre}enewsdownurlqz where urlid='$urlid'");
- if($r['urlid'])
- {
- $re['repath']=$r['url'].$path;
- }
- else
- {
- $re['repath']=$path;
- }
- $re['downtype']=$r['downtype'];
- }
- return $re;
- }
- //返回带防盗链的绝对地址
- function ReturnDSofturl($downurl,$qz,$path='../../',$isdown=0){
- $urlr=ReturnDownQzPath(stripSlashes($downurl),$qz);
- $url=$urlr['repath'];
- @include_once(ECMS_PATH."e/DownSys/class/enpath.php");//防盗链
- if($isdown)
- {
- $url=DoEnDownpath($url);
- }
- else
- {
- $url=DoEnOnlinepath($url);
- }
- return $url;
- }
- //验证提交来源
- function CheckCanPostUrl(){
- global $public_r;
- if($public_r['canposturl'])
- {
- $r=explode("\r\n",$public_r['canposturl']);
- $count=count($r);
- $b=0;
- for($i=0;$i<$count;$i++)
- {
- if(strstr($_SERVER['HTTP_REFERER'],$r[$i]))
- {
- $b=1;
- break;
- }
- }
- if($b==0)
- {
- printerror('NotCanPostUrl','',1);
- }
- }
- }
- //adminpath
- function eGetSelfAdminPath(){
- $selfpath=eReturnSelfPage(0);
- $selfpath=str_replace("\\","/",$selfpath);
- if(strstr($selfpath,'//'))
- {
- exit();
- }
- $pr=explode('/e/',$selfpath);
- $pr2=explode('/',$pr[1]);
- $adminpath=$pr2[0];
- if(empty($adminpath))
- {
- exit();
- }
- return $adminpath;
- }
- //特殊来源验证
- function hCheckSpFromUrl(){
- if(defined('EmpireCMSSpFromUrl'))
- {
- return '';
- }
- $spurl=',AddNews.php,ShowInfo.php,ShowWfInfo.php,EditCjNews.php,infoeditor,';
- $r=explode(',',$spurl);
- $count=count($r);
- $fromurl=$_SERVER['HTTP_REFERER'];
- for($i=1;$i<$count;$i++)
- {
- if(empty($r[$i]))
- {
- continue;
- }
- if(stristr($fromurl,$r[$i]))
- {
- printerror("FailHash","history.go(-1)");
- }
- }
- }
- //设定特殊来源
- function hSetSpFromUrl(){
- define('EmpireCMSSpFromUrl',TRUE);
- }
- //验证来源
- function DoSafeCheckFromurl(){
- global $ecms_config;
- if($ecms_config['esafe']['ckfromurl']==0||defined('EmpireCMSNFPage'))//不启用
- {
- return '';
- }
- $fromurl=$_SERVER['HTTP_REFERER'];
- if(!$fromurl)
- {
- return '';
- }
- $domain=eReturnDomain();
- if($ecms_config['esafe']['ckfromurl']==1)//全部启用
- {
- if(!stristr($fromurl,$domain))
- {
- echo"";
- exit();
- }
- }
- elseif($ecms_config['esafe']['ckfromurl']==2)//后台启用
- {
- if(defined('EmpireCMSAdmin')&&!stristr($fromurl,$domain.'/'))
- {
- echo"";
- exit();
- }
- }
- elseif($ecms_config['esafe']['ckfromurl']==3)//前台启用
- {
- if(!defined('EmpireCMSAdmin')&&!stristr($fromurl,$domain))
- {
- echo"";
- exit();
- }
- }
- elseif($ecms_config['esafe']['ckfromurl']==4)//全部启用(严格)
- {
- if(!stristr($fromurl,$domain))
- {
- echo"";
- exit();
- }
- if(defined('EmpireCMSAdmin'))
- {
- $adminpath=eGetSelfAdminPath();
- if(!stristr($fromurl,'/e/'.$adminpath.'/'))
- {
- echo"";
- exit();
- }
- }
- }
- elseif($ecms_config['esafe']['ckfromurl']==5)//后台启用(严格)
- {
- if(defined('EmpireCMSAdmin'))
- {
- if(!stristr($fromurl,$domain.'/'))
- {
- echo"";
- exit();
- }
- $adminpath=eGetSelfAdminPath();
- if(!stristr($fromurl,'/e/'.$adminpath.'/'))
- {
- echo"";
- exit();
- }
- }
- }
- elseif($ecms_config['esafe']['ckfromurl']==6)//前台启用(严格)
- {
- if(!defined('EmpireCMSAdmin')&&!stristr($fromurl,$domain))
- {
- echo"";
- exit();
- }
- }
- }
- //验证agent信息
- function EcmsCheckUserAgent($ckstr){
- if(empty($ckstr))
- {
- return '';
- }
- $userinfo=$_SERVER['HTTP_USER_AGENT'];
- $cr=explode('||',$ckstr);
- $count=count($cr);
- for($i=0;$i<$count;$i++)
- {
- if(empty($cr[$i]))
- {
- continue;
- }
- if(!strstr($userinfo,$cr[$i]))
- {
- //echo'Userinfo Error';
- exit();
- }
- }
- }
- //验证IP
- function eCheckAccessIp($ecms=0){
- global $public_r;
- $userip=egetip();
- if($ecms)//后台
- {
- //允许IP
- if($public_r['hopenip'])
- {
- $close=1;
- foreach(explode("\n",$public_r['hopenip']) as $ctrlip)
- {
- if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
- {
- $close=0;
- break;
- }
- }
- if($close==1)
- {
- echo"Ip<font color='#cccccc'>(".$userip.")</font> be prohibited.";
- exit();
- }
- }
- }
- else
- {
- //允许IP
- if($public_r['openip'])
- {
- $close=1;
- foreach(explode("\n",$public_r['openip']) as $ctrlip)
- {
- if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
- {
- $close=0;
- break;
- }
- }
- if($close==1)
- {
- echo"Ip<font color='#cccccc'>(".$userip.")</font> be prohibited.";
- exit();
- }
- }
- //禁止IP
- if($public_r['closeip'])
- {
- foreach(explode("\n",$public_r['closeip']) as $ctrlip)
- {
- if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
- {
- echo"Ip<font color='#cccccc'>(".$userip.")</font> be prohibited.";
- exit();
- }
- }
- }
- }
- }
- //验证提交IP
- function eCheckAccessDoIp($doing){
- global $public_r,$empire,$dbtbpre;
- $pr=$empire->fetch1("select opendoip,closedoip,doiptype from {$dbtbpre}enewspublic limit 1");
- if(!strstr($pr['doiptype'],','.$doing.','))
- {
- return '';
- }
- $userip=egetip();
- //允许IP
- if($pr['opendoip'])
- {
- $close=1;
- foreach(explode("\n",$pr['opendoip']) as $ctrlip)
- {
- if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
- {
- $close=0;
- break;
- }
- }
- if($close==1)
- {
- printerror('NotCanPostIp','history.go(-1)',1);
- }
- }
- //禁止IP
- if($pr['closedoip'])
- {
- foreach(explode("\n",$pr['closedoip']) as $ctrlip)
- {
- if(preg_match("/^(".preg_quote(($ctrlip=trim($ctrlip)),'/').")/",$userip))
- {
- printerror('NotCanPostIp','history.go(-1)',1);
- }
- }
- }
- }
- //验证是否关闭相关模块
- function eCheckCloseMods($mod){
- global $public_r;
- if(strstr($public_r['closemods'],','.$mod.','))
- {
- echo $mod.' is close';
- exit();
- }
- }
- //验证操作时间
- function eCheckTimeCloseDo($ecms){
- global $public_r;
- if(stristr($public_r['timeclosedo'],','.$ecms.','))
- {
- $h=date('G');
- if(strstr($public_r['timeclose'],','.$h.','))
- {
- printerror('ThisTimeCloseDo','history.go(-1)',1);
- }
- }
- }
- //验证外部登录是否开启
- function eCheckCloseMemberConnect(){
- global $public_r;
- if(!$public_r['memberconnectnum'])
- {
- printerror('NotOpenMemberConnect','history.go(-1)',1);
- }
- }
- //过滤
- function ClearNewsBadCode($text){
- $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('<script','</script>','<link','<iframe','</iframe>','<meta','<body','<style','</style>',' one rror','<marquee','</marquee>','<!---ecms ',' onl oad',' onm ouse','<frame','<frameset'),$text);
- return $text;
- }
- //验证包含字符
- function toCheckCloseWord($word,$closestr,$mess){
- if($closestr&&$closestr!='|')
- {
- $checkr=explode('|',$closestr);
- $ckcount=count($checkr);
- for($i=0;$i<$ckcount;$i++)
- {
- if($checkr[$i])
- {
- if(stristr($checkr[$i],'##'))//多字
- {
- $morer=explode('##',$checkr[$i]);
- if(stristr($word,$morer[0])&&stristr($word,$morer[1]))
- {
- printerror($mess,"history.go(-1)",1);
- }
- }
- else
- {
- if(stristr($word,$checkr[$i]))
- {
- printerror($mess,"history.go(-1)",1);
- }
- }
- }
- }
- }
- }
- //替换评论表情
- function RepPltextFace($text){
- global $public_r;
- if(empty($public_r['plface'])||$public_r['plface']=='||')
- {
- return $text;
- }
- $facer=explode('||',$public_r['plface']);
- $count=count($facer);
- for($i=1;$i<$count-1;$i++)
- {
- $r=explode('##',$facer[$i]);
- $text=str_replace($r[0],"<img src='".$public_r['newsurl']."e/data/face/".$r[1]."' border=0>",$text);
- }
- return $text;
- }
- //替换空格
- function RepFieldtextNbsp($text){
- return str_replace(array("\t",' ',' '),array(' ',' ',' '),$text);
- }
- //保留扩展名验证
- function CheckSaveTranFiletype($filetype){
- $savetranfiletype=',.php,.php3,.php4,.php5,.php6,.asp,.aspx,.jsp,.cgi,.phtml,.asa,.asax,.fcgi,.pl,.ascx,.ashx,.cer,.cdx,.pht,.shtml,.shtm,.stm,';
- if(stristr($savetranfiletype,','.$filetype.','))
- {
- return true;
- }
- return false;
- }
- //设置验证码
- function ecmsSetShowKey($varname,$val,$ecms=0,$isadmin=0){
- global $public_r;
- $pubkeyrnd=$isadmin==1?$public_r['hkeyrnd']:$public_r['keyrnd'];
- $time=time();
- $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');
- $key=$time.','.$checkpass.',EmpireCMS';
- esetcookie($varname,$key,0,$ecms);
- }
- //检查验证码
- function ecmsCheckShowKey($varname,$postval,$dopr,$ecms=0,$isadmin=0){
- global $public_r;
- $postval=trim($postval);
- if($isadmin==1)
- {
- $pubkeytime=$public_r['hkeytime'];
- $pubkeyrnd=$public_r['hkeyrnd'];
- }
- else
- {
- $pubkeytime=$public_r['keytime'];
- $pubkeyrnd=$public_r['keyrnd'];
- }
- $r=explode(',',getcvar($varname,$ecms));
- $cktime=(int)$r[0];
- $pass=$r[1];
- $val=$r[2];
- $time=time();
- if($cktime>$time||$time-$cktime>$pubkeytime)
- {
- printerror('OutKeytime','',$dopr);
- }
- if(empty($postval))
- {
- printerror('FailKey','',$dopr);
- }
- $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');
- if('dg'.$checkpass<>'dg'.$pass)
- {
- printerror('FailKey','',$dopr);
- }
- }
- //清空验证码
- function ecmsEmptyShowKey($varname,$ecms=0,$isadmin=0){
- esetcookie($varname,'',0,$ecms);
- }
- //设置提交码
- function DoSetActionPass($userid,$username,$rnd,$other,$ecms=0){
- global $ecms_config;
- $varname='actionepass';
- $date=date("Y-m-d-H");
- $pass=md5(md5($rnd.'-'.$userid.'-'.$date.'-'.$other).$ecms_config['cks']['ckrnd'].$username);
- esetcookie($varname,$pass,0,$ecms);
- }
- //清除提交码
- function DoEmptyActionPass($ecms=0){
- $varname='actionepass';
- esetcookie($varname,'',0,$ecms);
- }
- //检测提交码
- function DoCheckActionPass($userid,$username,$rnd,$other,$ecms=0){
- global $ecms_config;
- $varname='actionepass';
- $date=date("Y-m-d-H");
- $checkpass=md5(md5($rnd.'-'.$userid.'-'.$date.'-'.$other).$ecms_config['cks']['ckrnd'].$username);
- $pass=getcvar($varname,$ecms);
- if('dg'.$checkpass<>'dg'.$pass)
- {
- exit();
- }
- }
- //返回字段标识
- function toReturnFname($tbname,$f){
- global $empire,$dbtbpre;
- $r=$empire->fetch1("select fname from {$dbtbpre}enewsf where f='$f' and tbname='$tbname' limit 1");
- return $r[fname];
- }
- //返回拼音
- function ReturnPinyinFun($hz){
- global $ecms_config;
- include_once(ECMS_PATH.'e/class/epinyin.php');
- //编码
- if($ecms_config['sets']['pagechar']!='gb2312')
- {
- include_once(ECMS_PATH.'e/class/doiconv.php');
- $iconv=new Chinese('');
- $char=$ecms_config['sets']['pagechar']=='big5'?'BIG5':'UTF8';
- $targetchar='GB2312';
- $hz=$iconv->Convert($char,$targetchar,$hz);
- }
- return c($hz);
- }
- //取得字母
- function GetInfoZm($hz){
- if(!trim($hz))
- {
- return '';
- }
- $py=ReturnPinyinFun($hz);
- $zm=substr($py,0,1);
- return strtoupper($zm);
- }
- //返回加密后的IP
- function ToReturnXhIp($ip,$n=1){
- $newip='';
- $ipr=explode(".",$ip);
- $ipnum=count($ipr);
- for($i=0;$i<$ipnum;$i++)
- {
- if($i!=0)
- {$d=".";}
- if($i==$ipnum-1)
- {
- $ipr[$i]="*";
- }
- if($n==2)
- {
- if($i==$ipnum-2)
- {
- $ipr[$i]="*";
- }
- }
- $newip.=$d.$ipr[$i];
- }
- return $newip;
- }
- //验证是否使用https
- function eCheckUseHttps(){
- if($_SERVER['HTTPS']&&strtolower($_SERVER['HTTPS'])!='off')
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- //返回http类型
- function eReturnHttpType(){
- global $public_r;
- if($public_r['httptype'])
- {
- if($public_r['httptype']==1)
- {
- return 'http://';
- }
- elseif($public_r['httptype']==2)
- {
- return 'https://';
- }
- elseif($public_r['httptype']==3)
- {
- if(defined('EmpireCMSAdmin'))
- {
- return 'https://';
- }
- else
- {
- return 'http://';
- }
- }
- elseif($public_r['httptype']==4)
- {
- if(defined('EmpireCMSAdmin'))
- {
- return 'http://';
- }
- else
- {
- return 'https://';
- }
- }
- }
- return eCheckUseHttps()==1?'https://':'http://';
- }
- //返回当前域名2
- function eReturnTrueDomain(){
- $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
- if(empty($domain))
- {
- return '';
- }
- return $domain;
- }
- //返回当前域名
- function eReturnDomain(){
- $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
- if(empty($domain))
- {
- return '';
- }
- return eReturnHttpType().$domain;
- }
- //返回域名网站地址
- function eReturnDomainSiteUrl(){
- global $public_r;
- $PayReturnUrlQz=$public_r['newsurl'];
- if(!stristr($public_r['newsurl'],'://'))
- {
- $PayReturnUrlQz=eReturnDomain().$public_r['newsurl'];
- }
- return $PayReturnUrlQz;
- }
- //返回当前地址
- function eReturnSelfPage($ecms=0){
- if(empty($ecms))
- {
- $page=$_SERVER['PHP_SELF'];
- }
- else
- {
- $page=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
- }
- $page=str_replace('&','&',RepPostStr($page,1));
- return $page;
- }
- //验证当前会员权限
- function sys_CheckMemberGroup($groupid){
- if(!defined('InEmpireCMSUser'))
- {
- include_once ECMS_PATH.'e/member/class/user.php';
- }
- $r=qCheckLoginAuthstr();
- if(!$r['islogin'])
- {
- return 0;
- }
- if(!strstr(','.$groupid.',',','.$r['groupid'].','))
- {
- return -1;
- }
- return 1;
- }
- //EMAIL地址检查
- function chemail($email){
- $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
- if (strpos($email, '@') !== false && strpos($email, '.') !== false)
- {
- if (preg_match($chars, $email))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- //去除adds
- function ClearAddsData($data){
- if(MAGIC_QUOTES_GPC)
- {
- $data=stripSlashes($data);
- }
- return $data;
- }
- //增加adds
- function AddAddsData($data){
- if(!MAGIC_QUOTES_GPC)
- {
- $data=addslashes($data);
- }
- return $data;
- }
- //原字符adds
- function StripAddsData($data){
- $data=addslashes(stripSlashes($data));
- return $data;
- }
- //反增加adds
- function fAddAddsData($data){
- if(MAGIC_QUOTES_GPC)
- {
- $data=addslashes($data);
- }
- return $data;
- }
- //------- 存文本 -------
- //读取文本字段内容
- function GetTxtFieldText($pagetexturl){
- global $ecms_config;
- if(empty($pagetexturl))
- {
- return '';
- }
- $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
- $text=ReadFiletext($file);
- $text=substr($text,12);//去除exit
- return $text;
- }
- //取得文本地址
- function GetTxtFieldTextUrl($pagetexturl){
- global $ecms_config;
- $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
- return $file;
- }
- //修改文本字段内容
- function EditTxtFieldText($pagetexturl,$pagetext){
- global $ecms_config;
- $pagetext="<? exit();?>".$pagetext;
- $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
- WriteFiletext_n($file,$pagetext);
- }
- //删除文本字段内容
- function DelTxtFieldText($pagetexturl){
- global $ecms_config;
- if(empty($pagetexturl))
- {
- return '';
- }
- $file=$ecms_config['sets']['txtpath'].$pagetexturl.".php";
- DelFiletext($file);
- }
- //取得随机数
- function GetFileMd5(){
- $p=md5(uniqid(microtime()).EcmsRandInt());
- return $p;
- }
- //建立存放目录
- function MkDirTxtFile($date,$file){
- global $ecms_config;
- $r=explode("/",$date);
- $path=$ecms_config['sets']['txtpath'].$r[0];
- DoMkdir($path);
- $path=$ecms_config['sets']['txtpath'].$date;
- DoMkdir($path);
- $returnpath=$date."/".$file;
- return $returnpath;
- }
- //替换公共标记
- function ReplaceSvars($temp,$url,$classid,$title,$key,$des,$add,$repvar=1){
- global $public_r,$class_r,$class_zr;
- if($repvar==1)//全局模板变量
- {
- $temp=ReplaceTempvar($temp);
- }
- $temp=str_replace('[!--class.menu--]',$public_r['classnavs'],$temp);//栏目导航
- $temp=str_replace('[!--newsnav--]',$url,$temp);//位置导航
- $temp=str_replace('[!--pagetitle--]',$title,$temp);
- $temp=str_replace('[!--pagekey--]',$key,$temp);
- $temp=str_replace('[!--pagedes--]',$des,$temp);
- $temp=str_replace('[!--self.classid--]',0,$temp);
- $temp=str_replace('[!--news.url--]',$public_r['newsurl'],$temp);
- return $temp;
- }
- //返回数组组合字符
- function eReturnRDataStr($r){
- $count=count($r);
- if(!$count)
- {
- return '';
- }
- $str=',';
- for($i=0;$i<$count;$i++)
- {
- $str.=$r[$i].',';
- }
- return $str;
- }
- //------- firewall -------
- //提示
- function FWShowMsg($msg){
- //echo $msg;
- exit();
- }
- //防火墙
- function DoEmpireCMSFireWall(){
- global $ecms_config;
- if(!empty($ecms_config['fw']['adminloginurl']))
- {
- $usehost=FWeReturnDomain();
- if($usehost!=$ecms_config['fw']['adminloginurl'])
- {
- FWShowMsg('Login Url');
- }
- }
- if($ecms_config['fw']['adminhour']!=='')
- {
- $h=date('G');
- if(!strstr(','.$ecms_config['fw']['adminhour'].',',','.$h.','))
- {
- FWShowMsg('Admin Hour');
- }
- }
- if($ecms_config['fw']['adminweek']!=='')
- {
- $w=date('w');
- if(!strstr(','.$ecms_config['fw']['adminweek'].',',','.$w.','))
- {
- FWShowMsg('Admin Week');
- }
- }
- if(!defined('EmpireCMSAPage')&&$ecms_config['fw']['adminckpassvar']&&$ecms_config['fw']['adminckpassval'])
- {
- FWCheckPassword();
- }
- }
- //返回当前域名
- function FWeReturnDomain(){
- $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
- if(empty($domain))
- {
- return '';
- }
- return eReturnHttpType().$domain;
- }
- //检查敏感字符
- function FWClearGetText($str){
- global $ecms_config;
- if(empty($ecms_config['fw']['eopen']))
- {
- return '';
- }
- if(empty($ecms_config['fw']['cleargettext']))
- {
- return '';
- }
- $r=explode(',',$ecms_config['fw']['cleargettext']);
- $count=count($r);
- for($i=0;$i<$count;$i++)
- {
- if(stristr($r[$i],'##'))//多字
- {
- $morer=explode('##',$r[$i]);
- if(stristr($str,$morer[0])&&stristr($str,$morer[1]))
- {
- FWShowMsg('Post String');
- }
- }
- else
- {
- if(stristr($str,$r[$i]))
- {
- FWShowMsg('Post String');
- }
- }
- }
- }
- //后台防火墙密码
- function FWSetPassword(){
- global $ecms_config;
- if(!$ecms_config['fw']['eopen']||!$ecms_config['fw']['adminckpassvar']||!$ecms_config['fw']['adminckpassval'])
- {
- return '';
- }
- $ip=$ecms_config['esafe']['ckhloginip']==0?'127.0.0.1':egetip();
- $ecmsckpass=md5(md5($ecms_config['fw']['adminckpassval'].'-empirecms-'.$ecms_config['fw']['epass']).'-'.$ip.'-'.$ecms_config['fw']['adminckpassval'].'-phome.net-');
- esetcookie($ecms_config['fw']['adminckpassvar'],$ecmsckpass,0,1);
- }
- function FWCheckPassword(){
- global $ecms_config;
- if(!$ecms_config['fw']['eopen']||!$ecms_config['fw']['adminckpassvar']||!$ecms_config['fw']['adminckpassval'])
- {
- return '';
- }
- $ip=$ecms_config['esafe']['ckhloginip']==0?'127.0.0.1':egetip();
- $ecmsckpass=md5(md5($ecms_config['fw']['adminckpassval'].'-empirecms-'.$ecms_config['fw']['epass']).'-'.$ip.'-'.$ecms_config['fw']['adminckpassval'].'-phome.net-');
- if('dg'.$ecmsckpass<>'dg'.getcvar($ecms_config['fw']['adminckpassvar'],1))
- {
- FWShowMsg('Password');
- }
- }
- function FWEmptyPassword(){
- global $ecms_config;
- esetcookie($ecms_config['fw']['adminckpassvar'],'',0,1);
- }
- //--------------- 缓存 ---------------
- //取最后一两级目录
- function Ecms_eReturnShowMkdir($path){
- global $ecms_config;
- if(!$ecms_config['sets']['webdebug'])
- {
- return '';
- }
- if(!stristr($path,'/'))
- {
- return '';
- }
- $path=str_replace(eReturnTrueEcmsPath(),'/',$path);
- $r=explode('/',$path);
- $count=count($r);
- if($count<2)
- {
- return '';
- }
- else
- {
- return '/'.$r[$count-1];
- }
- }
- //建立目录(普通)
- function Ecms_eMkdir($path){
- if(!file_exists($path))
- {
- $mk=@mkdir($path,0777);
- @chmod($path,0777);
- if(empty($mk))
- {
- echo 'Create path fail: '.Ecms_eReturnShowMkdir($path);
- exit();
- }
- }
- return true;
- }
- //递级建立目录
- function Ecms_eMoreMkdir($basepath,$path){
- if(empty($path))
- {
- return '';
- }
- if(file_exists($basepath.$path))
- {
- return $path;
- }
- $returnpath='';
- $r=explode('/',$path);
- $count=count($r);
- for($i=0;$i<$count;$i++)
- {
- if(empty($r[$i]))
- {
- continue;
- }
- if($returnpath)
- {
- $returnpath.='/'.$r[$i];
- }
- else
- {
- $returnpath.=$r[$i];
- }
- $createpath=$basepath.$returnpath;
- $mk=Ecms_eMkdir($createpath);
- }
- return $returnpath;
- }
- //取得文件内容(可锁定)
- function Ecms_ReadFiletext($filepath,$dolock=0){
- $filepath=trim($filepath);
- $htmlfp=@fopen($filepath,"r");
- if($dolock==1)
- {
- flock($htmlfp,LOCK_SH);
- }
- $string=@fread($htmlfp,@filesize($filepath));
- if($dolock==1)
- {
- flock($htmlfp,LOCK_UN);
- }
- @fclose($htmlfp);
- return $string;
- }
- //写文件(可锁定)
- function Ecms_WriteFiletext($filepath,$string,$dolock=0,$strip=0){
- global $public_r;
- if($strip==1)
- {
- $string=stripSlashes($string);
- }
- $fp=@fopen($filepath,"w");
- if($dolock==1)
- {
- flock($fp,LOCK_EX);
- }
- @fputs($fp,$string);
- if($dolock==1)
- {
- flock($fp,LOCK_UN);
- }
- @fclose($fp);
- if(empty($public_r['filechmod']))
- {
- @chmod($filepath,0777);
- }
- }
- //返回文件修改时间
- function Ecms_GetFileEditTime($filepath){
- return file_exists($filepath)?intval(filemtime($filepath)):0;
- }
- //ID返回动态缓存目录
- function ePagenoGetPageCache($cpage){
- $r=array();
- if($cpage==1)//首页
- {
- $r['esyspath']='empirecms';
- $r['cpath']='cindex';
- }
- elseif($cpage==2)//封面
- {
- $r['esyspath']='empirecms';
- $r['cpath']='cpage';
- }
- elseif($cpage==3)//列表
- {
- $r['esyspath']='empirecms';
- $r['cpath']='clist';
- }
- elseif($cpage==4)//内容
- {
- $r['esyspath']='empirecms';
- $r['cpath']='ctext';
- }
- elseif($cpage==5)//标题分类
- {
- $r['esyspath']='empirecms';
- $r['cpath']='cinfotype';
- }
- elseif($cpage==6)//TAGS
- {
- $r['esyspath']='empirecms';
- $r['cpath']='ctags';
- }
- elseif($cpage==10000)//ALLECMS
- {
- $r['esyspath']='empirecms';
- $r['cpath']='';
- }
- else
- {
- $r['esyspath']='';
- $r['cpath']='no';
- }
- return $r;
- }
- //返回缓存文件名
- function Ecms_eCacheReturnFile($cachetype,$ids,$datepath,$path='empirecms'){
- global $ecms_config,$public_r;
- $filer['basepath']=$ecms_config['sets']['ecmscachepath'].$path.'/';
- $filer['cpath']=$datepath;
- $filer['cfile']=md5($cachetype.'!-'.$ids.'-,'.$public_r['ctimernd'].'-!'.$path).$ecms_config['sets']['ecmscachefiletype'];
- $filer['ctruefile']=$filer['basepath'].$filer['cpath'].'/'.$filer['cfile'];
- return $filer;
- }
- //输出缓存
- function Ecms_eCacheOut($cr,$usedo=0){
- $cachetime=abs($cr['cachetime'])*60;
- $filer=Ecms_eCacheReturnFile($cr['cachetype'],$cr['cacheids'],$cr['cachedatepath'],$cr['cachepath']);
- $cachefile=$filer['ctruefile'];
- $filetime=Ecms_GetFileEditTime($cachefile);
- if(!$filetime)
- {
- return 0;
- }
- $time=time();
- if($time-$filetime>$cachetime)
- {
- return 0;
- }
- $cr['cachelastedit']=(int)$cr['cachelastedit'];
- if($cr['cachelastedit']&&$cr['cachelastedit']>$filetime)
- {
- return 0;
- }
- if($cr['cachelasttime']>=$filetime)
- {
- return 0;
- }
- echo Ecms_ReadFiletext($cachefile);
- if($usedo==0)
- {
- db_close();
- $empire=null;
- exit();
- }
- elseif($usedo==1)
- {
- exit();
- }
- else
- {}
- return 1;
- }
- //写入缓存
- function Ecms_eCacheIn($cr,$cachetext){
- $filer=Ecms_eCacheReturnFile($cr['cachetype'],$cr['cacheids'],$cr['cachedatepath'],$cr['cachepath']);
- $cachefile=$filer['ctruefile'];
- Ecms_eMoreMkdir($filer['basepath'],$filer['cpath']);
- Ecms_WriteFiletext($cachefile,$cachetext,1);
- echo $cachetext;
- }
- //验证是否启用缓存
- function Ecms_eCacheCheckOpen($cachetime){
- global $ecms_config,$public_r,$ecms_tofunr;
- if(empty($public_r['ctimeopen']))
- {
- return 0;
- }
- if($cachetime>0)
- {
- $open=1;
- }
- elseif($cachetime<0)
- {
- $open=1;
- $userid=(int)getcvar('mluserid');
- if($userid)
- {
- $open=0;
- }
- }
- else
- {
- $open=0;
- }
- if($public_r['ctimegids'])
- {
- $groupid=(int)getcvar('mlgroupid');
- if($groupid&&strstr(','.$public_r['ctimegids'].',',','.$groupid.','))
- {
- $open=0;
- }
- }
- if($public_r['ctimecids']&&$ecms_tofunr['cacheselfcid'])
- {
- $selfcid=(int)$ecms_tofunr['cacheselfcid'];
- if($selfcid&&strstr(','.$public_r['ctimecids'].',',','.$selfcid.','))
- {
- $open=0;
- }
- }
- return $open;
- }
- //设置更新缓存
- function eDoUpCache($id,$tname,$ecms=0,$ck=0){
- global $empire,$dbtbpre,$public_r;
- if(empty($public_r['ctimeopen']))
- {
- return '';
- }
- $time=time();
- $uptime=$time-2;
- $addwhere='';
- $addwhere_index=' where fclastindex<'.$uptime;
- if($ck==1)
- {
- $addwhere=' and fclast<'.$uptime;
- $addwhere_index=' where fclastindex<'.$uptime;
- }
- if($ecms==1)//栏目
- {
- if(!$id)
- {
- return '';
- }
- $empire->query("update {$dbtbpre}enewsclass set fclast='$time' where classid in (".$id.")".$addwhere);
- }
- elseif($ecms==2)//标题分类
- {
- if(!$id)
- {
- return '';
- }
- $empire->query("update {$dbtbpre}enewsinfotype set fclast='$time' where typeid in (".$id.")".$addwhere);
- }
- elseif($ecms==3)//内容页
- {
- if(!$id||!$tname)
- {
- return '';
- }
- $empire->query("update {$dbtbpre}ecms_".$tname." set lastdotime='$time' where id in (".$id.")");
- }
- elseif($ecms==4)//TAGS
- {
- if(!$id&&!$tname)
- {
- return '';
- }
- if($tname)
- {
- $tr=explode(',',$tname);
- $tcount=count($tr);
- $where='';
- $or='';
- for($ti=0;$ti<$tcount;$ti++)
- {
- $tr[$ti]=RepPostVar($tr[$ti]);
- if(!$tr[$ti])
- {
- continue;
- }
- $where.=$or."tagname='".$tr[$ti]."'";
- $or=' or ';
- }
- if(!$where)
- {
- return '';
- }
- }
- else
- {
- $where="tagid in (".$id.")";
- }
- $empire->query("update {$dbtbpre}enewstags set fclast='$time' where ".$where.$addwhere);
- }
- else//首页
- {
- $empire->query("update {$dbtbpre}enewspublic_fc set fclastindex='$time'".$addwhere_index." limit 1");
- }
- }
- //设置更新缓存
- function eUpCacheInfo($ecms,$classid,$id,$pid,$ttid,$tagid,$tagname,$oldclassid=0,$oldttid=0,$ck=0){
- global $empire,$dbtbpre,$public_r,$class_r;
- if(empty($public_r['ctimeopen']))
- {
- return '';
- }
- $ctimeaddre=$ecms==1?$public_r['ctimeaddre']:$public_r['ctimeqaddre'];
- if(!$ctimeaddre)
- {
- return '';
- }
- $classid=(int)$classid;
- $id=(int)$id;
- $pid=(int)$pid;
- $ttid=(int)$ttid;
- $oldclassid=(int)$oldclassid;
- $oldttid=(int)$oldttid;
- //首页
- if($ctimeaddre==2||$ctimeaddre==4||$ctimeaddre==6||$ctimeaddre==7||$ctimeaddre==8)
- {
- eDoUpCache(0,'',0,$ck);
- }
- //栏目
- if($ctimeaddre!=2)
- {
- if(!empty($classid))
- {
- $cids='';
- if($ctimeaddre==1)//当前
- {
- $cids=$classid;
- if($oldclassid&&$oldclassid!=$classid)
- {
- $cids.=','.$oldclassid;
- }
- }
- else
- {
- $featherclass=$class_r[$classid]['featherclass'];
- if($ctimeaddre>=5)
- {
- if(empty($featherclass))
- {
- $featherclass='|';
- }
- $featherclass.=$classid.'|';
- if($oldclassid&&$oldclassid!=$classid)
- {
- $featherclass.=$oldclassid.'|';
- }
- }
- $cids=eReturnInFcids($featherclass);
- }
- if(empty($cids))
- {
- return '';
- }
- eDoUpCache($cids,'',1,$ck);
- }
- }
- //标题分类
- if($ctimeaddre>=7)
- {
- if(!empty($ttid))
- {
- if($oldttid&&$oldttid!=$ttid)
- {
- $ttid.=','.$oldttid;
- }
- eDoUpCache($ttid,'',2,$ck);
- }
- }
- //TAGS
- if($ctimeaddre>=8)
- {
- eDoUpCache('',$tagname,4,$ck);
- }
- //信息
- if($id||$pid)
- {
- $tbname=$class_r[$classid]['tbname'];
- if(!empty($tbname))
- {
- $ids='';
- $iddh='';
- if($id)
- {
- $ids.=$id;
- $iddh=',';
- }
- if($pid)
- {
- $ids.=$iddh.$pid;
- $iddh=',';
- }
- eDoUpCache($ids,$tbname,3,$ck);
- }
- }
- }
- ?>
|