Rss & Php

Discussion in 'PHP' started by olli460, Jan 18, 2009.

  1. #1
    Hello,

    I was just wondering how it is possible to have a RSS feed from my database for the last 20 videos that have been added to the site.

    I can't understand how i can use the RSS page and use PHP to grab the info, i can do the RSS page manually but as soon as i put php in i get errors cos its a .rss file extension.

    Would be greatfull for any help
    Olli460
     
    olli460, Jan 18, 2009 IP
  2. SilverBulletUK

    SilverBulletUK Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you are using Apache as your webserver, you could use a .htaccess to force it to parse .rss as .php.

    .htaccess
    
    AddType application/x-httpd-php .rss
    
    Code (markup):
    :)
     
    SilverBulletUK, Jan 18, 2009 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    Magpie will read an RSS file and convert it to html if it is properly coded.

    But is that what you want to do? Why not query the DB using php and simply get the html version of the last 20 then you either could find or buy a script to convert it to RSS so that other can read it. Or continue to code it by hand.

    Maybe I misunderstood what you are trying to do.
     
    Colbyt, Jan 18, 2009 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    RewriteRule ^feed(\.rss)?/?$ feed.php [L,NC,QSA]

    Perhaps?
     
    Danltn, Jan 18, 2009 IP
  5. NinjaWork

    NinjaWork Guest

    Messages:
    132
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can try something like:

    domain.com/rss/top_20/

    and then .htaccess to redirect requests to the php file
     
    NinjaWork, Jan 18, 2009 IP
  6. SGBoise

    SGBoise Peon

    Messages:
    647
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I personally would recommend saving the rss to a xml file. If you think about if one person subribes to your rss then they will hit your site every few minutes. With every hit you're going to the database to retrieve the data even if it hasn't changed.

    If you times by 1,000 subscribers your server will slow down with unnecessary requests.
     
    SGBoise, Jan 18, 2009 IP
  7. olli460

    olli460 Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7

    So how do other sites with a rss feed get the php to load into a rss page. Im currently using an XML page but it dosent look nice lol.
     
    olli460, Jan 19, 2009 IP
  8. SGBoise

    SGBoise Peon

    Messages:
    647
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    They vary where some where some are dynamic and some use xml files. I'm pretty anal about efficiency. Getting data from the database is pretty expensive especially if the data doesn't change.

    Here is my code that I use for TopMediaScript. You can use this to write to one file. Let me know if something doesn't make sense and I'll can explain it.

    // Open the rss file for writing
    if (!$xmlfile = fopen("allmediafeed.xml", "w")) {
    	if ($rss_to_output = true) {
    		echo "Could not open allmediafeed.xml for writing.<br /><br />";
    	}
    	$tms->site_adminalerts(0, "Could not open allmediafeed.xml for writing.", "rss");
    	exit;
    }
    
    // Write the header
    fwrite($xmlfile,
    	"<rss version=\"2.0\">
    		<channel>
    			<title>{$tms->settings->sitetitle}</title>
    			<link>{$tms->paths->tms_url}{$tms->paths->tms_subfolderuri}</link>
    			<description>{$tms->settings->sitedescription}</description> 
    			<pubDate>".date("D, d M Y H:i:s O")."</pubDate>
    			<generator>http://www.topmediascript.com</generator>
    			<language>en</language>");
    
    foreach ($media_queue["mediaobjects"] as $media) {
    	// Ignore All adult media
    	if ($media->category->is_adult == false) {
    		$progressmsg .= "<br />Processing: id={$media->id} title={$media->title}";
    		$media->title = $tms->strip_html($media->title);
    		$media->description = $tms->strip_html($media->description);
    		
    		fwrite($xmlfile,
    			"<item>
    				<title>{$media->title}</title>
    				<link>{$tms->paths->tms_url}{$media->uri}</link>
    				<pubDate>{$media->submitdate}</pubDate>
    				<guid>{$media->id}</guid>
    				<description>{$media->description}</description>
    			</item>
    			");
    	}
    }
    
    fwrite($xmlfile,
    	"</channel>
    	</rss>");
    fclose($xmlfile);
    
    if ($rss_to_output == true) {
    	echo $progressmsg;
    	if ($msg != "") {
    		echo "<br /><br />The following errors occurred:<br />";
    		echo $msg;
    	}
    }
    PHP:
    The xml file looks like this:

    <rss version="2.0">
    	<channel>
    		<title>TopMediaScript.com - The ultimate multimedia site script</title>
    		<link>http://localhost/tms4/</link>
    		<description>The ultimate media site script for the webmasters wanting to run their own media web site.</description> 
    		<pubDate>Fri, 19 Dec 2008 11:39:43 -0700</pubDate>
    		<generator>http://www.topmediascript.com</generator>
    		<language>en</language><item>
    			<title>Test</title>
    			<link>http://localhost/tms4/mediaviewer/5655/test.html</link>
    			<pubDate>2008-12-19 11:34:38</pubDate>
    			<guid>5655</guid>
    			<description>Test</description>
    		</item>
    		<item>
    			<title>Redneck Shoot-Out</title>
    			<link>http://localhost/tms4/mediaviewer/5654/redneck-shoot-out.html</link>
    			<pubDate>2008-12-12 11:34:34</pubDate>
    			<guid>5654</guid>
    			<description>Eliminate all redneck by shooting them. Complete 3 levels of difficulty to win the game.</description>
    		</item>
    		<item>
    			<title>Flash Chess 3D</title>
    			<link>http://localhost/tms4/mediaviewer/5653/flash-chess-3d.html</link>
    			<pubDate>2008-12-12 11:34:34</pubDate>
    			<guid>5653</guid>
    			<description>3D Flash Chess with great AI opponent</description>
    		</item>
    	</channel>
    </rss>
    Code (markup):
     
    SGBoise, Jan 19, 2009 IP
  9. SGBoise

    SGBoise Peon

    Messages:
    647
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I forgot to mention that you can setup a cron job to run at certain times to regenerate the rss or code it in your script to run when are a new item added to your site.
     
    SGBoise, Jan 19, 2009 IP
  10. olli460

    olli460 Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hey,

    Thanks for posting that code but i don't really know where to start.

    I can get an XML file with these tags

    <video_title>
    <video_description>
    <video_url>
    <video_thumb>

    but how can i get these to go inside a normal looking rss page rather then the XML page

    thanks in advance
     
    olli460, Jan 20, 2009 IP
  11. SGBoise

    SGBoise Peon

    Messages:
    647
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #11
    SGBoise, Jan 20, 2009 IP