Sparx_Tweets - Version 0.1.0

Version Notes

Able to disable and enable the extension from the admin end.
Admin can choose whether to display the latest tweets in left or right sidebar of your magento site
Admin can choose number of twitter feeds you want to display in the frontend.
Able to choose using widget or auth 2

Download this release

Release Info

Developer Bhoopendra Dwivedi
Extension Sparx_Tweets
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Sparx/Tweets/Block/Adminhtml/System/Config/Implementcode.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sparx_Tweets_Block_Adminhtml_System_Config_Implementcode extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
5
+
6
+ return '
7
+ <div class="entry-edit-head collapseable"><a onclick="Fieldset.toggleCollapse(\'tweets_template\'); return false;" href="#" id="tweets_template-head" class="open">Implement Code</a></div>
8
+ <input id="tweets_template-state" type="hidden" value="1" name="config_state[tweets_template]">
9
+ <fieldset id="tweets_template" class="config collapseable" style="">
10
+ <h4 class="icon-head head-edit-form fieldset-legend">Code for Twitter Tweets</h4>
11
+
12
+ <div id="messages">
13
+ <ul class="messages">
14
+ <li class="notice-msg">
15
+ <ul>
16
+ <li>'.Mage::helper('tweets')->__('Add code below to a template file').'</li>
17
+ </ul>
18
+ </li>
19
+ </ul>
20
+ </div>
21
+ <br>
22
+ <ul>
23
+ <li>
24
+ <code>
25
+ $this->getLayout()->createBlock('.'"tweets/tweets"'.')->setTemplate('.'"tweets/tweets.phtml"'.')->toHtml();
26
+ </code>
27
+ </li>
28
+ </ul>
29
+ <br>
30
+ <div id="messages">
31
+ <ul class="messages">
32
+ <li class="notice-msg">
33
+ <ul>
34
+ <li>'.Mage::helper('tweets')->__('Put code on a CMS page').'</li>
35
+ </ul>
36
+ </li>
37
+ </ul>
38
+ </div>
39
+ <br>
40
+ <ul>
41
+ <li>
42
+ <code>
43
+ {{block type="tweets/tweets" name="tweets.cms" template="tweets/tweets.phtml"}}
44
+ </code>
45
+ </li>
46
+ </ul>
47
+ <br>
48
+ <div id="messages">
49
+ <ul class="messages">
50
+ <li class="notice-msg">
51
+ <ul>
52
+ <li>'.Mage::helper('tweets')->__('Please copy and paste the code below on one of xml layout files where you want to show the Twitter Tweets.').'</li>
53
+ </ul>
54
+ </li>
55
+ </ul>
56
+ </div>
57
+
58
+ <ul>
59
+ <li>
60
+ <code>
61
+ &lt;block type="tweets/tweets" name="tweets.tweets" template="tweets/tweets.phtml"&gt;<br>
62
+
63
+ &lt;/block&gt;
64
+ </code>
65
+ </li>
66
+ </ul>
67
+
68
+ <br>
69
+
70
+ </fieldset>';
71
+ }
72
+ }
app/code/community/Sparx/Tweets/Block/Tweets.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sparx_Tweets_Block_Tweets extends Mage_Core_Block_Template{
3
+
4
+ /*
5
+ * Get Tweets By Username
6
+ * return array
7
+ */
8
+ public function getTweetsByUsername ($username)
9
+ {
10
+ $feed = Mage::getModel('tweets/feed')->getFeed($username);
11
+ return($this->getTweets($feed));
12
+ }
13
+ function getTime($time){
14
+ $tweetdate = $time;
15
+ $tweet = $tweettag["content"];
16
+ $timedate = explode(" ",$tweetdate);
17
+ $date1 = $timedate[2];
18
+ $date2 = $timedate[1];
19
+ $date3 = $timedate[5];
20
+ $time = substr($timedate[3],0, -1);
21
+ $tweettime = (strtotime($date1." ".$date2." ".$date3." ".$time))+3600; // This is the value of the time difference - UK + 1 hours (3600 seconds)
22
+ $nowtime = time();
23
+ $timeago = ($nowtime-$tweettime);
24
+ $thehours = floor($timeago/3600);
25
+ $theminutes = floor($timeago/60);
26
+ $thedays = floor($timeago/86400);
27
+ /********************* Checking the times and returning correct value */
28
+ if($theminutes < 60){
29
+ if($theminutes < 1){
30
+ $timemessage = "Less than 1 minute ago";
31
+ } else if($theminutes == 1) {
32
+ $timemessage = $theminutes." minute ago.";
33
+ } else {
34
+ $timemessage = $theminutes." minutes ago.";
35
+ }
36
+ } else if($theminutes > 60 && $thedays < 1){
37
+ if($thehours == 1){
38
+ $timemessage = $thehours." hour ago.";
39
+ } else {
40
+ $timemessage = $thehours." hours ago.";
41
+ }
42
+ } else {
43
+ if($thedays == 1){
44
+ $timemessage = $thedays." day ago.";
45
+ } else {
46
+ $timemessage = $thedays." days ago.";
47
+ }
48
+ }
49
+ return $timemessage;
50
+ }
51
+ public function getTweets($tweets)
52
+ {
53
+ $t = array();
54
+ $i = 0;
55
+ foreach($tweets as $tweet)
56
+ {
57
+ $text = $tweet['text'];
58
+ $urls = $tweet['entities']['urls'];
59
+ $mentions = $tweet['entities']['user_mentions'];
60
+ $hashtags = $tweet['entities']['hashtags'];
61
+ if($urls){
62
+ foreach($urls as $url){
63
+ if(strpos($text,$url['url']) !== false){
64
+ $text = str_replace($url['url'],'<a href="'.$url['url'].'">'.$url['url'].'</a>',$text);
65
+ }
66
+ }
67
+ }
68
+ /*
69
+ if($mentions && $this->getAttags()){
70
+ foreach($mentions as $mention){
71
+ if(strpos($text,$mention->screen_name) !== false){
72
+ $text = str_replace("@".$mention->screen_name." ",'<a href="http://twitter.com/'.$mention->screen_name.'">@'.$mention->screen_name.'</a> ',$text);
73
+ }
74
+ }
75
+ }
76
+ if($hashtags && $this->getHashtags()){
77
+ foreach($hashtags as $hashtag){
78
+ if(strpos($text,$hashtag->text) !== false){
79
+ $text = str_replace('#'.$hashtag->text." ",'<a href="http://twitter.com/search?q=%23'.$hashtag->text.'">#'.$hashtag->text.'</a> ',$text);
80
+ }
81
+ }
82
+ }
83
+ */
84
+ //$t[$i]["tweet"] = trim($this->changeLink($text, $this->getTagPref(), $this->getNoFollow(), $this->getNewWindow()));
85
+ $t[$i]["text"] = $text;
86
+ $t[$i]["created_at"] = trim($this->getTime($tweet['created_at']));
87
+ $i++;
88
+ }
89
+ return $t;
90
+ }
91
+ }
app/code/community/Sparx/Tweets/Helper/Data.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sparx_Tweets_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ public function isEnabled(){
5
+ return Mage::getStoreConfig('tweets/general/enable');
6
+ }
7
+ public function isShowIn(){
8
+ return Mage::getStoreConfig('tweets/general/position');
9
+ }
10
+ public function isEnabledWidgets(){
11
+ return Mage::getStoreConfig('tweets/general/widgets');
12
+ }
13
+ public function getWidgetScript(){
14
+ return Mage::getStoreConfig('tweets/general/widgets_script');
15
+ }
16
+ public function getUsername(){
17
+ return Mage::getStoreConfig('tweets/general/username');
18
+ }
19
+ public function getAccessToken(){
20
+ return Mage::getStoreConfig('tweets/general/access_token');
21
+ }
22
+ public function getAccessTokenSecret(){
23
+ return Mage::getStoreConfig('tweets/general/access_token_secret');
24
+ }
25
+ public function getConsumerKey(){
26
+ return Mage::getStoreConfig('tweets/general/consumer_key');
27
+ }
28
+ public function getConsumerSecrete(){
29
+ return Mage::getStoreConfig('tweets/general/consumer_secret');
30
+ }
31
+ public function getLimit(){
32
+ return Mage::getStoreConfig('tweets/general/response_limit');
33
+ }
34
+ public function isDisplayPostedTime(){
35
+ return Mage::getStoreConfig('tweets/general/display_posted_time');
36
+ }
37
+
38
+ }
39
+
app/code/community/Sparx/Tweets/Model/Feed.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sparx_Tweets_Model_Feed extends Mage_Core_Model_Abstract
3
+ {
4
+ const RESPONSE_LIMIT =5;
5
+ public function getFeed($username, $limit = self::RESPONSE_LIMIT){
6
+ try{
7
+ require_once('twitteroauth/TwitterAPIExchange.php');
8
+ $coreHelper = Mage::helper('core');
9
+ $helper = Mage::helper('tweets');
10
+ $username = trim($username);
11
+ if($helper->getLimit()){
12
+ $limit = $helper->getLimit();
13
+ }
14
+ $limit = intval($limit);
15
+ $tweets = array();
16
+
17
+ if (!$username || !$limit || $limit <= 0) {
18
+ return array();
19
+ }
20
+
21
+ // this is where we instantiate and configure
22
+ // our API interface.
23
+ $twitter = new TwitterAPIExchange(array(
24
+ 'oauth_access_token' => $helper->getAccessToken(),
25
+ 'oauth_access_token_secret' => $helper->getAccessTokenSecret(),
26
+ 'consumer_key' => $helper->getConsumerKey(),
27
+ 'consumer_secret' => $helper->getConsumerSecrete()
28
+ ));
29
+
30
+ // set our parameters for accessing user_timeline.json
31
+ // see more: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
32
+ $getParameters = array(
33
+ 'screen_name=' . urlencode($username),
34
+ 'count=' . urlencode($limit)
35
+ );
36
+
37
+ // this is where the request is being made
38
+ $responseJson = $twitter->setGetfield('?' . implode('&', $getParameters))
39
+ ->buildOauth('https://api.twitter.com/1.1/statuses/user_timeline.json', 'GET')
40
+ ->performRequest();
41
+
42
+ // decode JSON response
43
+ $response = $coreHelper->jsonDecode($responseJson);
44
+
45
+ if (isset($response['statuses'])) {
46
+ $response = $response['statuses'];
47
+ }
48
+
49
+ if (empty($response)) {
50
+ return array();
51
+ }
52
+ return $response;
53
+ }catch(Exception $e){
54
+ return array();
55
+ }
56
+ }
57
+ }
app/code/community/Sparx/Tweets/Model/Source/Position.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sparx_Tweets_Model_Source_Position
3
+ {
4
+ /**
5
+ * Options getter
6
+ *
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array('value' => 1, 'label'=>Mage::helper('tweets')->__('Left')),
13
+ array('value' => 2, 'label'=>Mage::helper('tweets')->__('Right')),
14
+ array('value' => 0, 'label'=>Mage::helper('tweets')->__('Custom'))
15
+ );
16
+ }
17
+ }
app/code/community/Sparx/Tweets/controllers/IndexController.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sparx_Tweets_IndexController extends Mage_Core_Controller_Front_Action{
3
+ public function IndexAction() {
4
+
5
+ $this->loadLayout();
6
+ $this->getLayout()->getBlock("head")->setTitle($this->__("Tweets"));
7
+ $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
8
+ $breadcrumbs->addCrumb("home", array(
9
+ "label" => $this->__("Home Page"),
10
+ "title" => $this->__("Home Page"),
11
+ "link" => Mage::getBaseUrl()
12
+ ));
13
+
14
+ $breadcrumbs->addCrumb("tweets", array(
15
+ "label" => $this->__("Tweets"),
16
+ "title" => $this->__("Tweets")
17
+ ));
18
+
19
+ $this->renderLayout();
20
+
21
+ }
22
+ }
app/code/community/Sparx/Tweets/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <tweets translate="title" module="tweets">
12
+ <title>Tweets Section</title>
13
+ <sort_order>0</sort_order>
14
+ </tweets>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Sparx/Tweets/etc/config.xml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sparx_Tweets>
5
+ <version>0.1.0</version>
6
+ </Sparx_Tweets>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <tweets>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Sparx_Tweets</module>
14
+ <frontName>tweets</frontName>
15
+ </args>
16
+ </tweets>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <tweets>
21
+ <file>tweets.xml</file>
22
+ </tweets>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <global>
27
+ <helpers>
28
+ <tweets>
29
+ <class>Sparx_Tweets_Helper</class>
30
+ </tweets>
31
+ </helpers>
32
+ <blocks>
33
+ <tweets>
34
+ <class>Sparx_Tweets_Block</class>
35
+ </tweets>
36
+ </blocks>
37
+ <models>
38
+ <tweets>
39
+ <class>Sparx_Tweets_Model</class>
40
+ </tweets>
41
+ </models>
42
+ </global>
43
+ <default>
44
+ <tweets>
45
+ <general>
46
+ <enable>1</enable>
47
+ <position>1</position>
48
+ </general>
49
+ </tweets>
50
+ </default>
51
+ </config>
app/code/community/Sparx/Tweets/etc/system.xml ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <sparx translate="label" module="tweets">
5
+ <label>Sparx</label>
6
+ <sort_order>0</sort_order>
7
+ </sparx>
8
+ </tabs>
9
+ <sections>
10
+ <tweets translate="label" module="tweets">
11
+ <label>Tweets</label>
12
+ <tab>sparx</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>0</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general translate="label">
20
+ <label>General Configuration</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>0</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <enable translate="label">
28
+ <label>Enable</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </enable>
36
+ <position translate="label">
37
+ <label>Position</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>tweets/source_position</source_model>
40
+ <sort_order>20</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </position>
45
+ <widgets translate="label">
46
+ <label>By using Twitter Widgets</label>
47
+ <frontend_type>select</frontend_type>
48
+ <source_model>adminhtml/system_config_source_yesno</source_model>
49
+ <comment>If you enable it then only need to enter widgets script and you can leave further fields</comment>
50
+ <sort_order>32</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </widgets>
55
+ <widgets_script translate="label">
56
+ <label>Twitter Widgets Script</label>
57
+ <frontend_type>text</frontend_type>
58
+ <sort_order>35</sort_order>
59
+ <comment>Enter Twitter Widgets Script if you need to use widgets</comment>
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
+ </widgets_script>
64
+ <username translate="label">
65
+ <label>Twitter Username</label>
66
+ <frontend_type>text</frontend_type>
67
+ <sort_order>40</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </username>
72
+ <access_token translate="label">
73
+ <label>Access Token</label>
74
+ <frontend_type>text</frontend_type>
75
+ <sort_order>50</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ </access_token>
80
+ <access_token_secret translate="label">
81
+ <label>Access Token Secret</label>
82
+ <frontend_type>text</frontend_type>
83
+ <sort_order>60</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>1</show_in_website>
86
+ <show_in_store>1</show_in_store>
87
+ </access_token_secret>
88
+ <consumer_key translate="label">
89
+ <label>Consumer Key</label>
90
+ <frontend_type>text</frontend_type>
91
+ <sort_order>70</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>1</show_in_website>
94
+ <show_in_store>1</show_in_store>
95
+ </consumer_key>
96
+ <consumer_secret translate="label">
97
+ <label>Consumer Secret</label>
98
+ <frontend_type>text</frontend_type>
99
+ <sort_order>80</sort_order>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>1</show_in_website>
102
+ <show_in_store>1</show_in_store>
103
+ </consumer_secret>
104
+ <!--height translate="label">
105
+ <label>Height</label>
106
+ <frontend_type>text</frontend_type>
107
+ <sort_order>90</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>1</show_in_store>
111
+ </height-->
112
+ <response_limit translate="label">
113
+ <label>Response Limit</label>
114
+ <frontend_type>text</frontend_type>
115
+ <sort_order>100</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ </response_limit>
120
+ <display_posted_time translate="label">
121
+ <label>Display Posted Time</label>
122
+ <frontend_type>select</frontend_type>
123
+ <source_model>adminhtml/system_config_source_yesno</source_model>
124
+ <sort_order>110</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>1</show_in_store>
128
+ </display_posted_time>
129
+ </fields>
130
+ </general>
131
+ <implement translate="label">
132
+ <label>Implement Code</label>
133
+ <frontend_model>tweets/adminhtml_system_config_implementcode</frontend_model>
134
+ <sort_order>20</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ </implement>
139
+ </groups>
140
+
141
+ </tweets>
142
+ </sections>
143
+ </config>
app/design/frontend/base/default/layout/tweets.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="left">
5
+ <block type="tweets/tweets" name="tweets_left" after="-">
6
+ <action method="setTemplate" ifconfig="tweets/general/position" condition="1">
7
+ <template>tweets/left.phtml</template>
8
+ </action>
9
+ </block>
10
+ </reference>
11
+ <reference name="right">
12
+ <block type="tweets/tweets" name="tweets_right" after="-">
13
+ <action method="setTemplate" ifconfig="tweets/general/position" condition="2">
14
+ <template>tweets/right.phtml</template>
15
+ </action>
16
+ </block>
17
+ </reference>
18
+ </default>
19
+ <tweets_index_index>
20
+ <reference name="content">
21
+ <block type="tweets/tweets" name="tweets_index" after="-">
22
+ <action method="setTemplate" ifconfig="tweets/general/position" condition="2">
23
+ <template>tweets/tweets.phtml</template>
24
+ </action>
25
+ </block>
26
+ </reference>
27
+ </tweets_index_index>
28
+ </layout>
29
+
app/design/frontend/base/default/template/tweets/left.phtml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $helper = Mage::helper('tweets'); ?>
2
+ <?php if($helper->isEnabled()): ?>
3
+ <?php if($helper->isEnabledWidgets()): ?>
4
+ <?php echo $helper->getWidgetScript(); ?>
5
+ <?php elseif($helper->isShowIn() == 1 && $tweets = $this->getTweetsByUsername($helper->getUsername())): ?>
6
+ <div class="block block-creare-twitter">
7
+ <div class="block-title">
8
+ <strong>
9
+ <span><?php echo $this->__('Tweets'); ?></span>
10
+ </strong>
11
+ </div>
12
+ <div class="block-content">
13
+ <ul id="sparx-tweets">
14
+ <?php foreach($tweets as $tweet): ?>
15
+ <li class="item">
16
+ <?php echo (string) trim($tweet["text"]); ?>
17
+ <?php if($helper->isDisplayPostedTime()): ?>
18
+ <span> - <?php echo (string) trim($tweet["created_at"]); ?></span>
19
+ <?php endif; ?>
20
+ </li>
21
+ <?php endforeach; ?>
22
+ </ul>
23
+ <script type="text/javascript">decorateList('sparx-tweets');</script>
24
+ </div>
25
+ </div>
26
+ <?php endif; ?>
27
+ <?php endif; ?>
app/design/frontend/base/default/template/tweets/right.phtml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $helper = Mage::helper('tweets'); ?>
2
+ <?php if($helper->isEnabled()): ?>
3
+ <?php if($helper->isEnabledWidgets()): ?>
4
+ <?php echo $helper->getWidgetScript(); ?>
5
+ <?php elseif($helper->isShowIn() == 2 && $tweets = $this->getTweetsByUsername($helper->getUsername())): ?>
6
+ <div class="block block-creare-twitter">
7
+ <div class="block-title">
8
+ <strong>
9
+ <span><?php echo $this->__('Tweets'); ?></span>
10
+ </strong>
11
+ </div>
12
+ <div class="block-content">
13
+ <ul id="sparx-tweets">
14
+ <?php foreach($tweets as $tweet): ?>
15
+ <li class="item">
16
+ <?php echo (string) trim($tweet["text"]); ?>
17
+ <?php if($helper->isDisplayPostedTime()): ?>
18
+ <span> - <?php echo (string) trim($tweet["created_at"]); ?></span>
19
+ <?php endif; ?>
20
+ </li>
21
+ <?php endforeach; ?>
22
+ </ul>
23
+ <script type="text/javascript">decorateList('sparx-tweets');</script>
24
+ </div>
25
+ </div>
26
+ <?php endif; ?>
27
+ <?php endif; ?>
app/design/frontend/base/default/template/tweets/tweets.phtml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $helper = Mage::helper('tweets'); ?>
2
+ <?php if($helper->isEnabled()): ?>
3
+ <?php if($helper->isEnabledWidgets()): ?>
4
+ <?php echo $helper->getWidgetScript(); ?>
5
+ <?php elseif($helper->isShowIn() == 0 && $tweets = $this->getTweetsByUsername($helper->getUsername())): ?>
6
+ <div class="block block-creare-twitter">
7
+ <div class="block-title">
8
+ <strong>
9
+ <span><?php echo $this->__('Tweets'); ?></span>
10
+ </strong>
11
+ </div>
12
+ <div class="block-content">
13
+ <ul id="sparx-tweets">
14
+ <?php foreach($tweets as $tweet): ?>
15
+ <li class="item">
16
+ <?php echo (string) trim($tweet["text"]); ?>
17
+ <?php if($helper->isDisplayPostedTime()): ?>
18
+ <span> - <?php echo (string) trim($tweet["created_at"]); ?></span>
19
+ <?php endif; ?>
20
+ </li>
21
+ <?php endforeach; ?>
22
+ </ul>
23
+ <script type="text/javascript">decorateList('sparx-tweets');</script>
24
+ </div>
25
+ </div>
26
+ <?php endif; ?>
27
+ <?php endif; ?>
app/etc/modules/Sparx_Tweets.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sparx_Tweets>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Sparx_Tweets>
9
+ </modules>
10
+ </config>
lib/twitteroauth/TwitterAPIExchange.php ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Twitter-API-PHP : Simple PHP wrapper for the v1.1 API
5
+ *
6
+ * PHP version 5.3.10
7
+ *
8
+ * @category Awesomeness
9
+ * @package Twitter-API-PHP
10
+ * @author James Mallison <me@j7mbo.co.uk>
11
+ * @license MIT License
12
+ * @link http://github.com/j7mbo/twitter-api-php
13
+ */
14
+ class TwitterAPIExchange
15
+ {
16
+ private $oauth_access_token;
17
+ private $oauth_access_token_secret;
18
+ private $consumer_key;
19
+ private $consumer_secret;
20
+ private $postfields;
21
+ private $getfield;
22
+ protected $oauth;
23
+ public $url;
24
+
25
+ /**
26
+ * Create the API access object. Requires an array of settings::
27
+ * oauth access token, oauth access token secret, consumer key, consumer secret
28
+ * These are all available by creating your own application on dev.twitter.com
29
+ * Requires the cURL library
30
+ *
31
+ * @param array $settings
32
+ */
33
+ public function __construct(array $settings)
34
+ {
35
+ if (!in_array('curl', get_loaded_extensions()))
36
+ {
37
+ throw new Exception('You need to install cURL, see: http://curl.haxx.se/docs/install.html');
38
+ }
39
+
40
+ if (!isset($settings['oauth_access_token'])
41
+ || !isset($settings['oauth_access_token_secret'])
42
+ || !isset($settings['consumer_key'])
43
+ || !isset($settings['consumer_secret']))
44
+ {
45
+ throw new Exception('Make sure you are passing in the correct parameters');
46
+ }
47
+
48
+ $this->oauth_access_token = $settings['oauth_access_token'];
49
+ $this->oauth_access_token_secret = $settings['oauth_access_token_secret'];
50
+ $this->consumer_key = $settings['consumer_key'];
51
+ $this->consumer_secret = $settings['consumer_secret'];
52
+ }
53
+
54
+ /**
55
+ * Set postfields array, example: array('screen_name' => 'J7mbo')
56
+ *
57
+ * @param array $array Array of parameters to send to API
58
+ *
59
+ * @return TwitterAPIExchange Instance of self for method chaining
60
+ */
61
+ public function setPostfields(array $array)
62
+ {
63
+ if (!is_null($this->getGetfield()))
64
+ {
65
+ throw new Exception('You can only choose get OR post fields.');
66
+ }
67
+
68
+ if (isset($array['status']) && substr($array['status'], 0, 1) === '@')
69
+ {
70
+ $array['status'] = sprintf("\0%s", $array['status']);
71
+ }
72
+
73
+ $this->postfields = $array;
74
+
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Set getfield string, example: '?screen_name=J7mbo'
80
+ *
81
+ * @param string $string Get key and value pairs as string
82
+ *
83
+ * @return \TwitterAPIExchange Instance of self for method chaining
84
+ */
85
+ public function setGetfield($string)
86
+ {
87
+ if (!is_null($this->getPostfields()))
88
+ {
89
+ throw new Exception('You can only choose get OR post fields.');
90
+ }
91
+
92
+ $search = array('#', ',', '+', ':');
93
+ $replace = array('%23', '%2C', '%2B', '%3A');
94
+ $string = str_replace($search, $replace, $string);
95
+
96
+ $this->getfield = $string;
97
+
98
+ return $this;
99
+ }
100
+
101
+ /**
102
+ * Get getfield string (simple getter)
103
+ *
104
+ * @return string $this->getfields
105
+ */
106
+ public function getGetfield()
107
+ {
108
+ return $this->getfield;
109
+ }
110
+
111
+ /**
112
+ * Get postfields array (simple getter)
113
+ *
114
+ * @return array $this->postfields
115
+ */
116
+ public function getPostfields()
117
+ {
118
+ return $this->postfields;
119
+ }
120
+
121
+ /**
122
+ * Build the Oauth object using params set in construct and additionals
123
+ * passed to this method. For v1.1, see: https://dev.twitter.com/docs/api/1.1
124
+ *
125
+ * @param string $url The API url to use. Example: https://api.twitter.com/1.1/search/tweets.json
126
+ * @param string $requestMethod Either POST or GET
127
+ * @return \TwitterAPIExchange Instance of self for method chaining
128
+ */
129
+ public function buildOauth($url, $requestMethod)
130
+ {
131
+ if (!in_array(strtolower($requestMethod), array('post', 'get')))
132
+ {
133
+ throw new Exception('Request method must be either POST or GET');
134
+ }
135
+
136
+ $consumer_key = $this->consumer_key;
137
+ $consumer_secret = $this->consumer_secret;
138
+ $oauth_access_token = $this->oauth_access_token;
139
+ $oauth_access_token_secret = $this->oauth_access_token_secret;
140
+
141
+ $oauth = array(
142
+ 'oauth_consumer_key' => $consumer_key,
143
+ 'oauth_nonce' => time(),
144
+ 'oauth_signature_method' => 'HMAC-SHA1',
145
+ 'oauth_token' => $oauth_access_token,
146
+ 'oauth_timestamp' => time(),
147
+ 'oauth_version' => '1.0'
148
+ );
149
+
150
+ $getfield = $this->getGetfield();
151
+
152
+ if (!is_null($getfield))
153
+ {
154
+ $getfields = str_replace('?', '', explode('&', $getfield));
155
+ foreach ($getfields as $g)
156
+ {
157
+ $split = explode('=', $g);
158
+ $oauth[$split[0]] = $split[1];
159
+ }
160
+ }
161
+
162
+ $base_info = $this->buildBaseString($url, $requestMethod, $oauth);
163
+ $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
164
+ $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
165
+ $oauth['oauth_signature'] = $oauth_signature;
166
+
167
+ $this->url = $url;
168
+ $this->oauth = $oauth;
169
+
170
+ return $this;
171
+ }
172
+
173
+ /**
174
+ * Perform the actual data retrieval from the API
175
+ *
176
+ * @param boolean $return If true, returns data.
177
+ *
178
+ * @return string json If $return param is true, returns json data.
179
+ */
180
+ public function performRequest($return = true)
181
+ {
182
+ if (!is_bool($return))
183
+ {
184
+ throw new Exception('performRequest parameter must be true or false');
185
+ }
186
+
187
+ $header = array($this->buildAuthorizationHeader($this->oauth), 'Expect:');
188
+
189
+ $getfield = $this->getGetfield();
190
+ $postfields = $this->getPostfields();
191
+
192
+ $options = array(
193
+ CURLOPT_HTTPHEADER => $header,
194
+ CURLOPT_HEADER => false,
195
+ CURLOPT_URL => $this->url,
196
+ CURLOPT_RETURNTRANSFER => true,
197
+ CURLOPT_TIMEOUT => 10,
198
+ );
199
+
200
+ if (!is_null($postfields))
201
+ {
202
+ $options[CURLOPT_POSTFIELDS] = $postfields;
203
+ }
204
+ else
205
+ {
206
+ if ($getfield !== '')
207
+ {
208
+ $options[CURLOPT_URL] .= $getfield;
209
+ }
210
+ }
211
+
212
+ $feed = curl_init();
213
+ curl_setopt_array($feed, $options);
214
+ $json = curl_exec($feed);
215
+ curl_close($feed);
216
+
217
+ if ($return) { return $json; }
218
+ }
219
+
220
+ /**
221
+ * Private method to generate the base string used by cURL
222
+ *
223
+ * @param string $baseURI
224
+ * @param string $method
225
+ * @param array $params
226
+ *
227
+ * @return string Built base string
228
+ */
229
+ private function buildBaseString($baseURI, $method, $params)
230
+ {
231
+ $return = array();
232
+ ksort($params);
233
+
234
+ foreach($params as $key=>$value)
235
+ {
236
+ $return[] = "$key=" . $value;
237
+ }
238
+
239
+ return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $return));
240
+ }
241
+
242
+ /**
243
+ * Private method to generate authorization header used by cURL
244
+ *
245
+ * @param array $oauth Array of oauth data generated by buildOauth()
246
+ *
247
+ * @return string $return Header used by cURL for request
248
+ */
249
+ private function buildAuthorizationHeader($oauth)
250
+ {
251
+ $return = 'Authorization: OAuth ';
252
+ $values = array();
253
+
254
+ foreach($oauth as $key => $value)
255
+ {
256
+ $values[] = "$key=\"" . rawurlencode($value) . "\"";
257
+ }
258
+
259
+ $return .= implode(', ', $values);
260
+ return $return;
261
+ }
262
+
263
+ }
package.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Sparx_Tweets</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Show Latest Twitter Tweets on Magento site.</summary>
10
+ <description>Show Latest Twitter Tweets on Magento site.</description>
11
+ <notes>Able to disable and enable the extension from the admin end.&#xD;
12
+ Admin can choose whether to display the latest tweets in left or right sidebar of your magento site&#xD;
13
+ Admin can choose number of twitter feeds you want to display in the frontend.&#xD;
14
+ Able to choose using widget or auth 2</notes>
15
+ <authors><author><name>Bhoopendra Dwivedi</name><user>Sparx</user><email>bhoopendra.dwivedi@sparxtechnologies.com</email></author></authors>
16
+ <date>2014-06-11</date>
17
+ <time>06:41:17</time>
18
+ <contents><target name="magecommunity"><dir name="Sparx"><dir name="Tweets"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><file name="Implementcode.php" hash="84b51fcbd4a9bcf7506cfebdd1faace8"/></dir></dir></dir><file name="Tweets.php" hash="c8a7e4d164d6861dbcbf64dc3d75dd25"/></dir><dir name="Helper"><file name="Data.php" hash="47e6c144c7b89fe4ac0aef2c786c6426"/></dir><dir name="Model"><file name="Feed.php" hash="422e872b1f0a5f3f6debc92c21bb4bfa"/><dir name="Source"><file name="Position.php" hash="6a1df8d78a0c6a37e16185a6de6b3cf7"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="fc493c9ac08bc7b459a7b0f6887d6865"/></dir><dir name="etc"><file name="adminhtml.xml" hash="eb6d7ddd3448c44022b681537039eed7"/><file name="config.xml" hash="99a3607ce13755d859a6322456008f99"/><file name="system.xml" hash="ae17b163a028740b598eb56486db206b"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="tweets"><file name="left.phtml" hash="0cdbe111102c27cd48f0dc98b3d09772"/><file name="right.phtml" hash="68a7aefea38959f097ba1b1244631709"/><file name="tweets.phtml" hash="92d93aad5dc20048e775ee7889b5e747"/></dir></dir><dir name="layout"><file name="tweets.xml" hash=""/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sparx_Tweets.xml" hash="b26bb9df9954f64b6b84f53c0d947321"/></dir></target><target name="magelib"><dir name="twitteroauth"><file name="TwitterAPIExchange.php" hash="caa63a6be18f79d81f6cf28dbeec45db"/></dir></target></contents>
19
+ <compatible/>
20
+ <dependencies><required><php><min>5.0.1</min><max>6.0.0</max></php></required></dependencies>
21
+ </package>