XML2JSON callback PHP

XML2JSON callback PHP

by zachreynolds

HTML

<form id="rssForm" action="fichier.php" method="post">
  <label for="pseudo">RSS URL</label>
  <input type="text" id="rssurl" name="rssurl" size="45" value="http://feeds.feedburner.com/tedtalks_video" />
  <input type="submit" id="envoyer" value="Fetch RSS" />
</form>
<div id="result"></div>

CSS

img {
  max-width: 100%;
  height: auto;
  /* max-height: 228px; */
  margin: 12px 0;
}

iframe {
  max-width: 100%;
}

.favicon {
  height: 16px;
  width: auto;
  vertical-align: middle;
  margin-right: 6px;
}

JavaScript

$(document).ready(function() {

  $('#rssForm').on('submit', function(e) {
    e.preventDefault(); // J'empêche le comportement par défaut du navigateur, c-à-d de soumettre le formulaire

    //var $this = $(this);
    var rssfeed = $('#rssurl').val();

    getfeed(rssfeed);

  });
});


function getfeed(rssfeed) {

  var itemenclosure = '';

  //alert(rssfeed);

  $.ajax({
    url: 'http://feedsocial.com/lab/rss/XML2JSON/GC-XML-TO-JSON/xml-to-json-callback.php',
    method: 'GET',
    dataType: 'jsonP',
    data: {
      url: rssfeed,
      //url: 'https://www.rt.com/rss',
      //api_key: 'z6hgvtruazf0ghcv27xrgo6ieyznezyet0i9khad', // put your api key here
      // count: 5
    }
  }).done(function(data) {
    //if(data.status != 'ok'){ throw data.message; }

    var feedimage = "";

    var channel = data.rss.channel;

    if (channel.hasOwnProperty('image')) {
      //itemenclosure = item.enclosure.url;
      feedimage = '<img class="favicon" src="' + channel.image.url + '" >';
    }

    $('#result').html('<h2>' + feedimage + channel.title + '</h2>');
    //$('#result').html('<h2>' + data.channel.title + '</h2>');

    console.log('====== title ' + channel.title + ' ======');
    console.log('====== description ' + channel.description + ' ======');
    console.log('====== author ' + channel.author + ' ======');
    console.log('====== iTune author ' + channel['itunes:author'] + ' ======');
    //console.log('====== url ' + data.url + ' ======');
    console.log('====== link ' + channel.link + ' ======');
    console.log('====== lastBuildDate ' + channel.lastBuildDate + ' ======');
    console.log('====== language ' + channel.language + ' ======');


    $.each(data.rss.channel.item, function(i, item) {

      // Enclosure error handling
      if (item.hasOwnProperty('enclosure')) {
      
        if (item.enclosure.type == 'audio/mpeg' || item.enclosure.type == 'audio/ogg')
          itemenclosure = '<br><audio controls><source src="' + item.enclosure.url +...