summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gallery/helpers/gallery_theme.php24
-rw-r--r--modules/gallery/libraries/Admin_View.php17
-rw-r--r--modules/gallery/libraries/Gallery_View.php89
-rw-r--r--modules/gallery/libraries/Theme_View.php61
-rw-r--r--themes/admin_default/views/admin.html.php10
-rw-r--r--themes/default/views/page.html.php24
6 files changed, 128 insertions, 97 deletions
diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php
index b6b24b27..cffecb12 100644
--- a/modules/gallery/helpers/gallery_theme.php
+++ b/modules/gallery/helpers/gallery_theme.php
@@ -21,22 +21,6 @@ class gallery_theme_Core {
static function head($theme) {
$session = Session::instance();
$buf = "";
- $theme->script("lib/jquery.js");
- $theme->script("lib/jquery.form.js");
- $theme->script("lib/jquery-ui.js");
- $theme->script("lib/gallery.common.js");
- $theme->script("lib/gallery.dialog.js");
- $theme->script("lib/gallery.form.js");
- $theme->script("lib/superfish/js/superfish.js");
- if ($theme->page_type == 'photo') {
- $theme->script("lib/jquery.scrollTo.js");
- $theme->script("lib/jquery.localscroll.js");
- $theme->script("lib/gallery.show_full_size.js");
- }
- if ($theme->page_type == 'movie') {
- $theme->script("lib/flowplayer.js");
- }
- $theme->script($theme->url("js/ui.init.js", false, true));
if ($session->get("debug")) {
$buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .
url::file("modules/gallery/css/debug.css") . "\" />";
@@ -95,14 +79,6 @@ class gallery_theme_Core {
static function admin_head($theme) {
$session = Session::instance();
$buf = "";
- $theme->script("lib/jquery.js");
- $theme->script("lib/jquery.form.js");
- $theme->script("lib/jquery-ui.js");
- $theme->script("lib/gallery.common.js");
- $theme->script("lib/gallery.dialog.js");
- $theme->script("lib/superfish/js/superfish.js");
- $theme->script($theme->url("js/jquery.dropshadow.js", false, true));
- $theme->script($theme->url("js/ui.init.js", false, true));
if ($session->get("debug")) {
$buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .
url::file("modules/gallery/css/debug.css") . "\" />";
diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php
index 7a7396eb..01496c0d 100644
--- a/modules/gallery/libraries/Admin_View.php
+++ b/modules/gallery/libraries/Admin_View.php
@@ -17,9 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Admin_View_Core extends View {
- private $theme_name = null;
-
+class Admin_View_Core extends Gallery_View {
/**
* Attempts to load a view and pre-load view data.
*
@@ -46,15 +44,6 @@ class Admin_View_Core extends View {
$this->set_global("user", user::active());
}
- public function url($path, $absolute_url=false) {
- $arg = "themes/{$this->theme_name}/$path";
- return $absolute_url ? url::abs_file($arg) : url::file($arg);
- }
-
- public function display($page_name, $view_class="View") {
- return new $view_class($page_name);
- }
-
public function admin_menu() {
$menu = Menu::factory("root");
gallery_menu::admin($menu, $this);
@@ -109,6 +98,10 @@ class Admin_View_Core extends View {
}
}
+ if ($function == "admin_head") {
+ array_unshift($blocks, $this->combine_script());
+ }
+
if (Session::instance()->get("debug")) {
if ($function != "admin_head") {
array_unshift(
diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php
new file mode 100644
index 00000000..f2298b7d
--- /dev/null
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -0,0 +1,89 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 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 Gallery_View_Core extends View {
+ protected $theme_name = null;
+ protected $scripts = array();
+
+ /**
+ * Add a script to the combined scripts list.
+ * @param $file the relative path to a script from the gallery3 directory
+ */
+ public function script($file, $theme_relative=false) {
+ $this->scripts[$file] = 1;
+ }
+
+ /**
+ * Add a script to the combined scripts list.
+ * @param $file the relative path to a script from the base of the active theme
+ * @param
+ */
+ public function theme_script($file) {
+ $file = "themes/{$this->theme_name}/$file";
+ $this->scripts[$file] = 1;
+ }
+
+ /**
+ * Provide a url to a resource within the current theme. This allows us to refer to theme
+ * resources without naming the theme itself which makes themes easier to copy.
+ */
+ public function url($path, $absolute_url=false) {
+ $arg = "themes/{$this->theme_name}/$path";
+ return $absolute_url ? url::abs_file($arg) : url::file($arg);
+ }
+
+ /**
+ * Combine a series of Javascript files into a single one and cache it in the database, then
+ * return a single <script> element to refer to it.
+ */
+ protected function combine_script() {
+ $links = array();
+ $key = "";
+ foreach (array_keys($this->scripts) as $file) {
+ $path = DOCROOT . $file;
+ if (file_exists($path)) {
+ $stats = stat($path);
+ $links[] = $path;
+ // 7 == size, 9 == mtime, see http://php.net/stat
+ $key = "{$key}$file $stats[7] $stats[9],";
+ } else {
+ Kohana::log("alert", "Javascript file missing: " . $file);
+ }
+ }
+
+ $key = md5($key);
+ $cache = Cache::instance();
+ $contents = $cache->get($key);
+ if (empty($contents)) {
+ $contents = "";
+ foreach ($links as $link) {
+ $contents .= file_get_contents($link);
+ }
+ $cache->set($key, $contents, array("javascript"), 30 * 84600);
+ if (function_exists("gzencode")) {
+ $cache->set("{$key}_gz", gzencode($contents, 9, FORCE_GZIP),
+ array("javascript", "gzip"), 30 * 84600);
+ }
+ }
+
+ // Handcraft the script link because html::script will add a .js extenstion
+ return "<script type=\"text/javascript\" src=\"" . url::site("combined/javascript/$key") .
+ "\"></script>";
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index 25818821..8e320f44 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -17,10 +17,7 @@
* 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_View_Core extends View {
- private $theme_name = null;
- private $scripts = array();
-
+class Theme_View_Core extends Gallery_View {
/**
* Attempts to load a view and pre-load view data.
*
@@ -69,11 +66,6 @@ class Theme_View_Core extends View {
return module::get_var("gallery", "thumb_size", 200) / 200;
}
- public function url($path, $absolute_url=false, $no_root=false) {
- $arg = "themes/{$this->theme_name}/$path";
- return $absolute_url ? url::abs_file($arg) : $no_root ? $arg : url::file($arg);
- }
-
public function item() {
return $this->item;
}
@@ -86,10 +78,6 @@ class Theme_View_Core extends View {
return $this->page_type;
}
- public function display($page_name, $view_class="View") {
- return new $view_class($page_name);
- }
-
public function site_menu() {
$menu = Menu::factory("root");
if ($this->page_type != "login") {
@@ -168,49 +156,6 @@ class Theme_View_Core extends View {
return message::get();
}
- public function script($file) {
- $this->scripts[$file] = 1;
- }
-
- /**
- * Combine a series of Javascript files into a single one and cache it in the database, then
- * return a single <script> element to refer to it.
- */
- private function _combine_script() {
- $links = array();
- $key = "";
- foreach (array_keys($this->scripts) as $file) {
- $path = DOCROOT . $file;
- if (file_exists($path)) {
- $stats = stat($path);
- $links[] = $path;
- // 7 == size, 9 == mtime, see http://php.net/stat
- $key = "{$key}$file $stats[7] $stats[9],";
- } else {
- Kohana::log("warn", "Javascript file missing: " . $file);
- }
- }
-
- $key = md5($key);
- $cache = Cache::instance();
- $contents = $cache->get($key);
- if (empty($contents)) {
- $contents = "";
- foreach ($links as $link) {
- $contents .= file_get_contents($link);
- }
- $cache->set($key, $contents, array("javascript"), 30 * 84600);
- if (function_exists("gzencode")) {
- $cache->set("{$key}_gz", gzencode($contents, 9, FORCE_GZIP),
- array("javascript", "gzip"), 30 * 84600);
- }
- }
-
- // Handcraft the script link because html::script will add a .js extenstion
- return "<script type=\"text/javascript\" src=\"" . url::site("combined/javascript/$key") .
- "\"></script>";
- }
-
/**
* Handle all theme functions that insert module content.
*/
@@ -270,8 +215,8 @@ class Theme_View_Core extends View {
}
}
- if ($function == "head" || $function == "admin_head") {
- array_unshift($blocks, $this->_combine_script());
+ if ($function == "head") {
+ array_unshift($blocks, $this->combine_script());
}
if (Session::instance()->get("debug")) {
diff --git a/themes/admin_default/views/admin.html.php b/themes/admin_default/views/admin.html.php
index dfbafe31..2a91a76c 100644
--- a/themes/admin_default/views/admin.html.php
+++ b/themes/admin_default/views/admin.html.php
@@ -20,6 +20,16 @@
<link rel="stylesheet" type="text/css" href="<?= $theme->url("css/fix-ie.css") ?>"
media="screen,print,projection" />
<![endif]-->
+
+ <?= $theme->script("lib/jquery.js") ?>
+ <?= $theme->script("lib/jquery.form.js") ?>
+ <?= $theme->script("lib/jquery-ui.js") ?>
+ <?= $theme->script("lib/gallery.common.js") ?>
+ <?= $theme->script("lib/gallery.dialog.js") ?>
+ <?= $theme->script("lib/superfish/js/superfish.js") ?>
+ <?= $theme->theme_script("js/jquery.dropshadow.js") ?>
+ <?= $theme->theme_script("js/ui.init.js") ?>
+
<?= $theme->admin_head() ?>
</head>
diff --git a/themes/default/views/page.html.php b/themes/default/views/page.html.php
index c74d4097..8b9466ac 100644
--- a/themes/default/views/page.html.php
+++ b/themes/default/views/page.html.php
@@ -49,6 +49,24 @@
</style>
<? endif ?>
<? endif ?>
+ <?= $theme->script("lib/jquery.js") ?>
+ <?= $theme->script("lib/jquery.form.js") ?>
+ <?= $theme->script("lib/jquery-ui.js") ?>
+ <?= $theme->script("lib/gallery.common.js") ?>
+ <?= $theme->script("lib/gallery.dialog.js") ?>
+ <?= $theme->script("lib/gallery.form.js") ?>
+ <?= $theme->script("lib/superfish/js/superfish.js") ?>
+ <?= $theme->script("lib/jquery.localscroll.js") ?>
+ <?= $theme->theme_script("js/ui.init.js") ?>
+
+ <? /* These are page specific, but if we put them before $theme->head() they get combined */ ?>
+ <? if ($theme->page_type == "photo"): ?>
+ <?= $theme->script("lib/jquery.scrollTo.js") ?>
+ <?= $theme->script("lib/gallery.show_full_size.js") ?>
+ <? elseif ($theme->page_type == "movie"): ?>
+ <?= $theme->script("lib/flowplayer.js") ?>
+ <? endif ?>
+
<?= $theme->head() ?>
</head>
@@ -57,7 +75,7 @@
<div id="doc4" class="yui-t5 gView">
<?= $theme->site_status() ?>
<div id="gHeader">
- <?= $theme->display("header.html") ?>
+ <?= new View("header.html") ?>
</div>
<div id="bd">
<div id="yui-main">
@@ -70,12 +88,12 @@
</div>
<div id="gSidebar" class="yui-b">
<? if ($theme->page_type != "login"): ?>
- <?= $theme->display("sidebar.html") ?>
+ <?= new View("sidebar.html") ?>
<? endif ?>
</div>
</div>
<div id="gFooter">
- <?= $theme->display("footer.html") ?>
+ <?= new View("footer.html") ?>
</div>
</div>
<?= $theme->page_bottom() ?>