Comments.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © 2015 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Block\Post\View;
  9. use Magento\Store\Model\ScopeInterface;
  10. /**
  11. * Blog post comments block
  12. */
  13. class Comments extends \Magento\Framework\View\Element\Template
  14. {
  15. /**
  16. * @var \Magento\Framework\Locale\ResolverInterface
  17. */
  18. protected $_localeResolver;
  19. /**
  20. * @var \Magento\Framework\Registry
  21. */
  22. protected $_coreRegistry;
  23. /**
  24. * Construct
  25. *
  26. * @param \Magento\Framework\View\Element\Context $context
  27. * @param \Magento\Framework\Registry $coreRegistry,
  28. * @param \Magento\Cms\Model\Page $post
  29. * @param \Magento\Framework\Registry $coreRegistry,
  30. * @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
  31. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  32. * @param \Magento\Cms\Model\PageFactory $postFactory
  33. * @param array $data
  34. */
  35. public function __construct(
  36. \Magento\Framework\View\Element\Template\Context $context,
  37. \Magento\Framework\Registry $coreRegistry,
  38. \Magento\Framework\Locale\ResolverInterface $localeResolver,
  39. array $data = []
  40. ) {
  41. parent::__construct($context, $data);
  42. $this->_coreRegistry = $coreRegistry;
  43. $this->_localeResolver = $localeResolver;
  44. }
  45. /**
  46. * Block template file
  47. * @var string
  48. */
  49. protected $_template = 'post/view/comments.phtml';
  50. /**
  51. * Retrieve comments type
  52. * @return bool
  53. */
  54. public function getCommentsType()
  55. {
  56. return $this->_scopeConfig->getValue(
  57. 'mfblog/post_view/comments/type', ScopeInterface::SCOPE_STORE
  58. );
  59. }
  60. /**
  61. * Retrieve number of comments to display
  62. * @return int
  63. */
  64. public function getNumberOfComments()
  65. {
  66. return (int)$this->_scopeConfig->getValue(
  67. 'mfblog/post_view/comments/number_of_comments', ScopeInterface::SCOPE_STORE
  68. );
  69. }
  70. /**
  71. * Retrieve facebook app id
  72. * @return string
  73. */
  74. public function getFacebookAppId()
  75. {
  76. return $this->_scopeConfig->getValue(
  77. 'mfblog/post_view/comments/fb_app_id', ScopeInterface::SCOPE_STORE
  78. );
  79. }
  80. /**
  81. * Retrieve disqus forum shortname
  82. * @return string
  83. */
  84. public function getDisqusShortname()
  85. {
  86. return $this->_scopeConfig->getValue(
  87. 'mfblog/post_view/comments/disqus_forum_shortname', ScopeInterface::SCOPE_STORE
  88. );
  89. }
  90. /**
  91. * Retrieve locale code
  92. * @return string
  93. */
  94. public function getLocaleCode()
  95. {
  96. return $this->_localeResolver->getLocale();
  97. }
  98. /**
  99. * Retrieve posts instance
  100. *
  101. * @return \Magefan\Blog\Model\Category
  102. */
  103. public function getPost()
  104. {
  105. if (!$this->hasData('post')) {
  106. $this->setData('post',
  107. $this->_coreRegistry->registry('current_blog_post')
  108. );
  109. }
  110. return $this->getData('post');
  111. }
  112. }