1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP and my RSS feed. {need help}

Discussion in 'PHP' started by rurbaniak, May 19, 2005.

  1. #1
    Ok, I've been playing around with my RSS feed file for my blog because I want to be able to use <enclosure> tags without having to use a service like feedburner which can convert your normal RSS files with MP3's, Bit Torrents, etc. links in them to the enclosures.

    That being said, I have it coded right now to do this, but the <enclosure> always shows up no matter if there is a media file or not, and that is not what I want.

    So how it works is that it looks in the database in a field called [torrent] and uses that determine the name, and size of the file. Because the <enclosure> tags are hard coded it will always show up. So I need to build some kind of IF/THEN statement around it to check if $torrentfile == "" then DON'T ADD IT. and finish off the rest of the RSS file. Otherwise it should add it and finish the rest.

    See my code below, and where the <enclosure url= is where it needs to be, between the <item> tags.
    SEMrush
    Also heres my RSS Feed to see how it looks now. Notice the first <enclosure> doesn't have a file name at the end, like the second one does.

    I appreciate any help. Thanks.

    <?
    
    header("Content-type: text/xml\n\n");
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
    <rss version=\"2.0\">
    <channel>
    <title>$user[title]</title>
    <description>$user[description]</description>
    <link>$basepath1</link>
    <language>en-us</language>
    <generator>Blog</generator>
    ";
    
    $entries = mysql_query("SELECT * FROM bhost_entries WHERE u_id='$user[u_id]' AND privacy='3' AND draft='0' ORDER BY e_id DESC LIMIT $user[rss_entries]");
    while($entry = mysql_fetch_assoc($entries)) {
    $basepath2 = url("entry_rss", "$user[username]", "$entry[e_id]");
    $content = str_replace("'", "'", $entry['contents']);
    $title = str_replace("'", "'", $entry['title']);
    
    [B]$torrentfile = $entry['torrent'];[/B]
    
    $torrentsize = filesize('manager/torrents/'.$torrentfile);
      if($user[rss_html] == "0") {
      $content = strip_tags($content);
      $content = strip_tags($title);
      }
    $content = htmlspecialchars($content);
    $title = htmlspecialchars($title);
    echo "
    <item>
    <title>$title</title>
    <description>$content</description>
    <link>$basepath2</link>
    
    <enclosure url='$baseurl$torrentfile' length='$torrentsize' type='$torrenttype' />
    
    </item>
    ";
    }
    
    echo "
    </channel>
    </rss>";
    
    ?>
    PHP:
     
    rurbaniak, May 19, 2005 IP
    SEMrush
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    You are aware RSS is a fixed defined record and a custom record will not be parsed?

    You may need to use an XML feed for custom output that folks can read by your definition of the record.
     
    noppid, May 19, 2005 IP
  3. rurbaniak

    rurbaniak Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This currently parses, and validates fine according to Feed Validator. :confused:
     
    rurbaniak, May 19, 2005 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    Parsing the xml of the so called RSS and having the record correct for the RSS RFC are two different things.
     
    noppid, May 19, 2005 IP
  5. Stin

    Stin Guest

    Messages:
    264
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you just need to do some check such as, isset($torrent) or isnull($torrent) and if (isset($torrent)){ echo " <enclosure .. . . . > "; }

    something along those lines heh shouldnt be difficult
     
    Stin, May 19, 2005 IP