<?php
/*
 *
 * @package		ARI Framework
 * @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('Direct Access to this location is not allowed.');

AriKernel::import('SimpleTemplate.Filters.FilterBase');

class AriSimpleTemplateSubstrFilter extends AriSimpleTemplateFilterBase
{	
	function getFilterName()
	{
		return 'substr';
	}

	function parse($value, $startPos = 0, $length = null)
	{
		$startPos = @intval($startPos, 10);
		
		if (is_null($length) || $length === '')
			$value = substr($value, $startPos);
		else
			$value = substr($value, $startPos, @intval($length, 10));

		return $value;
	}
}

new AriSimpleTemplateSubstrFilter();