index.php 194 KB

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