Check if a string matches the given url.

@param string $page
@param bool   $loose

@return bool
336886
protected function isOnPage($page, $loose = true)
    {
        $page = $loose ? $page : '^'.$page.'$';
        $page = str_replace('#', '\#', $page);

        return (bool) preg_match('#'.$page.'#', $this->request->path());
    }
125357
public function contains($pattern, $regexp = FALSE)
  {
    if(empty($pattern))
    {
      return TRUE;
    }

    if($regexp)
    {
      return (preg_match("/" . $pattern . "/i", $this->string)) ? TRUE : FALSE;
    }
    else
    {
      return (stristr($this->string, $pattern) !== FALSE) ? TRUE : FALSE;
    }
  }
114475
public function url($page = null, $arguments = array())
    {
        if (is_object($page) && $page instanceof URL) {
            // we receive URL
            return $page->setArguments($arguments);
        }
        if (is_array($page)) {
            $p = $page[0];
            unset($page[0]);
            $arguments = $page;
            $page = $p;
        }
        /** @type URL $url */
        $url = $this->add('URL');
        unset($this->elements[$url->short_name]); // garbage collect URLs
        if (strpos($page, 'http://') === 0 || strpos($page, 'https://') === 0) {
            $url->setURL($page);
        } else {
            $url->setPage($page);
        }

        return $url->setArguments($arguments);
    }
818578
public static function page($total, $perPage)
        {
            $page = (null === request()->getCrudNumPage()) ? 1 : request()->getCrudNumPage();

            // The page will be validated and adjusted if it is less than one or greater
            // than the last page. For example, if the current page is not an integer or
            // less than one, one will be returned. If the current page is greater than
            // the last page, the last page will be returned.
            if (is_numeric($page) && $page > $last = ceil($total / $perPage)) {
                return ($last > 0) ? $last : 1;
            }

            return (static::valid($page)) ? $page : 1;
        }
1152738
private function isLinkList(string $html): bool
    {
        if (preg_match('/<(?:ul|dl|ol)(.+?)<\/(?:ul|dl|ol)>/isu', $html, $matched)) {
            $listPart = $matched[1];
            $outside = preg_replace('/<(?:ul|dl)(.+?)<\/(?:ul|dl)>/isu', '', $html);
            $outside = preg_replace('/<.+?>/su', '', $outside);
            $outside = preg_replace('/\s+/su', ' ', $outside);
            $list = preg_split('/<li[^>]*>/u', $listPart);
            array_shift($list);

            $rate = $this->evaluateList($list);
            if ($rate == 1) {
                return false;
            }

            return strlen($outside) <= (strlen($html) / (45 / $rate));
        }

        return false;
    }
1314095
public function getUniqueness(Page $page, $url)
    {
        if (!$this->preserveUnicity) {
            return $url;
        }

        $pageRepository = $this->application->getEntityManager()->getRepository('BackBee\NestedNode\Page');
        if (null === $pageRepository->findOneBy(['_url' => $url, '_root' => $page->getRoot(), '_state' => $page->getUndeletedStates()])) {
            return $url;
        }

        $baseUrl = $url.'-%d';

        $matches = [];
        $existings = [];
        if (preg_match('#(.*)\/$#', $baseUrl, $matches)) {
            $baseUrl = $matches[1].'-%d/';
            $existings = $pageRepository->createQueryBuilder('p')
                    ->andRootIs($page->getRoot())
                    ->andWhere('p._url LIKE :url')
                    ->setParameter('url', $matches[1] . '%/')
                    ->getQuery()
                    ->getResult()
            ;
        } else {
            $existings = $this->application->getEntityManager()->getConnection()->executeQuery(
                'SELECT p.uid FROM page p LEFT JOIN section s ON s.uid = p.section_uid WHERE s.root_uid = :root AND p.url REGEXP :regex',
                [
                    'regex' => str_replace(['+'], ['[+]'], $url).'(-[0-9]+)?$',
                    'root'  => $page->getRoot()->getUid(),
                ]
            )->fetchAll();

            $uids = [];

            foreach ($existings as $existing) {
                $uids[] = $existing['uid'];
            }

            $existings = $pageRepository->findBy(['_uid' => $uids]);
        }

        $existingUrls = [];
        foreach ($existings as $existing) {
            if (!$existing->isDeleted() && $existing->getUid() !== $page->getUid()) {
                $existingUrls[] = $existing->getUrl(false);
            }
        }

        $count = 1;
        while (in_array($url, $existingUrls)) {
            $url = sprintf($baseUrl, $count++);
        }

        return $url;
    }
1295615
protected function _hasPage($model, $page)
    {
        $params = $this->params($model);

        return !empty($params) && $params[$page . 'Page'];
    }
