<?php
/**
 * Main Administrator Component File
 * This defines what controller to use and what task to execute
 *
 * @package     Content Templater
 * @version     1.5.4
 *
 * @author      Peter van Westen <peter@nonumber.nl>
 * @link        http://www.nonumber.nl
 * @copyright   Copyright (C) 2010 NoNumber! All Rights Reserved
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Load Language
// Loads English language file as fallback (for undefined stuff in other language file)
require_once JPATH_PLUGINS.DS.'system'.DS.'nonumberelements'.DS.'elements'.DS.'loadlanguage.php';
JElementLoadLanguage::loadLanguage( 'com_contenttemplater' );

// Dependency
require_once JPATH_PLUGINS.DS.'system'.DS.'nonumberelements'.DS.'elements'.DS.'dependency.php';
JElementDependency::setMessage( '/plugins/editors-xtd/contenttemplater.php', 'the Content Templater editor button plugin' );
JElementDependency::setMessage( '/plugins/system/contenttemplater.php', 'the Content Templater system plugin' );

// Do the version check
require_once JPATH_PLUGINS.DS.'system'.DS.'nonumberelements'.DS.'helpers'.DS.'versions.php';
$versions = NNVersions::instance();
$version = '';
$xml = JApplicationHelper::parseXMLInstallFile( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_contenttemplater'.DS.'com_contenttemplater.xml' );
if ( $xml && isset( $xml['version'] ) ) {
	$version = $xml['version'];
}
$versions->setMessage( $version, 'version_contenttemplater', 'http://www.nonumber.nl/versions', 'http://www.nonumber.nl/contenttemplater/download' );

// If no controller then default controller = 'list'
$controller = JRequest::getVar( 'controller', 'list' );

// Set the controller page
require_once JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';

// Create the controller contenttemplaterController
$classname = 'ContentTemplaterController'.$controller;

// Create a new class of classname and set the default task: display
$controller = new $classname( array( 'default_task'=>'display' ) );

// Perform the Request task
$controller->execute( JRequest::getVar( 'task' ) );

// Redirect if set by the controller
$controller->redirect();

$extension = 'Content Templater';

// Place Commercial License Code check
require_once JPATH_PLUGINS.DS.'system'.DS.'nonumberelements'.DS.'helpers'.DS.'licenses.php';
$licenses = NNLicenses::instance();
echo $licenses->getMessage( $extension );

echo '<p style="text-align:center;">'.$extension;
if ( $version ) {
	echo ' v'.$version;
}
echo ' - '.JText::_( 'Copyright' ).' (C) 2010 NoNumber! '.JText::_( 'All Rights Reserved' ).'</p>';