Skip to content

Commit c6b7065

Browse files
add sitemap
1 parent 630d43d commit c6b7065

12 files changed

Lines changed: 1038 additions & 0 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ RUN unzip -q /var/www/omeka-s.zip -d /var/www/ \
4747
COPY themes /var/www/html/themes
4848
COPY modules /var/www/html/modules
4949
COPY OEmbed.php /var/www/html/application/src/Media/Ingester/OEmbed.php
50+
COPY google23e26c94f7d8e210.html /var/www/html/google23e26c94f7d8e210.html
5051

5152
COPY extra.ini /usr/local/etc/php/conf.d/
5253
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini

google23e26c94f7d8e210.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-site-verification: google23e26c94f7d8e210.html

modules/Sitemaps/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

modules/Sitemaps/Module.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
namespace Sitemaps;
3+
4+
use Omeka\Module\AbstractModule;
5+
use Laminas\EventManager\SharedEventManagerInterface;
6+
use Laminas\EventManager\EventInterface;
7+
use Laminas\ServiceManager\ServiceLocatorInterface;
8+
use Laminas\Mvc\MvcEvent;
9+
use Omeka\Permissions\Acl;
10+
11+
class Module extends AbstractModule
12+
{
13+
/**
14+
* Include the configuration array containing the sitelogin controller, the
15+
* sitelogin controller factory and the sitelogin route
16+
*
17+
* {@inheritDoc}
18+
*
19+
* @see \Omeka\Module\AbstractModule::getConfig()
20+
*/
21+
public function getConfig ()
22+
{
23+
return include __DIR__ . '/config/module.config.php';
24+
}
25+
26+
/**
27+
* Called on module application bootstrap, this adds the required ACL level
28+
* authorization for anybody to use the sitelogin controller
29+
*
30+
* {@inheritDoc}
31+
*
32+
* @see \Omeka\Module\AbstractModule::onBootstrap()
33+
*/
34+
public function onBootstrap(MvcEvent $event)
35+
{
36+
parent::onBootstrap($event);
37+
38+
/** @var Acl $acl */
39+
$acl = $this->getServiceLocator()->get('Omeka\Acl');
40+
$acl->allow(
41+
null,
42+
[
43+
'Sitemaps\Controller\Site\SitemapsController'
44+
],
45+
null
46+
);
47+
}
48+
49+
/**
50+
* Attach to Laminas and Omeka specific listeners
51+
*/
52+
public function attachListeners(
53+
SharedEventManagerInterface $sharedEventManager
54+
) {
55+
// Attach to site settings form to add the module settings
56+
$sharedEventManager->attach(
57+
'Omeka\Form\SiteSettingsForm',
58+
'form.add_elements',
59+
array(
60+
$this,
61+
'addSitemapsSiteSetting'
62+
)
63+
);
64+
}
65+
66+
public function uninstall(ServiceLocatorInterface $serviceLocator)
67+
{
68+
$api = $serviceLocator->get('Omeka\ApiManager');
69+
$sites = $api->search('sites', [])->getContent();
70+
$siteSettings = $serviceLocator->get('Omeka\Settings\Site');
71+
72+
foreach ($sites as $site) {
73+
$siteSettings->setTargetId($site->id());
74+
$siteSettings->delete('sitemaps_enablesitemap');
75+
}
76+
}
77+
78+
/**
79+
* Adds a Checkbox element to the site settings form
80+
* This element is automatically handled by Omeka in the site_settings table
81+
*
82+
* @param EventInterface $event
83+
*/
84+
public function addSitemapsSiteSetting(EventInterface $event)
85+
{
86+
/** @var \Omeka\Form\UserForm $form */
87+
$form = $event->getTarget();
88+
89+
$siteSettings = $form->getSiteSettings();
90+
91+
$form->add([
92+
'type' => 'fieldset',
93+
'name' => 'sitemaps',
94+
'options' => [
95+
'label' => 'Sitemap file', // @translate
96+
],
97+
]);
98+
99+
$rsFieldset = $form->get('sitemaps');
100+
101+
$rsFieldset->add(
102+
array(
103+
'name' => 'sitemaps_enablesitemap',
104+
'type' => 'Checkbox',
105+
'options' => array(
106+
'label' => 'Enable dynamic sitemap for this site', // @translate
107+
'info' => 'Dynamically generates a sitemap.xml file at the root of the site, e.g.: https://myomekasite.com/s/slug/sitemap.xml', // @translate
108+
),
109+
'attributes' => array(
110+
'value' => (bool) $siteSettings->get(
111+
'sitemaps_enablesitemap',
112+
false
113+
)
114+
)
115+
)
116+
);
117+
return;
118+
}
119+
}

