ParserController.php 188 KB

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