Mage_AdminNotification_Model_Feed Class Reference

Inheritance diagram for Mage_AdminNotification_Model_Feed:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getFeedUrl ()
 checkUpdate ()
 getDate ($rssDate)
 getFrequency ()
 getLastUpdate ()
 setLastUpdate ()
 getFeedData ()
 getFeedXml ()

Public Attributes

const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https'
const XML_FEED_URL_PATH = 'system/adminnotification/feed_url'
const XML_FREQUENCY_PATH = 'system/adminnotification/frequency'
const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update'

Protected Member Functions

 _construct ()

Protected Attributes

 $_feedUrl


Detailed Description

Definition at line 35 of file Feed.php.


Member Function Documentation

_construct (  )  [protected]

Init model

Reimplemented from Varien_Object.

Definition at line 53 of file Feed.php.

00054     {}

checkUpdate (  ) 

Check feed for modification

Returns:
Mage_AdminNotification_Model_Feed

Definition at line 75 of file Feed.php.

00076     {
00077         if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
00078             return $this;
00079         }
00080 
00081         $feedData = array();
00082 
00083         $feedXml = $this->getFeedData();
00084 
00085         if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
00086             foreach ($feedXml->channel->item as $item) {
00087                 $feedData[] = array(
00088                     'severity'      => (int)$item->severity,
00089                     'date_added'    => $this->getDate((string)$item->pubDate),
00090                     'title'         => (string)$item->title,
00091                     'description'   => (string)$item->description,
00092                     'url'           => (string)$item->link,
00093                 );
00094             }
00095 
00096             if ($feedData) {
00097                 Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData));
00098             }
00099 
00100         }
00101         $this->setLastUpdate();
00102 
00103         return $this;
00104     }

getDate ( rssDate  ) 

Retrieve DB date from RSS date

Parameters:
string $rssDate
Returns:
string YYYY-MM-DD YY:HH:SS

Definition at line 112 of file Feed.php.

00113     {
00114         return gmdate('Y-m-d H:i:s', strtotime($rssDate));
00115     }

getFeedData (  ) 

Retrieve feed data as XML element

Returns:
SimpleXMLElement

Definition at line 157 of file Feed.php.

00158     {
00159         $curl = new Varien_Http_Adapter_Curl();
00160         $curl->setConfig(array(
00161             'timeout'   => 2
00162         ));
00163         $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
00164         $data = $curl->read();
00165         if ($data === false) {
00166             return false;
00167         }
00168         $data = preg_split('/^\r?$/m', $data, 2);
00169         $data = trim($data[1]);
00170         $curl->close();
00171 
00172         try {
00173             $xml  = new SimpleXMLElement($data);
00174         }
00175         catch (Exception $e) {
00176             return false;
00177         }
00178 
00179         return $xml;
00180     }

getFeedUrl (  ) 

Retrieve feed url

Returns:
string

Definition at line 61 of file Feed.php.

00062     {
00063         if (is_null($this->_feedUrl)) {
00064             $this->_feedUrl = (Mage::getStoreConfigFlag(self::XML_USE_HTTPS_PATH) ? 'https://' : 'http://')
00065                 . Mage::getStoreConfig(self::XML_FEED_URL_PATH);
00066         }
00067         return $this->_feedUrl;
00068     }

getFeedXml (  ) 

Definition at line 182 of file Feed.php.

00183     {
00184         try {
00185             $data = $this->getFeedData();
00186             $xml  = new SimpleXMLElement($data);
00187         }
00188         catch (Exception $e) {
00189             $xml  = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?>');
00190         }
00191 
00192         return $xml;
00193     }

getFrequency (  ) 

Retrieve Update Frequency

Returns:
int

Definition at line 122 of file Feed.php.

00123     {
00124         return Mage::getStoreConfig(self::XML_FREQUENCY_PATH) * 3600;
00125     }

getLastUpdate (  ) 

Retrieve Last update time

Returns:
int

Definition at line 132 of file Feed.php.

00133     {
00134         return Mage::app()->loadCache('admin_notifications_lastcheck');
00135 //        return Mage::getStoreConfig(self::XML_LAST_UPDATE_PATH);
00136     }

setLastUpdate (  ) 

Set last update time (now)

Returns:
Mage_AdminNotification_Model_Feed

Definition at line 143 of file Feed.php.

00144     {
00145         Mage::app()->saveCache(time(), 'admin_notifications_lastcheck');
00146 //        $config = Mage::getModel('core/config');
00147 //        /* @var $config Mage_Core_Model_Config */
00148 //        $config->saveConfig(self::XML_LAST_UPDATE_PATH, time());
00149         return $this;
00150     }


Member Data Documentation

$_feedUrl [protected]

Definition at line 47 of file Feed.php.

const XML_FEED_URL_PATH = 'system/adminnotification/feed_url'

Definition at line 38 of file Feed.php.

const XML_FREQUENCY_PATH = 'system/adminnotification/frequency'

Definition at line 39 of file Feed.php.

const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update'

Definition at line 40 of file Feed.php.

const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https'

Definition at line 37 of file Feed.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:30 2009 for Magento by  doxygen 1.5.8