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

ParserController.php 197KB

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