From dc7427c18ba9802d9e01716bbe914fd58ed954f7 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 26 Jan 2019 21:46:33 +0000
Subject: [PATCH] [server] Add changelog action

---
 composer.json               |  3 +-
 composer.lock               | 92 ++++++++++++++++++++++++++++++++++++-
 logic/Actions/Changelog.php | 40 ++++++++++++++++
 3 files changed, 133 insertions(+), 2 deletions(-)
 create mode 100644 logic/Actions/Changelog.php

diff --git a/composer.json b/composer.json
index 2082b08..2d244b6 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,8 @@
     "require": {
         "yosymfony/toml": "^1.0",
         "aura/autoload": "^2.0",
-        "php-di/php-di": "^6.0"
+        "php-di/php-di": "^6.0",
+        "erusev/parsedown-extra": "^0.7.1"
     },
     "license": "MPL-2.0",
     "authors": [
diff --git a/composer.lock b/composer.lock
index d64feb3..3b6e901 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "e2c066b5e1e6ab212ea3d3033225ed87",
+    "content-hash": "d42581b26b6c99bcc70da335a64f686b",
     "packages": [
         {
             "name": "aura/autoload",
@@ -55,6 +55,96 @@
             ],
             "time": "2016-10-03T19:36:19+00:00"
         },
+        {
+            "name": "erusev/parsedown",
+            "version": "1.7.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/erusev/parsedown.git",
+                "reference": "92e9c27ba0e74b8b028b111d1b6f956a15c01fc1"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/erusev/parsedown/zipball/92e9c27ba0e74b8b028b111d1b6f956a15c01fc1",
+                "reference": "92e9c27ba0e74b8b028b111d1b6f956a15c01fc1",
+                "shasum": ""
+            },
+            "require": {
+                "ext-mbstring": "*",
+                "php": ">=5.3.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "Parsedown": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Emanuil Rusev",
+                    "email": "hello@erusev.com",
+                    "homepage": "http://erusev.com"
+                }
+            ],
+            "description": "Parser for Markdown.",
+            "homepage": "http://parsedown.org",
+            "keywords": [
+                "markdown",
+                "parser"
+            ],
+            "time": "2018-03-08T01:11:30+00:00"
+        },
+        {
+            "name": "erusev/parsedown-extra",
+            "version": "0.7.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/erusev/parsedown-extra.git",
+                "reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/0db5cce7354e4b76f155d092ab5eb3981c21258c",
+                "reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c",
+                "shasum": ""
+            },
+            "require": {
+                "erusev/parsedown": "~1.4"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "ParsedownExtra": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Emanuil Rusev",
+                    "email": "hello@erusev.com",
+                    "homepage": "http://erusev.com"
+                }
+            ],
+            "description": "An extension of Parsedown that adds support for Markdown Extra.",
+            "homepage": "https://github.com/erusev/parsedown-extra",
+            "keywords": [
+                "markdown",
+                "markdown extra",
+                "parsedown",
+                "parser"
+            ],
+            "time": "2015-11-01T10:19:22+00:00"
+        },
         {
             "name": "jeremeamia/SuperClosure",
             "version": "2.4.0",
diff --git a/logic/Actions/Changelog.php b/logic/Actions/Changelog.php
new file mode 100644
index 0000000..5aaa62a
--- /dev/null
+++ b/logic/Actions/Changelog.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace AirQuality\Actions;
+
+use \SBRL\TomlConfig;
+
+use \AirQuality\PerfFormatter;
+
+class Changelog implements IAction {
+	/** @var TomlConfig */
+	private $settings;
+	
+	/** @var \ParsedownExtra */
+	private $parsedown_ext;
+	
+	public function __construct(
+		TomlConfig $in_settings,
+		\ParsedownExtra $in_parsedown_ext) {
+		$this->settings = $in_settings;
+		$this->parsedown_ext = $in_parsedown_ext;
+	}
+	
+	public function handle() : bool {
+		global $start_time;
+		
+		$start_handle = microtime(true);
+		
+		
+		// 1: Parse markdown
+		$result = $this->parsedown_ext->text(file_get_contents(ROOT_DIR."Changelog.md"));
+		
+		
+		// 2: Send response
+		header("content-length: " . strlen($result));
+		header("content-type: text/html");
+		header("x-time-taken: " . PerfFormatter::format_perf_data($start_time, $start_handle, null));
+		echo($result);
+		return true;
+	}
+}
