diff options
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/controllers/javascript.php | 64 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 34 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 67 |
3 files changed, 158 insertions, 7 deletions
diff --git a/modules/gallery/controllers/javascript.php b/modules/gallery/controllers/javascript.php new file mode 100644 index 00000000..d3c0ded5 --- /dev/null +++ b/modules/gallery/controllers/javascript.php @@ -0,0 +1,64 @@ +<?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 Javascript_Controller extends Controller { + public function combined($key) { + if (preg_match('/[^0-9a-f]/', $key)) { + /* The key can't contain non-hex, so just terminate early */ + Kohana::show_404(); + } + + // We don't need to save the session for this request + Session::abort_save(); + + Kohana::log("error", Kohana::debug($_SERVER)); + // Dump out the javascript file + $ext = strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ? "_gzip" : ""; + $file = VARPATH . "tmp/CombinedJavascript_$key{$ext}"; + + if (!file_exists($file)) { + Kohana::show_404(); + } + + $stats = stat($file); + if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && + $stats[9] <= $_SERVER["HTTP_IF_MODIFIED_SINCE"]) { + header("HTTP/1.0 304 Not Modified"); + return; + } + + Kohana::log("error", Kohana::debug($_SERVER)); + if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) { + header("Content-Encoding: gzip"); + header("Cache-Control: private, x-gzip-ok=\"public\""); + } + + header("Content-Type: text/javascript; charset=UTF-8"); + + header("Expires: " . gmdate(21474383647)); + header("Last-Modified: " . gmdate($stats[9])); + + Kohana::close_buffers(false); + + $fd = fopen($file, "rb"); + fpassthru($fd); + fclose($fd); + } +} + diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index a96c8f5b..b6b24b27 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -21,6 +21,22 @@ 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") . "\" />"; @@ -29,7 +45,7 @@ class gallery_theme_Core { && access::can("edit", $theme->item())) { $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . url::file("modules/gallery/css/quick.css") . "\" />"; - $buf .= html::script("modules/gallery/js/quick.js"); + $theme->script("modules/gallery/js/quick.js"); } if (module::is_active("rss")) { @@ -43,8 +59,8 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . url::file("modules/gallery/css/l10n_client.css") . "\" />"; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("modules/gallery/js/l10n_client.js"); + $theme->script("lib/jquery.cookie.js"); + $theme->script("modules/gallery/js/l10n_client.js"); } return $buf; @@ -79,6 +95,14 @@ 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") . "\" />"; @@ -87,8 +111,8 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . url::file("modules/gallery/css/l10n_client.css") . "\" />"; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("modules/gallery/js/l10n_client.js"); + $theme->script("lib/jquery.cookie.js"); + $theme->script("modules/gallery/js/l10n_client.js"); } return $buf; diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 4612a74b..167f8a8d 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -19,6 +19,7 @@ */ class Theme_View_Core extends View { private $theme_name = null; + private $scripts = array(); /** * Attempts to load a view and pre-load view data. @@ -68,9 +69,9 @@ class Theme_View_Core extends View { return module::get_var("gallery", "thumb_size", 200) / 200; } - public function url($path, $absolute_url=false) { + public function url($path, $absolute_url=false, $no_root=false) { $arg = "themes/{$this->theme_name}/$path"; - return $absolute_url ? url::abs_file($arg) : url::file($arg); + return $absolute_url ? url::abs_file($arg) : $no_root ? $arg : url::file($arg); } public function item() { @@ -167,6 +168,42 @@ class Theme_View_Core extends View { return message::get(); } + public function script($file) { + $this->scripts[$file] = 1; + } + + 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); + $file = "tmp/CombinedJavascript_$key"; + if (!file_exists(VARPATH . $file)) { + $contents = ''; + foreach ($links as $link) { + $contents .= file_get_contents($link); + } + file_put_contents(VARPATH . $file, $contents); + if (function_exists("gzencode")) { + file_put_contents(VARPATH . "{$file}_gzip", gzencode($contents, 9, FORCE_GZIP)); + } + } + + return "<script type=\"text/javascript\" src=\"" . url::site("javascript/combined/$key") . + "\"></script>"; + } + /** * Handle all theme functions that insert module content. */ @@ -196,7 +233,28 @@ class Theme_View_Core extends View { case "thumb_info": case "thumb_top": $blocks = array(); + if (method_exists("gallery_theme", $function)) { + switch (count($args)) { + case 0: + $blocks[] = gallery_theme::$function($this); + break; + case 1: + $blocks[] = gallery_theme::$function($this, $args[0]); + break; + case 2: + $blocks[] = gallery_theme::$function($this, $args[0], $args[1]); + break; + default: + $blocks[] = call_user_func_array( + array("gallery_theme", $function), + array_merge(array($this), $args)); + } + + } foreach (module::active() as $module) { + if ($module->name == "gallery") { + continue; + } $helper_class = "{$module->name}_theme"; if (method_exists($helper_class, $function)) { $blocks[] = call_user_func_array( @@ -204,6 +262,11 @@ class Theme_View_Core extends View { array_merge(array($this), $args)); } } + + if ($function == "head" || $function == "admin_head") { + array_unshift($blocks, $this->_combine_script()); + } + if (Session::instance()->get("debug")) { if ($function != "head") { array_unshift( |