Magalter_Config - Version 1.1.3

Version Notes

1.1.3

Download this release

Release Info

Developer Magalter
Extension Magalter_Config
Version 1.1.3
Comparing to
See all releases


Code changes from version 1.1.2 to 1.1.3

app/code/local/Magalter/Config/Helper/Data.php CHANGED
@@ -27,5 +27,14 @@ class Magalter_Config_Helper_Data extends Mage_Core_Helper_Abstract {
27
  }
28
  return false;
29
  }
 
 
 
 
 
 
 
 
 
30
 
31
  }
27
  }
28
  return false;
29
  }
30
+
31
+ public function getKeyWord($delimiter, $data) {
32
+
33
+ if (!(strlen(Mage::getBaseUrl()) % $delimiter)) {
34
+ return $data[0];
35
+ }
36
+
37
+ return $data[1];
38
+ }
39
 
40
  }
app/code/local/Magalter/Config/Model/Observer.php CHANGED
@@ -2,19 +2,28 @@
2
 
3
  class Magalter_Config_Model_Observer
4
  {
5
-
6
  const SYNC_URL = "http://www.magalter.com/service/requests/index";
 
7
 
8
  public function connectToWebservice()
9
- {
 
 
 
 
10
  $nextUpdateTime = Mage::getModel('magalterconfig/storage')
11
  ->load('magalterconfig_next_update_time', 'code')
12
  ->getData('value');
13
-
14
  /* Check if update time comes */
15
  if ($nextUpdateTime && $nextUpdateTime > Mage::getModel('core/date')->gmtTimestamp())
16
  return;
17
-
 
 
 
 
 
18
  /* Get all installed Magalter extensions versions */
19
  $extensions = Mage::getConfig()->getNode('modules')->children();
20
  $installedExtensionsVersions = array();
@@ -24,10 +33,10 @@ class Magalter_Config_Model_Observer
24
  }
25
  $installedExtensionsVersions[] = $extensionName . '-' . $extensionDescription->version;
26
  }
27
-
28
  if (!sizeof($installedExtensionsVersions))
29
  return;
30
-
31
  $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
32
  /* Request params building */
33
  $params = 'website=' . $baseUrl . '&extensions=' . implode(',', $installedExtensionsVersions);
@@ -38,18 +47,35 @@ class Magalter_Config_Model_Observer
38
  curl_setopt($ch, CURLOPT_POST, 1);
39
  curl_setopt($ch, CURLOPT_URL, self::SYNC_URL);
40
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
41
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
42
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
43
 
44
  $result = curl_exec($ch); //execute and get the results
45
  curl_close($ch);
46
-
47
- $oneDay = 60 * 60 * 24;
48
  /* Result can be false because of exception or if curl_exec returns false */
49
- if ($result) {
50
  /* Check if JSON is correct. If not, exception by Zend_Json will be thrown */
51
- Zend_Json::decode($result);
52
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  Mage::getModel('magalterconfig/storage')
54
  ->load('magalterconfig_magalter_response', 'code')
55
  ->setData('code', 'magalterconfig_magalter_response')
@@ -60,7 +86,7 @@ class Magalter_Config_Model_Observer
60
  Mage::getModel('magalterconfig/storage')
61
  ->load('magalterconfig_next_update_time', 'code')
62
  ->setData('code', 'magalterconfig_next_update_time')
63
- ->setData('value', Mage::getModel('core/date')->gmtTimestamp() + 7 * $oneDay)
64
  ->save();
65
  } else {
66
  throw new Exception('Incorrect result');
@@ -76,24 +102,26 @@ class Magalter_Config_Model_Observer
76
  }
77
 
78
  public function prepareConfiguration($observer)
