Page 1 of 1

How to show your most recent Twitter tweets on your site

Posted: Sun Jul 05, 2009 12:39 pm
by Simon66
I just finished styling the twitter plugin by Nils Haack and I thought I'd share it.

This is what it looks like:
Image

To do this first upload function.nh_essentials.php and function.nh_api_twitteruser.php to the plugins folder.
These can be found in the forge.
(Look in function.nh_api_twitteruser.php and remove

Code: Select all

echo $rest;
from line 20 if it's there.

There are two images used in the example above:
The arrows - Image
The Twitter logo - Image

Here they are as Fireworks PNGs with transparent backgrounds:
The arrows - Image
The Twitter logo - Image

Next insert this in your template or GCB and change "CaffeineNews" to your Twitter username:

Code: Select all

{* Start Twitter *}
{nh_essentials}
{nh_api_twitteruser name="CaffeineNews" date_format="%a, %d-%b-%g @ %R"}
<div id="tweetbox">
<div id="twit_header">
<div id="twit_icon"><img src="{$tweets[0]->user->image}" alt="twittericon" /></div>
<span id="twit_user">{$tweets[0]->user->screenname}</span>
<span id="twit_followers">Followers: {$tweets[0]->user->followers}</span>
<span id="twit_page"><a href="http://twitter.com/{$tweets[0]->user->screenname}" title="Follow us on Twitter" target="_blank">Follow us on Twitter</a></span>
</div>
<div id="tweets">
{section name="i" start=1 loop=5 step=1}
{assign var=pointer value=$smarty.section.i.index-1}
<div class="onetweet">
<!--[if gt IE 7]><!-->
{* Curved corners are thanks to Stu Nicholls at http://www.cssplay.co.uk/boxes/curves.html  *}
<em id="ctl"><b>•</b></em>
<em id="cbl"><b>•</b></em>
<em id="ctr"><b>•</b></em>
<em id="cbr"><b>•</b></em>
<!--<![endif]-->
<p>
<a class="tweet_text" href="http://twitter.com/{$tweets[$pointer]->user->screenname}/statuses/{$tweets[$pointer]->id}" title="open in twitter" target="_blank">{$tweets[$pointer]->text}</a><br />
<span class="tweet_date">{$tweets[$pointer]->timestamp}</span>
<a class="tweet_reply" title="reply to {$tweets[$pointer]->user->screenname}" href="http://twitter.com/home?status=@{$tweets[$pointer]->user->screenname}%20&in_reply_to_status_id={$tweets[$pointer]->id}&in_reply_to={$tweets[$pointer]->user->screenname}"  target="_blank"></a>
</p>
</div>
{/section}
</div>
<div id="twitter_logo"></div>
</div>
{* End Twitter *}
Finally, create a new stylesheet with this in it and link it to your template:

Code: Select all

#tweetbox {
	background-color: #3C2415;
	padding: 5px 0px;
}
#twit_header {
	font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
	margin: 0px 5px 5px 0px;
	height: 48px;
	width: 100%;
}
#twit_icon {
	float: left;
	padding: 0px 5px;
}
#twit_user {
	font-size: 20px;
	color: #D3DD19;
	display: block;
}
#twit_followers {
	font-size: 14px;
	color: #BC3E23;
	display: block;
	padding-top: 4px;
}
#twit_page {
	display: block;
}
#twit_page a {
	font-size: 14px;
	text-decoration: none;
	color: #D3DD19;
	outline: none;
}
#twit_page a:hover {
	color: #BC3E23;
}
#tweets {
}
.onetweet {
	color:#3C2415; 
	position:relative;
	background-color: #DAE118;
	margin:5px;
}
#ctl, #cbl, #ctr, #cbr {position:absolute; width:8px; height:8px; color:#DAE118; background:#3C2415; overflow:hidden; font-style:normal; z-index:1;}
#ctl {top:0; left:0;}
#cbl {bottom:0; left:0;}
#ctr {top:0; right:0;}
#cbr {bottom:0; right:0;}
.onetweet em b {position:absolute; font-size:60px; font-family:arial; color:#DAE118; line-height:19px; font-weight:normal;}
#ctl b {left:-3px; top:-1px;}
#ctr b {left:-10px; top:-1px;}
#cbl b {left:-3px; top:-8px;}
#cbr b {left:-10px; top:-8px;}
.onetweet p {
	position:relative;
	z-index:100;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	line-height: 12px;
	margin: 5px;
	padding: 3px 0px;
}
.onetweet p a {
	text-decoration: none;
	color: #912C20;
	outline: none;
}
.onetweet p a:hover {
	text-decoration: none;
	color: #82941B;
}
.tweet_date {
	font-size: 10px;
	font-style: italic;
	font-weight: bold;
}
a.tweet_reply {
	background-image: url(/images/cms/replyarrow.png);
	background-repeat: no-repeat;
	background-position: left top;
	height: 12px;
	width: 7px;
	display: block;
	position: absolute;
	right: 5px;
	bottom: 2px;
	outline: none;
}
a.tweet_reply:hover {
	background-position: right top;
}
#twitter_logo {
	text-align: right;
	margin: 10px 5px 5px 5px;
	background-image: url(/images/cms/twitter_logo.png);
	background-repeat: no-repeat;
	background-position: right center;
	height: 16px;
}
That should be everything.
Hope you like it.
Simon66

