We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17855
    • 43 Posts
    Hi has anyone integrated twitter feeds or written a snippet for it?

    Just before I start to get my head around it....

    Thanks -
      • 7231
      • 4,205 Posts
      I think that there are feed readers for MODx that might handle this, not sure though. Take a look into the repository.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 17855
        • 43 Posts
        thanks dev_cw

        I’m just playing with FeedX and it seems to work nicely

        Except I am now having problems using FeedX in a ditto tpl/chunk....seems not to function from within ditto. working on it though...
          • 20728
          • 53 Posts
          Hi,

          Just wondering how you got on with displaying a Twitter feed?

          I need to achieve the same thing but I have no ideas how to strip out the Twitter username from the Twitter RSS feed.

          Also I’d really love to be able to present the date as "15 minutes ago" or "2 weeks ago" something like that.

          Thanks.
            Enovate Design | Web Design Agency Essex
            • 27708 MODX Staff
            • 2,502 Posts
            I’ll write it tomorrow. I have no less than 2 php wrapper classes for Twitter. Do you just want to output your twitter stream?


            Thoughts on parameters? Username and number of tweets to show?
              Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 27708 MODX Staff
              • 2,502 Posts
              Twitter does have rss but so you could just use FeedX. I like a modx native snippet though as I could extend it to do posts and other twitter API magic.

              Cheers

              Jay
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 20728
                • 53 Posts
                Thanks for your responses on this SmashingRed and sorry for not getting back in touch.

                I managed to get this sorted using FeedX. It took some figuring out to get the "15 minutes ago" working but I found the code elsewhere. I also needed to enter the string length of the username prefix so that could be removed as well.

                I’ll post the files here when I get a moment.
                  Enovate Design | Web Design Agency Essex
                  • 25663 MODX Staff
                  • 12,272 Posts
                  Thanks mwalsh. Would be appreciated. smiley
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 20728
                    • 53 Posts
                    Firstly, I’m not a programmer so I’m sure there may well be better ways to do this, please feel free to post improvements!

                    OK, I’ve attached the Twitter TPL, just drop that into your FeedX tpl directory.

                    Then you need to set-up two snippets:

                    Call the first one "phx:str2twit" and paste the following:

                    <?php
                    $twit = substr($output, 12);
                    return $twit;
                    ?>
                    


                    In the above code you need to edit the number "12" to correspond to the length of your Twitter username as this code cuts it from your updates.

                    Call the second one "phx:str2timesince" and paste the following:

                    <?php
                    if (!function_exists('timeSince'))
                    {
                    function timeSince($timestamp)
                    {
                    if ($timestamp >= time())
                    {
                    $timeago = '0 seconds ago';
                    return $timeago;
                    }
                    $seconds = time()-$timestamp;
                    $units = array(
                    'year' => 31556926,
                    'month' => 2629743,
                    'day' => 86400,
                    'hour' => 3600,
                    'minute' => 60,
                    // 'second' => 1
                    );
                    $timeago = '';
                    foreach ($units as $key => $val)
                    {
                    if ($seconds >= $val)
                    {
                    $results = floor($seconds/$val);
                    $seconds = ($seconds-($results*$val));
                    $timeago .= ($results >= 2) ? $results . ' ' . $key . 's, ' : $results . ' ' . $key . ', ';
                    }
                    }
                    return rtrim($timeago, ', ') . ' ago';
                    }
                    }
                    
                    // Correct Time
                    
                    function pubDate_to_timestamp($time){
                       //Thu, 21 Aug 2008 01:14:36 PDT
                       //=> date("D, j M Y H:i:s T");
                    
                       $time = explode(' ', $time);
                       $chrono = explode(':', $time[4]);
                    
                       $month = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5,
                                      'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10,
                                      'Nov' => 11, 'Dec' => 12);
                    
                       $mktime = mktime($chrono[0], $chrono[1], $chrono[2], $month[$time[2]], $time[1], $time[3], $time[5]);
                    
                       return $mktime;
                    }
                    
                    $twitime = pubDate_to_timestamp($output);
                    return timeSince($twitime);
                    ?>
                    


                    I found the above code here: http://wiki.modxcms.com/index.php/PHx/CustomModifiers#phx:timesince

                    Then the snippet call to drop into your page (replacing the URL with the correct one for your Twitter account):

                    [!FeedX? &url=`http://twitter.com/statuses/user_timeline/123456789.rss` &cacheTime=`600` &maxElements=`ITEM(1)` &preset=`twitter` !]
                    


                    All done.
                      Enovate Design | Web Design Agency Essex
                      • 29703
                      • 217 Posts
                      I’ve been staring at mwalsh’s solution for a while now and just can’t get it to function with more than one instance of the timesince modification. Using the existing timesince phx snippet worked perfectly with multiple instances, but the amended version by mwalsh (which fixes the time display) cannot appear more than once.

                      If someone could have a quick peek and tell me what’s wrong with it, it would be greatly appreciated.

                      Thanks,