Feed.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Mageplaza
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Mageplaza.com license that is
  8. * available through the world-wide-web at this URL:
  9. * https://www.mageplaza.com/LICENSE.txt
  10. *
  11. * DISCLAIMER
  12. *
  13. * Do not edit or add to this file if you wish to upgrade this extension to newer
  14. * version in the future.
  15. *
  16. * @category Mageplaza
  17. * @package Mageplaza_Core
  18. * @copyright Copyright (c) 2016-2018 Mageplaza (http://www.mageplaza.com/)
  19. * @license https://www.mageplaza.com/LICENSE.txt
  20. */
  21. namespace Mageplaza\Core\Model;
  22. /**
  23. * Class Feed
  24. * @package Mageplaza\Core\Model
  25. */
  26. class Feed extends \Magento\AdminNotification\Model\Feed
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. const MAGEPLAZA_FEED_URL = 'www.mageplaza.com/notifications.xml';
  32. /**
  33. * @inheritdoc
  34. */
  35. public function getFeedUrl()
  36. {
  37. $httpPath = $this->_backendConfig->isSetFlag(self::XML_USE_HTTPS_PATH) ? 'https://' : 'http://';
  38. if ($this->_feedUrl === null) {
  39. $this->_feedUrl = $httpPath . self::MAGEPLAZA_FEED_URL;
  40. }
  41. return $this->_feedUrl;
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. public function checkUpdate()
  47. {
  48. if (!(boolean)$this->_backendConfig->getValue('mageplaza/general/notice_enable')) {
  49. return $this;
  50. }
  51. return parent::checkUpdate();
  52. }
  53. /**
  54. * @inheritdoc
  55. */
  56. public function getFeedData()
  57. {
  58. $type = $this->_backendConfig->getValue('mageplaza/general/notice_type');
  59. if (!$type) {
  60. return false;
  61. }
  62. $feedXml = parent::getFeedData();
  63. if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
  64. $typeArray = explode(',', $type);
  65. $noteToRemove = [];
  66. foreach ($feedXml->channel->item as $item) {
  67. if (!in_array((string)$item->type, $typeArray)) {
  68. $noteToRemove[] = $item;
  69. }
  70. }
  71. foreach ($noteToRemove as $item) {
  72. unset($item[0]);
  73. }
  74. }
  75. return $feedXml;
  76. }
  77. /**
  78. * @inheritdoc
  79. */
  80. public function getLastUpdate()
  81. {
  82. return $this->_cacheManager->load('mageplaza_notifications_lastcheck');
  83. }
  84. /**
  85. * @inheritdoc
  86. */
  87. public function setLastUpdate()
  88. {
  89. $this->_cacheManager->save(time(), 'mageplaza_notifications_lastcheck');
  90. return $this;
  91. }
  92. }