980381
public static function giveMeLinks($page) {
		$result = [];
		$pattern = "/<a \s [^<]*? href \s*  = \s* (['|\"]) \s* ([^\\1]*?) (\\1) .*? > (.*?) <\/a\s*>/xis";

		if (preg_match_all($pattern, $page, $subject, PREG_SET_ORDER)) {
			foreach ($subject as $e) {
				$result[] = [
					'href' => $e[2],
					'anchor' => $e[4]
				];
			}
		}

		$subject = [];
		$pattern = "/<a \s [^<]*? href \s* = \s*([^'\"]+?) ( (\s[^>]*? >) | > ) (.*?) <\/a\s*>/xis";
		if (preg_match_all($pattern, $page, $subject, PREG_SET_ORDER)) {
			foreach ($subject as $e) {
				if (!in_array($e[1], \Set::extract('{n}.href', $result))) {
					$result[] = [
						'href' => $e[1],
						'anchor' => $e[4]
					];
				}
			}
		}
		return $result;
	}
232358
public function getText(Page $page = null)
    {
        $texts = array();
        $pages = $this->getPages();

        foreach ($pages as $index => $page) {
            /**
             * In some cases, the $page variable may be null.
             */
            if (is_null($page)) {
                continue;
            }
            if ($text = trim($page->getText())) {
                $texts[] = $text;
            }
        }

        return implode("\n\n", $texts);
    }
674214
public static function is($url, $regexp = false) {
        $r = self::getRouter();
        if ($regexp) {
            return preg_match('`^' . $url . '$`', $r->requestURL);
        }

        return $url == $r->requestURL;
    }
42811
public function deletePage(Page $page)
    {
        $findPage = $this->findPage($page);
        if ($findPage === false) {
            return false;
        }

        $deleteStm = $this->connection->prepare("DELETE FROM Page WHERE page_id=?");
        $deleteStm->execute([$page->getID()]);
        if (!$deleteStm->rowCount() > 0) {
            return false;
        }
        if ($findPage == 'active') {
            unset($this->activePages[$page->getID()]);
        } else {
            unset($this->inactivePages[$page->getID()]);
        }

        return true;
    }
1290428
static function PageUrl(Page $page, array $params = array(), $fragment = '')
    {
        $siteUrl = $page->GetSite()->GetUrl();
        $pageUrl = $page->GetUrl();
        if ($pageUrl == 'index.html') {
            $url = $siteUrl;
        }
        else {
            $url = Path::Combine($siteUrl, $pageUrl);
        }

        $oblParams = self::GatherParams($url);
        $urlObl = self::AttachObligatoryParams($url, $oblParams, $params);

        $urlAllParams = self::AttachMoreParams($urlObl, $oblParams, $params);
        return $fragment ? $urlAllParams . '#' . $fragment : $urlAllParams;
    }
1205974
public function checkWhitelist(string $url): bool
	{
		$pluginSettings = EmbeddedAssets::$plugin->getSettings();
		$whitelist = array_merge($pluginSettings->whitelist, $pluginSettings->extraWhitelist);

		foreach ($whitelist as $whitelistUrl)
		{
			if ($whitelistUrl)
			{
				$pattern = explode('*', $whitelistUrl);
				$pattern = array_map('preg_quote', $pattern);
				$pattern = implode('[a-z][a-z0-9]*', $pattern);
				$pattern = "%^(https?:)?//([a-z0-9\-]+\\.)?$pattern([:/].*)?$%";

				if (preg_match($pattern, $url))
				{
					return true;
				}
			}
		}

		return false;
	}
764161
public function match($url = null)
    {
        $match = parent::match($url);

        $find = $this->replaceParameters();

        if (false !== $find || true === $match) {
            return true;
        } else {
            return false;
        }
    }
1029571
public function getUrl($page)
    {
        if (is_null($this->url)) {
            throw new RuntimeException('URL template must be defined');
        }

        if (strpos($this->url, $this->placeholder) !== false) {
            return str_replace($this->placeholder, $page, $this->url);
        } else {
            // Without placeholder, no substitution is done, therefore pagination links won't work
            throw new LogicException('The URL string must contain at least one placeholder to make pagination links work');
        }
    }
487764
public function match($url)
    {
        foreach ($this->_parsedRoutes as $value)
        {
            if (preg_match('!^' . $value['path'] . '$!', $url, $result) == 1)
            {
                $paramsWithValues = array();

                foreach ($value['params'] as $param)
                {
                    $paramsWithValues[$param] = $result[$param];
                }

                $value['params'] = $paramsWithValues;

                return $value;
            }
        }

        return false;
    }
209259
public function matches(Route $route, Request $request)
	{
		if (is_null($route->getCompiled()->getHostRegex())) return true;

		return preg_match($route->getCompiled()->getHostRegex(), $request->getHost());
	}