diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..b545aae
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,17 @@
+{
+ "name": "auto_sitemap",
+ "description": "Create a dynamic sitemap.xml file based on elgg public entities",
+ "type": "elgg-plugin",
+ "keywords": ["elgg", "plugin", "tools"],
+ "license": "GPL-2.0",
+ "support": {
+ "source": "https://github.com/rohit1290/auto_sitemap",
+ "issues": "https://github.com/rohit1290/auto_sitemap/issues"
+ },
+ "require": {
+ "composer/installers": "^1.0.8"
+ },
+ "conflict": {
+ "elgg/elgg": "<3.3"
+ }
+}
\ No newline at end of file
diff --git a/elgg-plugin.php b/elgg-plugin.php
index 173e139..994fb31 100644
--- a/elgg-plugin.php
+++ b/elgg-plugin.php
@@ -2,9 +2,14 @@
require_once(__DIR__ . '/lib/functions.php');
return [
+ 'plugin' => [
+ 'name' => 'Auto Sitemap',
+ 'version' => '4.0',
+ 'dependencies' => [],
+ ],
'routes' => [
'collection:object:auto_sitemap' => [
- 'path' => 'auto_sitemap/{type}',
+ 'path' => 'auto_sitemap/{type}/{page}',
'resource' => 'auto_sitemap/default',
],
'auto_sitemap:object:xmlview' => [
diff --git a/languages/en.php b/languages/en.php
index fa77f7f..a2457ed 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -1,6 +1,6 @@
'Sitemap',
+return [
+ 'auto_sitemap:sitemap' => 'Sitemap',
'auto_sitemap:sitemap-learn-more' => 'If you want to learn more about sitemaps visit: ',
'auto_sitemap:entity-urls:title' =>'Entity URLs',
@@ -17,7 +17,7 @@
'auto_sitemap:schema:description' => 'For the time being there is only implemented version 0.9 of sitemaps.org.',
'auto_sitemap:main_url:title' => 'Main URL of the site',
- /* Opciones dropdown*/
+ /* Options dropdown*/
'auto_sitemap:updatefreq:disabled' => 'disabled (Skip this value)',
'auto_sitemap:updatefreq:always' => 'continuously (always)',
'auto_sitemap:updatefreq:hourly' => 'every hour (hourly)',
@@ -31,17 +31,14 @@
'auto_sitemap:changefreq_url:description' => 'Each URL in one line',
'auto_sitemap:other_entities:description' => 'Choose other entities to include in the sitemap',
'auto_sitemap:module:active:entity' => 'Add %s to sitemap? ',
- 'auto_sitemap:entity:user:title' => 'user profiles',
- 'auto_sitemap:entity:group:title' => 'groups profiles',
- 'auto_sitemap:entity:blog:title' => 'blog posts',
- 'auto_sitemap:entity:file:title' => 'uploaded files',
- 'auto_sitemap:entity:event:title' => 'events from event_calendar',
- 'auto_sitemap:entity:otros:title' => 'other entities',
-
+
+ 'collection:object:user' => "Users",
+ 'collection:object:group' => "Groups",
+
'option:yes' => 'Yes',
'option:no' => 'No',
'auto_sitemap:priority:none' => 'None',
'auto_sitemap:changefreq:description' => 'Choose a value for the changefreq atribute',
'auto_sitemap:priority:description' => 'Choose a priority for this URLs',
-);
\ No newline at end of file
+];
\ No newline at end of file
diff --git a/languages/es.php b/languages/es.php
deleted file mode 100644
index 3ca881b..0000000
--- a/languages/es.php
+++ /dev/null
@@ -1,48 +0,0 @@
- 'Si quieres aprender más sobre los sitemaps visita: ',
- 'auto_sitemap:entity-urls:title' =>'Entity URLs',
- 'auto_sitemap:entity-urls:description' =>'Escoge que objetos deseas añadir a tu sitemap',
- 'auto_sitemap:custom-urls:title' =>'Custom URLs',
- 'auto_sitemap:custom-urls:description' =>'Adicionalmente puedes especificar de forma manual URLs especificas de tu sitio web. Por ejemplo páginas estáticas, paginas, de ayuda, etc.',
- 'auto_sitemap:basic-config:title' => 'Configuración básica',
- 'auto_sitemap:max_urls:title' => 'Número máximo de URLs por sitemap (5000 por defecto)',
- 'auto_sitemap:max_urls:description' => 'Google recomienda mantener en el sitemap solo las URLs más recientes. Esto te ahorrará un montón de tráfico y tus urls antiguas seguirán indexadas en los buscadores',
- 'auto_sitemap:use_xsl:title' => 'Utilizar hoja de estilos en el sitemap?',
- 'auto_sitemap:use_xsl:description' => 'Añadir la hoja de estilos hará que puedas navegar entre los diferentes sitemaps por medio de enlaces como si se tratase de un documento html, y no influirá en la forma en la que los buscadores tratan tu sitemap. Desactivala solo si tienes algún tipo de problema para ver el sitemap',
- 'auto_sitemap:schema:title' => 'Esquema del sitemap',
- 'auto_sitemap:schema:description' => 'Por ahora solo hay implementada la version 0.9 de sitemaps.org.',
- 'auto_sitemap:main_url:title' => 'URL principal del sitio',
-
- /* Opciones dropdown*/
- 'auto_sitemap:updatefreq:disabled' => 'descativado (Omitir este valor)',
- 'auto_sitemap:updatefreq:always' => 'continuamente (always)',
- 'auto_sitemap:updatefreq:hourly' => 'cada hora (hourly)',
- 'auto_sitemap:updatefreq:daily' => 'cada dÃa (daily)',
- 'auto_sitemap:updatefreq:weekly' => 'cada semana (weekly)',
- 'auto_sitemap:updatefreq:monthly' => 'cada mes (monthly)',
- 'auto_sitemap:updatefreq:yearly' => 'cada año (yearly)',
- 'auto_sitemap:updatefreq:never' => 'nunca (never)',
-
- 'auto_sitemap:module:header:changefreq' => 'URLs que se actualizan ',
- 'auto_sitemap:changefreq_url:description' => 'Introduce una URL por cada linea',
- 'auto_sitemap:other_entities:description' => 'Selecciona otras entidades que se deben añadir al sitemap',
- 'auto_sitemap:module:active:entity' => 'Añadir %s al sitemap? ',
- 'auto_sitemap:entity:user:title' => 'los perfiles de los usuarios',
- 'auto_sitemap:entity:group:title' => 'los perfiles de los grupos',
- 'auto_sitemap:entity:blog:title' => 'las entradas del blog',
- 'auto_sitemap:entity:file:title' => 'los archivos',
- 'auto_sitemap:entity:event:title' => 'los eventos del calendario',
- 'auto_sitemap:entity:otros:title' => 'otras entidades',
-
- 'option:yes' => 'Si',
- 'option:no' => 'No',
-
- 'auto_sitemap:priority:none' => 'Omitir',
- 'auto_sitemap:changefreq:description' => 'Selecciona un valor para el atributo changefreq',
- 'auto_sitemap:priority:description' => 'Selecciona una prioridad para estas URLs',
-);
\ No newline at end of file
diff --git a/languages/fr.php b/languages/fr.php
deleted file mode 100644
index 0a3975f..0000000
--- a/languages/fr.php
+++ /dev/null
@@ -1,57 +0,0 @@
- "Pour en savoir plus sur les sitemaps, visitez : ",
-
- 'auto_sitemap:entity-urls:title' => "URLs de entités",
- 'auto_sitemap:entity-urls:description' => "Choisissez quels éléments vous souhaitez ajouter à votre sitemap",
- 'auto_sitemap:custom-urls:title' => "URLs personnalisées",
- 'auto_sitemap:custom-urls:description' => "Vous pouvez préciser une série d'URLs personnalisées supplémentaires pour votre site. Par exemple dezs pages statiques, pages d'aide, etc.",
-
- 'auto_sitemap:basic-config:title' => "Configuration simple",
- 'auto_sitemap:max_urls:title' => "Nombre maximum d'URLs dans chaque sitemap",
- 'auto_sitemap:max_urls:description' => "Google recommende de ne conserver que les dernières URLs dans la sitemap. Ceci vous économisera beaucoup de trafic, et vos anciennes URLs resteront indexées par les moteurs de recherche ",
- 'auto_sitemap:use_xsl:title' => "Utilisez une feuille de style dans la sitemap ?",
- 'auto_sitemap:use_xsl:description' => "Si activé, vous pourrez naviguer à travers les différentes sitemap du site via des liens comme dans un document HTML, et ceci n'affectera aucunement la manière dont les moteurs de recherche traitenet votre sitemap. Si vous rencontrez des difficulté pour accéder à la sitemap, veuillez désactiver cette option",
-
- 'auto_sitemap:esquema:title' => "Schéma de la sitemap",
- 'auto_sitemap:esquema:description' => "Pour le moment, seule la version 0.9 de sitemaps.org est implémentée.",
- 'auto_sitemap:main_url:title' => "Adresse principale du site",
-
-
- /* Opciones dropdown*/
- 'auto_sitemap:updatefreq:disabled' => "désactivé (skip this value)",
- 'auto_sitemap:updatefreq:always' => "continuellement (always)",
- 'auto_sitemap:updatefreq:hourly' => "toutes les heures (hourly)",
- 'auto_sitemap:updatefreq:daily' => "tous les jours (daily)",
- 'auto_sitemap:updatefreq:weekly' => "toutes les semaines (weekly)",
- 'auto_sitemap:updatefreq:monthly' => "tous les mois (monthly)",
- 'auto_sitemap:updatefreq:yearly' => "tous les ans (yearly)",
- 'auto_sitemap:updatefreq:never' => "jamais (never)",
-
- 'auto_sitemap:module:header:changefreq' => "URLs mises à jour ",
- 'auto_sitemap:changefreq_url:description' => "Une seule URL par ligne",
-
- 'auto_sitemap:other_entities:description' => "Choisissez les autres entités à inclure dans la sitemap",
-
- 'auto_sitemap:module:active:entity' => "Ajouter %s à la sitemap? ",
- 'auto_sitemap:entity:user:title' => "profiles des membres",
- 'auto_sitemap:entity:group:title' => "profiles des groupes",
- 'auto_sitemap:entity:blog:title' => "articles de blog",
- 'auto_sitemap:entity:file:title' => "fichiers publiés",
- 'auto_sitemap:entity:event:title' => "événements de event_calendar",
- 'auto_sitemap:entity:otros:title' => "autres entités",
-
- 'option:yes' => "Oui",
- 'option:no' => "Non",
-
- 'auto_sitemap:priority:none' => "Aucune",
- 'auto_sitemap:changefreq:description' => "Choisissez une valeur pour l'attribut changefreq",
- 'auto_sitemap:priority:description' => "Choisissez une priorité pour ces URLs",
-
-);
\ No newline at end of file
diff --git a/lib/functions.php b/lib/functions.php
index 6221a85..4dd0e79 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -1,15 +1,33 @@
$counter) {
+ if ($subtype != 'plugin' &&
+ $subtype != '__base__' &&
+ $subtype != 'admin_notice' &&
+ $subtype != 'messages' &&
+ $subtype != 'widget' &&
+ $subtype != 'site_notification' &&
+ $subtype != 'elgg_upgrade' &&
+ $subtype != 'api_key' &&
+ $subtype != 'eventday' &&
+ $subtype != 'eventslot' &&
+ $subtype != 'eventregistration' &&
+ $subtype != 'eventregistrationquestion' &&
+ $subtype != 'tidypics_batch' &&
+ $subtype != 'custom_group_field' &&
+ $subtype != 'custom_profile_field' &&
+ $subtype != 'event_calendar'
+ ) {
+ $relevantEntities[] = $subtype;
+ }
+}
-function auto_sitemap_getCustomUrls( $tipos ) {
+function auto_sitemap_getCustomUrls($entities) {
// get main url
$mainurl = elgg_get_plugin_setting('main_url','auto_sitemap');
@@ -17,27 +35,27 @@ function auto_sitemap_getCustomUrls( $tipos ) {
$priority = elgg_get_plugin_setting('main_url_priority','auto_sitemap');
if ( !empty($mainurl) ){
- $urls[] = Array(
- 'loc' => $mainurl,
- 'changefreq' => $changefreq,
- 'priority' => $priority
- );
+ $urls[] = [
+ 'loc' => $mainurl,
+ 'changefreq' => $changefreq,
+ 'priority' => $priority
+ ];
}
- // get custmo urls
- foreach ($tipos as $tipo) {
+ // get custom urls
+ foreach ($entities as $entity) {
- $urlList = Array();
- $urlList = explode("\n", elgg_get_plugin_setting( $tipo . '_url','auto_sitemap'));
- $priority = elgg_get_plugin_setting( $tipo . '_url_priority','auto_sitemap');
+ $urlList = [];
+ $urlList = explode("\n", elgg_get_plugin_setting( $entity . '_url','auto_sitemap'));
+ $priority = elgg_get_plugin_setting( $entity . '_url_priority','auto_sitemap');
foreach ($urlList as $url) {
if ( ! empty($url) ){
- $urls[] = Array(
- 'loc' => $url,
- 'changefreq' => $tipo,
- 'priority' => $priority
- );
+ $urls[] = [
+ 'loc' => $url,
+ 'changefreq' => $entity,
+ 'priority' => $priority
+ ];
}
}
}
@@ -45,120 +63,50 @@ function auto_sitemap_getCustomUrls( $tipos ) {
return $urls;
}
-function auto_sitemap_getEntityUrls($tipo) {
+function auto_sitemap_getEntityUrls($entity, $page) {
- switch ($tipo) {
+ switch ($entity) {
case 'user':
$options['type'] = 'user';
- break;
-
+ break;
case 'group':
$options['type'] = 'group';
- break;
-
-
- case 'blog':
- case 'file':
- $options['type'] = 'object';
- $options['subtypes'] = $tipo;
- break;
-
- case 'event':
+ break;
+ default:
$options['type'] = 'object';
- $options['subtypes'] = 'event_calendar';
+ $options['subtypes'] = $entity;
break;
}
- $changefreq = elgg_get_plugin_setting( $tipo . '_url_changefreq','auto_sitemap');
- $priority = elgg_get_plugin_setting( $tipo . '_url_priority','auto_sitemap');
- $max_urls = elgg_get_plugin_setting('max_urls','auto_sitemap');
-
- if ( ! is_numeric($max_urls) || $max_urls < 1 ) {
- $max_urls = 5000;
- }
+ $changefreq = elgg_get_plugin_setting( $entity . '_url_changefreq','auto_sitemap');
+ $priority = elgg_get_plugin_setting( $entity . '_url_priority','auto_sitemap');
+ $max_urls = get_max_urls_count();
$options['limit'] = $max_urls;
- // $options['wheres'] = array('e.access_id = 2');
- $options['wheres'] = [function(\Elgg\Database\QueryBuilder $qb, $main_alias) {
- return $qb->compare("{$main_alias}.access_id", '=', '2');
- }];
- $entradas = elgg_get_entities($options);
-
- foreach ($entradas as $value) {
-
- $entityUrls[] = array('loc' => $value->getURL(),
- 'lastmod' => $value->getTimeUpdated(),
- 'changefreq' => $changefreq,
- 'priority' => $priority
- );
- }
-
- // Ordeno por fecha
- usort($entityUrls, 'auto_sitemap_comparar');
-
- return $entityUrls;
-
-}
-
+ $options['offset'] = $max_urls*($page - 1);
-function auto_sitemap_getOtherEntityUrls( $entities ) {
-
- foreach ($entities as $entity) {
-
- $options['type'] = 'object';
- $options['subtypes'] = $entity;
-
- $changefreq = elgg_get_plugin_setting('other_url_changefreq','auto_sitemap');
- $priority = elgg_get_plugin_setting('other_url_priority','auto_sitemap');
- $max_urls = elgg_get_plugin_setting('max_urls','auto_sitemap');
-
- if ( ! is_numeric($max_urls) || $max_urls < 1 ) {
- $max_urls = 5000;
- }
-
- $options['limit'] = $max_urls;
-
- $entradas = elgg_get_entities($options);
+ $count = elgg_count_entities($options);
+ if($count == 0) { return []; }
+
+ $objects = elgg_get_entities($options);
- foreach ($entradas as $value) {
+ foreach ($objects as $value) {
- $entityUrls[] = array('loc' => $value->getURL(),
- 'lastmod' => $value->getTimeUpdated(),
- 'changefreq' => $changefreq,
- 'priority' => $priority
- );
- }
+ $entityUrls[] = [
+ 'loc' => $value->getURL(),
+ 'lastmod' => $value->getTimeUpdated(),
+ 'changefreq' => $changefreq,
+ 'priority' => $priority
+ ];
}
- // Ordeno por fecha
- usort($entityUrls, 'auto_sitemap_comparar');
+ // Compare
+ usort($entityUrls, 'auto_sitemap_compare');
return $entityUrls;
-
}
-
-function xml_plugin_get_otherEntityTypes() {
- $valid_types = array();
- $entity_stats = get_entity_statistics();
-
- foreach($entity_stats['object'] as $subtype => $counter) {
- if ($subtype != 'plugin' &&
- $subtype != '__base__' &&
- $subtype != 'admin_notice' &&
- $subtype != 'messages' &&
- $subtype != 'widget' &&
- $subtype != 'blog' &&
- $subtype != 'file' &&
- $subtype != 'event_calendar'
- ) {
- $valid_types[elgg_echo($subtype)] = $subtype;
- }
- }
- return $valid_types;
-}
-
-function auto_sitemap_comparar($x,$y){
+function auto_sitemap_compare($x,$y){
if ( $x['lastmod'] == $y['lastmod'] )
return 0;
else if ( $x['lastmod'] > $y['lastmod'] )
@@ -166,3 +114,12 @@ function auto_sitemap_comparar($x,$y){
else
return 1;
}
+
+function get_max_urls_count() {
+ $max_urls = elgg_get_plugin_setting('max_urls','auto_sitemap');
+
+ if ( !is_numeric($max_urls) || $max_urls < 1 ) {
+ $max_urls = 5000;
+ }
+ return $max_urls;
+}
diff --git a/manifest.xml b/manifest.xml
deleted file mode 100644
index 7c52781..0000000
--- a/manifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
';
-// max amount of urls to display in sitemap
+// max number of urls to display in sitemap
$content .= '