Beispiel #1
0
 function callback_relative_url(&$matches)
 {
     return hotpot_convert_relative_url($this->get_baseurl(), $this->reference, $matches[1], $matches[6], $matches[7], false);
 }
function hotpot_convert_relative_urls($str, $baseurl, $filename)
{
    $tagopen = '(?:(<)|(&lt;)|(&amp;#x003C;))';
    // left angle bracket
    $tagclose = '(?(2)>|(?(3)&gt;|(?(4)&amp;#x003E;)))';
    //  right angle bracket (to match left angle bracket)
    $space = '\\s+';
    // at least one space
    $anychar = '(?:[^>]*?)';
    // any character
    $quoteopen = '("|&quot;|&amp;quot;)';
    // open quote
    $quoteclose = '\\5';
    //  close quote (to match open quote)
    $replace = "hotpot_convert_relative_url('" . $baseurl . "', '" . $filename . "', '\\1', '\\6', '\\7')";
    $tags = array('script' => 'src', 'link' => 'href', 'a' => 'href', 'img' => 'src', 'param' => 'value', 'object' => 'data', 'embed' => 'src');
    foreach ($tags as $tag => $attribute) {
        if ($tag == 'param') {
            $url = '\\S+?\\.\\S+?';
            // must include a filename and have no spaces
        } else {
            $url = '.*?';
        }
        $search = "/({$tagopen}{$tag}{$space}{$anychar}{$attribute}={$quoteopen})({$url})({$quoteclose}{$anychar}{$tagclose})/is";
        if (preg_match_all($search, $str, $matches, PREG_OFFSET_CAPTURE)) {
            $i_max = count($matches[0]) - 1;
            for ($i = $i_max; $i >= 0; $i--) {
                $match = $matches[0][$i][0];
                $start = $matches[0][$i][1];
                $replace = hotpot_convert_relative_url($baseurl, $filename, $matches[1][$i][0], $matches[6][$i][0], $matches[7][$i][0], false);
                $str = substr_replace($str, $replace, $start, strlen($match));
            }
        }
    }
    return $str;
}