Core  3.2
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  * @package FDL
5 */
6 /**
7  * JS scripts and CSS stylesheets merger/packer
8  *
9  * @author Anakeen 2011
10  */
11 
13 {
14  /**
15  * Pack JS scripts
16  *
17  * @param Action $action The action on which the resulting JS will be added
18  * @param array $static_js List of static JS file to pack
19  * @param array $dynamic_js List of dynamic JS file to pack
20  *
21  * @param string $extraCode add js code before including file
22  * @return boolean true
23  */
24  static function pack_js(Action & $action, array & $static_js = array() , array & $dynamic_js = array() , $extraCode = '')
25  {
26  print "//Pack js\n";
27  print $extraCode . "\n";
28 
29  foreach ($static_js as $jsfile) {
30  if (is_file($jsfile)) {
31  print sprintf("// --- <static file='%s'> ---\n", $jsfile);
32  print str_replace("include_js(", "//include_js(", file_get_contents($jsfile)) . "\n";
33  print sprintf("// -- </static file='%s'> ---\n", $jsfile);
34  print "\n";
35  } else {
36  print ("\nalert(\"$jsfile not found\");\n");
37  }
38  }
39  foreach ($dynamic_js as $jsfile) {
40  if (is_file($jsfile)) {
41  $action->lay->template.= sprintf("// --- <dynamic file='%s'> ---\n", $jsfile);
42  $action->lay->template.= str_replace("include_js(", "//include_js(", file_get_contents($jsfile)) . "\n";
43  $action->lay->template.= sprintf("// --- </dynamic file='%s'> ---\n", $jsfile);
44  } else {
45  $action->lay->template.= ("\nalert(\"$jsfile not found\");\n");
46  }
47  }
48 
49  $action->lay->template = str_replace("\ninclude_js(", "\n//include_js(", $action->lay->template);
50  return true;
51  }
52  /**
53  * Pack CSS stylesheets
54  *
55  * @param Action $action The action on which the resulting CSS will be added
56  * @param array $static_css List of static CSS stylesheets to pack
57  * @param array $dynamic_css List of dynamic CSS stylesheets to pack
58  */
59  static function pack_css(Action & $action, array $static_css = array() , array $dynamic_css = array())
60  {
61  foreach ($static_css as $cssfile) {
62  if (is_file($cssfile)) {
63  print sprintf("/* <static file='%s'> */\n", $cssfile);
64  print file_get_contents($cssfile) . "\n";
65  print sprintf("/* </static file='%s'> */\n", $cssfile);
66  print "\n";
67  } else {
68  print sprintf("/* CSS file '%s' not found */\n", $cssfile);
69  $action->log->error(sprintf("CSS file '%s' not found", $cssfile));
70  }
71  }
72  foreach ($dynamic_css as $cssfile) {
73  if (is_file($cssfile)) {
74  $action->lay->template.= sprintf("/* <dynamic file='%s'> */\n", $cssfile);
75  $action->lay->template.= file_get_contents($cssfile) . "\n";
76  $action->lay->template.= sprintf("/* </dynamic file='%s'> */\n", $cssfile);
77  } else {
78  $action->lay->template.= sprintf("/* CSS file '%s' not found */\n", $cssfile);
79  $action->log->error(sprintf("CSS file '%s' not found", $cssfile));
80  }
81  }
82  return true;
83  }
84 }
85 ?>
static pack_css(Action &$action, array $static_css=array(), array $dynamic_css=array())
global $action
static pack_js(Action &$action, array &$static_js=array(), array &$dynamic_js=array(), $extraCode= '')
error($msg)
print
Definition: checklist.php:49
← centre documentaire © anakeen