Menu page URL.

@since 160712 Menu page utils.

@param string       $page_path  Page (or path).
@param array|string $query_args Query args (or tab).
@param string       $context    `admin`, `network`, `self`.

@return string Current menu page.
484506
public function url(string $page_path = '', $query_args = [], string $context = ''): string
    {
        switch ($context) {
            case 'admin':
                $admin_url = 'admin_url';
                break;

            case 'network':
                $admin_url = 'network_admin_url';
                break;

            case 'self':
            default: // Default case handler.
                $admin_url = 'self_admin_url';
                break;
        }
        if (!is_array($query_args)) {
            if ($query_args && is_string($query_args)) {
                $query_args = ['tab' => $query_args];
            } else {
                $query_args = []; // Force array.
            }
        } // ↑ Tab as 2nd parameter if it's a string.

        $_tmp_query_args = $query_args;
        $query_args      = []; // Reinitialize.

        $brand_slug       = $this->App->Config->©brand['©slug'];
        $brand_short_slug = $this->App->Config->©brand['©short_slug'];

        $brand_var       = $this->App->Config->©brand['©var'];
        $brand_short_var = $this->App->Config->©brand['©short_var'];

        foreach ($_tmp_query_args as $_key => $_value) {
            if ($_key && is_string($_key)) {
                $_key = str_replace('~', $brand_var, $_key);
                $_key = str_replace('%', $brand_short_var, $_key);
            }
            if ($_value && is_string($_value)) {
                $_value = str_replace('~', $brand_slug, $_value);
                $_value = str_replace('%', $brand_short_slug, $_value);
            }
            $query_args[$_key] = $_value; // New `key` => `value`.
        } // unset($_tmp_query_args, $_key, $_value); // Housekeeping.

        $page_path = $page_path ?: $brand_slug;
        $page_path = str_replace('~', $brand_slug, $page_path);
        $page_path = str_replace('%', $brand_short_slug, $page_path);

        if (!$page_path || $page_path[0] === '/' || mb_stripos($page_path, '.php') !== false) {
            $path       = '/'.$this->c::mbLTrim($page_path, '/');
            return $url = $this->c::addUrlQueryArgs($query_args, $admin_url($path));
            //
        } else { // Treat as `?page` instead of a path.
            $page       = $this->c::mbTrim($page_path, '/');
            $query_args = array_merge(['page' => $page], $query_args);
            return $url = $this->c::addUrlQueryArgs($query_args, $admin_url('/admin.php'));
        }
    }
922917
public function handlePagination($args)
    {
        $uri = $args['uri'];
        $current = $args['current'];
        $total = $args['total'];
        $limit = $args['limit'];

        $uri   = preg_replace('/offset=([0-9]+)/', '', $uri);
        $pages = ceil($total / $limit);
        $page  = $current;

        if ($pages < 2) {
            return;
        }

        $start = 1;

        if ($page >= 3) {
            $start = $page - 2;
        }

        $rtn = '<ul class="pagination">';

        $rtn .= $this->getPaginationPrevLink($page, $uri);

        for ($i = 0; $i < 5 && ($start + $i) <= $pages; $i++) {
            $num = $start + $i;
            $cls = ($page == $num ? 'active' : '');
            $rtn .= '<li class="' . $cls . '"><a href="' . $uri . 'p=' . $num . '">' . $num . '</a></li>';
        }

        $rtn .= $this->getPaginationNextLink($page, $uri, $pages);

        $rtn .= '</ul>';

        return $rtn;
    }
1183927
public static function currentUrl( $includeQuery = true, $includePath = true )
    {
        //	Are we SSL? Check for load balancer protocol as well...
        $_port = intval( Option::get( $_SERVER, 'HTTP_X_FORWARDED_PORT', Option::get( $_SERVER, 'SERVER_PORT', 80 ) ) );
        $_protocol = Option::get( $_SERVER, 'HTTP_X_FORWARDED_PROTO', 'http' . ( Option::getBool( $_SERVER, 'HTTPS' ) ? 's' : null ) ) . '://';
        $_host = Option::get( $_SERVER, 'HTTP_X_FORWARDED_HOST', Option::get( $_SERVER, 'HTTP_HOST', gethostname() ) );
        $_parts = parse_url( $_protocol . $_host . Option::get( $_SERVER, 'REQUEST_URI' ) );

        if ( ( empty( $_port ) || !is_numeric( $_port ) ) && null !== ( $_parsePort = Option::get( $_parts, 'port' ) ) )
        {
            $_port = @intval( $_parsePort );
        }

        if ( null !== ( $_query = Option::get( $_parts, 'query' ) ) )
        {
            $_query = static::urlSeparator( $_query ) . http_build_query( explode( '&', $_query ) );
        }

        if ( false !== strpos( $_host, ':' ) || ( $_protocol == 'https://' && $_port == 443 ) || ( $_protocol == 'http://' && $_port == 80 ) )
        {
            $_port = null;
        }
        else
        {
            $_port = ':' . $_port;
        }

        if ( false !== strpos( $_host, ':' ) )
        {
            $_port = null;
        }

        $_currentUrl =
            $_protocol .
            $_host .
            $_port .
            ( true === $includePath ? Option::get( $_parts, 'path' ) : null ) .
            ( true === $includeQuery ? $_query : null );

        if ( \Kisma::get( 'debug.curl.current_url' ) )
        {
            Log::debug( 'Parsed current URL to be: ' . $_currentUrl, $_parts );
        }

        return $_currentUrl;
    }
839689
private function url($page)
	{
		$param=$this->param;
		$param[$this->pageField]=$page;
		echo Dispatch::url($this->rule,$param);
	}
1182242
public function page_links($path='?', $ext=null)
    {
        $adjacents="2";
        $prev=$this->_page - 1;
        $next=$this->_page + 1;
        $lastpage=ceil($this->_totalRows / $this->_perPage);
        $lpm1=$lastpage - 1;
        $pagination="";
        if ($lastpage > 1)
        {
            if ($ext == null) {
                $ext=$this->getParam();
            }
            $pagination.="<ul class='pager'>";
            if ($this->_page > 1) {
                            $pagination.="<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>";
            } else {
                            $pagination.="<li class='disabled previous'><span class='disabled'><<</span></li>";
            }

            if ($lastpage < 7 + ($adjacents * 2))
            {
                for ($counter=1; $counter <= $lastpage; $counter++)
                {
                    if ($counter == $this->_page) {
                                            $pagination.="<li class='current'><span>$counter</span></li>";
                    } else {
                                            $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>";
                    }
                }
            } elseif ($lastpage > 5 + ($adjacents * 2))
            {
                if ($this->_page < 1 + ($adjacents * 2))
                {
                    for ($counter=1; $counter < 4 + ($adjacents * 2); $counter++)
                    {
                        if ($counter == $this->_page) {
                                                    $pagination.="<li class='current'><span>$counter</span></li>";
                        } else {
                                                    $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>";
                        }
                    }
                    $pagination.="...";
                    $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>";
                    $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>";
                } elseif ($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2))
                {
                    $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>";
                    $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>";
                    $pagination.="...";
                    for ($counter=$this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++)
                    {
                        if ($counter == $this->_page) {
                                                    $pagination.="<li class='current'><span>$counter</span></li>";
                        } else {
                                                    $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>";
                        }
                    }
                    $pagination.="..";
                    $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>";
                    $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>";
                } else
                {
                    $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>";
                    $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>";
                    $pagination.="..";
                    for ($counter=$lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                    {
                        if ($counter == $this->_page) {
                                                    $pagination.="<li class='current'><span>$counter</span></li>";
                        } else {
                                                    $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>";
                        }
                    }
                }
            }

            if ($this->_page < $counter - 1) {
                            $pagination.="<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>";
            } else {
                            $pagination.="<li class='next disabled'><span class='disabled'>>></span></li>";
            }
            $pagination.="</ul>\n";
        }


        return $pagination;
    }
