index.php 186 KB

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