Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_AdminNotification_Helper_Data
  • Mage_AdminNotification_Model_Feed
  • Mage_AdminNotification_Model_Inbox
  • Mage_AdminNotification_Model_Mysql4_Inbox
  • Mage_AdminNotification_Model_Mysql4_Inbox_Collection
  • Mage_AdminNotification_Model_Observer
  • Mage_AdminNotification_Model_Resource_Inbox
  • Mage_AdminNotification_Model_Resource_Inbox_Collection
  • Mage_AdminNotification_Model_Survey
  • Overview
  • Package
  • Class
  • Tree
  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 Feed model
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_AdminNotification
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_AdminNotification_Model_Feed extends Mage_Core_Model_Abstract
 36: {
 37:     const XML_USE_HTTPS_PATH    = 'system/adminnotification/use_https';
 38:     const XML_FEED_URL_PATH     = 'system/adminnotification/feed_url';
 39:     const XML_FREQUENCY_PATH    = 'system/adminnotification/frequency';
 40:     const XML_LAST_UPDATE_PATH  = 'system/adminnotification/last_update';
 41: 
 42:     /**
 43:      * Feed url
 44:      *
 45:      * @var string
 46:      */
 47:     protected $_feedUrl;
 48: 
 49:     /**
 50:      * Init model
 51:      *
 52:      */
 53:     protected function _construct()
 54:     {}
 55: 
 56:     /**
 57:      * Retrieve feed url
 58:      *
 59:      * @return string
 60:      */
 61:     public function getFeedUrl()
 62:     {
 63:         if (is_null($this->_feedUrl)) {
 64:             $this->_feedUrl = (Mage::getStoreConfigFlag(self::XML_USE_HTTPS_PATH) ? 'https://' : 'http://')
 65:                 . Mage::getStoreConfig(self::XML_FEED_URL_PATH);
 66:         }
 67:         return $this->_feedUrl;
 68:     }
 69: 
 70:     /**
 71:      * Check feed for modification
 72:      *
 73:      * @return Mage_AdminNotification_Model_Feed
 74:      */
 75:     public function checkUpdate()
 76:     {
 77:         if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
 78:             return $this;
 79:         }
 80: 
 81:         $feedData = array();
 82: 
 83:         $feedXml = $this->getFeedData();
 84: 
 85:         if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
 86:             foreach ($feedXml->channel->item as $item) {
 87:                 $feedData[] = array(
 88:                     'severity'      => (int)$item->severity,
 89:                     'date_added'    => $this->getDate((string)$item->pubDate),
 90:                     'title'         => (string)$item->title,
 91:                     'description'   => (string)$item->description,
 92:                     'url'           => (string)$item->link,
 93:                 );
 94:             }
 95: 
 96:             if ($feedData) {
 97:                 Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData));
 98:             }
 99: 
100:         }
101:         $this->setLastUpdate();
102: 
103:         return $this;
104:     }
105: 
106:     /**
107:      * Retrieve DB date from RSS date
108:      *
109:      * @param string $rssDate
110:      * @return string YYYY-MM-DD YY:HH:SS
111:      */
112:     public function getDate($rssDate)
113:     {
114:         return gmdate('Y-m-d H:i:s', strtotime($rssDate));
115:     }
116: 
117:     /**
118:      * Retrieve Update Frequency
119:      *
120:      * @return int
121:      */
122:     public function getFrequency()
123:     {
124:         return Mage::getStoreConfig(self::XML_FREQUENCY_PATH) * 3600;
125:     }
126: 
127:     /**
128:      * Retrieve Last update time
129:      *
130:      * @return int
131:      */
132:     public function getLastUpdate()
133:     {
134:         return Mage::app()->loadCache('admin_notifications_lastcheck');
135: //        return Mage::getStoreConfig(self::XML_LAST_UPDATE_PATH);
136:     }
137: 
138:     /**
139:      * Set last update time (now)
140:      *
141:      * @return Mage_AdminNotification_Model_Feed
142:      */
143:     public function setLastUpdate()
144:     {
145:         Mage::app()->saveCache(time(), 'admin_notifications_lastcheck');
146: //        $config = Mage::getModel('core/config');
147: //        /* @var $config Mage_Core_Model_Config */
148: //        $config->saveConfig(self::XML_LAST_UPDATE_PATH, time());
149:         return $this;
150:     }
151: 
152:     /**
153:      * Retrieve feed data as XML element
154:      *
155:      * @return SimpleXMLElement
156:      */
157:     public function getFeedData()
158:     {
159:         $curl = new Varien_Http_Adapter_Curl();
160:         $curl->setConfig(array(
161:             'timeout'   => 2
162:         ));
163:         $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
164:         $data = $curl->read();
165:         if ($data === false) {
166:             return false;
167:         }
168:         $data = preg_split('/^\r?$/m', $data, 2);
169:         $data = trim($data[1]);
170:         $curl->close();
171: 
172:         try {
173:             $xml  = new SimpleXMLElement($data);
174:         }
175:         catch (Exception $e) {
176:             return false;
177:         }
178: 
179:         return $xml;
180:     }
181: 
182:     public function getFeedXml()
183:     {
184:         try {
185:             $data = $this->getFeedData();
186:             $xml  = new SimpleXMLElement($data);
187:         }
188:         catch (Exception $e) {
189:             $xml  = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?>');
190:         }
191: 
192:         return $xml;
193:     }
194: }
195: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0