MediaEmbed::_match()

@param string $url
@param array $regexRules
@return array
191442
protected function _matchUrl($url, array $regexRules) {
		foreach ($regexRules as $regexRule) {
			if (preg_match('~' . $regexRule . '~imu', $url, $match)) {
				return $match;
			}
		}
		return [];
	}
1184341
public static function getDailymotionEmbedUrl( $videoUrl )
    {
        $embedLink = '';
        $embedINI = eZINI::instance( 'embedtag.ini' );

        preg_match( self::DAILYMOTION_VIDEOID_REGEXP, $videoUrl, $matches );
        if ( isset( $matches['videoId'] ) )
        {
            $embedLink = str_replace( '$$$VIDEO$$$', $matches['videoId'], $embedINI->variable( 'DailymotionSettings', 'EmbedLinkPattern' ) );
        }

        return array( 'result' => $embedLink );
    }
713520
public function match($regexp, $tagName)
	{
		$tagName        = TagName::normalize($tagName);
		$passthroughIdx = 0;
		$this->parseRegexp($regexp);
		foreach ($this->captures as $i => $capture)
		{
			if (!$this->isCatchAll($capture['expr']))
			{
				continue;
			}
			$passthroughIdx = $i;
		}

		$this->collection[] = [$tagName, $regexp, $passthroughIdx];
	}
974775
private function getMatchingData(array $params, $regex)
    {
        foreach ($params as $data) {
            if (preg_match($regex, $data)) {
                return $data;
            }
        }

        return '';
    }
614080
public static function getVimeoEmbedUrl( $videoUrl )
    {
        $embedLink = '';
        $embedINI = eZINI::instance( 'embedtag.ini' );

        preg_match( self::VIMEO_VIDEOID_REGEXP, $videoUrl, $matches );
        if ( isset( $matches['videoId'] ) )
        {
            $embedLink = str_replace( '$$$VIDEO$$$', $matches['videoId'], $embedINI->variable( 'VimeoSettings', 'EmbedLinkPattern' ) );
        }

        return array( 'result' => $embedLink );
    }
888303
public function embed( $url, $params = [] ) : string
    {
        $code = $this->getInfo($url)->code;

        // check if theree are any parameters passed along
        if (!empty($params)) {
            
            // looks like there are, now let's only do this for YouTube and Vimeo
            if($this->getInfo($url)->type == 'video' && ($this->isYouTube($url) || $this->isVimeo($url)))
            {

                // for videos add autoplay check if the embed gets the code

                // create an easy html parser to verify the iframe and add autoplay for video types
                $dom = new DOMDocument;

                // set error level so that the html parser doesn't raise exceptions on warnings
                $internalErrors = libxml_use_internal_errors(true);

                $dom->loadHTML($code);

                // Restore error level
                libxml_use_internal_errors($internalErrors);

                // get the iframe
                $frame = $dom->getElementsByTagName('iframe')->item(0);

                //get the src from iframe
                $src = $frame->getAttribute('src');


                // check if url has any other parameters to properly add the parameter
                if (strpos($src,'?') !== false) {
                    $src .= "&";
                } else {
                    $src .= "?";
                }
                
                $parameters = '';
                foreach ($params as $k=>$v) {
                    if ($parameters !== null) {
                        $parameters .= '&';
                    }
                    $parameters .= "{$k}={$v}";
                }

                $src .= $parameters;

                // set the new src with all the parameters
                $frame->setAttribute('src', $src);

                // replace old iframe html with new one
                return htmlspecialchars_decode($dom->saveHTML($frame));
            }
            else
            {
                if (!empty($code)) {
                    // Not YouTube or Vimeo, just output the code
                    return $code;
                }
                else
                {
                    return '';
                }
            }
        }
        else
        {
            if (!empty($code)) {
                // No parameters passed, just output the code
                return $code;
            }
            else
            {
                return '';
            }
        }

    }
1340747
public function match($url)
    {
        if (!$this->pattern) {
            $this->pattern = self::buildPatternFromScheme($this);
        }

        return (bool) preg_match($this->pattern, $url);
    }
