index.php 186 KB

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