Merge branch 'master' of git@github.com:gallery/gallery3

This commit is contained in:
Chad Kieffer
2009-06-28 17:57:23 -06:00
17 changed files with 220 additions and 76 deletions
+2 -2
View File
@@ -19,8 +19,8 @@
*/
class comment_theme_Core {
static function head($theme) {
$url = url::file("modules/comment/js/comment.js");
return "<script src=\"$url\" type=\"text/javascript\"></script>\n";
$theme->script("modules/comment/js/comment.js");
return "";
}
static function photo_bottom($theme) {
+1 -1
View File
@@ -19,6 +19,6 @@
*/
class digibug_theme_Core {
static function head($theme) {
return html::script("modules/digibug/js/digibug.js");
$theme->script("modules/digibug/js/digibug.js");
}
}
@@ -0,0 +1,62 @@
<?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();
// 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;
}
$cache = Cache::instance();
if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ) {
$content = $cache->get("{$key}_gz");
}
if (empty($content)) {
$content = $cache->get($key);
}
if (empty($content)) {
Kohana::show_404();
}
if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) {
header("Content-Encoding: gzip");
header("Cache-Control: public");
}
header("Content-Type: text/javascript; charset=UTF-8");
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);
print $content;
}
}
+32 -17
View File
@@ -32,6 +32,16 @@ class gallery_installer {
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {caches} (
`id` int(9) NOT NULL auto_increment,
`key` 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 +191,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` 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);
}
@@ -258,7 +259,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 <a href=\"%url\">Gallery %version</a>");
module::set_version("gallery", 4);
module::set_version("gallery", 5);
}
static function upgrade($version) {
@@ -278,15 +279,29 @@ 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) {
Cache::instance()->delete_all();
$db->query("ALTER TABLE {caches} MODIFY COLUMN `cache` LONGBLOB");
module::set_version("gallery", $version = 5);
}
if ($version == 5) {
Cache::instance()->delete_all();
$db->query("ALTER TABLE {caches} DROP COLUMN `id`");
$db->query("ALTER TABLE {caches} ADD COLUMN `key` varchar(255) NOT NULL");
$db->query("ALTER TABLE {caches} ADD COLUMN `id` int(9) NOT NULL auto_increment PRIMARY KEY");
module::set_version("gallery", $version = 6);
}
}
static function uninstall() {
+29 -5
View File
@@ -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;
+72 -2
View File
@@ -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,49 @@ 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("javascript/combined/$key") .
"\"></script>";
}
/**
* Handle all theme functions that insert module content.
*/
@@ -196,7 +240,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 +269,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(
@@ -32,9 +32,8 @@ class Cache_Database_Driver implements Cache_Driver {
$this->db = Database::instance();
if (!$this->db->table_exists("caches")) {
throw new Kohana_Exception("cache.driver_error", "Cache table is not defined");
throw new Exception("@todo Cache table is not defined");
}
Kohana::log("debug", "Cache Database Driver Initialized");
}
/**
@@ -44,7 +43,7 @@ class Cache_Database_Driver implements Cache_Driver {
* @return boolean
*/
public function exists($id) {
$count = $this->db->count_records("caches", array("id" => $id, "expiration >=" => time()));
$count = $this->db->count_records("caches", array("key" => $id, "expiration >=" => time()));
return $count > 0;
}
@@ -68,13 +67,12 @@ 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));
array("tags" => $tags, "expiration" => $lifetime, "cache" => $data), array("key" => $id));
} else {
$status = $this->db->insert("caches",
array("id" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => $data));
array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => $data));
}
return count($status) > 0;
@@ -101,7 +99,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
@@ -120,7 +118,7 @@ class Cache_Database_Driver implements Cache_Driver {
*/
public function get($id) {
$data = null;
$result = $this->db->getwhere("caches", array("id" => $id));
$result = $this->db->getwhere("caches", array("key" => $id));
if (count($result) > 0) {
$cache = $result->current();
@@ -133,7 +131,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);
@@ -158,7 +156,7 @@ class Cache_Database_Driver implements Cache_Driver {
} else if ($tag === true) {
$this->db->like("tags", "<$id>");
} else {
$this->db->where("id", $id);
$this->db->where("key", $id);
}
$status = $this->db->delete();
+1 -1
View File
@@ -1,3 +1,3 @@
name = Gallery 3
description = Gallery core application
version = 4
version = 6
+3 -5
View File
@@ -20,11 +20,9 @@
class organize_theme {
static function head($theme) {
// @tdo remove the addition css and organize.js (just here to test)
$script[] = html::script("modules/organize/js/organize_init.js");
$script[] = html::script("modules/organize/js/organize.js");
$script[] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .
$theme->script("modules/organize/js/organize_init.js");
$theme->script("modules/organize/js/organize.js");
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .
url::file("modules/organize/css/organize.css") . "\" />";
return implode("\n", $script);
//return html::script("modules/organize/js/organize_init.js");
}
}
@@ -20,7 +20,7 @@
class server_add_theme_Core {
static function head($theme) {
if (user::active()->admin) {
return html::script("modules/server_add/js/server_add.js");
$theme->script("modules/server_add/js/server_add.js");
}
}
@@ -33,8 +33,8 @@ class server_add_theme_Core {
$csrf = access::csrf_token();
$head[] = "<script> var base_url = \"$base\"; var csrf = \"$csrf\";</script>";
$head[] = html::script("lib/jquery.autocomplete.js");
$head[] = html::script("modules/server_add/js/admin.js");
$theme->script("lib/jquery.autocomplete.js");
$theme->script("modules/server_add/js/admin.js");
}
return implode("\n", $head);
+5 -2
View File
@@ -19,8 +19,11 @@
*/
class tag_theme_Core {
static function head($theme) {
$url = url::file("modules/tag/js/tag.js");
return "<script src=\"$url\" type=\"text/javascript\"></script>";
$theme->script("modules/tag/js/tag.js");
}
static function admin_head($theme) {
$theme->script("modules/tag/js/tag.js");
}
static function sidebar_blocks($theme) {
-1
View File
@@ -1,5 +1,4 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<script src="<?= url::file("modules/tag/js/tag.js") ?>" type="text/javascript"></script>
<script>
var TAG_RENAME_URL = "<?= url::site("admin/tags/rename/__ID__") ?>";
$("document").ready(function() {
+1 -4
View File
@@ -25,11 +25,8 @@ class user_theme_Core {
}
static function admin_head($theme) {
$head = array();
if (strpos(Router::$current_uri, "admin/users") !== false) {
$head[] = html::script("lib/gallery.panel.js");
$theme->script("lib/gallery.panel.js");
}
return implode("\n", $head);
}
}
+1 -9
View File
@@ -20,15 +20,7 @@
<link rel="stylesheet" type="text/css" href="<?= $theme->url("css/fix-ie.css") ?>"
media="screen,print,projection" />
<![endif]-->
<script src="<?= url::file("lib/jquery.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/jquery.form.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/jquery-ui.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/gallery.common.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/gallery.dialog.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/superfish/js/superfish.js") ?>" type="text/javascript"></script>
<script src="<?= $theme->url("js/jquery.dropshadow.js") ?>" type="text/javascript"></script>
<script src="<?= $theme->url("js/ui.init.js") ?>" type="text/javascript"></script>
<?= $theme->admin_head() ?>
<?= $theme->admin_head() ?>
</head>
<body <?= $theme->body_attributes() ?>>
-1
View File
@@ -1,5 +1,4 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<script src="<?= url::file("lib/flowplayer.js") ?>" type="text/javascript"></script>
<div id="gItem">
<?= $theme->photo_top() ?>
-12
View File
@@ -49,18 +49,6 @@
</style>
<? endif ?>
<? endif ?>
<script src="<?= url::file("lib/jquery.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/jquery.form.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/jquery-ui.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/gallery.common.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/gallery.dialog.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/gallery.form.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/superfish/js/superfish.js") ?>" type="text/javascript"></script>
<? if ($theme->page_type == 'photo'): ?>
<script src="<?= url::file("lib/jquery.scrollTo.js") ?>" type="text/javascript"></script>
<script src="<?= url::file("lib/jquery.localscroll.js") ?>" type="text/javascript"></script>
<? endif ?>
<script src="<?= $theme->url("js/ui.init.js") ?>" type="text/javascript"></script>
<?= $theme->head() ?>
</head>
-1
View File
@@ -2,7 +2,6 @@
<? if (access::can("view_full", $theme->item())): ?>
<!-- Use javascript to show the full size as an overlay on the current page -->
<script src="<?= url::file("lib/gallery.show_full_size.js") ?>" type="text/javascript"></script>
<script>
$(document).ready(function() {
$(".gFullSizeLink").click(function() {