ParserController.php 188 KB

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