<commit_before><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_View
 * @copyright	Copyright (C) 2007 - 2008 Joomlatools. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.koowa.org
 */

/**
 * Abstract View Class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package		Koowa_View
 * @uses		KMixinClass
 * @uses 		KTemplateDefault
 * @uses 		KFactory
 */
abstract class KViewAbstract extends KObject
{
	/**
	 * The base path of the view
	 *
	 * @var		string
	 */
	protected $_basePath;

	/**
	 * Layout name
	 *
	 * @var		string
	 */
	protected $_layout = 'default';

	/**
	* The set of search directories for templatex
	*
	* @var array
	*/
	protected $_templatePath = array();

	/**
	* The name of the default template source file.
	*
	* @var string
	*/
	protected $_template;

	/**
	* The output of the template script.
	*
	* @var string
	*/
	protected $_output = null;

	/**
     * Callback for escaping.
     *
     * @var string
     */
    protected $_escape;

	/**
	 * Constructor
	 * 
	 * @param	array An optional associative array of configuration settings.
	 */
	public function __construct(array $options = array())
	{
        // Initialize the options
        $options  = $this->_initialize($options);

        // Mixin the KMixinClass
        $this->mixin(new KMixinClass($this, 'View'));

        // Assign the classname with values from the config
        $this->setClassName($options['name']);

		 // set the charset (used by the variable escaping functions)
        $this->_charset = $options['charset'];

		 // user-defined escaping callback
        $this->setEscape($options['escape']);

		// Set a base path for use by the view
		if ($options['base_path']) {
			$this->_basePath	= $options['base_path'];
		} else {
			$this->_basePath	= JPATH_COMPONENT.DS.'views'.DS.$this->getClassName('suffix');
		}

		// Set a base path for use by the view
		$this->assign('baseurl',	$options['base_url']);

		// set the default template search path
		if ($options['template_path']) {
			// user-defined dirs
			$this->setTemplatePath($options['template_path']);
		} else {
			$this->setTemplatePath($this->_basePath.DS.'tmpl');
		}

		// set the layout
		$this->setLayout($options['layout']);

		// assign the document object
		if ($options['document']) {
			$this->assignRef('document', $options['document']);
		} else {
			$this->assignRef('document', KFactory::get('lib.joomla.document'));
		}

		//Register the view stream wrapper
		KTemplateDefault::register();
		KTemplateDefault::addRules($options['template_rules']);

		//Add the include paths for the helpers
		KViewHelper::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_'.$this->getClassName('prefix').DS.'helpers');
	}

    /**
     * Initializes the options for the object
     * 
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   array   Options
     * @return  array   Options
     */
    protected function _initialize(array $options)
    {
        $defaults = array(
            'base_path'     => JPATH_COMPONENT,
            'base_url'      => JURI::base(true),
            'charset'       => null, // TODO unused?
            'document'      => null,
            'escape'        => 'htmlspecialchars',
            'layout'        => 'default',
            'name'          => array(
                        'prefix'    => 'k',
                        'base'      => 'view',
                        'suffix'    => 'default'
                        ),
			'template_rules' => array(
						'@template' => '@loadTemplate',
						'@text'	    => 'JText::_',
						'@helper'   => '@loadHelper',
						'@route'    => '@createRoute', 
                        '@token'	=> 'KSecurityToken::render'
						),
            'template_path' => null
        );

        return array_merge($defaults, $options);
    }

