Viewing 15 replies - 1 through 15 (of 15 total)
  • *bump*

    Is there no answer to this problem? The same thing’s happened to my widget.

    Thread Starter jazfotodesign

    (@jazfotodesign)

    Never figured it out, ended using Advanced Twitter Widget works nicely.. http://jazsheen.com/about/

    Resolved? Same problem with the Years Ago… Seems there is a major lack of support for this plugin.

    Thread Starter jazfotodesign

    (@jazfotodesign)

    Not resolved, see above post… I just mark resolved to keep my forum posts organized… sorry >.<

    Hi – I had the same problem (all timestamps on tweets were showing up as 41 years ago) and here is how I fixed it along with the explanation.

    (referencing version 1.0.5)
    Line 175 is the culprit — seems that twitter api returns dates in this format:

    Tue Dec 28 15:05:27 +0000 2010

    which makes the php call to strtotime() fail, returning a -1. This value is then being passed to the function wpcom_time_since() (which subtracts currentTime – timeOfTweet to figure elapsed time) and treated as a valid UNIX timestamp. Interestingly, since a unix timestamp is the number of seconds since Jan 01 1970, the -1 registers as the second before the stroke of midnight on Dec 31, 1969, making the “41 years ago” (strictly speaking) correct.

    Turns out (perhaps having something to do with the version of PHP on my server since not everyone is having this problem), strtotime() doesn’t like the +0000 in the twitter return value. Soooo, if you remove that part of the string, everything works as advertised. Here’s the fix:

    Replace current line 175:
    echo "<li>{$before_tweet}{$text}{$before_timesince}<a href=\"" . esc_url( "http://twitter.com/{$account}/statuses/{$tweet_id}" ) . '" class="timesince">' . str_replace(' ', '&nbsp;', wpcom_time_since(strtotime($tweet['created_at']))) . "&nbsp;ago</a></li>\n";

    With this line:
    echo "<li>{$before_tweet}{$text}{$before_timesince}<a href=\"" . esc_url( "http://twitter.com/{$account}/statuses/{$tweet_id}" ) . '" class="timesince">' . str_replace(' ', '&nbsp;', wpcom_time_since(strtotime(str_replace(' +0000', '', $tweet['created_at'])))) . "&nbsp;ago</a></li>\n";

    Or if you are into surgery, here’s the choice bits — replace:
    wpcom_time_since(strtotime($tweet['created_at'])))

    With this:
    wpcom_time_since(strtotime(str_replace(' +0000', '', $tweet['created_at']))))

    Thanks tim.garrett! Your fix worked beautifully.

    Thanks for posting a fix for this. I hope it’ll be fixed in the next version of the plugin (I specifically wanted a plugin I didn’t have to hack to make it work!)

    This is definitely to do with the version of PHP. I always develop and test my site using a local webserver on my workstation, but I have PHP 5.1.6, which seemed fine, whereas my host uses PHP 4.4.4, and that had the problem with the datestamp.

    I can’t see it give a PHP version as a requirement, and I note that the plugins website allows users to report whether it’s working by WordPress version, but not by PHP version.

    More Kudos for tim.garrett – thank you!

    I tried the fix, but now my posts are either saying “-1 years ago” or “1 day ago”. My host reports PHP 5.2.14. Any ideas?

    PHP 5 and above should not need the fix.
    Can you be a bit more specific about the errors you are getting?
    Are you getting -1 and 1 using the same code, or using different code?
    Also — what should the values be for those posts?

    I was getting all my tweets reported back as “41 years ago”, so I tried the fix. However, now recent tweets are showing “-1 years ago”. Upon closer look, it seems like anything older than 1 day is displaying correctly. My site is http://punaro.com

    I fixed it somehow… I went back and downloaded the original plugin again, edited the file in an editor, then copy/pasted the code back into WordPress and now it seems to be working.

    I take it back. It’s not fully fixed. It seems to anything that is “x minutes ago” as “-1 years ago”. Anything that is “x hours ago” or “x days ago” displays correctly.

    I have been battling this problem since yesterday. I hunted down the wpcom_time_since(strtotime($tweet['created_at'])))
    and figured it for the problem. However I dint think I would have come to a solution for it. So thank you Tim for that.

    I have been looking at the wpcom_time_since function as a possible cause

    function wpcom_time_since( $original, $do_more = 0 ) {
    	// array of time period chunks
    	$chunks = array(
    		array( 60 * 60 * 24 * 365 , 'year' ),
    		array( 60 * 60 * 24 * 30 , 'month' ),
    		array( 60 * 60 * 24 * 7, 'week' ),
    		array( 60 * 60 * 24 , 'day' ),
    		array( 60 * 60 , 'hour' ),
    		array( 60 , 'minute' ),
    	);
    
    	$today = time();
    	$since =  $today - $original;
    
    	for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) {
    		$seconds = $chunks[$i][0];
    		$name = $chunks[$i][1];
    
    		if ( ( $count = floor( $since / $seconds ) ) != 0 )
    			break;
    	}
    
    $print = ( $count == 1 ) ? '1 ' . $name : $count . $name . 's';
    
    	if ( $i + 1 < $j ) {
    		$seconds2 = $chunks[$i + 1][0];
    		$name2 = $chunks[$i + 1][1];
    
    		// add second item if it's greater than 0
    		if ( ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) && $do_more )
    			$print .= ( $count2 == 1 ) ? ', 1 ' . $name2 : ", $count2 {$name2}s";
    	}
    	return $print;

    Now I am getting the -1 year problem myself. I am still hunting down the root of the problem, but I found the $original value that is passed from created_at is larger then the current time. So $since is set to a negative number which messes with the wpcom_time_since function.

    I don’t know enough yet with php or twitter api to know if it is the time() function or the created_at that is giving the wrong number. I also don’t know how they handle time zones and if that could be a problem. I am going to keep researching it, hopefully one of you have some more insight.

    Ok.. so my simple hack. I compared what the time stamp of the widget was for my older post and compared it to the stamp on twitter. For me it was 7 hours which equates to 25200 seconds.

    So I just subtracted that from the &original before subtracting from $today.

    $since = $today - ($original - 25200);

    I know this is kind of a hack and I would like to know why twitter is 7 hours ahead. Also if its always 7 ahead, or if it gains/losses time. Also if it is 7 hours for everyone. Maybe timezone does matter?

    So many questions, but at least it works for my site (for now).

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Plugin: Wickett Twitter Widget] 40 years ago?’ is closed to new replies.