<commit_before><?php
/**
 * url Class
 *
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Helpers;

use Helpers\Session;
use Helpers\Inflector;

/**
 * Collection of methods for working with urls.
 */
class Url
{
    /**
     * Redirect to chosen url.
     *
     * @param string $url      the url to redirect to
     * @param bool   $fullpath if true use only url in redirect instead of using DIR
     * @param int $code the server status code for the redirection
     */
    public static function redirect($url = null, $fullpath = false, $code = 200)
    {
        $url = ($fullpath === false) ? DIR.$url : $url;

        if ($code == 200) {
            header('Location: '.$url);
        } else {
            header('Location: '.$url, true, $code);
        }
        exit;
    }

    /**
     * Detect the true URI
     *
     * * @return string parsed URI
     */
    public static function detectUri()
    {
        $requestUri = $_SERVER['REQUEST_URI'];
        $scriptName = $_SERVER['SCRIPT_NAME'];

        $pathName = dirname($scriptName);

        if (strpos($requestUri, $scriptName) === 0) {
            $requestUri = substr($requestUri, strlen($scriptName));
        } else if (strpos($requestUri, $pathName) === 0) {
            $requestUri = substr($requestUri, strlen($pathName));
        }

        $uri = parse_url($requestUri, PHP_URL_PATH);

        if (($uri == '/') || empty($uri)) {
            return '/';
        }

        return str_replace(array('//', '../'), '/', ltrim($uri, '/'));
    }

    /**
     * Created the absolute address to the assets folder.
     *
     * @param  string|null $module
     * @return string url to assets folder
     */
    public static function resourcePath($module = null)
    {
        if ($module !== null) {
            $path = sprintf('modules/%s/', Inflector::tableize($module));
        } else {
            $path = '';
        }

        return SITEURL .$path .'assets/';
    }

    /**
     * Created the absolute address to the template folder.
     *
     * @param  boolean $custom<commit_msg>Further improve the URI cleanup into Helpers\Url::detectUri()<commit_after><?php
/**
 * url Class
 *
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Helpers;

use Helpers\Session;
use Helpers\Inflector;

/**
 * Collection of methods for working with urls.
 */
class Url
{
    /**
     * Redirect to chosen url.
     *
     * @param string $url      the url to redirect to
     * @param bool   $fullpath if true use only url in redirect instead of using DIR
     * @param int $code the server status code for the redirection
     */
    public static function redirect($url = null, $fullpath = false, $code = 200)
    {
        $url = ($fullpath === false) ? DIR.$url : $url;

        if ($code == 200) {
            header('Location: '.$url);
        } else {
            header('Location: '.$url, true, $code);
        }
        exit;
    }

    /**
     * Detect the true URI
     *
     * * @return string parsed URI
     */
    public static function detectUri()
    {
        $requestUri = $_SERVER['REQUEST_URI'];
        $scriptName = $_SERVER['SCRIPT_NAME'];

        $pathName = dirname($scriptName);

        if (strpos($requestUri, $scriptName) === 0) {
            $requestUri = substr($requestUri, strlen($scriptName));
        } else if (strpos($requestUri, $pathName) === 0) {
            $requestUri = substr($requestUri, strlen($pathName));
        }

        $uri = parse_url(ltrim($requestUri, '/'), PHP_URL_PATH);

        if (! empty($uri)) {
            return str_replace(array('//', '../'), '/', $uri);
        }

        // Empty URI of homepage; internally encoded as '/'
        return '/';
    }

    /**
     * Created the absolute address to the assets folder.
     *
     * @param  string|null $module
     * @return string url to assets folder
     */
    public static function resourcePath($module = null)
    {
        if ($module !== null) {
            $path = sprintf('modules/%s/', Inflector::tableize($module));
        } else {
            $path = '';
        }

        return SITEURL .$path .'assets/';
    }

    /**
     * Created the absolute address to the template folder.
     *
     * @param  boolean $custom
{'fraction_non_alphanumeric': 0.14605418138987045, 'fraction_numerical': 0.004711425206124852, 'mean_word_length': 1.9985875706214689, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2813102', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1237, 'n_words': 355}