Commit 504b3a15 authored by gbyte.co's avatar gbyte.co

Include table sorting library and tidy up

parent fb1fe3d1
......@@ -19,8 +19,7 @@
"license": "GPL-2.0+",
"minimum-stability": "dev",
"require": {
"ext-xmlwriter": "*",
"mottie/tablesorter": "^2.31"
"ext-xmlwriter": "*"
},
"extra": {
"drush": {
......
......@@ -69,9 +69,10 @@ class SimplesitemapController extends ControllerBase {
}
/**
* Returns the XML stylesheet for sitemap.
* Returns the XML stylesheet for the sitemap.
*/
public function getSitemapXsl() {
// Read the XSL content from the file.
$module_path = drupal_get_path('module', 'simple_sitemap');
$xsl_content = file_get_contents($module_path . '/xsl/simple_sitemap.xsl');
......@@ -79,7 +80,7 @@ class SimplesitemapController extends ControllerBase {
// Replace custom tokens in the XSL content with appropriate values.
$replacements = [
'[title]' => $this->t('Sitemap file'),
'[generated-by]' => $this->t('Generated by the <a href="@link">Drupal Simple XML sitemap module</a>.', ['@link' => 'https://www.drupal.org/project/simple_sitemap']),
'[generated-by]' => $this->t('Generated by the <a href="@link">Simple XML sitemap</a> Drupal module.', ['@link' => 'https://www.drupal.org/project/simple_sitemap']),
'[number-of-sitemaps]' => $this->t('Number of sitemaps in this index'),
'[sitemap-url]' => $this->t('Sitemap URL'),
'[number-of-urls]' => $this->t('Number of URLs in this sitemap'),
......@@ -90,7 +91,7 @@ class SimplesitemapController extends ControllerBase {
'[translation-set]' => $this->t('Translation set'),
'[images]' => $this->t('Images'),
'[jquery]' => base_path() . 'core/assets/vendor/jquery/jquery.min.js',
'[jquery-tablesorter]' => base_path() . 'libraries/tablesorter/dist/js/jquery.tablesorter.min.js',
'[jquery-tablesorter]' => base_path() . $module_path . '/xsl/jquery.tablesorter.min.js',
'[xsl-js]' => base_path() . $module_path . '/xsl/simple_sitemap.xsl.js',
'[xsl-css]' => base_path() . $module_path . '/xsl/simple_sitemap.xsl.css',
];
......@@ -100,6 +101,7 @@ class SimplesitemapController extends ControllerBase {
$response = new Response($xsl_content);
$response->headers->set('Content-type', 'application/xml; charset=utf-8');
$response->headers->set('X-Robots-Tag', 'noindex, follow');
return $response;
}
......
......@@ -134,7 +134,6 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$sitemap_manager = $this->generator->getSitemapManager();
$sitemap_statuses = $this->fetchSitemapInstanceStatuses();
foreach ($sitemap_manager->getSitemapTypes() as $type_name => $type_definition) {
if (!empty($variants = $sitemap_manager->getSitemapVariants($type_name, FALSE))) {
$form['simple_sitemap_settings']['status']['types'][$type_name] = [
......@@ -239,8 +238,8 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$form['simple_sitemap_settings']['settings']['xsl'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include a stylesheet in the sitemaps for humans'),
'#description' => $this->t('When enabled, this will add formatting and tables with sorting to make it easier to view the XML sitemap data instead of viewing raw XML output. Search engines will ignore this.'),
'#title' => $this->t('Add styling and sorting to sitemaps'),
'#description' => $this->t('If checked, sitemaps will be displayed as tables with sortable entries and thus become much friendlier towards human visitors. Search engines will not care.'),
'#default_value' => $this->generator->getSetting('xsl', TRUE),
];
......@@ -250,13 +249,6 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#open' => FALSE,
];
$language_options = [];
foreach ($this->languageManager->getLanguages() as $language) {
if (!$language->isDefault()) {
$language_options[$language->getId()] = $language->getName();
}
}
$form['simple_sitemap_settings']['settings']['languages']['skip_untranslated'] = [
'#type' => 'checkbox',
'#title' => $this->t('Skip non-existent translations'),
......@@ -264,6 +256,12 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#default_value' => $this->generator->getSetting('skip_untranslated', FALSE),
];
$language_options = [];
foreach ($this->languageManager->getLanguages() as $language) {
if (!$language->isDefault()) {
$language_options[$language->getId()] = $language->getName();
}
}
$form['simple_sitemap_settings']['settings']['languages']['excluded_languages'] = [
'#title' => $this->t('Exclude languages'),
'#type' => 'checkboxes',
......
......@@ -99,12 +99,14 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
protected function getXml(array $links) {
$this->writer->openMemory();
$this->writer->setIndent(TRUE);
$this->writer->startDocument(self::XML_VERSION, self::ENCODING);
// Add the XML stylesheet to document if necessary.
$this->writer->startSitemapDocument();
// Add the XML stylesheet to document if enabled.
if ($this->settings['xsl']) {
$this->writer->writeXsl();
}
$this->writer->writeComment(self::GENERATED_BY);
$this->writer->writeGeneratedBy();
$this->writer->startElement('urlset');
// Add attributes to document.
......
......@@ -17,10 +17,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
const FIRST_CHUNK_DELTA = 1;
const INDEX_DELTA = 0;
const GENERATED_BY = 'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.';
const XML_VERSION = '1.0';
const ENCODING = 'UTF-8';
const XMLNS = 'http://www.sitemaps.org/schemas/sitemap/0.9';
/**
......@@ -147,12 +143,14 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
protected function getIndexXml(array $chunk_info) {
$this->writer->openMemory();
$this->writer->setIndent(TRUE);
$this->writer->startDocument(self::XML_VERSION, self::ENCODING);
// Add the XML stylesheet to document if necessary.
$this->writer->startSitemapDocument();
// Add the XML stylesheet to document if enabled.
if ($this->settings['xsl']) {
$this->writer->writeXsl();
}
$this->writer->writeComment(self::GENERATED_BY);
$this->writer->writeGeneratedBy();
$this->writer->startElement('sitemapindex');
// Add attributes to document.
......
......@@ -10,6 +10,10 @@ use Drupal\Core\Url;
*/
class SitemapWriter extends \XMLWriter {
const GENERATED_BY = 'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.';
const XML_VERSION = '1.0';
const ENCODING = 'UTF-8';
/**
* Adds the XML stylesheet to the XML page.
*/
......@@ -18,4 +22,12 @@ class SitemapWriter extends \XMLWriter {
$this->writePI('xml-stylesheet', 'type="text/xsl" href="' . $xsl_url . '"');
}
public function writeGeneratedBy() {
$this->writeComment(self::GENERATED_BY);
}
public function startSitemapDocument() {
$this->startDocument(self::XML_VERSION, self::ENCODING);
}
}
......@@ -227,6 +227,7 @@ class Simplesitemap {
* Returns a sitemap variant, its index, or its requested chunk.
*
* @param int|null $delta
* Optional delta of the chunk.
*
* @return string|false
* If no chunk delta is provided, either the sitemap variant is returned,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment