Get current page or the referer if executing a WP AJAX request.

@author Vova Feldman (@svovaf)
@since  1.2.1.8

@return string
777410
static function get_current_page() {
            if ( ! isset( self::$_pagenow ) ) {
                global $pagenow;
                if ( empty( $pagenow ) && is_admin() && is_multisite() ) {
                    /**
                     * It appears that `$pagenow` is not yet initialized in some network admin pages when this method
                     * is called, so initialize it here using some pieces of code from `wp-includes/vars.php`.
                     *
                     * @author Leo Fajardo (@leorw)
                     * @since 2.2.3
                     */
                    if ( is_network_admin() ) {
                        preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
                    } else if ( is_user_admin() ) {
                        preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
                    } else {
                        preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
                    }

                    $pagenow = $self_matches[1];
                    $pagenow = trim( $pagenow, '/' );
                    $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
                    if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
                        $pagenow = 'index.php';
                    } else {
                        preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
                        $pagenow = strtolower( $self_matches[1] );
                        if ( '.php' !== substr($pagenow, -4, 4) )
                            $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
                    }
                }

                self::$_pagenow = $pagenow;

                if ( self::is_ajax() &&
                     'admin-ajax.php' === $pagenow
                ) {
                    $referer = fs_get_raw_referer();

                    if ( is_string( $referer ) ) {
                        $parts = explode( '?', $referer );

                        self::$_pagenow = basename( $parts[0] );
                    }
                }
            }

            return self::$_pagenow;
        }
438337
public static function currentPage() {
		$uri = static::to(static::detectPath());
		foreach ($_GET as $k => $v) {
			$uri->param($k, $v);
		}

		return $uri;
	}
229005
public function get()
    {
        if ($this->page_count <= 1) {
            return '';
        }

        // Output HTML holder.
        $output = '';

        $output .= $this->get_opening_links();
        $output .= $this->get_links();
        $output .= $this->get_closing_links();

        // Apply before and after content if present in the args.
        if (! empty($output)) {
            $output = $this->args['before_output'] . $output . $this->args['after_output'];
        }

        /**
         * Filter snap_pagination output.
         *
         * @since  1.0.0
         *
         * @var string $output The output HTML for the pagination.
         * @return  string The filtered HTML.
         */
        $output = apply_filters('snap_pagination_output', $output);

        return $output;
    }
743961
public static function getCurrentAction()
    {
        $request = Request::instance();
        return $request->module() . '/' . $request->controller() . '/' . $request->action();
    }
1319417
public function fetchRefererUrl(): string
    {
        $url = $this->session->get($this->refererUrlKey, '');
        $this->session->remove($this->refererUrlKey);

        return $url;
    }
1137363
public function currentUrl()
    {
        $context = $this->contextObject();

        if ($context && isset($context['url'])) {
            return $this->createAbsoluteUrl($context['url']);
        }

        return null;
    }
930411
public function current()
    {
        if (!$this->page) {
            $this->page = $this->executeCall();
        }

        if (isset($this->page['prefixes'])) {
            $this->updatePrefixes();
        }

        return $this->get($this->itemsPath, $this->page);
    }
218792
public function getCurrent()
    {
        if (is_null($this->current))
        {
            $siteView = $this->makeNewViewModel();

            $this->current = $siteView;
        }

        return $this->current;
    }
732386
private function currentURL() {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $pageURL;
    }
769964
protected function get_current_url()
    {
        // When running from commandline the REQUEST_URI is missing.
        if (!isset($_SERVER['REQUEST_URI'])) {
            return null;
        }

        // HTTP_HOST is a client-supplied header that is optional in HTTP 1.0
        $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']
            : (!empty($_SERVER['LOCAL_ADDR'])  ? $_SERVER['LOCAL_ADDR']
            : (!empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '')));

        $httpS = $this->isHttps() ? 's' : '';
        return "http{$httpS}://{$host}{$_SERVER['REQUEST_URI']}";
    }
634325
public function get_handler()
    {
        $handler = new PrettyPageHandler();
            
        $handler->addDataTableCallback('$wp_query', [$this, 'add_query']);

        $handler->addDataTableCallback('$post', [$this, 'add_post']);

        $handler->addDataTableCallback('$wp', [$this, 'add_wp']);

        return $handler;
    }
546237
public function getPage() {
    $page = $this->traverse($this->pageMap, Server::getRequestUriParts());
    if ($page === null) {
      return null;
    }
    return $this->createWebPageFromClassName($page);
  }
960377
public static function getCurrentUrl()
    {
        if (isset($_SERVER['HTTPS']) &&
            ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
            isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
            $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
            $protocol = 'https';
        }
        else {
            $protocol = 'http';
        }

        return "$protocol://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    }
1260549
public function current()
  {
    // Work around pre-PHP 5.5 issue that prevents `empty($this->count())`:
    if (!isset($this->_objects)) {
      $this->_loadFrom($this->_href);
    }

    if ($this->_position >= sizeof($this->_objects)) {
      if (isset($this->_links['next'])) {
        $this->_loadFrom($this->_links['next']);
        $this->_position = 0;
      }
      else if (empty($this->_objects) && ($this->_position == 0)) {
        return null;
      }
      else {
        throw new Recurly_Error("Pager is not in a valid state");
      }
    }

    return $this->_objects[$this->_position];
  }
274360
private function getRefererId()
    {
        return $this->trackIfEnabled('referers', function () {
            return $this->getRefererTracker()->track(
                $this->request->headers->get('referer'),
                $this->request->url()
            );
        });
    }
1333648
public static function isFrontendAjax()
    {
        if (self::isAjax()) {
            $referer = '';
            $filename = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';

            if (!empty($_REQUEST['_wp_http_referer'])) {
                $referer = wp_unslash($_REQUEST['_wp_http_referer']);
            } elseif (!empty($_SERVER['HTTP_REFERER'])) {
                $referer = wp_unslash($_SERVER['HTTP_REFERER']);
            }

            return strpos($referer, admin_url()) === false && basename($filename) === 'admin-ajax.php';
        }

        return false;
    }
876516
protected function currentInternal()
    {
        return $this->current ? Alias::getAlias($this->current) : $this->request->getAbsoluteUrl();
    }