Version Notes
First stable release
Download this release
Release Info
Developer | David Danier |
Extension | Team23_ExternalSources |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Team23/ExternalSources/Block/Html/Head.php +177 -0
- app/code/community/Team23/ExternalSources/Helper/Data.php +17 -0
- app/code/community/Team23/ExternalSources/etc/adminhtml.xml +39 -0
- app/code/community/Team23/ExternalSources/etc/config.xml +47 -0
- app/code/community/Team23/ExternalSources/etc/system.xml +80 -0
- app/etc/modules/Team23_ExternalSources.xml +23 -0
- package.xml +26 -0
app/code/community/Team23/ExternalSources/Block/Html/Head.php
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Team23 External Sources
|
5 |
+
*
|
6 |
+
* @category Team23
|
7 |
+
* @package Team23_ExternalSources
|
8 |
+
* @version 1.0.0
|
9 |
+
* @copyright 2014 Team23 GmbH & Co. KG (http://www.team23.de)
|
10 |
+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
|
11 |
+
*/
|
12 |
+
|
13 |
+
|
14 |
+
class Team23_ExternalSources_Block_Html_Head extends Mage_Page_Block_Html_Head
|
15 |
+
{
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Add external javascript source
|
19 |
+
*
|
20 |
+
* @param string $name
|
21 |
+
* @param string $params
|
22 |
+
* @return Team23_ExternalSources_Block_Html_Head
|
23 |
+
*/
|
24 |
+
public function addExternalJs($name, $params = "")
|
25 |
+
{
|
26 |
+
$this->addExternalItem('external_js', $name, $params);
|
27 |
+
|
28 |
+
return $this;
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Add external css source
|
33 |
+
*
|
34 |
+
* @param string $name
|
35 |
+
* @param string $params
|
36 |
+
* @return $this
|
37 |
+
*/
|
38 |
+
public function addExternalCss($name, $params = "")
|
39 |
+
{
|
40 |
+
$this->addExternalItem('external_css', $name, $params);
|
41 |
+
|
42 |
+
return $this;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Add HEAD external item
|
47 |
+
*
|
48 |
+
* Allowed types:
|
49 |
+
* - js
|
50 |
+
* - js_css
|
51 |
+
* - skin_js
|
52 |
+
* - skin_css
|
53 |
+
* - rss
|
54 |
+
* - external_css
|
55 |
+
* - external_js
|
56 |
+
*
|
57 |
+
* @param string $type
|
58 |
+
* @param string $name
|
59 |
+
* @param string $params
|
60 |
+
* @param string $if
|
61 |
+
* @param string $cond
|
62 |
+
* @return Mage_Page_Block_Html_Head
|
63 |
+
*/
|
64 |
+
public function addExternalItem($type, $name, $params = null, $if = null, $cond = null)
|
65 |
+
{
|
66 |
+
$this->addItem($type, $name, $params, $if, $cond);
|
67 |
+
|
68 |
+
return $this;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Remove external item from HEAD entity
|
73 |
+
*
|
74 |
+
* @param string $type
|
75 |
+
* @param string $name
|
76 |
+
* @return Mage_Page_Block_Html_Head
|
77 |
+
*/
|
78 |
+
public function removeExternalItem($type, $name)
|
79 |
+
{
|
80 |
+
$this->removeItem($type, $name);
|
81 |
+
|
82 |
+
return $this;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Get HEAD HTML with CSS/JS/RSS definitions
|
87 |
+
*
|
88 |
+
* @return string
|
89 |
+
*/
|
90 |
+
public function getCssJsHtml()
|
91 |
+
{
|
92 |
+
// separate items by types
|
93 |
+
$lines = array();
|
94 |
+
|
95 |
+
foreach ($this->_data['items'] as $item)
|
96 |
+
{
|
97 |
+
if (!is_null($item['cond']) && !$this->getData($item['cond']) || !isset($item['name']))
|
98 |
+
continue;
|
99 |
+
|
100 |
+
$if = !empty($item['if']) ? $item['if'] : '';
|
101 |
+
$params = !empty($item['params']) ? $item['params'] : '';
|
102 |
+
|
103 |
+
switch ($item['type'])
|
104 |
+
{
|
105 |
+
case 'external_css': // cdn
|
106 |
+
case 'external_js': // cdn
|
107 |
+
case 'js': // js/*.js
|
108 |
+
case 'skin_js': // skin/*/*.js
|
109 |
+
case 'js_css': // js/*.css
|
110 |
+
case 'skin_css': // skin/*/*.css
|
111 |
+
$lines[$if][$item['type']][$params][$item['name']] = $item['name'];
|
112 |
+
break;
|
113 |
+
default:
|
114 |
+
$this->_separateOtherHtmlHeadElements($lines, $if, $item['type'], $params, $item['name'], $item);
|
115 |
+
break;
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
// prepare HTML
|
120 |
+
$shouldMergeJs = Mage::getStoreConfigFlag('dev/js/merge_files');
|
121 |
+
$shouldMergeCss = Mage::getStoreConfigFlag('dev/css/merge_css_files');
|
122 |
+
$html = '';
|
123 |
+
|
124 |
+
foreach ($lines as $if => $items)
|
125 |
+
{
|
126 |
+
if (empty($items))
|
127 |
+
continue;
|
128 |
+
|
129 |
+
if (!empty($if))
|
130 |
+
$html .= '<!--[if '.$if.']>'."\n";
|
131 |
+
|
132 |
+
// prepare external css sources
|
133 |
+
if (isset($items['external_css']))
|
134 |
+
{
|
135 |
+
foreach ($items['external_css'] as $external_param => $external_items)
|
136 |
+
{
|
137 |
+
foreach ($external_items as $external)
|
138 |
+
$html .= sprintf('<link rel="stylesheet" type="text/css" href="%s" %s/>', $external, $external_param);
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
// static and skin css
|
143 |
+
$html .= $this->_prepareStaticAndSkinElements('<link rel="stylesheet" type="text/css" href="%s"%s />' . "\n",
|
144 |
+
empty($items['js_css']) ? array() : $items['js_css'],
|
145 |
+
empty($items['skin_css']) ? array() : $items['skin_css'],
|
146 |
+
$shouldMergeCss ? array(Mage::getDesign(), 'getMergedCssUrl') : null
|
147 |
+
);
|
148 |
+
|
149 |
+
// prepare external js sources
|
150 |
+
if (isset($items['external_js']))
|
151 |
+
{
|
152 |
+
foreach ($items['external_js'] as $external_param => $external_items)
|
153 |
+
{
|
154 |
+
foreach ($external_items as $external)
|
155 |
+
$html .= sprintf('<script type="text/javascript" src="%s" %s></script>', $external, $external_param);
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
// static and skin javascripts
|
160 |
+
$html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n",
|
161 |
+
empty($items['js']) ? array() : $items['js'],
|
162 |
+
empty($items['skin_js']) ? array() : $items['skin_js'],
|
163 |
+
$shouldMergeJs ? array(Mage::getDesign(), 'getMergedJsUrl') : null
|
164 |
+
);
|
165 |
+
|
166 |
+
// other stuff
|
167 |
+
if (!empty($items['other']))
|
168 |
+
$html .= $this->_prepareOtherHtmlHeadElements($items['other']) . "\n";
|
169 |
+
|
170 |
+
if (!empty($if))
|
171 |
+
$html .= '<![endif]-->'."\n";
|
172 |
+
}
|
173 |
+
|
174 |
+
return $html;
|
175 |
+
}
|
176 |
+
|
177 |
+
}
|
app/code/community/Team23/ExternalSources/Helper/Data.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Team23 External Sources
|
5 |
+
*
|
6 |
+
* @category Team23
|
7 |
+
* @package Team23_ExternalSources
|
8 |
+
* @version 1.0.0
|
9 |
+
* @copyright 2014 Team23 GmbH & Co. KG (http://www.team23.de)
|
10 |
+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
|
11 |
+
*/
|
12 |
+
|
13 |
+
|
14 |
+
class Team23_ExternalSources_Helper_Data extends Mage_Core_Helper_Abstract
|
15 |
+
{
|
16 |
+
|
17 |
+
}
|
app/code/community/Team23/ExternalSources/etc/adminhtml.xml
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<!--
|
4 |
+
/**
|
5 |
+
* Team23 External Sources
|
6 |
+
*
|
7 |
+
* @category Team23
|
8 |
+
* @package Team23_ExternalSources
|
9 |
+
* @version 1.0.0
|
10 |
+
* @copyright 2014 Team23 GmbH & Co. KG (http://www.team23.de)
|
11 |
+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
|
12 |
+
*/
|
13 |
+
-->
|
14 |
+
|
15 |
+
<config>
|
16 |
+
<acl>
|
17 |
+
<resources>
|
18 |
+
<all>
|
19 |
+
<title>Allow Everything</title>
|
20 |
+
</all>
|
21 |
+
|
22 |
+
<admin>
|
23 |
+
<children>
|
24 |
+
<system>
|
25 |
+
<children>
|
26 |
+
<config>
|
27 |
+
<children>
|
28 |
+
<externalsourcesinfo>
|
29 |
+
<title>Team23 External Sources</title>
|
30 |
+
</externalsourcesinfo>
|
31 |
+
</children>
|
32 |
+
</config>
|
33 |
+
</children>
|
34 |
+
</system>
|
35 |
+
</children>
|
36 |
+
</admin>
|
37 |
+
</resources>
|
38 |
+
</acl>
|
39 |
+
</config>
|
app/code/community/Team23/ExternalSources/etc/config.xml
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<!--
|
4 |
+
/**
|
5 |
+
* Team23 External Sources
|
6 |
+
*
|
7 |
+
* @category Team23
|
8 |
+
* @package Team23_ExternalSources
|
9 |
+
* @version 1.0.0
|
10 |
+
* @copyright 2014 Team23 GmbH & Co. KG (http://www.team23.de)
|
11 |
+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
|
12 |
+
*/
|
13 |
+
-->
|
14 |
+
|
15 |
+
<config>
|
16 |
+
<modules>
|
17 |
+
<Team23_ExternalSources>
|
18 |
+
<version>1.0.0</version>
|
19 |
+
</Team23_ExternalSources>
|
20 |
+
</modules>
|
21 |
+
|
22 |
+
<global>
|
23 |
+
<models>
|
24 |
+
<externalsources>
|
25 |
+
<class>Team23_ExternalSources_Model</class>
|
26 |
+
</externalsources>
|
27 |
+
</models>
|
28 |
+
|
29 |
+
<helpers>
|
30 |
+
<externalsources>
|
31 |
+
<class>Team23_ExternalSources_Helper</class>
|
32 |
+
</externalsources>
|
33 |
+
</helpers>
|
34 |
+
|
35 |
+
<blocks>
|
36 |
+
<externalsources>
|
37 |
+
<class>Team23_ExternalSources_Block</class>
|
38 |
+
</externalsources>
|
39 |
+
|
40 |
+
<page>
|
41 |
+
<rewrite>
|
42 |
+
<html_head>Team23_ExternalSources_Block_Html_Head</html_head>
|
43 |
+
</rewrite>
|
44 |
+
</page>
|
45 |
+
</blocks>
|
46 |
+
</global>
|
47 |
+
</config>
|
app/code/community/Team23/ExternalSources/etc/system.xml
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<!--
|
4 |
+
/**
|
5 |
+
* Team23 External Sources
|
6 |
+
*
|
7 |
+
* @category Team23
|
8 |
+
* @package Team23_ExternalSources
|
9 |
+
* @version 1.0.0
|
10 |
+
* @copyright 2014 Team23 GmbH & Co. KG (http://www.team23.de)
|
11 |
+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
|
12 |
+
*/
|
13 |
+
-->
|
14 |
+
|
15 |
+
<config>
|
16 |
+
<tabs>
|
17 |
+
<team23config translate="label" module="externalsources">
|
18 |
+
<label>Team23</label>
|
19 |
+
<sort_order>150</sort_order>
|
20 |
+
</team23config>
|
21 |
+
</tabs>
|
22 |
+
|
23 |
+
<sections>
|
24 |
+
<externalsourcesinfo translate="label" module="externalsources">
|
25 |
+
<label>External Sources</label>
|
26 |
+
<tab>team23config</tab>
|
27 |
+
<frontend_type>text</frontend_type>
|
28 |
+
<show_in_default>1</show_in_default>
|
29 |
+
<show_in_website>0</show_in_website>
|
30 |
+
<show_in_store>0</show_in_store>
|
31 |
+
<groups>
|
32 |
+
<extensioninfo translate="label">
|
33 |
+
<label>External Sources</label>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<sort_order>10</sort_order>
|
36 |
+
<expanded>1</expanded>
|
37 |
+
<show_in_default>1</show_in_default>
|
38 |
+
<show_in_website>0</show_in_website>
|
39 |
+
<show_in_store>0</show_in_store>
|
40 |
+
<comment>
|
41 |
+
<![CDATA[<div style="padding:10px;background-color:#fff;border:1px solid #ddd;margin-bottom:7px;">
|
42 |
+
<p><strong>Team23 External Sources</strong></p>
|
43 |
+
<p>This extension provides the possibility to add any external JavaScript or CSS resource via PHP or XML configuration.</p>
|
44 |
+
<p> </p>
|
45 |
+
<p><strong>Integration Information</strong></p>
|
46 |
+
<p>There are 2 possibilietes to add external js/css source to your template, either directly via blocks or via XML configuration. See examples.</p>
|
47 |
+
<p> </p>
|
48 |
+
<p><strong>Direct integration in PHP:</strong></p>
|
49 |
+
<pre>
|
50 |
+
public function prepareLayoutBefore(Varien_Event_Observer $observer)
|
51 |
+
{
|
52 |
+
$block = $observer->getEvent()->getBlock();
|
53 |
+
|
54 |
+
if ("head" == $block->getNameInLayout())
|
55 |
+
{
|
56 |
+
$block->addExternalJs('//code.jquery.com/jquery-1.11.0.min.js');
|
57 |
+
$block->addExternalCss('http://fonts.googleapis.com/css?family=Droid+Sans:400,700');
|
58 |
+
}
|
59 |
+
|
60 |
+
return $this;
|
61 |
+
}</pre>
|
62 |
+
<p> </p>
|
63 |
+
<p><strong>XML integration:</strong></p>
|
64 |
+
<pre>
|
65 |
+
<layout version="0.1.0">
|
66 |
+
<default>
|
67 |
+
<reference name="head">
|
68 |
+
<action method="addItem"><type>external_js</type><name>//code.jquery.com/jquery-1.11.0.min.js</name></action>
|
69 |
+
<action method="addItem"><type>external_css</type><name>http://fonts.googleapis.com/css?family=Droid+Sans:400,700</name></action>
|
70 |
+
</reference>
|
71 |
+
</default>
|
72 |
+
</layout>
|
73 |
+
</pre>
|
74 |
+
</div>]]>
|
75 |
+
</comment>
|
76 |
+
</extensioninfo>
|
77 |
+
</groups>
|
78 |
+
</externalsourcesinfo>
|
79 |
+
</sections>
|
80 |
+
</config>
|
app/etc/modules/Team23_ExternalSources.xml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<!--
|
4 |
+
/**
|
5 |
+
* Team23 External Sources
|
6 |
+
*
|
7 |
+
* @category Team23
|
8 |
+
* @package Team23_ExternalSources
|
9 |
+
* @version 1.0.0
|
10 |
+
* @copyright 2014 Team23 GmbH & Co. KG (http://www.team23.de)
|
11 |
+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
|
12 |
+
*/
|
13 |
+
-->
|
14 |
+
|
15 |
+
<config>
|
16 |
+
<modules>
|
17 |
+
<Team23_ExternalSources>
|
18 |
+
<active>true</active>
|
19 |
+
<codePool>community</codePool>
|
20 |
+
<depends/>
|
21 |
+
</Team23_ExternalSources>
|
22 |
+
</modules>
|
23 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Team23_ExternalSources</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/MIT">MITL</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>This extension provides the possibility to add any external JS or CSS resource via PHP or XML configuration.</summary>
|
10 |
+
<description>Team23 External Sources gives you the freedom to add easily any external source (e.g. from CDN) to your Magento theme. This can be done via XML configuration or directly in PHP code.
|
11 |
+

|
12 |
+
* Add external CSS / JS sources via XML or PHP function
|
13 |
+
* Light and easy to use
|
14 |
+
* Full open source
|
15 |
+

|
16 |
+
See attached screenshot for examples, or install extension, go to System -> Admin -> External Sources and read the documentation
|
17 |
+

|
18 |
+
This module is licensed under the MIT license.</description>
|
19 |
+
<notes>First stable release</notes>
|
20 |
+
<authors><author><name>Marc Rochow</name><user>team23</user><email>info@team23.de</email></author></authors>
|
21 |
+
<date>2014-04-14</date>
|
22 |
+
<time>16:16:16</time>
|
23 |
+
<contents><target name="magecommunity"><dir name="Team23"><dir name="ExternalSources"><dir name="Block"><dir name="Html"><file name="Head.php" hash="fc19ae1e9b7f67f202a2598180e71553"/></dir></dir><dir name="Helper"><file name="Data.php" hash="f936ab923976c83d643c91b6213176ce"/></dir><dir name="etc"><file name="adminhtml.xml" hash="5ec2a586ccfbd5b8c378476f5785545b"/><file name="config.xml" hash="5995b4192116da9d814b38df79170842"/><file name="system.xml" hash="433a5cd2c962fc468fb555ff0afde4f6"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Team23_ExternalSources.xml" hash="8a06b221d8f46c826626d2ec852df309"/></dir></target></contents>
|
24 |
+
<compatible/>
|
25 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.8.1.0</max></package></required></dependencies>
|
26 |
+
</package>
|