<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2010, EllisLab, Inc.
 * @license		https://codeigniter.com/user_guide/license.html
 * @link		https://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * CodeIgniter HTML Helpers
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		ExpressionEngine Dev Team
 * @link		https://codeigniter.com/user_guide/helpers/html_helper.html
 */
// ------------------------------------------------------------------------

if (!function_exists('heading')) {

    /**
     * Heading
     *
     * Generates an HTML heading tag.
     *
     * @param	string	content
     * @param	int	heading level
     * @param	string
     * @return	string
     */
    function heading($data = '', $h = '1', $attributes = '')
    {
        return '<h' . $h . _stringify_attributes($attributes) . '>' . $data . '</h' . $h . '>';
    }

}

// ------------------------------------------------------------------------

if (!function_exists('ul')) {

    /**
     * Unordered List
     *
     * Generates an HTML unordered list from an single or multi-dimensional array.
     *
     * @param	array
     * @param	mixed
     * @return	string
     */
    function ul($list, $attributes = '')
    {
        return _list('ul', $list, $attributes);
    }

}

// ------------------------------------------------------------------------

if (!function_exists('ol')) {

    /**
     * Ordered List
     *
     * Generates an HTML ordered list from an single or multi-dimensional array.
     *
     * @param	array
     * @param	mixed
     * @return	string
     */
    function ol($list, $attributes = '')
    {
        return _list('ol', $list, $attributes);
    }

}

// ------------------------------------------------------------------------
if (!function_exists('_stringify_attributes')) {

    /**
     * Stringify attributes for use in HTML tags.
     *
     * Helper function used to convert a string, array, or object
     * of attributes to a string.
     *
     * @param	mixed	string, array, object
     * @param	bool
     * @return	string
     */
    function _stringify_attributes($attributes, $js = FALSE)
    {
        if (empty($attributes)) {
            return NULL;
        }

        if (is_string($attributes)) {
            return ' ' . $attributes;
        }

        $attributes = (array) $attributes;

        $atts = '';
        foreach ($attributes as $key => $val) {
            $atts .= ($js) ? $key . '=' . $val . ',' : ' ' . $key . '="' . $val . '"';
        }

        return rtrim($atts, ',');
    }

}

// ------------------------------------------------------------------------

/**
 * Generates the list
 *
 * Generates an HTML ordered list from an single or multi-dimensional array.
 *
 * @access	private
 * @param	string
 * @param	mixed
 * @param	mixed
 * @param	integer
 * @return	string
 */
if (!function_exists('_list')) {

    /**
     * Generates the list
     *
     * Generates an HTML ordered list from an single or multi-dimensional array.
     *
     * @param	string
     * @param	mixed
     * @param	mixed
     * @param	int
     * @return	string
     */
    function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0)
    {
        // If an array wasn't submitted there's nothing to do...
        if (!is_array($list)) {
            return $list;
        }

        if (empty($list)) {
            return '- - -'."\n";
        }

        // Set the indentation based on the depth
        $out = str_repeat(' ', $depth)
                // Write the opening list tag
                . '<' . $type . _stringify_attributes($attributes) . '>';

        // Cycle through the list elements.  If an array is
        // encountered we will recursively call _list()

        static $_last_list_item = '';
        foreach ($list as $key => $val) {
            $_last_list_item = is_object($key) ? print_r($key, true) : $key;

            $out .= str_repeat(' ', $depth + 2) . '<li>';

            if (!is_array($val) && !is_object($val)) {
                $out .= $_last_list_item . ' = ' . $val;
            } else {
                $out .= $_last_list_item . "\n" . _list($type, (array) $val, '', $depth + 4) . str_repeat(' ', $depth + 2);
            }

            $out .= '</li>';
        }

        // Set the indentation for the closing tag and apply it
        return $out . str_repeat(' ', $depth) . '</' . $type . '>';
    }

}

/**
 * @modified CK untermStrich - Removed unused functions
 */

/* End of file html_helper.php */
/* Location: ./system/helpers/html_helper.php */