HEX
Server: Apache
System: Linux webm002.cluster115.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: centralexf (54246)
PHP: 5.4.45
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/centralexf/www/modules/mod_qcategories/helper.php
<?php
/**
 * QCategories Module
 *
 * @version 1.0.1
 * @package qcategories
 * @author Massimo Giagnoni  ( http://www.latenight-coding.com )
 * @copyright Copyright (C) 2008 Massimo Giagnoni. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die('Restricted access');
require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');

class modQCategoriesHelper {
		
	function getCategories(&$params) {
		$user =& JFactory::getUser();

		$categories = array();
		$section = modQCategoriesHelper::_loadSection($params);
		if(is_object($section) && $section->published && $section->access <= $user->get('aid', 0)) {
			
			$categories = modQCategoriesHelper::_loadCategories($params);
			if($cc=count($categories)) {
				for($i = 0; $i < $cc; $i++) {
					$category =& $categories[$i];
					$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout='.($params->get('layout',0) ? 'default':'blog'));
					if($params->get('show_description',0)) {
						if($params->get('process_plugin',0)) {
							$category->description = JHTML::_('content.prepare', $category->description);
						} else {
							$category->description = preg_replace('#{.*?}#','',$category->description);
						}
						$category->description = modQCategoriesHelper::_limitDescr($category->description,$params);
						if($params->get('strip_tags',1)) {
							$tags = $params->get('allowed_tags','<b><i><strong><em>');
							$tags = str_replace(array(' ',"\n","\r"),'',$tags);
							$category->description = strip_tags($category->description,$tags);
						}
					}
				}
			}
		}
		return $categories;
	}
	function _loadSection(&$params) {
		$where = ' WHERE id = '. (int) $params->get('section_id',0);
			
		$db =& JFactory::getDBO();
		$query = 'SELECT *' .
			' FROM #__sections' .
			$where;
		$db->setQuery($query, 0, 1);
		$section = $db->loadObject();
		return $section;
	}
	function _loadCategories(&$params) {
		global $mainframe;
		
		$user =& JFactory::getUser();
		$noauth	= !$params->get('show_noauth',0);
		$gid = $user->get('aid', 0);
		$now = $mainframe->get('requestTime');
		
		$db =& JFactory::getDBO();
		$nullDate = $db->getNullDate();
		
		switch((int)$params->get('order_by')) {
			case 0:
				$orderby = 'a.title';
				break;
			case 1:
				$orderby = 'a.ordering';
				break;
			case 2:
				$orderby = 'numitems DESC';
				break;
		}
		$xwhere = ' AND a.published = 1';
		$xwhere2 = ' AND b.state = 1' .
		' AND ( b.publish_up = '.$db->Quote($nullDate).' OR b.publish_up <= '.$db->Quote($now).' )' .
		' AND ( b.publish_down = '.$db->Quote($nullDate).' OR b.publish_down >= '.$db->Quote($now).' )';
		if ($noauth) {
			$xwhere2 .= ' AND b.access <= '.(int) $gid;
		}
		
		$empty_sec = null;

		if (!$params->get('show_empty_categories')) {
			$empty_sec = ' HAVING numitems > 0';
		}

		$access_check = null;
		if ($noauth) {
			$access_check = ' AND a.access <= '.(int) $gid;
		}
		$query = 'SELECT a.*, COUNT( b.id ) AS numitems,' .
			' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'.
			' FROM #__categories AS a' .
			' LEFT JOIN #__content AS b ON b.catid = a.id'.
			$xwhere2 .
			' WHERE a.section = '.(int) $params->get('section_id',0).
			$xwhere.
			$access_check .
			' GROUP BY a.id'.$empty_sec .
			' ORDER BY '. $orderby;
		$db->setQuery($query);
		$categories = $db->loadObjectList();
		return $categories;
	}
	function _limitDescr($descr,&$params) {
		$r = $descr;
		
		switch((int)$params->get('cut_description',0)) {
			case 1:
				if(preg_match('#^(<p>|<br />|\s)*(.*?\.)(\s|</p>|<br />|$)#',$r,$m)) {
					$r = $m[2];
				}
				break;
			case 2:
				if(preg_match('#^(<p>|<br />|\s)*(.*?)(</p>|<br /><br />|$)#',$r,$m)) {
					$r = $m[2];
				}
		}
		return $r;
	}
}
?>