PHP Classes

REWRITE_SRC_PATH support for css background imgs

Recommend this page to a friend!

      Fast Template  >  All threads  >  REWRITE_SRC_PATH support for css...  >  (Un) Subscribe thread alerts  
Subject:REWRITE_SRC_PATH support for css...
Summary:implementation of the css background img to the rewrite_src_path
Author:Niels Lynx
Date:2007-08-17 22:03:14
Update:2007-08-17 22:36:21

  1. REWRITE_SRC_PATH support for css...   Reply   Report abuse  
Picture of Niels Lynx Niels Lynx - 2007-08-17 22:03:14
First of all, thank you for this great class.

I had use the rewrite src path i noticed it didnt support the css background imgs, so i coded it.
I hope this can be usefull to someone

Here's the new function (the old one is @ around line 550):

function rewrite_src_path($contents){
// Rewrite src path regex using Heredoc
$regexPattern[] = "/src\s*=(.*?)[\\\"']?([^\\\"' >]+)[\\\"'> ]/is";//src="..."
$regexReplacement[] = 'src="'.$this->REWRITE_SRC_PATH.'\\2"';

//added by Niels Bugge
$regexPattern[] = "/(background:.*)\s?url\s*\((.*)\)([^;]*;)/siU";//style="background:url(...);"
$regexReplacement[] = '\\1 url('.$this->REWRITE_SRC_PATH.'\\2)\\3';

//$regexPattern[] = "/<\s*link\s+[^>]*href\s*=\s*[\\\"']?([^\\\"' >]+)[\\\"' >]/is"; //BUG in 1.5.1
$regexPattern_2 = "/<\s*link\s+[^>]*href\s*=\s*[\\\"']?[^\\\"' >]+[\\\"' >]/is";

if(sizeof($this->REWRITE_SRC_PATH)>0) {
$contents=preg_replace($regexPattern, $regexReplacement, $contents);
// preg_reclace_callback return his result to a function outside class body
$contents=preg_replace_callback($regexPattern_2, 'rewrite_link_href_callback', $contents);
return $contents;

I Hope i help someone.
good night :)

  2. Re: REWRITE_SRC_PATH support for css...   Reply   Report abuse  
Picture of Valics Lehel Valics Lehel - 2007-08-17 22:36:21 - In reply to message 1 from Niels Lynx
TX we will review.