<commit_before><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2007 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Library;

/**
 * Behavior Template Helper
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Nooku\Library\Template
 */
class TemplateHelperBehavior extends TemplateHelperAbstract
{
    /**
     * Array which holds a list of loaded javascript libraries
     *
     * boolean
     */
    protected static $_loaded = array();

    /**
     * Method to load the mootools framework into the document head
     *
     * - If debugging mode is on an uncompressed version of mootools is included for easier debugging.
     *
     * @param array $config An optional array with configuration options
     * @return string    The html output
     */
    public function mootools($config = array())
    {
        $html = '';

        // Only load once
        if (!isset(self::$_loaded['mootools']))
        {
            $config = new ObjectConfig($config);

            $html .= '<script src="assets://js/mootools.js" />';
            self::$_loaded['mootools'] = true;
        }

        return $html;
    }

    /**
     * Render a modal box
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function modal($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'selector' => 'a.modal',
            'options'  => array('disableFx' => true)
        ));

        $html = '';

        // Load the necessary files if they haven't yet been loaded
        if (!isset(self::$_loaded['modal'])) {
            $html .= '<script src="assets://js/modal.js" />';
            $html .= '<style src="assets://css/modal.css" />';

            self::$_loaded['modal'] = true;
        }

        $signature = 'modal-' . $config->selector;
        if (!isset(self::$_loaded[$signature]))
        {
            $options = !empty($config->options) ? $config->options->toArray() : array();
            $html .= "
			<script>
				window.addEvent('domready', function() {

				SqueezeBox.initialize(" . json_encode($options) . ");
				SqueezeBox.assign($$('" . $config->selector . "'), {
			        parse: 'rel'
				});
			});
			</script>";

            self::$_loaded[$signature] = true;
        }

        return $html;
    }

    /**
     * Render a tooltip
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function tooltip($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'selector' => '.hasTip',
            'options' => array()
        ));

        $html = '';

        $signature = 'tooltip-' . $config->selector;
        if (!isset(self::$_loaded[$signature]))
        {
            //Don't pass an empty array as options
            $options = $config->options->toArray() ? ', ' . $config->options : '';
            $html .= "
			<script>
				window.addEvent('domready', function(){ new Tips($$('" . $config->selector . "')" . $options . "); });
			</script>";

            self::$_loaded[$signature] = true;
        }

        return $html;
    }

    /**
     * Render an overlay
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function overlay($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'url' => '',
            'options' => array(),
            'attribs' => array(),
        ));

        $html = '';
        // Load the necessary files if they haven't yet been loaded
        if (!isset(self::$_loaded['overlay']))
        {
            $html .= '<script src="assets://js/koowa.js" />';
            $html .= '<style src="assets://css/koowa.css" />';

            self::$_loaded['overlay'] = true;
        }

        $url = $this->getObject('lib:http.url', array('url' => $config->url));

        //Force tmpl to overlay
        $url->query['tmpl'] = 'overlay';

        $attribs = $this->buildAttributes($config->attribs);

        $id = 'overlay' . rand();
        if ($url->fragment) {
            //Allows multiple identical ids, legacy should be considered replaced with #$url->fragment instead
            $config->append(array(
                'options' => array(
                    'selector' => '[id=' . $url->fragment . ']'
                )
            ));
        }

        //Don't pass an empty array as options
        $options = $config->options->toArray() ? ', ' . $config->options : '';
        $html .= "<script>window.addEvent('domready', function(){new Koowa.Overlay('$id'" . $options . ");});</script>";

        $html .= '<div data-url="' . $url . '" class="-koowa-overlay" id="' . $id . '" ' . $attribs . '><div class="-koowa-overlay-status">' . $this->translate('Loading...') . '</div></div>';
        return $html;
    }

    /**
     * Keep session alive
     *
     * This will send an ascynchronous request to the server via AJAX on an interval in miliseconds
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function keepalive($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'refresh' => 15 * 60000, //default refresh is 15min
            'url'     => $this->getTemplate()->getView()->getRoute('', false, false),<commit_msg>Use mt_rand instead or rand for performance.<commit_after><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2007 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Library;

/**
 * Behavior Template Helper
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Nooku\Library\Template
 */
class TemplateHelperBehavior extends TemplateHelperAbstract
{
    /**
     * Array which holds a list of loaded javascript libraries
     *
     * boolean
     */
    protected static $_loaded = array();

