心理咨询网

ParserController.php 199KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2018年2月14日
  7. * 标签解析引擎控制器
  8. */
  9. namespace app\home\controller;
  10. use core\basic\Controller;
  11. use app\home\model\ParserModel;
  12. use core\basic\Url;
  13. use app\home\model\DoModel;
  14. use app\home\model\MemberModel;
  15. class ParserController extends Controller
  16. {
  17. protected $model;
  18. protected $pre = array();
  19. protected $var = array();
  20. public function __construct()
  21. {
  22. $this->model = new ParserModel();
  23. }
  24. public function _empty()
  25. {
  26. _404('您访问的地址有误,请核对后重试!');
  27. }
  28. // 解析全局前置公共标签
  29. public function parserBefore($content)
  30. {
  31. // 处理模板中不需要解析的标签
  32. $content = $this->savePreLabel($content);
  33. $content = $this->parserSingleLabel($content); // 单标签解析
  34. $content = $this->parserUserLabel($content); // 自定义标签
  35. return $content;
  36. }
  37. // 解析全局后置公共标签
  38. public function parserAfter($content)
  39. {
  40. // 默认页面信息替换
  41. $content = str_replace('{pboot:pagetitle}', $this->config('other_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
  42. $content = str_replace('{pboot:pagekeywords}', '{pboot:sitekeywords}', $content);
  43. $content = str_replace('{pboot:pagedescription}', '{pboot:sitedescription}', $content);
  44. $content = str_replace('{pboot:keyword}', get('keyword', 'vars'), $content); // 当前搜索的关键字
  45. $content = $this->parserSiteLabel($content); // 站点标签
  46. $content = $this->parserCompanyLabel($content); // 公司标签
  47. $content = $this->parserMemberLabel($content); // 会员标签
  48. $content = $this->parserNavLabel($content); // 分类列表
  49. $content = $this->parserCityListLabel($content); // 解析城市分站标签
  50. $content = $this->parserSelectAllLabel($content); // CMS筛选全部标签解析
  51. $content = $this->parserSelectLabel($content); // CMS筛选标签解析
  52. $content = $this->parserSpecifySortLabel($content); // 指定分类
  53. $content = $this->parserListLabel($content); // 指定列表
  54. $content = $this->parserSpecifyContentLabel($content); // 指定内容
  55. $content = $this->parserContentPicsLabel($content); // 内容多图
  56. $content = $this->parserContentCheckboxLabel($content); // 内容多选调取
  57. $content = $this->parserContentTagsLabel($content); // 内容tags调取
  58. $content = $this->parserSlideLabel($content); // 幻灯片
  59. $content = $this->parserLinkLabel($content); // 友情链接
  60. $content = $this->parserMessageLabel($content); // 留言板
  61. $content = $this->parserFormLabel($content); // 自定义表单
  62. $content = $this->parserSubmitFormLabel($content); // 自定义表单提交
  63. $content = $this->parserSqlListLabel($content); // 自定义SQL输出
  64. $content = $this->parserQrcodeLabel($content); // 二维码生成
  65. $content = $this->parserPageLabel($content); // CMS分页标签解析(需置后)
  66. $content = $this->parserIfLabel($content); // IF语句(需置最后)
  67. $content = $this->parserLoopLabel($content); // LOOP语句(需置后,不可放到if前面,否则有安全风险)
  68. $content = $this->restorePreLabel($content); // 还原不需要解析的内容
  69. $content = $this->parserReplaceKeyword($content); // 页面关键词替换
  70. $content = $this->parserTitleReplaceLabel($content); // 通用内容替换标签 这里是我新增的
  71. $content = $this->parserBLock($content); //自定义方法2
  72. // 解析个人扩展标签,升级不覆盖
  73. if (file_exists(APP_PATH . '/home/controller/ExtLabelController.php')) {
  74. if (class_exists('app\home\controller\ExtLabelController')) {
  75. $extlabel = new ExtLabelController();
  76. $content = $extlabel->run($content);
  77. }
  78. }
  79. return $content;
  80. }
  81. // 通用内容替换标签 @mk-title_replace
  82. //$content这里用的时文章标题,直接是字符串
  83. public function parserTitleReplaceLabel($content)
  84. {
  85. $pattern = '/\{pboot:titlereplace(\s+[^}]+)?\}/';
  86. //先对$content 进行处理 包含 {xx}
  87. //{pboot:titlereplace title='{xx}心理咨询,{xx}心理医生,{xx}心理咨询中心机构【乐达心理】' /}
  88. //因为{xx} 正则问题
  89. $content = str_replace('{xx}', '[xx]', $content);
  90. //var_dump($content);die;
  91. if (preg_match_all($pattern, $content, $matches)) {
  92. $count = count($matches[0]);
  93. for ($i = 0; $i < $count; $i ++) {
  94. //var_dump($matches[0][$i]);die;
  95. $matches[0][$i] = str_replace('[xx]', '{xx}', $matches[0][$i]);
  96. $params = $this->parserParam($matches[0][$i]);
  97. $data = '';
  98. foreach ($params as $key => $value) {
  99. switch ($key) {
  100. case 'title'://这里其实可以解析很多的,不只是title,可以根据case进行不同的解析
  101. $data = $value; // 获取到的文章title
  102. //$data = titlereplace($data); //testreplace方法为自定义方法,在\apps\common\function.php里
  103. //$data = str_replace("`", '', $data);
  104. //var_dump($data);die;
  105. $data = explode(',',$data);
  106. $data = $data[0];
  107. break;
  108. }
  109. }
  110. if (!$data) { // 无内容不解析
  111. continue;
  112. }
  113. //$content = str_replace($matches[0][$i], $data, $content);
  114. //$content {pboot:titlereplace title='广州心理咨询,广州心理医生,广州心理咨询中心机构【乐达心理】' /}
  115. //$data '广州
  116. //$matches[0][$i] {pboot:titlereplace title='广州
  117. //$content = str_replace("`/}", '', $content);
  118. $content = str_replace('[xx]', '{xx}', $content);
  119. //var_dump($content);die;
  120. $content = str_replace($matches[0][$i], $data, $content);
  121. }
  122. if((int)$count === 0){
  123. $content = str_replace('[xx]', '{xx}', $content);
  124. }
  125. }else{
  126. $content = str_replace('[xx]', '{xx}', $content);
  127. }
  128. return $content;
  129. }
  130. public function parserBLock($content){
  131. $pattern = '/\{pboot:block(\s+[^}]+)?\}/';
  132. if (preg_match_all($pattern, $content, $matches)) {
  133. $count = count($matches[0]);
  134. for ($i = 0; $i < $count; $i ++) {
  135. $params = $this->parserParam($matches[0][$i]);
  136. $data = '';
  137. foreach ($params as $key => $value) {
  138. switch ($key) {
  139. case 'id':
  140. $data = $this->model->getBlockContent($value);
  141. //return $data['value'];
  142. //print_r($data);exit();
  143. break;
  144. /*$data = $this->model->getContent($value)->content; // 获取到的文章id去获取文章内容
  145. $data = testreplace($data);*/
  146. }
  147. }
  148. if (!$data) { // 无内容不解析
  149. continue;
  150. }
  151. //$content = $data['value'];
  152. $content = str_replace($matches[0][$i], $data, $content);
  153. }
  154. }
  155. return $content;
  156. }
  157. // 保存保留内容
  158. public function savePreLabel($content)
  159. {
  160. $pattern = '/\{pboot:pre}([\s\S]*?)\{\/pboot:pre\}/';
  161. if (preg_match_all($pattern, $content, $matches)) {
  162. $count = count($matches[0]);
  163. for ($i = 0; $i < $count; $i ++) {
  164. $this->pre[] = $matches[1][$i];
  165. end($this->pre);
  166. $content = str_replace($matches[0][$i], '#pre:' . key($this->pre) . '#', $content);
  167. }
  168. }
  169. return $content;
  170. }
  171. // 还原保留内容
  172. public function restorePreLabel($content)
  173. {
  174. $pattern = '/\#pre:([0-9]+)\#/';
  175. if (preg_match_all($pattern, $content, $matches)) {
  176. $count = count($matches[0]);
  177. for ($i = 0; $i < $count; $i ++) {
  178. $content = str_replace($matches[0][$i], $this->pre[$matches[1][$i]], $content);
  179. }
  180. }
  181. $content = str_replace('pboot@if', 'pboot:if', $content); // 还原系统解析if标签
  182. return $content;
  183. }
  184. // 解析单标签
  185. public function parserSingleLabel($content)
  186. {
  187. $content = str_replace('{pboot:ucenter}', Url::home('member/ucenter'), $content); // 用户中心
  188. if (! ! $url = get("backurl")) { // 获取会跳地址
  189. $content = str_replace('{pboot:login}', Url::home('member/login', null, "backurl=" . urlencode($url)), $content); // 登录地址
  190. } else {
  191. $content = str_replace('{pboot:login}', Url::home('member/login'), $content); // 登录地址
  192. }
  193. $content = str_replace('{pboot:register}', Url::home('member/register'), $content); // 注册地址
  194. $content = str_replace('{pboot:retrieve}', Url::home('member/retrieve'), $content); //找回密码
  195. $content = str_replace('{pboot:isregister}', Url::home('member/isRegister'), $content); // 检查是否注册地址
  196. $content = str_replace('{pboot:umodify}', Url::home('member/umodify'), $content); // 修改资料地址
  197. $content = str_replace('{pboot:logout}', Url::home('member/logout'), $content); // 推出登录
  198. $content = str_replace('{pboot:upload}', Url::home('member/upload'), $content); // 上传资料
  199. if (strpos($content, '{pboot:sendemail}')) {
  200. session('sendemail', true); // 避免非法外部提交
  201. $content = str_replace('{pboot:sendemail}', Url::home('member/sendEmail'), $content); // 上传资料
  202. } else {
  203. session('sendemail', false);
  204. }
  205. $content = str_replace('{pboot:islogin}', session('pboot_uid') ? 1 : 0, $content); // 是否登录
  206. if (strpos($content, '{pboot:mustlogin}') !== false) {
  207. $content = str_replace('{pboot:mustlogin}', '', $content);
  208. if (! session('pboot_uid')) { // 没有经登录
  209. if ($this->config('login_no_wait')) {
  210. location(Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
  211. } else {
  212. error('您的权限不足,无法浏览本页面!', Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
  213. }
  214. }
  215. }
  216. $content = str_replace('{pboot:msgaction}', Url::home('message'), $content); // 留言提交路径
  217. $content = str_replace('{pboot:scaction}', Url::home('search'), $content); // 搜索提交路径
  218. $content = str_replace('{pboot:msgcodestatus}', $this->config('message_check_code') === '0' ? 0 : 1, $content); // 是否开留言启验证码
  219. $content = str_replace('{pboot:formcodestatus}', $this->config('form_check_code') === '0' ? 0 : 1, $content); // 是否开启表单验证码
  220. $content = str_replace('{pboot:checkcode}', CORE_DIR . '/code.php', $content); // 验证码路径
  221. $content = str_replace('{pboot:lgpath}', Url::get('home/Do/area'), $content); // 多语言切换前置路径,如{pboot:lgpath}?lg=cn
  222. $content = str_replace('{pboot:appid}', $this->config('api_appid'), $content); // API认证用户
  223. $content = str_replace('{pboot:timestamp}', time(), $content); // 认证时间戳
  224. $content = str_replace('{pboot:signature}', md5(md5($this->config('api_appid') . $this->config('api_secret') . time())), $content); // API认证密钥
  225. $content = str_replace('{pboot:httpurl}', get_http_url(), $content); // 当前访问的域名地址
  226. $content = str_replace('{pboot:pageurl}', get_current_url(), $content); // 当前页面的地址
  227. $content = str_replace('{pboot:registercodestatus}', $this->config('register_check_code') === '0' ? 0 : ($this->config('register_check_code') ?: 1), $content); // 是否开启注册验证码
  228. $content = str_replace('{pboot:logincodestatus}', $this->config('login_check_code') === '0' ? 0 : 1, $content); // 是否开启评论验证码
  229. $content = str_replace('{pboot:commentcodestatus}', $this->config('comment_check_code') === '0' ? 0 : 1, $content); // 是否开启评论验证码
  230. $content = str_replace('{pboot:commentaction}', Url::home('comment/add', null, "contentid={content:id}"), $content); // 评论提交路径
  231. $content = str_replace('{pboot:mycommentpage}', Url::home('comment/my'), $content); // 我的评论
  232. $content = str_replace('{pboot:registerstatus}', $this->config('register_status') === '0' ? 0 : 1, $content); // 是否开启注册
  233. $content = str_replace('{pboot:loginstatus}', $this->config('login_status') === '0' ? 0 : 1, $content); // 是否开启登录
  234. $content = str_replace('{pboot:commentstatus}', $this->config('comment_status') === '0' ? 0 : 1, $content); // 是否开启评论
  235. // 记录蜘蛛爬行
  236. if ($this->config('spiderlog') !== '0') {
  237. if ($this->config('tpl_html_cache')) { // 缓存时插入script,否则直接执行
  238. $spidercode = "<script src='" . Url::home('Spider', null, 'url=' . URL) . "' async='async'></script>";
  239. $content = preg_replace('/(<\/body>)/i', $spidercode . "\n$1", $content);
  240. } else {
  241. $spider = new SpiderController(URL);
  242. $spider->index();
  243. }
  244. }
  245. // 生成分站首页
  246. $city_suffix = $this->config('city_suffix')?true:false; //分站后缀
  247. $content = str_replace('{zong}', Url::home('home/Index/', $city_suffix), $content); // {zong}
  248. $content = str_replace('{iscity}', cookie('city') ? 1 : 0, $content); // 用来判断当前是否是分站
  249. return $content;
  250. }
  251. // 解析站点标签
  252. public function parserSiteLabel($content)
  253. {
  254. $pattern = '/\{pboot:site([\w]+)(\s+[^}]+)?\}/';
  255. $data = array();
  256. // 页面自适应标题避免多横线
  257. if (preg_match($pattern, $content)) {
  258. $data = $this->model->getSite();
  259. if (! $data->subtitle) {
  260. $content = str_replace('{pboot:sitetitle}-{pboot:sitesubtitle}', '{pboot:sitetitle}', $content);
  261. }
  262. }
  263. if (preg_match_all($pattern, $content, $matches)) {
  264. $data = $data ?: $this->model->getSite();
  265. $count = count($matches[0]);
  266. for ($i = 0; $i < $count; $i ++) {
  267. $params = $this->parserParam($matches[2][$i]);
  268. switch ($matches[1][$i]) {
  269. case 'index':
  270. $content = str_replace($matches[0][$i], Url::home('home/Index/'), $content);
  271. break;
  272. case 'path':
  273. $content = str_replace($matches[0][$i], SITE_DIR, $content);
  274. break;
  275. case 'enter':
  276. $content = str_replace($matches[0][$i], SITE_INDEX_DIR, $content);
  277. break;
  278. case 'logo':
  279. if (isset($data->logo) && $data->logo) {
  280. if (! preg_match('/^http/', $data->logo)) {
  281. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->logo), $content);
  282. } else {
  283. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->logo), $content);
  284. }
  285. } else {
  286. $content = str_replace($matches[0][$i], STATIC_DIR . '/images/logo.png', $content);
  287. }
  288. break;
  289. case 'tplpath':
  290. $content = str_replace($matches[0][$i], APP_THEME_DIR, $content);
  291. break;
  292. case 'language':
  293. $content = str_replace($matches[0][$i], get_lg(), $content);
  294. break;
  295. case 'statistical':
  296. if (isset($data->statistical)) {
  297. $content = str_replace($matches[0][$i], decode_string($data->statistical), $content);
  298. } else {
  299. $content = str_replace($matches[0][$i], '', $content);
  300. }
  301. case 'copyright':
  302. if (isset($data->copyright)) {
  303. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, decode_string($data->copyright)), $content);
  304. } else {
  305. $content = str_replace($matches[0][$i], '', $content);
  306. }
  307. default:
  308. if (strpos(file_get_contents(CORE_PATH . base64_decode('L2Jhc2ljL0tlcm5lbC5waHA=')), base64_decode('S2VybmVs')))
  309. exit();
  310. if (isset($data->{$matches[1][$i]})) {
  311. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->{$matches[1][$i]}), $content);
  312. } else {
  313. $content = str_replace($matches[0][$i], '', $content);
  314. }
  315. }
  316. }
  317. }
  318. return $content;
  319. }
  320. // 解析公司标签
  321. public function parserCompanyLabel($content)
  322. {
  323. $pattern = '/\{pboot:company([\w]+)(\s+[^}]+)?\}/';
  324. if (preg_match_all($pattern, $content, $matches)) {
  325. $data = $this->model->getCompany();
  326. $count = count($matches[0]);
  327. //
  328. $city = cookie('city');
  329. $city_info = $this->config('citys')[$city];
  330. for ($i = 0; $i < $count; $i ++) {
  331. if (! $data) { // 无数据时直接替换为空
  332. $content = str_replace($matches[0][$i], '', $content);
  333. continue;
  334. }
  335. $params = $this->parserParam($matches[2][$i]);
  336. switch ($matches[1][$i]) {
  337. case 'weixin':
  338. if (isset($data->weixin) && $data->weixin) {
  339. if (! preg_match('/^http/', $data->weixin)) {
  340. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->weixin), $content);
  341. } else {
  342. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->weixin), $content);
  343. }
  344. } else {
  345. $content = str_replace($matches[0][$i], '', $content);
  346. }
  347. break;
  348. case 'contact':
  349. case 'mobile':
  350. case 'phone':
  351. case 'fax':
  352. case 'email':
  353. case 'qq':
  354. case 'address':
  355. if( $city_info[$matches[1][$i]] ){
  356. $data->{$matches[1][$i]} = $city_info[$matches[1][$i]];
  357. }
  358. default:
  359. if (isset($data->{$matches[1][$i]})) {
  360. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->{$matches[1][$i]}), $content);
  361. }
  362. }
  363. }
  364. }
  365. return $content;
  366. }
  367. // 解析自定义标签
  368. public function parserUserLabel($content)
  369. {
  370. $pattern = '/\{label:([\w]+)(\s+[^}]+)?\}/';
  371. if (preg_match_all($pattern, $content, $matches)) {
  372. $data = $this->model->getLabel();
  373. $count = count($matches[0]);
  374. for ($i = 0; $i < $count; $i ++) {
  375. if (! $data) { // 无数据时直接替换为空
  376. $content = str_replace($matches[0][$i], '', $content);
  377. continue;
  378. }
  379. $params = $this->parserParam($matches[2][$i]);
  380. switch ($matches[1][$i]) {
  381. default:
  382. if (isset($data[$matches[1][$i]])) {
  383. if ($data[$matches[1][$i]]['type'] == 3 && $data[$matches[1][$i]]['value']) {
  384. if (! preg_match('/^http/', $data[$matches[1][$i]]['value'])) {
  385. $data[$matches[1][$i]]['value'] = $this->adjustLabelData($params, SITE_DIR . $data[$matches[1][$i]]['value']);
  386. } else {
  387. $data[$matches[1][$i]]['value'] = $this->adjustLabelData($params, $data[$matches[1][$i]]['value']);
  388. }
  389. }
  390. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data[$matches[1][$i]]['value']), $content);
  391. }
  392. }
  393. }
  394. }
  395. return $content;
  396. }
  397. // 会员标签解析
  398. private function parserMemberLabel($content)
  399. {
  400. $pattern = '/\{user:([\w]+)(\s+[^}]+)?\}/';
  401. if (preg_match_all($pattern, $content, $matches)) {
  402. $count = count($matches[0]);
  403. $model = new MemberModel();
  404. $data = $model->getUser();
  405. for ($i = 0; $i < $count; $i ++) {
  406. // 无数据直接替换并跳过
  407. if (! $data) {
  408. $content = str_replace($matches[0][$i], '', $content);
  409. continue;
  410. }
  411. $params = $this->parserParam($matches[2][$i]);
  412. switch ($matches[1][$i]) {
  413. case 'password': // 密码不允许显示
  414. $content = str_replace($matches[0][$i], '', $content);
  415. break;
  416. case 'registertime':
  417. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->register_time), $content);
  418. break;
  419. case 'logincount':
  420. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->login_count), $content);
  421. break;
  422. case 'lastloginip':
  423. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, long2ip($data->last_login_ip)), $content);
  424. break;
  425. case 'lastlogintime':
  426. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->last_login_time), $content);
  427. break;
  428. case 'headpic':
  429. if ($data->headpic) {
  430. if (! preg_match('/^http/', $data->headpic)) {
  431. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->headpic), $content);
  432. } else {
  433. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->headpic), $content);
  434. }
  435. } else {
  436. $content = str_replace($matches[0][$i], SITE_DIR . '/apps/admin/view/default/images/logo.png', $content);
  437. }
  438. default:
  439. if (isset($data->{$matches[1][$i]})) {
  440. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->{$matches[1][$i]}), $content);
  441. } else {
  442. $content = str_replace($matches[0][$i], '', $content);
  443. }
  444. }
  445. }
  446. }
  447. return $content;
  448. }
  449. // 解析栏目列表标签
  450. public function parserNavLabel($content)
  451. {
  452. $pattern = '/\{pboot:nav(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:nav\}/';
  453. $pattern2 = '/\[nav:([\w]+)(\s+[^]]+)?\]/';
  454. $pattern3 = '/pboot:([0-9])+nav/';
  455. if (preg_match_all($pattern, $content, $matches)) {
  456. $data = $this->model->getSortsTree();
  457. $count = count($matches[0]);
  458. for ($i = 0; $i < $count; $i ++) {
  459. // 无数据时直接替换整体标签为空
  460. if (! $data['tree']) {
  461. $content = str_replace($matches[0][$i], '', $content);
  462. continue;
  463. }
  464. // 获取调节参数
  465. $params = $this->parserParam($matches[1][$i]);
  466. if (! self::checkLabelLevel($params)) {
  467. $content = str_replace($matches[0][$i], '', $content);
  468. continue;
  469. }
  470. $parent = 0;
  471. $num = 0;
  472. $scode = 0;
  473. $scode_arr = array();
  474. foreach ($params as $key => $value) {
  475. switch ($key) {
  476. case 'parent':
  477. $parent = $value;
  478. break;
  479. case 'num':
  480. $num = $value;
  481. break;
  482. case 'scode':
  483. $scode = $value;
  484. $scode_arr = explode(',', $scode);
  485. break;
  486. }
  487. }
  488. if ($parent) { // 非顶级栏目起始,调用子栏目
  489. $parent_arr = explode(',', $parent);
  490. $out_data = array();
  491. foreach ($parent_arr as $vp) {
  492. if (isset($data['tree'][trim($vp)]['son'])) {
  493. $out_data = array_merge($out_data, $data['tree'][trim($vp)]['son']);
  494. }
  495. }
  496. } else { // 顶级栏目起始
  497. $out_data = $data['top'];
  498. }
  499. // 读取指定数量
  500. if ($num) {
  501. $out_data = array_slice($out_data, 0, $num);
  502. }
  503. // 匹配到内部标签
  504. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  505. $count2 = count($matches2[0]); // 循环内的内容标签数量
  506. } else {
  507. $count2 = 0;
  508. }
  509. $out_html = '';
  510. $key = 1;
  511. foreach ($out_data as $value) { // 按查询的数据条数循环
  512. if ($scode_arr && ! in_array($value['scode'], $scode_arr)) {
  513. continue;
  514. }
  515. $one_html = $matches[2][$i];
  516. if ($count2) {
  517. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  518. $params = $this->parserParam($matches2[2][$j]);
  519. switch ($matches2[1][$j]) {
  520. case 'n':
  521. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  522. break;
  523. case 'i':
  524. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  525. break;
  526. case 'link':
  527. if ($value['outlink']) {
  528. $one_html = str_replace($matches2[0][$j], $value['outlink'], $one_html);
  529. } else {
  530. $one_html = str_replace($matches2[0][$j], $this->parserLink($value['type'], $value['urlname'], 'list', $value['scode'], $value['filename'], '', ''), $one_html);
  531. }
  532. break;
  533. case 'soncount':
  534. if (isset($data['tree'][$value['scode']]['son'])) {
  535. $one_html = str_replace($matches2[0][$j], count($data['tree'][$value['scode']]['son']), $one_html);
  536. } else {
  537. $one_html = str_replace($matches2[0][$j], 0, $one_html);
  538. }
  539. break;
  540. case 'rows':
  541. $one_html = str_replace($matches2[0][$j], $this->model->getSortRows($value['scode']), $one_html);
  542. break;
  543. case 'ico':
  544. if ($value['ico']) {
  545. if (! preg_match('/^http/', $value['ico'])) {
  546. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value['ico']), $one_html);
  547. } else {
  548. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value['ico']), $one_html);
  549. }
  550. } else {
  551. $one_html = str_replace($matches2[0][$j], '', $one_html);
  552. }
  553. break;
  554. case 'pic':
  555. if ($value['pic']) {
  556. if (! preg_match('/^http/', $value['pic'])) {
  557. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value['pic']), $one_html);
  558. } else {
  559. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value['pic']), $one_html);
  560. }
  561. } else {
  562. $one_html = str_replace($matches2[0][$j], '', $one_html);
  563. }
  564. break;
  565. default:
  566. if (isset($value[$matches2[1][$j]])) {
  567. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value[$matches2[1][$j]]), $one_html);
  568. }
  569. }
  570. }
  571. }
  572. $key ++;
  573. $out_html .= $one_html;
  574. }
  575. // 无限极嵌套解析
  576. if (preg_match($pattern3, $out_html, $matches3)) {
  577. $out_html = str_replace('pboot:' . $matches3[1] . 'nav', 'pboot:nav', $out_html);
  578. $out_html = str_replace('[' . $matches3[1] . 'nav:', '[nav:', $out_html);
  579. $out_html = $this->parserNavLabel($out_html);
  580. }
  581. // 执行内容替换
  582. $content = str_replace($matches[0][$i], $out_html, $content);
  583. }
  584. }
  585. return $content;
  586. }
  587. // 解析当前位置
  588. public function parserPositionLabel($content, $scode, $page = null, $link = null)
  589. {
  590. $pattern = '/\{pboot:position(\s+[^}]+)?\}/';
  591. if (preg_match_all($pattern, $content, $matches)) {
  592. $count = count($matches[0]);
  593. $data = $this->model->getPosition($scode);
  594. for ($i = 0; $i < $count; $i ++) {
  595. $params = $this->parserParam($matches[1][$i], false); // 保留对html标签的支持
  596. $separator = '';
  597. $separatoricon = '';
  598. $indextext = '';
  599. $indexicon = '';
  600. // 分离参数
  601. foreach ($params as $key => $value) {
  602. switch ($key) {
  603. case 'separator':
  604. $separator = $value;
  605. break;
  606. case 'separatoricon':
  607. $separatoricon = $value;
  608. break;
  609. case 'indextext':
  610. $indextext = $value;
  611. break;
  612. case 'indexicon':
  613. $indexicon = $value;
  614. break;
  615. }
  616. }
  617. // 已经设置图标,则图标优先,如果没有,则判断是否已经设置文字
  618. if ($separatoricon) {
  619. $separator = ' <i class="' . $separatoricon . '"></i> ';
  620. } elseif (! $separator) {
  621. $separator = ' >> ';
  622. }
  623. if ($indexicon) {
  624. $indextext = '<i class="' . $indexicon . '"></i>';
  625. } elseif (! $indextext) {
  626. $indextext = '首页';
  627. }
  628. $out_html = '<a href="' . Url::home('home/Index') . '">' . $indextext . '</a>';
  629. if ($page && $scode == 0) {
  630. $out_html .= $separator . '<a href="' . $link . '">' . $page . '</a>';
  631. } else {
  632. foreach ($data as $key => $value) {
  633. if ($value['outlink']) {
  634. $out_html .= $separator . '<a href="' . $value['outlink'] . '">' . $value['name'] . '</a>';
  635. } else {
  636. $out_html .= $separator . '<a href="' . $this->parserLink($value['type'], $value['urlname'], 'list', $value['scode'], $value['filename'], '', '') . '">' . $value['name'] . '</a>';
  637. }
  638. }
  639. }
  640. // 执行内容替换
  641. $content = str_replace($matches[0][$i], $out_html, $content);
  642. }
  643. }
  644. return $content;
  645. }
  646. // 解析当前分类标签
  647. public function parserSortLabel($content, $sort)
  648. {
  649. $pattern = '/\{sort:([\w]+)(\s+[^}]+)?\}/';
  650. if (preg_match_all($pattern, $content, $matches)) {
  651. $count = count($matches[0]);
  652. for ($i = 0; $i < $count; $i ++) {
  653. $params = $this->parserParam($matches[2][$i]);
  654. switch ($matches[1][$i]) {
  655. case 'link':
  656. if ($sort->outlink) {
  657. $content = str_replace($matches[0][$i], $sort->outlink, $content);
  658. } else {
  659. $content = str_replace($matches[0][$i], $this->parserLink($sort->type, $sort->urlname, 'list', $sort->scode, $sort->filename, '', ''), $content);
  660. }
  661. break;
  662. case 'tcode': // 顶级栏目ID
  663. if (! isset($tcode))
  664. $tcode = $this->model->getSortTopScode($sort->scode);
  665. $content = str_replace($matches[0][$i], $tcode, $content);
  666. break;
  667. case 'topname':
  668. if (! isset($tcode))
  669. $tcode = $this->model->getSortTopScode($sort->scode);
  670. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $this->model->getSortName($tcode)), $content);
  671. break;
  672. case 'toplink':
  673. if (! isset($tcode)) {
  674. $tcode = $this->model->getSortTopScode($sort->scode);
  675. }
  676. $top_sort = $this->model->getSort($tcode);
  677. if ($top_sort->outlink) {
  678. $toplink = $top_sort->outlink;
  679. } else {
  680. $toplink = $this->parserLink($top_sort->type, $top_sort->urlname, 'list', $top_sort->scode, $top_sort->filename, '', '');
  681. }
  682. $content = str_replace($matches[0][$i], $toplink, $content);
  683. break;
  684. case 'parentname':
  685. if ($sort->pcode == 0) {
  686. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->name), $content);
  687. } else {
  688. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->parentname), $content);
  689. }
  690. break;
  691. case 'parentlink':
  692. if ($sort->pcode == 0) {
  693. $parent_sort = $sort;
  694. } else {
  695. $parent_sort = $this->model->getSort($sort->pcode);
  696. }
  697. if ($parent_sort->outlink) {
  698. $parentlink = $top_sort->outlink;
  699. } else {
  700. $parentlink = $this->parserLink($parent_sort->type, $parent_sort->urlname, 'list', $parent_sort->scode, $parent_sort->filename, '', '');
  701. }
  702. $content = str_replace($matches[0][$i], $parentlink, $content);
  703. break;
  704. case 'toprows':
  705. if (! isset($tcode))
  706. $tcode = $this->model->getSortTopScode($sort->scode);
  707. $content = str_replace($matches[0][$i], $this->model->getSortRows($tcode), $content);
  708. break;
  709. case 'parentrows':
  710. if ($sort->pcode == 0) {
  711. $content = str_replace($matches[0][$i], $this->model->getSortRows($sort->scode), $content);
  712. } else {
  713. $content = str_replace($matches[0][$i], $this->model->getSortRows($sort->pcode), $content);
  714. }
  715. break;
  716. case 'rows':
  717. $content = str_replace($matches[0][$i], $this->model->getSortRows($sort->scode), $content);
  718. break;
  719. case 'ico':
  720. if ($sort->ico) {
  721. if (! preg_match('/^http/', $sort->ico)) {
  722. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $sort->ico), $content);
  723. } else {
  724. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->ico), $content);
  725. }
  726. } else {
  727. $content = str_replace($matches[0][$i], '', $content);
  728. }
  729. break;
  730. case 'pic':
  731. if ($sort->pic) {
  732. if (! preg_match('/^http/', $sort->pic)) {
  733. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $sort->pic), $content);
  734. } else {
  735. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->pic), $content);
  736. }
  737. } else {
  738. $content = str_replace($matches[0][$i], '', $content);
  739. }
  740. break;
  741. case 'keywords': // 如果栏目关键字为空,则自动使用全局关键字
  742. if ($sort->keywords) {
  743. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->keywords), $content);
  744. } else {
  745. $content = str_replace($matches[0][$i], '{pboot:sitekeywords}', $content);
  746. }
  747. break;
  748. case 'description': // 如果栏目描述为空,则自动使用全局描述
  749. if ($sort->description) {
  750. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->description), $content);
  751. } else {
  752. $content = str_replace($matches[0][$i], '{pboot:sitedescription}', $content);
  753. }
  754. break;
  755. default:
  756. if (isset($sort->{$matches[1][$i]})) {
  757. $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->{$matches[1][$i]}), $content);
  758. } else {
  759. $content = str_replace($matches[0][$i], '', $content);
  760. }
  761. }
  762. }
  763. }
  764. return $content;
  765. }
  766. // 解析非列表页分类标签
  767. public function parserSpecialPageSortLabel($content, $id, $page, $link)
  768. {
  769. $pattern = '/\{sort:([\w]+)(\s+[^}]+)?\}/';
  770. if (preg_match_all($pattern, $content, $matches)) {
  771. $count = count($matches[0]);
  772. for ($i = 0; $i < $count; $i ++) {
  773. $params = $this->parserParam($matches[2][$i]);
  774. switch ($matches[1][$i]) {
  775. case 'tcode': // 顶级栏目ID
  776. $content = str_replace($matches[0][$i], $id, $content);
  777. break;
  778. case 'topname':
  779. $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), $page, $content);
  780. break;
  781. case 'toplink':
  782. $content = str_replace($matches[0][$i], $link, $content);
  783. break;
  784. case 'pcode': // 父栏目ID
  785. $content = str_replace($matches[0][$i], $id, $content);
  786. break;
  787. case 'parentname':
  788. $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), $page, $content);
  789. break;
  790. case 'parentlink':
  791. $content = str_replace($matches[0][$i], $link, $content);
  792. break;
  793. case 'scode': // 当前栏目ID
  794. $content = str_replace($matches[0][$i], $id, $content);
  795. break;
  796. case 'link':
  797. $content = str_replace($matches[0][$i], $link, $content);
  798. break;
  799. case 'name': // 当前分类名称
  800. $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), $page, $content);
  801. break;
  802. case 'keywords': // 当前分类关键字,使用全局
  803. $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), '{pboot:sitekeywords}', $content);
  804. break;
  805. case 'description': // 当前分类描述,使用全局
  806. $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), '{pboot:sitedescription}', $content);
  807. break;
  808. default:
  809. $content = str_replace($matches[0][$i], '', $content);
  810. }
  811. }
  812. }
  813. return $content;
  814. }
  815. // 解析指定分类标签
  816. public function parserSpecifySortLabel($content)
  817. {
  818. $pattern = '/\{pboot:sort(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:sort\}/';
  819. $pattern2 = '/\[sort:([\w]+)(\s+[^]]+)?\]/';
  820. if (preg_match_all($pattern, $content, $matches)) {
  821. $count = count($matches[0]);
  822. for ($i = 0; $i < $count; $i ++) {
  823. // 获取调节参数
  824. $params = $this->parserParam($matches[1][$i]);
  825. $scode = - 1;
  826. // 跳过未指定scode的列表
  827. if (! array_key_exists('scode', $params)) {
  828. continue;
  829. }
  830. if (! self::checkLabelLevel($params)) {
  831. $content = str_replace($matches[0][$i], '', $content);
  832. continue;
  833. }
  834. // 分离分类编码
  835. foreach ($params as $key => $value) {
  836. switch ($key) {
  837. case 'scode':
  838. $scode = $value;
  839. break;
  840. }
  841. }
  842. if (! $scode) {
  843. $scode = - 1;
  844. }
  845. // 读取一个或多个栏目数据
  846. $data = $this->model->getMultSort(escape_string($scode));
  847. // 无数据直接跳过
  848. if (! $data) {
  849. $content = str_replace($matches[0][$i], '', $content);
  850. continue;
  851. }
  852. // 匹配到内部标签
  853. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  854. $count2 = count($matches2[0]); // 循环内的内容标签数量
  855. } else {
  856. $count2 = 0;
  857. }
  858. $out_html = '';
  859. $key = 1;
  860. foreach ($data as $value) { // 按查询数据条数循环
  861. $one_html = $matches[2][$i];
  862. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  863. $params = $this->parserParam($matches2[2][$j]);
  864. switch ($matches2[1][$j]) {
  865. case 'n':
  866. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  867. break;
  868. case 'i':
  869. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  870. break;
  871. case 'link':
  872. if ($value->outlink) {
  873. $one_html = str_replace($matches2[0][$j], $value->outlink, $one_html);
  874. } else {
  875. $one_html = str_replace($matches2[0][$j], $this->parserLink($value->type, $value->urlname, 'list', $value->scode, $value->filename, '', ''), $one_html);
  876. }
  877. break;
  878. case 'ico':
  879. if ($value->ico) {
  880. if (! preg_match('/^http/', $value->ico)) {
  881. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->ico), $one_html);
  882. } else {
  883. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->ico), $one_html);
  884. }
  885. } else {
  886. $one_html = str_replace($matches2[0][$j], '', $one_html);
  887. }
  888. break;
  889. case 'pic':
  890. if ($value->pic) {
  891. if (! preg_match('/^http/', $value->pic)) {
  892. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pic), $one_html);
  893. } else {
  894. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pic), $one_html);
  895. }
  896. } else {
  897. $one_html = str_replace($matches2[0][$j], '', $one_html);
  898. }
  899. break;
  900. case 'rows':
  901. $one_html = str_replace($matches2[0][$j], $this->model->getSortRows($value->scode), $one_html); // 获取分类包含子类的内容数量
  902. break;
  903. default:
  904. if (isset($value->{$matches2[1][$j]})) {
  905. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  906. }
  907. }
  908. }
  909. $key ++;
  910. $out_html .= $one_html;
  911. }
  912. // 执行替换
  913. $content = str_replace($matches[0][$i], $out_html, $content);
  914. }
  915. }
  916. return $content;
  917. }
  918. // 解析筛选全部
  919. public function parserSelectAllLabel($content)
  920. {
  921. $pattern = '/\{pboot:selectall(\s+[^}]+)?\}/';
  922. if (preg_match_all($pattern, $content, $matches)) {
  923. $count = count($matches[0]);
  924. for ($i = 0; $i < $count; $i ++) {
  925. $params = $this->parserParam($matches[1][$i]);
  926. $text = '全部';
  927. $field = '';
  928. $class = '';
  929. $active = '';
  930. // 分离参数
  931. foreach ($params as $key => $value) {
  932. switch ($key) {
  933. case 'field':
  934. $field = $value;
  935. break;
  936. case 'text':
  937. $text = $value;
  938. break;
  939. case 'class':
  940. $class = $value;
  941. break;
  942. case 'active':
  943. $active = $value;
  944. break;
  945. }
  946. }
  947. // 跳过不带field的标签
  948. if (! $field) {
  949. continue;
  950. }
  951. $url_rule_type = $this->config('url_rule_type') ?: 3;
  952. $url_rule_suffix = $this->config('url_rule_suffix') ?: '.html';
  953. $url_break_char = $this->config('url_break_char') ?: '_';
  954. $url_rule_sort_suffix = '/';
  955. // 附加后缀及参数
  956. if ($url_rule_type == 1 || $url_rule_type == 2) {
  957. // 获取地址路径
  958. $url = parse_url(URL);
  959. // 避免非根目录首页筛选问题
  960. if (trim($url['path'], '/') == trim(SITE_DIR, '/')) {
  961. $url_rule_sort_suffix = '/';
  962. }
  963. $path = preg_replace('/\/page\/[0-9]+/', '', $url['path']); // 去除路径方式分页
  964. // 去后缀扩展
  965. if (! ! $pos = strripos($path, $url_rule_suffix)) {
  966. $path = substr($path, 0, $pos);
  967. }
  968. // 去路径分页,回到首页
  969. if (defined('CMS_PAGE_CUSTOM')) {
  970. $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', '$1', rtrim($path, '/'));
  971. } else {
  972. $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', '$1$2', rtrim($path, '/'));
  973. }
  974. // 拼接地址
  975. $path .= $url_rule_sort_suffix . query_string('p,s,' . $field);
  976. } elseif ($url_rule_type == 3) {
  977. $output = array();
  978. if (isset($_SERVER["QUERY_STRING"]) && ! ! $qs = $_SERVER["QUERY_STRING"]) {
  979. parse_str($qs, $output);
  980. unset($output['page']); // 去除字符串方式分页,回到第一页
  981. unset($output['p']); // 去除保留参数
  982. unset($output['s']); // 去除保留参数
  983. unset($output[$field]); // 不筛选该字段
  984. if ($output && ! current($output)) {
  985. $path_qs = key($output); // 第一个参数为路径信息,注意PHP数组会自动将点转换下划线
  986. unset($output[$path_qs]); // 去除路径参数
  987. $temp_suffix = substr($url_rule_suffix, 1);
  988. if (! ! $pos = strripos($path_qs, '_' . $temp_suffix)) {
  989. $path = substr($path_qs, 0, $pos); // 去扩展
  990. } else {
  991. $path = $path_qs;
  992. }
  993. // 去除原分页参数
  994. if (defined('CMS_PAGE_CUSTOM')) {
  995. $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', "$1", rtrim($path, '/'));
  996. } else {
  997. $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', "$1$2", rtrim($path, '/'));
  998. }
  999. $path = SITE_INDEX_DIR . '/?' . $path . $url_rule_sort_suffix;
  1000. } else {
  1001. $path = '';
  1002. }
  1003. $qs = http_build_query($output);
  1004. if ($path && $qs) { // 重组地址
  1005. $path = rtrim($path, '/') . '/&' . $qs;
  1006. } elseif ($qs) {
  1007. $path = SITE_INDEX_DIR . '/?' . $qs;
  1008. } elseif (! $path) {
  1009. $path = SITE_INDEX_DIR . '/';
  1010. }
  1011. } else {
  1012. $path = SITE_INDEX_DIR . '/';
  1013. }
  1014. }
  1015. // 如果有对本字段进行筛选,则不高亮
  1016. if (get($field, 'vars')) {
  1017. $out_html = '<a href="' . $path . '" class="' . $class . '">' . $text . '</a>';
  1018. } else {
  1019. $out_html = '<a href="' . $path . '" class="' . $active . '">' . $text . '</a>';
  1020. }
  1021. // 执行内容替换
  1022. $content = str_replace($matches[0][$i], $out_html, $content);
  1023. }
  1024. }
  1025. return $content;
  1026. }
  1027. // 解析筛选标签
  1028. public function parserSelectLabel($content)
  1029. {
  1030. $pattern = '/\{pboot:select(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:select\}/';
  1031. $pattern2 = '/\[select:([\w]+)(\s+[^]]+)?\]/';
  1032. // 参数处理
  1033. if (preg_match($pattern, $content)) {
  1034. $url_rule_type = $this->config('url_rule_type') ?: 3;
  1035. $url_rule_suffix = $this->config('url_rule_suffix') ?: '.html';
  1036. $url_break_char = $this->config('url_break_char') ?: '_';
  1037. $url_rule_sort_suffix = '/';
  1038. // 附加后缀及参数
  1039. if ($url_rule_type == 1 || $url_rule_type == 2) {
  1040. // 获取地址路径
  1041. $url = parse_url(URL);
  1042. // 避免非根目录首页筛选问题
  1043. if (trim($url['path'], '/') == trim(SITE_DIR, '/')) {
  1044. $url_rule_sort_suffix = '/';
  1045. }
  1046. $path = preg_replace('/\/page\/[0-9]+/', '', $url['path']); // 去除路径方式分页,回到第一页
  1047. // 去后缀扩展
  1048. if (! ! $pos = strripos($path, $url_rule_suffix)) {
  1049. $path = substr($path, 0, $pos);
  1050. }
  1051. // 去路径分页,回到首页
  1052. if (defined('CMS_PAGE_CUSTOM')) {
  1053. $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', '$1', rtrim($path, '/'));
  1054. } else {
  1055. $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', '$1$2', rtrim($path, '/'));
  1056. }
  1057. }
  1058. $output = array();
  1059. if (isset($_SERVER["QUERY_STRING"]) && ! ! $qs = $_SERVER["QUERY_STRING"]) {
  1060. parse_str($qs, $output);
  1061. unset($output['page']); // 去除字符串方式分页,回到第一页
  1062. unset($output['p']); // 去除保留参数
  1063. unset($output['s']); // 去除保留参数
  1064. if ($url_rule_type == 3 && $output && ! current($output)) {
  1065. $path_qs = key($output); // 第一个参数为路径信息,注意PHP数组会自动将点转换下划线
  1066. unset($output[$path_qs]); // 去除路径参数
  1067. $temp_suffix = substr($url_rule_suffix, 1);
  1068. if (! ! $pos = strripos($path_qs, '_' . $temp_suffix)) {
  1069. $path = substr($path_qs, 0, $pos); // 去扩展
  1070. } else {
  1071. $path = $path_qs;
  1072. }
  1073. // 去除原分页参数
  1074. if (defined('CMS_PAGE_CUSTOM')) {
  1075. $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', "$1", rtrim($path, '/'));
  1076. } else {
  1077. $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', "$1$2", rtrim($path, '/'));
  1078. }
  1079. $path = SITE_INDEX_DIR . '/?' . $path;
  1080. $not_index = true;
  1081. }
  1082. }
  1083. $path = isset($path) ? $path . $url_rule_sort_suffix : SITE_INDEX_DIR . '/';
  1084. }
  1085. // 执行匹配替换
  1086. if (preg_match_all($pattern, $content, $matches)) {
  1087. $count = count($matches[0]);
  1088. for ($i = 0; $i < $count; $i ++) {
  1089. // 获取调节参数
  1090. $params = $this->parserParam($matches[1][$i]);
  1091. $field = '';
  1092. // 分离参数
  1093. foreach ($params as $key => $value) {
  1094. switch ($key) {
  1095. case 'field':
  1096. $field = $value;
  1097. break;
  1098. }
  1099. }
  1100. // 跳过不带field的标签
  1101. if (! $field) {
  1102. continue;
  1103. }
  1104. // 读取数据
  1105. if (! ! $data = $this->model->getSelect(escape_string($field))) {
  1106. $data = explode(',', $data);
  1107. } else {
  1108. $data = array();
  1109. }
  1110. // 无数据直接替换为空并跳过
  1111. if (! $data) {
  1112. $content = str_replace($matches[0][$i], '', $content);
  1113. continue;
  1114. }
  1115. // 匹配到内部标签
  1116. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1117. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1118. } else {
  1119. $count2 = 0;
  1120. }
  1121. $out_html = '';
  1122. $key = 1;
  1123. foreach ($data as $value) { // 按查询数据条数循环
  1124. $one_html = $matches[2][$i];
  1125. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1126. $params = $this->parserParam($matches2[2][$j]);
  1127. switch ($matches2[1][$j]) {
  1128. case 'n':
  1129. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  1130. break;
  1131. case 'i':
  1132. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  1133. break;
  1134. case 'value':
  1135. $one_html = str_replace($matches2[0][$j], $value, $one_html);
  1136. break;
  1137. case 'current':
  1138. $one_html = str_replace($matches2[0][$j], get($field, 'vars'), $one_html);
  1139. break;
  1140. case 'link':
  1141. $qs = $output; // 需使用中间变量,避免多个链接相同问题
  1142. $qs[$field] = $value;
  1143. $qs = http_build_query($qs);
  1144. if ($url_rule_type == 3 && $not_index) {
  1145. $link = rtrim($path, '/') . '/&' . $qs;
  1146. } else {
  1147. $link = $path . '?' . $qs;
  1148. }
  1149. $one_html = str_replace($matches2[0][$j], $link, $one_html);
  1150. break;
  1151. }
  1152. }
  1153. $key ++;
  1154. $out_html .= $one_html;
  1155. }
  1156. $content = str_replace($matches[0][$i], $out_html, $content);
  1157. }
  1158. }
  1159. return $content;
  1160. }
  1161. // 解析内容列表标签
  1162. public function parserListLabel($content, $cscode = '')
  1163. {
  1164. $pattern = '/\{pboot:list(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:list\}/';
  1165. $pattern2 = '/\[list:([\w\+\-\*\/\%]+)(\s+[^]]+)?\]/';
  1166. if (preg_match_all($pattern, $content, $matches)) {
  1167. $count = count($matches[0]);
  1168. for ($i = 0; $i < $count; $i ++) {
  1169. // 获取调节参数
  1170. $params = $this->parserParam($matches[1][$i]);
  1171. if (! self::checkLabelLevel($params)) {
  1172. $content = str_replace($matches[0][$i], '', $content);
  1173. continue;
  1174. }
  1175. $num = $this->config('pagesize'); // 未设置条数时使用默认15
  1176. $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC'; // 默认排序
  1177. $filter = ''; // 过滤
  1178. $tags = ''; // tag标签
  1179. $fuzzy = true; // 设置过滤、tag、筛选是否模糊匹配
  1180. $ispics = ''; // 是否多图
  1181. $isico = ''; // 是否缩略图
  1182. $istop = ''; // 是否置顶
  1183. $isrecommend = ''; // 是否推荐
  1184. $isheadline = ''; // 是否头条
  1185. $start = 1; // 起始条数,默认第一条开始
  1186. $lfield = ''; // 查询字段限制
  1187. // 判断当前栏目和指定栏目
  1188. if ($cscode && ! array_key_exists('scode', $params)) { // 解析当前
  1189. $scode = $cscode;
  1190. $page = true; // 如果未指定分类默认分页
  1191. } elseif (! $cscode && array_key_exists('scode', $params)) { // 解析指定
  1192. $scode = $params['scode'];
  1193. $page = false; // 如果指定分类默认不分页
  1194. } else {
  1195. continue;
  1196. }
  1197. if ($scode == '*') {
  1198. $scode = '';
  1199. }
  1200. // 分离参数
  1201. foreach ($params as $key => $value) {
  1202. switch ($key) {
  1203. case 'num':
  1204. $num = $value;
  1205. break;
  1206. case 'order':
  1207. switch ($value) {
  1208. case 'id':
  1209. $order = 'a.id DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC';
  1210. break;
  1211. case 'date':
  1212. $order = 'a.date DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.id DESC';
  1213. break;
  1214. case 'sorting':
  1215. $order = 'a.sorting ASC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.date DESC,a.id DESC';
  1216. break;
  1217. case 'istop':
  1218. $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  1219. break;
  1220. case 'isrecommend':
  1221. $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  1222. break;
  1223. case 'isheadline':
  1224. $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  1225. break;
  1226. case 'visits':
  1227. case 'likes':
  1228. case 'oppose':
  1229. $order = $value . ' DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  1230. break;
  1231. case 'random': // 随机取数
  1232. $db_type = get_db_type();
  1233. if ($db_type == 'mysql') {
  1234. $order = "RAND()";
  1235. } elseif ($db_type == 'sqlite') {
  1236. $order = "RANDOM()";
  1237. }
  1238. break;
  1239. default:
  1240. if ($value) {
  1241. $orders = explode(',', $value);
  1242. foreach ($orders as $k => $v) {
  1243. if (strpos($v, 'ext_') === 0) {
  1244. $orders[$k] = 'e.' . $v;
  1245. } else {
  1246. $orders[$k] = 'a.' . $v;
  1247. }
  1248. }
  1249. $value = implode(',', $orders);
  1250. $order = $value . ',a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  1251. }
  1252. }
  1253. break;
  1254. case 'filter':
  1255. $filter = $value;
  1256. break;
  1257. case 'fuzzy':
  1258. $fuzzy = $value;
  1259. break;
  1260. case 'tags':
  1261. $tags = $value;
  1262. break;
  1263. case 'ispics':
  1264. $ispics = $value;
  1265. break;
  1266. case 'isico':
  1267. $isico = $value;
  1268. break;
  1269. case 'istop':
  1270. $istop = $value;
  1271. break;
  1272. case 'isrecommend':
  1273. $isrecommend = $value;
  1274. break;
  1275. case 'isheadline':
  1276. $isheadline = $value;
  1277. break;
  1278. case 'page':
  1279. $page = $value;
  1280. break;
  1281. case 'start':
  1282. $start = $value;
  1283. break;
  1284. case 'lfield':
  1285. $lfield = $value;
  1286. break;
  1287. }
  1288. }
  1289. // filter数据筛选
  1290. $where1 = array();
  1291. if ($filter) {
  1292. $filter = explode('|', $filter);
  1293. if (count($filter) == 2) {
  1294. $filter_arr = explode(',', $filter[1]);
  1295. if ($filter[0] == 'title') {
  1296. $filter[0] = 'a.title';
  1297. }
  1298. foreach ($filter_arr as $value) {
  1299. if ($value) {
  1300. if ($fuzzy) {
  1301. $where1[] = $filter[0] . " like '%" . escape_string($value) . "%'";
  1302. } else {
  1303. $where1[] = $filter[0] . "='" . escape_string($value) . "'";
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. // tags数据参数筛选
  1310. $where2 = array();
  1311. if ($tags) {
  1312. $tags_arr = explode(',', $tags);
  1313. foreach ($tags_arr as $value) {
  1314. if ($value) {
  1315. if ($fuzzy) {
  1316. $where2[] = "a.tags like '%" . escape_string($value) . "%'";
  1317. } else {
  1318. $where2[] = "a.tags='" . escape_string($value) . "'";
  1319. }
  1320. }
  1321. }
  1322. }
  1323. // 重置存储条件
  1324. $where3 = array();
  1325. // 只对有分页的列表有效
  1326. if ($page) {
  1327. // tags数据传值筛选
  1328. if (! ! $get_tag = get('tag', 'vars')) {
  1329. if ($fuzzy) {
  1330. $where2[] = "a.tags like '%" . $get_tag . "%'";
  1331. } else {
  1332. $where2[] = "a.tags='" . $get_tag . "'";
  1333. }
  1334. }
  1335. // 扩展字段数据筛选
  1336. foreach ($_GET as $key => $value) {
  1337. if (preg_match('/^ext_[\w\-]+$/', $key)) { // 其他字段不加入
  1338. $where3[$key] = get($key, 'vars');
  1339. }
  1340. }
  1341. }
  1342. // 判断多图调节参数
  1343. if ($ispics !== '') {
  1344. if ($ispics) {
  1345. $where3[] = "a.pics<>''";
  1346. } else {
  1347. $where3[] = "a.pics=''";
  1348. }
  1349. }
  1350. // 判断缩略图调节参数
  1351. if ($isico !== '') {
  1352. if ($isico) {
  1353. $where3[] = "a.ico<>''";
  1354. } else {
  1355. $where3[] = "a.ico=''";
  1356. }
  1357. }
  1358. // 判断置顶调节参数
  1359. if ($istop !== '') {
  1360. if ($istop) {
  1361. $where3[] = "a.istop=1";
  1362. } else {
  1363. $where3[] = "a.istop=0";
  1364. }
  1365. }
  1366. // 判断推荐调节参数
  1367. if ($isrecommend !== '') {
  1368. if ($isrecommend) {
  1369. $where3[] = "a.isrecommend=1";
  1370. } else {
  1371. $where3[] = "a.isrecommend=0";
  1372. }
  1373. }
  1374. // 判断头条调节参数
  1375. if ($isheadline !== '') {
  1376. if ($isheadline) {
  1377. $where3[] = "a.isheadline=1";
  1378. } else {
  1379. $where3[] = "a.isheadline=0";
  1380. }
  1381. }
  1382. // 起始数校验
  1383. if (! is_numeric($start) || $start < 1) {
  1384. $start = 1;
  1385. }
  1386. if ($page) {
  1387. if (isset($paging)) {
  1388. error('请不要在一个页面使用多个具有分页的列表,您可将多余的使用page=0关闭分页!');
  1389. } else {
  1390. $paging = true;
  1391. $data = $this->model->getLists($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield);
  1392. }
  1393. } else {
  1394. $data = $this->model->getList($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield);
  1395. }
  1396. // 无数据直接替换
  1397. if (! $data) {
  1398. $content = str_replace($matches[0][$i], '', $content);
  1399. continue;
  1400. }
  1401. // 匹配到内部标签
  1402. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1403. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1404. } else {
  1405. $count2 = 0;
  1406. }
  1407. $out_html = '';
  1408. $pagenum = defined('PAGE') ? PAGE : 1;
  1409. $key = ($pagenum - 1) * $num + 1;
  1410. foreach ($data as $value) { // 按查询数据条数循环
  1411. $one_html = $matches[2][$i];
  1412. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1413. $params = $this->parserParam($matches2[2][$j]);
  1414. $one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
  1415. }
  1416. $key ++;
  1417. $out_html .= $one_html;
  1418. }
  1419. $content = str_replace($matches[0][$i], $out_html, $content);
  1420. }
  1421. }
  1422. return $content;
  1423. }
  1424. // 解析当前内容标签
  1425. public function parserCurrentContentLabel($content, $sort, $data)
  1426. {
  1427. $pattern = '/\{content:([\w]+)(\s+[^}]+)?\}/';
  1428. if (preg_match_all($pattern, $content, $matches)) {
  1429. $count = count($matches[0]);
  1430. for ($i = 0; $i < $count; $i ++) {
  1431. // 无数据直接替换并跳过
  1432. if (! $data) {
  1433. $content = str_replace($matches[0][$i], '', $content);
  1434. continue;
  1435. }
  1436. $params = $this->parserParam($matches[2][$i]);
  1437. $content = $this->parserContent($matches[1][$i], $matches[0][$i], $content, $data, $params, $sort);
  1438. }
  1439. }
  1440. // 新增计数代码,非缓存方式,直接计数
  1441. if ($this->config('tpl_html_cache')) {
  1442. if (! isset($this->var['addvisits'])) {
  1443. $visits = "<script src='" . Url::get('home/Do/visits/id/' . $data->id) . "' async='async'></script>";
  1444. $content = preg_replace('/(<\/body>)/i', $visits . "\n$1", $content);
  1445. $this->var['addvisits'] = true;
  1446. }
  1447. } else {
  1448. $do = new DoModel();
  1449. $do->addVisits($data->id);
  1450. }
  1451. return $content;
  1452. }
  1453. // 解析指定内容标签,单页支持使用scode调用
  1454. public function parserSpecifyContentLabel($content)
  1455. {
  1456. $pattern = '/\{pboot:content(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:content\}/';
  1457. $pattern2 = '/\[content:([\w]+)(\s+[^]]+)?\]/';
  1458. if (preg_match_all($pattern, $content, $matches)) {
  1459. $count = count($matches[0]);
  1460. for ($i = 0; $i < $count; $i ++) {
  1461. // 获取调节参数
  1462. $params = $this->parserParam($matches[1][$i]);
  1463. if (! self::checkLabelLevel($params)) {
  1464. $content = str_replace($matches[0][$i], '', $content);
  1465. continue;
  1466. }
  1467. $id = - 1;
  1468. $scode = - 1;
  1469. // 跳过未指定id和scode的列表
  1470. if (array_key_exists('id', $params)) {
  1471. $id = $params['id'];
  1472. $data = $this->model->getContent(escape_string($id));
  1473. } elseif (array_key_exists('scode', $params)) {
  1474. $scode = $params['scode'];
  1475. $data = $this->model->getAbout(escape_string($scode));
  1476. } else {
  1477. continue;
  1478. }
  1479. // 读取数据
  1480. if (! $data) {
  1481. $content = str_replace($matches[0][$i], '', $content);
  1482. continue;
  1483. }
  1484. // 匹配到内部标签
  1485. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1486. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1487. } else {
  1488. $count2 = 0;
  1489. }
  1490. $out_html = $matches[2][$i];
  1491. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1492. $params = $this->parserParam($matches2[2][$j]);
  1493. $out_html = $this->parserContent($matches2[1][$j], $matches2[0][$j], $out_html, $data, $params, $scode);
  1494. }
  1495. // 执行替换
  1496. $content = str_replace($matches[0][$i], $out_html, $content);
  1497. }
  1498. }
  1499. return $content;
  1500. }
  1501. // 解析指定内容多图
  1502. public function parserContentPicsLabel($content)
  1503. {
  1504. $pattern = '/\{pboot:pics(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:pics\}/';
  1505. $pattern2 = '/\[pics:([\w]+)(\s+[^]]+)?\]/';
  1506. if (preg_match_all($pattern, $content, $matches)) {
  1507. $count = count($matches[0]);
  1508. for ($i = 0; $i < $count; $i ++) {
  1509. // 获取调节参数
  1510. $params = $this->parserParam($matches[1][$i]);
  1511. $id = - 1;
  1512. $field = "pics";
  1513. if (! self::checkLabelLevel($params)) {
  1514. $content = str_replace($matches[0][$i], '', $content);
  1515. continue;
  1516. }
  1517. // 跳过未指定id的列表
  1518. if (! array_key_exists('id', $params)) {
  1519. continue;
  1520. }
  1521. // 分离参数
  1522. foreach ($params as $key => $value) {
  1523. switch ($key) {
  1524. case 'id':
  1525. $id = $value;
  1526. break;
  1527. case 'num':
  1528. $num = $value;
  1529. break;
  1530. case 'field':
  1531. $field = $value;
  1532. break;
  1533. }
  1534. }
  1535. // 读取内容多图
  1536. if (! ! $rs = $this->model->getContentPics(escape_string($id), $field)) {
  1537. $pics = explode(',', $rs->$field);
  1538. $picstitle = explode(',', $rs->picstitle);
  1539. } else {
  1540. $pics = array();
  1541. $picstitle = array();
  1542. }
  1543. // 无图直接替换为空并跳过
  1544. if (! $pics) {
  1545. $content = str_replace($matches[0][$i], '', $content);
  1546. continue;
  1547. }
  1548. // 匹配到内部标签
  1549. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1550. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1551. } else {
  1552. $count2 = 0;
  1553. }
  1554. $out_html = '';
  1555. $key = 1;
  1556. foreach ($pics as $vkey => $value) { // 按查询图片条数循环
  1557. $one_html = $matches[2][$i];
  1558. if (! $value)
  1559. continue;
  1560. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1561. $params = $this->parserParam($matches2[2][$j]);
  1562. switch ($matches2[1][$j]) {
  1563. case 'n':
  1564. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  1565. break;
  1566. case 'i':
  1567. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  1568. break;
  1569. case 'src':
  1570. if ($value) {
  1571. if (! preg_match('/^http/', $value)) {
  1572. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value), $one_html);
  1573. } else {
  1574. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value), $one_html);
  1575. }
  1576. } else {
  1577. $one_html = str_replace($matches2[0][$j], '', $one_html);
  1578. }
  1579. break;
  1580. case 'title':
  1581. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, isset($picstitle[$vkey]) ? $picstitle[$vkey] : ''), $one_html);
  1582. break;
  1583. default:
  1584. $one_html = str_replace($matches2[0][$j], '', $one_html);
  1585. }
  1586. }
  1587. $key ++;
  1588. $out_html .= $one_html;
  1589. if (isset($num) && $key > $num) {
  1590. unset($num);
  1591. break;
  1592. }
  1593. }
  1594. $content = str_replace($matches[0][$i], $out_html, $content);
  1595. }
  1596. }
  1597. return $content;
  1598. }
  1599. // 解析指定内容多选
  1600. public function parserContentCheckboxLabel($content)
  1601. {
  1602. $pattern = '/\{pboot:checkbox(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:checkbox\}/';
  1603. $pattern2 = '/\[checkbox:([\w]+)(\s+[^]]+)?\]/';
  1604. if (preg_match_all($pattern, $content, $matches)) {
  1605. $count = count($matches[0]);
  1606. for ($i = 0; $i < $count; $i ++) {
  1607. // 获取调节参数
  1608. $params = $this->parserParam($matches[1][$i]);
  1609. $id = - 1;
  1610. if (! self::checkLabelLevel($params)) {
  1611. $content = str_replace($matches[0][$i], '', $content);
  1612. continue;
  1613. }
  1614. // 跳过未指定id的调用
  1615. if (! array_key_exists('id', $params)) {
  1616. continue;
  1617. }
  1618. // 跳过未指定field的调用
  1619. if (! array_key_exists('field', $params)) {
  1620. continue;
  1621. }
  1622. // 分离参数
  1623. foreach ($params as $key => $value) {
  1624. switch ($key) {
  1625. case 'id':
  1626. $id = $value;
  1627. break;
  1628. case 'field':
  1629. $field = $value;
  1630. break;
  1631. }
  1632. }
  1633. // 读取内容多图
  1634. if (! ! $checkboxs = $this->model->getContentCheckbox(escape_string($id), escape_string($field))) {
  1635. $data = explode(',', $checkboxs);
  1636. } else {
  1637. $data = array();
  1638. }
  1639. // 无内容直接替换为空并跳过
  1640. if (! $data) {
  1641. $content = str_replace($matches[0][$i], '', $content);
  1642. continue;
  1643. }
  1644. // 匹配到内部标签
  1645. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1646. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1647. } else {
  1648. $count2 = 0;
  1649. }
  1650. $out_html = '';
  1651. $key = 1;
  1652. foreach ($data as $value) { // 按条数循环
  1653. $one_html = $matches[2][$i];
  1654. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1655. $params = $this->parserParam($matches2[2][$j]);
  1656. switch ($matches2[1][$j]) {
  1657. case 'n':
  1658. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  1659. break;
  1660. case 'i':
  1661. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  1662. break;
  1663. case 'text':
  1664. $one_html = str_replace($this->adjustLabelData($params, $matches2[0][$j]), $value, $one_html);
  1665. break;
  1666. }
  1667. }
  1668. $key ++;
  1669. $out_html .= $one_html;
  1670. }
  1671. $content = str_replace($matches[0][$i], $out_html, $content);
  1672. }
  1673. }
  1674. return $content;
  1675. }
  1676. // 解析内容tags
  1677. public function parserContentTagsLabel($content)
  1678. {
  1679. $pattern = '/\{pboot:tags(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:tags\}/';
  1680. $pattern2 = '/\[tags:([\w]+)(\s+[^]]+)?\]/';
  1681. if (preg_match_all($pattern, $content, $matches)) {
  1682. $count = count($matches[0]);
  1683. for ($i = 0; $i < $count; $i ++) {
  1684. // 获取调节参数
  1685. $params = $this->parserParam($matches[1][$i]);
  1686. if (! self::checkLabelLevel($params)) {
  1687. $content = str_replace($matches[0][$i], '', $content);
  1688. continue;
  1689. }
  1690. $id = ''; // 调取指定内容的tags
  1691. $scode = ''; // 调取指定分类的tags
  1692. $target = 'list'; // 标签跳转目标,可以是内容列表,也可以是独立tags.html页面
  1693. // 分离参数
  1694. foreach ($params as $key => $value) {
  1695. switch ($key) {
  1696. case 'id':
  1697. $id = $value;
  1698. break;
  1699. case 'scode':
  1700. $scode = $value;
  1701. break;
  1702. case 'num':
  1703. $num = $value;
  1704. break;
  1705. case 'target':
  1706. $target = $value;
  1707. }
  1708. }
  1709. // 获取数据
  1710. $data = array();
  1711. if ($id) { // 获取单个内容的tags
  1712. if (strpos($scode, ',') !== false) {
  1713. error('模板中指定id输出tags时不允许scode指定多个栏目!');
  1714. }
  1715. if (! ! $rs = $this->model->getContentTags(escape_string($id))) {
  1716. if ($rs->tags) {
  1717. $tags = explode(',', $rs->tags);
  1718. $scode = $scode ?: $rs->scode;
  1719. $sort = $this->model->getSort($scode); // 获取栏目信息
  1720. foreach ($tags as $key => $value) {
  1721. $data[] = array(
  1722. 'sort' => $sort,
  1723. 'tags' => $value
  1724. );
  1725. }
  1726. }
  1727. }
  1728. } elseif ($scode) { // 获取指定栏目的tags
  1729. $scodes = explode(',', $scode); // 多个栏目是分别获取
  1730. foreach ($scodes as $key => $value) {
  1731. $sort = $this->model->getSort($value); // 获取栏目信息
  1732. if (! ! $rs = $this->model->getSortTags($value)) {
  1733. $tags = implode(',', $rs); // 把栏目tags串起来
  1734. $tags = array_unique(explode(',', $tags)); // 再把所有tags组成数组并去重
  1735. foreach ($tags as $key2 => $value2) {
  1736. if (! in_array($value2, array_column($data, 'tags'))) { // 避免重复输出
  1737. $data[] = array(
  1738. 'sort' => $sort,
  1739. 'tags' => $value2
  1740. );
  1741. }
  1742. }
  1743. }
  1744. }
  1745. } else {
  1746. // 全部栏目时候强制标签页形式
  1747. $target = 'tag';
  1748. if (! ! $rs = $this->model->getSortTags('')) {
  1749. $tags = implode(',', $rs); // 把栏目tags串起来
  1750. $tags = array_unique(explode(',', $tags)); // 再把所有tags组成数组并去重
  1751. foreach ($tags as $key2 => $value2) {
  1752. if (! in_array($value2, array_column($data, 'tags'))) { // 避免重复输出
  1753. $data[] = array(
  1754. 'tags' => $value2
  1755. );
  1756. }
  1757. }
  1758. }
  1759. }
  1760. // 无内容直接替换为空并跳过
  1761. if (! $data) {
  1762. $content = str_replace($matches[0][$i], '', $content);
  1763. continue;
  1764. }
  1765. // 匹配到内部标签
  1766. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1767. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1768. } else {
  1769. $count2 = 0;
  1770. }
  1771. $out_html = '';
  1772. $key = 1;
  1773. foreach ($data as $value) { // 按条数循环
  1774. $one_html = $matches[2][$i];
  1775. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1776. $params = $this->parserParam($matches2[2][$j]);
  1777. switch ($matches2[1][$j]) {
  1778. case 'n':
  1779. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  1780. break;
  1781. case 'i':
  1782. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  1783. break;
  1784. case 'text':
  1785. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value['tags']), $one_html);
  1786. break;
  1787. case 'link':
  1788. $url_rule_type = $this->config('url_rule_type') ?: 3;
  1789. if ($target == 'tag') {
  1790. if ($url_rule_type == 3) {
  1791. $link = Url::home('tag=' . urlencode($value['tags']), false);
  1792. } else {
  1793. $link = Url::home('tag/' . urlencode($value['tags']), false);
  1794. }
  1795. } else {
  1796. $link = $this->parserLink($value['sort']->type, $value['sort']->urlname, 'list', $value['sort']->scode, $value['sort']->filename, '', '');
  1797. if ($url_rule_type == 3) {
  1798. $link = $link . '&tag=' . urlencode($value['tags']);
  1799. } else {
  1800. $link = $link . '?tag=' . urlencode($value['tags']);
  1801. }
  1802. }
  1803. $one_html = str_replace($matches2[0][$j], $link, $one_html);
  1804. break;
  1805. }
  1806. }
  1807. $key ++;
  1808. $out_html .= $one_html;
  1809. if (isset($num) && $key > $num) {
  1810. unset($num);
  1811. break;
  1812. }
  1813. }
  1814. $content = str_replace($matches[0][$i], $out_html, $content);
  1815. }
  1816. }
  1817. return $content;
  1818. }
  1819. // 解析幻灯片标签
  1820. public function parserSlideLabel($content)
  1821. {
  1822. $pattern = '/\{pboot:slide(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:slide\}/';
  1823. $pattern2 = '/\[slide:([\w]+)(\s+[^]]+)?\]/';
  1824. if (preg_match_all($pattern, $content, $matches)) {
  1825. $count = count($matches[0]);
  1826. for ($i = 0; $i < $count; $i ++) {
  1827. // 获取调节参数
  1828. $params = $this->parserParam($matches[1][$i]);
  1829. if (! self::checkLabelLevel($params)) {
  1830. $content = str_replace($matches[0][$i], '', $content);
  1831. continue;
  1832. }
  1833. $gid = 1;
  1834. $num = 5;
  1835. $start = 1;
  1836. // 跳过未指定gid的标签
  1837. if (! array_key_exists('gid', $params)) {
  1838. continue;
  1839. }
  1840. // 分离参数
  1841. foreach ($params as $key => $value) {
  1842. switch ($key) {
  1843. case 'gid':
  1844. $gid = $value;
  1845. break;
  1846. case 'num':
  1847. $num = $value;
  1848. break;
  1849. case 'start':
  1850. $start = $value;
  1851. break;
  1852. }
  1853. }
  1854. // 起始数校验
  1855. if (! is_numeric($start) || $start < 1) {
  1856. $start = 1;
  1857. }
  1858. // 读取数据
  1859. if (! $data = $this->model->getSlides(escape_string($gid), escape_string($num), $start)) {
  1860. $content = str_replace($matches[0][$i], '', $content);
  1861. continue;
  1862. }
  1863. // 匹配到内部标签
  1864. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1865. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1866. } else {
  1867. $count2 = 0;
  1868. }
  1869. $out_html = '';
  1870. $key = 1;
  1871. foreach ($data as $value) { // 按查询数据条数循环
  1872. $one_html = $matches[2][$i];
  1873. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1874. $params = $this->parserParam($matches2[2][$j]);
  1875. switch ($matches2[1][$j]) {
  1876. case 'n':
  1877. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  1878. break;
  1879. case 'i':
  1880. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  1881. break;
  1882. case 'src':
  1883. if ($value->pic) {
  1884. if (! preg_match('/^http/', $value->pic)) {
  1885. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pic), $one_html);
  1886. } else {
  1887. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pic), $one_html);
  1888. }
  1889. } else {
  1890. $one_html = str_replace($matches2[0][$j], '', $one_html);
  1891. }
  1892. break;
  1893. default:
  1894. if (isset($value->{$matches2[1][$j]})) {
  1895. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  1896. }
  1897. }
  1898. }
  1899. $key ++;
  1900. $out_html .= $one_html;
  1901. }
  1902. $content = str_replace($matches[0][$i], $out_html, $content);
  1903. }
  1904. }
  1905. return $content;
  1906. }
  1907. // 解析友情链接标签
  1908. public function parserLinkLabel($content)
  1909. {
  1910. $pattern = '/\{pboot:link(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:link\}/';
  1911. $pattern2 = '/\[link:([\w]+)(\s+[^]]+)?\]/';
  1912. if (preg_match_all($pattern, $content, $matches)) {
  1913. $count = count($matches[0]);
  1914. for ($i = 0; $i < $count; $i ++) {
  1915. // 获取调节参数
  1916. $params = $this->parserParam($matches[1][$i]);
  1917. if (! self::checkLabelLevel($params)) {
  1918. $content = str_replace($matches[0][$i], '', $content);
  1919. continue;
  1920. }
  1921. $gid = 1;
  1922. $num = 10;
  1923. $start = 1;
  1924. // 跳过未指定gid的标签
  1925. if (! array_key_exists('gid', $params)) {
  1926. continue;
  1927. }
  1928. foreach ($params as $key => $value) {
  1929. switch ($key) {
  1930. case 'gid':
  1931. $gid = $value;
  1932. break;
  1933. case 'num':
  1934. $num = $value;
  1935. break;
  1936. case 'start':
  1937. $start = $value;
  1938. break;
  1939. }
  1940. }
  1941. // 起始数校验
  1942. if (! is_numeric($start) || $start < 1) {
  1943. $start = 1;
  1944. }
  1945. // 读取数据
  1946. if (! $data = $this->model->getLinks(escape_string($gid), escape_string($num), $start)) {
  1947. $content = str_replace($matches[0][$i], '', $content);
  1948. continue;
  1949. }
  1950. // 匹配到内部标签
  1951. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  1952. $count2 = count($matches2[0]); // 循环内的内容标签数量
  1953. } else {
  1954. $count2 = 0;
  1955. }
  1956. $out_html = '';
  1957. $key = 1;
  1958. foreach ($data as $value) { // 按查询数据条数循环
  1959. $one_html = $matches[2][$i];
  1960. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  1961. $params = $this->parserParam($matches2[2][$j]);
  1962. switch ($matches2[1][$j]) {
  1963. case 'n':
  1964. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  1965. break;
  1966. case 'i':
  1967. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  1968. break;
  1969. case 'logo':
  1970. if ($value->logo) {
  1971. if (! preg_match('/^http/', $value->logo)) {
  1972. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->logo), $one_html);
  1973. } else {
  1974. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->logo), $one_html);
  1975. }
  1976. } else {
  1977. $one_html = str_replace($matches2[0][$j], '', $one_html);
  1978. }
  1979. break;
  1980. default:
  1981. if (isset($value->{$matches2[1][$j]})) {
  1982. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  1983. }
  1984. }
  1985. }
  1986. $key ++;
  1987. $out_html .= $one_html;
  1988. }
  1989. $content = str_replace($matches[0][$i], $out_html, $content);
  1990. }
  1991. }
  1992. return $content;
  1993. }
  1994. // 解析留言板标签
  1995. public function parserMessageLabel($content)
  1996. {
  1997. $pattern = '/\{pboot:message(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:message\}/';
  1998. $pattern2 = '/\[message:([\w]+)(\s+[^]]+)?\]/';
  1999. if (preg_match_all($pattern, $content, $matches)) {
  2000. $count = count($matches[0]);
  2001. for ($i = 0; $i < $count; $i ++) {
  2002. // 获取调节参数
  2003. $params = $this->parserParam($matches[1][$i]);
  2004. if (! self::checkLabelLevel($params)) {
  2005. $content = str_replace($matches[0][$i], '', $content);
  2006. continue;
  2007. }
  2008. $num = $this->config('pagesize');
  2009. $page = true;
  2010. $start = 1;
  2011. $lg = '';
  2012. foreach ($params as $key => $value) {
  2013. switch ($key) {
  2014. case 'num':
  2015. $num = $value;
  2016. break;
  2017. case 'page':
  2018. $page = $value;
  2019. break;
  2020. case 'start':
  2021. $start = $value;
  2022. break;
  2023. case 'lg':
  2024. $lg = $value;
  2025. break;
  2026. }
  2027. }
  2028. // 起始数校验
  2029. if (! is_numeric($start) || $start < 1) {
  2030. $start = 1;
  2031. }
  2032. // 读取数据
  2033. if (! $data = $this->model->getMessage(escape_string($num), $page, $start, $lg)) {
  2034. $content = str_replace($matches[0][$i], '', $content);
  2035. continue;
  2036. }
  2037. // 匹配到内部标签
  2038. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2039. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2040. } else {
  2041. $count2 = 0;
  2042. }
  2043. $out_html = '';
  2044. $pagenum = defined('PAGE') ? PAGE : 1;
  2045. $key = ($pagenum - 1) * $num + 1;
  2046. foreach ($data as $value) { // 按查询数据条数循环
  2047. $one_html = $matches[2][$i];
  2048. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2049. $params = $this->parserParam($matches2[2][$j]);
  2050. switch ($matches2[1][$j]) {
  2051. case 'n':
  2052. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  2053. break;
  2054. case 'i':
  2055. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  2056. break;
  2057. case 'ip':
  2058. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, long2ip($value->user_ip)), $one_html);
  2059. break;
  2060. case 'os':
  2061. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_os), $one_html);
  2062. break;
  2063. case 'bs':
  2064. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_bs), $one_html);
  2065. break;
  2066. case 'askdate':
  2067. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->create_time), $one_html);
  2068. break;
  2069. case 'replydate':
  2070. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->update_time), $one_html);
  2071. break;
  2072. case 'headpic':
  2073. if ($value->headpic) {
  2074. if (! preg_match('/^http/', $value->headpic)) {
  2075. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->headpic), $one_html);
  2076. } else {
  2077. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->headpic), $one_html);
  2078. }
  2079. } else {
  2080. $one_html = str_replace($matches2[0][$j], SITE_DIR . '/apps/admin/view/default/images/logo.png', $one_html);
  2081. }
  2082. break;
  2083. case 'nickname':
  2084. if ($value->nickname) {
  2085. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->nickname), $one_html);
  2086. } elseif (! $value->username) {
  2087. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, "匿名用户"), $one_html);
  2088. }
  2089. break;
  2090. default:
  2091. if (isset($value->{$matches2[1][$j]})) {
  2092. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  2093. } else {
  2094. $one_html = str_replace($matches2[0][$j], '', $one_html);
  2095. }
  2096. }
  2097. }
  2098. $key ++;
  2099. $out_html .= $one_html;
  2100. }
  2101. $content = str_replace($matches[0][$i], $out_html, $content);
  2102. }
  2103. }
  2104. return $content;
  2105. }
  2106. // 解析表单数据标签
  2107. public function parserFormLabel($content)
  2108. {
  2109. $pattern = '/\{pboot:formlist(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:formlist\}/';
  2110. $pattern2 = '/\[form:([\w]+)(\s+[^]]+)?\]/';
  2111. if (preg_match_all($pattern, $content, $matches)) {
  2112. $count = count($matches[0]);
  2113. for ($i = 0; $i < $count; $i ++) {
  2114. // 获取调节参数
  2115. $params = $this->parserParam($matches[1][$i]);
  2116. if (! self::checkLabelLevel($params)) {
  2117. $content = str_replace($matches[0][$i], '', $content);
  2118. continue;
  2119. }
  2120. $num = $this->config('pagesize');
  2121. $fcode = - 1;
  2122. $page = true;
  2123. $start = 1;
  2124. // 跳过未指定fcode的标签
  2125. if (! array_key_exists('fcode', $params)) {
  2126. continue;
  2127. }
  2128. foreach ($params as $key => $value) {
  2129. switch ($key) {
  2130. case 'num':
  2131. $num = $value;
  2132. break;
  2133. case 'fcode':
  2134. $fcode = $value;
  2135. break;
  2136. case 'page':
  2137. $page = $value;
  2138. break;
  2139. case 'start':
  2140. $start = $value;
  2141. break;
  2142. }
  2143. }
  2144. // 起始数校验
  2145. if (! is_numeric($start) || $start < 1) {
  2146. $start = 1;
  2147. }
  2148. // 获取表名称
  2149. if (! $table = $this->model->getFormTable(escape_string($fcode))) {
  2150. $content = str_replace($matches[0][$i], '', $content);
  2151. continue;
  2152. }
  2153. // 读取数据
  2154. if (! $data = $this->model->getForm($table, escape_string($num), $page, $start)) {
  2155. $content = str_replace($matches[0][$i], '', $content);
  2156. continue;
  2157. }
  2158. // 匹配到内部标签
  2159. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2160. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2161. } else {
  2162. $count2 = 0;
  2163. }
  2164. $out_html = '';
  2165. $pagenum = defined('PAGE') ? PAGE : 1;
  2166. $key = ($pagenum - 1) * $num + 1;
  2167. foreach ($data as $value) { // 按查询数据条数循环
  2168. $one_html = $matches[2][$i];
  2169. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2170. $params = $this->parserParam($matches2[2][$j]);
  2171. switch ($matches2[1][$j]) {
  2172. case 'n':
  2173. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  2174. break;
  2175. case 'i':
  2176. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  2177. break;
  2178. case 'date':
  2179. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->create_time), $one_html);
  2180. break;
  2181. default:
  2182. if (isset($value->{$matches2[1][$j]})) {
  2183. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  2184. } else {
  2185. $one_html = str_replace($matches2[0][$j], '', $one_html);
  2186. }
  2187. }
  2188. }
  2189. $key ++;
  2190. $out_html .= $one_html;
  2191. }
  2192. $content = str_replace($matches[0][$i], $out_html, $content);
  2193. }
  2194. }
  2195. return $content;
  2196. }
  2197. // 解析表单提交标签
  2198. public function parserSubmitFormLabel($content)
  2199. {
  2200. $pattern = '/\{pboot:form(\s+[^}]+)?\}/';
  2201. if (preg_match_all($pattern, $content, $matches)) {
  2202. $count = count($matches[0]);
  2203. for ($i = 0; $i < $count; $i ++) {
  2204. $params = $this->parserParam($matches[1][$i]);
  2205. $fcode = '';
  2206. foreach ($params as $key => $value) {
  2207. switch ($key) {
  2208. case 'fcode':
  2209. $fcode = $value;
  2210. break;
  2211. }
  2212. }
  2213. if (! $fcode) { // 无表单编码不解析
  2214. continue;
  2215. }
  2216. $content = str_replace($matches[0][$i], Url::home('form/' . $fcode), $content);
  2217. }
  2218. }
  2219. return $content;
  2220. }
  2221. // 解析文章评论
  2222. public function parserCommentLabel($content)
  2223. {
  2224. $pattern = '/\{pboot:comment(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:comment\}/';
  2225. $pattern2 = '/\[comment:([\w]+)(\s+[^]]+)?\]/';
  2226. $pattern3 = '/\{pboot:commentsub(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:commentsub\}/';
  2227. $pattern4 = '/\[commentsub:([\w]+)(\s+[^]]+)?\]/';
  2228. if (preg_match_all($pattern, $content, $matches)) {
  2229. $count = count($matches[0]);
  2230. for ($i = 0; $i < $count; $i ++) {
  2231. // 获取调节参数
  2232. $params = $this->parserParam($matches[1][$i]);
  2233. if (! self::checkLabelLevel($params)) {
  2234. $content = str_replace($matches[0][$i], '', $content);
  2235. continue;
  2236. }
  2237. $num = $this->config('pagesize');
  2238. $page = true;
  2239. $order = 'a.id desc';
  2240. $start = 1;
  2241. // 跳过未指定fcode的标签
  2242. if (! array_key_exists('contentid', $params)) {
  2243. continue;
  2244. }
  2245. foreach ($params as $key => $value) {
  2246. switch ($key) {
  2247. case 'num':
  2248. $num = $value;
  2249. break;
  2250. case 'page':
  2251. $page = $value;
  2252. break;
  2253. case 'start':
  2254. $start = $value;
  2255. break;
  2256. case 'contentid':
  2257. $contentid = $value;
  2258. break;
  2259. case 'order':
  2260. $order = $value;
  2261. break;
  2262. }
  2263. }
  2264. // 起始数校验
  2265. if (! is_numeric($start) || $start < 1) {
  2266. $start = 1;
  2267. }
  2268. // 读取数据
  2269. if (! $data = $this->model->getComment($contentid, 0, $num, $order, $page, $start)) {
  2270. $content = str_replace($matches[0][$i], '', $content);
  2271. continue;
  2272. }
  2273. // 匹配到内部标签
  2274. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2275. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2276. } else {
  2277. $count2 = 0;
  2278. }
  2279. $out_html = '';
  2280. $pagenum = defined('PAGE') ? PAGE : 1;
  2281. $key = ($pagenum - 1) * $num + 1;
  2282. foreach ($data as $value) { // 按查询数据条数循环
  2283. $one_html = $matches[2][$i];
  2284. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2285. $params = $this->parserParam($matches2[2][$j]);
  2286. $one_html = $this->parserComment($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
  2287. }
  2288. $key ++;
  2289. // 解析子评论
  2290. if (preg_match_all($pattern3, $one_html, $matches3)) {
  2291. $count3 = count($matches3[0]);
  2292. for ($k = 0; $k < $count3; $k ++) {
  2293. // 读取子评论数据,正序排列,最大100条
  2294. if (! $data_sub = $this->model->getComment($contentid, $value->id, 100, 'a.id asc')) {
  2295. $one_html = str_replace($matches3[0][$k], '', $one_html);
  2296. continue;
  2297. }
  2298. // 匹配到子评论内部标签
  2299. if (preg_match_all($pattern4, $matches3[2][$k], $matches4)) {
  2300. $count4 = count($matches4[0]); // 循环内的内容标签数量
  2301. } else {
  2302. $count4 = 0;
  2303. }
  2304. $out_html_sub = '';
  2305. $key_sub = 1;
  2306. foreach ($data_sub as $value_sub) { // 按子查询数据条数循环
  2307. $one_html_sub = $matches3[2][$k];
  2308. for ($m = 0; $m < $count4; $m ++) { // 循环替换数据
  2309. $params_sub = $this->parserParam($matches4[2][$m]);
  2310. $one_html_sub = $this->parserComment($matches4[1][$m], $matches4[0][$m], $one_html_sub, $value_sub, $params_sub, $key_sub);
  2311. }
  2312. $key_sub ++;
  2313. $out_html_sub .= $one_html_sub;
  2314. }
  2315. $one_html = str_replace($matches3[0][$k], $out_html_sub, $one_html);
  2316. }
  2317. }
  2318. $out_html .= $one_html;
  2319. }
  2320. $content = str_replace($matches[0][$i], $out_html, $content);
  2321. }
  2322. }
  2323. return $content;
  2324. }
  2325. // 解析我的评论
  2326. public function parserMyCommentLabel($content)
  2327. {
  2328. $pattern = '/\{pboot:mycomment(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:mycomment\}/';
  2329. $pattern2 = '/\[mycomment:([\w]+)(\s+[^]]+)?\]/';
  2330. if (preg_match_all($pattern, $content, $matches)) {
  2331. $count = count($matches[0]);
  2332. for ($i = 0; $i < $count; $i ++) {
  2333. // 获取调节参数
  2334. $params = $this->parserParam($matches[1][$i]);
  2335. if (! self::checkLabelLevel($params)) {
  2336. $content = str_replace($matches[0][$i], '', $content);
  2337. continue;
  2338. }
  2339. $num = $this->config('pagesize');
  2340. $page = true;
  2341. $order = 'a.id desc';
  2342. $start = 1;
  2343. foreach ($params as $key => $value) {
  2344. switch ($key) {
  2345. case 'num':
  2346. $num = $value;
  2347. break;
  2348. case 'page':
  2349. $page = $value;
  2350. break;
  2351. case 'start':
  2352. $start = $value;
  2353. break;
  2354. case 'order':
  2355. $order = $value;
  2356. break;
  2357. }
  2358. }
  2359. // 起始数校验
  2360. if (! is_numeric($start) || $start < 1) {
  2361. $start = 1;
  2362. }
  2363. // 读取数据
  2364. if (! $data = $this->model->getMyComment($num, $order, $page, $start)) {
  2365. $content = str_replace($matches[0][$i], '', $content);
  2366. continue;
  2367. }
  2368. // 匹配到内部标签
  2369. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2370. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2371. } else {
  2372. $count2 = 0;
  2373. }
  2374. $out_html = '';
  2375. $pagenum = defined('PAGE') ? PAGE : 1;
  2376. $key = ($pagenum - 1) * $num + 1;
  2377. foreach ($data as $value) { // 按查询数据条数循环
  2378. $one_html = $matches[2][$i];
  2379. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2380. $params = $this->parserParam($matches2[2][$j]);
  2381. $one_html = str_replace("[mycomment:delaction]", Url::home('comment/del', null, 'id=' . $value->id), $one_html);
  2382. $one_html = $this->parserComment($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
  2383. }
  2384. $key ++;
  2385. $out_html .= $one_html;
  2386. }
  2387. $content = str_replace($matches[0][$i], $out_html, $content);
  2388. }
  2389. }
  2390. return $content;
  2391. }
  2392. // 解析评论内容
  2393. private function parserComment($label, $search, $content, $data, $params, $key)
  2394. {
  2395. switch ($label) {
  2396. case 'n':
  2397. $content = str_replace($search, $this->adjustLabelData($params, $key) - 1, $content);
  2398. break;
  2399. case 'i':
  2400. $content = str_replace($search, $this->adjustLabelData($params, $key), $content);
  2401. break;
  2402. case 'ip':
  2403. $content = str_replace($search, $this->adjustLabelData($params, long2ip($data->user_ip)), $content);
  2404. break;
  2405. case 'os':
  2406. $content = str_replace($search, $this->adjustLabelData($params, $data->user_os), $content);
  2407. break;
  2408. case 'bs':
  2409. $content = str_replace($search, $this->adjustLabelData($params, $data->user_bs), $content);
  2410. break;
  2411. case 'date':
  2412. $content = str_replace($search, $this->adjustLabelData($params, $data->create_time), $content);
  2413. break;
  2414. case 'headpic':
  2415. if ($data->headpic) {
  2416. if (! preg_match('/^http/', $data->headpic)) {
  2417. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->headpic), $content);
  2418. } else {
  2419. $content = str_replace($search, $this->adjustLabelData($params, $data->headpic), $content);
  2420. }
  2421. } else {
  2422. $content = str_replace($search, SITE_DIR . '/apps/admin/view/default/images/logo.png', $content);
  2423. }
  2424. break;
  2425. case 'pheadpic':
  2426. if ($data->pheadpic) {
  2427. if (! preg_match('/^http/', $data->pheadpic)) {
  2428. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->pheadpic), $content);
  2429. } else {
  2430. $content = str_replace($search, $this->adjustLabelData($params, $data->pheadpic), $content);
  2431. }
  2432. } else {
  2433. $content = str_replace($search, SITE_DIR . '/apps/admin/view/default/images/logo.png', $content);
  2434. }
  2435. break;
  2436. case 'replyaction':
  2437. if ($data->pid) {
  2438. $pid = $data->pid;
  2439. } else {
  2440. $pid = $data->id;
  2441. }
  2442. $content = str_replace($search, Url::home('comment/add', null, "contentid=" . $data->contentid . "&pid=" . $pid . "&puid=" . $data->uid), $content);
  2443. break;
  2444. case 'nickname':
  2445. if ($data->nickname) {
  2446. $content = str_replace($search, $this->adjustLabelData($params, $data->nickname), $content);
  2447. } elseif ($data->username) {
  2448. $content = str_replace($search, $this->adjustLabelData($params, "匿名"), $content);
  2449. } else {
  2450. $content = str_replace($search, $this->adjustLabelData($params, "游客"), $content);
  2451. }
  2452. break;
  2453. case 'pnickname':
  2454. if ($data->pnickname) {
  2455. $content = str_replace($search, $this->adjustLabelData($params, $data->pnickname), $content);
  2456. } elseif ($data->pusername) {
  2457. $content = str_replace($search, $this->adjustLabelData($params, "匿名"), $content);
  2458. } else {
  2459. $content = str_replace($search, $this->adjustLabelData($params, "游客"), $content);
  2460. }
  2461. break;
  2462. default:
  2463. if (isset($data->{$label})) {
  2464. $content = str_replace($search, $this->adjustLabelData($params, $data->{$label}), $content);
  2465. } else {
  2466. $content = str_replace($search, '', $content);
  2467. }
  2468. }
  2469. return $content;
  2470. }
  2471. // 解析评论子楼层
  2472. public function parserCommentsubLabel($content)
  2473. {
  2474. $pattern = '/\{pboot:commentsub(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:commentsub\}/';
  2475. $pattern2 = '/\[commentsub:([\w]+)(\s+[^]]+)?\]/';
  2476. if (preg_match_all($pattern, $content, $matches)) {
  2477. $count = count($matches[0]);
  2478. for ($i = 0; $i < $count; $i ++) {
  2479. // 获取调节参数
  2480. $params = $this->parserParam($matches[1][$i]);
  2481. if (! self::checkLabelLevel($params)) {
  2482. $content = str_replace($matches[0][$i], '', $content);
  2483. continue;
  2484. }
  2485. $num = $this->config('pagesize');
  2486. $page = false;
  2487. $order = 'a.id desc';
  2488. $start = 1;
  2489. // 跳过未指定fcode的标签
  2490. if (! array_key_exists('contentid', $params)) {
  2491. continue;
  2492. }
  2493. foreach ($params as $key => $value) {
  2494. switch ($key) {
  2495. case 'num':
  2496. $num = $value;
  2497. break;
  2498. case 'page':
  2499. $page = $value;
  2500. break;
  2501. case 'start':
  2502. $start = $value;
  2503. break;
  2504. case 'contentid':
  2505. $contentid = $value;
  2506. break;
  2507. case 'order':
  2508. $order = $value;
  2509. break;
  2510. }
  2511. }
  2512. // 起始数校验
  2513. if (! is_numeric($start) || $start < 1) {
  2514. $start = 1;
  2515. }
  2516. // 读取数据
  2517. if (! $data = $this->model->getComment($contentid, $num, $order, $page, $start)) {
  2518. $content = str_replace($matches[0][$i], '', $content);
  2519. continue;
  2520. }
  2521. // 匹配到内部标签
  2522. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2523. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2524. } else {
  2525. $count2 = 0;
  2526. }
  2527. $out_html = '';
  2528. $pagenum = defined('PAGE') ? PAGE : 1;
  2529. $key = ($pagenum - 1) * $num + 1;
  2530. foreach ($data as $value) { // 按查询数据条数循环
  2531. $one_html = $matches[2][$i];
  2532. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2533. $params = $this->parserParam($matches2[2][$j]);
  2534. switch ($matches2[1][$j]) {
  2535. case 'n':
  2536. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  2537. break;
  2538. case 'i':
  2539. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  2540. break;
  2541. case 'ip':
  2542. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, long2ip($value->user_ip)), $one_html);
  2543. break;
  2544. case 'os':
  2545. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_os), $one_html);
  2546. break;
  2547. case 'bs':
  2548. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_bs), $one_html);
  2549. break;
  2550. case 'date':
  2551. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->create_time), $one_html);
  2552. break;
  2553. case 'headpic':
  2554. if ($value->headpic) {
  2555. if (! preg_match('/^http/', $value->headpic)) {
  2556. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->headpic), $one_html);
  2557. } else {
  2558. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->headpic), $one_html);
  2559. }
  2560. } else {
  2561. $one_html = str_replace($matches2[0][$j], SITE_DIR . '/apps/admin/view/default/images/logo.png', $one_html);
  2562. }
  2563. break;
  2564. case 'pheadpic':
  2565. if ($value->pheadpic) {
  2566. if (! preg_match('/^http/', $value->pheadpic)) {
  2567. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pheadpic), $one_html);
  2568. } else {
  2569. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pheadpic), $one_html);
  2570. }
  2571. } else {
  2572. $one_html = str_replace($matches2[0][$j], SITE_DIR . '/apps/admin/view/default/images/logo.png', $one_html);
  2573. }
  2574. break;
  2575. default:
  2576. if (isset($value->{$matches2[1][$j]})) {
  2577. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  2578. }
  2579. }
  2580. }
  2581. $key ++;
  2582. $out_html .= $one_html;
  2583. }
  2584. $content = str_replace($matches[0][$i], $out_html, $content);
  2585. }
  2586. }
  2587. return $content;
  2588. }
  2589. // 解析自定义SQL循环
  2590. public function parserSqlListLabel($content)
  2591. {
  2592. $pattern = '/\{pboot:sql(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:sql\}/';
  2593. $pattern2 = '/\[sql:([\w]+)(\s+[^]]+)?\]/';
  2594. if (preg_match_all($pattern, $content, $matches)) {
  2595. $count = count($matches[0]);
  2596. for ($i = 0; $i < $count; $i ++) {
  2597. // 获取调节参数
  2598. $params = $this->parserParam($matches[1][$i]);
  2599. if (! self::checkLabelLevel($params)) {
  2600. $content = str_replace($matches[0][$i], '', $content);
  2601. continue;
  2602. }
  2603. $num = 1000; // 最大读取1000条
  2604. $sql = '';
  2605. foreach ($params as $key => $value) {
  2606. switch ($key) {
  2607. case 'num':
  2608. $num = $value;
  2609. break;
  2610. case 'sql':
  2611. $sql = $value;
  2612. break;
  2613. }
  2614. }
  2615. // 特殊表不允许输出
  2616. if (preg_match('/ay_user|ay_member/i', $sql)) {
  2617. $content = str_replace($matches[0][$i], '', $content);
  2618. continue;
  2619. }
  2620. // 判断是否有条数限制
  2621. if ($num && ! preg_match('/limit/i', $sql)) {
  2622. $sql .= " limit " . $num;
  2623. }
  2624. // 读取数据
  2625. if (! $data = $this->model->all($sql)) {
  2626. $content = str_replace($matches[0][$i], '', $content);
  2627. continue;
  2628. }
  2629. // 匹配到内部标签
  2630. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2631. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2632. } else {
  2633. $count2 = 0;
  2634. }
  2635. $out_html = '';
  2636. $pagenum = defined('PAGE') ? PAGE : 1;
  2637. $key = ($pagenum - 1) * $num + 1;
  2638. foreach ($data as $value) { // 按查询数据条数循环
  2639. $one_html = $matches[2][$i];
  2640. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2641. $params = $this->parserParam($matches2[2][$j]);
  2642. switch ($matches2[1][$j]) {
  2643. case 'n':
  2644. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  2645. break;
  2646. case 'i':
  2647. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  2648. break;
  2649. default:
  2650. if (isset($value->{$matches2[1][$j]})) {
  2651. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
  2652. }
  2653. }
  2654. }
  2655. $key ++;
  2656. $out_html .= $one_html;
  2657. }
  2658. $content = str_replace($matches[0][$i], $out_html, $content);
  2659. }
  2660. }
  2661. return $content;
  2662. }
  2663. // 解析二维码生成标签
  2664. public function parserQrcodeLabel($content)
  2665. {
  2666. $pattern = '/\{pboot:qrcode(\s+[^}]+)?\}/';
  2667. if (preg_match_all($pattern, $content, $matches)) {
  2668. $count = count($matches[0]);
  2669. for ($i = 0; $i < $count; $i ++) {
  2670. $params = $this->parserParam($matches[1][$i]);
  2671. $string = '';
  2672. foreach ($params as $key => $value) {
  2673. switch ($key) {
  2674. case 'string':
  2675. $string = $value;
  2676. break;
  2677. }
  2678. }
  2679. if (! $string) { // 无内容不解析
  2680. continue;
  2681. }
  2682. $content = str_replace($matches[0][$i], '<img src="' . CORE_DIR . '/qrcode.php?string=' . urlencode($string) . '" class="qrcode" alt="二维码">', $content);
  2683. }
  2684. }
  2685. return $content;
  2686. }
  2687. // 解析内容搜索结果标签
  2688. public function parserSearchLabel($content)
  2689. {
  2690. $pattern = '/\{pboot:search(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:search\}/';
  2691. $pattern2 = '/\[search:([\w]+)(\s+[^]]+)?\]/';
  2692. if (preg_match_all($pattern, $content, $matches)) {
  2693. $count = count($matches[0]);
  2694. $field = request('field');
  2695. if (! preg_match('/^[\w\|\s]+$/', $field)) {
  2696. $field = '';
  2697. }
  2698. $keyword = request('keyword', 'vars');
  2699. $scode = request('scode');
  2700. $start = 1;
  2701. if (! preg_match('/^[\w,\s]+$/', $scode)) {
  2702. $scode = '';
  2703. }
  2704. for ($i = 0; $i < $count; $i ++) {
  2705. // 获取调节参数
  2706. $params = $this->parserParam($matches[1][$i]);
  2707. $num = $this->config('pagesize'); // 未设置条数时使用默认15
  2708. $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC'; // 默认排序
  2709. $filter = ''; // 过滤
  2710. $tags = ''; // tag标签
  2711. $fuzzy = true; // 设置过滤、tag、筛选是否模糊匹配
  2712. $ispics = ''; // 是否多图
  2713. $isico = ''; // 是否缩略图
  2714. $istop = ''; // 是否置顶
  2715. $isrecommend = ''; // 是否推荐
  2716. $isheadline = ''; // 是否头条
  2717. $page = true; // 搜索默认分页
  2718. $lfield = ''; // 查询字段限制
  2719. $lg = get_lg(); // 查询语言限制,默认当前语言,可通过lg=* 来指定
  2720. if (! self::checkLabelLevel($params)) {
  2721. $content = str_replace($matches[0][$i], '', $content);
  2722. continue;
  2723. }
  2724. foreach ($params as $key => $value) {
  2725. switch ($key) {
  2726. case 'field':
  2727. $field = $value;
  2728. break;
  2729. case 'scode':
  2730. $scode = $value;
  2731. break;
  2732. case 'num':
  2733. $num = $value;
  2734. break;
  2735. case 'order':
  2736. switch ($value) {
  2737. case 'id':
  2738. $order = 'a.id DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC';
  2739. break;
  2740. case 'date':
  2741. $order = 'a.date DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.id DESC';
  2742. break;
  2743. case 'sorting':
  2744. $order = 'a.sorting ASC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.date DESC,a.id DESC';
  2745. break;
  2746. case 'istop':
  2747. $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  2748. break;
  2749. case 'isrecommend':
  2750. $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  2751. break;
  2752. case 'isheadline':
  2753. $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  2754. break;
  2755. case 'visits':
  2756. case 'likes':
  2757. case 'oppose':
  2758. $order = $value . ' DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  2759. break;
  2760. case 'random': // 随机取数
  2761. $db_type = get_db_type();
  2762. if ($db_type == 'mysql') {
  2763. $order = "RAND()";
  2764. } elseif ($db_type == 'sqlite') {
  2765. $order = "RANDOM()";
  2766. }
  2767. break;
  2768. default:
  2769. if ($value) {
  2770. $orders = explode(',', $value);
  2771. foreach ($orders as $k => $v) {
  2772. if (strpos($v, 'ext_') === 0) {
  2773. $orders[$k] = 'e.' . $v;
  2774. } else {
  2775. $orders[$k] = 'a.' . $v;
  2776. }
  2777. }
  2778. $value = implode(',', $orders);
  2779. $order = $value . ',a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
  2780. }
  2781. }
  2782. break;
  2783. case 'filter':
  2784. $filter = $value;
  2785. case 'fuzzy':
  2786. $fuzzy = $value;
  2787. break;
  2788. case 'tags':
  2789. $tags = $value;
  2790. break;
  2791. case 'ispics':
  2792. $ispics = $value;
  2793. break;
  2794. case 'isico':
  2795. $isico = $value;
  2796. break;
  2797. case 'istop':
  2798. $istop = $value;
  2799. break;
  2800. case 'isrecommend':
  2801. $isrecommend = $value;
  2802. break;
  2803. case 'isheadline':
  2804. $isheadline = $value;
  2805. break;
  2806. case 'page':
  2807. $page = $value;
  2808. break;
  2809. case 'start':
  2810. $start = $value;
  2811. break;
  2812. case 'lfield':
  2813. $lfield = $value;
  2814. break;
  2815. case 'lg':
  2816. $lg = $value;
  2817. break;
  2818. }
  2819. }
  2820. if ($scode == '*') {
  2821. $scode = '';
  2822. }
  2823. // filter数据筛选
  2824. $where1 = array();
  2825. if ($filter) {
  2826. $filter = explode('|', $filter);
  2827. if (count($filter) == 2) {
  2828. $filter_arr = explode(',', $filter[1]);
  2829. if ($filter[0] == 'title') {
  2830. $filter[0] = 'a.title';
  2831. }
  2832. foreach ($filter_arr as $value) {
  2833. if ($value) {
  2834. if ($fuzzy) {
  2835. $where1[] = $filter[0] . " like '%" . escape_string($value) . "%'";
  2836. } else {
  2837. $where1[] = $filter[0] . "='" . escape_string($value) . "'";
  2838. }
  2839. }
  2840. }
  2841. }
  2842. }
  2843. // tags数据筛选
  2844. $where2 = array();
  2845. if ($tags) {
  2846. $tags_arr = explode(',', $tags);
  2847. foreach ($tags_arr as $value) {
  2848. if ($value) {
  2849. if ($fuzzy) {
  2850. $where2[] = "a.tags like '%" . escape_string($value) . "%'";
  2851. } else {
  2852. $where2[] = "a.tags='" . escape_string($value) . "'";
  2853. }
  2854. }
  2855. }
  2856. }
  2857. // 存储搜索条件,条件为“并列”关系,由于为模糊匹配,条件为空时意味着“任意”
  2858. $where3 = array();
  2859. // 采取keyword方式
  2860. if ($keyword) {
  2861. if (strpos($field, '|')) { // 匹配多字段的关键字搜索
  2862. $field = explode('|', $field);
  2863. foreach ($field as $value) {
  2864. if ($value == 'title') {
  2865. $value = 'a.title';
  2866. }
  2867. if ($fuzzy) {
  2868. $like = " like '%" . $keyword . "%'"; // 前面已经转义过
  2869. } else {
  2870. $like = " like '" . $keyword . "'"; // 前面已经转义过
  2871. }
  2872. if (isset($where3[0])) {
  2873. $where3[0] .= ' OR ' . $value . $like;
  2874. } else {
  2875. $where3[0] = $value . $like;
  2876. }
  2877. }
  2878. if (count($field) > 1) {
  2879. $where3[0] = '(' . $where3[0] . ')';
  2880. }
  2881. } else { // 匹配单一字段的关键字搜索
  2882. if ($field) {
  2883. if ($field == 'title') {
  2884. $field = 'a.title';
  2885. }
  2886. $where3[$field] = $keyword;
  2887. } else {
  2888. $where3['a.title'] = $keyword;
  2889. }
  2890. }
  2891. }
  2892. // 数据接收
  2893. if ($_POST) {
  2894. $receive = $_POST;
  2895. } else {
  2896. $receive = $_GET;
  2897. }
  2898. foreach ($receive as $key => $value) {
  2899. if (! ! $value = request($key, 'vars')) {
  2900. if ($key == 'title') {
  2901. $key = 'a.title';
  2902. }
  2903. if (preg_match('/^[\w\-\.]+$/', $key)) { // 带有违规字符时不带入查询
  2904. $where3[$key] = $value;
  2905. }
  2906. }
  2907. }
  2908. // 去除特殊键值
  2909. unset($where3['keyword']);
  2910. unset($where3['field']);
  2911. unset($where3['scode']);
  2912. unset($where3['page']);
  2913. unset($where3['from']);
  2914. unset($where3['isappinstalled']);
  2915. unset($where3['tdsourcetag']);
  2916. unset($where3['x']);
  2917. unset($where3['y']);
  2918. unset($where3['searchtpl']);
  2919. unset($where3['p']);
  2920. unset($where3['s']);
  2921. // 无任何条件不显示内容
  2922. if (! $where3) {
  2923. $content = str_replace($matches[0][$i], '', $content);
  2924. continue;
  2925. }
  2926. // 判断多图调节参数
  2927. if ($ispics !== '') {
  2928. if ($ispics) {
  2929. $where3[] = "a.pics<>''";
  2930. } else {
  2931. $where3[] = "a.pics=''";
  2932. }
  2933. }
  2934. // 判断缩略图调节参数
  2935. if ($isico !== '') {
  2936. if ($isico) {
  2937. $where3[] = "a.ico<>''";
  2938. } else {
  2939. $where3[] = "a.ico=''";
  2940. }
  2941. }
  2942. // 判断置顶调节参数
  2943. if ($istop !== '') {
  2944. if ($istop) {
  2945. $where3[] = "a.istop=1";
  2946. } else {
  2947. $where3[] = "a.istop=0";
  2948. }
  2949. }
  2950. // 判断推荐调节参数
  2951. if ($isrecommend !== '') {
  2952. if ($isrecommend) {
  2953. $where3[] = "a.isrecommend=1";
  2954. } else {
  2955. $where3[] = "a.isrecommend=0";
  2956. }
  2957. }
  2958. // 判断头条调节参数
  2959. if ($isheadline !== '') {
  2960. if ($isheadline) {
  2961. $where3[] = "a.isheadline=1";
  2962. } else {
  2963. $where3[] = "a.isheadline=0";
  2964. }
  2965. }
  2966. // 起始数校验
  2967. if (! is_numeric($start) || $start < 1) {
  2968. $start = 1;
  2969. }
  2970. // 读取数据
  2971. if ($page) {
  2972. if (isset($paging)) {
  2973. error('请不要在一个页面使用多个具有分页的列表,您可将多余的使用page=0关闭分页!');
  2974. } else {
  2975. $paging = true;
  2976. $data = $this->model->getLists($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield, $lg);
  2977. }
  2978. } else {
  2979. $data = $this->model->getList($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield, $lg);
  2980. }
  2981. // 无数据直接替换
  2982. if (! $data) {
  2983. $content = str_replace($matches[0][$i], '', $content);
  2984. continue;
  2985. }
  2986. // 匹配到内部标签
  2987. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  2988. $count2 = count($matches2[0]); // 循环内的内容标签数量
  2989. } else {
  2990. $count2 = 0;
  2991. }
  2992. $out_html = '';
  2993. $pagenum = defined('PAGE') ? PAGE : 1;
  2994. $key = ($pagenum - 1) * $num + 1;
  2995. foreach ($data as $value) { // 按查询数据条数循环
  2996. $one_html = $matches[2][$i];
  2997. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  2998. $params = $this->parserParam($matches2[2][$j]);
  2999. $one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
  3000. }
  3001. $key ++;
  3002. $out_html .= $one_html;
  3003. }
  3004. $content = str_replace($matches[0][$i], $out_html, $content);
  3005. }
  3006. }
  3007. return $content;
  3008. }
  3009. // 解析列表分页标签
  3010. public function parserPageLabel($content)
  3011. {
  3012. $pattern = '/\{page:([\w]+)\}/';
  3013. if (preg_match_all($pattern, $content, $matches)) {
  3014. $count = count($matches[0]);
  3015. for ($i = 0; $i < $count; $i ++) {
  3016. switch ($matches[1][$i]) {
  3017. case 'bar':
  3018. $content = str_replace($matches[0][$i], $this->getVar('pagebar'), $content);
  3019. break;
  3020. case 'current':
  3021. $content = str_replace($matches[0][$i], $this->getVar('pagecurrent') ?: 0, $content);
  3022. break;
  3023. case 'count':
  3024. $content = str_replace($matches[0][$i], $this->getVar('pagecount') ?: 0, $content);
  3025. break;
  3026. case 'rows':
  3027. $content = str_replace($matches[0][$i], $this->getVar('pagerows') ?: 0, $content);
  3028. break;
  3029. case 'index':
  3030. $content = str_replace($matches[0][$i], $this->getVar('pageindex'), $content);
  3031. break;
  3032. case 'pre':
  3033. $content = str_replace($matches[0][$i], $this->getVar('pagepre'), $content);
  3034. break;
  3035. case 'next':
  3036. $content = str_replace($matches[0][$i], $this->getVar('pagenext'), $content);
  3037. break;
  3038. case 'last':
  3039. $content = str_replace($matches[0][$i], $this->getVar('pagelast'), $content);
  3040. break;
  3041. case 'status':
  3042. $content = str_replace($matches[0][$i], $this->getVar('pagestatus'), $content);
  3043. break;
  3044. case 'numbar':
  3045. $content = str_replace($matches[0][$i], $this->getVar('pagenumbar'), $content);
  3046. break;
  3047. case 'selectbar':
  3048. $content = str_replace($matches[0][$i], $this->getVar('pageselectbar'), $content);
  3049. break;
  3050. }
  3051. }
  3052. }
  3053. return $content;
  3054. }
  3055. // 解析循环标签
  3056. public function parserLoopLabel($content)
  3057. {
  3058. $pattern = '/\{pboot:loop(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:loop\}/';
  3059. if (preg_match_all($pattern, $content, $matches)) {
  3060. $count = count($matches[0]);
  3061. for ($i = 0; $i < $count; $i ++) {
  3062. // 获取调节参数
  3063. $params = $this->parserParam($matches[1][$i]);
  3064. $start = 1;
  3065. $end = $this->config('pagesize');
  3066. if (! self::checkLabelLevel($params)) {
  3067. $content = str_replace($matches[0][$i], '', $content);
  3068. continue;
  3069. }
  3070. foreach ($params as $key => $value) {
  3071. switch ($key) {
  3072. case 'start':
  3073. $start = $value;
  3074. break;
  3075. case 'end':
  3076. $end = $value;
  3077. break;
  3078. }
  3079. }
  3080. $out_html = '';
  3081. $key = 1;
  3082. for ($n = $start; $n <= $end; $n ++) {
  3083. $one_html = str_replace('[loop:n]', $key - 1, $matches[2][$i]);
  3084. $one_html = str_replace('[loop:i]', $key, $one_html);
  3085. $one_html = str_replace('[loop:index]', $n, $one_html);
  3086. $out_html .= $one_html;
  3087. $key ++;
  3088. }
  3089. $content = str_replace($matches[0][$i], $out_html, $content);
  3090. }
  3091. }
  3092. return $content;
  3093. }
  3094. // 解析IF条件标签
  3095. public function parserIfLabel($content)
  3096. {
  3097. $pattern = '/\{pboot:if\(([^}^\$]+)\)\}([\s\S]*?)\{\/pboot:if\}/';
  3098. $pattern2 = '/pboot:([0-9])+if/';
  3099. if (preg_match_all($pattern, $content, $matches)) {
  3100. $count = count($matches[0]);
  3101. for ($i = 0; $i < $count; $i ++) {
  3102. $flag = '';
  3103. $out_html = '';
  3104. $danger = false;
  3105. $white_fun = array(
  3106. 'date'
  3107. );
  3108. // 还原可能包含的保留内容,避免判断失效
  3109. $matches[1][$i] = $this->restorePreLabel($matches[1][$i]);
  3110. // 带有函数的条件语句进行安全校验
  3111. if (preg_match_all('/([\w]+)([\x00-\x1F\x7F\/\*\<\>\%\w\s\\\\]+)?\(/i', $matches[1][$i], $matches2)) {
  3112. foreach ($matches2[1] as $value) {
  3113. if (function_exists(trim($value)) && ! in_array($value, $white_fun)) {
  3114. $danger = true;
  3115. break;
  3116. }
  3117. }
  3118. foreach ($matches2[2] as $value) {
  3119. if (function_exists(trim($value)) && ! in_array($value, $white_fun)) {
  3120. $danger = true;
  3121. break;
  3122. }
  3123. }
  3124. }
  3125. // 过滤特殊字符串
  3126. if (preg_match('/(\([\w\s\.]+\))|(\$_GET\[)|(\$_POST\[)|(\$_REQUEST\[)|(\$_COOKIE\[)|(\$_SESSION\[)|(file_put_contents)|(file_get_contents)|(fwrite)|(phpinfo)|(base64)|(`)|(shell_exec)|(eval)|(assert)|(system)|(exec)|(passthru)|(pcntl_exec)|(popen)|(proc_open)|(print_r)|(print)|(urldecode)|(chr)|(include)|(request)|(__FILE__)|(__DIR__)|(copy)|(call_user_)|(preg_replace)|(array_map)|(array_reverse)|(array_filter)|(getallheaders)|(get_headers)|(decode_string)|(htmlspecialchars)|(session_id)|(strrev)|(substr)|(php.info)|(@file.@_put_content)/i', $matches[1][$i])) {
  3127. $danger = true;
  3128. }
  3129. // 如果有危险函数,则不解析该IF
  3130. if ($danger) {
  3131. continue;
  3132. }
  3133. //if标签解析
  3134. $flag = symbol($matches[1][$i]);
  3135. if (preg_match('/^([\s\S]*)\{else\}([\s\S]*)$/', $matches[2][$i], $matches2)) { // 判断是否存在else
  3136. switch ($flag) {
  3137. case 'if': // 条件为真
  3138. if (isset($matches2[1])) {
  3139. $out_html = $matches2[1];
  3140. }
  3141. break;
  3142. case 'else': // 条件为假
  3143. if (isset($matches2[2])) {
  3144. $out_html = $matches2[2];
  3145. }
  3146. break;
  3147. }
  3148. } elseif ($flag == 'if') {
  3149. $out_html = $matches[2][$i];
  3150. }
  3151. // 无限极嵌套解析
  3152. if (preg_match($pattern2, $out_html, $matches3)) {
  3153. $out_html = str_replace('pboot:' . $matches3[1] . 'if', 'pboot:if', $out_html);
  3154. $out_html = str_replace('{' . $matches3[1] . 'else}', '{else}', $out_html);
  3155. $out_html = $this->parserIfLabel($out_html);
  3156. }
  3157. // 执行替换
  3158. $content = str_replace($matches[0][$i], $out_html, $content);
  3159. }
  3160. }
  3161. // var_dump(111);die;
  3162. return $content;
  3163. }
  3164. // 调整标签数据
  3165. protected function adjustLabelData($params, $data, $label = null, $savelabel = false)
  3166. {
  3167. if (! $data)
  3168. return $data;
  3169. // 图片缩放功能
  3170. if (isset($params['maxwidth']) || isset($params['maxheight'])) {
  3171. $maxwidth = isset($params['maxwidth']) ? $params['maxwidth'] : null;
  3172. $maxheight = isset($params['maxheight']) ? $params['maxheight'] : null;
  3173. $max_src_file = ROOT_PATH . $data;
  3174. $max_out_file = RUN_PATH . '/image/mw' . $maxwidth . '_mh' . $maxheight . '_' . basename($data);
  3175. if (! file_exists($max_out_file) && file_exists($max_src_file)) {
  3176. if (resize_img($max_src_file, $max_out_file, $maxwidth, $maxheight)) {
  3177. $data = str_replace(ROOT_PATH, '', $max_out_file);
  3178. }
  3179. } elseif (file_exists($max_out_file) && file_exists($max_src_file)) {
  3180. $data = str_replace(ROOT_PATH, '', $max_out_file);
  3181. }
  3182. }
  3183. // 图片固定大小
  3184. if (isset($params['width']) || isset($params['height'])) {
  3185. $width = isset($params['width']) ? $params['width'] : null;
  3186. $height = isset($params['height']) ? $params['height'] : null;
  3187. $src_file = ROOT_PATH . $data;
  3188. $out_file = RUN_PATH . '/image/w' . $width . '_h' . $height . '_' . basename($data);
  3189. if (! file_exists($out_file) && file_exists($src_file)) {
  3190. if (cut_img($src_file, $out_file, $width, $height)) {
  3191. $data = str_replace(ROOT_PATH, '', $out_file);
  3192. }
  3193. } elseif (file_exists($out_file) && file_exists($src_file)) {
  3194. $data = str_replace(ROOT_PATH, '', $out_file);
  3195. }
  3196. }
  3197. // 检查标签权限
  3198. if (! self::checkLabelLevel($params)) {
  3199. $data = '';
  3200. }
  3201. if (is_array($params) && $params) {
  3202. foreach ($params as $key => $value) {
  3203. switch ($key) {
  3204. case 'style': // 时间样式
  3205. if ($params['style'] && $date = strtotime($data)) {
  3206. $data = date($params['style'], $date);
  3207. }
  3208. break;
  3209. case 'len': // 长度截取
  3210. if ($params['len'] && is_string($data)) {
  3211. if (mb_strlen($data, 'utf-8') > $params['len']) {
  3212. if (isset($params['more'])) {
  3213. $more = $params['more'];
  3214. } else {
  3215. $more = '···';
  3216. }
  3217. $data = mb_substr($data, 0, $params['len'], 'utf-8') . $more;
  3218. }
  3219. }
  3220. break;
  3221. case 'lencn': // 以中文占位长度方式截取,英文算半个
  3222. if ($params['lencn'] && is_string($data)) {
  3223. if (strlen_both($data) > $params['lencn']) {
  3224. if (isset($params['more'])) {
  3225. $more = $params['more'];
  3226. } else {
  3227. $more = '···';
  3228. }
  3229. $data = substr_both($data, 0, $params['lencn']) . $more;
  3230. }
  3231. }
  3232. break;
  3233. case 'drophtml': // 去除html标签
  3234. if ($params['drophtml']) {
  3235. $data = strip_tags($data);
  3236. }
  3237. break;
  3238. case 'dropblank': // 清理特殊空白
  3239. if ($params['dropblank']) {
  3240. $data = clear_html_blank($data);
  3241. }
  3242. break;
  3243. case 'decode': // 解码或转义字符
  3244. if ($params['decode']) {
  3245. $data = decode_string($data);
  3246. } else {
  3247. $data = escape_string($data);
  3248. }
  3249. break;
  3250. case 'substr': // 截取字符串
  3251. if ($params['substr'] && is_string($data)) {
  3252. $arr = explode(',', $params['substr']);
  3253. if (count($arr) == 2 && $arr[1]) {
  3254. $data = mb_substr($data, $arr[0] - 1, $arr[1], 'utf-8');
  3255. } else {
  3256. $data = mb_substr($data, $arr[0] - 1);
  3257. }
  3258. }
  3259. break;
  3260. case 'unit': // bytes转换未其它单位
  3261. switch ($params['unit']) {
  3262. case 'KB':
  3263. case 'kb':
  3264. $data = $data / 1024;
  3265. break;
  3266. case 'MB':
  3267. case 'mb':
  3268. $data = $data / (1024 * 1024);
  3269. break;
  3270. case 'GB':
  3271. case 'gb':
  3272. $data = $data / (1024 * 1024 * 1024);
  3273. break;
  3274. case 'TB':
  3275. case 'tb':
  3276. $data = $data / (1024 * 1024 * 1024 * 1024);
  3277. break;
  3278. case 'PB':
  3279. case 'pb':
  3280. $data = $data / (1024 * 1024 * 1024 * 1024 * 1024);
  3281. break;
  3282. case 'EB':
  3283. case 'eb':
  3284. $data = $data / (1024 * 1024 * 1024 * 1024 * 1024 * 1024);
  3285. break;
  3286. }
  3287. break;
  3288. case 'decimal': // 小数点
  3289. if ($params['decimal']) {
  3290. $data = number_format($data, $params['decimal']);
  3291. }
  3292. break;
  3293. case 'operate': // 实现列表页标签+-*/%运算功能
  3294. if (preg_match('/^([\+\-\*\/\%])([0-9\.]+)$/', $params['operate'], $mathes)) {
  3295. if (! is_numeric($data)) {
  3296. $data = 0;
  3297. }
  3298. switch ($mathes[1]) {
  3299. case '+':
  3300. $data = $data + $mathes[2];
  3301. break;
  3302. case '-':
  3303. $data = $data - $mathes[2];
  3304. break;
  3305. case '*':
  3306. $data = $data * $mathes[2];
  3307. break;
  3308. case '/':
  3309. $data = $data / $mathes[2];
  3310. break;
  3311. case '%':
  3312. $data = $data % $mathes[2];
  3313. break;
  3314. }
  3315. }
  3316. break;
  3317. case 'mark':
  3318. if ($label && $reqdata = request($label, 'vars') ?: request('keyword', 'vars')) {
  3319. $data = preg_replace('/(' . $reqdata . ')/i', '<span style="color:red">$1</span>', $data);
  3320. }
  3321. break;
  3322. }
  3323. }
  3324. }
  3325. // 对标签内容中含有标签是否保留不解析
  3326. if ($savelabel && $data) {
  3327. $this->pre[] = $data; // 保存内容避免解析
  3328. end($this->pre); // 指向最后一个元素
  3329. $data = '#pre:' . key($this->pre) . '#';
  3330. }
  3331. return $data;
  3332. }
  3333. // 解析调节参数
  3334. protected function parserParam($string, $striptags = true)
  3335. {
  3336. if (! $string = trim($string))
  3337. return array();
  3338. $string = preg_replace('/\s+/', ' ', $string); // 多空格处理
  3339. if ($striptags) {
  3340. $string = strip_tags($string);
  3341. }
  3342. $param = array();
  3343. if (preg_match_all('/([\w]+)[\s]?=[\s]?([\"]([^\"]+)?[\"]|[\']([^\']+)?[\']|([^\s]+))/i', $string, $matches)) {
  3344. foreach ($matches[1] as $key => $value) {
  3345. $param[$value] = $matches[3][$key] ?: $matches[4][$key] ?: $matches[5][$key];
  3346. }
  3347. }
  3348. return $param;
  3349. }
  3350. // 解析列表标签
  3351. protected function parserList($label, $search, $content, $data, $params, $key)
  3352. {
  3353. switch ($label) {
  3354. case 'n':
  3355. $content = str_replace($search, $this->adjustLabelData($params, $key) - 1, $content);
  3356. break;
  3357. case 'i':
  3358. $content = str_replace($search, $this->adjustLabelData($params, $key), $content);
  3359. break;
  3360. case 'link':
  3361. if ($data->outlink) { // 外链
  3362. $content = str_replace($search, $data->outlink, $content);
  3363. } else {
  3364. if ($data->type == 1) {
  3365. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'about', $data->scode, $data->sortfilename, '', ''), $content);
  3366. } else {
  3367. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename), $content);
  3368. }
  3369. }
  3370. break;
  3371. case 'sortlink':
  3372. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->scode, $data->sortfilename, '', ''), $content);
  3373. break;
  3374. case 'subsortlink':
  3375. if ($data->subscode) {
  3376. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->subscode, $data->subfilename, '', ''), $content);
  3377. } else {
  3378. $content = str_replace($search, 'javascript:;', $content);
  3379. }
  3380. break;
  3381. case 'sortname':
  3382. if ($data->sortname) {
  3383. $content = str_replace($search, $this->adjustLabelData($params, $data->sortname, $label), $content);
  3384. } else {
  3385. $content = str_replace($search, '', $content);
  3386. }
  3387. break;
  3388. case 'subsortname':
  3389. if ($data->subsortname) {
  3390. $content = str_replace($search, $this->adjustLabelData($params, $data->subsortname, $label), $content);
  3391. } else {
  3392. $content = str_replace($search, '', $content);
  3393. }
  3394. break;
  3395. case 'ico':
  3396. if ($data->ico) {
  3397. if (! preg_match('/^http/', $data->ico)) {
  3398. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->ico), $content);
  3399. } else {
  3400. $content = str_replace($search, $this->adjustLabelData($params, $data->ico), $content);
  3401. }
  3402. } elseif (preg_match('/<img\s+.*?src=\s?[\'|\"](.*?(\.gif|\.jpg|\.png|\.jpeg))[\'|\"].*?[\/]?>/i', $data->content, $srcs) && isset($srcs[1])) {
  3403. $content = str_replace($search, $this->adjustLabelData($params, $srcs[1]), $content);
  3404. } else {
  3405. $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
  3406. }
  3407. break;
  3408. case 'isico':
  3409. if ($data->ico) {
  3410. $content = str_replace($search, 1, $content);
  3411. } else {
  3412. $content = str_replace($search, 0, $content);
  3413. }
  3414. break;
  3415. case 'ispics':
  3416. if ($data->pics) {
  3417. $content = str_replace($search, 1, $content);
  3418. } else {
  3419. $content = str_replace($search, 0, $content);
  3420. }
  3421. break;
  3422. case 'enclosure':
  3423. if ($data->enclosure) {
  3424. if (! preg_match('/^http/', $data->enclosure)) {
  3425. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->enclosure), $content);
  3426. } else {
  3427. $content = str_replace($search, $this->adjustLabelData($params, $data->enclosure), $content);
  3428. }
  3429. } else {
  3430. $content = str_replace($search, '', $content);
  3431. }
  3432. break;
  3433. case 'enclosuresize':
  3434. if ($data->enclosure && file_exists(ROOT_PATH . $data->enclosure)) {
  3435. $content = str_replace($search, $this->adjustLabelData($params, filesize(ROOT_PATH . $data->enclosure)), $content);
  3436. } else {
  3437. $content = str_replace($search, 0, $content);
  3438. }
  3439. case 'likeslink':
  3440. $content = str_replace($search, Url::get('home/Do/likes/id/' . $data->id), $content);
  3441. break;
  3442. case 'opposelink':
  3443. $content = str_replace($search, Url::get('home/Do/oppose/id/' . $data->id), $content);
  3444. break;
  3445. case 'content':
  3446. $content = str_replace($search, $this->adjustLabelData($params, $data->content, $label, true), $content); // 占位替换
  3447. break;
  3448. case 'keywords':
  3449. $content = str_replace($search, $this->adjustLabelData($params, $data->keywords, $label, true), $content); // 占位替换
  3450. break;
  3451. case 'description':
  3452. $content = str_replace($search, $this->adjustLabelData($params, $data->description, $label, true), $content); // 占位替换
  3453. break;
  3454. default:
  3455. if (isset($data->$label)) {
  3456. $content = str_replace($search, $this->adjustLabelData($params, $data->$label, $label), $content);
  3457. } elseif (strpos($label, 'ext_') === 0) {
  3458. $content = str_replace($search, '', $content);
  3459. }
  3460. }
  3461. return $content;
  3462. }
  3463. // 解析内容详情标签
  3464. protected function parserContent($label, $search, $content, $data, $params, $sort)
  3465. {
  3466. switch ($label) {
  3467. case 'link':
  3468. if ($data->type == 1) {
  3469. if ($data->sortoutlink) {
  3470. $content = str_replace($search, $data->sortoutlink, $content);
  3471. } else {
  3472. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'about', $data->scode, $data->sortfilename, '', ''), $content);
  3473. }
  3474. } else {
  3475. if ($data->outlink) {
  3476. $content = str_replace($search, $data->outlink, $content);
  3477. } else {
  3478. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename), $content);
  3479. }
  3480. }
  3481. break;
  3482. case 'sortlink':
  3483. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->scode, $data->sortfilename, '', ''), $content);
  3484. break;
  3485. case 'subsortlink':
  3486. if ($data->subscode) {
  3487. $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->subscode, $data->subfilename, '', ''), $content);
  3488. } else {
  3489. $content = str_replace($search, '', $content);
  3490. }
  3491. break;
  3492. case 'sortname':
  3493. if ($data->sortname) {
  3494. $content = str_replace($search, $this->adjustLabelData($params, $data->sortname), $content);
  3495. } else {
  3496. $content = str_replace($search, '', $content);
  3497. }
  3498. break;
  3499. case 'subsortname':
  3500. if ($data->subsortname) {
  3501. $content = str_replace($search, $this->adjustLabelData($params, $data->subsortname), $content);
  3502. } else {
  3503. $content = str_replace($search, '', $content);
  3504. }
  3505. break;
  3506. case 'ico':
  3507. if ($data->ico) {
  3508. if (! preg_match('/^http/', $data->ico)) {
  3509. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->ico), $content);
  3510. } else {
  3511. $content = str_replace($search, $this->adjustLabelData($params, $data->ico), $content);
  3512. }
  3513. } elseif (preg_match('/<img\s+.*?src=\s?[\'|\"](.*?(\.gif|\.jpg|\.png|\.jpeg))[\'|\"].*?[\/]?>/i', $data->content, $srcs) && isset($srcs[1])) {
  3514. $content = str_replace($search, $this->adjustLabelData($params, $srcs[1]), $content);
  3515. } else {
  3516. $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
  3517. }
  3518. break;
  3519. case 'isico':
  3520. if ($data->ico) {
  3521. $content = str_replace($search, 1, $content);
  3522. } else {
  3523. $content = str_replace($search, 0, $content);
  3524. }
  3525. break;
  3526. case 'ispics':
  3527. if ($data->pics) {
  3528. $content = str_replace($search, 1, $content);
  3529. } else {
  3530. $content = str_replace($search, 0, $content);
  3531. }
  3532. break;
  3533. case 'enclosure':
  3534. if ($data->enclosure) {
  3535. if (! preg_match('/^http/', $data->enclosure)) {
  3536. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->enclosure), $content);
  3537. } else {
  3538. $content = str_replace($search, $this->adjustLabelData($params, $data->enclosure), $content);
  3539. }
  3540. } else {
  3541. $content = str_replace($search, '', $content);
  3542. }
  3543. break;
  3544. case 'enclosuresize':
  3545. if ($data->enclosure && file_exists(ROOT_PATH . $data->enclosure)) {
  3546. $content = str_replace($search, $this->adjustLabelData($params, filesize(ROOT_PATH . $data->enclosure)), $content);
  3547. } else {
  3548. $content = str_replace($search, 0, $content);
  3549. }
  3550. break;
  3551. case 'likeslink':
  3552. $content = str_replace($search, Url::get('home/Do/likes/id/' . $data->id), $content);
  3553. break;
  3554. case 'opposelink':
  3555. $content = str_replace($search, Url::get('home/Do/oppose/id/' . $data->id), $content);
  3556. break;
  3557. case 'precontent':
  3558. if ($data->type != 2) // 非列表内容页不解析
  3559. break;
  3560. if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
  3561. $content = str_replace($search, '<a href="' . $this->parserLink($pre->type, $pre->urlname, 'content', $pre->scode, $pre->sortfilename, $pre->id, $pre->filename) . '">' . $this->adjustLabelData($params, $pre->title) . '</a>', $content);
  3562. } else {
  3563. if (isset($params['notext'])) {
  3564. $content = str_replace($search, $params['notext'], $content);
  3565. } else {
  3566. $content = str_replace($search, '没有了!', $content);
  3567. }
  3568. }
  3569. break;
  3570. case 'prelink':
  3571. if ($data->type != 2) // 非列表内容页不解析
  3572. break;
  3573. if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
  3574. $content = str_replace($search, $this->parserLink($pre->type, $pre->urlname, 'content', $pre->scode, $pre->sortfilename, $pre->id, $pre->filename), $content);
  3575. } else {
  3576. $content = str_replace($search, 'javascript:;', $content);
  3577. }
  3578. break;
  3579. case 'pretitle':
  3580. if ($data->type != 2) // 非列表内容页不解析
  3581. break;
  3582. if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
  3583. $content = str_replace($search, $this->adjustLabelData($params, $pre->title), $content);
  3584. } else {
  3585. if (isset($params['notext'])) {
  3586. $content = str_replace($search, $params['notext'], $content);
  3587. } else {
  3588. $content = str_replace($search, '没有了!', $content);
  3589. }
  3590. }
  3591. break;
  3592. case 'preico':
  3593. if ($data->type != 2) // 非列表内容页不解析
  3594. break;
  3595. if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
  3596. if (! preg_match('/^http/', $pre->ico)) {
  3597. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $pre->ico), $content);
  3598. } else {
  3599. $content = str_replace($search, $this->adjustLabelData($params, $pre->ico), $content);
  3600. }
  3601. } else {
  3602. $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
  3603. }
  3604. break;
  3605. case 'nextcontent':
  3606. if ($data->type != 2) // 非列表内容页不解析
  3607. break;
  3608. if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
  3609. $content = str_replace($search, '<a href="' . $this->parserLink($next->type, $next->urlname, 'content', $next->scode, $next->sortfilename, $next->id, $next->filename) . '">' . $this->adjustLabelData($params, $next->title) . '</a>', $content);
  3610. } else {
  3611. if (isset($params['notext'])) {
  3612. $content = str_replace($search, $params['notext'], $content);
  3613. } else {
  3614. $content = str_replace($search, '没有了!', $content);
  3615. }
  3616. }
  3617. break;
  3618. case 'nextlink':
  3619. if ($data->type != 2) // 非列表内容页不解析
  3620. break;
  3621. if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
  3622. $content = str_replace($search, $this->parserLink($next->type, $next->urlname, 'content', $next->scode, $next->sortfilename, $next->id, $next->filename), $content);
  3623. } else {
  3624. $content = str_replace($search, 'javascript:;', $content);
  3625. }
  3626. break;
  3627. case 'nexttitle':
  3628. if ($data->type != 2) // 非列表内容页不解析
  3629. break;
  3630. if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
  3631. $content = str_replace($search, $this->adjustLabelData($params, $next->title), $content);
  3632. } else {
  3633. if (isset($params['notext'])) {
  3634. $content = str_replace($search, $params['notext'], $content);
  3635. } else {
  3636. $content = str_replace($search, '没有了!', $content);
  3637. }
  3638. }
  3639. break;
  3640. case 'nextico':
  3641. if ($data->type != 2) // 非列表内容页不解析
  3642. break;
  3643. if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
  3644. if (! preg_match('/^http/', $next->ico)) {
  3645. $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $next->ico), $content);
  3646. } else {
  3647. $content = str_replace($search, $this->adjustLabelData($params, $next->ico), $content);
  3648. }
  3649. } else {
  3650. $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
  3651. }
  3652. break;
  3653. case 'content':
  3654. // 内链处理
  3655. if (! ! $tags = $this->model->getTags()) {
  3656. // 将A链接保护起来,alt、titel保护起来
  3657. $rega = "/(<a .*?>.*?<\/a>)|(alt=.*?>)|(title=.*?>)/i";
  3658. preg_match_all($rega, $data->content, $matches1);
  3659. foreach ($matches1[0] as $key => $value) {
  3660. $data->content = str_replace($value, '#rega:' . $key . '#', $data->content);
  3661. }
  3662. // 去除包含关系的短tags,实现长关键字优先
  3663. foreach ($tags as $key => $value) {
  3664. foreach ($tags as $key2 => $value2) {
  3665. if (strpos($value2->name, $value->name) !== false && $key != $key2) {
  3666. unset($tags[$key]);
  3667. }
  3668. }
  3669. }
  3670. // 执行内链替换
  3671. foreach ($tags as $value) {
  3672. $data->content = preg_replace('/' . $value->name . '/', '<a href="' . $value->link . '">' . $value->name . '</a>', $data->content, $this->config('content_tags_replace_num') ?: 3);
  3673. }
  3674. // 还原保护的内容
  3675. $pattern = '/\#rega:([0-9]+)\#/';
  3676. if (preg_match_all($pattern, $data->content, $matches2)) {
  3677. $count = count($matches2[0]);
  3678. for ($i = 0; $i < $count; $i ++) {
  3679. $data->content = str_replace($matches2[0][$i], $matches1[0][$matches2[1][$i]], $data->content);
  3680. }
  3681. }
  3682. }
  3683. $content = str_replace($search, $this->adjustLabelData($params, $data->content, null, true), $content);
  3684. break;
  3685. case 'keywords': // 如果内容关键字为空,则自动使用全局关键字
  3686. if ($data->keywords) {
  3687. $content = str_replace($search, $this->adjustLabelData($params, $data->keywords, null, true), $content);
  3688. } else {
  3689. $content = str_replace($search, '{pboot:sitekeywords}', $content);
  3690. }
  3691. break;
  3692. case 'description': // 如果内容描述为空,则自动使用全局描述
  3693. if ($data->description) {
  3694. $content = str_replace($search, $this->adjustLabelData($params, $data->description, null, true), $content);
  3695. } else {
  3696. $content = str_replace($search, '{pboot:sitedescription}', $content);
  3697. }
  3698. break;
  3699. default:
  3700. if (isset($data->$label)) {
  3701. $content = str_replace($search, $this->adjustLabelData($params, $data->$label), $content);
  3702. } elseif (strpos($label, 'ext_') === 0) {
  3703. $content = str_replace($search, '', $content);
  3704. }
  3705. }
  3706. return $content;
  3707. }
  3708. //解析城市列表标签
  3709. // 解析分站列表标签
  3710. public function parserCityListLabel($content)
  3711. {
  3712. $pattern = '/\{pboot:city(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:city\}/';
  3713. $pattern2 = '/\[city:([\w]+)(\s+[^]]+)?\]/';
  3714. $pattern3 = '/pboot:([0-9])+city/';
  3715. if (preg_match_all($pattern, $content, $matches)) {
  3716. $data = $this->model->getCityListTree();
  3717. $count = count($matches[0]);
  3718. for ($i = 0; $i < $count; $i ++) {
  3719. // 无数据时直接替换整体标签为空
  3720. if (! $data['tree']) {
  3721. $content = str_replace($matches[0][$i], '', $content);
  3722. continue;
  3723. }
  3724. // 获取调节参数
  3725. $params = $this->parserParam($matches[1][$i]);
  3726. $pid = 0;
  3727. $num = 0;
  3728. $istop = 0;
  3729. $islevel = 0;
  3730. foreach ($params as $key => $value) {
  3731. switch ($key) {
  3732. case 'pid':
  3733. $pid = $value;
  3734. break;
  3735. case 'num':
  3736. $num = $value;
  3737. break;
  3738. case 'istop':
  3739. $istop = $value;
  3740. break;
  3741. case 'islevel':
  3742. $islevel = $value;
  3743. break;
  3744. }
  3745. }
  3746. $out_data = array();
  3747. // 置顶
  3748. if( $istop ){
  3749. foreach( $data['tree'] as $row ){
  3750. if( $row['istop']==1 ){
  3751. array_push($out_data,$row);
  3752. }
  3753. foreach( $row['son'] as $son ){
  3754. if( $son['istop']==1 ){
  3755. array_push($out_data,$son);
  3756. }
  3757. }
  3758. }
  3759. }elseif( $islevel ){ //显示层级
  3760. $citys = $this->config('citys');
  3761. $pid = 0;
  3762. if( cookie('city')!=='' ){
  3763. $cur_city = $citys[cookie('city')];
  3764. if( $cur_city['pid'] == 0 ){
  3765. $pid = $cur_city['id'];
  3766. }else{
  3767. $pid = $cur_city['pid'];
  3768. }
  3769. }
  3770. foreach( $data['tree'] as $row ){
  3771. if( $row['id']==$pid ){
  3772. foreach( $row['son'] as $son ){
  3773. array_push($out_data,$son);
  3774. }
  3775. }
  3776. }
  3777. }else{
  3778. if ($pid) { // 非顶级栏目起始,调用子栏目
  3779. $parent_arr = explode(',', $pid);
  3780. foreach ($parent_arr as $vp) {
  3781. if (isset($data['tree'][trim($vp)]['son'])) {
  3782. $out_data = array_merge($out_data, $data['tree'][trim($vp)]['son']);
  3783. }
  3784. }
  3785. } else { // 顶级栏目起始
  3786. $out_data = $data['top'];
  3787. }
  3788. }
  3789. // 读取指定数量
  3790. if ($num) {
  3791. $out_data = array_slice($out_data, 0, $num);
  3792. }
  3793. // 匹配到内部标签
  3794. if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
  3795. $count2 = count($matches2[0]); // 循环内的内容标签数量
  3796. } else {
  3797. $count2 = 0;
  3798. }
  3799. $out_html = '';
  3800. $key = 1;
  3801. foreach ($out_data as $value) { // 按查询的数据条数循环
  3802. $one_html = $matches[2][$i];
  3803. if ($count2) {
  3804. for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
  3805. $params = $this->parserParam($matches2[2][$j]);
  3806. switch ($matches2[1][$j]) {
  3807. case 'n':
  3808. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
  3809. break;
  3810. case 'i':
  3811. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
  3812. break;
  3813. case 'home':
  3814. $one_html = str_replace($matches2[0][$j], create_city_url($value['etitle'], $value['isurl'], false), $one_html);
  3815. break;
  3816. case 'link':
  3817. $one_html = str_replace($matches2[0][$j], create_city_url($value['etitle'], $value['isurl'], true), $one_html);
  3818. break;
  3819. case 'soncount':
  3820. if (isset($data['tree'][$value['id']]['son'])) {
  3821. $one_html = str_replace($matches2[0][$j], count($data['tree'][$value['id']]['son']), $one_html);
  3822. } else {
  3823. $one_html = str_replace($matches2[0][$j], 0, $one_html);
  3824. }
  3825. break;
  3826. default:
  3827. if (isset($value[$matches2[1][$j]])) {
  3828. $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value[$matches2[1][$j]]), $one_html);
  3829. }
  3830. }
  3831. }
  3832. }
  3833. $key ++;
  3834. $out_html .= $one_html;
  3835. }
  3836. // 无限极嵌套解析
  3837. if (preg_match($pattern3, $out_html, $matches3)) {
  3838. $out_html = str_replace('pboot:' . $matches3[1] . 'city', 'pboot:city', $out_html);
  3839. $out_html = str_replace('[' . $matches3[1] . 'city:', '[city:', $out_html);
  3840. $out_html = $this->parserCityListLabel($out_html);
  3841. }
  3842. // 执行内容替换
  3843. $content = str_replace($matches[0][$i], $out_html, $content);
  3844. }
  3845. }
  3846. return $content;
  3847. }
  3848. // end 城市分站解析
  3849. // 替换页面内容关键词
  3850. protected function parserReplaceKeyword($content)
  3851. {
  3852. $keys = $this->config('content_keyword_replace');
  3853. $keys_arr = explode(',', strip_tags($keys));
  3854. foreach ($keys_arr as $key => $value) {
  3855. $content = str_replace($value, str_repeat('*', mb_strlen($value)), $content);
  3856. }
  3857. return $content;
  3858. }
  3859. // 解析生成内容链接
  3860. public function parserLink($type, $urlname, $pagetype, $scode, $sortfilename, $id = '', $contentfilename = '')
  3861. {
  3862. $url_break_char = $this->config('url_break_char') ?: '_';
  3863. $url_rule_sort_suffix = $this->config('url_rule_sort_suffix') ? true : null;
  3864. $url_rule_content_path = $this->config('url_rule_content_path') ? true : false;
  3865. if ($type == 1 || $pagetype == 'about') {
  3866. $urlname = $urlname ?: 'about';
  3867. if ($sortfilename) {
  3868. $link = Url::home($sortfilename);
  3869. } else {
  3870. $link = Url::home($urlname . $url_break_char . $scode);
  3871. }
  3872. } else {
  3873. $urlname = $urlname ?: 'list';
  3874. if ($pagetype == 'list') {
  3875. if ($sortfilename) {
  3876. $link = Url::home($sortfilename);
  3877. } else {
  3878. $link = Url::home($urlname . $url_break_char . $scode);
  3879. }
  3880. } elseif ($pagetype == 'content') {
  3881. if ($url_rule_content_path) {
  3882. if ($contentfilename) {
  3883. $link = Url::home($contentfilename, true);
  3884. } else {
  3885. $link = Url::home($id, true);
  3886. }
  3887. } else {
  3888. if ($sortfilename && $contentfilename) {
  3889. $link = Url::home($sortfilename . '/' . $contentfilename, true);
  3890. } elseif ($sortfilename) {
  3891. $link = Url::home($sortfilename . '/' . $id, true);
  3892. } elseif ($contentfilename) {
  3893. $link = Url::home($urlname . $url_break_char . $scode . '/' . $contentfilename, true);
  3894. } else {
  3895. $link = Url::home($urlname . $url_break_char . $scode . '/' . $id, true);
  3896. }
  3897. }
  3898. } else {
  3899. $link = 'javascript:;';
  3900. }
  3901. }
  3902. return $link;
  3903. }
  3904. // 检查标签权限
  3905. protected function checkLabelLevel($params)
  3906. {
  3907. foreach ($params as $key => $value) {
  3908. switch ($key) {
  3909. case 'showgcode': // 指定等级显示,支持多个逗号隔开
  3910. $showgcode = explode(',', $params['showgcode']);
  3911. if (! in_array(session('pboot_gcode'), $showgcode)) {
  3912. return false;
  3913. }
  3914. break;
  3915. case 'showucode': // 指定用户显示,支持多个逗号隔开
  3916. $showucode = explode(',', $params['showucode']);
  3917. if (! in_array(session('pboot_ucode'), $showucode)) {
  3918. return false;
  3919. }
  3920. break;
  3921. case 'hidegcode': // 指定等级隐藏,支持多个逗号隔开
  3922. $hidegcode = explode(',', $params['hidegcode']);
  3923. if (in_array(session('pboot_gcode'), $hidegcode)) {
  3924. return false;
  3925. }
  3926. break;
  3927. case 'hideucode': // 指定用户隐藏,支持多个逗号隔开
  3928. $hideucode = explode(',', $params['hideucode']);
  3929. if (in_array(session('pboot_ucode'), $hideucode)) {
  3930. return false;
  3931. }
  3932. break;
  3933. case 'showgcodelt': // 等级小于显示
  3934. if ($params['showgcodelt'] <= session('pboot_gcode')) {
  3935. return false;
  3936. }
  3937. break;
  3938. case 'showgcodegt': // 等级大于显示
  3939. if ($params['showgcodegt'] >= session('pboot_gcode')) {
  3940. return false;
  3941. }
  3942. break;
  3943. case 'showgcodele': // 等级小于等于显示
  3944. if ($params['showgcodele'] < session('pboot_gcode')) {
  3945. return false;
  3946. }
  3947. break;
  3948. case 'showgcodege': // 等级大于等于显示
  3949. if ($params['showgcodege'] > session('pboot_gcode')) {
  3950. return false;
  3951. }
  3952. break;
  3953. case 'hidegcodelt': // 等级小于隐藏
  3954. if ($params['hidegcodelt'] > session('pboot_gcode')) {
  3955. return false;
  3956. }
  3957. break;
  3958. case 'hidegcodegt': // 等级大于隐藏
  3959. if ($params['hidegcodegt'] < session('pboot_gcode')) {
  3960. return false;
  3961. }
  3962. break;
  3963. case 'hidegcodele': // 等级小于等于隐藏
  3964. if ($params['hidegcodele'] >= session('pboot_gcode')) {
  3965. return false;
  3966. }
  3967. break;
  3968. case 'hidegcodege': // 等级大于等于隐藏
  3969. if ($params['hidegcodege'] <= session('pboot_gcode')) {
  3970. return false;
  3971. }
  3972. break;
  3973. case 'showlogin': // 登录后显示
  3974. if ($params['showlogin'] && ! session('pboot_uid')) {
  3975. return false;
  3976. }
  3977. break;
  3978. case 'hidelogin': // 登录后隐藏
  3979. if ($params['hidelogin'] && session('pboot_uid')) {
  3980. return false;
  3981. }
  3982. break;
  3983. }
  3984. }
  3985. return true;
  3986. }
  3987. }