<pubDate> tag in RSS Feed

Discussion in 'XML & RSS' started by maihannijat, Mar 15, 2011.

  1. #1
    Hello,

    I have RSS XMl feed but I want to improve it more with adding <pubDate> tag in it to differentiate between posts.

    Here is my complete rss code:

    
    <?php
    
    session_start();
    include("include/config.php");
    include("include/functions/import.php");
    $thebaseurl = $config['baseurl'];
    
    $getfilter = htmlentities(strip_tags($_REQUEST[filter]));
    $filter = escape($getfilter);
    $showmax = $config['max_syndicate_results'];
    
    if ($filter =="0")
    {
    	$query = "SELECT * from docs where public='1' AND active='1' order by time_added desc limit $showmax";
    	$showtitle = "$lang[674]";
    	$link   = $config['baseurl']."/syndicate/docs/0/$lang[174]"; 
    }
    elseif ($filter =="1")
    {
    	$query = "SELECT * from docs where public='1' AND active='1' order by viewcount desc limit $showmax";
    	$showtitle = "$lang[675]";
    	$link   = $config['baseurl']."/syndicate/docs/1/$lang[178]";
    }
    elseif ($filter =="2")
    {
    	$query = "SELECT * from docs where public='1' AND active='1' order by rating desc limit $showmax";
    	$showtitle = "$lang[676]";
    	$link   = $config['baseurl']."/syndicate/docs/2/$lang[179]";
    }
    elseif ($filter =="3")
    {
    	$query = "SELECT * from docs where public='1' AND active='1' order by commentcount desc limit $showmax";
    	$showtitle = "$lang[677]";
    	$link   = $config['baseurl']."/syndicate/docs/3/$lang[180]";
    }
    elseif ($filter =="4")
    {
    	$query = "SELECT * from docs where public='1' AND active='1' order by favoritecount desc limit $showmax";
    	$showtitle = "$lang[678]";
    	$link   = $config['baseurl']."/syndicate/docs/4/$lang[182]";
    }
    elseif ($filter =="6")
    {
    	$query = "SELECT * from docs where public='1' AND active='1' AND featured='1' order by time_added desc limit $showmax";
    	$showtitle = "$lang[215]";
    	$link   = $config['baseurl']."/syndicate/docs/6/$lang[53]";
    }
    
    
    header("Content-Type: text/xml"); 
    header("Expires: 0"); 
    print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; 
    print "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\">\n"; 
    print "<channel>\n"; 
    print "<title>".$showtitle." - ".$config['site_name']."</title>\n"; 
    print "<link>$link</link>\n"; 
    print "<description>".$showtitle."</description>\n"; 
    
    $db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($DBNAME); 
      
    $result = mysql_query($query) or die ('Query Error: ' . mysql_error()); 
    while ($results = mysql_fetch_array($result)) 
    { 
      $thumbnail       = $config['thumburl']."/".$results['DID'].".jpg"; 
      $video       = $config['baseurl']."/docs/".$results['DID']."/".seo_clean_titles_sendmail($results['title']); 
      $description = str_replace ("&amp","",htmlspecialchars(stripslashes($results['description']))); 
      
      $query="SELECT username FROM members WHERE USERID='".mysql_real_escape_string($results[USERID])."'";
      $executequery=$conn->execute($query);
      $getusername = $executequery->fields[username];
    		
    	print "<item>\n"; 
    	print "  <title>".$results['title']."</title>\n";
    	print "  <link>".$video."</link>\n"; 
    	print "  <description>\n"; 
    	print "    <![CDATA["; 
    	print "<img src=\"$thumbnail\" align=\"right\" border=\"0\" width=\"170\" height=\"120\" vspace=\"5\" hspace=\"5\"/>".$description."<br><br>$lang[672]: <a href=\"$config[baseurl]/members/profile/$results[USERID]/$getusername\">$getusername</a>"; 
      		
    
    	
    	print "<br />Pubplication Date: <pubDate>";
    	$query="SELECT date_added FROM docs WHERE DID='".mysql_real_escape_string($results['DID'])."'";
    	$executequery=$conn->execute($query);
    	$list=explode('-',$executequery->fields[date_added]);
    	print_r($list[2]);print_r('-');
    	print_r($list[1]);print_r('-');
    	print_r($list[0]);
    	
    	print "</pubDate>\n";
    	
    		
    	
    	$query = "select name from categories_docs WHERE CATID='".mysql_real_escape_string($results['categories'])."' limit 1"; 
    	$executequery = $conn->execute($query);
    	$category = $executequery->fields[name];
    	
    	print "<br>$lang[218]: $category<br/>$lang[325]: "; 
    	$gettags = strtok($results[tags], " "); 
      	while ($gettags !== false) 
      	{ 
        	print "<a href=\"$config[baseurl]/search/docs/a/0/".$gettags."\">".$gettags."</a> "; 
        	$gettags = strtok(" "); 
      	} 
    	
    	print "<br>$lang[60]: $results[viewcount] | $lang[63]: $results[commentcount]";
    	
    	
    	
    	print "<br/><br/><br /><hr>"; 
    	print "    ]]>\n"; 
    	print "  </description>\n"; 
    	print "  <author>".$getusername."</author>\n"; 
    	print "</item>\n"; 
    } 
    mysql_close(); 
    print "</channel>\n"; 
    print "</rss>"; 
    ?> 
    
    Code (markup):
    I tried to add pubDate tag here but didn't work:
    
    print "<br />Pubplication Date: <pubDate>";
    	$query="SELECT date_added FROM docs WHERE DID='".mysql_real_escape_string($results['DID'])."'";
    	$executequery=$conn->execute($query);
    	$list=explode('-',$executequery->fields[date_added]);
    	print_r($list[2]);print_r('-');
    	print_r($list[1]);print_r('-');
    	print_r($list[0]);
    	
    	print "</pubDate>\n";
    
    Code (markup):

    you can access RSS FEED with this link

    http://www.chaptersworld.com/syndicate/docs/0/RecentlyAdded

    any help will be highly appreciate it.
     
    maihannijat, Mar 15, 2011 IP
  2. Theah

    Theah Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You've placed the <pubDate></pubDate> tags inside the <description></description> tag. You should not do that. It should be outside like the <author> tag.

    Put it right above this line:

    print "  <author>".$getusername."</author>\n"; 
    
    Code (markup):
    Also, just put the tag. I see you also have a "Pubplication Date:" label - that is unnecessary. Rss readers will know how to display it.
     
    Last edited: Mar 17, 2011
    Theah, Mar 17, 2011 IP
  3. maihannijat

    maihannijat Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Hello

    I have done what you said, but it doesn't appear now in xml page but when i check page source there is pubdate tags with data.
     
    maihannijat, Mar 18, 2011 IP
  4. Theah

    Theah Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You have a <br /> tag in the xml. This should be inside the description tag, because it's HTML.
     
    Theah, Mar 18, 2011 IP
  5. maihannijat

    maihannijat Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    Same issue again, i removed br tag from it. and I can see date in page source but not in xml page.
     
    maihannijat, Mar 18, 2011 IP
  6. Theah

    Theah Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Good news is the XML looks right now! Bad news is you have to put the Date in a very specific format...

    It needs to be like this:

    Wed, 04 Feb 2008 13:00:00 GMT
    or
    Wed, 04 Feb 2008 15:00:00 +0200

    Google "RSS date specification" and follow the second link titled "Correct RSS date format « Life in the startup lane" to learn more. I would give you a link, but I'm not allowed to in this forum yet.
     
    Theah, Mar 18, 2011 IP
  7. maihannijat

    maihannijat Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    Thank you for quick reply.

    I fetch date with this code, how can I change format of date in following code?

    print "<pubDate>";
    	$query="SELECT date_added FROM docs WHERE DID='".mysql_real_escape_string($results['DID'])."'";
    	$executequery=$conn->execute($query);
    	$list=explode('-',$executequery->fields[date_added]);
    	print_r($list[2]);print_r('-');
    	print_r($list[1]);print_r('-');
    	print_r($list[0]);
    	
    	print "</pubDate>\n";
    
    
    Code (markup):
     
    maihannijat, Mar 18, 2011 IP
  8. Theah

    Theah Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You will have to find a PHP script that does the conversion or write it yourself.

    I'm sure other people have done this before in PHP and made it free and available somewhere. I don't write PHP often, so I can't help you there.
     
    Theah, Mar 18, 2011 IP
  9. vinoth.t

    vinoth.t Peon

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    pubDate Should be in <pubDate>Thu, 24 Mar 2011 01:30:50 +0530</pubDate> format.
    You can convert the mysql function to above format using the php function date_format($datetime, DATE_RFC2822)
    Here the example that will be helpful for you
    Create RSS Feed PHP
     
    vinoth.t, Mar 23, 2011 IP
  10. maihannijat

    maihannijat Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #10
    Hello,

    I tried integrating this code <pubDate><?=date_format($datetime, DATE_RFC2822)?></pubDate> in my rss feed, but couldn't able.

    anyone could tell me how to do this?
     
    maihannijat, Mar 23, 2011 IP
  11. vinoth.t

    vinoth.t Peon

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I think replace $datetime with $row[4]. Make sure $row[4] should be mysql timestamp format
     
    vinoth.t, Mar 23, 2011 IP