	/**
	* Execute and display a template script.
	*
	* @param string $tpl The name of the template file to parse;
	* automatically searches through the template paths.
	*
	* @throws object An JError object.
	* @see fetch()
	*/
	public function display($tpl = null)
	{
		$result = $this->loadTemplate($tpl);<commit_msg>Template rules need a '(' to make sure tags like @textfield dont get read as @text<commit_after><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_View
 * @copyright	Copyright (C) 2007 - 2008 Joomlatools. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.koowa.org
 */

/**
 * Abstract View Class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package		Koowa_View
 * @uses		KMixinClass
 * @uses 		KTemplateDefault
 * @uses 		KFactory
 */
abstract class KViewAbstract extends KObject
{
	/**
	 * The base path of the view
	 *
	 * @var		string
	 */
	protected $_basePath;

	/**
	 * Layout name
	 *
	 * @var		string
	 */
	protected $_layout = 'default';

	/**
	* The set of search directories for templatex
	*
	* @var array
	*/
	protected $_templatePath = array();

	/**
	* The name of the default template source file.
	*
	* @var string
	*/
	protected $_template;

	/**
	* The output of the template script.
	*
	* @var string
	*/
	protected $_output = null;

	/**
     * Callback for escaping.
     *
     * @var string
     */
    protected $_escape;

	/**
	 * Constructor
	 * 
	 * @param	array An optional associative array of configuration settings.
	 */
	public function __construct(array $options = array())
	{
        // Initialize the options
        $options  = $this->_initialize($options);

        // Mixin the KMixinClass
        $this->mixin(new KMixinClass($this, 'View'));

        // Assign the classname with values from the config
        $this->setClassName($options['name']);

		 // set the charset (used by the variable escaping functions)
        $this->_charset = $options['charset'];

		 // user-defined escaping callback
        $this->setEscape($options['escape']);

		// Set a base path for use by the view
		if ($options['base_path']) {
			$this->_basePath	= $options['base_path'];
		} else {
			$this->_basePath	= JPATH_COMPONENT.DS.'views'.DS.$this->getClassName('suffix');
		}

		// Set a base path for use by the view
		$this->assign('baseurl',	$options['base_url']);

		// set the default template search path
		if ($options['template_path']) {
			// user-defined dirs
			$this->setTemplatePath($options['template_path']);
		} else {
			$this->setTemplatePath($this->_basePath.DS.'tmpl');
		}

		// set the layout
		$this->setLayout($options['layout']);

		// assign the document object
		if ($options['document']) {
			$this->assignRef('document', $options['document']);
		} else {
			$this->assignRef('document', KFactory::get('lib.joomla.document'));
		}

		//Register the view stream wrapper
		KTemplateDefault::register();
		KTemplateDefault::addRules($options['template_rules']);

		//Add the include paths for the helpers
		KViewHelper::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_'.$this->getClassName('prefix').DS.'helpers');
	}

    /**
     * Initializes the options for the object
     * 
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   array   Options
     * @return  array   Options
     */
    protected function _initialize(array $options)
    {
        $defaults = array(
            'base_path'     => JPATH_COMPONENT,
            'base_url'      => JURI::base(true),
            'charset'       => null, // TODO unused?
            'document'      => null,
            'escape'        => 'htmlspecialchars',
            'layout'        => 'default',
            'name'          => array(
                        'prefix'    => 'k',
                        'base'      => 'view',
                        'suffix'    => 'default'
                        ),
			'template_rules' => array(
						'@template('	=> '@loadTemplate(',
						'@text('	 	=> 'JText::_(',
						'@helper('   	=> '@loadHelper(',
						'@route('    	=> '@createRoute(', 
                        '@token('		=> 'KSecurityToken::render('
						),
            'template_path' => null
        );

        return array_merge($defaults, $options);
    }

	/**
	* Execute and display a template script.
	*
	* @param string $tpl The name of the template file to parse;
	* automatically searches through the template paths.
	*
	* @throws object An JError object.
	* @see fetch()
	*/
	public function display($tpl = null)
	{
		$result = $this->loadTemplate($tpl);
{'fraction_non_alphanumeric': 0.1478594695207073, 'fraction_numerical': 0.0025593299208934387, 'mean_word_length': 2.4429315178213855, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5001207', 'n_tokens_mistral': 2837, 'n_tokens_neox': 2585, 'n_words': 665}