- Database connection file(db.php)
- Linking Html file(rss.html)
- rssVideo.php file for generate rss feed xml file
- htaccess file for url rewriting
first file:-db.php
DEFINE('HOSTNAME','localhost');
DEFINE('USERNAME','root');
DEFINE('PASSWORD','');
DEFINE('DATABASE','tbc_main');
//End of Constraint Declaration.
/*
Function for DataBase Connection
$dbc variable for database connection
*/
$dbc=mysql_connect(HOSTNAME,USERNAME,PASSWORD) or die('There is error to connect to server:-'.mysqli_connect_error());
$db_selected = mysql_select_db(DATABASE,$dbc);
function getUserName($id,$dbc){
$getUserName="select user_name,user_id from users where user_id=$id";
$userNameResult=mysql_query($getUserName,$dbc)or die('Error in get User Name'.mysql_error());
$name=mysql_fetch_array($userNameResult);
return($name[0]);
}
function getVideoName($id){
return(substr(md5($id),0,15));
}
second file : rss.html
<html>
<ul>
<li><a href="http://www.sitename.com/rss/newadded.html">
<div style="float:left; width:100px; height:20px;">New Video </div>
</a></li>
<li><a href="http://www.sitename.com/rss/mostview.html">
<div style="float:left; width:100px; height:20px;">Most view </div>
</a></li>
<?php
include_once(db.php);
$selVideoCat="select video_category_id,video_category_name from video_category where video_category_status='Yes'";
$catRs=mysql_query($selVideoCat,$dbc);
while($row=mysql_fetch_array($catRs)){
echo '<li">
'.$row["video_category_name"].'</a>
<a href="http://sitename.com/rss/guru/'.$row["video_category_id"].'.html"></a></li>';
?>
</ul>
</html>
third file:rssvideo.php
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=iso-8859-1");
include_once('db.php');
$cat=$_REQUEST['cate']; //get which type of video require
$value=$_REQUEST['value'];//value to match for fetching video
switch($cat){
case 'newadded':
$where="where video_status='Ok' order by video_id DESC limit 0,50";
break;
case 'mostview':
$where="where video_status='Ok' order by total_views DESC limit 0,50";
break;
case'cate':
$where="where video_status='Ok' and video_category_id=$value order by video_id DESC limit 0,500";
break;
}
if(isset($cat)){
$rss="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
$rss .= '<!-- Generated on ' . date('r') . ' -->' . "\n";
$rss .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
$rss .= ' <channel>' . "\n";
$rss .= ' <atom:link href="http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'" rel="self" type="application/rss+xml" />' . "\n";
$rss .= ' <title>sitename Videos </title>' . "\n";
$rss .= ' <link>http://www.sitename.com/videoCategory.php</link>' . "\n";
$rss .= ' <description>sitename is the best place to one with great guru pravchan and their bhajan</description>' . "\n";
$rss .= ' <language>en-us </language>' . "\n";
$sql="select * from video ".$where;
$result=mysql_query($sql,$dbc) or die('Feed Error:-'.mysql_error());
while($row=mysql_fetch_array($result)){
$rss.="<item>\n";
$rss.="<title>".$row['video_title']."</title>\n";
$rss.="<link>http://www.sitename.com/viewVideo.php?video_id=".$row['video_id']."</link>\n";//page path (link) to view that perticular video on website
$rss.="<description><![CDATA[
<img src=\"http://www.sitename.com/files/videos/thumbnails/".getVideoName($row['video_id']).'S.jpg'."\" align=\"right\" border=\"0\" width=\"120\" height=\"90\" vspace=\"4\" hspace=\"4\" />// video thum location on server
<p>".$row['video_title']."</p>
<p>
".$row['video_tags']."<br/>
Added:".$row['date_added']."<br/>
</p>
]]></description>\n";
$rss.="<guid isPermaLink=\"true\">http://www.sitename.com/viewVideo.php?video_id=".$row['video_id']."</guid>\n";
$rss.="<pubDate>".gmdate('D, d M Y H:i:s \G\M\T',$row['date_added'])."</pubDate>\n"; //video add date according to rss rules
$rss.="</item>\r";
}
$rss.="</channel>\r";
$rss.="</rss>";
echo $rss;
}
?>
forth file : .htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/([0-9]+)\.html$ rssvideo.php?cate=$1&value=$2 [NC,L]
RewriteRule ^(.*)\.html$ rssvideo.php?cate=$1 [NC,L]
No comments:
Post a Comment