index.php 181 KB

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