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@magentocommerce.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.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_AdminNotification
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * AdminNotification Data helper
30: *
31: * @category Mage
32: * @package Mage_AdminNotification
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_AdminNotification_Helper_Data extends Mage_Core_Helper_Abstract
36: {
37: const XML_PATH_POPUP_URL = 'system/adminnotification/popup_url';
38:
39: /**
40: * Widget Popup Notification Object URL
41: *
42: * @var string
43: */
44: protected $_popupUrl;
45:
46: /**
47: * Is readable Popup Notification Object flag
48: *
49: * @var bool
50: */
51: protected $_popupReadable;
52:
53: /**
54: * Last Notice object
55: *
56: * @var Mage_AdminNotification_Model_Inbox
57: */
58: protected $_latestNotice;
59:
60: /**
61: * count of unread notes by type
62: *
63: * @var array
64: */
65: protected $_unreadNoticeCounts;
66:
67: /**
68: * Retrieve latest notice model
69: *
70: * @return Mage_AdminNotification_Model_Inbox
71: */
72: public function getLatestNotice()
73: {
74: if (is_null($this->_latestNotice)) {
75: $this->_latestNotice = Mage::getModel('adminnotification/inbox')->loadLatestNotice();
76: }
77: return $this->_latestNotice;
78: }
79:
80: /**
81: * Retrieve count of unread notes by type
82: *
83: * @param int $severity
84: * @return int
85: */
86: public function getUnreadNoticeCount($severity)
87: {
88: if (is_null($this->_unreadNoticeCounts)) {
89: $this->_unreadNoticeCounts = Mage::getModel('adminnotification/inbox')->getNoticeStatus();
90: }
91: return isset($this->_unreadNoticeCounts[$severity]) ? $this->_unreadNoticeCounts[$severity] : 0;
92: }
93:
94: /**
95: * Retrieve Widget Popup Notification Object URL
96: *
97: * @param bool $withExt
98: * @return string
99: */
100: public function getPopupObjectUrl($withExt = false)
101: {
102: if (is_null($this->_popupUrl)) {
103: $sheme = Mage::app()->getFrontController()->getRequest()->isSecure()
104: ? 'https://'
105: : 'http://';
106:
107: $this->_popupUrl = $sheme . Mage::getStoreConfig(self::XML_PATH_POPUP_URL);
108: }
109: return $this->_popupUrl . ($withExt ? '.swf' : '');
110: }
111:
112: /**
113: * Check is readable Popup Notification Object
114: * @deprecated after 1.4.2.0
115: *
116: * @return bool
117: */
118: public function isReadablePopupObject()
119: {
120: if (is_null($this->_popupReadable)) {
121: $this->_popupReadable = false;
122: $curl = new Varien_Http_Adapter_Curl();
123: $curl->setConfig(array(
124: 'timeout' => 2
125: ));
126: $curl->write(Zend_Http_Client::GET, $this->getPopupObjectUrl(true));
127: if ($curl->read()) {
128: if ($curl->getInfo(CURLINFO_HTTP_CODE) == 200) {
129: $this->_popupReadable = true;
130: }
131: }
132:
133: $curl->close();
134: }
135: return $this->_popupReadable;
136: }
137: }
138: