public static function getUrl($lng, $object = NULL)
    {
        if (!self::exists($lng)) {
            return false;
        }

        // Default path
        $res = '/'. $lng .'/';

        $router = Router::getInstance();
        $current_page = $router->getPageData();
        $path = $router->getPath();

        // Try to find by same label
        $page_url_by_label = Structure::getPathByLabel($current_page['string_label'], $lng, false);
        if ($page_url_by_label) {
            $res = $page_url_by_label;
        } else {
            // No label page, compose path by location
            $p = [];
            foreach ($path as $v) {
                if (isset($v['location'])) {
                    $p[] = $v['location'];
                }
            }
            $p[0] = $lng;
            $p = '/' . implode('/', $p) . '/';

            // If have page in Structure
            if (Structure::getIdByPath($p)) {
                $res = $p;
            }
        }

        $skip_get_path = false;
        if ($object) {
            $object_slug = $object->getSlugUrl($lng);
            if ($object_slug) {
                $res .= $object_slug . '/';
            }
            $skip_get_path = true;
        }

        // $_GET in path
        $so = count($_GET);
        $path_gets = [];
        $param_get = $_GET;
        $skip = false;

        for ($i = 0; $i < $so; $i++) {
            // Skip next if non-next
            if ($skip) {
                continue;
            }

            if (isset($_GET[$i])) {
                if(!$skip_get_path)
                    $path_gets[] = $_GET[$i];
                unset($param_get[$i]);
            } else {
                $skip = true;
            }
        }

        // If have transparent get
        if ($path_gets) {
            $res .= implode('/', $path_gets) . '/';
        }

        // If have usual get params
        if ($param_get) {
            $res .= '?' . http_build_query($param_get);
        }

        return $res;
    }
public static function getUrl($lng, $object = NULL)
    {
        if (!self::exists($lng)) {
            return false;
        }

        // Default path
        $res = '/'. $lng .'/';

        $router = Router::getInstance();
        $current_page = $router->getPageData();
        $path = $router->getPath();

        // Try to find by same label
        $page_url_by_label = Structure::getPathByLabel($current_page['string_label'], $lng, false);
        if ($page_url_by_label) {
            $res = $page_url_by_label;
        } else {
            // No label page, compose path by location
            $p = [];
            foreach ($path as $v) {
                if (isset($v['location'])) {
                    $p[] = $v['location'];
                }
            }
            $p[0] = $lng;
            $p = '/' . implode('/', $p) . '/';

            // If have page in Structure
            if (Structure::getIdByPath($p)) {
                $res = $p;
            }
        }

        $skip_get_path = false;
        if ($object) {
            $object_slug = $object->getSlugUrl($lng);
            if ($object_slug) {
                $res .= $object_slug . '/';
            }
            $skip_get_path = true;
        }

        // $_GET in path
        $so = count($_GET);
        $path_gets = [];
        $param_get = $_GET;
        $skip = false;

        for ($i = 0; $i < $so; $i++) {
            // Skip next if non-next
            if ($skip) {
                continue;
            }

            if (isset($_GET[$i])) {
                if(!$skip_get_path)
                    $path_gets[] = $_GET[$i];
                unset($param_get[$i]);
            } else {
                $skip = true;
            }
        }

        // If have transparent get
        if ($path_gets) {
            $res .= implode('/', $path_gets) . '/';
        }

        // If have usual get params
        if ($param_get) {
            $res .= '?' . http_build_query($param_get);
        }

        return $res;
    }
public static function getUrl ( $ lng , $ object = NULL ) { if ( ! self :: exists ( $ lng ) ) { return false ; } // Default path $ res = '/' . $ lng . '/' ; $ router = Router :: getInstance ( ) ; $ current_page = $ router -> getPageData ( ) ; $ path = $ router -> getPath ( ) ; // Try to find by same label $ page_url_by_label = Structure :: getPathByLabel ( $ current_page [ 'string_label' ] , $ lng , false ) ; if ( $ page_url_by_label ) { $ res = $ page_url_by_label ; } else { // No label page, compose path by location $ p = [ ] ; foreach ( $ path as $ v ) { if ( isset ( $ v [ 'location' ] ) ) { $ p [ ] = $ v [ 'location' ] ; } } $ p [ 0 ] = $ lng ; $ p = '/' . implode ( '/' , $ p ) . '/' ; // If have page in Structure if ( Structure :: getIdByPath ( $ p ) ) { $ res = $ p ; } } $ skip_get_path = false ; if ( $ object ) { $ object_slug = $ object -> getSlugUrl ( $ lng ) ; if ( $ object_slug ) { $ res .= $ object_slug . '/' ; } $ skip_get_path = true ; } // $_GET in path $ so = count ( $ _GET ) ; $ path_gets = [ ] ; $ param_get = $ _GET ; $ skip = false ; for ( $ i = 0 ; $ i < $ so ; $ i ++ ) { // Skip next if non-next if ( $ skip ) { continue ; } if ( isset ( $ _GET [ $ i ] ) ) { if ( ! $ skip_get_path ) $ path_gets [ ] = $ _GET [ $ i ] ; unset ( $ param_get [ $ i ] ) ; } else { $ skip = true ; } } // If have transparent get if ( $ path_gets ) { $ res .= implode ( '/' , $ path_gets ) . '/' ; } // If have usual get params if ( $ param_get ) { $ res .= '?' . http_build_query ( $ param_get ) ; } return $ res ; }
Gets url of same page for selected language
@param string $lng language to get page link to
@param null|Entity $object to postfix path
@return bool|string path to page in selected language
Gets url of same page for selected language