summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/albums.php6
-rw-r--r--core/controllers/photos.php8
-rw-r--r--core/libraries/Theme_View.php (renamed from core/libraries/Theme.php)29
-rw-r--r--core/tests/Theme_Test.php47
-rw-r--r--modules/tag/controllers/tags.php6
-rw-r--r--themes/default/views/form.html.php70
6 files changed, 60 insertions, 106 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php
index c2935c09..50317979 100644
--- a/core/controllers/albums.php
+++ b/core/controllers/albums.php
@@ -27,19 +27,15 @@ class Albums_Controller extends Items_Controller {
$theme_name = "default";
$page_size = 9;
- $template = new View("page.html");
+ $template = new Theme_View("page.html", "album", $theme_name);
$page = $this->input->get("page", "1");
- $theme = new Theme($theme_name, $template);
- $template->set_global("page_type", "album");
$template->set_global('page_size', $page_size);
$template->set_global('item', $item);
$template->set_global('children', $item->children($page_size, ($page - 1) * $page_size));
$template->set_global('children_count', $item->children_count());
$template->set_global('parents', $item->parents());
- $template->set_global('theme', $theme);
- $template->set_global('user', Session::instance()->get('user', null));
$template->content = new View("album.html");
print $template;
diff --git a/core/controllers/photos.php b/core/controllers/photos.php
index 2e0c63f5..143c3bb8 100644
--- a/core/controllers/photos.php
+++ b/core/controllers/photos.php
@@ -23,18 +23,14 @@ class Photos_Controller extends Items_Controller {
* @see Rest_Controller::_show($resource)
*/
public function _show($item) {
- $template = new View("page.html");
-
// @todo: this needs to be data-driven
- $theme = new Theme("default", $template);
+ $template = new Theme_View("page.html", "photo", "default");
- $template->set_global("page_type", "photo");
$template->set_global('item', $item);
$template->set_global('children', $item->children());
$template->set_global('children_count', $item->children_count());
$template->set_global('parents', $item->parents());
- $template->set_global('theme', $theme);
- $template->set_global('user', Session::instance()->get('user', null));
+
$template->content = new View("photo.html");
print $template;
diff --git a/core/libraries/Theme.php b/core/libraries/Theme_View.php
index 99a44f9f..5bb1b843 100644
--- a/core/libraries/Theme.php
+++ b/core/libraries/Theme_View.php
@@ -17,13 +17,24 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Theme_Core {
+class Theme_View_Core extends View {
private $theme_name = null;
- private $template = null;
- public function __construct($theme_name, $template) {
+ /**
+ * Attempts to load a view and pre-load view data.
+ *
+ * @throws Kohana_Exception if the requested view cannot be found
+ * @param string $name view name
+ * @param string $page_type page type: album, photo, tags, admin, etc
+ * @param string $theme_name view name
+ * @return void
+ */
+ public function __construct($name, $page_type, $theme_name="default") {
+ parent::__construct($name);
$this->theme_name = $theme_name;
- $this->template = $template;
+ $this->set_global('theme', $this);
+ $this->set_global('user', Session::instance()->get('user', null));
+ $this->set_global("page_type", $page_type);
}
public function url($path) {
@@ -31,11 +42,11 @@ class Theme_Core {
}
public function item() {
- return $this->template->item;
+ return $this->item;
}
public function page_type() {
- return $this->template->page_type;
+ return $this->page_type;
}
public function display($page_name, $view_class="View") {
@@ -46,8 +57,8 @@ class Theme_Core {
$this->pagination = new Pagination();
$this->pagination->initialize(
array('query_string' => 'page',
- 'total_items' => $this->template->children_count,
- 'items_per_page' => $this->template->page_size,
+ 'total_items' => $this->children_count,
+ 'items_per_page' => $this->page_size,
'style' => 'classic'));
return $this->pagination->render();
}
@@ -104,4 +115,4 @@ class Theme_Core {
throw new Exception("@todo UNKNOWN_THEME_FUNCTION: $function");
}
}
-}
+} \ No newline at end of file
diff --git a/core/tests/Theme_Test.php b/core/tests/Theme_Test.php
deleted file mode 100644
index 8852a6a1..00000000
--- a/core/tests/Theme_Test.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2008 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-class Theme_Test extends Unit_Test_Case {
- public function url_test() {
- $theme = new Theme("fake_theme", new View());
- $this->assert_equal("http://./themes/fake_theme/file", $theme->url("file"));
- }
-
- public function display_test() {
- $theme = new Theme("fake_theme", new View());
- $view = $theme->display("test_page", "Theme_Test_Mock_View");
- $this->assert_equal("test_page", $view->page_name);
- }
-
- public function item_test() {
- $v = new View();
- $v->item = "fake_item";
- $theme = new Theme("fake_theme", $v);
- $this->assert_equal("fake_item", $theme->item());
- }
-}
-
-class Theme_Test_Mock_View {
- public $page_name = null;
-
- public function __construct($page_name) {
- $this->page_name = $page_name;
- }
-} \ No newline at end of file
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index e2ab8f87..34474be5 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -25,18 +25,14 @@ class Tags_Controller extends REST_Controller {
$theme_name = "default";
$page_size = 9;
- $template = new View("page.html");
+ $template = new Theme_View("page.html", "tag", $theme_name);
$page = $this->input->get("page", "1");
- $theme = new Theme($theme_name, $template);
- $template->set_global("page_type", "tag");
$template->set_global('page_size', $page_size);
$template->set_global('tag', $tag);
$template->set_global('children', $tag->items($page_size, ($page-1) * $page_size));
$template->set_global('children_count', $tag->count);
- $template->set_global('theme', $theme);
- $template->set_global('user', Session::instance()->get('user', null));
$template->content = new View("tag.html");
print $template;
diff --git a/themes/default/views/form.html.php b/themes/default/views/form.html.php
index 1873c53e..41bdc0f9 100644
--- a/themes/default/views/form.html.php
+++ b/themes/default/views/form.html.php
@@ -10,43 +10,45 @@ if ($title) {
print "<!-- unused title in form.html.php: $title -->";
}
-function DrawForm($inputs, $level=1) {
- $error_messages = array();
- $prefix = str_repeat(" ", $level);
+if (!function_exists("DrawForm")) {
+ function DrawForm($inputs, $level=1) {
+ $error_messages = array();
+ $prefix = str_repeat(" ", $level);
- foreach ($inputs as $input) {
- if ($input->type == 'group') {
- print "$prefix<fieldset>\n";
- print "$prefix <legend>$input->name</legend>\n";
- print "$prefix <ul>\n";
- DrawForm($input->inputs, $level + 2);
- DrawForm($input->hidden, $level + 2);
- print "$prefix </ul>\n";
- print "$prefix</fieldset>\n";
- } else {
- if ($input->error_messages()) {
- print "$prefix<li class=\"gError\">\n";
- } else if ($input->type) {
- print "$prefix<li>\n";
+ foreach ($inputs as $input) {
+ if ($input->type == 'group') {
+ print "$prefix<fieldset>\n";
+ print "$prefix <legend>$input->name</legend>\n";
+ print "$prefix <ul>\n";
+ DrawForm($input->inputs, $level + 2);
+ DrawForm($input->hidden, $level + 2);
+ print "$prefix </ul>\n";
+ print "$prefix</fieldset>\n";
} else {
- // no type means its a "hidden" so don't wrap it in <li>
- }
- if ($input->label()) {
- print "$prefix {$input->label()}\n";
- }
- print "$prefix {$input->render()}\n";
- if ($input->message()) {
- print "$prefix <p>{$input->message()}</p>\n";
- }
- if ($input->error_messages()) {
- foreach ($input->error_messages() as $error_message) {
- print "$prefix <p class=\"gError\">\n";
- print "$prefix $error_message\n";
- print "$prefix </p>\n";
+ if ($input->error_messages()) {
+ print "$prefix<li class=\"gError\">\n";
+ } else if ($input->type) {
+ print "$prefix<li>\n";
+ } else {
+ // no type means its a "hidden" so don't wrap it in <li>
+ }
+ if ($input->label()) {
+ print "$prefix {$input->label()}\n";
+ }
+ print "$prefix {$input->render()}\n";
+ if ($input->message()) {
+ print "$prefix <p>{$input->message()}</p>\n";
+ }
+ if ($input->error_messages()) {
+ foreach ($input->error_messages() as $error_message) {
+ print "$prefix <p class=\"gError\">\n";
+ print "$prefix $error_message\n";
+ print "$prefix </p>\n";
+ }
+ }
+ if ($input->type) {
+ print "$prefix</li>\n";
}
- }
- if ($input->type) {
- print "$prefix</li>\n";
}
}
}