From 6d01fe82c7be21f9965978e2a980ab6861f47e33 Mon Sep 17 00:00:00 2001 From: tmont Date: Sun, 19 Oct 2008 02:33:35 +0000 Subject: [PATCH] lots of changes, added footer and main view, implemented an initial wiki page --- src/bootstrap.php | 9 +++ src/index.php | 2 +- src/lib/PanaceaControllerFactory.php | 15 ++-- src/lib/PanaceaDefaultController.php | 17 ++++- src/lib/PanaceaViewFactory.php | 32 ++------- src/lib/PanaceaWikiController.php | 71 ++++++++++++++++++ src/lib/WikiViewFactory.php | 61 ++++++++++++++++ src/lib/views/PanaceaFooterView.php | 50 +++++++++++++ src/lib/views/PanaceaHomeView.php | 27 ++++--- src/lib/views/PanaceaMainView.php | 43 +++++++++++ src/lib/views/PanaceaTemplateView.php | 4 ++ src/lib/views/PanaceaWelcomeView.php | 100 ++++++++++++++++++++++++++ src/lib/views/wiki/WikiPageView.php | 44 ++++++++++++ src/media/css/global.css | 66 +++++++++++++++-- 14 files changed, 493 insertions(+), 48 deletions(-) create mode 100644 src/lib/PanaceaWikiController.php create mode 100644 src/lib/WikiViewFactory.php create mode 100644 src/lib/views/PanaceaFooterView.php create mode 100644 src/lib/views/PanaceaMainView.php create mode 100644 src/lib/views/PanaceaWelcomeView.php create mode 100644 src/lib/views/wiki/WikiPageView.php diff --git a/src/bootstrap.php b/src/bootstrap.php index b82276d..04bb816 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -24,17 +24,26 @@ $file = ''; switch ($className) { case 'PanaceaControllerFactory': + case 'PanaceaWikiController': + case 'WikiViewFactory': case 'PanaceaDefaultController': case 'PanaceaViewFactory': $file = "$path/lib/$className.php"; break; + case 'WikiPageView': + $file = "$path/lib/views/wiki/$className.php"; + break; + case 'PanaceaView': case 'PanaceaHomeView': + case 'PanaceaMainView': case 'PanaceaTemplateView': case 'PanaceaHeaderView': case 'PanaceaLogoView': case 'PanaceaMenuView': + case 'PanaceaFooterView': + case 'PanaceaWelcomeView': $file = "$path/lib/views/$className.php"; break; } diff --git a/src/index.php b/src/index.php index 5cf5445..5d2f40a 100644 --- a/src/index.php +++ b/src/index.php @@ -13,7 +13,7 @@ $uriRegex = str_replace(str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']), '', dirname(__FILE__)); $uriRegex = str_replace('\\', '/', $uriRegex); - $uriRegex = '^' . $uriRegex . '/([^/]*)(?:/(.+))?'; + $uriRegex = '^' . $uriRegex . '/([^/]*)(?:/(.*))?'; Dispatcher::getInstance()->setUriRegex($uriRegex) ->setThrowExceptions(true) diff --git a/src/lib/PanaceaControllerFactory.php b/src/lib/PanaceaControllerFactory.php index e539c46..d10f9cd 100644 --- a/src/lib/PanaceaControllerFactory.php +++ b/src/lib/PanaceaControllerFactory.php @@ -67,17 +67,24 @@ if (isset($uriFragments[1])) { $section = ucfirst($uriFragments[0]); - $page = $uriFragments[1]; + $page = ucfirst($uriFragments[1]); } if (empty($section)) { $section = 'Default'; } - if (empty($page)) { - $page = 'home'; - } $controllerName = 'Panacea' . $section . 'Controller'; + if (empty($page)) { + try { + $refclass = new ReflectionClass($controllerName); + $page = $refclass->getMethod('getDefaultPageName')->invoke(null); + } + catch (ReflectionException $e) { + throw $e; + } + } + return new $controllerName($page); } diff --git a/src/lib/PanaceaDefaultController.php b/src/lib/PanaceaDefaultController.php index a730002..cfd03f6 100644 --- a/src/lib/PanaceaDefaultController.php +++ b/src/lib/PanaceaDefaultController.php @@ -36,6 +36,18 @@ $this->viewFactory = PanaceaViewFactory::getInstance(); } + /** + * Gets the default page if none is specified in the URI + * + * @author Tommy Montgomery + * @since 2008-10-18 + * + * @return string + */ + public static function getDefaultPageName() { + return 'Home'; + } + /** * Handles the specified request, and generates a * suitable response @@ -54,8 +66,9 @@ } try { - $templateView = new PanaceaTemplateView($this->page); - $templateView->addView($this->viewFactory->getView($this->page, $templateView->getNextPriority())); + $title = (empty($this->page) || $this->page === 'Home') ? 'It doesn\'t suck' : $this->page; + $templateView = new PanaceaTemplateView($title); + $templateView->mainView->addView($this->viewFactory->getView($this->page)); return $templateView; } catch (ClassNotFoundException $e) { diff --git a/src/lib/PanaceaViewFactory.php b/src/lib/PanaceaViewFactory.php index 601c966..037aa12 100644 --- a/src/lib/PanaceaViewFactory.php +++ b/src/lib/PanaceaViewFactory.php @@ -44,38 +44,16 @@ } /** - * Creates an instance of a {@link View} given a - * page name + * {@inheritdoc} * * @author Tommy Montgomery - * @since 2008-10-05 + * @since 2008-10-18 * * @param string $page The name of the page - * @param mixed $args Other arguments for creating the view - * @throws {@link InvalidTypeException} - * @throws {@link ClassNotFoundException} - * @return View + * @return string */ - public function getView($page, $priority = 0) { - if (!is_string($page)) { - throw new InvalidTypeException(1, 'string', $page); - } - - $viewName = 'Panacea' . ucfirst($page) . 'View'; - - try { - $refclass = new ReflectionClass($viewName); - $args = array_slice(func_get_args(), 1, 1); - if (!empty($args)) { - return $refclass->newInstanceArgs($args); - } - else { - return $refclass->newInstance(); - } - } - catch (ReflectionException $e) { - throw new ClassNotFoundException($viewName); - } + protected function getViewName($page) { + return 'Panacea' . ucfirst($page) . 'View'; } } diff --git a/src/lib/PanaceaWikiController.php b/src/lib/PanaceaWikiController.php new file mode 100644 index 0000000..4294393 --- /dev/null +++ b/src/lib/PanaceaWikiController.php @@ -0,0 +1,71 @@ +viewFactory = WikiViewFactory::getInstance(); + } + + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @since 2008-10-18 + * + * @return string + */ + public static function getDefaultPageName() { + return 'MainPage'; + } + + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @since 2008-10-18 + * @uses Request::create() + * @uses HttpUtil::getRequestMethod() + * + * @throws {@link InvalidRequestException} if a {@link View} cannot be created + * @return PanaceaTemplateView + */ + public function handleRequest(Request $request = null) { + if (!($request instanceof Request)) { + $request = Request::create(HttpUtil::getRequestMethod()); + } + + try { + $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); + $mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); + $wikiObject = new WikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); + $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); + $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject)); + return $templateView; + } + catch (ClassNotFoundException $e) { + throw new InvalidRequestException($request); + } + } + + } + +?> \ No newline at end of file diff --git a/src/lib/WikiViewFactory.php b/src/lib/WikiViewFactory.php new file mode 100644 index 0000000..ad5e0e8 --- /dev/null +++ b/src/lib/WikiViewFactory.php @@ -0,0 +1,61 @@ + \ No newline at end of file diff --git a/src/lib/views/PanaceaFooterView.php b/src/lib/views/PanaceaFooterView.php new file mode 100644 index 0000000..51f66cf --- /dev/null +++ b/src/lib/views/PanaceaFooterView.php @@ -0,0 +1,50 @@ + + +
+ + + \ No newline at end of file diff --git a/src/lib/views/PanaceaHomeView.php b/src/lib/views/PanaceaHomeView.php index 4138fb9..e46d50d 100644 --- a/src/lib/views/PanaceaHomeView.php +++ b/src/lib/views/PanaceaHomeView.php @@ -22,21 +22,30 @@ */ class PanaceaHomeView extends PanaceaView { + /** + * Renders the view + * + * @author Tommy Montgomery + * @since 2008-10-18 + * @uses addView() + * @uses PanaceaWelcomeView + * + * @param int $priority The priority of this view + */ + public function __construct($priority = 0) { + parent::__construct($priority); + + $this->addView(new PanaceaWelcomeView(1)); + } + /** * Renders the view * * @author Tommy Montgomery * @since 2008-10-05 */ - public function send() { ?> - -

Panacea

- -

- Hello! -

- + +
+ + +
+ \ No newline at end of file diff --git a/src/lib/views/PanaceaTemplateView.php b/src/lib/views/PanaceaTemplateView.php index 3a7d1d4..269fdaa 100644 --- a/src/lib/views/PanaceaTemplateView.php +++ b/src/lib/views/PanaceaTemplateView.php @@ -59,6 +59,8 @@ $this->separator = ' - '; $this->addView(new PanaceaHeaderView(1)); + $this->addView(new PanaceaMainView(2)); + $this->addView(new PanaceaFooterView(3)); } /** @@ -101,6 +103,8 @@ case 'defaultTitle': case 'separator': return $this->$var; + case 'mainView': + return $this->views[1]; default: return parent::__get($var); } diff --git a/src/lib/views/PanaceaWelcomeView.php b/src/lib/views/PanaceaWelcomeView.php new file mode 100644 index 0000000..d171afa --- /dev/null +++ b/src/lib/views/PanaceaWelcomeView.php @@ -0,0 +1,100 @@ + + +

Welcome

+
+

+ Welcome to Panacea, a web-based application that + doesn't suck. It's aimed at software developers, + software development managers, QA professionals, + and people who like using wikis + (which should be everybody, unless you're a robot). +

+
+ +

What is Panacea?

+
+

+ Panacea is modeled after Trac, + which is a fantastic application very similar to this one. Panacea + aims to ease integration, configuration and installation. That is not to say + that Panacea is simple; it is in fact just the opposite. Panacea is + infintely complex and extensible; it is well documented and well-written; it + is a panacea to all your software development troubles; it's also a lot of + fun, in the sense that there's a lot of crap to mess around with. +

+ +

+ More information about the technology and reason for Panacea can be + viewed at the about page. +

+
+ +

Stuff to do here

+
+

+ This whole site is an example of Panacea, except for this page. + This page is just a bunch of static HTML, and is not + under the control of a wiki. +

+ +

Demo

+
+

+ Words are boring. Here is a demo: do + it. +

+
+ +

Download

+
+

+ Click here to go + to our download page. +

+
+ +

Install

+
+

+ Click here to go + to view installation instructions. +

+
+
+ \ No newline at end of file diff --git a/src/lib/views/wiki/WikiPageView.php b/src/lib/views/wiki/WikiPageView.php new file mode 100644 index 0000000..528472e --- /dev/null +++ b/src/lib/views/wiki/WikiPageView.php @@ -0,0 +1,44 @@ +page = $page; + } + + /** + * Renders the view + * + * @author Tommy Montgomery + * @since 2008-10-18 + */ + public function send() { + echo $this->page; + } + + } + +?> \ No newline at end of file diff --git a/src/media/css/global.css b/src/media/css/global.css index c55f988..00d6685 100644 --- a/src/media/css/global.css +++ b/src/media/css/global.css @@ -7,6 +7,9 @@ body { font-size: 8pt; color: #FFFFFF; } +a { + text-decoration: none; +} #wrapper { width: 95%; @@ -37,11 +40,10 @@ body { padding: 0; } #menu ul li { - float:left; - display:block; - margin-right:5px; - width:100px; - height:25px; + float: left; + margin-right: 5px; + width: 100px; + height: 25px; } #menu ul li a { display: inline; @@ -73,4 +75,58 @@ body { color: #FFFFFF; line-height: 35px; border: 1px solid #FFFFFF; +} + +#main { + position: relative; + padding: 5px; +} +#main p { + line-height: 1.5em; +} +#main a { + border-bottom: 1px dotted #000000; + color: #669966 ; + font-weight: bold; +} +#main a:hover { + color: #000000; + border-bottom: 2px solid #669966; +} + +#foot { + position: relative; + padding: 5px; + margin: 2px; +} +#foot ul { + list-style-type: none; + margin: 0; + padding: 0; +} +#foot ul li { + float: right; +} +#foot ul li:first-child:after, #foot ul li:before { + content: "|"; + color: #999999; +} +#foot ul li a { + text-decoration: none; + color: #999999; +} +#foot ul li a:hover { + color: #000000; + text-decoration: underline; +} + + +.inset { + margin-left: 20px; +} +.hrule { + height: .1em; + border-top: 1px solid #000000; + border-bottom: 1px solid #000000; + background-color: #DDDD77; } \ No newline at end of file