index.php 202 KB

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