From afeeba4269f28b48d19b3c7502e9b4dfb831a070 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 15 Jun 2011 21:30:22 +0100 Subject: [PATCH] Add a Main subclass to customise the templating directory structure --- public/index.php | 27 +++-------- source/lib/MediaListing/Main.class.php | 67 ++++++++++++++++++++++++++ source/pages/list.php | 6 ++- 3 files changed, 78 insertions(+), 22 deletions(-) create mode 100644 source/lib/MediaListing/Main.class.php diff --git a/public/index.php b/public/index.php index 7d04df5..f5c94a8 100644 --- a/public/index.php +++ b/public/index.php @@ -1,35 +1,20 @@ smarty(); - $smarty = new Smarty(); - $smarty->template_dir = '../source/templates'; - $smarty->compile_dir = '../private/tmp/templates'; - $smarty->cache_dir = '../private/tmp/cache'; - $smarty->config_dir = '../private/config'; - $smarty->register_modifier('formatDuration', array('MediaListing_Main', 'formatDuration')); - $smarty->register_modifier('formatFilesize', array('MediaListing_Main', 'formatFilesize')); - $smarty->assign('version', '0.1'); - $smarty->assign('base_uri', $main->baseUri()); - - $request = new MediaListing_RequestParser(isset($_GET['l']) ? $_GET['l'] : ''); - $page = new MediaListing_Page($smarty, $request); - if ($page->evaluate( - array( - 'smarty' => $smarty, - 'request' => $request, - ) - )) { + $page = new MediaListing_Page($smarty, $main->request()); + if ($page->evaluate()) { $smarty->display('index.tpl'); } - + } catch (Sihnon_Exception $e) { die("Uncaught " . get_class($e) . ": " . $e->getMessage()); } diff --git a/source/lib/MediaListing/Main.class.php b/source/lib/MediaListing/Main.class.php new file mode 100644 index 0000000..2e00358 --- /dev/null +++ b/source/lib/MediaListing/Main.class.php @@ -0,0 +1,67 @@ +request = new MediaListing_RequestParser($request_string, $this->template_dir, $this->template_code_dir); + + if (ML_File == 'index') { + $this->smarty = new Smarty(); + $this->smarty->template_dir = $this->template_dir; + $this->smarty->compile_dir = '../private/tmp/templates'; + $this->smarty->cache_dir = '../private/tmp/cache'; + $this->smarty->config_dir = '../private/tmp/config'; + + $this->smarty->registerPlugin('modifier', 'formatDuration', array('MediaListing_Main', 'formatDuration')); + $this->smarty->registerPlugin('modifier', 'formatFilesize', array('MediaListing_Main', 'formatFilesize')); + + $this->smarty->assign('version', '0.1'); + $this->smarty->assign('messages', array()); + + $this->smarty->assign('base_uri', $this->base_uri); + } + } + + /** + * Returns the directory where page templates can be found + * + * @return string + */ + public function templateDir() { + return $this->template_dir; + } + + /** + * + * @return Smarty + */ + public function smarty() { + return $this->smarty; + } + + /** + * + * @return MediaListing_RequestParser + */ + public function request() { + return $this->request; + } + + +} + +?> diff --git a/source/pages/list.php b/source/pages/list.php index bf47b0f..3b69ec0 100644 --- a/source/pages/list.php +++ b/source/pages/list.php @@ -1,6 +1,10 @@ config(); +$main = MediaListing_Main::instance(); +$config = $main->config(); +$request = $main->request(); +$smarty = $main->smarty(); + $source_paths = $config->get('sources'); $sources = array();