2009-10-24, 23:08:39
You can see it here http://www.manage-projects.ru
This is buildrss.php. I placed it in theme/yourthemename/plugins
I include it in function.php in theme.
Than in template.php i put next code
where first parametr - name of parent page for news for example.
second - quantity of items add in rss (it is not work yet )
third - qty of symbols in description.
I make cron task to generate rss file.
This is buildrss.php. I placed it in theme/yourthemename/plugins
Code:
<?php
// Begin Function
function createRSSFile($post_title,$post_description,$post_link,$guid)
{
$returnITEM = "<item>\n";
$returnITEM .= "<guid>".$guid."</guid>\n";
# this will return the Title of the Article.
$returnITEM .= "<title>".$post_title."</title>\n";
# this will return the Description of the Article.
$returnITEM .= "<description>".$post_description."</description>\n";
# this will return the URL to the post.
$returnITEM .= "<link>".$post_link."</link>\n";
$returnITEM .= "</item>\n";
return $returnITEM;
}
// rss_categories - category to rss
// items number
// lenght of descrip)
function buildrssfile($rss_categories,$itemsnumber,$descl)
{
if (empty($rss_categories)) { $rss_categories ='news'; }
if (empty($descl)) { $descl =256; }
if (empty($itemsnumber)) { $itemsnumber =5; }
$TITLE_OF_YOUR_RSS_FEED = "ãÿрðòûõýøõ ÿрþõúтðüø";
$DESCRIPTION_OF_YOUR_FEED = "Ã’ÑÂõ þñ уÿрðòûõýøø ÿрþõúтðüø ò þôýþü üõÑÂтõ";
$path = tsl('data/pages/');
$counter = '0';
$table = '';
//display all pages
$filenames = getFiles($path);
$count="0";
$pagesArray = array();
if (count($filenames) != 0) {
foreach ($filenames as $file) {
if (isFile($file, $path, 'xml')) {
$data = getXML($path .$file);
if ($data->parent == $rss_categories) {
$status = $data->menuStatus;
//$pagesArray[$count]['title'] = $data->title;
$pagesArray[$count]['title'] = html_entity_decode($data->title, ENT_QUOTES, 'UTF-8');
$pagesArray[$count]['parent'] = $data->parent;
$pagesArray[$count]['menuStatus'] = $data->menuStatus;
$pagesArray[$count]['private'] = $data->private;
$pagesArray[$count]['content'] = htmlspecialchars($data->content, ENT_QUOTES, 'UTF-8');
//$pagesArray[$count]['content'] = $data->content;
if ($data->parent != '') {
$parentdata = getXML($path . $data->parent .'.xml');
$parentTitle = $parentdata->title;
$pagesArray[$count]['sort'] = $parentTitle .' '. $data->title;
} else {
$pagesArray[$count]['sort'] = $data->title;
}
$pagesArray[$count]['url'] = $data->url;
$pagesArray[$count]['date'] = $data->pubDate;
$parentTitle = '';
$count++;
}
}
}
}
// Lets build the page
$filename = "feeds/index.xml";
$rootURL = "http://www.manage-projects.ru/feeds/";
$webroot = "http://www.manage-projects.ru/";
$latestBuild = date("r");
// Lets define the the type of doc we're creating.
$createXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$createXML .= "<rss version=\"0.92\">\n";
$createXML .= "<channel>
<title>".$TITLE_OF_YOUR_RSS_FEED."</title>
<link>".$rootURL."</link>
<description>".$DESCRIPTION_OF_YOUR_FEED."</description>
<lastBuildDate>".$latestBuild."</lastBuildDate>
<docs></docs>
<language>ru</language>
";
// Lets get the results
$ff=0;
while ($pagesArray[$ff]<>'') {
$item = $pagesArray[$ff];
if (empty($item['parent'])) {
$page = $webroot.$item['url'];
} else {
$page = $webroot.$item['parent']."/".$item['url'];
}
$pieces = explode(" ", $item['content']);
$feedcontent = '';
$rr=0;
while (strlen($feedcontent)<$descl) {
$feedcontent .= $pieces[$rr]." ";
$rr++;
}
$description = $feedcontent;
$title = $item['title'];
$guid = $item['date'];
$createXML .= createRSSFile($title,$description,$page,$guid);
$ff++;
}
$createXML .= "</channel>\n </rss>";
// Finish it up
$filehandle = fopen($filename,"w") or die("Can't open the file");
fwrite($filehandle,$createXML);
fclose($filehandle);
echo "XML Sitemap updated!";
}
?>
I include it in function.php in theme.
Code:
<?php
require_once('plugins/buildrss.php');
?>
Than in template.php i put next code
Code:
$generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}
where first parametr - name of parent page for news for example.
second - quantity of items add in rss (it is not work yet )
third - qty of symbols in description.
I make cron task to generate rss file.