Auto-publish to Twitter

Posted In Hacks - By Geoserv On Sunday, November 1st, 2009 With 163 Comments

In this tutorial I will show you how to have your stories sent to the published page automatically Tweeted to Twitter using whatever Twitter account you want.

I have already shown you how to use Twitterfeed and Bit.ly to auto publish your published submissions, now lets cut out the middleman, Twitterfeed.

The following code was sent to us by Jorge from the good folks at Bierzeame.

Open your libs/link.php file and find:
function publish() {
if(!$this->read) $this->read_basic();
$this->published_date = time();

totals_adjust_count($this->status, -1);
totals_adjust_count('published', 1);

$this->status = 'published';
$this->store_basic();
}

change it to:
function publish() {
if(!$this->read) $this->read_basic();
$this->published_date = time();

totals_adjust_count($this->status, -1);
totals_adjust_count('published', 1);

$this->status = 'published';
$this->twitter();
$this->store_basic();
}

find:

function username() {

just before it add:
function twitter(){
global $db;

$id = $this->id;
if(!is_numeric($id)){return false;}
if(($link = $db->get_row("SELECT link_title FROM " . table_links . " WHERE link_id = $id"))) {

$message = $link->link_title;
$toshort = getmyFullurl("storyURL", $this->category_name(), urlencode($link->link_title_url), $id);

$bitly = "http://api.bit.ly/shorten?version=2.0.1&longUrl=".urlencode($toshort)."&login=BITLYUSERNAME&apiKey=YOURBITLYAPICODE&history=1";

$bitlyresponse = file_get_contents($bitly);

$jsonresponse = @json_decode($bitlyresponse,true);

$urlshort = $jsonresponse['results'][$toshort]['shortUrl'];

$messagelen = strlen($message);
$urllen = strlen($urlshort);
$totallen = $messagelen+$urllen+1;

if ($totallen>140){
$urllen = $urllen+4;
$message = substr($message,0,139-$urllen);
$message = $message."...";
}

$message = $message." ".$urlshort;

$args= 'status='.urlencode($message);

$twit = curl_init();
curl_setopt($twit, CURLOPT_URL, 'http://twitter.com/statuses/update.xml');
curl_setopt($twit, CURLOPT_VERBOSE, 0);
curl_setopt($twit, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($twit, CURLOPT_VERBOSE, 0); // no imprimir nada
curl_setopt($twit, CURLOPT_USERPWD, "TWITTERUSERNAME:TWITTERPASSWORD");
curl_setopt($twit, CURLOPT_POSTFIELDS, $args);
curl_setopt($twit, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($twit, CURLOPT_POST, 1);

$result = curl_exec($twit);
$http_status = curl_getinfo($twit, CURLINFO_HTTP_CODE);

curl_close($twit);

if( $http_status != "200" ) {
return false;
}

return true;
}
}

Save.

That’s it. Now every story that is sent to the published page will auto Tweet, giving your members another reason to submit.

Make sure you edit your Twitter login details and your Bit.ly details.

It will shorten the submission URL using Bit.ly and send the user when clicked on Twitter to your story page. This will also track how many clicks each one gets which you can check when you login to Bit.ly.

bitlyclicks

A company offers cheap flights so try our remarkable online 640-802 and 642-447 training programs will lead you to success in the itil certification and pass4sure mcp exams.

Related Search:

  • publish to twitter
  • publish on twitter
  • auto publish on twitter
  • how to publish twitter
  • how to publish to twitter
  • how to publish automatically in twitter
  • how to auto publish to twitter
  • auto publish twitter
  • twitter auto publish
  • publish a twitter

About - Geoserv has been working with the Pligg CMS for 2+ years.

  • Raj Dotglum

    Hi – does the above code change work for Pligg v1.1.3?
    Thanks much for this nice promotional code hack.

  • http://www.themattresssuperstore.co.uk Memory Foam Mattress

    I have started a blog and I now want to market it. Does Facebook and Twitter allow me to market my website, and if so, how?Thanks a lot.

  • http://www.spinxwebdesign.com/ Web Design Los Angeles

    Great tutorial. It will be very beneficial that what we post in Pliggs, will automatically publish on Twitter. It will make a great marketing of blog post.

  • http://www.libertyforexchange.com Liberty Reserve

    This is an Excellent Tutorial. Thanks for the great Post.

  • http://www.lucaslabels.ie Printer consumables

    thanks..but i don’t use twitter.i am using facebook.

  • http://www.stellarinfo.com/outlook-pst-file-recovery.htm PST Recovery

    Thanks for imparting such important information at all. This post is also impressive one. My friend is sitting near me also appreciate your information and blog.

  • http://www.utilitysoftwarereviews.net driver detector

    Exactly what i was looking for thank you very much for the article.

  • http://www.themattresssuperstore.co.uk Memory Foam Mattress

    How do i create followers for my business without following?Is there a marketing company that does that?Thanks

  • http://www.collegesurvivalgear.com/ College Gear

    I have not tried to add the ability to auto add to twitter. Thanks this will help out with my marketing efforts.

  • http://www.collegesurvivalgear.com/ College Gear

    Just finished setting this up thanks for the help

  • http://www.hairup.gen.tr sac cikarici

    Türkçe dilinden İngilizce diline çeviri
    Almond, a tree species in the family Rosaceae, edible fruit. Unlike other members of the family can be found in almonds, sweet and succulent instead of an external environment is covered with a blanket, a ser of acceptance and in the shell is the edible part of the core.
    Almond tree is unique to southwest Asia, 4-9 feet, can reach long, lanceolate leaves and 5 of the crown is a type of white or light pink petals with a small tree. Was first grown in Mediterranean regions of wild state. Were cultured to be grown in northern regions.

    Almond Greece, Iran, Italy, Morocco, Portugal, Spain, Syria, Turkey and the United States are the main producers and the production of approximately 1.5 million tons.

    Almond oil, almond kernel is obtained by cold press method sıkılmasından, pale yellow in color, mild odor and taste of walnuts in a hard rain. Almond oil is a very positive effect on dry and cracked skin and removes roughness. Almond oil hair is also nutritious, prevents hair loss. Constipation has antioxidant properties. The almond oil is rich in antioxidant vitamin E, this feature is protective from many diseases and the effects of old age. In addition to these almond oil is applied to the abdominal region during pregnancy, after birth is known to inhibit the formation of cracks

    Almond oil, bitter or sweet type of amygdalus communis varyeterlerinin a yağdır.Badem bitter oil obtained from mature seeds in the cold sıkılmasıyla 8m.yükseklikte bitkidir.Badem oil a pale yellow color, mild odor and taste of walnuts a drogdur.

    The inside is used as a laxative, especially for babies. Outside of the softening, wound treatment, burn healing, hair gürleştirici bilinir.Orta era as the famous journey of Ibn Sina used in relieving thirst.

    However, in the 16th century in the 17th century Turkish physician in Nidai Nasrullah Salim bin sürüleceğini freckles on the face of the oil, almond oil is hot pain from ear to ear damlatılacağını, her hair back to gürleştirmesi sürüleceğini bildiler.Eski herbalists to obtain almond oil from the oil, almonds and crush stone mill fill the cans.

    Proposals such as the cutting of your hair color is also very important! Perçemin curly hair, thick hair too much and if you have short hair as a model yakışmaması sector, for reasons such as haircut regrets after cutting is as important as that can not be ignored. That suits you the most of your hair according to the type of hair cut model suggestions.

    Fine-wire and straight hair

    Shoulders, extend your hair down, cleverly cut your hair thicker layers showing the move saves. Also a good idea to a suitable fringe of your face. Bop to the hair-cutting model, revaşta which is a cut and the option to create a fine image can be from.

    Thick and hard hair

    The easiest type of hair but it requires continuous maintenance and control. Do not cut too short or the lawn guy is similar.

    Wavy hair

    Fine, residential stretches, so I completely cut and the length depends on the shape of the face. What a stretch, the waves is so low.

    Curly hair

    This shows the great variability in the structure of hair, but not limited to the options in front of you. Leave its natural state, look good and knitting, learn the techniques of style, such as mace or make plain. This last one requires a chemical process, will need to apply constant care to keep your hair healthy. Flattening process is the best professionals to leave

  • http://kpiultrasound.com/ Ultrasound machines

    I m looking for such type of coding in my account… Thanks for helping me out

  • Show_3

    good idea let’s see if it works. Follow @therealfrogs got some good tweets.