first commit
This commit is contained in:
309
plugins/jlsitemap/content/content.php
Normal file
309
plugins/jlsitemap/content/content.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* @package JLSitemap - Content Plugin
|
||||
* @version 1.12.0
|
||||
* @author Joomline - joomline.ru
|
||||
* @copyright Copyright (c) 2010 - 2022 Joomline. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
* @link https://joomline.ru/
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
class plgJLSitemapContent extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Affects constructor behavior. If true, language files will be loaded automatically.
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Method to get urls array
|
||||
*
|
||||
* @param array $urls Urls array
|
||||
* @param Registry $config Component config
|
||||
*
|
||||
* @return array Urls array with attributes
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public function onGetUrls(&$urls, $config)
|
||||
{
|
||||
$categoryExcludeStates = array(
|
||||
0 => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY_UNPUBLISH'),
|
||||
-2 => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY_TRASH'),
|
||||
2 => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY_ARCHIVE'));
|
||||
|
||||
$articleExcludeStates = array(
|
||||
0 => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_UNPUBLISH'),
|
||||
-2 => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_TRASH'),
|
||||
2 => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_ARCHIVE'));
|
||||
|
||||
$multilanguage = $config->get('multilanguage');
|
||||
|
||||
// Categories
|
||||
if ($this->params->get('categories_enable', false))
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select(array('c.id', 'c.title', 'c.published', 'c.access', 'c.metadata', 'c.language', 'MAX(a.modified) as modified', 'c.params'))
|
||||
->from($db->quoteName('#__categories', 'c'))
|
||||
->join('LEFT', '#__content AS a ON a.catid = c.id')
|
||||
->where($db->quoteName('c.extension') . ' = ' . $db->quote('com_content'))
|
||||
->group('c.id')
|
||||
->order($db->escape('c.lft') . ' ' . $db->escape('asc'));
|
||||
|
||||
// Join over associations
|
||||
if ($multilanguage)
|
||||
{
|
||||
$query->select('assoc.key as association')
|
||||
->join('LEFT', '#__associations AS assoc ON assoc.id = c.id AND assoc.context = ' .
|
||||
$db->quote('com_categories.item'));
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadObjectList();
|
||||
|
||||
$nullDate = $db->getNullDate();
|
||||
$changefreq = $this->params->get('categories_changefreq', $config->get('changefreq', 'weekly'));
|
||||
$priority = $this->params->get('categories_priority', $config->get('priority', '0.5'));
|
||||
|
||||
$categories_images_enable = $this->params->get('categories_images_enable', 1);
|
||||
|
||||
// Add categories to arrays
|
||||
$categories = array();
|
||||
$alternates = array();
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
// Prepare loc attribute
|
||||
$loc = 'index.php?option=com_content&view=category&id=' . $row->id;
|
||||
if (!empty($row->language) && $row->language !== '*' && $multilanguage)
|
||||
{
|
||||
$loc .= '&lang=' . $row->language;
|
||||
}
|
||||
|
||||
// Prepare exclude attribute
|
||||
$metadata = new Registry($row->metadata);
|
||||
$exclude = array();
|
||||
if (preg_match('/noindex/', $metadata->get('robots', $config->get('siteRobots'))))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY_ROBOTS'));
|
||||
}
|
||||
|
||||
if (isset($categoryExcludeStates[$row->published]))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY'),
|
||||
'msg' => $categoryExcludeStates[$row->published]);
|
||||
}
|
||||
|
||||
if (!in_array($row->access, $config->get('guestAccess', array())))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY_ACCESS'));
|
||||
}
|
||||
|
||||
// Prepare lastmod attribute
|
||||
$lastmod = (!empty($row->modified) && $row->modified != $nullDate) ? $row->modified : false;
|
||||
|
||||
// Prepare category object
|
||||
$category = new stdClass();
|
||||
$category->type = Text::_('PLG_JLSITEMAP_CONTENT_TYPES_CATEGORY');
|
||||
$category->title = $row->title;
|
||||
$category->loc = $loc;
|
||||
$category->changefreq = $changefreq;
|
||||
$category->priority = $priority;
|
||||
$category->lastmod = $lastmod;
|
||||
$category->exclude = (!empty($exclude)) ? $exclude : false;
|
||||
$category->alternates = ($multilanguage && !empty($row->association)) ? $row->association : false;
|
||||
|
||||
if ($categories_images_enable)
|
||||
{
|
||||
$category_params = json_decode($row->params);
|
||||
if (is_object($category_params) && !empty($category_params->image))
|
||||
{
|
||||
$category->images = array(Uri::root() . $category_params->image);
|
||||
}
|
||||
}
|
||||
|
||||
// Add category to array
|
||||
$categories[] = $category;
|
||||
|
||||
// Add category to alternates array
|
||||
if ($multilanguage && !empty($row->association) && empty($exclude))
|
||||
{
|
||||
if (!isset($alternates[$row->association]))
|
||||
{
|
||||
$alternates[$row->association] = array();
|
||||
}
|
||||
|
||||
$alternates[$row->association][$row->language] = $loc;
|
||||
};
|
||||
}
|
||||
|
||||
// Add alternates to categories
|
||||
if (!empty($alternates))
|
||||
{
|
||||
foreach ($categories as &$category)
|
||||
{
|
||||
$category->alternates = ($category->alternates) ? $alternates[$category->alternates] : false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add categories to urls
|
||||
$urls = array_merge($urls, $categories);
|
||||
}
|
||||
|
||||
// Articles
|
||||
if ($this->params->get('articles_enable', false))
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select(array('a.id', 'a.title', 'a.alias', 'a.state', 'a.modified', 'a.publish_up', 'a.publish_down', 'a.access',
|
||||
'a.metadata', 'a.language', 'c.id as category_id', 'c.published as category_published',
|
||||
'c.access as category_access', 'a.images'))
|
||||
->from($db->quoteName('#__content', 'a'))
|
||||
->join('LEFT', '#__categories AS c ON c.id = a.catid')
|
||||
->group('a.id')
|
||||
->order($db->escape('a.ordering') . ' ' . $db->escape('asc'));
|
||||
|
||||
// Join over associations
|
||||
if ($multilanguage)
|
||||
{
|
||||
$query->select('assoc.key as association')
|
||||
->join('LEFT', '#__associations AS assoc ON assoc.id = a.id AND assoc.context = ' .
|
||||
$db->quote('com_content.item'));
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadObjectList();
|
||||
|
||||
$nullDate = $db->getNullDate();
|
||||
$nowDate = Factory::getDate()->toUnix();
|
||||
$changefreq = $this->params->get('articles_changefreq', $config->get('changefreq', 'weekly'));
|
||||
$priority = $this->params->get('articles_priority', $config->get('priority', '0.5'));
|
||||
|
||||
$articles_images_enable = $this->params->get('articles_images_enable', 1);
|
||||
|
||||
// Add articles to urls arrays
|
||||
$articles = array();
|
||||
$alternates = array();
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
// Prepare loc attribute
|
||||
$slug = ($row->alias) ? ($row->id . ':' . $row->alias) : $row->id;
|
||||
$loc = 'index.php?option=com_content&view=article&id=' . $slug . '&catid=' . $row->category_id;
|
||||
if (!empty($row->language) && $row->language !== '*' && $multilanguage)
|
||||
{
|
||||
$loc .= '&lang=' . $row->language;
|
||||
}
|
||||
|
||||
// Prepare exclude attribute
|
||||
$metadata = new Registry($row->metadata);
|
||||
$exclude = array();
|
||||
if (preg_match('/noindex/', $metadata->get('robots', $config->get('siteRobots'))))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_ROBOTS'));
|
||||
}
|
||||
|
||||
if (isset($articleExcludeStates[$row->state]))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE'),
|
||||
'msg' => $articleExcludeStates[$row->state]);
|
||||
}
|
||||
|
||||
if ($row->publish_up == $nullDate || Factory::getDate($row->publish_up)->toUnix() > $nowDate)
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_PUBLISH_UP'));
|
||||
}
|
||||
|
||||
if ($row->publish_down != $nullDate && Factory::getDate($row->publish_down)->toUnix() < $nowDate)
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_PUBLISH_DOWN'));
|
||||
}
|
||||
|
||||
if (!in_array($row->access, $config->get('guestAccess', array())))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_ARTICLE_ACCESS'));
|
||||
}
|
||||
|
||||
if (isset($categoryExcludeStates[$row->category_published]))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY'),
|
||||
'msg' => $categoryExcludeStates[$row->category_published]);
|
||||
}
|
||||
|
||||
if (!in_array($row->category_access, $config->get('guestAccess', array())))
|
||||
{
|
||||
$exclude[] = array('type' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY'),
|
||||
'msg' => Text::_('PLG_JLSITEMAP_CONTENT_EXCLUDE_CATEGORY_ACCESS'));
|
||||
}
|
||||
|
||||
// Prepare lastmod attribute
|
||||
$lastmod = (!empty($row->modified) && $row->modified != $nullDate) ? $row->modified : false;
|
||||
|
||||
// Prepare article object
|
||||
$article = new stdClass();
|
||||
$article->type = Text::_('PLG_JLSITEMAP_CONTENT_TYPES_ARTICLE');
|
||||
$article->title = $row->title;
|
||||
$article->loc = $loc;
|
||||
$article->changefreq = $changefreq;
|
||||
$article->priority = $priority;
|
||||
$article->lastmod = $lastmod;
|
||||
$article->exclude = (!empty($exclude)) ? $exclude : false;
|
||||
$article->alternates = ($multilanguage && !empty($row->association)) ? $row->association : false;
|
||||
|
||||
if ($articles_images_enable)
|
||||
{
|
||||
$article_images = json_decode($row->images);
|
||||
if (is_object($article_images) && !empty($article_images->image_fulltext))
|
||||
{
|
||||
$article->images = array(Uri::root() . $article_images->image_fulltext);
|
||||
}
|
||||
}
|
||||
|
||||
// Add article to array
|
||||
$articles[] = $article;
|
||||
|
||||
// Add article to alternates array
|
||||
if ($multilanguage && !empty($row->association) && empty($exclude))
|
||||
{
|
||||
if (!isset($alternates[$row->association]))
|
||||
{
|
||||
$alternates[$row->association] = array();
|
||||
}
|
||||
|
||||
$alternates[$row->association][$row->language] = $loc;
|
||||
};
|
||||
}
|
||||
|
||||
// Add alternates to articles
|
||||
if (!empty($alternates))
|
||||
{
|
||||
foreach ($articles as &$article)
|
||||
{
|
||||
$article->alternates = ($article->alternates) ? $alternates[$article->alternates] : false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add articles to urls
|
||||
$urls = array_merge($urls, $articles);
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
}
|
||||
109
plugins/jlsitemap/content/content.xml
Normal file
109
plugins/jlsitemap/content/content.xml
Normal file
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.9" type="plugin" group="jlsitemap" method="upgrade">
|
||||
<name>PLG_JLSITEMAP_CONTENT</name>
|
||||
<author>Joomline</author>
|
||||
<creationDate>13.04.2022</creationDate>
|
||||
<copyright>Copyright (c) 2010 - 2022 Joomline. All rights reserved.</copyright>
|
||||
<license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
|
||||
<authorEmail>sale@joomline.ru</authorEmail>
|
||||
<authorUrl>https://joomline.ru/</authorUrl>
|
||||
<version>1.12.0</version>
|
||||
<description>PLG_JLSITEMAP_CONTENT_DESCRIPTION</description>
|
||||
<languages folder="language">
|
||||
<language tag="en-GB">en-GB/en-GB.plg_jlsitemap_content.ini</language>
|
||||
<language tag="en-GB">en-GB/en-GB.plg_jlsitemap_content.sys.ini</language>
|
||||
<language tag="ru-RU">ru-RU/ru-RU.plg_jlsitemap_content.ini</language>
|
||||
<language tag="ru-RU">ru-RU/ru-RU.plg_jlsitemap_content.sys.ini</language>
|
||||
</languages>
|
||||
<files>
|
||||
<filename plugin="content">content.php</filename>
|
||||
</files>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="articles" label="PLG_JLSITEMAP_CONTENT_PARAMS_ARTICLES">
|
||||
<field name="articles_enable" type="radio"
|
||||
label="PLG_JLSITEMAP_CONTENT_PARAMS_ENABLE"
|
||||
default="1"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="articles_images_enable" type="radio"
|
||||
label="JGLOBAL_FIELDSET_IMAGE_OPTIONS"
|
||||
default="1"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="articles_changefreq" type="list" default="weekly"
|
||||
label="PLG_JLSITEMAP_CONTENT_PARAMS_CHANGEFREQ"
|
||||
showon="articles_enable:1">
|
||||
<option value="always">always</option>
|
||||
<option value="hourly">hourly</option>
|
||||
<option value="daily">daily</option>
|
||||
<option value="weekly">weekly</option>
|
||||
<option value="monthly">monthly</option>
|
||||
<option value="yearly">yearly</option>
|
||||
<option value="never">never</option>
|
||||
</field>
|
||||
<field name="articles_priority" type="list"
|
||||
default="0.5" label="PLG_JLSITEMAP_CONTENT_PARAMS_PRIORITY"
|
||||
showon="articles_enable:1">
|
||||
<option value="0.0">0.0</option>
|
||||
<option value="0.1">0.1</option>
|
||||
<option value="0.2">0.2</option>
|
||||
<option value="0.3">0.3</option>
|
||||
<option value="0.4">0.4</option>
|
||||
<option value="0.5">0.5</option>
|
||||
<option value="0.6">0.6</option>
|
||||
<option value="0.7">0.7</option>
|
||||
<option value="0.8">0.8</option>
|
||||
<option value="0.9">0.9</option>
|
||||
<option value="1">1</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fieldset name="categories" label="PLG_JLSITEMAP_CONTENT_PARAMS_CATEGORIES">
|
||||
<field name="categories_enable" type="radio"
|
||||
label="PLG_JLSITEMAP_CONTENT_PARAMS_ENABLE"
|
||||
default="1"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="categories_images_enable" type="radio"
|
||||
label="JGLOBAL_FIELDSET_IMAGE_OPTIONS"
|
||||
default="1"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="categories_changefreq" type="list" default="weekly"
|
||||
label="PLG_JLSITEMAP_CONTENT_PARAMS_CHANGEFREQ"
|
||||
showon="categories_enable:1">
|
||||
<option value="always">always</option>
|
||||
<option value="hourly">hourly</option>
|
||||
<option value="daily">daily</option>
|
||||
<option value="weekly">weekly</option>
|
||||
<option value="monthly">monthly</option>
|
||||
<option value="yearly">yearly</option>
|
||||
<option value="never">never</option>
|
||||
</field>
|
||||
<field name="categories_priority" type="list"
|
||||
default="0.5" label="PLG_JLSITEMAP_CONTENT_PARAMS_PRIORITY"
|
||||
showon="categories_enable:1">
|
||||
<option value="0.0">0.0</option>
|
||||
<option value="0.1">0.1</option>
|
||||
<option value="0.2">0.2</option>
|
||||
<option value="0.3">0.3</option>
|
||||
<option value="0.4">0.4</option>
|
||||
<option value="0.5">0.5</option>
|
||||
<option value="0.6">0.6</option>
|
||||
<option value="0.7">0.7</option>
|
||||
<option value="0.8">0.8</option>
|
||||
<option value="0.9">0.9</option>
|
||||
<option value="1">1</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
Reference in New Issue
Block a user