Example #1
0
 /**
  * Remove script tags from the source
  *
  * @param string $content
  * @param array $files
  * @return void
  */
 function remove_scripts(&$content, $files)
 {
     $regexps = array();
     $home_url_regexp = w3_get_home_url_regexp();
     $path = '';
     if (w3_is_network() && !w3_is_subdomain_install()) {
         $path = ltrim(w3_get_home_path(), '/');
     }
     foreach ($files as $file) {
         if ($path && strpos($file, $path) === 0) {
             $file = substr($file, strlen($path));
         }
         $this->replaced_scripts[] = $file;
         if (w3_is_url($file) && !preg_match('~' . $home_url_regexp . '~i', $file)) {
             // external JS files
             $regexps[] = w3_preg_quote($file);
         } else {
             // local JS files
             $file = ltrim($file, '/');
             if (ltrim(w3_get_site_path(), '/') && strpos($file, ltrim(w3_get_site_path(), '/')) === 0) {
                 $file = str_replace(ltrim(w3_get_site_path(), '/'), '', $file);
             }
             $file = ltrim(preg_replace('~' . $home_url_regexp . '~i', '', $file), '/\\');
             $regexps[] = '(' . $home_url_regexp . ')?/?' . w3_preg_quote($file);
         }
     }
     foreach ($regexps as $regexp) {
         $content = preg_replace('~<script\\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*>\\s*</script>~Uis', '', $content);
     }
 }
Example #2
0
/**
 * Normalizes file name
 *
 * Relative to site root!
 *
 * @param string $file
 * @return string
 */
function w3_normalize_file($file)
{
    if (w3_is_url($file)) {
        if (strstr($file, '?') === false) {
            $home_url_regexp = '~' . w3_get_home_url_regexp() . '~i';
            $file = preg_replace($home_url_regexp, '', $file);
        }
    }
    if (!w3_is_url($file)) {
        $file = w3_path($file);
        $file = str_replace(w3_get_site_root(), '', $file);
        $file = ltrim($file, '/');
    }
    return $file;
}