ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
CssUtils.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2014 OpenSky Project Inc
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Assetic\Util;
13
19abstract class CssUtils
20{
21 const REGEX_URLS = '/url\‍((["\']?)(?P<url>.*?)(\\1)\‍)/';
22 const REGEX_IMPORTS = '/@import (?:url\‍()?(\'|"|)(?P<url>[^\'"\‍)\n\r]*)\1\‍)?;?/';
23 const REGEX_IMPORTS_NO_URLS = '/@import (?!url\‍()(\'|"|)(?P<url>[^\'"\‍)\n\r]*)\1;?/';
24 const REGEX_IE_FILTERS = '/src=(["\']?)(?P<url>.*?)\\1/';
25 const REGEX_COMMENTS = '/(\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)/';
26
35 public static function filterReferences($content, $callback)
36 {
37 $content = static::filterUrls($content, $callback);
38 $content = static::filterImports($content, $callback, false);
39 $content = static::filterIEFilters($content, $callback);
40
41 return $content;
42 }
43
52 public static function filterUrls($content, $callback)
53 {
54 $pattern = static::REGEX_URLS;
55
56 return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
57 return preg_replace_callback($pattern, $callback, $part);
58 });
59 }
60
70 public static function filterImports($content, $callback, $includeUrl = true)
71 {
72 $pattern = $includeUrl ? static::REGEX_IMPORTS : static::REGEX_IMPORTS_NO_URLS;
73
74 return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
75 return preg_replace_callback($pattern, $callback, $part);
76 });
77 }
78
87 public static function filterIEFilters($content, $callback)
88 {
89 $pattern = static::REGEX_IE_FILTERS;
90
91 return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
92 return preg_replace_callback($pattern, $callback, $part);
93 });
94 }
95
104 public static function filterCommentless($content, $callback)
105 {
106 $result = '';
107 foreach (preg_split(static::REGEX_COMMENTS, $content, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) {
108 if (!preg_match(static::REGEX_COMMENTS, $part, $match) || $part != $match[0]) {
109 $part = call_user_func($callback, $part);
110 }
111
112 $result .= $part;
113 }
114
115 return $result;
116 }
117
125 public static function extractImports($content)
126 {
127 $imports = array();
128 static::filterImports($content, function ($matches) use (&$imports) {
129 $imports[] = $matches['url'];
130 });
131
132 return array_unique($imports);
133 }
134
135 final private function __construct()
136 {
137 }
138}
$result
static extractImports($content)
Extracts all references from the supplied CSS content.
Definition: CssUtils.php:125
static filterReferences($content, $callback)
Filters all references – url() and "@import" – through a callable.
Definition: CssUtils.php:35
static filterCommentless($content, $callback)
Filters each non-comment part through a callable.
Definition: CssUtils.php:104
static filterUrls($content, $callback)
Filters all CSS url()'s through a callable.
Definition: CssUtils.php:52
static filterImports($content, $callback, $includeUrl=true)
Filters all CSS imports through a callable.
Definition: CssUtils.php:70
static filterIEFilters($content, $callback)
Filters all IE filters (AlphaImageLoader filter) through a callable.
Definition: CssUtils.php:87
const REGEX_IMPORTS_NO_URLS
Definition: CssUtils.php:23
An exception for terminatinating execution or to throw for unit testing.
echo;exit;}function LogoutNotification($SessionID) { global $ilDB; $q="SELECT session_id, data FROM usr_session WHERE expires > (\w+)\|/" PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE