diff --git a/Block/Adminhtml/System/Config/Form/InfoBlogExtra.php b/Block/Adminhtml/System/Config/Form/InfoBlogExtra.php index bdcb11a8..7e2be951 100644 --- a/Block/Adminhtml/System/Config/Form/InfoBlogExtra.php +++ b/Block/Adminhtml/System/Config/Form/InfoBlogExtra.php @@ -37,7 +37,8 @@ protected function getSectionsJson(): string 'mfblog_blog_search', 'mfblog_sidebar_contents', 'mfblog_ai_writer', - 'mfblog_draft_autosave' + 'mfblog_draft_autosave', + 'mfblog_design_version' ]); return $sections; } diff --git a/Block/Author/PostList.php b/Block/Author/PostList.php index 8dbd563e..7d0c53aa 100755 --- a/Block/Author/PostList.php +++ b/Block/Author/PostList.php @@ -107,15 +107,30 @@ protected function _prepareLayout() */ public function getPostTemplateType() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + $template = (string)$this->getAuthor()->getData('posts_list_template'); + if (!empty($this->templatePool->getAll('blog_post_list' . ($designVersion == '2025-04' ? '_2025_04' : ''))[$template])) { + if ($template) { + return $template; + } + } $template = (string)$this->_scopeConfig->getValue( 'mfblog/author/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); - if ($template) { - return $template; + + + if ($designVersion == '2025-04') { + $template = $this->_scopeConfig->getValue( + 'mfblog/author/templates_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); } - $template = (string)$this->getAuthor()->getData('posts_list_template'); if ($template) { return $template; } diff --git a/Block/Catalog/Product/RelatedPosts.php b/Block/Catalog/Product/RelatedPosts.php index fe7474c1..e327e548 100755 --- a/Block/Catalog/Product/RelatedPosts.php +++ b/Block/Catalog/Product/RelatedPosts.php @@ -74,6 +74,20 @@ public function getProduct() return $this->getData('product'); } + /** + * @return string + */ + public function getBlockKey() { + return 'related-posts'; + } + + /** + * @return string + */ + public function getBlockTitle() { + return 'Related Posts'; + } + /** * Get relevant path to template * @@ -81,6 +95,29 @@ public function getProduct() */ public function getTemplate() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + if ($designVersion == '2025-04') { + $template = (string)$this->_scopeConfig->getValue( + 'mfblog/product_page/related_posts_template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + if ($template == 'default') { + return parent::getTemplate(); + } + if ($template == 'article-slider') { + return 'Magefan_BlogExtra::post/list/carousel-2025-04.phtml'; + } + if (strpos((string) parent::getTemplate(), 'article.phtml') !== false) { + return parent::getTemplate(); + } + + return 'Magefan_BlogExtra::post/view/post-bottom-2025-04.phtml'; + } + $templateName = (string)$this->_scopeConfig->getValue( 'mfblog/product_page/related_posts_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE diff --git a/Block/Post/PostList.php b/Block/Post/PostList.php index 1fbdbb8e..bfde0577 100755 --- a/Block/Post/PostList.php +++ b/Block/Post/PostList.php @@ -73,10 +73,11 @@ public function getPostHtml($post) */ public function getTemplate() { - if (!in_array($this->_template, ['post/list.phtml', 'Magefan_Blog::post/list.phtml'])) { - /* If template was not customized in layout */ - return parent::getTemplate(); - } + if (!in_array($this->_template, ['post/list.phtml', 'Magefan_Blog::post/list.phtml'])) { + /* If template was not customized in layout */ + return parent::getTemplate(); + } + if ($template = $this->templatePool->getTemplate('blog_post_list', $this->getPostTemplateType())) { $this->_template = $template; diff --git a/Block/Post/PostList/AbstractList.php b/Block/Post/PostList/AbstractList.php index 9284bd61..65c3431d 100755 --- a/Block/Post/PostList/AbstractList.php +++ b/Block/Post/PostList/AbstractList.php @@ -59,6 +59,11 @@ abstract class AbstractList extends Template implements IdentityInterface */ protected $templatePool; + /** + * @var + */ + protected $templateType ; + const POSTS_SORT_FIELD_BY_PUBLISH_TIME = 'main_table.publish_time'; const POSTS_SORT_FIELD_BY_POSITION = 'position'; const POSTS_SORT_FIELD_BY_TITLE = 'main_table.title'; @@ -277,4 +282,40 @@ public function readingTimeEnabled() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + + /** + * Set template type for new design + * + * @return mixed + */ + public function getNewDesignType() { + if (!$this->templateType) { + if (!empty($this->templatePool->getAll('blog_post_list_2025_04')[$this->getPostTemplateType()])) { + $this->setNewDesignType($this->getPostTemplateType()); + } else { + $this->setNewDesignType( + $this->_scopeConfig->getValue('mfblog/post_list/templates_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ); + } + if ($this->getRequest()->getFullActionName() == 'blog_index_index') { + $this->setNewDesignType( + $this->_scopeConfig->getValue('mfblog/index_page/templates_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ); + } + } + return $this->templateType; + } + + /** + * Get template type for new design + * + * @param $templateType + * @return $this + */ + public function setNewDesignType($templateType) { + $this->templateType = $templateType; + return $this; + } } diff --git a/Block/Post/View/Comments.php b/Block/Post/View/Comments.php index a54742cc..1da4253a 100755 --- a/Block/Post/View/Comments.php +++ b/Block/Post/View/Comments.php @@ -52,7 +52,7 @@ public function __construct( * Block template file * @var string */ - protected $_template = 'post/view/comments.phtml'; + protected $_template = 'Magefan_Blog::post/view/comments.phtml'; /** * Retrieve comments type diff --git a/Block/Post/View/RelatedPosts.php b/Block/Post/View/RelatedPosts.php index 68e49ecf..6ec9c9c6 100755 --- a/Block/Post/View/RelatedPosts.php +++ b/Block/Post/View/RelatedPosts.php @@ -63,6 +63,18 @@ public function getPost() return $this->getData('post'); } + /** + * @return string + */ + public function getBlockTitle() { + return 'Related Posts'; + } + /** + * @return string + */ + public function getBlockKey() { + return 'related-post'; + } /** * Get relevant path to template * @@ -70,6 +82,26 @@ public function getPost() */ public function getTemplate() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + if ($designVersion == '2025-04') { + $template = (string)$this->_scopeConfig->getValue( + 'mfblog/post_view/related_posts/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + if (strpos((string) parent::getTemplate(), 'article.phtml') !== false) { + return parent::getTemplate(); + } + + if ($template = $this->templatePool->getTemplate('blog_post_view_related_post_2025_04', $template)) { + return $template; + } + } + $templateName = (string)$this->_scopeConfig->getValue( 'mfblog/post_view/related_posts/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE diff --git a/Block/Sidebar/Featured.php b/Block/Sidebar/Featured.php index 1e378d9f..00641f05 100644 --- a/Block/Sidebar/Featured.php +++ b/Block/Sidebar/Featured.php @@ -62,18 +62,40 @@ protected function getPostIdsConfigValue() ); } + /** + * @return string + */ + public function getWidgetKey() { + return (string)$this->_widgetKey; + } + /** * Retrieve true if display the post image is enabled in the config * @return bool */ public function getDisplayImage() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + if ($designVersion == '2025-04') { + return false; + } return (bool)$this->_scopeConfig->getValue( 'mfblog/sidebar/'.$this->_widgetKey.'/display_image', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + public function getClass() { + return (string)$this->_scopeConfig->getValue( + 'mfblog/sidebar/'.$this->_widgetKey.'/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + /** * Get relevant path to template * @@ -81,13 +103,35 @@ public function getDisplayImage() */ public function getTemplate() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + $templateName = (string)$this->_scopeConfig->getValue( 'mfblog/sidebar/'.$this->_widgetKey.'/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + + if ($designVersion == '2025-04') { + $template = $this->_scopeConfig->getValue( + 'mfblog/sidebar/'.$this->_widgetKey.'/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + if (strpos((string) parent::getTemplate(), 'article.phtml') !== false) { + return parent::getTemplate(); + } + if ($template == 'default') { + $templateName = 'modern'; + } else { + return 'Magefan_BlogExtra::sidebar/recent_2025_04.phtml'; + } + } + if ($template = $this->templatePool->getTemplate('blog_post_sidebar_posts', $templateName)) { $this->_template = $template; } + return parent::getTemplate(); } } diff --git a/Block/Sidebar/Popular.php b/Block/Sidebar/Popular.php index 6c3bc5ca..313714b2 100644 --- a/Block/Sidebar/Popular.php +++ b/Block/Sidebar/Popular.php @@ -50,12 +50,26 @@ public function getCollectionOrderField() */ public function getDisplayImage() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + if ($designVersion == '2025-04') { + return false; + } return (bool)$this->_scopeConfig->getValue( 'mfblog/sidebar/'.$this->_widgetKey.'/display_image', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } - + + public function getClass() { + return (string)$this->_scopeConfig->getValue( + 'mfblog/sidebar/'.$this->_widgetKey.'/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } /** * Get relevant path to template * @@ -63,10 +77,30 @@ public function getDisplayImage() */ public function getTemplate() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); $templateName = (string)$this->_scopeConfig->getValue( 'mfblog/sidebar/'.$this->_widgetKey.'/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + + if ($designVersion == '2025-04') { + $template = $this->_scopeConfig->getValue( + 'mfblog/sidebar/'.$this->_widgetKey.'/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + if (strpos((string) parent::getTemplate(), 'article.phtml') !== false) { + return parent::getTemplate(); + } + if ($template == 'default') { + $templateName = 'modern'; + } else { + return 'Magefan_BlogExtra::sidebar/recent_2025_04.phtml'; + } + } + if ($template = $this->templatePool->getTemplate('blog_post_sidebar_posts', $templateName)) { $this->_template = $template; } diff --git a/Block/Sidebar/Recent.php b/Block/Sidebar/Recent.php index d5fa5656..2cc3c31d 100755 --- a/Block/Sidebar/Recent.php +++ b/Block/Sidebar/Recent.php @@ -51,12 +51,27 @@ protected function _preparePostCollection() */ public function getDisplayImage() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + + if ($designVersion == '2025-04') { + return false; + } return (bool)$this->_scopeConfig->getValue( 'mfblog/sidebar/'.$this->_widgetKey.'/display_image', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + public function getClass() { + return (string)$this->_scopeConfig->getValue( + 'mfblog/sidebar/'.$this->_widgetKey.'/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + /** * Get relevant path to template * @@ -64,10 +79,31 @@ public function getDisplayImage() */ public function getTemplate() { + $designVersion = (string)$this->_scopeConfig->getValue( + 'mfblog/design/version', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + $templateName = (string)$this->_scopeConfig->getValue( 'mfblog/sidebar/'.$this->_widgetKey.'/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + + if ($designVersion == '2025-04') { + $template = $this->_scopeConfig->getValue( + 'mfblog/sidebar/'.$this->_widgetKey.'/template_new', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + if (strpos((string) parent::getTemplate(), 'article.phtml') !== false) { + return parent::getTemplate(); + } + if ($template == 'default') { + $templateName = 'modern'; + } else { + return 'Magefan_BlogExtra::sidebar/recent_2025_04.phtml'; + } + } + if ($template = $this->templatePool->getTemplate('blog_post_sidebar_posts', $templateName)) { $this->_template = $template; } diff --git a/Block/Widget/Featured.php b/Block/Widget/Featured.php index b6fd5cf8..1c4d2ab9 100644 --- a/Block/Widget/Featured.php +++ b/Block/Widget/Featured.php @@ -23,7 +23,7 @@ class Featured extends \Magefan\Blog\Block\Sidebar\Featured implements \Magento\ public function _toHtml() { $this->setTemplate( - $this->getData('custom_template') ?: 'Magefan_Blog::widget/recent.phtml' + $this->getCustomTemplate() ); return \Magento\Framework\View\Element\Template::_toHtml(); @@ -46,9 +46,21 @@ public function getTitle() */ protected function getPostIdsConfigValue() { - return (string)$this->getData('posts_ids'); + $postsIds = (string) $this->getData('posts_ids'); + $registeredPostsIds = $this->_coreRegistry->registry('posts_ids'); + + if ($postsIds !== '' && $postsIds !== $registeredPostsIds) { + if ($registeredPostsIds !== null) { + $this->_coreRegistry->unregister('posts_ids'); + } + $this->_coreRegistry->register('posts_ids', $postsIds); + } + + return $this->_coreRegistry->registry('posts_ids'); } + + /** * Retrieve post short content * @@ -72,4 +84,34 @@ public function getTemplate() { return \Magefan\Blog\Block\Post\PostList\AbstractList::getTemplate(); } + + /** + * @return mixed + */ + public function getElementClass(){ + return 'featured'; + } + + /** + * @return string + */ + public function getCustomTemplate() { + $designVersion = $this->_scopeConfig->getValue('mfblog/design/version', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + if ($designVersion === '2025-04' && $this->getTemplate() && strpos($this->getTemplate(), 'article.phtml') !== false) { + return $this->getTemplate(); + } + if ($this->getData('mf_template')) { + if ($designVersion == '2025-04') { + $this->setNewDesignType($this->getData('mf_template')); + return 'Magefan_BlogExtra::widget/blog-widget-2025-04.phtml'; + } + + if ($template = $this->templatePool->getTemplate('blog_post_list', $this->getData('mf_template'))) { + return $template; + } + } elseif ($this->getData('custom_template')) { + return $this->getData('custom_template'); + } + return 'Magefan_Blog::widget/recent.phtml'; + } } diff --git a/Block/Widget/Recent.php b/Block/Widget/Recent.php index 270e4556..1d21db48 100755 --- a/Block/Widget/Recent.php +++ b/Block/Widget/Recent.php @@ -32,6 +32,9 @@ class Recent extends AbstractList implements \Magento\Widget\Block\BlockInterfac */ protected $_category; + + protected $mfTemplate = null; + /** * Construct * @@ -64,7 +67,7 @@ public function __construct( public function _toHtml() { $this->setTemplate( - $this->getData('custom_template') ?: 'Magefan_Blog::widget/recent.phtml' + $this->getCustomTemplate() ); foreach ($this->getPostCollection() as $item) { @@ -207,4 +210,36 @@ public function getCollectionOrderDirection() return parent::getCollectionOrderDirection(); } + + /** + * @return mixed + */ + public function getElementClass(){ + return 'recent'; + } + + /** + * @return string + */ + public function getCustomTemplate() { + $designVersion = $this->_scopeConfig->getValue('mfblog/design/version', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + if ($designVersion === '2025-04' && $this->getTemplate() + && strpos($this->getTemplate(), 'article.phtml') !== false + ) { + return $this->getTemplate(); + } + if ($this->getData('mf_template')) { + if ($designVersion === '2025-04') { + $this->setNewDesignType($this->getData('mf_template')); + return 'Magefan_BlogExtra::widget/blog-widget-2025-04.phtml'; + } + + if ($template = $this->templatePool->getTemplate('blog_post_list', $this->getData('mf_template'))) { + return $template; + } + } elseif ($this->getData('custom_template')) { + return $this->getData('custom_template'); + } + return 'Magefan_Blog::widget/recent.phtml'; + } } diff --git a/Model/Config/Source/DesignVersion.php b/Model/Config/Source/DesignVersion.php new file mode 100644 index 00000000..597e1665 --- /dev/null +++ b/Model/Config/Source/DesignVersion.php @@ -0,0 +1,42 @@ + '2024-12', 'label' => '2024-12'], + ['value' => '2025-04', 'label' => '2025-04'] + ]; + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toArray() + { + $array = []; + foreach ($this->toOptionArray() as $item) { + $array[$item['value']] = $item['label']; + } + return $array; + } +} diff --git a/Model/Config/Source/Template.php b/Model/Config/Source/Template.php index 7fb47943..16ab371e 100644 --- a/Model/Config/Source/Template.php +++ b/Model/Config/Source/Template.php @@ -52,6 +52,13 @@ public function toOptionArray():array if (!$this->templateType) { return[]; } + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $config = $objectManager->get(\Magefan\Blog\Model\Config::class); + + if ($this->templateType == 'blog_post_list' && ($config->getConfig('mfblog/design/version') == '2025-04')) { + $this->templateType = 'blog_post_list_2025_04'; + } + if (!isset($this->options[$this->templateType])) { $this->options[$this->templateType] = []; foreach ($this->templatePool->getAll($this->templateType) as $value => $info) { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 214c1397..0452e9cb 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -38,6 +38,11 @@ + + + Magefan\Blog\Model\Config\Source\DesignVersion + Magefan\Blog\Model\Config\Source\PageLayout @@ -97,6 +102,16 @@ Magefan\Blog\Model\Config\Source\PostListTemplate + + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\PostListTemplateNew + + 2025-04 + @@ -124,6 +139,9 @@ + + 2024-12 + Magefan\Blog\Model\Config\Source\PostViewTemplate @@ -141,6 +159,15 @@ Magefan\Blog\Model\Config\Source\LatestFromCategoryTemplate 1 + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\LatestFromCategoryTemplateNew + + 1 + 2025-04 @@ -162,6 +189,15 @@ Magefan\Blog\Model\Config\Source\RelatedPostTemplate 1 + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\RelatedPostTemplateNew + + 1 + 2025-04 @@ -371,6 +407,7 @@ Magefan\Blog\Model\Config\Source\NextPrevPostTemplate 1 + 2024-12 @@ -433,6 +470,16 @@ Magefan\Blog\Model\Config\Source\PostListTemplate + + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\PostListTemplateNew + + 2025-04 + @@ -481,6 +528,15 @@ Magefan\Blog\Model\Config\Source\PostListTemplate 1 + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\PostListTemplateNew + + 1 + 2025-04 @@ -579,6 +635,16 @@ Magefan\Blog\Model\Config\Source\PostListTemplate + + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\PostListTemplateNew + + 2025-04 + @@ -636,10 +702,23 @@ Magefan\Blog\Model\Config\Source\SidebarPostsTemplate + + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\SidebarPostsTemplateNew + + 2025-04 + Magento\Config\Model\Config\Source\Yesno + + 2024-12 + @@ -657,6 +736,16 @@ Magefan\Blog\Model\Config\Source\SidebarPostsTemplate + + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\SidebarPostsTemplateNew + + 2025-04 + @@ -682,6 +771,16 @@ Magefan\Blog\Model\Config\Source\SidebarPostsTemplate + + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\SidebarPostsTemplateNew + + 2025-04 + @@ -819,6 +918,15 @@ Magefan\Blog\Model\Config\Source\RelatedPostTemplate 1 + 2024-12 + + + + + Magefan\Blog\Model\Config\Source\RelatedPostTemplateNew + + 1 + 2025-04 @@ -924,7 +1032,7 @@ - Magefan\Blog\Model\Config\Source\PermalinkType + Magefan\Blog\Model\Config\Source\PermalinkType diff --git a/etc/config.xml b/etc/config.xml index 9a075cb9..5d8f7968 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -24,6 +24,7 @@ 0 + 2024-12 F d, Y 1 @@ -39,6 +40,7 @@ 0> 0