index.php 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061
  1. <?php
  2. /* Copyright (C) 2016-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/website/index.php
  20. * \ingroup website
  21. * \brief Page to website view/edit
  22. */
  23. define('NOSCANPOSTFORINJECTION', 1);
  24. define('NOSTYLECHECK', 1);
  25. define('USEDOLIBARREDITOR', 1);
  26. define('FORCE_CKEDITOR', 1); // We need CKEditor, even if module is off.
  27. if (!defined('DISABLE_JS_GRAHP')) define('DISABLE_JS_GRAPH', 1);
  28. //header('X-XSS-Protection:0'); // Disable XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  44. // Load translation files required by the page
  45. $langs->loadLangs(array("admin", "other", "website", "errors"));
  46. // Security check
  47. if (!$user->rights->website->read) {
  48. accessforbidden();
  49. }
  50. $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
  51. $error = 0;
  52. $websiteid = GETPOST('websiteid', 'int');
  53. $websitekey = GETPOST('website', 'alpha');
  54. $page = GETPOST('page', 'alpha');
  55. $pageid = GETPOST('pageid', 'int');
  56. $pageref = GETPOST('pageref', 'alphanohtml');
  57. $action = GETPOST('action', 'aZ09');
  58. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  59. $confirm = GETPOST('confirm', 'alpha');
  60. $cancel = GETPOST('cancel', 'alpha');
  61. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  62. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'websitelist'; // To manage different context of search
  63. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  64. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  65. $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int');
  66. $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int');
  67. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  68. $type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
  69. $section_dir = GETPOST('section_dir', 'alpha');
  70. $file_manager = GETPOST('file_manager', 'alpha');
  71. $replacesite = GETPOST('replacesite', 'alpha');
  72. $mode = GETPOST('mode', 'alpha');
  73. if (GETPOST('deletesite', 'alpha')) {
  74. $action = 'deletesite';
  75. }
  76. if (GETPOST('delete', 'alpha')) {
  77. $action = 'delete';
  78. }
  79. if (GETPOST('preview', 'alpha')) {
  80. $action = 'preview';
  81. }
  82. if (GETPOST('createsite', 'alpha')) {
  83. $action = 'createsite';
  84. }
  85. if (GETPOST('createcontainer', 'alpha')) {
  86. $action = 'createcontainer';
  87. }
  88. if (GETPOST('editcss', 'alpha')) {
  89. $action = 'editcss';
  90. }
  91. if (GETPOST('editmenu', 'alpha')) {
  92. $action = 'editmenu';
  93. }
  94. if (GETPOST('setashome', 'alpha')) {
  95. $action = 'setashome';
  96. }
  97. if (GETPOST('editmeta', 'alpha')) {
  98. $action = 'editmeta';
  99. }
  100. if (GETPOST('editsource', 'alpha')) {
  101. $action = 'editsource';
  102. }
  103. if (GETPOST('editcontent', 'alpha')) {
  104. $action = 'editcontent';
  105. }
  106. if (GETPOST('exportsite', 'alpha')) {
  107. $action = 'exportsite';
  108. }
  109. if (GETPOST('importsite', 'alpha')) {
  110. $action = 'importsite';
  111. }
  112. if (GETPOST('createfromclone', 'alpha')) {
  113. $action = 'createfromclone';
  114. }
  115. if (GETPOST('createpagefromclone', 'alpha')) {
  116. $action = 'createpagefromclone';
  117. }
  118. if (empty($action) && $file_manager) {
  119. $action = 'file_manager';
  120. }
  121. if (empty($action) && $replacesite) {
  122. $mode = 'replacesite';
  123. }
  124. if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x')) {
  125. $pageid = 0;
  126. }
  127. // Load variable for pagination
  128. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  129. $sortfield = GETPOST('sortfield', 'aZ09comma');
  130. $sortorder = GETPOST('sortorder', 'aZ09comma');
  131. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  132. if (empty($page) || $page == -1) {
  133. $page = 0;
  134. } // If $page is not defined, or '' or -1
  135. $offset = $limit * $page;
  136. $pageprev = $page - 1;
  137. $pagenext = $page + 1;
  138. //if (! $sortfield) $sortfield='name';
  139. //if (! $sortorder) $sortorder='ASC';
  140. if (empty($action)) {
  141. $action = 'preview';
  142. }
  143. $object = new Website($db);
  144. $objectpage = new WebsitePage($db);
  145. $object->fetchAll('ASC', 'position'); // Init $object->records with list of websites
  146. // If website not defined, we take first found
  147. if (!($websiteid > 0) && empty($websitekey) && $action != 'createsite') {
  148. foreach ($object->records as $key => $valwebsite) {
  149. $websitekey = $valwebsite->ref;
  150. break;
  151. }
  152. }
  153. if ($websiteid > 0 || $websitekey) {
  154. $res = $object->fetch($websiteid, $websitekey);
  155. $websitekey = $object->ref;
  156. }
  157. $website = $object;
  158. // Check pageid received as parameter
  159. if ($pageid < 0) {
  160. $pageid = 0;
  161. }
  162. if (($pageid > 0 || $pageref) && $action != 'addcontainer') {
  163. $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
  164. if ($res == 0) {
  165. $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), null, $pageref);
  166. }
  167. // Check if pageid is inside the new website, if not we reset param pageid
  168. if ($res >= 0 && $object->id > 0) {
  169. if ($objectpage->fk_website != $object->id) { // We have a bad page that does not belong to web site
  170. if ($object->fk_default_home > 0) {
  171. $res = $objectpage->fetch($object->fk_default_home, $object->id, ''); // We search first page of web site
  172. if ($res > 0) {
  173. $pageid = $object->fk_default_home;
  174. }
  175. } else {
  176. $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
  177. if ($res == 0) { // Page was not found, we reset it
  178. $objectpage = new WebsitePage($db);
  179. } else // We found a page, we set pageid to it.
  180. {
  181. $pageid = $objectpage->id;
  182. }
  183. }
  184. } else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
  185. {
  186. $pageid = $objectpage->id;
  187. }
  188. }
  189. }
  190. // Define pageid if pageid and pageref not received as parameter or was wrong
  191. if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer') {
  192. $pageid = $object->fk_default_home;
  193. if (empty($pageid)) {
  194. $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  195. if (!is_array($array) && $array < 0) {
  196. dol_print_error('', $objectpage->error, $objectpage->errors);
  197. }
  198. $atleastonepage = (is_array($array) && count($array) > 0);
  199. $firstpageid = 0; $homepageid = 0;
  200. foreach ($array as $key => $valpage) {
  201. if (empty($firstpageid)) {
  202. $firstpageid = $valpage->id;
  203. }
  204. if ($object->fk_default_home && $key == $object->fk_default_home) {
  205. $homepageid = $valpage->id;
  206. }
  207. }
  208. $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
  209. }
  210. }
  211. global $dolibarr_main_data_root;
  212. $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
  213. $filehtmlheader = $pathofwebsite.'/htmlheader.html';
  214. $filecss = $pathofwebsite.'/styles.css.php';
  215. $filejs = $pathofwebsite.'/javascript.js.php';
  216. $filerobot = $pathofwebsite.'/robots.txt';
  217. $filehtaccess = $pathofwebsite.'/.htaccess';
  218. $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
  219. $fileindex = $pathofwebsite.'/index.php';
  220. $filewrapper = $pathofwebsite.'/wrapper.php';
  221. $filemanifestjson = $pathofwebsite.'/manifest.json.php';
  222. $filereadme = $pathofwebsite.'/README.md';
  223. $filelicense = $pathofwebsite.'/LICENSE';
  224. $filemaster = $pathofwebsite.'/master.inc.php';
  225. // Define $urlwithroot
  226. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  227. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  228. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  229. $permtouploadfile = $user->hasRight('website', 'write');
  230. $diroutput = $conf->medias->multidir_output[$conf->entity];
  231. $relativepath = $section_dir;
  232. $upload_dir = preg_replace('/\/$/', '', $diroutput).'/'.preg_replace('/^\//', '', $relativepath);
  233. $htmlheadercontentdefault = '';
  234. $htmlheadercontentdefault .= '<link rel="stylesheet" id="google-fonts-css" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,700" />'."\n";
  235. $htmlheadercontentdefault .= '<link rel="stylesheet" id="font-wasesome-css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />'."\n";
  236. $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>'."\n";
  237. $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>'."\n";
  238. $htmlheadercontentdefault .= '<!--'."\n";
  239. $htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=css/myfile.css"></script>'."\n";
  240. $htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=js/myfile.js"></script>'."\n";
  241. $htmlheadercontentdefault .= '-->'."\n";
  242. $manifestjsoncontentdefault = '';
  243. $manifestjsoncontentdefault .= '{
  244. "name": "MyWebsite",
  245. "short_name": "MyWebsite",
  246. "start_url": "/",
  247. "lang": "en-US",
  248. "display": "standalone",
  249. "background_color": "#fff",
  250. "description": "A simple Web app.",
  251. "icons": [{
  252. "src": "images/'.urlencode($website->ref).'/homescreen48.png",
  253. "sizes": "48x48",
  254. "type": "image/png"
  255. }, {
  256. "src": "image/'.urlencode($website->ref).'/homescreen72.png",
  257. "sizes": "72x72",
  258. "type": "image/png"
  259. }, {
  260. "src": "image/'.urlencode($website->ref).'/homescreen96.png",
  261. "sizes": "96x96",
  262. "type": "image/png"
  263. }, {
  264. "src": "image/'.urlencode($website->ref).'/homescreen144.png",
  265. "sizes": "144x144",
  266. "type": "image/png"
  267. }, {
  268. "src": "image/'.urlencode($website->ref).'/homescreen168.png",
  269. "sizes": "168x168",
  270. "type": "image/png"
  271. }, {
  272. "src": "image/'.urlencode($website->ref).'/homescreen192.png",
  273. "sizes": "192x192",
  274. "type": "image/png"
  275. }],
  276. "related_applications": [{
  277. "platform": "play",
  278. "url": "https://play.google.com/store/apps/details?id=com.nltechno.dolidroidpro"
  279. }]
  280. }';
  281. $listofpages = array();
  282. $algo = '';
  283. if (GETPOST('optionmeta')) {
  284. $algo .= 'meta';
  285. }
  286. if (GETPOST('optioncontent')) {
  287. $algo .= 'content';
  288. }
  289. if (GETPOST('optionsitefiles')) {
  290. $algo .= 'sitefiles';
  291. }
  292. if (empty($sortfield)) {
  293. if ($action == 'file_manager') {
  294. $sortfield = 'name'; $sortorder = 'ASC';
  295. } else {
  296. $sortfield = 'pageurl'; $sortorder = 'ASC';
  297. }
  298. }
  299. $searchkey = GETPOST('searchstring', 'restricthtml');
  300. if ($mode == 'replacesite') {
  301. $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
  302. $langcode = GETPOST('optionlanguage', 'aZ09');
  303. $otherfilters = array();
  304. if (GETPOST('optioncategory', 'int') > 0) {
  305. $otherfilters['category'] = GETPOST('optioncategory', 'int');
  306. }
  307. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
  308. }
  309. $usercanedit = $user->rights->website->write;
  310. $permissiontoadd = $user->rights->website->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  311. $permissiontodelete = $user->hasRight('website', 'delete');
  312. /*
  313. * Actions
  314. */
  315. // Protections
  316. if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
  317. $action = 'preview'; // To avoid to make an action on another page or another site when we click on button to select another site or page.
  318. }
  319. if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETPOST('refreshsite_x', 'alpha')) { // If we change the site, we reset the pageid and cancel addsite action.
  320. if ($action == 'addsite') {
  321. $action = 'preview';
  322. }
  323. if ($action == 'updatesource') {
  324. $action = 'preview';
  325. }
  326. $pageid = $object->fk_default_home;
  327. if (empty($pageid)) {
  328. $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  329. if (!is_array($array) && $array < 0) {
  330. dol_print_error('', $objectpage->error, $objectpage->errors);
  331. }
  332. $atleastonepage = (is_array($array) && count($array) > 0);
  333. $firstpageid = 0; $homepageid = 0;
  334. foreach ($array as $key => $valpage) {
  335. if (empty($firstpageid)) {
  336. $firstpageid = $valpage->id;
  337. }
  338. if ($object->fk_default_home && $key == $object->fk_default_home) {
  339. $homepageid = $valpage->id;
  340. }
  341. }
  342. $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
  343. }
  344. }
  345. if (GETPOST('refreshpage', 'alpha') && !in_array($action, array('updatecss'))) {
  346. $action = 'preview';
  347. }
  348. if ($cancel && $action == 'renamefile') {
  349. $cancel = '';
  350. }
  351. // Cancel
  352. if ($cancel) {
  353. $action = 'preview';
  354. $mode = '';
  355. if ($backtopage) {
  356. header("Location: ".$backtopage);
  357. exit;
  358. }
  359. }
  360. $savbacktopage = $backtopage;
  361. $backtopage = $_SERVER["PHP_SELF"].'?file_manager=1&website='.urlencode($websitekey).'&pageid='.urlencode($pageid).(GETPOST('section_dir', 'alpha') ? '&section_dir='.urlencode(GETPOST('section_dir', 'alpha')) : ''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
  362. if ($sortfield) {
  363. $backtopage .= '&sortfield='.urlencode($sortfield);
  364. }
  365. if ($sortorder) {
  366. $backtopage .= '&sortorder='.urlencode($sortorder);
  367. }
  368. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // This manage 'sendit', 'confirm_deletefile', 'renamefile' action when submitting new file.
  369. $backtopage = $savbacktopage;
  370. //var_dump($backtopage);
  371. //var_dump($action);
  372. if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager'
  373. $action = 'file_manager';
  374. }
  375. if ($action == 'setwebsiteonline') {
  376. $website->setStatut($website::STATUS_VALIDATED, null, '', 'WEBSITE_MODIFY', 'status');
  377. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int'));
  378. exit;
  379. }
  380. if ($action == 'setwebsiteoffline') {
  381. $result = $website->setStatut($website::STATUS_DRAFT, null, '', 'WEBSITE_MODIFY', 'status');
  382. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int'));
  383. exit;
  384. }
  385. if ($action == 'seteditinline') {
  386. dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1);
  387. setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
  388. //dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 0); // Force disable of 'Include dynamic content'
  389. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  390. exit;
  391. }
  392. if ($action == 'unseteditinline') {
  393. dolibarr_del_const($db, 'WEBSITE_EDITINLINE');
  394. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  395. exit;
  396. }
  397. if ($action == 'setshowsubcontainers') {
  398. dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1);
  399. //dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 0); // Force disable of edit inline
  400. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  401. exit;
  402. }
  403. if ($action == 'unsetshowsubcontainers') {
  404. dolibarr_del_const($db, 'WEBSITE_SUBCONTAINERSINLINE');
  405. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  406. exit;
  407. }
  408. if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searchkey) {
  409. $mode = 'replacesite';
  410. $massaction = '';
  411. }
  412. if ($action == 'deletetemplate') {
  413. $dirthemes = array('/doctemplates/websites');
  414. if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application
  415. foreach ($conf->modules_parts['websitetemplates'] as $reldir) {
  416. $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites'));
  417. }
  418. }
  419. $dirthemes = array_unique($dirthemes);
  420. // Delete template files and dir
  421. $mode = 'importsite';
  422. $action = 'importsite';
  423. if (count($dirthemes)) {
  424. $i = 0;
  425. foreach ($dirthemes as $dir) {
  426. //print $dirroot.$dir;exit;
  427. $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root
  428. if (is_dir($dirtheme)) {
  429. $templateuserfile = GETPOST('templateuserfile');
  430. $imguserfile = preg_replace('/\.zip$/', '', $templateuserfile).'.jpg';
  431. dol_delete_file($dirtheme.'/'.$templateuserfile);
  432. dol_delete_file($dirtheme.'/'.$imguserfile);
  433. }
  434. }
  435. }
  436. }
  437. // Set category
  438. if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
  439. $error = 0;
  440. $nbupdate = 0;
  441. $db->begin();
  442. $categoryid = GETPOST('setcategory', 'int');
  443. if ($categoryid > 0) {
  444. $tmpwebsitepage = new WebsitePage($db);
  445. $category = new Categorie($db);
  446. $category->fetch($categoryid);
  447. foreach ($toselect as $tmpid) {
  448. $tmpwebsitepage->id = $tmpid;
  449. $result = $category->add_type($tmpwebsitepage, 'website_page');
  450. if ($result < 0 && $result != -3) {
  451. $error++;
  452. setEventMessages($category->error, $category->errors, 'errors');
  453. break;
  454. } else {
  455. $nbupdate++;
  456. }
  457. }
  458. }
  459. if ($error) {
  460. $db->rollback();
  461. } else {
  462. if ($nbupdate) {
  463. setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
  464. }
  465. $db->commit();
  466. }
  467. // Now we reload list
  468. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
  469. }
  470. // Del category
  471. if ($massaction == 'delcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
  472. $error = 0;
  473. $nbupdate = 0;
  474. $db->begin();
  475. $categoryid = GETPOST('setcategory', 'int');
  476. if ($categoryid > 0) {
  477. $tmpwebsitepage = new WebsitePage($db);
  478. $category = new Categorie($db);
  479. $category->fetch($categoryid);
  480. foreach ($toselect as $tmpid) {
  481. $tmpwebsitepage->id = $tmpid;
  482. $result = $category->del_type($tmpwebsitepage, 'website_page');
  483. if ($result < 0 && $result != -3) {
  484. $error++;
  485. setEventMessages($category->error, $category->errors, 'errors');
  486. break;
  487. } else {
  488. $nbupdate++;
  489. }
  490. }
  491. }
  492. if ($error) {
  493. $db->rollback();
  494. } else {
  495. if ($nbupdate) {
  496. setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
  497. }
  498. $db->commit();
  499. }
  500. // Now we reload list
  501. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
  502. }
  503. // Replacement of string into pages
  504. if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
  505. $replacestring = GETPOST('replacestring', 'none');
  506. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  507. $allowimportsite = true;
  508. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  509. $allowimportsite = false;
  510. }
  511. if (!$allowimportsite) {
  512. // Blocked by installmodules.lock
  513. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  514. // Show clean corporate message
  515. $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
  516. } else {
  517. // Show technical generic message
  518. $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
  519. }
  520. setEventMessages($message, null, 'errors');
  521. } elseif (empty($user->rights->website->writephp)) {
  522. setEventMessages("NotAllowedToAddDynamicContent", null, 'errors');
  523. } elseif (!$replacestring) {
  524. setEventMessages("ErrorReplaceStringEmpty", null, 'errors');
  525. } else {
  526. $nbreplacement = 0;
  527. foreach ($toselect as $keyselected) {
  528. $objectpage = $listofpages['list'][$keyselected];
  529. if ($objectpage->pageurl) {
  530. dol_syslog("Replace string into page ".$objectpage->pageurl);
  531. if (GETPOST('optioncontent', 'aZ09')) {
  532. $objectpage->content = str_replace($searchkey, $replacestring, $objectpage->content);
  533. }
  534. if (GETPOST('optionmeta', 'aZ09')) {
  535. $objectpage->title = str_replace($searchkey, $replacestring, $objectpage->title);
  536. $objectpage->description = str_replace($searchkey, $replacestring, $objectpage->description);
  537. $objectpage->keywords = str_replace($searchkey, $replacestring, $objectpage->keywords);
  538. }
  539. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  540. $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
  541. // Save page alias
  542. $result = dolSavePageAlias($filealias, $object, $objectpage);
  543. if (!$result) {
  544. setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
  545. }
  546. // Save page of content
  547. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  548. if ($result) {
  549. $nbreplacement++;
  550. //var_dump($objectpage->content);exit;
  551. $objectpage->update($user);
  552. } else {
  553. $error++;
  554. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  555. $action = 'createcontainer';
  556. break;
  557. }
  558. }
  559. }
  560. if ($nbreplacement > 0) {
  561. setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs');
  562. }
  563. $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
  564. $langcode = GETPOST('optionlanguage', 'aZ09');
  565. $otherfilters = array();
  566. if (GETPOST('optioncategory', 'int') > 0) {
  567. $otherfilters['category'] = GETPOST('optioncategory', 'int');
  568. }
  569. // Now we reload list
  570. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
  571. }
  572. }
  573. // Add directory
  574. /*
  575. if ($action == 'adddir' && $permtouploadfile)
  576. {
  577. $ecmdir->ref = 'NOTUSEDYET';
  578. $ecmdir->label = GETPOST("label");
  579. $ecmdir->description = GETPOST("desc");
  580. //$id = $ecmdir->create($user);
  581. if ($id > 0)
  582. {
  583. header("Location: ".$_SERVER["PHP_SELF"]);
  584. exit;
  585. }
  586. else
  587. {
  588. setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
  589. $action = "createcontainer";
  590. }
  591. clearstatcache();
  592. }
  593. */
  594. // Add site
  595. if ($action == 'addsite' && $usercanedit) {
  596. $db->begin();
  597. if (GETPOST('virtualhost', 'alpha') && !preg_match('/^http/', GETPOST('virtualhost', 'alpha'))) {
  598. $error++;
  599. setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
  600. }
  601. if (!$error && !GETPOST('WEBSITE_REF', 'alpha')) {
  602. $error++;
  603. $langs->load("errors");
  604. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("WebsiteName")), null, 'errors');
  605. }
  606. if (!$error && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF', 'alpha'))) {
  607. $error++;
  608. $langs->load("errors");
  609. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
  610. }
  611. if (!$error) {
  612. $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
  613. foreach ($arrayotherlang as $key => $val) {
  614. // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
  615. if (empty(trim($val))) continue;
  616. $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
  617. }
  618. $tmpobject = new Website($db);
  619. $tmpobject->ref = GETPOST('WEBSITE_REF', 'alpha');
  620. $tmpobject->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
  621. $tmpobject->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  622. $tmpobject->otherlang = join(',', $arrayotherlang);
  623. $tmpobject->virtualhost = GETPOST('virtualhost', 'alpha');
  624. $result = $tmpobject->create($user);
  625. if ($result == 0) {
  626. $error++;
  627. setEventMessages($langs->trans("ErrorLabelAlreadyExists"), null, 'errors');
  628. } elseif ($result < 0) {
  629. $error++;
  630. setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
  631. }
  632. }
  633. if (!$error) {
  634. $db->commit();
  635. setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
  636. $action = '';
  637. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
  638. exit;
  639. } else {
  640. $db->rollback();
  641. $action = 'createsite';
  642. }
  643. if (!$error) {
  644. $action = 'preview';
  645. $id = $object->id;
  646. }
  647. }
  648. // Add page/container
  649. if ($action == 'addcontainer' && $usercanedit) {
  650. dol_mkdir($pathofwebsite);
  651. $db->begin();
  652. $objectpage->fk_website = $object->id;
  653. if (GETPOSTISSET('fetchexternalurl')) { // Fetch from external url
  654. $urltograb = GETPOST('externalurl', 'alpha');
  655. $grabimages = GETPOST('grabimages', 'alpha');
  656. $grabimagesinto = GETPOST('grabimagesinto', 'alpha');
  657. include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
  658. if (empty($urltograb)) {
  659. $error++;
  660. $langs->load("errors");
  661. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors');
  662. $action = 'createcontainer';
  663. } elseif (!preg_match('/^http/', $urltograb)) {
  664. $error++;
  665. $langs->load("errors");
  666. setEventMessages('Error URL must start with http:// or https://', null, 'errors');
  667. $action = 'createcontainer';
  668. }
  669. if (!$error) {
  670. // Clean url to grab, so url can be
  671. // http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
  672. $urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
  673. //$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
  674. $urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
  675. if (empty($urltograbwithoutdomainandparam) && !preg_match('/\/$/', $urltograb)) {
  676. $urltograb .= '/';
  677. }
  678. $pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/', '-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
  679. $urltograbdirwithoutslash = dirname($urltograb.'.');
  680. $urltograbdirrootwithoutslash = getRootURLFromURL($urltograbdirwithoutslash);
  681. // Exemple, now $urltograbdirwithoutslash is https://www.dolimed.com/screenshots
  682. // and $urltograbdirrootwithoutslash is https://www.dolimed.com
  683. }
  684. // Check pageurl is not already used
  685. if ($pageurl) {
  686. $tmpwebsitepage = new WebsitePage($db);
  687. $result = $tmpwebsitepage->fetch(0, $object->id, $pageurl);
  688. if ($result > 0) {
  689. setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors');
  690. $error++;
  691. $action = 'createcontainer';
  692. }
  693. }
  694. if (!$error) {
  695. $tmp = getURLContent($urltograb, 'GET', '', 1, array(), array('http', 'https'), 0);
  696. if ($tmp['curl_error_no']) {
  697. $error++;
  698. setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
  699. $action = 'createcontainer';
  700. } elseif ($tmp['http_code'] != '200') {
  701. $error++;
  702. setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
  703. $action = 'createcontainer';
  704. } else {
  705. // Remove comments
  706. $tmp['content'] = removeHtmlComment($tmp['content']);
  707. // Check there is no PHP content into the imported file (must be only HTML + JS)
  708. $phpcontent = dolKeepOnlyPhpCode($tmp['content']);
  709. if ($phpcontent) {
  710. $error++;
  711. setEventMessages('Error getting '.$urltograb.': file that include PHP content is not allowed', null, 'errors');
  712. $action = 'createcontainer';
  713. }
  714. }
  715. if (!$error) {
  716. $regs = array();
  717. preg_match('/<head>(.*)<\/head>/ims', $tmp['content'], $regs);
  718. $head = $regs[1];
  719. $objectpage->type_container = 'page';
  720. $objectpage->pageurl = $pageurl;
  721. if (empty($objectpage->pageurl)) {
  722. $tmpdomain = getDomainFromURL($urltograb);
  723. $objectpage->pageurl = $tmpdomain.'-home';
  724. }
  725. $objectpage->aliasalt = '';
  726. if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) {
  727. $objectpage->aliasalt = $regs[1];
  728. }
  729. $regtmp = array();
  730. if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp)) {
  731. $objectpage->title = $regtmp[1];
  732. }
  733. if (preg_match('/<meta name="title"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
  734. if (empty($objectpage->title)) {
  735. $objectpage->title = $regtmp[1]; // If title not found into <title>, we get it from <meta title>
  736. }
  737. }
  738. if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
  739. $objectpage->description = $regtmp[1];
  740. }
  741. if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
  742. $objectpage->keywords = $regtmp[1];
  743. }
  744. if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp)) {
  745. $tmplang = explode('-', $regtmp[1]);
  746. $objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
  747. }
  748. $tmp['content'] = preg_replace('/\s*<meta name="generator"[^"]+content="([^"]+)"\s*\/?>/ims', '', $tmp['content']);
  749. $objectpage->content = $tmp['content'];
  750. $objectpage->content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $objectpage->content);
  751. $objectpage->content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $objectpage->content);
  752. // TODO Replace 'action="$urltograbdirwithoutslash' into action="/"
  753. // TODO Replace 'action="$urltograbdirwithoutslash..."' into action="..."
  754. // TODO Replace 'a href="$urltograbdirwithoutslash' into a href="/"
  755. // TODO Replace 'a href="$urltograbdirwithoutslash..."' into a href="..."
  756. // Now loop to fetch all css files. Include them inline into header of page
  757. $objectpage->htmlheader = $tmp['content'];
  758. $objectpage->htmlheader = preg_replace('/^.*<head(\s[^>]*)*>/ims', '', $objectpage->htmlheader);
  759. $objectpage->htmlheader = preg_replace('/<\/head(\s[^>]*)*>.*$/ims', '', $objectpage->htmlheader);
  760. $objectpage->htmlheader = preg_replace('/<base(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  761. $objectpage->htmlheader = preg_replace('/<meta http-equiv="content-type"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  762. $objectpage->htmlheader = preg_replace('/<meta name="robots"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  763. $objectpage->htmlheader = preg_replace('/<meta name="title"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  764. $objectpage->htmlheader = preg_replace('/<meta name="description"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  765. $objectpage->htmlheader = preg_replace('/<meta name="keywords"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  766. $objectpage->htmlheader = preg_replace('/<meta name="generator"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  767. //$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
  768. //$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
  769. $objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
  770. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
  771. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="alternate[^>]*>\n/ims', '', $objectpage->htmlheader);
  772. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="canonical[^>]*>\n/ims', '', $objectpage->htmlheader);
  773. // Now loop to fetch JS
  774. $tmp = $objectpage->htmlheader;
  775. // We grab files found into <script> tags
  776. preg_match_all('/<script([^\.>]+)src=["\']([^"\'>]+)["\']([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
  777. $errorforsubresource = 0;
  778. foreach ($regs[0] as $key => $val) {
  779. dol_syslog("We will grab the script resource found into script tag ".$regs[2][$key]);
  780. $linkwithoutdomain = $regs[2][$key];
  781. if (preg_match('/^\//', $regs[2][$key])) {
  782. $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
  783. } else {
  784. $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
  785. }
  786. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
  787. if (preg_match('/^http/', $regs[2][$key])) {
  788. $urltograbbis = $regs[2][$key];
  789. $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
  790. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  791. }
  792. //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
  793. //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
  794. // Test if this is an external URL of grabbed web site. If yes, we do not load resource
  795. $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
  796. $domaintograbbis = getDomainFromURL($urltograbbis);
  797. if ($domaintograb != $domaintograbbis) {
  798. continue;
  799. }
  800. /*
  801. $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
  802. if ($tmpgeturl['curl_error_no'])
  803. {
  804. $error++;
  805. setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
  806. $errorforsubresource++;
  807. $action='createcontainer';
  808. }
  809. elseif ($tmpgeturl['http_code'] != '200')
  810. {
  811. $error++;
  812. setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
  813. $errorforsubresource++;
  814. $action='createcontainer';
  815. }
  816. else
  817. {
  818. dol_mkdir(dirname($filetosave));
  819. $fp = fopen($filetosave, "w");
  820. fputs($fp, $tmpgeturl['content']);
  821. fclose($fp);
  822. if (!empty($conf->global->MAIN_UMASK))
  823. @chmod($file, octdec($conf->global->MAIN_UMASK));
  824. }
  825. */
  826. //$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  827. $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '', $tmp);
  828. }
  829. $objectpage->htmlheader = trim($tmp)."\n";
  830. // Now we grab CSS found into <link> tags
  831. $pagecsscontent = "\n".'<style>'."\n";
  832. preg_match_all('/<link([^\.>]+)href=["\']([^"\'>]+\.css[^"\'>]*)["\']([^>]*)>/i', $objectpage->htmlheader, $regs);
  833. $errorforsubresource = 0;
  834. foreach ($regs[0] as $key => $val) {
  835. dol_syslog("We will grab the css resources found into link tag ".$regs[2][$key]);
  836. $linkwithoutdomain = $regs[2][$key];
  837. if (preg_match('/^\//', $regs[2][$key])) {
  838. $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
  839. } else {
  840. $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
  841. }
  842. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
  843. if (preg_match('/^http/', $regs[2][$key])) {
  844. $urltograbbis = $regs[2][$key];
  845. $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
  846. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  847. }
  848. //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
  849. //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
  850. // Test if this is an external URL of grabbed web site. If yes, we do not load resource
  851. $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
  852. $domaintograbbis = getDomainFromURL($urltograbbis);
  853. if ($domaintograb != $domaintograbbis) {
  854. continue;
  855. }
  856. $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
  857. if ($tmpgeturl['curl_error_no']) {
  858. $errorforsubresource++;
  859. setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
  860. dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
  861. $action = 'createcontainer';
  862. } elseif ($tmpgeturl['http_code'] != '200') {
  863. $errorforsubresource++;
  864. setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
  865. dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
  866. $action = 'createcontainer';
  867. } else {
  868. // Clean some comment
  869. //$tmpgeturl['content'] = dol_string_is_good_iso($tmpgeturl['content'], 1);
  870. //$tmpgeturl['content'] = mb_convert_encoding($tmpgeturl['content'], 'UTF-8', 'UTF-8');
  871. //$tmpgeturl['content'] = remove_bs($tmpgeturl['content']);
  872. //$tmpgeturl['content'] = str_replace('$screen-md-max', 'auto', $tmpgeturl['content']);
  873. //var_dump($tmpgeturl['content']);exit;
  874. $tmpgeturl['content'] = preg_replace('/\/\*\s+CSS content[a-z\s]*\s+\*\//', '', $tmpgeturl['content']);
  875. //dol_mkdir(dirname($filetosave));
  876. //$fp = fopen($filetosave, "w");
  877. //fputs($fp, $tmpgeturl['content']);
  878. //fclose($fp);
  879. //if (!empty($conf->global->MAIN_UMASK))
  880. // @chmod($file, octdec($conf->global->MAIN_UMASK));
  881. // $filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  882. $pagecsscontent .= '/* Content of file '.$urltograbbis.' */'."\n";
  883. getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto);
  884. // We try to convert the CSS we got by adding a prefix .bodywebsite with lessc to avoid conflict with CSS of Dolibarr.
  885. include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php';
  886. $lesscobj = new Lessc();
  887. try {
  888. $contentforlessc = ".bodywebsite {\n".$tmpgeturl['content']."\n}\n";
  889. //print '<pre>'.$contentforlessc.'</pre>';
  890. $contentforlessc = $lesscobj->compile($contentforlessc);
  891. //var_dump($contentforlessc); exit;
  892. $pagecsscontent .= $contentforlessc."\n";
  893. //$pagecsscontent.=$tmpgeturl['content']."\n";
  894. } catch (exception $e) {
  895. //echo "failed to compile lessc";
  896. dol_syslog("Failed to compile the CSS from URL ".$urltograbbis." with lessc: ".$e->getMessage(), LOG_WARNING);
  897. $pagecsscontent .= $tmpgeturl['content']."\n";
  898. }
  899. $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key], '/').'\n*/ims', '', $objectpage->htmlheader);
  900. }
  901. }
  902. $pagecsscontent .= '</style>';
  903. //var_dump($pagecsscontent);
  904. //print dol_escape_htmltag($tmp);exit;
  905. $objectpage->htmlheader .= trim($pagecsscontent)."\n";
  906. // Now we have to fetch all images into page
  907. $tmp = $objectpage->content;
  908. getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1, $grabimages, $grabimagesinto);
  909. // Normalize links href to Dolibarr internal naming
  910. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2.php"', $tmp);
  911. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3.php"', $tmp);
  912. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3-\4.php"', $tmp);
  913. //print dol_escape_htmltag($tmp);exit;
  914. $objectpage->content = $tmp;
  915. $objectpage->grabbed_from = $urltograb;
  916. }
  917. }
  918. } else {
  919. $newaliasnames = '';
  920. if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
  921. $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
  922. $websitepagetemp = new WebsitePage($db);
  923. foreach ($arrayofaliastotest as $aliastotest) {
  924. $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
  925. // Disallow alias name pageX (already used to save the page with id)
  926. if (preg_match('/^page\d+/i', $aliastotest)) {
  927. $error++;
  928. $langs->load("errors");
  929. setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
  930. $action = 'createcontainer';
  931. break;
  932. } else {
  933. $result = $websitepagetemp->fetch(0, $object->id, $aliastotest);
  934. if ($result < 0) {
  935. $error++;
  936. $langs->load("errors");
  937. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  938. $action = 'createcontainer';
  939. break;
  940. }
  941. if ($result > 0) {
  942. $error++;
  943. $langs->load("errors");
  944. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  945. $action = 'createcontainer';
  946. break;
  947. }
  948. $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
  949. }
  950. }
  951. }
  952. $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
  953. $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
  954. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  955. $objectpage->aliasalt = $newaliasnames;
  956. $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
  957. $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  958. $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
  959. $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
  960. $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
  961. $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
  962. $objectpage->htmlheader = GETPOST('htmlheader', 'none');
  963. $objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
  964. $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
  965. $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
  966. $substitutionarray = array();
  967. $substitutionarray['__WEBSITE_CREATE_BY__'] = $user->getFullName($langs);
  968. // Define id of page the new page is translation of
  969. $pageidfortranslation = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
  970. if ($pageidfortranslation > 0) {
  971. // Check if the page we are translation of is alreayd a translation of a source page. if yes, we will use source id instead
  972. $objectpagetmp = new WebsitePage($db);
  973. $objectpagetmp->fetch($pageidfortranslation);
  974. if ($objectpagetmp->fk_page > 0) {
  975. $pageidfortranslation = $objectpagetmp->fk_page;
  976. }
  977. }
  978. $objectpage->fk_page = $pageidfortranslation;
  979. $sample = GETPOST('sample', 'alpha');
  980. if (empty($sample)) {
  981. $sample = 'empty';
  982. }
  983. $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName($sample).'.html';
  984. // Init content with content into pagetemplate.html, blogposttempltate.html, ...
  985. $objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray);
  986. }
  987. if (!$error) {
  988. if (empty($objectpage->pageurl)) {
  989. $langs->load("errors");
  990. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
  991. $error++;
  992. $action = 'createcontainer';
  993. } elseif (!preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl)) {
  994. $langs->load("errors");
  995. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
  996. $error++;
  997. $action = 'createcontainer';
  998. }
  999. if (empty($objectpage->title)) {
  1000. $langs->load("errors");
  1001. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
  1002. $error++;
  1003. $action = 'createcontainer';
  1004. }
  1005. if ($objectpage->fk_page > 0 && empty($objectpage->lang)) {
  1006. $langs->load("errors");
  1007. setEventMessages($langs->trans("ErrorLanguageRequiredIfPageIsTranslationOfAnother"), null, 'errors');
  1008. $error++;
  1009. $action = 'createcontainer';
  1010. }
  1011. if ($objectpage->fk_page > 0 && !empty($objectpage->lang)) {
  1012. if ($objectpage->lang == $website->lang) {
  1013. $langs->load("errors");
  1014. setEventMessages($langs->trans("ErrorLanguageMustNotBeSourceLanguageIfPageIsTranslationOfAnother"), null, 'errors');
  1015. $error++;
  1016. $action = 'createcontainer';
  1017. }
  1018. }
  1019. }
  1020. if (!$error) {
  1021. $pageid = $objectpage->create($user);
  1022. if ($pageid <= 0) {
  1023. $error++;
  1024. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1025. $action = 'createcontainer';
  1026. }
  1027. }
  1028. if (!$error) {
  1029. // Website categories association
  1030. $categoriesarray = GETPOST('categories', 'array');
  1031. $result = $objectpage->setCategories($categoriesarray);
  1032. if ($result < 0) {
  1033. $error++;
  1034. setEventMessages($object->error, $object->errors, 'errors');
  1035. }
  1036. }
  1037. if (!$error) {
  1038. // If there is no home page yet, this new page will be set as the home page
  1039. if (empty($object->fk_default_home)) {
  1040. $object->fk_default_home = $pageid;
  1041. $res = $object->update($user);
  1042. if ($res <= 0) {
  1043. $error++;
  1044. setEventMessages($object->error, $object->errors, 'errors');
  1045. } else {
  1046. $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
  1047. // Generate the index.php page (to be the home page) and the wrapper.php file
  1048. $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
  1049. if ($result <= 0) {
  1050. setEventMessages('Failed to write file '.$fileindex, null, 'errors');
  1051. }
  1052. }
  1053. }
  1054. }
  1055. if (!$error) {
  1056. if (!empty($objectpage->content)) {
  1057. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1058. $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
  1059. // Save page alias
  1060. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1061. if (!$result) {
  1062. setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
  1063. }
  1064. // Save page of content
  1065. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  1066. if ($result) {
  1067. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1068. } else {
  1069. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1070. $action = 'createcontainer';
  1071. }
  1072. }
  1073. }
  1074. if (!$error) {
  1075. $db->commit();
  1076. setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
  1077. $action = '';
  1078. } else {
  1079. $db->rollback();
  1080. }
  1081. if (!$error) {
  1082. $pageid = $objectpage->id;
  1083. // To generate the CSS, robot and htmlheader file.
  1084. // Check symlink to medias and restore it if ko
  1085. $pathtomedias = DOL_DATA_ROOT.'/medias';
  1086. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  1087. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  1088. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  1089. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  1090. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  1091. }
  1092. // Now generate the master.inc.php page if it does not exists yet
  1093. if (!dol_is_file($filemaster)) {
  1094. $result = dolSaveMasterFile($filemaster);
  1095. if (!$result) {
  1096. $error++;
  1097. setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1098. }
  1099. }
  1100. if (!dol_is_file($filehtmlheader)) {
  1101. $htmlheadercontent = "<html>\n";
  1102. $htmlheadercontent .= $htmlheadercontentdefault;
  1103. $htmlheadercontent .= "</html>";
  1104. $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
  1105. }
  1106. if (!dol_is_file($filecss)) {
  1107. $csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
  1108. $result = dolSaveCssFile($filecss, $csscontent);
  1109. }
  1110. if (!dol_is_file($filejs)) {
  1111. $jscontent = "/* JS content (all pages) */\n";
  1112. $result = dolSaveJsFile($filejs, $jscontent);
  1113. }
  1114. if (!dol_is_file($filerobot)) {
  1115. $robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
  1116. $result = dolSaveRobotFile($filerobot, $robotcontent);
  1117. }
  1118. if (!dol_is_file($filehtaccess)) {
  1119. $htaccesscontent = "# Order allow,deny\n# Deny from all";
  1120. $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
  1121. }
  1122. if (!dol_is_file($filemanifestjson)) {
  1123. $manifestjsoncontent = "";
  1124. $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
  1125. }
  1126. if (!dol_is_file($filereadme)) {
  1127. $readmecontent = "Website generated by Dolibarr ERP CRM";
  1128. $result = dolSaveReadme($filereadme, $readmecontent);
  1129. }
  1130. if (!dol_is_file($filelicense)) {
  1131. $licensecontent = "MIT License";
  1132. $result = dolSaveLicense($filelicense, $licensecontent);
  1133. }
  1134. $action = 'preview';
  1135. }
  1136. }
  1137. // Delete site
  1138. if ($action == 'confirm_deletesite' && $confirm == 'yes' && $permissiontodelete) {
  1139. $error = 0;
  1140. $db->begin();
  1141. $res = $object->fetch(GETPOST('id', 'int'));
  1142. $website = $object;
  1143. if ($res > 0) {
  1144. $res = $object->delete($user);
  1145. if ($res <= 0) {
  1146. $error++;
  1147. setEventMessages($object->error, $object->errors, 'errors');
  1148. }
  1149. }
  1150. if (!$error) {
  1151. if (GETPOST('delete_also_js', 'alpha') == 'on') {
  1152. $pathofwebsitejs = DOL_DATA_ROOT.'/medias/js/'.$object->ref;
  1153. dol_delete_dir_recursive($pathofwebsitejs);
  1154. }
  1155. if (GETPOST('delete_also_medias', 'alpha') == 'on') {
  1156. $pathofwebsitemedias = DOL_DATA_ROOT.'/medias/image/'.$object->ref;
  1157. dol_delete_dir_recursive($pathofwebsitemedias);
  1158. }
  1159. }
  1160. if (!$error) {
  1161. $db->commit();
  1162. setEventMessages($langs->trans("SiteDeleted", $object->ref), null, 'mesgs');
  1163. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
  1164. exit;
  1165. } else {
  1166. $db->rollback();
  1167. setEventMessages($object->error, $object->errors, 'errors');
  1168. }
  1169. }
  1170. // Delete page (from website page menu)
  1171. if (GETPOSTISSET('pageid') && $action == 'delete' && $permissiontodelete && !GETPOST('file_manager')) {
  1172. $error = 0;
  1173. $db->begin();
  1174. $res = $object->fetch(0, $websitekey);
  1175. $website = $object;
  1176. $res = $objectpage->fetch($pageid, $object->id);
  1177. if ($res > 0) {
  1178. $res = $objectpage->delete($user);
  1179. if ($res <= 0) {
  1180. $error++;
  1181. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1182. }
  1183. }
  1184. if (!$error) {
  1185. $db->commit();
  1186. setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $websitekey), null, 'mesgs');
  1187. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey);
  1188. exit;
  1189. } else {
  1190. $db->rollback();
  1191. dol_print_error($db);
  1192. }
  1193. }
  1194. // Delete page (from menu search)
  1195. if (!GETPOSTISSET('pageid')) {
  1196. $objectclass = 'WebsitePage';
  1197. // Add part of code from actions_massactions.inc.php
  1198. // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
  1199. if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
  1200. $db->begin();
  1201. $objecttmp = new $objectclass($db);
  1202. $nbok = 0;
  1203. foreach ($toselect as $toselectid) {
  1204. $result = $objecttmp->fetch($toselectid);
  1205. if ($result > 0) {
  1206. $result = $objecttmp->delete($user);
  1207. if ($result <= 0) {
  1208. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1209. $error++;
  1210. break;
  1211. } else {
  1212. $nbok++;
  1213. }
  1214. } else {
  1215. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1216. $error++;
  1217. break;
  1218. }
  1219. }
  1220. if (!$error) {
  1221. if ($nbok > 1) {
  1222. setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  1223. } else {
  1224. setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  1225. }
  1226. $db->commit();
  1227. } else {
  1228. $db->rollback();
  1229. }
  1230. //var_dump($listofobjectthirdparties);exit;
  1231. }
  1232. if ($action == 'delete') {
  1233. $mode = 'replacesite';
  1234. $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
  1235. $langcode = GETPOST('optionlanguage', 'aZ09');
  1236. $otherfilters = array();
  1237. if (GETPOST('optioncategory', 'int') > 0) {
  1238. $otherfilters['category'] = GETPOST('optioncategory', 'int');
  1239. }
  1240. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
  1241. }
  1242. }
  1243. // Update css site properties. Re-generates also the wrapper.
  1244. if ($action == 'updatecss' && $usercanedit) {
  1245. // If we tried to reload another site/page, we stay on editcss mode.
  1246. if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
  1247. $action = 'editcss';
  1248. } else {
  1249. $res = $object->fetch(0, $websitekey);
  1250. $website = $object;
  1251. if (GETPOSTISSET('virtualhost')) {
  1252. $tmpvirtualhost = preg_replace('/\/$/', '', GETPOST('virtualhost', 'alpha'));
  1253. if ($tmpvirtualhost && !preg_match('/^http/', $tmpvirtualhost)) {
  1254. $error++;
  1255. setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
  1256. $action = 'editcss';
  1257. }
  1258. if (!$error) {
  1259. $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
  1260. foreach ($arrayotherlang as $key => $val) {
  1261. // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
  1262. if (empty(trim($val))) continue;
  1263. $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
  1264. }
  1265. $object->virtualhost = $tmpvirtualhost;
  1266. $object->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  1267. $object->otherlang = join(',', $arrayotherlang);
  1268. $object->use_manifest = GETPOST('use_manifest', 'alpha');
  1269. $result = $object->update($user);
  1270. if ($result < 0) {
  1271. $error++;
  1272. setEventMessages($object->error, $object->errors, 'errors');
  1273. $action = 'editcss';
  1274. }
  1275. }
  1276. }
  1277. if (!$error) {
  1278. if (($_FILES['addedfile']["name"] != '')) {
  1279. $uploadfolder = $conf->website->dir_output.'/'.$websitekey;
  1280. if ($_FILES['addedfile']['type'] != 'image/png') {
  1281. $error++;
  1282. setEventMessages($langs->trans('ErrorFaviconType'), array(), 'errors');
  1283. }
  1284. $filetoread = realpath(dol_osencode($_FILES['addedfile']['tmp_name']));
  1285. $filesize = getimagesize($filetoread);
  1286. if ($filesize[0] != $filesize[1]) {
  1287. $error++;
  1288. setEventMessages($langs->trans('ErrorFaviconMustBeASquaredImage'), array(), 'errors');
  1289. }
  1290. if (! $error && ($filesize[0] != 16 && $filesize[0] != 32 && $filesize[0] != 64)) {
  1291. $error++;
  1292. setEventMessages($langs->trans('ErrorFaviconSize'), array(), 'errors');
  1293. }
  1294. if (!$error) {
  1295. dol_add_file_process($uploadfolder, 1, 0, 'addedfile', 'favicon.png');
  1296. }
  1297. }
  1298. if ($error) {
  1299. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
  1300. $action = 'preview';
  1301. if ($backtopage) {
  1302. $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
  1303. header("Location: ".$backtopage);
  1304. exit;
  1305. }
  1306. } else {
  1307. $action = 'editcss';
  1308. }
  1309. }
  1310. }
  1311. if (!$error) {
  1312. // Save master.inc.php file
  1313. dol_syslog("Save master file ".$filemaster);
  1314. dol_mkdir($pathofwebsite);
  1315. // Now generate the master.inc.php page
  1316. $result = dolSaveMasterFile($filemaster);
  1317. if (!$result) {
  1318. $error++;
  1319. setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1320. }
  1321. $dataposted = trim(GETPOST('WEBSITE_HTML_HEADER', 'none'));
  1322. $dataposted = preg_replace(array('/<html>\n*/ims', '/<\/html>\n*/ims'), array('', ''), $dataposted);
  1323. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1324. // Html header file
  1325. $phpfullcodestringold = '';
  1326. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1327. // Security analysis
  1328. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1329. if (!$errorphpcheck) {
  1330. $htmlheadercontent = '';
  1331. /* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
  1332. $htmlheadercontent.= "<?php // BEGIN PHP\n";
  1333. $htmlheadercontent.= '$websitekey=basename(__DIR__);'."\n";
  1334. $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
  1335. $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1336. $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1337. $htmlheadercontent.= "ob_start();\n";
  1338. // $htmlheadercontent.= "header('Content-type: text/html');\n"; // Not required. htmlheader.html is never call as a standalone page
  1339. $htmlheadercontent.= "// END PHP ?>\n";*/
  1340. $htmlheadercontent .= $dataposted."\n";
  1341. /*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
  1342. $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  1343. $htmlheadercontent.= "// END PHP ?>"."\n";*/
  1344. $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
  1345. if (!$result) {
  1346. $error++;
  1347. setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
  1348. }
  1349. } else {
  1350. $error++;
  1351. }
  1352. $dataposted = trim(GETPOST('WEBSITE_CSS_INLINE', 'none'));
  1353. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1354. // Css file
  1355. $phpfullcodestringold = '';
  1356. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1357. // Security analysis
  1358. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1359. if (!$errorphpcheck) {
  1360. $csscontent = '';
  1361. $csscontent .= "<?php // BEGIN PHP\n";
  1362. $csscontent .= '$websitekey=basename(__DIR__);'."\n";
  1363. $csscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
  1364. $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1365. $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1366. $csscontent .= "ob_start();\n";
  1367. $csscontent .= "if (! headers_sent()) { /* because file is included inline when in edit mode and we don't want warning */ \n";
  1368. $csscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1369. $csscontent .= "header('Content-type: text/css');\n";
  1370. $csscontent .= "}\n";
  1371. $csscontent .= "// END PHP ?>\n";
  1372. $csscontent .= $dataposted."\n";
  1373. $csscontent .= '<?php // BEGIN PHP'."\n";
  1374. $csscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "css");'."\n";
  1375. $csscontent .= "// END PHP ?>\n";
  1376. dol_syslog("Save css content into ".$filecss);
  1377. $result = dolSaveCssFile($filecss, $csscontent);
  1378. if (!$result) {
  1379. $error++;
  1380. setEventMessages('Failed to write file '.$filecss, null, 'errors');
  1381. }
  1382. } else {
  1383. $error++;
  1384. }
  1385. $dataposted = trim(GETPOST('WEBSITE_JS_INLINE', 'none'));
  1386. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1387. // Js file
  1388. $phpfullcodestringold = '';
  1389. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1390. // Security analysis
  1391. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1392. if (!$errorphpcheck) {
  1393. $jscontent = '';
  1394. $jscontent .= "<?php // BEGIN PHP\n";
  1395. $jscontent .= '$websitekey=basename(__DIR__);'."\n";
  1396. $jscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
  1397. $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1398. $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1399. $jscontent .= "ob_start();\n";
  1400. $jscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1401. $jscontent .= "header('Content-type: application/javascript');\n";
  1402. $jscontent .= "// END PHP ?>\n";
  1403. $jscontent .= $dataposted."\n";
  1404. $jscontent .= '<?php // BEGIN PHP'."\n";
  1405. $jscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "js");'."\n";
  1406. $jscontent .= "// END PHP ?>\n";
  1407. $result = dolSaveJsFile($filejs, $jscontent);
  1408. if (!$result) {
  1409. $error++;
  1410. setEventMessages('Failed to write file '.$filejs, null, 'errors');
  1411. }
  1412. } else {
  1413. $error++;
  1414. }
  1415. $dataposted = trim(GETPOST('WEBSITE_ROBOT', 'restricthtml'));
  1416. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1417. // Robot file
  1418. $phpfullcodestringold = '';
  1419. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1420. // Security analysis
  1421. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1422. if (!$errorphpcheck) {
  1423. $robotcontent = '';
  1424. /*$robotcontent.= "<?php // BEGIN PHP\n";
  1425. $robotcontent.= '$websitekey=basename(__DIR__);'."\n";
  1426. $robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
  1427. $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1428. $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1429. $robotcontent.= "ob_start();\n";
  1430. $robotcontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1431. $robotcontent.= "header('Content-type: text/css');\n";
  1432. $robotcontent.= "// END PHP ?>\n";*/
  1433. $robotcontent .= $dataposted."\n";
  1434. /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
  1435. $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "robot");'."\n";
  1436. $robotcontent.= "// END PHP ?>"."\n";*/
  1437. $result = dolSaveRobotFile($filerobot, $robotcontent);
  1438. if (!$result) {
  1439. $error++;
  1440. setEventMessages('Failed to write file '.$filerobot, null, 'errors');
  1441. }
  1442. } else {
  1443. $error++;
  1444. }
  1445. $dataposted = trim(GETPOST('WEBSITE_HTACCESS', 'restricthtml'));
  1446. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1447. // Htaccess file
  1448. $phpfullcodestringold = '';
  1449. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1450. // Security analysis
  1451. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1452. if (!$errorphpcheck) {
  1453. $htaccesscontent = '';
  1454. $htaccesscontent .= $dataposted."\n";
  1455. $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
  1456. if (!$result) {
  1457. $error++;
  1458. setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
  1459. }
  1460. } else {
  1461. $error++;
  1462. }
  1463. $dataposted = trim(GETPOST('WEBSITE_MANIFEST_JSON', 'none'));
  1464. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1465. // Manifest.json file
  1466. $phpfullcodestringold = '';
  1467. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1468. // Security analysis
  1469. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1470. if (!$errorphpcheck) {
  1471. $manifestjsoncontent = '';
  1472. $manifestjsoncontent .= "<?php // BEGIN PHP\n";
  1473. $manifestjsoncontent .= '$websitekey=basename(__DIR__);'."\n";
  1474. $manifestjsoncontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
  1475. $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1476. $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1477. $manifestjsoncontent .= "ob_start();\n";
  1478. $manifestjsoncontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1479. $manifestjsoncontent .= "header('Content-type: application/manifest+json');\n";
  1480. $manifestjsoncontent .= "// END PHP ?>\n";
  1481. $manifestjsoncontent .= $dataposted."\n";
  1482. $manifestjsoncontent .= '<?php // BEGIN PHP'."\n";
  1483. $manifestjsoncontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
  1484. $manifestjsoncontent .= "// END PHP ?>\n";
  1485. $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
  1486. if (!$result) {
  1487. $error++;
  1488. setEventMessages('Failed to write file '.$filemanifestjson, null, 'errors');
  1489. }
  1490. } else {
  1491. $error++;
  1492. }
  1493. $dataposted = trim(GETPOST('WEBSITE_README', 'restricthtml'));
  1494. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1495. // README.md file
  1496. $phpfullcodestringold = '';
  1497. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1498. // Security analysis
  1499. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1500. if (!$errorphpcheck) {
  1501. $readmecontent = '';
  1502. /*$readmecontent.= "<?php // BEGIN PHP\n";
  1503. $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
  1504. $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
  1505. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1506. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1507. $readmecontent.= "ob_start();\n";
  1508. $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1509. $readmecontent.= "header('Content-type: application/manifest+json');\n";
  1510. $readmecontent.= "// END PHP ?>\n";*/
  1511. $readmecontent .= $dataposted."\n";
  1512. /*$readmecontent.= '<?php // BEGIN PHP'."\n";
  1513. $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
  1514. $readmecontent.= "// END PHP ?>"."\n";*/
  1515. $result = dolSaveReadme($filereadme, $readmecontent);
  1516. if (!$result) {
  1517. $error++;
  1518. setEventMessages('Failed to write file '.$filereadme, null, 'errors');
  1519. }
  1520. } else {
  1521. $error++;
  1522. }
  1523. $dataposted = trim(GETPOST('WEBSITE_LICENSE', 'restricthtml'));
  1524. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1525. // LICENSE file
  1526. $phpfullcodestringold = '';
  1527. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1528. // Security analysis
  1529. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1530. if (!$errorphpcheck) {
  1531. $licensecontent = '';
  1532. /*$readmecontent.= "<?php // BEGIN PHP\n";
  1533. $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
  1534. $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
  1535. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1536. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1537. $readmecontent.= "ob_start();\n";
  1538. $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1539. $readmecontent.= "header('Content-type: application/manifest+json');\n";
  1540. $readmecontent.= "// END PHP ?>\n";*/
  1541. $licensecontent .= $dataposted."\n";
  1542. /*$readmecontent.= '<?php // BEGIN PHP'."\n";
  1543. $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
  1544. $readmecontent.= "// END PHP ?>"."\n";*/
  1545. $result = dolSaveLicense($filelicense, $licensecontent);
  1546. if (!$result) {
  1547. $error++;
  1548. setEventMessages('Failed to write file '.$filelicense, null, 'errors');
  1549. }
  1550. } else {
  1551. $error++;
  1552. }
  1553. // Save wrapper.php
  1554. $result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper, $object);
  1555. // Message if no error
  1556. if (!$error) {
  1557. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1558. }
  1559. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
  1560. $action = 'preview';
  1561. if ($backtopage) {
  1562. $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
  1563. header("Location: ".$backtopage);
  1564. exit;
  1565. }
  1566. } else {
  1567. $action = 'editcss';
  1568. }
  1569. }
  1570. }
  1571. }
  1572. // Update page
  1573. if ($action == 'setashome' && $usercanedit) {
  1574. $db->begin();
  1575. $object->fetch(0, $websitekey);
  1576. $website = $object;
  1577. $object->fk_default_home = $pageid;
  1578. $res = $object->update($user);
  1579. if (! ($res > 0)) {
  1580. $error++;
  1581. setEventMessages($object->error, $object->errors, 'errors');
  1582. }
  1583. if (!$error) {
  1584. $db->commit();
  1585. $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
  1586. // Generate the index.php page to be the home page
  1587. $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
  1588. if ($result) {
  1589. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1590. } else {
  1591. setEventMessages('Failed to write file '.$fileindex, null, 'errors');
  1592. }
  1593. $action = 'preview';
  1594. } else {
  1595. $db->rollback();
  1596. }
  1597. }
  1598. // Update page properties (meta)
  1599. if ($action == 'updatemeta' && $usercanedit) {
  1600. $db->begin();
  1601. $result = $object->fetch(0, $websitekey);
  1602. $website = $object;
  1603. $objectpage->fk_website = $object->id;
  1604. // Check parameters
  1605. if (!preg_match('/^[a-z0-9\-\_]+$/i', GETPOST('WEBSITE_PAGENAME', 'alpha'))) {
  1606. $error++;
  1607. $langs->load("errors");
  1608. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
  1609. $action = 'editmeta';
  1610. }
  1611. $res = $objectpage->fetch($pageid, $object->id);
  1612. if ($res <= 0) {
  1613. $error++;
  1614. setEventMessages('Page not found '.$objectpage->error, $objectpage->errors, 'errors');
  1615. }
  1616. // Check alias not exists
  1617. if (!$error && GETPOST('WEBSITE_PAGENAME', 'alpha')) {
  1618. $websitepagetemp = new WebsitePage($db);
  1619. $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha'));
  1620. if ($result < 0) {
  1621. $error++;
  1622. $langs->load("errors");
  1623. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  1624. $action = 'editmeta';
  1625. }
  1626. if ($result > 0) {
  1627. $error++;
  1628. $langs->load("errors");
  1629. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  1630. $action = 'editmeta';
  1631. }
  1632. }
  1633. $newaliasnames = '';
  1634. if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
  1635. $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
  1636. $websitepagetemp = new WebsitePage($db);
  1637. foreach ($arrayofaliastotest as $aliastotest) {
  1638. $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
  1639. // Disallow alias name pageX (already used to save the page with id)
  1640. if (preg_match('/^page\d+/i', $aliastotest)) {
  1641. $error++;
  1642. $langs->load("errors");
  1643. setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
  1644. $action = 'editmeta';
  1645. break;
  1646. } else {
  1647. $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, $aliastotest);
  1648. if ($result < 0) {
  1649. $error++;
  1650. $langs->load("errors");
  1651. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  1652. $action = 'editmeta';
  1653. break;
  1654. }
  1655. if ($result > 0) {
  1656. $error++;
  1657. $langs->load("errors");
  1658. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  1659. $action = 'editmeta';
  1660. break;
  1661. }
  1662. $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
  1663. }
  1664. }
  1665. }
  1666. if (!$error) {
  1667. $objectpage->old_object = clone $objectpage;
  1668. $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
  1669. $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
  1670. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  1671. $objectpage->aliasalt = $newaliasnames;
  1672. $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  1673. $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
  1674. $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
  1675. $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
  1676. $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
  1677. $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
  1678. $objectpage->htmlheader = trim(GETPOST('htmlheader', 'none'));
  1679. $objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
  1680. $objectpage->author_alias = trim(GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml'));
  1681. $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS', 'alpha');
  1682. $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID', 'aZ09');
  1683. $newdatecreation = dol_mktime(GETPOST('datecreationhour', 'int'), GETPOST('datecreationmin', 'int'), GETPOST('datecreationsec', 'int'), GETPOST('datecreationmonth', 'int'), GETPOST('datecreationday', 'int'), GETPOST('datecreationyear', 'int'));
  1684. if ($newdatecreation) {
  1685. $objectpage->date_creation = $newdatecreation;
  1686. }
  1687. $res = $objectpage->update($user);
  1688. if (!($res > 0)) {
  1689. $langs->load("errors");
  1690. if ($db->lasterrno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  1691. $error++;
  1692. $langs->load("errors");
  1693. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists"), null, 'errors');
  1694. $action = 'editmeta';
  1695. } else {
  1696. $error++;
  1697. $langs->load("errors");
  1698. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1699. $action = 'editmeta';
  1700. }
  1701. }
  1702. }
  1703. if (!$error) {
  1704. // Website categories association
  1705. $categoriesarray = GETPOST('categories', 'array');
  1706. $result = $objectpage->setCategories($categoriesarray);
  1707. if ($result < 0) {
  1708. $error++;
  1709. setEventMessages($object->error, $object->errors, 'errors');
  1710. }
  1711. }
  1712. if (!$error) {
  1713. $db->commit();
  1714. } else {
  1715. $db->rollback();
  1716. }
  1717. if (!$error) {
  1718. $filemaster = $pathofwebsite.'/master.inc.php';
  1719. $fileoldalias = $pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
  1720. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1721. dol_mkdir($pathofwebsite);
  1722. // Now generate the master.inc.php page
  1723. $result = dolSaveMasterFile($filemaster);
  1724. if (!$result) {
  1725. setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1726. }
  1727. // Now delete the alias.php page
  1728. if (!empty($fileoldalias)) {
  1729. dol_syslog("We delete old alias page name=".$fileoldalias." to build a new alias page=".$filealias);
  1730. dol_delete_file($fileoldalias);
  1731. // Delete also pages into language subdirectories
  1732. if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
  1733. $dirname = dirname($fileoldalias);
  1734. $filename = basename($fileoldalias);
  1735. $sublangs = explode(',', $object->otherlang);
  1736. foreach ($sublangs as $sublang) {
  1737. // Under certain conditions $sublang can be an empty string
  1738. // ($object->otherlang with empty string or with string like this 'en,,sv')
  1739. // if is the case we try to re-delete the main alias file. Avoid it.
  1740. if (empty(trim($sublang))) continue;
  1741. $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
  1742. dol_delete_file($fileoldaliassub);
  1743. }
  1744. }
  1745. }
  1746. // Now delete the alternative alias.php pages
  1747. if (!empty($objectpage->old_object->aliasalt)) {
  1748. $tmpaltaliases = explode(',', $objectpage->old_object->aliasalt);
  1749. if (is_array($tmpaltaliases)) {
  1750. foreach ($tmpaltaliases as $tmpaliasalt) {
  1751. dol_syslog("We delete old alt alias pages name=".trim($tmpaliasalt));
  1752. dol_delete_file($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1753. // Delete also pages into language subdirectories
  1754. if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
  1755. $dirname = dirname($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1756. $filename = basename($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1757. $sublangs = explode(',', $object->otherlang);
  1758. foreach ($sublangs as $sublang) {
  1759. // Under certain conditions $ sublang can be an empty string
  1760. // ($object->otherlang with empty string or with string like this 'en,,sv')
  1761. // if is the case we try to re-delete the main alias file. Avoid it.
  1762. if (empty(trim($sublang))) continue;
  1763. $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
  1764. dol_delete_file($fileoldaliassub);
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. // Save page main alias
  1771. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1772. if (!$result) {
  1773. setEventMessages('Failed to write file '.$filealias, null, 'errors');
  1774. }
  1775. // Save alt aliases
  1776. if (!empty($objectpage->aliasalt)) {
  1777. $tmpaltaliases = explode(',', $objectpage->aliasalt);
  1778. if (is_array($tmpaltaliases)) {
  1779. foreach ($tmpaltaliases as $tmpaliasalt) {
  1780. if (trim($tmpaliasalt)) {
  1781. $filealias = $pathofwebsite.'/'.trim($tmpaliasalt).'.php';
  1782. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1783. if (!$result) {
  1784. setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. // Save page of content
  1791. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  1792. if ($result) {
  1793. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1794. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
  1795. //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1796. //exit;
  1797. $action = 'preview';
  1798. } else {
  1799. $action = 'editmeta';
  1800. }
  1801. } else {
  1802. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1803. //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1804. //exit;
  1805. $action = 'preview';
  1806. }
  1807. }
  1808. }
  1809. // Update page
  1810. if ($usercanedit && (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone')
  1811. || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))) {
  1812. $object->fetch(0, $websitekey);
  1813. $website = $object;
  1814. if ($action == 'confirm_createfromclone') {
  1815. $db->begin();
  1816. $objectnew = new Website($db);
  1817. $result = $objectnew->createFromClone($user, GETPOST('id', 'int'), GETPOST('siteref', 'aZ09'), (GETPOST('newlang', 'aZ09') ?GETPOST('newlang', 'aZ09') : ''));
  1818. if ($result < 0) {
  1819. $error++;
  1820. setEventMessages($objectnew->error, $objectnew->errors, 'errors');
  1821. $action = 'preview';
  1822. $db->rollback();
  1823. } else {
  1824. $object = $objectnew;
  1825. $id = $object->id;
  1826. $pageid = $object->fk_default_home;
  1827. $websitekey = GETPOST('siteref', 'aZ09');
  1828. $db->commit();
  1829. }
  1830. }
  1831. if ($action == 'confirm_createpagefromclone') {
  1832. $istranslation = (GETPOST('is_a_translation', 'aZ09') == 'on' ? 1 : 0);
  1833. // Protection if it is a translation page
  1834. if ($istranslation) {
  1835. if (GETPOST('newlang', 'aZ09') == $objectpage->lang || !GETPOST('newlang', 'aZ09')) {
  1836. $error++;
  1837. setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
  1838. $action = 'preview';
  1839. }
  1840. if (GETPOST('newwebsite', 'int') != $object->id) {
  1841. $error++;
  1842. setEventMessages($langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation"), null, 'errors');
  1843. $action = 'preview';
  1844. }
  1845. }
  1846. if (!$error) {
  1847. $db->begin();
  1848. $newwebsiteid = GETPOST('newwebsite', 'int');
  1849. $pathofwebsitenew = $pathofwebsite;
  1850. $tmpwebsite = new Website($db);
  1851. if ($newwebsiteid > 0 && $newwebsiteid != $object->id) {
  1852. $tmpwebsite->fetch($newwebsiteid);
  1853. $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$tmpwebsite->ref;
  1854. } else {
  1855. $tmpwebsite = $object;
  1856. }
  1857. $objectpage = new WebsitePage($db);
  1858. $resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'));
  1859. if ($resultpage < 0) {
  1860. $error++;
  1861. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1862. $action = 'createpagefromclone';
  1863. $db->rollback();
  1864. } else {
  1865. $filetpl = $pathofwebsitenew.'/page'.$resultpage->id.'.tpl.php';
  1866. $fileindex = $pathofwebsitenew.'/index.php';
  1867. $filewrapper = $pathofwebsitenew.'/wrapper.php';
  1868. //var_dump($pathofwebsitenew);
  1869. //var_dump($filetpl);
  1870. //exit;
  1871. dolSavePageContent($filetpl, $tmpwebsite, $resultpage, 1);
  1872. // Switch on the new page if web site of new page/container is same
  1873. if (empty($newwebsiteid) || $newwebsiteid == $object->id) {
  1874. $pageid = $resultpage->id;
  1875. }
  1876. $db->commit();
  1877. }
  1878. }
  1879. }
  1880. $res = 0;
  1881. if (!$error) {
  1882. // Check symlink to medias and restore it if ko
  1883. $pathtomedias = DOL_DATA_ROOT.'/medias';
  1884. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  1885. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  1886. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  1887. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  1888. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  1889. }
  1890. /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
  1891. {
  1892. $object->virtualhost = GETPOST('previewsite', 'alpha');
  1893. $object->update($user);
  1894. }*/
  1895. $objectpage->fk_website = $object->id;
  1896. if ($pageid > 0) {
  1897. $res = $objectpage->fetch($pageid);
  1898. } else {
  1899. $res = 0;
  1900. if ($object->fk_default_home > 0) {
  1901. $res = $objectpage->fetch($object->fk_default_home);
  1902. }
  1903. if (!($res > 0)) {
  1904. $res = $objectpage->fetch(0, $object->id);
  1905. }
  1906. }
  1907. }
  1908. if (!$error && $res > 0) {
  1909. if ($action == 'updatesource' || $action == 'updatecontent') {
  1910. $db->begin();
  1911. $phpfullcodestringold = dolKeepOnlyPhpCode($objectpage->content);
  1912. $objectpage->content = GETPOST('PAGE_CONTENT', 'none');
  1913. $phpfullcodestring = dolKeepOnlyPhpCode($objectpage->content);
  1914. // Security analysis
  1915. $error = checkPHPCode($phpfullcodestringold, $phpfullcodestring);
  1916. if ($error) {
  1917. if ($action == 'updatesource') {
  1918. $action = 'editsource';
  1919. }
  1920. if ($action == 'updatecontent') {
  1921. $action = 'editcontent';
  1922. }
  1923. }
  1924. // Clean data. We remove all the head section.
  1925. $objectpage->content = preg_replace('/<head>.*<\/head>/ims', '', $objectpage->content);
  1926. /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
  1927. $res = $objectpage->update($user);
  1928. if ($res < 0) {
  1929. $error++;
  1930. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1931. if ($action == 'updatesource') {
  1932. $action = 'editsource';
  1933. }
  1934. if ($action == 'updatecontent') {
  1935. $action = 'editcontent';
  1936. }
  1937. }
  1938. if (!$error) {
  1939. $db->commit();
  1940. $filemaster = $pathofwebsite.'/master.inc.php';
  1941. //$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
  1942. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1943. dol_mkdir($pathofwebsite);
  1944. // Now generate the master.inc.php page
  1945. $result = dolSaveMasterFile($filemaster);
  1946. if (!$result) {
  1947. setEventMessages('Failed to write the master file file '.$filemaster, null, 'errors');
  1948. }
  1949. // Now delete the old alias.php page if we removed one
  1950. /*if (!empty($fileoldalias))
  1951. {
  1952. dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
  1953. dol_delete_file($fileoldalias);
  1954. // Delete also pages into language subdirectories
  1955. if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
  1956. $dirname = dirname($fileoldalias);
  1957. $filename = basename($fileoldalias);
  1958. $sublangs = explode(',', $object->otherlang);
  1959. foreach ($sublangs as $sublang) {
  1960. $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
  1961. dol_delete_file($fileoldaliassub);
  1962. }
  1963. }
  1964. }*/
  1965. // Save page alias
  1966. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1967. if (!$result) {
  1968. setEventMessages('Failed to write the alias file '.basename($filealias), null, 'errors');
  1969. }
  1970. // Save page content
  1971. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  1972. if ($result) {
  1973. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1974. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
  1975. if ($backtopage) {
  1976. header("Location: ".$backtopage);
  1977. exit;
  1978. } else {
  1979. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1980. exit;
  1981. }
  1982. } else {
  1983. if ($action == 'updatesource') {
  1984. $action = 'editsource';
  1985. }
  1986. if ($action == 'updatecontent') {
  1987. $action = 'editcontent';
  1988. }
  1989. }
  1990. } else {
  1991. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1992. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1993. exit;
  1994. }
  1995. } else {
  1996. $db->rollback();
  1997. }
  1998. } else {
  1999. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  2000. exit;
  2001. }
  2002. } else {
  2003. if (!$error) {
  2004. if (empty($websitekey) || $websitekey == '-1') {
  2005. setEventMessages($langs->trans("NoWebSiteCreateOneFirst"), null, 'warnings');
  2006. } else {
  2007. setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
  2008. setEventMessages($langs->trans("YouCanCreatePageOrImportTemplate"), null, 'warnings');
  2009. }
  2010. }
  2011. }
  2012. }
  2013. // Export site
  2014. if ($action == 'exportsite' && !empty($user->rights->website->export)) {
  2015. $fileofzip = $object->exportWebSite();
  2016. if ($fileofzip) {
  2017. $file_name = basename($fileofzip);
  2018. header("Content-Type: application/zip");
  2019. header("Content-Disposition: attachment; filename=".$file_name);
  2020. header("Content-Length: ".filesize($fileofzip));
  2021. readfile($fileofzip);
  2022. exit;
  2023. } else {
  2024. setEventMessages($object->error, $object->errors, 'errors');
  2025. $action = 'preview';
  2026. }
  2027. }
  2028. // Regenerate site
  2029. if ($action == 'regeneratesite' && $usercanedit) {
  2030. // Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
  2031. $pathtomedias = DOL_DATA_ROOT.'/medias';
  2032. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  2033. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  2034. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  2035. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
  2036. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  2037. if (!$result) {
  2038. setEventMessages($langs->trans("ErrorFieldToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
  2039. $action = 'preview';
  2040. }
  2041. }
  2042. $result = $object->rebuildWebSiteFiles();
  2043. if ($result > 0) {
  2044. setEventMessages($langs->trans("PagesRegenerated", $result), null, 'mesgs');
  2045. $action = 'preview';
  2046. } else {
  2047. setEventMessages($object->error, $object->errors, 'errors');
  2048. $action = 'preview';
  2049. }
  2050. }
  2051. // Import site
  2052. if ($action == 'importsiteconfirm' && $usercanedit) {
  2053. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  2054. $allowimportsite = true;
  2055. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  2056. $allowimportsite = false;
  2057. }
  2058. if ($allowimportsite) {
  2059. if (empty($_FILES) && !GETPOSTISSET('templateuserfile')) {
  2060. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  2061. $action = 'importsite';
  2062. } else {
  2063. if (!empty($_FILES) || GETPOSTISSET('templateuserfile')) {
  2064. // Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
  2065. $pathtomedias = DOL_DATA_ROOT.'/medias';
  2066. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  2067. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  2068. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  2069. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  2070. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  2071. if (!$result) {
  2072. setEventMessages($langs->trans("ErrorFieldToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
  2073. $action = 'importsite';
  2074. }
  2075. }
  2076. $fileofzip = '';
  2077. if (GETPOSTISSET('templateuserfile')) {
  2078. // Case we selected one template
  2079. $fileofzip = DOL_DATA_ROOT.'/doctemplates/websites/'.GETPOST('templateuserfile', 'alpha'); // $fileofzip will be sanitized later into the importWebSite()
  2080. } elseif (!empty($_FILES)) {
  2081. // Case we upload a new template
  2082. if (is_array($_FILES['userfile']['tmp_name'])) {
  2083. $userfiles = $_FILES['userfile']['tmp_name'];
  2084. } else {
  2085. $userfiles = array($_FILES['userfile']['tmp_name']);
  2086. }
  2087. // Check if $_FILES is ok
  2088. foreach ($userfiles as $key => $userfile) {
  2089. if (empty($_FILES['userfile']['tmp_name'][$key])) {
  2090. $error++;
  2091. if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) {
  2092. setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
  2093. $action = 'importsite';
  2094. } else {
  2095. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  2096. $action = 'importsite';
  2097. }
  2098. }
  2099. }
  2100. if (!$error) {
  2101. //$upload_dir = $conf->website->dir_temp;
  2102. $upload_dir = DOL_DATA_ROOT.'/doctemplates/websites/';
  2103. $result = dol_add_file_process($upload_dir, 1, -1, 'userfile', '');
  2104. }
  2105. // Get name of file (take last one if several name provided)
  2106. /*
  2107. $fileofzip = $upload_dir.'/unknown';
  2108. foreach ($_FILES as $key => $ifile) {
  2109. foreach ($ifile['name'] as $key2 => $ifile2) {
  2110. $fileofzip = $upload_dir.'/'.$ifile2;
  2111. }
  2112. }
  2113. */
  2114. $action = 'importsite';
  2115. }
  2116. if (!$error && GETPOSTISSET('templateuserfile')) {
  2117. $result = $object->importWebSite($fileofzip);
  2118. if ($result < 0) {
  2119. setEventMessages($object->error, $object->errors, 'errors');
  2120. $action = 'importsite';
  2121. } else {
  2122. // Force mode dynamic on
  2123. dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1, 'chaine', 0, '', $conf->entity);
  2124. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$object->ref);
  2125. exit();
  2126. }
  2127. }
  2128. }
  2129. }
  2130. } else {
  2131. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  2132. // Show clean corporate message
  2133. $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
  2134. } else {
  2135. // Show technical generic message
  2136. $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
  2137. }
  2138. setEventMessages($message, null, 'errors');
  2139. }
  2140. }
  2141. $domainname = '0.0.0.0:8080';
  2142. $tempdir = $conf->website->dir_output.'/'.$websitekey.'/';
  2143. // Generate web site sitemaps
  2144. if ($action == 'generatesitemaps' && $usercanedit) {
  2145. $domtree = new DOMDocument('1.0', 'UTF-8');
  2146. $root = $domtree->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
  2147. $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
  2148. $domtree->formatOutput = true;
  2149. $xmlname = 'sitemap.xml';
  2150. $sql = "SELECT wp.rowid, wp.type_container , wp.pageurl, wp.lang, wp.fk_page, wp.tms as tms,";
  2151. $sql .= " w.virtualhost, w.fk_default_home";
  2152. $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w";
  2153. $sql .= " WHERE wp.type_container IN ('page', 'blogpost')";
  2154. $sql .= " AND wp.fk_website = w.rowid";
  2155. $sql .= " AND wp.status = ".WebsitePage::STATUS_VALIDATED;
  2156. $sql .= " AND wp.pageurl NOT IN ('404', '500', '501', '503')";
  2157. $sql .= " AND w.ref = '".dol_escape_json($websitekey)."'";
  2158. $sql .= " ORDER BY wp.tms DESC, wp.rowid DESC";
  2159. $resql = $db->query($sql);
  2160. if ($resql) {
  2161. $num_rows = $db->num_rows($resql);
  2162. if ($num_rows > 0) {
  2163. $i = 0;
  2164. while ($i < $num_rows) {
  2165. $objp = $db->fetch_object($resql);
  2166. $url = $domtree->createElement('url');
  2167. $shortlangcode = '';
  2168. if ($objp->lang) {
  2169. $shortlangcode = substr($objp->lang, 0, 2); // en_US or en-US -> en
  2170. }
  2171. if (empty($shortlangcode)) {
  2172. $shortlangcode = substr($object->lang, 0, 2); // Use short lang code of website
  2173. }
  2174. // Forge $pageurl, adding language prefix if it is an alternative language
  2175. $pageurl = $objp->pageurl.'.php';
  2176. if ($objp->fk_default_home == $objp->rowid) {
  2177. $pageurl = '';
  2178. } else {
  2179. if ($shortlangcode != substr($object->lang, 0, 2)) {
  2180. $pageurl = $shortlangcode.'/'.$pageurl;
  2181. }
  2182. }
  2183. if ($objp->virtualhost) {
  2184. $domainname = $objp->virtualhost;
  2185. }
  2186. if (! preg_match('/^http/i', $domainname)) {
  2187. $domainname = 'https://'.$domainname;
  2188. }
  2189. //$pathofpage = $dolibarr_main_url_root.'/'.$pageurl.'.php';
  2190. // URL of sitemaps must end with trailing slash if page is ''
  2191. $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl);
  2192. $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate($objp->tms), 'dayrfc', 'gmt'));
  2193. $changefreq = $domtree->createElement('changefreq', 'weekly'); // TODO Manage other values
  2194. $priority = $domtree->createElement('priority', '1');
  2195. $url->appendChild($loc);
  2196. $url->appendChild($lastmod);
  2197. // Add suggested frequency for refresh
  2198. if (!empty($conf->global->WEBSITE_SITEMAPS_ADD_WEEKLY_FREQ)) {
  2199. $url->appendChild($changefreq);
  2200. }
  2201. // Add higher priority for home page
  2202. if ($objp->fk_default_home == $objp->rowid) {
  2203. $url->appendChild($priority);
  2204. }
  2205. // Now add alternate language entries
  2206. if ($object->isMultiLang()) {
  2207. $alternatefound = 0;
  2208. // Add page "translation of"
  2209. $translationof = $objp->fk_page;
  2210. if ($translationof) {
  2211. $tmppage = new WebsitePage($db);
  2212. $tmppage->fetch($translationof);
  2213. if ($tmppage->id > 0) {
  2214. $tmpshortlangcode = '';
  2215. if ($tmppage->lang) {
  2216. $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
  2217. }
  2218. if (empty($tmpshortlangcode)) {
  2219. $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
  2220. }
  2221. if ($tmpshortlangcode != $shortlangcode) {
  2222. $xhtmllink = $domtree->createElement('xhtml:link', '');
  2223. $xhtmllink->setAttribute("rel", "alternate");
  2224. $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
  2225. $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php'));
  2226. $url->appendChild($xhtmllink);
  2227. $alternatefound++;
  2228. }
  2229. }
  2230. }
  2231. // Add "has translation pages"
  2232. $sql = 'SELECT rowid as id, lang, pageurl from '.MAIN_DB_PREFIX.'website_page';
  2233. $sql .= " WHERE status = ".((int) WebsitePage::STATUS_VALIDATED).' AND fk_page IN ('.$db->sanitize($objp->rowid.($translationof ? ", ".$translationof : "")).")";
  2234. $resqlhastrans = $db->query($sql);
  2235. if ($resqlhastrans) {
  2236. $num_rows_hastrans = $db->num_rows($resqlhastrans);
  2237. if ($num_rows_hastrans > 0) {
  2238. while ($objhastrans = $db->fetch_object($resqlhastrans)) {
  2239. $tmpshortlangcode = '';
  2240. if ($objhastrans->lang) {
  2241. $tmpshortlangcode = preg_replace('/[_-].*$/', '', $objhastrans->lang); // en_US or en-US -> en
  2242. }
  2243. if ($tmpshortlangcode != $shortlangcode) {
  2244. $xhtmllink = $domtree->createElement('xhtml:link', '');
  2245. $xhtmllink->setAttribute("rel", "alternate");
  2246. $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
  2247. $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $objhastrans->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$objhastrans->pageurl.'.php'));
  2248. $url->appendChild($xhtmllink);
  2249. $alternatefound++;
  2250. }
  2251. }
  2252. }
  2253. } else {
  2254. dol_print_error($db);
  2255. }
  2256. if ($alternatefound) {
  2257. // Add myself
  2258. $xhtmllink = $domtree->createElement('xhtml:link', '');
  2259. $xhtmllink->setAttribute("rel", "alternate");
  2260. $xhtmllink->setAttribute("hreflang", $shortlangcode);
  2261. $xhtmllink->setAttribute("href", $domainname.'/'.$pageurl);
  2262. $url->appendChild($xhtmllink);
  2263. }
  2264. }
  2265. // Now add sitempas extension for news
  2266. // TODO When adding and when not ?
  2267. /*<news:news>
  2268. <news:publication>
  2269. <news:name>The Example Times</news:name>
  2270. <news:language>en</news:language>
  2271. </news:publication>
  2272. <news:publication_date>2008-12-23</news:publication_date>
  2273. <news:title>Companies A, B in Merger Talks</news:title>
  2274. </news:news>
  2275. */
  2276. $root->appendChild($url);
  2277. $i++;
  2278. }
  2279. $domtree->appendChild($root);
  2280. if ($domtree->save($tempdir.$xmlname)) {
  2281. if (!empty($conf->global->MAIN_UMASK)) {
  2282. @chmod($tempdir.$xmlname, octdec($conf->global->MAIN_UMASK));
  2283. }
  2284. setEventMessages($langs->trans("SitemapGenerated", $xmlname), null, 'mesgs');
  2285. } else {
  2286. setEventMessages($object->error, $object->errors, 'errors');
  2287. }
  2288. }
  2289. } else {
  2290. dol_print_error($db);
  2291. }
  2292. // Add the entry Sitemap: into the robot file.
  2293. $robotcontent = @file_get_contents($filerobot);
  2294. $result = preg_replace('/<?php // BEGIN PHP[^?]END PHP ?>\n/ims', '', $robotcontent);
  2295. if ($result) {
  2296. $robotcontent = $result;
  2297. }
  2298. $robotsitemap = "Sitemap: ".$domainname."/".$xmlname;
  2299. $result = strpos($robotcontent, 'Sitemap: ');
  2300. if ($result) {
  2301. $result = preg_replace('/Sitemap:.*/', $robotsitemap, $robotcontent);
  2302. $robotcontent = $result ? $result : $robotcontent;
  2303. } else {
  2304. $robotcontent .= $robotsitemap."\n";
  2305. }
  2306. $result = dolSaveRobotFile($filerobot, $robotcontent);
  2307. if (!$result) {
  2308. $error++;
  2309. setEventMessages('Failed to write file '.$filerobot, null, 'errors');
  2310. }
  2311. $action = 'preview';
  2312. }
  2313. /*
  2314. * View
  2315. */
  2316. $form = new Form($db);
  2317. $formadmin = new FormAdmin($db);
  2318. $formwebsite = new FormWebsite($db);
  2319. $formother = new FormOther($db);
  2320. $formconfirm = "";
  2321. // Confirm generation of website sitemaps
  2322. if ($action == 'confirmgeneratesitemaps') {
  2323. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.urlencode($website->ref), $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1);
  2324. $action = 'preview';
  2325. }
  2326. $helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:M&oacute;dulo_Website';
  2327. $arrayofjs = array(
  2328. '/includes/ace/src/ace.js',
  2329. '/includes/ace/src/ext-statusbar.js',
  2330. '/includes/ace/src/ext-language_tools.js',
  2331. //'/includes/ace/src/ext-chromevox.js'
  2332. //'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
  2333. );
  2334. $arrayofcss = array();
  2335. $moreheadcss = '';
  2336. $moreheadjs = '';
  2337. $arrayofjs[] = 'includes/jquery/plugins/blockUI/jquery.blockUI.js';
  2338. $arrayofjs[] = 'core/js/blockUI.js'; // Used by ecm/tpl/enabledfiletreeajax.tpl.php
  2339. if (empty($conf->global->MAIN_ECM_DISABLE_JS)) {
  2340. $arrayofjs[] = "includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
  2341. }
  2342. $moreheadjs .= '<script type="text/javascript">'."\n";
  2343. $moreheadjs .= 'var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
  2344. $moreheadjs .= '</script>'."\n";
  2345. llxHeader($moreheadcss.$moreheadjs, $langs->trans("Website").(empty($website->ref) ? '' : ' - '.$website->ref), $helpurl, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
  2346. print "\n";
  2347. print '<!-- Open form for all page -->'."\n";
  2348. print '<form action="'.$_SERVER["PHP_SELF"].($action == 'file_manager' ? '?uploadform=1': '').'" method="POST" enctype="multipart/form-data" class="websiteformtoolbar">';
  2349. print '<input type="hidden" name="token" value="'.newToken().'">';
  2350. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  2351. print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
  2352. if ($action == 'createsite') {
  2353. print '<input type="hidden" name="action" value="addsite">';
  2354. }
  2355. if ($action == 'createcontainer') {
  2356. print '<input type="hidden" name="action" value="addcontainer">';
  2357. }
  2358. if ($action == 'editcss') {
  2359. print '<input type="hidden" name="action" value="updatecss">';
  2360. }
  2361. if ($action == 'editmenu') {
  2362. print '<input type="hidden" name="action" value="updatemenu">';
  2363. }
  2364. if ($action == 'setashome') {
  2365. print '<input type="hidden" name="action" value="updateashome">';
  2366. }
  2367. if ($action == 'editmeta') {
  2368. print '<input type="hidden" name="action" value="updatemeta">';
  2369. }
  2370. if ($action == 'editsource') {
  2371. print '<input type="hidden" name="action" value="updatesource">';
  2372. }
  2373. if ($action == 'editcontent') {
  2374. print '<input type="hidden" name="action" value="updatecontent">';
  2375. }
  2376. if ($action == 'edit') {
  2377. print '<input type="hidden" name="action" value="update">';
  2378. }
  2379. if ($action == 'importsite') {
  2380. print '<input type="hidden" name="action" value="importsiteconfirm">';
  2381. }
  2382. if ($action == 'file_manager') {
  2383. print '<input type="hidden" name="action" value="file_manager">';
  2384. }
  2385. if ($mode) {
  2386. print '<input type="hidden" name="mode" value="'.$mode.'">';
  2387. }
  2388. print '<div>';
  2389. // Add a margin under toolbar ?
  2390. $style = '';
  2391. if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource' && !GETPOST('createpagefromclone', 'alphanohtml')) {
  2392. $style = ' margin-bottom: 5px;';
  2393. }
  2394. if (!GETPOST('hide_websitemenu')) {
  2395. $disabled = '';
  2396. if (empty($user->rights->website->write)) {
  2397. $disabled = ' disabled="disabled"';
  2398. }
  2399. $disabledexport = '';
  2400. if (empty($user->rights->website->export)) {
  2401. $disabledexport = ' disabled="disabled"';
  2402. }
  2403. if ($websitekey) {
  2404. $virtualurl = '';
  2405. $dataroot = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
  2406. if (!empty($object->virtualhost)) {
  2407. $virtualurl = $object->virtualhost;
  2408. }
  2409. }
  2410. $array = array();
  2411. if ($object->id > 0) {
  2412. $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  2413. $object->lines = $array;
  2414. }
  2415. if (!is_array($array) && $array < 0) {
  2416. dol_print_error('', $objectpage->error, $objectpage->errors);
  2417. }
  2418. $atleastonepage = (is_array($array) && count($array) > 0);
  2419. $websitepage = new WebSitePage($db);
  2420. if ($pageid > 0) {
  2421. $websitepage->fetch($pageid);
  2422. }
  2423. //var_dump($objectpage);exit;
  2424. print '<div class="centpercent websitebar'.(GETPOST('dol_openinpopup', 'aZ09') ? ' hidden' : '').'">';
  2425. //
  2426. // Toolbar for websites
  2427. //
  2428. print '<!-- Toolbar for website -->';
  2429. if ($action != 'file_manager') {
  2430. print '<div class="websiteselection hideonsmartphoneimp minwidth75 tdoverflowmax100 inline-block">';
  2431. print $langs->trans("Website").': ';
  2432. print '</div>';
  2433. // Button Add new website
  2434. $urltocreatenewwebsite = $_SERVER["PHP_SELF"].'?action=createsite';
  2435. print '<span class="websiteselection paddingrightonly">';
  2436. print '<a href="'.$urltocreatenewwebsite.'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddWebsite")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"><span></a>';
  2437. print '</span>';
  2438. // List of website
  2439. print '<span class="websiteselection nopaddingrightimp">';
  2440. $out = '';
  2441. $out .= '<select name="website" class="minwidth100 width200 maxwidth150onsmartphone" id="website">';
  2442. if (empty($object->records)) {
  2443. $out .= '<option value="-1">&nbsp;</option>';
  2444. }
  2445. // Loop on each sites
  2446. $i = 0;
  2447. foreach ($object->records as $key => $valwebsite) {
  2448. if (empty($websitekey)) {
  2449. if ($action != 'createsite') {
  2450. $websitekey = $valwebsite->ref;
  2451. }
  2452. }
  2453. $out .= '<option value="'.$valwebsite->ref.'"';
  2454. if ($websitekey == $valwebsite->ref) {
  2455. $out .= ' selected'; // To preselect a value
  2456. }
  2457. //$outoption = $valwebsite->getLibStatut(3).' '.$valwebsite->ref.' ';
  2458. $outoption = (($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '<span class="opacitymedium">' : '').$valwebsite->ref.(($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '</span>' : '');
  2459. $out .= ' data-html="'.dol_escape_htmltag($outoption).'"';
  2460. $out .= '>';
  2461. $out .= $valwebsite->ref;
  2462. $out .= '</option>';
  2463. $i++;
  2464. }
  2465. $out .= '</select>';
  2466. $out .= ajax_combobox('website');
  2467. if (!empty($conf->use_javascript_ajax)) {
  2468. $out .= '<script type="text/javascript">';
  2469. $out .= 'jQuery(document).ready(function () {';
  2470. $out .= ' jQuery("#website").change(function () {';
  2471. $out .= ' console.log("We select "+jQuery("#website option:selected").val());';
  2472. $out .= ' if (jQuery("#website option:selected").val() == \'-2\') {';
  2473. $out .= ' window.location.href = "'.dol_escape_js($urltocreatenewwebsite).'";';
  2474. $out .= ' } else {';
  2475. $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website="+jQuery("#website option:selected").val();';
  2476. $out .= ' }';
  2477. $out .= ' });';
  2478. $out .= '});';
  2479. $out .= '</script>';
  2480. }
  2481. print $out;
  2482. print '</span>';
  2483. // Switch offline/onine
  2484. if (!empty($conf->use_javascript_ajax)) {
  2485. print '<span class="websiteselection">';
  2486. // Do not use ajax, we need a refresh of full page when we change status of a website
  2487. //print '<div class="inline-block marginrightonly">';
  2488. //print ajax_object_onoff($object, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle', 'statuswebsite');
  2489. //print '</div>';
  2490. if ($website->status == $website::STATUS_DRAFT) {
  2491. $text_off = 'Offline';
  2492. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setwebsiteonline&token='.newToken().'&website='.urlencode($website->ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_off').'</a>';
  2493. } else {
  2494. $text_off = 'Online';
  2495. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setwebsiteoffline&token='.newToken().'&website='.urlencode($website->ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_on').'</a>';
  2496. }
  2497. print '</span>';
  2498. }
  2499. // Refresh / Reload web site (for non javascript browers)
  2500. if (empty($conf->use_javascript_ajax)) {
  2501. print '<span class="websiteselection">';
  2502. print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshsite" value="'.$langs->trans("Load").'">';
  2503. print '</span>';
  2504. }
  2505. print '<span class="websiteselection">';
  2506. if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
  2507. // Edit website properties
  2508. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.urlencode($object->ref).'&pageid='.((int) $pageid).'&action=editcss&token='.newToken().'" class="button bordertransp" title="'.dol_escape_htmltag($langs->trans("EditCss")).'"'.$disabled.'><span class="fa fa-cog paddingrightonly"></span><span class="hideonsmartphone">'.dol_escape_htmltag($langs->trans("EditCss")).'</span></a>';
  2509. // Import web site
  2510. $importlabel = $langs->trans("ImportSite");
  2511. $exportlabel = $langs->trans("ExportSite");
  2512. if (!empty($conf->dol_optimize_smallscreen)) {
  2513. $importlabel = $langs->trans("Import");
  2514. $exportlabel = $langs->trans("Export");
  2515. }
  2516. if ($atleastonepage) {
  2517. print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
  2518. } else {
  2519. print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
  2520. }
  2521. // Export web site
  2522. print '<input type="submit" class="button bordertransp"'.$disabledexport.' value="'.dol_escape_htmltag($exportlabel).'" name="exportsite">';
  2523. // Clone web site
  2524. print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
  2525. // Delete website
  2526. if (!$permissiontodelete) {
  2527. $disabled = ' disabled="disabled"';
  2528. $title = $langs->trans("NotEnoughPermissions");
  2529. $url = '#';
  2530. } else {
  2531. if ($website->status == $website::STATUS_VALIDATED) {
  2532. $disabled = ' disabled="disabled"';
  2533. $title = $langs->trans("WebsiteMustBeDisabled", $langs->transnoentitiesnoconv($website->LibStatut(0, 0)));
  2534. $url = '#';
  2535. } else {
  2536. $disabled = '';
  2537. $title = $langs->trans("Delete");
  2538. $url = $_SERVER["PHP_SELF"].'?action=deletesite&token='.newToken().'&website='.urlencode($website->ref);
  2539. }
  2540. }
  2541. print '<a href="'.$url.'" class="button buttonDelete bordertransp'.($disabled ? ' disabled' : '').'"'.$disabled.' title="'.dol_escape_htmltag($title).'">'.img_picto('', 'delete', 'class=""').'<span class="hideonsmartphone paddingleft">'.$langs->trans("Delete").'</span></a>';
  2542. // Regenerate all pages
  2543. print '<a href="'.$_SERVER["PHP_SELF"].'?action=regeneratesite&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'"><span class="far fa-hdd"></span></a>';
  2544. // Generate site map
  2545. print '<a href="'.$_SERVER["PHP_SELF"].'?action=confirmgeneratesitemaps&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'"><span class="fa fa-sitemap"></span></a>';
  2546. // Find / replace tool
  2547. print '<a href="'.$_SERVER["PHP_SELF"].'?mode=replacesite&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'"><span class="fa fa-search"></span></a>';
  2548. }
  2549. print '</span>';
  2550. if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
  2551. print '<span class="websiteselection">';
  2552. print dolButtonToOpenUrlInDialogPopup('file_manager', $langs->transnoentitiesnoconv("MediaFiles"), '<span class="fa fa-image"></span>', '/website/index.php?action=file_manager&website='.urlencode($website->ref).'&section_dir='.urlencode('image/'.$website->ref.'/'), $disabled);
  2553. if (isModEnabled('categorie')) {
  2554. //print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=website&dol_hide_leftmenu=1&nosearch=1&type=website_page&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("Categories")).'"><span class="fa fa-tags"></span></a>';
  2555. print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), '<span class="fa fa-tags"></span>', '/categories/index.php?leftmenu=website&nosearch=1&type=website_page&website='.urlencode($website->ref), $disabled);
  2556. }
  2557. print '</span>';
  2558. }
  2559. } else {
  2560. print '<input type="hidden" name="website" id="website" value="'.$websitekey.'">';
  2561. }
  2562. print '<span class="websitetools">';
  2563. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
  2564. $urlext = $virtualurl;
  2565. $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
  2566. print '<span class="websiteinputurl valignmiddle" id="websiteinputurl">';
  2567. $linktotestonwebserver = '<a href="'.($virtualurl ? $virtualurl : '#').'" class="valignmiddle">';
  2568. $linktotestonwebserver .= '<span class="hideonsmartphone paddingrightonly">'.$langs->trans("TestDeployOnWeb", $virtualurl).'</span>'.img_picto('', 'globe');
  2569. $linktotestonwebserver .= '</a>';
  2570. $htmltext = '';
  2571. if (empty($object->fk_default_home)) {
  2572. $htmltext .= '<br><span class="error">'.$langs->trans("YouMustDefineTheHomePage").'</span><br><br>';
  2573. } elseif (empty($virtualurl)) {
  2574. //$htmltext .= '<br><span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span><br><br>';
  2575. } else {
  2576. $htmltext .= '<br><center>'.$langs->trans("GoTo").' <a href="'.$virtualurl.'" target="_website">'.$virtualurl.'</a></center><br>';
  2577. }
  2578. if (!empty($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER)) {
  2579. $htmltext .= '<!-- Message defined translate key set into WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER -->';
  2580. $htmltext .= '<br>'.$langs->trans($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER);
  2581. } else {
  2582. $htmltext .= $langs->trans("SetHereVirtualHost", $dataroot);
  2583. $htmltext .= '<br>';
  2584. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  2585. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
  2586. $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);
  2587. $examplewithapache = '#php_admin_value open_basedir /tmp/:'.DOL_DOCUMENT_ROOT.':'.DOL_DATA_ROOT.':/dev/urandom'."\n";
  2588. $examplewithapache .= '<Directory "'.DOL_DOCUMENT_ROOT.'">'."\n";
  2589. $examplewithapache .= 'AllowOverride FileInfo Options
  2590. Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
  2591. Require all granted
  2592. </Directory>
  2593. <Directory "'.DOL_DATA_ROOT.'/website">
  2594. AllowOverride FileInfo Options
  2595. Options -Indexes -MultiViews +FollowSymLinks -ExecCGI
  2596. Require all granted
  2597. </Directory>
  2598. <Directory "'.DOL_DATA_ROOT.'/medias">
  2599. AllowOverride FileInfo Options
  2600. Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
  2601. Require all granted
  2602. </Directory>';
  2603. $htmltext .= '<br>'.$langs->trans("ExampleToUseInApacheVirtualHostConfig").':<br>';
  2604. $htmltext .= '<div class="centpercent exampleapachesetup">'.dol_nl2br(dol_escape_htmltag($examplewithapache, 1, 1)).'</div>';
  2605. $htmltext .= '<br>';
  2606. $htmltext .= $langs->trans("YouCanAlsoTestWithPHPS", $dataroot);
  2607. $htmltext .= '<br>';
  2608. $htmltext .= '<br>';
  2609. $htmltext .= $langs->trans("YouCanAlsoDeployToAnotherWHP");
  2610. }
  2611. print $form->textwithpicto($linktotestonwebserver, $htmltext, 1, 'none', 'valignmiddle', 0, 3, 'helpvirtualhost');
  2612. print '</span>';
  2613. }
  2614. if (in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesiteconfirm')) || in_array($mode, array('replacesite'))) {
  2615. if ($action == 'editcss') {
  2616. print '<input type="submit" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
  2617. }
  2618. if (preg_match('/^create/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
  2619. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2620. }
  2621. if (preg_match('/^edit/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
  2622. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2623. }
  2624. if ($action != 'preview') {
  2625. print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
  2626. }
  2627. }
  2628. print '</span>';
  2629. //
  2630. // Toolbar for pages
  2631. //
  2632. if ($websitekey && $websitekey != '-1' && (!in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesiteconfirm'))) && (!in_array($mode, array('replacesite'))) && !$file_manager) {
  2633. print '</div>'; // Close current websitebar to open a new one
  2634. print '<!-- Toolbar for websitepage -->';
  2635. print '<div class="centpercent websitebar"'.($style ? ' style="'.$style.'"' : '').'">';
  2636. print '<div class="websiteselection hideonsmartphoneimp minwidth75 tdoverflowmax100 inline-block">';
  2637. print $langs->trans("PageContainer").': ';
  2638. print '</div>';
  2639. // Button Add new web page
  2640. print '<span class="websiteselection paddingrightonly">';
  2641. print '<a href="'.$_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref).'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"></span></a>';
  2642. print '</span>';
  2643. $out = '';
  2644. $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone');
  2645. $out .= '<span class="websiteselection nopaddingrightimp">';
  2646. $out .= $s;
  2647. $out .= '</span>';
  2648. $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref);
  2649. if (!empty($conf->use_javascript_ajax)) {
  2650. $out .= '<script type="text/javascript">';
  2651. $out .= 'jQuery(document).ready(function () {';
  2652. $out .= ' jQuery("#pageid").change(function () {';
  2653. $out .= ' console.log("We select "+jQuery("#pageid option:selected").val());';
  2654. $out .= ' if (jQuery("#pageid option:selected").val() == \'-2\') {';
  2655. $out .= ' window.location.href = "'.$urltocreatenewpage.'";';
  2656. $out .= ' } else {';
  2657. $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website='.urlencode($website->ref).'&pageid="+jQuery("#pageid option:selected").val();';
  2658. $out .= ' }';
  2659. $out .= ' });';
  2660. $out .= '});';
  2661. $out .= '</script>';
  2662. }
  2663. print $out;
  2664. if (!empty($conf->use_javascript_ajax)) {
  2665. print '<span class="websiteselection">';
  2666. //print '<div class="inline-block marginrightonly">';
  2667. if ($object->status == $object::STATUS_DRAFT) { // website is off, we do not allow to change status of page
  2668. $text_off = 'SetWebsiteOnlineBefore';
  2669. if ($websitepage->status == $websitepage::STATUS_DRAFT) { // page is off
  2670. print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_off').'</span>';
  2671. } else {
  2672. print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_on').'</span>';
  2673. }
  2674. } else {
  2675. print ajax_object_onoff($websitepage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle'.(empty($websitepage->id) ? ' opacitymedium disabled' : ''), 'statuswebsitepage');
  2676. }
  2677. //print '</div>';
  2678. print '</span>';
  2679. }
  2680. print '<span class="websiteselection">';
  2681. print '<input type="image" class="valignmiddle buttonwebsite" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'"'.(($action != 'editsource') ? '' : ' disabled="disabled"').'>';
  2682. // Print nav arrows
  2683. $pagepreviousid = 0;
  2684. $pagenextid = 0;
  2685. if ($pageid) {
  2686. $sql = "SELECT MAX(rowid) as pagepreviousid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid < ".((int) $pageid)." AND fk_website = ".((int) $object->id);
  2687. $resql = $db->query($sql);
  2688. if ($resql) {
  2689. $obj = $db->fetch_object($resql);
  2690. if ($obj) {
  2691. $pagepreviousid = $obj->pagepreviousid;
  2692. }
  2693. } else {
  2694. dol_print_error($db);
  2695. }
  2696. $sql = "SELECT MIN(rowid) as pagenextid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid > ".((int) $pageid)." AND fk_website = ".((int) $object->id);
  2697. $resql = $db->query($sql);
  2698. if ($resql) {
  2699. $obj = $db->fetch_object($resql);
  2700. if ($obj) {
  2701. $pagenextid = $obj->pagenextid;
  2702. }
  2703. } else {
  2704. dol_print_error($db);
  2705. }
  2706. }
  2707. if ($pagepreviousid) {
  2708. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.((int) $pagepreviousid).'&action='.urlencode($action).'&token='.newToken().'">'.img_previous($langs->trans("PreviousContainer")).'</a>';
  2709. } else {
  2710. print '<span class="valignmiddle opacitymedium">'.img_previous($langs->trans("PreviousContainer")).'</span>';
  2711. }
  2712. if ($pagenextid) {
  2713. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.((int) $pagenextid).'&action='.urlencode($action).'&token='.newToken().'">'.img_next($langs->trans("NextContainer")).'</a>';
  2714. } else {
  2715. print '<span class="valignmiddle opacitymedium">'.img_next($langs->trans("NextContainer")).'</span>';
  2716. }
  2717. print '</span>';
  2718. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
  2719. $disabled = '';
  2720. if (empty($user->rights->website->write)) {
  2721. $disabled = ' disabled="disabled"';
  2722. }
  2723. // Confirmation delete site
  2724. if ($action == 'deletesite') {
  2725. // Create an array for form
  2726. $formquestion = array(
  2727. array('type' => 'checkbox', 'name' => 'delete_also_js', 'label' => $langs->trans("DeleteAlsoJs"), 'value' => 0),
  2728. array('type' => 'checkbox', 'name' => 'delete_also_medias', 'label' => $langs->trans("DeleteAlsoMedias"), 'value' => 0),
  2729. //array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'aZ09')?GETPOST('newlang', 'aZ09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')),
  2730. //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
  2731. );
  2732. if ($atleastonepage) {
  2733. $langs->load("errors");
  2734. $formquestion[] = array('type' => 'onecolumn', 'value' => '<div class="warning">'.$langs->trans("WarningPagesWillBeDeleted").'</div>');
  2735. }
  2736. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsite'), '', 'confirm_deletesite', $formquestion, 0, 1, 210 + ($atleastonepage ? 70 : 0), 580);
  2737. print $formconfirm;
  2738. }
  2739. // Confirmation to clone
  2740. if ($action == 'createfromclone') {
  2741. // Create an array for form
  2742. $formquestion = array(
  2743. array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite"), 'value'=> 'copy_of_'.$object->ref)
  2744. );
  2745. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
  2746. print $formconfirm;
  2747. }
  2748. if ($pageid > 0 && $atleastonepage) { // pageid can be set without pages, if homepage of site is set and all pages were removed
  2749. // Confirmation to clone
  2750. if ($action == 'createpagefromclone') {
  2751. // Create an array for form
  2752. $preselectedlanguage = GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''; // Dy default, we do not force any language on pages
  2753. $onlylang = array();
  2754. if ($website->otherlang) {
  2755. if (!empty($website->lang)) {
  2756. $onlylang[$website->lang] = $website->lang.' ('.$langs->trans("Default").')';
  2757. }
  2758. foreach (explode(',', $website->otherlang) as $langkey) {
  2759. if (empty(trim($langkey))) continue;
  2760. $onlylang[$langkey] = $langkey;
  2761. }
  2762. $textifempty = $langs->trans("Default");
  2763. } else {
  2764. $onlylang['none'] = 'none';
  2765. $textifempty = $langs->trans("Default");
  2766. }
  2767. $formquestion = array(
  2768. array('type' => 'hidden', 'name' => 'sourcepageurl', 'value'=> $objectpage->pageurl),
  2769. array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
  2770. array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'moreattr'=>'autofocus="autofocus"', 'name' => 'newtitle', 'label'=> $langs->trans("WEBSITE_TITLE"), 'value'=> $langs->trans("CopyOf").' '.$objectpage->title),
  2771. array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'newpageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> '')
  2772. );
  2773. if (count($onlylang) > 1) {
  2774. $formquestion[] = array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0, 'morecss'=>'margintoponly');
  2775. }
  2776. $value= $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, $textifempty, 0, 0, 'minwidth200', 1, 0, 0, $onlylang, 1);
  2777. $formquestion[] = array('type' => 'other', 'name' => 'newlang', 'label' => $form->textwithpicto($langs->trans("Language"), $langs->trans("DefineListOfAltLanguagesInWebsiteProperties")), 'value' => $value);
  2778. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
  2779. print $formconfirm;
  2780. }
  2781. print '<span class="websiteselection">';
  2782. // Edit web page properties
  2783. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editmeta&token='.newToken().'" class="button bordertransp" title="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'"'.$disabled.'><span class="fa fa-cog paddingrightonly"></span><span class="hideonsmartphone">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</span></a>';
  2784. // Edit HTML content
  2785. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editsource&token='.newToken().'" class="button bordertransp"'.$disabled.'>'.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "HTML" : "EditHTMLSource")).'</a>';
  2786. print '</span>';
  2787. // Switch include dynamic content / edit inline
  2788. print '<!-- button EditInLine and ShowSubcontainers -->'."\n";
  2789. print '<div class="websiteselectionsection inline-block">';
  2790. print '<div class="inline-block marginrightonly">'; // Button include dynamic contant
  2791. print $langs->trans("ShowSubcontainers");
  2792. if (empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) {
  2793. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=setshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2794. } else {
  2795. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unsetshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2796. }
  2797. print '</div>';
  2798. print '<div class="inline-block marginrightonly">'; // Button edit inline
  2799. print '<span id="switchckeditorinline">'."\n";
  2800. print '<!-- Code to enabled edit inline ckeditor -->'."\n";
  2801. print '<script type="text/javascript">
  2802. $(document).ready(function() {
  2803. var isEditingEnabled = '.(getDolGlobalString("WEBSITE_EDITINLINE") ? 'true' : 'false').';
  2804. if (isEditingEnabled)
  2805. {
  2806. switchEditorOnline(true);
  2807. }
  2808. $( "#switchckeditorinline" ).click(function() {
  2809. switchEditorOnline();
  2810. });
  2811. function switchEditorOnline(forceenable)
  2812. {
  2813. if (! isEditingEnabled || forceenable)
  2814. {
  2815. console.log("Enable inline edit");
  2816. jQuery(\'section[contenteditable="true"],div[contenteditable="true"]\').each(function(idx){
  2817. var idtouse = $(this).attr(\'id\');
  2818. console.log("Enable inline edit for "+idtouse);
  2819. CKEDITOR.inline(idtouse, {
  2820. // Allow some non-standard markup that we used in the introduction.
  2821. extraAllowedContent: \'span(*);cite(*);q(*);dl(*);dt(*);dd(*);ul(*);li(*);header(*);button(*);h1(*);h2(*);\',
  2822. //extraPlugins: \'sourcedialog\',
  2823. removePlugins: \'flash,stylescombo,exportpdf,scayt,wsc,pagebreak,iframe,smiley\',
  2824. // Show toolbar on startup (optional).
  2825. // startupFocus: true
  2826. });
  2827. })
  2828. isEditingEnabled = true;
  2829. }
  2830. else {
  2831. console.log("Disable inline edit");
  2832. for(name in CKEDITOR.instances)
  2833. {
  2834. CKEDITOR.instances[name].destroy(true);
  2835. }
  2836. isEditingEnabled = false;
  2837. }
  2838. };
  2839. });
  2840. </script>';
  2841. print $langs->trans("EditInLine");
  2842. print '</span>';
  2843. //$disableeditinline = $websitepage->grabbed_from;
  2844. $disableeditinline = 0;
  2845. if ($disableeditinline) {
  2846. //print '<input type="submit" class="button bordertransp" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'" value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
  2847. print '<a class="nobordertransp opacitymedium nohoverborder marginleftonlyshort"'.$disabled.' href="#" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'">'.img_picto($langs->trans("OnlyEditionOfSourceForGrabbedContent"), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2848. } else {
  2849. //print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
  2850. if (empty($conf->global->WEBSITE_EDITINLINE)) {
  2851. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=seteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2852. } else {
  2853. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unseteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2854. }
  2855. }
  2856. print '</div>';
  2857. print '</div>';
  2858. // Set page as homepage
  2859. if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) {
  2860. //$disabled=' disabled="disabled"';
  2861. //print '<span class="button bordertransp disabled"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fa fa-home"></span></span>';
  2862. //print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  2863. print '<a href="#" class="button bordertransp disabled" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fa fa-home valignmiddle btnTitle-icon"></span></a>';
  2864. } else {
  2865. //$disabled='';
  2866. //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  2867. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setashome&token='.newToken().'&website='.urlencode($website->ref).'&pageid='.((int) $pageid).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fa fa-home valignmiddle btnTitle-icon"></span></a>';
  2868. }
  2869. print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
  2870. // Delete
  2871. if ($websitepage->status != $websitepage::STATUS_DRAFT) {
  2872. $disabled = ' disabled="disabled"';
  2873. $title = $langs->trans("WebpageMustBeDisabled", $langs->transnoentitiesnoconv($websitepage->LibStatut(0, 0)));
  2874. $url = '#';
  2875. } else {
  2876. $disabled = '';
  2877. $title = '';
  2878. $url = $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&pageid='.((int) $websitepage->id).'&website='.urlencode($website->ref); // action=delete for webpage, deletesite for website
  2879. }
  2880. print '<a href="'.$url.'" class="button buttonDelete bordertransp'.($disabled ? ' disabled' : '').'"'.$disabled.' title="'.dol_escape_htmltag($title).'">'.img_picto('', 'delete', 'class=""').'<span class="hideonsmartphone paddingleft">'.$langs->trans("Delete").'</span></a>';
  2881. }
  2882. }
  2883. //print '</span>'; // end website selection
  2884. print '<span class="websitetools">';
  2885. if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
  2886. $realpage = $urlwithroot.'/public/website/index.php?website='.$websitekey.'&pageref='.$websitepage->pageurl;
  2887. $pagealias = $websitepage->pageurl;
  2888. $htmltext = $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot);
  2889. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), '{s1}');
  2890. $htmltext = str_replace('{s1}', $dataroot.'<br>'.DOL_DATA_ROOT.'/medias<br>'.DOL_DOCUMENT_ROOT, $htmltext);
  2891. //$htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
  2892. //$htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/medias', $htmltext);
  2893. print '<div class="websiteinputurl inline-block paddingright">';
  2894. print '<a class="websitebuttonsitepreview inline-block" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$websitekey.'" alt="'.dol_escape_htmltag($htmltext).'">';
  2895. print $form->textwithpicto('', $htmltext, 1, 'preview');
  2896. print '</a>'; // View page in new Tab
  2897. print '</div>';
  2898. /*print '<div class="websiteinputurl inline-block" id="websiteinputpage">';
  2899. print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
  2900. $htmltext = $langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
  2901. print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
  2902. print '</div>';*/
  2903. /*
  2904. $urlext = $virtualurl.'/'.$pagealias.'.php';
  2905. $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
  2906. $htmltext = $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl ? $urlext : '<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>');
  2907. print '<a class="websitebuttonsitepreview'.($virtualurl ? '' : ' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$websitekey.'ext" alt="'.dol_escape_htmltag($htmltext).'">';
  2908. print $form->textwithpicto('', $htmltext, 1, 'preview_ext');
  2909. print '</a>';
  2910. */
  2911. //print '<input type="submit" class="button" name="previewpage" target="tab'.$websitekey.'"value="'.$langs->trans("ViewPageInNewTab").'">';
  2912. // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
  2913. }
  2914. if (!in_array($mode, array('replacesite')) && !in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesiteconfirm', 'createsite', 'createcontainer', 'createfromclone', 'createpagefromclone', 'deletesite'))) {
  2915. if ($action == 'editsource' || $action == 'editmeta') {
  2916. print '<input type="submit" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
  2917. }
  2918. if (preg_match('/^create/', $action)) {
  2919. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2920. }
  2921. if (preg_match('/^edit/', $action)) {
  2922. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2923. }
  2924. if ($action != 'preview') {
  2925. print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
  2926. }
  2927. }
  2928. print '</span>'; // end websitetools
  2929. print '<span class="websitehelp">';
  2930. if ($action == 'editsource' || $action == 'editcontent' || GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha')) {
  2931. $url = 'https://wiki.dolibarr.org/index.php/Module_Website';
  2932. $htmltext = $langs->transnoentitiesnoconv("YouCanEditHtmlSource", $url);
  2933. $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource2", $url);
  2934. $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourceMore", $url);
  2935. $htmltext .= '<br>';
  2936. if ($conf->browser->layout == 'phone') {
  2937. print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
  2938. } else {
  2939. //img_help(($tooltiptrigger != '' ? 2 : 1), $alt)
  2940. print $form->textwithpicto($langs->trans("SyntaxHelp").' '.img_help(2, $langs->trans("SyntaxHelp")), $htmltext, 1, 'none', 'inline-block', 1, 2, 'tooltipsubstitution');
  2941. }
  2942. }
  2943. print '</span>'; // end websitehelp
  2944. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') {
  2945. // Adding jquery code to change on the fly url of preview ext
  2946. if (!empty($conf->use_javascript_ajax)) {
  2947. print '<script type="text/javascript">
  2948. jQuery(document).ready(function() {
  2949. jQuery("#websiteinputurl").keyup(function() {
  2950. console.log("Website external url modified "+jQuery("#previewsiteurl").val());
  2951. if (jQuery("#previewsiteurl").val() != "" && jQuery("#previewsiteurl").val().startsWith("http"))
  2952. {
  2953. jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
  2954. }
  2955. else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
  2956. ';
  2957. print '
  2958. });
  2959. jQuery("#previewsiteext,#previewpageext").click(function() {
  2960. newurl=jQuery("#previewsiteurl").val();
  2961. if (! newurl.startsWith("http"))
  2962. {
  2963. alert(\''.dol_escape_js($langs->trans("ErrorURLMustStartWithHttp")).'\');
  2964. return false;
  2965. }
  2966. newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
  2967. console.log("Open url "+newurl);
  2968. /* Save url */
  2969. jQuery.ajax({
  2970. method: "POST",
  2971. url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
  2972. data: {
  2973. field: \'editval_virtualhost\',
  2974. element: \'website\',
  2975. table_element: \'website\',
  2976. fk_element: '.((int) $object->id).',
  2977. value: newurl,
  2978. },
  2979. context: document.body
  2980. });
  2981. jQuery("#previewsiteext").attr("href",newurl);
  2982. jQuery("#previewpageext").attr("href",newpage);
  2983. });
  2984. });
  2985. </script>';
  2986. }
  2987. }
  2988. }
  2989. print '</div>'; // end current websitebar
  2990. }
  2991. $head = array();
  2992. /*
  2993. * Edit Site HTML header and CSS
  2994. */
  2995. if ($action == 'editcss') {
  2996. print '<div class="fiche">';
  2997. print '<br>';
  2998. if (!GETPOSTISSET('WEBSITE_CSS_INLINE')) {
  2999. $csscontent = @file_get_contents($filecss);
  3000. // Clean the php css file to remove php code and get only css part
  3001. $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
  3002. } else {
  3003. $csscontent = GETPOST('WEBSITE_CSS_INLINE', 'none');
  3004. }
  3005. if (!trim($csscontent)) {
  3006. $csscontent = '/* CSS content (all pages) */'."\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
  3007. }
  3008. if (!GETPOSTISSET('WEBSITE_JS_INLINE')) {
  3009. $jscontent = @file_get_contents($filejs);
  3010. // Clean the php js file to remove php code and get only js part
  3011. $jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
  3012. } else {
  3013. $jscontent = GETPOST('WEBSITE_JS_INLINE', 'none');
  3014. }
  3015. if (!trim($jscontent)) {
  3016. $jscontent = '/* JS content (all pages) */'."\n";
  3017. }
  3018. if (!GETPOSTISSET('WEBSITE_HTML_HEADER')) {
  3019. $htmlheadercontent = @file_get_contents($filehtmlheader);
  3020. // Clean the php htmlheader file to remove php code and get only html part
  3021. $htmlheadercontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheadercontent);
  3022. } else {
  3023. $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER', 'none');
  3024. }
  3025. if (!trim($htmlheadercontent)) {
  3026. $htmlheadercontent = "<html>\n";
  3027. $htmlheadercontent .= $htmlheadercontentdefault;
  3028. $htmlheadercontent .= "</html>";
  3029. } else {
  3030. $htmlheadercontent = preg_replace('/^\s*<html>/ims', '', $htmlheadercontent);
  3031. $htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent);
  3032. $htmlheadercontent = '<html>'."\n".trim($htmlheadercontent)."\n".'</html>';
  3033. }
  3034. if (!GETPOSTISSET('WEBSITE_ROBOT')) {
  3035. $robotcontent = @file_get_contents($filerobot);
  3036. // Clean the php htmlheader file to remove php code and get only html part
  3037. $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
  3038. } else {
  3039. $robotcontent = GETPOST('WEBSITE_ROBOT', 'nothtml');
  3040. }
  3041. if (!trim($robotcontent)) {
  3042. $robotcontent .= "# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
  3043. $robotcontent .= "User-agent: *\n";
  3044. $robotcontent .= "Allow: /public/\n";
  3045. $robotcontent .= "Disallow: /administrator/\n";
  3046. }
  3047. if (!GETPOSTISSET('WEBSITE_HTACCESS')) {
  3048. $htaccesscontent = @file_get_contents($filehtaccess);
  3049. // Clean the php htaccesscontent file to remove php code and get only html part
  3050. $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
  3051. } else {
  3052. $htaccesscontent = GETPOST('WEBSITE_HTACCESS', 'nohtml'); // We must use 'nohtml' and not 'alphanohtml' because we must accept "
  3053. }
  3054. if (!trim($htaccesscontent)) {
  3055. $htaccesscontent .= "# Order allow,deny\n";
  3056. $htaccesscontent .= "# Deny from all\n";
  3057. }
  3058. if (!GETPOSTISSET('WEBSITE_MANIFEST_JSON')) {
  3059. $manifestjsoncontent = @file_get_contents($filemanifestjson);
  3060. // Clean the manifestjson file to remove php code and get only html part
  3061. $manifestjsoncontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $manifestjsoncontent);
  3062. } else {
  3063. $manifestjsoncontent = GETPOST('WEBSITE_MANIFEST_JSON', 'restricthtml');
  3064. }
  3065. if (!trim($manifestjsoncontent)) {
  3066. //$manifestjsoncontent.="";
  3067. }
  3068. if (!GETPOSTISSET('WEBSITE_README')) {
  3069. $readmecontent = @file_get_contents($filereadme);
  3070. // Clean the readme file to remove php code and get only html part
  3071. $readmecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $readmecontent);
  3072. } else {
  3073. $readmecontent = GETPOST('WEBSITE_README', 'none');
  3074. }
  3075. if (!trim($readmecontent)) {
  3076. //$readmecontent.="";
  3077. }
  3078. if (!GETPOSTISSET('WEBSITE_LICENSE')) {
  3079. $licensecontent = @file_get_contents($filelicense);
  3080. // Clean the readme file to remove php code and get only html part
  3081. $licensecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $licensecontent);
  3082. } else {
  3083. $licensecontent = GETPOST('WEBSITE_LICENSE', 'none');
  3084. }
  3085. if (!trim($licensecontent)) {
  3086. //$readmecontent.="";
  3087. }
  3088. print dol_get_fiche_head();
  3089. print '<!-- Edit Website properties -->'."\n";
  3090. print '<table class="border centpercent">';
  3091. // Website
  3092. print '<tr><td class="titlefieldcreate fieldrequired">';
  3093. print $langs->trans('WebSite');
  3094. print '</td><td>';
  3095. print $websitekey;
  3096. print '</td></tr>';
  3097. // Status of web site
  3098. if ($action != 'createcontainer') {
  3099. if (empty($conf->use_javascript_ajax)) {
  3100. print '<!-- Status of web site page -->'."\n";
  3101. print '<tr><td class="fieldrequired">';
  3102. print $langs->trans('Status');
  3103. print '</td><td>';
  3104. print $form->selectyesno('status', $object->status);
  3105. print '</td></tr>';
  3106. }
  3107. }
  3108. // Main language
  3109. print '<tr><td class="tdtop fieldrequired">';
  3110. $htmltext = '';
  3111. print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
  3112. print '</td><td>';
  3113. print img_picto('', 'language', 'class="picotfixedwidth"');
  3114. print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
  3115. print '</td>';
  3116. print '</tr>';
  3117. // Other languages
  3118. print '<tr><td class="tdtop">';
  3119. $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
  3120. print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
  3121. print '</td><td>';
  3122. print img_picto('', 'language', 'class="picotfixedwidth"');
  3123. print '<input type="text" class="flat" value="'.(GETPOSTISSET('WEBSITE_OTHERLANG') ? GETPOST('WEBSITE_OTHERLANG', 'alpha') : $object->otherlang).'" name="WEBSITE_OTHERLANG">';
  3124. print '</td>';
  3125. print '</tr>';
  3126. // VirtualHost
  3127. print '<tr><td class="tdtop">';
  3128. $htmltext = $langs->trans("VirtualhostDesc");
  3129. print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
  3130. print '</td><td>';
  3131. print '<input type="text" class="flat minwidth300" value="'.(GETPOSTISSET('virtualhost') ? GETPOST('virtualhost', 'alpha') : $virtualurl).'" name="virtualhost">';
  3132. print '</td>';
  3133. print '</tr>';
  3134. // Favicon
  3135. print '<tr><td>';
  3136. print $form->textwithpicto($langs->trans('ImportFavicon'), $langs->trans('FaviconTooltip'));
  3137. print '</td><td>';
  3138. $maxfilesizearray = getMaxFileSizeArray();
  3139. $maxmin = $maxfilesizearray['maxmin'];
  3140. if ($maxmin > 0) {
  3141. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  3142. }
  3143. print '<input type="file" class="flat minwidth300" name="addedfile" id="addedfile"/>';
  3144. print '</tr></td>';
  3145. // CSS file
  3146. print '<tr><td class="tdtop">';
  3147. $htmlhelp = $langs->trans("CSSContentTooltipHelp");
  3148. print $form->textwithpicto($langs->trans('WEBSITE_CSS_INLINE'), $htmlhelp, 1, 'help', '', 0, 2, 'csstooltip');
  3149. print '</td><td>';
  3150. $poscursor = array('x'=>GETPOST('WEBSITE_CSS_INLINE_x'), 'y'=>GETPOST('WEBSITE_CSS_INLINE_y'));
  3151. $doleditor = new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3152. print $doleditor->Create(1, '', true, 'CSS', 'css');
  3153. print '</td></tr>';
  3154. // JS file
  3155. print '<tr><td class="tdtop">';
  3156. $textwithhelp = $langs->trans('WEBSITE_JS_INLINE');
  3157. $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
  3158. print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmljstooltip2');
  3159. print '</td><td>';
  3160. $poscursor = array('x'=>GETPOST('WEBSITE_JS_INLINE_x'), 'y'=>GETPOST('WEBSITE_JS_INLINE_y'));
  3161. $doleditor = new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3162. print $doleditor->Create(1, '', true, 'JS', 'javascript');
  3163. print '</td></tr>';
  3164. // Common HTML header
  3165. print '<tr><td class="tdtop">';
  3166. print $langs->trans('WEBSITE_HTML_HEADER');
  3167. $htmlhelp = $langs->trans("Example").' :<br>';
  3168. $htmlhelp .= dol_htmlentitiesbr($htmlheadercontentdefault);
  3169. $textwithhelp = $form->textwithpicto('', $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
  3170. $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
  3171. print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmlheadertooltip2');
  3172. print '</td><td>';
  3173. $poscursor = array('x'=>GETPOST('WEBSITE_HTML_HEADER_x'), 'y'=>GETPOST('WEBSITE_HTML_HEADER_y'));
  3174. $doleditor = new DolEditor('WEBSITE_HTML_HEADER', $htmlheadercontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3175. print $doleditor->Create(1, '', true, 'HTML Header', 'html');
  3176. print '</td></tr>';
  3177. // Robot file
  3178. print '<tr><td class="tdtop">';
  3179. print $langs->trans('WEBSITE_ROBOT');
  3180. print '</td><td>';
  3181. $poscursor = array('x'=>GETPOST('WEBSITE_ROBOT_x'), 'y'=>GETPOST('WEBSITE_ROBOT_y'));
  3182. $doleditor = new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3183. print $doleditor->Create(1, '', true, 'Robot file', 'text');
  3184. print '</td></tr>';
  3185. // .htaccess
  3186. print '<tr><td class="tdtop">';
  3187. print $langs->trans('WEBSITE_HTACCESS');
  3188. print '</td><td>';
  3189. $poscursor = array('x'=>GETPOST('WEBSITE_HTACCESS_x'), 'y'=>GETPOST('WEBSITE_HTACCESS_y'));
  3190. $doleditor = new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3191. print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'text');
  3192. print '</td></tr>';
  3193. // Manifest.json
  3194. print '<tr><td class="tdtop">';
  3195. $htmlhelp = $langs->trans("Example").' :<br>';
  3196. $htmlhelp .= '<small>'.dol_htmlentitiesbr($manifestjsoncontentdefault).'</small>';
  3197. print $form->textwithpicto($langs->trans('WEBSITE_MANIFEST_JSON'), $htmlhelp, 1, 'help', '', 0, 2, 'manifestjsontooltip');
  3198. print '</td><td>';
  3199. print $langs->trans("UseManifest").': '.$form->selectyesno('use_manifest', $website->use_manifest, 1).'<br>';
  3200. $poscursor = array('x'=>GETPOST('WEBSITE_MANIFEST_JSON_x'), 'y'=>GETPOST('WEBSITE_MANIFEST_JSON_y'));
  3201. $doleditor = new DolEditor('WEBSITE_MANIFEST_JSON', $manifestjsoncontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3202. print $doleditor->Create(1, '', true, $langs->trans("File").' manifest.json', 'text');
  3203. print '</td></tr>';
  3204. // README.md
  3205. print '<tr><td class="tdtop">';
  3206. $htmlhelp = $langs->trans("EnterHereReadmeInformation");
  3207. print $form->textwithpicto($langs->trans("File").' README.md', $htmlhelp, 1, 'help', '', 0, 2, 'readmetooltip');
  3208. print '</td><td>';
  3209. $poscursor = array('x'=>GETPOST('WEBSITE_README_x'), 'y'=>GETPOST('WEBSITE_README_y'));
  3210. $doleditor = new DolEditor('WEBSITE_README', $readmecontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3211. print $doleditor->Create(1, '', true, $langs->trans("File").' README.md', 'text');
  3212. print '</td></tr>';
  3213. // LICENSE
  3214. print '<tr><td class="tdtop">';
  3215. $htmlhelp = $langs->trans("EnterHereLicenseInformation");
  3216. print $form->textwithpicto($langs->trans("File").' LICENSE', $htmlhelp, 1, 'help', '', 0, 2, 'licensetooltip');
  3217. print '</td><td>';
  3218. $poscursor = array('x'=>GETPOST('WEBSITE_LICENSE_x'), 'y'=>GETPOST('WEBSITE_LICENSE_y'));
  3219. $doleditor = new DolEditor('WEBSITE_LICENSE', $licensecontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3220. print $doleditor->Create(1, '', true, $langs->trans("File").' LICENSE', 'text');
  3221. print '</td></tr>';
  3222. // RSS
  3223. print '<tr><td class="tdtop">';
  3224. $htmlhelp = $langs->trans('RSSFeedDesc');
  3225. print $form->textwithpicto($langs->trans('RSSFeed'), $htmlhelp, 1, 'help', '', 0, 2, '');
  3226. print '</td><td>';
  3227. print '/wrapper.php?rss=1[&l=XX][&limit=123]';
  3228. print '</td></tr>';
  3229. print '</table>';
  3230. print dol_get_fiche_end();
  3231. print '</div>';
  3232. print '<br>';
  3233. }
  3234. if ($action == 'createsite') {
  3235. print '<div class="fiche">';
  3236. print '<br>';
  3237. /*$h = 0;
  3238. $head = array();
  3239. $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
  3240. $head[$h][1] = $langs->trans("AddSite");
  3241. $head[$h][2] = 'card';
  3242. $h++;
  3243. print dol_get_fiche_head($head, 'card', $langs->trans("AddSite"), -1, 'globe');
  3244. */
  3245. if ($action == 'createcontainer') {
  3246. print load_fiche_titre($langs->trans("AddSite"));
  3247. }
  3248. print '<!-- Add site -->'."\n";
  3249. print '<div class="tabBar tabBarWithBottom">';
  3250. print '<table class="border centpercent">';
  3251. $siteref = $sitedesc = $sitelang = $siteotherlang = '';
  3252. if (GETPOST('WEBSITE_REF')) {
  3253. $siteref = GETPOST('WEBSITE_REF', 'aZ09');
  3254. }
  3255. if (GETPOST('WEBSITE_DESCRIPTION')) {
  3256. $sitedesc = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
  3257. }
  3258. if (GETPOST('WEBSITE_LANG')) {
  3259. $sitelang = GETPOST('WEBSITE_LANG', 'aZ09');
  3260. }
  3261. if (GETPOST('WEBSITE_OTHERLANG')) {
  3262. $siteotherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
  3263. }
  3264. print '<tr><td class="titlefieldcreate fieldrequired">';
  3265. print $form->textwithpicto($langs->trans('WebsiteName'), $langs->trans("Example").': MyPortal, www.mywebsite.com, ...');
  3266. print '</td><td>';
  3267. print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'" autofocus>';
  3268. print '</td></tr>';
  3269. print '<tr><td class="fieldrequired">';
  3270. print $langs->trans('MainLanguage');
  3271. print '</td><td>';
  3272. $shortlangcode = preg_replace('/[_-].*$/', '', trim($langs->defaultlang));
  3273. print img_picto('', 'language', 'class="pictofixedwidth"');
  3274. print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : $shortlangcode), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
  3275. print '</td></tr>';
  3276. print '<tr><td>';
  3277. $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
  3278. print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
  3279. print '</td><td>';
  3280. print img_picto('', 'language', 'class="pictofixedwidth"');
  3281. print '<input type="text" class="flat minwidth300" name="WEBSITE_OTHERLANG" value="'.dol_escape_htmltag($siteotherlang).'">';
  3282. print '</td></tr>';
  3283. print '<tr><td>';
  3284. print $langs->trans('Description');
  3285. print '</td><td>';
  3286. print '<input type="text" class="flat minwidth500" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
  3287. print '</td></tr>';
  3288. print '<tr><td>';
  3289. $htmltext = $langs->trans("VirtualhostDesc");
  3290. /*$htmltext = str_replace('{s1}', DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/<i>websiteref</i>', $htmltext);
  3291. $htmltext .= '<br>';
  3292. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  3293. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
  3294. $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);*/
  3295. print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, '');
  3296. print '</td><td>';
  3297. print '<input type="text" class="flat minwidth300" name="virtualhost" value="'.dol_escape_htmltag(GETPOST('virtualhost', 'alpha')).'">';
  3298. print '</td></tr>';
  3299. print '</table>';
  3300. print '</div>';
  3301. if ($action == 'createsite') {
  3302. print '<div class="center">';
  3303. print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
  3304. print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  3305. print '</div>';
  3306. }
  3307. //print '</div>';
  3308. //print dol_get_fiche_end();
  3309. print '</div>';
  3310. print '<br>';
  3311. }
  3312. if ($action == 'importsite') {
  3313. print '<div class="fiche">';
  3314. print '<br>';
  3315. print load_fiche_titre($langs->trans("ImportSite"));
  3316. print dol_get_fiche_head(array(), '0', '', -1);
  3317. print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToImport").'</span><br><br>';
  3318. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  3319. $allowimportsite = true;
  3320. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  3321. $allowimportsite = false;
  3322. }
  3323. if ($allowimportsite) {
  3324. $maxfilesizearray = getMaxFileSizeArray();
  3325. $maxmin = $maxfilesizearray['maxmin'];
  3326. if ($maxmin > 0) {
  3327. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  3328. }
  3329. print '<input class="flat minwidth400" type="file" name="userfile[]" accept=".zip">';
  3330. print '<input type="submit" class="button small" name="buttonsubmitimportfile" value="'.dol_escape_htmltag($langs->trans("Upload")).'">';
  3331. print '<input type="submit" class="button button-cancel small" name="preview" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3332. print '<br><br><br>';
  3333. } else {
  3334. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  3335. // Show clean corporate message
  3336. $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
  3337. } else {
  3338. // Show technical generic message
  3339. $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
  3340. }
  3341. print info_admin($message).'<br><br>';
  3342. }
  3343. print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToLoad").'</span><br><br>';
  3344. showWebsiteTemplates($website);
  3345. print dol_get_fiche_end();
  3346. print '</div>';
  3347. print '<br>';
  3348. }
  3349. if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties of a web site OR properties of a web page
  3350. print '<div class="fiche">';
  3351. print '<br>';
  3352. /*$h = 0;
  3353. $head = array();
  3354. $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
  3355. $head[$h][1] = $langs->trans("AddPage");
  3356. $head[$h][2] = 'card';
  3357. $h++;
  3358. print dol_get_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe');
  3359. */
  3360. if ($action == 'createcontainer') {
  3361. print load_fiche_titre($langs->trans("AddPage"));
  3362. }
  3363. print '<!-- Edit or create page/container -->'."\n";
  3364. //print '<div class="fichecenter">';
  3365. $hiddenfromfetchingafterload = ' hideobject';
  3366. $hiddenmanuallyafterload = ' hideobject';
  3367. if (GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching') {
  3368. $hiddenfromfetchingafterload = '';
  3369. }
  3370. if (GETPOST('radiocreatefrom') == 'checkboxcreatemanually') {
  3371. $hiddenmanuallyafterload = '';
  3372. }
  3373. if ($action == 'editmeta' || empty($conf->use_javascript_ajax)) { // No autohide/show in such case
  3374. $hiddenfromfetchingafterload = '';
  3375. $hiddenmanuallyafterload = '';
  3376. }
  3377. if ($action == 'createcontainer') {
  3378. print '<br>';
  3379. if (!empty($conf->use_javascript_ajax)) {
  3380. print '<input type="radio" name="radiocreatefrom" id="checkboxcreatemanually" value="checkboxcreatemanually"'.(GETPOST('radiocreatefrom') == 'checkboxcreatemanually' ? ' checked' : '').'> ';
  3381. }
  3382. print '<label for="checkboxcreatemanually"><span class="opacitymediumxx">'.$langs->trans("OrEnterPageInfoManually").'</span></label><br>';
  3383. print '<hr class="tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
  3384. }
  3385. print '<table class="border tableforfield nobackground centpercent tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
  3386. if ($action != 'createcontainer') {
  3387. print '<tr><td class="titlefield fieldrequired">';
  3388. print $langs->trans('IDOfPage').' - '.$langs->trans('InternalURLOfPage');
  3389. print '</td><td>';
  3390. print $pageid;
  3391. //print '</td></tr>';
  3392. //print '<tr><td class="titlefield fieldrequired">';
  3393. //print $langs->trans('InternalURLOfPage');
  3394. //print '</td><td>';
  3395. print ' &nbsp; - &nbsp; ';
  3396. print '/public/website/index.php?website='.urlencode($websitekey).'&pageid='.urlencode($pageid);
  3397. //if ($objectpage->grabbed_from) print ' - <span class="opacitymedium">'.$langs->trans('InitiallyGrabbedFrom').' '.$objectpage->grabbed_from.'</span>';
  3398. print '</td></tr>';
  3399. $type_container = $objectpage->type_container;
  3400. $pageurl = $objectpage->pageurl;
  3401. $pagealiasalt = $objectpage->aliasalt;
  3402. $pagetitle = $objectpage->title;
  3403. $pagedescription = $objectpage->description;
  3404. $pageimage = $objectpage->image;
  3405. $pagekeywords = $objectpage->keywords;
  3406. $pagelang = $objectpage->lang;
  3407. $pageallowedinframes = $objectpage->allowed_in_frames;
  3408. $pagehtmlheader = $objectpage->htmlheader;
  3409. $pagedatecreation = $objectpage->date_creation;
  3410. $pagedatemodification = $objectpage->date_modification;
  3411. $pageauthorid = $objectpage->fk_user_creat;
  3412. $pageusermodifid = $objectpage->fk_user_modif;
  3413. $pageauthoralias = $objectpage->author_alias;
  3414. $pagestatus = $objectpage->status;
  3415. } else { // $action = 'createcontainer'
  3416. $type_container = 'page';
  3417. $pageurl = '';
  3418. $pagealiasalt = '';
  3419. $pagetitle = '';
  3420. $pagedescription = '';
  3421. $pageimage = '';
  3422. $pagekeywords = '';
  3423. $pagelang = '';
  3424. $pageallowedinframes = 0;
  3425. $pagehtmlheader = '';
  3426. $pagedatecreation = dol_now();
  3427. $pagedatemodification = '';
  3428. $pageauthorid = $user->id;
  3429. $pageusermodifid = 0;
  3430. $pageauthoralias = '';
  3431. $pagestatus = 1;
  3432. }
  3433. if (GETPOST('WEBSITE_TITLE', 'alpha')) {
  3434. $pagetitle = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
  3435. }
  3436. if (GETPOST('WEBSITE_PAGENAME', 'alpha')) {
  3437. $pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  3438. }
  3439. if (GETPOST('WEBSITE_ALIASALT', 'alpha')) {
  3440. $pagealiasalt = str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alphanohtml'));
  3441. }
  3442. if (GETPOST('WEBSITE_DESCRIPTION', 'alpha')) {
  3443. $pagedescription = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
  3444. }
  3445. if (GETPOST('WEBSITE_IMAGE', 'alpha')) {
  3446. $pageimage = GETPOST('WEBSITE_IMAGE', 'alpha');
  3447. }
  3448. if (GETPOST('WEBSITE_KEYWORDS', 'alpha')) {
  3449. $pagekeywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
  3450. }
  3451. if (GETPOST('WEBSITE_LANG', 'aZ09')) {
  3452. $pagelang = GETPOST('WEBSITE_LANG', 'aZ09');
  3453. }
  3454. if (GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09')) {
  3455. $pageallowedinframes = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
  3456. }
  3457. if (GETPOST('htmlheader', 'none')) {
  3458. $pagehtmlheader = GETPOST('htmlheader', 'none');
  3459. }
  3460. if ($action != 'createcontainer') {
  3461. if (empty($conf->use_javascript_ajax)) {
  3462. print '<!-- Status of web site page -->'."\n";
  3463. print '<tr><td class="fieldrequired">';
  3464. print $langs->trans('Status');
  3465. print '</td><td>';
  3466. print $form->selectyesno('status', $objectpage->status);
  3467. print '</td></tr>';
  3468. }
  3469. }
  3470. // Type of container
  3471. print '<tr><td class="titlefield fieldrequired">';
  3472. print $langs->trans('WEBSITE_TYPE_CONTAINER');
  3473. print '</td><td>';
  3474. print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
  3475. $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1);
  3476. print '</td></tr>';
  3477. // Example/templates of page
  3478. if ($action == 'createcontainer') {
  3479. print '<tr><td class="titlefield fieldrequired">';
  3480. print $langs->trans('WEBSITE_PAGE_EXAMPLE');
  3481. print '</td><td>';
  3482. print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ? GETPOST('sample', 'alpha') : 'empty'), 0, '', 1, 'minwidth300');
  3483. print '</td></tr>';
  3484. }
  3485. // Title
  3486. print '<tr><td class="fieldrequired">';
  3487. print $langs->trans('WEBSITE_TITLE');
  3488. print '</td><td>';
  3489. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'" autofocus>';
  3490. print '</td></tr>';
  3491. // Alias
  3492. print '<tr><td class="titlefieldcreate fieldrequired">';
  3493. print $langs->trans('WEBSITE_PAGENAME');
  3494. print '</td><td>';
  3495. print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
  3496. print '</td></tr>';
  3497. print '<tr><td class="titlefieldcreate">';
  3498. $htmlhelp = $langs->trans("WEBSITE_ALIASALTDesc");
  3499. print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
  3500. print '</td><td>';
  3501. print '<input type="text" class="flat minwidth500" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
  3502. print '</td></tr>';
  3503. print '<tr><td>';
  3504. print $langs->trans('WEBSITE_DESCRIPTION');
  3505. print '</td><td>';
  3506. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
  3507. print '</td></tr>';
  3508. print '<tr><td>';
  3509. $htmlhelp = $langs->trans("WEBSITE_IMAGEDesc");
  3510. print $form->textwithpicto($langs->trans('WEBSITE_IMAGE'), $htmlhelp, 1, 'help', '', 0, 2, 'imagetooltip');
  3511. print '</td><td>';
  3512. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_IMAGE" value="'.dol_escape_htmltag($pageimage).'">';
  3513. print '</td></tr>';
  3514. // Keywords
  3515. print '<tr><td>';
  3516. $htmlhelp = $langs->trans("WEBSITE_KEYWORDSDesc");
  3517. print $form->textwithpicto($langs->trans('WEBSITE_KEYWORDS'), $htmlhelp, 1, 'help', '', 0, 2, 'keywordtooltip');
  3518. print '</td><td>';
  3519. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
  3520. print '</td></tr>';
  3521. print '<tr><td>';
  3522. print $langs->trans('Language');
  3523. print '</td><td>';
  3524. $onlykeys = array();
  3525. if ($object->lang) {
  3526. $onlykeys[$object->lang] = $object->lang;
  3527. } else {
  3528. $onlykeys[$langs->defaultlang] = $langs->defaultlang;
  3529. }
  3530. if ($object->otherlang) {
  3531. $tmparray = explode(',', $object->otherlang);
  3532. foreach ($tmparray as $key) {
  3533. $tmpkey = trim($key);
  3534. if (strlen($key) == 2) {
  3535. $tmpkey = strtolower($key);
  3536. }
  3537. $onlykeys[$tmpkey] = $tmpkey;
  3538. }
  3539. }
  3540. if (empty($object->lang) && empty($object->otherlang)) {
  3541. $onlykeys = null; // We keep full list of languages
  3542. }
  3543. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1);
  3544. $htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
  3545. print $form->textwithpicto('', $htmltext);
  3546. print '</td></tr>';
  3547. // Translation of
  3548. $translationof = 0;
  3549. $translatedby = 0;
  3550. print '<!-- Translation of --><tr><td>';
  3551. print $langs->trans('TranslationLinks');
  3552. print '</td><td>';
  3553. if ($action != 'createcontainer') {
  3554. // Has translation pages
  3555. $sql = "SELECT rowid, lang from ".MAIN_DB_PREFIX."website_page where fk_page = ".((int) $objectpage->id);
  3556. $resql = $db->query($sql);
  3557. if ($resql) {
  3558. $num_rows = $db->num_rows($resql);
  3559. if ($num_rows > 0) {
  3560. print '<span class="opacitymedium">'.$langs->trans('ThisPageHasTranslationPages').':</span>';
  3561. $i = 0;
  3562. $tmppage = new WebsitePage($db);
  3563. $tmpstring = '';
  3564. while ($obj = $db->fetch_object($resql)) {
  3565. $result = $tmppage->fetch($obj->rowid);
  3566. if ($result > 0) {
  3567. if ($i > 0) {
  3568. $tmpstring .= '<br>';
  3569. }
  3570. $tmpstring .= $tmppage->getNomUrl(1).' ('.$tmppage->lang.')';
  3571. $translatedby++;
  3572. $i++;
  3573. }
  3574. }
  3575. if ($i > 1) {
  3576. print '<br>';
  3577. } else {
  3578. print ' ';
  3579. }
  3580. print $tmpstring;
  3581. }
  3582. } else {
  3583. dol_print_error($db);
  3584. }
  3585. }
  3586. if (empty($translatedby) && ($action == 'editmeta' || $action == 'createcontainer' || $objectpage->fk_page > 0)) {
  3587. $sourcepage = new WebsitePage($db);
  3588. $result = $sourcepage->fetch($objectpage->fk_page);
  3589. if ($result == 0) {
  3590. // not found, we can reset value to clean database
  3591. } elseif ($result > 0) {
  3592. $translationof = $objectpage->fk_page;
  3593. print '<span class="opacitymedium">'.$langs->trans('ThisPageIsTranslationOf').'</span> ';
  3594. print $formwebsite->selectContainer($website, 'pageidfortranslation', ($translationof ? $translationof : -1), 1, $action, 'minwidth300', array($objectpage->id));
  3595. if ($translationof > 0 && $sourcepage->lang) {
  3596. print $sourcepage->getNomUrl(2).' ('.$sourcepage->lang.')';
  3597. }
  3598. }
  3599. }
  3600. print '</td></tr>';
  3601. // Allowed in frames
  3602. print '<tr><td>';
  3603. print $langs->trans('AllowedInFrames');
  3604. //$htmlhelp = $langs->trans("AllowedInFramesDesc");
  3605. //print $form->textwithpicto($langs->trans('AllowedInFrames'), $htmlhelp, 1, 'help', '', 0, 2, 'allowedinframestooltip');
  3606. print '</td><td>';
  3607. print '<input type="checkbox" class="flat" name="WEBSITE_ALLOWED_IN_FRAMES" value="1"'.($pageallowedinframes ? 'checked="checked"' : '').'>';
  3608. print '</td></tr>';
  3609. // Categories
  3610. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  3611. $langs->load('categories');
  3612. if (!GETPOSTISSET('categories')) {
  3613. $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', null, null, null, 1);
  3614. $c = new Categorie($db);
  3615. $cats = $c->containing($objectpage->id, Categorie::TYPE_WEBSITE_PAGE);
  3616. $arrayselected = array();
  3617. if (is_array($cats)) {
  3618. foreach ($cats as $cat) {
  3619. $arrayselected[] = $cat->id;
  3620. }
  3621. }
  3622. $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', 'parent', null, null, 1);
  3623. }
  3624. print '<tr><td class="toptd">'.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).'</td><td>';
  3625. print img_picto('', 'category', 'class="pictofixedwidth"');
  3626. print $form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), null, null, 'minwidth200 widthcentpercentminusxx');
  3627. print "</td></tr>";
  3628. }
  3629. if (!empty($conf->global->WEBSITE_PAGE_SHOW_INTERNAL_LINKS_TO_OBJECT)) { // TODO Replace this with link into element_element ?
  3630. print '<tr><td class="titlefieldcreate">';
  3631. print 'ObjectClass';
  3632. print '</td><td>';
  3633. print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTCLASS" placeholder="ClassName::/path/class/ObjectClass.class.php" >';
  3634. print '</td></tr>';
  3635. print '<tr><td class="titlefieldcreate">';
  3636. print 'ObjectID';
  3637. print '</td><td>';
  3638. print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTID" >';
  3639. print '</td></tr>';
  3640. }
  3641. $fuser = new User($db);
  3642. print '<tr><td>';
  3643. print $langs->trans('Author');
  3644. print '</td><td>';
  3645. if ($pageauthorid > 0) {
  3646. $fuser->fetch($pageauthorid);
  3647. print $fuser->getNomUrl(1);
  3648. } else {
  3649. print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
  3650. }
  3651. print '</td></tr>';
  3652. print '<tr><td>';
  3653. print $langs->trans('PublicAuthorAlias');
  3654. print '</td><td>';
  3655. print '<input type="text" class="flat minwidth300" name="WEBSITE_AUTHORALIAS" value="'.dol_escape_htmltag($pageauthoralias).'" placeholder="Anonymous">';
  3656. print '</td></tr>';
  3657. print '<tr><td>';
  3658. print $langs->trans('DateCreation');
  3659. print '</td><td>';
  3660. print $form->selectDate($pagedatecreation, 'datecreation', 1, 1, 0, '', 1, 1);
  3661. //print dol_print_date($pagedatecreation, 'dayhour');
  3662. print '</td></tr>';
  3663. if ($action != 'createcontainer') {
  3664. print '<tr><td>';
  3665. print $langs->trans('UserModif');
  3666. print '</td><td>';
  3667. if ($pageusermodifid > 0) {
  3668. $fuser->fetch($pageusermodifid);
  3669. print $fuser->getNomUrl(1);
  3670. }
  3671. print '</td></tr>';
  3672. print '<tr><td>';
  3673. print $langs->trans('DateModification');
  3674. print '</td><td>';
  3675. print dol_print_date($pagedatemodification, 'dayhour', 'tzuser');
  3676. print '</td></tr>';
  3677. }
  3678. print '<tr><td class="tdhtmlheader tdtop">';
  3679. $htmlhelp = $langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
  3680. $htmlhelp .= $langs->trans("Example").' :<br>';
  3681. $htmlhelp .= dol_htmlentitiesbr($htmlheadercontentdefault);
  3682. print $form->textwithpicto($langs->trans('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
  3683. print '</td><td>';
  3684. $poscursor = array('x'=>GETPOST('htmlheader_x'), 'y'=>GETPOST('htmlheader_y'));
  3685. $doleditor = new DolEditor('htmlheader', $pagehtmlheader, '', '120', 'ace', 'In', true, false, 'ace', ROWS_3, '100%', '', $poscursor);
  3686. print $doleditor->Create(1, '', true, 'HTML Header', 'html');
  3687. print '</td></tr>';
  3688. print '</table>';
  3689. if ($action == 'createcontainer') {
  3690. print '<div class="center tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
  3691. print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
  3692. print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  3693. print '</div>';
  3694. print '<br>';
  3695. if (!empty($conf->use_javascript_ajax)) {
  3696. print '<input type="radio" name="radiocreatefrom" id="checkboxcreatefromfetching" value="checkboxcreatefromfetching"'.(GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching' ? ' checked' : '').'> ';
  3697. }
  3698. print '<label for="checkboxcreatefromfetching"><span class="opacitymediumxx">'.$langs->trans("CreateByFetchingExternalPage").'</span></label><br>';
  3699. print '<hr class="tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
  3700. print '<table class="tableforfield centpercent tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
  3701. print '<tr><td class="titlefield">';
  3702. print $langs->trans("URL");
  3703. print '</td><td>';
  3704. print info_admin($langs->trans("OnlyEditionOfSourceForGrabbedContentFuture"), 0, 0, 'warning');
  3705. print '<input class="flat minwidth500" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl', 'alpha')).'" placeholder="https://externalsite/pagetofetch"> ';
  3706. print '<br><input class="flat paddingtop" type="checkbox" name="grabimages" value="1" checked="checked"> '.$langs->trans("GrabImagesInto");
  3707. print ' ';
  3708. print $langs->trans("ImagesShouldBeSavedInto").' ';
  3709. $arraygrabimagesinto = array('root'=>$langs->trans("WebsiteRootOfImages"), 'subpage'=>$langs->trans("SubdirOfPage"));
  3710. print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ? GETPOST('grabimagesinto') : 'root', 0, 0, 0, '', 0, 0, 0, '', '', 1);
  3711. print '<br>';
  3712. print '<input class="button small" style="margin-top: 5px" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
  3713. print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  3714. print '</td></tr>';
  3715. print '</table>';
  3716. }
  3717. if ($action == 'createcontainer') {
  3718. print '<script type="text/javascript">
  3719. jQuery(document).ready(function() {
  3720. var disableautofillofalias = 0;
  3721. var selectedm = \'\';
  3722. var selectedf = \'\';
  3723. jQuery("#WEBSITE_TITLE").keyup(function() {
  3724. if (disableautofillofalias == 0)
  3725. {
  3726. var valnospecial = jQuery("#WEBSITE_TITLE").val();
  3727. valnospecial = valnospecial.replace(/[éèê]/g, \'e\').replace(/[à]/g, \'a\').replace(/[ù]/g, \'u\').replace(/[î]/g, \'i\');
  3728. valnospecial = valnospecial.replace(/[ç]/g, \'c\').replace(/[ö]/g, \'o\');
  3729. valnospecial = valnospecial.replace(/[^\w]/gi, \'-\').toLowerCase();
  3730. valnospecial = valnospecial.replace(/\-+/g, \'-\').replace(/\-$/, \'\');
  3731. console.log("disableautofillofalias=0 so we replace WEBSITE_TITLE with "+valnospecial);
  3732. jQuery("#WEBSITE_PAGENAME").val(valnospecial);
  3733. }
  3734. });
  3735. jQuery("#WEBSITE_PAGENAME").keyup(function() {
  3736. disableautofillofalias = 1;
  3737. });
  3738. jQuery("#checkboxcreatefromfetching,#checkboxcreatemanually").click(function() {
  3739. console.log("we select a method to create a new container "+jQuery("#checkboxcreatefromfetching:checked").val())
  3740. jQuery(".tablecheckboxcreatefromfetching").hide();
  3741. jQuery(".tablecheckboxcreatemanually").hide();
  3742. if (typeof(jQuery("#checkboxcreatefromfetching:checked").val()) != \'undefined\') {
  3743. console.log("show a");
  3744. if (selectedf != \'createfromfetching\') {
  3745. jQuery(".tablecheckboxcreatefromfetching").show();
  3746. selectedf = \'createfromfetching\';
  3747. selectedm = \'\';
  3748. } else {
  3749. jQuery(".tablecheckboxcreatefromfetching").hide();
  3750. selectedf = \'\';
  3751. }
  3752. }
  3753. if (typeof(jQuery("#checkboxcreatemanually:checked").val()) != \'undefined\') {
  3754. console.log("show b");
  3755. if (selectedm != \'createmanually\') {
  3756. jQuery(".tablecheckboxcreatemanually").show();
  3757. selectedm = \'createmanually\';
  3758. selectedf = \'\';
  3759. } else {
  3760. jQuery(".tablecheckboxcreatemanually").hide();
  3761. selectedm = \'\';
  3762. }
  3763. }
  3764. });
  3765. });
  3766. </script>';
  3767. }
  3768. //print '</div>';
  3769. //print dol_get_fiche_end();
  3770. print '</div>';
  3771. print '<br>';
  3772. }
  3773. // Print formconfirm
  3774. if ($action == 'preview') {
  3775. print $formconfirm;
  3776. }
  3777. if ($action == 'editfile' || $action == 'file_manager' || $action == 'convertimgwebp' || $action == 'confirmconvertimgwebp') {
  3778. print '<!-- Edit Media -->'."\n";
  3779. print '<div class="fiche"><br>';
  3780. //print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  3781. $module = 'medias';
  3782. $formalreadyopen = 2; // So the form to submit a new file will not be opened another time inside the core/tpl/filemanager.tpl.php
  3783. if (empty($url)) {
  3784. $url = DOL_URL_ROOT.'/website/index.php'; // Must be an url without param
  3785. }
  3786. include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php';
  3787. print '</div>';
  3788. }
  3789. if ($action == 'editmenu') {
  3790. print '<!-- Edit Menu -->'."\n";
  3791. print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  3792. }
  3793. if ($action == 'editsource') {
  3794. // Editing with source editor
  3795. $contentforedit = '';
  3796. //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  3797. //$contentforedit.=$csscontent;
  3798. //$contentforedit.='</style>'."\n";
  3799. $contentforedit .= $objectpage->content;
  3800. //var_dump($_SESSION["dol_screenheight"]);
  3801. $maxheightwin = 480;
  3802. if (isset($_SESSION["dol_screenheight"])) {
  3803. if ($_SESSION["dol_screenheight"] > 680) {
  3804. $maxheightwin = $_SESSION["dol_screenheight"] - 400;
  3805. }
  3806. if ($_SESSION["dol_screenheight"] > 800) {
  3807. $maxheightwin = $_SESSION["dol_screenheight"] - 490;
  3808. }
  3809. }
  3810. $poscursor = array('x'=>GETPOST('PAGE_CONTENT_x'), 'y'=>GETPOST('PAGE_CONTENT_y'));
  3811. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  3812. $doleditor = new DolEditor('PAGE_CONTENT', $contentforedit, '', $maxheightwin, 'Full', '', true, true, 'ace', ROWS_5, '40%', 0, $poscursor);
  3813. $doleditor->Create(0, '', false, 'HTML Source', 'php');
  3814. }
  3815. /*if ($action == 'editcontent')
  3816. {
  3817. // Editing with default ckeditor
  3818. $contentforedit = '';
  3819. //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  3820. //$contentforedit.=$csscontent;
  3821. //$contentforedit.='</style>'."\n";
  3822. $contentforedit .= $objectpage->content;
  3823. $contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
  3824. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  3825. $poscursor = array('x'=>GETPOST('PAGE_CONTENT_x'), 'y'=>GETPOST('PAGE_CONTENT_y'));
  3826. $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%',$poscursor);
  3827. $doleditor->Create(0, '', false);
  3828. }*/
  3829. print "</div>\n";
  3830. print "</form>\n";
  3831. if ($mode == 'replacesite' || $massaction == 'replace') {
  3832. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3833. print '<input type="hidden" name="token" value="'.newToken().'">';
  3834. print '<input type="hidden" name="action" value="replacesiteconfirm">';
  3835. print '<input type="hidden" name="mode" value="replacesite">';
  3836. print '<input type="hidden" name="website" value="'.$website->ref.'">';
  3837. print '<!-- Search page and replace string -->'."\n";
  3838. print '<div class="fiche"><br>';
  3839. print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
  3840. print '<div class="fichecenter"><div class="fichehalfleft">';
  3841. print '<div class="tagtable">';
  3842. print '<div class="tagtr">';
  3843. print '<div class="tagtd paddingrightonly opacitymedium">';
  3844. print $langs->trans("SearchReplaceInto");
  3845. print '</div>';
  3846. print '<div class="tagtd">';
  3847. print '<input type="checkbox" class="marginleftonly" id="checkboxoptioncontent" name="optioncontent" value="content"'.((!GETPOSTISSET('buttonreplacesitesearch') || GETPOST('optioncontent', 'aZ09')) ? ' checked' : '').'> <label for="checkboxoptioncontent" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Content").'</label><br>';
  3848. print '<input type="checkbox" class="marginleftonly" id="checkboxoptionmeta" name="optionmeta" value="meta"'.(GETPOST('optionmeta', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionmeta" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Title").' | '.$langs->trans("Description").' | '.$langs->trans("Keywords").'</label><br>';
  3849. print '<input type="checkbox" class="marginleftonly" id="checkboxoptionsitefiles" name="optionsitefiles" value="sitefiles"'.(GETPOST('optionsitefiles', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionsitefiles" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("GlobalCSSorJS").'</label><br>';
  3850. print '</div>';
  3851. print '</div>';
  3852. print '<div class="tagtr">';
  3853. print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
  3854. print $langs->trans("SearchString");
  3855. print '</div>';
  3856. print '<div class="tagtd">';
  3857. print '<input type="text" name="searchstring" value="'.dol_escape_htmltag($searchkey, 0, 0, '', 1).'" autofocus>';
  3858. print '</div>';
  3859. print '</div>';
  3860. print '</div>';
  3861. print '</div><div class="fichehalfleft">';
  3862. print '<div class="tagtable">';
  3863. print '<div class="tagtr">';
  3864. print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
  3865. print $langs->trans("WEBSITE_TYPE_CONTAINER");
  3866. print '</div>';
  3867. print '<div class="tagtd">';
  3868. print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
  3869. $formwebsite->selectTypeOfContainer('optioncontainertype', (GETPOST('optioncontainertype', 'alpha') ? GETPOST('optioncontainertype', 'alpha') : ''), 1, '', 1, 'minwidth125 maxwidth400 widthcentpercentminusx');
  3870. print '</div>';
  3871. print '</div>';
  3872. print '<div class="tagtr">';
  3873. print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
  3874. print $langs->trans("Language");
  3875. print '</div>';
  3876. print '<div class="tagtd">';
  3877. print img_picto('', 'language', 'class="paddingrightonly"').' '.$formadmin->select_language(GETPOSTISSET('optionlanguage') ? GETPOST('optionlanguage') : '', 'optionlanguage', 0, null, '1', 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx', 2, 0, 0, null, 1);
  3878. print '</div>';
  3879. print '</div>';
  3880. // Categories
  3881. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  3882. print '<div class="tagtr">';
  3883. print '<div class="tagtd paddingrightonly marginrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
  3884. print $langs->trans("Category");
  3885. print '</div>';
  3886. print '<div class="tagtd">';
  3887. print img_picto('', 'category', 'class="paddingrightonly"').' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('optioncategory') ? GETPOST('optioncategory') : '', 'optioncategory', 0, 0, 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx');
  3888. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  3889. print ajax_combobox('optioncategory');
  3890. print '</div>';
  3891. print '</div>';
  3892. }
  3893. print '</div>';
  3894. print '<input type="submit" class="button margintoponly" name="buttonreplacesitesearch" value="'.dol_escape_htmltag($langs->trans("Search")).'">';
  3895. print '</div></div>';
  3896. if ($mode == 'replacesite') {
  3897. print '<!-- List of search result -->'."\n";
  3898. print '<div class="rowsearchresult clearboth">';
  3899. print '<br>';
  3900. print '<br>';
  3901. if ($listofpages['code'] == 'OK') {
  3902. $arrayofselected = is_array($toselect) ? $toselect : array();
  3903. $param = '';
  3904. $nbtotalofrecords = count($listofpages['list']);
  3905. $num = $limit;
  3906. $permissiontodelete = $user->hasRight('website', 'delete');
  3907. // List of mass actions available
  3908. $arrayofmassactions = array();
  3909. if ($user->hasRight('website', 'writephp') && $searchkey) {
  3910. $arrayofmassactions['replace'] = img_picto('', 'replacement', 'class="pictofixedwidth"').$langs->trans("Replace");
  3911. }
  3912. if ($user->hasRight('website', 'write')) {
  3913. $arrayofmassactions['setcategory'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("ClassifyInCategory");
  3914. }
  3915. if ($user->hasRight('website', 'write')) {
  3916. $arrayofmassactions['delcategory'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("RemoveCategory");
  3917. }
  3918. if ($permissiontodelete) {
  3919. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  3920. }
  3921. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  3922. $arrayofmassactions = array();
  3923. }
  3924. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  3925. $massactionbutton .= '<div class="massactionother massactionreplace hidden">';
  3926. $massactionbutton .= $langs->trans("ReplaceString");
  3927. $massactionbutton .= ' <input type="text" name="replacestring" value="'.dol_escape_htmltag(GETPOST('replacestring', 'none')).'">';
  3928. $massactionbutton .= '</div>';
  3929. $massactionbutton .= '<div class="massactionother massactionsetcategory massactiondelcategory hidden">';
  3930. $massactionbutton .= img_picto('', 'category').' '.$langs->trans("Category");
  3931. $massactionbutton .= ' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('setcategory') ? GETPOST('setcategory') : '', 'setcategory', 64, 0, 0, 0, 'minwidth300 alignstart');
  3932. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  3933. $massactionbutton .= ajax_combobox('setcategory');
  3934. $massactionbutton .= '</div>';
  3935. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  3936. //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  3937. $selectedfields = '';
  3938. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  3939. print_barre_liste($langs->trans("Results"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 1, 1, 1);
  3940. $topicmail = "WebsitePageRef";
  3941. $modelmail = "websitepage_send";
  3942. $objecttmp = new WebsitePage($db);
  3943. $trackid = 'wsp'.$object->id;
  3944. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  3945. $param = 'mode=replacesite&website='.urlencode($website->ref);
  3946. $param .= '&searchstring='.urlencode($searchkey);
  3947. if (GETPOST('optioncontent')) {
  3948. $param .= '&optioncontent=content';
  3949. }
  3950. if (GETPOST('optionmeta')) {
  3951. $param .= '&optionmeta=meta';
  3952. }
  3953. if (GETPOST('optionsitefiles')) {
  3954. $param .= '&optionsitefiles=optionsitefiles';
  3955. }
  3956. if (GETPOST('optioncontainertype')) {
  3957. $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
  3958. }
  3959. if (GETPOST('optionlanguage')) {
  3960. $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
  3961. }
  3962. if (GETPOST('optioncategory')) {
  3963. $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
  3964. }
  3965. print '<div class="div-table-responsive-no-min">';
  3966. print '<table class="noborder centpercent">';
  3967. print '<tr class="liste_titre">';
  3968. print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n";
  3969. print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n";
  3970. print getTitleFieldOfList("Categories", 0, $_SERVER['PHP_SELF']);
  3971. print getTitleFieldOfList("Language", 0, $_SERVER['PHP_SELF'], 'lang', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
  3972. print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
  3973. print getTitleFieldOfList("DateLastModification", 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n"; // Date last modif
  3974. print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
  3975. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  3976. print '</tr>';
  3977. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  3978. $c = new Categorie($db);
  3979. $totalnbwords = 0;
  3980. foreach ($listofpages['list'] as $answerrecord) {
  3981. if (is_object($answerrecord) && get_class($answerrecord) == 'WebsitePage') {
  3982. print '<tr>';
  3983. // Type of container
  3984. print '<td class="nowraponall">'.$langs->trans("Container").' - ';
  3985. print $langs->trans($answerrecord->type_container); // TODO Use label of container
  3986. print '</td>';
  3987. // Container url and label
  3988. print '<td>';
  3989. print $answerrecord->getNomUrl(1);
  3990. print ' <span class="opacitymedium">('.($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle")).')</span>';
  3991. //print '</td>';
  3992. //print '<td class="tdoverflow100">';
  3993. print '<br>';
  3994. print '<span class="opacitymedium">'.$answerrecord->description.'</span>';
  3995. print '</td>';
  3996. // Categories - Tags
  3997. print '<td>';
  3998. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  3999. // Get current categories
  4000. $existing = $c->containing($answerrecord->id, Categorie::TYPE_WEBSITE_PAGE, 'object');
  4001. if (is_array($existing)) {
  4002. foreach ($existing as $tmpcategory) {
  4003. //var_dump($tmpcategory);
  4004. print img_object($langs->trans("Category").' : '.$tmpcategory->label, 'category', 'style="padding-left: 2px; padding-right: 2px; color: #'.($tmpcategory->color != '' ? $tmpcategory->color : '888').'"');
  4005. }
  4006. }
  4007. }
  4008. //var_dump($existing);
  4009. print '</td>';
  4010. $param = '?mode=replacesite';
  4011. $param .= '&websiteid='.$website->id;
  4012. $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
  4013. $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
  4014. $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
  4015. $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
  4016. $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
  4017. $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
  4018. $param .= '&searchstring='.urlencode($searchkey);
  4019. // Language
  4020. print '<td class="center">';
  4021. print picto_from_langcode($answerrecord->lang, $answerrecord->lang);
  4022. print '</td>';
  4023. // Number of words
  4024. print '<td class="center nowraponall">';
  4025. $textwithouthtml = dol_string_nohtmltag(dolStripPhpCode($answerrecord->content));
  4026. $characterMap = 'áàéèëíóúüñùç0123456789';
  4027. $nbofwords = str_word_count($textwithouthtml, 0, $characterMap);
  4028. if ($nbofwords) {
  4029. print $nbofwords.' '.$langs->trans("words");
  4030. $totalnbwords += $nbofwords;
  4031. }
  4032. print '</td>';
  4033. // Date last modification
  4034. print '<td class="center nowraponall">';
  4035. print dol_print_date($answerrecord->date_modification, 'dayhour');
  4036. print '</td>';
  4037. // Edit properties, HTML sources, status
  4038. print '<td class="tdwebsitesearchresult right nowraponall">';
  4039. $disabled = '';
  4040. $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editmeta&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
  4041. if (empty($user->rights->website->write)) {
  4042. $disabled = ' disabled';
  4043. $urltoedithtmlsource = '';
  4044. }
  4045. print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditPageMeta").'">'.img_picto($langs->trans("EditPageMeta"), 'pencil-ruler').'</a>';
  4046. $disabled = '';
  4047. $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editsource&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
  4048. if (empty($user->rights->website->write)) {
  4049. $disabled = ' disabled';
  4050. $urltoedithtmlsource = '';
  4051. }
  4052. print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditHTMLSource").'">'.img_picto($langs->trans("EditHTMLSource"), 'edit').'</a>';
  4053. print '<span class="marginleftonly marginrightonly"></span>';
  4054. print ajax_object_onoff($answerrecord, 'status', 'status', 'Enabled', 'Disabled', array(), 'valignmiddle');
  4055. print '</td>';
  4056. // Action column
  4057. print '<td class="nowrap center">';
  4058. print '<!-- Status of page -->'."\n";
  4059. if ($massactionbutton || $massaction) {
  4060. $selected = 0;
  4061. if (in_array($answerrecord->id, $arrayofselected)) {
  4062. $selected = 1;
  4063. }
  4064. print '<input id="'.$answerrecord->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$answerrecord->id.'"'.($selected ? ' checked="checked"' : '').'>';
  4065. }
  4066. print '</td>';
  4067. print '</tr>';
  4068. } else {
  4069. print '<tr>';
  4070. // Type of container
  4071. print '<td>';
  4072. $translateofrecordtype = array(
  4073. 'website_csscontent'=>'WEBSITE_CSS_INLINE',
  4074. 'website_jscontent'=>'WEBSITE_JS_INLINE',
  4075. 'website_robotcontent'=>'WEBSITE_ROBOT',
  4076. 'website_htmlheadercontent'=>'WEBSITE_HTML_HEADER',
  4077. 'website_htaccess'=>'WEBSITE_HTACCESS',
  4078. 'website_readme'=>'WEBSITE_README',
  4079. 'website_manifestjson'=>'WEBSITE_MANIFEST_JSON'
  4080. );
  4081. if (!empty($translateofrecordtype[$answerrecord['type']])) {
  4082. print $langs->trans($translateofrecordtype[$answerrecord['type']]);
  4083. } else {
  4084. print $answerrecord['type'];
  4085. }
  4086. print '</td>';
  4087. $param = '?mode=replacesite';
  4088. $param .= '&websiteid='.$website->id;
  4089. $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
  4090. $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
  4091. $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
  4092. $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
  4093. $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
  4094. $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
  4095. $param .= '&searchstring='.urlencode($searchkey);
  4096. // Container url and label
  4097. print '<td>';
  4098. $backtopageurl = $_SERVER["PHP_SELF"].$param;
  4099. print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcss&token='.newToken().'&website='.urlencode($website->ref).'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").'</a>';
  4100. print '</td>';
  4101. // Language
  4102. print '<td>';
  4103. print '</td>';
  4104. // Categories - Tags
  4105. print '<td>';
  4106. print '</td>';
  4107. // Nb of words
  4108. print '<td>';
  4109. print '</td>';
  4110. // Date last modification
  4111. print '<td class="center nowraponall">';
  4112. //print dol_print_date(filemtime());
  4113. print '</td>';
  4114. // Edit properties, HTML sources, status
  4115. print '<td>';
  4116. print '</td>';
  4117. // Action column
  4118. print '<td class="nowrap center">';
  4119. print '</td>';
  4120. print '</tr>';
  4121. }
  4122. }
  4123. if (count($listofpages['list']) >= 2) {
  4124. // Total
  4125. print '<tr class="lite_titre">';
  4126. // Type of container
  4127. print '<td>';
  4128. print $langs->trans("Total");
  4129. print '</td>';
  4130. // Container url and label
  4131. print '<td>';
  4132. print '</td>';
  4133. // Language
  4134. print '<td>';
  4135. print '</td>';
  4136. // Categories - Tags
  4137. print '<td>';
  4138. print '</td>';
  4139. // Nb of words
  4140. print '<td class="center nowraponall">';
  4141. print $totalnbwords.' '.$langs->trans("words");
  4142. print '</td>';
  4143. // Date last modification
  4144. print '<td>';
  4145. print '</td>';
  4146. // Edit properties, HTML sources, status
  4147. print '<td>';
  4148. print '</td>';
  4149. // Action column
  4150. print '<td class="nowrap center">';
  4151. print '</td>';
  4152. print '</tr>';
  4153. }
  4154. print '</table>';
  4155. print '</div>';
  4156. print '<br>';
  4157. } else {
  4158. print '<div class="warning">'.$listofpages['message'].'</div>';
  4159. }
  4160. print '</div>';
  4161. }
  4162. print '</form>';
  4163. }
  4164. if ((empty($action) || $action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') && !in_array($mode, array('replacesite'))) {
  4165. if ($pageid > 0 && $atleastonepage) {
  4166. // $filejs
  4167. // $filecss
  4168. // $filephp
  4169. // Ouput page under the Dolibarr top menu
  4170. $objectpage->fetch($pageid);
  4171. $jscontent = @file_get_contents($filejs);
  4172. $out = '<!-- Page content '.$filetpl.' : Div with (Htmlheader/Style of page from database + CSS Of website from file + Page content from database or by include if WEBSITE_SUBCONTAINERSINLINE is on) -->'."\n";
  4173. // Include a html so we can benefit of the header of page.
  4174. // Note: We can't use iframe as it can be used to include another external html file
  4175. // Note: We can't use frame as it is deprecated.
  4176. /*if ($includepageintoaframeoradiv == 'iframe')
  4177. {
  4178. $out .= "<iframe><body></html>";
  4179. }*/
  4180. $out .= "\n<html><head>\n";
  4181. $out .= "<!-- htmlheader/style of page from database -->\n";
  4182. $out .= dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1, 'htmlheader');
  4183. $out .= "<!-- htmlheader/style of website from files -->\n";
  4184. // TODO Keep only the <link> or the <script> tags
  4185. /*
  4186. $htmlheadercontent = @file_get_contents($filehtmlheader);
  4187. $dom = new DOMDocument;
  4188. @$dom->loadHTML($htmlheadercontent);
  4189. $styles = $dom->getElementsByTagName('link');
  4190. $scripts = $dom->getElementsByTagName('script');
  4191. foreach($styles as $stylescursor)
  4192. {
  4193. $out.=$stylescursor;
  4194. }
  4195. foreach($scripts as $scriptscursor)
  4196. {
  4197. $out.=$scriptscursor;
  4198. }
  4199. */
  4200. $out .= "</head>\n";
  4201. $out .= "\n<body>";
  4202. $out .= '<div id="websitecontentundertopmenu" class="websitecontentundertopmenu boostrap-iso">'."\n";
  4203. // REPLACEMENT OF LINKS When page called by website editor
  4204. $out .= '<!-- style of website from file -->'."\n";
  4205. $out .= '<style scoped>'."\n"; // "scoped" means "apply to parent element only and not grand parent". No more supported by browsers, snif !
  4206. $tmpout = '';
  4207. $tmpout .= '/* Include website CSS file */'."\n";
  4208. //$csscontent = @file_get_contents($filecss);
  4209. ob_start();
  4210. include $filecss;
  4211. $csscontent = ob_get_contents();
  4212. ob_end_clean();
  4213. $tmpout .= dolWebsiteReplacementOfLinks($object, $csscontent, 1, 'css');
  4214. $tmpout .= '/* Include style from the HTML header of page */'."\n";
  4215. // Clean the html header of page to get only <style> content
  4216. $tmp = preg_split('(<style[^>]*>|</style>)', $objectpage->htmlheader);
  4217. $tmpstyleinheader = '';
  4218. $i = 0;
  4219. foreach ($tmp as $valtmp) {
  4220. $i++;
  4221. if ($i % 2 == 0) {
  4222. $tmpstyleinheader .= $valtmp."\n";
  4223. }
  4224. }
  4225. $tmpout .= $tmpstyleinheader."\n";
  4226. // Clean style that may affect global style of Dolibarr
  4227. $tmpout = preg_replace('/}[\s\n]*body\s*{[^}]+}/ims', '}', $tmpout);
  4228. $out .= $tmpout;
  4229. $out .= '</style>'."\n";
  4230. // Note: <div> or <section> with contenteditable="true" inside this can be edited with inline ckeditor
  4231. // Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
  4232. // so editable will be available only from container created from scratch
  4233. //$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
  4234. $out .= '<div id="divbodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n";
  4235. $newcontent = $objectpage->content;
  4236. // If mode WEBSITE_SUBCONTAINERSINLINE is on
  4237. if (!empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) {
  4238. // TODO Check file $filephp exists, if not create it.
  4239. //var_dump($filetpl);
  4240. $filephp = $filetpl;
  4241. ob_start();
  4242. try {
  4243. $res = include $filephp;
  4244. if (empty($res)) {
  4245. print "ERROR: Failed to include file '".$filephp."'. Try to edit and re-save page ith this ID.";
  4246. }
  4247. } catch (Exception $e) {
  4248. print $e->getMessage();
  4249. }
  4250. $newcontent = ob_get_contents();
  4251. ob_end_clean();
  4252. }
  4253. // Change the contenteditable to "true" or "false" when mode Edit Inline is on or off
  4254. if (empty($conf->global->WEBSITE_EDITINLINE)) {
  4255. // Remove the contenteditable="true"
  4256. $newcontent = preg_replace('/(div|section)(\s[^\>]*)contenteditable="true"/', '\1\2', $newcontent);
  4257. } else {
  4258. // Keep the contenteditable="true" when mode Edit Inline is on
  4259. }
  4260. $out .= dolWebsiteReplacementOfLinks($object, $newcontent, 0, 'html', $objectpage->id)."\n";
  4261. //$out.=$newcontent;
  4262. $out .= '</div>';
  4263. $out .= '</div> <!-- End div id=websitecontentundertopmenu -->';
  4264. /*if ($includepageintoaframeoradiv == 'iframe')
  4265. {
  4266. $out .= "</body></html></iframe>";
  4267. }*/
  4268. $out .= "\n</body></html>\n";
  4269. $out .= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
  4270. print $out;
  4271. /*file_put_contents($filetpl, $out);
  4272. if (!empty($conf->global->MAIN_UMASK))
  4273. @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
  4274. // Output file on browser
  4275. dol_syslog("index.php include $filetpl $filename content-type=$type");
  4276. $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset
  4277. // This test if file exists should be useless. We keep it to find bug more easily
  4278. if (! file_exists($original_file_osencoded))
  4279. {
  4280. dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
  4281. exit;
  4282. }
  4283. //include_once $original_file_osencoded;
  4284. */
  4285. /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$pageid.'"/>';
  4286. print '</iframe>';*/
  4287. } else {
  4288. if (empty($websitekey) || $websitekey == '-1') {
  4289. print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("NoWebSiteCreateOneFirst").'</span></div><br><br><br>';
  4290. print '<div class="center"><div class="logo_setup"></div></div>';
  4291. } else {
  4292. print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("PreviewOfSiteNotYetAvailable", $object->ref).'</span></div><br><br><br>';
  4293. print '<div class="center"><div class="logo_setup"></div></div>';
  4294. }
  4295. }
  4296. }
  4297. // End of page
  4298. llxFooter();
  4299. $db->close();