index.php 186 KB

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