Not signed in ( Sign In)

Categories

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  permalink
    Hi,

    I have a PHP script for showing the latest tweet on a page. I would like to turn this into a Plugin widget, but not sure how to go about this.

    This is the PHP script to show latest tweet, works good on it's own.


    <?php

    // Your twitter username.
    $username = "account name";

    // Prefix - some text you want displayed before your latest tweet.
    // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
    $prefix = "<span>Latest Mini Update:</span>";

    // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
    $suffix = "";

    $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";

    function parse_feed($feed) {
    $stepOne = explode("<content type=\"html\">", $feed);
    $stepTwo = explode("</content>", $stepOne[1]);
    $tweet = $stepTwo[0];
    $tweet = str_replace("&lt;", "<", $tweet);
    $tweet = str_replace("&gt;", ">", $tweet);
    return $tweet;
    }

    $twitterFeed = file_get_contents($feed);
    echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
    ?>



    I was trying to add it to a standard plugin page like I've been doing with a few others, but because this is PHP it just spits out code into the page the widget is on.



    <?php

    /*
    Plugin Name: Latest Tweet
    Version: 1.0
    Plugin URI: None
    Description: None
    Release Date: None
    Author: None
    Author URI: None
    */

    function plugin_latesttweet_widget() {

    $content = '


    WAS GOING TO PUT THE PHP SCRIPT HERE.
    WAS GOING TO PUT THE PHP SCRIPT HERE.
    WAS GOING TO PUT THE PHP SCRIPT HERE.
    WAS GOING TO PUT THE PHP SCRIPT HERE.
    WAS GOING TO PUT THE PHP SCRIPT HERE.
    WAS GOING TO PUT THE PHP SCRIPT HERE.


    ';

    return array(
    'subject' => 'Latest Tweet',
    'content' => $content
    );
    }

    register_widget('latesttweet', 'Latesttweet', 'plugin_latesttweet_widget');

    ?>



    Can some one help me out on this. Was hoping it would work but I kinda knew it would be more complicated.

    Thanks
  2.  permalink
    OK, I have it working now, I just needed to remove the content bit


    <?php

    /*
    Plugin Name: Latest Tweet
    Version: 1.0
    Plugin URI: None
    Description: Adding the latest tweet to your page
    Release Date: June 26, 2009
    Author: None
    Author URI: None
    */

    function plugin_latesttweet_widget() {




    // Your twitter username.
    $username = "GloriousCounts";

    // Prefix - some text you want displayed before your latest tweet.
    // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
    $prefix = "<span>Latest Mini Update:</span>";

    // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
    $suffix = "";

    $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";

    function parse_feed($feed) {
    $stepOne = explode("<content type=\"html\">", $feed);
    $stepTwo = explode("</content>", $stepOne[1]);
    $tweet = $stepTwo[0];
    $tweet = str_replace("&lt;", "<", $tweet);
    $tweet = str_replace("&gt;", ">", $tweet);
    return $tweet;
    }

    $twitterFeed = file_get_contents($feed);
    echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);





    return array(
    'subject' => 'Latest Tweet',
    'content' => $content
    );
    }

    register_widget('latesttweet', 'Latesttweet', 'plugin_latesttweet_widget');

    ?>


    New problem. The title is below the tweet. See here http://www.cotnw.com/

    Many thanks
    •  
      CommentAuthorNoWhereMan
    • CommentTimeJun 27th 2009
     permalink
    replace echo with $content =
  3.  permalink
    Many thanks, very simple. Maybe I should buy myself a book on PHP and make the plunge.
    •  
      CommentAuthorkebre001
    • CommentTimeSep 5th 2010
     permalink
    I dont get it to work? can you send the finished code?