diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index f59c7d23697..6c43fa7fc7c 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -138,6 +138,6 @@ RegenerateWebsiteContent=Regenerate web site cache files AllowedInFrames=Allowed in Frames DefineListOfAltLanguagesInWebsiteProperties=Define list of all available languages into web site properties. GenerateSitemaps=Generate website sitemap file -BackToPreview= Back to preview -GeneratedSitemapsFiles = Generated sitemap files -EnterWebsiteUrl= Enter your website URL +ConfirmGenerateSitemaps=If you confirm, you will erase the existing sitemap file... +ConfirmSitemapsCreation=Confirm sitemap generation +SitemapGenerated=Sitemap Generated diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 5475efc50eb..49e1c4d0d55 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -2155,6 +2155,65 @@ if ($action == 'regeneratesite') } } +$form = new Form($db); +$formadmin = new FormAdmin($db); +$formwebsite = new FormWebsite($db); +$formother = new FormOther($db); +$domainname = '0.0.0.0:8080'; +$tempdir = $conf->website->dir_output.'/'.$websitekey.'/'; + +// Confirm generation of website sitemaps +if($action == 'confirmgeneratesitemaps'){ + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$website->ref, $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref),'generatesitemaps', '', "yes", 1); + $action = 'preview'; +} + +// Generate web site sitemaps +if ($action == 'generatesitemaps') { + $domtree = new DOMDocument('1.0', 'UTF-8'); + $root = $domtree->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'); + $domtree->formatOutput = true; + + $sql = "SELECT wp.type_container , wp.pageurl, wp.lang, DATE(wp.tms) as tms, w.virtualhost"; + $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w"; + $sql .= " WHERE wp.type_container IN ('page', 'blogpost')"; + $resql = $db->query($sql); + if ($resql) { + $num_rows = $db->num_rows($resql); + if ($num_rows > 0) { + $i = 0; + while ($i < $num_rows) { + $objp = $db->fetch_object($resql); + $url = $domtree->createElement('url'); + $pageurl = $objp->pageurl; + if ($objp->lang) { + $pageurl = $objp->lang.'/'.$pageurl; + } + if ($objp->virtualhost) { + $domainname = $objp->virtualhost; + } + $loc = $domtree->createElement('loc', 'http://'.$domainname.'/'.$pageurl); + $lastmod = $domtree->createElement('lastmod', $objp->tms); + + $url->appendChild($loc); + $url->appendChild($lastmod); + $root->appendChild($url); + $i++; + } + $domtree->appendChild($root); + if ($domtree->save($tempdir.'sitemaps.'.$websitekey.'.xml')) + { + setEventMessages($langs->trans("SitemapGenerated"), null, 'mesgs'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + }else { + dol_print_error($db); + } + $action = 'preview'; +} + // Import site if ($action == 'importsiteconfirm') { @@ -2251,11 +2310,6 @@ if ($action == 'importsiteconfirm') * View */ -$form = new Form($db); -$formadmin = new FormAdmin($db); -$formwebsite = new FormWebsite($db); -$formother = new FormOther($db); -$formfile = new FormFile($db); $helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:Módulo_Website'; @@ -2470,11 +2524,9 @@ if (!GETPOST('hide_websitemenu')) print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'">'; print '   '; - - if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) - { - print dolButtonToOpenUrlInDialogPopup('generate_sitemap', $langs->transnoentitiesnoconv("GenerateSitemaps"), '', '/website/index.php?action=generatesitemapsdomainname&website='.$website->ref, $disabled); - } + + // Generate site map + print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'">'; print '   '; @@ -2579,7 +2631,7 @@ if (!GETPOST('hide_websitemenu')) // Toolbar for pages // - if ($websitekey && $websitekey != '-1' && !in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesite', 'replacesiteconfirm', 'generatesitemaps')) && !$file_manager) + if ($websitekey && $websitekey != '-1' && !in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesite', 'replacesiteconfirm')) && !$file_manager) { print ''; // Close current websitebar to open a new one @@ -3800,70 +3852,9 @@ if ($action == 'editmeta' || $action == 'createcontainer') // Edit properties of print '
'; } -$domainname = '0.0.0.0:8080'; -$tempdir = $conf->website->dir_temp.'/'.$websitekey.'/'; - -// Form URL for generate web site sitemaps -if ($action == 'generatesitemapsdomainname'){ - print '
'; - print ''; - print ''; - print ''; - print '

'; - print '
'.$langs->trans('EnterWebsiteUrl').'

'; - print ''.$form->textwithpicto('', $langs->trans("Exemple").': www.exemple.com').'

'; - print ''; - print '
'; - print '
'; -} - -// Generate web site sitemaps -if ($action == 'generatesitemaps') { - if (!empty($_POST['domainname'])) { - $domainname = $_POST['domainname']; - } - $container_array = array(); - $sql = "SELECT wp.type_container , wp.pageurl, wp.lang, DATE(wp.tms) as tms"; - $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp"; - $sql .= " WHERE wp.type_container IN ('page', 'blogpost')"; - $resql = $db->query($sql); - if ($resql) { - $num_rows = $db->num_rows($resql); - if ($num_rows > 0) { - $i = 0; - while ($i < $num_rows) { - $objp = $db->fetch_object($resql); - $container_array[] = $objp; - $i++; - } - } - }else { - dol_print_error($db); - } - - if (!is_dir($tempdir)) { - mkdir($tempdir); - } - $domtree = new DOMDocument('1.0', 'UTF-8'); - $domtree->formatOutput = true; - $root = $domtree->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'); - foreach ($container_array as $container) { - $url = $domtree->createElement('url'); - $pageurl = $container->pageurl; - if ($container->lang) { - $pageurl = $container->lang.'/'.$pageurl; - } - $loc = $domtree->createElement('loc', 'http://'.$domainname.'/'.$pageurl); - $lastmod = $domtree->createElement('lastmod', $container->tms); - - $url->appendChild($loc); - $url->appendChild($lastmod); - $root->appendChild($url); - } - $domtree->appendChild($root); - $domtree->save($tempdir.'sitemaps.'.$websitekey.'.xml'); - print '
'; - print $formfile->showdocuments('website', 'temp/'.$websitekey, $tempdir, $_SERVER["PHP_SELF"].'?action=""', $liste, 0, '', 1, 1, 0, 0, 0, '', $langs->trans("GeneratedSitemapsFiles")); +// Print formconfirm +if ($action == 'preview'){ + print $formconfirm; } if ($action == 'editfile' || $action == 'file_manager')