index.php 183 KB

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