2015-04-02 13:41:05 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura News Page
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare Namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Use DOMDocument
|
|
|
|
use DOMDocument;
|
|
|
|
|
2015-04-02 13:41:05 +00:00
|
|
|
// Include components
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
2015-04-02 13:41:05 +00:00
|
|
|
|
2015-09-11 23:31:54 +00:00
|
|
|
// Create a new News object
|
2015-11-06 22:30:37 +00:00
|
|
|
$news = new News(isset($_GET['cat']) ? $_GET['cat'] : Config::getConfig('site_news_category'));
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-11 22:20:19 +00:00
|
|
|
// News XML feed
|
2015-09-14 20:51:23 +00:00
|
|
|
if (isset($_GET['xml'])) {
|
2015-09-11 23:31:54 +00:00
|
|
|
// Get the news posts
|
2015-11-15 21:43:39 +00:00
|
|
|
$posts = $news->posts;
|
2015-09-11 23:31:54 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Meta data attributes
|
|
|
|
$metaData = [
|
2015-11-06 22:30:37 +00:00
|
|
|
'title' => ($_FEED_TITLE = Config::getConfig('sitename')) . ' News',
|
|
|
|
'link' => ($_FEED_URL = 'http://' . Config::getConfig('url_main')),
|
2015-09-14 20:51:23 +00:00
|
|
|
'description' => 'News about ' . $_FEED_TITLE,
|
|
|
|
'language' => 'en-gb',
|
2015-11-06 22:30:37 +00:00
|
|
|
'webMaster' => Config::getConfig('admin_email') . ' (' . $_FEED_TITLE . ' Webmaster)',
|
2015-10-10 21:17:50 +00:00
|
|
|
'pubDate' => ($_FEED_DATE = date('r', $posts[array_keys($posts)[0]]['news_timestamp'])),
|
2015-09-14 20:51:23 +00:00
|
|
|
'lastBuildDate' => $_FEED_DATE,
|
2015-05-23 03:31:42 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Item attributes
|
|
|
|
$itemData = [
|
2015-10-10 21:17:50 +00:00
|
|
|
'title' => ['text' => '0', 'eval' => '$post["news_title"]'],
|
|
|
|
'link' => ['text' => $_FEED_URL . (new Urls())->format('SITE_NEWS_POST', ['0']), 'eval' => '$post["news_id"]'],
|
|
|
|
'guid' => ['text' => $_FEED_URL . (new Urls())->format('SITE_NEWS_POST', ['0']), 'eval' => '$post["news_id"]'],
|
|
|
|
'pubDate' => ['text' => '{EVAL}', 'eval' => 'date("D, d M Y G:i:s O", $post["news_timestamp"])'],
|
2015-11-07 22:58:02 +00:00
|
|
|
'dc:publisher' => ['text' => '0', 'eval' => '$post["news_poster"]->username()'],
|
2015-10-10 21:17:50 +00:00
|
|
|
'description' => ['cdata' => '0', 'eval' => '$post["news_content_parsed"]'],
|
2015-05-23 03:31:42 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Create a new DOM document
|
|
|
|
$feed = new DOMDocument('1.0', 'utf-8');
|
|
|
|
|
|
|
|
// Create the RSS element
|
|
|
|
$fRss = $feed->createElement('rss');
|
|
|
|
|
|
|
|
// Set attributes
|
2015-09-14 20:51:23 +00:00
|
|
|
$fRss->setAttribute('version', '2.0');
|
|
|
|
$fRss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
|
|
|
|
$fRss->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1');
|
2015-05-23 03:31:42 +00:00
|
|
|
|
|
|
|
// Create the channel element
|
|
|
|
$fChannel = $feed->createElement('channel');
|
|
|
|
|
|
|
|
// Build meta elements
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($metaData as $name => $value) {
|
2015-05-23 03:31:42 +00:00
|
|
|
// Create the elements
|
2015-09-14 20:51:23 +00:00
|
|
|
$mElem = $feed->createElement($name);
|
|
|
|
$mElemText = $feed->createTextNode($value);
|
2015-05-23 03:31:42 +00:00
|
|
|
|
|
|
|
// Append them
|
2015-09-14 20:51:23 +00:00
|
|
|
$mElem->appendChild($mElemText);
|
|
|
|
$fChannel->appendChild($mElem);
|
2015-05-23 03:31:42 +00:00
|
|
|
|
|
|
|
// Unset the working vars
|
|
|
|
unset($mElem);
|
|
|
|
unset($mElemText);
|
|
|
|
}
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Add all the posts
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($posts as $post) {
|
2015-05-23 03:31:42 +00:00
|
|
|
// Create item element
|
|
|
|
$fPost = $feed->createElement('item');
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Create post attributes
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($itemData as $tag => $valueData) {
|
2015-05-23 03:31:42 +00:00
|
|
|
// Create the element
|
|
|
|
$pElem = $feed->createElement($tag);
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Create value
|
2015-09-14 20:51:23 +00:00
|
|
|
eval('$value = ' . $valueData['eval'] . ';');
|
2015-09-14 21:41:43 +00:00
|
|
|
$value = str_replace(
|
2015-10-10 21:17:50 +00:00
|
|
|
'0',
|
2015-09-14 21:41:43 +00:00
|
|
|
$value,
|
|
|
|
$valueData[(array_key_exists('cdata', $valueData) ? 'cdata' : 'text')]
|
|
|
|
);
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Create text node or cdata container
|
2015-09-14 21:41:43 +00:00
|
|
|
$pElemText = (array_key_exists('cdata', $valueData)) ?
|
|
|
|
$feed->createCDATASection($value) :
|
|
|
|
$feed->createTextNode($value);
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Append them
|
2015-09-14 20:51:23 +00:00
|
|
|
$pElem->appendChild($pElemText);
|
|
|
|
$fPost->appendChild($pElem);
|
2015-05-23 03:31:42 +00:00
|
|
|
|
|
|
|
// Unset the working vars
|
|
|
|
unset($pElem);
|
|
|
|
unset($pElemText);
|
|
|
|
unset($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the item to the channel
|
|
|
|
$fChannel->appendChild($fPost);
|
2015-04-02 14:25:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Append the channel element to RSS
|
|
|
|
$fRss->appendChild($fChannel);
|
|
|
|
|
|
|
|
// Append the RSS element to the DOM
|
|
|
|
$feed->appendChild($fRss);
|
2015-04-02 14:25:35 +00:00
|
|
|
|
2015-05-23 03:31:42 +00:00
|
|
|
// Return the feed
|
|
|
|
print $feed->saveXML();
|
2015-04-02 14:25:35 +00:00
|
|
|
exit;
|
|
|
|
}
|
2015-04-02 13:41:05 +00:00
|
|
|
|
2015-09-11 23:31:54 +00:00
|
|
|
$renderData = array_merge($renderData, [
|
2015-09-14 20:51:23 +00:00
|
|
|
'news' => $news,
|
2015-11-06 22:30:37 +00:00
|
|
|
'postsPerPage' => Config::getConfig('news_posts_per_page'),
|
2015-09-14 20:51:23 +00:00
|
|
|
'viewPost' => isset($_GET['id']),
|
|
|
|
'postExists' => $news->postExists(isset($_GET['id']) ? $_GET['id'] : 0),
|
2015-09-11 23:31:54 +00:00
|
|
|
]);
|
2015-07-31 21:18:14 +00:00
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Initialise templating engine
|
|
|
|
$template = new Template();
|
|
|
|
|
|
|
|
// Change templating engine
|
|
|
|
$template->setTemplate($templateName);
|
|
|
|
|
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
2015-04-02 13:41:05 +00:00
|
|
|
// Print page contents
|
2015-11-06 22:30:37 +00:00
|
|
|
echo $template->render('main/news.tpl');
|