225522
protected function _actionBrowse(AnCommandContext $context)
    {
        if (!$context->query) {
            $context->query = $this->getRepository()->getQuery();
        }

        $query = $context->query;

        if ($this->q) {
            $query->keyword = $this->getService('anahita:filter.term')->sanitize($this->q);
        }

        if ($this->hasBehavior('parentable') && $this->getParent()) {
            $query->parent($this->getParent());
        }

        if ($this->hasBehavior('ownable') && $this->hasBehavior('pinnable')) {
            $owner = $this->getActor();
            if (isset($owner)) {
                $query->order('pinned', 'DESC');
            }
        }

        switch ($this->sort) {
            case 'top':
                $identifierName = $this->_mixer->getIdentifier()->name;
                $query->order('(COALESCE('.$identifierName.'.comment_count,0) + COALESCE('.$identifierName.'.vote_up_count,0) + COALESCE('.$identifierName.'.subscriber_count,0) + COALESCE('.$identifierName.'.follower_count,0))', 'DESC');
            break;

            case 'updated':
                $query->order('updateTime', 'DESC');
            break;

            case 'oldest':
                $query->order('creationTime', 'ASC');
            break;

            case 'recent':
            case 'newest':
                $query->order('creationTime', 'DESC');
            break;
        }

        $query->limit($this->limit, $this->start);

        return $this->getState()->setList($query->toEntityset())->getList();
    }
557481
public function currentPageUrl($parameters = [], $routePersistence = true)
    {
        if (!$currentFile = $this->page->getFileName()) {
            return null;
        }

        return $this->pageUrl($currentFile, $parameters, $routePersistence);
    }
447766
protected function _addPageNrParam($url, $page, $languageId = null)
    {
        if ($page) {
            if ((strpos($url, 'pgNr='))) {
                $url = preg_replace('/pgNr=[0-9]*/', 'pgNr=' . $page, $url);
            } else {
                $url .= ((strpos($url, '?') === false) ? '?' : '&amp;') . 'pgNr=' . $page;
            }
        } else {
            $url = preg_replace('/pgNr=[0-9]*/', '', $url);
            $url = preg_replace('/\&amp\;\&amp\;/', '&amp;', $url);
            $url = preg_replace('/\?\&amp\;/', '?', $url);
            $url = preg_replace('/\&amp\;$/', '', $url);
        }

        return $url;
    }
512116
def pages_breadcrumb(context, page, url='/'):
    
    lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)
    page = get_page_from_string_or_id(page, lang)
    pages_navigation = None
    if page:
        pages_navigation = page.get_ancestors()
    context.update({'pages_navigation': pages_navigation, 'page': page})
    return context
987979
private function _build_uri($page) {

        // if page propagation method is through SEO friendly URLs
        if ($this->_properties['method'] == 'url') {

            // see if the current page is already set in the URL
            if (preg_match('/\b' . $this->_properties['variable_name'] . '([0-9]+)\b/i', $this->_properties['base_url']) > 0) {

                // build string
                $url = str_replace('//', '/', preg_replace(

                    // replace the currently existing value
                    '/\b' . $this->_properties['variable_name'] . '([0-9]+)\b/i',

                    // if on the first page, remove it in order to avoid duplicate content
                    ($page == 1 ? '' : $this->_properties['variable_name'] . $page),

                    $this->_properties['base_url']

                ));

            // if the current page is not yet in the URL, set it, unless we're on the first page
            // case in which we don't set it in order to avoid duplicate content
            } else $url = rtrim($this->_properties['base_url'], '/') . '/' . ($this->_properties['variable_name'] . $page);

            // handle trailing slash according to preferences
            $url = rtrim($url, '/') . ($this->_properties['trailing_slash'] ? '/' : '');

            // if values in the query string - other than those set through base_url() - are not to be preserved
            // preserve only those set initially
            if (!$this->_properties['preserve_query_string']) $query = implode('&', $this->_properties['base_url_query']);

            // otherwise, get the current query string
            else $query = $_SERVER['QUERY_STRING'];

            // return the built string also appending the query string, if any
            return $url . ($query != '' ? '?' . $query : '');

        // if page propagation is to be done through GET
        } else {

            // if values in the query string - other than those set through base_url() - are not to be preserved
            // preserve only those set initially
            if (!$this->_properties['preserve_query_string']) $query = $this->_properties['base_url_query'];

            // otherwise, get the current query string, if any, and transform it to an array
            else parse_str($_SERVER['QUERY_STRING'], $query);

            // if we are avoiding duplicate content and if not the first/last page (depending on whether the pagination links are shown in natural or reversed order)
            if (!$this->_properties['avoid_duplicate_content'] || ($page != ($this->_properties['reverse'] ? $this->_properties['total_pages'] : 1)))

                // add/update the page number
                $query[$this->_properties['variable_name']] = $page;

            // if we are avoiding duplicate content, don't use the "page" variable on the first/last page
            elseif ($this->_properties['avoid_duplicate_content'] && $page == ($this->_properties['reverse'] ? $this->_properties['total_pages'] : 1))

                unset($query[$this->_properties['variable_name']]);

            // make sure the returned HTML is W3C compliant
            return htmlspecialchars(html_entity_decode($this->_properties['base_url']) . (!empty($query) ? '?' . urldecode(http_build_query($query)) : ''));

        }

    }