modules/Sitemaps/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# omeka-s-module-Sitemaps
2+
Module for Omeka S
3+
4+
This module generates dynamic individual sitemap XML files for your Omeka S sites.
5+
Indexed URLs include items show pages, item-sets browse pages, and site pages.
6+
7+
The module is in early development stage and could do with more advanced usage and testing. Use at your own risk.
8+
9+
## Installing / Getting started
10+
11+
This module requires Omeka S v3 or greater.
12+
13+
* Download and unzip in your `omeka-s/modules` directory.
14+
* Rename the uncompressed folder to `Sitemaps`.
15+
* Log into your Omeka-S admin backend and navigate to the `Modules` menu.
16+
* Click `Install` next to the Sitemaps module.
17+
18+
## Features
19+
20+
This module includes the following features:
21+
22+
* Individual site setting to enable Sitemap generation
23+
* Dynamically generate a sitemap.xml file for each site
24+
25+
### Enable Sitemap for a site
26+
27+
To enable the sitemap on a site of your choice:
28+
29+
* Navigate to your Omeka-S admin panel.
30+
* Click on the `Sites` menu.
31+
* Click the pencil icon next to the site you wish to configure.
32+
* Navigate to your site `Settings` menu.
33+
* Check the `Enable dynamic sitemap for this site` option and save.
34+
35+
The sitemap.xml file is dynamically generated: there is no file physically created on the server.
36+
The URL for site `site-slug` is the following: `http://myomekasite.com/s/site-slug/sitemap.xml`
37+
38+
## Module configuration
39+
40+
There is no module specific configuration.
41+
42+
## Known issues
43+
44+
See the Issues page.
45+
46+
## Contributing
47+
48+
The module is in early development stage and could do with more advanced usage and testing. Contributions are welcome. Please use Issues and Pull Requests workflows to contribute.
49+
50+
## Links
51+
52+
Also check out my other Omeka S modules:
53+
54+
* RestrictedSites: https://github.com/ManOnDaMoon/omeka-s-module-RestrictedSites
55+
* UserNames: https://github.com/ManOnDaMoon/omeka-s-module-UserNames
56+
* RoleBasedNavigation: https://github.com/ManOnDaMoon/omeka-s-module-RoleBasedNavigation
57+
58+
## Licensing
59+
60+
The code in this project is licensed under GNU GPLv3.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
return [
3+
'view_manager' => [
4+
'template_path_stack' => [
5+
OMEKA_PATH . '/modules/Sitemaps/view'
6+
]
7+
],
8+
'translator' => [
9+
'translation_file_patterns' => [
10+
[
11+
'type' => 'gettext',
12+
'base_dir' => OMEKA_PATH . '/modules/Sitemaps/language',
13+
'pattern' => '%s.mo',
14+
'text_domain' => null,
15+
],
16+
],
17+
],
18+
'controllers' => [
19+
'factories' => [
20+
'Sitemaps\Controller\Site\SitemapsController' => Sitemaps\Service\Controller\Site\SitemapsControllerFactory::class,
21+
]
22+
],
23+
'router' => [
24+
'routes' => [
25+
'site' => [
26+
'child_routes' => [
27+
'sitemap' => [
28+
'type' => 'Literal',
29+
'options' => [
30+
'route' => '/sitemap.xml',
31+
'defaults' => [
32+
'__NAMESPACE__' => 'Sitemaps\Controller\Site',
33+
'__SITE__' => true,
34+
'controller' => Sitemaps\Controller\Site\SitemapsController::class,
35+
'action' => 'index',
36+
],
37+
],
38+
'may_terminate' => true,
39+
],
40+
],
41+
],
42+
],
43+
],
44+
];
45+

