0x1998 - MANAGER
Edit File: helper.php
<?php /** * @version $Id: mod_jdownloads_featured.php v3.8 * @package mod_jdownloads_featured * @copyright (C) 2018 Arno Betz * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @author Arno Betz http://www.jDownloads.com */ 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 ModJDownloadsFeaturedHelper { 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.featured', 'only'); // Access filter $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.created'; $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; } } ?>