primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
/**
* @package OSMap
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2007-2014 XMap - Joomla! Vargas - Guillermo Vargas. All rights reserved.
* @copyright 2016-2024 Joomlashack.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSMap.
*
* OSMap is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSMap. If not, see <https://www.gnu.org/licenses/>.
*/
use Joomla\CMS\Language\Language;
defined('_JEXEC') or die();
/**
* @var OsmapViewXml $this
* @var object $template
* @var string $layout
* @var string $layoutTemplate
* @var Language $lang
* @var string $filetofind
*/
echo sprintf('<?xml version="1.0" encoding="%s"?>' . "\n", $this->_charset);
if (empty($this->message)) {
echo $this->loadTemplate($this->type);
} else {
echo '<message>' . $this->message . '</message>';
}

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_OSMAP_SITEMAP_XML_VIEW_DEFAULT_TITLE">
<message>
<![CDATA[COM_OSMAP_SITEMAP_XML_VIEW_DEFAULT_DESC]]>
</message>
</layout>
<fields name="request">
<fieldset name="request"
addfieldpath="/administrator/components/com_osmap/form/fields">
<field name="id"
type="osmap.sitemaps"
required="true"
label="COM_OSMAP_SITEMAP"/>
<field name="format"
type="hidden"
default="xml"/>
</fieldset>
</fields>
<fields name="params">
<fieldset name="basic"
label="COM_OSMAP_FIELDSET_SITEMAP_SETTINGS_LABEL">
<field name="add_styling"
type="radio"
class="btn-group btn-group-yesno"
layout="joomla.form.field.radio.switcher"
label="COM_OSMAP_OPTION_ADD_STYLING_LABEL"
description="COM_OSMAP_OPTION_ADD_STYLING_DESC"
default="1">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="debug"
type="radio"
class="btn-group btn-group-yesno"
layout="joomla.form.field.radio.switcher"
label="COM_OSMAP_OPTION_DEBUG_LABEL"
description="COM_OSMAP_OPTION_DEBUG_DESC"
default="0">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="news_publication_name"
type="text"
label="COM_OSMAP_NEWS_PUBLICATION_NAME_LABEL"
description="COM_OSMAP_NEWS_PUBLICATION_NAME_DESC"/>
</fieldset>
</fields>
</metadata>

View File

@ -0,0 +1,93 @@
<?php
/**
* @package OSMap
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2007-2014 XMap - Joomla! Vargas - Guillermo Vargas. All rights reserved.
* @copyright 2016-2024 Joomlashack.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSMap.
*
* OSMap is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSMap. If not, see <https://www.gnu.org/licenses/>.
*/
use Alledia\OSMap\Sitemap\Item;
use Joomla\CMS\Language\Language;
use Joomla\Utilities\ArrayHelper;
defined('_JEXEC') or die();
/**
* @var OSMapViewXml $this
* @var string $template
* @var string $layout
* @var string $layoutTemplate
* @var Language $lang
* @var string $filetofind
*/
$ignoreDuplicates = (int)$this->osmapParams->get('ignore_duplicated_uids', 1);
$printNodeCallback = function (Item $node) use ($ignoreDuplicates) {
$display = !$node->ignore
&& $node->published
&& (!$node->duplicate || !$ignoreDuplicates)
&& $node->visibleForRobots
&& $node->parentIsVisibleForRobots
&& $node->visibleForXML
&& $node->isInternal
&& trim($node->fullLink) != ''
&& $node->hasCompatibleLanguage();
if ($display && !empty($node->images)) {
echo '<url>';
echo sprintf('<loc><![CDATA[%s]]></loc>', $node->fullLink);
foreach ($node->images as $image) {
if (!empty($image->src)) {
echo '<image:image>';
echo '<image:loc><![CDATA[' . $image->src . ']]></image:loc>';
echo empty($image->title)
? '<image:title/>'
: '<image:title><![CDATA[' . $image->title . ']]></image:title>';
if (!empty($image->license)) {
echo '<image:license><![CDATA[' . $image->license . ']]></image:license>';
}
echo '</image:image>';
}
}
echo '</url>';
}
/*
* Return true if there were no images
* so any child nodes will get checked
*/
return $display || empty($node->images);
};
echo $this->addStylesheet();
$attributes = [
'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
'xmlns:image' => 'http://www.google.com/schemas/sitemap-image/1.1'
];
echo sprintf('<urlset %s>', ArrayHelper::toString($attributes));
$this->sitemap->traverse($printNodeCallback);
echo '</urlset>';

