In the hierarchy of php developers, I am less than novice. I don't know squat about it. What I'm trying to do is install a module on my Joomla website for a Tweeter plug-in. When I enable the "mod" and display my page, I get:
Parse error: parse error, unexpected T_VARIABLE in /home/ [my website name]/public_html/joomla/modules/mod_tweetxt/helper.php on line 107
I had no idea what this meant, so I did my own research and discovered the problem has to do with a missing semi-colon. (Before asking help from others, I try to see if I can research and figure it out.) I counted down 107 lines and didn't see anything obvious; because I don't know what I'm looking for. Do you count the blank lines or just the lines of code? Either way, at 107 lines down, I see semi-colons. Obviously it must be missing somewhere around there. I tried comparing the IF logic elsewhere in the code to see if there is a pattern for entering the semi-colon. No luck figuring this out.
Could one of you folks help me find the error so I can fix this code so it will run? Here is the php code: (I hope that is the correct terminology. )
<?php
/**
* TweetXT for Joomla!
* @Copyright ((c) 2009 joomlaxt.com
* @ All rights reserved
* @ Released under GNU/GPL License : [url]http://www.gnu.org/copyleft/gpl.html[/url]
* @ [url]http://www.joomlaxt.com[/url]
* @version 0.09.05
**/
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
?>
<?php
class tweetXtHelper
{
function getLimit($params) {
$uname = $params->get("twitterName","");
$count = $params->get("twitterCount",3);
$url = "twitter.com";
$req = "/account/rate_limit_status/".$uname.".json?count=".$count."";
$fp = fsockopen ($url, 80, $errno, $errstr, 30);
if (!$fp || $errno) return $errstr;
@fputs($fp, "GET ".$req." HTTP/1.1\r\n");
@fputs($fp, "HOST: ".$url."\r\n");
@fputs($fp, "Connection: close\r\n\r\n");
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
fclose ($fp);
$obj = json_decode($res);
return $obj;
}
function getTweets($params)
{
$uname = $params->get("twitterName","");
$count = $params->get("twitterCount",3);
$url = "api.twitter.com";
// get 3 times the limit. That should ensure that the limit is reached even if there are some retweets (which will be filtered out by the API)
$xCount = 3 * $count;
$req = "/1/statuses/user_timeline/".$uname.".json?count=".$xCount."";
$fp = fsockopen ($url, 80, $errno, $errstr, 30);
if (!$fp || $errno) return $errstr;
@fputs($fp, "GET ".$req." HTTP/1.1\r\n");
@fputs($fp, "HOST: ".$url."\r\n");
@fputs($fp, "Connection: close\r\n\r\n");
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
fclose ($fp);
$obj = json_decode($res);
if (isset($obj->error)) return false;
// get user Info from first tweet
if (isset ($obj[0]))
$twitter->user = $obj[0]->user;
else
return false;
$i = 0;
// get the tweets
foreach ($obj as $o) {
foreach ($o as $k=>$v) {
if ($k != "user") {
$t->$k = $v;
}
}
$tweet[] = clone $t;
$i++;
if ($i == $count) break;
}
$twitter->tweets = $tweet;
$twitter = renderTwitter($twitter, $params);
return $twitter;
}
}
function renderTwitter($twitter, $params) {
// user
$twitter->user->image_html = "<img alt=\"".$twitter->user->screen_name."\"src=\"".$twitter->user->profile_image_url."\"/>";
$twitter->user->image_html = "<img alt=\"".$twitter->user->screen_name."\"src=\"".$twitter->user->profile_image_url."\" width=\"".$params->get("userImgSize", 73)."px\"/>";
$twitter->user->twitter_link = "<a href=\"http://twitter.com/".$twitter->user->screen_name."\">".$twitter->user->screen_name."</a>";
$twitter->user->web_link = "<a href=\"".$twitter->user->url."\">".$twitter->user->url."</a>";
// tweets
foreach ($twitter->tweets as $t) {
if ($params->get("relativeTime", 1) == 1) {
$t->created_html = "<a href=\"http://twitter.com/".$twitter->user->screen_name."/status/".$t->id."\">".getRelativeTime($t->created_at)."</a>";
}
else {
$t->created_html = "<a href=\"http://twitter.com/".$twitter->user->screen_name."/status/".$t->id."\">".JHTML::date($t->created_at)."</a>";
}
if (($params->get("showSource", 1) == 1)) {
$t->created_html .= " from ".$t->source;
}
$t->image_html = "<img align=\"left\" alt=\"".$twitter->user->screen_name."\"src=\"".$twitter->user->profile_image_url."\" width=\"".$params->get("tweetImgSize", 32)."px\"/>";
$t->text_html = preg_replace("/(http:\/\/[^\s]+)/", "<a href=\"$1\">$1</a>", $t->text);
}
return $twitter;
}
function getRelativeTime($date) {
$diff = time() - strtotime($date);
if ($diff<60)
return JText::sprintf("SECONDS AGO", $diff);
$diff = round($diff/60);
if ($diff<2)
return JText::_("ABOUT A MINUTE AGO");
if ($diff<60)
return JText::sprintf("MINUTES AGO", $diff);
$diff = round($diff/60);
if ($diff<2)
return JText::_("ABOUT AN HOUR AGO");
if ($diff<24)
return JText::sprintf("HOURS AGO", $diff);
$diff = round($diff/24);
if ($diff<2)
return JText::_("ABOUT A DAY AGO");
if ($diff<7)
return JText::sprintf("DAYS AGO", $diff);
$diff = round($diff/7);
if ($diff<2)
return JText::_("ABOUT A WEEK AGO");
if ($diff<4)
return JText::sprintf("WEEKS AGO", $diff);
return JHTML::date($date);
}