    /**
     * Method to load the mootools framework into the document head
     *
     * - If debugging mode is on an uncompressed version of mootools is included for easier debugging.
     *
     * @param array $config An optional array with configuration options
     * @return string    The html output
     */
    public function mootools($config = array())
    {
        $html = '';

        // Only load once
        if (!isset(self::$_loaded['mootools']))
        {
            $config = new ObjectConfig($config);

            $html .= '<script src="assets://js/mootools.js" />';
            self::$_loaded['mootools'] = true;
        }

        return $html;
    }

    /**
     * Render a modal box
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function modal($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'selector' => 'a.modal',
            'options'  => array('disableFx' => true)
        ));

        $html = '';

        // Load the necessary files if they haven't yet been loaded
        if (!isset(self::$_loaded['modal'])) {
            $html .= '<script src="assets://js/modal.js" />';
            $html .= '<style src="assets://css/modal.css" />';

            self::$_loaded['modal'] = true;
        }

        $signature = 'modal-' . $config->selector;
        if (!isset(self::$_loaded[$signature]))
        {
            $options = !empty($config->options) ? $config->options->toArray() : array();
            $html .= "
			<script>
				window.addEvent('domready', function() {

				SqueezeBox.initialize(" . json_encode($options) . ");
				SqueezeBox.assign($$('" . $config->selector . "'), {
			        parse: 'rel'
				});
			});
			</script>";

            self::$_loaded[$signature] = true;
        }

        return $html;
    }

    /**
     * Render a tooltip
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function tooltip($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'selector' => '.hasTip',
            'options' => array()
        ));

        $html = '';

        $signature = 'tooltip-' . $config->selector;
        if (!isset(self::$_loaded[$signature]))
        {
            //Don't pass an empty array as options
            $options = $config->options->toArray() ? ', ' . $config->options : '';
            $html .= "
			<script>
				window.addEvent('domready', function(){ new Tips($$('" . $config->selector . "')" . $options . "); });
			</script>";

            self::$_loaded[$signature] = true;
        }

        return $html;
    }

    /**
     * Render an overlay
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function overlay($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'url' => '',
            'options' => array(),
            'attribs' => array(),
        ));

        $html = '';
        // Load the necessary files if they haven't yet been loaded
        if (!isset(self::$_loaded['overlay']))
        {
            $html .= '<script src="assets://js/koowa.js" />';
            $html .= '<style src="assets://css/koowa.css" />';

            self::$_loaded['overlay'] = true;
        }

        $url = $this->getObject('lib:http.url', array('url' => $config->url));

        //Force tmpl to overlay
        $url->query['tmpl'] = 'overlay';

        $attribs = $this->buildAttributes($config->attribs);

        $id = 'overlay' . mt_rand();
        if ($url->fragment)
        {
            //Allows multiple identical ids, legacy should be considered replaced with #$url->fragment instead
            $config->append(array(
                'options' => array(
                    'selector' => '[id=' . $url->fragment . ']'
                )
            ));
        }

        //Don't pass an empty array as options
        $options = $config->options->toArray() ? ', ' . $config->options : '';
        $html .= "<script>window.addEvent('domready', function(){new Koowa.Overlay('$id'" . $options . ");});</script>";

        $html .= '<div data-url="' . $url . '" class="-koowa-overlay" id="' . $id . '" ' . $attribs . '><div class="-koowa-overlay-status">' . $this->translate('Loading...') . '</div></div>';
        return $html;
    }

    /**
     * Keep session alive
     *
     * This will send an ascynchronous request to the server via AJAX on an interval in miliseconds
     *
     * @param 	array 	$config An optional array with configuration options
     * @return string    The html output
     */
    public function keepalive($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'refresh' => 15 * 60000, //default refresh is 15min
            'url'     => $this->getTemplate()->getView()->getRoute('', false, false),
{'fraction_non_alphanumeric': 0.16305830207978178, 'fraction_numerical': 0.003068530514831231, 'mean_word_length': 2.0115503080082138, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '913309', 'n_tokens_mistral': 3477, 'n_tokens_neox': 3294, 'n_words': 833}