index.php 186 KB

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