This repository was archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Feature(RSS): Implementation of RSS2.0 and ATOM1.0 feed. #183
Open
LauraRozier
wants to merge
5
commits into
defendtheweb:master
Choose a base branch
from
LauraRozier:RSSFeed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db6afed
Feature(RSS): First implementation of RSS2.0 and ATOM feed.
LauraRozier a3f7ad6
Indentation fix
LauraRozier ab8ff91
Update(RSS): Complete RSS2.0 and ATOM implementation
LauraRozier 842292f
Update(RSS): Full standardization RSS2.0 and ATOM
LauraRozier 55df14d
Update(RSS): Add buttons to both RSS and ATOM feeds in the page footer.
LauraRozier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| <?php | ||
| 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'); | ||
|
|
||
| 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 $slug Link to the thread/news item/article | ||
| * @param string $description A short descriptive text | ||
| * @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, $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` (`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(); | ||
| } catch(PDOException $e) { | ||
| $this->db->rollBack(); | ||
| return False; | ||
| } | ||
| 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 = '<?xml version="1.0" encoding="UTF-8" ?>'; | ||
| $data .= '<?xml-stylesheet type="text/css" href="../files/css/rss.css" ?>'; | ||
| $data .= '<rss version="2.0">'; | ||
| $data .= '<channel>'; | ||
| $data .= '<title>HackThis!! RSS</title>'; | ||
| $data .= '<link>https://www.hackthis.co.uk/</link>'; | ||
| $data .= '<description>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.</description>'; | ||
| $data .= '<language>en-gb</language>'; | ||
|
|
||
| foreach ($result as $row) { | ||
| $data .= '<item>'; | ||
| $data .= '<title>'.$row->title.'</title>'; | ||
| $data .= '<guid>'.$row->unique_id.'</guid>'; | ||
| $data .= '<link>'.$row->link.'</link>'; | ||
| $data .= '<description>'.$row->description.'</description>'; | ||
| $data .= '<category>'.$row->category.'</category>'; | ||
| $data .= '<pubDate>'.$row->pubDate.'</pubDate>'; | ||
| $data .= '</item>'; | ||
| } | ||
|
|
||
| $data .= '</channel>'; | ||
| $data .= '</rss> '; | ||
| } elseif ($type == feedType::ATOM) { | ||
| $objDateTime = new DateTime('NOW'); | ||
| $data = '<?xml version="1.0" encoding="utf-8" ?>'; | ||
| $data .= '<?xml-stylesheet type="text/css" href="../files/css/rss.css" ?>'; | ||
| $data .= '<feed xmlns="http://www.w3.org/2005/Atom">'; | ||
| $data .= '<id>https://www.hackthis.co.uk/</id>'; | ||
| $data .= '<title>HackThis!! ATOM</title>'; | ||
| $data .= '<updated>'.$objDateTime->format(DateTime::ATOM).'</updated>'; | ||
| $data .= '<link href="https://www.hackthis.co.uk/" />'; | ||
| $data .= '<subtitle>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.</subtitle>'; | ||
|
|
||
| foreach ($result as $row) { | ||
| $data .= '<entry>'; | ||
| $data .= '<title>'.$row->title.'</title>'; | ||
| $data .= '<id>'.$row->unique_id.'</id>'; | ||
| $data .= '<link href="'.$row->link.'" />'; | ||
| $data .= '<updated>'.$row->pubDate.'</updated>'; | ||
| $data .= '<summary>'.$row->description.'</summary>'; | ||
| $data .= '<category term=">'.$row->category.'" />'; | ||
| $data .= '</entry>'; | ||
| } | ||
|
|
||
| $data .= '</feed> '; | ||
| } else { | ||
| $data = null; | ||
| throw IllegalArgumentException(); | ||
| } | ||
|
|
||
| return $data; | ||
| } | ||
| } | ||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| 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; | ||
| } | ||
| 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; | ||
| 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, feed>updated { | ||
| display: block; | ||
| 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, channel>item>guid, feed>entry>summary, feed>entry>id{ | ||
| 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; | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
| include_once 'class.rss.php'; | ||
|
|
||
| $feedClass = new rss(); | ||
| $rssFeed = $feedClass->generateRSS(feedType::ATOM); | ||
|
|
||
| header('Content-Type: application/xml'); | ||
| echo $rssFeed; | ||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
| include_once 'class.rss.php'; | ||
|
|
||
| $feedClass = new rss(); | ||
| $rssFeed = $feedClass->generateRSS(feedType::RSS); | ||
|
|
||
| header('Content-Type: application/xml'); | ||
| echo $rssFeed; | ||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to mention this one, it bugged the logs out.