<commit_before><?php
/**
 * @version     $Id$
 * @package     Nooku_Components
 * @subpackage  Default
 * @copyright   Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Template Menubar Helper
 *
 * @author      <NAME> <<EMAIL>>
 * @package     Nooku_Components
 * @subpackage  Default
 */
class ComDefaultTemplateHelperMenubar extends KTemplateHelperAbstract
{
	/**
     * 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(
    		'menubar' => null,
        ));

        parent::_initialize($config);
    }

 	/**
     * Render the menubar
     *
     * @param   array   An optional array with configuration options
     * @return  string  Html
     */
    public function render($config = array())
    {
        $config = new KConfig($config);
        $config->append(array(
        	'menubar' => null
        ));

		$html = '';

		if (version_compare(JVERSION, '1.7', 'ge')) {
			$html .= '<div id="submenu-box"><div class="m">';
		}

        $html .= '<ul id="submenu">';
	    foreach ($config->menubar->getCommands() as $command)
	    {
	        $html .= '<li>';
            $html .= $this->command(array('command' => $command));
            $html .= '</li>';
        }

        $html .= '</ul>';

		if (version_compare(JVERSION, '1.7', 'ge')) {
			$html .= '<div class="clr"></div></div></div>';
		}


		return $html;
    }

    /**
     * Render a menubar command
     *
     * @param   array   An optional array with configuration options
     * @return  string  Html
     */
    public function command($config = array())
    {
        $config = new KConfig($config);
        $config->append(array(
        	'command' => null
        ));

        $command = $config->command;

        //Add a nolink class if the command is disabled
        if($command->disabled) {
            $command->attribs->class->append(array('nolink'));
        }

        if($command->active) {
             $command->attribs->class->append(array('active'));
        }

        //Explode the class array
        $command->attribs->class = implode(" ", KConfig::unbox($command->attribs->class));

        if ($command->disabled) {
			$html = '<span '.KHelperArray::toString($command->attribs).'>'.$this->translate($command->label).'</span>';
		} else {
			$html = '<a href="'.$command->href.'" '.KHelperArray::toString($command->attribs).'>'.$this->translate($command->label).'</a>';
		}

    	return $html;
    }
}<commit_msg>re #20: Use JSubmenuHelper for rendering submenus<commit_after><?php
/**
 * @version     $Id$
 * @package     Nooku_Components
 * @subpackage  Default
 * @copyright   Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Template Menubar Helper
 *
 * @author      <NAME> <<EMAIL>>
 * @package     Nooku_Components
 * @subpackage  Default
 */
class ComDefaultTemplateHelperMenubar extends KTemplateHelperAbstract
{
	/**
     * 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(
    		'menubar' => null,
        ));

        parent::_initialize($config);
    }

 	/**
     * Render the menubar
     *
     * @param   array   An optional array with configuration options
     * @return  string  Html
     */
    public function render($config = array())
    {
        $config = new KConfig($config);
        $config->append(array(
        	'menubar' => null
        ));
        
        if (version_compare(JVERSION, '3.0', 'ge')) 
        {
        	foreach ($config->menubar->getCommands() as $command) {
        		JSubmenuHelper::addEntry($this->translate($command->label), $command->href, $command->active);
        	}
        	return;
        }

		$html = '';

		if (version_compare(JVERSION, '1.7', 'ge')) {
			$html .= '<div id="submenu-box"><div class="m">';
		}

        $html .= '<ul id="submenu">';
	    foreach ($config->menubar->getCommands() as $command)
	    {
	        $html .= '<li>';
            $html .= $this->command(array('command' => $command));
            $html .= '</li>';
        }

        $html .= '</ul>';

		if (version_compare(JVERSION, '1.7', 'ge')) {
			$html .= '<div class="clr"></div></div></div>';
		}


		return $html;
    }

    /**
     * Render a menubar command
     *
     * @param   array   An optional array with configuration options
     * @return  string  Html
     */
    public function command($config = array())
    {
        $config = new KConfig($config);
        $config->append(array(
        	'command' => null
        ));

        $command = $config->command;

        //Add a nolink class if the command is disabled
        if($command->disabled) {
            $command->attribs->class->append(array('nolink'));
        }

        if($command->active) {
             $command->attribs->class->append(array('active'));
        }

        //Explode the class array
        $command->attribs->class = implode(" ", KConfig::unbox($command->attribs->class));

        if ($command->disabled) {
			$html = '<span '.KHelperArray::toString($command->attribs).'>'.$this->translate($command->label).'</span>';
		} else {
			$html = '<a href="'.$command->href.'" '.KHelperArray::toString($command->attribs).'>'.$this->translate($command->label).'</a>';
		}

    	return $html;
    }
}
{'fraction_non_alphanumeric': 0.17020917678812417, 'fraction_numerical': 0.005060728744939271, 'mean_word_length': 2.292059966685175, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 109, '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': '7152014', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1812, 'n_words': 396}