8
8
9
9
namespace Magefan \Blog \Block \Archive ;
10
10
11
- use Magefan \Blog \Block \Post \PostList \Toolbar ;
12
11
use Magento \Store \Model \ScopeInterface ;
13
12
14
13
/**
15
14
* Blog archive posts list
16
15
*/
17
16
class PostList extends \Magefan \Blog \Block \Post \PostList
18
17
{
18
+ use Archive;
19
+
19
20
/**
20
21
* Prepare posts collection
21
22
* @return \Magefan\Blog\Model\ResourceModel\Post\Collection
@@ -29,37 +30,22 @@ protected function _preparePostCollection()
29
30
);
30
31
}
31
32
32
- /**
33
- * Get archive month
34
- * @return int
35
- */
36
- public function getMonth ()
37
- {
38
- return (int )$ this ->_coreRegistry ->registry ('current_blog_archive_month ' );
39
- }
40
-
41
- /**
42
- * Get archive year
43
- * @return int
44
- */
45
- public function getYear ()
46
- {
47
- return (int )$ this ->_coreRegistry ->registry ('current_blog_archive_year ' );
48
- }
49
-
50
33
/**
51
34
* Preparing global layout
52
35
*
53
36
* @return $this
54
37
*/
55
38
protected function _prepareLayout ()
56
39
{
57
- $ title = $ this ->_getTitle ( );
40
+ $ title = $ this ->filterContent (( string ) $ this -> _getConfigValue ( ' title ' ) );
58
41
$ this ->_addBreadcrumbs ($ title , 'blog_search ' );
59
- $ this ->pageConfig ->getTitle ()->set ($ title );
60
42
61
- $ this ->pageConfig ->setKeywords ($ this ->replaceVars ($ this ->_getConfigValue ('meta_keywords ' )));
62
- $ this ->pageConfig ->setDescription ($ this ->replaceVars ($ this ->_getConfigValue ('meta_description ' )));
43
+ $ this ->pageConfig ->getTitle ()->set (
44
+ $ this ->_getConfigValue ('meta_title ' ) ? $ this ->filterContent ($ this ->_getConfigValue ('meta_title ' )) : $ title
45
+ );
46
+
47
+ $ this ->pageConfig ->setKeywords ($ this ->filterContent ((string )$ this ->_getConfigValue ('meta_keywords ' )));
48
+ $ this ->pageConfig ->setDescription ($ this ->filterContent ((string )$ this ->_getConfigValue ('meta_description ' )));
63
49
64
50
if ($ this ->config ->getDisplayCanonicalTag (\Magefan \Blog \Model \Config::CANONICAL_PAGE_TYPE_ARCHIVE )) {
65
51
$ month = '' ;
@@ -94,16 +80,6 @@ protected function _prepareLayout()
94
80
return parent ::_prepareLayout ();
95
81
}
96
82
97
- /**
98
- * Retrieve title
99
- * @return string
100
- */
101
- protected function _getTitle ()
102
- {
103
- return (string )$ this ->replaceVars ($ this ->_getConfigValue ('meta_title ' ) ?: $ this ->_getConfigValue ('title ' ));
104
- }
105
-
106
-
107
83
/**
108
84
* @param $param
109
85
* @return mixed
@@ -116,32 +92,4 @@ protected function _getConfigValue($param)
116
92
);
117
93
}
118
94
119
- /**
120
- * @param $content
121
- * @return array|mixed|string|string[]
122
- */
123
- private function replaceVars ($ content )
124
- {
125
- if (!$ content ) {
126
- return '' ;
127
- }
128
- $ vars = ['year ' , 'month ' ];
129
- $ values = [];
130
- foreach ($ vars as $ var ) {
131
- $ schemaVar = '{{ ' . $ var . '}} ' ;
132
- if ($ content && strpos ($ content , $ schemaVar ) !== false ) {
133
- switch ($ var ) {
134
- case 'year ' :
135
- $ values [$ var ] = date ('Y ' , strtotime ($ this ->getYear () . '-01-01 ' ));
136
- break ;
137
- case 'month ' :
138
- $ values [$ var ] = date ('F ' , strtotime ($ this ->getYear () . '- ' . $ this ->getMonth () . '-01 ' ));
139
- break ;
140
- }
141
- $ content = str_replace ($ schemaVar , $ values [$ var ] ?? '' , $ content );
142
- }
143
-
144
- }
145
- return $ content ;
146
- }
147
95
}
0 commit comments