From 42a5bd20a550a9edb5ec84625037b9d85889ff63 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 26 Jun 2009 07:51:29 -0700 Subject: 1) Move the generation of script tags to gallery_theme::head and gallery_theme::admin_head. This allows us to potentially manage the scripts like we do in g2 (single file and compressed) 2) Change Theme_View::_call to always call the gallery_theme::$function first. --- modules/gallery/helpers/gallery_theme.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index a96c8f5b..24f4129b 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -21,6 +21,18 @@ class gallery_theme_Core { static function head($theme) { $session = Session::instance(); $buf = ""; + $buf .= html::script("lib/jquery.js"); + $buf .= html::script("lib/jquery.form.js"); + $buf .= html::script("lib/jquery-ui.js"); + $buf .= html::script("lib/gallery.common.js"); + $buf .= html::script("lib/gallery.dialog.js"); + $buf .= html::script("lib/gallery.form.js"); + $buf .= html::script("lib/superfish/js/superfish.js"); + if ($theme->page_type == 'photo') { + $buf .= html::script("lib/jquery.scrollTo.js"); + $buf .= html::script("lib/jquery.localscroll.js"); + } + $buf .= html::script($theme->url("js/ui.init.js", false, true)); if ($session->get("debug")) { $buf .= ""; @@ -79,6 +91,14 @@ class gallery_theme_Core { static function admin_head($theme) { $session = Session::instance(); $buf = ""; + $buf .= html::script("lib/jquery.js"); + $buf .= html::script("lib/jquery.form.js"); + $buf .= html::script("lib/jquery-ui.js"); + $buf .= html::script("lib/gallery.common.js"); + $buf .= html::script("lib/gallery.dialog.js"); + $buf .= html::script("lib/superfish/js/superfish.js"); + $buf .= html::script($theme->url("js/jquery.dropshadow.js", false, true)); + $buf .= html::script($theme->url("js/ui.init.js", false, true)); if ($session->get("debug")) { $buf .= ""; -- cgit v1.2.3 From 84e98e830c4967c277dfcb5bb6d18c0ec3313355 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 26 Jun 2009 08:25:24 -0700 Subject: Move the inclusion of photo and movie specific javascript into gallery_theme --- modules/gallery/helpers/gallery_theme.php | 4 ++++ themes/default/views/movie.html.php | 1 - themes/default/views/photo.html.php | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 24f4129b..0679087e 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -31,6 +31,10 @@ class gallery_theme_Core { if ($theme->page_type == 'photo') { $buf .= html::script("lib/jquery.scrollTo.js"); $buf .= html::script("lib/jquery.localscroll.js"); + $buf .= html::script("lib/gallery.show_full_size.js"); + } + if ($theme->page_type == 'movie') { + $buf .= html::script("lib/flowplayer.js"); } $buf .= html::script($theme->url("js/ui.init.js", false, true)); if ($session->get("debug")) { diff --git a/themes/default/views/movie.html.php b/themes/default/views/movie.html.php index e8559697..134e3571 100644 --- a/themes/default/views/movie.html.php +++ b/themes/default/views/movie.html.php @@ -1,5 +1,4 @@ -
photo_top() ?> diff --git a/themes/default/views/photo.html.php b/themes/default/views/photo.html.php index 1c3b81a7..4765a4e3 100644 --- a/themes/default/views/photo.html.php +++ b/themes/default/views/photo.html.php @@ -2,7 +2,6 @@ item())): ?> - \n"; + $theme->script("modules/comment/js/comment.js"); + return ""; } static function photo_bottom($theme) { diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 0679087e..b6b24b27 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -21,22 +21,22 @@ class gallery_theme_Core { static function head($theme) { $session = Session::instance(); $buf = ""; - $buf .= html::script("lib/jquery.js"); - $buf .= html::script("lib/jquery.form.js"); - $buf .= html::script("lib/jquery-ui.js"); - $buf .= html::script("lib/gallery.common.js"); - $buf .= html::script("lib/gallery.dialog.js"); - $buf .= html::script("lib/gallery.form.js"); - $buf .= html::script("lib/superfish/js/superfish.js"); + $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') { - $buf .= html::script("lib/jquery.scrollTo.js"); - $buf .= html::script("lib/jquery.localscroll.js"); - $buf .= html::script("lib/gallery.show_full_size.js"); + $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') { - $buf .= html::script("lib/flowplayer.js"); + $theme->script("lib/flowplayer.js"); } - $buf .= html::script($theme->url("js/ui.init.js", false, true)); + $theme->script($theme->url("js/ui.init.js", false, true)); if ($session->get("debug")) { $buf .= ""; @@ -45,7 +45,7 @@ class gallery_theme_Core { && access::can("edit", $theme->item())) { $buf .= ""; - $buf .= html::script("modules/gallery/js/quick.js"); + $theme->script("modules/gallery/js/quick.js"); } if (module::is_active("rss")) { @@ -59,8 +59,8 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= ""; - $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; @@ -95,14 +95,14 @@ class gallery_theme_Core { static function admin_head($theme) { $session = Session::instance(); $buf = ""; - $buf .= html::script("lib/jquery.js"); - $buf .= html::script("lib/jquery.form.js"); - $buf .= html::script("lib/jquery-ui.js"); - $buf .= html::script("lib/gallery.common.js"); - $buf .= html::script("lib/gallery.dialog.js"); - $buf .= html::script("lib/superfish/js/superfish.js"); - $buf .= html::script($theme->url("js/jquery.dropshadow.js", false, true)); - $buf .= html::script($theme->url("js/ui.init.js", false, true)); + $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 .= ""; @@ -111,8 +111,8 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= ""; - $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 5235fabb..7696f3b0 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. @@ -163,6 +164,19 @@ class Theme_View_Core extends View { return message::get(); } + public function script($file) { + $this->scripts[$file] = 1; + } + + private function _combine_script() { + $links = array(); + Kohana::log("error", Kohana::debug($this->scripts)); + foreach (array_keys($this->scripts) as $file) { + $links[] = html::script($file); + } + return empty($links) ? "" : implode("\n", $links); + } + /** * Handle all theme functions that insert module content. */ @@ -221,6 +235,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( -- cgit v1.2.3 From 3000c789986d93b3911a3217d7153b0de041c887 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 27 Jun 2009 23:30:02 -0700 Subject: Update the version number and upgrade method for gallery to reflect the addition of the cache table. --- modules/gallery/helpers/gallery_installer.php | 25 ++++++++++++++++++++++++- modules/gallery/module.info | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index df555d52..92fc662d 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -181,6 +181,15 @@ class gallery_installer { UNIQUE KEY(`module_name`, `name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE {caches} ( + `id` varchar(255) NOT NULL, + `tags` varchar(255), + `expiration` int(9) NOT NULL, + `cache` text, + PRIMARY KEY (`id`), + KEY (`tags`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) { @mkdir(VARPATH . $dir); } @@ -249,10 +258,11 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by Gallery %version"); - module::set_version("gallery", 3); + module::set_version("gallery", 4); } static function upgrade($version) { + $db = Database::instance(); if ($version == 1) { module::set_var("gallery", "date_format", "Y-M-d"); module::set_var("gallery", "date_time_format", "Y-M-d H:i:s"); @@ -265,6 +275,18 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); module::set_version("gallery", $version = 3); } + + if ($version == 3) { + $db->query("CREATE TABLE {caches} ( + `id` varchar(255) NOT NULL, + `tags` varchar(255), + `expiration` int(9) NOT NULL, + `cache` text, + PRIMARY KEY (`id`), + KEY (`tags`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + module::set_version("gallery", $version = 4); + } } static function uninstall() { @@ -282,6 +304,7 @@ class gallery_installer { $db->query("DROP TABLE IF EXISTS {tasks}"); $db->query("DROP TABLE IF EXISTS {themes}"); $db->query("DROP TABLE IF EXISTS {vars}"); + $db->query("DROP TABLE IF EXISTS {caches}"); foreach (array("albums", "resizes", "thumbs", "uploads", "modules", "logs", "database.php") as $entry) { system("/bin/rm -rf " . VARPATH . $entry); diff --git a/modules/gallery/module.info b/modules/gallery/module.info index e5b1f809..1a44ce51 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = Gallery 3 description = Gallery core application -version = 3 +version = 4 -- cgit v1.2.3 From 7a3310e91b50f37b09a1c9d10173409244015653 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 28 Jun 2009 13:14:47 -0700 Subject: Change the cache column of the caches table to a large blob. This fixes ticket #485 and gives us the extra adavantage of not having to serialize the data (as the database driver handles that for us) --- modules/gallery/helpers/gallery_installer.php | 9 +++++++-- modules/gallery/libraries/drivers/Cache/Database.php | 5 ++--- modules/gallery/module.info | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 92fc662d..8ccbd51b 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -185,7 +185,7 @@ class gallery_installer { `id` varchar(255) NOT NULL, `tags` varchar(255), `expiration` int(9) NOT NULL, - `cache` text, + `cache` longblob, PRIMARY KEY (`id`), KEY (`tags`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); @@ -258,7 +258,7 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by Gallery %version"); - module::set_version("gallery", 4); + module::set_version("gallery", 5); } static function upgrade($version) { @@ -287,6 +287,11 @@ class gallery_installer { ENGINE=InnoDB DEFAULT CHARSET=utf8;"); module::set_version("gallery", $version = 4); } + if ($version == 4) { + Cache::instance()->delete_all(); + $db->query("ALTER TABLE {caches} modify column cache LONGBLOB"); + module::set_version("gallery", $version = 5); + } } static function uninstall() { diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 70235e05..158f7b3a 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -68,7 +68,6 @@ class Cache_Database_Driver implements Cache_Driver { $lifetime += time(); } - $data = serialize($data); if ($this->exists($id)) { $status = $this->db->update("caches", array("tags" => $tags, "expiration" => $lifetime, "cache" => $data), array("id" => $id)); @@ -101,7 +100,7 @@ class Cache_Database_Driver implements Cache_Driver { foreach ($db_result as $row) { // Add each cache to the array - $result[$row->id] = unserialize($row->cache); + $result[$row->id] = $row->cache; } // Turn notices back on @@ -133,7 +132,7 @@ class Cache_Database_Driver implements Cache_Driver { $ER = error_reporting(~E_NOTICE); // Return the valid cache data - $data = unserialize($cache->cache); + $data = $cache->cache; // Turn notices back on error_reporting($ER); diff --git a/modules/gallery/module.info b/modules/gallery/module.info index 1a44ce51..817fdddd 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = Gallery 3 description = Gallery core application -version = 4 +version = 5 -- cgit v1.2.3 From aa31e1f0090522c3cfb3a44b947ad8c33a275979 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 28 Jun 2009 16:24:51 -0700 Subject: Tweak the cache implementation 1) Drop the *_modified key, we don't really need it. The modification date is not relevant to our browser caching strategy. 2) Fix multiple issues with the Expires header and just hardcode it to the biggest possibly value for code clarity. 3) print the $content out directly instead of using fwrite 4) Minor cleanups in the installer. --- modules/gallery/controllers/javascript.php | 21 ++++++------------ modules/gallery/helpers/gallery_installer.php | 32 +++++++++++++-------------- modules/gallery/libraries/Theme_View.php | 16 +++++++++----- 3 files changed, 33 insertions(+), 36 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/controllers/javascript.php b/modules/gallery/controllers/javascript.php index bc231e0a..ba5cbf4b 100644 --- a/modules/gallery/controllers/javascript.php +++ b/modules/gallery/controllers/javascript.php @@ -27,16 +27,13 @@ class Javascript_Controller extends Controller { // We don't need to save the session for this request Session::abort_save(); - // Dump out the javascript file - $cache = Cache::instance(); - - $modified = $cache->get("{$key}_modified"); - if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && !empty($modified)) { + // Our data is immutable, so if they already have a copy then it needs no updating. + if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"])) { header('HTTP/1.0 304 Not Modified'); return; } - $content = ""; + $cache = Cache::instance(); if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ) { $content = $cache->get("{$key}_gz"); } @@ -51,19 +48,15 @@ class Javascript_Controller extends Controller { if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) { header("Content-Encoding: gzip"); - header("Cache-Control: private, x-gzip-ok=\"public\""); + header("Cache-Control: public"); } header("Content-Type: text/javascript; charset=UTF-8"); - - header("Expires: " . gmdate(21474383647)); - header("Last-Modified: " . $modified); + header("Expires: Tue, 19 Jan 2038 00:00:00 GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s T", time())); Kohana::close_buffers(false); - - $handle = fopen("php://output", "wb"); - fwrite($handle, $content); - fclose($handle); + print $content; } } diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 8ccbd51b..d0bfa629 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -32,6 +32,15 @@ class gallery_installer { PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE {caches} ( + `id` varchar(255) NOT NULL, + `tags` varchar(255), + `expiration` int(9) NOT NULL, + `cache` longblob, + PRIMARY KEY (`id`), + KEY (`tags`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE {graphics_rules} ( `id` int(9) NOT NULL auto_increment, `active` BOOLEAN default 0, @@ -181,15 +190,6 @@ class gallery_installer { UNIQUE KEY(`module_name`, `name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - $db->query("CREATE TABLE {caches} ( - `id` varchar(255) NOT NULL, - `tags` varchar(255), - `expiration` int(9) NOT NULL, - `cache` longblob, - PRIMARY KEY (`id`), - KEY (`tags`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) { @mkdir(VARPATH . $dir); } @@ -278,13 +278,13 @@ class gallery_installer { if ($version == 3) { $db->query("CREATE TABLE {caches} ( - `id` varchar(255) NOT NULL, - `tags` varchar(255), - `expiration` int(9) NOT NULL, - `cache` text, - PRIMARY KEY (`id`), - KEY (`tags`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + `id` varchar(255) NOT NULL, + `tags` varchar(255), + `expiration` int(9) NOT NULL, + `cache` text, + PRIMARY KEY (`id`), + KEY (`tags`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); module::set_version("gallery", $version = 4); } if ($version == 4) { diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index f55cb55a..c3acfeb3 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -172,6 +172,10 @@ class Theme_View_Core extends View { $this->scripts[$file] = 1; } + /** + * Combine a series of Javascript files into a single one and cache it in the database, then + * return a single