Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate RSS channel file Yandex turbo for Aegea blogengine
<?
$db_user = ''; // db user name
$db_password = ''; // db pass
$db_database = ''; // db name
$db_host = 'localhost'; // db url
$domain = 'mopsicus.ru'; // domain
$title = '#mopsicus.ru – про Unity, игры и разработку'; // title for channel
$desc = 'Блог о Unity, разработке и личном опыте'; // desciption
$metrika = '123456789'; // metrika id counter
$author = 'Игорь Лопатин'; // author name
$db = new mysqli($db_host, $db_user, $db_password, $db_database);
$result = $db->query("SELECT * FROM `notes` WHERE IsPublished = 1 AND isvisible = 1 ORDER BY `Stamp` DESC LIMIT 1");
$row = $result->fetch_assoc();
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= "\n";
$xml .= '<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0">';
$xml .= "\n";
$xml .= '<channel>';
$xml .= "\n";
$xml .= "<title>$title</title>";
$xml .= "\n";
$xml .= "<link>https://$domain</link>";
$xml .= "\n";
$xml .= "<description>$desc</description>";
$xml .= "\n";
$xml .= '<language>ru</language>';
$xml .= "\n";
$xml .= "<turbo:analytics type=\"Yandex\" id=\"$metrika\"></turbo:analytics>";
$xml .= "\n";
$xml .= '<item turbo="true">';
$xml .= "\n";
$xml .= "<link>https://$domain</link>";
$xml .= "\n";
$xml .= "<pubDate>".date('r', $row['LastModified'])."</pubDate>";
$xml .= "\n";
$xml .= "<author>$author</author>";
$xml .= "\n";
$xml .= '<turbo:content>';
$xml .= "\n";
$xml .= '<![CDATA[';
$xml .= "\n";
$xml .= "<header>";
$xml .= "\n";
$xml .= "<h1>#$domain</h1>";
$xml .= "\n";
$xml .= "<h2>$desc</h2>";
$xml .= "\n";
$xml .= "<figure>";
$xml .= "\n";
$xml .= "<img src=\"https://$domain/user/userpic@2x.jpg\"/>";
$xml .= "\n";
$xml .= "</figure>";
$xml .= "\n";
$xml .= "<menu>";
$xml .= "\n";
$xml .= "<a href=\"https://$domain/selected/\">Избранное</a>"; // custom menu, could be removed
$xml .= "\n";
$xml .= "<a href=\"https://$domain/all/\">Все заметки</a>";
$xml .= "\n";
$xml .= "<a href=\"https://$domain/all/monthly-newsletter-unity/\">Рассылка</a>";
$xml .= "\n";
$xml .= "<a href=\"http://github.com/mopsicus\">Мой Github</a>";
$xml .= "\n";
$xml .= "<a href=\"https://$domain/tags/projects/\">Проекты</a>";
$xml .= "\n";
$xml .= "<a href=\"https://$domain/all/about/\">Обо мне</a>";
$xml .= "\n";
$xml .= "</menu>";
$xml .= "\n";
$xml .= "</header>";
$xml .= "\n";
$result = $db->query("SELECT * FROM `notes` WHERE IsPublished = 1 AND isvisible = 1 ORDER BY `Stamp` DESC LIMIT 10");
while ($row = $result->fetch_assoc()) {
$body = iconv('windows-1251', 'UTF-8', $row['Text']);
$title = htmlspecialchars (iconv('windows-1251', 'UTF-8', $row['Title']), ENT_NOQUOTES);
$xml .= "<h3>$title</h3>";
$body = nl2br($body, false);
$body = '<p>' . preg_replace('#(<br>[\r\n\s]+){2}#', "</p>\n\n<p>", $body) . '</p>';
$xml .= $body;
$xml .= "<br /><br />\n";
}
$xml .= "\n";
$xml .= ']]>';
$xml .= "\n";
$xml .= '</turbo:content>';
$xml .= "\n";
$xml .= '</item>';
$xml .= "\n\n";
$result = $db->query("SELECT * FROM `notes` WHERE IsPublished = 1 AND isvisible = 1");
while ($row = $result->fetch_assoc()) {
$page = $row['OriginalAlias'];
$title = htmlspecialchars (iconv('windows-1251', 'UTF-8', $row['Title']), ENT_NOQUOTES);
$body = iconv('windows-1251', 'UTF-8', $row['Text']);
$xml .= '<item turbo="true">';
$xml .= "\n";
$xml .= "<link>https://$domain/all/$page</link>";
$xml .= "\n";
$xml .= "<pubDate>".date('r', $row['LastModified'])."</pubDate>";
$xml .= "\n";
$xml .= "<author>$author</author>";
$xml .= "\n";
$xml .= '<turbo:content>';
$xml .= "\n";
$xml .= '<![CDATA[';
$xml .= "\n";
$xml .= "<header>";
$xml .= "\n";
$xml .= "<h1>$title</h1>";
$xml .= "\n";
$xml .= "</header>";
$xml .= "\n";
$body = nl2br($body, false);
$body = '<p>' . preg_replace('#(<br>[\r\n\s]+){2}#', "</p>\n\n<p>", $body) . '</p>';
$xml .= $body;
$xml .= "\n";
$xml .= ']]>';
$xml .= "\n";
$xml .= '</turbo:content>';
$xml .= "\n";
$xml .= '</item>';
$xml .= "\n\n";
}
$xml .= "\n";
$xml .= '</channel>';
$xml .= "\n";
$xml .= '</rss>';
$db->close();
$fp = fopen('/home/turbo.xml', 'w'); // path to xml file
fwrite($fp, $xml);
fclose($fp);
echo 'ok';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.