心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ParserController.php 204KB

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