Skip to content

Commit

Permalink
Updating for Twitter API 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wilken committed Oct 15, 2012
1 parent fb42fff commit f01ba20
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
Binary file added Archive.zip
Binary file not shown.
27 changes: 12 additions & 15 deletions helper.php
Expand Up @@ -10,10 +10,10 @@

defined('_JEXEC') or die('Direct Access is forbidden, shame on you');

class modTweetsHelper
class modTweetsHelper
{

function getTweets($params)
function getTweets($params)
{
// Initialize variables and set defaults
$cache = dirname(__FILE__) . '/cache/';
Expand All @@ -26,21 +26,21 @@ function getTweets($params)
if ($quantity > 20 || $quantity < 0) {
$quantity = 5;
}

if ($type == 'search')
{
$tweetURL = 'http://search.twitter.com/search.json?q=' . $search . '&rpp=' . $quantity . '&result_type=recent';
$tweetURL = 'https://search.twitter.com/search.json?q=' . $search . '&rpp=' . $quantity . '&result_type=recent';
$cachefile = JFile::makeSafe($search) . '.json';
}
else
{
$tweetURL = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $user . '&count=' . $quantity;
$tweetURL = 'https://search.twitter.com/search.json?q=from:' . $user . '&rpp=' . $quantity . '&result_type=recent';
$cachefile = $user . '.json';
}
$cachepathfile = $cache . $cachefile;

// Check if cached version is uptodate or not
if (!file_exists($cachepathfile) || (time() - $cachetime) > filemtime($cachepathfile))
if (!file_exists($cachepathfile) || (time() - $cachetime) > filemtime($cachepathfile))
{
// If curl is enabled, use it
if (in_array('curl', get_loaded_extensions()))
Expand All @@ -55,15 +55,15 @@ function getTweets($params)
{
$file = @file_get_contents($tweetURL);
}

$tweets = json_decode($file);

if (!$file)
{
// Unable to download a file
$tweets->error = JText::_('MOD_TWEETS_ERROR_COULD_NOT_DOWNLOAD');
}

if (count($tweets) && !isset($tweets->error))
{
JFile::write($cachepathfile, $file);
Expand All @@ -81,11 +81,8 @@ function getTweets($params)
$file = JFile::read($cachepathfile);
$tweets = json_decode($file);
}

if ($type == 'search')
{
$tweets = $tweets->results;
}

$tweets = $tweets->results;

return $tweets;
}
Expand Down
4 changes: 2 additions & 2 deletions mod_tweets.xml
Expand Up @@ -7,7 +7,7 @@
<license>GNU GPL v.2</license>
<authorEmail>gnomation@gnomeontherun.com</authorEmail>
<authorUrl>http://www.gnomeontherun.com</authorUrl>
<version>2.0</version>
<version>2.0.1</version>
<description>A simple twitter module for Joomla, lets you style how you it should be displayed.</description>

<files>
Expand Down Expand Up @@ -46,7 +46,7 @@
<param name="aftertext" type="textarea" filter="raw" label="MOD_TWEETS_AFTER" description="MOD_TWEETS_AFTER_DESC" />
<param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="PARAMMODULECLASSSUFFIX" />
</params>

<config>
<fields name="params">
<fieldset name="basic">
Expand Down
20 changes: 10 additions & 10 deletions tmpl/default.php
Expand Up @@ -6,34 +6,34 @@

defined('_JEXEC') or die('Direct Access is forbidden, shame on you');

if (isset($tweets->error))
if (isset($tweets->error))
{
//echo "<div class=\"message\">" . $tweets->error . "</div>";
}
else
echo "<div class=\"message\">" . $tweets->error . "</div>";
}
else
{
$date = $params->get('date', 'ago');
$format = $params->get('format', 'd.m.y H\:m');
$format = $params->get('format', 'd.m.y H\:m');
?>

<div class="<?php echo htmlspecialchars($params->get('moduleclass_sfx')); ?>">

<?php if ($params->get('beforetext', '') !== '') :
?>
<div class="beforeTweets">
<?php print $params->get('beforetext', ''); ?>
</div>
<?php endif; ?>
<ul class="tweets">
<?php foreach ($tweets as $tweet) :
<?php foreach ($tweets as $tweet) :
$tweet->text = preg_replace('#[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]#', '<a href=\'\\0\'>\\0</a>', $tweet->text);
$tweet->text = preg_replace('/@(.+?)\b/', "<a href=\"https://twitter.com/#!/$1\">@$1</a>", $tweet->text);
$tweet->screen_name = (isset($tweet->user->screen_name)) ? $tweet->user->screen_name : $tweet->from_user;
?>
<li>
<span class="tweet_author"><a href="https://twitter.com/#!/<?php echo $tweet->screen_name; ?>">@<?php echo $tweet->screen_name; ?></a></span>:
<span class="tweet_author"><a href="https://twitter.com/#!/<?php echo $tweet->screen_name; ?>">@<?php echo $tweet->screen_name; ?></a></span>:
<?php echo $tweet->text; ?><br />
<span class="tweet_time"><?php echo modTweetsHelper::timeDifference(strtotime($tweet->created_at)); ?></span> -
<span class="tweet_time"><?php echo modTweetsHelper::timeDifference(strtotime($tweet->created_at)); ?></span> -
<a href="https://twitter.com/#!/<?php echo $tweet->screen_name; ?>/status/<?php echo $tweet->id_str; ?>"<?php echo ($params->get('linktype') == 'blank') ? ' target="_blank"' : ''; ?>><?php echo JText::_('MOD_TWEETS_VIEW'); ?> &raquo;</a></span>
</li>
<?php endforeach; ?>
Expand Down

0 comments on commit f01ba20

Please sign in to comment.