Plugin Directory

Changeset 146592


Ignore:
Timestamp:
08/17/2009 11:33:19 AM (17 years ago)
Author:
Regen
Message:

Fix IE conditional comment bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • script-compressor/trunk/script-compressor.php

    r146576 r146592  
    199199        $output_aft = '';
    200200        $output_css = '';
     201
     202        $shelve = $this->shelve('%<!--\[if .*\]>.+<!\[endif\]-->%s', $content);
    201203
    202204        if (preg_match_all($regex_js, $content, $matches, PREG_SET_ORDER)) {
     
    241243        }
    242244
     245        $this->unshelve($shelve, $content);
     246
    243247        if ($this->options['output_footer']) {
    244248            $this->output .= $output_aft;
     
    247251            return $content . $output_css . $output_aft;
    248252        }
     253    }
     254
     255    /**
     256     * Shelve strings which match pattern.
     257     *
     258     * @param string $pattern Preg pattern
     259     * @param string $str Target strings
     260     * @return array Shelved data
     261     */
     262    function shelve($pattern, &$str) {
     263        $data = array();
     264        if (preg_match_all($pattern, $str, $matches, PREG_SET_ORDER)) {
     265            foreach ($matches as $match) {
     266                $key = sprintf('__SHELVE_%s_%s__', count($data), time());
     267                $data[$key] = $match[0];
     268                $str = str_replace($match[0], $key, $str);
     269            }
     270        }
     271        return $data;
     272    }
     273
     274    /**
     275     * Unshelve strings which shelved.
     276     *
     277     * @param string $data Shelved data
     278     * @param string $str Target strings
     279     */
     280    function unshelve($data, &$str) {
     281        $str = str_replace(array_keys($data), array_values($data), $str);
    249282    }
    250283
Note: See TracChangeset for help on using the changeset viewer.