Your IP : 216.73.216.240


Current Path : /home/juvelize/www/modules/mod_lofresponsivecarousel/libs/source/content/
Upload File :
Current File : /home/juvelize/www/modules/mod_lofresponsivecarousel/libs/source/content/source.php

<?php
/**
 * $ModDesc
 * 
 * @version   $Id: $file.php $Revision
 * @package   modules
 * @subpackage  $Subpackage.
 * @copyright Copyright (C) November 2010 LandOfCoder.com <@emai:landofcoder@gmail.com>.All rights reserved.
 * @license   GNU General Public License version 2
 */
 
if( !class_exists("LofContentDataSource") ) {
// no direct access
defined('_JEXEC') or die;
require_once JPATH_SITE.'/components/com_content/helpers/route.php';
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
require_once JPATH_SITE.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_content'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'route.php';
if( !class_exists("LofContentDataSource") ) {
	/**
	 * class LofContentDataSource
	 */
	class LofContentDataSource extends LofDataSourceBase{
		/**
		 * Get instance of LofContentDataSource Object
		 */
		public static function getInstance(){
			static $_instance = null;
			if( !$_instance ){
				$_instance = new LofContentDataSource(); 
			}
			return $_instance;
		}
		
		/**
		 * Get List articles following to parameters
		 */
		function getList( $params ){
			
			$formatter           = $params->get( 'style_displaying', 'title' );
			$titleMaxChars       = $params->get( 'title_max_chars', '100' );
			$descriptionMaxChars = $params->get( 'description_max_chars', 100 );
			$isThumb       = $params->get( 'auto_renderthumb',1);
			$replacer      = $params->get('replacer','...'); 
			$navDescLimit = $params->get('navdesc_max_chars','0');
			$limitDescriptionBy = $params->get('limit_description_by','char'); 
			$isStrips = $params->get("auto_strip_tags",1);
			$ordering      = $params->get('ordering', 'created-asc');
			
			$app = JFactory::getApplication();

			// Get an instance of the generic articles model
			$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));

			// Set application parameters in model
			
			$appParams = JFactory::getApplication()->getParams();
			$model->setState('params', $appParams);
			$model->setState('list.select', 'a.fulltext, a.id, a.title, a.alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' .
				' a.modified, a.modified_by, a.publish_up, a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' .
				' a.hits, a.featured' );
			
			// Set the filters based on the module params
			$model->setState('list.start', 0);
			$model->setState('list.limit', (int) $params->get('limit_items', 5));
			$model->setState('filter.published', 1);
			// Access filter
			$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
			$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
			$model->setState('filter.access', $access);

			// Category filter
			$model->setState('filter.category_id', $params->get('catid', array()));

			// Filter by language
			$model->setState('filter.language', $app->getLanguageFilter());

			// Set ordering
			$ordering = explode( '-', $ordering );
			if( trim($ordering[0]) == 'rand' ){
				$model->setState('list.ordering', ' RAND() '); 
			}
			else {
				$model->setState('list.ordering', 'a.'.$ordering[0]);
				$model->setState('list.direction', $ordering[1]);
			} 
		  
			
			
			//	Retrieve Content
			$items = $model->getItems();
		//	echo '<pre>'.print_r( $items ,1 ); die;
			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 article
					$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
				}
				else {
					$item->link = JRoute::_('index.php?option=com_user&view=login');
				}
				$item->date = JHtml::_('date', $item->created, JText::_('DATE_FORMAT_LC2')); 
				$item = $this->generateImages( $item, $isThumb );
				$item->fulltext = $item->introtext;
				$item->introtext   = JHtml::_('content.prepare', $item->introtext);
				$item->authorLink = '#';
				$item->categoryLink 	 = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catid));
				if( $limitDescriptionBy=='word' ){
					$string = preg_replace( "/\s+/", " ", strip_tags($item->introtext) );
					$tmp    = explode(" ", $string);
					$item->description = $descriptionMaxChars>count($tmp)?$string:implode(" ",array_slice($tmp, 0, $descriptionMaxChars)).$replacer;
				} else {
					$item->description = self::substring( $item->introtext, $descriptionMaxChars, $replacer, $isStrips  );
				}
			}
			return $items;
		}
	}
	}
}
?>