47 'css' =>
'cssimport,cssembed,?cssmin',
65 'assets' => array(
'media/jquery/jquery.js'),
70 'assets' => array(
'media/jquery/ui/jquery-ui.js'),
75 'assets' => array(
'media/jquery/plugins/jquery.jgrowl.js'),
107 $this->assetManager =
new AssetManager();
108 if (isset($_REQUEST[
'ASSET_DEBUG'])) {
113 foreach ($this->default_asset_refs as $ref) {
127 $assetsPrefs = array();
130 $assetsPrefs =
$xoops->cache()->read($this->assetsPrefsCacheKey);
133 if ($assetsPrefs===
false || !isset($assetsPrefs[
'mtime']) || !
$mtime
134 || (isset($assetsPrefs[
'mtime']) && $assetsPrefs[
'mtime']<
$mtime)) {
137 if (!is_array($assetsPrefs)) {
138 $xoops->logger()->error(
"Invalid config in system_assets_prefs.yml");
139 $assetsPrefs = array();
141 $assetsPrefs[
'mtime']=
$mtime;
142 $xoops->cache()->write($this->assetsPrefsCacheKey, $assetsPrefs);
146 $assetsPrefs = array(
147 'default_filters' => $this->default_filters,
148 'default_asset_refs' => $this->default_asset_refs,
154 if (!empty($assetsPrefs[
'default_filters']) && is_array($assetsPrefs[
'default_filters'])) {
155 $this->default_filters = $assetsPrefs[
'default_filters'];
157 if (!empty($assetsPrefs[
'default_asset_refs']) && is_array($assetsPrefs[
'default_asset_refs'])) {
158 $this->default_asset_refs = $assetsPrefs[
'default_asset_refs'];
160 }
catch (\Exception $e) {
161 $xoops->events()->triggerEvent(
'core.exception', $e);
162 $assetsPrefs = array();
177 if (is_array($assets_prefs)) {
181 $xoops->cache()->write($this->assetsPrefsCacheKey, $assets_prefs);
182 }
catch (\Exception $e) {
183 $xoops->events()->triggerEvent(
'core.exception', $e);
204 if (is_scalar($assets)) {
205 $assets = array($assets);
208 if ($filters==
'default') {
209 if (isset($this->default_filters[
$type])) {
210 $filters = $this->default_filters[
$type];
216 if (!is_array($filters)) {
217 if (empty($filters)) {
220 $filters = explode(
',', str_replace(
' ',
'', $filters));
224 if (isset($this->default_output[
$type])) {
225 $output = $this->default_output[
$type];
235 $target_path =
$xoops->path(
'assets');
240 $fm =
new FilterManager();
242 foreach ($filters as
$filter) {
243 if (is_object($filter) && $filter instanceof $this->filterInterface) {
246 switch (ltrim($filter,
'?')) {
248 $fm->set(
'cssembed',
new Filter\PhpCssEmbedFilter());
251 $fm->set(
'cssmin',
new Filter\CssMinFilter());
254 $fm->set(
'cssimport',
new Filter\CssImportFilter());
257 $fm->set(
'cssrewrite',
new Filter\CssRewriteFilter());
260 $fm->set(
'lessphp',
new Filter\LessphpFilter());
263 $fm->set(
'scssphp',
new Filter\ScssphpFilter());
266 $fm->set(
'jsmin',
new Filter\JSMinFilter());
269 throw new \Exception(sprintf(
'%s filter not implemented.', $filter));
276 $factory =
new AssetFactory($target_path);
277 $factory->setAssetManager($am);
278 $factory->setFilterManager($fm);
279 $factory->setDefaultOutput($output);
280 $factory->setDebug($this->debug);
281 $factory->addWorker(
new CacheBustingWorker());
284 $writer =
new AssetWriter($target_path);
287 $translated_assets = array();
288 foreach ($assets as $k => $v) {
290 if (0 == preg_match(
"/^\\/|^\\\\|^[a-zA-Z]:|^@/", $v)) {
293 if (!in_array($v, $translated_assets)) {
294 $translated_assets[] = $v;
299 $asset = $factory->createAsset(
303 $asset_path = $asset->getTargetPath();
304 if (!is_readable($target_path . $asset_path)) {
305 $xoops->events()->triggerEvent(
'debug.timer.start', array(
'writeAsset', $asset_path));
306 $oldumask = umask(0002);
307 $writer->writeAsset($asset);
309 $xoops->events()->triggerEvent(
'debug.timer.stop',
'writeAsset');
312 return $xoops->url(
'assets/' . $asset_path);
314 }
catch (\Exception $e) {
315 $xoops->events()->triggerEvent(
'core.exception', $e);
330 $this->debug = (boolean)
$debug;
348 $assetArray = array();
349 $filterArray = array();
352 if (is_scalar($assets)) {
353 $assets = array($assets);
355 foreach ($assets as $a) {
357 if ((substr_compare($a,
'@', 0, 1) != 0)
358 && (substr_compare($a,
'/', 0, 1) != 0)) {
361 if (
false===strpos($a,
'*')) {
362 $assetArray[] =
new FileAsset($a);
364 $assetArray[] =
new GlobAsset($a);
368 if (!is_array($filters)) {
369 if (empty($filters)) {
372 $filters = explode(
',', str_replace(
' ',
'', $filters));
375 foreach ($filters as
$filter) {
376 if (is_object($filter) && $filter instanceof $this->filterInterface) {
379 switch (ltrim($filter,
'?')) {
381 $filterArray[] =
new Filter\PhpCssEmbedFilter();
384 $filterArray[] =
new Filter\CssMinFilter();
387 $filterArray[] =
new Filter\CssImportFilter();
390 $filterArray[] =
new Filter\CssRewriteFilter();
393 $filterArray[] =
new Filter\LessphpFilter();
396 $filterArray[] =
new Filter\ScssphpFilter();
399 $filterArray[] =
new Filter\JSMinFilter();
402 throw new \Exception(sprintf(
'%s filter not implemented.', $filter));
408 $collection =
new AssetCollection($assetArray, $filterArray);
409 $this->assetManager->set(
$name, $collection);
412 }
catch (\Exception $e) {
413 $xoops->events()->triggerEvent(
'core.exception', $e);
435 $to_path =
$xoops->path(
'assets') .
'/' . $output .
'/';
436 $from = glob($from_path .
'/' . $pattern);
437 $xoops->events()->triggerEvent(
'debug.log', $from);
439 if (!is_dir($to_path)) {
441 mkdir($to_path, 0775,
true);
445 if (!is_writable($to_path)) {
446 $xoops->logger()->warning(
'Asset directory is not writable. ' . $output);
451 foreach ($from as $filepath) {
452 $filename = basename($filepath);
453 $status=copy($filepath, $to_path.$filename);
455 $xoops->logger()->warning(
'Failed to copy asset '.$filename);
457 $xoops->logger()->debug(
'Copied asset '.$filename);
registerAssetReference($name, $assets, $filters=null)
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
getUrlToAssets($type, $assets, $filters= 'default', $target=null)
saveAssetsPrefs($assets_prefs)
copyFileAssets($from_path, $pattern, $output)
static save($var, $yamlFile, $inline=4, $indent=4)
if($file===false||$dir===false||!strstr($file, $dir)) if(empty($file)||strpos($file, '.php')!==false) $mtime