summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/admin_languages.php12
-rw-r--r--modules/gallery/controllers/albums.php2
-rw-r--r--modules/gallery/controllers/file_proxy.php13
-rw-r--r--modules/gallery/controllers/movies.php4
-rw-r--r--modules/gallery/controllers/packager.php2
-rw-r--r--modules/gallery/controllers/photos.php4
-rw-r--r--modules/gallery/helpers/gallery.php9
-rw-r--r--modules/gallery/helpers/gallery_event.php4
-rw-r--r--modules/gallery/helpers/gallery_graphics.php2
-rw-r--r--modules/gallery/helpers/graphics.php86
-rw-r--r--modules/gallery/helpers/item.php88
-rw-r--r--modules/gallery/helpers/l10n_client.php23
-rw-r--r--modules/gallery/helpers/module.php2
-rw-r--r--modules/gallery/helpers/movie.php14
-rw-r--r--modules/gallery/helpers/system.php43
-rw-r--r--modules/gallery/libraries/Admin_View.php5
-rw-r--r--modules/gallery/libraries/Gallery_View.php61
-rw-r--r--modules/gallery/libraries/Theme_View.php14
-rw-r--r--modules/gallery/models/item.php85
-rw-r--r--modules/gallery/views/movieplayer.html.php3
20 files changed, 273 insertions, 203 deletions
diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php
index 573ededf..f96a0eb7 100644
--- a/modules/gallery/controllers/admin_languages.php
+++ b/modules/gallery/controllers/admin_languages.php
@@ -74,9 +74,11 @@ class Admin_Languages_Controller extends Admin_Controller {
private function _save_api_key($form) {
$new_key = $form->sharing->api_key->value;
- if ($new_key && !l10n_client::validate_api_key($new_key)) {
- $form->sharing->api_key->add_error("invalid", 1);
- $valid = false;
+ if ($new_key) {
+ list($connected, $valid) = l10n_client::validate_api_key($new_key);
+ if (!$valid) {
+ $form->sharing->api_key->add_error($connected ? "invalid" : "no_connection", 1);
+ }
} else {
$valid = true;
}
@@ -119,7 +121,9 @@ class Admin_Languages_Controller extends Admin_Controller {
array("server-link" => html::mark_clean(html::anchor($server_link))))
: t("API key"))
->value($api_key)
- ->error_messages("invalid", t("The API key you provided is invalid."));
+ ->error_messages("invalid", t("The API key you provided is invalid."))
+ ->error_messages(
+ "no_connection", t("Could not connect to remote server to validate the API key."));
$group->submit("save")->value(t("Save settings"));
if ($api_key && $this->_outgoing_translations_count()) {
// TODO: UI improvement: hide API key / save button when API key is set.
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index 25df0da7..3435465c 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -37,7 +37,7 @@ class Albums_Controller extends Items_Controller {
if ($show) {
$child = ORM::factory("item", $show);
- $index = $album->get_position($child);
+ $index = item::get_position($child);
if ($index) {
$page = ceil($index / $page_size);
if ($page == 1) {
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php
index 22854fbd..98f4e839 100644
--- a/modules/gallery/controllers/file_proxy.php
+++ b/modules/gallery/controllers/file_proxy.php
@@ -27,10 +27,13 @@
* input is sanitized against the database before we perform any file I/O.
*/
class File_Proxy_Controller extends Controller {
+ const ALLOW_PRIVATE_GALLERY = true;
public function __call($function, $args) {
- // request_uri: gallery3/var/trunk/albums/foo/bar.jpg
+ // request_uri: gallery3/var/albums/foo/bar.jpg?m=1234
$request_uri = rawurldecode(Input::instance()->server("REQUEST_URI"));
+ // get rid of query parameters
+ // request_uri: gallery3/var/albums/foo/bar.jpg
$request_uri = preg_replace("/\?.*/", "", $request_uri);
// var_uri: gallery3/var/
@@ -42,13 +45,11 @@ class File_Proxy_Controller extends Controller {
throw new Kohana_404_Exception();
}
+ // file_uri: albums/foo/bar.jpg
$file_uri = substr($request_uri, strlen($var_uri));
- // Make sure that we don't leave the var dir
- if (strpos($file_uri, "..") !== false) {
- throw new Kohana_404_Exception();
- }
-
+ // type: albums
+ // path: foo/bar.jpg
list ($type, $path) = explode("/", $file_uri, 2);
if ($type != "resizes" && $type != "albums" && $type != "thumbs") {
throw new Kohana_404_Exception();
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index bf50abd5..7c85dd98 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -28,10 +28,10 @@ class Movies_Controller extends Items_Controller {
access::required("view", $movie);
$where = array(array("type", "!=", "album"));
- $position = $movie->parent()->get_position($movie, $where);
+ $position = item::get_position($movie, $where);
if ($position > 1) {
list ($previous_item, $ignore, $next_item) =
- $movie->parent()->children(3, $position - 2, $where);
+ $movie->parent()->viewable()->children(3, $position - 2, $where);
} else {
$previous_item = null;
list ($next_item) = $movie->parent()->viewable()->children(1, $position, $where);
diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php
index bd51b93c..9da34f9c 100644
--- a/modules/gallery/controllers/packager.php
+++ b/modules/gallery/controllers/packager.php
@@ -59,7 +59,7 @@ class Packager_Controller extends Controller {
// numbers, keeping our install.sql file more stable.
srand(0);
- foreach (array("gallery", "user", "comment", "organize", "info", "rest",
+ foreach (array("gallery", "user", "comment", "organize", "info",
"rss", "search", "slideshow", "tag") as $module_name) {
module::install($module_name);
module::activate($module_name);
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index d500a92e..4578747d 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -28,10 +28,10 @@ class Photos_Controller extends Items_Controller {
access::required("view", $photo);
$where = array(array("type", "!=", "album"));
- $position = $photo->parent()->get_position($photo, $where);
+ $position = item::get_position($photo, $where);
if ($position > 1) {
list ($previous_item, $ignore, $next_item) =
- $photo->parent()->children(3, $position - 2, $where);
+ $photo->parent()->viewable()->children(3, $position - 2, $where);
} else {
$previous_item = null;
list ($next_item) = $photo->parent()->viewable()->children(1, $position, $where);
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index 69aabc4f..282289b5 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -153,8 +153,15 @@ class gallery_Core {
if (is_string($file_name)) {
// make relative to DOCROOT
$parts = explode("/", $file_name);
+ $count = count($parts);
foreach ($parts as $idx => $part) {
- if (in_array($part, array("application", "modules", "themes", "lib"))) {
+ // If this part is "modules" or "themes" make sure that the part 2 after this
+ // is the target directory, and if it is then we're done. This check makes
+ // sure that if Gallery is installed in a directory called "modules" or "themes"
+ // We don't parse the directory structure incorrectly.
+ if (in_array($part, array("modules", "themes")) &&
+ $idx + 2 < $count &&
+ $parts[$idx + 2] == $directory) {
break;
}
unset($parts[$idx]);
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 689e21d1..13a0bdb4 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -178,10 +178,6 @@ class gallery_event_Core {
}
Session::instance()->set("active_auth_timestamp", time());
auth::clear_failed_attempts($user);
-
- if ($user->admin && ini_get("session.use_trans_sid")) {
- message::info(t("PHP is configured with <a href=\"url\">session.use_trans_sid</a> enabled which will cause random logouts. Please disable this setting.", array("url" => "http://www.php.net/manual/en/session.configuration.php#ini.session.use-trans-sid")));
- }
}
static function user_auth_failed($name) {
diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php
index fca18076..4cd7143e 100644
--- a/modules/gallery/helpers/gallery_graphics.php
+++ b/modules/gallery/helpers/gallery_graphics.php
@@ -56,7 +56,7 @@ class gallery_graphics_Core {
}
$dims = getimagesize($input_file);
- if (max($dims[0], $dims[1]) < min($options["width"], $options["height"])) {
+ if (max($dims[0], $dims[1]) <= min($options["width"], $options["height"])) {
// Image would get upscaled; do nothing
copy($input_file, $output_file);
} else {
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index edba6b76..18820ed7 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -313,60 +313,42 @@ class graphics_Core {
$toolkits->graphicsmagick->installed = false;
$toolkits->graphicsmagick->error = t("GraphicsMagick requires the <b>exec</b> function");
} else {
- gallery::set_path_env(
- array(module::get_var("gallery", "graphics_toolkit_path"),
- getenv("PATH"),
- module::get_var("gallery", "extra_binary_paths")));
-
- // @todo: consider refactoring the two segments below into a loop since they are so
- // similar.
-
- // ImageMagick
- $path = exec("which convert");
- $toolkits->imagemagick->name = "ImageMagick";
- if ($path) {
- if (@is_file($path)) {
- preg_match('/Version: \S+ (\S+)/', `convert -v`, $matches);
- $version = $matches[1];
-
- $toolkits->imagemagick->installed = true;
- $toolkits->imagemagick->version = $version;
- $toolkits->imagemagick->binary = $path;
- $toolkits->imagemagick->dir = dirname($path);
- $toolkits->imagemagick->rotate = true;
- $toolkits->imagemagick->sharpen = true;
- } else {
- $toolkits->imagemagick->installed = false;
- $toolkits->imagemagick->error =
- t("ImageMagick is installed, but PHP's open_basedir restriction prevents Gallery from using it.");
- }
- } else {
- $toolkits->imagemagick->installed = false;
- $toolkits->imagemagick->error = t("We could not locate ImageMagick on your system.");
- }
-
- // GraphicsMagick
- $path = exec("which gm");
- $toolkits->graphicsmagick->name = "GraphicsMagick";
- if ($path) {
- if (@is_file($path)) {
- preg_match('/\S+ (\S+)/', `gm version`, $matches);
- $version = $matches[1];
-
- $toolkits->graphicsmagick->installed = true;
- $toolkits->graphicsmagick->version = $version;
- $toolkits->graphicsmagick->binary = $path;
- $toolkits->graphicsmagick->dir = dirname($path);
- $toolkits->graphicsmagick->rotate = true;
- $toolkits->graphicsmagick->sharpen = true;
+ // ImageMagick & GraphicsMagick
+ $magick_kits = array(
+ "imagemagick" => array(
+ "name" => "ImageMagick", "binary" => "convert", "version" => "convert -v",
+ "version_regex" => "/Version: \S+ (\S+)/"),
+ "graphicsmagick" => array(
+ "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version",
+ "version_regex" => "/\S+ (\S+)/"));
+ // Loop through the kits
+ foreach ($magick_kits as $index => $settings) {
+ $path = system::find_binary(
+ $settings["binary"], module::get_var("gallery", "graphics_toolkit_path"));
+ $toolkits->$index->name = $settings["name"];
+ if ($path) {
+ if (@is_file($path) &&
+ preg_match($settings["version_regex"], shell_exec($settings["version"]), $matches)) {
+ $version = $matches[1];
+
+ $toolkits->$index->installed = true;
+ $toolkits->$index->version = $version;
+ $toolkits->$index->binary = $path;
+ $toolkits->$index->dir = dirname($path);
+ $toolkits->$index->rotate = true;
+ $toolkits->$index->sharpen = true;
+ } else {
+ $toolkits->$index->installed = false;
+ $toolkits->$index->error =
+ t("%toolkit_name is installed, but PHP's open_basedir restriction prevents Gallery from using it.",
+ array("toolkit_name" => $settings["name"]));
+ }
} else {
- $toolkits->graphicsmagick->installed = false;
- $toolkits->graphicsmagick->error =
- t("GraphicsMagick is installed, but PHP's open_basedir restriction prevents Gallery from using it.");
+ $toolkits->$index->installed = false;
+ $toolkits->$index->error =
+ t("We could not locate %toolkit_name on your system.",
+ array("toolkit_name" => $settings["name"]));
}
- } else {
- $toolkits->graphicsmagick->installed = false;
- $toolkits->graphicsmagick->error = t("We could not locate GraphicsMagick on your system.");
}
}
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 29dd8603..8aa14934 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -304,4 +304,92 @@ class item_Core {
->where("rand_key", "<", random::percent())
->order_by("rand_key", "DESC");
}
+
+ /**
+ * Find the position of the given item in its parent album. The resulting
+ * value is 1-indexed, so the first child in the album is at position 1.
+ *
+ * @param Item_Model $item
+ * @param array $where an array of arrays, each compatible with ORM::where()
+ */
+ static function get_position($item, $where=array()) {
+ $album = $item->parent();
+
+ if (!strcasecmp($album->sort_order, "DESC")) {
+ $comp = ">";
+ } else {
+ $comp = "<";
+ }
+ $query_model = ORM::factory("item");
+
+ // If the comparison column has NULLs in it, we can't use comparators on it
+ // and will have to deal with it the hard way.
+ $count = $query_model->viewable()
+ ->where("parent_id", "=", $album->id)
+ ->where($album->sort_column, "IS", null)
+ ->merge_where($where)
+ ->count_all();
+
+ if (empty($count)) {
+ // There are no NULLs in the sort column, so we can just use it directly.
+ $sort_column = $album->sort_column;
+
+ $position = $query_model->viewable()
+ ->where("parent_id", "=", $album->id)
+ ->where($sort_column, $comp, $item->$sort_column)
+ ->merge_where($where)
+ ->count_all();
+
+ // We stopped short of our target value in the sort (notice that we're
+ // using a inequality comparator above) because it's possible that we have
+ // duplicate values in the sort column. An equality check would just
+ // arbitrarily pick one of those multiple possible equivalent columns,
+ // which would mean that if you choose a sort order that has duplicates,
+ // it'd pick any one of them as the child's "position".
+ //
+ // Fix this by doing a 2nd query where we iterate over the equivalent
+ // columns and add them to our position count.
+ foreach ($query_model->viewable()
+ ->select("id")
+ ->where("parent_id", "=", $album->id)
+ ->where($sort_column, "=", $item->$sort_column)
+ ->merge_where($where)
+ ->order_by(array("id" => "ASC"))
+ ->find_all() as $row) {
+ $position++;
+ if ($row->id == $item->id) {
+ break;
+ }
+ }
+ } else {
+ // There are NULLs in the sort column, so we can't use MySQL comparators.
+ // Fall back to iterating over every child row to get to the current one.
+ // This can be wildly inefficient for really large albums, but it should
+ // be a rare case that the user is sorting an album with null values in
+ // the sort column.
+ //
+ // Reproduce the children() functionality here using Database directly to
+ // avoid loading the whole ORM for each row.
+ $order_by = array($album->sort_column => $album->sort_order);
+ // Use id as a tie breaker
+ if ($album->sort_column != "id") {
+ $order_by["id"] = "ASC";
+ }
+
+ $position = 0;
+ foreach ($query_model->viewable()
+ ->select("id")
+ ->where("parent_id", "=", $album->id)
+ ->merge_where($where)
+ ->order_by($order_by)
+ ->find_all() as $row) {
+ $position++;
+ if ($row->id == $item->id) {
+ break;
+ }
+ }
+ }
+
+ return $position;
+ }
} \ No newline at end of file
diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php
index 8c2685a8..8fc66b68 100644
--- a/modules/gallery/helpers/l10n_client.php
+++ b/modules/gallery/helpers/l10n_client.php
@@ -55,15 +55,24 @@ class l10n_client_Core {
$url = self::_server_url("status");
$signature = self::_sign($version, $api_key);
- list ($response_data, $response_status) = remote::post(
- $url, array("version" => $version,
- "client_token" => l10n_client::client_token(),
- "signature" => $signature,
- "uid" => l10n_client::server_uid($api_key)));
+ try {
+ list ($response_data, $response_status) = remote::post(
+ $url, array("version" => $version,
+ "client_token" => l10n_client::client_token(),
+ "signature" => $signature,
+ "uid" => l10n_client::server_uid($api_key)));
+ } catch (ErrorException $e) {
+ // Log the error, but then return a "can't make connection" error
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ }
+ if (!isset($response_data) && !isset($response_status)) {
+ return array(false, false);
+ }
+
if (!remote::success($response_status)) {
- return false;
+ return array(true, false);
}
- return true;
+ return array(true, true);
}
/**
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 7c5578af..6efe6162 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -168,7 +168,7 @@ class module_Core {
if (method_exists($installer_class, "install")) {
call_user_func_array(array($installer_class, "install"), array());
} else {
- module::set_version($module_name, 1);
+ module::set_version($module_name, module::available()->$module_name->code_version);
}
// Set the weight of the new module, which controls the order in which the modules are
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index 0895c5f4..dd0b437e 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -83,22 +83,18 @@ class movie_Core {
}
}
+ /**
+ * Return the path to the ffmpeg binary if one exists and is executable, or null.
+ */
static function find_ffmpeg() {
if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || !file_exists($ffmpeg_path)) {
- gallery::set_path_env(
- array(module::get_var("gallery", "graphics_toolkit_path"),
- getenv("PATH"),
- module::get_var("gallery", "extra_binary_paths")));
- if (function_exists("exec")) {
- $ffmpeg_path = exec("which ffmpeg");
- }
-
+ $ffmpeg_path = system::find_binary(
+ "ffmpeg", module::get_var("gallery", "graphics_toolkit_path"));
module::set_var("gallery", "ffmpeg_path", $ffmpeg_path);
}
return $ffmpeg_path;
}
-
/**
* Return the width, height, mime_type and extension of the given movie file.
*/
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
new file mode 100644
index 00000000..4a6a3c0f
--- /dev/null
+++ b/modules/gallery/helpers/system.php
@@ -0,0 +1,43 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2010 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 system_Core {
+ /**
+ * Return the path to an executable version of the named binary, or null.
+ * Traverse the PATH environment variable looking for the given file. If
+ * the $priority_path variable is set, check that path first.
+ */
+ static function find_binary($binary, $priority_path=null) {
+ $paths = array_merge(
+ explode(":", getenv("PATH")),
+ explode(":", module::get_var("gallery", "extra_binary_paths")));
+ if ($priority_path) {
+ array_unshift($paths, $priority_path);
+ }
+
+ foreach ($paths as $path) {
+ $candidate = "$path/$binary";
+ // @suppress errors below to avoid open_basedir issues
+ if (@file_exists($candidate) && @is_executable($candidate)) {
+ return $candidate;
+ }
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php
index 28a003cc..1a633a34 100644
--- a/modules/gallery/libraries/Admin_View.php
+++ b/modules/gallery/libraries/Admin_View.php
@@ -96,11 +96,6 @@ class Admin_View_Core extends Gallery_View {
}
}
- if ($function == "admin_head") {
- array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
- array_unshift($blocks, $this->combine_files($this->css, "css"));
- }
-
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
index b45bb94a..8befda95 100644
--- a/modules/gallery/libraries/Gallery_View.php
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -19,18 +19,35 @@
*/
class Gallery_View_Core extends View {
protected $theme_name = null;
- protected $scripts = array();
- protected $css = array();
+ protected $combine_queue = array();
/**
- * Add a script to the combined scripts list.
+ * Begin gather up scripts or css files so that they can be combined into a single request.
+ *
+ * @param $types a comma separated list of types to combine, eg "script,css"
+ */
+ public function start_combining($types) {
+ foreach (explode(",", $types) as $type) {
+ $this->combine_queue[$type] = array();
+ }
+ }
+
+ /**
+ * If script combining is enabled, add this script to the list of scripts that will be
+ * combined into a single script element. When combined, the order of scripts is preserved.
+ *
* @param $file the file name or path of the script to include. If a path is specified then
* it needs to be relative to DOCROOT. Just specifying a file name will result
* in searching Kohana's cascading file system.
+ * @param $group the group of scripts to combine this with. defaults to "core"
*/
- public function script($file) {
+ public function script($file, $group="core") {
if (($path = gallery::find_file("js", $file, false))) {
- $this->scripts[$path] = 1;
+ if (isset($this->combine_queue["script"])) {
+ $this->combine_queue["script"][$group][$path] = 1;
+ } else {
+ return html::script($path);
+ }
} else {
Kohana_Log::add("error", "Can't find script file: $file");
}
@@ -46,14 +63,22 @@ class Gallery_View_Core extends View {
}
/**
- * Add a css file to the combined css list.
- * @param $file the file name or path of the script to include. If a path is specified then
+ * If css combining is enabled, add this css to the list of css that will be
+ * combined into a single style element. When combined, the order of style elements
+ * is preserved.
+ *
+ * @param $file the file name or path of the css to include. If a path is specified then
* it needs to be relative to DOCROOT. Just specifying a file name will result
* in searching Kohana's cascading file system.
+ * @param $group the group of css to combine this with. defaults to "core"
*/
- public function css($file) {
+ public function css($file, $group="core") {
if (($path = gallery::find_file("css", $file, false))) {
- $this->css[$path] = 1;
+ if (isset($this->combine_queue["css"])) {
+ $this->combine_queue["css"][$group][$path] = 1;
+ } else {
+ return html::stylesheet($path);
+ }
} else {
Kohana_Log::add("error", "Can't find css file: $file");
}
@@ -61,11 +86,13 @@ class Gallery_View_Core extends View {
/**
* Combine a series of files into a single one and cache it in the database.
+ * @param $type the data type (script or css)
+ * @param $group the group of scripts or css we want
*/
- protected function combine_files($paths, $type) {
+ public function get_combined($type, $group="core") {
$links = array();
- if (empty($paths)) {
+ if (empty($this->combine_queue[$type][$group])) {
return;
}
@@ -73,7 +100,7 @@ class Gallery_View_Core extends View {
// entries.
$key = array(url::abs_file(""));
- foreach (array_keys($paths) as $path) {
+ foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
$stats = stat($path);
// 7 == size, 9 == mtime, see http://php.net/stat
$key[] = "$path $stats[7] $stats[9]";
@@ -85,7 +112,7 @@ class Gallery_View_Core extends View {
if (empty($contents)) {
$contents = "";
- foreach (array_keys($paths) as $path) {
+ foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
if ($type == "css") {
$contents .= "/* $path */\n" . $this->process_css($path) . "\n";
} else {
@@ -103,12 +130,12 @@ class Gallery_View_Core extends View {
}
}
+ unset($this->combine_queue[$type][$group]);
+
if ($type == "css") {
- return "<!-- LOOKING FOR YOUR CSS? It's all been combined into the link below -->\n" .
- html::stylesheet("combined/css/$key", "screen,print,projection", true);
+ return html::stylesheet("combined/css/$key", "screen,print,projection", true);
} else {
- return "<!-- LOOKING FOR YOUR JAVASCRIPT? It's all been combined into the link below -->\n" .
- html::script("combined/javascript/$key", true);
+ return html::script("combined/javascript/$key", true);
}
}
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index ba1862c0..04784ca1 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -236,13 +236,6 @@ class Theme_View_Core extends Gallery_View {
case "thumb_bottom":
case "thumb_info":
case "thumb_top":
- if ($function == "head") {
- // Stash any CSS we have already; that came from the theme and we want theme CSS to
- // override module CSs
- $save_css = $this->css;
- $this->css = array();
- }
-
$blocks = array();
if (method_exists("gallery_theme", $function)) {
switch (count($args)) {
@@ -281,13 +274,6 @@ class Theme_View_Core extends Gallery_View {
array_merge(array($this), $args));
}
- if ($function == "head") {
- // Merge the theme CSS/JS at the end
- $this->css = array_merge($this->css, $save_css);
- array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
- array_unshift($blocks, $this->combine_files($this->css, "css"));
- }
-
if (Session::instance()->get("debug")) {
if ($function != "head" && $function != "body_attributes") {
array_unshift(
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 7ddcb4c2..47b062b8 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -546,83 +546,12 @@ class Item_Model_Core extends ORM_MPTT {
/**
* Find the position of the given child id in this album. The resulting value is 1-indexed, so
* the first child in the album is at position 1.
+ *
+ * This method stands as a backward compatibility for gallery 3.0, and will
+ * be deprecated in version 3.1.
*/
public function get_position($child, $where=array()) {
- if (!strcasecmp($this->sort_order, "DESC")) {
- $comp = ">";
- } else {
- $comp = "<";
- }
- $db = db::build();
-
- // If the comparison column has NULLs in it, we can't use comparators on it and will have to
- // deal with it the hard way.
- $count = $db->from("items")
- ->where("parent_id", "=", $this->id)
- ->where($this->sort_column, "IS", null)
- ->merge_where($where)
- ->count_records();
-
- if (empty($count)) {
- // There are no NULLs in the sort column, so we can just use it directly.
- $sort_column = $this->sort_column;
-
- $position = $db->from("items")
- ->where("parent_id", "=", $this->id)
- ->where($sort_column, $comp, $child->$sort_column)
- ->merge_where($where)
- ->count_records();
-
- // We stopped short of our target value in the sort (notice that we're using a < comparator
- // above) because it's possible that we have duplicate values in the sort column. An
- // equality check would just arbitrarily pick one of those multiple possible equivalent
- // columns, which would mean that if you choose a sort order that has duplicates, it'd pick
- // any one of them as the child's "position".
- //
- // Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to
- // our base value.
- foreach ($db
- ->select("id")
- ->from("items")
- ->where("parent_id", "=", $this->id)
- ->where($sort_column, "=", $child->$sort_column)
- ->merge_where($where)
- ->order_by(array("id" => "ASC"))
- ->execute() as $row) {
- $position++;
- if ($row->id == $child->id) {
- break;
- }
- }
- } else {
- // There are NULLs in the sort column, so we can't use MySQL comparators. Fall back to
- // iterating over every child row to get to the current one. This can be wildly inefficient
- // for really large albums, but it should be a rare case that the user is sorting an album
- // with null values in the sort column.
- //
- // Reproduce the children() functionality here using Database directly to avoid loading the
- // whole ORM for each row.
- $order_by = array($this->sort_column => $this->sort_order);
- // Use id as a tie breaker
- if ($this->sort_column != "id") {
- $order_by["id"] = "ASC";
- }
-
- $position = 0;
- foreach ($db->select("id")
- ->from("items")
- ->where("parent_id", "=", $this->id)
- ->merge_where($where)
- ->order_by($order_by)
- ->execute() as $row) {
- $position++;
- if ($row->id == $child->id) {
- break;
- }
- }
- }
-
- return $position;
+ return item::get_position($child, $where);
}
/**
@@ -653,7 +582,7 @@ class Item_Model_Core extends ORM_MPTT {
/**
* Calculate the largest width/height that fits inside the given maximum, while preserving the
- * aspect ratio.
+ * aspect ratio. Don't upscale.
* @param int $max Maximum size of the largest dimension
* @return array
*/
@@ -661,6 +590,10 @@ class Item_Model_Core extends ORM_MPTT {
$width = $this->thumb_width;
$height = $this->thumb_height;
+ if ($width <= $max && $height <= $max) {
+ return array($height, $width);
+ }
+
if ($height) {
if (isset($max)) {
if ($width > $height) {
diff --git a/modules/gallery/views/movieplayer.html.php b/modules/gallery/views/movieplayer.html.php
index 2e79b620..5c280a36 100644
--- a/modules/gallery/views/movieplayer.html.php
+++ b/modules/gallery/views/movieplayer.html.php
@@ -9,6 +9,9 @@
provider: "pseudostreaming"
},
{
+ clip: {
+ scaling: 'fit'
+ },
plugins: {
pseudostreaming: {
url: "<?= url::abs_file("lib/flowplayer.pseudostreaming.swf") ?>"