1325920
public function match($regex)
    {
        $match = array();
        if($this->isValidRegex($regex) && preg_match($regex, $this->toString(), $match)===1)
        {
            return new ObjectArray($match);
        }
        return null;
    }
767093
public function matches($url, array $annotations)
	{
		foreach ( $annotations as $annotation ) {
			if ( $this->matchComponent($annotation, $url) ) {
				return true;
			}
		}

		return false;
	}
812175
protected function matchBrowser(array $regexes, $string)
    {
        // Build regex that matches phrases for known browsers (e.g. "Firefox/2.0" or "MSIE 6.0").
        // This only matches the major and minor version numbers (e.g. "2.0.0.6" is parsed as simply "2.0").
        $pattern = '#('.join('|', $regexes).')[/ ]+([0-9]+(?:\.[0-9]+)?)#i';

        if (preg_match($pattern, $string, $matches)) {
            return $matches;
        }

        return false;
    }
355935
protected function processYoutube($url)
    {
        $firstMatches = [];
        $pattern = '%^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=))([^"&?/ ]{11})(?:.+)?$%xs';
        if (preg_match($pattern, $url, $firstMatches)) {
            $toEmbed = $firstMatches[1];
            $patternForAdditionalParams = '%^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=))(?:[^"&?\/ ]{11})(.+)?(?:.+)?$%xs';
            $secondMatches = [];
            if (preg_match($patternForAdditionalParams, $url, $secondMatches) > 1) {
                $toEmbed .= '?' . substr($secondMatches[1], 1);
            }
            return 'https://www.youtube-nocookie.com/embed/' . $toEmbed;
        }
        return null;
    }
227974
private function parseMediaToString($media, array $rules)
    {
        if ($media == '') {
            return
                join(
                    '',
                    array_map(
                        function (Rule $rule) {
                            return $this->parsePropertiesToString($rule->getSelector(), $rule->getProperties());
                        },
                        $rules
                    )
                );

        }

        return "$media { " . join(
                '',
                array_map(
                    function (Rule $rule) {
                        return $this->parsePropertiesToString($rule->getSelector(), $rule->getProperties());
                    },
                    $rules
                )
            ) . "}";
    }
904366
public function tags_preg_callback($matches)
    {
        switch (strtolower($matches[1])) {
        case 'b':
        case 'strong':
            return $this->_toupper($matches[3]);
        case 'th':
            return $this->_toupper("\t\t". $matches[3] ."\n");
        case 'h':
            return $this->_toupper("\n\n". $matches[3] ."\n\n");
        case 'a':
            // Remove spaces in URL (#1487805)
            $url = str_replace(' ', '', $matches[3]);
            return $this->_build_link_list($url, $matches[4]);
        }
    }
610782
public function matches(string $regex): bool
    {
        if (\func_num_args() !== 1) {
            throw new LogicException('Offset is no longer supported');
        }

        return RegExp::of($regex)->matches($this);
    }
1212686
private function match_regex($value, $pattern, $rules = array())
    {
        $pieces = explode(':', $pattern);
        if(count($pieces) <= 1)
            return false;

        $regex = $pieces[1];

        if (array_key_exists($regex, $rules)) {
            $regex = $rules[$regex];
        }

        // ritorna vero se il valore
        // rispetta l'espressione regolare
        return preg_match( "/$regex/", $value );
    }
341997
private function callback(array $matches) {
        $mediamanager = core_media_manager::instance();

        global $CFG, $PAGE;
        // Check if we ignore it.
        if (preg_match('/class="[^"]*nomediaplugin/i', $matches[0])) {
            return $matches[0];
        }

        // Get name.
        $name = trim($matches[2]);
        if (empty($name) or strpos($name, 'http') === 0) {
            $name = ''; // Use default name.
        }

        // Split provided URL into alternatives.
        $urls = $mediamanager->split_alternatives($matches[1], $width, $height);

        $options = [core_media_manager::OPTION_ORIGINAL_TEXT => $matches[0]];
        return $this->embed_alternatives($urls, $name, $width, $height, $options);
    }
1264356
public function mustFind($re, $filter = null) {
        $result = $this->find($re, $filter);
        if ($result->isEmpty()) {
            throw new QueryException('No match for regexp: '.$re);
        }

        return $result;
    }