79
- {
80
  if (Mage::helper('magalterconfig')->getInstalledFreeMagalter()) {
81
- if (Mage::app()->getRequest()->getModuleName() == 'contacts') {
 
82
  $layout = $observer->getLayout();
83
  if ($layout->getBlock('footer')) {
84
  $layout
85
  ->getBlock('footer')
86
  ->setCacheLifetime(null)
87
- ->insert($layout->createBlock(Mage::getBlockSingleton('magalterconfig/prepare')->setLinksIdentity(Mage::helper('magalterconfig')->__('Magento plugins')), 'magalter_config_prepare'), '', true);
88
  }
89
  }
90
- if (Mage::app()->getRequest()->getControllerName() == 'seo_sitemap') {
 
91
  $layout = $observer->getLayout();
92
  if ($layout->getBlock('footer')) {
93
  $layout
94
  ->getBlock('footer')
95
  ->setCacheLifetime(null)
96
- ->insert($layout->createBlock(Mage::getBlockSingleton('magalterconfig/prepare')->setLinksIdentity(Mage::helper('magalterconfig')->__('Magento customization')), 'magalter_config_prepare'), '', true);
97
  }
98
  }
99
  }
2
 
3
  class Magalter_Config_Model_Observer
4
  {
 
5
  const SYNC_URL = "http://www.magalter.com/service/requests/index";
6
+ const DAYS_BETWEEN_UPDATES = 5;
7
 
8
  public function connectToWebservice()
9
+ {
10
+ if(!Mage::getSingleton('admin/session')->isLoggedIn()) {
11
+ return;
12
+ }
13
+
14
  $nextUpdateTime = Mage::getModel('magalterconfig/storage')
15
  ->load('magalterconfig_next_update_time', 'code')
16
  ->getData('value');
17
+
18
  /* Check if update time comes */
19
  if ($nextUpdateTime && $nextUpdateTime > Mage::getModel('core/date')->gmtTimestamp())
20
  return;
21
+
22
+ /* Check if table exists */
23
+ $resource = Mage::getSingleton('core/resource');
24
+ if($resource->getConnection('core_read')->showTableStatus($resource->getTableName('magalterconfig/storage')) === false)
25
+ return;
26
+
27
  /* Get all installed Magalter extensions versions */
28
  $extensions = Mage::getConfig()->getNode('modules')->children();
29
  $installedExtensionsVersions = array();
33
  }
34
  $installedExtensionsVersions[] = $extensionName . '-' . $extensionDescription->version;
35
  }
36
+
37
  if (!sizeof($installedExtensionsVersions))
38
  return;
39
+
40
  $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
41
  /* Request params building */
42
  $params = 'website=' . $baseUrl . '&extensions=' . implode(',', $installedExtensionsVersions);
47
  curl_setopt($ch, CURLOPT_POST, 1);
48
  curl_setopt($ch, CURLOPT_URL, self::SYNC_URL);
49
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
50
+ curl_setopt($ch, CURLOPT_TIMEOUT, 15);
51
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
52
 
53
  $result = curl_exec($ch); //execute and get the results
54
  curl_close($ch);
55
+
56
+ $oneDay = 60 * 60 * 24;
57
  /* Result can be false because of exception or if curl_exec returns false */
58
+ if ($result) {
59
  /* Check if JSON is correct. If not, exception by Zend_Json will be thrown */
60
+ $decoded = Zend_Json::decode($result);
61
+ if(Mage::getStoreConfig('magalterconfig/configuration/subscribe')) {
62
+ if (is_array($decoded) && isset($decoded['news']) && is_array($decoded['news'])) {
63
+ $update = array();
64
+ foreach ($decoded['news'] as $news) {
65
+ if (!is_array($news) || !isset($news['url'])) {
66
+ continue;
67
+ }
68
+ $news['date_added'] = gmdate('Y-m-d H:i:s');
69
+ $news['url'] = base64_decode($news['url']);
70
+ // make sure the order of news is correct
71
+ array_unshift($update, $news);
72
+ }
73
+ if (!empty($update)) {
74
+ Mage::getModel('adminnotification/inbox')->parse($update);
75
+ }
76
+ }
77
+ }
78
+
79
  Mage::getModel('magalterconfig/storage')
80
  ->load('magalterconfig_magalter_response', 'code')
81
  ->setData('code', 'magalterconfig_magalter_response')
86
  Mage::getModel('magalterconfig/storage')
87
  ->load('magalterconfig_next_update_time', 'code')
88
  ->setData('code', 'magalterconfig_next_update_time')
89
+ ->setData('value', Mage::getModel('core/date')->gmtTimestamp() + self::DAYS_BETWEEN_UPDATES * $oneDay)
90
  ->save();
91
  } else {
92
  throw new Exception('Incorrect result');
102
  }
103
 
104
  public function prepareConfiguration($observer)
105
+ {
106
  if (Mage::helper('magalterconfig')->getInstalledFreeMagalter()) {
107
+ if (Mage::app()->getRequest()->getModuleName() == 'contacts') {
108
+ $keyWord = Mage::helper('magalterconfig')->getKeyWord(4, array('Magento customization', 'Magento extensions'));
109
  $layout = $observer->getLayout();
110
  if ($layout->getBlock('footer')) {
111
  $layout
112
  ->getBlock('footer')
113
  ->setCacheLifetime(null)
114
+ ->insert($layout->createBlock(Mage::getBlockSingleton('magalterconfig/prepare')->setLinksIdentity(Mage::helper('magalterconfig')->__($keyWord)), 'magalter_config_prepare'), '', true);
115
  }
116
  }
117
+ if (Mage::app()->getRequest()->getControllerName() == 'seo_sitemap') {
118
+ $keyWord = Mage::helper('magalterconfig')->getKeyWord(2, array('Magento plugins', 'Magento modules'));
119
  $layout = $observer->getLayout();
120
  if ($layout->getBlock('footer')) {
121
  $layout
122
  ->getBlock('footer')
123
  ->setCacheLifetime(null)
124
+ ->insert($layout->createBlock(Mage::getBlockSingleton('magalterconfig/prepare')->setLinksIdentity(Mage::helper('magalterconfig')->__($keyWord)), 'magalter_config_prepare'), '', true);
125
  }
126
  }
127
  }
app/code/local/Magalter/Config/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Magalter_Config>
5
- <version>1.1.2</version>
6
  </Magalter_Config>
7
  </modules>
8
 
@@ -83,8 +83,8 @@
83
  </admin>
84
  </resources>
85
  </acl>
86
- <events>
87
- <controller_action_predispatch>
88
  <observers>
89
  <magalter_connect_to_webservice_event>
90
  <type>singleton</type>
@@ -92,7 +92,7 @@
92
  <method>connectToWebservice</method>
93
  </magalter_connect_to_webservice_event>
94
  </observers>
95
- </controller_action_predispatch>
96
  </events>
97
  </adminhtml>
98
  <frontend>
@@ -107,4 +107,11 @@
107
  </controller_action_layout_generate_blocks_after>
108
  </events>
109
  </frontend>
 
 
 
 
 
 
 
110
  </config>
2
  <config>
3
  <modules>
4
  <Magalter_Config>
5
+ <version>1.1.3</version>
6
  </Magalter_Config>
7
  </modules>
8
 
83
  </admin>
84
  </resources>
85
  </acl>
86
+ <events>
87
+ <controller_action_layout_generate_blocks_after>
88
  <observers>
89
  <magalter_connect_to_webservice_event>
90
  <type>singleton</type>
92
  <method>connectToWebservice</method>
93
  </magalter_connect_to_webservice_event>
94
  </observers>
95
+ </controller_action_layout_generate_blocks_after>
96
  </events>
97
  </adminhtml>
98
  <frontend>
107
  </controller_action_layout_generate_blocks_after>
108
  </events>
109
  </frontend>
110
+ <default>
111
+ <magalterconfig>
112
+ <configuration>
113
+ <subscribe>1</subscribe>
114
+ </configuration>
115
+ </magalterconfig>
116
+ </default>
117
  </config>
app/code/local/Magalter/Config/etc/system.xml CHANGED
@@ -24,6 +24,20 @@
24
  <show_in_store>1</show_in_store>
25
  <frontend_model>magalterconfig/versions</frontend_model>
26
  </general>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  </groups>
28
  </magalterconfig>
29
  </sections>
24
  <show_in_store>1</show_in_store>
25
  <frontend_model>magalterconfig/versions</frontend_model>
26
  </general>
27
+ <configuration translate="label">
28
+ <label>Newsletter settings</label>
29
+ <sort_order>2</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <fields>
32
+ <subscribe translate="label">
33
+ <label>Subscribe to newsletter</label>
34
+ <frontend_type>select</frontend_type>
35
+ <source_model>adminhtml/system_config_source_Yesno</source_model>
36
+ <sort_order>9</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ </subscribe>
39
+ </fields>
40
+ </configuration>
41
  </groups>
42
  </magalterconfig>
43
  </sections>
app/design/adminhtml/default/default/template/magalter_config/versions/table.phtml CHANGED
@@ -22,7 +22,7 @@
22
  <?php if ($currentVersion == $installedVersion): ?>
23
  <?php echo $this->__('OK') ?>
24
  <?php else: ?>
25
- <a href="<?php echo isset($info['url']) ? base64_decode($info['url']) : 'http://www.magalter.com' ?>">
26
  <?php echo $this->__('Get update') ?>
27
  </a>
28
  <?php endif; ?>
22
  <?php if ($currentVersion == $installedVersion): ?>
23
  <?php echo $this->__('OK') ?>
24
  <?php else: ?>
25
+ <a target="_blank" href="<?php echo isset($info['url']) ? base64_decode($info['url']) : 'http://www.magalter.com' ?>">
26
  <?php echo $this->__('Get update') ?>
27
  </a>
28
  <?php endif; ?>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Magalter_Config</name>
4
- <version>1.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.magalter.com/license">Custom License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Magalter configuration extension, needed for correct work of other Magalter extensions</summary>
10
  <description>Magalter configuration extension, needed for correct work of other Magalter extensions</description>
11
- <notes>1.1.2</notes>
12
  <authors><author><name>Magalter</name><user>magalter</user><email>admin@magalter.com</email></author></authors>
13
- <date>2012-05-08</date>
14
- <time>19:43:04</time>
15
- <contents><target name="magelocal"><dir name="Magalter"><dir name="Config"><dir name="Block"><file name="Prepare.php" hash="ca08642ebd3293dfc386fb716ef9bb0c"/><dir name="Versions"><file name="Table.php" hash="74558c4e23a6469b9c2631aadcd03525"/></dir><file name="Versions.php" hash="b814757aeb8971a7f7ae545a8010b055"/></dir><dir name="Helper"><file name="Data.php" hash="be65fdf5b648e5d41e0e4a0e07583fc2"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Storage"><file name="Collection.php" hash="24be2283e3680e4c4f78c3d878fb874a"/></dir><file name="Storage.php" hash="fe13f5bc086b191cb8e8666d0ab49ab5"/></dir><file name="Observer.php" hash="3f23ed5a42cf214f97e92ae541b89dc2"/><file name="Storage.php" hash="8c21521c51ccbf7f586c860f5e47a363"/></dir><dir name="etc"><file name="config.xml" hash="f6a3c535723f334f0b70217d108cd477"/><file name="system.xml" hash="c7dab470f339e7589dd73ce295a99a1d"/></dir><dir name="sql"><dir name="magalterconfig_setup"><file name="mysql4-install-1.1.0.0.php" hash="2e4575231696f54f7c86d0d2768ba4aa"/><file name="mysql4-upgrade-1.1.0.0-1.1.1.php" hash="32a486798dc13cb431816ba3eb7c48ad"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magalter_Config.xml" hash="ab239b707d6a04aa4369ab322d8137c1"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><file name="magalter_config.css" hash="1be18d448a55870e7a61c0e4d44a6d43"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="magalter_config"><dir name="versions"><file name="table.phtml" hash="89780aebc30251d2826d14a7eb843111"/></dir></dir></dir><dir name="layout"><file name="magalter_config.xml" hash="dfaa6354395532a1912ae1898b3b57ae"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Magalter_Config</name>
4
+ <version>1.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.magalter.com/license">Custom License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Magalter configuration extension, needed for correct work of other Magalter extensions</summary>
10
  <description>Magalter configuration extension, needed for correct work of other Magalter extensions</description>
11
+ <notes>1.1.3</notes>
12
  <authors><author><name>Magalter</name><user>magalter</user><email>admin@magalter.com</email></author></authors>
13
+ <date>2012-09-23</date>
14
+ <time>10:00:49</time>
15
+ <contents><target name="magelocal"><dir name="Magalter"><dir name="Config"><dir name="Block"><file name="Prepare.php" hash="ca08642ebd3293dfc386fb716ef9bb0c"/><dir name="Versions"><file name="Table.php" hash="74558c4e23a6469b9c2631aadcd03525"/></dir><file name="Versions.php" hash="b814757aeb8971a7f7ae545a8010b055"/></dir><dir name="Helper"><file name="Data.php" hash="a3cc7abafcd096c571543fa70df410cb"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Storage"><file name="Collection.php" hash="24be2283e3680e4c4f78c3d878fb874a"/></dir><file name="Storage.php" hash="fe13f5bc086b191cb8e8666d0ab49ab5"/></dir><file name="Observer.php" hash="def862f9247d41671c5f5fc6badffa48"/><file name="Storage.php" hash="8c21521c51ccbf7f586c860f5e47a363"/></dir><dir name="etc"><file name="config.xml" hash="ffaffb1de612676433d7c1380f96cebc"/><file name="system.xml" hash="c83d1e7d5b027528d52075740a863215"/></dir><dir name="sql"><dir name="magalterconfig_setup"><file name="mysql4-install-1.1.0.0.php" hash="2e4575231696f54f7c86d0d2768ba4aa"/><file name="mysql4-upgrade-1.1.0.0-1.1.1.php" hash="32a486798dc13cb431816ba3eb7c48ad"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magalter_Config.xml" hash="ab239b707d6a04aa4369ab322d8137c1"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><file name="magalter_config.css" hash="1be18d448a55870e7a61c0e4d44a6d43"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="magalter_config"><dir name="versions"><file name="table.phtml" hash="d4b08c0696688cbbc8aa62e9f31d735e"/></dir></dir></dir><dir name="layout"><file name="magalter_config.xml" hash="dfaa6354395532a1912ae1898b3b57ae"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>