-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
132 lines (111 loc) · 4.35 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
<?php
/**
* @version $Id: mod_jdownloads_latest.php v3.8
* @package mod_jdownloads_latest
* @copyright (C) 2018 Arno Betz
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author Arno Betz http://www.jDownloads.com
*
*
* This modul shows you the most recent downloads from the jDownloads component.
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once JPATH_SITE . '/components/com_jdownloads/helpers/route.php';
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_jdownloads/models', 'jdownloadsModel');
class modJdownloadsTopHelper
{
static function getList($params)
{
$db = JFactory::getDbo();
// Get an instance of the generic downloads model
$model = JModelLegacy::getInstance ('downloads', 'jdownloadsModel', array('ignore_request' => true));
// Set application parameters in model
$app = JFactory::getApplication();
$appParams = $app->getParams('com_jdownloads');
$model->setState('params', $appParams);
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', (int) $params->get('sum_view', 5));
$model->setState('filter.published', 1);
$model->setState('filter.access', true);
$model->setState('filter.user_access', true);
$access = true;
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
// Category filter
$catid = $params->get('catid', array());
if (empty($catid)){
$model->setState('filter.category_id', '');
} else {
$model->setState('filter.category_id', $catid);
}
// User filter
$userId = JFactory::getUser()->get('id');
// Filter by language
$model->setState('filter.language', $app->getLanguageFilter());
// Set sort ordering
$ordering = 'a.downloads';
$dir = 'DESC';
$model->setState('list.ordering', $ordering);
$model->setState('list.direction', $dir);
$items = $model->getItems();
foreach ($items as &$item)
{
$item->slug = $item->id . ':' . $item->alias;
$item->catslug = $item->catid . ':' . $item->category_alias;
if ($access || in_array($item->access, $authorised))
{
// We know that user has the privilege to view the download
$item->link = '-';
} else {
$item->link = JRoute::_('index.php?option=com_users&view=login');
}
}
return $items;
}
/**
* remove the language tag from a given text and return only the text
*
* @param string $msg
*/
public static function getOnlyLanguageSubstring($msg)
{
// Get the current locale language tag
$lang = JFactory::getLanguage();
$lang_key = $lang->getTag();
// remove the language tag from the text
$startpos = strpos($msg, '{'.$lang_key.'}') + strlen( $lang_key) + 2 ;
$endpos = strpos($msg, '{/'.$lang_key.'}') ;
if ($startpos !== false && $endpos !== false){
return substr($msg, $startpos, ($endpos - $startpos ));
} else {
return $msg;
}
}
/**
* Converts a string into Float while taking the given or locale number format into account
* Used as default the defined separator characters from the Joomla main language ini file (as example: en-GB.ini)
*
* @param mixed $str
* @param mixed $dec_point
* @param mixed $thousands_sep
* @param mixed $decimals
* @return mixed
*/
public static function strToNumber( $str, $dec_point=null, $thousands_sep=null, $decimals = 0 )
{
if( is_null($dec_point) || is_null($thousands_sep) ) {
if( is_null($dec_point) ) {
$dec_point = JText::_('DECIMALS_SEPARATOR');
}
if( is_null($thousands_sep) ) {
$thousands_sep = JText::_('THOUSANDS_SEPARATOR');
}
}
// in this case use we as default the en-GB format
if (!$dec_point) $dec_point = '.';
if (!$thousands_sep) $thousands_sep = ',';
$number = number_format($str, $decimals, $dec_point, $thousands_sep);
return $number;
}
}
?>