XOOPS  2.6.0
block.assets.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Smarty plugin
4  * ------------------------------------------------------------
5  * Type: block
6  * Name: asset
7  * Purpose: XOOPS smarty plugin for Assetic assets
8  * Author: Pierre-Jean Parra, Dejian Xu https://github.com/xudejian/assetic-smarty
9  * Richard Griffith <richard@geekwright.com>
10  * Version: 1.0
11  *
12  * Parameters
13  * assets - comma separated list of assets to process. Assets should be absolute
14  * file paths, or Xoops::path resolveable
15  * output - type of output, css = Stylesheet, js = Javascript
16  * debug - boolean, true for debug mode, defaults to false
17  * filters - list of assetic filters to apply to asset. The following filters are supported
18  * cssembed - PhpCssEmbedFilter()
19  * cssmin - CssMinFilter()
20  * cssimport - CssImportFilter()
21  * cssrewrite - CssRewriteFilter()
22  * lessphp - LessphpFilter()
23  * scssphp - ScssphpFilter()
24  * jsmin - JSMinFilter()
25  * asset_url - smarty variable to assign asset path
26  *
27  * Example:
28  * <{assets
29  * assets="modules/demo/assets/css/reset.css,modules/demo/assets/css/common.css"
30  * output="css"
31  * debug=false
32  * filters="cssimport,cssembed,?cssmin"
33  * asset_url=asset_url}>
34  * <link rel="stylesheet" href="<{$asset_url}>">
35  * <{/assets}>
36  * ------------------------------------------------------------
37  */
38 
39 function smarty_block_assets($params, $content, $template, &$repeat)
40 {
41  // Opening tag (first call only)
42  if ($repeat) {
44 
45  $assets = explode(',', $params['assets']);
46 
47  if (isset($params['filters'])) {
48  $filters = $params['filters'];
49  } else {
50  $filters = 'default';
51  }
52 
53  $output = strtolower($params['output']);
54 
55  $debug = isset($params['debug'])? (boolean)$params['debug'] : false;
56  if ($debug) {
57  $xoops->assets()->setDebug($debug);
58  }
59 
60  $url = $xoops->assets()->getUrlToAssets($output, $assets, $filters);
61 
62  if (isset($params['asset_url'])) {
63  $asset_url = $params['asset_url'];
64  } else {
65  $asset_url = 'asset_url';
66  }
67 
68  $template->assign($asset_url, $url);
69  } else { // Closing tag
70  if (isset($content)) {
71  return $content;
72  }
73  }
74 }
static getInstance()
Definition: Xoops.php:160
smarty_block_assets($params, $content, $template, &$repeat)
$xoops
Definition: admin.php:25
$url
Definition: register.php:72