From 630b0f26fc5dc970d8634e58489c41c5a40481f1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 4 Nov 2008 05:02:37 +0000 Subject: Restructure the theme code to be more like WordPress / Habari. Now, the controller initiates a request to a top level page (eg: album.html.php) which is then free to include whatever other page chunks it wants with calls like display('header.html') ?> Variables like $item and $children are in the global space for all views. theme.php helper is now Theme.php library which lets us store the name of the theme inside the variable itself. This means that the theme does not have to know its own name because you can use $theme->url() for all urls to stuff inside the theme itself, which makes it possible to cline a theme without changing a single line. Still using the mock album UI. --- core/controllers/album.php | 20 +--- core/helpers/core_installer.php | 2 + core/helpers/theme.php | 33 ------- core/libraries/Theme.php | 34 +++++++ core/models/item.php | 18 ++++ core/tests/Theme_Test.php | 20 ++-- themes/default/views/album.html.php | 128 ++++++++++++++------------ themes/default/views/footer.html.php | 7 ++ themes/default/views/header.html.php | 53 +++++++++++ themes/default/views/page_footer.html.php | 4 - themes/default/views/page_header.html.php | 30 ------ themes/default/views/page_sidebar.html.php | 141 ----------------------------- themes/default/views/sidebar.html.php | 141 +++++++++++++++++++++++++++++ 13 files changed, 342 insertions(+), 289 deletions(-) delete mode 100644 core/helpers/theme.php create mode 100644 core/libraries/Theme.php create mode 100644 themes/default/views/footer.html.php create mode 100644 themes/default/views/header.html.php delete mode 100644 themes/default/views/page_footer.html.php delete mode 100644 themes/default/views/page_header.html.php delete mode 100644 themes/default/views/page_sidebar.html.php create mode 100644 themes/default/views/sidebar.html.php diff --git a/core/controllers/album.php b/core/controllers/album.php index a22e5eeb..b1c7d205 100644 --- a/core/controllers/album.php +++ b/core/controllers/album.php @@ -18,28 +18,16 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Album_Controller extends Template_Controller { - public $template = "page.html"; + public $template = "album.html"; public function View($id) { $item = ORM::factory("item")->where("id", $id)->find(); if (empty($item->id)) { return Kohana::show_404(); } - $this->template->item = $item; - - $this->template->header = new View("page_header.html"); - $this->template->header->item = $item; - - $this->template->footer = new View("page_footer.html"); - $this->template->footer->item = $item; - - $this->template->content = new View("album.html"); - $this->template->content->item = $item; - $this->template->content->maxRows = 3; - $this->template->content->maxColumns = 3; - - $this->template->sidebar = new View("page_sidebar.html"); - $this->template->sidebar->item = $item; + $this->template->set_global('item', $item); + $this->template->set_global('children', $item->get_children()); + $this->template->set_global('theme', new Theme("default", $this->template)); } } diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index 9dd5224c..ea01a0c0 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -43,6 +43,7 @@ class core_installer { `id` int(9) NOT NULL auto_increment, `type` char(32) default NULL, `title` char(255) default NULL, + `description` char(255) default NULL, `path` char(255) default NULL, `left` int(9) default NULL, `right` int(9) default NULL, @@ -64,6 +65,7 @@ class core_installer { $root = ORM::factory("item"); $root->title = "Gallery"; + $root->description = "Welcome to your Gallery3"; $root->make_root(); } } diff --git a/core/helpers/theme.php b/core/helpers/theme.php deleted file mode 100644 index 5aa568c7..00000000 --- a/core/helpers/theme.php +++ /dev/null @@ -1,33 +0,0 @@ -theme_name = $theme_name; + } + + public function url($path) { + return url::base() . "themes/{$this->theme_name}/$path"; + } + + public function display($page_name, $view_class="View") { + return new $view_class($page_name); + } +} diff --git a/core/models/item.php b/core/models/item.php index b8957911..8b08b699 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -20,4 +20,22 @@ class Item_Model extends MPTT { protected $left_column = "left"; protected $right_column = "right"; + + public function is_album() { + return $this->type == 'album'; + } + + public function is_photo() { + return $this->type == 'photo'; + } + + // MPTT::get_children returns null if there are no children; change that to an empty array for + // consistency. + public function get_children() { + $children = parent::get_children(); + if (empty($children)) { + $children = array(); + } + return $children; + } } diff --git a/core/tests/Theme_Test.php b/core/tests/Theme_Test.php index 5b568b19..f73a98eb 100644 --- a/core/tests/Theme_Test.php +++ b/core/tests/Theme_Test.php @@ -19,16 +19,22 @@ */ class Theme_Test extends Unit_Test_Case { - public function teardown() { - theme::$debug_backtrace = "debug_backtrace"; + public function url_test() { + $theme = new Theme("fake_theme"); + $this->assert_equal("http://./themes/fake_theme/file", $theme->url("file")); } - public function url_test() { - theme::$debug_backtrace = array("Theme_Test", "_fake_debug_backtrace"); - $this->assert_equal("http://./themes/fake_theme/file", theme::url("file")); + public function display_test() { + $theme = new Theme("fake_theme"); + $view = $theme->display("test_page", "Theme_Test_Mock_View"); + $this->assert_equal("test_page", $view->page_name); } +} + +class Theme_Test_Mock_View { + public $page_name = null; - public function _fake_debug_backtrace() { - return array(array(), array('file' => THEMEPATH . "fake_theme/views/some_file.html.php")); + public function __construct($page_name) { + $this->page_name = $page_name; } } \ No newline at end of file diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php index 10930daa..2abb810f 100644 --- a/themes/default/views/album.html.php +++ b/themes/default/views/album.html.php @@ -1,72 +1,84 @@ - +display('header.html') ?> -
-
-

Christmas 2007

- (interesting information about the Album) - Slideshow -
+
+
+
+ -
- photo" /> -

Album title

- -
+
+
+

title ?>

+ description ?> + Slideshow +
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Album title

+ +
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- photo" /> -

Photo title

-
+
+ photo" /> +

Photo title

+
-
- Items 1-10 of 34 - first - previous - - last +
+ photo" /> +

Photo title

+
+ +
+ Items 1-10 of 34 + first + previous + + last +
+
+ +
+ display('sidebar.html') ?>
+ +display('footer.html') ?> diff --git a/themes/default/views/footer.html.php b/themes/default/views/footer.html.php new file mode 100644 index 00000000..ab40a417 --- /dev/null +++ b/themes/default/views/footer.html.php @@ -0,0 +1,7 @@ + +
+ Powered by GalleryX | About this Gallery | ... +
+
+ + diff --git a/themes/default/views/header.html.php b/themes/default/views/header.html.php new file mode 100644 index 00000000..797dcb7c --- /dev/null +++ b/themes/default/views/header.html.php @@ -0,0 +1,53 @@ + + + + + Browse Photos :: <?= $item->title ?> + + + + + + " media="screen,projection" /> + + + + + + + + + + + + +
+
+ " src="url("images/logo.png") ?>" /> + +

title ?>

+ +
+ | + +
+ + + + + +
+ "/> + +
+
diff --git a/themes/default/views/page_footer.html.php b/themes/default/views/page_footer.html.php deleted file mode 100644 index 4e15fbff..00000000 --- a/themes/default/views/page_footer.html.php +++ /dev/null @@ -1,4 +0,0 @@ - -
- Powered by GalleryX | About this Gallery | ... -
diff --git a/themes/default/views/page_header.html.php b/themes/default/views/page_header.html.php deleted file mode 100644 index 58eb8847..00000000 --- a/themes/default/views/page_header.html.php +++ /dev/null @@ -1,30 +0,0 @@ - -
- " src="" /> - -

title ?>

- -
- | - -
- - - - - -
- "/> - -
-
diff --git a/themes/default/views/page_sidebar.html.php b/themes/default/views/page_sidebar.html.php deleted file mode 100644 index 923b4e4e..00000000 --- a/themes/default/views/page_sidebar.html.php +++ /dev/null @@ -1,141 +0,0 @@ - -
- -
-

Album Navigation

- -
-
    -
  • Gallery -
      -
    • Friends & Family -
        -
      • Christmas 2006
      • -
      • Family Reunion
      • -
      • Christmas 2007
      • -
      -
    • -
    • Vactions -
        -
      • Cuba
      • -
      • Europe
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/themes/default/views/sidebar.html.php b/themes/default/views/sidebar.html.php new file mode 100644 index 00000000..923b4e4e --- /dev/null +++ b/themes/default/views/sidebar.html.php @@ -0,0 +1,141 @@ + +
+ +
+

Album Navigation

+ +
+
    +
  • Gallery +
      +
    • Friends & Family +
        +
      • Christmas 2006
      • +
      • Family Reunion
      • +
      • Christmas 2007
      • +
      +
    • +
    • Vactions +
        +
      • Cuba
      • +
      • Europe
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- cgit v1.2.3