htmly.php 212 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814
  1. <?php
  2. if (!defined('HTMLY')) die('HTMLy');
  3. use PragmaRX\Google2FA\Google2FA;
  4. // Load the configuration file
  5. config('source', $config_file);
  6. // Get search query. Redir to /search/
  7. get_search_query();
  8. // Load the language file
  9. get_language();
  10. // Set the timezone
  11. if (config('timezone')) {
  12. date_default_timezone_set(config('timezone'));
  13. } else {
  14. date_default_timezone_set('Asia/Jakarta');
  15. }
  16. // Publish scheduled post
  17. publish_scheduled();
  18. // Load theme settings
  19. theme_settings();
  20. // The front page of the blog
  21. get('/index', function () {
  22. if (!login()) {
  23. file_cache($_SERVER['REQUEST_URI']);
  24. }
  25. $vroot = rtrim(config('views.root'), '/');
  26. $lt = $vroot . '/layout--front.html.php';
  27. if (file_exists($lt)) {
  28. $layout = 'layout--front';
  29. } else {
  30. $layout = '';
  31. }
  32. if (config('static.frontpage') == 'true') {
  33. $front = get_frontpage();
  34. $pv = $vroot . '/static--front.html.php';
  35. if (file_exists($pv)) {
  36. $pview = 'static--front';
  37. } else {
  38. $pview = 'static';
  39. }
  40. render($pview, array(
  41. 'title' => generate_title('is_front', null),
  42. 'description' => safe_html(strip_tags(blog_description())),
  43. 'canonical' => site_url(),
  44. 'metatags' => generate_meta(null, null),
  45. 'bodyclass' => 'in-front',
  46. 'breadcrumb' => '',
  47. 'p' => $front,
  48. 'static' => $front,
  49. 'type' => 'is_frontpage',
  50. 'is_front' => true
  51. ), $layout);
  52. } else {
  53. $page = from($_GET, 'page');
  54. $page = $page ? (int)$page : 1;
  55. $perpage = config('posts.perpage');
  56. $posts = get_posts(null, $page, $perpage);
  57. $total = count(get_blog_posts());
  58. $pv = $vroot . '/main--front.html.php';
  59. if (file_exists($pv)) {
  60. $pview = 'main--front';
  61. } else {
  62. $pview = 'main';
  63. }
  64. $tblog = new stdClass;
  65. $tblog->title = blog_tagline();
  66. $tblog->url = site_url();
  67. $tblog->count = count(get_blog_posts());
  68. $tblog->description = blog_description();
  69. $tblog->body = $tblog->description;
  70. $tblog->rss = site_url() . 'feed/rss';
  71. $tblog->slug = site_path();
  72. if (empty($posts) || $page < 1) {
  73. // a non-existing page
  74. render('no-posts', array(
  75. 'title' => generate_title('is_front', null),
  76. 'description' => safe_html(strip_tags(blog_description())),
  77. 'canonical' => site_url(),
  78. 'metatags' => generate_meta(null, null),
  79. 'breadcrumb' => '',
  80. 'bodyclass' => 'no-posts',
  81. 'type' => 'is_frontpage',
  82. 'is_front' => true
  83. ), $layout);
  84. die;
  85. }
  86. if ($page > 1) {
  87. $CanonicalPageNum = '?page=' . $page;
  88. } else {
  89. $CanonicalPageNum = NULL;
  90. }
  91. render($pview, array(
  92. 'title' => generate_title('is_front', null),
  93. 'description' => safe_html(strip_tags(blog_description())),
  94. 'canonical' => site_url() . $CanonicalPageNum,
  95. 'metatags' => generate_meta(null, null),
  96. 'page' => $page,
  97. 'posts' => $posts,
  98. 'taxonomy' => $tblog,
  99. 'bodyclass' => 'in-front',
  100. 'breadcrumb' => '',
  101. 'pagination' => has_pagination($total, $perpage, $page),
  102. 'type' => 'is_frontpage',
  103. 'is_front' => true,
  104. 'is_taxonomy' => true
  105. ), $layout);
  106. }
  107. });
  108. // Get submitted login data
  109. post('/login', function () {
  110. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  111. $captcha = config('login.protect.system');
  112. if (is_null($captcha) || $captcha === 'disabled') {
  113. $captcha = true;
  114. } elseif ($captcha === 'cloudflare') {
  115. $captcha = isTurnstile(from($_REQUEST, 'cf-turnstile-response'));
  116. } elseif ($captcha === 'google') {
  117. $captcha = isCaptcha(from($_REQUEST, 'g-recaptcha-response'));
  118. }
  119. $user = from($_REQUEST, 'user');
  120. $pass = from($_REQUEST, 'password');
  121. $mfa_secret = user('mfa_secret', $user);
  122. if ($proper && $captcha && !empty($user) && !empty($pass)) {
  123. if (!is_null($mfa_secret) && $mfa_secret !== "disabled" && config('mfa.state') === 'true') {
  124. config('views.root', 'system/admin/views');
  125. render('login-mfa', array(
  126. 'title' => generate_title('is_default', i18n('Login')),
  127. 'description' => i18n('Login') . ' ' . blog_title(),
  128. 'canonical' => site_url(),
  129. 'metatags' => generate_meta(null, null),
  130. 'username' => $user,
  131. 'password' => $pass,
  132. 'type' => 'is_login',
  133. 'is_login' => true,
  134. 'bodyclass' => 'in-login',
  135. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  136. ));
  137. } else {
  138. session($user, $pass);
  139. $log = session($user, $pass);
  140. if (!empty($log)) {
  141. config('views.root', 'system/admin/views');
  142. render('login', array(
  143. 'title' => generate_title('is_default', i18n('Login')),
  144. 'description' => i18n('Login') . ' ' . blog_title(),
  145. 'canonical' => site_url(),
  146. 'metatags' => generate_meta(null, null),
  147. 'error' => '<ul>' . $log . '</ul>',
  148. 'type' => 'is_login',
  149. 'is_login' => true,
  150. 'bodyclass' => 'in-login',
  151. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  152. ));
  153. }
  154. }
  155. } else {
  156. $message['error'] = '';
  157. if (empty($user)) {
  158. $message['error'] .= '<li class="alert alert-danger">' . i18n('User_Error') . '</li>';
  159. }
  160. if (empty($pass)) {
  161. $message['error'] .= '<li class="alert alert-danger">' . i18n('Pass_Error') . '</li>';
  162. }
  163. if (!$proper) {
  164. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  165. }
  166. if (!$captcha) {
  167. $message['error'] .= '<li class="alert alert-danger">' . i18n('Captcha_Error') . '</li>';
  168. }
  169. config('views.root', 'system/admin/views');
  170. render('login', array(
  171. 'title' => generate_title('is_default', i18n('Login')),
  172. 'description' => i18n('Login') . ' ' . blog_title(),
  173. 'canonical' => site_url(),
  174. 'metatags' => generate_meta(null, null),
  175. 'error' => '<ul>' . $message['error'] . '</ul>',
  176. 'username' => $user,
  177. 'password' => $pass,
  178. 'type' => 'is_login',
  179. 'is_login' => true,
  180. 'bodyclass' => 'in-login',
  181. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  182. ));
  183. }
  184. });
  185. // Verify MFA
  186. post('/login-mfa', function () {
  187. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  188. $user = $_SESSION["mfa_uid"];
  189. $pass = $_SESSION["mfa_pwd"];
  190. $mfacode = from($_REQUEST, 'mfacode');
  191. $mfa_secret = user('mfa_secret', $user);
  192. $google2fa = new Google2FA();
  193. if ($proper && $google2fa->verifyKey($mfa_secret, $mfacode, '1')) {
  194. session($user, $pass);
  195. $log = session($user, $pass);
  196. if (!empty($log)) {
  197. config('views.root', 'system/admin/views');
  198. render('login', array(
  199. 'title' => generate_title('is_default', i18n('Login')),
  200. 'description' => i18n('Login') . ' ' . blog_title(),
  201. 'canonical' => site_url(),
  202. 'metatags' => generate_meta(null, null),
  203. 'error' => '<ul>' . $log . '</ul>',
  204. 'type' => 'is_login',
  205. 'is_login' => true,
  206. 'bodyclass' => 'in-login',
  207. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  208. ));
  209. }
  210. } else {
  211. $message['error'] = '';
  212. if (!$proper) {
  213. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  214. } else {
  215. $message['error'] .= '<li class="alert alert-danger">' . i18n('MFA_Error') . '</li>';
  216. }
  217. config('views.root', 'system/admin/views');
  218. render('login-mfa', array(
  219. 'title' => generate_title('is_default', i18n('Login')),
  220. 'description' => i18n('Login') . ' ' . blog_title(),
  221. 'canonical' => site_url(),
  222. 'metatags' => generate_meta(null, null),
  223. 'error' => '<ul>' . $message['error'] . '</ul>',
  224. 'username' => $user,
  225. 'password' => $pass,
  226. 'type' => 'is_login',
  227. 'is_login' => true,
  228. 'bodyclass' => 'in-login',
  229. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  230. ));
  231. }
  232. });
  233. // Show the author page
  234. get('/author/:name', function ($name) {
  235. if (!login()) {
  236. file_cache($_SERVER['REQUEST_URI']);
  237. }
  238. $page = from($_GET, 'page');
  239. $page = $page ? (int)$page : 1;
  240. $perpage = config('profile.perpage');
  241. $total = '';
  242. $posts = get_profile_posts($name, $page, $perpage);
  243. if (!empty($posts)) {
  244. $total = $posts[1];
  245. $posts = $posts[0];
  246. }
  247. $author = get_author($name);
  248. if (isset($author[0])) {
  249. $author = $author[0];
  250. } else {
  251. $userConfig = 'config/users/' . $name . '.ini';
  252. if (file_exists($userConfig) || !empty($posts)) {
  253. $author = default_profile(safe_html(strip_tags($name)));
  254. } else {
  255. not_found();
  256. }
  257. }
  258. $vroot = rtrim(config('views.root'), '/');
  259. $lt = $vroot . '/layout--profile--' . strtolower($name) . '.html.php';
  260. $ls = $vroot . '/layout--profile.html.php';
  261. if (file_exists($lt)) {
  262. $layout = 'layout--profile--' . strtolower($name);
  263. } else if (file_exists($ls)) {
  264. $layout = 'layout--profile';
  265. } else {
  266. $layout = '';
  267. }
  268. $pv = $vroot . '/profile--'. strtolower($name) .'.html.php';
  269. if (file_exists($pv)) {
  270. $pview = 'profile--'. strtolower($name);
  271. } else {
  272. $pview = 'profile';
  273. }
  274. if (empty($posts) || $page < 1) {
  275. render($pview, array(
  276. 'title' => generate_title('is_profile', $author),
  277. 'description' => $author->description,
  278. 'canonical' => $author->url,
  279. 'metatags' => generate_meta('is_profile', $author),
  280. 'page' => $page,
  281. 'posts' => null,
  282. 'about' => $author->about,
  283. 'name' => $author->name,
  284. 'author' => $author,
  285. 'type' => 'is_profile',
  286. 'bodyclass' => 'in-profile author-' . $name,
  287. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Profile_for') . ' ' . $author->name,
  288. 'pagination' => has_pagination($total, $perpage, $page),
  289. 'is_profile' => true
  290. ), $layout);
  291. die;
  292. }
  293. if ($page > 1) {
  294. $CanonicalPageNum = '?page=' . $page;
  295. } else {
  296. $CanonicalPageNum = NULL;
  297. }
  298. render($pview, array(
  299. 'title' => generate_title('is_profile', $author),
  300. 'description' => $author->description,
  301. 'canonical' => $author->url . $CanonicalPageNum,
  302. 'metatags' => generate_meta('is_profile', $author),
  303. 'page' => $page,
  304. 'posts' => $posts,
  305. 'about' => $author->about,
  306. 'name' => $author->name,
  307. 'author' => $author,
  308. 'type' => 'is_profile',
  309. 'bodyclass' => 'in-profile author-' . $name,
  310. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Profile_for') . ' ' . $author->name,
  311. 'pagination' => has_pagination($total, $perpage, $page),
  312. 'is_profile' => true
  313. ), $layout);
  314. });
  315. // Show the RSS feed
  316. get('/author/:name/feed', function ($name) {
  317. header('Content-Type: application/rss+xml');
  318. $posts = array();
  319. $posts = get_profile_posts($name, 1, config('rss.count'));
  320. if ($posts) {
  321. $posts = $posts[0];
  322. }
  323. $author = get_author($name);
  324. if (isset($author[0])) {
  325. $author = $author[0];
  326. } else {
  327. $userConfig = 'config/users/' . $name . '.ini';
  328. if (file_exists($userConfig) || !empty($posts)) {
  329. $author = default_profile(safe_html(strip_tags($name)));
  330. } else {
  331. not_found();
  332. }
  333. }
  334. // Show an RSS feed
  335. echo generate_rss($posts, $author);
  336. });
  337. // Edit the profile
  338. get('/edit/profile', function () {
  339. if (login()) {
  340. config('views.root', 'system/admin/views');
  341. render('edit-page', array(
  342. 'title' => generate_title('is_default', i18n('Edit_profile')),
  343. 'description' => safe_html(strip_tags(blog_description())),
  344. 'canonical' => site_url(),
  345. 'metatags' => generate_meta(null, null),
  346. 'type' => 'is_profile',
  347. 'is_admin' => true,
  348. 'bodyclass' => 'edit-profile',
  349. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('Edit_profile'),
  350. ));
  351. } else {
  352. $login = site_url() . 'login';
  353. header("location: $login");
  354. }
  355. });
  356. // Get submitted data from edit profile page
  357. post('/edit/profile', function () {
  358. if(!login()) {
  359. $login = site_url() . 'login';
  360. header("location: $login");
  361. }
  362. $field = array();
  363. $aField = array();
  364. $field_file = 'content/data/field/profile.json';
  365. if (file_exists($field_file)) {
  366. $aField = json_decode(file_get_contents($field_file, true));
  367. }
  368. if(!empty($aField)) {
  369. foreach ($aField as $af) {
  370. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  371. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  372. } else {
  373. $field[$af->name] = from($_REQUEST, $af->name);
  374. }
  375. }
  376. }
  377. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  378. $user = $_SESSION[site_url()]['user'];
  379. $title = from($_REQUEST, 'title');
  380. $description = from($_REQUEST, 'description');
  381. $image = from($_REQUEST, 'image');
  382. $content = from($_REQUEST, 'content');
  383. if ($proper && !empty($title) && !empty($content)) {
  384. edit_profile($title, $content, $user, $description, $image, $field);
  385. } else {
  386. $message['error'] = '';
  387. if (empty($title)) {
  388. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  389. }
  390. if (empty($content)) {
  391. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  392. }
  393. if (!$proper) {
  394. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  395. }
  396. config('views.root', 'system/admin/views');
  397. render('edit-page', array(
  398. 'title' => generate_title('is_default', 'Edit profile'),
  399. 'description' => safe_html(strip_tags(blog_description())),
  400. 'canonical' => site_url(),
  401. 'metatags' => generate_meta(null, null),
  402. 'error' => '<ul>' . $message['error'] . '</ul>',
  403. 'postTitle' => $title,
  404. 'postContent' => $content,
  405. 'postImage' => $image,
  406. 'type' => 'is_profile',
  407. 'is_admin' => true,
  408. 'bodyclass' => 'edit-profile',
  409. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit profile'
  410. ));
  411. }
  412. });
  413. get('/edit/password', function () {
  414. if (login()) {
  415. config('views.root', 'system/admin/views');
  416. render('edit-password', array(
  417. 'title' => generate_title('is_default', i18n('change_password')),
  418. 'description' => safe_html(strip_tags(blog_description())),
  419. 'canonical' => site_url(),
  420. 'metatags' => generate_meta(null, null),
  421. 'type' => 'is_profile',
  422. 'is_admin' => true,
  423. 'bodyclass' => 'edit-password',
  424. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('change_password'),
  425. ));
  426. } else {
  427. $login = site_url() . 'login';
  428. header("location: $login");
  429. }
  430. });
  431. post('/edit/password', function() {
  432. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  433. if (login() && $proper) {
  434. $username = from($_REQUEST, 'username');
  435. $new_password = from($_REQUEST, 'password');
  436. $user = $_SESSION[site_url()]['user'];
  437. $role = user('role', $user);
  438. $mfa = user('mfa_secret', $user);
  439. $old_password = user('password', $username);
  440. if ($user === $username) {
  441. $file = 'config/users/' . $user . '.ini';
  442. if (file_exists($file)) {
  443. if (!empty($new_password)) {
  444. update_user($user, $new_password, $role, $mfa);
  445. }
  446. }
  447. $redir = site_url() . 'admin';
  448. header("location: $redir");
  449. } else {
  450. $redir = site_url();
  451. header("location: $redir");
  452. }
  453. } else {
  454. $login = site_url() . 'login';
  455. header("location: $login");
  456. }
  457. });
  458. get('/edit/mfa', function () {
  459. if (login()) {
  460. config('views.root', 'system/admin/views');
  461. render('edit-mfa', array(
  462. 'title' => generate_title('is_default', i18n('config_mfa')),
  463. 'description' => safe_html(strip_tags(blog_description())),
  464. 'canonical' => site_url(),
  465. 'metatags' => generate_meta(null, null),
  466. 'type' => 'is_profile',
  467. 'is_admin' => true,
  468. 'bodyclass' => 'edit-mfa',
  469. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('config_mfa'),
  470. ));
  471. } else {
  472. $login = site_url() . 'login';
  473. header("location: $login");
  474. }
  475. });
  476. post('/edit/mfa', function() {
  477. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  478. if (login() && $proper) {
  479. $username = from($_REQUEST, 'username');
  480. $mfa_secret = from($_REQUEST, 'mfa_secret');
  481. $mfacode = from($_REQUEST, 'mfacode');
  482. $user = $_SESSION[site_url()]['user'];
  483. $role = user('role', $user);
  484. $old_password = user('password', $user);
  485. $password = from($_REQUEST, 'password');
  486. $message['error'] = '';
  487. if ($user === $username) {
  488. if (!is_null($mfa_secret) && $mfa_secret !== "disabled") {
  489. $google2fa = new Google2FA();
  490. if ($google2fa->verifyKey($mfa_secret, $mfacode)) {
  491. if (password_verify($password, $old_password)) {
  492. if (!empty($mfa_secret)) {
  493. update_user($user, $password, $role, $mfa_secret);
  494. }
  495. } else {
  496. $message['error'] .= '<li class="alert alert-danger">' . i18n('Pass_Error') . '</li>';
  497. }
  498. } else {
  499. $message['error'] .= '<li class="alert alert-danger">' . i18n('MFA_Error') . '</li>';
  500. }
  501. config('views.root', 'system/admin/views');
  502. render('edit-mfa', array(
  503. 'title' => generate_title('is_default', i18n('config_mfa')),
  504. 'description' => safe_html(strip_tags(blog_description())),
  505. 'canonical' => site_url(),
  506. 'metatags' => generate_meta(null, null),
  507. 'error' => '<ul>' . $message['error'] . '</ul>',
  508. 'type' => 'is_profile',
  509. 'is_admin' => true,
  510. 'bodyclass' => 'edit-mfa',
  511. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('config_mfa'),
  512. ));
  513. } else {
  514. if (password_verify($password, $old_password)) {
  515. update_user($user, $password, $role, 'disabled');
  516. } else {
  517. $message['error'] .= '<li class="alert alert-danger">' . i18n('Pass_Error') . '</li>';
  518. }
  519. config('views.root', 'system/admin/views');
  520. render('edit-mfa', array(
  521. 'title' => generate_title('is_default', i18n('config_mfa')),
  522. 'description' => safe_html(strip_tags(blog_description())),
  523. 'canonical' => site_url(),
  524. 'metatags' => generate_meta(null, null),
  525. 'error' => '<ul>' . $message['error'] . '</ul>',
  526. 'type' => 'is_profile',
  527. 'is_admin' => true,
  528. 'bodyclass' => 'edit-mfa',
  529. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('config_mfa'),
  530. ));
  531. }
  532. } else {
  533. $redir = site_url();
  534. header("location: $redir");
  535. }
  536. } else {
  537. $login = site_url() . 'login';
  538. header("location: $login");
  539. }
  540. });
  541. // Edit the frontpage
  542. get('/edit/frontpage', function () {
  543. $user = $_SESSION[site_url()]['user'];
  544. $role = user('role', $user);
  545. if (login()) {
  546. config('views.root', 'system/admin/views');
  547. if ($role === 'editor' || $role === 'admin') {
  548. render('edit-page', array(
  549. 'title' => generate_title('is_default', 'Edit frontpage'),
  550. 'description' => safe_html(strip_tags(blog_description())),
  551. 'canonical' => site_url(),
  552. 'metatags' => generate_meta(null, null),
  553. 'type' => 'is_frontpage',
  554. 'is_admin' => true,
  555. 'bodyclass' => 'edit-frontpage',
  556. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit frontpage',
  557. ));
  558. } else {
  559. render('denied', array(
  560. 'title' => generate_title('is_default', i18n('Denied')),
  561. 'description' => safe_html(strip_tags(blog_description())),
  562. 'canonical' => site_url(),
  563. 'metatags' => generate_meta(null, null),
  564. 'type' => 'is_frontpage',
  565. 'is_admin' => true,
  566. 'bodyclass' => 'denied',
  567. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  568. ));
  569. }
  570. } else {
  571. $login = site_url() . 'login';
  572. header("location: $login");
  573. }
  574. });
  575. // Get submitted data from edit frontpage
  576. post('/edit/frontpage', function () {
  577. if(!login()) {
  578. $login = site_url() . 'login';
  579. header("location: $login");
  580. }
  581. $field = array();
  582. $aField = array();
  583. $field_file = 'content/data/field/page.json';
  584. if (file_exists($field_file)) {
  585. $aField = json_decode(file_get_contents($field_file, true));
  586. }
  587. if(!empty($aField)) {
  588. foreach ($aField as $af) {
  589. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  590. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  591. } else {
  592. $field[$af->name] = from($_REQUEST, $af->name);
  593. }
  594. }
  595. }
  596. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  597. $user = $_SESSION[site_url()]['user'];
  598. $role = user('role', $user);
  599. $title = from($_REQUEST, 'title');
  600. $content = from($_REQUEST, 'content');
  601. if ($role === 'editor' || $role === 'admin') {
  602. if ($proper && !empty($title) && !empty($content)) {
  603. edit_frontpage($title, $content, $field);
  604. } else {
  605. $message['error'] = '';
  606. if (empty($title)) {
  607. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  608. }
  609. if (empty($content)) {
  610. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  611. }
  612. if (!$proper) {
  613. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  614. }
  615. config('views.root', 'system/admin/views');
  616. render('edit-page', array(
  617. 'title' => generate_title('is_default', 'Edit frontpage'),
  618. 'description' => safe_html(strip_tags(blog_description())),
  619. 'canonical' => site_url(),
  620. 'metatags' => generate_meta(null, null),
  621. 'error' => '<ul>' . $message['error'] . '</ul>',
  622. 'postTitle' => $title,
  623. 'postContent' => $content,
  624. 'type' => 'is_frontpage',
  625. 'is_admin' => true,
  626. 'bodyclass' => 'edit-frontpage',
  627. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit frontpage'
  628. ));
  629. }
  630. } else {
  631. $redir = site_url();
  632. header("location: $redir");
  633. }
  634. });
  635. // Edit the frontpage
  636. get('/front/edit', function () {
  637. if (login()) {
  638. $edit = site_url() . 'edit/frontpage';
  639. header("location: $edit");
  640. } else {
  641. $login = site_url() . 'login';
  642. header("location: $login");
  643. }
  644. });
  645. // Show the "Add content" page
  646. get('/add/content', function () {
  647. if (isset($_GET['type'])) {
  648. $req = _h($_GET['type']);
  649. } else {
  650. $req = 'post';
  651. }
  652. $type = 'is_' . $req;
  653. if (login()) {
  654. config('views.root', 'system/admin/views');
  655. render('add-content', array(
  656. 'title' => generate_title('is_default', i18n('Add_new_post')),
  657. 'description' => safe_html(strip_tags(blog_description())),
  658. 'canonical' => site_url(),
  659. 'metatags' => generate_meta(null, null),
  660. 'type' => $type,
  661. 'is_admin' => true,
  662. 'bodyclass' => 'add-content',
  663. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_new_post')
  664. ));
  665. } else {
  666. $login = site_url() . 'login';
  667. header("location: $login");
  668. }
  669. });
  670. // Submitted add post data
  671. post('/add/content', function () {
  672. if(!login()) {
  673. $login = site_url() . 'login';
  674. header("location: $login");
  675. }
  676. $field = array();
  677. $aField = array();
  678. $field_file = 'content/data/field/post.json';
  679. if (file_exists($field_file)) {
  680. $aField = json_decode(file_get_contents($field_file, true));
  681. }
  682. if(!empty($aField)) {
  683. foreach ($aField as $af) {
  684. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  685. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  686. } else {
  687. $field[$af->name] = from($_REQUEST, $af->name);
  688. }
  689. }
  690. }
  691. // The "AI was used" flag. Unchecked means empty, so no tag is written.
  692. $field['ai'] = from($_REQUEST, 'ai') ? 'yes' : '';
  693. $is_image = from($_REQUEST, 'is_image');
  694. $is_audio = from($_REQUEST, 'is_audio');
  695. $is_video = from($_REQUEST, 'is_video');
  696. $is_quote = from($_REQUEST, 'is_quote');
  697. $is_link = from($_REQUEST, 'is_link');
  698. $is_post = from($_REQUEST, 'is_post');
  699. if (!empty($is_image)) {
  700. $type = 'is_image';
  701. } elseif (!empty($is_video)) {
  702. $type = 'is_video';
  703. } elseif (!empty($is_link)) {
  704. $type = 'is_link';
  705. } elseif (!empty($is_quote)) {
  706. $type = 'is_quote';
  707. } elseif (!empty($is_audio)) {
  708. $type = 'is_audio';
  709. } elseif (!empty($is_post)) {
  710. $type = 'is_post';
  711. }
  712. $link = from($_REQUEST, 'link');
  713. $image = from($_REQUEST, 'image');
  714. $audio = from($_REQUEST, 'audio');
  715. $video = from($_REQUEST, 'video');
  716. $quote = from($_REQUEST, 'quote');
  717. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  718. $title = from($_REQUEST, 'title');
  719. $tag = from($_REQUEST, 'tag');
  720. $url = from($_REQUEST, 'url');
  721. $content = from($_REQUEST, 'content');
  722. $description = from($_REQUEST, 'description');
  723. $user = $_SESSION[site_url()]['user'];
  724. $draft = from($_REQUEST, 'draft');
  725. $category = from($_REQUEST, 'category');
  726. $date = from($_REQUEST, 'date');
  727. $time = from($_REQUEST, 'time');
  728. $dateTime = null;
  729. if ($date !== null && $time !== null) {
  730. $dateTime = $date . ' ' . $time;
  731. }
  732. if (empty($url)) {
  733. $url = $title;
  734. }
  735. if (empty($is_post) && empty($is_image) && empty($is_video) && empty($is_audio) && empty($is_link) && empty($is_quote)) {
  736. $add = site_url() . 'admin/content';
  737. header("location: $add");
  738. }
  739. if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
  740. add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime, null, null, $field);
  741. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
  742. add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime, null, null, $field);
  743. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
  744. add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime, null, null, $field);
  745. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
  746. add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime, null, null, $field);
  747. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
  748. add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime, null, null, $field);
  749. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
  750. add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime, null, null, $field);
  751. } else {
  752. $message['error'] = '';
  753. if (empty($title)) {
  754. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  755. }
  756. if (empty($tag)) {
  757. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_tag') . '</li>';
  758. }
  759. if (empty($content)) {
  760. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  761. }
  762. if (!$proper) {
  763. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  764. }
  765. if (!empty($is_image)) {
  766. if (empty($image)) {
  767. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_image') . '</li>';
  768. }
  769. } elseif (!empty($is_video)) {
  770. if (empty($video)) {
  771. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_video') . '</li>';
  772. }
  773. } elseif (!empty($is_link)) {
  774. if (empty($link)) {
  775. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_link') . '</li>';
  776. }
  777. } elseif (!empty($is_quote)) {
  778. if (empty($quote)) {
  779. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_quote') . '</li>';
  780. }
  781. } elseif (!empty($is_audio)) {
  782. if (empty($audio)) {
  783. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_audio') . '</li>';
  784. }
  785. }
  786. config('views.root', 'system/admin/views');
  787. render('add-content', array(
  788. 'title' => generate_title('is_default', i18n('Add_content')),
  789. 'description' => safe_html(strip_tags(blog_description())),
  790. 'canonical' => site_url(),
  791. 'metatags' => generate_meta(null, null),
  792. 'error' => '<ul>' . $message['error'] . '</ul>',
  793. 'postTitle' => $title,
  794. 'postImage' => $image,
  795. 'postVideo' => $video,
  796. 'postLink' => $link,
  797. 'postQuote' => $quote,
  798. 'postAudio' => $audio,
  799. 'postTag' => $tag,
  800. 'postUrl' => $url,
  801. 'postContent' => $content,
  802. 'type' => $type,
  803. 'is_admin' => true,
  804. 'bodyclass' => 'add-content',
  805. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_content')
  806. ));
  807. }
  808. });
  809. // Show the static add page
  810. get('/add/page', function () {
  811. $user = $_SESSION[site_url()]['user'];
  812. $role = user('role', $user);
  813. if (login()) {
  814. config('views.root', 'system/admin/views');
  815. if ($role === 'editor' || $role === 'admin') {
  816. render('add-page', array(
  817. 'title' => generate_title('is_default', i18n('Add_new_page')),
  818. 'description' => safe_html(strip_tags(blog_description())),
  819. 'canonical' => site_url(),
  820. 'metatags' => generate_meta(null, null),
  821. 'type' => 'is_page',
  822. 'is_admin' => true,
  823. 'bodyclass' => 'add-page',
  824. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_new_page')
  825. ));
  826. } else {
  827. render('denied', array(
  828. 'title' => generate_title('is_default', i18n('Denied')),
  829. 'description' => safe_html(strip_tags(blog_description())),
  830. 'canonical' => site_url(),
  831. 'metatags' => generate_meta(null, null),
  832. 'type' => 'is_page',
  833. 'is_admin' => true,
  834. 'bodyclass' => 'denied',
  835. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  836. ));
  837. }
  838. } else {
  839. $login = site_url() . 'login';
  840. header("location: $login");
  841. }
  842. });
  843. // Submitted static add page data
  844. post('/add/page', function () {
  845. if(!login()) {
  846. $login = site_url() . 'login';
  847. header("location: $login");
  848. }
  849. $field = array();
  850. $aField = array();
  851. $field_file = 'content/data/field/page.json';
  852. if (file_exists($field_file)) {
  853. $aField = json_decode(file_get_contents($field_file, true));
  854. }
  855. if(!empty($aField)) {
  856. foreach ($aField as $af) {
  857. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  858. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  859. } else {
  860. $field[$af->name] = from($_REQUEST, $af->name);
  861. }
  862. }
  863. }
  864. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  865. $title = from($_REQUEST, 'title');
  866. $url = from($_REQUEST, 'url');
  867. $content = from($_REQUEST, 'content');
  868. $description = from($_REQUEST, 'description');
  869. $draft = from($_REQUEST, 'draft');
  870. $user = $_SESSION[site_url()]['user'];
  871. $role = user('role', $user);
  872. if (empty($url)) {
  873. $url = $title;
  874. }
  875. if ($role === 'editor' || $role === 'admin') {
  876. if ($proper && !empty($title) && !empty($content) && login()) {
  877. add_page($title, $url, $content, $draft, $description, null, null, $field);
  878. } else {
  879. $message['error'] = '';
  880. if (empty($title)) {
  881. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  882. }
  883. if (empty($content)) {
  884. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  885. }
  886. if (!$proper) {
  887. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  888. }
  889. config('views.root', 'system/admin/views');
  890. render('add-page', array(
  891. 'title' => generate_title('is_default', i18n('Add_new_page')),
  892. 'description' => safe_html(strip_tags(blog_description())),
  893. 'canonical' => site_url(),
  894. 'metatags' => generate_meta(null, null),
  895. 'error' => '<ul>' . $message['error'] . '</ul>',
  896. 'postTitle' => $title,
  897. 'postUrl' => $url,
  898. 'postContent' => $content,
  899. 'type' => 'is_page',
  900. 'is_admin' => true,
  901. 'bodyclass' => 'add-page',
  902. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_new_page')
  903. ));
  904. }
  905. } else {
  906. $redir = site_url();
  907. header("location: $redir");
  908. }
  909. });
  910. // Autosave
  911. post('/admin/autosave', function () {
  912. if (login()) {
  913. $title = $_REQUEST['title'];
  914. $url = $_REQUEST['url'];
  915. $content = $_REQUEST['content'];
  916. $description = $_REQUEST['description'];
  917. $draft = 'draft';
  918. $posttype = $_REQUEST['posttype'];
  919. $autoSave = $_REQUEST['autoSave'];
  920. $oldfile = $_REQUEST['oldfile'];
  921. $addEdit = $_REQUEST['addEdit'];
  922. $user = $_SESSION[site_url()]['user'];
  923. $role = user('role', $user);
  924. $field = array();
  925. $aField = array();
  926. if ($posttype == 'is_post') {
  927. $field_file = 'content/data/field/post.json';
  928. if (file_exists($field_file)) {
  929. $aField = json_decode(file_get_contents($field_file, true));
  930. }
  931. } elseif ($posttype == 'is_page') {
  932. $field_file = 'content/data/field/page.json';
  933. if (file_exists($field_file)) {
  934. $aField = json_decode(file_get_contents($field_file, true));
  935. }
  936. } elseif ($posttype == 'is_subpage') {
  937. $field_file = 'content/data/field/subpage.json';
  938. if (file_exists($field_file)) {
  939. $aField = json_decode(file_get_contents($field_file, true));
  940. }
  941. }
  942. if(!empty($aField)) {
  943. foreach ($aField as $af) {
  944. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  945. $field[$af->name] = !empty($_REQUEST[$af->name]) ? "checked" : '';
  946. } else {
  947. $field[$af->name] = from($_REQUEST, $af->name);
  948. }
  949. }
  950. }
  951. // The "AI was used" flag. Unchecked means empty, so no tag is written.
  952. if ($posttype == 'is_post') {
  953. $field['ai'] = from($_REQUEST, 'ai') ? 'yes' : '';
  954. }
  955. if (empty($url)) {
  956. $url = $title;
  957. }
  958. if ($addEdit == 'edit') {
  959. $revertPage = '';
  960. $revertPost = '';
  961. $publishDraft = '';
  962. $destination = null;
  963. }
  964. if (!empty($title) && !empty($content)) {
  965. if ($posttype == 'is_page') {
  966. if ($role === 'editor' || $role === 'admin') {
  967. if ($addEdit == 'add') {
  968. $response = add_page($title, $url, $content, $draft, $description, $autoSave, $oldfile, $field);
  969. } else {
  970. $response = edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, null, $autoSave, $field);
  971. }
  972. }
  973. } elseif ($posttype == 'is_subpage') {
  974. if ($role === 'editor' || $role === 'admin') {
  975. $static = $_REQUEST['parent_page'];
  976. if ($addEdit == 'add') {
  977. $response = add_sub_page($title, $url, $content, $static, $draft, $description, $autoSave, $oldfile, $field);
  978. } else {
  979. $response = edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static, $autoSave, $field);
  980. }
  981. }
  982. } else {
  983. $tag = $_REQUEST['tag'];
  984. $category = $_REQUEST['category'];
  985. $dateTime = $_REQUEST['dateTime'];
  986. if ($posttype == 'is_image') {
  987. $type = 'image';
  988. $media = $_REQUEST['pimage'];
  989. } elseif ($posttype == 'is_video') {
  990. $type = 'video';
  991. $media = $_REQUEST['pvideo'];
  992. } elseif ($posttype == 'is_link') {
  993. $type = 'link';
  994. $media = $_REQUEST['plink'];
  995. } elseif ($posttype == 'is_quote') {
  996. $type = 'quote';
  997. $media = $_REQUEST['pquote'];
  998. } elseif ($posttype == 'is_audio') {
  999. $type = 'audio';
  1000. $media = $_REQUEST['paudio'];
  1001. } elseif ($posttype == 'is_post') {
  1002. $type = 'post';
  1003. $media = null;
  1004. }
  1005. if ($type == 'post') {
  1006. if (!empty($title) && !empty($tag) && !empty($content)) {
  1007. if ($addEdit == 'add') {
  1008. $response = add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description, $media, $dateTime, $autoSave, $oldfile, $field);
  1009. } else {
  1010. $arr = explode('/', $oldfile);
  1011. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  1012. $response = edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination, $description, $dateTime, $media, $autoSave, $field);
  1013. }
  1014. }
  1015. } else {
  1016. $response = json_encode(array('message' => '<strong>Cannot save draft!</strong><br>Please fill in all required fields', 'file' => ''));
  1017. }
  1018. } else {
  1019. if (!empty($title) && !empty($tag) && !empty($content) && !empty($media)) {
  1020. if ($addEdit == 'add') {
  1021. $response = add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description, $media, $dateTime, $autoSave, $oldfile, $field);
  1022. } else {
  1023. $arr = explode('/', $oldfile);
  1024. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  1025. $response = edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination, $description, $dateTime, $media, $autoSave, $field);
  1026. }
  1027. }
  1028. } else {
  1029. $response = json_encode(array('message' => '<strong>Cannot save draft!</strong><br>Please fill in all required fields', 'file' => ''));
  1030. }
  1031. }
  1032. }
  1033. } else {
  1034. $response = json_encode(array('message' => '<strong>Cannot save draft!</strong><br>Please fill in all required fields', 'file' => ''));
  1035. }
  1036. header('Content-Type: application/json');
  1037. echo $response;
  1038. } else {
  1039. error(401, "Not logged in");
  1040. }
  1041. });
  1042. // Show the add category
  1043. get('/add/category', function () {
  1044. $user = $_SESSION[site_url()]['user'];
  1045. $role = user('role', $user);
  1046. if (login()) {
  1047. config('views.root', 'system/admin/views');
  1048. if ($role === 'editor' || $role === 'admin') {
  1049. render('add-page', array(
  1050. 'title' => generate_title('is_default', i18n('Add_category')),
  1051. 'description' => safe_html(strip_tags(blog_description())),
  1052. 'canonical' => site_url(),
  1053. 'metatags' => generate_meta(null, null),
  1054. 'type' => 'is_category',
  1055. 'is_admin' => true,
  1056. 'bodyclass' => 'add-category',
  1057. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_category')
  1058. ));
  1059. } else {
  1060. render('denied', array(
  1061. 'title' => generate_title('is_default', i18n('Denied')),
  1062. 'description' => safe_html(strip_tags(blog_description())),
  1063. 'canonical' => site_url(),
  1064. 'metatags' => generate_meta(null, null),
  1065. 'type' => 'is_category',
  1066. 'is_admin' => true,
  1067. 'bodyclass' => 'denied',
  1068. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1069. ));
  1070. }
  1071. } else {
  1072. $login = site_url() . 'login';
  1073. header("location: $login");
  1074. }
  1075. });
  1076. // Submitted add category
  1077. post('/add/category', function () {
  1078. if(!login()) {
  1079. $login = site_url() . 'login';
  1080. header("location: $login");
  1081. }
  1082. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1083. $title = from($_REQUEST, 'title');
  1084. $url = from($_REQUEST, 'url');
  1085. $content = from($_REQUEST, 'content');
  1086. $description = from($_REQUEST, 'description');
  1087. $user = $_SESSION[site_url()]['user'];
  1088. $role = user('role', $user);
  1089. if (empty($url)) {
  1090. $url = $title;
  1091. }
  1092. if ($role === 'editor' || $role === 'admin') {
  1093. if ($proper && !empty($title) && !empty($content)) {
  1094. add_category($title, $url, $content, $description);
  1095. } else {
  1096. $message['error'] = '';
  1097. if (empty($title)) {
  1098. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  1099. }
  1100. if (empty($content)) {
  1101. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  1102. }
  1103. if (!$proper) {
  1104. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  1105. }
  1106. config('views.root', 'system/admin/views');
  1107. render('add-page', array(
  1108. 'title' => generate_title('is_default', i18n('Add_category')),
  1109. 'description' => safe_html(strip_tags(blog_description())),
  1110. 'canonical' => site_url(),
  1111. 'metatags' => generate_meta(null, null),
  1112. 'error' => '<ul>' . $message['error'] . '</ul>',
  1113. 'postTitle' => $title,
  1114. 'postUrl' => $url,
  1115. 'postContent' => $content,
  1116. 'type' => 'is_category',
  1117. 'is_admin' => true,
  1118. 'bodyclass' => 'add-category',
  1119. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_category')
  1120. ));
  1121. }
  1122. } else {
  1123. $redir = site_url();
  1124. header("location: $redir");
  1125. }
  1126. });
  1127. // Show admin/posts
  1128. get('/admin/posts', function () {
  1129. $user = $_SESSION[site_url()]['user'];
  1130. $role = user('role', $user);
  1131. if (login()) {
  1132. config('views.root', 'system/admin/views');
  1133. if ($role === 'editor' || $role === 'admin') {
  1134. config('views.root', 'system/admin/views');
  1135. $page = from($_GET, 'page');
  1136. $page = $page ? (int)$page : 1;
  1137. $perpage = 20;
  1138. $posts = get_posts(null, $page, $perpage);
  1139. $total = count(get_blog_posts());
  1140. if (empty($posts) || $page < 1) {
  1141. // a non-existing page
  1142. render('no-posts', array(
  1143. 'title' => generate_title('is_default', i18n('All_blog_posts')),
  1144. 'description' => safe_html(strip_tags(blog_description())),
  1145. 'canonical' => site_url(),
  1146. 'metatags' => generate_meta(null, null),
  1147. 'bodyclass' => 'no-posts',
  1148. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('All_blog_posts')
  1149. ));
  1150. die;
  1151. }
  1152. render('posts-list', array(
  1153. 'title' => generate_title('is_default', i18n('All_blog_posts')),
  1154. 'description' => safe_html(strip_tags(blog_description())),
  1155. 'canonical' => site_url(),
  1156. 'metatags' => generate_meta(null, null),
  1157. 'heading' => i18n('All_blog_posts'),
  1158. 'page' => $page,
  1159. 'posts' => $posts,
  1160. 'bodyclass' => 'all-posts',
  1161. 'type' => 'is_admin-posts',
  1162. 'is_admin' => true,
  1163. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('All_blog_posts'),
  1164. 'pagination' => has_pagination($total, $perpage, $page)
  1165. ));
  1166. } else {
  1167. render('denied', array(
  1168. 'title' => generate_title('is_default', i18n('All_blog_posts')),
  1169. 'description' => safe_html(strip_tags(blog_description())),
  1170. 'canonical' => site_url(),
  1171. 'metatags' => generate_meta(null, null),
  1172. 'type' => 'is_admin-posts',
  1173. 'is_admin' => true,
  1174. 'bodyclass' => 'denied',
  1175. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('All_blog_posts')
  1176. ));
  1177. }
  1178. } else {
  1179. $login = site_url() . 'login';
  1180. header("location: $login");
  1181. }
  1182. });
  1183. // Show admin/popular
  1184. get('/admin/popular', function () {
  1185. $user = $_SESSION[site_url()]['user'];
  1186. $role = user('role', $user);
  1187. if (login()) {
  1188. config('views.root', 'system/admin/views');
  1189. if ($role === 'editor' || $role === 'admin') {
  1190. config('views.root', 'system/admin/views');
  1191. $page = from($_GET, 'page');
  1192. $page = $page ? (int)$page : 1;
  1193. $perpage = 20;
  1194. $posts = popular_posts(true,$perpage);
  1195. $total = '';
  1196. if (empty($posts) || $page < 1) {
  1197. // a non-existing page
  1198. render('no-posts', array(
  1199. 'title' => generate_title('is_default', i18n('Popular_posts')),
  1200. 'description' => safe_html(strip_tags(blog_description())),
  1201. 'canonical' => site_url(),
  1202. 'metatags' => generate_meta(null, null),
  1203. 'is_admin' => true,
  1204. 'bodyclass' => 'admin-popular',
  1205. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Popular_posts')
  1206. ));
  1207. die;
  1208. }
  1209. render('popular-posts', array(
  1210. 'title' => generate_title('is_default', i18n('Popular_posts')),
  1211. 'description' => safe_html(strip_tags(blog_description())),
  1212. 'canonical' => site_url(),
  1213. 'metatags' => generate_meta(null, null),
  1214. 'heading' => i18n('Popular_posts'),
  1215. 'page' => $page,
  1216. 'posts' => $posts,
  1217. 'is_admin' => true,
  1218. 'bodyclass' => 'admin-popular',
  1219. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Popular_posts'),
  1220. 'pagination' => has_pagination($total, $perpage, $page)
  1221. ));
  1222. } else {
  1223. render('denied', array(
  1224. 'title' => generate_title('is_default', i18n('Popular_posts')),
  1225. 'description' => safe_html(strip_tags(blog_description())),
  1226. 'canonical' => site_url(),
  1227. 'metatags' => generate_meta(null, null),
  1228. 'is_admin' => true,
  1229. 'bodyclass' => 'denied',
  1230. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Popular_posts')
  1231. ));
  1232. }
  1233. } else {
  1234. $login = site_url() . 'login';
  1235. header("location: $login");
  1236. }
  1237. });
  1238. // Show admin/mine
  1239. get('/admin/mine', function () {
  1240. if (login()) {
  1241. config('views.root', 'system/admin/views');
  1242. $name = $_SESSION[site_url()]['user'];
  1243. $page = from($_GET, 'page');
  1244. $page = $page ? (int)$page : 1;
  1245. $perpage = config('profile.perpage');
  1246. $total = '';
  1247. $posts = get_profile_posts($name, $page, $perpage);
  1248. if (!empty($posts)) {
  1249. $total = $posts[1];
  1250. $posts = $posts[0];
  1251. }
  1252. $author = get_author($name);
  1253. if (isset($author[0])) {
  1254. $author = $author[0];
  1255. } else {
  1256. $author = default_profile($name);
  1257. }
  1258. if (empty($posts) || $page < 1) {
  1259. render('user-posts', array(
  1260. 'title' => generate_title('is_default', i18n('My_posts')),
  1261. 'description' => safe_html(strip_tags(blog_description())),
  1262. 'canonical' => site_url(),
  1263. 'metatags' => generate_meta(null, null),
  1264. 'page' => $page,
  1265. 'heading' => i18n('My_posts'),
  1266. 'posts' => null,
  1267. 'about' => $author->about,
  1268. 'name' => $author->name,
  1269. 'type' => 'is_admin-mine',
  1270. 'is_admin' => true,
  1271. 'bodyclass' => 'admin-mine',
  1272. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_posts') . ': '. $author->name,
  1273. 'pagination' => has_pagination($total, $perpage, $page)
  1274. ));
  1275. die;
  1276. }
  1277. render('user-posts', array(
  1278. 'title' => generate_title('is_default', i18n('My_posts')),
  1279. 'description' => safe_html(strip_tags(blog_description())),
  1280. 'canonical' => site_url(),
  1281. 'metatags' => generate_meta(null, null),
  1282. 'heading' => i18n('My_posts'),
  1283. 'page' => $page,
  1284. 'posts' => $posts,
  1285. 'about' => $author->about,
  1286. 'name' => $author->name,
  1287. 'type' => 'is_admin-mine',
  1288. 'is_admin' => true,
  1289. 'bodyclass' => 'admin-mine',
  1290. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_posts') . ': '. $author->name,
  1291. 'pagination' => has_pagination($total, $perpage, $page)
  1292. ));
  1293. } else {
  1294. $login = site_url() . 'login';
  1295. header("location: $login");
  1296. }
  1297. });
  1298. // Show admin/draft
  1299. get('/admin/draft', function () {
  1300. if (login()) {
  1301. config('views.root', 'system/admin/views');
  1302. $name = $_SESSION[site_url()]['user'];
  1303. $page = from($_GET, 'page');
  1304. $page = $page ? (int)$page : 1;
  1305. $perpage = config('profile.perpage');
  1306. $total = '';
  1307. $posts = get_draft($name, $page, $perpage);
  1308. if (!empty($posts)) {
  1309. $total = $posts[1];
  1310. $posts = $posts[0];
  1311. }
  1312. $draftPages = find_draft_page();
  1313. $draftSubpages = find_draft_subpage();
  1314. $author = get_author($name);
  1315. if (isset($author[0])) {
  1316. $author = $author[0];
  1317. } else {
  1318. $author = default_profile($name);
  1319. }
  1320. if (empty($posts) || $page < 1) {
  1321. render('user-draft', array(
  1322. 'title' => generate_title('is_default', i18n('My_draft')),
  1323. 'description' => safe_html(strip_tags(blog_description())),
  1324. 'canonical' => site_url(),
  1325. 'metatags' => generate_meta(null, null),
  1326. 'page' => $page,
  1327. 'heading' => i18n('My_draft'),
  1328. 'posts' => null,
  1329. 'draftPages' => $draftPages,
  1330. 'draftSubpages' => $draftSubpages,
  1331. 'about' => $author->about,
  1332. 'name' => $author->name,
  1333. 'type' => 'is_admin-draft',
  1334. 'is_admin' => true,
  1335. 'bodyclass' => 'admin-draft',
  1336. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_draft'). ': ' . $author->name,
  1337. 'pagination' => has_pagination($total, $perpage, $page)
  1338. ));
  1339. die;
  1340. }
  1341. render('user-draft', array(
  1342. 'title' => generate_title('is_default', i18n('My_draft')),
  1343. 'description' => safe_html(strip_tags(blog_description())),
  1344. 'canonical' => site_url(),
  1345. 'metatags' => generate_meta(null, null),
  1346. 'heading' => i18n('My_draft'),
  1347. 'page' => $page,
  1348. 'posts' => $posts,
  1349. 'draftPages' => $draftPages,
  1350. 'draftSubpages' => $draftSubpages,
  1351. 'about' => $author->about,
  1352. 'name' => $author->name,
  1353. 'type' => 'is_admin-draft',
  1354. 'is_admin' => true,
  1355. 'bodyclass' => 'admin-draft',
  1356. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_draft') . ': ' . $author->name,
  1357. 'pagination' => has_pagination($total, $perpage, $page)
  1358. ));
  1359. } else {
  1360. $login = site_url() . 'login';
  1361. header("location: $login");
  1362. }
  1363. });
  1364. // Show admin/scheduled
  1365. get('/admin/scheduled', function () {
  1366. if (login()) {
  1367. config('views.root', 'system/admin/views');
  1368. $name = $_SESSION[site_url()]['user'];
  1369. $page = from($_GET, 'page');
  1370. $page = $page ? (int)$page : 1;
  1371. $perpage = config('profile.perpage');
  1372. $total = '';
  1373. $posts = get_scheduled($name, $page, $perpage);
  1374. if (!empty($posts)) {
  1375. $total = $posts[1];
  1376. $posts = $posts[0];
  1377. }
  1378. $author = get_author($name);
  1379. if (isset($author[0])) {
  1380. $author = $author[0];
  1381. } else {
  1382. $author = default_profile($name);
  1383. }
  1384. if (empty($posts) || $page < 1) {
  1385. render('scheduled', array(
  1386. 'title' => generate_title('is_default', i18n('Scheduled_posts')),
  1387. 'description' => safe_html(strip_tags(blog_description())),
  1388. 'canonical' => site_url(),
  1389. 'metatags' => generate_meta(null, null),
  1390. 'page' => $page,
  1391. 'heading' => i18n('Scheduled_posts'),
  1392. 'posts' => null,
  1393. 'about' => $author->about,
  1394. 'name' => $author->name,
  1395. 'type' => 'is_admin-scheduled',
  1396. 'is_admin' => true,
  1397. 'bodyclass' => 'admin-scheduled',
  1398. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Scheduled_posts') . ': ' . $author->name,
  1399. 'pagination' => has_pagination($total, $perpage, $page)
  1400. ));
  1401. die;
  1402. }
  1403. render('scheduled', array(
  1404. 'title' => generate_title('is_default', i18n('Scheduled_posts')),
  1405. 'description' => safe_html(strip_tags(blog_description())),
  1406. 'canonical' => site_url(),
  1407. 'metatags' => generate_meta(null, null),
  1408. 'heading' => i18n('Scheduled_posts'),
  1409. 'page' => $page,
  1410. 'posts' => $posts,
  1411. 'about' => $author->about,
  1412. 'name' => $author->name,
  1413. 'type' => 'is_admin-scheduled',
  1414. 'is_admin' => true,
  1415. 'bodyclass' => 'admin-scheduled',
  1416. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Scheduled_posts') . ': ' . $author->name,
  1417. 'pagination' => has_pagination($total, $perpage, $page)
  1418. ));
  1419. } else {
  1420. $login = site_url() . 'login';
  1421. header("location: $login");
  1422. }
  1423. });
  1424. // Show admin/content
  1425. get('/admin/content', function () {
  1426. if (login()) {
  1427. config('views.root', 'system/admin/views');
  1428. render('content-type', array(
  1429. 'title' => generate_title('is_default', i18n('Add_content')),
  1430. 'description' => safe_html(strip_tags(blog_description())),
  1431. 'canonical' => site_url(),
  1432. 'metatags' => generate_meta(null, null),
  1433. 'type' => 'is_admin-content',
  1434. 'is_admin' => true,
  1435. 'bodyclass' => 'admin-content',
  1436. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_content')
  1437. ));
  1438. } else {
  1439. $login = site_url() . 'login';
  1440. header("location: $login");
  1441. }
  1442. });
  1443. // Show admin/pages
  1444. get('/admin/pages', function () {
  1445. $user = $_SESSION[site_url()]['user'];
  1446. $role = user('role', $user);
  1447. if (login()) {
  1448. config('views.root', 'system/admin/views');
  1449. if ($role === 'editor' || $role === 'admin') {
  1450. render('static-pages', array(
  1451. 'title' => generate_title('is_default', i18n('Static_pages')),
  1452. 'description' => safe_html(strip_tags(blog_description())),
  1453. 'canonical' => site_url(),
  1454. 'metatags' => generate_meta(null, null),
  1455. 'type' => 'is_admin-pages',
  1456. 'is_admin' => true,
  1457. 'bodyclass' => 'admin-pages',
  1458. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Static_pages')
  1459. ));
  1460. } else {
  1461. render('denied', array(
  1462. 'title' => generate_title('is_default', i18n('Denied')),
  1463. 'description' => safe_html(strip_tags(blog_description())),
  1464. 'canonical' => site_url(),
  1465. 'metatags' => generate_meta(null, null),
  1466. 'type' => 'is_admin-config',
  1467. 'is_admin' => true,
  1468. 'bodyclass' => 'denied',
  1469. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1470. ));
  1471. }
  1472. } else {
  1473. $login = site_url() . 'login';
  1474. header("location: $login");
  1475. }
  1476. });
  1477. post('/admin/pages', function () {
  1478. if (login()) {
  1479. $user = $_SESSION[site_url()]['user'];
  1480. $role = user('role', $user);
  1481. if ($role === 'editor' || $role === 'admin') {
  1482. $json = $_REQUEST['json'];
  1483. reorder_pages($json);
  1484. echo json_encode(array(
  1485. 'message' => 'Page order saved successfully!',
  1486. ));
  1487. }
  1488. }
  1489. });
  1490. // Show admin/pages
  1491. get('/admin/pages/:static', function ($static)
  1492. {
  1493. $user = $_SESSION[site_url()]['user'];
  1494. $role = user('role', $user);
  1495. if (login()) {
  1496. config('views.root', 'system/admin/views');
  1497. if ($role === 'editor' || $role === 'admin') {
  1498. $post = find_page($static);
  1499. if (!$post) {
  1500. not_found();
  1501. }
  1502. if (array_key_exists('prev', $post)) {
  1503. $prev = $post['prev'];
  1504. } else {
  1505. $prev = array();
  1506. }
  1507. if (array_key_exists('next', $post)) {
  1508. $next = $post['next'];
  1509. } else {
  1510. $next = array();
  1511. }
  1512. $post = $post['current'];
  1513. render('static-subpages', array(
  1514. 'title' => generate_title('is_default', $post->title),
  1515. 'description' => $post->description,
  1516. 'canonical' => $post->url,
  1517. 'metatags' => generate_meta(null, null),
  1518. 'bodyclass' => 'in-page ' . strtolower($static),
  1519. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/pages">' .i18n('pages').'</a> &#187; ' . $post->title,
  1520. 'p' => $post,
  1521. 'static' => $post,
  1522. 'type' => 'is_subpage',
  1523. 'prev' => static_prev($prev),
  1524. 'next' => static_next($next),
  1525. 'is_page' => true
  1526. ));
  1527. } else {
  1528. render('denied', array(
  1529. 'title' => generate_title('is_default', 'Pages'),
  1530. 'description' => safe_html(strip_tags(blog_description())),
  1531. 'canonical' => site_url(),
  1532. 'metatags' => generate_meta(null, null),
  1533. 'type' => 'is_subpage',
  1534. 'is_admin' => true,
  1535. 'bodyclass' => 'denied',
  1536. 'breadcrumb' => '',
  1537. ));
  1538. }
  1539. } else {
  1540. $login = site_url() . 'login';
  1541. }
  1542. });
  1543. post('/admin/pages/:static', function ($static) {
  1544. if (login()) {
  1545. $user = $_SESSION[site_url()]['user'];
  1546. $role = user('role', $user);
  1547. if ($role === 'editor' || $role === 'admin') {
  1548. $json = $_REQUEST['json'];
  1549. reorder_subpages($json);
  1550. echo json_encode(array(
  1551. 'message' => 'Page order saved successfully!',
  1552. ));
  1553. }
  1554. }
  1555. });
  1556. // Show import page
  1557. get('/admin/import', function () {
  1558. $user = $_SESSION[site_url()]['user'];
  1559. $role = user('role', $user);
  1560. if (login()) {
  1561. config('views.root', 'system/admin/views');
  1562. if ($role === 'admin') {
  1563. render('import', array(
  1564. 'title' => generate_title('is_default', i18n('Import_Feed')),
  1565. 'description' => safe_html(strip_tags(blog_description())),
  1566. 'canonical' => site_url(),
  1567. 'metatags' => generate_meta(null, null),
  1568. 'type' => 'is_admin-import',
  1569. 'is_admin' => true,
  1570. 'bodyclass' => 'admin-import',
  1571. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Import_Feed')
  1572. ));
  1573. } else {
  1574. render('denied', array(
  1575. 'title' => generate_title('is_default', i18n('Denied')),
  1576. 'description' => safe_html(strip_tags(blog_description())),
  1577. 'canonical' => site_url(),
  1578. 'metatags' => generate_meta(null, null),
  1579. 'type' => 'is_admin-import',
  1580. 'is_admin' => true,
  1581. 'bodyclass' => 'denied',
  1582. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1583. ));
  1584. }
  1585. } else {
  1586. $login = site_url() . 'login';
  1587. header("location: $login");
  1588. }
  1589. die;
  1590. });
  1591. // Submitted import page data
  1592. post('/admin/import', function () {
  1593. if(!login()) {
  1594. $login = site_url() . 'login';
  1595. header("location: $login");
  1596. }
  1597. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1598. $url = from($_REQUEST, 'url');
  1599. $credit = from($_REQUEST, 'credit');
  1600. $user = $_SESSION[site_url()]['user'];
  1601. $role = user('role', $user);
  1602. if ($role === 'admin') {
  1603. if (!empty($url) && $proper) {
  1604. get_feed($url, $credit);
  1605. $log = get_feed($url, $credit);
  1606. if (!empty($log)) {
  1607. config('views.root', 'system/admin/views');
  1608. render('import', array(
  1609. 'title' => generate_title('is_default', i18n('Import_Feed')),
  1610. 'description' => safe_html(strip_tags(blog_description())),
  1611. 'canonical' => site_url(),
  1612. 'metatags' => generate_meta(null, null),
  1613. 'error' => '<ul>' . $log . '</ul>',
  1614. 'type' => 'is_admin-import',
  1615. 'is_admin' => true,
  1616. 'bodyclass' => 'admin-import',
  1617. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Import_Feed')
  1618. ));
  1619. }
  1620. } else {
  1621. $message['error'] = '';
  1622. if (empty($url)) {
  1623. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_feedurl') . '</li>';
  1624. }
  1625. if (!$proper) {
  1626. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  1627. }
  1628. config('views.root', 'system/admin/views');
  1629. render('import', array(
  1630. 'title' => generate_title('is_default', i18n('Import_Feed')),
  1631. 'description' => safe_html(strip_tags(blog_description())),
  1632. 'canonical' => site_url(),
  1633. 'metatags' => generate_meta(null, null),
  1634. 'error' => '<ul>' . $message['error'] . '</ul>',
  1635. 'url' => $url,
  1636. 'type' => 'is_admin-import',
  1637. 'is_admin' => true,
  1638. 'bodyclass' => 'admin-import',
  1639. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Import_Feed')
  1640. ));
  1641. }
  1642. } else {
  1643. $redir = site_url();
  1644. header("location: $redir");
  1645. }
  1646. });
  1647. // Show admin/search
  1648. get('/admin/search', function () {
  1649. $user = $_SESSION[site_url()]['user'];
  1650. $role = user('role', $user);
  1651. config('views.root', 'system/admin/views');
  1652. if (login()) {
  1653. if ($role === 'editor' || $role === 'admin' && config('fulltext.search') == "true") {
  1654. $page = from($_GET, 'page');
  1655. $page = $page ? (int)$page : 1;
  1656. $perpage = 40;
  1657. $tmp = array();
  1658. $search = array();
  1659. $total = '';
  1660. $searchFile = "content/data/search.json";
  1661. if (file_exists($searchFile)) {
  1662. $search = json_decode(file_get_contents($searchFile), true);
  1663. }
  1664. $posts = get_blog_posts();
  1665. foreach ($posts as $index => $v) {
  1666. $arr = explode('_', $v['filename']);
  1667. if (!isset($search['post_' . $arr[2]])) {
  1668. $tmp[] = $v;
  1669. }
  1670. }
  1671. if (!empty($tmp)) {
  1672. $posts = get_posts($tmp, $page, $perpage);
  1673. $total = count($tmp);
  1674. }
  1675. if (empty($tmp) || $page < 1) {
  1676. render('search', array(
  1677. 'title' => generate_title('is_default', i18n('search_index')),
  1678. 'heading' => i18n('search_index'),
  1679. 'description' => safe_html(strip_tags(blog_description())),
  1680. 'canonical' => site_url(),
  1681. 'metatags' => generate_meta(null, null),
  1682. 'bodyclass' => 'no-posts',
  1683. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('search_index')
  1684. ));
  1685. die;
  1686. }
  1687. render('search', array(
  1688. 'title' => generate_title('is_default', i18n('search_index')),
  1689. 'description' => safe_html(strip_tags(blog_description())),
  1690. 'canonical' => site_url(),
  1691. 'metatags' => generate_meta(null, null),
  1692. 'heading' => i18n('search_index'),
  1693. 'page' => $page,
  1694. 'posts' => $posts,
  1695. 'bodyclass' => 'all-index-posts',
  1696. 'type' => 'is_admin-index-posts',
  1697. 'is_admin' => true,
  1698. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('search_index'),
  1699. 'pagination' => has_pagination($total, $perpage, $page)
  1700. ));
  1701. } else {
  1702. render('denied', array(
  1703. 'title' => generate_title('is_default', i18n('search_index')),
  1704. 'description' => safe_html(strip_tags(blog_description())),
  1705. 'canonical' => site_url(),
  1706. 'metatags' => generate_meta(null, null),
  1707. 'type' => 'is_admin-index-posts',
  1708. 'is_admin' => true,
  1709. 'bodyclass' => 'denied',
  1710. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('search_index')
  1711. ));
  1712. }
  1713. } else {
  1714. $login = site_url() . 'login';
  1715. header("location: $login");
  1716. }
  1717. });
  1718. post('/admin/search', function () {
  1719. if (login()) {
  1720. $user = $_SESSION[site_url()]['user'];
  1721. $role = user('role', $user);
  1722. if ($role === 'editor' || $role === 'admin') {
  1723. $json = $_REQUEST['json'];
  1724. if ($json == 'content/data/search.json') {
  1725. unlink($json);
  1726. }
  1727. echo json_encode(array(
  1728. 'message' => 'Search Index cleared successfully!',
  1729. ));
  1730. }
  1731. }
  1732. });
  1733. post('/admin/search/reindex', function () {
  1734. if (login()) {
  1735. $user = $_SESSION[site_url()]['user'];
  1736. $role = user('role', $user);
  1737. $search = json_decode(htmlspecialchars_decode($_POST['search_index']));
  1738. config('views.root', 'system/admin/views');
  1739. if ($role === 'editor' || $role === 'admin' && config('fulltext.search') == "true") {
  1740. render('search-reindex', array(
  1741. 'title' => generate_title('is_default', i18n('search_index')),
  1742. 'description' => safe_html(strip_tags(blog_description())),
  1743. 'canonical' => site_url(),
  1744. 'metatags' => generate_meta(null, null),
  1745. 'type' => 'is_admin-search',
  1746. 'search' => $search,
  1747. 'is_admin' => true,
  1748. 'bodyclass' => 'admin-search',
  1749. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('search_index')
  1750. ));
  1751. }
  1752. }
  1753. });
  1754. // Show Config page
  1755. get('/admin/config', function () {
  1756. $user = $_SESSION[site_url()]['user'];
  1757. $role = user('role', $user);
  1758. if (login()) {
  1759. config('views.root', 'system/admin/views');
  1760. if ($role === 'admin') {
  1761. render('config', array(
  1762. 'title' => generate_title('is_default', i18n('Config')),
  1763. 'description' => safe_html(strip_tags(blog_description())),
  1764. 'canonical' => site_url(),
  1765. 'metatags' => generate_meta(null, null),
  1766. 'type' => 'is_admin-config',
  1767. 'is_admin' => true,
  1768. 'bodyclass' => 'admin-config',
  1769. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1770. ));
  1771. } else {
  1772. render('denied', array(
  1773. 'title' => generate_title('is_default', i18n('Config')),
  1774. 'description' => safe_html(strip_tags(blog_description())),
  1775. 'canonical' => site_url(),
  1776. 'metatags' => generate_meta(null, null),
  1777. 'type' => 'is_admin-config',
  1778. 'is_admin' => true,
  1779. 'bodyclass' => 'denied',
  1780. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1781. ));
  1782. }
  1783. } else {
  1784. $login = site_url() . 'login';
  1785. header("location: $login");
  1786. }
  1787. die;
  1788. });
  1789. // Submitted Config page data
  1790. post('/admin/config', function () {
  1791. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1792. if (login() && $proper) {
  1793. $user = $_SESSION[site_url()]['user'];
  1794. $role = user('role', $user);
  1795. if ($role === 'admin') {
  1796. $new_config = array();
  1797. $new_Keys = array();
  1798. foreach ($_POST as $name => $value) {
  1799. if (substr($name, 0, 8) == "-config-") {
  1800. $name = str_replace("_", ".", substr($name, 8));
  1801. if(!is_null(config($name))) {
  1802. $new_config[$name] = $value;
  1803. } else {
  1804. $new_Keys[$name] = $value;
  1805. }
  1806. }
  1807. }
  1808. save_config($new_config, $new_Keys);
  1809. foreach (glob('cache/widget/archive*.cache', GLOB_NOSORT) as $file) {
  1810. unlink($file);
  1811. }
  1812. $redir = site_url() . 'admin/config';
  1813. header("location: $redir");
  1814. } else {
  1815. $redir = site_url();
  1816. header("location: $redir");
  1817. }
  1818. } else {
  1819. $login = site_url() . 'login';
  1820. header("location: $login");
  1821. }
  1822. });
  1823. // Show Config page
  1824. get('/admin/config/custom', function () {
  1825. $user = $_SESSION[site_url()]['user'];
  1826. $role = user('role', $user);
  1827. if (login()) {
  1828. config('views.root', 'system/admin/views');
  1829. if ($role === 'admin') {
  1830. render('config-custom', array(
  1831. 'title' => generate_title('is_default', i18n('Config')),
  1832. 'description' => safe_html(strip_tags(blog_description())),
  1833. 'canonical' => site_url(),
  1834. 'metatags' => generate_meta(null, null),
  1835. 'type' => 'is_admin-config',
  1836. 'is_admin' => true,
  1837. 'bodyclass' => 'admin-config',
  1838. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1839. ));
  1840. } else {
  1841. render('denied', array(
  1842. 'title' => generate_title('is_default', i18n('Config')),
  1843. 'description' => safe_html(strip_tags(blog_description())),
  1844. 'canonical' => site_url(),
  1845. 'metatags' => generate_meta(null, null),
  1846. 'type' => 'is_admin-config',
  1847. 'is_admin' => true,
  1848. 'bodyclass' => 'denied',
  1849. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1850. ));
  1851. }
  1852. } else {
  1853. $login = site_url() . 'login';
  1854. header("location: $login");
  1855. }
  1856. });
  1857. // Submitted Config page data
  1858. post('/admin/config/custom', function () {
  1859. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1860. if (login() && $proper) {
  1861. $user = $_SESSION[site_url()]['user'];
  1862. $role = user('role', $user);
  1863. if ($role === 'admin') {
  1864. $newKey = from($_REQUEST, 'newKey');
  1865. $newValue = from($_REQUEST, 'newValue');
  1866. $new_config = array();
  1867. $new_Keys = array();
  1868. if (!empty($newKey)) {
  1869. $new_Keys[$newKey] = $newValue;
  1870. }
  1871. foreach ($_POST as $name => $value) {
  1872. if (substr($name, 0, 8) == "-config-") {
  1873. $name = str_replace("_", ".", substr($name, 8));
  1874. $new_config[$name] = $value;
  1875. }
  1876. }
  1877. save_config($new_config, $new_Keys);
  1878. $redir = site_url() . 'admin/config/custom';
  1879. header("location: $redir");
  1880. } else {
  1881. $redir = site_url();
  1882. header("location: $redir");
  1883. }
  1884. } else {
  1885. $login = site_url() . 'login';
  1886. header("location: $login");
  1887. }
  1888. });
  1889. // Show Config page
  1890. get('/admin/config/reading', function () {
  1891. $user = $_SESSION[site_url()]['user'];
  1892. $role = user('role', $user);
  1893. if (login()) {
  1894. config('views.root', 'system/admin/views');
  1895. if ($role === 'admin') {
  1896. render('config-reading', array(
  1897. 'title' => generate_title('is_default', i18n('Config')),
  1898. 'description' => safe_html(strip_tags(blog_description())),
  1899. 'canonical' => site_url(),
  1900. 'metatags' => generate_meta(null, null),
  1901. 'type' => 'is_admin-config',
  1902. 'is_admin' => true,
  1903. 'bodyclass' => 'admin-config',
  1904. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1905. ));
  1906. } else {
  1907. render('denied', array(
  1908. 'title' => generate_title('is_default', i18n('Config')),
  1909. 'description' => safe_html(strip_tags(blog_description())),
  1910. 'canonical' => site_url(),
  1911. 'metatags' => generate_meta(null, null),
  1912. 'type' => 'is_admin-config',
  1913. 'is_admin' => true,
  1914. 'bodyclass' => 'denied',
  1915. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1916. ));
  1917. }
  1918. } else {
  1919. $login = site_url() . 'login';
  1920. header("location: $login");
  1921. }
  1922. });
  1923. // Submitted Config page data
  1924. post('/admin/config/reading', function () {
  1925. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1926. if (login() && $proper) {
  1927. $new_config = array();
  1928. $new_Keys = array();
  1929. $user = $_SESSION[site_url()]['user'];
  1930. $role = user('role', $user);
  1931. if ($role === 'admin') {
  1932. foreach ($_POST as $name => $value) {
  1933. if (substr($name, 0, 8) == "-config-") {
  1934. $name = str_replace("_", ".", substr($name, 8));
  1935. if(!is_null(config($name))) {
  1936. $new_config[$name] = $value;
  1937. } else {
  1938. $new_Keys[$name] = $value;
  1939. }
  1940. }
  1941. }
  1942. save_config($new_config, $new_Keys);
  1943. $redir = site_url() . 'admin/config/reading';
  1944. header("location: $redir");
  1945. } else {
  1946. $redir = site_url();
  1947. header("location: $redir");
  1948. }
  1949. } else {
  1950. $login = site_url() . 'login';
  1951. header("location: $login");
  1952. }
  1953. });
  1954. // Show Config page
  1955. get('/admin/config/writing', function () {
  1956. $user = $_SESSION[site_url()]['user'];
  1957. $role = user('role', $user);
  1958. if (login()) {
  1959. config('views.root', 'system/admin/views');
  1960. if ($role === 'admin') {
  1961. render('config-writing', array(
  1962. 'title' => generate_title('is_default', i18n('Config')),
  1963. 'description' => safe_html(strip_tags(blog_description())),
  1964. 'canonical' => site_url(),
  1965. 'metatags' => generate_meta(null, null),
  1966. 'type' => 'is_admin-config',
  1967. 'is_admin' => true,
  1968. 'bodyclass' => 'admin-config',
  1969. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1970. ));
  1971. } else {
  1972. render('denied', array(
  1973. 'title' => generate_title('is_default', i18n('Config')),
  1974. 'description' => safe_html(strip_tags(blog_description())),
  1975. 'canonical' => site_url(),
  1976. 'metatags' => generate_meta(null, null),
  1977. 'type' => 'is_admin-config',
  1978. 'is_admin' => true,
  1979. 'bodyclass' => 'denied',
  1980. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1981. ));
  1982. }
  1983. } else {
  1984. $login = site_url() . 'login';
  1985. header("location: $login");
  1986. }
  1987. });
  1988. // Submitted Config page data
  1989. post('/admin/config/writing', function () {
  1990. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1991. if (login() && $proper) {
  1992. $new_config = array();
  1993. $new_Keys = array();
  1994. $user = $_SESSION[site_url()]['user'];
  1995. $role = user('role', $user);
  1996. if ($role === 'admin') {
  1997. foreach ($_POST as $name => $value) {
  1998. if (substr($name, 0, 8) == "-config-") {
  1999. $name = str_replace("_", ".", substr($name, 8));
  2000. if(!is_null(config($name))) {
  2001. $new_config[$name] = $value;
  2002. } else {
  2003. $new_Keys[$name] = $value;
  2004. }
  2005. }
  2006. }
  2007. save_config($new_config, $new_Keys);
  2008. $redir = site_url() . 'admin/config/writing';
  2009. header("location: $redir");
  2010. } else {
  2011. $redir = site_url();
  2012. header("location: $redir");
  2013. }
  2014. } else {
  2015. $login = site_url() . 'login';
  2016. header("location: $login");
  2017. }
  2018. });
  2019. // Show Config page
  2020. get('/admin/config/widget', function () {
  2021. $user = $_SESSION[site_url()]['user'];
  2022. $role = user('role', $user);
  2023. if (login()) {
  2024. config('views.root', 'system/admin/views');
  2025. if ($role === 'admin') {
  2026. render('config-widget', array(
  2027. 'title' => generate_title('is_default', i18n('Config')),
  2028. 'description' => safe_html(strip_tags(blog_description())),
  2029. 'canonical' => site_url(),
  2030. 'metatags' => generate_meta(null, null),
  2031. 'type' => 'is_admin-config',
  2032. 'is_admin' => true,
  2033. 'bodyclass' => 'admin-config',
  2034. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2035. ));
  2036. } else {
  2037. render('denied', array(
  2038. 'title' => generate_title('is_default', i18n('Config')),
  2039. 'description' => safe_html(strip_tags(blog_description())),
  2040. 'canonical' => site_url(),
  2041. 'metatags' => generate_meta(null, null),
  2042. 'type' => 'is_admin-config',
  2043. 'is_admin' => true,
  2044. 'bodyclass' => 'denied',
  2045. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2046. ));
  2047. }
  2048. } else {
  2049. $login = site_url() . 'login';
  2050. header("location: $login");
  2051. }
  2052. });
  2053. // Submitted Config page data
  2054. post('/admin/config/widget', function () {
  2055. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2056. if (login() && $proper) {
  2057. $new_config = array();
  2058. $new_Keys = array();
  2059. $user = $_SESSION[site_url()]['user'];
  2060. $role = user('role', $user);
  2061. if ($role === 'admin') {
  2062. foreach ($_POST as $name => $value) {
  2063. if (substr($name, 0, 8) == "-config-") {
  2064. $name = str_replace("_", ".", substr($name, 8));
  2065. if(!is_null(config($name))) {
  2066. $new_config[$name] = $value;
  2067. } else {
  2068. $new_Keys[$name] = $value;
  2069. }
  2070. }
  2071. }
  2072. save_config($new_config, $new_Keys);
  2073. foreach (glob('cache/widget/tags*.cache', GLOB_NOSORT) as $file) {
  2074. unlink($file);
  2075. }
  2076. $redir = site_url() . 'admin/config/widget';
  2077. header("location: $redir");
  2078. } else {
  2079. $redir = site_url();
  2080. header("location: $redir");
  2081. }
  2082. } else {
  2083. $login = site_url() . 'login';
  2084. header("location: $login");
  2085. }
  2086. });
  2087. // Show Config page
  2088. get('/admin/config/metatags', function () {
  2089. $user = $_SESSION[site_url()]['user'];
  2090. $role = user('role', $user);
  2091. if (login()) {
  2092. config('views.root', 'system/admin/views');
  2093. if ($role === 'admin') {
  2094. render('config-metatags', array(
  2095. 'title' => generate_title('is_default', i18n('Config')),
  2096. 'description' => safe_html(strip_tags(blog_description())),
  2097. 'canonical' => site_url(),
  2098. 'metatags' => generate_meta(null, null),
  2099. 'type' => 'is_admin-config',
  2100. 'is_admin' => true,
  2101. 'bodyclass' => 'admin-config',
  2102. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2103. ));
  2104. } else {
  2105. render('denied', array(
  2106. 'title' => generate_title('is_default', i18n('Config')),
  2107. 'description' => safe_html(strip_tags(blog_description())),
  2108. 'canonical' => site_url(),
  2109. 'metatags' => generate_meta(null, null),
  2110. 'type' => 'is_admin-config',
  2111. 'is_admin' => true,
  2112. 'bodyclass' => 'denied',
  2113. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2114. ));
  2115. }
  2116. } else {
  2117. $login = site_url() . 'login';
  2118. header("location: $login");
  2119. }
  2120. die;
  2121. });
  2122. // Submitted Config page data
  2123. post('/admin/config/metatags', function () {
  2124. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2125. if (login() && $proper) {
  2126. $new_config = array();
  2127. $new_Keys = array();
  2128. $user = $_SESSION[site_url()]['user'];
  2129. $role = user('role', $user);
  2130. if ($role === 'admin') {
  2131. foreach ($_POST as $name => $value) {
  2132. if (substr($name, 0, 8) == "-config-") {
  2133. $name = str_replace("_", ".", substr($name, 8));
  2134. if(!is_null(config($name))) {
  2135. $new_config[$name] = $value;
  2136. } else {
  2137. $new_Keys[$name] = $value;
  2138. }
  2139. }
  2140. }
  2141. save_config($new_config, $new_Keys);
  2142. foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) {
  2143. unlink($file);
  2144. }
  2145. $redir = site_url() . 'admin/config/metatags';
  2146. header("location: $redir");
  2147. } else {
  2148. $redir = site_url();
  2149. header("location: $redir");
  2150. }
  2151. } else {
  2152. $login = site_url() . 'login';
  2153. header("location: $login");
  2154. }
  2155. });
  2156. // Show Config page
  2157. get('/admin/config/security', function () {
  2158. $user = $_SESSION[site_url()]['user'];
  2159. $role = user('role', $user);
  2160. if (login()) {
  2161. config('views.root', 'system/admin/views');
  2162. if ($role === 'admin') {
  2163. render('config-security', array(
  2164. 'title' => generate_title('is_default', i18n('Config')),
  2165. 'description' => safe_html(strip_tags(blog_description())),
  2166. 'canonical' => site_url(),
  2167. 'metatags' => generate_meta(null, null),
  2168. 'type' => 'is_admin-config',
  2169. 'is_admin' => true,
  2170. 'bodyclass' => 'admin-config',
  2171. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2172. ));
  2173. } else {
  2174. render('denied', array(
  2175. 'title' => generate_title('is_default', i18n('Config')),
  2176. 'description' => safe_html(strip_tags(blog_description())),
  2177. 'canonical' => site_url(),
  2178. 'metatags' => generate_meta(null, null),
  2179. 'type' => 'is_admin-config',
  2180. 'is_admin' => true,
  2181. 'bodyclass' => 'denied',
  2182. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2183. ));
  2184. }
  2185. } else {
  2186. $login = site_url() . 'login';
  2187. header("location: $login");
  2188. }
  2189. });
  2190. // Submitted Config page data
  2191. post('/admin/config/security', function () {
  2192. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2193. if (login() && $proper) {
  2194. $new_config = array();
  2195. $new_Keys = array();
  2196. $user = $_SESSION[site_url()]['user'];
  2197. $role = user('role', $user);
  2198. if ($role === 'admin') {
  2199. foreach ($_POST as $name => $value) {
  2200. if (substr($name, 0, 8) == "-config-") {
  2201. $name = str_replace("_", ".", substr($name, 8));
  2202. if(!is_null(config($name))) {
  2203. $new_config[$name] = $value;
  2204. } else {
  2205. $new_Keys[$name] = $value;
  2206. }
  2207. }
  2208. }
  2209. save_config($new_config, $new_Keys);
  2210. $redir = site_url() . 'admin/config/security';
  2211. header("location: $redir");
  2212. } else {
  2213. $redir = site_url();
  2214. header("location: $redir");
  2215. }
  2216. } else {
  2217. $login = site_url() . 'login';
  2218. header("location: $login");
  2219. }
  2220. });
  2221. // Show Config page
  2222. get('/admin/config/performance', function () {
  2223. $user = $_SESSION[site_url()]['user'];
  2224. $role = user('role', $user);
  2225. if (login()) {
  2226. config('views.root', 'system/admin/views');
  2227. if ($role === 'admin') {
  2228. render('config-performance', array(
  2229. 'title' => generate_title('is_default', i18n('Config')),
  2230. 'description' => safe_html(strip_tags(blog_description())),
  2231. 'canonical' => site_url(),
  2232. 'metatags' => generate_meta(null, null),
  2233. 'type' => 'is_admin-config',
  2234. 'is_admin' => true,
  2235. 'bodyclass' => 'admin-config',
  2236. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2237. ));
  2238. } else {
  2239. render('denied', array(
  2240. 'title' => generate_title('is_default', i18n('Config')),
  2241. 'description' => safe_html(strip_tags(blog_description())),
  2242. 'canonical' => site_url(),
  2243. 'metatags' => generate_meta(null, null),
  2244. 'type' => 'is_admin-config',
  2245. 'is_admin' => true,
  2246. 'bodyclass' => 'denied',
  2247. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  2248. ));
  2249. }
  2250. } else {
  2251. $login = site_url() . 'login';
  2252. header("location: $login");
  2253. }
  2254. die;
  2255. });
  2256. // Submitted Config page data
  2257. post('/admin/config/performance', function () {
  2258. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2259. if (login() && $proper) {
  2260. $new_config = array();
  2261. $new_Keys = array();
  2262. $user = $_SESSION[site_url()]['user'];
  2263. $role = user('role', $user);
  2264. if ($role === 'admin') {
  2265. foreach ($_POST as $name => $value) {
  2266. if (substr($name, 0, 8) == "-config-") {
  2267. $name = str_replace("_", ".", substr($name, 8));
  2268. if(!is_null(config($name))) {
  2269. $new_config[$name] = $value;
  2270. } else {
  2271. $new_Keys[$name] = $value;
  2272. }
  2273. }
  2274. }
  2275. save_config($new_config, $new_Keys);
  2276. $redir = site_url() . 'admin/config/performance';
  2277. header("location: $redir");
  2278. } else {
  2279. $redir = site_url();
  2280. header("location: $redir");
  2281. }
  2282. } else {
  2283. $login = site_url() . 'login';
  2284. header("location: $login");
  2285. }
  2286. });
  2287. // Show Backup page
  2288. get('/admin/backup', function () {
  2289. $user = $_SESSION[site_url()]['user'];
  2290. $role = user('role', $user);
  2291. if (login()) {
  2292. config('views.root', 'system/admin/views');
  2293. if ($role === 'admin') {
  2294. render('backup', array(
  2295. 'title' => generate_title('is_default', i18n('Backup')),
  2296. 'description' => safe_html(strip_tags(blog_description())),
  2297. 'canonical' => site_url(),
  2298. 'metatags' => generate_meta(null, null),
  2299. 'type' => 'is_admin-backup',
  2300. 'is_admin' => true,
  2301. 'bodyclass' => 'admin-backup',
  2302. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Backup')
  2303. ));
  2304. } else {
  2305. render('denied', array(
  2306. 'title' => generate_title('is_default', i18n('Denied')),
  2307. 'description' => safe_html(strip_tags(blog_description())),
  2308. 'canonical' => site_url(),
  2309. 'metatags' => generate_meta(null, null),
  2310. 'type' => 'is_admin-config',
  2311. 'is_admin' => true,
  2312. 'bodyclass' => 'denied',
  2313. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2314. ));
  2315. }
  2316. } else {
  2317. $login = site_url() . 'login';
  2318. header("location: $login");
  2319. }
  2320. });
  2321. // Show Create backup page
  2322. get('/admin/backup-start', function () {
  2323. if (login()) {
  2324. config('views.root', 'system/admin/views');
  2325. $user = $_SESSION[site_url()]['user'];
  2326. $role = user('role', $user);
  2327. if ($role === 'admin') {
  2328. render('backup-start', array(
  2329. 'title' => generate_title('is_default', i18n('Create_backup')),
  2330. 'description' => safe_html(strip_tags(blog_description())),
  2331. 'canonical' => site_url(),
  2332. 'metatags' => generate_meta(null, null),
  2333. 'type' => 'is_admin-backup-start',
  2334. 'is_admin' => true,
  2335. 'bodyclass' => 'admin-backup-start',
  2336. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Create_backup')
  2337. ));
  2338. } else {
  2339. $redir = site_url();
  2340. header("location: $redir");
  2341. }
  2342. } else {
  2343. $login = site_url() . 'login';
  2344. header("location: $login");
  2345. }
  2346. });
  2347. // Show clear cache page
  2348. get('/admin/clear-cache', function () {
  2349. $user = $_SESSION[site_url()]['user'];
  2350. $role = user('role', $user);
  2351. if (login()) {
  2352. config('views.root', 'system/admin/views');
  2353. if ($role === 'editor' || $role === 'admin') {
  2354. render('clear-cache', array(
  2355. 'title' => generate_title('is_default', i18n('Clear_cache')),
  2356. 'description' => safe_html(strip_tags(blog_description())),
  2357. 'canonical' => site_url(),
  2358. 'metatags' => generate_meta(null, null),
  2359. 'type' => 'is_admin-clear-cache',
  2360. 'is_admin' => true,
  2361. 'bodyclass' => 'admin-clear-cache',
  2362. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Clear_cache')
  2363. ));
  2364. } else {
  2365. render('denied', array(
  2366. 'title' => generate_title('is_default', i18n('Denied')),
  2367. 'description' => safe_html(strip_tags(blog_description())),
  2368. 'canonical' => site_url(),
  2369. 'metatags' => generate_meta(null, null),
  2370. 'type' => 'is_admin-clear-cache',
  2371. 'is_admin' => true,
  2372. 'bodyclass' => 'denied',
  2373. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2374. ));
  2375. }
  2376. } else {
  2377. $login = site_url() . 'login';
  2378. header("location: $login");
  2379. }
  2380. });
  2381. // Show Update page
  2382. get('/admin/update', function () {
  2383. $user = $_SESSION[site_url()]['user'];
  2384. $role = user('role', $user);
  2385. if (login()) {
  2386. config('views.root', 'system/admin/views');
  2387. if ($role === 'admin') {
  2388. render('update', array(
  2389. 'title' => generate_title('is_default', i18n('Check_update')),
  2390. 'description' => safe_html(strip_tags(blog_description())),
  2391. 'canonical' => site_url(),
  2392. 'metatags' => generate_meta(null, null),
  2393. 'type' => 'is_admin-update',
  2394. 'is_admin' => true,
  2395. 'bodyclass' => 'admin-update',
  2396. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Check_update')
  2397. ));
  2398. } else {
  2399. render('denied', array(
  2400. 'title' => generate_title('is_default', i18n('Denied')),
  2401. 'description' => safe_html(strip_tags(blog_description())),
  2402. 'canonical' => site_url(),
  2403. 'metatags' => generate_meta(null, null),
  2404. 'type' => 'is_admin-config',
  2405. 'is_admin' => true,
  2406. 'bodyclass' => 'denied',
  2407. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2408. ));
  2409. }
  2410. } else {
  2411. $login = site_url() . 'login';
  2412. header("location: $login");
  2413. }
  2414. });
  2415. // Show the update now link
  2416. get('/admin/update/now/:csrf', function ($CSRF) {
  2417. $proper = is_csrf_proper($CSRF);
  2418. $updater = new \Kanti\HubUpdater(array(
  2419. 'name' => 'danpros/htmly',
  2420. 'prerelease' => !!config("prerelease"),
  2421. ));
  2422. if (login() && $proper && $updater->able()) {
  2423. $user = $_SESSION[site_url()]['user'];
  2424. $role = user('role', $user);
  2425. if ($role === 'admin') {
  2426. $updater->update();
  2427. config('views.root', 'system/admin/views');
  2428. render('updated-to', array(
  2429. 'title' => generate_title('is_default', i18n('Update')),
  2430. 'description' => safe_html(strip_tags(blog_description())),
  2431. 'canonical' => site_url(),
  2432. 'metatags' => generate_meta(null, null),
  2433. 'info' => $updater->getCurrentInfo(),
  2434. 'type' => 'is_admin-update',
  2435. 'is_admin' => true,
  2436. 'bodyclass' => 'admin-update',
  2437. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Update')
  2438. ));
  2439. } else {
  2440. $redir = site_url();
  2441. header("location: $redir");
  2442. }
  2443. } else {
  2444. $login = site_url() . 'login';
  2445. header("location: $login");
  2446. }
  2447. });
  2448. // Show Menu builder
  2449. get('/admin/menu', function () {
  2450. $user = $_SESSION[site_url()]['user'];
  2451. $role = user('role', $user);
  2452. if (login()) {
  2453. config('views.root', 'system/admin/views');
  2454. if ($role === 'editor' || $role === 'admin') {
  2455. render('menu', array(
  2456. 'title' => generate_title('is_default', i18n('Menus')),
  2457. 'description' => safe_html(strip_tags(blog_description())),
  2458. 'canonical' => site_url(),
  2459. 'metatags' => generate_meta(null, null),
  2460. 'type' => 'is_admin-menu',
  2461. 'is_admin' => true,
  2462. 'bodyclass' => 'admin-menu',
  2463. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Menus')
  2464. ));
  2465. } else {
  2466. render('denied', array(
  2467. 'title' => generate_title('is_default', i18n('Denied')),
  2468. 'description' => safe_html(strip_tags(blog_description())),
  2469. 'canonical' => site_url(),
  2470. 'metatags' => generate_meta(null, null),
  2471. 'type' => 'is_admin-menu',
  2472. 'is_admin' => true,
  2473. 'bodyclass' => 'denied',
  2474. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2475. ));
  2476. }
  2477. } else {
  2478. $login = site_url() . 'login';
  2479. header("location: $login");
  2480. }
  2481. });
  2482. post('/admin/menu', function () {
  2483. if (login()) {
  2484. $user = $_SESSION[site_url()]['user'];
  2485. $role = user('role', $user);
  2486. if ($role === 'editor' || $role === 'admin') {
  2487. $json = from($_REQUEST, 'json');
  2488. file_put_contents('content/data/menu.json', json_encode($json, JSON_UNESCAPED_UNICODE));
  2489. echo json_encode(array(
  2490. 'message' => 'Menu saved successfully!',
  2491. ));
  2492. } else {
  2493. $redir = site_url();
  2494. header("location: $redir");
  2495. }
  2496. }
  2497. });
  2498. // Manage users page
  2499. get('/admin/users', function () {
  2500. $user = $_SESSION[site_url()]['user'];
  2501. $role = user('role', $user);
  2502. if (login()) {
  2503. config('views.root', 'system/admin/views');
  2504. if ($role === 'admin') {
  2505. render('users', array(
  2506. 'title' => generate_title('is_default', i18n('User')),
  2507. 'description' => safe_html(strip_tags(blog_description())),
  2508. 'canonical' => site_url(),
  2509. 'metatags' => generate_meta(null, null),
  2510. 'type' => 'is_admin-users',
  2511. 'is_admin' => true,
  2512. 'bodyclass' => 'admin-users',
  2513. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('User')
  2514. ));
  2515. } else {
  2516. render('denied', array(
  2517. 'title' => generate_title('is_default', i18n('Denied')),
  2518. 'description' => safe_html(strip_tags(blog_description())),
  2519. 'canonical' => site_url(),
  2520. 'metatags' => generate_meta(null, null),
  2521. 'type' => 'is_admin-menu',
  2522. 'is_admin' => true,
  2523. 'bodyclass' => 'denied',
  2524. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2525. ));
  2526. }
  2527. } else {
  2528. $login = site_url() . 'login';
  2529. header("location: $login");
  2530. }
  2531. });
  2532. get('/admin/add/user', function () {
  2533. $user = $_SESSION[site_url()]['user'];
  2534. $role = user('role', $user);
  2535. if (login()) {
  2536. config('views.root', 'system/admin/views');
  2537. if ($role === 'admin') {
  2538. render('add-user', array(
  2539. 'title' => generate_title('is_default', i18n('Add_user')),
  2540. 'description' => safe_html(strip_tags(blog_description())),
  2541. 'canonical' => site_url(),
  2542. 'metatags' => generate_meta(null, null),
  2543. 'type' => 'is_admin-users',
  2544. 'is_admin' => true,
  2545. 'bodyclass' => 'admin-users',
  2546. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('add_user')
  2547. ));
  2548. } else {
  2549. render('denied', array(
  2550. 'title' => generate_title('is_default', i18n('Denied')),
  2551. 'description' => safe_html(strip_tags(blog_description())),
  2552. 'canonical' => site_url(),
  2553. 'metatags' => generate_meta(null, null),
  2554. 'type' => 'is_admin-menu',
  2555. 'is_admin' => true,
  2556. 'bodyclass' => 'denied',
  2557. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2558. ));
  2559. }
  2560. } else {
  2561. $login = site_url() . 'login';
  2562. header("location: $login");
  2563. }
  2564. });
  2565. post('/admin/add/user', function () {
  2566. $user = $_SESSION[site_url()]['user'];
  2567. $role = user('role', $user);
  2568. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2569. $username = from($_REQUEST, 'username');
  2570. $user_role = from($_REQUEST, 'user-role');
  2571. $password = from($_REQUEST, 'password');
  2572. if (login() && $proper) {
  2573. config('views.root', 'system/admin/views');
  2574. if ($role === 'admin') {
  2575. if (!empty($username) && !empty($password)) {
  2576. create_user($username, $password, $user_role);
  2577. } else {
  2578. $message['error'] = '';
  2579. if (empty($username)) {
  2580. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_username') . '</li>';
  2581. }
  2582. if (empty($password)) {
  2583. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_password') . '</li>';
  2584. }
  2585. render('add-user', array(
  2586. 'title' => generate_title('is_default', i18n('Add_user')),
  2587. 'description' => safe_html(strip_tags(blog_description())),
  2588. 'canonical' => site_url(),
  2589. 'metatags' => generate_meta(null, null),
  2590. 'error' => '<ul>' . $message['error'] . '</ul>',
  2591. 'type' => 'is_admin-users',
  2592. 'is_admin' => true,
  2593. 'username' => $username,
  2594. 'user_role' => $user_role,
  2595. 'password' => $password,
  2596. 'bodyclass' => 'admin-users',
  2597. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('add_user')
  2598. ));
  2599. }
  2600. $redir = site_url() . 'admin/users';
  2601. header("location: $redir");
  2602. } else {
  2603. $redir = site_url();
  2604. header("location: $redir");
  2605. }
  2606. } else {
  2607. $login = site_url() . 'login';
  2608. header("location: $login");
  2609. }
  2610. });
  2611. get('/admin/users/:username/edit', function ($username) {
  2612. $user = $_SESSION[site_url()]['user'];
  2613. $role = user('role', $user);
  2614. if (login()) {
  2615. config('views.root', 'system/admin/views');
  2616. if ($role === 'admin') {
  2617. render('edit-user', array(
  2618. 'title' => generate_title('is_default', $username),
  2619. 'description' => safe_html(strip_tags(blog_description())),
  2620. 'canonical' => site_url(),
  2621. 'metatags' => generate_meta(null, null),
  2622. 'type' => 'is_admin-users',
  2623. 'username' => $username,
  2624. 'is_admin' => true,
  2625. 'bodyclass' => 'admin-users',
  2626. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $username
  2627. ));
  2628. } else {
  2629. render('denied', array(
  2630. 'title' => generate_title('is_default', i18n('Denied')),
  2631. 'description' => safe_html(strip_tags(blog_description())),
  2632. 'canonical' => site_url(),
  2633. 'metatags' => generate_meta(null, null),
  2634. 'type' => 'is_admin-menu',
  2635. 'is_admin' => true,
  2636. 'bodyclass' => 'denied',
  2637. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2638. ));
  2639. }
  2640. } else {
  2641. $login = site_url() . 'login';
  2642. header("location: $login");
  2643. }
  2644. });
  2645. // Submitted Config page data
  2646. post('/admin/users/:username/edit', function () {
  2647. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2648. if (login() && $proper) {
  2649. $username = from($_REQUEST, 'username');
  2650. $user_role = from($_REQUEST, 'role-name');
  2651. $new_password = from($_REQUEST, 'password');
  2652. $user = $_SESSION[site_url()]['user'];
  2653. $role = user('role', $user);
  2654. $old_password = user('password', $username);
  2655. if ($role === 'admin') {
  2656. $file = 'config/users/' . $username . '.ini';
  2657. if (file_exists($file)) {
  2658. if (empty($new_password)) {
  2659. file_put_contents($file, "password = " . $old_password . "\n" .
  2660. "encryption = password_hash\n" .
  2661. "role = " . $user_role . "\n", LOCK_EX);
  2662. } else {
  2663. update_user($username, $new_password, $user_role);
  2664. }
  2665. }
  2666. $redir = site_url() . 'admin/users';
  2667. header("location: $redir");
  2668. } else {
  2669. $redir = site_url();
  2670. header("location: $redir");
  2671. }
  2672. } else {
  2673. $login = site_url() . 'login';
  2674. header("location: $login");
  2675. }
  2676. });
  2677. get('/admin/users/:username/delete', function ($username) {
  2678. $user = $_SESSION[site_url()]['user'];
  2679. $role = user('role', $user);
  2680. if (login()) {
  2681. config('views.root', 'system/admin/views');
  2682. if ($role === 'admin') {
  2683. render('delete-user', array(
  2684. 'title' => generate_title('is_default', $username),
  2685. 'description' => safe_html(strip_tags(blog_description())),
  2686. 'canonical' => site_url(),
  2687. 'metatags' => generate_meta(null, null),
  2688. 'type' => 'is_admin-users',
  2689. 'username' => $username,
  2690. 'is_admin' => true,
  2691. 'bodyclass' => 'admin-users',
  2692. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $username
  2693. ));
  2694. } else {
  2695. render('denied', array(
  2696. 'title' => generate_title('is_default', i18n('Denied')),
  2697. 'description' => safe_html(strip_tags(blog_description())),
  2698. 'canonical' => site_url(),
  2699. 'metatags' => generate_meta(null, null),
  2700. 'type' => 'is_admin-menu',
  2701. 'is_admin' => true,
  2702. 'bodyclass' => 'denied',
  2703. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2704. ));
  2705. }
  2706. } else {
  2707. $login = site_url() . 'login';
  2708. header("location: $login");
  2709. }
  2710. });
  2711. post('/admin/users/:username/delete', function () {
  2712. $user = $_SESSION[site_url()]['user'];
  2713. $role = user('role', $user);
  2714. $file = from($_REQUEST, 'file');
  2715. $username = from($_REQUEST, 'username');
  2716. $user_role = user('role', $username);
  2717. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2718. if ($proper && login()) {
  2719. if ($role === 'admin') {
  2720. if ($user_role !== 'admin') {
  2721. unlink($file);
  2722. }
  2723. }
  2724. $redir = site_url() . 'admin/users';
  2725. header("location: $redir");
  2726. } else {
  2727. $login = site_url() . 'login';
  2728. header("location: $login");
  2729. }
  2730. });
  2731. post('/admin/gallery', function () {
  2732. if (login()) {
  2733. $page = from($_REQUEST, 'page');
  2734. $images = image_gallery(null, $page, 40);
  2735. echo json_encode(array('images' => $images));
  2736. }
  2737. });
  2738. // Show category page
  2739. get('/admin/categories', function () {
  2740. $user = $_SESSION[site_url()]['user'];
  2741. $role = user('role', $user);
  2742. if (login()) {
  2743. config('views.root', 'system/admin/views');
  2744. if ($role === 'editor' || $role === 'admin') {
  2745. render('categories', array(
  2746. 'title' => generate_title('is_default', i18n('Categories')),
  2747. 'description' => safe_html(strip_tags(blog_description())),
  2748. 'canonical' => site_url(),
  2749. 'metatags' => generate_meta(null, null),
  2750. 'type' => 'is_admin-categories',
  2751. 'is_admin' => true,
  2752. 'bodyclass' => 'admin-categories',
  2753. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Categories')
  2754. ));
  2755. } else {
  2756. render('denied', array(
  2757. 'title' => generate_title('is_default', i18n('Denied')),
  2758. 'description' => safe_html(strip_tags(blog_description())),
  2759. 'canonical' => site_url(),
  2760. 'metatags' => generate_meta(null, null),
  2761. 'type' => 'is_admin-categories',
  2762. 'is_admin' => true,
  2763. 'bodyclass' => 'denied',
  2764. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2765. ));
  2766. }
  2767. } else {
  2768. $login = site_url() . 'login';
  2769. header("location: $login");
  2770. }
  2771. });
  2772. // Show the category page
  2773. get('/admin/categories/:category', function ($category) {
  2774. $user = $_SESSION[site_url()]['user'];
  2775. $role = user('role', $user);
  2776. if (login()) {
  2777. config('views.root', 'system/admin/views');
  2778. if ($role === 'editor' || $role === 'admin') {
  2779. $page = from($_GET, 'page');
  2780. $page = $page ? (int)$page : 1;
  2781. $perpage = config('category.perpage');
  2782. $total = '';
  2783. if (empty($perpage)) {
  2784. $perpage = 10;
  2785. }
  2786. $posts = get_category($category, $page, $perpage);
  2787. if (!empty($posts)) {
  2788. $total = $posts[1];
  2789. $posts = $posts[0];
  2790. }
  2791. $desc = get_category_info($category);
  2792. if (empty($desc)) {
  2793. // a non-existing page
  2794. not_found();
  2795. }
  2796. $desc = $desc[0];
  2797. render('category-list', array(
  2798. 'title' => generate_title('is_default', $desc->title),
  2799. 'description' => $desc->description,
  2800. 'canonical' => $desc->url,
  2801. 'metatags' => generate_meta(null, null),
  2802. 'page' => $page,
  2803. 'posts' => $posts,
  2804. 'category' => $desc,
  2805. 'bodyclass' => 'in-category category-' . strtolower($category),
  2806. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/categories">' . i18n('Categories') .'</a> &#187; ' . $desc->title,
  2807. 'pagination' => has_pagination($total, $perpage, $page),
  2808. 'is_category' => true,
  2809. ));
  2810. } else {
  2811. render('denied', array(
  2812. 'title' => generate_title('is_default', 'Categories'),
  2813. 'description' => safe_html(strip_tags(blog_description())),
  2814. 'canonical' => site_url(),
  2815. 'metatags' => generate_meta(null, null),
  2816. 'type' => 'is_admin-categories',
  2817. 'is_admin' => true,
  2818. 'bodyclass' => 'denied',
  2819. 'breadcrumb' => '',
  2820. ));
  2821. }
  2822. } else {
  2823. $login = site_url() . 'login';
  2824. }
  2825. });
  2826. // Show admin/field
  2827. get('/admin/field', function () {
  2828. if (login()) {
  2829. config('views.root', 'system/admin/views');
  2830. render('custom-field', array(
  2831. 'title' => generate_title('is_default', i18n('custom_fields')),
  2832. 'description' => safe_html(strip_tags(blog_description())),
  2833. 'canonical' => site_url(),
  2834. 'metatags' => generate_meta(null, null),
  2835. 'type' => 'is_admin-content',
  2836. 'is_admin' => true,
  2837. 'bodyclass' => 'admin-content',
  2838. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('custom_fields')
  2839. ));
  2840. } else {
  2841. $login = site_url() . 'login';
  2842. header("location: $login");
  2843. }
  2844. });
  2845. // Show admin/field/post
  2846. get('/admin/field/post', function () {
  2847. if (login()) {
  2848. config('views.root', 'system/admin/views');
  2849. render('custom-field-post', array(
  2850. 'title' => generate_title('is_default', i18n('post')),
  2851. 'description' => safe_html(strip_tags(blog_description())),
  2852. 'canonical' => site_url(),
  2853. 'metatags' => generate_meta(null, null),
  2854. 'type' => 'is_admin-content',
  2855. 'is_admin' => true,
  2856. 'bodyclass' => 'admin-content',
  2857. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/field">' .i18n('custom_fields').'</a> &#187; ' . i18n('post')
  2858. ));
  2859. } else {
  2860. $login = site_url() . 'login';
  2861. header("location: $login");
  2862. }
  2863. });
  2864. post('/admin/field/post', function () {
  2865. if (login()) {
  2866. $user = $_SESSION[site_url()]['user'];
  2867. $role = user('role', $user);
  2868. if ($role === 'editor' || $role === 'admin') {
  2869. $dir = 'content/data/field/';
  2870. if (!is_dir($dir)) {
  2871. mkdir($dir, 0775, true);
  2872. }
  2873. $json = $_REQUEST['json'];
  2874. save_json_pretty('content/data/field/post.json', json_decode($json));
  2875. echo json_encode(array(
  2876. 'message' => 'Post fields saved successfully!',
  2877. ));
  2878. }
  2879. }
  2880. });
  2881. // Show admin/field/page
  2882. get('/admin/field/page', function () {
  2883. if (login()) {
  2884. config('views.root', 'system/admin/views');
  2885. render('custom-field-page', array(
  2886. 'title' => generate_title('is_default', i18n('page')),
  2887. 'description' => safe_html(strip_tags(blog_description())),
  2888. 'canonical' => site_url(),
  2889. 'metatags' => generate_meta(null, null),
  2890. 'type' => 'is_admin-content',
  2891. 'is_admin' => true,
  2892. 'bodyclass' => 'admin-content',
  2893. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/field">' .i18n('custom_fields').'</a> &#187; ' .i18n('page')
  2894. ));
  2895. } else {
  2896. $login = site_url() . 'login';
  2897. header("location: $login");
  2898. }
  2899. });
  2900. post('/admin/field/page', function () {
  2901. if (login()) {
  2902. $user = $_SESSION[site_url()]['user'];
  2903. $role = user('role', $user);
  2904. if ($role === 'editor' || $role === 'admin') {
  2905. $dir = 'content/data/field/';
  2906. if (!is_dir($dir)) {
  2907. mkdir($dir, 0775, true);
  2908. }
  2909. $json = $_REQUEST['json'];
  2910. save_json_pretty('content/data/field/page.json', json_decode($json));
  2911. echo json_encode(array(
  2912. 'message' => 'Page fields saved successfully!',
  2913. ));
  2914. }
  2915. }
  2916. });
  2917. // Show admin/field/subpage
  2918. get('/admin/field/subpage', function () {
  2919. if (login()) {
  2920. config('views.root', 'system/admin/views');
  2921. render('custom-field-subpage', array(
  2922. 'title' => generate_title('is_default', i18n('subpage')),
  2923. 'description' => safe_html(strip_tags(blog_description())),
  2924. 'canonical' => site_url(),
  2925. 'metatags' => generate_meta(null, null),
  2926. 'type' => 'is_admin-content',
  2927. 'is_admin' => true,
  2928. 'bodyclass' => 'admin-content',
  2929. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/field">' .i18n('custom_fields').'</a> &#187; ' .i18n('subpage')
  2930. ));
  2931. } else {
  2932. $login = site_url() . 'login';
  2933. header("location: $login");
  2934. }
  2935. });
  2936. post('/admin/field/subpage', function () {
  2937. if (login()) {
  2938. $user = $_SESSION[site_url()]['user'];
  2939. $role = user('role', $user);
  2940. if ($role === 'editor' || $role === 'admin') {
  2941. $dir = 'content/data/field/';
  2942. if (!is_dir($dir)) {
  2943. mkdir($dir, 0775, true);
  2944. }
  2945. $json = $_REQUEST['json'];
  2946. save_json_pretty('content/data/field/subpage.json', json_decode($json));
  2947. echo json_encode(array(
  2948. 'message' => 'Subpage fields saved successfully!',
  2949. ));
  2950. }
  2951. }
  2952. });
  2953. // Show admin/field/profile
  2954. get('/admin/field/profile', function () {
  2955. if (login()) {
  2956. config('views.root', 'system/admin/views');
  2957. render('custom-field-profile', array(
  2958. 'title' => generate_title('is_default', i18n('profile')),
  2959. 'description' => safe_html(strip_tags(blog_description())),
  2960. 'canonical' => site_url(),
  2961. 'metatags' => generate_meta(null, null),
  2962. 'type' => 'is_admin-content',
  2963. 'is_admin' => true,
  2964. 'bodyclass' => 'admin-content',
  2965. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/field">' .i18n('custom_fields').'</a> &#187; ' .i18n('profile')
  2966. ));
  2967. } else {
  2968. $login = site_url() . 'login';
  2969. header("location: $login");
  2970. }
  2971. });
  2972. post('/admin/field/profile', function () {
  2973. if (login()) {
  2974. $user = $_SESSION[site_url()]['user'];
  2975. $role = user('role', $user);
  2976. if ($role === 'editor' || $role === 'admin') {
  2977. $dir = 'content/data/field/';
  2978. if (!is_dir($dir)) {
  2979. mkdir($dir, 0775, true);
  2980. }
  2981. $json = $_REQUEST['json'];
  2982. save_json_pretty('content/data/field/profile.json', json_decode($json));
  2983. echo json_encode(array(
  2984. 'message' => 'Profile fields saved successfully!',
  2985. ));
  2986. }
  2987. }
  2988. });
  2989. // Show admin/themes
  2990. get('/admin/themes', function () {
  2991. if (login()) {
  2992. config('views.root', 'system/admin/views');
  2993. render('theme', array(
  2994. 'title' => generate_title('is_default', i18n('themes')),
  2995. 'description' => safe_html(strip_tags(blog_description())),
  2996. 'canonical' => site_url(),
  2997. 'metatags' => generate_meta(null, null),
  2998. 'type' => 'is_admin-content',
  2999. 'is_admin' => true,
  3000. 'bodyclass' => 'admin-content',
  3001. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('themes')
  3002. ));
  3003. } else {
  3004. $login = site_url() . 'login';
  3005. header("location: $login");
  3006. }
  3007. });
  3008. post('/admin/themes', function () {
  3009. if (login()) {
  3010. $new_config = array();
  3011. $new_Keys = array();
  3012. $user = $_SESSION[site_url()]['user'];
  3013. $role = user('role', $user);
  3014. if ($role === 'admin') {
  3015. $json = $_REQUEST['json'];
  3016. $new_config['views.root'] = $json;
  3017. save_config($new_config, $new_Keys);
  3018. echo json_encode(array(
  3019. 'message' => 'Theme activated!',
  3020. ));
  3021. }
  3022. }
  3023. });
  3024. // Show admin/themes/:theme
  3025. get('/admin/themes/:theme', function ($theme) {
  3026. $exp = explode('/', config('views.root'));
  3027. if ($theme !== $exp[1]) {
  3028. $redir = site_url() . 'admin/themes';
  3029. header("location: $redir");
  3030. }
  3031. if (login()) {
  3032. config('views.root', 'system/admin/views');
  3033. render('theme-settings', array(
  3034. 'title' => generate_title('is_default', $theme),
  3035. 'description' => safe_html(strip_tags(blog_description())),
  3036. 'canonical' => site_url(),
  3037. 'metatags' => generate_meta(null, null),
  3038. 'type' => 'is_admin-content',
  3039. 'theme' => $theme,
  3040. 'is_admin' => true,
  3041. 'bodyclass' => 'admin-content',
  3042. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="'. site_url() .'admin/themes">' . i18n('themes') . '</a> &#187; ' . $theme
  3043. ));
  3044. } else {
  3045. $login = site_url() . 'login';
  3046. header("location: $login");
  3047. }
  3048. });
  3049. // Submitted theme settings data
  3050. post('/admin/themes/:theme', function ($theme) {
  3051. $exp = explode('/', config('views.root'));
  3052. if ($theme !== $exp[1]) {
  3053. $redir = site_url() . 'admin/themes';
  3054. header("location: $redir");
  3055. }
  3056. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3057. if (login() && $proper) {
  3058. $new_config = array();
  3059. $new_Keys = array();
  3060. $user = $_SESSION[site_url()]['user'];
  3061. $role = user('role', $user);
  3062. if ($role === 'admin') {
  3063. foreach ($_POST as $name => $value) {
  3064. if (substr($name, 0, 8) == "-config-") {
  3065. $name = substr($name, 8);
  3066. if(!is_null(theme_config($name))) {
  3067. $new_config[$name] = $value;
  3068. } else {
  3069. $new_Keys[$name] = $value;
  3070. }
  3071. }
  3072. }
  3073. save_theme_config($new_config, $new_Keys, $theme);
  3074. $redir = site_url() . 'admin/themes/' . $theme;
  3075. header("location: $redir");
  3076. } else {
  3077. $redir = site_url();
  3078. header("location: $redir");
  3079. }
  3080. } else {
  3081. $login = site_url() . 'login';
  3082. header("location: $login");
  3083. }
  3084. });
  3085. // Show the category page
  3086. get('/category/:category', function ($category) {
  3087. if (!login()) {
  3088. file_cache($_SERVER['REQUEST_URI']);
  3089. }
  3090. $page = from($_GET, 'page');
  3091. $page = $page ? (int)$page : 1;
  3092. $perpage = config('category.perpage');
  3093. $total = '';
  3094. if (empty($perpage)) {
  3095. $perpage = 10;
  3096. }
  3097. $posts = get_category($category, $page, $perpage);
  3098. if (!empty($posts)) {
  3099. $total = $posts[1];
  3100. $posts = $posts[0];
  3101. }
  3102. if (empty($posts) || $page < 1) {
  3103. // a non-existing page
  3104. not_found();
  3105. }
  3106. $desc = get_category_info($category);
  3107. if(!empty($desc)) {
  3108. $desc = $desc[0];
  3109. }
  3110. $vroot = rtrim(config('views.root'), '/');
  3111. $lt = $vroot . '/layout--category--'. strtolower($category) .'.html.php';
  3112. $ls = $vroot . '/layout--category.html.php';
  3113. if (file_exists($lt)) {
  3114. $layout = 'layout--category--' . strtolower($category);
  3115. } else if (file_exists($ls)) {
  3116. $layout = 'layout--category';
  3117. } else {
  3118. $layout = '';
  3119. }
  3120. $pv = $vroot . '/main--category--'. strtolower($category) .'.html.php';
  3121. $ps = $vroot . '/main--category.html.php';
  3122. if (file_exists($pv)) {
  3123. $pview = 'main--category--' . strtolower($category);
  3124. } else if (file_exists($ps)) {
  3125. $pview = 'main--category';
  3126. } else {
  3127. $pview = 'main';
  3128. }
  3129. if ($page > 1) {
  3130. $CanonicalPageNum = '?page=' . $page;
  3131. } else {
  3132. $CanonicalPageNum = NULL;
  3133. }
  3134. render($pview, array(
  3135. 'title' => generate_title('is_category', $desc),
  3136. 'description' => $desc->description,
  3137. 'canonical' => $desc->url . $CanonicalPageNum,
  3138. 'metatags' => generate_meta('is_category', $desc),
  3139. 'page' => $page,
  3140. 'posts' => $posts,
  3141. 'category' => $desc,
  3142. 'taxonomy' => $desc,
  3143. 'bodyclass' => 'in-category category-' . strtolower($category),
  3144. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $desc->title,
  3145. 'pagination' => has_pagination($total, $perpage, $page),
  3146. 'is_category' => true,
  3147. 'is_taxonomy' => true
  3148. ), $layout);
  3149. });
  3150. // Show the RSS feed
  3151. get('/category/:category/feed', function ($category) {
  3152. header('Content-Type: application/rss+xml');
  3153. $posts = array();
  3154. $posts = get_category($category, 1, config('rss.count'));
  3155. if ($posts) {
  3156. $posts = $posts[0];
  3157. }
  3158. $data = get_category_info($category);
  3159. if(!empty($data)) {
  3160. $data = $data[0];
  3161. }
  3162. // Show an RSS feed
  3163. echo generate_rss($posts, $data);
  3164. });
  3165. // Show edit the category page
  3166. get('/category/:category/edit', function ($category) {
  3167. $user = $_SESSION[site_url()]['user'];
  3168. $role = user('role', $user);
  3169. if (login()) {
  3170. config('views.root', 'system/admin/views');
  3171. if ($role === 'editor' || $role === 'admin') {
  3172. $post = get_category_info($category);
  3173. if(empty($post)) {
  3174. not_found();
  3175. }
  3176. $post = $post[0];
  3177. render('edit-page', array(
  3178. 'title' => generate_title('is_default', i18n('Edit_category')),
  3179. 'description' => safe_html(strip_tags(blog_description())),
  3180. 'canonical' => site_url(),
  3181. 'metatags' => generate_meta(null, null),
  3182. 'type' => 'is_category',
  3183. 'is_admin' => true,
  3184. 'bodyclass' => 'edit-category',
  3185. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Category') . ': ' . $post->title,
  3186. 'p' => $post,
  3187. 'static' => $post,
  3188. ));
  3189. } else {
  3190. render('denied', array(
  3191. 'title' => generate_title('is_default', i18n('Denied')),
  3192. 'description' => safe_html(strip_tags(blog_description())),
  3193. 'canonical' => site_url(),
  3194. 'metatags' => generate_meta(null, null),
  3195. 'type' => 'is_category',
  3196. 'is_admin' => true,
  3197. 'bodyclass' => 'denied',
  3198. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  3199. ));
  3200. }
  3201. } else {
  3202. $login = site_url() . 'login';
  3203. header("location: $login");
  3204. }
  3205. });
  3206. // Get edited data from category page
  3207. post('/category/:category/edit', function () {
  3208. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3209. if(!login()) {
  3210. $login = site_url() . 'login';
  3211. header("location: $login");
  3212. }
  3213. $title = from($_REQUEST, 'title');
  3214. $url = from($_REQUEST, 'url');
  3215. $content = from($_REQUEST, 'content');
  3216. $oldfile = from($_REQUEST, 'oldfile');
  3217. $destination = from($_GET, 'destination');
  3218. $description = from($_REQUEST, 'description');
  3219. $user = $_SESSION[site_url()]['user'];
  3220. $role = user('role', $user);
  3221. if (empty($url)) {
  3222. $url = $title;
  3223. }
  3224. if ($role === 'editor' || $role === 'admin') {
  3225. if ($proper && !empty($title) && !empty($content)) {
  3226. edit_category($title, $url, $content, $oldfile, $destination, $description);
  3227. } else {
  3228. $message['error'] = '';
  3229. if (empty($title)) {
  3230. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  3231. }
  3232. if (empty($content)) {
  3233. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  3234. }
  3235. if (!$proper) {
  3236. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  3237. }
  3238. config('views.root', 'system/admin/views');
  3239. render('edit-page', array(
  3240. 'title' => generate_title('is_default', i18n('Edit_category')),
  3241. 'description' => safe_html(strip_tags(blog_description())),
  3242. 'canonical' => site_url(),
  3243. 'metatags' => generate_meta(null, null),
  3244. 'error' => '<ul>' . $message['error'] . '</ul>',
  3245. 'oldfile' => $oldfile,
  3246. 'postTitle' => $title,
  3247. 'postUrl' => $url,
  3248. 'postContent' => $content,
  3249. 'type' => 'is_category',
  3250. 'is_admin' => true,
  3251. 'bodyclass' => 'edit-category',
  3252. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit_category')
  3253. ));
  3254. }
  3255. } else {
  3256. $redir = site_url();
  3257. header("location: $redir");
  3258. }
  3259. });
  3260. // Delete category
  3261. get('/category/:category/delete', function ($category) {
  3262. $user = $_SESSION[site_url()]['user'];
  3263. $role = user('role', $user);
  3264. if (login()) {
  3265. config('views.root', 'system/admin/views');
  3266. if ($role === 'editor' || $role === 'admin') {
  3267. $post = get_category_info($category);
  3268. if(empty($post)) {
  3269. not_found();
  3270. }
  3271. $post = $post[0];
  3272. render('delete-category', array(
  3273. 'title' => generate_title('is_default', i18n('Delete') . ' ' . i18n('Category')),
  3274. 'description' => safe_html(strip_tags(blog_description())),
  3275. 'canonical' => site_url(),
  3276. 'metatags' => generate_meta(null, null),
  3277. 'type' => 'is_category',
  3278. 'is_admin' => true,
  3279. 'bodyclass' => 'delete-category',
  3280. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Category') . ': ' . $post->title,
  3281. 'p' => $post,
  3282. 'static' => $post,
  3283. 'type' => 'categoryPage',
  3284. ));
  3285. } else {
  3286. render('denied', array(
  3287. 'title' => generate_title('is_default', i18n('Denied')),
  3288. 'description' => safe_html(strip_tags(blog_description())),
  3289. 'canonical' => site_url(),
  3290. 'metatags' => generate_meta(null, null),
  3291. 'type' => 'is_admin-config',
  3292. 'is_admin' => true,
  3293. 'bodyclass' => 'denied',
  3294. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  3295. ));
  3296. }
  3297. } else {
  3298. $login = site_url() . 'login';
  3299. header("location: $login");
  3300. }
  3301. });
  3302. // Get deleted category data
  3303. post('/category/:category/delete', function () {
  3304. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3305. if ($proper && login()) {
  3306. $user = $_SESSION[site_url()]['user'];
  3307. $role = user('role', $user);
  3308. if ($role === 'editor' || $role === 'admin') {
  3309. $file = from($_REQUEST, 'file');
  3310. $destination = from($_GET, 'destination');
  3311. delete_page($file, $destination);
  3312. } else {
  3313. $redir = site_url();
  3314. header("location: $redir");
  3315. }
  3316. }
  3317. });
  3318. // Show the type page
  3319. get('/type/:type', function ($type) {
  3320. if (!login()) {
  3321. file_cache($_SERVER['REQUEST_URI']);
  3322. }
  3323. $page = from($_GET, 'page');
  3324. $page = $page ? (int)$page : 1;
  3325. $perpage = config('type.perpage');
  3326. $total = '';
  3327. if (empty($perpage)) {
  3328. $perpage = 10;
  3329. }
  3330. $posts = get_type($type, $page, $perpage);
  3331. if (!empty($posts)) {
  3332. $total = $posts[1];
  3333. $posts = $posts[0];
  3334. }
  3335. if (empty($posts) || $page < 1) {
  3336. // a non-existing page
  3337. not_found();
  3338. }
  3339. $ttype = new stdClass;
  3340. $ttype->title = ucfirst($type);
  3341. $ttype->url = site_url() . 'type/' . strtolower($type);
  3342. $ttype->count = $total;
  3343. $ttype->description = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title();
  3344. $ttype->body = $ttype->description;
  3345. $ttype->rss = $ttype->url . '/feed';
  3346. $ttype->slug = strtolower($type);
  3347. $vroot = rtrim(config('views.root'), '/');
  3348. $lt = $vroot . '/layout--type--'. strtolower($type) .'.html.php';
  3349. $ls = $vroot . '/layout--type.html.php';
  3350. if (file_exists($lt)) {
  3351. $layout = 'layout--type--' . strtolower($type);
  3352. } else if (file_exists($ls)) {
  3353. $layout = 'layout--type';
  3354. } else {
  3355. $layout = '';
  3356. }
  3357. $pv = $vroot . '/main--type--'. strtolower($type) .'.html.php';
  3358. $ps = $vroot . '/main--type.html.php';
  3359. if (file_exists($pv)) {
  3360. $pview = 'main--type--' . strtolower($type);
  3361. } else if (file_exists($ps)) {
  3362. $pview = 'main--type';
  3363. } else {
  3364. $pview = 'main';
  3365. }
  3366. if ($page > 1) {
  3367. $CanonicalPageNum = '?page=' . $page;
  3368. } else {
  3369. $CanonicalPageNum = NULL;
  3370. }
  3371. render($pview, array(
  3372. 'title' => generate_title('is_type', $ttype),
  3373. 'description' => $ttype->description,
  3374. 'canonical' => $ttype->url . $CanonicalPageNum,
  3375. 'metatags' => generate_meta('is_type', $ttype),
  3376. 'page' => $page,
  3377. 'posts' => $posts,
  3378. 'type' => $ttype,
  3379. 'taxonomy' => $ttype,
  3380. 'bodyclass' => 'in-type type-' . strtolower($type),
  3381. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . ucfirst($type),
  3382. 'pagination' => has_pagination($total, $perpage, $page),
  3383. 'is_type' => true,
  3384. 'is_taxonomy' => true
  3385. ), $layout);
  3386. });
  3387. // Show the RSS feed
  3388. get('/type/:type/feed', function ($type) {
  3389. header('Content-Type: application/rss+xml');
  3390. $posts = array();
  3391. $posts = get_type($type, 1, config('rss.count'));
  3392. if ($posts) {
  3393. $posts = $posts[0];
  3394. }
  3395. $data = new stdClass;
  3396. $data->title = ucfirst($type);
  3397. $data->url = site_url() . 'type/' . strtolower($type);
  3398. $data->body = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title();
  3399. // Show an RSS feed
  3400. echo generate_rss($posts, $data);
  3401. });
  3402. // Show the tag page
  3403. get('/tag/:tag', function ($tag) {
  3404. if (!login()) {
  3405. file_cache($_SERVER['REQUEST_URI']);
  3406. }
  3407. $page = from($_GET, 'page');
  3408. $page = $page ? (int)$page : 1;
  3409. $perpage = config('tag.perpage');
  3410. $total = '';
  3411. $posts = get_tag($tag, $page, $perpage);
  3412. if (!empty($posts)) {
  3413. $total = $posts[1];
  3414. $posts = $posts[0];
  3415. }
  3416. if (empty($posts) || $page < 1) {
  3417. // a non-existing page
  3418. not_found();
  3419. }
  3420. $ttag = new stdClass;
  3421. $ttag->title = tag_i18n($tag);
  3422. $ttag->url = site_url() . 'tag/' . strtolower($tag);
  3423. $ttag->count = $total;
  3424. $ttag->description = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title();
  3425. $ttag->body = $ttag->description;
  3426. $ttag->rss = $ttag->url . '/feed';
  3427. $ttag->slug = strtolower($tag);
  3428. $vroot = rtrim(config('views.root'), '/');
  3429. $lt = $vroot . '/layout--tag--' . strtolower($tag) . '.html.php';
  3430. $ls = $vroot . '/layout--tag.html.php';
  3431. if (file_exists($lt)) {
  3432. $layout = 'layout--tag--' . strtolower($tag);
  3433. } else if (file_exists($ls)) {
  3434. $layout = 'layout--tag';
  3435. } else {
  3436. $layout = '';
  3437. }
  3438. $pv = $vroot . '/main--tag--' . strtolower($tag) . '.html.php';
  3439. $ps = $vroot . '/main--tag.html.php';
  3440. if (file_exists($pv)) {
  3441. $pview = 'main--tag--' . strtolower($tag);
  3442. } elseif (file_exists($ps)) {
  3443. $pview = 'main--tag';
  3444. } else {
  3445. $pview = 'main';
  3446. }
  3447. if ($page > 1) {
  3448. $CanonicalPageNum = '?page=' . $page;
  3449. } else {
  3450. $CanonicalPageNum = NULL;
  3451. }
  3452. render($pview, array(
  3453. 'title' => generate_title('is_tag', $ttag),
  3454. 'description' => $ttag->description,
  3455. 'canonical' => $ttag->url . $CanonicalPageNum,
  3456. 'metatags' => generate_meta('is_tag', $ttag),
  3457. 'page' => $page,
  3458. 'posts' => $posts,
  3459. 'tag' => $ttag,
  3460. 'taxonomy' => $ttag,
  3461. 'bodyclass' => 'in-tag tag-' . strtolower($tag),
  3462. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Posts_tagged') . ' ' . tag_i18n($tag),
  3463. 'pagination' => has_pagination($total, $perpage, $page),
  3464. 'is_tag' => true,
  3465. 'is_taxonomy' => true
  3466. ), $layout);
  3467. });
  3468. // Show the RSS feed
  3469. get('/tag/:tag/feed', function ($tag) {
  3470. header('Content-Type: application/rss+xml');
  3471. $posts = array();
  3472. $posts = get_tag($tag, 1, config('rss.count'));
  3473. if ($posts) {
  3474. $posts = $posts[0];
  3475. }
  3476. $data = new stdClass;
  3477. $data->title = tag_i18n($tag);
  3478. $data->url = site_url() . 'tag/' . strtolower($tag);
  3479. $data->body = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title();
  3480. // Show an RSS feed
  3481. echo generate_rss($posts, $data);
  3482. });
  3483. // Show the archive page
  3484. get('/archive/:req', function ($req) {
  3485. if (!login()) {
  3486. file_cache($_SERVER['REQUEST_URI']);
  3487. }
  3488. $page = from($_GET, 'page');
  3489. $page = $page ? (int)$page : 1;
  3490. $perpage = config('archive.perpage');
  3491. $total = '';
  3492. $posts = get_archive($req, $page, $perpage);
  3493. if (!empty($posts)) {
  3494. $total = $posts[1];
  3495. $posts = $posts[0];
  3496. }
  3497. if (empty($posts) || $page < 1) {
  3498. // a non-existing page
  3499. not_found();
  3500. }
  3501. $time = explode('-', $req);
  3502. $date = strtotime($req);
  3503. if (!$date) {
  3504. // a non-existing page
  3505. not_found();
  3506. }
  3507. if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
  3508. $timestamp = format_date($date, 'd F Y');
  3509. } elseif (isset($time[0]) && isset($time[1])) {
  3510. $timestamp = format_date($date, 'F Y');
  3511. } else {
  3512. $timestamp = $req;
  3513. }
  3514. $tarchive = new stdClass;
  3515. $tarchive->title = $timestamp;
  3516. $tarchive->url = site_url() . 'archive/' . $req;
  3517. $tarchive->count = $total;
  3518. $tarchive->description = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title();
  3519. $tarchive->body = $tarchive->description;
  3520. $tarchive->rss = $tarchive->url . '/feed';
  3521. $tarchive->slug = strtolower($req);
  3522. $vroot = rtrim(config('views.root'), '/');
  3523. $lt = $vroot . '/layout--archive.html.php';
  3524. if (file_exists($lt)) {
  3525. $layout = 'layout--archive';
  3526. } else {
  3527. $layout = '';
  3528. }
  3529. $pv = $vroot . '/main--archive.html.php';
  3530. if (file_exists($pv)) {
  3531. $pview = 'main--archive';
  3532. } else {
  3533. $pview = 'main';
  3534. }
  3535. if ($page > 1) {
  3536. $CanonicalPageNum = '?page=' . $page;
  3537. } else {
  3538. $CanonicalPageNum = NULL;
  3539. }
  3540. render($pview, array(
  3541. 'title' => generate_title('is_archive', $tarchive),
  3542. 'description' => $tarchive->description,
  3543. 'canonical' => $tarchive->url . $CanonicalPageNum,
  3544. 'metatags' => generate_meta('is_archive', $tarchive),
  3545. 'page' => $page,
  3546. 'posts' => $posts,
  3547. 'archive' => $tarchive,
  3548. 'taxonomy' => $tarchive,
  3549. 'bodyclass' => 'in-archive archive-' . strtolower($req),
  3550. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Archive_for') . ' ' . $timestamp,
  3551. 'pagination' => has_pagination($total, $perpage, $page),
  3552. 'is_archive' => true,
  3553. 'is_taxonomy' => true
  3554. ), $layout);
  3555. });
  3556. // Show the RSS feed
  3557. get('/archive/:req/feed', function ($req) {
  3558. header('Content-Type: application/rss+xml');
  3559. $posts = array();
  3560. $posts = get_archive($req, 1, config('rss.count'));
  3561. if ($posts) {
  3562. $posts = $posts[0];
  3563. }
  3564. $time = explode('-', $req);
  3565. $date = strtotime($req);
  3566. if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
  3567. $timestamp = format_date($date, 'd F Y');
  3568. } elseif (isset($time[0]) && isset($time[1])) {
  3569. $timestamp = format_date($date, 'F Y');
  3570. } else {
  3571. $timestamp = $req;
  3572. }
  3573. $data = new stdClass;
  3574. $data->title = $timestamp;
  3575. $data->url = site_url() . 'archive/' . $req;
  3576. $data->body = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title();
  3577. // Show an RSS feed
  3578. echo generate_rss($posts, $data);
  3579. });
  3580. // Show the search page
  3581. get('/search/:keyword', function ($keyword) {
  3582. if (!login()) {
  3583. file_cache($_SERVER['REQUEST_URI']);
  3584. }
  3585. $page = from($_GET, 'page');
  3586. $page = $page ? (int)$page : 1;
  3587. $perpage = config('search.perpage');
  3588. $total = '';
  3589. $posts = get_keyword($keyword, $page, $perpage);
  3590. if (!empty($posts)) {
  3591. $total = $posts[1];
  3592. $posts = $posts[0];
  3593. }
  3594. $vroot = rtrim(config('views.root'), '/');
  3595. $lt = $vroot . '/layout--search.html.php';
  3596. if (file_exists($lt)) {
  3597. $layout = 'layout--search';
  3598. } else {
  3599. $layout = '';
  3600. }
  3601. if (!$posts || $page < 1) {
  3602. // a non-existing page or no search result
  3603. render('404-search', array(
  3604. 'title' => i18n('Search_results_not_found') . ' - ' . blog_title(),
  3605. 'description' => i18n('Search_results_not_found'),
  3606. 'canonical' => site_url(),
  3607. 'metatags' => generate_meta(null, null),
  3608. 'search' => '',
  3609. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('No_search_results'),
  3610. 'canonical' => site_url(),
  3611. 'bodyclass' => 'error-404-search',
  3612. 'is_404search' => true,
  3613. ), $layout);
  3614. die;
  3615. }
  3616. $tsearch = new stdClass;
  3617. $tsearch->title = $keyword;
  3618. $tsearch->url = site_url() . 'search/' . strtolower($keyword);
  3619. $tsearch->count = $total;
  3620. $tsearch->description = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title();
  3621. $tsearch->body = $tsearch->description;
  3622. $tsearch->rss = $tsearch->url . '/feed';
  3623. $tsearch->slug = strtolower($keyword);
  3624. $pv = $vroot . '/main--search.html.php';
  3625. if (file_exists($pv)) {
  3626. $pview = 'main--search';
  3627. } else {
  3628. $pview = 'main';
  3629. }
  3630. if ($page > 1) {
  3631. $CanonicalPageNum = '?page=' . $page;
  3632. } else {
  3633. $CanonicalPageNum = NULL;
  3634. }
  3635. render($pview, array(
  3636. 'title' => generate_title('is_search', $tsearch),
  3637. 'description' => $tsearch->description,
  3638. 'canonical' => $tsearch->url . $CanonicalPageNum,
  3639. 'metatags' => generate_meta('is_search', $tsearch),
  3640. 'page' => $page,
  3641. 'posts' => $posts,
  3642. 'search' => $tsearch,
  3643. 'taxonomy' => $tsearch,
  3644. 'bodyclass' => 'in-search search-' . strtolower($keyword),
  3645. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Search_results_for') . ' ' . $keyword,
  3646. 'pagination' => has_pagination($total, $perpage, $page),
  3647. 'is_search' => true,
  3648. 'is_taxonomy' => true
  3649. ), $layout);
  3650. });
  3651. // Show the RSS feed
  3652. get('/search/:keyword/feed', function ($keyword) {
  3653. header('Content-Type: application/rss+xml');
  3654. $posts = array();
  3655. $posts = get_keyword($keyword, 1, config('rss.count'));
  3656. if ($posts) {
  3657. $posts = $posts[0];
  3658. }
  3659. $data = new stdClass;
  3660. $data->title = $keyword;
  3661. $data->url = site_url() . 'search/' . strtolower($keyword);
  3662. $data->body = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title();
  3663. // Show an RSS feed
  3664. echo generate_rss($posts, $data);
  3665. });
  3666. // The JSON API
  3667. get('/api/json', function () {
  3668. header('Content-type: application/json');
  3669. $page = from($_GET, 'page');
  3670. $page = $page ? (int)$page : 1;
  3671. $perpage = config('json.count');
  3672. echo generate_json(get_posts(null, $page, $perpage));
  3673. });
  3674. // Show the RSS feed
  3675. get('/feed/rss', function () {
  3676. header('Content-Type: application/rss+xml');
  3677. // Show an RSS feed with the 30 latest posts
  3678. echo generate_rss(get_posts(null, 1, config('rss.count')));
  3679. });
  3680. // Generate OPML file
  3681. get('/feed/opml', function () {
  3682. header('Content-Type: text/xml');
  3683. // Generate OPML file for the RSS
  3684. echo generate_opml();
  3685. });
  3686. // Show blog post without year-month
  3687. get('/'. permalink_type() .'/:name', function ($name) {
  3688. if (permalink_type() == 'default') {
  3689. $post = find_post(null, null, $name);
  3690. if (is_null($post)) {
  3691. not_found();
  3692. } else {
  3693. $current = $post['current'];
  3694. }
  3695. $redir = site_url() . date('Y/m', $current->date) . '/' . $name;
  3696. header("location: $redir", TRUE, 301);
  3697. }
  3698. if (config("views.counter") != "true") {
  3699. if (!login()) {
  3700. file_cache($_SERVER['REQUEST_URI']);
  3701. }
  3702. } else {
  3703. add_view('post_' . $name);
  3704. if (!login()) {
  3705. file_cache($_SERVER['REQUEST_URI']);
  3706. }
  3707. }
  3708. $post = find_post(null, null, $name);
  3709. if (is_null($post)) {
  3710. not_found('post_' . $name);
  3711. } else {
  3712. $current = $post['current'];
  3713. }
  3714. $author = new stdClass;
  3715. $author->url = $current->authorUrl;
  3716. $author->name = $current->authorName;
  3717. $author->description = $current->authorDescription;
  3718. $author->about = $current->authorAbout;
  3719. $author->avatar = $current->authorAvatar;
  3720. $author->rss = $current->authorRss;
  3721. $author->slug = $current->author;
  3722. if (array_key_exists('prev', $post)) {
  3723. $prev = $post['prev'];
  3724. } else {
  3725. $prev = array();
  3726. }
  3727. if (array_key_exists('next', $post)) {
  3728. $next = $post['next'];
  3729. } else {
  3730. $next = array();
  3731. }
  3732. if (isset($current->image)) {
  3733. $var = 'imagePost';
  3734. } elseif (isset($current->link)) {
  3735. $var = 'linkPost';
  3736. } elseif (isset($current->quote)) {
  3737. $var = 'quotePost';
  3738. } elseif (isset($current->audio)) {
  3739. $var = 'audioPost';
  3740. } elseif (isset($current->video)) {
  3741. $var = 'videoPost'; }
  3742. else {
  3743. $var = 'blogPost';
  3744. }
  3745. if (config('blog.enable') === 'true') {
  3746. $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . blog_path() .'"><span itemprop="name">' . blog_string() . '</span></a><meta itemprop="position" content="2" /></li> &#187; ';
  3747. } else {
  3748. $blog = '';
  3749. }
  3750. $vroot = rtrim(config('views.root'), '/');
  3751. $lt = $vroot . '/layout--post--' . $current->ct . '.html.php';
  3752. $pt = $vroot . '/layout--post--' . $current->type . '.html.php';
  3753. $ls = $vroot . '/layout--post.html.php';
  3754. if (file_exists($lt)) {
  3755. $layout = 'layout--post--' . $current->ct;
  3756. } else if (file_exists($pt)) {
  3757. $layout = 'layout--post--' . $current->type;
  3758. } else if (file_exists($ls)) {
  3759. $layout = 'layout--post';
  3760. } else {
  3761. $layout = '';
  3762. }
  3763. $pv = $vroot . '/post--' . $current->ct . '.html.php';
  3764. $pvt = $vroot . '/post--' . $current->type . '.html.php';
  3765. if (file_exists($pv)) {
  3766. $pview = 'post--' . $current->ct;
  3767. } else if(file_exists($pvt)) {
  3768. $pview = 'post--' . $current->type;
  3769. } else {
  3770. $pview = 'post';
  3771. }
  3772. render($pview, array(
  3773. 'title' => generate_title('is_post', $current),
  3774. 'description' => $current->description,
  3775. 'canonical' => $current->url,
  3776. 'metatags' => generate_meta('is_post', $current),
  3777. 'p' => $current,
  3778. 'post' => $current,
  3779. 'author' => $author,
  3780. 'bodyclass' => 'in-post category-' . $current->ct . ' type-' . $current->type,
  3781. 'breadcrumb' => '<style>.breadcrumb-list {margin:0; padding:0;} .breadcrumb-list li {display: inline-block; list-style: none;}</style><ol class="breadcrumb-list" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . '"><span itemprop="name">' . config('breadcrumb.home') . '</span></a><meta itemprop="position" content="1" /></li> &#187; '. $blog . '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">' . $current->categoryb . '<meta itemprop="position" content="3" /></li>' . ' &#187; ' . $current->title . '</ol>',
  3782. 'prev' => has_prev($prev),
  3783. 'next' => has_next($next),
  3784. 'type' => $var,
  3785. 'is_post' => true
  3786. ), $layout);
  3787. });
  3788. // Edit blog post
  3789. get('/'. permalink_type() .'/:name/edit', function ($name) {
  3790. if (login()) {
  3791. $user = $_SESSION[site_url()]['user'];
  3792. $role = user('role', $user);
  3793. config('views.root', 'system/admin/views');
  3794. $post = find_post(null, null, $name);
  3795. if (!$post) {
  3796. $post = find_draft(null, null, $name);
  3797. if (!$post) {
  3798. $post = find_scheduled(null, null, $name);
  3799. if (!$post) {
  3800. not_found();
  3801. }
  3802. }
  3803. }
  3804. $current = $post['current'];
  3805. if (isset($current->image)) {
  3806. $type= 'is_image';
  3807. } elseif (isset($current->link)) {
  3808. $type = 'is_link';
  3809. } elseif (isset($current->quote)) {
  3810. $type = 'is_quote';
  3811. } elseif (isset($current->audio)) {
  3812. $type = 'is_audio';
  3813. } elseif (isset($current->video)) {
  3814. $type = 'is_video';
  3815. } else {
  3816. $type = 'is_post';
  3817. }
  3818. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  3819. render('edit-content', array(
  3820. 'title' => generate_title('is_default', $current->title),
  3821. 'description' => safe_html(strip_tags(blog_description())),
  3822. 'canonical' => site_url(),
  3823. 'metatags' => generate_meta(null, null),
  3824. 'p' => $current,
  3825. 'post' => $current,
  3826. 'type' => $type,
  3827. 'is_admin' => true,
  3828. 'bodyclass' => 'edit-post',
  3829. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  3830. ));
  3831. } else {
  3832. render('denied', array(
  3833. 'title' => generate_title('is_default', $current->title),
  3834. 'description' => safe_html(strip_tags(blog_description())),
  3835. 'canonical' => site_url(),
  3836. 'metatags' => generate_meta(null, null),
  3837. 'p' => $current,
  3838. 'post' => $current,
  3839. 'bodyclass' => 'denied',
  3840. 'is_admin' => true,
  3841. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  3842. ));
  3843. }
  3844. } else {
  3845. $login = site_url() . 'login';
  3846. header("location: $login");
  3847. }
  3848. });
  3849. // Get edited data from blog post
  3850. post('/'. permalink_type() .'/:name/edit', function () {
  3851. if(!login()) {
  3852. $login = site_url() . 'login';
  3853. header("location: $login");
  3854. }
  3855. $field = array();
  3856. $aField = array();
  3857. $field_file = 'content/data/field/post.json';
  3858. if (file_exists($field_file)) {
  3859. $aField = json_decode(file_get_contents($field_file, true));
  3860. }
  3861. if(!empty($aField)) {
  3862. foreach ($aField as $af) {
  3863. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  3864. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  3865. } else {
  3866. $field[$af->name] = from($_REQUEST, $af->name);
  3867. }
  3868. }
  3869. }
  3870. // The "AI was used" flag. Unchecked means empty, so no tag is written.
  3871. $field['ai'] = from($_REQUEST, 'ai') ? 'yes' : '';
  3872. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3873. $title = from($_REQUEST, 'title');
  3874. $is_post = from($_REQUEST, 'is_post');
  3875. $image = from($_REQUEST, 'image');
  3876. $is_image = from($_REQUEST, 'is_image');
  3877. $video = from($_REQUEST, 'video');
  3878. $is_video = from($_REQUEST, 'is_video');
  3879. $link = from($_REQUEST, 'link');
  3880. $is_link = from($_REQUEST, 'is_link');
  3881. $audio = from($_REQUEST, 'audio');
  3882. $is_audio = from($_REQUEST, 'is_audio');
  3883. $quote = from($_REQUEST, 'quote');
  3884. $is_quote = from($_REQUEST, 'is_quote');
  3885. $tag = from($_REQUEST, 'tag');
  3886. $url = from($_REQUEST, 'url');
  3887. $content = from($_REQUEST, 'content');
  3888. $oldfile = from($_REQUEST, 'oldfile');
  3889. $destination = from($_GET, 'destination');
  3890. $description = from($_REQUEST, 'description');
  3891. $date = from($_REQUEST, 'date');
  3892. $time = from($_REQUEST, 'time');
  3893. $dateTime = null;
  3894. $revertPost = from($_REQUEST, 'revertpost');
  3895. $publishDraft = from($_REQUEST, 'publishdraft');
  3896. $category = from($_REQUEST, 'category');
  3897. if ($date !== null && $time !== null) {
  3898. $dateTime = $date . ' ' . $time;
  3899. }
  3900. if (!empty($is_image)) {
  3901. $type = 'is_image';
  3902. } elseif (!empty($is_video)) {
  3903. $type = 'is_video';
  3904. } elseif (!empty($is_link)) {
  3905. $type = 'is_link';
  3906. } elseif (!empty($is_quote)) {
  3907. $type = 'is_quote';
  3908. } elseif (!empty($is_audio)) {
  3909. $type = 'is_audio';
  3910. } elseif (!empty($is_post)) {
  3911. $type = 'is_post';
  3912. }
  3913. if (empty($url)) {
  3914. $url = $title;
  3915. }
  3916. $arr = explode('/', $oldfile);
  3917. $user = $_SESSION[site_url()]['user'];
  3918. $role = user('role', $user);
  3919. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  3920. if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
  3921. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image,null, $field);
  3922. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
  3923. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video,null, $field);
  3924. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
  3925. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link,null, $field);
  3926. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
  3927. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote,null, $field);
  3928. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
  3929. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio,null, $field);
  3930. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
  3931. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null,null, $field);
  3932. } else {
  3933. $message['error'] = '';
  3934. if (empty($title)) {
  3935. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  3936. }
  3937. if (empty($tag)) {
  3938. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_tag') . '</li>';
  3939. }
  3940. if (empty($content)) {
  3941. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  3942. }
  3943. if (!$proper) {
  3944. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  3945. }
  3946. if (!empty($is_image)) {
  3947. if (empty($image)) {
  3948. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_image') . '</li>';
  3949. }
  3950. } elseif (!empty($is_video)) {
  3951. if (empty($video)) {
  3952. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_video') . '</li>';
  3953. }
  3954. } elseif (!empty($is_link)) {
  3955. if (empty($link)) {
  3956. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_link') . '</li>';
  3957. }
  3958. } elseif (!empty($is_quote)) {
  3959. if (empty($quote)) {
  3960. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_quote') . '</li>';
  3961. }
  3962. } elseif (!empty($is_audio)) {
  3963. if (empty($audio)) {
  3964. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_audio') . '</li>';
  3965. }
  3966. }
  3967. config('views.root', 'system/admin/views');
  3968. render('edit-content', array(
  3969. 'title' => generate_title('is_default', $title),
  3970. 'description' => safe_html(strip_tags(blog_description())),
  3971. 'canonical' => site_url(),
  3972. 'metatags' => generate_meta(null, null),
  3973. 'error' => '<ul>' . $message['error'] . '</ul>',
  3974. 'oldfile' => $oldfile,
  3975. 'postTitle' => $title,
  3976. 'postImage' => $image,
  3977. 'postVideo' => $video,
  3978. 'postLink' => $link,
  3979. 'postQuote' => $quote,
  3980. 'postAudio' => $audio,
  3981. 'postTag' => $tag,
  3982. 'postUrl' => $url,
  3983. 'type' => $type,
  3984. 'is_admin' => true,
  3985. 'postContent' => $content,
  3986. 'bodyclass' => 'edit-post',
  3987. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit_content')
  3988. ));
  3989. }
  3990. } else {
  3991. $redir = site_url();
  3992. header("location: $redir");
  3993. }
  3994. });
  3995. // Delete blog post
  3996. get('/'. permalink_type() .'/:name/delete', function ($name) {
  3997. if (login()) {
  3998. $user = $_SESSION[site_url()]['user'];
  3999. $role = user('role', $user);
  4000. config('views.root', 'system/admin/views');
  4001. $post = find_post(null, null, $name);
  4002. if (!$post) {
  4003. $post = find_draft(null, null, $name);
  4004. if (!$post) {
  4005. $post = find_scheduled(null, null, $name);
  4006. if (!$post) {
  4007. not_found();
  4008. }
  4009. }
  4010. }
  4011. $current = $post['current'];
  4012. if (config('blog.enable') === 'true') {
  4013. $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . 'blog"><span itemprop="name">Blog</span></a><meta itemprop="position" content="2" /></li> &#187; ';
  4014. } else {
  4015. $blog = '';
  4016. }
  4017. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  4018. render('delete-post', array(
  4019. 'title' => generate_title('is_default', i18n('Delete')),
  4020. 'description' => safe_html(strip_tags(blog_description())),
  4021. 'canonical' => site_url(),
  4022. 'metatags' => generate_meta(null, null),
  4023. 'p' => $current,
  4024. 'post' => $current,
  4025. 'is_admin' => true,
  4026. 'bodyclass' => 'delete-post',
  4027. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4028. ));
  4029. } else {
  4030. render('denied', array(
  4031. 'title' => generate_title('is_default', 'Delete post'),
  4032. 'description' => safe_html(strip_tags(blog_description())),
  4033. 'canonical' => site_url(),
  4034. 'metatags' => generate_meta(null, null),
  4035. 'p' => $current,
  4036. 'post' => $current,
  4037. 'is_admin' => true,
  4038. 'bodyclass' => 'delete-post',
  4039. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4040. ));
  4041. }
  4042. } else {
  4043. $login = site_url() . 'login';
  4044. header("location: $login");
  4045. }
  4046. });
  4047. // Get deleted data from blog post
  4048. post('/'. permalink_type() .'/:name/delete', function () {
  4049. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4050. if ($proper && login()) {
  4051. $file = from($_REQUEST, 'file');
  4052. $destination = from($_GET, 'destination');
  4053. $arr = explode('/', $file);
  4054. $user = $_SESSION[site_url()]['user'];
  4055. $role = user('role', $user);
  4056. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  4057. delete_post($file, $destination);
  4058. } else {
  4059. $redir = site_url();
  4060. header("location: $redir");
  4061. }
  4062. }
  4063. });
  4064. // Show various page (top-level), admin, login, sitemap, static page.
  4065. get('/:static', function ($static) {
  4066. if (strpos($static, ".xml") !== false) {
  4067. if ($static === 'sitemap.xml') {
  4068. $sitemap = 'index.xml';
  4069. } else {
  4070. $sitemap = str_replace('sitemap.', '', $static);
  4071. }
  4072. header('Content-Type: text/xml');
  4073. generate_sitemap($sitemap);
  4074. die;
  4075. } elseif ($static === 'admin') {
  4076. if (login()) {
  4077. config('views.root', 'system/admin/views');
  4078. render('main', array(
  4079. 'title' => generate_title('is_default', i18n('Admin')),
  4080. 'description' => safe_html(strip_tags(blog_description())),
  4081. 'canonical' => site_url(),
  4082. 'metatags' => generate_meta(null, null),
  4083. 'bodyclass' => 'admin-front',
  4084. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Admin')
  4085. ));
  4086. } else {
  4087. $login = site_url() . 'login';
  4088. header("location: $login");
  4089. }
  4090. die;
  4091. } elseif ($static === 'login') {
  4092. if (session_status() == PHP_SESSION_NONE) session_start();
  4093. config('views.root', 'system/admin/views');
  4094. render('login', array(
  4095. 'title' => generate_title('is_default', i18n('Login')),
  4096. 'description' => 'Login page from ' . blog_title() . '.',
  4097. 'canonical' => site_url() . '/login',
  4098. 'metatags' => generate_meta(null, null),
  4099. 'bodyclass' => 'in-login',
  4100. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  4101. ));
  4102. die;
  4103. } elseif ($static === 'logout') {
  4104. if (login()) {
  4105. config('views.root', 'system/admin/views');
  4106. render('logout', array(
  4107. 'title' => generate_title('is_default', i18n('Logout')),
  4108. 'description' => safe_html(strip_tags(blog_description())),
  4109. 'canonical' => site_url(),
  4110. 'metatags' => generate_meta(null, null),
  4111. 'bodyclass' => 'in-logout',
  4112. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Logout')
  4113. ));
  4114. } else {
  4115. $login = site_url() . 'login';
  4116. header("location: $login");
  4117. }
  4118. die;
  4119. } elseif ($static === blog_path()) {
  4120. if(config('blog.enable') !== 'true') {
  4121. $url = site_url();
  4122. header("Location: $url");
  4123. }
  4124. if (!login()) {
  4125. file_cache($_SERVER['REQUEST_URI']);
  4126. }
  4127. $page = from($_GET, 'page');
  4128. $page = $page ? (int)$page : 1;
  4129. $perpage = config('posts.perpage');
  4130. $posts = get_posts(null, $page, $perpage);
  4131. $total = count(get_blog_posts());
  4132. $vroot = rtrim(config('views.root'), '/');
  4133. $lt = $vroot . '/layout--blog.html.php';
  4134. if (file_exists($lt)) {
  4135. $layout = 'layout--blog';
  4136. } else {
  4137. $layout = '';
  4138. }
  4139. $pv = $vroot . '/main--blog.html.php';
  4140. if (file_exists($pv)) {
  4141. $pview = 'main--blog';
  4142. } else {
  4143. $pview = 'main';
  4144. }
  4145. $tblog = new stdClass;
  4146. $tblog->title = blog_string();
  4147. $tblog->url = site_url() . blog_path();
  4148. $tblog->count = count(get_blog_posts());
  4149. $tblog->description = i18n('all_blog_posts') . ' ' . i18n('by') . ' ' . blog_title();
  4150. $tblog->body = $tblog->description;
  4151. $tblog->rss = site_url() . 'feed/rss';
  4152. $tblog->slug = blog_path();
  4153. if (empty($posts) || $page < 1) {
  4154. // a non-existing page
  4155. render('no-posts', array(
  4156. 'title' => generate_title('is_blog', null),
  4157. 'description' => blog_title() . ' ' . blog_string(),
  4158. 'canonical' => site_url(),
  4159. 'metatags' => generate_meta('is_blog', null),
  4160. 'bodyclass' => 'no-posts',
  4161. 'is_front' => true,
  4162. ), $layout);
  4163. die;
  4164. }
  4165. if ($page > 1) {
  4166. $CanonicalPageNum = '?page=' . $page;
  4167. } else {
  4168. $CanonicalPageNum = NULL;
  4169. }
  4170. render($pview, array(
  4171. 'title' => generate_title('is_blog', null),
  4172. 'description' => blog_title() . ' ' . blog_string(),
  4173. 'canonical' => site_url() . blog_path() . $CanonicalPageNum,
  4174. 'metatags' => generate_meta('is_blog', null),
  4175. 'page' => $page,
  4176. 'posts' => $posts,
  4177. 'taxonomy' => $tblog,
  4178. 'bodyclass' => 'in-blog',
  4179. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . blog_string(),
  4180. 'pagination' => has_pagination($total, $perpage, $page),
  4181. 'is_blog' => true,
  4182. 'is_taxonomy' => true
  4183. ), $layout);
  4184. } elseif ($static === 'front') {
  4185. $redir = site_url();
  4186. header("location: $redir", TRUE, 301);
  4187. } else {
  4188. $pages = '';
  4189. if (config("views.counter") != "true") {
  4190. if (!login()) {
  4191. file_cache($_SERVER['REQUEST_URI']);
  4192. }
  4193. } else {
  4194. $pages = get_static_pages();
  4195. if (!empty($pages)) {
  4196. foreach ($pages as $index => $v) {
  4197. if (stripos($v['basename'], $static . '.md') !== false) {
  4198. add_view('page_' . $static);
  4199. }
  4200. }
  4201. }
  4202. if (!login()) {
  4203. file_cache($_SERVER['REQUEST_URI']);
  4204. }
  4205. }
  4206. $post = find_page($static, $pages);
  4207. if (!$post) {
  4208. not_found('page_' . $static);
  4209. }
  4210. if (array_key_exists('prev', $post)) {
  4211. $prev = $post['prev'];
  4212. } else {
  4213. $prev = array();
  4214. }
  4215. if (array_key_exists('next', $post)) {
  4216. $next = $post['next'];
  4217. } else {
  4218. $next = array();
  4219. }
  4220. $post = $post['current'];
  4221. $vroot = rtrim(config('views.root'), '/');
  4222. $lt = $vroot . '/layout--' . strtolower($static) . '.html.php';
  4223. $ls = $vroot . '/layout--static.html.php';
  4224. if (file_exists($lt)) {
  4225. $layout = 'layout--' . strtolower($static);
  4226. } else if (file_exists($ls)) {
  4227. $layout = 'layout--static';
  4228. } else {
  4229. $layout = '';
  4230. }
  4231. $pv = $vroot . '/static--' . strtolower($static) . '.html.php';
  4232. if (file_exists($pv)) {
  4233. $pview = 'static--' . strtolower($static);
  4234. } else {
  4235. $pview = 'static';
  4236. }
  4237. render($pview, array(
  4238. 'title' => generate_title('is_page', $post),
  4239. 'description' => $post->description,
  4240. 'canonical' => $post->url,
  4241. 'metatags' => generate_meta('is_page', $post),
  4242. 'bodyclass' => 'in-page ' . strtolower($static),
  4243. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $post->title,
  4244. 'p' => $post,
  4245. 'static' => $post,
  4246. 'type' => 'is_page',
  4247. 'prev' => static_prev($prev),
  4248. 'next' => static_next($next),
  4249. 'is_page' => true
  4250. ), $layout);
  4251. }
  4252. });
  4253. // Show the add sub static page
  4254. get('/:static/add', function ($static) {
  4255. $user = $_SESSION[site_url()]['user'];
  4256. $role = user('role', $user);
  4257. if (login()) {
  4258. config('views.root', 'system/admin/views');
  4259. if ($role === 'editor' || $role === 'admin') {
  4260. $post = find_page($static);
  4261. if (!$post) {
  4262. not_found();
  4263. }
  4264. $post = $post['current'];
  4265. render('add-page', array(
  4266. 'title' => generate_title('is_default', i18n('Add_new_page')),
  4267. 'description' => safe_html(strip_tags(blog_description())),
  4268. 'canonical' => site_url(),
  4269. 'metatags' => generate_meta(null, null),
  4270. 'type' => 'is_subpage',
  4271. 'parent' => $static,
  4272. 'is_admin' => true,
  4273. 'bodyclass' => 'add-page',
  4274. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . i18n('Add_new_page')
  4275. ));
  4276. } else {
  4277. render('denied', array(
  4278. 'title' => generate_title('is_default', i18n('Denied')),
  4279. 'description' => safe_html(strip_tags(blog_description())),
  4280. 'canonical' => site_url(),
  4281. 'metatags' => generate_meta(null, null),
  4282. 'type' => 'is_admin-config',
  4283. 'is_admin' => true,
  4284. 'bodyclass' => 'denied',
  4285. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4286. ));
  4287. }
  4288. } else {
  4289. $login = site_url() . 'login';
  4290. header("location: $login");
  4291. }
  4292. });
  4293. // Submitted data from add sub static page
  4294. post('/:static/add', function ($static) {
  4295. if(!login()) {
  4296. $login = site_url() . 'login';
  4297. header("location: $login");
  4298. }
  4299. $field = array();
  4300. $aField = array();
  4301. $field_file= 'content/data/field/subpage.json';
  4302. if (file_exists($field_file)) {
  4303. $aField = json_decode(file_get_contents($field_file, true));
  4304. }
  4305. if(!empty($aField)) {
  4306. foreach ($aField as $af) {
  4307. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  4308. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  4309. } else {
  4310. $field[$af->name] = from($_REQUEST, $af->name);
  4311. }
  4312. }
  4313. }
  4314. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4315. $title = from($_REQUEST, 'title');
  4316. $url = from($_REQUEST, 'url');
  4317. $content = from($_REQUEST, 'content');
  4318. $description = from($_REQUEST, 'description');
  4319. $draft = from($_REQUEST, 'draft');
  4320. $user = $_SESSION[site_url()]['user'];
  4321. $role = user('role', $user);
  4322. if (empty($url)) {
  4323. $url = $title;
  4324. }
  4325. if ($role === 'editor' || $role === 'admin') {
  4326. if ($proper && !empty($title) && !empty($content)) {
  4327. add_sub_page($title, $url, $content, $static, $draft, $description, null, null, $field);
  4328. } else {
  4329. $message['error'] = '';
  4330. if (empty($title)) {
  4331. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  4332. }
  4333. if (empty($content)) {
  4334. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  4335. }
  4336. if (!$proper) {
  4337. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  4338. }
  4339. config('views.root', 'system/admin/views');
  4340. render('add-page', array(
  4341. 'title' => generate_title('is_default', i18n('Add_new_page')),
  4342. 'description' => safe_html(strip_tags(blog_description())),
  4343. 'canonical' => site_url(),
  4344. 'metatags' => generate_meta(null, null),
  4345. 'error' => '<ul>' . $message['error'] . '</ul>',
  4346. 'postTitle' => $title,
  4347. 'postUrl' => $url,
  4348. 'postContent' => $content,
  4349. 'type' => 'is_subpage',
  4350. 'is_admin' => true,
  4351. 'bodyclass' => 'add-page',
  4352. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $title . '">' . $title . '</a> &#187; ' . i18n('Add_new_page')
  4353. ));
  4354. }
  4355. } else {
  4356. $redir = site_url();
  4357. header("location: $redir");
  4358. }
  4359. });
  4360. // Show edit the static page
  4361. get('/:static/edit', function ($static) {
  4362. $user = $_SESSION[site_url()]['user'];
  4363. $role = user('role', $user);
  4364. if (login()) {
  4365. config('views.root', 'system/admin/views');
  4366. if ($role === 'editor' || $role === 'admin') {
  4367. $post = find_page($static);
  4368. if (!$post) {
  4369. $post = find_draft_page($static);
  4370. if (!$post) {
  4371. not_found();
  4372. } else {
  4373. $post = $post[0];
  4374. }
  4375. } else {
  4376. $post = $post['current'];
  4377. }
  4378. render('edit-page', array(
  4379. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $post->title),
  4380. 'description' => safe_html(strip_tags(blog_description())),
  4381. 'canonical' => site_url(),
  4382. 'metatags' => generate_meta(null, null),
  4383. 'bodyclass' => 'edit-page',
  4384. 'is_admin' => true,
  4385. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="'. site_url() .'admin/pages">' .i18n('pages').'</a> &#187; ' . $post->title,
  4386. 'p' => $post,
  4387. 'static' => $post,
  4388. 'type' => 'is_page',
  4389. 'parent' => ''
  4390. ));
  4391. } else {
  4392. render('denied', array(
  4393. 'title' => generate_title('is_default', i18n('Denied')),
  4394. 'description' => safe_html(strip_tags(blog_description())),
  4395. 'canonical' => site_url(),
  4396. 'metatags' => generate_meta(null, null),
  4397. 'type' => 'is_page',
  4398. 'is_admin' => true,
  4399. 'bodyclass' => 'denied',
  4400. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4401. ));
  4402. }
  4403. } else {
  4404. $login = site_url() . 'login';
  4405. header("location: $login");
  4406. }
  4407. });
  4408. // Get edited data from static page
  4409. post('/:static/edit', function () {
  4410. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4411. if(!login()) {
  4412. $login = site_url() . 'login';
  4413. header("location: $login");
  4414. }
  4415. $field = array();
  4416. $aField = array();
  4417. $field_file = 'content/data/field/page.json';
  4418. if (file_exists($field_file)) {
  4419. $aField = json_decode(file_get_contents($field_file, true));
  4420. }
  4421. if(!empty($aField)) {
  4422. foreach ($aField as $af) {
  4423. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  4424. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  4425. } else {
  4426. $field[$af->name] = from($_REQUEST, $af->name);
  4427. }
  4428. }
  4429. }
  4430. $title = from($_REQUEST, 'title');
  4431. $url = from($_REQUEST, 'url');
  4432. $content = from($_REQUEST, 'content');
  4433. $oldfile = from($_REQUEST, 'oldfile');
  4434. $destination = from($_GET, 'destination');
  4435. $description = from($_REQUEST, 'description');
  4436. $revertPage = from($_REQUEST, 'revertpage');
  4437. $publishDraft = from($_REQUEST, 'publishdraft');
  4438. $user = $_SESSION[site_url()]['user'];
  4439. $role = user('role', $user);
  4440. if (empty($url)) {
  4441. $url = $title;
  4442. }
  4443. if ($role === 'editor' || $role === 'admin') {
  4444. if ($proper && !empty($title) && !empty($content)) {
  4445. edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, null, null, $field);
  4446. } else {
  4447. $message['error'] = '';
  4448. if (empty($title)) {
  4449. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  4450. }
  4451. if (empty($content)) {
  4452. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  4453. }
  4454. if (!$proper) {
  4455. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  4456. }
  4457. config('views.root', 'system/admin/views');
  4458. render('edit-page', array(
  4459. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $title),
  4460. 'description' => safe_html(strip_tags(blog_description())),
  4461. 'canonical' => site_url(),
  4462. 'metatags' => generate_meta(null, null),
  4463. 'error' => '<ul>' . $message['error'] . '</ul>',
  4464. 'oldfile' => $oldfile,
  4465. 'postTitle' => $title,
  4466. 'postUrl' => $url,
  4467. 'postContent' => $content,
  4468. 'bodyclass' => 'edit-page',
  4469. 'is_admin' => true,
  4470. 'type' => 'is_page',
  4471. 'parent' => '',
  4472. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit')
  4473. ));
  4474. }
  4475. } else {
  4476. $redir = site_url();
  4477. header("location: $redir");
  4478. }
  4479. });
  4480. // Deleted the static page
  4481. get('/:static/delete', function ($static) {
  4482. $user = $_SESSION[site_url()]['user'];
  4483. $role = user('role', $user);
  4484. if (login()) {
  4485. config('views.root', 'system/admin/views');
  4486. if ($role === 'editor' || $role === 'admin') {
  4487. $post = find_page($static);
  4488. if (!$post) {
  4489. $post = find_draft_page($static);
  4490. if (!$post) {
  4491. not_found();
  4492. } else {
  4493. $post = $post[0];
  4494. }
  4495. } else {
  4496. $post = $post['current'];
  4497. }
  4498. render('delete-page', array(
  4499. 'title' => generate_title('is_default', i18n('Delete') . ': ' . $post->title),
  4500. 'description' => safe_html(strip_tags(blog_description())),
  4501. 'canonical' => site_url(),
  4502. 'metatags' => generate_meta(null, null),
  4503. 'bodyclass' => 'delete-page',
  4504. 'is_admin' => true,
  4505. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Delete') . ': ' . $post->title,
  4506. 'p' => $post,
  4507. 'static' => $post,
  4508. 'type' => 'is_page',
  4509. ));
  4510. } else {
  4511. render('denied', array(
  4512. 'title' => generate_title('is_default', i18n('Denied')),
  4513. 'description' => safe_html(strip_tags(blog_description())),
  4514. 'canonical' => site_url(),
  4515. 'metatags' => generate_meta(null, null),
  4516. 'type' => 'is_admin-config',
  4517. 'is_admin' => true,
  4518. 'bodyclass' => 'denied',
  4519. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4520. ));
  4521. }
  4522. } else {
  4523. $login = site_url() . 'login';
  4524. header("location: $login");
  4525. }
  4526. });
  4527. // Get deleted data for static page
  4528. post('/:static/delete', function () {
  4529. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4530. if ($proper && login()) {
  4531. $user = $_SESSION[site_url()]['user'];
  4532. $role = user('role', $user);
  4533. if ($role === 'editor' || $role === 'admin') {
  4534. $file = from($_REQUEST, 'file');
  4535. $destination = from($_GET, 'destination');
  4536. delete_page($file, $destination);
  4537. } else {
  4538. $redir = site_url();
  4539. header("location: $redir");
  4540. }
  4541. }
  4542. });
  4543. // Show the sb static page
  4544. get('/:static/:sub', function ($static, $sub) {
  4545. if ($static === 'front') {
  4546. $redir = site_url();
  4547. header("location: $redir", TRUE, 301);
  4548. }
  4549. $sub_pages = '';
  4550. if (config("views.counter") != "true") {
  4551. if (!login()) {
  4552. file_cache($_SERVER['REQUEST_URI']);
  4553. }
  4554. } else {
  4555. $sub_pages = array_values(get_static_subpages($static));
  4556. if (!empty($sub_pages)) {
  4557. foreach ($sub_pages as $index => $v) {
  4558. if (stripos($v['basename'], $sub . '.md') !== false) {
  4559. add_view('subpage_' . $static.'.'.$sub);
  4560. }
  4561. }
  4562. }
  4563. if (!login()) {
  4564. file_cache($_SERVER['REQUEST_URI']);
  4565. }
  4566. }
  4567. $parent_post = find_page($static);
  4568. if (!$parent_post) {
  4569. not_found('subpage_' . $static.'.'.$sub);
  4570. }
  4571. $post = find_subpage($static, $sub, $sub_pages);
  4572. if (!$post) {
  4573. not_found('subpage_' . $static.'.'.$sub);
  4574. }
  4575. if (array_key_exists('prev', $post)) {
  4576. $prev = $post['prev'];
  4577. } else {
  4578. $prev = array();
  4579. }
  4580. if (array_key_exists('next', $post)) {
  4581. $next = $post['next'];
  4582. } else {
  4583. $next = array();
  4584. }
  4585. $post = $post['current'];
  4586. $vroot = rtrim(config('views.root'), '/');
  4587. $lt = $vroot . '/layout--' . strtolower($static) . '--' . strtolower($sub) . '.html.php';
  4588. $ls = $vroot . '/layout--' . strtolower($static) . '.html.php';
  4589. $lf = $vroot . '/layout--static.html.php';
  4590. $lsp = $vroot . '/layout--' . strtolower($sub) . '.html.php';
  4591. $lsps = $vroot . '/layout--substatic.html.php';
  4592. if (file_exists($lt)) {
  4593. $layout = 'layout--' . strtolower($static) . '--' . strtolower($sub);
  4594. } else if (file_exists($lsp)) {
  4595. $layout = 'layout--' . strtolower($sub);
  4596. } else if (file_exists($lsps)) {
  4597. $layout = 'layout--substatic';
  4598. } else if (file_exists($ls)) {
  4599. $layout = 'layout--' . strtolower($static);
  4600. } else if (file_exists($lf)) {
  4601. $layout = 'layout--static';
  4602. } else {
  4603. $layout = '';
  4604. }
  4605. $pv = $vroot . '/static--' . strtolower($static) . '--' . strtolower($sub) . '.html.php';
  4606. $ps = $vroot . '/static--' . strtolower($static) . '.html.php';
  4607. $psp = $vroot . '/substatic--' . strtolower($sub) . '.html.php';
  4608. $psps = $vroot . '/substatic.html.php';
  4609. if (file_exists($pv)) {
  4610. $pview = 'static--' . strtolower($static) . '--' . strtolower($sub);
  4611. } else if (file_exists($psp)) {
  4612. $pview = 'substatic--' . strtolower($sub);
  4613. } else if (file_exists($psps)) {
  4614. $pview = 'substatic';
  4615. } else if (file_exists($ps)) {
  4616. $pview = 'static--' . strtolower($static);
  4617. } else {
  4618. $pview = 'static';
  4619. }
  4620. render($pview, array(
  4621. 'title' => generate_title('is_subpage', $post),
  4622. 'description' => $post->description,
  4623. 'canonical' => $post->url,
  4624. 'metatags' => generate_meta('is_subpage', $post),
  4625. 'bodyclass' => 'in-page ' . strtolower($static) . ' ' . strtolower($sub) ,
  4626. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $parent_post['current']->url . '">' . $parent_post['current']->title . '</a> &#187; ' . $post->title,
  4627. 'p' => $post,
  4628. 'static' => $post,
  4629. 'parent' => $parent_post,
  4630. 'prev' => static_prev($prev),
  4631. 'next' => static_next($next),
  4632. 'type' => 'is_subpage',
  4633. 'is_subpage' => true
  4634. ), $layout);
  4635. });
  4636. // Edit the sub static page
  4637. get('/:static/:sub/edit', function ($static, $sub) {
  4638. $user = $_SESSION[site_url()]['user'];
  4639. $role = user('role', $user);
  4640. if (login()) {
  4641. config('views.root', 'system/admin/views');
  4642. if ($role === 'editor' || $role === 'admin') {
  4643. $post = find_page($static);
  4644. if (!$post) {
  4645. not_found();
  4646. }
  4647. $post = $post['current'];
  4648. $page = find_subpage($static, $sub);
  4649. if (!$page) {
  4650. $page = find_draft_subpage($static, $sub);
  4651. if (!$page) {
  4652. not_found();
  4653. } else {
  4654. $page = $page[0];
  4655. }
  4656. } else {
  4657. $page = $page['current'];
  4658. }
  4659. render('edit-page', array(
  4660. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $page->title),
  4661. 'description' => safe_html(strip_tags(blog_description())),
  4662. 'canonical' => site_url(),
  4663. 'metatags' => generate_meta(null, null),
  4664. 'bodyclass' => 'edit-page',
  4665. 'is_admin' => true,
  4666. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . $page->title,
  4667. 'p' => $page,
  4668. 'static' => $page,
  4669. 'type' => 'is_subpage',
  4670. 'parent' => $static
  4671. ));
  4672. } else {
  4673. render('denied', array(
  4674. 'title' => generate_title('is_default', i18n('Denied')),
  4675. 'description' => safe_html(strip_tags(blog_description())),
  4676. 'canonical' => site_url(),
  4677. 'metatags' => generate_meta(null, null),
  4678. 'type' => 'is_subpage',
  4679. 'is_admin' => true,
  4680. 'bodyclass' => 'denied',
  4681. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4682. ));
  4683. }
  4684. } else {
  4685. $login = site_url() . 'login';
  4686. header("location: $login");
  4687. }
  4688. });
  4689. // Submitted data from edit sub static page
  4690. post('/:static/:sub/edit', function ($static, $sub) {
  4691. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4692. if(!login()) {
  4693. $login = site_url() . 'login';
  4694. header("location: $login");
  4695. }
  4696. $field = array();
  4697. $aField = array();
  4698. $field_file = 'content/data/field/subpage.json';
  4699. if (file_exists($field_file)) {
  4700. $aField = json_decode(file_get_contents($field_file, true));
  4701. }
  4702. if(!empty($aField)) {
  4703. foreach ($aField as $af) {
  4704. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  4705. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  4706. } else {
  4707. $field[$af->name] = from($_REQUEST, $af->name);
  4708. }
  4709. }
  4710. }
  4711. $title = from($_REQUEST, 'title');
  4712. $url = from($_REQUEST, 'url');
  4713. $content = from($_REQUEST, 'content');
  4714. $oldfile = from($_REQUEST, 'oldfile');
  4715. $destination = from($_GET, 'destination');
  4716. $description = from($_REQUEST, 'description');
  4717. $revertPage = from($_REQUEST, 'revertpage');
  4718. $publishDraft = from($_REQUEST, 'publishdraft');
  4719. if ($destination === null) {
  4720. $destination = $static . "/" . $sub;
  4721. }
  4722. $user = $_SESSION[site_url()]['user'];
  4723. $role = user('role', $user);
  4724. if (empty($url)) {
  4725. $url = $title;
  4726. }
  4727. if ($role === 'editor' || $role === 'admin') {
  4728. if ($proper && !empty($title) && !empty($content)) {
  4729. edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static, null, $field);
  4730. } else {
  4731. $message['error'] = '';
  4732. if (empty($title)) {
  4733. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  4734. }
  4735. if (empty($content)) {
  4736. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  4737. }
  4738. if (!$proper) {
  4739. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  4740. }
  4741. config('views.root', 'system/admin/views');
  4742. render('edit-page', array(
  4743. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $title),
  4744. 'description' => safe_html(strip_tags(blog_description())),
  4745. 'canonical' => site_url(),
  4746. 'metatags' => generate_meta(null, null),
  4747. 'error' => '<ul>' . $message['error'] . '</ul>',
  4748. 'oldfile' => $oldfile,
  4749. 'postTitle' => $title,
  4750. 'postUrl' => $url,
  4751. 'postContent' => $content,
  4752. 'static' => $static,
  4753. 'sub' => $sub,
  4754. 'type' => 'is_subpage',
  4755. 'bodyclass' => 'edit-page',
  4756. 'is_admin' => true,
  4757. 'parent' => $static,
  4758. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit')
  4759. ));
  4760. }
  4761. } else {
  4762. $redir = site_url();
  4763. header("location: $redir");
  4764. }
  4765. });
  4766. // Delete sub static page
  4767. get('/:static/:sub/delete', function ($static, $sub) {
  4768. $user = $_SESSION[site_url()]['user'];
  4769. $role = user('role', $user);
  4770. if (login()) {
  4771. config('views.root', 'system/admin/views');
  4772. if ($role === 'editor' || $role === 'admin') {
  4773. $post = find_page($static);
  4774. if (!$post) {
  4775. not_found();
  4776. }
  4777. $post = $post['current'];
  4778. $page = find_subpage($static, $sub);
  4779. if (!$page) {
  4780. $page = find_draft_subpage($static, $sub);
  4781. if (!$page) {
  4782. not_found();
  4783. } else {
  4784. $page = $page[0];
  4785. }
  4786. } else {
  4787. $page = $page['current'];
  4788. }
  4789. render('delete-page', array(
  4790. 'title' => generate_title('is_default', i18n('Delete') . ': ' . $page->title),
  4791. 'description' => safe_html(strip_tags(blog_description())),
  4792. 'canonical' => site_url(),
  4793. 'metatags' => generate_meta(null, null),
  4794. 'bodyclass' => 'delete-page',
  4795. 'is_admin' => true,
  4796. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . $page->title,
  4797. 'p' => $page,
  4798. 'static' => $page,
  4799. 'type' => 'is_subpage',
  4800. ));
  4801. } else {
  4802. render('denied', array(
  4803. 'title' => generate_title('is_default', i18n('Denied')),
  4804. 'description' => safe_html(strip_tags(blog_description())),
  4805. 'canonical' => site_url(),
  4806. 'metatags' => generate_meta(null, null),
  4807. 'type' => 'is_subpage',
  4808. 'is_admin' => true,
  4809. 'bodyclass' => 'denied',
  4810. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4811. ));
  4812. }
  4813. } else {
  4814. $login = site_url() . 'login';
  4815. header("location: $login");
  4816. }
  4817. });
  4818. // Submitted data from delete sub static page
  4819. post('/:static/:sub/delete', function () {
  4820. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4821. if ($proper && login()) {
  4822. $user = $_SESSION[site_url()]['user'];
  4823. $role = user('role', $user);
  4824. if ($role === 'editor' || $role === 'admin') {
  4825. $file = from($_REQUEST, 'file');
  4826. $destination = from($_GET, 'destination');
  4827. delete_page($file, $destination);
  4828. } else {
  4829. $redir = site_url();
  4830. header("location: $redir");
  4831. }
  4832. }
  4833. });
  4834. // Show blog post with year-month
  4835. get('/:year/:month/:name', function ($year, $month, $name) {
  4836. if (permalink_type() !== 'default') {
  4837. $redir = site_url() . permalink_type() . '/' . $name;
  4838. header("location: $redir", TRUE, 301);
  4839. }
  4840. if (config("views.counter") != "true") {
  4841. if (!login()) {
  4842. file_cache($_SERVER['REQUEST_URI']);
  4843. }
  4844. } else {
  4845. add_view('post_' . $name);
  4846. if (!login()) {
  4847. file_cache($_SERVER['REQUEST_URI']);
  4848. }
  4849. }
  4850. $post = find_post($year, $month, $name);
  4851. if (is_null($post)) {
  4852. not_found('post_'. $name);
  4853. } else {
  4854. $current = $post['current'];
  4855. }
  4856. $author = new stdClass;
  4857. $author->url = $current->authorUrl;
  4858. $author->name = $current->authorName;
  4859. $author->description = $current->authorDescription;
  4860. $author->about = $current->authorAbout;
  4861. $author->avatar = $current->authorAvatar;
  4862. $author->rss = $current->authorRss;
  4863. $author->slug = $current->author;
  4864. if (array_key_exists('prev', $post)) {
  4865. $prev = $post['prev'];
  4866. } else {
  4867. $prev = array();
  4868. }
  4869. if (array_key_exists('next', $post)) {
  4870. $next = $post['next'];
  4871. } else {
  4872. $next = array();
  4873. }
  4874. if (isset($current->image)) {
  4875. $var = 'imagePost';
  4876. } elseif (isset($current->link)) {
  4877. $var = 'linkPost';
  4878. } elseif (isset($current->quote)) {
  4879. $var = 'quotePost';
  4880. } elseif (isset($current->audio)) {
  4881. $var = 'audioPost';
  4882. } elseif (isset($current->video)) {
  4883. $var = 'videoPost'; }
  4884. else {
  4885. $var = 'blogPost';
  4886. }
  4887. if (config('blog.enable') === 'true') {
  4888. $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . blog_path() . '"><span itemprop="name">' . blog_string() . '</span></a><meta itemprop="position" content="2" /></li> &#187; ';
  4889. } else {
  4890. $blog = '';
  4891. }
  4892. $vroot = rtrim(config('views.root'), '/');
  4893. $lt = $vroot . '/layout--post--' . $current->ct . '.html.php';
  4894. $pt = $vroot . '/layout--post--' . $current->type . '.html.php';
  4895. $ls = $vroot . '/layout--post.html.php';
  4896. if (file_exists($lt)) {
  4897. $layout = 'layout--post--' . $current->ct;
  4898. } else if (file_exists($pt)) {
  4899. $layout = 'layout--post--' . $current->type;
  4900. } else if (file_exists($ls)) {
  4901. $layout = 'layout--post';
  4902. } else {
  4903. $layout = '';
  4904. }
  4905. $pv = $vroot . '/post--' . $current->ct . '.html.php';
  4906. $pvt = $vroot . '/post--' . $current->type . '.html.php';
  4907. if (file_exists($pv)) {
  4908. $pview = 'post--' . $current->ct;
  4909. } else if(file_exists($pvt)) {
  4910. $pview = 'post--' . $current->type;
  4911. } else {
  4912. $pview = 'post';
  4913. }
  4914. render($pview, array(
  4915. 'title' => generate_title('is_post', $current),
  4916. 'description' => $current->description,
  4917. 'canonical' => $current->url,
  4918. 'metatags' => generate_meta('is_post', $current),
  4919. 'p' => $current,
  4920. 'post' => $current,
  4921. 'author' => $author,
  4922. 'bodyclass' => 'in-post category-' . $current->ct . ' type-' . $current->type,
  4923. 'breadcrumb' => '<style>.breadcrumb-list {margin:0; padding:0;} .breadcrumb-list li {display: inline-block; list-style: none;}</style><ol class="breadcrumb-list" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . '"><span itemprop="name">' . config('breadcrumb.home') . '</span></a><meta itemprop="position" content="1" /></li> &#187; '. $blog . '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">' . $current->categoryb . '<meta itemprop="position" content="3" /></li>' . ' &#187; ' . $current->title . '</ol>',
  4924. 'prev' => has_prev($prev),
  4925. 'next' => has_next($next),
  4926. 'type' => $var,
  4927. 'is_post' => true
  4928. ), $layout);
  4929. });
  4930. // Edit blog post
  4931. get('/:year/:month/:name/edit', function ($year, $month, $name) {
  4932. if (login()) {
  4933. $user = $_SESSION[site_url()]['user'];
  4934. $role = user('role', $user);
  4935. config('views.root', 'system/admin/views');
  4936. $post = find_post($year, $month, $name);
  4937. if (!$post) {
  4938. $post = find_draft($year, $month, $name);
  4939. if (!$post) {
  4940. $post = find_scheduled($year, $month, $name);
  4941. if (!$post) {
  4942. not_found();
  4943. }
  4944. }
  4945. }
  4946. $current = $post['current'];
  4947. if (isset($current->image)) {
  4948. $type= 'is_image';
  4949. } elseif (isset($current->link)) {
  4950. $type = 'is_link';
  4951. } elseif (isset($current->quote)) {
  4952. $type = 'is_quote';
  4953. } elseif (isset($current->audio)) {
  4954. $type = 'is_audio';
  4955. } elseif (isset($current->video)) {
  4956. $type = 'is_video';
  4957. } else {
  4958. $type = 'is_post';
  4959. }
  4960. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  4961. render('edit-content', array(
  4962. 'title' => generate_title('is_default', $current->title),
  4963. 'description' => safe_html(strip_tags(blog_description())),
  4964. 'canonical' => site_url(),
  4965. 'metatags' => generate_meta(null, null),
  4966. 'p' => $current,
  4967. 'post' => $current,
  4968. 'type' => $type,
  4969. 'bodyclass' => 'edit-post',
  4970. 'is_admin' => true,
  4971. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4972. ));
  4973. } else {
  4974. render('denied', array(
  4975. 'title' => generate_title('is_default', $current->title),
  4976. 'description' => safe_html(strip_tags(blog_description())),
  4977. 'canonical' => site_url(),
  4978. 'metatags' => generate_meta(null, null),
  4979. 'p' => $current,
  4980. 'post' => $current,
  4981. 'bodyclass' => 'denied',
  4982. 'is_admin' => true,
  4983. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4984. ));
  4985. }
  4986. } else {
  4987. $login = site_url() . 'login';
  4988. header("location: $login");
  4989. }
  4990. });
  4991. // Get edited data from blog post
  4992. post('/:year/:month/:name/edit', function () {
  4993. if(!login()) {
  4994. $login = site_url() . 'login';
  4995. header("location: $login");
  4996. }
  4997. $field = array();
  4998. $aField = array();
  4999. $field_file = 'content/data/field/post.json';
  5000. if (file_exists($field_file)) {
  5001. $aField = json_decode(file_get_contents($field_file, true));
  5002. }
  5003. if(!empty($aField)) {
  5004. foreach ($aField as $af) {
  5005. if ($af->type == 'checkbox' && isset($_REQUEST[$af->name])) {
  5006. $field[$af->name] = isset($_REQUEST[$af->name]) ? "checked" : 0;
  5007. } else {
  5008. $field[$af->name] = from($_REQUEST, $af->name);
  5009. }
  5010. }
  5011. }
  5012. // The "AI was used" flag. Unchecked means empty, so no tag is written.
  5013. $field['ai'] = from($_REQUEST, 'ai') ? 'yes' : '';
  5014. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  5015. $title = from($_REQUEST, 'title');
  5016. $is_post = from($_REQUEST, 'is_post');
  5017. $image = from($_REQUEST, 'image');
  5018. $is_image = from($_REQUEST, 'is_image');
  5019. $video = from($_REQUEST, 'video');
  5020. $is_video = from($_REQUEST, 'is_video');
  5021. $link = from($_REQUEST, 'link');
  5022. $is_link = from($_REQUEST, 'is_link');
  5023. $audio = from($_REQUEST, 'audio');
  5024. $is_audio = from($_REQUEST, 'is_audio');
  5025. $quote = from($_REQUEST, 'quote');
  5026. $is_quote = from($_REQUEST, 'is_quote');
  5027. $tag = from($_REQUEST, 'tag');
  5028. $url = from($_REQUEST, 'url');
  5029. $content = from($_REQUEST, 'content');
  5030. $oldfile = from($_REQUEST, 'oldfile');
  5031. $destination = from($_GET, 'destination');
  5032. $description = from($_REQUEST, 'description');
  5033. $date = from($_REQUEST, 'date');
  5034. $time = from($_REQUEST, 'time');
  5035. $dateTime = null;
  5036. $revertPost = from($_REQUEST, 'revertpost');
  5037. $publishDraft = from($_REQUEST, 'publishdraft');
  5038. $category = from($_REQUEST, 'category');
  5039. if ($date !== null && $time !== null) {
  5040. $dateTime = $date . ' ' . $time;
  5041. }
  5042. if (!empty($is_image)) {
  5043. $type = 'is_image';
  5044. } elseif (!empty($is_video)) {
  5045. $type = 'is_video';
  5046. } elseif (!empty($is_link)) {
  5047. $type = 'is_link';
  5048. } elseif (!empty($is_quote)) {
  5049. $type = 'is_quote';
  5050. } elseif (!empty($is_audio)) {
  5051. $type = 'is_audio';
  5052. } elseif (!empty($is_post)) {
  5053. $type = 'is_post';
  5054. }
  5055. if (empty($url)) {
  5056. $url = $title;
  5057. }
  5058. $arr = explode('/', $oldfile);
  5059. $user = $_SESSION[site_url()]['user'];
  5060. $role = user('role', $user);
  5061. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  5062. if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
  5063. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image, null, $field);
  5064. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
  5065. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video,null, $field);
  5066. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
  5067. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link,null, $field);
  5068. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
  5069. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote,null, $field);
  5070. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
  5071. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio,null, $field);
  5072. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
  5073. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null,null, $field);
  5074. } else {
  5075. $message['error'] = '';
  5076. if (empty($title)) {
  5077. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_title') . '</li>';
  5078. }
  5079. if (empty($tag)) {
  5080. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_tag') . '</li>';
  5081. }
  5082. if (empty($content)) {
  5083. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_content') . '</li>';
  5084. }
  5085. if (!$proper) {
  5086. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  5087. }
  5088. if (!empty($is_image)) {
  5089. if (empty($image)) {
  5090. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_image') . '</li>';
  5091. }
  5092. } elseif (!empty($is_video)) {
  5093. if (empty($video)) {
  5094. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_video') . '</li>';
  5095. }
  5096. } elseif (!empty($is_link)) {
  5097. if (empty($link)) {
  5098. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_link') . '</li>';
  5099. }
  5100. } elseif (!empty($is_quote)) {
  5101. if (empty($quote)) {
  5102. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_quote') . '</li>';
  5103. }
  5104. } elseif (!empty($is_audio)) {
  5105. if (empty($audio)) {
  5106. $message['error'] .= '<li class="alert alert-danger">' . i18n('msg_error_field_req_audio') . '</li>';
  5107. }
  5108. }
  5109. config('views.root', 'system/admin/views');
  5110. render('edit-content', array(
  5111. 'title' => generate_title('is_default', $title),
  5112. 'description' => safe_html(strip_tags(blog_description())),
  5113. 'canonical' => site_url(),
  5114. 'metatags' => generate_meta(null, null),
  5115. 'error' => '<ul>' . $message['error'] . '</ul>',
  5116. 'oldfile' => $oldfile,
  5117. 'postTitle' => $title,
  5118. 'postImage' => $image,
  5119. 'postVideo' => $video,
  5120. 'postLink' => $link,
  5121. 'postQuote' => $quote,
  5122. 'postAudio' => $audio,
  5123. 'postTag' => $tag,
  5124. 'postUrl' => $url,
  5125. 'type' => $type,
  5126. 'postContent' => $content,
  5127. 'is_admin' => true,
  5128. 'bodyclass' => 'edit-post',
  5129. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $title
  5130. ));
  5131. }
  5132. } else {
  5133. $redir = site_url();
  5134. header("location: $redir");
  5135. }
  5136. });
  5137. // Delete blog post
  5138. get('/:year/:month/:name/delete', function ($year, $month, $name) {
  5139. if (login()) {
  5140. $user = $_SESSION[site_url()]['user'];
  5141. $role = user('role', $user);
  5142. config('views.root', 'system/admin/views');
  5143. $post = find_post($year, $month, $name);
  5144. if (!$post) {
  5145. $post = find_draft($year, $month, $name);
  5146. if (!$post) {
  5147. $post = find_scheduled($year, $month, $name);
  5148. if (!$post) {
  5149. not_found();
  5150. }
  5151. }
  5152. }
  5153. $current = $post['current'];
  5154. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  5155. render('delete-post', array(
  5156. 'title' => generate_title('is_default', i18n('Delete')),
  5157. 'description' => safe_html(strip_tags(blog_description())),
  5158. 'canonical' => site_url(),
  5159. 'metatags' => generate_meta(null, null),
  5160. 'p' => $current,
  5161. 'post' => $current,
  5162. 'bodyclass' => 'delete-post',
  5163. 'is_admin' => true,
  5164. 'breadcrumb' => '<span><a rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  5165. ));
  5166. } else {
  5167. render('denied', array(
  5168. 'title' => generate_title('is_default', i18n('Delete')),
  5169. 'description' => safe_html(strip_tags(blog_description())),
  5170. 'canonical' => site_url(),
  5171. 'metatags' => generate_meta(null, null),
  5172. 'p' => $current,
  5173. 'post' => $current,
  5174. 'bodyclass' => 'delete-post',
  5175. 'is_admin' => true,
  5176. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  5177. ));
  5178. }
  5179. } else {
  5180. $login = site_url() . 'login';
  5181. header("location: $login");
  5182. }
  5183. });
  5184. // Get deleted data from blog post
  5185. post('/:year/:month/:name/delete', function () {
  5186. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  5187. if ($proper && login()) {
  5188. $file = from($_REQUEST, 'file');
  5189. $destination = from($_GET, 'destination');
  5190. $arr = explode('/', $file);
  5191. $user = $_SESSION[site_url()]['user'];
  5192. $role = user('role', $user);
  5193. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  5194. delete_post($file, $destination);
  5195. }
  5196. }
  5197. });
  5198. // If we get here, it means that
  5199. // nothing has been matched above
  5200. get('.*', function () {
  5201. not_found();
  5202. });
  5203. // Serve the blog
  5204. dispatch();