index.php 187 KB

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