HusseyCoding_TwitterReader - Version 1.0.5

Version Notes

Fixed losing block order on cms edit page load

Download this release

Release Info

Developer Hussey Coding
Extension HusseyCoding_TwitterReader
Version 1.0.5
Comparing to
See all releases


Version 1.0.5

Files changed (24) hide show
  1. app/code/community/HusseyCoding/Common/etc/system.xml +9 -0
  2. app/code/community/HusseyCoding/TwitterReader/Block/Tweets.php +8 -0
  3. app/code/community/HusseyCoding/TwitterReader/Block/Verify.php +84 -0
  4. app/code/community/HusseyCoding/TwitterReader/Helper/Data.php +128 -0
  5. app/code/community/HusseyCoding/TwitterReader/Model/Config/CoreData.php +8 -0
  6. app/code/community/HusseyCoding/TwitterReader/Model/Manage.php +197 -0
  7. app/code/community/HusseyCoding/TwitterReader/Model/Mysql4/Twitterreader.php +8 -0
  8. app/code/community/HusseyCoding/TwitterReader/Model/Mysql4/Twitterreader/Collection.php +9 -0
  9. app/code/community/HusseyCoding/TwitterReader/Model/Observer.php +17 -0
  10. app/code/community/HusseyCoding/TwitterReader/Model/Twitterreader.php +9 -0
  11. app/code/community/HusseyCoding/TwitterReader/controllers/CallbackController.php +49 -0
  12. app/code/community/HusseyCoding/TwitterReader/etc/adminhtml.xml +25 -0
  13. app/code/community/HusseyCoding/TwitterReader/etc/config.xml +111 -0
  14. app/code/community/HusseyCoding/TwitterReader/etc/system.xml +186 -0
  15. app/code/community/HusseyCoding/TwitterReader/sql/twitterreader_setup/mysql4-install-1.0.0.php +19 -0
  16. app/design/adminhtml/default/default/layout/twitterreader.xml +14 -0
  17. app/design/adminhtml/default/default/template/twitterreader/verify.phtml +24 -0
  18. app/design/frontend/base/default/layout/twitterreader.xml +47 -0
  19. app/design/frontend/base/default/template/twitterreader/tweets.phtml +48 -0
  20. app/etc/modules/HusseyCoding_Common.xml +9 -0
  21. app/etc/modules/HusseyCoding_TwitterReader.xml +9 -0
  22. package.xml +18 -0
  23. skin/adminhtml/default/default/twitterreader/js/twitterreader.js +62 -0
  24. skin/frontend/base/default/css/twitterreader.css +6 -0
