PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / kriswallsmith / assetic / src / functions.php

functions.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/kriswallsmith/assetic/src/functions.php

126 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
12 use Assetic\Factory\AssetFactory;
13 use Assetic\Util\TraversableString;
14
15 if (function_exists('assetic_init')) {
16 return;
17 }
18
19 /**
20 * Initializes the global Assetic object.
21 *
22 * @param AssetFactory $factory The asset factory
23 */
24 function assetic_init(AssetFactory $factory)
25 {
26 global $_assetic;
27
28 $_assetic = new stdClass();
29 $_assetic->factory = $factory;
30 }
31
32 /**
33 * Returns an array of javascript URLs.
34 *
35 * @param array|string $inputs Input strings
36 * @param array|string $filters Filter names
37 * @param array $options An array of options
38 *
39 * @return array An array of javascript URLs
40 */
41 function assetic_javascripts($inputs = array(), $filters = array(), array $options = array())
42 {
43 if (!isset($options['output'])) {
44 $options['output'] = 'js/*.js';
45 }
46
47 return _assetic_urls($inputs, $filters, $options);
48 }
49
50 /**
51 * Returns an array of stylesheet URLs.
52 *
53 * @param array|string $inputs Input strings
54 * @param array|string $filters Filter names
55 * @param array $options An array of options
56 *
57 * @return array An array of stylesheet URLs
58 */
59 function assetic_stylesheets($inputs = array(), $filters = array(), array $options = array())
60 {
61 if (!isset($options['output'])) {
62 $options['output'] = 'css/*.css';
63 }
64
65 return _assetic_urls($inputs, $filters, $options);
66 }
67
68 /**
69 * Returns an image URL.
70 *
71 * @param string $input An input
72 * @param array|string $filters Filter names
73 * @param array $options An array of options
74 *
75 * @return string An image URL
76 */
77 function assetic_image($input, $filters = array(), array $options = array())
78 {
79 if (!isset($options['output'])) {
80 $options['output'] = 'images/*';
81 }
82
83 $urls = _assetic_urls($input, $filters, $options);
84
85 return current($urls);
86 }
87
88 /**
89 * Returns an array of asset urls.
90 *
91 * @param array|string $inputs Input strings
92 * @param array|string $filters Filter names
93 * @param array $options An array of options
94 *
95 * @return array An array of URLs
96 */
97 function _assetic_urls($inputs = array(), $filters = array(), array $options = array())
98 {
99 global $_assetic;
100
101 if (!is_array($inputs)) {
102 $inputs = array_filter(array_map('trim', explode(',', $inputs)));
103 }
104
105 if (!is_array($filters)) {
106 $filters = array_filter(array_map('trim', explode(',', $filters)));
107 }
108
109 $coll = $_assetic->factory->createAsset($inputs, $filters, $options);
110
111 $debug = isset($options['debug']) ? $options['debug'] : $_assetic->factory->isDebug();
112 $combine = isset($options['combine']) ? $options['combine'] : !$debug;
113
114 $one = $coll->getTargetPath();
115 if ($combine) {
116 $many = array($one);
117 } else {
118 $many = array();
119 foreach ($coll as $leaf) {
120 $many[] = $leaf->getTargetPath();
121 }
122 }
123
124 return new TraversableString($one, $many);
125 }
126