1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402 |
- <?php
- /**
- * @copyright (C)2016-2099 Hnaoyun Inc.
- * @author XingMeng
- * @email hnxsh@foxmail.com
- * @date 2018年2月14日
- * 标签解析引擎控制器
- */
- namespace app\home\controller;
-
- use core\basic\Controller;
- use app\home\model\ParserModel;
- use core\basic\Url;
- use app\home\model\DoModel;
- use app\home\model\MemberModel;
-
- class ParserController extends Controller
- {
-
- protected $model;
-
- protected $pre = array();
-
- protected $var = array();
-
- public function __construct()
- {
- $this->model = new ParserModel();
- }
-
- public function _empty()
- {
- _404('您访问的地址有误,请核对后重试!');
- }
-
- // 解析全局前置公共标签
- public function parserBefore($content)
- {
- // 处理模板中不需要解析的标签
- $content = $this->savePreLabel($content);
- $content = $this->parserSingleLabel($content); // 单标签解析
- $content = $this->parserUserLabel($content); // 自定义标签
- return $content;
- }
-
- // 解析全局后置公共标签
- public function parserAfter($content)
- {
- // 默认页面信息替换
- $content = str_replace('{pboot:pagetitle}', $this->config('other_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
- $content = str_replace('{pboot:pagekeywords}', '{pboot:sitekeywords}', $content);
- $content = str_replace('{pboot:pagedescription}', '{pboot:sitedescription}', $content);
- $content = str_replace('{pboot:keyword}', get('keyword', 'vars'), $content); // 当前搜索的关键字
-
- $content = $this->parserSiteLabel($content); // 站点标签
- $content = $this->parserCompanyLabel($content); // 公司标签
- $content = $this->parserMemberLabel($content); // 会员标签
- $content = $this->parserNavLabel($content); // 分类列表
- $content = $this->parserCityListLabel($content); // 解析城市分站标签
- $content = $this->parserSelectAllLabel($content); // CMS筛选全部标签解析
- $content = $this->parserSelectLabel($content); // CMS筛选标签解析
- $content = $this->parserSpecifySortLabel($content); // 指定分类
- $content = $this->parserListLabel($content); // 指定列表
- $content = $this->parserSpecifyContentLabel($content); // 指定内容
- $content = $this->parserContentPicsLabel($content); // 内容多图
- $content = $this->parserContentCheckboxLabel($content); // 内容多选调取
- $content = $this->parserContentTagsLabel($content); // 内容tags调取
- $content = $this->parserSlideLabel($content); // 幻灯片
- $content = $this->parserLinkLabel($content); // 友情链接
- $content = $this->parserMessageLabel($content); // 留言板
- $content = $this->parserFormLabel($content); // 自定义表单
- $content = $this->parserSubmitFormLabel($content); // 自定义表单提交
- $content = $this->parserSqlListLabel($content); // 自定义SQL输出
-
- $content = $this->parserQrcodeLabel($content); // 二维码生成
- $content = $this->parserPageLabel($content); // CMS分页标签解析(需置后)
- $content = $this->parserIfLabel($content); // IF语句(需置最后)
- $content = $this->parserLoopLabel($content); // LOOP语句(需置后,不可放到if前面,否则有安全风险)
- $content = $this->restorePreLabel($content); // 还原不需要解析的内容
- $content = $this->parserReplaceKeyword($content); // 页面关键词替换
- $content = $this->parserTitleReplaceLabel($content); // 通用内容替换标签 这里是我新增的
- $content = $this->parserBLock($content); //自定义方法2
- $content = $this->parserForeachLabel($content); // 指定随意内容按条件遍
-
- // 解析个人扩展标签,升级不覆盖
- if (file_exists(APP_PATH . '/home/controller/ExtLabelController.php')) {
- if (class_exists('app\home\controller\ExtLabelController')) {
- $extlabel = new ExtLabelController();
- $content = $extlabel->run($content);
- }
- }
-
- return $content;
- }
-
- // 解析指定随意内容遍历,支持设定分隔符 @pbhtml
- /*
- * foreach标签无法匹配成功
- * 模板代码不要有php原生 因为无法与标签传值
- * 复制link标签 加上city_id 的手法 就可以了
- */
- public function parserForeachLabel($content)
- {
- $pattern = '/{pboot:foreach(s+[^}]+)?}([sS]*?){/pboot:foreach}/';
- $pattern2 = '/[foreach:([w]+)(s+[^]]+)?]/';
-
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i<$count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $str = '';
- $char = ',';
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'str':
- //var_dump($value);
- $str = $value;
- break;
- case 'char':
- if ($value) $char = $value;
- break;
- }
- }
-
- // 无数据直接替换为空并跳过
- if (! $str) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- //$arr是数组 可以调用自定义函数或模型方法 一般直接用sql
- $arr = explode($char,$str);
- foreach ($arr as $value) { // 按查询图片条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j<$count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'name':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value), $one_html);
- break;
- }
- }
- $key ++;
- $out_html .= $one_html;
- if (isset($num) && $key > $num) {
- unset($num);
- break;
- }
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
-
- // 通用内容替换标签 @mk-title_replace
- //$content这里用的时文章标题,直接是字符串
- public function parserTitleReplaceLabel($content)
- {
-
- $pattern = '/\{pboot:titlereplace(\s+[^}]+)?\}/';
-
- //先对$content 进行处理 包含 {xx}
- //{pboot:titlereplace title='{xx}心理咨询,{xx}心理医生,{xx}心理咨询中心机构【乐达心理】' /}
- //因为{xx} 正则问题
- $content = str_replace('{xx}', '[xx]', $content);
-
- //var_dump($content);die;
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- //var_dump($matches[0][$i]);die;
- $matches[0][$i] = str_replace('[xx]', '{xx}', $matches[0][$i]);
- $params = $this->parserParam($matches[0][$i]);
- $data = '';
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'title'://这里其实可以解析很多的,不只是title,可以根据case进行不同的解析
- $data = $value; // 获取到的文章title
- //$data = titlereplace($data); //testreplace方法为自定义方法,在\apps\common\function.php里
- //$data = str_replace("`", '', $data);
- //var_dump($data);die;
- $data = explode(',',$data);
- $data = $data[0];
- break;
- }
- }
- if (!$data) { // 无内容不解析
- continue;
- }
- //$content = str_replace($matches[0][$i], $data, $content);
- //$content {pboot:titlereplace title='广州心理咨询,广州心理医生,广州心理咨询中心机构【乐达心理】' /}
- //$data '广州
- //$matches[0][$i] {pboot:titlereplace title='广州
- //$content = str_replace("`/}", '', $content);
- $content = str_replace('[xx]', '{xx}', $content);
- //var_dump($content);die;
- $content = str_replace($matches[0][$i], $data, $content);
- }
-
- if((int)$count === 0){
- $content = str_replace('[xx]', '{xx}', $content);
- }
- }else{
- $content = str_replace('[xx]', '{xx}', $content);
- }
- return $content;
- }
-
- /*
- * {pboot:block id='{pboot:httpurl}' /}
- */
- public function parserBLock($content){
-
- $pattern = '/\{pboot:block(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[0][$i]);
- $data = '';
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'id':
- //var_dump($value);
- //$value里面存在{xx} 就需要特殊处理
- //解析顺序不同 与eyoucms的模板机制 区别
- $data = $this->model->getBlockContent($value);
- //return $data['value'];
- //print_r($data);exit();
- break;
- /*$data = $this->model->getContent($value)->content; // 获取到的文章id去获取文章内容
- $data = testreplace($data);*/
-
- }
- }
- if (!$data) { // 无内容不解析
- continue;
- }
- //$content = $data['value'];
- $content = str_replace($matches[0][$i], $data, $content);
- }
- }
- return $content;
- }
-
- // 保存保留内容
- public function savePreLabel($content)
- {
- $pattern = '/\{pboot:pre}([\s\S]*?)\{\/pboot:pre\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $this->pre[] = $matches[1][$i];
- end($this->pre);
- $content = str_replace($matches[0][$i], '#pre:' . key($this->pre) . '#', $content);
- }
- }
- return $content;
- }
-
- // 还原保留内容
- public function restorePreLabel($content)
- {
- $pattern = '/\#pre:([0-9]+)\#/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $content = str_replace($matches[0][$i], $this->pre[$matches[1][$i]], $content);
- }
- }
- $content = str_replace('pboot@if', 'pboot:if', $content); // 还原系统解析if标签
- return $content;
- }
-
- // 解析单标签
- public function parserSingleLabel($content)
- {
- $content = str_replace('{pboot:ucenter}', Url::home('member/ucenter'), $content); // 用户中心
- if (! ! $url = get("backurl")) { // 获取会跳地址
- $content = str_replace('{pboot:login}', Url::home('member/login', null, "backurl=" . urlencode($url)), $content); // 登录地址
- } else {
- $content = str_replace('{pboot:login}', Url::home('member/login'), $content); // 登录地址
- }
-
- $content = str_replace('{pboot:register}', Url::home('member/register'), $content); // 注册地址
- $content = str_replace('{pboot:retrieve}', Url::home('member/retrieve'), $content); //找回密码
- $content = str_replace('{pboot:isregister}', Url::home('member/isRegister'), $content); // 检查是否注册地址
- $content = str_replace('{pboot:umodify}', Url::home('member/umodify'), $content); // 修改资料地址
- $content = str_replace('{pboot:logout}', Url::home('member/logout'), $content); // 推出登录
- $content = str_replace('{pboot:upload}', Url::home('member/upload'), $content); // 上传资料
-
- if (strpos($content, '{pboot:sendemail}')) {
- session('sendemail', true); // 避免非法外部提交
- $content = str_replace('{pboot:sendemail}', Url::home('member/sendEmail'), $content); // 上传资料
- } else {
- session('sendemail', false);
- }
-
- $content = str_replace('{pboot:islogin}', session('pboot_uid') ? 1 : 0, $content); // 是否登录
- if (strpos($content, '{pboot:mustlogin}') !== false) {
- $content = str_replace('{pboot:mustlogin}', '', $content);
- if (! session('pboot_uid')) { // 没有经登录
- if ($this->config('login_no_wait')) {
- location(Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
- } else {
- error('您的权限不足,无法浏览本页面!', Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
- }
- }
- }
-
- $content = str_replace('{pboot:msgaction}', Url::home('message'), $content); // 留言提交路径
- $content = str_replace('{pboot:scaction}', Url::home('search'), $content); // 搜索提交路径
- $content = str_replace('{pboot:msgcodestatus}', $this->config('message_check_code') === '0' ? 0 : 1, $content); // 是否开留言启验证码
- $content = str_replace('{pboot:formcodestatus}', $this->config('form_check_code') === '0' ? 0 : 1, $content); // 是否开启表单验证码
-
- $content = str_replace('{pboot:checkcode}', CORE_DIR . '/code.php', $content); // 验证码路径
- $content = str_replace('{pboot:lgpath}', Url::get('home/Do/area'), $content); // 多语言切换前置路径,如{pboot:lgpath}?lg=cn
-
- $content = str_replace('{pboot:appid}', $this->config('api_appid'), $content); // API认证用户
- $content = str_replace('{pboot:timestamp}', time(), $content); // 认证时间戳
- $content = str_replace('{pboot:signature}', md5(md5($this->config('api_appid') . $this->config('api_secret') . time())), $content); // API认证密钥
-
- $content = str_replace('{pboot:httpurl}', get_http_url(), $content); // 当前访问的域名地址
- $content = str_replace('{pboot:pageurl}', get_current_url(), $content); // 当前页面的地址
-
- $content = str_replace('{pboot:registercodestatus}', $this->config('register_check_code') === '0' ? 0 : ($this->config('register_check_code') ?: 1), $content); // 是否开启注册验证码
- $content = str_replace('{pboot:logincodestatus}', $this->config('login_check_code') === '0' ? 0 : 1, $content); // 是否开启评论验证码
- $content = str_replace('{pboot:commentcodestatus}', $this->config('comment_check_code') === '0' ? 0 : 1, $content); // 是否开启评论验证码
- $content = str_replace('{pboot:commentaction}', Url::home('comment/add', null, "contentid={content:id}"), $content); // 评论提交路径
- $content = str_replace('{pboot:mycommentpage}', Url::home('comment/my'), $content); // 我的评论
-
- $content = str_replace('{pboot:registerstatus}', $this->config('register_status') === '0' ? 0 : 1, $content); // 是否开启注册
- $content = str_replace('{pboot:loginstatus}', $this->config('login_status') === '0' ? 0 : 1, $content); // 是否开启登录
- $content = str_replace('{pboot:commentstatus}', $this->config('comment_status') === '0' ? 0 : 1, $content); // 是否开启评论
-
- // 记录蜘蛛爬行
- if ($this->config('spiderlog') !== '0') {
- if ($this->config('tpl_html_cache')) { // 缓存时插入script,否则直接执行
- $spidercode = "<script src='" . Url::home('Spider', null, 'url=' . URL) . "' async='async'></script>";
- $content = preg_replace('/(<\/body>)/i', $spidercode . "\n$1", $content);
- } else {
- $spider = new SpiderController(URL);
- $spider->index();
- }
- }
- // 生成分站首页
- $city_suffix = $this->config('city_suffix')?true:false; //分站后缀
- $content = str_replace('{zong}', Url::home('home/Index/', $city_suffix), $content); // {zong}
- $content = str_replace('{iscity}', cookie('city') ? 1 : 0, $content); // 用来判断当前是否是分站
-
- return $content;
- }
-
- // 解析站点标签
- public function parserSiteLabel($content)
- {
- $pattern = '/\{pboot:site([\w]+)(\s+[^}]+)?\}/';
- $data = array();
-
- // 页面自适应标题避免多横线
- if (preg_match($pattern, $content)) {
- $data = $this->model->getSite();
- if (! $data->subtitle) {
- $content = str_replace('{pboot:sitetitle}-{pboot:sitesubtitle}', '{pboot:sitetitle}', $content);
- }
- }
-
- if (preg_match_all($pattern, $content, $matches)) {
- $data = $data ?: $this->model->getSite();
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[2][$i]);
- switch ($matches[1][$i]) {
- case 'index':
- $content = str_replace($matches[0][$i], Url::home('home/Index/'), $content);
- break;
- case 'path':
- $content = str_replace($matches[0][$i], SITE_DIR, $content);
- break;
- case 'enter':
- $content = str_replace($matches[0][$i], SITE_INDEX_DIR, $content);
- break;
- case 'logo':
- if (isset($data->logo) && $data->logo) {
- if (! preg_match('/^http/', $data->logo)) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->logo), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->logo), $content);
- }
- } else {
- $content = str_replace($matches[0][$i], STATIC_DIR . '/images/logo.png', $content);
- }
- break;
- case 'tplpath':
- $content = str_replace($matches[0][$i], APP_THEME_DIR, $content);
- break;
- case 'language':
- $content = str_replace($matches[0][$i], get_lg(), $content);
- break;
- case 'statistical':
- if (isset($data->statistical)) {
- $content = str_replace($matches[0][$i], decode_string($data->statistical), $content);
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- case 'copyright':
- if (isset($data->copyright)) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, decode_string($data->copyright)), $content);
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- default:
- if (strpos(file_get_contents(CORE_PATH . base64_decode('L2Jhc2ljL0tlcm5lbC5waHA=')), base64_decode('S2VybmVs')))
- exit();
- if (isset($data->{$matches[1][$i]})) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->{$matches[1][$i]}), $content);
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- }
- }
- }
- return $content;
- }
-
- // 解析公司标签
- public function parserCompanyLabel($content)
- {
- $pattern = '/\{pboot:company([\w]+)(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $data = $this->model->getCompany();
- $count = count($matches[0]);
-
- //
- $city = cookie('city');
- $city_info = $this->config('citys')[$city];
-
- for ($i = 0; $i < $count; $i ++) {
- if (! $data) { // 无数据时直接替换为空
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
- $params = $this->parserParam($matches[2][$i]);
- switch ($matches[1][$i]) {
- case 'weixin':
- if (isset($data->weixin) && $data->weixin) {
- if (! preg_match('/^http/', $data->weixin)) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->weixin), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->weixin), $content);
- }
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- break;
- case 'contact':
- case 'mobile':
- case 'phone':
- case 'fax':
- case 'email':
- case 'qq':
- case 'address':
- if( $city_info[$matches[1][$i]] ){
- $data->{$matches[1][$i]} = $city_info[$matches[1][$i]];
- }
- default:
- if (isset($data->{$matches[1][$i]})) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->{$matches[1][$i]}), $content);
- }
- }
- }
- }
- return $content;
- }
-
- // 解析自定义标签
- public function parserUserLabel($content)
- {
- $pattern = '/\{label:([\w]+)(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $data = $this->model->getLabel();
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- if (! $data) { // 无数据时直接替换为空
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
- $params = $this->parserParam($matches[2][$i]);
- switch ($matches[1][$i]) {
- default:
- if (isset($data[$matches[1][$i]])) {
- if ($data[$matches[1][$i]]['type'] == 3 && $data[$matches[1][$i]]['value']) {
- if (! preg_match('/^http/', $data[$matches[1][$i]]['value'])) {
- $data[$matches[1][$i]]['value'] = $this->adjustLabelData($params, SITE_DIR . $data[$matches[1][$i]]['value']);
- } else {
- $data[$matches[1][$i]]['value'] = $this->adjustLabelData($params, $data[$matches[1][$i]]['value']);
- }
- }
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data[$matches[1][$i]]['value']), $content);
- }
- }
- }
- }
- return $content;
- }
-
- // 会员标签解析
- private function parserMemberLabel($content)
- {
- $pattern = '/\{user:([\w]+)(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- $model = new MemberModel();
- $data = $model->getUser();
- for ($i = 0; $i < $count; $i ++) {
- // 无数据直接替换并跳过
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
- $params = $this->parserParam($matches[2][$i]);
- switch ($matches[1][$i]) {
- case 'password': // 密码不允许显示
- $content = str_replace($matches[0][$i], '', $content);
- break;
- case 'registertime':
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->register_time), $content);
- break;
- case 'logincount':
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->login_count), $content);
- break;
- case 'lastloginip':
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, long2ip($data->last_login_ip)), $content);
- break;
- case 'lastlogintime':
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->last_login_time), $content);
- break;
- case 'headpic':
- if ($data->headpic) {
- if (! preg_match('/^http/', $data->headpic)) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->headpic), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->headpic), $content);
- }
- } else {
- $content = str_replace($matches[0][$i], SITE_DIR . '/apps/admin/view/default/images/logo.png', $content);
- }
- default:
- if (isset($data->{$matches[1][$i]})) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->{$matches[1][$i]}), $content);
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- }
- }
- }
- return $content;
- }
-
- // 解析栏目列表标签
- public function parserNavLabel($content)
- {
- $pattern = '/\{pboot:nav(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:nav\}/';
- $pattern2 = '/\[nav:([\w]+)(\s+[^]]+)?\]/';
- $pattern3 = '/pboot:([0-9])+nav/';
- if (preg_match_all($pattern, $content, $matches)) {
- $data = $this->model->getSortsTree();
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
-
- // 无数据时直接替换整体标签为空
- if (! $data['tree']) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
- $parent = 0;
- $num = 0;
- $scode = 0;
- $scode_arr = array();
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'parent':
- $parent = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'scode':
- $scode = $value;
- $scode_arr = explode(',', $scode);
- break;
- }
- }
-
- if ($parent) { // 非顶级栏目起始,调用子栏目
- $parent_arr = explode(',', $parent);
- $out_data = array();
- foreach ($parent_arr as $vp) {
- if (isset($data['tree'][trim($vp)]['son'])) {
- $out_data = array_merge($out_data, $data['tree'][trim($vp)]['son']);
- }
- }
- } else { // 顶级栏目起始
- $out_data = $data['top'];
- }
-
- // 读取指定数量
- if ($num) {
- $out_data = array_slice($out_data, 0, $num);
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($out_data as $value) { // 按查询的数据条数循环
- if ($scode_arr && ! in_array($value['scode'], $scode_arr)) {
- continue;
- }
- $one_html = $matches[2][$i];
- if ($count2) {
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'link':
- if ($value['outlink']) {
- $one_html = str_replace($matches2[0][$j], $value['outlink'], $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->parserLink($value['type'], $value['urlname'], 'list', $value['scode'], $value['filename'], '', ''), $one_html);
- }
- break;
- case 'soncount':
- if (isset($data['tree'][$value['scode']]['son'])) {
- $one_html = str_replace($matches2[0][$j], count($data['tree'][$value['scode']]['son']), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], 0, $one_html);
- }
- break;
- case 'rows':
- $one_html = str_replace($matches2[0][$j], $this->model->getSortRows($value['scode']), $one_html);
- break;
- case 'ico':
- if ($value['ico']) {
- if (! preg_match('/^http/', $value['ico'])) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value['ico']), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value['ico']), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- case 'pic':
- if ($value['pic']) {
- if (! preg_match('/^http/', $value['pic'])) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value['pic']), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value['pic']), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- default:
- if (isset($value[$matches2[1][$j]])) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value[$matches2[1][$j]]), $one_html);
- }
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
-
- // 无限极嵌套解析
- if (preg_match($pattern3, $out_html, $matches3)) {
- $out_html = str_replace('pboot:' . $matches3[1] . 'nav', 'pboot:nav', $out_html);
- $out_html = str_replace('[' . $matches3[1] . 'nav:', '[nav:', $out_html);
- $out_html = $this->parserNavLabel($out_html);
- }
-
- // 执行内容替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析当前位置
- public function parserPositionLabel($content, $scode, $page = null, $link = null)
- {
- $pattern = '/\{pboot:position(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- $data = $this->model->getPosition($scode);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[1][$i], false); // 保留对html标签的支持
-
- $separator = '';
- $separatoricon = '';
- $indextext = '';
- $indexicon = '';
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'separator':
- $separator = $value;
- break;
- case 'separatoricon':
- $separatoricon = $value;
- break;
- case 'indextext':
- $indextext = $value;
- break;
- case 'indexicon':
- $indexicon = $value;
- break;
- }
- }
-
- // 已经设置图标,则图标优先,如果没有,则判断是否已经设置文字
- if ($separatoricon) {
- $separator = ' <i class="' . $separatoricon . '"></i> ';
- } elseif (! $separator) {
- $separator = ' >> ';
- }
-
- if ($indexicon) {
- $indextext = '<i class="' . $indexicon . '"></i>';
- } elseif (! $indextext) {
- $indextext = '首页';
- }
-
- $out_html = '<a href="' . Url::home('home/Index') . '">' . $indextext . '</a>';
- if ($page && $scode == 0) {
- $out_html .= $separator . '<a href="' . $link . '">' . $page . '</a>';
- } else {
- foreach ($data as $key => $value) {
- if ($value['outlink']) {
- $out_html .= $separator . '<a href="' . $value['outlink'] . '">' . $value['name'] . '</a>';
- } else {
- $out_html .= $separator . '<a href="' . $this->parserLink($value['type'], $value['urlname'], 'list', $value['scode'], $value['filename'], '', '') . '">' . $value['name'] . '</a>';
- }
- }
- }
- // 执行内容替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析当前分类标签
- public function parserSortLabel($content, $sort)
- {
- $pattern = '/\{sort:([\w]+)(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[2][$i]);
- switch ($matches[1][$i]) {
- case 'link':
- if ($sort->outlink) {
- $content = str_replace($matches[0][$i], $sort->outlink, $content);
- } else {
- $content = str_replace($matches[0][$i], $this->parserLink($sort->type, $sort->urlname, 'list', $sort->scode, $sort->filename, '', ''), $content);
- }
- break;
- case 'tcode': // 顶级栏目ID
- if (! isset($tcode))
- $tcode = $this->model->getSortTopScode($sort->scode);
- $content = str_replace($matches[0][$i], $tcode, $content);
- break;
- case 'topname':
- if (! isset($tcode))
- $tcode = $this->model->getSortTopScode($sort->scode);
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $this->model->getSortName($tcode)), $content);
- break;
- case 'toplink':
- if (! isset($tcode)) {
- $tcode = $this->model->getSortTopScode($sort->scode);
- }
- $top_sort = $this->model->getSort($tcode);
- if ($top_sort->outlink) {
- $toplink = $top_sort->outlink;
- } else {
- $toplink = $this->parserLink($top_sort->type, $top_sort->urlname, 'list', $top_sort->scode, $top_sort->filename, '', '');
- }
- $content = str_replace($matches[0][$i], $toplink, $content);
- break;
- case 'parentname':
- if ($sort->pcode == 0) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->name), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->parentname), $content);
- }
- break;
- case 'parentlink':
- if ($sort->pcode == 0) {
- $parent_sort = $sort;
- } else {
- $parent_sort = $this->model->getSort($sort->pcode);
- }
- if ($parent_sort->outlink) {
- $parentlink = $top_sort->outlink;
- } else {
- $parentlink = $this->parserLink($parent_sort->type, $parent_sort->urlname, 'list', $parent_sort->scode, $parent_sort->filename, '', '');
- }
- $content = str_replace($matches[0][$i], $parentlink, $content);
- break;
- case 'toprows':
- if (! isset($tcode))
- $tcode = $this->model->getSortTopScode($sort->scode);
- $content = str_replace($matches[0][$i], $this->model->getSortRows($tcode), $content);
- break;
- case 'parentrows':
- if ($sort->pcode == 0) {
- $content = str_replace($matches[0][$i], $this->model->getSortRows($sort->scode), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->model->getSortRows($sort->pcode), $content);
- }
- break;
- case 'rows':
- $content = str_replace($matches[0][$i], $this->model->getSortRows($sort->scode), $content);
- break;
- case 'ico':
- if ($sort->ico) {
- if (! preg_match('/^http/', $sort->ico)) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $sort->ico), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->ico), $content);
- }
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- break;
- case 'pic':
- if ($sort->pic) {
- if (! preg_match('/^http/', $sort->pic)) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $sort->pic), $content);
- } else {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->pic), $content);
- }
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- break;
- case 'keywords': // 如果栏目关键字为空,则自动使用全局关键字
- if ($sort->keywords) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->keywords), $content);
- } else {
- $content = str_replace($matches[0][$i], '{pboot:sitekeywords}', $content);
- }
- break;
- case 'description': // 如果栏目描述为空,则自动使用全局描述
- if ($sort->description) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->description), $content);
- } else {
- $content = str_replace($matches[0][$i], '{pboot:sitedescription}', $content);
- }
- break;
- default:
- if (isset($sort->{$matches[1][$i]})) {
- $content = str_replace($matches[0][$i], $this->adjustLabelData($params, $sort->{$matches[1][$i]}), $content);
- } else {
- $content = str_replace($matches[0][$i], '', $content);
- }
- }
- }
- }
- return $content;
- }
-
- // 解析非列表页分类标签
- public function parserSpecialPageSortLabel($content, $id, $page, $link)
- {
- $pattern = '/\{sort:([\w]+)(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[2][$i]);
- switch ($matches[1][$i]) {
- case 'tcode': // 顶级栏目ID
- $content = str_replace($matches[0][$i], $id, $content);
- break;
- case 'topname':
- $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), $page, $content);
- break;
- case 'toplink':
- $content = str_replace($matches[0][$i], $link, $content);
- break;
- case 'pcode': // 父栏目ID
- $content = str_replace($matches[0][$i], $id, $content);
- break;
- case 'parentname':
- $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), $page, $content);
- break;
- case 'parentlink':
- $content = str_replace($matches[0][$i], $link, $content);
- break;
- case 'scode': // 当前栏目ID
- $content = str_replace($matches[0][$i], $id, $content);
- break;
- case 'link':
- $content = str_replace($matches[0][$i], $link, $content);
- break;
- case 'name': // 当前分类名称
- $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), $page, $content);
- break;
- case 'keywords': // 当前分类关键字,使用全局
- $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), '{pboot:sitekeywords}', $content);
- break;
- case 'description': // 当前分类描述,使用全局
- $content = str_replace($this->adjustLabelData($params, $matches[0][$i]), '{pboot:sitedescription}', $content);
- break;
- default:
- $content = str_replace($matches[0][$i], '', $content);
- }
- }
- }
- return $content;
- }
-
- // 解析指定分类标签
- public function parserSpecifySortLabel($content)
- {
- $pattern = '/\{pboot:sort(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:sort\}/';
- $pattern2 = '/\[sort:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $scode = - 1;
-
- // 跳过未指定scode的列表
- if (! array_key_exists('scode', $params)) {
- continue;
- }
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 分离分类编码
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'scode':
- $scode = $value;
- break;
- }
- }
-
- if (! $scode) {
- $scode = - 1;
- }
-
- // 读取一个或多个栏目数据
- $data = $this->model->getMultSort(escape_string($scode));
-
- // 无数据直接跳过
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'link':
- if ($value->outlink) {
- $one_html = str_replace($matches2[0][$j], $value->outlink, $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->parserLink($value->type, $value->urlname, 'list', $value->scode, $value->filename, '', ''), $one_html);
- }
- break;
- case 'ico':
- if ($value->ico) {
- if (! preg_match('/^http/', $value->ico)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->ico), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->ico), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- case 'pic':
- if ($value->pic) {
- if (! preg_match('/^http/', $value->pic)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pic), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pic), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- case 'rows':
- $one_html = str_replace($matches2[0][$j], $this->model->getSortRows($value->scode), $one_html); // 获取分类包含子类的内容数量
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- // 执行替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析筛选全部
- public function parserSelectAllLabel($content)
- {
- $pattern = '/\{pboot:selectall(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[1][$i]);
- $text = '全部';
- $field = '';
- $class = '';
- $active = '';
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'field':
- $field = $value;
- break;
- case 'text':
- $text = $value;
- break;
- case 'class':
- $class = $value;
- break;
- case 'active':
- $active = $value;
- break;
- }
- }
-
- // 跳过不带field的标签
- if (! $field) {
- continue;
- }
-
- $url_rule_type = $this->config('url_rule_type') ?: 3;
- $url_rule_suffix = $this->config('url_rule_suffix') ?: '.html';
- $url_break_char = $this->config('url_break_char') ?: '_';
- $url_rule_sort_suffix = '/';
-
- // 附加后缀及参数
- if ($url_rule_type == 1 || $url_rule_type == 2) {
- // 获取地址路径
- $url = parse_url(URL);
-
- // 避免非根目录首页筛选问题
- if (trim($url['path'], '/') == trim(SITE_DIR, '/')) {
- $url_rule_sort_suffix = '/';
- }
-
- $path = preg_replace('/\/page\/[0-9]+/', '', $url['path']); // 去除路径方式分页
-
- // 去后缀扩展
- if (! ! $pos = strripos($path, $url_rule_suffix)) {
- $path = substr($path, 0, $pos);
- }
-
- // 去路径分页,回到首页
- if (defined('CMS_PAGE_CUSTOM')) {
- $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', '$1', rtrim($path, '/'));
- } else {
- $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', '$1$2', rtrim($path, '/'));
- }
-
- // 拼接地址
- $path .= $url_rule_sort_suffix . query_string('p,s,' . $field);
- } elseif ($url_rule_type == 3) {
- $output = array();
- if (isset($_SERVER["QUERY_STRING"]) && ! ! $qs = $_SERVER["QUERY_STRING"]) {
- parse_str($qs, $output);
- unset($output['page']); // 去除字符串方式分页,回到第一页
- unset($output['p']); // 去除保留参数
- unset($output['s']); // 去除保留参数
- unset($output[$field]); // 不筛选该字段
-
- if ($output && ! current($output)) {
- $path_qs = key($output); // 第一个参数为路径信息,注意PHP数组会自动将点转换下划线
- unset($output[$path_qs]); // 去除路径参数
- $temp_suffix = substr($url_rule_suffix, 1);
- if (! ! $pos = strripos($path_qs, '_' . $temp_suffix)) {
- $path = substr($path_qs, 0, $pos); // 去扩展
- } else {
- $path = $path_qs;
- }
-
- // 去除原分页参数
- if (defined('CMS_PAGE_CUSTOM')) {
- $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', "$1", rtrim($path, '/'));
- } else {
- $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', "$1$2", rtrim($path, '/'));
- }
-
- $path = SITE_INDEX_DIR . '/?' . $path . $url_rule_sort_suffix;
- } else {
- $path = '';
- }
-
- $qs = http_build_query($output);
-
- if ($path && $qs) { // 重组地址
- $path = rtrim($path, '/') . '/&' . $qs;
- } elseif ($qs) {
- $path = SITE_INDEX_DIR . '/?' . $qs;
- } elseif (! $path) {
- $path = SITE_INDEX_DIR . '/';
- }
- } else {
- $path = SITE_INDEX_DIR . '/';
- }
- }
-
- // 如果有对本字段进行筛选,则不高亮
- if (get($field, 'vars')) {
- $out_html = '<a href="' . $path . '" class="' . $class . '">' . $text . '</a>';
- } else {
- $out_html = '<a href="' . $path . '" class="' . $active . '">' . $text . '</a>';
- }
-
- // 执行内容替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析筛选标签
- public function parserSelectLabel($content)
- {
- $pattern = '/\{pboot:select(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:select\}/';
- $pattern2 = '/\[select:([\w]+)(\s+[^]]+)?\]/';
-
- // 参数处理
- if (preg_match($pattern, $content)) {
-
- $url_rule_type = $this->config('url_rule_type') ?: 3;
- $url_rule_suffix = $this->config('url_rule_suffix') ?: '.html';
- $url_break_char = $this->config('url_break_char') ?: '_';
- $url_rule_sort_suffix = '/';
-
- // 附加后缀及参数
- if ($url_rule_type == 1 || $url_rule_type == 2) {
- // 获取地址路径
- $url = parse_url(URL);
-
- // 避免非根目录首页筛选问题
- if (trim($url['path'], '/') == trim(SITE_DIR, '/')) {
- $url_rule_sort_suffix = '/';
- }
-
- $path = preg_replace('/\/page\/[0-9]+/', '', $url['path']); // 去除路径方式分页,回到第一页
-
- // 去后缀扩展
- if (! ! $pos = strripos($path, $url_rule_suffix)) {
- $path = substr($path, 0, $pos);
- }
-
- // 去路径分页,回到首页
- if (defined('CMS_PAGE_CUSTOM')) {
- $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', '$1', rtrim($path, '/'));
- } else {
- $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', '$1$2', rtrim($path, '/'));
- }
- }
-
- $output = array();
- if (isset($_SERVER["QUERY_STRING"]) && ! ! $qs = $_SERVER["QUERY_STRING"]) {
- parse_str($qs, $output);
- unset($output['page']); // 去除字符串方式分页,回到第一页
- unset($output['p']); // 去除保留参数
- unset($output['s']); // 去除保留参数
- if ($url_rule_type == 3 && $output && ! current($output)) {
- $path_qs = key($output); // 第一个参数为路径信息,注意PHP数组会自动将点转换下划线
- unset($output[$path_qs]); // 去除路径参数
- $temp_suffix = substr($url_rule_suffix, 1);
- if (! ! $pos = strripos($path_qs, '_' . $temp_suffix)) {
- $path = substr($path_qs, 0, $pos); // 去扩展
- } else {
- $path = $path_qs;
- }
-
- // 去除原分页参数
- if (defined('CMS_PAGE_CUSTOM')) {
- $path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', "$1", rtrim($path, '/'));
- } else {
- $path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', "$1$2", rtrim($path, '/'));
- }
- $path = SITE_INDEX_DIR . '/?' . $path;
- $not_index = true;
- }
- }
- $path = isset($path) ? $path . $url_rule_sort_suffix : SITE_INDEX_DIR . '/';
- }
-
- // 执行匹配替换
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
-
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $field = '';
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'field':
- $field = $value;
- break;
- }
- }
-
- // 跳过不带field的标签
- if (! $field) {
- continue;
- }
-
- // 读取数据
- if (! ! $data = $this->model->getSelect(escape_string($field))) {
- $data = explode(',', $data);
- } else {
- $data = array();
- }
-
- // 无数据直接替换为空并跳过
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'value':
- $one_html = str_replace($matches2[0][$j], $value, $one_html);
- break;
- case 'current':
- $one_html = str_replace($matches2[0][$j], get($field, 'vars'), $one_html);
- break;
- case 'link':
- $qs = $output; // 需使用中间变量,避免多个链接相同问题
- $qs[$field] = $value;
- $qs = http_build_query($qs);
- if ($url_rule_type == 3 && $not_index) {
- $link = rtrim($path, '/') . '/&' . $qs;
- } else {
- $link = $path . '?' . $qs;
- }
- $one_html = str_replace($matches2[0][$j], $link, $one_html);
- break;
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析内容列表标签
- public function parserListLabel($content, $cscode = '')
- {
- $pattern = '/\{pboot:list(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:list\}/';
- $pattern2 = '/\[list:([\w\+\-\*\/\%]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
-
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = $this->config('pagesize'); // 未设置条数时使用默认15
- $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC'; // 默认排序
- $filter = ''; // 过滤
- $tags = ''; // tag标签
- $fuzzy = true; // 设置过滤、tag、筛选是否模糊匹配
- $ispics = ''; // 是否多图
- $isico = ''; // 是否缩略图
- $istop = ''; // 是否置顶
- $isrecommend = ''; // 是否推荐
- $isheadline = ''; // 是否头条
- $start = 1; // 起始条数,默认第一条开始
- $lfield = ''; // 查询字段限制
-
- // 判断当前栏目和指定栏目
- if ($cscode && ! array_key_exists('scode', $params)) { // 解析当前
- $scode = $cscode;
- $page = true; // 如果未指定分类默认分页
- } elseif (! $cscode && array_key_exists('scode', $params)) { // 解析指定
- $scode = $params['scode'];
- $page = false; // 如果指定分类默认不分页
- } else {
- continue;
- }
-
- if ($scode == '*') {
- $scode = '';
- }
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'order':
- switch ($value) {
- case 'id':
- $order = 'a.id DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC';
- break;
- case 'date':
- $order = 'a.date DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.id DESC';
- break;
- case 'sorting':
- $order = 'a.sorting ASC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.date DESC,a.id DESC';
- break;
- case 'istop':
- $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'isrecommend':
- $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'isheadline':
- $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'visits':
- case 'likes':
- case 'oppose':
- $order = $value . ' DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'random': // 随机取数
- $db_type = get_db_type();
- if ($db_type == 'mysql') {
- $order = "RAND()";
- } elseif ($db_type == 'sqlite') {
- $order = "RANDOM()";
- }
- break;
- default:
- if ($value) {
- $orders = explode(',', $value);
- foreach ($orders as $k => $v) {
- if (strpos($v, 'ext_') === 0) {
- $orders[$k] = 'e.' . $v;
- } else {
- $orders[$k] = 'a.' . $v;
- }
- }
- $value = implode(',', $orders);
- $order = $value . ',a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- }
- }
- break;
- case 'filter':
- $filter = $value;
- break;
- case 'fuzzy':
- $fuzzy = $value;
- break;
- case 'tags':
- $tags = $value;
- break;
- case 'ispics':
- $ispics = $value;
- break;
- case 'isico':
- $isico = $value;
- break;
- case 'istop':
- $istop = $value;
- break;
- case 'isrecommend':
- $isrecommend = $value;
- break;
- case 'isheadline':
- $isheadline = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- case 'lfield':
- $lfield = $value;
- break;
- }
- }
-
- // filter数据筛选
- $where1 = array();
- if ($filter) {
- $filter = explode('|', $filter);
- if (count($filter) == 2) {
- $filter_arr = explode(',', $filter[1]);
- if ($filter[0] == 'title') {
- $filter[0] = 'a.title';
- }
- foreach ($filter_arr as $value) {
- if ($value) {
- if ($fuzzy) {
- $where1[] = $filter[0] . " like '%" . escape_string($value) . "%'";
- } else {
- $where1[] = $filter[0] . "='" . escape_string($value) . "'";
- }
- }
- }
- }
- }
-
- // tags数据参数筛选
- $where2 = array();
- if ($tags) {
- $tags_arr = explode(',', $tags);
- foreach ($tags_arr as $value) {
- if ($value) {
- if ($fuzzy) {
- $where2[] = "a.tags like '%" . escape_string($value) . "%'";
- } else {
- $where2[] = "a.tags='" . escape_string($value) . "'";
- }
- }
- }
- }
-
- // 重置存储条件
- $where3 = array();
-
- // 只对有分页的列表有效
- if ($page) {
- // tags数据传值筛选
- if (! ! $get_tag = get('tag', 'vars')) {
- if ($fuzzy) {
- $where2[] = "a.tags like '%" . $get_tag . "%'";
- } else {
- $where2[] = "a.tags='" . $get_tag . "'";
- }
- }
-
- // 扩展字段数据筛选
- foreach ($_GET as $key => $value) {
- if (preg_match('/^ext_[\w\-]+$/', $key)) { // 其他字段不加入
- $where3[$key] = get($key, 'vars');
- }
- }
- }
-
- // 判断多图调节参数
- if ($ispics !== '') {
- if ($ispics) {
- $where3[] = "a.pics<>''";
- } else {
- $where3[] = "a.pics=''";
- }
- }
-
- // 判断缩略图调节参数
- if ($isico !== '') {
- if ($isico) {
- $where3[] = "a.ico<>''";
- } else {
- $where3[] = "a.ico=''";
- }
- }
-
- // 判断置顶调节参数
- if ($istop !== '') {
- if ($istop) {
- $where3[] = "a.istop=1";
- } else {
- $where3[] = "a.istop=0";
- }
- }
-
- // 判断推荐调节参数
- if ($isrecommend !== '') {
- if ($isrecommend) {
- $where3[] = "a.isrecommend=1";
- } else {
- $where3[] = "a.isrecommend=0";
- }
- }
-
- // 判断头条调节参数
- if ($isheadline !== '') {
- if ($isheadline) {
- $where3[] = "a.isheadline=1";
- } else {
- $where3[] = "a.isheadline=0";
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- if ($page) {
- if (isset($paging)) {
- error('请不要在一个页面使用多个具有分页的列表,您可将多余的使用page=0关闭分页!');
- } else {
- $paging = true;
- $data = $this->model->getLists($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield);
- }
- } else {
- $data = $this->model->getList($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield);
- }
-
- // 无数据直接替换
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- $one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析当前内容标签
- public function parserCurrentContentLabel($content, $sort, $data)
- {
- $pattern = '/\{content:([\w]+)(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 无数据直接替换并跳过
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
- $params = $this->parserParam($matches[2][$i]);
- $content = $this->parserContent($matches[1][$i], $matches[0][$i], $content, $data, $params, $sort);
- }
- }
-
- // 新增计数代码,非缓存方式,直接计数
- if ($this->config('tpl_html_cache')) {
- if (! isset($this->var['addvisits'])) {
- $visits = "<script src='" . Url::get('home/Do/visits/id/' . $data->id) . "' async='async'></script>";
- $content = preg_replace('/(<\/body>)/i', $visits . "\n$1", $content);
- $this->var['addvisits'] = true;
- }
- } else {
- $do = new DoModel();
- $do->addVisits($data->id);
- }
- return $content;
- }
-
- // 解析指定内容标签,单页支持使用scode调用
- public function parserSpecifyContentLabel($content)
- {
- $pattern = '/\{pboot:content(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:content\}/';
- $pattern2 = '/\[content:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $id = - 1;
- $scode = - 1;
-
- // 跳过未指定id和scode的列表
- if (array_key_exists('id', $params)) {
- $id = $params['id'];
- $data = $this->model->getContent(escape_string($id));
- } elseif (array_key_exists('scode', $params)) {
- $scode = $params['scode'];
- $data = $this->model->getAbout(escape_string($scode));
- } else {
- continue;
- }
-
- // 读取数据
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- $out_html = $this->parserContent($matches2[1][$j], $matches2[0][$j], $out_html, $data, $params, $scode);
- }
- // 执行替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析指定内容多图
- public function parserContentPicsLabel($content)
- {
- $pattern = '/\{pboot:pics(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:pics\}/';
- $pattern2 = '/\[pics:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $id = - 1;
- $field = "pics";
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 跳过未指定id的列表
- if (! array_key_exists('id', $params)) {
- continue;
- }
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'id':
- $id = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'field':
- $field = $value;
- break;
- }
- }
-
- // 读取内容多图
- if (! ! $rs = $this->model->getContentPics(escape_string($id), $field)) {
- $pics = explode(',', $rs->$field);
- $picstitle = explode(',', $rs->picstitle);
- } else {
- $pics = array();
- $picstitle = array();
- }
-
- // 无图直接替换为空并跳过
- if (! $pics) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($pics as $vkey => $value) { // 按查询图片条数循环
- $one_html = $matches[2][$i];
- if (! $value)
- continue;
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'src':
- if ($value) {
- if (! preg_match('/^http/', $value)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- case 'title':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, isset($picstitle[$vkey]) ? $picstitle[$vkey] : ''), $one_html);
- break;
- default:
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- }
- $key ++;
- $out_html .= $one_html;
- if (isset($num) && $key > $num) {
- unset($num);
- break;
- }
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析指定内容多选
- public function parserContentCheckboxLabel($content)
- {
- $pattern = '/\{pboot:checkbox(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:checkbox\}/';
- $pattern2 = '/\[checkbox:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $id = - 1;
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 跳过未指定id的调用
- if (! array_key_exists('id', $params)) {
- continue;
- }
-
- // 跳过未指定field的调用
- if (! array_key_exists('field', $params)) {
- continue;
- }
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'id':
- $id = $value;
- break;
- case 'field':
- $field = $value;
- break;
- }
- }
-
- // 读取内容多图
- if (! ! $checkboxs = $this->model->getContentCheckbox(escape_string($id), escape_string($field))) {
- $data = explode(',', $checkboxs);
- } else {
- $data = array();
- }
-
- // 无内容直接替换为空并跳过
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($data as $value) { // 按条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'text':
- $one_html = str_replace($this->adjustLabelData($params, $matches2[0][$j]), $value, $one_html);
- break;
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析内容tags
- public function parserContentTagsLabel($content)
- {
- $pattern = '/\{pboot:tags(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:tags\}/';
- $pattern2 = '/\[tags:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $id = ''; // 调取指定内容的tags
- $scode = ''; // 调取指定分类的tags
- $target = 'list'; // 标签跳转目标,可以是内容列表,也可以是独立tags.html页面
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'id':
- $id = $value;
- break;
- case 'scode':
- $scode = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'target':
- $target = $value;
- }
- }
-
- // 获取数据
- $data = array();
- if ($id) { // 获取单个内容的tags
- if (strpos($scode, ',') !== false) {
- error('模板中指定id输出tags时不允许scode指定多个栏目!');
- }
- if (! ! $rs = $this->model->getContentTags(escape_string($id))) {
- if ($rs->tags) {
- $tags = explode(',', $rs->tags);
- $scode = $scode ?: $rs->scode;
- $sort = $this->model->getSort($scode); // 获取栏目信息
- foreach ($tags as $key => $value) {
- $data[] = array(
- 'sort' => $sort,
- 'tags' => $value
- );
- }
- }
- }
- } elseif ($scode) { // 获取指定栏目的tags
- $scodes = explode(',', $scode); // 多个栏目是分别获取
- foreach ($scodes as $key => $value) {
- $sort = $this->model->getSort($value); // 获取栏目信息
- if (! ! $rs = $this->model->getSortTags($value)) {
- $tags = implode(',', $rs); // 把栏目tags串起来
- $tags = array_unique(explode(',', $tags)); // 再把所有tags组成数组并去重
- foreach ($tags as $key2 => $value2) {
- if (! in_array($value2, array_column($data, 'tags'))) { // 避免重复输出
- $data[] = array(
- 'sort' => $sort,
- 'tags' => $value2
- );
- }
- }
- }
- }
- } else {
- // 全部栏目时候强制标签页形式
- $target = 'tag';
- if (! ! $rs = $this->model->getSortTags('')) {
- $tags = implode(',', $rs); // 把栏目tags串起来
- $tags = array_unique(explode(',', $tags)); // 再把所有tags组成数组并去重
- foreach ($tags as $key2 => $value2) {
- if (! in_array($value2, array_column($data, 'tags'))) { // 避免重复输出
- $data[] = array(
- 'tags' => $value2
- );
- }
- }
- }
- }
-
- // 无内容直接替换为空并跳过
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($data as $value) { // 按条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'text':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value['tags']), $one_html);
- break;
- case 'link':
- $url_rule_type = $this->config('url_rule_type') ?: 3;
- if ($target == 'tag') {
- if ($url_rule_type == 3) {
- $link = Url::home('tag=' . urlencode($value['tags']), false);
- } else {
- $link = Url::home('tag/' . urlencode($value['tags']), false);
- }
- } else {
- $link = $this->parserLink($value['sort']->type, $value['sort']->urlname, 'list', $value['sort']->scode, $value['sort']->filename, '', '');
- if ($url_rule_type == 3) {
- $link = $link . '&tag=' . urlencode($value['tags']);
- } else {
- $link = $link . '?tag=' . urlencode($value['tags']);
- }
- }
-
- $one_html = str_replace($matches2[0][$j], $link, $one_html);
- break;
- }
- }
- $key ++;
- $out_html .= $one_html;
- if (isset($num) && $key > $num) {
- unset($num);
- break;
- }
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析幻灯片标签
- public function parserSlideLabel($content)
- {
- $pattern = '/\{pboot:slide(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:slide\}/';
- $pattern2 = '/\[slide:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $gid = 1;
- $num = 5;
- $start = 1;
-
- // 跳过未指定gid的标签
- if (! array_key_exists('gid', $params)) {
- continue;
- }
-
- // 分离参数
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'gid':
- $gid = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'start':
- $start = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if (! $data = $this->model->getSlides(escape_string($gid), escape_string($num), $start)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'src':
- if ($value->pic) {
- if (! preg_match('/^http/', $value->pic)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pic), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pic), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析友情链接标签
- public function parserLinkLabel($content)
- {
- $pattern = '/\{pboot:link(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:link\}/';
- $pattern2 = '/\[link:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $gid = 1;
- $num = 10;
- $start = 1;
-
- // 跳过未指定gid的标签
- if (! array_key_exists('gid', $params)) {
- continue;
- }
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'gid':
- $gid = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'start':
- $start = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if (! $data = $this->model->getLinks(escape_string($gid), escape_string($num), $start)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $key = 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'logo':
- if ($value->logo) {
- if (! preg_match('/^http/', $value->logo)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->logo), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->logo), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析留言板标签
- public function parserMessageLabel($content)
- {
- $pattern = '/\{pboot:message(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:message\}/';
- $pattern2 = '/\[message:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = $this->config('pagesize');
- $page = true;
- $start = 1;
- $lg = '';
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- case 'lg':
- $lg = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if (! $data = $this->model->getMessage(escape_string($num), $page, $start, $lg)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
-
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'ip':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, long2ip($value->user_ip)), $one_html);
- break;
- case 'os':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_os), $one_html);
- break;
- case 'bs':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_bs), $one_html);
- break;
- case 'askdate':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->create_time), $one_html);
- break;
- case 'replydate':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->update_time), $one_html);
- break;
- case 'headpic':
- if ($value->headpic) {
- if (! preg_match('/^http/', $value->headpic)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->headpic), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->headpic), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], SITE_DIR . '/apps/admin/view/default/images/logo.png', $one_html);
- }
- break;
- case 'nickname':
- if ($value->nickname) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->nickname), $one_html);
- } elseif (! $value->username) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, "匿名用户"), $one_html);
- }
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析表单数据标签
- public function parserFormLabel($content)
- {
- $pattern = '/\{pboot:formlist(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:formlist\}/';
- $pattern2 = '/\[form:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = $this->config('pagesize');
- $fcode = - 1;
- $page = true;
- $start = 1;
-
- // 跳过未指定fcode的标签
- if (! array_key_exists('fcode', $params)) {
- continue;
- }
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'fcode':
- $fcode = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 获取表名称
- if (! $table = $this->model->getFormTable(escape_string($fcode))) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 读取数据
- if (! $data = $this->model->getForm($table, escape_string($num), $page, $start)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'date':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->create_time), $one_html);
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], '', $one_html);
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析表单提交标签
- public function parserSubmitFormLabel($content)
- {
- $pattern = '/\{pboot:form(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[1][$i]);
- $fcode = '';
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'fcode':
- $fcode = $value;
- break;
- }
- }
- if (! $fcode) { // 无表单编码不解析
- continue;
- }
- $content = str_replace($matches[0][$i], Url::home('form/' . $fcode), $content);
- }
- }
- return $content;
- }
-
- // 解析文章评论
- public function parserCommentLabel($content)
- {
- $pattern = '/\{pboot:comment(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:comment\}/';
- $pattern2 = '/\[comment:([\w]+)(\s+[^]]+)?\]/';
- $pattern3 = '/\{pboot:commentsub(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:commentsub\}/';
- $pattern4 = '/\[commentsub:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = $this->config('pagesize');
- $page = true;
- $order = 'a.id desc';
- $start = 1;
-
- // 跳过未指定fcode的标签
- if (! array_key_exists('contentid', $params)) {
- continue;
- }
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- case 'contentid':
- $contentid = $value;
- break;
- case 'order':
- $order = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if (! $data = $this->model->getComment($contentid, 0, $num, $order, $page, $start)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
-
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- $one_html = $this->parserComment($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
- }
- $key ++;
-
- // 解析子评论
- if (preg_match_all($pattern3, $one_html, $matches3)) {
- $count3 = count($matches3[0]);
- for ($k = 0; $k < $count3; $k ++) {
-
- // 读取子评论数据,正序排列,最大100条
- if (! $data_sub = $this->model->getComment($contentid, $value->id, 100, 'a.id asc')) {
- $one_html = str_replace($matches3[0][$k], '', $one_html);
- continue;
- }
-
- // 匹配到子评论内部标签
- if (preg_match_all($pattern4, $matches3[2][$k], $matches4)) {
- $count4 = count($matches4[0]); // 循环内的内容标签数量
- } else {
- $count4 = 0;
- }
-
- $out_html_sub = '';
- $key_sub = 1;
- foreach ($data_sub as $value_sub) { // 按子查询数据条数循环
- $one_html_sub = $matches3[2][$k];
- for ($m = 0; $m < $count4; $m ++) { // 循环替换数据
- $params_sub = $this->parserParam($matches4[2][$m]);
- $one_html_sub = $this->parserComment($matches4[1][$m], $matches4[0][$m], $one_html_sub, $value_sub, $params_sub, $key_sub);
- }
- $key_sub ++;
- $out_html_sub .= $one_html_sub;
- }
- $one_html = str_replace($matches3[0][$k], $out_html_sub, $one_html);
- }
- }
-
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析我的评论
- public function parserMyCommentLabel($content)
- {
- $pattern = '/\{pboot:mycomment(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:mycomment\}/';
- $pattern2 = '/\[mycomment:([\w]+)(\s+[^]]+)?\]/';
-
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = $this->config('pagesize');
- $page = true;
- $order = 'a.id desc';
- $start = 1;
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- case 'order':
- $order = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if (! $data = $this->model->getMyComment($num, $order, $page, $start)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
-
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- $one_html = str_replace("[mycomment:delaction]", Url::home('comment/del', null, 'id=' . $value->id), $one_html);
- $one_html = $this->parserComment($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析评论内容
- private function parserComment($label, $search, $content, $data, $params, $key)
- {
- switch ($label) {
- case 'n':
- $content = str_replace($search, $this->adjustLabelData($params, $key) - 1, $content);
- break;
- case 'i':
- $content = str_replace($search, $this->adjustLabelData($params, $key), $content);
- break;
- case 'ip':
- $content = str_replace($search, $this->adjustLabelData($params, long2ip($data->user_ip)), $content);
- break;
- case 'os':
- $content = str_replace($search, $this->adjustLabelData($params, $data->user_os), $content);
- break;
- case 'bs':
- $content = str_replace($search, $this->adjustLabelData($params, $data->user_bs), $content);
- break;
- case 'date':
- $content = str_replace($search, $this->adjustLabelData($params, $data->create_time), $content);
- break;
- case 'headpic':
- if ($data->headpic) {
- if (! preg_match('/^http/', $data->headpic)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->headpic), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $data->headpic), $content);
- }
- } else {
- $content = str_replace($search, SITE_DIR . '/apps/admin/view/default/images/logo.png', $content);
- }
- break;
- case 'pheadpic':
- if ($data->pheadpic) {
- if (! preg_match('/^http/', $data->pheadpic)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->pheadpic), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $data->pheadpic), $content);
- }
- } else {
- $content = str_replace($search, SITE_DIR . '/apps/admin/view/default/images/logo.png', $content);
- }
- break;
- case 'replyaction':
- if ($data->pid) {
- $pid = $data->pid;
- } else {
- $pid = $data->id;
- }
- $content = str_replace($search, Url::home('comment/add', null, "contentid=" . $data->contentid . "&pid=" . $pid . "&puid=" . $data->uid), $content);
- break;
- case 'nickname':
- if ($data->nickname) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->nickname), $content);
- } elseif ($data->username) {
- $content = str_replace($search, $this->adjustLabelData($params, "匿名"), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, "游客"), $content);
- }
- break;
- case 'pnickname':
- if ($data->pnickname) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->pnickname), $content);
- } elseif ($data->pusername) {
- $content = str_replace($search, $this->adjustLabelData($params, "匿名"), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, "游客"), $content);
- }
- break;
- default:
- if (isset($data->{$label})) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->{$label}), $content);
- } else {
- $content = str_replace($search, '', $content);
- }
- }
- return $content;
- }
-
- // 解析评论子楼层
- public function parserCommentsubLabel($content)
- {
- $pattern = '/\{pboot:commentsub(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:commentsub\}/';
- $pattern2 = '/\[commentsub:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = $this->config('pagesize');
- $page = false;
- $order = 'a.id desc';
- $start = 1;
-
- // 跳过未指定fcode的标签
- if (! array_key_exists('contentid', $params)) {
- continue;
- }
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- case 'contentid':
- $contentid = $value;
- break;
- case 'order':
- $order = $value;
- break;
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if (! $data = $this->model->getComment($contentid, $num, $order, $page, $start)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
-
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'ip':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, long2ip($value->user_ip)), $one_html);
- break;
- case 'os':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_os), $one_html);
- break;
- case 'bs':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->user_bs), $one_html);
- break;
- case 'date':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->create_time), $one_html);
- break;
- case 'headpic':
- if ($value->headpic) {
- if (! preg_match('/^http/', $value->headpic)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->headpic), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->headpic), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], SITE_DIR . '/apps/admin/view/default/images/logo.png', $one_html);
- }
- break;
- case 'pheadpic':
- if ($value->pheadpic) {
- if (! preg_match('/^http/', $value->pheadpic)) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pheadpic), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pheadpic), $one_html);
- }
- } else {
- $one_html = str_replace($matches2[0][$j], SITE_DIR . '/apps/admin/view/default/images/logo.png', $one_html);
- }
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析自定义SQL循环
- public function parserSqlListLabel($content)
- {
- $pattern = '/\{pboot:sql(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:sql\}/';
- $pattern2 = '/\[sql:([\w]+)(\s+[^]]+)?\]/';
-
- if (preg_match_all($pattern, $content, $matches)) {
-
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- $num = 1000; // 最大读取1000条
- $sql = '';
- $kp = 0;
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'num':
- $num = $value;
- break;
- case 'sql':
- $sql = $value;
- break;
- case 'kp':
- $kp = $value;
- break;
- }
- }
-
- // 特殊表不允许输出
- if (preg_match('/ay_user|ay_member/i', $sql)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 判断是否有条数限制
- if ($num && ! preg_match('/limit/i', $sql)) {
- $sql .= " limit " . $num;
- }
-
- // 读取数据
- if (! $data = $this->model->all($sql)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
-
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- $a = 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- default:
- if (isset($value->{$matches2[1][$j]})) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->{$matches2[1][$j]}), $one_html);
- }
- }
-
- if($kp > 0){
- if($a%$kp == 0 && $a > 0){
- $one_html = $one_html."<br/>";
- }
- }
- }
- $a++;
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析二维码生成标签
- public function parserQrcodeLabel($content)
- {
- $pattern = '/\{pboot:qrcode(\s+[^}]+)?\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $params = $this->parserParam($matches[1][$i]);
- $string = '';
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'string':
- $string = $value;
- break;
- }
- }
- if (! $string) { // 无内容不解析
- continue;
- }
- $content = str_replace($matches[0][$i], '<img src="' . CORE_DIR . '/qrcode.php?string=' . urlencode($string) . '" class="qrcode" alt="二维码">', $content);
- }
- }
- return $content;
- }
-
- // 解析内容搜索结果标签
- public function parserSearchLabel($content)
- {
- $pattern = '/\{pboot:search(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:search\}/';
- $pattern2 = '/\[search:([\w]+)(\s+[^]]+)?\]/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- $field = request('field');
- if (! preg_match('/^[\w\|\s]+$/', $field)) {
- $field = '';
- }
- $keyword = request('keyword', 'vars');
- $scode = request('scode');
- $start = 1;
- if (! preg_match('/^[\w,\s]+$/', $scode)) {
- $scode = '';
- }
-
- for ($i = 0; $i < $count; $i ++) {
-
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $num = $this->config('pagesize'); // 未设置条数时使用默认15
- $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC'; // 默认排序
- $filter = ''; // 过滤
- $tags = ''; // tag标签
- $fuzzy = true; // 设置过滤、tag、筛选是否模糊匹配
- $ispics = ''; // 是否多图
- $isico = ''; // 是否缩略图
- $istop = ''; // 是否置顶
- $isrecommend = ''; // 是否推荐
- $isheadline = ''; // 是否头条
- $page = true; // 搜索默认分页
- $lfield = ''; // 查询字段限制
- $lg = get_lg(); // 查询语言限制,默认当前语言,可通过lg=* 来指定
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'field':
- $field = $value;
- break;
- case 'scode':
- $scode = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'order':
- switch ($value) {
- case 'id':
- $order = 'a.id DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC';
- break;
- case 'date':
- $order = 'a.date DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.id DESC';
- break;
- case 'sorting':
- $order = 'a.sorting ASC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.date DESC,a.id DESC';
- break;
- case 'istop':
- $order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'isrecommend':
- $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'isheadline':
- $order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'visits':
- case 'likes':
- case 'oppose':
- $order = $value . ' DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- break;
- case 'random': // 随机取数
- $db_type = get_db_type();
- if ($db_type == 'mysql') {
- $order = "RAND()";
- } elseif ($db_type == 'sqlite') {
- $order = "RANDOM()";
- }
- break;
- default:
- if ($value) {
- $orders = explode(',', $value);
- foreach ($orders as $k => $v) {
- if (strpos($v, 'ext_') === 0) {
- $orders[$k] = 'e.' . $v;
- } else {
- $orders[$k] = 'a.' . $v;
- }
- }
- $value = implode(',', $orders);
- $order = $value . ',a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
- }
- }
- break;
- case 'filter':
- $filter = $value;
- case 'fuzzy':
- $fuzzy = $value;
- break;
- case 'tags':
- $tags = $value;
- break;
- case 'ispics':
- $ispics = $value;
- break;
- case 'isico':
- $isico = $value;
- break;
- case 'istop':
- $istop = $value;
- break;
- case 'isrecommend':
- $isrecommend = $value;
- break;
- case 'isheadline':
- $isheadline = $value;
- break;
- case 'page':
- $page = $value;
- break;
- case 'start':
- $start = $value;
- break;
- case 'lfield':
- $lfield = $value;
- break;
- case 'lg':
- $lg = $value;
- break;
- }
- }
-
- if ($scode == '*') {
- $scode = '';
- }
-
- // filter数据筛选
- $where1 = array();
- if ($filter) {
- $filter = explode('|', $filter);
- if (count($filter) == 2) {
- $filter_arr = explode(',', $filter[1]);
- if ($filter[0] == 'title') {
- $filter[0] = 'a.title';
- }
- foreach ($filter_arr as $value) {
- if ($value) {
- if ($fuzzy) {
- $where1[] = $filter[0] . " like '%" . escape_string($value) . "%'";
- } else {
- $where1[] = $filter[0] . "='" . escape_string($value) . "'";
- }
- }
- }
- }
- }
-
- // tags数据筛选
- $where2 = array();
- if ($tags) {
- $tags_arr = explode(',', $tags);
- foreach ($tags_arr as $value) {
- if ($value) {
- if ($fuzzy) {
- $where2[] = "a.tags like '%" . escape_string($value) . "%'";
- } else {
- $where2[] = "a.tags='" . escape_string($value) . "'";
- }
- }
- }
- }
-
- // 存储搜索条件,条件为“并列”关系,由于为模糊匹配,条件为空时意味着“任意”
- $where3 = array();
-
- // 采取keyword方式
- if ($keyword) {
- if (strpos($field, '|')) { // 匹配多字段的关键字搜索
- $field = explode('|', $field);
- foreach ($field as $value) {
- if ($value == 'title') {
- $value = 'a.title';
- }
- if ($fuzzy) {
- $like = " like '%" . $keyword . "%'"; // 前面已经转义过
- } else {
- $like = " like '" . $keyword . "'"; // 前面已经转义过
- }
- if (isset($where3[0])) {
- $where3[0] .= ' OR ' . $value . $like;
- } else {
- $where3[0] = $value . $like;
- }
- }
- if (count($field) > 1) {
- $where3[0] = '(' . $where3[0] . ')';
- }
- } else { // 匹配单一字段的关键字搜索
- if ($field) {
- if ($field == 'title') {
- $field = 'a.title';
- }
- $where3[$field] = $keyword;
- } else {
- $where3['a.title'] = $keyword;
- }
- }
- }
-
- // 数据接收
- if ($_POST) {
- $receive = $_POST;
- } else {
- $receive = $_GET;
- }
-
- foreach ($receive as $key => $value) {
- if (! ! $value = request($key, 'vars')) {
- if ($key == 'title') {
- $key = 'a.title';
- }
- if (preg_match('/^[\w\-\.]+$/', $key)) { // 带有违规字符时不带入查询
- $where3[$key] = $value;
- }
- }
- }
-
- // 去除特殊键值
- unset($where3['keyword']);
- unset($where3['field']);
- unset($where3['scode']);
- unset($where3['page']);
- unset($where3['from']);
- unset($where3['isappinstalled']);
- unset($where3['tdsourcetag']);
- unset($where3['x']);
- unset($where3['y']);
- unset($where3['searchtpl']);
- unset($where3['p']);
- unset($where3['s']);
-
- // 无任何条件不显示内容
- if (! $where3) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 判断多图调节参数
- if ($ispics !== '') {
- if ($ispics) {
- $where3[] = "a.pics<>''";
- } else {
- $where3[] = "a.pics=''";
- }
- }
-
- // 判断缩略图调节参数
- if ($isico !== '') {
- if ($isico) {
- $where3[] = "a.ico<>''";
- } else {
- $where3[] = "a.ico=''";
- }
- }
-
- // 判断置顶调节参数
- if ($istop !== '') {
- if ($istop) {
- $where3[] = "a.istop=1";
- } else {
- $where3[] = "a.istop=0";
- }
- }
-
- // 判断推荐调节参数
- if ($isrecommend !== '') {
- if ($isrecommend) {
- $where3[] = "a.isrecommend=1";
- } else {
- $where3[] = "a.isrecommend=0";
- }
- }
-
- // 判断头条调节参数
- if ($isheadline !== '') {
- if ($isheadline) {
- $where3[] = "a.isheadline=1";
- } else {
- $where3[] = "a.isheadline=0";
- }
- }
-
- // 起始数校验
- if (! is_numeric($start) || $start < 1) {
- $start = 1;
- }
-
- // 读取数据
- if ($page) {
- if (isset($paging)) {
- error('请不要在一个页面使用多个具有分页的列表,您可将多余的使用page=0关闭分页!');
- } else {
- $paging = true;
- $data = $this->model->getLists($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield, $lg);
- }
- } else {
- $data = $this->model->getList($scode, $num, $order, $where1, $where2, $where3, $fuzzy, $start, $lfield, $lg);
- }
-
- // 无数据直接替换
- if (! $data) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
-
- $out_html = '';
- $pagenum = defined('PAGE') ? PAGE : 1;
- $key = ($pagenum - 1) * $num + 1;
- foreach ($data as $value) { // 按查询数据条数循环
- $one_html = $matches[2][$i];
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- $one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
- }
- $key ++;
- $out_html .= $one_html;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析列表分页标签
- public function parserPageLabel($content)
- {
- $pattern = '/\{page:([\w]+)\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- switch ($matches[1][$i]) {
- case 'bar':
- $content = str_replace($matches[0][$i], $this->getVar('pagebar'), $content);
- break;
- case 'current':
- $content = str_replace($matches[0][$i], $this->getVar('pagecurrent') ?: 0, $content);
- break;
- case 'count':
- $content = str_replace($matches[0][$i], $this->getVar('pagecount') ?: 0, $content);
- break;
- case 'rows':
- $content = str_replace($matches[0][$i], $this->getVar('pagerows') ?: 0, $content);
- break;
- case 'index':
- $content = str_replace($matches[0][$i], $this->getVar('pageindex'), $content);
- break;
- case 'pre':
- $content = str_replace($matches[0][$i], $this->getVar('pagepre'), $content);
- break;
- case 'next':
- $content = str_replace($matches[0][$i], $this->getVar('pagenext'), $content);
- break;
- case 'last':
- $content = str_replace($matches[0][$i], $this->getVar('pagelast'), $content);
- break;
- case 'status':
- $content = str_replace($matches[0][$i], $this->getVar('pagestatus'), $content);
- break;
- case 'numbar':
- $content = str_replace($matches[0][$i], $this->getVar('pagenumbar'), $content);
- break;
- case 'selectbar':
- $content = str_replace($matches[0][$i], $this->getVar('pageselectbar'), $content);
- break;
- }
- }
- }
- return $content;
- }
-
- // 解析循环标签
- public function parserLoopLabel($content)
- {
- $pattern = '/\{pboot:loop(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:loop\}/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
- $start = 1;
- $end = $this->config('pagesize');
-
- if (! self::checkLabelLevel($params)) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
-
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'start':
- $start = $value;
- break;
- case 'end':
- $end = $value;
- break;
- }
- }
-
- $out_html = '';
- $key = 1;
- for ($n = $start; $n <= $end; $n ++) {
- $one_html = str_replace('[loop:n]', $key - 1, $matches[2][$i]);
- $one_html = str_replace('[loop:i]', $key, $one_html);
- $one_html = str_replace('[loop:index]', $n, $one_html);
- $out_html .= $one_html;
- $key ++;
- }
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
-
- // 解析IF条件标签
- public function parserIfLabel($content)
- {
- $pattern = '/\{pboot:if\(([^}^\$]+)\)\}([\s\S]*?)\{\/pboot:if\}/';
- $pattern2 = '/pboot:([0-9])+if/';
- if (preg_match_all($pattern, $content, $matches)) {
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- $flag = '';
- $out_html = '';
- $danger = false;
-
- $white_fun = array(
- 'date'
- );
-
- // 还原可能包含的保留内容,避免判断失效
- $matches[1][$i] = $this->restorePreLabel($matches[1][$i]);
-
- // 带有函数的条件语句进行安全校验
- if (preg_match_all('/([\w]+)([\x00-\x1F\x7F\/\*\<\>\%\w\s\\\\]+)?\(/i', $matches[1][$i], $matches2)) {
- foreach ($matches2[1] as $value) {
- if (function_exists(trim($value)) && ! in_array($value, $white_fun)) {
- $danger = true;
- break;
- }
- }
-
- foreach ($matches2[2] as $value) {
- if (function_exists(trim($value)) && ! in_array($value, $white_fun)) {
- $danger = true;
- break;
- }
- }
- }
-
- // 过滤特殊字符串
-
- 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])) {
- $danger = true;
- }
-
- // 如果有危险函数,则不解析该IF
- if ($danger) {
- continue;
- }
- //if标签解析
- $flag = symbol($matches[1][$i]);
- if (preg_match('/^([\s\S]*)\{else\}([\s\S]*)$/', $matches[2][$i], $matches2)) { // 判断是否存在else
- switch ($flag) {
- case 'if': // 条件为真
- if (isset($matches2[1])) {
- $out_html = $matches2[1];
- }
- break;
- case 'else': // 条件为假
- if (isset($matches2[2])) {
- $out_html = $matches2[2];
- }
- break;
- }
- } elseif ($flag == 'if') {
- $out_html = $matches[2][$i];
- }
-
- // 无限极嵌套解析
- if (preg_match($pattern2, $out_html, $matches3)) {
- $out_html = str_replace('pboot:' . $matches3[1] . 'if', 'pboot:if', $out_html);
- $out_html = str_replace('{' . $matches3[1] . 'else}', '{else}', $out_html);
- $out_html = $this->parserIfLabel($out_html);
- }
-
- // 执行替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- // var_dump(111);die;
- return $content;
- }
-
- // 调整标签数据
- protected function adjustLabelData($params, $data, $label = null, $savelabel = false)
- {
- if (! $data)
- return $data;
-
- // 图片缩放功能
- if (isset($params['maxwidth']) || isset($params['maxheight'])) {
- $maxwidth = isset($params['maxwidth']) ? $params['maxwidth'] : null;
- $maxheight = isset($params['maxheight']) ? $params['maxheight'] : null;
- $max_src_file = ROOT_PATH . $data;
- $max_out_file = RUN_PATH . '/image/mw' . $maxwidth . '_mh' . $maxheight . '_' . basename($data);
- if (! file_exists($max_out_file) && file_exists($max_src_file)) {
- if (resize_img($max_src_file, $max_out_file, $maxwidth, $maxheight)) {
- $data = str_replace(ROOT_PATH, '', $max_out_file);
- }
- } elseif (file_exists($max_out_file) && file_exists($max_src_file)) {
- $data = str_replace(ROOT_PATH, '', $max_out_file);
- }
- }
-
- // 图片固定大小
- if (isset($params['width']) || isset($params['height'])) {
- $width = isset($params['width']) ? $params['width'] : null;
- $height = isset($params['height']) ? $params['height'] : null;
- $src_file = ROOT_PATH . $data;
- $out_file = RUN_PATH . '/image/w' . $width . '_h' . $height . '_' . basename($data);
- if (! file_exists($out_file) && file_exists($src_file)) {
- if (cut_img($src_file, $out_file, $width, $height)) {
- $data = str_replace(ROOT_PATH, '', $out_file);
- }
- } elseif (file_exists($out_file) && file_exists($src_file)) {
- $data = str_replace(ROOT_PATH, '', $out_file);
- }
- }
-
- // 检查标签权限
- if (! self::checkLabelLevel($params)) {
- $data = '';
- }
-
- if (is_array($params) && $params) {
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'style': // 时间样式
- if ($params['style'] && $date = strtotime($data)) {
- $data = date($params['style'], $date);
- }
- break;
- case 'len': // 长度截取
- if ($params['len'] && is_string($data)) {
- if (mb_strlen($data, 'utf-8') > $params['len']) {
- if (isset($params['more'])) {
- $more = $params['more'];
- } else {
- $more = '···';
- }
- $data = mb_substr($data, 0, $params['len'], 'utf-8') . $more;
- }
- }
- break;
- case 'lencn': // 以中文占位长度方式截取,英文算半个
- if ($params['lencn'] && is_string($data)) {
- if (strlen_both($data) > $params['lencn']) {
- if (isset($params['more'])) {
- $more = $params['more'];
- } else {
- $more = '···';
- }
- $data = substr_both($data, 0, $params['lencn']) . $more;
- }
- }
- break;
- case 'drophtml': // 去除html标签
- if ($params['drophtml']) {
- $data = strip_tags($data);
- }
- break;
- case 'dropblank': // 清理特殊空白
- if ($params['dropblank']) {
- $data = clear_html_blank($data);
- }
- break;
- case 'decode': // 解码或转义字符
- if ($params['decode']) {
- $data = decode_string($data);
- } else {
- $data = escape_string($data);
- }
- break;
- case 'substr': // 截取字符串
- if ($params['substr'] && is_string($data)) {
- $arr = explode(',', $params['substr']);
- if (count($arr) == 2 && $arr[1]) {
- $data = mb_substr($data, $arr[0] - 1, $arr[1], 'utf-8');
- } else {
- $data = mb_substr($data, $arr[0] - 1);
- }
- }
- break;
- case 'unit': // bytes转换未其它单位
- switch ($params['unit']) {
- case 'KB':
- case 'kb':
- $data = $data / 1024;
- break;
- case 'MB':
- case 'mb':
- $data = $data / (1024 * 1024);
- break;
- case 'GB':
- case 'gb':
- $data = $data / (1024 * 1024 * 1024);
- break;
- case 'TB':
- case 'tb':
- $data = $data / (1024 * 1024 * 1024 * 1024);
- break;
- case 'PB':
- case 'pb':
- $data = $data / (1024 * 1024 * 1024 * 1024 * 1024);
- break;
- case 'EB':
- case 'eb':
- $data = $data / (1024 * 1024 * 1024 * 1024 * 1024 * 1024);
- break;
- }
- break;
- case 'decimal': // 小数点
- if ($params['decimal']) {
- $data = number_format($data, $params['decimal']);
- }
- break;
- case 'operate': // 实现列表页标签+-*/%运算功能
- if (preg_match('/^([\+\-\*\/\%])([0-9\.]+)$/', $params['operate'], $mathes)) {
- if (! is_numeric($data)) {
- $data = 0;
- }
- switch ($mathes[1]) {
- case '+':
- $data = $data + $mathes[2];
- break;
- case '-':
- $data = $data - $mathes[2];
- break;
- case '*':
- $data = $data * $mathes[2];
- break;
- case '/':
- $data = $data / $mathes[2];
- break;
- case '%':
- $data = $data % $mathes[2];
- break;
- }
- }
- break;
- case 'mark':
- if ($label && $reqdata = request($label, 'vars') ?: request('keyword', 'vars')) {
- $data = preg_replace('/(' . $reqdata . ')/i', '<span style="color:red">$1</span>', $data);
- }
- break;
- }
- }
- }
-
- // 对标签内容中含有标签是否保留不解析
- if ($savelabel && $data) {
- $this->pre[] = $data; // 保存内容避免解析
- end($this->pre); // 指向最后一个元素
- $data = '#pre:' . key($this->pre) . '#';
- }
- return $data;
- }
-
- // 解析调节参数
- protected function parserParam($string, $striptags = true)
- {
- if (! $string = trim($string))
- return array();
- $string = preg_replace('/\s+/', ' ', $string); // 多空格处理
- if ($striptags) {
- $string = strip_tags($string);
- }
-
- $param = array();
- if (preg_match_all('/([\w]+)[\s]?=[\s]?([\"]([^\"]+)?[\"]|[\']([^\']+)?[\']|([^\s]+))/i', $string, $matches)) {
- foreach ($matches[1] as $key => $value) {
- $param[$value] = $matches[3][$key] ?: $matches[4][$key] ?: $matches[5][$key];
- }
- }
- return $param;
- }
-
- // 解析列表标签
- protected function parserList($label, $search, $content, $data, $params, $key)
- {
- switch ($label) {
- case 'n':
- $content = str_replace($search, $this->adjustLabelData($params, $key) - 1, $content);
- break;
- case 'i':
- $content = str_replace($search, $this->adjustLabelData($params, $key), $content);
- break;
- case 'link':
- if ($data->outlink) { // 外链
- $content = str_replace($search, $data->outlink, $content);
- } else {
- if ($data->type == 1) {
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'about', $data->scode, $data->sortfilename, '', ''), $content);
- } else {
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename), $content);
- }
- }
- break;
- case 'sortlink':
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->scode, $data->sortfilename, '', ''), $content);
- break;
- case 'subsortlink':
- if ($data->subscode) {
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->subscode, $data->subfilename, '', ''), $content);
- } else {
- $content = str_replace($search, 'javascript:;', $content);
- }
- break;
- case 'sortname':
- if ($data->sortname) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->sortname, $label), $content);
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'subsortname':
- if ($data->subsortname) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->subsortname, $label), $content);
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'ico':
- if ($data->ico) {
- if (! preg_match('/^http/', $data->ico)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->ico), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $data->ico), $content);
- }
- } elseif (preg_match('/<img\s+.*?src=\s?[\'|\"](.*?(\.gif|\.jpg|\.png|\.jpeg))[\'|\"].*?[\/]?>/i', $data->content, $srcs) && isset($srcs[1])) {
- $content = str_replace($search, $this->adjustLabelData($params, $srcs[1]), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
- }
- break;
- case 'isico':
- if ($data->ico) {
- $content = str_replace($search, 1, $content);
- } else {
- $content = str_replace($search, 0, $content);
- }
- break;
- case 'ispics':
- if ($data->pics) {
- $content = str_replace($search, 1, $content);
- } else {
- $content = str_replace($search, 0, $content);
- }
- break;
- case 'enclosure':
- if ($data->enclosure) {
- if (! preg_match('/^http/', $data->enclosure)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->enclosure), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $data->enclosure), $content);
- }
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'enclosuresize':
- if ($data->enclosure && file_exists(ROOT_PATH . $data->enclosure)) {
- $content = str_replace($search, $this->adjustLabelData($params, filesize(ROOT_PATH . $data->enclosure)), $content);
- } else {
- $content = str_replace($search, 0, $content);
- }
- case 'likeslink':
- $content = str_replace($search, Url::get('home/Do/likes/id/' . $data->id), $content);
- break;
- case 'opposelink':
- $content = str_replace($search, Url::get('home/Do/oppose/id/' . $data->id), $content);
- break;
- case 'content':
- $content = str_replace($search, $this->adjustLabelData($params, $data->content, $label, true), $content); // 占位替换
- break;
- case 'keywords':
- $content = str_replace($search, $this->adjustLabelData($params, $data->keywords, $label, true), $content); // 占位替换
- break;
- case 'description':
- $content = str_replace($search, $this->adjustLabelData($params, $data->description, $label, true), $content); // 占位替换
- break;
- default:
- if (isset($data->$label)) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->$label, $label), $content);
- } elseif (strpos($label, 'ext_') === 0) {
- $content = str_replace($search, '', $content);
- }
- }
- return $content;
- }
-
- // 解析内容详情标签
- protected function parserContent($label, $search, $content, $data, $params, $sort)
- {
- switch ($label) {
- case 'link':
- if ($data->type == 1) {
- if ($data->sortoutlink) {
- $content = str_replace($search, $data->sortoutlink, $content);
- } else {
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'about', $data->scode, $data->sortfilename, '', ''), $content);
- }
- } else {
- if ($data->outlink) {
- $content = str_replace($search, $data->outlink, $content);
- } else {
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename), $content);
- }
- }
- break;
- case 'sortlink':
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->scode, $data->sortfilename, '', ''), $content);
- break;
- case 'subsortlink':
- if ($data->subscode) {
- $content = str_replace($search, $this->parserLink($data->type, $data->urlname, 'list', $data->subscode, $data->subfilename, '', ''), $content);
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'sortname':
- if ($data->sortname) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->sortname), $content);
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'subsortname':
- if ($data->subsortname) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->subsortname), $content);
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'ico':
- if ($data->ico) {
- if (! preg_match('/^http/', $data->ico)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->ico), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $data->ico), $content);
- }
- } elseif (preg_match('/<img\s+.*?src=\s?[\'|\"](.*?(\.gif|\.jpg|\.png|\.jpeg))[\'|\"].*?[\/]?>/i', $data->content, $srcs) && isset($srcs[1])) {
- $content = str_replace($search, $this->adjustLabelData($params, $srcs[1]), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
- }
- break;
- case 'isico':
- if ($data->ico) {
- $content = str_replace($search, 1, $content);
- } else {
- $content = str_replace($search, 0, $content);
- }
- break;
- case 'ispics':
- if ($data->pics) {
- $content = str_replace($search, 1, $content);
- } else {
- $content = str_replace($search, 0, $content);
- }
- break;
- case 'enclosure':
- if ($data->enclosure) {
- if (! preg_match('/^http/', $data->enclosure)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $data->enclosure), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $data->enclosure), $content);
- }
- } else {
- $content = str_replace($search, '', $content);
- }
- break;
- case 'enclosuresize':
- if ($data->enclosure && file_exists(ROOT_PATH . $data->enclosure)) {
- $content = str_replace($search, $this->adjustLabelData($params, filesize(ROOT_PATH . $data->enclosure)), $content);
- } else {
- $content = str_replace($search, 0, $content);
- }
- break;
- case 'likeslink':
- $content = str_replace($search, Url::get('home/Do/likes/id/' . $data->id), $content);
- break;
- case 'opposelink':
- $content = str_replace($search, Url::get('home/Do/oppose/id/' . $data->id), $content);
- break;
- case 'precontent':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
- $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);
- } else {
- if (isset($params['notext'])) {
- $content = str_replace($search, $params['notext'], $content);
- } else {
- $content = str_replace($search, '没有了!', $content);
- }
- }
- break;
- case 'prelink':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
- $content = str_replace($search, $this->parserLink($pre->type, $pre->urlname, 'content', $pre->scode, $pre->sortfilename, $pre->id, $pre->filename), $content);
- } else {
- $content = str_replace($search, 'javascript:;', $content);
- }
- break;
- case 'pretitle':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
- $content = str_replace($search, $this->adjustLabelData($params, $pre->title), $content);
- } else {
- if (isset($params['notext'])) {
- $content = str_replace($search, $params['notext'], $content);
- } else {
- $content = str_replace($search, '没有了!', $content);
- }
- }
- break;
- case 'preico':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $pre = $this->model->getContentPre($sort->scode, $data->id)) {
- if (! preg_match('/^http/', $pre->ico)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $pre->ico), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $pre->ico), $content);
- }
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
- }
- break;
- case 'nextcontent':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
- $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);
- } else {
- if (isset($params['notext'])) {
- $content = str_replace($search, $params['notext'], $content);
- } else {
- $content = str_replace($search, '没有了!', $content);
- }
- }
- break;
- case 'nextlink':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
- $content = str_replace($search, $this->parserLink($next->type, $next->urlname, 'content', $next->scode, $next->sortfilename, $next->id, $next->filename), $content);
- } else {
- $content = str_replace($search, 'javascript:;', $content);
- }
- break;
- case 'nexttitle':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
- $content = str_replace($search, $this->adjustLabelData($params, $next->title), $content);
- } else {
- if (isset($params['notext'])) {
- $content = str_replace($search, $params['notext'], $content);
- } else {
- $content = str_replace($search, '没有了!', $content);
- }
- }
- break;
- case 'nextico':
- if ($data->type != 2) // 非列表内容页不解析
- break;
- if (! ! $next = $this->model->getContentNext($sort->scode, $data->id)) {
- if (! preg_match('/^http/', $next->ico)) {
- $content = str_replace($search, $this->adjustLabelData($params, SITE_DIR . $next->ico), $content);
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, $next->ico), $content);
- }
- } else {
- $content = str_replace($search, $this->adjustLabelData($params, STATIC_DIR . '/images/nopic.png'), $content);
- }
- break;
- case 'content':
- // 内链处理
- if (! ! $tags = $this->model->getTags()) {
- // 将A链接保护起来,alt、titel保护起来
- $rega = "/(<a .*?>.*?<\/a>)|(alt=.*?>)|(title=.*?>)/i";
- preg_match_all($rega, $data->content, $matches1);
- foreach ($matches1[0] as $key => $value) {
- $data->content = str_replace($value, '#rega:' . $key . '#', $data->content);
- }
-
- // 去除包含关系的短tags,实现长关键字优先
- foreach ($tags as $key => $value) {
- foreach ($tags as $key2 => $value2) {
- if (strpos($value2->name, $value->name) !== false && $key != $key2) {
- unset($tags[$key]);
- }
- }
- }
-
- // 执行内链替换
- foreach ($tags as $value) {
- $data->content = preg_replace('/' . $value->name . '/', '<a href="' . $value->link . '">' . $value->name . '</a>', $data->content, $this->config('content_tags_replace_num') ?: 3);
- }
-
- // 还原保护的内容
- $pattern = '/\#rega:([0-9]+)\#/';
- if (preg_match_all($pattern, $data->content, $matches2)) {
- $count = count($matches2[0]);
- for ($i = 0; $i < $count; $i ++) {
- $data->content = str_replace($matches2[0][$i], $matches1[0][$matches2[1][$i]], $data->content);
- }
- }
- }
- $content = str_replace($search, $this->adjustLabelData($params, $data->content, null, true), $content);
- break;
- case 'keywords': // 如果内容关键字为空,则自动使用全局关键字
- if ($data->keywords) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->keywords, null, true), $content);
- } else {
- $content = str_replace($search, '{pboot:sitekeywords}', $content);
- }
- break;
- case 'description': // 如果内容描述为空,则自动使用全局描述
- if ($data->description) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->description, null, true), $content);
- } else {
- $content = str_replace($search, '{pboot:sitedescription}', $content);
- }
- break;
- default:
- if (isset($data->$label)) {
- $content = str_replace($search, $this->adjustLabelData($params, $data->$label), $content);
- } elseif (strpos($label, 'ext_') === 0) {
- $content = str_replace($search, '', $content);
- }
- }
- return $content;
- }
-
- //解析城市列表标签
- // 解析分站列表标签
- public function parserCityListLabel($content)
- {
- $pattern = '/\{pboot:city(\s+[^}]+)?\}([\s\S]*?)\{\/pboot:city\}/';
- $pattern2 = '/\[city:([\w]+)(\s+[^]]+)?\]/';
- $pattern3 = '/pboot:([0-9])+city/';
- if (preg_match_all($pattern, $content, $matches)) {
- $data = $this->model->getCityListTree();
- $count = count($matches[0]);
- for ($i = 0; $i < $count; $i ++) {
- // 无数据时直接替换整体标签为空
- if (! $data['tree']) {
- $content = str_replace($matches[0][$i], '', $content);
- continue;
- }
- // 获取调节参数
- $params = $this->parserParam($matches[1][$i]);
-
- $pid = 0;
- $num = 0;
- $istop = 0;
- $islevel = 0;
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'pid':
- $pid = $value;
- break;
- case 'num':
- $num = $value;
- break;
- case 'istop':
- $istop = $value;
- break;
- case 'islevel':
- $islevel = $value;
- break;
- }
- }
-
- $out_data = array();
- // 置顶
- if( $istop ){
- foreach( $data['tree'] as $row ){
- if( $row['istop']==1 ){
- array_push($out_data,$row);
- }
- foreach( $row['son'] as $son ){
- if( $son['istop']==1 ){
- array_push($out_data,$son);
- }
- }
- }
- }elseif( $islevel ){ //显示层级
- $citys = $this->config('citys');
- $pid = 0;
- if( cookie('city')!=='' ){
- $cur_city = $citys[cookie('city')];
- if( $cur_city['pid'] == 0 ){
- $pid = $cur_city['id'];
- }else{
- $pid = $cur_city['pid'];
- }
- }
- foreach( $data['tree'] as $row ){
- if( $row['id']==$pid ){
- foreach( $row['son'] as $son ){
- array_push($out_data,$son);
- }
- }
- }
- }else{
- if ($pid) { // 非顶级栏目起始,调用子栏目
- $parent_arr = explode(',', $pid);
- foreach ($parent_arr as $vp) {
- if (isset($data['tree'][trim($vp)]['son'])) {
- $out_data = array_merge($out_data, $data['tree'][trim($vp)]['son']);
- }
- }
- } else { // 顶级栏目起始
- $out_data = $data['top'];
- }
- }
- // 读取指定数量
- if ($num) {
- $out_data = array_slice($out_data, 0, $num);
- }
-
- // 匹配到内部标签
- if (preg_match_all($pattern2, $matches[2][$i], $matches2)) {
- $count2 = count($matches2[0]); // 循环内的内容标签数量
- } else {
- $count2 = 0;
- }
- $out_html = '';
- $key = 1;
- foreach ($out_data as $value) { // 按查询的数据条数循环
- $one_html = $matches[2][$i];
- if ($count2) {
- for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
- $params = $this->parserParam($matches2[2][$j]);
- switch ($matches2[1][$j]) {
- case 'n':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key) - 1, $one_html);
- break;
- case 'i':
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
- break;
- case 'home':
- $one_html = str_replace($matches2[0][$j], create_city_url($value['etitle'], $value['isurl'], false), $one_html);
- break;
- case 'link':
- $one_html = str_replace($matches2[0][$j], create_city_url($value['etitle'], $value['isurl'], true), $one_html);
- break;
- case 'soncount':
- if (isset($data['tree'][$value['id']]['son'])) {
- $one_html = str_replace($matches2[0][$j], count($data['tree'][$value['id']]['son']), $one_html);
- } else {
- $one_html = str_replace($matches2[0][$j], 0, $one_html);
- }
- break;
- default:
- if (isset($value[$matches2[1][$j]])) {
- $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value[$matches2[1][$j]]), $one_html);
- }
- }
- }
- }
- $key ++;
- $out_html .= $one_html;
- }
-
- // 无限极嵌套解析
- if (preg_match($pattern3, $out_html, $matches3)) {
- $out_html = str_replace('pboot:' . $matches3[1] . 'city', 'pboot:city', $out_html);
- $out_html = str_replace('[' . $matches3[1] . 'city:', '[city:', $out_html);
- $out_html = $this->parserCityListLabel($out_html);
- }
-
- // 执行内容替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
- }
- return $content;
- }
- // end 城市分站解析
-
- // 替换页面内容关键词
- protected function parserReplaceKeyword($content)
- {
- $keys = $this->config('content_keyword_replace');
- $keys_arr = explode(',', strip_tags($keys));
- foreach ($keys_arr as $key => $value) {
- $content = str_replace($value, str_repeat('*', mb_strlen($value)), $content);
- }
- return $content;
- }
-
- // 解析生成内容链接
- public function parserLink($type, $urlname, $pagetype, $scode, $sortfilename, $id = '', $contentfilename = '')
- {
- $url_break_char = $this->config('url_break_char') ?: '_';
- $url_rule_sort_suffix = $this->config('url_rule_sort_suffix') ? true : null;
- $url_rule_content_path = $this->config('url_rule_content_path') ? true : false;
-
- if ($type == 1 || $pagetype == 'about') {
- $urlname = $urlname ?: 'about';
- if ($sortfilename) {
- $link = Url::home($sortfilename);
- } else {
- $link = Url::home($urlname . $url_break_char . $scode);
- }
- } else {
- $urlname = $urlname ?: 'list';
- if ($pagetype == 'list') {
- if ($sortfilename) {
- $link = Url::home($sortfilename);
- } else {
- $link = Url::home($urlname . $url_break_char . $scode);
- }
- } elseif ($pagetype == 'content') {
- if ($url_rule_content_path) {
- if ($contentfilename) {
- $link = Url::home($contentfilename, true);
- } else {
- $link = Url::home($id, true);
- }
- } else {
- if ($sortfilename && $contentfilename) {
- $link = Url::home($sortfilename . '/' . $contentfilename, true);
- } elseif ($sortfilename) {
- $link = Url::home($sortfilename . '/' . $id, true);
- } elseif ($contentfilename) {
- $link = Url::home($urlname . $url_break_char . $scode . '/' . $contentfilename, true);
- } else {
- $link = Url::home($urlname . $url_break_char . $scode . '/' . $id, true);
- }
- }
- } else {
- $link = 'javascript:;';
- }
- }
- return $link;
- }
-
- // 检查标签权限
- protected function checkLabelLevel($params)
- {
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'showgcode': // 指定等级显示,支持多个逗号隔开
- $showgcode = explode(',', $params['showgcode']);
- if (! in_array(session('pboot_gcode'), $showgcode)) {
- return false;
- }
- break;
- case 'showucode': // 指定用户显示,支持多个逗号隔开
- $showucode = explode(',', $params['showucode']);
- if (! in_array(session('pboot_ucode'), $showucode)) {
- return false;
- }
- break;
- case 'hidegcode': // 指定等级隐藏,支持多个逗号隔开
- $hidegcode = explode(',', $params['hidegcode']);
- if (in_array(session('pboot_gcode'), $hidegcode)) {
- return false;
- }
- break;
- case 'hideucode': // 指定用户隐藏,支持多个逗号隔开
- $hideucode = explode(',', $params['hideucode']);
- if (in_array(session('pboot_ucode'), $hideucode)) {
- return false;
- }
- break;
- case 'showgcodelt': // 等级小于显示
- if ($params['showgcodelt'] <= session('pboot_gcode')) {
- return false;
- }
- break;
- case 'showgcodegt': // 等级大于显示
- if ($params['showgcodegt'] >= session('pboot_gcode')) {
- return false;
- }
- break;
- case 'showgcodele': // 等级小于等于显示
- if ($params['showgcodele'] < session('pboot_gcode')) {
- return false;
- }
- break;
- case 'showgcodege': // 等级大于等于显示
- if ($params['showgcodege'] > session('pboot_gcode')) {
- return false;
- }
- break;
- case 'hidegcodelt': // 等级小于隐藏
- if ($params['hidegcodelt'] > session('pboot_gcode')) {
- return false;
- }
- break;
- case 'hidegcodegt': // 等级大于隐藏
- if ($params['hidegcodegt'] < session('pboot_gcode')) {
- return false;
- }
- break;
- case 'hidegcodele': // 等级小于等于隐藏
- if ($params['hidegcodele'] >= session('pboot_gcode')) {
- return false;
- }
- break;
- case 'hidegcodege': // 等级大于等于隐藏
- if ($params['hidegcodege'] <= session('pboot_gcode')) {
- return false;
- }
- break;
- case 'showlogin': // 登录后显示
- if ($params['showlogin'] && ! session('pboot_uid')) {
- return false;
- }
- break;
- case 'hidelogin': // 登录后隐藏
- if ($params['hidelogin'] && session('pboot_uid')) {
- return false;
- }
- break;
- }
- }
- return true;
- }
- }
|