tuzlatuning adlı üyeden alıntı:
mesajı görüntüle
12
●110


<?php
header("Content-Type: application/xml; charset=UTF-8" , true);
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
date_default_timezone_set('UTC');
define('slash','/yazi/');
$url = 'https://'.$_SERVER['HTTP_HOST'];
$rss = new rss;
$rssTitle = 'Latest Updates';
$rssDescription = 'Get Latest Updates Of This Site';
$rss->head($rssTitle,$rssDescription,$url);
$date1 = $_REQUEST['date'];
echo date('D, d M Y H:i:s T', strtotime($date1));
$query = "SELECT * FROM news ORDER BY id";
if ($result = mysqli_query($rss->conn(), $query)) {
while ($row = mysqli_fetch_assoc($result)) {
$link = $url.slash.rss::clean($row['news_name']);
$baslik = ($row['news_name']);
$date= date("D, d M Y H:i:s T", $row['date']);
if (preg_match('/^.{1,500}\b/s', $row['news_description'], $match))
{
$description=$match[0].'...';
}
rss::feed(htmlspecialchars($row['date']),$link,htmlspecialchars($description),$date,);
}
mysqli_free_result($result);
}
$rss->foot();
$rss->close();
class rss
{
public $conn;
public function __construct()
{
if(!$this->conn())
{
die('Failed to connect with MySQL');
self::close();
}
}
public function conn()
{
$host = "localhost";
$user = "---";
$pass = "---";
$name = "----";
$conn = mysqli_connect($host,$user,$pass,$name);
if (mysqli_connect_errno())
{
die("Failed to connect with MySQL: ".mysqli_connect_error());
}
else
{
return $this->conn = $conn;
}
}
public function head($description,$siteurl)
{
echo '<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">';
echo '<channel>';
echo '<title>'.$rssTitle.'</title>';
echo '<link>'.$siteurl.'</link>';
echo '<description>'.$description.'</description>';
echo '<language>en-us</language>';
echo '<atom:link href="'.$siteurl.'/rss.xml" rel="self" type="application/rss+xml"/>';
}
public function feed($news_name,$url,$description,$date)
{
echo '
<item>
<lastBuildDate>'.$news_name.'</lastBuildDate>
<link>'.$url.'</link>
<description>'.$description.'</description>
<title>'.$baslik.'</title>
</item>
';
}
public function foot()
{
echo '</channel>';
echo '</rss>';
}
public function clean($string) {
$string = strtolower( preg_replace('@[\W_]+@', '-', $string) );
$string = rtrim($string,'-');
$string = strtolower($string);
return $string;
}
public function close()
{
mysqli_close(self::conn());
}
}
?>