<?php
	class DocViewerComponent extends Component {
		function GetUUIDs() {
			$uuids[] = 'docs\/(.*){0,1}$';
			$uuids[] = 'doc\/(.*){0,1}$';
			return $uuids;
		}

		function Run($page, $matches) {
			_page_header(SITE_NAME." :: Documentation :: $matches[1]");
		        $filepath = "../docs/" . $matches[1];

			if (file_exists($filepath))
			{
			        $text = file_get_contents($filepath);

		        	if (isset($_REQUEST['source'])) {
		                	echo "<pre>".htmlspecialchars($text)."</pre>";
					echo '<div style="text-align: right;"><a href="?">View Document</a></div>';
        			} else {
					global $frameworks_path;
					require_once($frameworks_path."/Markdown/markdown_parser.php");
        		        	echo Markdown($text);
					echo '<div style="text-align: right;"><a href="?source=yes" rel="nofollow">View Markdown Source</a></div>';
				}
			}
			else
			{
				echo "<p>The requested documentation was not found.</p>";
			}

			_page_footer();
		}
	};

	new DocViewerComponent;
?>
