Tuesday, 3 December 2013

Rss Fetcher Wordpress and PHP

One of the most important topic that consumed my whole night to build a RSS Fetcher.This code will guide you to convert rss feed into Wordpress Posts.There are lots of plugins which provide this facility but none of them does their job completely.

Here is a sample rss feed from clipsyndicate.

<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:syndi="http://clipsyndicate.com/rss/extension/mobileplayer"version="2.0">






<atom:link type="application/rss+xml" href="http://chic.clipsyndicate.com/rss/feed/12235" rel="self"/>



<title>Video: Locals React to Paul Walker's Death</title>

<table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><a href="http://chic.clipsyndicate.com/video/playlist/12235/4780626?cpt=8&wpid=6474"><img src="http://video-static.clipsyndicate.com/zStorage/clipsyndicate/247/2013/12/02/02/29/yllttxabgqohbybsuhpo.jpg" width="120" height="90" border="0" /></a></td><td style="padding:5px;">Walker's neighbors placed flowers on the front porch of his Mesa home as a tribute.</td></tr></table>


<pubDate>Mon, 02 Dec 2013 01:59:52 +0000</pubDate>

<media:thumbnail url="http://video-static.clipsyndicate.com/zStorage/clipsyndicate/247/2013/12/02/02/29/yllttxabgqohbybsuhpo.jpg" height="90" width="120"/>

<media:title>Locals React to Paul Walker's Death</media:title>

Walker's neighbors placed flowers on the front porch of his Mesa home as a tribute.


<media:credit>KEYT Santa Barbara, CA</media:credit>

the community. 00-05 21-27 40-44 1:09-1:18 1:42-1:50 1:56-2:07 2:15-2:22trt - 2:38 nats "one of them is paul walkefrom the fast and the furious!." . it was supposed to be a quick joyride, but it ended in a fiery crash that killed actor and santa barbara resident paul walker and his friend roger rodas. nats of crash scene if any . walker and rodas were leaving a charity event justnorth of los angeles on saturday when their car wrecked. both were pronounced dead at the scene. sot jim torp/friend of walker "Paul wanted to go for a rideThat was the last that we saw of them." . rodas was behind the wheel and walker a passenger in the red porsche that apparently spun out of control and slammed into a tree and light pole. . walker's friends heard thecrash and tried desperately to put out the flames.. sot antonio HOLMES/friend There was nothing....we tried..we went thru fire extinguishers and...." . all that was left was the burned out wreckage..the carbarely recognizable... dissolve... NEWS OF HIS death spread quickly on social media and throughout santabarbara, where walker had a home. 30:56 LAUREL PEREZ he was just a very open sweet friendly guy. We'll miss him. 31:00 . walker's neighbors placed flowers on the front porch of his mesa home as a tribute. 32:05 LAUREL PEREZ it's a small token of our appreciation for himhumbleness and generosity to this community and to others." neighbors say even though walker was a celebrity, he was a part of the community.30:27 LAUREL PEREZ "He was very friendly. He really liked and engaged with the kids in the neighborhood. There are some fun stories teasing the boys as they wouldwalk the dogs past his house. 30:41 walker was often spotted AROUND TOWN. Nats bowling strike he was a regular at zodo's bowling alley in goleta. sot "steve davis/zodos" 26:0most of the people really knew who hewas.... the girls thought he was a nice looking man and went gaga over him"26:12 . THE 4 year-old's good looks made him one of hollywood's most bankablestars. . he rose to fame behind the wheels of fast cars in the blockbuster fast and furious movie franchise. nats from movie clips "Righ behind you."Universal Pictures "Fast an Furious 6" . WALKER WAS I the middle of filming the 7th installment ofthe series at the time of his death. . the l-a county coronersays because of the fiery collision, it will be awhile until he can positively identify the bodies. . sot ed winter/la county CORONER's officeIt's gonna take some time...dental and possible medical x-rays." . as the investigation into the crash continues, so does the shock over walker;s death...one that many say came WAY TOO SOON. Sot: 30:27 he was a great guy. We are all very saddened by his death. in santa barbara, alys martinez newschannel 3. . paul walker is survived byhis 15- year old daughter, meadow. . now

<iframe frameborder="0" scrolling="no" src="http://eplayer.clipsyndicate.com/embed/iframe?cpt=8&pf_id=6477&pl_id=12235&va_id=4780626&windows=1" width="320" height="280"></iframe>

<media:category label="cs_tickers"/>

<media:category label="cs_keywords">Paul Walker,Fast and Furious,Car Accident</media:category>

<media:category label="cs_categories">News,Local News,Entertainment,Movies,Celebrity</media:category>

<syndi:mobilePlayer url="http://play.syndi.tv/v1/player.html?pf_id=6477&va_id=4780626"/>


Here is the code which i used for fetching this rss and making it wordpress post

$rss = new DOMDocument();
$feed = array();

foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'media' => $node->getElementsByTagNameNS("*","description")->item(0)->nodeValue,
'tags' => $node->getElementsByTagNameNS("*","category")->item(1)->nodeValue,
'video' => $node->getElementsByTagName('guid')->item(0)->nodeValue,
'image' => $node->getElementsByTagName('thumbnail')->item(0) ? $node->getElementsByTagName('thumbnail')->item(0)->getAttribute('url') : ''
    array_push($feed, $item);
$limit =100;  <-------Set no. of post u want to make

for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
$video = $feed[$x]['video'];
$image = $feed[$x]['image'];
$excerpt = $feed[$x]['media'];
$tag = $feed[$x]['tags'];
$uri = $video;
$pieces = explode("/", $uri);
    $uri_3 = $pieces[5];
$frame= '<iframe frameborder="0" scrolling="no" src="http://eplayer.clipsyndicate.com/embed/iframe?pf_id=&show_title=0&va_id='.$uri_3.'&windows=1" width="620" height="420"></iframe>';

if($title!='' && $uri_3!=''){ <----------------Wordpress code to insert post $post_id = wp_insert_post(array ( 'post_title' => $title, 'post_content' =>$frame, 'post_status' => 'publish', 'post_author' => 1, 'tags_input' => $tag, 'post_excerpt'=> $excerpt, 'comment_status'=>'open', 'post_category' => array(760) )); if ($post_id) { // insert post meta add_post_meta($post_id, 'Featured Image', $image); add_post_meta($post_id, 'Video Link', $videolink); } }



Hope this helps.Thnks

No comments:

Post a Comment