From db6afedd867b44f3a1bbe0ee1e0dc9855db5fafc Mon Sep 17 00:00:00 2001 From: ThibmoRozier Date: Fri, 18 Dec 2015 01:01:38 +0100 Subject: [PATCH 1/5] Feature(RSS): First implementation of RSS2.0 and ATOM feed. As put in the issues sections there was once a RSS feed. ( #75 ) Right now it is a fairly basic implementation of both RSS and ATOM feeds, as these are most commonly used. Right now it does not use UIDs for feeds, might be added later on. This commit: * Adds a RSS2.0 standard feed implementation * Adds a ATOM 2005 standard feed implementation ( Without UIDs ) * Adds a CSS file for browsers that do not support RSS * Adds a table to the chema * Adds test data for the table --- files/class.rss.php | 148 +++++++++++++++++++++++++++++++++++++++++ html/files/css/rss.css | 77 +++++++++++++++++++++ html/rss/atom.php | 9 +++ html/rss/rss.php | 9 +++ sql/schema.sql | 12 ++++ sql/testdata.sql | 10 +++ 6 files changed, 265 insertions(+) create mode 100644 files/class.rss.php create mode 100644 html/files/css/rss.css create mode 100644 html/rss/atom.php create mode 100644 html/rss/rss.php diff --git a/files/class.rss.php b/files/class.rss.php new file mode 100644 index 0000000..149d14a --- /dev/null +++ b/files/class.rss.php @@ -0,0 +1,148 @@ +getConstants())) + throw IllegalArgumentException(); + + $this->value = $value; + } + + final public function __toString() { + return $this->value; + } + } + + class feedType extends enumBase { + const ATOM = "atom"; + const RSS = "rss"; + } + + class feedCategory extends enumBase { + const ARTICLE = "Article"; + const FORUM = "Forum"; + const NEWS = "News"; + } + + class rss { + public function __construct() { + //load configuration file + require('config.php'); + + if (!isset($config) || !is_array($config)) + throw new Exception('Config error'); + + $this->config = $config; + $this->connectDB($this->config['db'], false); + } + + /** + * Create database connection + * + * @param object $config Databse connection config + * @param boolean $debug Should the connection ignore errors or throw exceptions + * + * @return void + * + * @todo Create site config option that is passed in to the debug param + */ + protected function connectDB($config, $debug=true) { + // Connect to database + try { + $dsn = "{$config['driver']}:host={$config['host']}"; + $dsn .= (!empty($config['port'])) ? ';port=' . $config['port'] : ''; + $dsn .= ";dbname={$config['database']}"; + $this->db = new PDO($dsn, $config['username'], $config['password']); + + if ($debug) + $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); + $this->db->setAttribute(PDO::MYSQL_ATTR_FOUND_ROWS, true); + } catch(PDOException $e) { + die($e->getMessage()); + } + } + + /** + * Store a new feed item in the DB + * + * @param string $title Feed title + * @param string $link Link to the thread/news item/article + * @param string $description A short descriptive text + * @param feedCategory $category To allow RSS readers to cathegorize the feeds + * + * @return Boolean + * + * @todo Create everything, pubDate will be done using SQL Now() + */ + public function storeRSS($title, $link, $description, $category) { + // TO-DO + return True; + } + + /** + * Create and parse RSS/ATOM feed + * + * @param feedType $type To determine output method + * + * @return array + */ + public function generateRSS($type) { + $sql = 'SELECT * FROM rss_feed ORDER BY id DESC'; + $st = $this->db->prepare($sql); + $st->execute(); + $result = $st->fetchAll(); + + if ($type == feedType::RSS) { + $data = ''; + $data .= ''; + $data .= ''; + $data .= ''; + $data .= 'HackThis!! RSS'; + $data .= 'https://www.hackthis.co.uk/'; + $data .= ''; + $data .= 'en-gb'; + + foreach ($result as $row) { + $data .= ''; + $data .= ''.$row->title.''; + $data .= ''.$row->link.''; + $data .= ''.$row->description.''; + $data .= ''.$row->category.''; + $data .= ''.$row->pubDate.''; + $data .= ''; + } + + $data .= ''; + $data .= ' '; + } elseif ($type == feedType::ATOM) { + $data = ''; + $data .= ''; + $data .= ''; + $data .= 'HackThis!! ATOM'; + $data .= ''; + $data .= 'Want to learn about hacking, hackers and network security. Try our hacking challenges or join our community to discuss the latest software and cracking tools.'; + $data .= 'en-gb'; + + foreach ($result as $row) { + $data .= ''; + $data .= ''.$row->title.''; + $data .= ''; + $data .= ''.$row->pubDate.''; + $data .= ''.$row->description.''; + $data .= ''; + $data .= ''; + } + + $data .= ' '; + } else { + $data = null; + throw IllegalArgumentException(); + } + + return $data; + } + } +?> diff --git a/html/files/css/rss.css b/html/files/css/rss.css new file mode 100644 index 0000000..fd70215 --- /dev/null +++ b/html/files/css/rss.css @@ -0,0 +1,77 @@ +rss, feed { + background-color: #000; + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 0.7em; + line-height: 130%; + margin: 1em; +} +/* HEADER */ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +channel { + display: block; + background-color: #1e1e1e; + padding-bottom: 0.3em; +} +channel>title, feed>title { + display: block; + padding: 0.4em 0.2em; + color: #0C8200; + border-bottom: 1px solid black; + font-weight: bold; + font-size: 140%; + background-color: #141414; +} +channel>link, feed>link { + display: block; + color: #aaa; + font-size: 130%; + font-weight: bold; + margin: 0.5em; +} +channel>description, feed>subtitle { + display: block; + float: left; + color: #aaa; + font-size: 130%; + font-weight: bold; + margin: 0.3em 0.5em 1em 0.5em; +} +language, feed>entry>link , feed>entry>category { + display: none; +} +/* CONTENT */ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +channel>item, feed>entry { + background-color: #383838; + border: 1px solid #094802; + clear: both; + display: block; + padding: 0 0 0.5em; + margin: 1em; +} +channel>item>title, feed>entry>title { + background-color: #141414; + color: #FFF; + display: block; + font-size: 110%; + font-weight: bold; + padding: 0.3em 0.5em; +} +channel>item>description, channel>item>category, feed>entry>summary{ + display: block; + float: none; + text-align: left; + padding: 0.2em 0.5em 0.4em; + color: #aaa; +} +channel>item>link { + color: #fff; + display: block; + margin: 0.5em 0.3em 1em 0.3em; +} +channel>item>pubDate, feed>entry>updated { + color: #aaa; + display: block; + font-size: 86%; + padding: 0 0.5em; +} diff --git a/html/rss/atom.php b/html/rss/atom.php new file mode 100644 index 0000000..8405666 --- /dev/null +++ b/html/rss/atom.php @@ -0,0 +1,9 @@ +generateRSS(feedType::ATOM); + + header('Content-Type: application/xml'); + echo $rssFeed; +?> diff --git a/html/rss/rss.php b/html/rss/rss.php new file mode 100644 index 0000000..acde544 --- /dev/null +++ b/html/rss/rss.php @@ -0,0 +1,9 @@ +generateRSS(feedType::RSS); + + header('Content-Type: application/xml'); + echo $rssFeed; +?> diff --git a/sql/schema.sql b/sql/schema.sql index 100571b..3b4b5b6 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -559,6 +559,18 @@ CREATE TABLE IF NOT EXISTS `irc_logs` ( PRIMARY KEY (`log_id`) ) ENGINE=MyISAM; +/* + RSS FEED +*/ +CREATE TABLE IF NOT EXISTS `rss_feed` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `title` varchar(200) NOT NULL, + `link` varchar(200) NOT NULL, + `description` text NOT NULL, + `category` varchar(20) NOT NULL, + `pubDate` timestamp DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; /* TRIGGERS diff --git a/sql/testdata.sql b/sql/testdata.sql index 58d8d1e..c3b9336 100644 --- a/sql/testdata.sql +++ b/sql/testdata.sql @@ -7,6 +7,7 @@ DELETE FROM users_profile; DELETE FROM articles_categories; DELETE FROM articles_draft; DELETE FROM articles_audit; +DELETE FROM rss_feed; -- Add a new user. INSERT INTO users (`username`, `password`, `email`) VALUES ('Osaka', '$2a$10$C5Ko0q9jlcTHKsZYvzYJxOD7DsxTsO9RFrihVdY3sGnkflf/e5XKe', 'test@gmail.com'); @@ -90,6 +91,15 @@ INSERT INTO `articles_comments` (`comment_id`, `article_id`, `user_id`, `parent_ (5, 2, 1, 4, 'LIES!!', NULL, '2013-05-13 18:03:51'), (6, 2, 4, 2, 'Me again...', NULL, '2013-05-13 19:34:34'); +-- rss_feed +INSERT INTO `rss_feed` (`id`, `title`, `link`, `description`, `category`) VALUES +('Test data 1', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'News'), +('Test data 2', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Articles'), +('Test data 3', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Forum'), +('Test data 4', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'News'), +('Test data 5', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Articles'), +('Test data 6', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Forum'); + -- Check The Data. SELECT '== USER =='; SELECT user_id, username, password FROM users; From a3f7ad613258fe43203f25d2e9764d0a523e0af5 Mon Sep 17 00:00:00 2001 From: ThibmoRozier Date: Fri, 18 Dec 2015 01:17:38 +0100 Subject: [PATCH 2/5] Indentation fix --- files/class.rss.php | 180 ++++++++++++++++++++++---------------------- html/rss/atom.php | 10 +-- html/rss/rss.php | 10 +-- sql/schema.sql | 14 ++-- 4 files changed, 107 insertions(+), 107 deletions(-) diff --git a/files/class.rss.php b/files/class.rss.php index 149d14a..b087f3e 100644 --- a/files/class.rss.php +++ b/files/class.rss.php @@ -1,32 +1,32 @@ getConstants())) - throw IllegalArgumentException(); - - $this->value = $value; - } - - final public function __toString() { - return $this->value; - } - } - - class feedType extends enumBase { - const ATOM = "atom"; - const RSS = "rss"; - } - - class feedCategory extends enumBase { - const ARTICLE = "Article"; - const FORUM = "Forum"; - const NEWS = "News"; - } - - class rss { - public function __construct() { + abstract class enumBase { + final public function __construct($value) { + $refClass = new ReflectionClass($this); + + if (!in_array($value, $refClass->getConstants())) + throw IllegalArgumentException(); + + $this->value = $value; + } + + final public function __toString() { + return $this->value; + } + } + + class feedType extends enumBase { + const ATOM = "atom"; + const RSS = "rss"; + } + + class feedCategory extends enumBase { + const ARTICLE = "Article"; + const FORUM = "Forum"; + const NEWS = "News"; + } + + class rss { + public function __construct() { //load configuration file require('config.php'); @@ -37,7 +37,7 @@ public function __construct() { $this->connectDB($this->config['db'], false); } - /** + /** * Create database connection * * @param object $config Databse connection config @@ -65,84 +65,84 @@ protected function connectDB($config, $debug=true) { } } - /** + /** * Store a new feed item in the DB * * @param string $title Feed title * @param string $link Link to the thread/news item/article - * @param string $description A short descriptive text - * @param feedCategory $category To allow RSS readers to cathegorize the feeds + * @param string $description A short descriptive text + * @param feedCategory $category To allow RSS readers to cathegorize the feeds * * @return Boolean * * @todo Create everything, pubDate will be done using SQL Now() */ - public function storeRSS($title, $link, $description, $category) { - // TO-DO - return True; - } + public function storeRSS($title, $link, $description, $category) { + // TO-DO + return True; + } - /** + /** * Create and parse RSS/ATOM feed * * @param feedType $type To determine output method * * @return array */ - public function generateRSS($type) { - $sql = 'SELECT * FROM rss_feed ORDER BY id DESC'; - $st = $this->db->prepare($sql); + public function generateRSS($type) { + $sql = 'SELECT * FROM rss_feed ORDER BY id DESC'; + $st = $this->db->prepare($sql); $st->execute(); $result = $st->fetchAll(); - if ($type == feedType::RSS) { - $data = ''; - $data .= ''; - $data .= ''; - $data .= ''; - $data .= 'HackThis!! RSS'; - $data .= 'https://www.hackthis.co.uk/'; - $data .= ''; - $data .= 'en-gb'; - - foreach ($result as $row) { - $data .= ''; - $data .= ''.$row->title.''; - $data .= ''.$row->link.''; - $data .= ''.$row->description.''; - $data .= ''.$row->category.''; - $data .= ''.$row->pubDate.''; - $data .= ''; - } - - $data .= ''; - $data .= ' '; - } elseif ($type == feedType::ATOM) { - $data = ''; - $data .= ''; - $data .= ''; - $data .= 'HackThis!! ATOM'; - $data .= ''; - $data .= 'Want to learn about hacking, hackers and network security. Try our hacking challenges or join our community to discuss the latest software and cracking tools.'; - $data .= 'en-gb'; - - foreach ($result as $row) { - $data .= ''; - $data .= ''.$row->title.''; - $data .= ''; - $data .= ''.$row->pubDate.''; - $data .= ''.$row->description.''; - $data .= ''; - $data .= ''; - } - - $data .= ' '; - } else { - $data = null; - throw IllegalArgumentException(); - } - - return $data; - } - } + if ($type == feedType::RSS) { + $data = ''; + $data .= ''; + $data .= ''; + $data .= ''; + $data .= 'HackThis!! RSS'; + $data .= 'https://www.hackthis.co.uk/'; + $data .= ''; + $data .= 'en-gb'; + + foreach ($result as $row) { + $data .= ''; + $data .= ''.$row->title.''; + $data .= ''.$row->link.''; + $data .= ''.$row->description.''; + $data .= ''.$row->category.''; + $data .= ''.$row->pubDate.''; + $data .= ''; + } + + $data .= ''; + $data .= ' '; + } elseif ($type == feedType::ATOM) { + $data = ''; + $data .= ''; + $data .= ''; + $data .= 'HackThis!! ATOM'; + $data .= ''; + $data .= 'Want to learn about hacking, hackers and network security. Try our hacking challenges or join our community to discuss the latest software and cracking tools.'; + $data .= 'en-gb'; + + foreach ($result as $row) { + $data .= ''; + $data .= ''.$row->title.''; + $data .= ''; + $data .= ''.$row->pubDate.''; + $data .= ''.$row->description.''; + $data .= ''; + $data .= ''; + } + + $data .= ' '; + } else { + $data = null; + throw IllegalArgumentException(); + } + + return $data; + } + } ?> diff --git a/html/rss/atom.php b/html/rss/atom.php index 8405666..2f25f65 100644 --- a/html/rss/atom.php +++ b/html/rss/atom.php @@ -1,9 +1,9 @@ generateRSS(feedType::ATOM); + $feedClass = new rss(); + $rssFeed = $feedClass->generateRSS(feedType::ATOM); - header('Content-Type: application/xml'); - echo $rssFeed; + header('Content-Type: application/xml'); + echo $rssFeed; ?> diff --git a/html/rss/rss.php b/html/rss/rss.php index acde544..2839ebf 100644 --- a/html/rss/rss.php +++ b/html/rss/rss.php @@ -1,9 +1,9 @@ generateRSS(feedType::RSS); + $feedClass = new rss(); + $rssFeed = $feedClass->generateRSS(feedType::RSS); - header('Content-Type: application/xml'); - echo $rssFeed; + header('Content-Type: application/xml'); + echo $rssFeed; ?> diff --git a/sql/schema.sql b/sql/schema.sql index 3b4b5b6..9b38e7a 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -563,13 +563,13 @@ CREATE TABLE IF NOT EXISTS `irc_logs` ( RSS FEED */ CREATE TABLE IF NOT EXISTS `rss_feed` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `title` varchar(200) NOT NULL, - `link` varchar(200) NOT NULL, - `description` text NOT NULL, - `category` varchar(20) NOT NULL, - `pubDate` timestamp DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) + `id` int(11) NOT NULL AUTO_INCREMENT, + `title` varchar(200) NOT NULL, + `link` varchar(200) NOT NULL, + `description` text NOT NULL, + `category` varchar(20) NOT NULL, + `pubDate` timestamp DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) ) ENGINE=InnoDB; /* From ab8ff919e6c7ffeab84983d56de4822ac5f2b06f Mon Sep 17 00:00:00 2001 From: ThibmoRozier Date: Fri, 18 Dec 2015 18:42:45 +0100 Subject: [PATCH 3/5] Update(RSS): Complete RSS2.0 and ATOM implementation Adds everything that was not there yet. Also fixes a micro bug("/files/log/" should be "/files/logs/") * Add functionality to add feeds to the DB * Add RSS adding to Articles, News and Forum threads ( OP only ) TO-DO: * Talk to main devs about pruning old feeds --- files/class.app.php | 4 +++- files/class.articles.php | 7 ++++++- files/class.forum.php | 6 +++++- files/class.rss.php | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/files/class.app.php b/files/class.app.php index 03eb937..000767c 100644 --- a/files/class.app.php +++ b/files/class.app.php @@ -11,7 +11,7 @@ function __construct($minimal = false) { $this->config = $config; $this->config['cache'] = $this->config['path'] . "/files/cache/"; - $this->config['log'] = $this->config['path'] . "/files/log/"; + $this->config['log'] = $this->config['path'] . "/files/logs/"; // Connect to database $this->connectDB($this->config['db'], false); @@ -69,6 +69,8 @@ function __construct($minimal = false) { $this->articles = new articles($this); // Create forum object $this->forum = new forum($this); + // Create RSS object + $this->rss = new rss(); if (!is_array($custom_css)) $custom_css = Array(); diff --git a/files/class.articles.php b/files/class.articles.php index 3672f4e..68a837d 100644 --- a/files/class.articles.php +++ b/files/class.articles.php @@ -439,19 +439,24 @@ public function acceptArticle($article_id) { if ($result->category_id == 0) { $slug = '/news/' . $result->slug; $type = 'news'; + $cat_id = 0; } else { $slug = '/articles/' . $result->slug; $type = 'article'; + $cat_id = 1; } $this->app->feed->call($result->username, $type, $result->title, $slug); // Award medal to user $this->app->user->awardMedal('writer', 2, $result->user_id); + // Add to RSS + if(!$this->app->rss->storeRSS($result->title, $slug, substr($result->body, 0, 100), $cat_id)) + $this->app->log->add('rss', 'Failed to add an item to the feed.'); + return true; } - /* * COMMENTS */ diff --git a/files/class.forum.php b/files/class.forum.php index 26eaf8c..324e644 100644 --- a/files/class.forum.php +++ b/files/class.forum.php @@ -102,7 +102,7 @@ public function getSections($parent=null) { } public function printThreadPost($post, $first=false, $last=false, $admin=false) { - if (!$post) return; + if (!$post) return; $post->first = $first; $post->last = $last; @@ -454,6 +454,10 @@ public function newThread($section, $title, $body) { $this->app->ssga->set_event('forum', 'thread.new', '/forum/' . $slug, $this->app->user->uid); $this->app->ssga->send(); + // Add to RSS + if(!$this->app->rss->storeRSS($title, $slug, substr($body, 0, 100), 2)) + $this->app->log->add('rss', 'Failed to add an item to the feed.'); + return '/forum/' . $slug; } diff --git a/files/class.rss.php b/files/class.rss.php index b087f3e..1bcf594 100644 --- a/files/class.rss.php +++ b/files/class.rss.php @@ -69,16 +69,42 @@ protected function connectDB($config, $debug=true) { * Store a new feed item in the DB * * @param string $title Feed title - * @param string $link Link to the thread/news item/article + * @param string $slug Link to the thread/news item/article * @param string $description A short descriptive text - * @param feedCategory $category To allow RSS readers to cathegorize the feeds + * @param integer $catID To allow RSS readers to cathegorize the feeds * * @return Boolean * * @todo Create everything, pubDate will be done using SQL Now() */ - public function storeRSS($title, $link, $description, $category) { - // TO-DO + public function storeRSS($title, $slug, $description, $catID) { + $category = feedCategory::ARTICLE; + + switch ($catID) { + case 0: + $category = feedCategory::NEWS; + break; + case 1: + $category = feedCategory::ARTICLE; + break; + case 2: + $category = feedCategory::FORUM; + break; + } + + $link = $this->config['domain'] . $slug; + + try { + // Insert article + $st = $this->db->prepare('INSERT INTO `rss_feed` (`title`,`link`,`description`,`category`) + VALUES (:title,:link,:description,:category)'); + $st->execute(array(':title' => $title, ':link' => $link, ':description' => $description, ':category' => $category)); + + $this->db->commit(); + } catch(PDOException $e) { + $this->db->rollBack(); + return False; + } return True; } @@ -90,7 +116,7 @@ public function storeRSS($title, $link, $description, $category) { * @return array */ public function generateRSS($type) { - $sql = 'SELECT * FROM rss_feed ORDER BY id DESC'; + $sql = 'SELECT * FROM `rss_feed` ORDER BY `id` DESC'; $st = $this->db->prepare($sql); $st->execute(); $result = $st->fetchAll(); @@ -102,7 +128,7 @@ public function generateRSS($type) { $data .= ''; $data .= 'HackThis!! RSS'; $data .= 'https://www.hackthis.co.uk/'; - $data .= ''; + $data .= 'Want to learn about hacking, hackers and network security. Try our hacking challenges or join our community to discuss the latest software and cracking tools.'; $data .= 'en-gb'; foreach ($result as $row) { From 842292fd584db59d7501be0c7fb9658f89ad07f9 Mon Sep 17 00:00:00 2001 From: ThibmoRozier Date: Fri, 18 Dec 2015 21:27:08 +0100 Subject: [PATCH 4/5] Update(RSS): Full standardization RSS2.0 and ATOM Now follows the standardization of RSS2.0 and ATOM1.0 to ensure compatibility. * Adds the use of UIDs and feed ID to satisfy ATOM. * Adds an update time of sorts to make ATOM happy. * Enlarges the amount of characters the description will show and ends it nicely. * Updates CSS to fit current situation. * Updates Schema.sql to current situation. * Updates TestData.sql to current situation. --- files/class.articles.php | 2 +- files/class.forum.php | 2 +- files/class.rss.php | 10 +++++++--- html/files/css/rss.css | 12 +++++++++--- sql/schema.sql | 3 ++- sql/testdata.sql | 14 +++++++------- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/files/class.articles.php b/files/class.articles.php index 68a837d..61c2ba2 100644 --- a/files/class.articles.php +++ b/files/class.articles.php @@ -451,7 +451,7 @@ public function acceptArticle($article_id) { $this->app->user->awardMedal('writer', 2, $result->user_id); // Add to RSS - if(!$this->app->rss->storeRSS($result->title, $slug, substr($result->body, 0, 100), $cat_id)) + if(!$this->app->rss->storeRSS($result->title, $slug, substr($result->body, 0, 200).'...', $cat_id)) $this->app->log->add('rss', 'Failed to add an item to the feed.'); return true; diff --git a/files/class.forum.php b/files/class.forum.php index 324e644..700331d 100644 --- a/files/class.forum.php +++ b/files/class.forum.php @@ -455,7 +455,7 @@ public function newThread($section, $title, $body) { $this->app->ssga->send(); // Add to RSS - if(!$this->app->rss->storeRSS($title, $slug, substr($body, 0, 100), 2)) + if(!$this->app->rss->storeRSS($title, $slug, substr($body, 0, 200).'...', 2)) $this->app->log->add('rss', 'Failed to add an item to the feed.'); return '/forum/' . $slug; diff --git a/files/class.rss.php b/files/class.rss.php index 1bcf594..5a07905 100644 --- a/files/class.rss.php +++ b/files/class.rss.php @@ -96,8 +96,8 @@ public function storeRSS($title, $slug, $description, $catID) { try { // Insert article - $st = $this->db->prepare('INSERT INTO `rss_feed` (`title`,`link`,`description`,`category`) - VALUES (:title,:link,:description,:category)'); + $st = $this->db->prepare('INSERT INTO `rss_feed` (`unique_id`,`title`,`link`,`description`,`category`) + VALUES (UUID(),:title,:link,:description,:category)'); $st->execute(array(':title' => $title, ':link' => $link, ':description' => $description, ':category' => $category)); $this->db->commit(); @@ -134,6 +134,7 @@ public function generateRSS($type) { foreach ($result as $row) { $data .= ''; $data .= ''.$row->title.''; + $data .= ''.$row->unique_id.''; $data .= ''.$row->link.''; $data .= ''.$row->description.''; $data .= ''.$row->category.''; @@ -144,17 +145,20 @@ public function generateRSS($type) { $data .= ''; $data .= ' '; } elseif ($type == feedType::ATOM) { + $objDateTime = new DateTime('NOW'); $data = ''; $data .= ''; $data .= ''; + $data .= 'https://www.hackthis.co.uk/'; $data .= 'HackThis!! ATOM'; + $data .= ''.$objDateTime->format(DateTime::ATOM).''; $data .= ''; $data .= 'Want to learn about hacking, hackers and network security. Try our hacking challenges or join our community to discuss the latest software and cracking tools.'; - $data .= 'en-gb'; foreach ($result as $row) { $data .= ''; $data .= ''.$row->title.''; + $data .= ''.$row->unique_id.''; $data .= ''; $data .= ''.$row->pubDate.''; $data .= ''.$row->description.''; diff --git a/html/files/css/rss.css b/html/files/css/rss.css index fd70215..e9c8c2c 100644 --- a/html/files/css/rss.css +++ b/html/files/css/rss.css @@ -12,6 +12,13 @@ channel { background-color: #1e1e1e; padding-bottom: 0.3em; } +feed>id { + display: block; + color: #0C8200; + font-size: 130%; + font-weight: bold; + margin: 0.3em 0.3em 1em 0.5em; +} channel>title, feed>title { display: block; padding: 0.4em 0.2em; @@ -28,9 +35,8 @@ channel>link, feed>link { font-weight: bold; margin: 0.5em; } -channel>description, feed>subtitle { +channel>description, feed>subtitle, feed>updated { display: block; - float: left; color: #aaa; font-size: 130%; font-weight: bold; @@ -57,7 +63,7 @@ channel>item>title, feed>entry>title { font-weight: bold; padding: 0.3em 0.5em; } -channel>item>description, channel>item>category, feed>entry>summary{ +channel>item>description, channel>item>category, channel>item>guid, feed>entry>summary, feed>entry>id{ display: block; float: none; text-align: left; diff --git a/sql/schema.sql b/sql/schema.sql index 9b38e7a..365b755 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -564,11 +564,12 @@ CREATE TABLE IF NOT EXISTS `irc_logs` ( */ CREATE TABLE IF NOT EXISTS `rss_feed` ( `id` int(11) NOT NULL AUTO_INCREMENT, + `unique_id` varchar(36) NOT NULL, `title` varchar(200) NOT NULL, `link` varchar(200) NOT NULL, `description` text NOT NULL, `category` varchar(20) NOT NULL, - `pubDate` timestamp DEFAULT CURRENT_TIMESTAMP, + `pubDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB; diff --git a/sql/testdata.sql b/sql/testdata.sql index c3b9336..a67b00d 100644 --- a/sql/testdata.sql +++ b/sql/testdata.sql @@ -92,13 +92,13 @@ INSERT INTO `articles_comments` (`comment_id`, `article_id`, `user_id`, `parent_ (6, 2, 4, 2, 'Me again...', NULL, '2013-05-13 19:34:34'); -- rss_feed -INSERT INTO `rss_feed` (`id`, `title`, `link`, `description`, `category`) VALUES -('Test data 1', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'News'), -('Test data 2', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Articles'), -('Test data 3', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Forum'), -('Test data 4', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'News'), -('Test data 5', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Articles'), -('Test data 6', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Forum'); +INSERT INTO `rss_feed` (`unique_id`, `title`, `link`, `description`, `category`) VALUES +('6a3091e4-a5bb-11e5-acec-000c29ce2aa6', 'Test data 1', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'News'), +('71957a4d-a5bb-11e5-acec-000c29ce2aa6', 'Test data 2', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Article'), +('8e74f552-a5bb-11e5-acec-000c29ce2aa6', 'Test data 3', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Forum'), +('8e74fe6f-a5bb-11e5-acec-000c29ce2aa6', 'Test data 4', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'News'), +('8e7505e9-a5bb-11e5-acec-000c29ce2aa6', 'Test data 5', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Article'), +('8e750e55-a5bb-11e5-acec-000c29ce2aa6', 'Test data 6', 'https://www.hackthis.co.uk/', 'This is a simple test.', 'Forum'); -- Check The Data. SELECT '== USER =='; From 55df14da17ed296e80adf2ec3936c7737a991702 Mon Sep 17 00:00:00 2001 From: ThibmoRozier Date: Fri, 18 Dec 2015 23:30:38 +0100 Subject: [PATCH 5/5] Update(RSS): Add buttons to both RSS and ATOM feeds in the page footer. --- files/footer.php | 4 ++++ html/files/css/main.scss | 2 +- html/files/images/atom.png | Bin 0 -> 256 bytes html/files/images/rss.png | Bin 0 -> 255 bytes 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 html/files/images/atom.png create mode 100644 html/files/images/rss.png diff --git a/files/footer.php b/files/footer.php index 1d44826..629cce0 100644 --- a/files/footer.php +++ b/files/footer.php @@ -45,6 +45,10 @@
  • Facebook
  • Twitter
  • GitHub
  • +
  • +   + +
  • diff --git a/html/files/css/main.scss b/html/files/css/main.scss index a01c6af..7a62536 100644 --- a/html/files/css/main.scss +++ b/html/files/css/main.scss @@ -511,7 +511,7 @@ div.image { a { color: $text; - .icon-facebook, .icon-twitter, .icon-feed { + .icon-facebook, .icon-twitter, .icon-feed, .icon-rss, .icon-atom { padding-right: 3px; } diff --git a/html/files/images/atom.png b/html/files/images/atom.png new file mode 100644 index 0000000000000000000000000000000000000000..3c7f809f16e5ec862b9b92b8cf861d9d85bab013 GIT binary patch literal 256 zcmeAS@N?(olHy`uVBq!ia0vp^T0qRr!3HEbjpa`ODaPU;cPEB*=VV?2IV|apzK#qG z8~eHcB(j3k6nI1yGcfQS24TkI`72U@f)XXJ5hcO-X(i=}MX3x0iJ5sNdU>fO3MP66 zdS-umlJ5i66neTihIn|togB#3V8G+NxA5Ta!%O5F1%kCL91|PcJ-7866x>!mCLiIP zp4{#A(NVeC4qFPi0LQm4dkmP^V7oiCBCPH5lsWzDG%SEs+U`u1R|xa;#zbNg&7 vOhjV4HqR@*=2y!#bEExb@krgTe~DWM4fK0jGZ literal 0 HcmV?d00001 diff --git a/html/files/images/rss.png b/html/files/images/rss.png new file mode 100644 index 0000000000000000000000000000000000000000..d5694f0f570649166d042bd6d82244e96b8a3027 GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^szA)m!3HFMSh%anMprAyFYeY$Kep*R+Vo@qXL1JcJiC$i6iGqoq zfu7l)p5*&LH3gn7jv*HQZzpWzJz&7WGSkpG9-nzopr0IsQB1poj5 literal 0 HcmV?d00001