View File

@ -0,0 +1,98 @@
<?php
/**
* @package OSMap
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2007-2014 XMap - Joomla! Vargas - Guillermo Vargas. All rights reserved.
* @copyright 2016-2024 Joomlashack.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSMap.
*
* OSMap is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSMap. If not, see <https://www.gnu.org/licenses/>.
*/
use Alledia\OSMap\Sitemap\Item;
use Joomla\CMS\Language\Language;
use Joomla\Utilities\ArrayHelper;
defined('_JEXEC') or die();
/**
* @var OSMapViewXml $this
* @var string $template
* @var string $layout
* @var string $layoutTemplate
* @var Language $lang
* @var string $filetofind
*/
$debug = $this->params->get('debug', 0) ? "\n" : '';
$printNodeCallback = function (Item $node) {
$display = !$node->ignore
&& $node->published
&& (!$node->duplicate || !$this->osmapParams->get('ignore_duplicated_uids', 1))
&& isset($node->newsItem)
&& !empty($node->newsItem)
&& $node->visibleForRobots
&& $node->parentIsVisibleForRobots
&& $node->visibleForXML
&& $node->isInternal
&& trim($node->fullLink) != ''
&& $node->hasCompatibleLanguage();
/** @var DateTime $publicationDate */
$publicationDate = $this->isNewsPublication($node);
if ($display && $publicationDate) {
echo '<url>';
echo sprintf('<loc><![CDATA[%s]]></loc>', $node->fullLink);
echo '<news:news>';
echo '<news:publication>';
echo ($publicationName = $this->params->get('news_publication_name', ''))
? '<news:name><![CDATA[' . $publicationName . ']]></news:name>'
: '<news:name/>';
if (empty($node->language) || $node->language == '*') {
$node->language = $this->language;
}
echo '<news:language>' . $node->language . '</news:language>';
echo '</news:publication>';
echo '<news:publication_date>' . $publicationDate->format('Y-m-d\TH:i:s\Z') . '</news:publication_date>';
echo '<news:title><![CDATA[' . $node->name . ']]></news:title>';
if (!empty($node->keywords)) {
echo '<news:keywords><![CDATA[' . $node->keywords . ']]></news:keywords>';
}
echo '</news:news>';
echo '</url>';
}
return $display;
};
echo $this->addStylesheet();
$attribs = [
'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
'xmlns:news' => 'http://www.google.com/schemas/sitemap-news/0.9'
];
echo sprintf($debug . '<urlset %s>' . $debug, ArrayHelper::toString($attribs));
$this->sitemap->traverse($printNodeCallback);
echo '</urlset>';

View File

@ -0,0 +1,90 @@
<?php
/**
* @package OSMap
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2007-2014 XMap - Joomla! Vargas - Guillermo Vargas. All rights reserved.
* @copyright 2016-2024 Joomlashack.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSMap.
*
* OSMap is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSMap. If not, see <https://www.gnu.org/licenses/>.
*/
use Alledia\OSMap\Helper\General;
use Alledia\OSMap\Sitemap\Item;
use Joomla\CMS\Language\Language;
defined('_JEXEC') or die();
/**
* @var OSMapViewXml $this
* @var string $template
* @var string $layout
* @var string $layoutTemplate
* @var Language $lang
* @var string $filetofind
*/
$showExternalLinks = (int)$this->osmapParams->get('show_external_links', 0);
$ignoreDuplicates = (int)$this->osmapParams->get('ignore_duplicated_uids', 1);
$debug = $this->params->get('debug', 0) ? "\n" : '';
$printNodeCallback = function (Item $node) use ($showExternalLinks, $ignoreDuplicates, $debug) {
$display = !$node->ignore
&& $node->published
&& (!$node->duplicate || !$ignoreDuplicates)
&& $node->visibleForRobots
&& $node->parentIsVisibleForRobots
&& $node->visibleForXML
&& trim($node->fullLink) != '';
if ($display && !$node->isInternal) {
// Show external links
$display = $showExternalLinks === 1;
}
if (!$node->hasCompatibleLanguage()) {
$display = false;
}
if (!$display) {
return false;
}
echo $debug;
echo '<url>';
echo '<loc><![CDATA[' . $node->fullLink . ']]></loc>';
if (!General::isEmptyDate($node->modified)) {
echo '<lastmod>' . $node->modified . '</lastmod>';
}
echo '<changefreq>' . $node->changefreq . '</changefreq>';
echo '<priority>' . $node->priority . '</priority>';
echo '</url>';
echo $debug;
return true;
};
echo $this->addStylesheet();
echo $debug . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . $debug;
$this->sitemap->traverse($printNodeCallback);
echo '</urlset>';

