Skip to content

Commit b4c9be2

Browse files
committed
Refactoring before release
1 parent d747886 commit b4c9be2

File tree

11 files changed

+115
-147
lines changed

11 files changed

+115
-147
lines changed

Block/Adminhtml/Widget/Featured/Grid/Chooser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected function _toHtml() : string
193193

194194
$html = '
195195
<input id="'. $chooserId . '_input" class="widget-option input-text admin__control-text"
196-
onkeyup="keyupFunctionMf()"
196+
onkeyup="keyupFunctionMfSelectPostIds()"
197197
value="' . ($this->getLabel() ? $this->escapeHtml($this->getLabel()) : '') .'" />
198198
<label class="widget-option-label" style="display: none" id="' .
199199
$chooserId .
@@ -204,7 +204,7 @@ protected function _toHtml() : string
204204
$chooserId .
205205
'advice-container" class="hidden"></div>';
206206

207-
$script = 'window.keyupFunctionMf = function() {
207+
$script = 'window.keyupFunctionMfSelectPostIds = function() {
208208
var inputV = document.getElementById("' . $chooserId . '_input").value;
209209
' . $chooserId . '.setElementValue(inputV);
210210
' . $chooserId . '.setElementLabel(inputV);

Block/Archive/Archive.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Block\Archive;
10+
11+
trait Archive
12+
{
13+
/**
14+
* Get archive month
15+
* @return int
16+
*/
17+
public function getMonth()
18+
{
19+
return (int)$this->_coreRegistry->registry('current_blog_archive_month');
20+
}
21+
22+
/**
23+
* Get archive year
24+
* @return int
25+
*/
26+
public function getYear()
27+
{
28+
return (int)$this->_coreRegistry->registry('current_blog_archive_year');
29+
}
30+
31+
32+
/**
33+
* @param string $content
34+
* @return string
35+
*/
36+
private function filterContent(string $content):string
37+
{
38+
if (!$content) {
39+
return '';
40+
}
41+
$vars = ['year', 'month'];
42+
foreach ($vars as $var) {
43+
$schemaVar = '{{' . $var . '}}';
44+
if (strpos($content, $schemaVar) !== false) {
45+
$value = '';
46+
switch ($var) {
47+
case 'year':
48+
$value = date('Y', strtotime($this->getYear() . '-01-01'));
49+
break;
50+
case 'month':
51+
if ($this->getMonth()) {
52+
$value = date('F', strtotime($this->getYear() . '-' . $this->getMonth() . '-01'));
53+
}
54+
break;
55+
}
56+
$content = str_replace($schemaVar, $value, $content);
57+
}
58+
}
59+
return $content;
60+
}
61+
}

Block/Archive/Description.php

