Results 1 to 16 of 16

Thread: PHP Tweet Reader for Mobile Web (Non Java scripts)

  1. #1
    Mobility Member firemax's Avatar
    Join Date
    Jan 2010
    Location
    Colombo/SL
    Posts
    50

    Default PHP Tweet Reader for Mobile Web (Non Java scripts)

    An easiest & most effective way to distribute your tweets on a mobile web page without using java scripts. specially for non java script support browsers & slow internet connection users.



    Download: http://yaaya.mobi/downloads/download.php?id=5982

    Product Page: http://yaaya.mobi/downloads/view.php?id=5982

  2. #2
    Mobility Regular morse's Avatar
    Join Date
    Apr 2009
    Location
    Mumbai, India
    Posts
    579

    Default

    Thanks for sharing .. repped !!!
    Btw as extra info, twitter had limited the amount of times access is made from applicants per minute. This news was there in blogosphere sometime ago, i dont know if the limit is still there or not. but it makes more sense to write the data using cronjob and then recall it numerous times from a flat file or database.

  3. #3
    Senior Member ChinaMobi's Avatar
    Join Date
    May 2010
    Posts
    1,593

    Default

    Are you saying PHP code is faster than JavaScript? I currently use the JavaScript code provided by Twitter to pull in tweets. Can you tell me more about their differences?

  4. #4
    Senior Member andymoore's Avatar
    Join Date
    Aug 2008
    Posts
    1,612

    Default

    One is client side JavaScript, the other is server side.

    Both are slow when it comes to getting a remote file as it involves either a client or server side dns lookup and parsing time.
    Andy Moore
    i don't do tech / mobi anymore - why do something that annoys and stresses lol

    New: Most Minty Tooth Oil - GMO and fluoride free toothpaste alternative

    100% natural botanical extracts to whiten teeth, freshen breath and strengthen gums
    Used, recommended and sold by Harley Street private dentists

    My other websites:

    http://sellyoursongs.info/ - Sell Your Songs using Mobile Payments
    http://detectmobilebrowsers.mobi/ - Detect Mobile Browsers
    http://andymoore.info/m-commerce-php/ - M-Commerce PHP (sell stuff on the mobile web)
    http://locationdetection.mobi/ - Detect a mobile browser's latitude & longitude
    http://andymoore.info/mysql-lyrics-database/ - Half a million lyrics


  5. #5
    Mobility Member firemax's Avatar
    Join Date
    Jan 2010
    Location
    Colombo/SL
    Posts
    50

    Default

    Quote Originally Posted by ChinaMobi View Post
    Are you saying PHP code is faster than JavaScript? I currently use the JavaScript code provided by Twitter to pull in tweets. Can you tell me more about their differences?
    Wow 500 posts. congrats chinamobi

    Actually, in theory, putting off more processing onto the client is more efficient. In reality, however, this is not the case.

    The theory is that if you have 10,000 tasks, for example serving 2 page loads to 5,000 clients, then what's more efficient, processing 100% of 10,000 tasks on one centralized server (could be a farm, granted) or processing 5% of 10,000 tasks on the centralized server and 95% of 10,000 tasks on 5,000 machines (the clients). In theory, passing the processing off to the client is more efficient.

    But the reality is that browsers are slow. None are designed with dynamic content in mind as the most important thing. The most effort on speed goes into rendering a static page, because that's the staple of the internet. The reality is that the clients are almost exponential in the extra time they take to process logic for dynamic page rendering when compared to preprocessing it on the server.Our job as programmers (specially for mobile devices) is to determine when the theory and the reality line up, and when they do not.

    A little calculation (for a normal slow internet connection)

    if your using twitter widget, user must connect to two http connections. first one for your server & second one for twitter server.
    1. user browsing data from your server (0.5 Sec)
    2. user browsing data from twitter server (0.5 Sec)
    Total 0.5+0.5= 1 Sec

    In my way,
    1. server get data from twitter (0.02 Sec -Maximum time, if cached file expired)
    2. user browsing data from your server (0.5 Sec)
    Total 0.5+0.02= 0.52 Sec (this is the maximum value, 99% times equal to 0.5 Sec)

  6. #6
    Senior Member andymoore's Avatar
    Join Date
    Aug 2008
    Posts
    1,612

    Default

    Right, now I'm on my PC rather than on the iPad, I was sitting outside in the sun on that last post....

    I've looked at the scripts, it could be done in about 150 less lines of code meaning it's rather on the bloated side for what it is.

    Nor did it want to run on my XMAPP install under localhost.

    So.........

    Five minutes later.....

    A Simple XML solution with cache:

    PHP Code:
    <?php

    $user 
    'detectmobiles';
    $data 'http://twitter.com/statuses/user_timeline/'.$user.'.xml';

    function 
    cached_simplexml_load_file($file,$hours='1'){
        if(isset(
    $_GET['cache'])){$hours '0';}
        
    $remote $file;
        
    $file 'cache/'.md5($file).'.xml';
        if(!(
    file_exists($file)&&(60*60*$hours)>(time()-filemtime($file)))){
        
    $fp fopen($file'wb');
        
    fwrite($fpfile_get_contents($remote));
        
    fclose($fp);
        }
        return 
    simplexml_load_file($file);
    }

    $xml cached_simplexml_load_file($data);
    foreach(
    $xml->status as $status){
        echo 
    '<p>'.$status->text.'<br />'.$tweet->time.'</p>';
    }

    ?>
    If you use it it will cache everything for an hour, say you just tweeted and want to clean the cache out just add ?cache to the end of the URL and it will get fresh data and store that.
    Last edited by andymoore; 10-10-2010 at 11:41 AM.
    Andy Moore
    i don't do tech / mobi anymore - why do something that annoys and stresses lol

    New: Most Minty Tooth Oil - GMO and fluoride free toothpaste alternative

    100% natural botanical extracts to whiten teeth, freshen breath and strengthen gums
    Used, recommended and sold by Harley Street private dentists

    My other websites:

    http://sellyoursongs.info/ - Sell Your Songs using Mobile Payments
    http://detectmobilebrowsers.mobi/ - Detect Mobile Browsers
    http://andymoore.info/m-commerce-php/ - M-Commerce PHP (sell stuff on the mobile web)
    http://locationdetection.mobi/ - Detect a mobile browser's latitude & longitude
    http://andymoore.info/mysql-lyrics-database/ - Half a million lyrics


  7. #7
    MobiEnthusiast coast's Avatar
    Join Date
    Jul 2007
    Posts
    4,720

    Default

    Firemax, thanks for sharing.

    ChinaMobi, not all phones allow for javascript. PHP is best for .mobi

    Andy, you are amazing. Flat out amazing. Glad to see you are using your talents for good ... LOL
    Need a developer? MobileSiteStore.com | More good stuff at Drosty.com
    Accepting Quality guest posts via PM only for mobiEnthusiast.mobi
    (NO press releases or story ideas, completed, unique articles only
    )

  8. #8
    Senior Member andymoore's Avatar
    Join Date
    Aug 2008
    Posts
    1,612

    Default

    @coast Thank you but I swear actually reading the manual, Googling and being more persistant than a bad stain makes up 99% of it.

    @firemax Oh dear, oh dear, oh dear:

    @all

    http://www.axllent.org/projects/mytwit

    Folks, look at his class, then look at the original and think how very, very similar they are.

    It is one thing to write something and take credit for it, it is another altogether different thing to take the code that was writen by someone else, bung it in a mobile template and take credit for it. In fact it's a scummy practice and you're out of order for taking the original authors work and making out it's your own creation.

    This is original, I put it together and where it uses functions that I found elsewhere I have given the original author the due respect and credit they deserve, just like a certain someone should have done.

    PHP Code:
    <?php

    date_default_timezone_set
    ('Europe/London'); // list of time zones - required to not puke when handling time calculations

    $user 'detectmobiles'// set the username you want to get the feed for
    $limit '10'// how many items do you want to return
    $data 'http://twitter.com/statuses/user_timeline/'.$user.'.xml'// build the endpoint

    // this function takes two arguments, the url of the endpoint and the duration in minutes to cache the data for
    // inspired by the cache article on http://www.addedbytes.com/articles/caching-output-in-php/
    function cached_simplexml_load_file($file,$minutes='5'){
        if(isset(
    $_GET['cache'])){$minutes '0';} // bypass the cache by adding ?cache to the url
        
    $remote $file// set the remote address in case we need it
        
    $file 'cache/'.md5($file).'.xml'// make up a  file name to store the data in
        
    if(!(file_exists($file)&&(60*$minutes)>(time()-filemtime($file)))){ // if the file exists and is older than the cache expiration time get the data and write it to a file
        
    $fp fopen($file'wb'); 
        
    fwrite($fpfile_get_contents($remote));
        
    fclose($fp);
        }
        return 
    simplexml_load_file($file); // now return the data with simple xml
    }

    function 
    make_clickable($text){ // 85% taken from http://snippets.dzone.com/posts/show/6156
        
    $ret ' ' $text;
      
    $ret preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise""'\\1<a href=\"\\2\" target=\"_blank\">\\2</a>'"$ret);
      
    $ret preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise""'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>'"$ret);
      
    $ret preg_replace("/@(\w+)/""<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>"$ret); // http://www.snipe.net/2009/09/php-twitter-clickable-links/
        
    $ret preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i""\\1<a href=\"mailto:\\[email protected]\\3\">\\[email protected]\\3</a>"$ret);
      
    $ret substr($ret1);
      return(
    $ret);
    }

    function 
    niceTime($time) { // taken from http://manas.tungare.name/software/twitter-php-script/
      
    $delta time() - $time;
      if (
    $delta 60) {
        return 
    'less than a minute ago.';
      } else if (
    $delta 120) {
        return 
    'about a minute ago.';
      } else if (
    $delta < (45 60)) {
        return 
    floor($delta 60) . ' minutes ago.';
      } else if (
    $delta < (90 60)) {
        return 
    'about an hour ago.';
      } else if (
    $delta < (24 60 60)) {
        return 
    'about ' floor($delta 3600) . ' hours ago.';
      } else if (
    $delta < (48 60 60)) {
        return 
    '1 day ago.';
      } else {
        return 
    floor($delta 86400) . ' days ago.';
      }
    }

    $xml cached_simplexml_load_file($data); // get the data either fresh or from the cache

    // now run through each status update in the xml
    foreach($xml->status as $status){
        if(++
    $cntr<=$limit){ // increment the counter and make sure that's less than or equal to the limit
            
    $tweet make_clickable($status->text);
            
    $time niceTime(strtotime(str_replace("+0000"""$status->created_at)));
            
    $tweets .= '<p>'.$tweet.'<br />'.$time.'</p>'// build up the tweets as paragraphd
            // $tweets .= '<li>'.$tweet.'<br />'.$time.'</li>'; // build up the tweets as list elements
            
    if($cntr=='1'){ // if this is the first tweet we are processing get the followers and friends counts
                
    $followers $status->user->followers_count;
                
    $following $status->user->friends_count;
            }
        }
    }

    // show what we have
    echo $tweets.'<p>Following '.$following.' people<br />Followed by '.$followers.' people</p>';

    // this entire file could be stashed away in an include, when it's called it will return three values:
    // $tweets = the full list of tweets upto the limit you set
    // $following = how many people you are following
    // $followers = how many people are folling you

    ?>
    http://andymoore.info/tweets.phps

    @firemax Giving away copyrighted material on your site and passing off other people's code are both bad practices which make me think you're scum.
    Last edited by andymoore; 10-10-2010 at 04:14 PM. Reason: tiny tweak of the comments in the code
    Andy Moore
    i don't do tech / mobi anymore - why do something that annoys and stresses lol

    New: Most Minty Tooth Oil - GMO and fluoride free toothpaste alternative

    100% natural botanical extracts to whiten teeth, freshen breath and strengthen gums
    Used, recommended and sold by Harley Street private dentists

    My other websites:

    http://sellyoursongs.info/ - Sell Your Songs using Mobile Payments
    http://detectmobilebrowsers.mobi/ - Detect Mobile Browsers
    http://andymoore.info/m-commerce-php/ - M-Commerce PHP (sell stuff on the mobile web)
    http://locationdetection.mobi/ - Detect a mobile browser's latitude & longitude
    http://andymoore.info/mysql-lyrics-database/ - Half a million lyrics


  9. #9
    Senior Member ChinaMobi's Avatar
    Join Date
    May 2010
    Posts
    1,593

    Default

    But the reality is that browsers are slow. None are designed with dynamic content in mind as the most important thing.
    ChinaMobi, not all phones allow for javascript. PHP is best for .mobi
    What about the smart phones that are coming out everyday now? Aren't their browsers designed to be fast and to handle PHP, JavaScript and complex contents? My only interest is smart phones so I don't look at the older generation phones that are not designed for browsing anyway.

  10. #10
    Mobility Member firemax's Avatar
    Join Date
    Jan 2010
    Location
    Colombo/SL
    Posts
    50

    Default

    Quote Originally Posted by andymoore View Post
    @coast Thank you but I swear actually reading the manual, Googling and being more persistant than a bad stain makes up 99% of it.

    @firemax Oh dear, oh dear, oh dear:

    @all

    http://www.axllent.org/projects/mytwit

    Folks, look at his class, then look at the original and think how very, very similar they are.

    It is one thing to write something and take credit for it, it is another altogether different thing to take the code that was writen by someone else, bung it in a mobile template and take credit for it. In fact it's a scummy practice and you're out of order for taking the original authors work and making out it's your own creation.

    This is original, I put it together and where it uses functions that I found elsewhere I have given the original author the due respect and credit they deserve, just like a certain someone should have done.

    PHP Code:
    <?php

    date_default_timezone_set
    ('Europe/London'); // list of time zones - required to not puke when handling time calculations

    $user 'detectmobiles'// set the username you want to get the feed for
    $limit '10'// how many items do you want to return
    $data 'http://twitter.com/statuses/user_timeline/'.$user.'.xml'// build the endpoint

    // this function takes two arguments, the url of the endpoint and the duration in minutes to cache the data for
    // inspired by the cache article on http://www.addedbytes.com/articles/caching-output-in-php/
    function cached_simplexml_load_file($file,$minutes='5'){
        if(isset(
    $_GET['cache'])){$minutes '0';} // bypass the cache by adding ?cache to the url
        
    $remote $file// set the remote address in case we need it
        
    $file 'cache/'.md5($file).'.xml'// make up a  file name to store the data in
        
    if(!(file_exists($file)&&(60*$minutes)>(time()-filemtime($file)))){ // if the file exists and is older than the cache expiration time get the data and write it to a file
        
    $fp fopen($file'wb'); 
        
    fwrite($fpfile_get_contents($remote));
        
    fclose($fp);
        }
        return 
    simplexml_load_file($file); // now return the data with simple xml
    }

    function 
    make_clickable($text){ // 85% taken from http://snippets.dzone.com/posts/show/6156
        
    $ret ' ' $text;
      
    $ret preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise""'\\1<a href=\"\\2\" target=\"_blank\">\\2</a>'"$ret);
      
    $ret preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise""'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>'"$ret);
      
    $ret preg_replace("/@(\w+)/""<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>"$ret); // http://www.snipe.net/2009/09/php-twitter-clickable-links/
        
    $ret preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i""\\1<a href=\"mailto:\\[email protected]\\3\">\\[email protected]\\3</a>"$ret);
      
    $ret substr($ret1);
      return(
    $ret);
    }

    function 
    niceTime($time) { // taken from http://manas.tungare.name/software/twitter-php-script/
      
    $delta time() - $time;
      if (
    $delta 60) {
        return 
    'less than a minute ago.';
      } else if (
    $delta 120) {
        return 
    'about a minute ago.';
      } else if (
    $delta < (45 60)) {
        return 
    floor($delta 60) . ' minutes ago.';
      } else if (
    $delta < (90 60)) {
        return 
    'about an hour ago.';
      } else if (
    $delta < (24 60 60)) {
        return 
    'about ' floor($delta 3600) . ' hours ago.';
      } else if (
    $delta < (48 60 60)) {
        return 
    '1 day ago.';
      } else {
        return 
    floor($delta 86400) . ' days ago.';
      }
    }

    $xml cached_simplexml_load_file($data); // get the data either fresh or from the cache

    // now run through each status update in the xml
    foreach($xml->status as $status){
        if(++
    $cntr<=$limit){ // increment the counter and make sure that's less than or equal to the limit
            
    $tweet make_clickable($status->text);
            
    $time niceTime(strtotime(str_replace("+0000"""$status->created_at)));
            
    $tweets .= '<p>'.$tweet.'<br />'.$time.'</p>'// build up the tweets as paragraphd
            // $tweets .= '<li>'.$tweet.'<br />'.$time.'</li>'; // build up the tweets as list elements
            
    if($cntr=='1'){ // if this is the first tweet we are processing get the followers and friends counts
                
    $followers $status->user->followers_count;
                
    $following $status->user->friends_count;
            }
        }
    }

    // show what we have
    echo $tweets.'<p>Following '.$following.' people<br />Followed by '.$followers.' people</p>';

    // this entire file could be stashed away in an include, when it's called it will return three values:
    // $tweets = the full list of tweets upto the limit you set
    // $following = how many people you are following
    // $followers = how many people are folling you

    ?>
    http://andymoore.info/tweets.phps

    @firemax Giving away copyrighted material on your site and passing off other people's code are both bad practices which make me think you're scum.
    read comments on http://www.axllent.org/projects/mytwit

    -----------------------------------------------------
    Artemwrote 8 months ago:
    Hi. I take MyTwit. I have to put a link to your site? Which license for MyTwit? Goodbye.

    Ralphwrote 8 months ago:
    ----------------------------------------------------

    No link is required to my site. MyTwit is just a script I wrote so use it for whatever you like. If anything I'd say it's GPL, although it doesn't actually come with a license. I'd just appreciate knowing where it's being used.

  11. #11
    Senior Member andymoore's Avatar
    Join Date
    Aug 2008
    Posts
    1,612

    Default

    To take one mans work and pretend it's your own is deceptive and bad practice.

    If you take something you give credit for it unless of course you're scum; in which case you've already set the benchmark on how to behave.
    Andy Moore
    i don't do tech / mobi anymore - why do something that annoys and stresses lol

    New: Most Minty Tooth Oil - GMO and fluoride free toothpaste alternative

    100% natural botanical extracts to whiten teeth, freshen breath and strengthen gums
    Used, recommended and sold by Harley Street private dentists

    My other websites:

    http://sellyoursongs.info/ - Sell Your Songs using Mobile Payments
    http://detectmobilebrowsers.mobi/ - Detect Mobile Browsers
    http://andymoore.info/m-commerce-php/ - M-Commerce PHP (sell stuff on the mobile web)
    http://locationdetection.mobi/ - Detect a mobile browser's latitude & longitude
    http://andymoore.info/mysql-lyrics-database/ - Half a million lyrics


  12. #12
    Senior Member andymoore's Avatar
    Join Date
    Aug 2008
    Posts
    1,612

    Default

    @paul - congratulations for being the most confusing person to post here in some time.
    Last edited by andymoore; 02-03-2011 at 12:41 PM.
    Andy Moore
    i don't do tech / mobi anymore - why do something that annoys and stresses lol

    New: Most Minty Tooth Oil - GMO and fluoride free toothpaste alternative

    100% natural botanical extracts to whiten teeth, freshen breath and strengthen gums
    Used, recommended and sold by Harley Street private dentists

    My other websites:

    http://sellyoursongs.info/ - Sell Your Songs using Mobile Payments
    http://detectmobilebrowsers.mobi/ - Detect Mobile Browsers
    http://andymoore.info/m-commerce-php/ - M-Commerce PHP (sell stuff on the mobile web)
    http://locationdetection.mobi/ - Detect a mobile browser's latitude & longitude
    http://andymoore.info/mysql-lyrics-database/ - Half a million lyrics


  13. #13
    Founding Member Scandiman's Avatar
    Join Date
    Jun 2007
    Location
    NorCal
    Posts
    9,538

    Default

    Quote Originally Posted by andymoore View Post
    @paul - congratulations for being the most confusing person to post here in some time.
    Its gonna be hard to top that solog dude

  14. #14
    Senior Member andymoore's Avatar
    Join Date
    Aug 2008
    Posts
    1,612

    Default

    Very true! He's still talking crap elsewhere claiming to have predicted recent events years ago.......

    Madder than a hatter! Maybe there's a lot of lead in the water where he is.....
    Andy Moore
    i don't do tech / mobi anymore - why do something that annoys and stresses lol

    New: Most Minty Tooth Oil - GMO and fluoride free toothpaste alternative

    100% natural botanical extracts to whiten teeth, freshen breath and strengthen gums
    Used, recommended and sold by Harley Street private dentists

    My other websites:

    http://sellyoursongs.info/ - Sell Your Songs using Mobile Payments
    http://detectmobilebrowsers.mobi/ - Detect Mobile Browsers
    http://andymoore.info/m-commerce-php/ - M-Commerce PHP (sell stuff on the mobile web)
    http://locationdetection.mobi/ - Detect a mobile browser's latitude & longitude
    http://andymoore.info/mysql-lyrics-database/ - Half a million lyrics


  15. #15
    Mobility Regular pilot's Avatar
    Join Date
    Jun 2007
    Posts
    812

    Default

    Quote Originally Posted by andymoore View Post
    Madder than a hatter! Maybe there's a lot of lead in the water where he is.....
    I grew up in Danbury which was the hat capital of the world and where the term "Mad Hatter" came from. The madness came from the mercury. That would explain a lot about me. TMI... I know.
    Last edited by pilot; 02-03-2011 at 04:42 PM.

  16. #16
    New Member
    Join Date
    Feb 2011
    Posts
    3

    Cool PHPTweet Reader for mobile web

    waw thanks for sharing i will give a try .

Similar Threads

  1. Free Mobile Scripts
    By morse in forum Mobile Scripts (NEW!)
    Replies: 17
    Last Post: 01-18-2012, 01:26 PM
  2. Tweet dot me
    By mediaadvantages in forum News & Discussion
    Replies: 2
    Last Post: 08-28-2009, 06:46 AM
  3. Tweet.me
    By mediaadvantages in forum News & Discussion
    Replies: 0
    Last Post: 07-28-2009, 12:12 AM
  4. What scripts do you want to see?
    By developmy.mobi in forum Mobile Web Design
    Replies: 13
    Last Post: 01-13-2008, 09:11 PM
  5. $35 for 3 scripts.
    By developmy.mobi in forum .mobi's For Sale - Offers Wanted
    Replies: 0
    Last Post: 01-02-2008, 03:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
A Yup.mobi Mobile Site
Mobile Dating