/app/code/core/Mage/Rss/Helper/Data.php

https://github.com/speedupmate/Magento-CE-Mirror · PHP · 149 lines · 70 code · 11 blank · 68 comment · 17 complexity · 9c8b801409e1947b6facb8d56e069531 MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Rss
  23. * @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Rss data helper
  28. *
  29. * @category Mage
  30. * @package Mage_Rss
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Rss_Helper_Data extends Mage_Core_Helper_Abstract
  34. {
  35. /**
  36. * Config path to RSS field
  37. */
  38. const XML_PATH_RSS_ACTIVE = 'rss/config/active';
  39. protected $_rssSession;
  40. protected $_adminSession;
  41. public function __construct(array $params = array())
  42. {
  43. $this->_rssSession = isset($params['rss_session']) ? $params['rss_session'] : Mage::getSingleton('rss/session');
  44. $this->_adminSession = isset($params['admin_session'])
  45. ? $params['admin_session'] : Mage::getSingleton('admin/session');
  46. }
  47. /**
  48. * Authenticate customer on frontend
  49. *
  50. */
  51. public function authFrontend()
  52. {
  53. if (!$this->_rssSession->isCustomerLoggedIn()) {
  54. list($username, $password) = $this->authValidate();
  55. $customer = Mage::getModel('customer/customer')->authenticate($username, $password);
  56. if ($customer && $customer->getId()) {
  57. $this->_rssSession->settCustomer($customer);
  58. } else {
  59. $this->authFailed();
  60. }
  61. }
  62. }
  63. /**
  64. * Authenticate admin and check ACL
  65. *
  66. * @param string $path
  67. */
  68. public function authAdmin($path)
  69. {
  70. if (!$this->_rssSession->isAdminLoggedIn() || !$this->_adminSession->isLoggedIn()) {
  71. list($username, $password) = $this->authValidate();
  72. Mage::getSingleton('adminhtml/url')->setNoSecret(true);
  73. $user = $this->_adminSession->login($username, $password);
  74. } else {
  75. $user = $this->_rssSession->getAdmin();
  76. }
  77. if ($user && $user->getId() && $user->getIsActive() == '1' && $this->_adminSession->isAllowed($path)) {
  78. $adminUserExtra = $user->getExtra();
  79. if ($adminUserExtra && !is_array($adminUserExtra)) {
  80. $adminUserExtra = Mage::helper('core/unserializeArray')->unserialize($user->getExtra());
  81. }
  82. if (!isset($adminUserExtra['indirect_login'])) {
  83. $adminUserExtra = array_merge($adminUserExtra, array('indirect_login' => true));
  84. $user->saveExtra($adminUserExtra);
  85. }
  86. $this->_adminSession->setIndirectLogin(true);
  87. $this->_rssSession->setAdmin($user);
  88. } else {
  89. $this->authFailed();
  90. }
  91. }
  92. /**
  93. * Validate Authenticate
  94. *
  95. * @param array $headers
  96. * @return array
  97. */
  98. public function authValidate($headers = null)
  99. {
  100. $userPass = Mage::helper('core/http')->authValidate($headers);
  101. return $userPass;
  102. }
  103. /**
  104. * Send authenticate failed headers
  105. *
  106. */
  107. public function authFailed()
  108. {
  109. Mage::helper('core/http')->authFailed();
  110. }
  111. /**
  112. * Disable using of flat catalog and/or product model to prevent limiting results to single store. Probably won't
  113. * work inside a controller.
  114. *
  115. * @return null
  116. */
  117. public function disableFlat()
  118. {
  119. /* @var $flatHelper Mage_Catalog_Helper_Product_Flat */
  120. $flatHelper = Mage::helper('catalog/product_flat');
  121. if ($flatHelper->isAvailable()) {
  122. /* @var $emulationModel Mage_Core_Model_App_Emulation */
  123. $emulationModel = Mage::getModel('core/app_emulation');
  124. // Emulate admin environment to disable using flat model - otherwise we won't get global stats
  125. // for all stores
  126. $emulationModel->startEnvironmentEmulation(0, Mage_Core_Model_App_Area::AREA_ADMINHTML);
  127. }
  128. }
  129. /**
  130. * Check if module was activated in system configurations
  131. *
  132. * @return bool
  133. */
  134. public function isRssEnabled()
  135. {
  136. return Mage::getStoreConfigFlag(self::XML_PATH_RSS_ACTIVE);
  137. }
  138. }