<?php
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die;

jimport('joomla.filter.filterinput');

AriKernel::import('Utils.Config');

class AriSmartContentHelper
{
	function getConfig()
	{
		return AriConfigFactory::getInstance('AriSmartContentConfig', 'Application.ARISmartContent.Utils.Config');
	}
	
	function getFormPath($group, $form = null, $formPath = null)
	{
		if (is_null($formPath))
			$formPath = JPATH_ADMINISTRATOR . '/components/com_arismartcontent/models/forms/';

		$filter =& JFilterInput::getInstance();
		$group = $filter->clean($group, 'CMD');
		$form = $filter->clean($form, 'CMD');

		if (empty($group))
			return null;
	
		$group = str_replace('_', '/', $group);
		
		if (empty($form))
		{
			$groupParts = explode('/', $group);
			if (count($groupParts) > 1)
			{
				$form = array_pop($groupParts);
				$group = join('/', $groupParts);
			}
		}
		
		if (empty($form))
			return null;
			
		return $formPath . $group . '/' . $form . '.xml'; 
	}
	
	function getPaginatorOptions()
	{
		return array(
			'firstPageLinkLabel' => JText::_('COM_ARISMARTCONTENT_LABEL_DTFIRSTPAGE'),
			'lastPageLinkLabel' => JText::_('COM_ARISMARTCONTENT_LABEL_DTLASTPAGE'),
			'nextPageLinkLabel' => JText::_('COM_ARISMARTCONTENT_LABEL_DTNEXTPAGE'),
			'previousPageLinkLabel' => JText::_('COM_ARISMARTCONTENT_LABEL_DTPREVPAGE'),
			'pageReportTemplate' => JText::_('COM_ARISMARTCONTENT_LABEL_DTPAGEREPORTTEMPLATE'),
			'template' => JText::_('COM_ARISMARTCONTENT_LABEL_DTTEMPLATE')
		);
	}
	
	function addSubmenu($vName)
	{
		JSubMenuHelper::addEntry(
			JText::_('COM_ARISMARTCONTENT_MENU_DATA'),
			'index.php?option=com_arismartcontent&view=data',
			$vName == 'data' || strpos($vName, 'provider_') !== false
		);
		
		JSubMenuHelper::addEntry(
			JText::_('COM_ARISMARTCONTENT_MENU_PLUGINS'),
			'index.php?option=com_arismartcontent&view=plugins',
			$vName == 'plugins'
		);

		JSubMenuHelper::addEntry(
			JText::_('COM_ARISMARTCONTENT_MENU_CONFIG'),
			'index.php?option=com_arismartcontent&view=config',
			$vName == 'config'
		);
		
		JSubMenuHelper::addEntry(
			JText::_('COM_ARISMARTCONTENT_MENU_ABOUT'),
			'index.php?option=com_arismartcontent&view=about',
			$vName == 'about'
		);
	}

	static function isK2Installed()
	{
		$k2path = JPATH_ADMINISTRATOR . '/components/com_k2';

		return file_exists($k2path);		
	}
}