<commit_before><?php
/**
 * @version     $Id$
 * @category    Nooku
 * @package     Nooku_Server
 * @subpackage  Templates
 * @copyright   Copyright (C) 2011 Timble CVBA and Contributors. (http://www.timble.net).
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Template Database Row Class
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/stiandidriksen>
 * @category    Nooku
 * @package     Nooku_Server
 * @subpackage  Templates
 */
class ComTemplatesDatabaseRowTemplate extends KDatabaseRowAbstract
{
    /**
     * Whitelist for keys to get from the xml manifest
     *
     * @var array
     */
    protected static $_manifest_fields = array(
        'creationDate',
        'author',
        'copyright',
        'authorEmail',
        'authorUrl',
        'version',
        'description'
    );

    /**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   object  An optional KConfig object with configuration options.
     * @return void
     */
    protected function _initialize(KConfig $config)
    {
        $config->append(array(
            'identity_column'   => 'name'
        ));

        parent::_initialize($config);
    }

    /**
     * Get a value by key
     *
     * @param   string  The key name.
     * @return  string  The corresponding value.
     */
    public function __get($column)
    {
        if($column == 'name' && empty($this->_data['name'])) {
            $this->_data['name'] = basename($this->_data['path']);
        }
    
        if($column == 'default' && !isset($this->_data['default']))
        {
            $default                = JComponentHelper::getParams('com_templates')->get($this->application, 'site');
            $this->_data['default'] = $default == $this->name;
        }

    	if($column == 'ini_file' && empty($this->_data['ini_file'])) {
            $this->_data['ini_file'] = $this->_data['path'].'/params.ini';
        }

        if($column == 'ini' && !isset($this->_data['ini']))
        {
        	if(file_exists($this->ini_file)) {
                $this->_data['ini'] = file_get_contents($this->ini_file);
            }
        }

        if($column == 'manifest_file' && empty($this->_data['manifest_file'])) {
            $this->_data['manifest_file'] = $this->_data['path'].'/templateDetails.xml';
        }
		
		if($column == 'manifest' && empty($this->_data['manifest'])) {
            $this->_data['manifest'] = simplexml_load_file($this->manifest_file);
        }

		if(in_array($column, self::$_manifest_fields) && empty($this->_data[$column])) {
            $this->_data[$column] = $this->manifest->{$column};
        }

        if($column == 'positions' && !isset($this->_data['positions']))
        {
            $this->_data['positions'] = array();
            if($this->manifest && isset($this->manifest->positions))
            {
                foreach($this->manifest->positions->children() as $position) {
                    $this->_data['positions'][] = (string)$position;
                }
            }
        }

        return parent::__get($column);
    }

    /**
     * Saves to the template data, like default state, and params.
     *
     * @return boolean  If successfull return TRUE, otherwise FALSE
     */
	public function save()
	{
		if(isset($this->_modified['default']) && $this->default)
		{
			$params = JComponentHelper::getParams('com_templates');
			$params->set($this->application, $this->name);

			$table = KFactory::get('admin::com.components.database.table.components', array('name' => 'components'));

			$row = $table->select(array('option' => 'com_templates'), KDatabase::FETCH_ROW);
			$row->params = $params->toString();

			if(!$row->save()) return false;
		}

		if(isset($this->_modified['params']))
		{
			$params = KFactory::tmp('admin::com.templates.filter.ini')->sanitize($this->params);
			if(!file_put_contents($this->ini_file, $params)) return false;
		}

		return true;
	}
    <commit_msg>Cleanup<commit_after><?php
/**
 * @version     $Id$
 * @category    Nooku
 * @package     Nooku_Server
 * @subpackage  Templates
 * @copyright   Copyright (C) 2011 Timble CVBA and Contributors. (http://www.timble.net).
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Template Database Row Class
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/stiandidriksen>
 * @category    Nooku
 * @package     Nooku_Server
 * @subpackage  Templates
 */
class ComTemplatesDatabaseRowTemplate extends KDatabaseRowAbstract
{
    /**
     * Whitelist for keys to get from the xml manifest
     *
     * @var array
     */
    protected static $_manifest_fields = array(
        'creationDate',
        'author',
        'copyright',
        'authorEmail',
        'authorUrl',
        'version',
        'description'
    );

    /**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   object  An optional KConfig object with configuration options.
     * @return void
     */
    protected function _initialize(KConfig $config)
    {
        $config->append(array(
            'identity_column'   => 'name'
        ));

        parent::_initialize($config);
    }

    /**
     * Get a value by key
     *
     * @param   string  The key name.
     * @return  string  The corresponding value.
     */
    public function __get($column)
    {
        if($column == 'name' && empty($this->_data['name'])) {
            $this->_data['name'] = basename($this->_data['path']);
        }
    
        if($column == 'default' && !isset($this->_data['default']))
        {
            $default                = JComponentHelper::getParams('com_templates')->get($this->application, 'site');
            $this->_data['default'] = $default == $this->name;
        }

    	if($column == 'ini_file' && empty($this->_data['ini_file'])) {
            $this->_data['ini_file'] = $this->_data['path'].'/params.ini';
        }

        if($column == 'ini' && !isset($this->_data['ini']))
        {
        	if(file_exists($this->ini_file)) {
                $this->_data['ini'] = file_get_contents($this->ini_file);
            }
        }

        if($column == 'manifest_file' && empty($this->_data['manifest_file'])) {
            $this->_data['manifest_file'] = $this->_data['path'].'/templateDetails.xml';
        }
		
		if($column == 'manifest' && empty($this->_data['manifest'])) {
            $this->_data['manifest'] = simplexml_load_file($this->manifest_file);
        }

		if(in_array($column, self::$_manifest_fields) && empty($this->_data[$column])) {
            $this->_data[$column] = $this->manifest->{$column};
        }

        if($column == 'positions' && !isset($this->_data['positions']))
        {
            $this->_data['positions'] = array();
            if($this->manifest && isset($this->manifest->positions))
            {
                foreach($this->manifest->positions->children() as $position) {
                    $this->_data['positions'][] = (string)$position;
                }
            }
        }

        return parent::__get($column);
    }

    /**
     * Saves to the template data, like default state, and params.
     *
     * @return boolean  If successfull return TRUE, otherwise FALSE
     */
	public function save()
	{
		if(isset($this->_modified['default']) && $this->default)
		{
			$params = JComponentHelper::getParams('com_templates');
			$params->set($this->application, $this->name);

			$table = KFactory::get('admin::com.components.database.table.components', array('name' => 'components'));

			$row = $table->select(array('option' => 'com_templates'), KDatabase::FETCH_ROW);
			$row->params = $params->toString();

			return $row->save();
		}

		if(isset($this->_modified['params']))
		{
			$params = KFactory::tmp('admin::com.templates.filter.ini')->sanitize($this->params);
			if(!file_put_contents($this->ini_file, $params)) {
			    return false;
			}
		}

		return true;
	}
    
{'fraction_non_alphanumeric': 0.17363226513951505, 'fraction_numerical': 0.0012184720360667724, 'mean_word_length': 2.437185929648241, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 6}, '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': '3229555', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2395, 'n_words': 439}