Version Notes
You have to set
System -> Configuration -> Developer ->
Merge JavaScript Files|Merge Css Files
to "Yes" in order to benefit from this extension
Download this release
Release Info
Developer | Sergey Radzishevskyi |
Extension | FileMerger |
Version | 0.1.1 |
Comparing to | |
See all releases |
Code changes from version 0.1.0 to 0.1.1
app/code/local/Radz/FileMerger/Model/Design/Package.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Radz_FileMerger_Model_Design_Package extends Mage_Core_Model_Design_Package
|
5 |
+
{
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Merge specified css files and return URL to the merged file on success
|
9 |
+
*
|
10 |
+
* @param $files
|
11 |
+
* @return string
|
12 |
+
*/
|
13 |
+
public function getMergedCssUrl($files)
|
14 |
+
{
|
15 |
+
// secure or unsecure
|
16 |
+
$isSecure = Mage::app()->getRequest()->isSecure();
|
17 |
+
$mergerDir = $isSecure ? 'css_secure' : 'css';
|
18 |
+
$targetDir = $this->_initMergerDir($mergerDir);
|
19 |
+
if (!$targetDir) {
|
20 |
+
return '';
|
21 |
+
}
|
22 |
+
|
23 |
+
// base hostname & port
|
24 |
+
$baseMediaUrl = Mage::getBaseUrl('media', $isSecure);
|
25 |
+
$hostname = parse_url($baseMediaUrl, PHP_URL_HOST);
|
26 |
+
$port = parse_url($baseMediaUrl, PHP_URL_PORT);
|
27 |
+
if (false === $port) {
|
28 |
+
$port = $isSecure ? 443 : 80;
|
29 |
+
}
|
30 |
+
|
31 |
+
$fileVersions = array();
|
32 |
+
foreach ($files as $file) {
|
33 |
+
$fileVersions[] = $file . '?' . filemtime($file);
|
34 |
+
}
|
35 |
+
|
36 |
+
// merge into target file
|
37 |
+
$targetFilename = md5(implode(',', $fileVersions) . "|{$hostname}|{$port}") . '.css';
|
38 |
+
if ($this->_mergeFiles($files, $targetDir . DS . $targetFilename, false, array($this, 'beforeMergeCss'), 'css')) {
|
39 |
+
return $baseMediaUrl . $mergerDir . '/' . $targetFilename;
|
40 |
+
}
|
41 |
+
return '';
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getMergedJsUrl($files)
|
45 |
+
{
|
46 |
+
$fileVersions = array();
|
47 |
+
foreach ($files as $file) {
|
48 |
+
$fileVersions[] = $file . '?' . filemtime($file);
|
49 |
+
}
|
50 |
+
|
51 |
+
$targetFilename = md5(implode(',', $fileVersions)) . '.js';
|
52 |
+
$targetDir = $this->_initMergerDir('js');
|
53 |
+
if (!$targetDir) {
|
54 |
+
return '';
|
55 |
+
}
|
56 |
+
if ($this->_mergeFiles($files, $targetDir . DS . $targetFilename, false, null, 'js')) {
|
57 |
+
return Mage::getBaseUrl('media', Mage::app()->getRequest()->isSecure()) . 'js/' . $targetFilename;
|
58 |
+
}
|
59 |
+
return '';
|
60 |
+
}
|
61 |
+
|
62 |
+
}
|
app/code/local/Radz/FileMerger/etc/config.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<modules>
|
3 |
+
<Radz_FileMerger>
|
4 |
+
<version>0.1.0</version>
|
5 |
+
</Radz_FileMerger>
|
6 |
+
</modules>
|
7 |
+
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<radz_filemerger>
|
11 |
+
<class>Radz_FileMerger_Model</class>
|
12 |
+
</radz_filemerger>
|
13 |
+
<core>
|
14 |
+
<rewrite>
|
15 |
+
<design_package>Radz_FileMerger_Model_Design_Package</design_package>
|
16 |
+
</rewrite>
|
17 |
+
</core>
|
18 |
+
</models>
|
19 |
+
</global>
|
20 |
+
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>FileMerger</name>
|
4 |
-
<version>0.1.
|
5 |
<stability>stable</stability>
|
6 |
<license>GNU Lesser General Public License </license>
|
7 |
<channel>community</channel>
|
@@ -14,9 +14,9 @@ System -> Configuration -> Developer -> 
|
|
14 |
Merge JavaScript Files|Merge Css Files
|
15 |
to "Yes" in order to benefit from this extension</notes>
|
16 |
<authors><author><name>Sergii Radzishevskyi</name><user>radzserg</user><email>radzserg@gmail.com</email></author></authors>
|
17 |
-
<date>2013-01-
|
18 |
-
<time>
|
19 |
-
<contents><target name="mageetc"><dir name="."><file name="Radz_FileMerger.xml" hash=""/></dir></target><target name="magelocal"><dir name="Radz"><
|
20 |
<compatible/>
|
21 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
22 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>FileMerger</name>
|
4 |
+
<version>0.1.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>GNU Lesser General Public License </license>
|
7 |
<channel>community</channel>
|
14 |
Merge JavaScript Files|Merge Css Files
|
15 |
to "Yes" in order to benefit from this extension</notes>
|
16 |
<authors><author><name>Sergii Radzishevskyi</name><user>radzserg</user><email>radzserg@gmail.com</email></author></authors>
|
17 |
+
<date>2013-01-14</date>
|
18 |
+
<time>09:38:17</time>
|
19 |
+
<contents><target name="mageetc"><dir name="."><file name="Radz_FileMerger.xml" hash=""/></dir></target><target name="magelocal"><dir name="Radz"><dir name="FileMerger"><dir name="Model"><dir name="Design"><file name="Package.php" hash="34d5ca7073c2cd557d5201d457db389a"/></dir></dir><dir name="etc"><file name="config.xml" hash="81478d0f880a29cf015c8b15b99560ac"/></dir></dir></dir></target></contents>
|
20 |
<compatible/>
|
21 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
22 |
</package>
|