心理咨询网
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 203KB

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