<?php
/**
* Replaces PNGs with equivalent GIFs
*/

function smarty_outputfilter_eF_template_replacePng($compiled, &$smarty) {

    preg_match_all("/images(\/.*)?\/((.*)\.png)/U", $compiled, $images);            // /U is necessary here

    if (!defined(G_ROOTPATH)) {
        define("G_ROOTPATH", "../../");
    }
    foreach ($images[0] as $image) {
        //echo G_ROOTPATH.'www/'.$image.': '.str_replace(".png", ".gif", $image);
        if (is_file(G_ROOTPATH.'www/'.$image)) {
            $new_image = str_replace(".png", ".gif", $image);
            if (is_file(G_ROOTPATH.'www/'.$new_image)) {
                $patterns[]     = $image;
                $replacements[] = $new_image;
            }
        } 
    }
    
    $new = str_replace($patterns, $replacements, $compiled);
    //$new = preg_replace("/\.png/", ".gif", $compiled);
    return $new;
}
?>