View File

@ -0,0 +1,31 @@
<?php
/**
* @package OSMap
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2007-2014 XMap - Joomla! Vargas - Guillermo Vargas. All rights reserved.
* @copyright 2016-2024 Joomlashack.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSMap.
*
* OSMap is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSMap. If not, see <https://www.gnu.org/licenses/>.
*/
defined('_JEXEC') or die();
/*
* Having a view.html.php file allows adding a .xml suffix to
* the url, if the sitemap is attached to a menu entry
*/
require_once __DIR__ . '/view.xml.php';

View File

@ -0,0 +1,187 @@
<?php
/**
* @package OSMap
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2007-2014 XMap - Joomla! Vargas - Guillermo Vargas. All rights reserved.
* @copyright 2016-2024 Joomlashack.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSMap.
*
* OSMap is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSMap. If not, see <https://www.gnu.org/licenses/>.
*/
use Alledia\OSMap\Factory;
use Alledia\OSMap\Helper\General;
use Alledia\OSMap\Sitemap\Item;
use Alledia\OSMap\Sitemap\Standard;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
defined('_JEXEC') or die();
// phpcs:enable PSR1.Files.SideEffects
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
class OsmapViewXml extends HtmlView
{
/**
* @var SiteApplication
*/
protected $app = null;
/**
* @var string
*/
protected $type = null;
/**
* @var Registry
*/
protected $params = null;
/**
* @var Registry
*/
protected $osmapParams = null;
/**
* @var Standard
*/
protected $sitemap = null;
/**
* @var string
*/
protected $language = null;
/**
* @var DateTime
*/
protected $newsCutoff = null;
/**
* @var int
*/
protected $newsLimit = 1000;
/**
* @inheritDoc
* @throws Exception
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->app = Factory::getApplication();
}
/**
* @inheritDoc
*/
public function display($tpl = null)
{
$document = $this->app->getDocument();
if ($document->getType() != 'xml') {
// There are ways to get here with a non-xml document, so we have to redirect
$uri = Uri::getInstance();
$uri->setVar('format', 'xml');
$this->app->redirect($uri);
// Not strictly necessary, but makes the point :)
return;
}
$this->type = General::getSitemapTypeFromInput();
$this->sitemap = Factory::getSitemap($this->app->input->getInt('id'), $this->type);
if (!$this->sitemap->isPublished) {
throw new Exception(Text::_('COM_OSMAP_MSG_SITEMAP_IS_UNPUBLISHED'), 404);
}
$this->params = $this->app->getParams();
$this->osmapParams = ComponentHelper::getParams('com_osmap');
$this->language = $document->getLanguage();
$this->newsCutoff = new DateTime('-' . $this->sitemap->newsDateLimit . ' days');
if ($this->params->get('debug', 0)) {
$document->setMimeEncoding('text/plain');
}
parent::display($tpl);
}
/**
* @return string
*/
protected function addStylesheet(): string
{
if ($this->params->get('add_styling', 1)) {
$query = [
'option' => 'com_osmap',
'view' => 'xsl',
'format' => 'xsl',
'layout' => $this->type,
'id' => $this->sitemap->id,
];
if ($itemId = $this->app->input->getInt('Itemid')) {
$query['Itemid'] = $itemId;
}
return sprintf(
'<?xml-stylesheet type="text/xsl" href="%s"?>',
Route::_('index.php?' . http_build_query($query))
);
}
return '';
}
/**
* @param Item $node
*
* @return ?DateTime
*/
protected function isNewsPublication(Item $node): ?DateTime
{
try {
$publicationDate = (
!empty($node->publishUp)
&& $node->publishUp != Factory::getDbo()->getNullDate()
&& $node->publishUp != -1
) ? $node->publishUp : null;
if ($publicationDate) {
$publicationDate = new DateTime($publicationDate);
if ($this->newsCutoff <= $publicationDate) {
$this->newsLimit--;
if ($this->newsLimit >= 0) {
return $publicationDate;
}
}
}
} catch (Throwable $error) {
// Don't care
}
return null;
}
}