363701
def url(page)
      @base_url_params ||= begin
                             url_params = merge_get_params(default_url_params)
                             merge_optional_params(url_params)
                           end

      url_params = @base_url_params.dup
      add_current_page_param(url_params, page)

      # Add optional url_builder support
      (@options[:url_builder] || @template).url_for(url_params)
    end
1177380
protected function display_category_form($contexts, $pageurl, $current) {
        echo \html_writer::start_div('choosecategory');
        $catmenu = question_category_options($contexts, true, 0, true);
        echo \html_writer::label(get_string('selectacategory', 'question'), 'id_selectacategory');
        echo \html_writer::select($catmenu, 'category', $current, array(),
                array('class' => 'searchoptions custom-select', 'id' => 'id_selectacategory'));
        echo \html_writer::end_div() . "\n";
    }
1026188
def pages_siblings_menu(context, page, url='/'):
    
    lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)
    page = get_page_from_string_or_id(page, lang)
    if page:
        if page.parent:
            root = page.parent
        else:
            root = page
        children = root.get_children_for_frontend()
        context.update({'children': children, 'page': page})
    return context
601704
private function setCurrentPageUrl()
    {
        $controller = Url::segment(1);
        $method = '';
        $method = (Url::segment(2) == '') ? 'index' : Url::segment(2);

        $this->currentPageUrl = Url::getBase().$controller.'/'.$method;
    }
832418
public static function currentUrl(bool $includeQuery = true, bool $urlEncode = false)
    {
        if (RequestHelper::isCli()) {
            return null;
        }

        $url = static::protocolHostPort() . static::currentUri($includeQuery, $urlEncode);

        return $urlEncode ? urlencode($url) : $url;
    }
1072629
public static function currentUrl($includeQuery = true, $includePath = true)
    {
        //	Are we SSL? Check for load balancer protocol as well...
        $_port =
            intval(array_get($_SERVER, 'HTTP_X_FORWARDED_PORT', array_get($_SERVER, 'SERVER_PORT', 80)));
        $_protocol = array_get($_SERVER,
                'HTTP_X_FORWARDED_PROTO',
                'http' . (array_get_bool($_SERVER, 'HTTPS') ? 's' : null)) . '://';
        $_host =
            array_get($_SERVER, 'HTTP_X_FORWARDED_HOST', array_get($_SERVER, 'HTTP_HOST', gethostname()));
        $_parts = parse_url($_protocol . $_host . array_get($_SERVER, 'REQUEST_URI'));

        if ((empty($_port) || !is_numeric($_port)) && null !== ($_parsePort = array_get($_parts, 'port'))) {
            $_port = @intval($_parsePort);
        }

        if (null !== ($_query = array_get($_parts, 'query'))) {
            $_query = static::urlSeparator($_query) . http_build_query(explode('&', $_query));
        }

        if (false !== strpos($_host,
                ':') || ($_protocol == 'https://' && $_port == 443) || ($_protocol == 'http://' && $_port == 80)
        ) {
            $_port = null;
        } else {
            $_port = ':' . $_port;
        }

        if (false !== strpos($_host, ':')) {
            $_port = null;
        }

        $_currentUrl =
            $_protocol . $_host . $_port . (true === $includePath ? array_get($_parts, 'path')
                : null) . (true === $includeQuery ? $_query : null);

        return $_currentUrl;
    }
1016823
public function url($page)
	{
		if ($page <= 0) $page = 1;

		// If we have any extra query string key / value pairs that need to be added
		// onto the URL, we will put them in query string form and then attach it
		// to the URL. This allows for extra information like sortings storage.
		$parameters = [$this->pageName => $page];

		if (count($this->query) > 0)
		{
			$parameters = array_merge($this->query, $parameters);
		}

		return $this->path.'?'
		                .http_build_query($parameters, null, '&')
		                .$this->buildFragment();
	}