<?php

/**

* @version		$Id: helper.php 11137 2008-10-15 19:47:01Z kdevine $

* @package		Joomla

* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.

* @license		GNU/GPL, see LICENSE.php

* Joomla! is free software. This version may have been modified pursuant

* to the GNU General Public License, and as distributed it includes or

* is derivative of works licensed under the GNU General Public License or

* other free or open source software licenses.

* See COPYRIGHT.php for copyright notices and details.

*/



// no direct access

defined('_JEXEC') or die('Restricted access');



require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');



class modCategoriaHelper{

	function getList($params){



		global $mainframe;



		$db					=& JFactory::getDBO();

		$user				=& JFactory::getUser();



		$option				= JRequest::getCmd('option');

		$view				= JRequest::getCmd('view');

		$temp				= JRequest::getString('id');



		$temp				= explode(':', $temp);

		$id					= $temp[0];



		$count              = $params->get('cantidad', 5);

		$categoria          = $params->get('categoria');
		$order              = $params->get('order', 'id');
		$desc               = $params->get('desc', 'DESC');



		// CONSULATAS A BD

		$db->setQuery("SELECT * FROM #__content 

					  WHERE catid='".$categoria."' 

					  AND state = '1'

					  ORDER BY ".$order." ".$desc." LIMIT ".$count."");

		$contenidos = $db->loadObjectList();

		

		return $contenidos;

	}



	function cortar_texto($frase_entrada,$cortar){ 



		if (strlen($frase_entrada) > $cortar){ 

			$frase_corta = substr(JFilterOutput::cleanText($frase_entrada),0,$cortar); // obtener la frase cortada. 

			$palabras = split(" ", $frase_corta); // obtener array con las palabras. 

			$total_palabras = count($palabras)-1; // contar total array elementos y restar 1 elementos 

			$palabras = array_splice($palabras,0,$total_palabras); // le quitamos la ultima palabra. 

			$frase_salida = implode(' ',$palabras); //  y concatenamos con el espacio hacia una cadena. 

			$frase_salida .= "..."; // se aņaden los puntos suspensivos a la cadena obtenida.. 

			}else{

				$frase_salida = JFilterOutput::cleanText($frase_entrada);

			}



		return $frase_salida; 

	}



	function get_link($id){

		global $mainframe;

		

		$db				=& JFactory::getDBO();

		$db->setQuery("SELECT * FROM #__content WHERE id=$id");

		$item_aux 		= $db->loadObject();

		

		$params_item	= new JParameter($item_aux->attribs);

				

		$urlExterna 	= $params_item->get('urlExterna');

		$pdf 			= $params_item->get('pdf');

		$urlTarget 		= $params_item->get('urlTarget');

		$urlTipo 		= $params_item->get('urlTipo');

		// IFS

		if($urlTipo != ''){

			switch ($urlTipo) {

				case 0:

					$link = JURI::base()."$pdf";

					break;

				case 1:

					$link = "http://".$urlExterna;

					break;

			}

		}else{

			$link = ContentHelperRoute::getArticleRoute($id, $item_aux->catid, $item_aux->secid);

			$urlTarget = "";

		}

		

		return $link;	

	}

	

	function get_target($id){

		global $mainframe;

		

		$db				=& JFactory::getDBO();

		$db->setQuery("SELECT * FROM #__content WHERE id=$id");

		$item_aux 		= $db->loadObject();

		

		$params_item	= new JParameter($item_aux->attribs);

				

		$urlTarget 		= 'target="'.$params_item->get('urlTarget').'"';

		$urlTipo 		= $params_item->get('urlTipo');

		// IFS

		if($urlTipo != ''){

		}else{

			$urlTarget = "";

		}

		

		return $urlTarget;	

	}



} 