We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit be7d9a9d authored by brokentwill's avatar brokentwill

Version 1.2.8 Add more magic functions in helper

parent a57652c7
<?php
/**
* Extensions Manager Extension
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://store.onlinebizsoft.com/license.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to admin@onlinebizsoft.com so we can mail you a copy immediately.
*
* @category Magento Extensions
* @package ExtensionManager
* @author OnlineBiz <sales@onlinebizsoft.com>
* @copyright 2007-2011 OnlineBiz
* @license http://store.onlinebizsoft.com/license.txt
* @version 1.0.1
* @link http://store.onlinebizsoft.com
*/
class OnlineBiz_ObBase_Block_Notification_Window extends Mage_Adminhtml_Block_Notification_Window{
protected function _construct(){
parent::_construct();
if(!Mage::getStoreConfig('obbase/install/run')){
$c = Mage::getModel('core/config_data');
$c->setScope('default')
->setPath('obbase/install/run')
->setValue(time())
->save();
$this->setHeaderText($this->__("OnlineBiz Notifications Setup"));
$this->setIsFirstRun(1);
$this->setIsHtml(1);
}
}
protected function _toHtml(){
if($this->getIsHtml()){
$this->setTemplate('onlinebizsoft/obbase/notification/window.phtml');
}
return parent::_toHtml();
}
public function presetFirstSetup(){
}
public function getNoticeMessageText(){
return $this->getData('notice_message_text');
}
}
...@@ -31,16 +31,11 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Conflict ...@@ -31,16 +31,11 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Conflict
{ {
$html = $this->_getHeaderHtml($element); $html = $this->_getHeaderHtml($element);
$html .= '<table cellpadding="5" cellspacing="5"> $html .= '<table cellpadding="5" cellspacing="5">
<tr><td width="80">Core Module</td><td>Core Class</td><td>Rewrite Classes</td><td>Conflict</td></tr>'; <tr><td width="80">Core Module</td><td>Core Class</td><td>Rewrite Classes</td><td>Is Conflict ?</td></tr>';
//retrieve all config.xml
$tConfigFiles = $this->getConfigFilesList();
//parse all config.xml //parse all config.xml
$rewrites = array(); $rewrites = Mage::helper('obbase')->getAllRewrites();
foreach($tConfigFiles as $configFile)
{
$rewrites = $this->getRewriteForFile($configFile, $rewrites);
}
$i = 0; $i = 0;
foreach($rewrites as $key => $value) foreach($rewrites as $key => $value)
{ {
...@@ -114,128 +109,6 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Conflict ...@@ -114,128 +109,6 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Conflict
} }
return $version; return $version;
} }
/**
*
*
* @param unknown_type $dirName
* @return unknown
*/
private function directoryIsValid($dirName)
{
switch ($dirName) {
case '.':
case '..':
case '':
return false;
break;
default:
return true;
break;
}
}
private function manageModule($moduleName)
{
switch ($moduleName) {
case 'global':
return false;
break;
default:
return true;
break;
}
}
/**
* create an array with all config.xml files
*
*/
public function getConfigFilesList()
{
$retour = array();
//$codePath = Mage::getStoreConfig('system/filesystem/code');
$codePath = BP . DS . 'app' . DS . 'code';
$tmpPath = Mage::app()->getConfig()->getTempVarDir().'/obexconflict/';
if (!is_dir($tmpPath))
mkdir($tmpPath);
$locations = array();
$locations[] = $codePath.'/local/';
$locations[] = $codePath.'/community/';
$locations[] = $tmpPath;
foreach ($locations as $location)
{
//parse every sub folders (means extension folders)
$poolDir = opendir($location);
while($namespaceName = readdir($poolDir))
{
if (!$this->directoryIsValid($namespaceName))
continue;
//parse modules within namespace
$namespacePath = $location.$namespaceName.'/';
$namespaceDir = opendir($namespacePath);
while($moduleName = readdir($namespaceDir))
{
if (!$this->directoryIsValid($moduleName))
continue;
$modulePath = $namespacePath.$moduleName.'/';
$configXmlPath = $modulePath.'etc/config.xml';
if (file_exists($configXmlPath))
$retour[] = $configXmlPath;
}
closedir($namespaceDir);
}
closedir($poolDir);
}
return $retour;
}
/**
* Return all rewrites for a config.xml
*
* @param unknown_type $configFilePath
*/
public function getRewriteForFile($configFilePath, $results)
{
try {
//load xml
$xmlcontent = file_get_contents($configFilePath);
$domDocument = new DOMDocument();
$domDocument->loadXML($xmlcontent);
//parse every node types
$nodeTypes = array('blocks', 'models', 'helpers');
foreach ($nodeTypes as $nodeType) {
if (!$domDocument->documentElement)
continue;
foreach ($domDocument->documentElement->getElementsByTagName($nodeType) as $nodeTypeMarkup) {
foreach ($nodeTypeMarkup->getElementsByTagName('rewrite') as $markup) {
//parse child nodes
$moduleName = $markup->parentNode->tagName;
if ($this->manageModule($moduleName)) {
foreach ($markup->getElementsByTagName('*') as $childNode) {
//get information
$className = $nodeType . '_' . $childNode->tagName;
$rewriteClass = $childNode->nodeValue;
//add to result
$key = $moduleName . '/' . $className;
if (!isset($results[$key]))
$results[$key] = array();
$results[$key][] = $rewriteClass;
}
}
}
}
}
} catch (Exception $ex) {
return $results;
}
return $results;
}
} }
...@@ -33,14 +33,18 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Extensions ...@@ -33,14 +33,18 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Extensions
$modules = array_keys((array)Mage::getConfig()->getNode('modules')->children()); $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
sort($modules); sort($modules);
$html.= '<table cellspacing="5"><tr><td>Status</td><td>Name</td><td>Installed Version</td><td>Latest Release</td><td>Online Document</td><tr>';
foreach ($modules as $moduleName) { foreach ($modules as $moduleName) {
if (strstr($moduleName,'OnlineBiz_') === false) { if (strstr($moduleName,'OnlineBiz_') === false) {
continue; continue;
} }
$field = $this->_getFieldData($moduleName);
$html.= $this->_getFieldHtml($element, $moduleName); $html .= '<tr><td>'.$field['icon'].'</td><td>'.$field['label'].'</td><td>'.$field['current_version'].'</td><td>'.$field['new_version'].'</td><td>'.$field['document'].'</td><tr>';
} }
$html .= '</table>';
$html .= $this->_getFooterHtml($element); $html .= $this->_getFooterHtml($element);
return $html; return $html;
...@@ -62,7 +66,7 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Extensions ...@@ -62,7 +66,7 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Extensions
return $this->_fieldRenderer; return $this->_fieldRenderer;
} }
protected function _getFieldHtml($fieldset, $moduleName) protected function _getFieldData($moduleName)
{ {
$configData = $this->getConfigData(); $configData = $this->getConfigData();
$path = 'advanced/modules_disable_output/'.$moduleName; //TODO: move as property of form $path = 'advanced/modules_disable_output/'.$moduleName; //TODO: move as property of form
...@@ -71,53 +75,60 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Extensions ...@@ -71,53 +75,60 @@ class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Extensions
$e = $this->_getDummyElement(); $e = $this->_getDummyElement();
$moduleKey = substr($moduleName, strpos($moduleName,'_')+1); $moduleKey = substr($moduleName, strpos($moduleName,'_')+1);
$ver = (Mage::getConfig()->getModuleConfig($moduleName)->version); $current_version = (Mage::getConfig()->getModuleConfig($moduleName)->version);
$id = $moduleName; $id = $moduleName;
$hasUpdate = false; $url = false;
if($displayNames = Mage::app()->loadCache('base_extensions_feed')){ $name = false;
$new_version = false;
$document = false;
if($displayNames = Mage::app()->loadCache('obbase_extensions_feed')){
if($displayNames = unserialize($displayNames)){ if($displayNames = unserialize($displayNames)){
if(isset($displayNames[$moduleName])){ if(isset($displayNames[$moduleName])){
$url = @$displayNames[$moduleName]['url']; $url = @$displayNames[$moduleName]['url'];
$name = @$displayNames[$moduleName]['display_name']; $name = @$displayNames[$moduleName]['display_name'];
$version = @$displayNames[$moduleName]['version']; $new_version = @$displayNames[$moduleName]['version'];
$document = @$displayNames[$moduleName]['document'];
$moduleName = '<a href="'.$url.'" target="_blank" title="'.$name.'">'.$name."</a>";
if($this->_convertVersion($ver) < $this->_convertVersion($version)){
$update = '<a href="'.$url.'" target="_blank"><img src="'.$this->getSkinUrl('onlinebizsoft/obbase/images/update.gif').'" title="'.$this->__("Update available").'"/></a>';
$hasUpdate = 1;
$moduleName ="$update $moduleName";
}
} }
} }
} }
if(!$hasUpdate){ if (!$name) $name = $moduleName;
$update = '<a target="_blank"><img src="'.$this->getSkinUrl('onlinebizsoft/obbase/images/ok.gif').'" title="'.$this->__("Installed").'"/></a>';
$moduleName ="$update $moduleName";
}
if($ver){ if ($url) {
$labelName = '<a href="'.$url.'" target="_blank" title="'.$name.'">'.$name."</a>";
} else {
$labelName = $name;
}
if($this->_convertVersion($current_version) < $this->_convertVersion($new_version)){
$icon = '<a href="'.$url.'" target="_blank"><img src="'.$this->getSkinUrl('onlinebizsoft/obbase/images/update.gif').'" title="'.$this->__("Version %s available", $new_version).'"/></a>';
} else {
$icon = '<a target="_blank"><img src="'.$this->getSkinUrl('onlinebizsoft/obbase/images/ok.gif').'" title="'.$this->__("Installed").'"/></a>';
}
if (!$new_version) {
$new_version = 'n/a';
}
if (!$document) {
$document = 'n/a';
} else {
$document = '<a href="'.$document.'">Read me</a>';
}
$field = $fieldset->addField($id, 'label', $field = array(
array( 'icon' => $icon,
'name' => 'ssssss', 'label' => $labelName,
'label' => $moduleName, 'current_version' => $current_version,
'value' => $ver . '<a href="">Document</a>', 'new_version' => $new_version,
'document' => $document,
))->setRenderer($this->_getFieldRenderer()); );
return $field->toHtml();
}
return '';
return $field;
} }
protected function _convertVersion($v){ protected function _convertVersion($v){
$digits = @explode(".", $v); $digits = @explode(".", $v);
$version = 0; $version = 0;
......
...@@ -19,49 +19,31 @@ ...@@ -19,49 +19,31 @@
* @link http://store.onlinebizsoft.com * @link http://store.onlinebizsoft.com
*/ */
class OnlineBiz_ObBase_Model_Feed_Abstract extends Mage_Core_Model_Abstract{
/**
* Retrieve feed data as XML element
*
* @return SimpleXMLElement
*/
public function getFeedData()
{
$curl = new Varien_Http_Adapter_Curl();
$curl->setConfig(array(
'timeout' => 1
));
$curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
$data = $curl->read();
if ($data === false) {
return false;
}
$data = preg_split('/^\r?$/m', $data, 2);
$data = trim($data[1]);
$curl->close();
try {
$xml = new SimpleXMLElement($data);
}
catch (Exception $e) {
return false;
}
return $xml;
}
class OnlineBiz_ObBase_Block_System_Config_Form_Fieldset_Support
extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
{
protected $_dummyElement;
protected $_fieldRenderer;
protected $_values;
/** public function render(Varien_Data_Form_Element_Abstract $element)
* Retrieve DB date from RSS date
*
* @param string $rssDate
* @return string YYYY-MM-DD YY:HH:SS
*/
public function getDate($rssDate)
{ {
return gmdate('Y-m-d H:i:s', strtotime($rssDate)); $html = $this->_getHeaderHtml($element);
$html .= 'You can submit a ticket at <a href="http://ticket.onlinebizsoft.com">ticket.onlinebizsoft.com</a> (preferred) or contact our support team at <a href="mailto:support@onlinebizsoft.com?subject=Support request for order XXXXXXXXX&amp;body=Problem description%20%3A%0D%0AMy store URL%20%3A%0D%0AMy license key%20%3A%0D%0AMy backend URL%20%3A%0D%0AAdmin login account%20%3A%0D%0AFTP login%20%3A%0D%0AphpMyAdmin access%20%3A%0D%0A">support@onlinebizsoft.com</a><br>
We will require you to provide below information for support<br>
<ul>
<li>- Your order ID at our store</li>
<li>- URL of your Magento installation</li>
<li>- The license key which is valid for your above Magento URL</li>
<li>- Magento backend URL and admin login (user and password)</li>
<li>- FTP Login to your Magento installation</li>
<li>- In some cases, we may require phpMyAdmin access to your Magento database</li>
</ul>';
$html .= $this->_getFooterHtml($element);
return $html;
} }
} }
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
class OnlineBiz_ObBase_Helper_Config extends Mage_Core_Helper_Abstract{ class OnlineBiz_ObBase_Helper_Config extends Mage_Core_Helper_Abstract{
/** Extensions feed path */ /** Extensions feed path */
const EXTENSIONS_FEED_URL = 'http://store.onlinebizsoft.com/feeds/extensions.xml'; const EXTENSIONS_FEED_URL = 'https://store.onlinebizsoft.com/feeds/extensions.xml';
/** Updates Feed path */ /** Updates Feed path */
const UPDATES_FEED_URL = 'http://store.onlinebizsoft.com/feeds/updates.xml'; const UPDATES_FEED_URL = 'https://store.onlinebizsoft.com/feeds/updates.xml';
/** Store URL */ /** Store URL */
const STORE_URL = 'http://store.onlinebizsoft.com/store/'; const STORE_URL = 'https://store.onlinebizsoft.com/store/';
/** Store response cache key*/ /** Store response cache key*/
const STORE_RESPONSE_CACHE_KEY = 'onlinebiz_store_response_cache_key'; const STORE_RESPONSE_CACHE_KEY = 'onlinebiz_store_response_cache_key';
......
...@@ -21,29 +21,236 @@ ...@@ -21,29 +21,236 @@
class OnlineBiz_ObBase_Helper_Data extends Mage_Core_Helper_Abstract class OnlineBiz_ObBase_Helper_Data extends Mage_Core_Helper_Abstract
{ {
public static function isActivated($module, $key=false, $generalConfig) protected $_own_module_name = false;
public function getOwnModuleName() {
if (!$this->_own_module_name) {
$this->_own_module_name = substr(get_class($this), 10, strpos(get_class($this), '_', 10)-10);//auto extract the own module name from helper class
}
return $this->_own_module_name;
}
public function isEnabled() {
return $this->isActivated('OnlineBiz_'.$this->getOwnModuleName());
}
//for writing trace or important information to log if debug is enabled
public function debug($string) {
if (Mage::getStoreConfig(strtolower($this->getOwnModuleName()). '/general/debug')) {
Mage::log($this->getOwnModuleName() . ' : ' . $string, null, 'obdebug.log');
}
}
//only call when a fatal error happen - should be written with all exception messages
public function error($string) {
Mage::log($this->getOwnModuleName() . ' : ' . $string, null, 'obdebug.log');
}
public function isConflict($module) {
$rewrites = $this->getAllRewrites();
$i = 0;
foreach($rewrites as $key => $value)
{
$i++;
$found = false;
foreach ($value as $class_name) {
if ((strpos($class_name, $module) === 0)) {
$found = true;
break;
}
}
$t = explode('/', $key);
$moduleName = $t[0];
$className = $t[1];
$rewriteClasses = join(', ', $value);
$conflict = 0;
if (count($value) > 1)
$conflict = 1;
if ($found && $conflict) {
return true;
}
}
return false;
}
public function isActivated($module, $key = false, $generalConfig = false)
{ {
//no need to pass Enabled path
if (!$generalConfig) {
$generalConfig = strtolower($this->getOwnModuleName()). '/general/enabled';
}
//normalize domain
$servStr = $_SERVER['HTTP_HOST']; $servStr = $_SERVER['HTTP_HOST'];
$servStr = str_replace('https://', '', $servStr); $servStr = str_replace('https://', '', $servStr);
$servStr = str_replace('http://', '', $servStr); $servStr = str_replace('http://', '', $servStr);
$servStr = str_replace('www.', '', $servStr); $servStr = str_replace('www.', '', $servStr);
$keys = preg_split("/(\r\n|\n|\r)/", Mage::getStoreConfig('managekey/general/keys'));
foreach($keys as $key){
if(base64_encode(md5($servStr.$module)) == $key && Mage::getStoreConfig($generalConfig)) {
return true;
}
}
//test/dev/local sites
if((preg_match('/dev./',$servStr) || preg_match('/test./',$servStr) || preg_match('/demo./',$servStr)) && Mage::getStoreConfig($generalConfig)) if((preg_match('/dev./',$servStr) || preg_match('/test./',$servStr) || preg_match('/demo./',$servStr)) && Mage::getStoreConfig($generalConfig))
return true; return true;
if(($servStr == '127.0.0.1' || preg_match('/localhost/',$servStr)) && Mage::getStoreConfig($generalConfig)) if(($servStr == '127.0.0.1' || preg_match('/localhost/',$servStr)) && Mage::getStoreConfig($generalConfig))
return true; return true;
//pass module key when check (old key management system)
if($key) { if($key) {
if(base64_encode(md5($servStr.$module)) == $key && Mage::getStoreConfig($generalConfig)) if(base64_encode(md5($servStr.$module)) == $key && Mage::getStoreConfig($generalConfig))
return true; return true;
} }
$keys = preg_split("/(\r\n|\n|\r)/", Mage::getStoreConfig('managekey/general/keys'));
foreach($keys as $key){ return false;
if(base64_encode(md5($servStr.$module)) == $key && Mage::getStoreConfig($generalConfig)) { }
/**
* create an array with all config.xml files
*
*/
protected function _getConfigFilesList()
{
$retour = array();
//$codePath = Mage::getStoreConfig('system/filesystem/code');
$codePath = BP . DS . 'app' . DS . 'code';
$locations = array();
$locations[] = $codePath.'/local/';
$locations[] = $codePath.'/community/';
foreach ($locations as $location)
{
//parse every sub folders (means extension folders)
$poolDir = opendir($location);
while($namespaceName = readdir($poolDir))
{
if (!$this->directoryIsValid($namespaceName))
continue;
//parse modules within namespace
$namespacePath = $location.$namespaceName.'/';
$namespaceDir = opendir($namespacePath);
while($moduleName = readdir($namespaceDir))
{
if (!$this->directoryIsValid($moduleName))
continue;
if (!Mage::helper('core')->isModuleEnabled($namespaceName.'_'.$moduleName))
continue;
$modulePath = $namespacePath.$moduleName.'/';
$configXmlPath = $modulePath.'etc/config.xml';
if (file_exists($configXmlPath))
$retour[] = $configXmlPath;
}
closedir($namespaceDir);
}
closedir($poolDir);
}
return $retour;
}
/**
*
*
* @param unknown_type $dirName
* @return unknown
*/
private function directoryIsValid($dirName)
{
switch ($dirName) {
case '.':
case '..':
case '':
return false;
break;
default:
return true; return true;
break;
} }
} }
private function manageModule($moduleName)
{
switch ($moduleName) {
case 'global':
return false; return false;
break;
default:
return true;
break;
} }
}
/**
* Return all rewrites for a config.xml
*
* @param unknown_type $configFilePath
*/
public function getRewriteForFile($configFilePath, $results)
{
try {
//load xml
$xmlcontent = file_get_contents($configFilePath);
$domDocument = new DOMDocument();
$domDocument->loadXML($xmlcontent);
//parse every node types
$nodeTypes = array('blocks', 'models', 'helpers');
foreach ($nodeTypes as $nodeType) {
if (!$domDocument->documentElement)
continue;
foreach ($domDocument->documentElement->getElementsByTagName($nodeType) as $nodeTypeMarkup) {
foreach ($nodeTypeMarkup->getElementsByTagName('rewrite') as $markup) {
//parse child nodes
$moduleName = $markup->parentNode->tagName;
if ($this->manageModule($moduleName)) {
foreach ($markup->getElementsByTagName('*') as $childNode) {
//get information
$className = $nodeType . '_' . $childNode->tagName;
$rewriteClass = $childNode->nodeValue;
//add to result
$key = $moduleName . '/' . $className;
if (!isset($results[$key]))
$results[$key] = array();
$results[$key][] = $rewriteClass;
}
}
}
}
}
} catch (Exception $ex) {
return $results;
}
return $results;
}
public function getAllRewrites() {
$xml_list = $this->_getConfigFilesList();
$rewrites = array();
foreach($xml_list as $configFile)
{
$rewrites = $this->getRewriteForFile($configFile, $rewrites);
}
return $rewrites;
}
} }
<?php
/**
* Extensions Manager Extension
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://store.onlinebizsoft.com/license.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to admin@onlinebizsoft.com so we can mail you a copy immediately.
*
* @category Magento Extensions
* @package ExtensionManager
* @author OnlineBiz <sales@onlinebizsoft.com>
* @copyright 2007-2011 OnlineBiz
* @license http://store.onlinebizsoft.com/license.txt
* @version 1.0.1
* @link http://store.onlinebizsoft.com
*/
class OnlineBiz_ObBase_Model_Feed extends Mage_AdminNotification_Model_Feed
{
const XML_USE_HTTPS_PATH = 'obbase/feed/use_https';
const XML_FEED_URL_PATH = 'obbase/feed/url';
const XML_FREQUENCY_PATH = 'obbase/feed/check_frequency';
const XML_FREQUENCY_ENABLE = 'obbase/feed/enabled';
const XML_LAST_UPDATE_PATH = 'obbase/feed/last_update';
public static function check(){
return Mage::getModel('obbase/feed')->checkUpdate();
}
public function getFrequency(){
return 86400 * 3600;
}
public function getLastUpdate(){
return Mage::app()->loadCache('obbase_notifications_lastcheck');
}
public function setLastUpdate()
{
Mage::app()->saveCache(time(), 'obbase_notifications_lastcheck');
return $this;
}
public function getFeedUrl(){
if (is_null($this->_feedUrl)) {
$this->_feedUrl = (Mage::getStoreConfigFlag(self::XML_USE_HTTPS_PATH) ? 'https://' : 'http://')
. Mage::getStoreConfig(self::XML_FEED_URL_PATH);
}
return $this->_feedUrl;
}
public function checkUpdate(){
if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
return $this;
}
$feedData = array();
$feedXml = $this->getFeedData();
if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
foreach ($feedXml->channel->item as $item) {
$feedData[] = array(
'severity' => (int)$item->severity ? (int)$item->severity : 3,
'date_added' => $this->getDate((string)$item->pubDate),
'title' => (string)$item->title,
'description' => (string)$item->description,
'url' => (string)$item->link,
);
}
if ($feedData) {
Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData));
}
}
$this->setLastUpdate();
return $this;
}
}
<?php
/**
* Extensions Manager Extension
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://store.onlinebizsoft.com/license.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to admin@onlinebizsoft.com so we can mail you a copy immediately.
*
* @category Magento Extensions
* @package ExtensionManager
* @author OnlineBiz <sales@onlinebizsoft.com>
* @copyright 2007-2011 OnlineBiz
* @license http://store.onlinebizsoft.com/license.txt
* @version 1.0.1
* @link http://store.onlinebizsoft.com
*/
class OnlineBiz_ObBase_Model_Feed_Extensions extends OnlineBiz_ObBase_Model_Feed_Abstract{
/**
* Retrieve feed url
*
* @return string
*/
public function getFeedUrl(){
return OnlineBiz_ObBase_Helper_Config::EXTENSIONS_FEED_URL;
}
/**
* Checks feed
* @return
*/
public function check(){
if(!(Mage::app()->loadCache('obbase_extensions_feed')) || (time()-Mage::app()->loadCache('obbase_extensions_feed_lastcheck')) > 86400){
$this->refresh();
}
}
public function refresh(){
$exts = array();
try{
$Node = $this->getFeedData();
if(!$Node) return false;
foreach($Node->children() as $ext){
$exts[(string)$ext->name] = array(
'display_name' => (string)$ext->display_name,
'version' => (string)$ext->version,
'url' => (string)$ext->url
);
}
Mage::app()->saveCache(serialize($exts), 'obbase_extensions_feed');
Mage::app()->saveCache(time(), 'obbase_extensions_feed_lastcheck');
return true;
}catch(Exception $E){
return false;
}
}
}
\ No newline at end of file
...@@ -19,28 +19,53 @@ ...@@ -19,28 +19,53 @@
* @link http://store.onlinebizsoft.com * @link http://store.onlinebizsoft.com
*/ */
class OnlineBiz_ObBase_Model_Feed_Updates extends OnlineBiz_ObBase_Model_Feed_Abstract{ class OnlineBiz_ObBase_Model_Observer extends Mage_Core_Model_Abstract
{
public function update(){
if ((!(Mage::app()->loadCache('obbase_update_last_check')) || (time()-Mage::app()->loadCache('obbase_update_last_check')) > 15*60) //avoid continous check when remote server is down
&& (!(Mage::app()->loadCache('obbase_update_last_success')) || (time()-Mage::app()->loadCache('obbase_update_last_check')) > 24*60*60)) //only keep checking when last success is more than 24 hours
{
Mage::app()->saveCache(time(), 'obbase_update_last_check');//saving last check time first
//verify license key status
$this->verifyLicenseKeys();
//send extension information
$this->reportExtensionInformation();
//update extension feed
$this->updateExtensionFeed();
//update important news
$this->updateNews();
}
}
/** protected function verifyLicenseKeys() {
* Retrieve feed url }
* protected function reportExtensionInformation() {
* @return string
*/
public function getFeedUrl(){
return OnlineBiz_ObBase_Helper_Config::UPDATES_FEED_URL;
} }
protected function updateExtensionFeed() {
$this->setFeedUrl(OnlineBiz_ObBase_Helper_Config::EXTENSIONS_FEED_URL);
/** $exts = array();
* Checks feed try{
* @return $Node = $this->getFeedData();
*/ if(!$Node) return false;
public function check(){ foreach($Node->children() as $ext){
if((time()-Mage::app()->loadCache('obbase_updates_feed_lastcheck')) > Mage::getStoreConfig('obbase/feed/check_frequency')){ $exts[(string)$ext->name] = array(
$this->refresh(); 'display_name' => (string)$ext->display_name,
'version' => (string)$ext->version,
'url' => (string)$ext->url
);
}
Mage::app()->saveCache(serialize($exts), 'obbase_extensions_feed');
Mage::app()->saveCache(time(), 'obbase_extensions_feed_lastcheck');
return true;
}catch(Exception $E){
return false;
} }
} }
protected function updateNews() {
$this->setFeedUrl(OnlineBiz_ObBase_Helper_Config::UPDATES_FEED_URL);
public function refresh(){
$feedData = array(); $feedData = array();
try{ try{
$Node = $this->getFeedData(); $Node = $this->getFeedData();
...@@ -51,7 +76,7 @@ class OnlineBiz_ObBase_Model_Feed_Updates extends OnlineBiz_ObBase_Model_Feed_Ab ...@@ -51,7 +76,7 @@ class OnlineBiz_ObBase_Model_Feed_Updates extends OnlineBiz_ObBase_Model_Feed_Ab
$date = strtotime((string)$item->date); $date = strtotime((string)$item->date);
if(!Mage::getStoreConfig('obbase/install/run') || (Mage::getStoreConfig('obbase/install/run') < $date)){ if(!Mage::getStoreConfig('obbase/install/run') || (Mage::getStoreConfig('obbase/install/run') < $date)){
$feedData[] = array( $feedData[] = array(
'severity' => 3, 'severity' => (int)$item->severity ? (int)$item->severity : 3,
'date_added' => $this->getDate((string)$item->date), 'date_added' => $this->getDate((string)$item->date),
'title' => (string)$item->title, 'title' => (string)$item->title,
'description' => (string)$item->content, 'description' => (string)$item->content,
...@@ -70,54 +95,46 @@ class OnlineBiz_ObBase_Model_Feed_Updates extends OnlineBiz_ObBase_Model_Feed_Ab ...@@ -70,54 +95,46 @@ class OnlineBiz_ObBase_Model_Feed_Updates extends OnlineBiz_ObBase_Model_Feed_Ab
return false; return false;
} }
} }
public function getInterests(){
if(!$this->getData('interests')){
$types = @explode(',', 'INFO,PROMO,UPDATE_RELEASE,NEW_RELEASE,INSTALLED_UPDATE');
$this->setData('interests', $types);
}
return $this->getData('interests');
}
/** /**
* Retrieve feed data as XML element
* *
* @return * @return SimpleXMLElement
*/ */
public function isInteresting($item){ public function getFeedData()
$interests = $this->getInterests(); {
$curl = new Varien_Http_Adapter_Curl();
$types = @explode(",", (string)$item->type); $curl->setConfig(array(
$exts = @explode(",", (string)$item->extensions); 'timeout' => 5
));
$isInterestedInSelfUpgrades = array_search(OnlineBiz_ObBase_Model_Source_Updates_Type::TYPE_INSTALLED_UPDATE, $types); $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
$data = $curl->read();
foreach($types as $type){ if ($data === false) {
if(array_search($type, $interests) !== false){ return false;
return true;
}
if(($type == OnlineBiz_ObBase_Model_Source_Updates_Type::TYPE_UPDATE_RELEASE) && $isInterestedInSelfUpgrades){
foreach($exts as $ext){
if($this->isExtensionInstalled($ext)){
return true;
}
}
} }
$data = preg_split('/^\r?$/m', $data, 2);
$data = trim($data[1]);
$curl->close();
try {
$xml = new SimpleXMLElement($data);
} }
catch (Exception $e) {
return false; return false;
} }
return $xml;
}
public function isExtensionInstalled($code){
$modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
foreach ($modules as $moduleName) { /**
if($moduleName == $code){ * Retrieve DB date from RSS date
return true; *
} * @param string $rssDate
} * @return string YYYY-MM-DD YY:HH:SS
return false; */
public function getDate($rssDate)
{
return gmdate('Y-m-d H:i:s', strtotime($rssDate));
} }
} }
<?php
/**
* Extensions Manager Extension
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://store.onlinebizsoft.com/license.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to admin@onlinebizsoft.com so we can mail you a copy immediately.
*
* @category Magento Extensions
* @package ExtensionManager
* @author OnlineBiz <sales@onlinebizsoft.com>
* @copyright 2007-2011 OnlineBiz
* @license http://store.onlinebizsoft.com/license.txt
* @version 1.0.1
* @link http://store.onlinebizsoft.com
*/
class OnlineBiz_ObBase_Model_Source_Updates_Type extends Mage_Eav_Model_Entity_Attribute_Source_Abstract{
const TYPE_PROMO = 'PROMO';
const TYPE_NEW_RELEASE = 'NEW_RELEASE';
const TYPE_UPDATE_RELEASE = 'UPDATE_RELEASE';
const TYPE_INFO = 'INFO';
const TYPE_INSTALLED_UPDATE = 'INSTALLED_UPDATE';
public function toOptionArray(){
return array(
array('value' => self::TYPE_INSTALLED_UPDATE, 'label' => Mage::helper('obbase')->__('My extensions updates')),
array('value' => self::TYPE_UPDATE_RELEASE, 'label' => Mage::helper('obbase')->__('All extensions updates')),
array('value' => self::TYPE_NEW_RELEASE, 'label' => Mage::helper('obbase')->__('New Releases')),
array('value' => self::TYPE_PROMO, 'label' => Mage::helper('obbase')->__('Promotions/Discounts')),
array('value' => self::TYPE_INFO, 'label' => Mage::helper('obbase')->__('Other information'))
);
}
/**
* Retrive all attribute options
*
* @return array
*/
public function getAllOptions()
{
return $this->toOptionArray();
}
/**
* Returns label for value
* @param string $value
* @return string
*/
public function getLabel($value){
$options = $this->toOptionArray();
foreach($options as $v){
if($v['value'] == $value){
return $v['label'];
}
}
return '';
}
/**
* Returns array ready for use by grid
* @return array
*/
public function getGridOptions(){
$items = $this->getAllOptions();
$out = array();
foreach($items as $item){
$out[$item['value']] = $item['label'];
}
return $out;
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<config> <config>
<modules> <modules>
<OnlineBiz_ObBase> <OnlineBiz_ObBase>
<version>0.1.0</version> <version>1.2.8</version>
</OnlineBiz_ObBase> </OnlineBiz_ObBase>
</modules> </modules>
...@@ -11,11 +11,6 @@ ...@@ -11,11 +11,6 @@
<obbase> <obbase>
<class>OnlineBiz_ObBase_Block</class> <class>OnlineBiz_ObBase_Block</class>
</obbase> </obbase>
<adminhtml>
<rewrite>
<notification_window>OnlineBiz_ObBase_Block_Notification_Window</notification_window>
</rewrite>
</adminhtml>
</blocks> </blocks>
<resources> <resources>
<obbase_setup> <obbase_setup>
...@@ -93,16 +88,11 @@ ...@@ -93,16 +88,11 @@
<events> <events>
<controller_action_predispatch> <controller_action_predispatch>
<observers> <observers>
<ob_extensions> <heartbeat>
<type>singleton</type>
<class>obbase/feed_extensions</class>
<method>check</method>
</ob_extensions>
<ob_upds>
<type>singleton</type> <type>singleton</type>
<class>obbase/feed_updates</class> <class>obbase/observer</class>
<method>check</method> <method>update</method>
</ob_upds> </heartbeat>
</observers> </observers>
</controller_action_predispatch> </controller_action_predispatch>
</events> </events>
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
<frontend_type>textarea</frontend_type> <frontend_type>textarea</frontend_type>
<sort_order>10</sort_order> <sort_order>10</sort_order>
<show_in_default>1</show_in_default> <show_in_default>1</show_in_default>
<show_in_website>1</show_in_website> <show_in_website>0</show_in_website>
<show_in_store>1</show_in_store> <show_in_store>0</show_in_store>
<comment><![CDATA[Enter your license keys, each per row.]]></comment> <comment><![CDATA[Enter your license keys, each per row.]]></comment>
</keys> </keys>
</fields> </fields>
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
<label>Installed Extensions Version</label> <label>Installed Extensions Version</label>
<frontend_type>text</frontend_type> <frontend_type>text</frontend_type>
<frontend_model>obbase/system_config_form_fieldset_extensions</frontend_model> <frontend_model>obbase/system_config_form_fieldset_extensions</frontend_model>
<sort_order>2</sort_order> <sort_order>10</sort_order>
<show_in_default>1</show_in_default> <show_in_default>1</show_in_default>
<show_in_website>1</show_in_website> <show_in_website>1</show_in_website>
<show_in_store>1</show_in_store> <show_in_store>1</show_in_store>
...@@ -58,11 +58,20 @@ ...@@ -58,11 +58,20 @@
<label>Rewrites</label> <label>Rewrites</label>
<frontend_type>text</frontend_type> <frontend_type>text</frontend_type>
<frontend_model>obbase/system_config_form_fieldset_conflict</frontend_model> <frontend_model>obbase/system_config_form_fieldset_conflict</frontend_model>
<sort_order>3</sort_order> <sort_order>20</sort_order>
<show_in_default>1</show_in_default> <show_in_default>1</show_in_default>
<show_in_website>1</show_in_website> <show_in_website>1</show_in_website>
<show_in_store>1</show_in_store> <show_in_store>1</show_in_store>
</extensions_conflict> </extensions_conflict>
<support translate="label">
<label>Support</label>
<frontend_type>text</frontend_type>
<frontend_model>obbase/system_config_form_fieldset_support</frontend_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</support>
</groups> </groups>
</obbase> </obbase>
<!--<storeview translate="label" module="obbase"> <!--<storeview translate="label" module="obbase">
......
<?php
/**
* Extensions Manager Extension
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://store.onlinebizsoft.com/license.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to admin@onlinebizsoft.com so we can mail you a copy immediately.
*
* @category Magento Extensions
* @package ExtensionManager
* @author OnlineBiz <sales@onlinebizsoft.com>
* @copyright 2007-2011 OnlineBiz
* @license http://store.onlinebizsoft.com/license.txt
* @version 1.0.1
* @link http://store.onlinebizsoft.com
*/
?>
<div id="message-popup-window" style="display:none;"></div>
<div style="position:relative;margin-left:-390px;">
<div id="onl_notif" class="notification" style="display:none;">
<div class="head">
<h3><?php echo $this->getHeaderText();?></h3>
<button type="button" class="close" onclick="closeMessagePopupWindow()"><span ><?php echo $this->getCloseText(); ?></span></button>
</div>
<div class="content">
<?php echo $this->getNoticeMessageText(); ?>
</div>
</div>
</div>
<script>
function showNot(){
openMessagePopupWindow();
Effect.Appear('onl_notif', { duration: 1.0 });
}
Event.observe(window, 'load', showNot);
function openMessagePopupWindow(){
var height = $('html-body').getHeight();
$('message-popup-window').setStyle({'height':height+'px'});
toggleSelectsUnderBlock($('message-popup-window'), false);
Element.show('message-popup-window');
}
function closeMessagePopupWindow()
{
toggleSelectsUnderBlock($('message-popup-window'), true);
Effect.Fade('onl_notif', { duration: 0.5 });
Element.hide('message-popup-window');
}
function saveCloseMessagePopupWindow()
{
$('onl_firstrun').request({
onComplete: function(){
toggleSelectsUnderBlock($('message-popup-window'), true);
Effect.Fade('onl_notif', { duration: 0.5 });
Element.hide('message-popup-window');
}
})
}
</script>
/app/code/local/OnlineBiz/ObBase /app/code/local/OnlineBiz/ObBase
/app/design/adminhtml/default/default/layout/onlinebizsoft/obbase.xml /app/design/adminhtml/default/default/layout/onlinebizsoft/obbase.xml
/app/design/adminhtml/default/default/template/onlinebizsoft/obbase/notification/window.phtml /app/design/adminhtml/default/default/template/onlinebizsoft/obbase/notification/window.phtml
/app/design/adminhtml/default/default/template/onlinebizsoft/obbase/store.phtml /app/design/adminhtml/default/default/template/onlinebizsoft/obbase/store.phtml
/app/etc/modules/OnlineBiz_ObBase.xml /app/etc/modules/OnlineBiz_ObBase.xml
/js/onlinebizsoft/obbase/base.js /js/onlinebizsoft/obbase/base.js
/skin/adminhtml/default/default/onlinebizsoft/obbase/css/base.css /skin/adminhtml/default/default/onlinebizsoft/obbase/css/base.css
/skin/adminhtml/default/default/onlinebizsoft/obbase/images/ok.gif /skin/adminhtml/default/default/onlinebizsoft/obbase/images/ok.gif
/skin/adminhtml/default/default/onlinebizsoft/obbase/images/update.gif /skin/adminhtml/default/default/onlinebizsoft/obbase/images/update.gif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment