index.php 198 KB

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