Results 1 to 8 of 8

Thread: Auto-feed HotaruCms to Twitter

  1. #1
    Senior Member kmai's Avatar
    Join Date
    Apr 2010
    Posts
    150
    Thanks
    43
    Thanked 15 Times in 13 Posts

    Thumbs up Auto-feed HotaruCms to Twitter

    So I have been on this Twitter kick lately, sorry. But, let’s face it, Twitter is where the action is. So let’s looks at how to have the built-in RSS feature work for you. Look Auto Feed step by step.

  2. Thanked by:


  3. #2
    Senior Member baadier's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town, South Africa
    Posts
    263
    Thanks
    80
    Thanked 14 Times in 10 Posts

    Default

    You could also accomplish this by burning your feed with feedburner and using the promote tab to set it to a twitter account. What ive done is all my popular posts get a #soccer #football hashtag and ive also burnt specific feeds from the tags of popular clubs and set it for Manchester United for example to have #manutd so the relevant people see the right stuff. The click through rate on the tag rss feeds is much better than the general rss

  4. #3
    Member apfind's Avatar
    Join Date
    May 2010
    Location
    New York City
    Posts
    56
    Thanks
    24
    Thanked 7 Times in 6 Posts

    Default

    There is a mayor problem with both options. They miss certain top posts.

    Here's what I think is happening. Due to the way these services work, they seem to be pulling only the latest posts, not changes in the feed.

    Here's an example:
    Lets say users bookmarked one story on Monday and one on Tuesday. Imagine that the one from Tuesday gets voted on and makes top posts. Feedburner or Twitter Feed reads the RSS and automatically posts to twitter. No issue there. But here's the problem. The next day the story from monday also gets enough votes to make the top posts. But, because it was technically created at a earlier date, it shows up lower on the RSS timeline. And, that means Feedburner or Twitter feed don't post it all. It's invisible to them.

  5. #4
    Senior Member baadier's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town, South Africa
    Posts
    263
    Thanks
    80
    Thanked 14 Times in 10 Posts

    Default

    That's an interesting argument I might be mistaken though,even if a post is created on a previous date it still gets posted from what I've seen.I've manually moved posts that got traffic to the popular section and once there it automatically posted to twitter. I'm not sure if it works if posts get to popular "naturally" but I see no reason why it shouldnt

  6. #5
    Member apfind's Avatar
    Join Date
    May 2010
    Location
    New York City
    Posts
    56
    Thanks
    24
    Thanked 7 Times in 6 Posts

    Default

    [PHP]Thanks Baadier. Hmmmm. I wonder what my issue is then. I keep getting lost posts. I ping a million times and feedburner still ignores them. I'll keep looking into it.

    For those looking to develop a solution within Hotaru CMS...

    Here is the PHP code to update your status on Twitter. I'm thinking that maybe this could be placed somewhere around line 75 in vote_functions.php (found within the vote plugin)
    On line 75 in vote_function.php you find - " if ($vote_rating > 0) { // Change the status to 'top' if we have enough votes and are within the time limit to hit the front page: "

    We might be able to insert the code below there, and use some of the code from the Tweet This Plugin to define the $message variable. We can also use some of the Tweet This code to URL shorten automatically.

    PHP code to update your status on Twitter:
    PHP Code:
    $username 'myUser';
    $password '**********';
    $format 'xml'//alternative: json 
    $message 'David Walsh\'s blog rocks! [url]http://davidwalsh.name/';[/url]
     
    /* work */ 
    $result shell_exec('curl http://twitter.com/statuses/update.'.$format.' -u '.$username.':'.$password.' -d status="'.str_replace('"','\"',$message).'"'); 
    Here is the Tweet_This.php code. We will probably have to fix some of the variables so that they no longer are taken from Tweet_This_Settings.php, but this is a good starting point...

    In Tweet_This.php this PHP code builds the link:

    PHP Code:
    /**
         * Build the link 
         */
        
    public function tweetThisPost($h)
        {
            
    // get the post's id from the url
            
    $post_id $h->cage->get->testInt('id');
            
            
    // get the compressed url for this link
            
    $shortened_url $this->getShortUrl($h$post_id);
            
            
    // add the compressed link to the Twitter status update url
            
    $twitter_url $this->getTwitterUrl($h$post_id$shortened_url); 

            
    // redirect to Twitter
            
    header("Location: " $twitter_url);
            exit;
        } 
    And, this code builds the shortened link:
    PHP Code:
        /**
         * Build the shortened link 
         *
         * @param int $post_id
         * @return string $url
         */
        
    public function getShortUrl($h$post_id)
        {
            
    // Check the database to see if there's already a short link there.
            
    $query "SELECT postmeta_value FROM " TABLE_POSTMETA " where postmeta_postid = %d AND postmeta_key = %s";
            
    $sql $h->db->prepare($query$post_id'compressed_url');
            
    $stored_short_link $h->db->get_var($sql);
            
            if(!
    $stored_short_link) {
                
    // no short link in db. We need to create one:
                
                // get the post's url and encode it:
                
    $post_url urlencode($h->url(array('page'=>$post_id)));
                
                
    // get settings so we know which shortener to use:
                
    $tweet_this_settings $h->getSerializedSettings();

                
    // get the post's url and encode it:
               
    if ($tweet_this_settings['tt_use_GA_tracking']) // do we want GA tracking tags?
               
    {
                    if (
    FRIENDLY_URLS == "false")    {
                        
    // friendly URLs are not enabled (add more query string parameters)
                        
    $post_url urlencode($h->url(array('page'=>$post_id)) . '&utm_source=tweet-this&utm_medium=Twitter&utm_campaign=story-promotion' );
                    }
                    else 
                    {   
    // friendly URLs are enabled (start with query string parameters)
                        
    $post_url urlencode($h->url(array('page'=>$post_id)) . '?utm_source=tweet-this&utm_medium=Twitter&utm_campaign=story-promotion' );
                    } 
                }
                else 
                {   
                    
    // just send the URL without tracking tags
                    
    $post_url urlencode($h->url(array('page'=>$post_id)));
                }
                
                
    // which shortener do we use?
                
    switch($tweet_this_settings['tt_shortener']) {
                    case 
    'tinyurl':
                        
    $url file_get_contents('http://tinyurl.com/api-create.php?url=' $post_url);
                        break;
                    case 
    'bitly':
                        
    $url $this->getBitlyLink($h$post_url$tweet_this_settings);
                        break;
                    default:
                        
    $url file_get_contents('http://is.gd/api.php?longurl=' $post_url);
                }

                
    // then store it in the database:
                
    $query "INSERT INTO " TABLE_POSTMETA " (postmeta_postid, postmeta_key, postmeta_value, postmeta_updateby) VALUES(%d, %s, %s, %d)";
                
    $sql $h->db->prepare($query$post_id'compressed_url'urlencode(trim($url)), $h->currentUser->id);
                
    $h->db->query($sql);

            } else {
                
    // we can use the existing one.
                
    $url $stored_short_link;
            }
            return 
    trim($url);
        } 
    This code builds the Twitter Status Update and inserts the shortened link from above...

    PHP Code:
        /**
         * Build the Twitter status update link
         *
         * @param int $post_id
         * @param string $shortened_url
         * @return string $url
         */
        
    public function getTwitterUrl($h$post_id$shortened_url)
        {
            
    $h->readPost($post_id);
            
    $title html_entity_decode($h->post->titleENT_QUOTES"UTF-8");
            
            
    $orig_length strlen($title); // get original title length
            
    if ($orig_length 110) {
                
    $title substr($title0100); // keep only the first 100 characters
                
    $title substr($title0strrpos($title,' ')); // keep everything up to the last space
                
    $title .= "..."// adds some dots to show we've truncated it
            
    }
            
    $title $title " "// 100 chars + "..." + " " = 104 chars, leaving 36 chars for the url
            
    $title urlencode($title);
            
            
    // The final Twitter URL:
            
    $url 'http://twitter.com/home/?status=' $title '+' $shortened_url ;
            return 
    $url;
        }

    Last edited by apfind; 06-04-2010 at 02:22 AM.

  7. #6
    Senior Member baadier's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town, South Africa
    Posts
    263
    Thanks
    80
    Thanked 14 Times in 10 Posts

    Default

    Are you maybe adding posts in batches? I know with feedburner you can post up to 8 tweets for every feed batch. I'm not sure what happens if you for instance make 10 posts popular in 1 go. Does the extra 2 get tweeted later or is it just "lost"

  8. #7
    Member apfind's Avatar
    Join Date
    May 2010
    Location
    New York City
    Posts
    56
    Thanks
    24
    Thanked 7 Times in 6 Posts

    Default

    That's a good watch out. I think I have had that happen in the past. But in this case it was just one lonely post that got lost.

  9. #8
    Senior Member baadier's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town, South Africa
    Posts
    263
    Thanks
    80
    Thanked 14 Times in 10 Posts

    Default

    I think keep in mind the limits when you change the status on posts cause when it happens naturally you won't have 20 posts go popular at once. Make sure the hashtags appended are relevant, and don't stress about the 10-15 minute delay before the posts get tweeted it will get there.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Twitter Widget 0.3
    By JonH in forum Deprecated Plugins
    Replies: 18
    Last Post: 12-31-2011, 12:34 PM
  2. Twitter Thumbs 0.2
    By JonH in forum Deprecated Plugins
    Replies: 7
    Last Post: 11-26-2010, 11:43 AM
  3. Replies: 7
    Last Post: 05-17-2010, 05:06 AM
  4. Following Plugin like Pligg and Twitter
    By bookwormxp in forum Plugin Suggestion Box
    Replies: 12
    Last Post: 03-20-2010, 01:23 AM

Tags for this Thread

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
  •