Creare_Latesttweet - Version 1.0.0

Version Notes

First Release

Download this release

Release Info

Developer Magento Core Team
Extension Creare_Latesttweet
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Creare/Latesttweet/Block/Latesttweet.php ADDED
@@ -0,0 +1,164 @@
1
+ <?php
2
+
3
+ class Creare_Latesttweet_Block_Latesttweet extends Mage_Core_Block_Template
4
+ {
5
+ public function _prepareLayout()
6
+ {
7
+ return parent::_prepareLayout();
8
+ }
9
+
10
+ public function isEnabled()
11
+ {
12
+ if(Mage::getStoreConfig('latesttweet/latesttweet/active')){
13
+ return true;
14
+ } else {
15
+ return false;
16
+ }
17
+ }
18
+
19
+ public function getTwitterId()
20
+ {
21
+ $twitterid = Mage::getStoreConfig('latesttweet/latesttweet/twitterid');
22
+ return $twitterid;
23
+ }
24
+
25
+ public function getNoFollow()
26
+ {
27
+ $nofollow = Mage::getStoreConfig('latesttweet/latesttweet/usenofollow');
28
+ return $nofollow;
29
+ }
30
+
31
+ public function getNumberOfTweets()
32
+ {
33
+ $numberoftweets = Mage::getStoreConfig('latesttweet/latesttweet/numberoftweets');
34
+ return $numberoftweets;
35
+ }
36
+
37
+ public function getTagPref()
38
+ {
39
+ $tagpref = Mage::getStoreConfig('latesttweet/latesttweet/showlinks');
40
+ return $tagpref;
41
+ }
42
+
43
+ public function getNewWindow()
44
+ {
45
+ $tagpref = Mage::getStoreConfig('latesttweet/latesttweet/opennew');
46
+ return $tagpref;
47
+ }
48
+
49
+ private function getTweetData($tweetxml)
50
+ {
51
+
52
+ $xmlDoc = new DOMDocument();
53
+ $xmlDoc->load($tweetxml);
54
+
55
+ $x = $xmlDoc->getElementsByTagName("entry"); // get all entries
56
+ $tweets = array();
57
+ foreach($x as $item){
58
+ $tweet = array();
59
+
60
+ if($item->childNodes->length) {
61
+ foreach($item->childNodes as $i){
62
+ $tweet[$i->nodeName] = $i->nodeValue;
63
+ }
64
+ }
65
+ $tweets[] = $tweet;
66
+ }
67
+
68
+ return $tweets;
69
+ }
70
+
71
+ private function cleanTwitterName($twitterid)
72
+ {
73
+ $test = substr($twitterid,0,1);
74
+
75
+ if($test == "@"){
76
+ $twitterid = substr($twitterid,1);
77
+ }
78
+
79
+ return $twitterid;
80
+
81
+ }
82
+
83
+ private function changeLink($string, $tags=true, $nofollow=true, $newwindow=true)
84
+ {
85
+ if(!$tags){
86
+ $string = strip_tags($string);
87
+ }
88
+ if($nofollow){
89
+ $string = str_replace('<a ','<a rel="nofollow"', $string);
90
+ }
91
+ if($newwindow){
92
+ $string = str_replace('<a ','<a target="_blank"', $string);
93
+ }
94
+ return $string;
95
+ }
96
+
97
+ private function getTweetArray($tweets)
98
+ {
99
+
100
+ $data = array();
101
+
102
+ if(empty($tweets)) {
103
+ return false;
104
+ }
105
+ for($i=0;$i<count($tweets);$i++){
106
+ $tweettag = $tweets[$i];
107
+ /********************** Getting Times (Hours/Minutes/Days) */
108
+ $tweetdate = $tweettag["published"];
109
+ $tweet = $tweettag["content"];
110
+ $timedate = explode("T",$tweetdate);
111
+ $date = $timedate[0];
112
+ $time = substr($timedate[1],0, -1);
113
+ $tweettime = (strtotime($date." ".$time))+3600; // This is the value of the time difference - UK + 1 hours (3600 seconds)
114
+ $nowtime = time();
115
+ $timeago = ($nowtime-$tweettime);
116
+ $thehours = floor($timeago/3600);
117
+ $theminutes = floor($timeago/60);
118
+ $thedays = floor($timeago/86400);
119
+ /********************* Checking the times and returning correct value */
120
+ if($theminutes < 60){
121
+ if($theminutes < 1){
122
+ $timemessage = "Less than 1 minute ago";
123
+ } else if($theminutes == 1) {
124
+ $timemessage = $theminutes." minute ago";
125
+ } else {
126
+ $timemessage = $theminutes." minutes ago";
127
+ }
128
+ } else if($theminutes > 60 && $thedays < 1){
129
+ if($thehours == 1){
130
+ $timemessage = $thehours." hour ago";
131
+ } else {
132
+ $timemessage = $thehours." hours ago";
133
+ }
134
+ } else {
135
+ if($thedays == 1){
136
+ $timemessage = $thedays." day ago";
137
+ } else {
138
+ $timemessage = $thedays." days ago";
139
+ }
140
+ }
141
+ $data[$i]["tweet"] = $this->changeLink($tweet, $this->getTagPref(), $this->getNoFollow(), $this->getNewWindow());
142
+ $data[$i]["time"] = $timemessage;
143
+ }
144
+
145
+ return $data;
146
+ }
147
+
148
+ public function getLatestTweets()
149
+ {
150
+
151
+ $twitterid = $this->getTwitterId();
152
+ $not = $this->getNumberOfTweets();
153
+
154
+ if (!$twitterid){
155
+ return false;
156
+ }
157
+
158
+ $twitterid = $this->cleanTwitterName($twitterid);
159
+ $tweetxml = "http://search.twitter.com/search.atom?q=from:" . $twitterid . "&rpp=" . $not . "";
160
+ $tweets = $this->getTweetData($tweetxml);
161
+ return($this->getTweetArray($tweets));
162
+
163
+ }
164
+ }
app/code/local/Creare/Latesttweet/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
1
+ <?php
2
+
3
+ class Creare_Latesttweet_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Creare/Latesttweet/Model/Adminhtml/System/Config/Source/Numbers.php ADDED
@@ -0,0 +1,13 @@
1
+ <?php
2
+ class Creare_Latesttweet_Model_Adminhtml_System_Config_Source_Numbers
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ $array = array();
7
+ for($i = 1; $i<=10; $i++)
8
+ {
9
+ $array[] = array('value'=>$i, 'label'=>ucfirst($i));
10
+ }
11
+ return $array;
12
+ }
13
+ }
app/code/local/Creare/Latesttweet/etc/config.xml ADDED
@@ -0,0 +1,108 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Creare
5
+ * @package Creare_Latesttweet
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Creare_Latesttweet>
12
+ <version>0.1.0</version>
13
+ </Creare_Latesttweet>
14
+ </modules>
15
+ <frontend>
16
+ <layout>
17
+ <updates>
18
+ <latesttweet>
19
+ <file>latesttweet.xml</file>
20
+ </latesttweet>
21
+ </updates>
22
+ </layout>
23
+ </frontend>
24
+ <adminhtml>
25
+ <layout>
26
+ <updates>
27
+ <latesttweet>
28
+ <file>latesttweet.xml</file>
29
+ </latesttweet>
30
+ </updates>
31
+ </layout>
32
+ </adminhtml>
33
+ <global>
34
+ <models>
35
+ <latesttweet>
36
+ <class>Creare_Latesttweet_Model</class>
37
+ <resourceModel>latesttweet_mysql4</resourceModel>
38
+ </latesttweet>
39
+ <latesttweet_adminhtml>
40
+ <class>Creare_Latesttweet_Model_Adminhtml</class>
41
+ </latesttweet_adminhtml>
42
+ <latesttweet_mysql4>
43
+ <class>Creare_Latesttweet_Model_Mysql4</class>
44
+ <entities>
45
+ <latesttweet>
46
+ <table>latesttweet</table>
47
+ </latesttweet>
48
+ </entities>
49
+ </latesttweet_mysql4>
50
+ </models>
51
+ <resources>
52
+ <creare_latesttweet_setup>
53
+ <setup>
54
+ <module>Creare_Latesttweet</module>
55
+ </setup>
56
+ <connection>
57
+ <use>core_setup</use>
58
+ </connection>
59
+ </creare_latesttweet_setup>
60
+ </resources>
61
+ <blocks>
62
+ <latesttweet>
63
+ <class>Creare_Latesttweet_Block</class>
64
+ </latesttweet>
65
+ </blocks>
66
+ <helpers>
67
+ <latesttweet>
68
+ <class>Creare_Latesttweet_Helper</class>
69
+ </latesttweet>
70
+ </helpers>
71
+ </global>
72
+ <default>
73
+ <latesttweet>
74
+ <latesttweet>
75
+ <active>1</active>
76
+ <twitterid>magentofox</twitterid>
77
+ <numberoftweets>1</numberoftweets>
78
+ <showlinks>1</showlinks>
79
+ <usenofollow>1</usenofollow>
80
+ <opennew>1</opennew>
81
+ </latesttweet>
82
+ </latesttweet>
83
+ </default>
84
+ <adminhtml>
85
+ <acl>
86
+ <resources>
87
+ <all>
88
+ <title>Allow Everything</title>
89
+ </all>
90
+ <admin>
91
+ <children>
92
+ <system>
93
+ <children>
94
+ <config>
95
+ <children>
96
+ <latesttweet>
97
+ <title>CreareGroup - All</title>
98
+ </latesttweet>
99
+ </children>
100
+ </config>
101
+ </children>
102
+ </system>
103
+ </children>
104
+ </admin>
105
+ </resources>
106
+ </acl>
107
+ </adminhtml>
108
+ </config>
app/code/local/Creare/Latesttweet/etc/system.xml ADDED
@@ -0,0 +1,90 @@
1
+ <config>
2
+ <tabs>
3
+ <creare translate="label" module="latesttweet">
4
+ <label>CreareGroup</label>
5
+ <sort_order>100</sort_order>
6
+ </creare>
7
+ </tabs>
8
+ <sections>
9
+ <latesttweet translate="label" module="latesttweet">
10
+ <label>Latest Tweet</label>
11
+ <tab>creare</tab>
12
+ <sort_order>1000</sort_order>
13
+ <show_in_default>1</show_in_default>
14
+ <show_in_website>1</show_in_website>
15
+ <show_in_store>1</show_in_store>
16
+ <groups>
17
+ <latesttweet translate="label" module="latesttweet">
18
+ <label>Latest Tweet</label>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>1000</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <comment>
25
+ <![CDATA[<div class="creare-container">
26
+ <div class="creare-header">This module was developed by <a href="http://www.e-commercewebdesign.co.uk" target="_blank">www.e-commercewebdesign.co.uk</a> - <strong>Magento Design, Development &amp; Extensions</strong>.</div>
27
+ <div class="creare-footer"><a href="http://www.e-commercewebdesign.co.uk" class="ecom-creare" target="_blank" title="E-Commerce Web Design"><span>E-Commerce Web Design</span></a> <a href="http://www.webdesigncreare.co.uk" class="web-creare" target="_blank" title="Web Design &amp; Development"><span>Web Design &amp; Development</span></a> <a href="http://www.seo-creare.co.uk" class="seo-creare" target="_blank" title="SEO &amp; Internet Marketing"><span>SEO (Search Engine Optimisation)</span></a> <span class="uk-flag"><span>Based In The UK</span></span></div>
28
+ </div>
29
+ <div class="creare-clear"></div>]]>
30
+ </comment>
31
+ <fields>
32
+ <active translate="label">
33
+ <label>Enabled</label>
34
+ <frontend_type>select</frontend_type>
35
+ <source_model>adminhtml/system_config_source_yesno</source_model>
36
+ <sort_order>10</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ </active>
41
+ <twitterid translate="label">
42
+ <label>Twitter ID</label>
43
+ <frontend_type>text</frontend_type>
44
+ <sort_order>20</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ </twitterid>
49
+ <numberoftweets translate="label">
50
+ <label>Number of Tweets to show</label>
51
+ <frontend_type>select</frontend_type>
52
+ <source_model>latesttweet_adminhtml/system_config_source_numbers</source_model>
53
+ <sort_order>30</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>1</show_in_store>
57
+ </numberoftweets>
58
+ <showlinks translate="label">
59
+ <label>Show Links In Tweet</label>
60
+ <frontend_type>select</frontend_type>
61
+ <source_model>adminhtml/system_config_source_yesno</source_model>
62
+ <sort_order>40</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </showlinks>
67
+ <usenofollow translate="label">
68
+ <label>Use Nofollow tag in Links</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>adminhtml/system_config_source_yesno</source_model>
71
+ <sort_order>50</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ </usenofollow>
76
+ <opennew translate="label">
77
+ <label>Open In New Window</label>
78
+ <frontend_type>select</frontend_type>
79
+ <source_model>adminhtml/system_config_source_yesno</source_model>
80
+ <sort_order>60</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ </opennew>
85
+ </fields>
86
+ </latesttweet>
87
+ </groups>
88
+ </latesttweet>
89
+ </sections>
90
+ </config>
app/design/frontend/default/default/layout/latesttweet.xml ADDED
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <action method="addCss"><stylesheet>css/latesttweet.css</stylesheet></action>
6
+ </reference>
7
+
8
+ <reference name="right">
9
+ <block type="latesttweet/latesttweet" name="latesttweet" before="-" template="latesttweet/tweet.phtml" />
10
+ </reference>
11
+ </default>
12
+ </layout>
app/design/frontend/default/default/template/latesttweet/tweet.phtml ADDED
@@ -0,0 +1,26 @@
1
+ <?php
2
+ /*
3
+ * Latest Tweet Extension by E-Commerce Web Design (http://www.e-commercewebdesign.co.uk)
4
+ *
5
+ *
6
+ */
7
+ ?>
8
+ <?php if($this->isEnabled() && $tweets = $this->getLatestTweets()): ?>
9
+ <div class="block">
10
+ <div class="block-title creare-tweet-bg">
11
+ <strong>
12
+ <span class="creare-tweet-title">Latest Tweet</span>
13
+ </strong>
14
+ </div>
15
+ <div class="block-content">
16
+ <ul class="creare-tweet">
17
+ <?php foreach($tweets as $tweet): ?>
18
+ <li>
19
+ <?php echo $tweet["tweet"]; ?>
20
+ <span><?php echo $tweet["time"]; ?></span>
21
+ </li>
22
+ <?php endforeach; ?>
23
+ </ul>
24
+ </div>
25
+ </div>
26
+ <?php endif; ?>
app/etc/modules/Creare_Latesttweet.xml ADDED
@@ -0,0 +1,8 @@
1
+ <config>
2
+ <modules>
3
+ <Creare_Latesttweet>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </Creare_Latesttweet>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Creare_Latesttweet</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Get Latest Tweet from Twitter. Choose whether to show links, open links in new window, make all links nofollow.</summary>
10
+ <description>Get Latest Tweet from Twitter. Choose whether to show links, open links in new window, make all links nofollow.&#xD;
11
+ &#xD;
12
+ Select to show up to 10 tweets. Visible in your side menu.</description>
13
+ <notes>First Release</notes>
14
+ <authors><author><name>E-Commerce Web Design</name><user>auto-converted</user><email>dev@e-commercewebdesign.co.uk</email></author></authors>
15
+ <date>2012-02-16</date>
16
+ <time>10:04:50</time>
17
+ <contents><target name="magelocal"><dir name="Creare"><dir name="Latesttweet"><dir name="Block"><file name="Latesttweet.php" hash="37613ce0191e3b9d410ff833a98977a5"/></dir><dir name="Helper"><file name="Data.php" hash="42e5c15537debb7f1c46890ee9dbd559"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="Numbers.php" hash="3a2ee4bf798c5f9e10ad8f8637fe26a5"/></dir></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="39481474924477af89890d26514f1e8e"/><file name="system.xml" hash="e2b8fe2b3ae892142ece4c1ac0a8bf9e"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="latesttweet"><file name="tweet.phtml" hash="f3d4b1d71b87d734b54a337935d30231"/></dir></dir><dir name="layout"><file name="latesttweet.xml" hash="4dbedfcb997d97bb6fe6ee21893d50f9"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Creare_Latesttweet.xml" hash="43faaaf27bfb2437089157bdee2439a5"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="css"><file name="latesttweet.css" hash="304864cf8d286bf77047432de5c19cea"/></dir><dir name="images"><dir name="latesttweet"><file name="tweet.gif" hash="21edf03982dae158df166cdad0478f91"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="latesttweet"><file name="admin.css" hash="790b7a705efea5b2f7d2f6e657244706"/></dir></dir></dir></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies/>
20
+ </package>
skin/adminhtml/default/default/latesttweet/admin.css ADDED
@@ -0,0 +1,12 @@
1
+ /* CSS Document */
2
+ .creare-header { width: 100%; }
3
+ .creare-footer { width: 100%; padding: 10px 0 0; clear: both; }
4
+ .creare-footer a span { display: none; }
5
+ .creare-footer a { display: block; float: left; margin-right: 5px; }
6
+ .creare-container { background-color:#fff;border:1px solid #CCC;padding:10px;margin-bottom:7px; height: 90px; }
7
+ .ecom-creare { background: url(images/creare-ecommerce.gif) no-repeat; width: 150px; height: 55px; }
8
+ .seo-creare { background: url(images/creare-seo.gif) no-repeat; width: 150px; height: 55px; }
9
+ .web-creare { background: url(images/creare-web.gif) no-repeat; width: 150px; height: 55px;}
10
+ .uk-flag { background: url(images/uk-flag.gif) no-repeat; width: 150px; height: 55px; display: block; float: left; }
11
+ .uk-flag span { display: none; }
12
+ .creare-clear { clear: both; }
skin/frontend/default/default/css/latesttweet.css ADDED
@@ -0,0 +1,5 @@
1
+ .creare-tweet-title { color: #33ccff!important; }
2
+ .creare-tweet-bg { background: url('../images/latesttweet/tweet.gif') top right no-repeat #F8F7F5!important; }
3
+ .creare-tweet { padding: 5px; }
4
+ .creare-tweet li { border-bottom: 1px bottom #bcbcbc; border-top: 1px solid #d5d5d5; padding: 5px 0; }
5
+ .creare-tweet li span { display: block; font-size: 0.8em; font-style:italic; }
skin/frontend/default/default/images/latesttweet/tweet.gif ADDED
Binary file