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 |
Definition at line 35 of file Feed.php.
_construct | ( | ) | [protected] |
checkUpdate | ( | ) |
Check feed for modification
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 | ) |
getFeedData | ( | ) |
Retrieve feed data as XML element
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
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
Definition at line 122 of file Feed.php.
00123 { 00124 return Mage::getStoreConfig(self::XML_FREQUENCY_PATH) * 3600; 00125 }
getLastUpdate | ( | ) |
setLastUpdate | ( | ) |
Set last update time (now)
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 }
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' |
const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https' |