123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416 |
- <?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/';
-
- $content = str_replace('{xx}', '[xx]', $content);
-
- 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[0][$i] = str_replace('[xx]', '{xx}', $matches[0][$i]);
-
- // 还原可能包含的保留内容,避免判断失效
- $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('[xx]', '{xx}', $content);
- // 执行替换
- $content = str_replace($matches[0][$i], $out_html, $content);
- }
-
- if((int)$count === 0){
- $content = str_replace('[xx]', '{xx}', $content);
- }
- }else{
- $content = str_replace('[xx]', '{xx}', $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;
- }
- }
|