You are here

public static function InstapageCmsPluginHelper::extractSlug in Instapage plugin 8.3

Same name and namespace in other branches
  1. 7.3 core/InstapageCmsPluginHelper.php \InstapageCmsPluginHelper::extractSlug()

Extracts a slug from current URL. Slug will be compared with values stored in plugin's database to find a landing page to display.

Parameters

string $homeUrl URL of the home page.:

Return value

string Trimmed slug, ready to compare with values stored in the DB.

4 calls to InstapageCmsPluginHelper::extractSlug()
InstapageCmsPluginDrupal7Connector::checkCustomUrl in core/connectors/InstapageCmsPluginDrupal7Connector.php
Checks (and displays) if a landing page hould be displayed instead of normal CMS page under current URL.
InstapageCmsPluginDrupal8Connector::checkCustomUrl in core/connectors/InstapageCmsPluginDrupal8Connector.php
Checks (and displays) if a landing page hould be displayed instead of normal CMS page under current URL.
InstapageCmsPluginHelper::isCustomParamPresent in core/InstapageCmsPluginHelper.php
Checks if one of the custom params, stored in plugin's settings, are present in curent URL.
InstapageCmsPluginWPConnector::checkCustomUrl in core/connectors/InstapageCmsPluginWPConnector.php
Checks (and displays) if a landing page hould be displayed instead of normal CMS page under current URL.

File

core/InstapageCmsPluginHelper.php, line 286

Class

InstapageCmsPluginHelper
Helper containing commonly used static functions.

Code

public static function extractSlug($homeUrl) {
  $uriSegments = explode('?', $_SERVER['REQUEST_URI']);
  self::writeDiagnostics($uriSegments, 'checkCustomUrl: $uriSegments');
  $path = trim(parse_url($homeUrl, PHP_URL_PATH), '/');
  $segment = trim($uriSegments[0], '/');
  if ($path) {
    $pos = strpos($segment, $path);
    if ($pos !== false) {
      $segment = substr_replace($segment, '', $pos, strlen($path));
    }
  }
  $slug = trim($segment, '/');

  // removing duplicated slashes from obtained almost final slug form
  $slug = preg_replace('~\\/{2,}~', '/', $slug);
  self::writeDiagnostics($slug, 'checkCustomUrl: $slug');
  return $slug;
}