Commit 2fd035f6 authored by Mike Rockétt's avatar Mike Rockétt

0.2.4-beta

- schema fixes (per ThePixelDeveloper's recent commits)
- config changes
- only allow addition of image fields if any exist
- change hook priority (after --> before) and prevent further hooks
- add X-SitemapRetrievedFromCache header for debugging purposes
parent 2ffd140c
{
"title": "Sitemap",
"version": "0.2.3",
"version": "0.2.4",
"author": "Mike Rockett",
"summary": "Renders a sitemap for your ProcessWire powered site. Supports multi-language, multi-site, and image sub-elements. Adapted from MarkupSitemapXML.",
"href": "http://github.com/rockettpw/markup-sitemap",
......
......@@ -180,7 +180,7 @@ class MarkupSitemap extends WireData implements Module
}
}
// Add the hook to process and render the sitemap.
$this->addHookAfter('ProcessPageView::pageNotFound', $this, 'render');
$this->addHookBefore('ProcessPageView::pageNotFound', $this, 'render');
}
// Add a hook that moves the XML Sitemap fields to the Settings tab
$this->addHookAfter('ProcessPageEdit::buildForm', $this, 'moveSitemapFields');
......@@ -233,34 +233,42 @@ class MarkupSitemap extends WireData implements Module
}
// Make sure that the root page exists.
if ($this->pages->get($rootPage) instanceof NullPage) {
return false;
}
// Check for cached sitemap or regenerate if it doesn't exist
$rootPageName = $this->sanitizer->pageName($rootPage);
$markupCache = $this->modules->MarkupCache;
if ((!$output = $markupCache->get('MarkupSitemap', 3600)) || $this->config->debug) {
$this->urlSet = new Urlset();
$this->addPages($this->pages->get($rootPage));
$sitemapOutput = new Output();
if ($this->sitemap_stylesheet) {
if ($this->sitemap_stylesheet_custom
&& filter_var($this->sitemap_stylesheet_custom, FILTER_VALIDATE_URL)) {
$stylesheetPath = $this->sitemap_stylesheet_custom;
} else {
$stylesheetPath = $this->urls->httpSiteModules . 'MarkupSitemap/assets/sitemap-stylesheet.xsl';
if (!$this->pages->get($rootPage) instanceof NullPage) {
// Check for cached sitemap or regenerate if it doesn't exist
$rootPageName = $this->sanitizer->pageName($rootPage);
$markupCache = $this->modules->MarkupCache;
if ((!$output = $markupCache->get('MarkupSitemap', 3600)) || $this->config->debug) {
$this->urlSet = new Urlset();
$this->addPages($this->pages->get($rootPage));
$sitemapOutput = new Output();
if ($this->sitemap_stylesheet) {
if ($this->sitemap_stylesheet_custom
&& filter_var($this->sitemap_stylesheet_custom, FILTER_VALIDATE_URL)) {
$stylesheetPath = $this->sitemap_stylesheet_custom;
} else {
$stylesheetPath = $this->urls->httpSiteModules . 'MarkupSitemap/assets/sitemap-stylesheet.xsl';
}
$sitemapOutput->addProcessingInstruction(
'xml-stylesheet',
'type="text/xsl" href="' . $stylesheetPath . '"'
);
}
$sitemapOutput->addProcessingInstruction(
'xml-stylesheet',
'type="text/xsl" href="' . $stylesheetPath . '"'
);
header('X-SitemapRetrievedFromCache: no');
$output = $sitemapOutput->setIndented(true)->getOutput($this->urlSet);
$markupCache->save($output);
} else {
header('X-SitemapRetrievedFromCache: yes');
}
$output = $sitemapOutput->setIndented(true)->getOutput($this->urlSet);
$markupCache->save($output);
header('Content-Type: application/xml', true, 200);
$event->return = $output;
// Prevent further hooks. This stops
// SystemNotifications from displaying a 404 event
// when /sitemap.xml is requested. Additionall,
// it prevents further modification to the sitemap.
$event->replace = true;
$event->cancelHooks = true;
}
header('Content-Type: application/xml', true, 200);
$event->return = $output;
}
/**
......@@ -323,13 +331,15 @@ class MarkupSitemap extends WireData implements Module
protected function addImages($page, $url, $language = null)
{
// Loop through declared image fields and skip non image fields
foreach ($this->sitemap_image_fields as $imageFieldName) {
$page->of(false);
$imageField = $page->$imageFieldName;
if ($imageField) {
foreach ($imageField as $image) {
if ($image instanceof Pageimage) {
$url->addSubElement($this->addImage($image, $language));
if ($this->sitemap_image_fields) {
foreach ($this->sitemap_image_fields as $imageFieldName) {
$page->of(false);
$imageField = $page->$imageFieldName;
if ($imageField) {
foreach ($imageField as $image) {
if ($image instanceof Pageimage) {
$url->addSubElement($this->addImage($image, $language));
}
}
}
}
......
......@@ -114,21 +114,19 @@ class MarkupSitemapConfig extends ModuleConfig
}
$inputfields->add($includeTemplatesField);
// Add the image-field-selector field
$imageFieldsField = $this->buildInputField('AsmSelect', [
'name+id' => 'sitemap_image_fields',
'label' => $this->_('Image fields'),
'description' => $this->_('If you’d like to include images in your sitemap (for somewhat enhanced Google Images support), specify the image fields you’d like MarkupSitemap to traverse and include. The sitemap will include images for every page that uses the field(s) you select below, except for pages that are set to not have their images included.'),
'icon' => 'image',
'collapsed' => Inputfield::collapsedBlank,
]);
foreach ($this->fields as $field) {
$fieldType = $field->get('type')->className;
if ($fieldType === 'FieldtypeImage') {
// Add the image-field-selector field if image fields exist
if ($imageFields = $this->fields->find('type=FieldtypeImage') and $imageFields->count) {
$imageFieldsField = $this->buildInputField('AsmSelect', [
'name+id' => 'sitemap_image_fields',
'label' => $this->_('Image fields'),
'description' => $this->_('If you’d like to include images in your sitemap (for somewhat enhanced Google Images support), specify the image fields you’d like MarkupSitemap to traverse and include. The sitemap will include images for every page that uses the field(s) you select below, except for pages that are set to not have their images included.'),
'icon' => 'image',
]);
foreach ($imageFields as $field) {
$imageFieldsField->addOption($field->name, "{$field->get('label|name')} (used in {$field->numFieldgroups()} templates)");
}
$inputfields->add($imageFieldsField);
}
$inputfields->add($imageFieldsField);
// Add the stylesheet checkbox
$inputfields->add($this->buildInputField('Checkbox', [
......@@ -136,6 +134,7 @@ class MarkupSitemapConfig extends ModuleConfig
'label' => $this->_('Sitemap Stylesheet'),
'label2' => $this->_('Add a stylesheet to the sitemap'),
'icon' => 'css3',
'columnWidth' => '35%',
]));
// Add the custom stylesheet text field
......@@ -147,7 +146,7 @@ class MarkupSitemapConfig extends ModuleConfig
'showIf' => 'sitemap_stylesheet=1',
'notes' => $this->_('The default stylesheet is located at **assets/sitemap-stylesheet.xsl** in the module’s directory. If you leave this field blank or your input is not a valid URL, the default will be used.'),
'icon' => 'file-o',
'collapsed' => Inputfield::collapsedBlank,
'columnWidth' => '65%',
]));
// Add the default-language iso text field
......@@ -155,7 +154,7 @@ class MarkupSitemapConfig extends ModuleConfig
$inputfields->add($this->buildInputField('Text', [
'name+id' => 'sitemap_default_iso',
'label' => $this->_('ISO code for default language'),
'description' => $this->_('If you’ve set your home page to not include a language ISO (default language name) **and** your home page’s default language name is empty, then you can set an ISO code here for the default language. This will prevent the sitemap from containing `hreflang="home"` for all default-language URLs.'),
'description' => $this->_('If you’ve set your home page to not include a language ISO (default language name) via LanguageSupportPageNames **and** your home page’s default language name is empty, then you can set an ISO code here for the default language that will appear in the sitemap. This will prevent the sitemap from containing `hreflang="home"` for all default-language URLs.'),
'notes' => $this->_('Note that if your home page has a name for the default language, then this option will not take any effect.'),
'placeholder' => $this->_('en'),
'icon' => 'language',
......@@ -163,6 +162,18 @@ class MarkupSitemapConfig extends ModuleConfig
]));
}
$this->config->scripts->add($this->urls->httpSiteModules . 'MarkupSitemap/assets/scripts/config.js');
// Add the support-development markup field
$supportText = $this->wire('sanitizer')->entitiesMarkdown($this->_('Sitemap is proudly [open-source](http://opensource.com/resources/what-open-source) and is [free to use](https://en.wikipedia.org/wiki/Free_software) for personal and commercial projects. Please consider [making a small donation](https://rockett.pw/donate) in support of the development of MarkupSitemap and other modules.'), ['fullMarkdown' => true]);
$inputfields->add($this->buildInputField('Markup', [
'id' => 'support_development',
'label' => $this->_('Support Development'),
'value' => $supportText,
'icon' => 'paypal',
'collapsed' => Inputfield::collapsedYes,
]));
return $inputfields;
}
......
## Sitemap for ProcessWire
![Shield: Version = 0.2.3-beta](https://img.shields.io/badge/version-0.2.3_beta-orange.svg?style=flat-square) ![Shield: Version = 0.2.3](https://img.shields.io/badge/requires_ProcessWire-2.8+-green.svg?style=flat-square) ![Shield: License = MIT](https://img.shields.io/github/license/rockettpw/markup-sitemap.svg?style=flat-square)
![Shield: Version = 0.2.4-beta](https://img.shields.io/badge/version-0.2.4_beta-orange.svg?style=flat-square) ![Shield: Version = 0.2.4](https://img.shields.io/badge/requires_ProcessWire-2.8+-green.svg?style=flat-square) ![Shield: License = MIT](https://img.shields.io/github/license/rockettpw/markup-sitemap.svg?style=flat-square)
An upgrade to MarkupSitemapXML by Pete, MarkupSitemap adds multi-language support using the built-in LanguageSupportPageNames. Where multi-language pages are available, they are added to the sitemap by means of an alternate link in that page’s `<url>`. Support for listing images in the sitemap on a page-by-page basis and using a sitemap stylesheet are also added.
......
$(function() {
$('#support_development > .InputfieldHeader, #support_development > .InputfieldContent').css('background-color', '#ffffeb');
});
\ No newline at end of file
......@@ -74,11 +74,11 @@ class Urlset implements OutputContract
{
$XMLWriter->startElement('urlset');
$XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$XMLWriter->writeAttribute('xmlns:xsi', 'https://www.w3.org/2001/XMLSchema-instance');
$XMLWriter->writeAttribute('xsi:schemaLocation',
'http://www.sitemaps.org/schemas/sitemap/0.9 ' .
'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd');
'https://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd');
$XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
......
......@@ -16,6 +16,7 @@ use XMLWriter;
/**
* Class SitemapIndex
* RESERVED FOR FUTURE USE
*
* @package Rockett\Sitemap
*/
......@@ -47,12 +48,12 @@ class SitemapIndex implements OutputContract
public function generateXML(XMLWriter $XMLWriter)
{
$XMLWriter->startElement('sitemapindex');
$XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$XMLWriter->writeAttribute('xmlns:xsi', 'https://www.w3.org/2001/XMLSchema-instance');
$XMLWriter->writeAttribute(
'xsi:schemaLocation',
'http://www.sitemaps.org/schemas/sitemap/0.9 ' .
'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd'
'https://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd'
);
$XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
......
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