modules/Sitemaps/config/module.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[info]
2+
name = "Sitemaps"
3+
version = "0.1"
4+
author = "Laurent Thomas"
5+
configurable = false
6+
description = "Sitemaps - Generate individual sitemaps for sites"
7+
module_link = "manondamoon.com"
8+
author_link = "manondamoon.com"

modules/Sitemaps/language/fr.mo

569 Bytes
Binary file not shown.

modules/Sitemaps/language/fr.po

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#, fuzzy
2+
msgid ""
3+
msgstr ""
4+
"MIME-Version: 1.0\n"
5+
"Content-Type: text/plain; charset=UTF-8\n"
6+
"Content-Transfer-Encoding: 8bit\n"
7+
8+
#: Module.php:95
9+
msgid "Sitemap file"
10+
msgstr "Fichier Sitemap"
11+
12+
#: Module.php:106
13+
msgid "Enable dynamic sitemap for this site"
14+
msgstr "Activer la génération dynamique du fichier sitemap pour ce site"
15+
16+
#: Module.php:107
17+
msgid ""
18+
"Dynamically generates a sitemap.xml file at the root of the site, e.g.: "
19+
"https://myomekasite.com/s/slug/sitemap.xml"
20+
msgstr "Génère dynamiquement un fichier sitemap.xml à la racine du site, ex. : "
21+
"https://monsiteomeka.com/s/slug/sitemap.xml"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace Sitemaps\Controller\Site;
3+
4+
use Laminas\Mvc\Controller\AbstractActionController;
5+
use Laminas\View\Model\ViewModel;
6+
use Doctrine\ORM\EntityManager;
7+
use Laminas\Http\Response;
8+
use Laminas\View\Renderer\PhpRenderer;
9+
10+
class SitemapsController extends AbstractActionController {
11+
12+
protected $viewRenderer;
13+
14+
public function __construct(PhpRenderer $viewRenderer) {
15+
$this->viewRenderer = $viewRenderer;
16+
}
17+
18+
public function indexAction() {
19+
20+
//TODO : Pagination for over 500 entries
21+
22+
$site = $this->currentSite();
23+
24+
$siteSettings = $this->siteSettings();
25+
$siteSettings->setTargetId($site->id());
26+
$hasSitemap = $siteSettings->get('sitemaps_enablesitemap', null);
27+
if (! $hasSitemap) {
28+
$this->response->setStatusCode(404);
29+
return;
30+
}
31+
32+
/** @var \Laminas\View\Model\ViewModel $view */
33+
$view = new ViewModel();
34+
$view->setTemplate('site/sitemap');
35+
36+
37+
$query = array();
38+
$query['site_id'] = $site->id();
39+
$response = $this->api()->search('items', $query);
40+
$response->getTotalResults();
41+
$items = $response->getContent();
42+
43+
44+
$query = array();
45+
$query['site_id'] = $site->id();
46+
$response = $this->api()->search('item_sets', $query);
47+
$response->getTotalResults();
48+
$itemsets = $response->getContent();
49+
50+
51+
$pages = array_merge($site->linkedPages(), $site->notlinkedPages());
52+
53+
$view->setVariable('site', $site);
54+
$view->setVariable('items', $items);
55+
$view->setVariable('itemsets', $itemsets);
56+
$view->setVariable('pages', $pages);
57+
$view->setTerminal(true);
58+
59+
return $view;
60+
}
61+
}

0 commit comments

Comments
 (0)