Skip to content

Commit

Permalink
v.1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytolkachyov authored Feb 16, 2022
1 parent 1bd0f92 commit 2d9c372
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 0 deletions.
108 changes: 108 additions & 0 deletions fields/plugininfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/**
* @package WebTolk plugin info field
* @version 1.0.0
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2020 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-2.0.html
* @since 1.0.0
*/

defined('_JEXEC') or die;

use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Language\Text;
use \Joomla\CMS\Factory;
use Joomla\Registry\Registry;
FormHelper::loadFieldClass('spacer');

class JFormFieldPlugininfo extends JFormFieldSpacer
{

protected $type = 'plugininfo';

/**
* Method to get the field input markup for a spacer.
* The spacer does not have accept input.
*
* @return string The field input markup.
*
* @since 1.7.0
*/
protected function getInput()
{
return ' ';
}

/**
* @return string The field label markup.
*
* @since 1.7.0
*/
protected function getLabel()
{
$data = $this->form->getData();
$element = $data->get('element');
$folder = $data->get('folder');


$doc = Factory::getDocument();
$doc->addStyleDeclaration("
.wt-b24-plugin-info{
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
padding:1rem;
margin-bottom: 2rem;
display:flex;
}
.plugin-info-img{
margin-right:auto;
max-width: 100%;
}
.plugin-info-img svg:hover * {
cursor:pointer;
}
");

$wt_plugin_info = simplexml_load_file(JPATH_SITE."/plugins/".$folder."/".$element."/".$element.".xml");



?>
<div class="wt-b24-plugin-info">
<div class="plugin-info-img span2">
<a href="https://web-tolk.ru" target="_blank">
<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Go to https://web-tolk.ru</title>
<text font-weight="bold" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="32" id="svg_3" y="36.085949" x="8.152073" stroke-opacity="null" stroke-width="0" stroke="#000" fill="#0fa2e6">Web</text>
<text font-weight="bold" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="32" id="svg_4" y="36.081862" x="74.239105" stroke-opacity="null" stroke-width="0" stroke="#000" fill="#384148">Tolk</text>
</g>
</svg>
</a>
</div>
<div style="padding: 0px 15px;" class="span10">
<span class="label label-success">v.<?php echo $wt_plugin_info->version; ?></span>
<?php echo Text::_("PLG_".strtoupper($element)."_DESC"); ?>
</div>
</div>
<?php

}

/**
* Method to get the field title.
*
* @return string The field title.
*
* @since 1.7.0
*/
protected function getTitle()
{
return $this->getLabel();
}

}
?>
7 changes: 7 additions & 0 deletions language/en-GB/en-GB.plg_jlsitemap_phocagallery.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PLG_JLSITEMAP_PHOCAGALLERY = "JLSitemap - Phoca Gallery"
PLG_PHOCAGALLERY_DESC = "Data plugin-provider for image gallery component <a href=\"https://www.phoca.cz/phocagallery\" target=\"_blank\">Phoca Gallery</a> and XML sitemap component <a href=\"https://joomline.org/extensions/component-for-joomla/jlsitemap.html\" target=\"_blank\">JL Sitemap</a>"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_CATEGORIES = "Categories"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_CHANGEFREQ = "Change Frequency"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_PRIORITY = "Priority"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_IMAGES="XML sitemap for images"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_IMAGES_DESC="Not only links to image categories will be added to the sitemap, but also the images themselves. According to <a href=\"https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps \" target=\"_blank\">Google documentation</a> no more than 1000 images can be specified for each link"
2 changes: 2 additions & 0 deletions language/en-GB/en-GB.plg_jlsitemap_phocagallery.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLG_JLSITEMAP_PHOCAGALLERY="JLSitemap - Phoca Gallery"
PLG_PHOCAGALLERY_DESC="Data plugin-provider for image gallery component <a href=\"https://www.phoca.cz/phocagallery\" target=\"_blank\">Phoca Gallery</a> and XML sitemap component <a href=\"https://joomline.org/extensions/component-for-joomla/jlsitemap.html\" target=\"_blank\">JL Sitemap</a>"
6 changes: 6 additions & 0 deletions language/ru-RU/ru-RU.plg_jlsitemap_phocagallery.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PLG_JLSITEMAP_PHOCAGALLERY="JLSitemap - Phoca Gallery"
PLG_PHOCAGALLERY_DESC="Плагин-провайдер данных <a href=\"https://www.phoca.cz/phocagallery\" target=\"_blank\">Phoca Gallery</a> для компонента карты сайта <a href=\"https://joomline.ru/rasshirenija/komponenty/jlsitemap.html\" target=\"_blank\">JL Sitemap</a>"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_CHANGEFREQ="Частота изменений"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_PRIORITY = "Приоритет"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_IMAGES="XML-карта сайта для изображений"
PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_IMAGES_DESC="В карту сайта будут добавляться не только ссылки на категории изображений, но и сами изображения. Согласно <a href=\"https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps\" target=\"_blank\">документации Google</a> для каждой ссылки можно указывать не более 1000 изображений"
2 changes: 2 additions & 0 deletions language/ru-RU/ru-RU.plg_jlsitemap_phocagallery.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLG_JLSITEMAP_PHOCAGALLERY="JLSitemap - Phoca Gallery"
PLG_PHOCAGALLERY_DESC="Плагин-провайдер данных <a href=\"https://www.phoca.cz/phocagallery\" target=\"_blank\">Phoca Gallery</a> для компонента карты сайта <a href=\"https://joomline.ru/rasshirenija/komponenty/jlsitemap.html\" target=\"_blank\">JL Sitemap</a>"
176 changes: 176 additions & 0 deletions phocagallery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php
/**
* @package JLSitemap - Phoca Gallery Plugin
* @version 1.0.0
* @author Sergey Tolkachyov - web-tolk.ru
* @copyright Copyright (c) 2022 Sergey Tolkachyov. All rights reserved.
* @license GNU General Public License v3.0
* @link https://web-tolk.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 plgJLSitemapPhocagallery extends CMSPlugin
{
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
*
* @since 1.0.0
*/
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 1.0.0
*/
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');


$db = Factory::getDbo();

$query = 'SELECT *'
. ' FROM #__phocagallery_categories AS a'
. ' WHERE a.published = 1'
. ' ORDER BY a.ordering';
$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();

JLoader::register('PhocaGalleryLoader', JPATH_ADMINISTRATOR . '/components/com_phocagallery/libraries/loader.php');
JLoader::register('PhocaGalleryAccess', JPATH_ADMINISTRATOR . '/components/com_phocagallery/libraries/phocagallery/access/access.php');
JLoader::register('PhocaGalleryImageFront', JPATH_ADMINISTRATOR . '/components/com_phocagallery/libraries/phocagallery/image/imagefront.php');

foreach ($rows as $row)
{
// Prepare loc attribute
$loc = 'index.php?option=com_phocagallery&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->date) && $row->date != $nullDate) ? $row->date : 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)
{

if (!empty($row->id))
{
$category_images = PhocaGalleryImageFront::getCategoryImages($row->id); //массив объектов
/**
* @link https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps
* no more than 1000 images
*/
$images_xml = [];
if (0 < count($category_images) && count($category_images) <= 1000)
{// no more than 1000 images
foreach ($category_images as $image)
{
$images_xml[] = JUri::root() . 'images/phocagallery/' . $image->filename;
}
}
$category->images = $images_xml;

}
}

// 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);


return $urls;
}
}
65 changes: 65 additions & 0 deletions phocagallery.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="jlsitemap" method="upgrade">
<name>PLG_JLSITEMAP_PHOCAGALLERY</name>
<author>Sergey Tolkachyov</author>
<creationDate>04.02.2022</creationDate>
<copyright>Copyright (c) 2022 Sergey Tolkachyov. All rights reserved.</copyright>
<license>GNU General Public License v3.0</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://web-tolk.ru</authorUrl>
<version>1.0.0</version>
<description>PLG_PHOCAGALLERY_DESC</description>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_jlsitemap_phocagallery.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_jlsitemap_phocagallery.sys.ini</language>
<language tag="ru-RU">ru-RU/ru-RU.plg_jlsitemap_phocagallery.ini</language>
<language tag="ru-RU">ru-RU/ru-RU.plg_jlsitemap_phocagallery.sys.ini</language>
</languages>
<files>
<filename plugin="phocagallery">phocagallery.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field addfieldpath="plugins/jlsitemap/phocagallery/fields" type="plugininfo" name="plugininfo"/>
<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 type="note" label="PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_IMAGES" description="PLG_JLSITEMAP_PHOCAGALLERY_PARAMS_IMAGES_DESC" showon="categories_images_enable:1" class="alert alert-info"/>
<field name="categories_changefreq" type="list" default="weekly"
label="PLG_JLSITEMAP_PHOCAGALLERY_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_PHOCAGALLERY_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>
<updateservers>
<server type="extension" name="WebTolkUpdateServer">https://web-tolk.ru/component/swjprojects/jupdate.html?element=jl_sitemap_phocagallery</server>
</updateservers>
</extension>

0 comments on commit 2d9c372

Please sign in to comment.