Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.RessourcePacker.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * JS scripts and CSS stylesheets merger/packer
9  *
10  * @author Anakeen 2011
11  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
12  */
13 
15 {
16  /**
17  * Pack JS scripts
18  *
19  * @param Action $action The action on which the resulting JS will be added
20  * @param array $static_js List of static JS file to pack
21  * @param array $dynamic_js List of dynamic JS file to pack
22  *
23  * @return boolean true
24  */
25  static function pack_js(Action & $action, array & $static_js = array() , array & $dynamic_js = array())
26  {
27  foreach ($static_js as $jsfile) {
28  if (is_file($jsfile)) {
29  print sprintf("// --- <static file='%s'> ---\n", $jsfile);
30  print str_replace("include_js(", "//include_js(", file_get_contents($jsfile)) . "\n";
31  print sprintf("// -- </static file='%s'> ---\n", $jsfile);
32  print "\n";
33  } else {
34  print ("\nalert(\"$jsfile not found\");\n");
35  }
36  }
37  foreach ($dynamic_js as $jsfile) {
38  if (is_file($jsfile)) {
39  $action->lay->template.= sprintf("// --- <dynamic file='%s'> ---\n", $jsfile);
40  $action->lay->template.= str_replace("include_js(", "//include_js(", file_get_contents($jsfile)) . "\n";
41  $action->lay->template.= sprintf("// --- </dynamic file='%s'> ---\n", $jsfile);
42  } else {
43  $action->lay->template.= ("\nalert(\"$jsfile not found\");\n");
44  }
45  }
46 
47  $action->lay->template = str_replace("\ninclude_js(", "\n//include_js(", $action->lay->template);
48  return true;
49  }
50  /**
51  * Pack CSS stylesheets
52  *
53  * @param Action $action The action on which the resulting CSS will be added
54  * @param array $static_css List of static CSS stylesheets to pack
55  * @param array $dynamic_css List of dynamic CSS stylesheets to pack
56  */
57  static function pack_css(Action & $action, array $static_css = array() , array $dynamic_css = array())
58  {
59  foreach ($static_css as $cssfile) {
60  if (is_file($cssfile)) {
61  print sprintf("/* <static file='%s'> */\n", $cssfile);
62  print file_get_contents($cssfile) . "\n";
63  print sprintf("/* </static file='%s'> */\n", $cssfile);
64  print "\n";
65  } else {
66  print sprintf("/* CSS file '%s' not found */\n", $cssfile);
67  $action->log->error(sprintf("CSS file '%s' not found", $cssfile));
68  }
69  }
70  foreach ($dynamic_css as $cssfile) {
71  if (is_file($cssfile)) {
72  $action->lay->template.= sprintf("/* <dynamic file='%s'> */\n", $cssfile);
73  $action->lay->template.= file_get_contents($cssfile) . "\n";
74  $action->lay->template.= sprintf("/* </dynamic file='%s'> */\n", $cssfile);
75  } else {
76  $action->lay->template.= sprintf("/* CSS file '%s' not found */\n", $cssfile);
77  $action->log->error(sprintf("CSS file '%s' not found", $cssfile));
78  }
79  }
80  return true;
81  }
82 }
83 ?>
← centre documentaire © anakeen - published under CC License - Dynacase