Re: How to show your most recent Twitter tweets on your site

Posted: Wed Sep 09, 2009 9:18 am
by voxberry
will try this and post results . nice work mate ;)

peace!

Re: How to show your most recent Twitter tweets on your site

Posted: Mon Sep 14, 2009 8:06 am
by voxberry
Hello .

The files can be downloaded here :

http://dev.cmsmadesimple.org/project/files/604

. And yes, it get's the job done :) ..

peace !

PROBLEM WITH THIS

Posted: Tue Sep 15, 2009 1:41 pm
by voxberry
Hello .
I have a real problem with this and I do not know why .

I was just working on some css of the site (cmsms 1.6) and BANG! the error .
I do not get the twwets anymore ... i get this error message :

Warning: simplexml_load_file() [function.simplexml-load-file]: in \plugins\function.nh_essentials.php on line 56

somehow it has a big problem with a file in the cache dir .


any help with this ? thanks .

Re: How to show your most recent Twitter tweets on your site

Posted: Tue Oct 06, 2009 3:39 am
by FabianDM
Hello,
first off thanks for this - i used it for our site and its looking pretty good and you made it simple to follow.

I dont know if there have been updates since this post or if i have missed something but it seems that the twitter text links keep leading to an invalid page no matter what twitter username i put in - it goes to http://twitter.com/TravelCTM/statuses/2147483647
and that ID seems invalid.

Any help would be greatly appreciated.

Re: How to show your most recent Twitter tweets on your site

Posted: Thu Dec 03, 2009 7:06 pm
by netzmelone
I dont know if there have been updates since this post or if i have missed something but it seems that the twitter text links keep leading to an invalid page no matter what twitter username i put in - it goes to http://twitter.com/TravelCTM/statuses/2147483647
and that ID seems invalid.
There is an error in the function.nh_api_twitteruser.php in line 36:

Code: Select all

$tweet->id = (integer)$item->id;
should be

Code: Select all

$tweet->id = (string)$item->id;
just change that and it works like a charm.

cheers

Re: How to show your most recent Twitter tweets on your site

Posted: Fri Dec 04, 2009 7:59 am
by netzmelone
I forgot one more thing:
there is also an error in the template.

Code: Select all

<a class="tweet_text" href="http://twitter.com/{$tweets[$pointer]->user->screenname}/statuses/{$tweets[$pointer]->id}" title="open in twitter" target="_blank">{$tweets[$pointer]->text}</a>
should be

Code: Select all

<a class="tweet_text" href="http://twitter.com/{$tweets[$pointer]->user->screenname}/status/{$tweets[$pointer]->id}" title="open in twitter" target="_blank">{$tweets[$pointer]->text}</a>
ater these two changes the URL will be displayed correctly.

cheers

Re: How to show your most recent Twitter tweets on your site

Posted: Mon Jul 26, 2010 10:04 pm
by SCJCR
Hi, I've got the style sheet to load but above the twitter box I get.
Warning: file_get_contents(http://twitter.com/statuses/user_timeli ... =10&page=1): failed to open stream: Connection timed out in /home/hudson/misc/dcd8jcr/public_html/plugins/function.nh_essentials.php on line 46 Warning: simplexml_load_file(): I/O warning : failed to load external entity "tmp/cache//twu_publictimeline_StChadsJCR_10_1.xml" in /home/hudson/misc/dcd8jcr/public_html/plugins/function.nh_essentials.php on line 56 Warning: filemtime(): stat failed for tmp/cache//twu_publictimeline_StChadsJCR_10_1.xml in /home/hudson/misc/dcd8jcr/public_html/plugins/function.nh_essentials.php on line 57
I've cleared the cache and that hasn't helped, any suggestions? I would be very grateful.

Re: How to show your most recent Twitter tweets on your site

Posted: Tue Jul 27, 2010 5:06 pm
by Dr.CSS
It seems to have picked up an extra / somewhere...

"tmp/cache//twu_publictimeline_StChadsJCR_10_1.xml"

Re: How to show your most recent Twitter tweets on your site

Posted: Thu Jul 29, 2010 2:16 pm
by SCJCR
Dr.CSS wrote: It seems to have picked up an extra / somewhere...

"tmp/cache//twu_publictimeline_StChadsJCR_10_1.xml"
Any idea where about the error occurred? I've searched the files and code for any // and I cant find any.

EDIT

I got rid of the extra slash but no help
Warning: file_get_contents(http://twitter.com/statuses/user_timeli ... =10&page=1): failed to open stream: Connection timed out in /home/hudson/misc/dcd8jcr/public_html/plugins/function.nh_essentials.php on line 46 Warning: simplexml_load_file(): I/O warning : failed to load external entity "tmp/cache/twu_publictimeline_StChadsJCR_10_1.xml" in /home/hudson/misc/dcd8jcr/public_html/plugins/function.nh_essentials.php on line 56 Warning: filemtime(): stat failed for tmp/cache/twu_publictimeline_StChadsJCR_10_1.xml in /home/hudson/misc/dcd8jcr/public_html/plugins/function.nh_essentials.php on line 57
I physically saved the twitter xml to the cache so its showing the feeds but its not going to update itself, it must be a problem with saving the twitter not finding it in the cache