-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.php
executable file
·175 lines (144 loc) · 5.3 KB
/
helper.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* @author JoomShaper http://www.joomshaper.com
* @copyright Copyright (C) 2010 - 2014 JoomShaper
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2
*/
defined('_JEXEC') or die;
require_once (JPATH_SITE.'/components/com_k2/helpers/route.php');
require_once (JPATH_SITE.'/components/com_k2/helpers/utilities.php');
class ModSPK2FeaturedSliderHelper
{
public static function getItems(&$params)
{
jimport('joomla.filesystem.file');
$mainframe = JFactory::getApplication();
$limit = $params->get('itemCount', 5);
$cid = $params->get('category_id', NULL);
$componentParams = JComponentHelper::getParams('com_k2');
$user = JFactory::getUser();
$db = JFactory::getDBO();
$jnow = JFactory::getDate();
$now = $jnow->toSql();
$nullDate = $db->getNullDate();
$query = "SELECT i.*,";
$query .= "c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
$query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid";
$query .= " WHERE i.published = 1 AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND i.trash = 0 AND c.published = 1 AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND c.trash = 0";
$query .= " AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." )";
$query .= " AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )";
if ($params->get('catfilter'))
{
if (!is_null($cid))
{
if (is_array($cid))
{
$itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
$categories = $itemListModel->getCategoryTree($cid);
$sql = @implode(',', $categories);
$query .= " AND i.catid IN ({$sql})";
}
else
{
$itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
$categories = $itemListModel->getCategoryTree($cid);
$sql = @implode(',', $categories);
$query .= " AND i.catid IN ({$sql})";
}
}
}
$query .= " AND i.featured = 1";
$query .= " ORDER BY i.created DESC";
$db->setQuery($query, 0, $limit);
$items = $db->loadObjectList();
$model = K2Model::getInstance('Item', 'K2Model');
if (count($items))
{
foreach ($items as $item)
{
$item->event = new stdClass;
//Clean title
$item->title = JFilterOutput::ampReplace($item->title);
//Images
$date = JFactory::getDate($item->modified);
$timestamp = '?t='.$date->toUnix();
if (JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg'))
{
$item->imageXSmall = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
if ($componentParams->get('imageTimestamp'))
{
$item->imageXSmall .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg'))
{
$item->imageSmall = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
if ($componentParams->get('imageTimestamp'))
{
$item->imageSmall .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg'))
{
$item->imageMedium = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
if ($componentParams->get('imageTimestamp'))
{
$item->imageMedium .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg'))
{
$item->imageLarge = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
if ($componentParams->get('imageTimestamp'))
{
$item->imageLarge .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg'))
{
$item->imageXLarge = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
if ($componentParams->get('imageTimestamp'))
{
$item->imageXLarge .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg'))
{
$item->imageGeneric = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
if ($componentParams->get('imageTimestamp'))
{
$item->imageGeneric .= $timestamp;
}
}
$image = 'image'.$params->get('itemImgSize', 'Small');
if (isset($item->$image)) {
$item->image = $item->$image;
} else {
$item->image = JURI::base(true) . '/modules/mod_sp_k2_featured_slider/assets/images/no-image.png';
}
//Read more link
$item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias), $item->catid.':'.urlencode($item->categoryalias))));
//Category link
if ($params->get('itemCategory'))
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid.':'.urlencode($item->categoryalias))));
// Introtext
$item->text = '';
if ($params->get('itemIntroText'))
{
// Word limit
if ($params->get('itemIntroTextWordLimit'))
{
$item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
}
else
{
$item->text .= $item->introtext;
}
}
$item->introtext = $item->text;
$rows[] = $item;
}
return $rows;
}
}
}