+4-19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
class Description extends Template
1919
{
20+
use Archive;
21+
2022
/**
2123
* @var \Magento\Framework\Registry
2224
*/
@@ -42,7 +44,7 @@ public function __construct(
4244
*/
4345
public function getDescription(): string
4446
{
45-
$description = $this->_scopeConfig->getValue(
47+
$description = (string)$this->_scopeConfig->getValue(
4648
'mfblog/archive/description',
4749
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4850
);
@@ -51,25 +53,8 @@ public function getDescription(): string
5153
return '';
5254
}
5355

54-
$vars = ['year', 'month'];
55-
$values = [];
56-
57-
foreach ($vars as $var) {
58-
$schemaVar = '{{' . $var . '}}';
59-
if (strpos($description, $schemaVar) !== false) {
60-
switch ($var) {
61-
case 'year':
62-
$values[$var] = date('Y', strtotime((int)$this->_coreRegistry->registry('current_blog_archive_year') . '-01-01'));
63-
break;
64-
case 'month':
65-
$data = (int)$this->_coreRegistry->registry('current_blog_archive_year') . '-' . (int)$this->_coreRegistry->registry('current_blog_archive_month') . '-01';
66-
$values[$var] = date('F', strtotime($data));
67-
break;
68-
}
69-
$description = str_replace($schemaVar, $values[$var] ?? '', $description);
70-
}
56+
$description = $this->filterContent($description);
7157

72-
}
7358
return (string)$description;
7459
}
7560
}

Block/Archive/PostList.php

+9-61
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
namespace Magefan\Blog\Block\Archive;
1010

11-
use Magefan\Blog\Block\Post\PostList\Toolbar;
1211
use Magento\Store\Model\ScopeInterface;
1312

1413
/**
1514
* Blog archive posts list
1615
*/
1716
class PostList extends \Magefan\Blog\Block\Post\PostList
1817
{
18+
use Archive;
19+
1920
/**
2021
* Prepare posts collection
2122
* @return \Magefan\Blog\Model\ResourceModel\Post\Collection
@@ -29,37 +30,22 @@ protected function _preparePostCollection()
2930
);
3031
}
3132

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-
5033
/**
5134
* Preparing global layout
5235
*
5336
* @return $this
5437
*/
5538
protected function _prepareLayout()
5639
{
57-
$title = $this->_getTitle();
40+
$title = $this->filterContent((string)$this->_getConfigValue('title'));
5841
$this->_addBreadcrumbs($title, 'blog_search');
59-
$this->pageConfig->getTitle()->set($title);
6042

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')));
6349

6450
if ($this->config->getDisplayCanonicalTag(\Magefan\Blog\Model\Config::CANONICAL_PAGE_TYPE_ARCHIVE)) {
6551
$month = '';
@@ -94,16 +80,6 @@ protected function _prepareLayout()
9480
return parent::_prepareLayout();
9581
}
9682

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-
10783
/**
10884
* @param $param
10985
* @return mixed
@@ -116,32 +92,4 @@ protected function _getConfigValue($param)
11692
);
11793
}
11894

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-
}
14795
}

Block/Post/CustomCss.php

-57
This file was deleted.

Block/Post/View/CustomCss.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Magefan\Blog\Block\Post\View;
12+
13+
use Magefan\Blog\Block\Post\AbstractPost;
14+
15+
class CustomCss extends AbstractPost
16+
{
17+
/**
18+
* Render html output
19+
*
20+
* @return string
21+
*/
22+
protected function _toHtml()
23+
{
24+
$post = $this->getPost();
25+
if ($post && $post->getCustomCss()) {
26+
return '<style>' . strip_tags($post->getCustomCss()) . '</style>';
27+
}
28+
29+
return '';
30+
}
31+
}

Model/Version.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
/**
3737
* @return false|string
3838
*/
39-
public function getVersion()
39+
public function getVersion(): string
4040
{
4141
try {
4242
$moduleName = 'Blog';
@@ -53,7 +53,7 @@ public function getVersion()
5353
$data = ['version' => $currentVersion, 'edition' => $edition];
5454
return json_encode($data);
5555
} catch (\Exception $e) {
56-
return false;
56+
return json_encode(['error' => true, 'message' => $e->getMessage()]);
5757
}
5858
}
5959
}

Plugin/Magento/Framework/App/Config/ScopeConfigInterfacePlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class ScopeConfigInterfacePlugin
1313
*/
1414
private $blogRoutes = [
1515
"index" => 'blog_index_index',
16-
"category" => 'blog_category_view',
1716
"post" => 'blog_post_view',
17+
"category" => 'blog_category_view',
1818
"author" => 'blog_author_view',
1919
"archive" =>'blog_archive_view',
2020
'tag' => 'blog_tag_view'

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"name": "magefan/module-blog",
33
"description": "Implements Blog functionality on Magento 2 store",
44
"require": {
5-
"magefan/module-community" : ">=2.1.30",
5+
"magefan/module-community" : ">=2.2.7",
66
"magefan/module-blog-graph-ql" : ">=2.1.9",
7-
"magefan/module-wysiwyg-advanced" : ">=2.0.16"
7+
"magefan/module-wysiwyg-advanced" : ">=2.0.17"
88
},
99
"suggest": {
1010
"magefan/module-amp-blog": "Install this module to activate Blog integration with the Plumrocket AMP extension."
1111
},
1212
"type": "magento2-module",
13-
"version": "2.12.2",
13+
"version": "2.12.3",
1414
"autoload": {
1515
"files": [ "registration.php" ],
1616
"psr-4": {

view/frontend/layout/blog_post_view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<block class="Magefan\Blog\Block\Social\AddThis" name="addthis.js.init" as="addthisJs" template="Magefan_Blog::addthis-js.phtml"/>
6262
</container>
6363
</block>
64-
<block class="Magefan\Blog\Block\Post\CustomCss" name="magefan.blog.post.custom.css" />
64+
<block class="Magefan\Blog\Block\Post\View\CustomCss" name="magefan.blog.post.custom.css" />
6565
</referenceContainer>
6666
</body>
6767
</page>

view/frontend/web/css/blog-new.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ body.blog-page {
2929

3030
.post-holder {margin-bottom: 40px;border-radius: 0;}
3131

32-
32+
.blog-page-list .index-description {margin-bottom: 15px}
3333

3434
/* Blog Post List *****************************************************************************************************/
3535
.post-list {margin-top: 0;margin-bottom: 20px;list-style: none;padding-left: 0}

0 commit comments

Comments
 (0)