index.php 202 KB

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