<commit_before><?php
namespace mobilejazz\yii2\cms\frontend\components;

use mobilejazz\yii2\cms\common\models\ContentSlug;
use mobilejazz\yii2\cms\common\models\Locale;
use mobilejazz\yii2\cms\common\models\UrlRedirect;
use yii;
use yii\base\InvalidConfigException;
use yii\base\Object;
use yii\helpers\ArrayHelper;
use yii\web\Request;
use yii\web\UrlRuleInterface;

class FrontendUrlRules extends Object implements UrlRuleInterface
{

    public $baseUrl;

    public $translationCategory = 'url';

    public $staticRoutes = [];

    public $module = 'cmsfrontend';

    private $_hostInfo;

    private $initialised = false;

    private $_staticRoutes = [
        ''                       => 'cmsfrontend/site/index',
        '/'                      => 'cmsfrontend/site/index',
        'set-locale'             => 'cmsfrontend/site/set-locale',
        'about'                  => 'cmsfrontend/site/about',
        'search'                 => 'cmsfrontend/site/search',
        'contact-us'             => 'cmsfrontend/site/contact',
        'sitemap'                => 'cmsfrontend/site/sitemap',
        'login'                  => 'cmsfrontend/site/login',
        'logout'                 => 'cmsfrontend/site/logout',
        'profile'                => 'cmsfrontend/site/profile',
        'signup'                 => 'cmsfrontend/site/signup',
        'request-password-reset' => 'cmsfrontend/site/request-password-reset',
        'reset-password'         => '<PASSWORD>',
        'send-mail'              => 'cmsfrontend/site/send-confirmation-mail',
        'submit'                 => 'cmsfrontend/webform/submission/submit'
    ];


    public function createBaseUrl($route, $params)
    {
        $url = $this->createUrl(null, $route, $params);

        if ($url == false)
        {
            $url = Yii::$app->urlManager->getBaseUrl();
        }

        if (strpos($url, '://') === false)
        {
            $url = $this->getHostInfo() . $url;
        }

        return $url;
    }


    /**
     * Creates a URL according to the given route and parameters.
     *
     * @param \yii\web\UrlManager $manager the URL manager
     * @param string              $route   the route. It should not have slashes at the beginning or the end.
     * @param array               $params  the parameters
     *
     * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
     */
    public function createUrl($manager, $route, $params)
    {

        $this->init();

        $slug = $params[ 'slug' ];
        $lang = $params[ 'lang' ];

        Yii::trace("Creating url for route = $route, slug = $slug, lang = $lang", __METHOD__);

        //If a parameter is defined and not empty - add it to the URL
        $url = '';

        if (array_key_exists('lang', $params) || array_key_exists('slug', $params))
        {
            if (array_key_exists('lang', $params) && !empty($params[ 'lang' ]))
            {
                if (Locale::isMultiLanguageSite())
                {
                    $url .= '/' . $params[ 'lang' ];
                }
            }

            if (array_key_exists('slug', $params) && !empty($params[ 'slug' ]))
            {
                if (Locale::isMultiLanguageSite())
                {
                    $url .= '/' . $params[ 'slug' ];
                }
                else<commit_msg>Further adjustment to frontend url rules<commit_after><?php
namespace mobilejazz\yii2\cms\frontend\components;

use mobilejazz\yii2\cms\common\models\ContentSlug;
use mobilejazz\yii2\cms\common\models\Locale;
use mobilejazz\yii2\cms\common\models\UrlRedirect;
use yii;
use yii\base\InvalidConfigException;
use yii\base\Object;
use yii\helpers\ArrayHelper;
use yii\web\Request;
use yii\web\UrlRuleInterface;

class FrontendUrlRules extends Object implements UrlRuleInterface
{

    public $baseUrl;

    public $translationCategory = 'url';

    public $staticRoutes = [];

    public $module = 'cmsfrontend';

    private $_hostInfo;

    private $initialised = false;

    private $_staticRoutes = [
        ''                       => 'cmsfrontend/site/index',
        '/'                      => 'cmsfrontend/site/index',
        'set-locale'             => 'cmsfrontend/site/set-locale',
        'about'                  => 'cmsfrontend/site/about',
        'search'                 => 'cmsfrontend/site/search',
        'contact-us'             => 'cmsfrontend/site/contact',
        'sitemap'                => 'cmsfrontend/site/sitemap',
        'login'                  => 'cmsfrontend/site/login',
        'logout'                 => 'cmsfrontend/site/logout',
        'profile'                => 'cmsfrontend/site/profile',
        'signup'                 => 'cmsfrontend/site/signup',
        'request-password-reset' => 'cmsfrontend/site/request-password-reset',
        'reset-password'         => '<PASSWORD>',
        'send-mail'              => 'cmsfrontend/site/send-confirmation-mail',
        'submit'                 => 'cmsfrontend/webform/submission/submit'
    ];


    public function createBaseUrl($route, $params)
    {
        $url = $this->createUrl(null, $route, $params);

        if ($url == false)
        {
            $url = Yii::$app->urlManager->getBaseUrl();
        }

        if (strpos($url, '://') === false)
        {
            $url = $this->getHostInfo() . $url;
        }

        return $url;
    }


    /**
     * Creates a URL according to the given route and parameters.
     *
     * @param \yii\web\UrlManager $manager the URL manager
     * @param string              $route   the route. It should not have slashes at the beginning or the end.
     * @param array               $params  the parameters
     *
     * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
     */
    public function createUrl($manager, $route, $params)
    {

        $this->init();

        //If a parameter is defined and not empty - add it to the URL
        $url = '';

        if (array_key_exists('lang', $params) || array_key_exists('slug', $params))
        {
            if (array_key_exists('lang', $params) && !empty($params[ 'lang' ]))
            {
                if (Locale::isMultiLanguageSite())
                {
                    $url .= '/' . $params[ 'lang' ];
                }
            }

            if (array_key_exists('slug', $params) && !empty($params[ 'slug' ]))
            {
                if (Locale::isMultiLanguageSite())
                {
                    $url .= '/' . $params[ 'slug' ];
                }
                else
{'fraction_non_alphanumeric': 0.13507821901323708, 'fraction_numerical': 0.0012033694344163659, 'mean_word_length': 1.7463857909954563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4143278', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1900, 'n_words': 408}