Team23_SeoPagination - Version 1.0.0

Version Notes

First stable release.

- Adds rel="prev" / rel="next" to HTML head section
- Possibility to provide better robots meta tag
- Optimized canonical tag

Download this release

Release Info

Developer David Danier
Extension Team23_SeoPagination
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Team23/SeoPagination/Helper/Data.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Team23 SeoPagination
5
+ *
6
+ * @category Team23
7
+ * @package Team23_SeoPagination
8
+ * @version 1.0.0
9
+ * @copyright 2016 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_SeoPagination_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+
17
+ /**
18
+ * Paths to module config
19
+ */
20
+ const XML_PATH_USE_PREVNEXT = 'catalog/seo/relprevnext';
21
+ const XML_PATH_USE_CANONICAL = 'catalog/seo/canonical';
22
+ const XML_PATH_ROBOTS_SETTING = 'catalog/seo/robots';
23
+ const XML_PATH_ALLOW_ALL = 'catalog/frontend/list_allow_all';
24
+
25
+ /**
26
+ * Check if module output is enabled
27
+ *
28
+ * @return bool
29
+ */
30
+ public function isEnabled()
31
+ {
32
+ if (!parent::isModuleOutputEnabled($this->_getModuleName())) {
33
+ return false;
34
+ }
35
+
36
+ return true;
37
+ }
38
+
39
+ /**
40
+ * Check if rel="prev" and rel="next" is in use
41
+ *
42
+ * @param Mage_Core_Model_Store $store
43
+ * @return bool
44
+ */
45
+ public function usePrevNext($store)
46
+ {
47
+ return (bool) Mage::getStoreConfigFlag(self::XML_PATH_USE_PREVNEXT, $store)
48
+ && !$this->isAllowAll($store);
49
+ }
50
+
51
+ /**
52
+ * Check if 'Allow All Products per Page' is enabled
53
+ *
54
+ * @param Mage_Core_Model_Store $store
55
+ * @return bool
56
+ */
57
+ public function isAllowAll($store) {
58
+ return (bool) Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_ALL, $store);
59
+ }
60
+
61
+ /**
62
+ * Check if canonical tag is used
63
+ *
64
+ * @param Mage_Core_Model_Store $store
65
+ * @return bool
66
+ */
67
+ public function useCanonical($store)
68
+ {
69
+ return (bool) Mage::getStoreConfigFlag(
70
+ self::XML_PATH_USE_CANONICAL, $store);
71
+ }
72
+
73
+ /**
74
+ * Get robot setting
75
+ *
76
+ * @param Mage_Core_Model_Store $store
77
+ * @return string
78
+ */
79
+ public function getRobots($store) {
80
+ return Mage::getStoreConfig(self::XML_PATH_ROBOTS_SETTING, $store);
81
+ }
82
+
83
+ }
app/code/community/Team23/SeoPagination/Model/Observer.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Team23 SeoPagination
5
+ *
6
+ * @category Team23
7
+ * @package Team23_SeoPagination
8
+ * @version 1.0.0
9
+ * @copyright 2016 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_SeoPagination_Model_Observer
15
+ {
16
+
17
+ /**
18
+ * Inject SEO pagination, if enabled
19
+ *
20
+ * @param Varien_Event_Observer $observer
21
+ * @return $this
22
+ */
23
+ public function injectPagination(Varien_Event_Observer $observer)
24
+ {
25
+ if (!Mage::helper('seopagination')->isEnabled())
26
+ return $this;
27
+
28
+ try {
29
+ $paginator = Mage::getModel('seopagination/paginator');
30
+ $paginator->createLinks();
31
+ } catch (Exception $e) {
32
+ Mage::logException($e);
33
+ }
34
+
35
+ return $this;
36
+ }
37
+
38
+ }
app/code/community/Team23/SeoPagination/Model/Paginator.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Team23 SeoPagination
5
+ *
6
+ * @category Team23
7
+ * @package Team23_SeoPagination
8
+ * @version 1.0.0
9
+ * @copyright 2016 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_SeoPagination_Model_Paginator extends Mage_Core_Model_Abstract
15
+ {
16
+
17
+ /** @var Mage_Page_Block_Html_Pager|null $_pager */
18
+ protected $_pager = null;
19
+
20
+ /** @var int|null $_limit */
21
+ protected $_limit = null;
22
+
23
+ /**
24
+ * Get product collection from layer
25
+ *
26
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
27
+ */
28
+ protected function _getProductCollection()
29
+ {
30
+ /** @var Mage_Catalog_Model_Layer $layer */
31
+ $layer = Mage::getSingleton('catalog/layer');
32
+
33
+ $collection = $layer->getProductCollection();
34
+ $collection->setPageSize($this->_getLimit());
35
+
36
+ return $collection;
37
+ }
38
+
39
+ /**
40
+ * Get toolbar block
41
+ *
42
+ * @return Mage_Catalog_Block_Product_List_Toolbar
43
+ */
44
+ protected function _getToolbar()
45
+ {
46
+ return Mage::app()->getLayout()
47
+ ->createBlock('catalog/product_list_toolbar');
48
+ }
49
+
50
+ /**
51
+ * Get product collection limit
52
+ *
53
+ * @return int|null
54
+ */
55
+ protected function _getLimit()
56
+ {
57
+ if (is_null($this->_limit))
58
+ $this->_limit = intval($this->_getToolbar()->getLimit());
59
+
60
+ return $this->_limit;
61
+ }
62
+
63
+ /**
64
+ * Get pager class
65
+ *
66
+ * @return Mage_Page_Block_Html_Pager
67
+ */
68
+ protected function _getPager()
69
+ {
70
+ if (is_null($this->_pager))
71
+ {
72
+ $collection = $this->_getProductCollection();
73
+
74
+ $this->_pager = Mage::app()->getLayout()
75
+ ->createBlock('page/html_pager');
76
+ $this->_pager->setLimit($this->_getLimit())
77
+ ->setCollection($collection);
78
+ }
79
+
80
+ return $this->_pager;
81
+ }
82
+
83
+ /**
84
+ * Get first page URL
85
+ *
86
+ * @return string
87
+ */
88
+ protected function _getFirstPageUrl()
89
+ {
90
+ $pager = $this->_getPager();
91
+
92
+ return $pager->getPagerUrl(array(
93
+ $pager->getPageVarName() => null
94
+ ));
95
+ }
96
+
97
+ /**
98
+ * Get previous page URL
99
+ *
100
+ * @return string
101
+ */
102
+ protected function _getPreviousPageUrl()
103
+ {
104
+ $pager = $this->_getPager();
105
+
106
+ if ($pager->getCurrentPage() > 2) {
107
+ return $pager->getPreviousPageUrl();
108
+ }
109
+
110
+ return $this->_getFirstPageUrl();
111
+ }
112
+
113
+ /**
114
+ * Create rel="next" and/or rel="prev" links and canonical tag, if enabled
115
+ */
116
+ public function createLinks()
117
+ {
118
+ /** @var Mage_Page_Block_Html_Head $headBlock */
119
+ $headBlock = Mage::app()->getLayout()->getBlock('head');
120
+
121
+ /** @var Mage_Core_Model_Store $store */
122
+ $store = Mage::app()->getStore();
123
+
124
+ $usePrevNext = Mage::helper('seopagination')->usePrevNext($store);
125
+
126
+ $pager = $this->_getPager();
127
+
128
+ if ($pager->getCurrentPage() != 1) {
129
+ $headBlock->setRobots(Mage::helper('seopagination')->getRobots($store));
130
+ }
131
+
132
+ if (Mage::helper('seopagination')->useCanonical($store)) {
133
+ $headBlock->removeItem('link_rel', $this->_getCategory()->getUrl());
134
+ $headBlock->removeItem('link_rel', $this->_getFirstPageUrl());
135
+
136
+ if ($usePrevNext) {
137
+ $headBlock->addLinkRel('canonical', $this->_getCategory()->getUrl());
138
+ } else {
139
+ $headBlock->addLinkRel('canonical', $this->_getToolbar()->getLimitUrl('all'));
140
+ }
141
+ }
142
+
143
+ if ($usePrevNext) {
144
+ if ($pager->getCurrentPage() < $pager->getLastPageNum()) {
145
+ $headBlock->addLinkRel('next',
146
+ $this->_getPageUrl($pager->getCollection()->getCurPage(+1)));
147
+ }
148
+
149
+ if ($pager->getCurrentPage() > 1) {
150
+ $headBlock->addLinkRel('prev',
151
+ $this->_getPageUrl($pager->getCollection()->getCurPage(-1)));
152
+ }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Get pager URL
158
+ *
159
+ * @param int $page
160
+ * @return string
161
+ */
162
+ protected function _getPageUrl($page)
163
+ {
164
+ return $this->_getCategory()->getUrl() . '?p' . (string) $page;
165
+ }
166
+
167
+ /**
168
+ * Get current category
169
+ *
170
+ * @return Mage_Catalog_Model_Category
171
+ */
172
+ protected function _getCategory()
173
+ {
174
+ return Mage::registry('current_category');
175
+ }
176
+
177
+ }
app/code/community/Team23/SeoPagination/etc/config.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * Team23 SeoPagination
6
+ *
7
+ * @category Team23
8
+ * @package Team23_SeoPagination
9
+ * @version 1.0.0
10
+ * @copyright 2016 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_SeoPagination>
18
+ <version>1.0.0</version>
19
+ </Team23_SeoPagination>
20
+ </modules>
21
+
22
+ <global>
23
+ <models>
24
+ <seopagination>
25
+ <class>Team23_SeoPagination_Model</class>
26
+ </seopagination>
27
+ </models>
28
+
29
+ <helpers>
30
+ <seopagination>
31
+ <class>Team23_SeoPagination_Helper</class>
32
+ </seopagination>
33
+ </helpers>
34
+ </global>
35
+
36
+ <frontend>
37
+ <events>
38
+ <controller_action_layout_render_before_catalog_category_view>
39
+ <observers>
40
+ <seopagination>
41
+ <type>singleton</type>
42
+ <class>seopagination/observer</class>
43
+ <method>injectPagination</method>
44
+ </seopagination>
45
+ </observers>
46
+ </controller_action_layout_render_before_catalog_category_view>
47
+ </events>
48
+ </frontend>
49
+
50
+ <adminhtml>
51
+ <translate>
52
+ <modules>
53
+ <Team23_SeoPagination>
54
+ <files>
55
+ <default>Team23_SeoPagination.csv</default>
56
+ </files>
57
+ </Team23_SeoPagination>
58
+ </modules>
59
+ </translate>
60
+ </adminhtml>
61
+
62
+ <default>
63
+ <catalog>
64
+ <seo>
65
+ <relprevnext>0</relprevnext>
66
+ <canonical>0</canonical>
67
+ <robots>INDEX,FOLLOW</robots>
68
+ </seo>
69
+ </catalog>
70
+ </default>
71
+ </config>
app/code/community/Team23/SeoPagination/etc/system.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * Team23 SeoPagination
6
+ *
7
+ * @category Team23
8
+ * @package Team23_SeoPagination
9
+ * @version 1.0.0
10
+ * @copyright 2016 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
+ <sections>
17
+ <catalog>
18
+ <groups>
19
+ <seo>
20
+ <fields>
21
+ <relprevnext translate="label comment" module="seopagination">
22
+ <label>Use rel="next" and rel="prev"</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>9</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <comment>Only applies if "Allow All Products per Page" is disabled.</comment>
30
+ </relprevnext>
31
+ <canonical translate="label comment" module="seopagination">
32
+ <label>Add canonical tag</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
+ <sort_order>10</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ <comment>Adds canonical tag depending on "Allow All Products per Page" setting.</comment>
40
+ </canonical>
41
+ <robots translate="label comment" module="seopagination">
42
+ <label>Robots setting</label>
43
+ <frontend_type>select</frontend_type>
44
+ <source_model>adminhtml/system_config_source_design_robots</source_model>
45
+ <sort_order>11</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment>Applies to paginated pages.</comment>
50
+ </robots>
51
+ </fields>
52
+ </seo>
53
+ </groups>
54
+ </catalog>
55
+ </sections>
56
+ </config>
app/etc/modules/Team23_SeoPagination.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * Team23 SeoPagination
6
+ *
7
+ * @category Team23
8
+ * @package Team23_SeoPagination
9
+ * @version 1.0.0
10
+ * @copyright 2016 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_SeoPagination>
18
+ <active>true</active>
19
+ <codePool>community</codePool>
20
+ <depends>
21
+ <Mage_Catalog/>
22
+ </depends>
23
+ </Team23_SeoPagination>
24
+ </modules>
25
+ </config>
app/locale/de_DE/Team23_SeoPagination.csv ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ "Use rel=""next"" and rel=""prev""","Verwende rel=""next"" und rel=""prev"""
2
+ "Only applies if ""Allow All Products per Page"" is disabled.","Wird nur angewandt wenn ""Erlaube alle Artikel pro Seite"" deaktiviert ist."
3
+ "Add canonical tag","Füge Canonical Tag hinzu"
4
+ "Adds canonical tag depending on ""Allow All Products per Page"" setting.","Fügt Canonical Tag in Abhängigkeit der Einstellung ""Erlaube alle Artikel pro Seite""."
5
+ "Robots setting","Robots Einstellung"
6
+ "Applies to paginated pages.","Bei Paginierten Seiten."
app/locale/en_US/Team23_SeoPagination.csv ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ "Use rel=""next"" and rel=""prev""","Use rel=""next"" and rel=""prev"""
2
+ "Only applies if ""Allow All Products per Page"" is disabled.","Only applies if ""Allow All Products per Page"" is disabled."
3
+ "Add canonical tag","Add canonical tag"
4
+ "Adds canonical tag depending on ""Allow All Products per Page"" setting.","Adds canonical tag depending on ""Allow All Products per Page"" setting."
5
+ "Robots setting","Robots setting"
6
+ "Applies to paginated pages.","Applies to paginated pages."
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Team23_SeoPagination</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/MIT">The MIT License (MIT)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>SEO optimized pagination.</summary>
10
+ <description>Adds optimized Canonical Tag and next/prev link relations to HTML head section. And also adds a better robots meta tag on paginated pages.</description>
11
+ <notes>First stable release.&#xD;
12
+ &#xD;
13
+ - Adds rel="prev" / rel="next" to HTML head section&#xD;
14
+ - Possibility to provide better robots meta tag&#xD;
15
+ - Optimized canonical tag&#xD;
16
+ </notes>
17
+ <authors><author><name>Marc Rochow</name><user>team23</user><email>magento@team23.de</email></author></authors>
18
+ <date>2016-09-16</date>
19
+ <time>12:03:24</time>
20
+ <contents><target name="magecommunity"><dir name="Team23"><dir name="SeoPagination"><dir name="Helper"><file name="Data.php" hash="db529303d45b43fe74a232b5ef650b78"/></dir><dir name="Model"><file name="Observer.php" hash="2b7855312707c56f79fa50df62dfd011"/><file name="Paginator.php" hash="e18565d5675c9528f3e54a4e652ae8f8"/></dir><dir name="etc"><file name="config.xml" hash="e29032f96eaf3c8bc3b8333c6de4f7ba"/><file name="system.xml" hash="d3ac0ff56caf6af39cb731f77c695bbd"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Team23_SeoPagination.xml" hash="546bfb2475b57b715d325db5b876c1c5"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Team23_SeoPagination.csv" hash="fe8651b0b778a9685d46be5a2bea2353"/></dir><dir name="de_DE"><file name="Team23_SeoPagination.csv" hash="3d3084c22fe79ddc54018a3d79fa24f0"/></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.3.0</min><max>8.0.0</max></php></required></dependencies>
23
+ </package>