-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdd_jugbanner.php
138 lines (112 loc) · 2.7 KB
/
dd_jugbanner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @package JUG.Banner
*
* @author HR-IT-Solutions Florian Häusler <[email protected]>
* @copyright Copyright (C) 2019 HR-IT-Solutions GmbH
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
*/
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Factory;
use Joomla\CMS\Cache\Cache;
/**
* JUG.Banner Plugin
*
* @since 1.0
*/
class PlgAJAXDD_JUGbanner extends JPlugin
{
/**
* @var
*/
protected $app;
/**
* @var string
*/
protected static $hash = 'sha512';
/**
* onAjaxBannerList.
*
*/
public function onAjaxBannerList()
{
$cacheDataId = 'ajaxjugbanner';
$options = array(
'defaultgroup' => $cacheDataId,
'storage' => Factory::getConfig()->get('cache_handler', ''),
'caching' => true,
'lifetime' => 60,
);
$cache = Cache::getInstance('', $options);
if ($cache->get($cacheDataId) !== false)
{
$data = $cache->get($cacheDataId);
}
else
{
$list = $this->getBannersList($this->params);
$data = $this->generateXML($list);
$cache->store($data, $cacheDataId);
}
echo $data;
}
/**
* onAjaxBannerHash.
*
*/
public function onAjaxBannerHash()
{
$list = $this->getBannersList($this->params);
$xml = $this->generateXML($list);
echo hash(static::$hash, $xml);
}
/**
* Retrieve list of banners
* Adapted from Joomla! mod_banners
*
* @param \Joomla\Registry\Registry &$params plugin parameters
*
* @return mixed
*/
protected function getBannersList(&$params)
{
BaseDatabaseModel::addIncludePath(JPATH_ROOT . '/components/com_banners/models', 'BannersModel');
$model = BaseDatabaseModel::getInstance('Banners', 'BannersModel', array('ignore_request' => true));
$model->setState('filter.category_id', $params->get('catid', array()));
$banners = $model->getItems();
return $banners;
}
/**
* generateXML
*
* @param array $list The com_banners getItems array list
*
* @since 1.0
* @return string
*/
protected function generateXML($list)
{
$xml = new SimpleXmlElement('<banners></banners>');
if (count($list))
{
foreach ($list as $item)
{
$link = new Uri($item->clickurl);
$file = JPATH_ROOT . '/' . $item->params->get('imageurl');
$file = Path::check($file);
if (is_file($file))
{
$banner = $xml->addChild('banner');
$banner->addChild('image', Uri::root() . $item->params->get('imageurl'));
$banner->addChild('link', $link->toString());
$file_content = file_get_contents($file);
$banner->addChild('verify', hash('sha256', hash(static::$hash, $file_content)));
}
}
}
return $xml->asXML();
}
}