<commit_before><?php

require_once dirname(__FILE__).'/../config.php';
Config::init();

# Templates helpers

# version of array_merge_recursive without overwriting numeric keys
# picked from
# http://www.php.net/manual/fr/function.array-merge-recursive.php#106985
function array_merge_recursive_new() {

    $arrays = func_get_args();
    $base = array_shift($arrays);

    foreach ($arrays as $array) {
        reset($base); //important
        while (list($key, $value) = @each($array)) {
            if (is_array($value) && @is_array($base[$key])) {
                $base[$key] = array_merge_recursive_new($base[$key], $value);
            } else {
                $base[$key] = $value;
            }
        }
    }

    return $base;
}

# Returns an array for site.global_links.others in function of user's state,
# i.e. connected or not
function global_menu_links() {

    if (!is_connected()) {
        return array(
            'site' => array(
                'global_links' => array(
                    'others' => array(
                        array( 'href' => Config::$root_uri.'connexion', 'title' => 'Connexion' )
                    )
                )
            )
        );
    }

    return array(
        'site' => array(
            'global_links' => array(
                'others' => array(
                    array( 'href' => Config::$root_uri.'forum',       'title' => 'Forum' ),
                    array( 'href' => Config::$root_uri.'profile',     'title' => 'Mon Profil'),
                    array( 'href' => Config::$root_uri.'?disconnect', 'title' => 'Déconnexion')
                )
            )
        )
    );
}

# Merge default templates values with the given
# array, and return a new array.
function tpl_array() {
    $arrays = func_get_args();
    array_unshift(&$arrays, global_menu_links());
    array_unshift(&$arrays, Config::$default_tpl_values);
    return call_user_func_array('array_merge_recursive_new', $arrays);
}


// shortcut
function tpl_render($tp, $values) {
    return Config::$tpl->render($tp, tpl_array($values));
}

?>
<commit_msg>tpl_date helper added<commit_after><?php

require_once dirname(__FILE__).'/../config.php';
Config::init();

# Templates helpers

# version of array_merge_recursive without overwriting numeric keys
# picked from
# http://www.php.net/manual/fr/function.array-merge-recursive.php#106985
function array_merge_recursive_new() {

    $arrays = func_get_args();
    $base = array_shift($arrays);

    foreach ($arrays as $array) {
        reset($base); //important
        while (list($key, $value) = @each($array)) {
            if (is_array($value) && @is_array($base[$key])) {
                $base[$key] = array_merge_recursive_new($base[$key], $value);
            } else {
                $base[$key] = $value;
            }
        }
    }

    return $base;
}

# Returns an array for site.global_links.others in function of user's state,
# i.e. connected or not
function global_menu_links() {

    if (!is_connected()) {
        return array(
            'site' => array(
                'global_links' => array(
                    'others' => array(
                        array( 'href' => Config::$root_uri.'connexion', 'title' => 'Connexion' )
                    )
                )
            )
        );
    }

    return array(
        'site' => array(
            'global_links' => array(
                'others' => array(
                    array( 'href' => Config::$root_uri.'forum',       'title' => 'Forum' ),
                    array( 'href' => Config::$root_uri.'profile',     'title' => 'Mon Profil'),
                    array( 'href' => Config::$root_uri.'?disconnect', 'title' => 'Déconnexion')
                )
            )
        )
    );
}

# Merge default templates values with the given
# array, and return a new array.
function tpl_array() {
    $arrays = func_get_args();
    array_unshift(&$arrays, global_menu_links());
    array_unshift(&$arrays, Config::$default_tpl_values);
    return call_user_func_array('array_merge_recursive_new', $arrays);
}


// shortcut
function tpl_render($tp, $values) {
    return Config::$tpl->render($tp, tpl_array($values));
}

// return an array which represents a date
function tpl_date($d) {
  return array( 'date' => date_fr($d), 'datetime_attr' => datetime_attr($d));
}

?>

{'fraction_non_alphanumeric': 0.1534744592728946, 'fraction_numerical': 0.0027611596870685687, 'mean_word_length': 2.234375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4352888', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1316, 'n_words': 275}