index.php 184 KB

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