app/code/community/HusseyCoding/Common/etc/system.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <husseycoding translate="label">
5
+ <label>Hussey Coding</label>
6
+ <sort_order>500</sort_order>
7
+ </husseycoding>
8
+ </tabs>
9
+ </config>
app/code/community/HusseyCoding/TwitterReader/Block/Tweets.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Block_Tweets extends Mage_Core_Block_Text_List
3
+ {
4
+ public function verifyBlock($config, $block)
5
+ {
6
+ if (!Mage::getStoreConfig('twitterreader/position/' . $config)) $this->unsetChild($block);
7
+ }
8
+ }
app/code/community/HusseyCoding/TwitterReader/Block/Verify.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Block_Verify extends Mage_Page_Block_Html
3
+ {
4
+ public function verifyCredentials()
5
+ {
6
+ if (Mage::app()->getRequest()->getParam('section') == 'twitterreader' && !Mage::app()->getRequest()->getParam('website')):
7
+ $key = Mage::getStoreConfig('twitterreader/configuration/consumer_key');
8
+ $secret = Mage::getStoreConfig('twitterreader/configuration/consumer_secret');
9
+ $request = Mage::helper('twitterreader')->getOauthObject('twitterreader/configuration/request_token');
10
+ $access = Mage::helper('twitterreader')->getOauthObject('twitterreader/configuration/access_token');
11
+ if (Mage::registry('twitterreader_problem')):
12
+ return 'problem';
13
+ elseif (!$key || !$secret):
14
+ return 'consumer_missing';
15
+ elseif (!$request && !$access):
16
+ $config = array(
17
+ 'callbackUrl' => Mage::helper('adminhtml')->getUrl('twitterreader/callback/access'),
18
+ 'siteUrl' => 'https://api.twitter.com/oauth',
19
+ 'consumerKey' => $key,
20
+ 'consumerSecret' => $secret
21
+ );
22
+ $consumer = new Zend_Oauth_Consumer($config);
23
+
24
+ try {
25
+ $request = $consumer->getRequestToken();
26
+ Mage::helper('twitterreader')->storeOauthObject($request, 'twitterreader/configuration/request_token');
27
+ $url = $consumer->getRedirectUrl();
28
+ Mage::getConfig()->saveConfig('twitterreader/configuration/callback_url', $url);
29
+ Mage::getConfig()->reinit();
30
+ Mage::app()->reinitStores();
31
+ return 'verify_credentials';
32
+ } catch (Exception $e) {
33
+ return 'bad_callback';
34
+ }
35
+ elseif ($request && !$access):
36
+ return 'verify_credentials';
37
+ else:
38
+ $config = array(
39
+ 'callbackUrl' => Mage::helper('adminhtml')->getUrl('twitterreader/callback/access'),
40
+ 'siteUrl' => 'https://api.twitter.com/oauth',
41
+ 'consumerKey' => $key,
42
+ 'consumerSecret' => $secret
43
+ );
44
+ $token = Mage::helper('twitterreader')->getAccessToken();
45
+
46
+ if ($token):
47
+ $client = $token->getHttpClient($config);
48
+ $client->setUri('https://api.twitter.com/1.1/application/rate_limit_status.json');
49
+ $client->setMethod(Zend_Http_Client::GET);
50
+ $client->setParameterGet('resources', 'account');
51
+
52
+ try {
53
+ $response = $client->request();
54
+
55
+ $limit = Zend_Json::decode($response->getBody());
56
+ $limit = $limit['resources']['account']['/account/verify_credentials'];
57
+ if ($limit['remaining'] > 0):
58
+ $client->setUri('https://api.twitter.com/1.1/account/verify_credentials.json');
59
+ $client->setMethod(Zend_Http_Client::GET);
60
+ $response = $client->request();
61
+
62
+ $status = Zend_Json::decode($response->getBody());
63
+
64
+ if (isset($status['errors'])):
65
+ return 'bad_verify';
66
+ endif;
67
+ elseif ($limit):
68
+ $timestamp = Mage::getModel('core/date')->timestamp($limit['reset']);
69
+ return $timestamp;
70
+ else:
71
+ return 'bad_callback';
72
+ endif;
73
+ } catch (Exception $e) {
74
+ return 'bad_verify';
75
+ }
76
+
77
+ return 'ready';
78
+ endif;
79
+ endif;
80
+ endif;
81
+
82
+ return false;
83
+ }
84
+ }
app/code/community/HusseyCoding/TwitterReader/Helper/Data.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ private $_collection;
5
+
6
+ public function collectFeedContent()
7
+ {
8
+ if (!$this->_collection):
9
+ $store = Mage::app()->getStore()->getCode();
10
+ $screenname = Mage::getStoreConfig('twitterreader/configuration/screen_name');
11
+ $collection = Mage::getModel('twitterreader/twitterreader')->getCollection();
12
+ $select = $collection->getSelect();
13
+ $select
14
+ ->where('store = ?', $store)
15
+ ->where('screen_name = ?', $screenname)
16
+ ->order(array('timestamp DESC'))
17
+ ->limit($this->getDisplayCount());
18
+
19
+ $collection = count($collection) ? $collection : false;
20
+ $this->_collection = $collection;
21
+ return $collection;
22
+ else:
23
+ return $this->_collection;
24
+ endif;
25
+ }
26
+
27
+ private function getDisplayCount($store = null)
28
+ {
29
+ if ($store):
30
+ $count = Mage::getStoreConfig('twitterreader/configuration/tweet_display', $store);
31
+ else:
32
+ $count = Mage::getStoreConfig('twitterreader/configuration/tweet_display');
33
+ endif;
34
+ $count = $count ? (int) $count : 5;
35
+
36
+ return $count ? $count : 5;
37
+ }
38
+
39
+ public function getStoreCount($store = null)
40
+ {
41
+ if ($store):
42
+ return $this->getDisplayCount($store) + 10;
43
+ else:
44
+ return $this->getDisplayCount() + 10;
45
+ endif;
46
+ }
47
+
48
+ public function storeOauthObject($object, $path)
49
+ {
50
+ $object = Zend_Serializer::serialize($object);
51
+ $resource = Mage::getSingleton('core/resource');
52
+ $write = $resource->getConnection('twitterreader_write');
53
+ $query = 'UPDATE `' . $resource->getTableName('core/config_data') . '` SET `value` = ' . $write->quote($object) . ' WHERE `path` = \'' . $path . '\'';
54
+ $write->query($query);
55
+ }
56
+
57
+ public function getOauthObject($path)
58
+ {
59
+ $resource = Mage::getSingleton('core/resource');
60
+ $read = $resource->getConnection('twitterreader_read');
61
+ $query = 'SELECT `value` FROM `' . $resource->getTableName('core/config_data') . '` WHERE `path` = \'' . $path . '\'';
62
+ $object = $read->fetchOne($query);
63
+
64
+ if ($object):
65
+ $object = stripslashes($object);
66
+ try {
67
+ $object = Zend_Serializer::unserialize($object);
68
+ } catch (Exception $e) {
69
+ Mage::register('twitterreader_problem', 1);
70
+ $object = false;
71
+ }
72
+ endif;
73
+
74
+ return $object;
75
+ }
76
+
77
+ public function removeOauthObject($path)
78
+ {
79
+ $resource = Mage::getSingleton('core/resource');
80
+ $write = $resource->getConnection('twitterreader_write');
81
+ $query = 'UPDATE `' . $resource->getTableName('core/config_data') . '` SET `value` = NULL WHERE `path` = \'' . $path . '\'';
82
+ $write->query($query);
83
+ }
84
+
85
+ public function checkCoreRow($path)
86
+ {
87
+ $resource = Mage::getSingleton('core/resource');
88
+ $read = $resource->getConnection('twitterreader_read');
89
+ $query = 'SELECT `config_id` FROM `' . $resource->getTableName('core/config_data') . '` WHERE `path` = \'' . $path . '\'';
90
+ $object = $read->fetchOne($query);
91
+
92
+ return $object ? true : false;
93
+ }
94
+
95
+ public function getAccessToken()
96
+ {
97
+ return $this->getOauthObject('twitterreader/configuration/access_token');
98
+ }
99
+
100
+ public function displayDate($timestamp)
101
+ {
102
+ $timestamp = strtotime($timestamp);
103
+ $format = Mage::getStoreConfig('twitterreader/configuration/date_format');
104
+ $format = $format ? $format : 'D jS M';
105
+ $return = date($format, $timestamp);
106
+
107
+ return $return ? ' - ' . $return : '';
108
+ }
109
+
110
+ public function formatContent($content)
111
+ {
112
+ $length = (int) Mage::getStoreConfig('twitterreader/configuration/tweet_length');
113
+ if ($length && strlen($content) > $length):
114
+ $content = substr($content, 0, $length) . '...';
115
+ endif;
116
+
117
+ return $content;
118
+ }
119
+
120
+ public function show()
121
+ {
122
+ if (Mage::getStoreConfig('twitterreader/position/custom')):
123
+ return Mage::app()->getLayout()->getBlock('twitterreader')->toHtml();
124
+ endif;
125
+
126
+ return '';
127
+ }
128
+ }
app/code/community/HusseyCoding/TwitterReader/Model/Config/CoreData.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Model_Config_CoreData extends Mage_Core_Model_Config_Data
3
+ {
4
+ public function disableSave()
5
+ {
6
+ $this->_dataSaveAllowed = false;
7
+ }
8
+ }
app/code/community/HusseyCoding/TwitterReader/Model/Manage.php ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Model_Manage
3
+ {
4
+ public function cron()
5
+ {
6
+ if (!Mage::registry('twitterreader_runonce')):
7
+ $count = Mage::getModel('twitterreader/twitterreader')->getCollection();
8
+ $count = count($count);
9
+ if ($this->getLatest() || $this->getCombinedCount() < $count):
10
+ $this->cleanUp();
11
+ endif;
12
+ Mage::register('twitterreader_runonce', true);
13
+ endif;
14
+
15
+ return true;
16
+ }
17
+
18
+ private function getCombinedCount()
19
+ {
20
+ $return = 0;
21
+ foreach (Mage::app()->getStores() as $store):
22
+ $return = $return + Mage::helper('twitterreader')->getStoreCount($store->getCode());
23
+ endforeach;
24
+
25
+ return $return;
26
+ }
27
+
28
+ private function getLatest()
29
+ {
30
+ $stores = array();
31
+ $storecount = array();
32
+ foreach (Mage::app()->getStores() as $store):
33
+ $screenname = Mage::getStoreConfig('twitterreader/configuration/screen_name', $store->getCode());
34
+ if ($screenname):
35
+ $stores[$store->getCode()] = $screenname;
36
+ $storecount[$store->getCode()] = Mage::helper('twitterreader')->getStoreCount($store->getCode());
37
+ endif;
38
+ endforeach;
39
+ $key = Mage::getStoreConfig('twitterreader/configuration/consumer_key');
40
+ $secret = Mage::getStoreConfig('twitterreader/configuration/consumer_secret');
41
+ $access = Mage::helper('twitterreader')->getAccessToken();
42
+
43
+ if (!$key || !$secret || !$access):
44
+ return false;
45
+ endif;
46
+
47
+ $config = array(
48
+ 'callbackUrl' => Mage::helper('adminhtml')->getUrl('twitterreader/callback/access'),
49
+ 'siteUrl' => 'https://api.twitter.com/oauth',
50
+ 'consumerKey' => $key,
51
+ 'consumerSecret' => $secret
52
+ );
53
+
54
+ $client = $access->getHttpClient($config);
55
+ $client->setUri('https://api.twitter.com/1.1/application/rate_limit_status.json');
56
+ $client->setMethod(Zend_Http_Client::GET);
57
+ $client->setParameterGet('resources', 'account,statuses');
58
+
59
+ try {
60
+ $response = $client->request();
61
+
62
+ $limit = Zend_Json::decode($response->getBody());
63
+ $credlimit = $limit['resources']['account']['/account/verify_credentials'];
64
+ if ($credlimit['remaining'] > 0):
65
+ $client->setUri('https://api.twitter.com/1.1/account/verify_credentials.json');
66
+ $client->setMethod(Zend_Http_Client::GET);
67
+ $response = $client->request();
68
+
69
+ $status = Zend_Json::decode($response->getBody());
70
+
71
+ if (isset($status['errors'])) return false;
72
+
73
+ $userlimit = $limit['resources']['statuses']['/statuses/user_timeline'];
74
+ if ($userlimit['remaining'] >= $this->findRequestCount($stores, $storecount)):
75
+ $screencontent = array();
76
+ $storecontent = array();
77
+ foreach ($stores as $store => $screenname):
78
+ $screenstore = isset($screencontent[$screenname]) ? $screencontent[$screenname] : false;
79
+ if ($screenstore && $storecount[$store] <= $storecount[$screenstore]):
80
+ $storecontent[$store] = $storecontent[$screenstore];
81
+ else:
82
+ $client->setUri('https://api.twitter.com/1.1/statuses/user_timeline.json');
83
+ $client->setMethod(Zend_Http_Client::GET);
84
+ $client->setParameterGet('screen_name', $screenname);
85
+ $client->setParameterGet('count', $storecount[$store]);
86
+ $client->setParameterGet('trim_user', 'true');
87
+ $client->setParameterGet('exclude_replies', 'true');
88
+ $client->setParameterGet('include_rts', 'false');
89
+
90
+ $response = $client->request();
91
+
92
+ $content = Zend_Json::decode($response->getBody());
93
+ $screencontent[$screenname] = $store;
94
+ $storecontent[$store] = $content;
95
+ endif;
96
+ endforeach;
97
+ endif;
98
+ endif;
99
+ } catch (Exception $e) {
100
+ return false;
101
+ }
102
+
103
+ $cleanup = $this->processStoreContent($storecontent);
104
+
105
+ return $cleanup;
106
+ }
107
+
108
+ private function findRequestCount($stores, $storecount)
109
+ {
110
+ $screencontent = array();
111
+ $return = 0;
112
+ foreach ($stores as $store => $screenname):
113
+ $screenstore = isset($screencontent[$screenname]) ? $screencontent[$screenname] : false;
114
+ if ($screenstore && $storecount[$store] <= $storecount[$screenstore]):
115
+ $return++;
116
+ else:
117
+ $screencontent[$screenname] = $store;
118
+ endif;
119
+ endforeach;
120
+
121
+ return count($stores) - $return;
122
+ }
123
+
124
+ private function processStoreContent($storecontent)
125
+ {
126
+ $cleanup = false;
127
+ $ids = $this->getIdsByStore();
128
+ foreach ($storecontent as $store => $content):
129
+ foreach ($content as $tweet):
130
+ $newid = $tweet['id_str'];
131
+ if (!in_array($newid, $ids[$store])):
132
+ $this->storeTweet($tweet, $store);
133
+ $cleanup = true;
134
+ endif;
135
+ endforeach;
136
+ endforeach;
137
+
138
+ return $cleanup;
139
+ }
140
+
141
+ private function getIdsByStore()
142
+ {
143
+ $ids = array();
144
+ foreach(Mage::getModel('twitterreader/twitterreader')->getCollection() as $content):
145
+ $ids[$content->getStore()][] = $content->getTwitterId();
146
+ endforeach;
147
+
148
+ return $ids;
149
+ }
150
+
151
+ private function storeTweet($tweet, $store)
152
+ {
153
+ $twitterid = $tweet['id_str'];
154
+ $content = $tweet['text'];
155
+ $timestamp = strtotime($tweet['created_at']);
156
+ $timestamp = date('Y-m-d H:i:s', $timestamp);
157
+ $screenname = Mage::getStoreConfig('twitterreader/configuration/screen_name', $store);
158
+
159
+ $newtweet = Mage::getModel('twitterreader/twitterreader');
160
+ $newtweet
161
+ ->setTwitterId($twitterid)
162
+ ->setContent($content)
163
+ ->setStore($store)
164
+ ->setScreenName($screenname)
165
+ ->setTimestamp($timestamp);
166
+
167
+ $newtweet->save();
168
+ }
169
+
170
+ private function cleanUp()
171
+ {
172
+ $resource = Mage::getSingleton('core/resource');
173
+ $write = $resource->getConnection('twitterreader_write');
174
+
175
+ $keepids = array();
176
+ foreach (Mage::app()->getStores() as $store):
177
+ $screenname = Mage::getStoreConfig('twitterreader/configuration/screen_name', $store->getCode());
178
+ $count = Mage::helper('twitterreader')->getStoreCount($store->getCode());
179
+ $collection = Mage::getModel('twitterreader/twitterreader')->getCollection();
180
+ $select = $collection->getSelect();
181
+ $select
182
+ ->where('store = ?', $store->getCode())
183
+ ->where('screen_name = ?', $screenname)
184
+ ->order(array('timestamp DESC'))
185
+ ->limit($count);
186
+
187
+ foreach ($collection as $tweet):
188
+ $keepids[] = $tweet->getId();
189
+ endforeach;
190
+ endforeach;
191
+
192
+ $write->delete(
193
+ $resource->getTableName('twitterreader/twitter_reader'),
194
+ array('id NOT IN (?)' => $keepids)
195
+ );
196
+ }
197
+ }
app/code/community/HusseyCoding/TwitterReader/Model/Mysql4/Twitterreader.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Model_Mysql4_Twitterreader extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ $this->_init('twitterreader/twitter_reader', 'id');
7
+ }
8
+ }
app/code/community/HusseyCoding/TwitterReader/Model/Mysql4/Twitterreader/Collection.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Model_Mysql4_Twitterreader_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('twitterreader/twitterreader');
8
+ }
9
+ }
app/code/community/HusseyCoding/TwitterReader/Model/Observer.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Model_Observer
3
+ {
4
+ public function adminhtmlCoreConfigDataSaveBefore($observer)
5
+ {
6
+ $config = $observer->getConfigData();
7
+ if ($config->getPath() == 'twitterreader/configuration/request_token'):
8
+ if (Mage::helper('twitterreader')->checkCoreRow('twitterreader/configuration/request_token')):
9
+ $config->disableSave();
10
+ endif;
11
+ elseif ($config->getPath() == 'twitterreader/configuration/access_token'):
12
+ if (Mage::helper('twitterreader')->checkCoreRow('twitterreader/configuration/access_token')):
13
+ $config->disableSave();
14
+ endif;
15
+ endif;
16
+ }
17
+ }
app/code/community/HusseyCoding/TwitterReader/Model/Twitterreader.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_Model_Twitterreader extends Mage_Core_Model_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('twitterreader/twitterreader');
8
+ }
9
+ }
app/code/community/HusseyCoding/TwitterReader/controllers/CallbackController.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_TwitterReader_CallbackController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ public function accessAction()
5
+ {
6
+ $config = array(
7
+ 'callbackUrl' => Mage::helper('adminhtml')->getUrl('twitterreader/callback/access'),
8
+ 'siteUrl' => 'https://api.twitter.com/oauth',
9
+ 'consumerKey' => Mage::getStoreConfig('twitterreader/configuration/consumer_key'),
10
+ 'consumerSecret' => Mage::getStoreConfig('twitterreader/configuration/consumer_secret')
11
+ );
12
+ $consumer = new Zend_Oauth_Consumer($config);
13
+
14
+ try {
15
+ $request = Mage::helper('twitterreader')->getOauthObject('twitterreader/configuration/request_token');
16
+ if ($request):
17
+ $access = $consumer->getAccessToken($_GET, $request);
18
+ Mage::helper('twitterreader')->storeOauthObject($access, 'twitterreader/configuration/access_token');
19
+ Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/request_token');
20
+ Mage::getConfig()->saveConfig('twitterreader/configuration/callback_url', '');
21
+ endif;
22
+ } catch (Exception $e) {
23
+ Mage::getConfig()->saveConfig('twitterreader/configuration/callback_url', '');
24
+ Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/request_token');
25
+ Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/access_token');
26
+ }
27
+
28
+ $url = Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit/section/twitterreader');
29
+ $this->getResponse()->setRedirect($url);
30
+ }
31
+
32
+ public function resetAction()
33
+ {
34
+ Mage::getConfig()->saveConfig('twitterreader/configuration/callback_url', '');
35
+ Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/request_token');
36
+ Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/access_token');
37
+
38
+ $url = Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit/section/twitterreader');
39
+ $this->getResponse()->setRedirect($url);
40
+ }
41
+
42
+ public function updateAction()
43
+ {
44
+ Mage::getModel('twitterreader/manage')->cron();
45
+
46
+ $url = Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit/section/twitterreader');
47
+ $this->getResponse()->setRedirect($url);
48
+ }
49
+ }
app/code/community/HusseyCoding/TwitterReader/etc/adminhtml.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Allow Everything</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <twitterreader module="twitterreader">
15
+ <title>Twitter Reader</title>
16
+ </twitterreader>
17
+ </children>
18
+ </config>
19
+ </children>
20
+ </system>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+ </config>
app/code/community/HusseyCoding/TwitterReader/etc/config.xml ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_TwitterReader>
5
+ <version>1.0.5</version>
6
+ </HusseyCoding_TwitterReader>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <twitterreader>
11
+ <class>HusseyCoding_TwitterReader_Model</class>
12
+ <resourceModel>twitterreader_mysql4</resourceModel>
13
+ </twitterreader>
14
+ <twitterreader_mysql4>
15
+ <class>HusseyCoding_TwitterReader_Model_Mysql4</class>
16
+ <entities>
17
+ <twitter_reader>
18
+ <table>twitter_reader</table>
19
+ </twitter_reader>
20
+ </entities>
21
+ </twitterreader_mysql4>
22
+ <core>
23
+ <rewrite>
24
+ <config_data>HusseyCoding_TwitterReader_Model_Config_CoreData</config_data>
25
+ </rewrite>
26
+ </core>
27
+ </models>
28
+ <helpers>
29
+ <twitterreader>
30
+ <class>HusseyCoding_TwitterReader_Helper</class>
31
+ </twitterreader>
32
+ </helpers>
33
+ <blocks>
34
+ <twitterreader>
35
+ <class>HusseyCoding_TwitterReader_Block</class>
36
+ </twitterreader>
37
+ </blocks>
38
+ <resources>
39
+ <twitterreader_setup>
40
+ <setup>
41
+ <module>HusseyCoding_TwitterReader</module>
42
+ <resourceModel>husseycoding_twitterreader_mysql4</resourceModel>
43
+ </setup>
44
+ <connection>
45
+ <use>core_setup</use>
46
+ </connection>
47
+ </twitterreader_setup>
48
+ <twitterreader_write>
49
+ <connection>
50
+ <use>core_write</use>
51
+ </connection>
52
+ </twitterreader_write>
53
+ <twitterreader_read>
54
+ <connection>
55
+ <use>core_read</use>
56
+ </connection>
57
+ </twitterreader_read>
58
+ </resources>
59
+ </global>
60
+ <frontend>
61
+ <layout>
62
+ <updates>
63
+ <twitterreader>
64
+ <file>twitterreader.xml</file>
65
+ </twitterreader>
66
+ </updates>
67
+ </layout>
68
+ </frontend>
69
+ <admin>
70
+ <routers>
71
+ <twitterreader>
72
+ <use>admin</use>
73
+ <args>
74
+ <module>HusseyCoding_TwitterReader</module>
75
+ <frontName>twitterreader</frontName>
76
+ </args>
77
+ </twitterreader>
78
+ </routers>
79
+ </admin>
80
+ <adminhtml>
81
+ <layout>
82
+ <updates>
83
+ <menupages>
84
+ <file>twitterreader.xml</file>
85
+ </menupages>
86
+ </updates>
87
+ </layout>
88
+ <events>
89
+ <core_config_data_save_before>
90
+ <observers>
91
+ <adminhtml_core_config_data_save_before_twitterreader>
92
+ <class>twitterreader/observer</class>
93
+ <method>adminhtmlCoreConfigDataSaveBefore</method>
94
+ </adminhtml_core_config_data_save_before_twitterreader>
95
+ </observers>
96
+ </core_config_data_save_before>
97
+ </events>
98
+ </adminhtml>
99
+ <crontab>
100
+ <jobs>
101
+ <twitterreader_manage>
102
+ <schedule>
103
+ <cron_expr>*/10 * * * *</cron_expr>
104
+ </schedule>
105
+ <run>
106
+ <model>twitterreader/manage::cron</model>
107
+ </run>
108
+ </twitterreader_manage>
109
+ </jobs>
110
+ </crontab>
111
+ </config>
app/code/community/HusseyCoding/TwitterReader/etc/system.xml ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <twitterreader translate="label" module="twitterreader">
5
+ <label>Twitter Reader</label>
6
+ <tab>husseycoding</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>1</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <configuration translate="label">
14
+ <label>Feed Configuration</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <screen_name>
22
+ <label>Twitter Screen Name</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>1</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ </screen_name>
29
+ <tweet_display>
30
+ <label>Maximum Tweets To Display</label>
31
+ <frontend_type>text</frontend_type>
32
+ <sort_order>2</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ <comment>Defaults to 5</comment>
37
+ </tweet_display>
38
+ <tweet_length>
39
+ <label>Limit Tweet Length</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>3</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ <comment>Number of characters to display. Blank for all</comment>
46
+ </tweet_length>
47
+ <display_date>
48
+ <label>Display Tweet Date</label>
49
+ <frontend_type>select</frontend_type>
50
+ <source_model>adminhtml/system_config_source_yesno</source_model>
51
+ <sort_order>4</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ </display_date>
56
+ <date_format>
57
+ <label>Date Format</label>
58
+ <frontend_type>text</frontend_type>
59
+ <sort_order>5</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ <comment>Optional. PHP date() function format</comment>
64
+ </date_format>
65
+ <consumer_key>
66
+ <label>Consumer Key</label>
67
+ <frontend_type>text</frontend_type>
68
+ <sort_order>6</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>0</show_in_website>
71
+ <show_in_store>0</show_in_store>
72
+ <comment><![CDATA[Create an application <a href="https://dev.twitter.com/apps" target="_blank">here</a> to obtain]]></comment>
73
+ </consumer_key>
74
+ <consumer_secret>
75
+ <label>Consumer Secret</label>
76
+ <frontend_type>text</frontend_type>
77
+ <sort_order>7</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>0</show_in_website>
80
+ <show_in_store>0</show_in_store>
81
+ <comment><![CDATA[Create an application <a href="https://dev.twitter.com/apps" target="_blank">here</a> to obtain]]></comment>
82
+ </consumer_secret>
83
+ <callback_url>
84
+ <label>Status</label>
85
+ <frontend_type>hidden</frontend_type>
86
+ <sort_order>8</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>0</show_in_website>
89
+ <show_in_store>0</show_in_store>
90
+ </callback_url>
91
+ <request_token>
92
+ <label>Request Token</label>
93
+ <frontend_type>hidden</frontend_type>
94
+ <sort_order>9</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>0</show_in_website>
97
+ <show_in_store>0</show_in_store>
98
+ </request_token>
99
+ <access_token>
100
+ <label>Access Token</label>
101
+ <frontend_type>hidden</frontend_type>
102
+ <sort_order>10</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>0</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </access_token>
107
+ </fields>
108
+ </configuration>
109
+ <position translate="label">
110
+ <label>Display Position</label>
111
+ <frontend_type>text</frontend_type>
112
+ <sort_order>2</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ <comment><![CDATA[For custom position add &lt;?php echo Mage::helper('twitterreader')-&gt;show(); ?&gt; to the template of your choice.]]></comment>
117
+ <fields>
118
+ <left_sidebar_top>
119
+ <label>Left Sidebar Top</label>
120
+ <frontend_type>select</frontend_type>
121
+ <source_model>adminhtml/system_config_source_yesno</source_model>
122
+ <sort_order>1</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>1</show_in_website>
125
+ <show_in_store>1</show_in_store>
126
+ </left_sidebar_top>
127
+ <left_sidebar_bottom>
128
+ <label>Left Sidebar Bottom</label>
129
+ <frontend_type>select</frontend_type>
130
+ <source_model>adminhtml/system_config_source_yesno</source_model>
131
+ <sort_order>2</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>1</show_in_website>
134
+ <show_in_store>1</show_in_store>
135
+ </left_sidebar_bottom>
136
+ <right_sidebar_top>
137
+ <label>Right Sidebar Top</label>
138
+ <frontend_type>select</frontend_type>
139
+ <source_model>adminhtml/system_config_source_yesno</source_model>
140
+ <sort_order>3</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>1</show_in_website>
143
+ <show_in_store>1</show_in_store>
144
+ </right_sidebar_top>
145
+ <right_sidebar_bottom>
146
+ <label>Right Sidebar Bottom</label>
147
+ <frontend_type>select</frontend_type>
148
+ <source_model>adminhtml/system_config_source_yesno</source_model>
149
+ <sort_order>4</sort_order>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>1</show_in_website>
152
+ <show_in_store>1</show_in_store>
153
+ </right_sidebar_bottom>
154
+ <footer_start>
155
+ <label>Footer Start</label>
156
+ <frontend_type>select</frontend_type>
157
+ <source_model>adminhtml/system_config_source_yesno</source_model>
158
+ <sort_order>5</sort_order>
159
+ <show_in_default>1</show_in_default>
160
+ <show_in_website>1</show_in_website>
161
+ <show_in_store>1</show_in_store>
162
+ </footer_start>
163
+ <footer_end>
164
+ <label>Footer End</label>
165
+ <frontend_type>select</frontend_type>
166
+ <source_model>adminhtml/system_config_source_yesno</source_model>
167
+ <sort_order>6</sort_order>
168
+ <show_in_default>1</show_in_default>
169
+ <show_in_website>1</show_in_website>
170
+ <show_in_store>1</show_in_store>
171
+ </footer_end>
172
+ <custom>
173
+ <label>Custom</label>
174
+ <frontend_type>select</frontend_type>
175
+ <source_model>adminhtml/system_config_source_yesno</source_model>
176
+ <sort_order>7</sort_order>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>1</show_in_website>
179
+ <show_in_store>1</show_in_store>
180
+ </custom>
181
+ </fields>
182
+ </position>
183
+ </groups>
184
+ </twitterreader>
185
+ </sections>
186
+ </config>
app/code/community/HusseyCoding/TwitterReader/sql/twitterreader_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ CREATE TABLE {$this->getTable('twitterreader/twitter_reader')} (
8
+ `id` int unsigned NOT NULL auto_increment,
9
+ `twitter_id` tinytext NOT NULL,
10
+ `content` text NOT NULL,
11
+ `store` tinytext NOT NULL,
12
+ `screen_name` tinytext NOT NULL,
13
+ `timestamp` datetime NOT NULL,
14
+ PRIMARY KEY (`id`)
15
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16
+
17
+ ");
18
+
19
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/twitterreader.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_system_config_edit>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_js</type>
7
+ <name>twitterreader/js/twitterreader.js</name>
8
+ </action>
9
+ </reference>
10
+ <reference name="content">
11
+ <block type="twitterreader/verify" template="twitterreader/verify.phtml" name="twitter_verify" />
12
+ </reference>
13
+ </adminhtml_system_config_edit>
14
+ </layout>
app/design/adminhtml/default/default/template/twitterreader/verify.phtml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($status = $this->verifyCredentials()): ?>
2
+ <script type="text/javascript">
3
+ //<![CDATA[
4
+ var thistwitterverify = new twitterverify();
5
+ thistwitterverify.status = "<?php echo $status; ?>";
6
+ <?php if ($status == 'ready'): ?>
7
+ thistwitterverify.reseturl = "<?php echo Mage::helper('adminhtml')->getUrl('twitterreader/callback/reset'); ?>";
8
+ thistwitterverify.updateurl = "<?php echo Mage::helper('adminhtml')->getUrl('twitterreader/callback/update'); ?>";
9
+ <?php elseif ($status == 'verify_credentials'): ?>
10
+ thistwitterverify.callbackurl = "<?php echo Mage::getStoreConfig('twitterreader/configuration/callback_url'); ?>";
11
+ thistwitterverify.reseturl = "<?php echo Mage::helper('adminhtml')->getUrl('twitterreader/callback/reset'); ?>";
12
+ <?php elseif ($status == 'bad_verify'): ?>
13
+ thistwitterverify.reseturl = "<?php echo Mage::helper('adminhtml')->getUrl('twitterreader/callback/reset'); ?>";
14
+ <?php elseif ($status == 'problem'): ?>
15
+ thistwitterverify.reseturl = "<?php echo Mage::helper('adminhtml')->getUrl('twitterreader/callback/reset'); ?>";
16
+ <?php elseif (is_int($status)): ?>
17
+ thistwitterverify.status = "exceeded";
18
+ thistwitterverify.reset = "<?php echo date('H:i:s', $status); ?>";
19
+ <?php elseif ($status == 'bad_callback'): ?>
20
+ thistwitterverify.reseturl = "<?php echo Mage::helper('adminhtml')->getUrl('twitterreader/callback/reset'); ?>";
21
+ <?php endif; ?>
22
+ //]]>
23
+ </script>
24
+ <?php endif; ?>
app/design/frontend/base/default/layout/twitterreader.xml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_css</type>
7
+ <name>css/twitterreader.css</name>
8
+ </action>
9
+ </reference>
10
+ <reference name="left">
11
+ <block type="twitterreader/tweets" name="twitterreader_left_sidebar_top_container" before="-">
12
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader_left_sidebar_top" />
13
+ <action method="verifyBlock"><config>left_sidebar_top</config><block>twitterreader_left_sidebar_top</block></action>
14
+ </block>
15
+ <block type="twitterreader/tweets" name="twitterreader_left_sidebar_bottom_container" after="-">
16
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader_left_sidebar_bottom" />
17
+ <action method="verifyBlock"><config>left_sidebar_bottom</config><block>twitterreader_left_sidebar_bottom</block></action>
18
+ </block>
19
+ </reference>
20
+ <reference name="right">
21
+ <block type="twitterreader/tweets" name="twitterreader_right_sidebar_top_container" before="-">
22
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader_right_sidebar_top" />
23
+ <action method="verifyBlock"><config>right_sidebar_top</config><block>twitterreader_right_sidebar_top</block></action>
24
+ </block>
25
+ <block type="twitterreader/tweets" name="twitterreader_right_sidebar_bottom_container" after="-">
26
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader_right_sidebar_bottom" />
27
+ <action method="verifyBlock"><config>right_sidebar_bottom</config><block>twitterreader_right_sidebar_bottom</block></action>
28
+ </block>
29
+ </reference>
30
+ <reference name="footer">
31
+ <block type="twitterreader/tweets" name="twitterreader_footer_start_container" before="-">
32
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader_footer_start" />
33
+ <action method="verifyBlock"><config>footer_start</config><block>twitterreader_footer_start</block></action>
34
+ </block>
35
+ <block type="twitterreader/tweets" name="twitterreader_right_sidebar_end_container" after="-">
36
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader_footer_end" />
37
+ <action method="verifyBlock"><config>footer_end</config><block>twitterreader_footer_end</block></action>
38
+ </block>
39
+ </reference>
40
+ <reference name="root">
41
+ <block type="twitterreader/tweets" name="twitterreader_container" after="-">
42
+ <block type="page/html" template="twitterreader/tweets.phtml" name="twitterreader" />
43
+ <action method="verifyBlock"><config>custom</config><block>twitterreader</block></action>
44
+ </block>
45
+ </reference>
46
+ </default>
47
+ </layout>
app/design/frontend/base/default/template/twitterreader/tweets.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($collection = Mage::helper('twitterreader')->collectFeedContent()): ?>
2
+ <?php $class = $this->getNameInLayout(); ?>
3
+ <?php if (strpos($class, 'footer')): ?>
4
+ <div class="<?php echo $this->getNameInLayout(); ?>">
5
+ <h3><?php echo $this->helper('twitterreader')->__('Recent Tweets'); ?></h3>
6
+ <div class="twitterreader_tweets">
7
+ <?php foreach ($collection as $tweet): ?>
8
+ <span>
9
+ <?php $screen = Mage::getStoreConfig('twitterreader/configuration/screen_name'); ?>
10
+ <a href="https://twitter.com/<?php echo $screen; ?>/status/<?php echo $tweet->getTwitterId(); ?>" target="_blank">
11
+ <?php echo $tweet->getContent(); ?>
12
+ </a>
13
+ <?php if (Mage::getStoreConfig('twitterreader/configuration/display_date')): ?>
14
+ <?php echo Mage::helper('twitterreader')->displayDate($tweet->getTimestamp()); ?>
15
+ <?php endif; ?>
16
+ </span>
17
+ <?php endforeach; ?>
18
+ </div>
19
+ </div>
20
+ <?php else: ?>
21
+ <div class="<?php echo $this->getNameInLayout(); ?>">
22
+ <div class="block">
23
+ <div class="block-title">
24
+ <strong>
25
+ <span>
26
+ <?php echo $this->helper('twitterreader')->__('Recent Tweets'); ?>
27
+ </span>
28
+ </strong>
29
+ </div>
30
+ <div class="block-content">
31
+ <ol>
32
+ <?php foreach ($collection as $tweet): ?>
33
+ <li class="item">
34
+ <?php $screen = Mage::getStoreConfig('twitterreader/configuration/screen_name'); ?>
35
+ <a href="https://twitter.com/<?php echo $screen; ?>/status/<?php echo $tweet->getTwitterId(); ?>" target="_blank">
36
+ <?php echo Mage::helper('twitterreader')->formatContent($tweet->getContent()); ?>
37
+ </a>
38
+ <?php if (Mage::getStoreConfig('twitterreader/configuration/display_date')): ?>
39
+ <?php echo Mage::helper('twitterreader')->displayDate($tweet->getTimestamp()); ?>
40
+ <?php endif; ?>
41
+ <li>
42
+ <?php endforeach; ?>
43
+ </ol>
44
+ </div>
45
+ </div>
46
+ </div>
47
+ <?php endif; ?>
48
+ <?php endif; ?>
app/etc/modules/HusseyCoding_Common.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_Common>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </HusseyCoding_Common>
8
+ </modules>
9
+ </config>
app/etc/modules/HusseyCoding_TwitterReader.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_TwitterReader>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </HusseyCoding_TwitterReader>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>HusseyCoding_TwitterReader</name>
4
+ <version>1.0.5</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Increase the social profile of your Magento site by easily adding store specific tweets.</summary>
10
+ <description>This extension seamlessly integrates with the latest Twitter API technology and allows you to quickly and easily add tweets, per store, to any page in any position.</description>
11
+ <notes>Fixed losing block order on cms edit page load</notes>
12
+ <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
13
+ <date>2015-08-26</date>
14
+ <time>10:13:18</time>
15
+ <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="TwitterReader"><dir name="Block"><file name="Tweets.php" hash="049d0934eeac08c235b39c71a1293910"/><file name="Verify.php" hash="68098cae4b409154a4aa618e5b2da6c2"/></dir><dir name="controllers"><file name="CallbackController.php" hash="4154dc3be629ca8b438e12b1a1e23511"/></dir><dir name="etc"><file name="adminhtml.xml" hash="909b1f48112a4c4b00a37e145041eadd"/><file name="config.xml" hash="f1b8d6a59b3dbcb9c4c9c08dd94196ce"/><file name="system.xml" hash="3609a56fbd345b8651066b5486d8de45"/></dir><dir name="Helper"><file name="Data.php" hash="01b6ef3fe4a5e33c7c24a8e4d1572b0b"/></dir><dir name="Model"><dir name="Config"><file name="CoreData.php" hash="ec734ef221f1c1527be82d7dd09ccf23"/></dir><file name="Manage.php" hash="c52b4b6af39cc8bececd0f6c6e6643e6"/><dir name="Mysql4"><dir name="Twitterreader"><file name="Collection.php" hash="d00dec73701177bdbe0b755a7cab65da"/></dir><file name="Twitterreader.php" hash="0ee1e85be7b2559ceff18c9ec9160f47"/></dir><file name="Observer.php" hash="355ab44cdb45102855b7fb4847aa489a"/><file name="Twitterreader.php" hash="0bcfbf3b1a569793e409cd7f1deec000"/></dir><dir name="sql"><dir name="twitterreader_setup"><file name="mysql4-install-1.0.0.php" hash="1e59e36f7e5eea1406e64d7f0099197b"/></dir></dir></dir><dir name="Common"><dir name="etc"><file name="system.xml" hash="6c9ba9f227b9adfc9abf97f17b46fdbf"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="HusseyCoding_TwitterReader.xml" hash="365441683cb1c3c5fef7569aab423dc0"/><file name="HusseyCoding_Common.xml" hash="31e82d3d9b3179c2fa9e002f9669da47"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="twitterreader.xml" hash="da55257b0be819190ce22e975f007a63"/></dir><dir name="template"><dir name="twitterreader"><file name="verify.phtml" hash="eab267b579bb5a419df3a2fbf31d397a"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="twitterreader.xml" hash="867abc35ab34bc33cbecf5362521d94a"/></dir><dir name="template"><dir name="twitterreader"><file name="tweets.phtml" hash="1aefa42a68f124df4571b26a4f3dfa80"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="twitterreader"><dir name="js"><file name="twitterreader.js" hash="4bdcd68a1648fde96cbd4f649ee07aa8"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="twitterreader.css" hash="6bdd8f39d0175c4e05d1f8804ef1f152"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/adminhtml/default/default/twitterreader/js/twitterreader.js ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var twitterverify = Class.create({
2
+ afterInit: function() {
3
+ $("row_twitterreader_configuration_callback_url").down("td.value").insert({ top: "<span id=\"twitterreader_apistatus\"></span>" });
4
+ this.showStatus();
5
+ },
6
+ showStatus: function() {
7
+ var el = $("twitterreader_apistatus");
8
+ if (this.status == "consumer_missing") {
9
+ el.update("Consumer Key/Secret missing");
10
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Invalid without consumer data</span>" });
11
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Invalid without consumer data</span>" });
12
+ } else if (this.status == "verify_credentials") {
13
+ el.update("Verify your credentials <a href=\"" + this.callbackurl + "\">here</a><br />If the page has expired reset the request <a id=\"twitterreader_readyreset\" href=\"javascript:void(null)\">here</a>");
14
+ this.resetListener();
15
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Obtained</span>" });
16
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Required</span>" });
17
+ } else if (this.status == "bad_callback") {
18
+ el.update("Please check your consumer credentials and make sure you have created an access token, and added a dummy 'Callback URL' to your <a href=\"https://dev.twitter.com/apps\" target=\"_blank\">application</a><br />Reset your credentials <a id=\"twitterreader_readyreset\" href=\"javascript:void(null)\">here</a>");
19
+ this.resetListener();
20
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Obtained</span>" });
21
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Required</span>" });
22
+ } else if (this.status == "ready") {
23
+ el.update("Verified and ready<br />Reset your credentials <a id=\"twitterreader_readyreset\" href=\"javascript:void(null)\">here</a><br />Tweets updated via cron, update manually <a id=\"twitterreader_readyupdate\" href=\"javascript:void(null)\">here</a>")
24
+ this.resetListener();
25
+ this.updateListener();
26
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Not required</span>" });
27
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Obtained</span>" });
28
+ } else if (this.status == "bad_verify") {
29
+ el.update("Failed to verify your credentials<br />You may need to reset them <a id=\"twitterreader_readyreset\" href=\"javascript:void(null)\">here</a>")
30
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Not required</span>" });
31
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Possibly invalidated</span>" });
32
+ this.resetListener();
33
+ } else if (this.status == "problem") {
34
+ el.update("There is a problem with your credentials<br />You may need to reset them <a id=\"twitterreader_readyreset\" href=\"javascript:void(null)\">here</a>")
35
+ this.resetListener();
36
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Not required</span>" });
37
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Invalidated</span>" });
38
+ } else if (this.status == "exceeded") {
39
+ el.update("Maximum requests exceeded<br />This will reset at " + this.reset);
40
+ $("row_twitterreader_configuration_request_token").down("td.value").insert({ top: "<span>Waiting</span>" });
41
+ $("row_twitterreader_configuration_access_token").down("td.value").insert({ top: "<span>Waiting</span>" });
42
+ }
43
+ },
44
+ resetListener: function() {
45
+ $("twitterreader_readyreset").observe("click", function(e) {
46
+ if (confirm("Are you sure?")) {
47
+ window.location = this.reseturl;
48
+ }
49
+ }.bind(this));
50
+ },
51
+ updateListener: function() {
52
+ $("twitterreader_readyupdate").observe("click", function(e) {
53
+ window.location = this.updateurl;
54
+ }.bind(this));
55
+ }
56
+ });
57
+
58
+ document.observe("dom:loaded", function() {
59
+ if (typeof(thistwitterverify) == "object") {
60
+ thistwitterverify.afterInit();
61
+ }
62
+ });
skin/frontend/base/default/css/twitterreader.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ .twitterreader_footer_start { width:25%; }
2
+ .twitterreader_footer_start .twitterreader_tweets { margin-bottom:10px; }
3
+ .twitterreader_footer_start .twitterreader_tweets a { display:block; padding:5px 0; text-align:left; }
4
+ .twitterreader_footer_end { width:25%; }
5
+ .twitterreader_footer_end .twitterreader_tweets { margin-bottom:10px; }
6
+ .twitterreader_footer_end .twitterreader_tweets a { display:block; padding:5px 0; text-align:left; }