Location: PHPKode > projects > Visitas > html/com_content/category/default_items.php
<?php
/**
 * Joomla! 1.5 template MobiVisit
 * A Joomla template for mobile phones
 *
 * @version $Id: $
 * @package Joomla
 * @subpackage MobiVisit
 *
 * This program has been created by Omicron Ceti AB on behalf of 
 * Norrbottens county council, Piteå municipality, Region of Västerbotten, 
 * Robertsfors municipality, Skellefteå municipality, Umeå municipality, 
 * Västerbottens county council and the European Regional Development Found
 * 
 * @copyright Copyright (C) 2010 Municipality of Umea, Sweden
 * @author Magnus Häggström - Omicron Ceti AB
 * @author Mikael Wiberg - Omicron Ceti AB
 * 
 * @license GNU/GPL v2
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

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

JPlugin::loadLanguage( 'tpl_mobivisit' );
// Get current language to select between distance units
$lang =& JFactory::getLanguage();

// Create a sortingTools object
require_once JPATH_THEMES.DS.'mobivisit'.DS.'mobivisitSortingTools.php';
$mvSortingTools = new MVisitSortingTools();

?>

<script type="text/javascript">
</script>

<?php 
// Only show the sorting box if it is enabled by the template
if ($mvSortingTools->getTemplateParams()->get('enableSorting') ): 
?>
<form action="<?php echo $this->action; ?>" method="post">
	<fieldset>
		<legend><?php echo JText::_("Sort")?></legend>
		<?php

		global $mainframe;
		$itemid = JRequest::getInt('id', 0) . ':' . JRequest::getInt('Itemid', 0);
		$orderby  = $mainframe->getUserStateFromRequest('com_content.category.list.' . $itemid . '.custom_filter_order', 'custom_filter_order', '', 'cmd');		

		// Get user position - if set
		$userlat = $mainframe->getUserState( "com_mobimaps.userlat");
		$userlng = $mainframe->getUserState( "com_mobimaps.userlng");

		// Get all articles and sort them according to $orderby
		$mvSortingTools->getArticles($this->items, $this->category->id);
		
		// Determine which radio button that shall be selected
		// Disables the distance radio button if user position is not set
		if($userlat != '' && $userlng != '')
		{
			if($orderby == 'distance')
			{
				$distanceSort = ' checked="checked"';
			}
			else if($orderby == 'lat')
			{
				$latSort = ' checked="checked"';
			}
			else if($orderby == 'a.title')
			{
				$titleSort = ' checked="checked"';
			}
			else if($orderby == 'rating')
			{
				$rateSort = ' checked="checked"';
			}
		}
		else
		{
			$distanceDisabled = ' disabled="disabled"';
			if($orderby == 'lat')
			{
				$latSort = ' checked="checked"';
			}
			else if($orderby == 'a.title')
			{
				$titleSort = ' checked="checked"';
			}
			else if($orderby == 'rating')
			{
				$rateSort = ' checked="checked"';
			}
		}
		
		if($this->lists['order_Dir'] == 'desc')
		{
			$descSortDir = ' selected="selected"';
		}
		else
		{
			$ascSortDir = ' selected="selected"';
		}

		// Check if mobirate component is installed and enabled - otherwise don't show the radio button
		if($mvSortingTools->isInstalled('mobirate'))
		{
			$rateRadio = "<label>\n";
			$rateRadio .= '  <input type="radio" name="custom_filter_order" value="rating"'.$rateSort.' />'.JText::_('Rating')."\n";
			$rateRadio .= '</label>'."\n";
		}
		// Check if mobimaps component is installed and enabled - otherwise don't show the radio button
		if($mvSortingTools->isInstalled('mobimaps'))
		{
			$latRadio = "<label>\n";
			$latRadio .= '  <input type="radio" name="custom_filter_order" value="lat"'.$latSort.' />'.JText::_('South to North')."\n";
			$latRadio .= '</label>'."\n";

			$distRadio = "<label>\n";
			$distRadio .= '  <input type="radio" name="custom_filter_order" value="distance"'.$distanceSort.$distanceDisabled.'/>'.JText::_('Distance')."\n";
			$distRadio .= '</label>'."\n";
		}

		// Print the "sort by" radio buttons
		echo '<label><input type="radio" name="custom_filter_order" value="a.title"'.$titleSort.' />'.JText::_('Title').'</label>';
		echo $rateRadio;
		echo $latRadio;
		echo $distRadio;
		echo '<br/>';
		?>
		<!-- // Print the "sort order" select box -->
		<select name="filter_order_Dir" id="ordering" class="inputbox">
			<option value="asc"<?php echo $ascSortDir; ?>><?php echo JText::_("Ascending"); ?></option>
			<option value="desc"<?php echo $descSortDir; ?>><?php echo JText::_("Descending"); ?></option>
		</select>

		<input type="submit" class="button" name="sort" value="<?php echo JText::_("Sort"); ?>" />
		<input type="hidden" name="id" value="<?php echo (int)$this->category->id; ?>" />
		<input type="hidden" name="sectionid" value="<?php echo (int)$this->category->sectionid; ?>" />
		<input type="hidden" name="task" value="<?php echo $this->lists['task']; ?>" />
		<input type="hidden" name="limitstart" value="0" />
	</fieldset>
</form>
<?php endif; ?>

<div class="categorylist">
	<?php foreach ($this->items as $item) : ?>
	<div class="contentlistentrywrap<?php echo ($item->odd + 1) . $this->escape($this->params->get('pageclass_sfx')); ?>">
		
		<?php 
		if ($item->access <= $this->user->get('aid', 0)) : ?>
			<a class="contentlistentry<?php echo ($item->odd + 1) . $this->escape($this->params->get('pageclass_sfx')); ?>" href="<?php echo $item->link; ?>">
				<?php if ($this->params->get('show_title')) : ?>
				<span class="listentrytitle">
					<?php echo $this->escape($item->title);	?>
				</span>
				<?php endif; ?>
				
				<?php if($item->rating != null && $item->rating != 0) : ?>
				<span class="listentryinfo">
					<?php echo JText::_('AVERAGE RATING') . ": "; ?>
					<?php printf("%1.1f", round($item->rating, 1)); ?>
				</span>
				<?php endif; ?>
				
				<?php if($item->distance != null && $item->distance != 99999999) : ?>
				<span class="listentryinfo">
					<?php
					echo JText::_('Distance') . ": ";
					if($lang->getTag() == 'en-GB')
					{
						echo round($item->distance, 1).' mi.';
					}
					else
					{
						echo round($item->distance*1.609344, 1).' km';
					}
					?>
				</span>
				<?php endif; ?>
				
				<?php if ($this->params->get('show_date')) : ?>
				<span class="listentryinfo">
					<?php echo JText::_('Date') . ": "; ?>
					<?php echo $this->escape($item->created); ?>
				</span>
				<?php endif; ?>
		
				<?php if ($this->params->get('show_author')) : ?>
				<span class="listentryinfo">
					<?php echo JText::_('Author') . ": "; ?>
					<?php echo $item->created_by_alias ? $this->escape($item->created_by_alias) : $this->escape($item->author); ?>
				</span>
				<?php endif; ?>

				<?php if ($this->params->get('show_hits')) : ?>
				<span class="listentryinfo">
					<?php echo JText::_('Hits') . ": "; ?>
					<?php echo $item->hits ? (int)$item->hits : '-'; ?>
				</span>
				<?php endif; ?>
		
			</a>
			<?php 
				/* 
				 * Edit button is disabled in MobiVisit
				 * A user shall never be able to edit site from MobiVisit frontend
				 *
				echo JHTML::_('icon.edit', $item, $this->params, $this->access);
				*/
			?>
		<?php
		else :
			echo $item->title; ?> :
			<a href="<?php echo JRoute::_('index.php?option=com_user&task=register'); ?>">
				<?php echo JText::_('Register to read more...'); ?></a>
		<?php endif; ?>
		
	</div>
	<?php endforeach; ?>

</div>

<?php if ($this->params->get('show_pagination')) : ?>
<p class="counter">
	<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php echo $this->pagination->getPagesLinks();
endif; ?>
Return current item: Visitas