summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorRomain LE DISEZ <romain.git@ledisez.net>2009-07-23 18:08:57 +0200
committerRomain LE DISEZ <romain.git@ledisez.net>2009-07-23 18:08:57 +0200
commit386130114b3e3a9cf1617a1ea62407f569ee391c (patch)
tree4728e044dc755b79494101effd7fab4689d5289d /modules/gallery
parent06fd89e8bcad2142f0b6158d5db7a91d2b6956d8 (diff)
parent5999ccb512d65ad9ae06a0a5542eb1123b44e9db (diff)
Merge commit 'upstream/master'
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/helpers/gallery.php2
-rw-r--r--modules/gallery/helpers/gallery_theme.php20
-rw-r--r--modules/gallery/libraries/Gallery_View.php66
-rw-r--r--modules/gallery/tests/Access_Helper_Test.php37
4 files changed, 75 insertions, 50 deletions
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index a32ac484..2fa7ad1c 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_Core {
- const VERSION = "3.0 beta 2";
+ const VERSION = "3.0 git (pre-beta3)";
/**
* If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is
diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php
index f245ea31..998eb289 100644
--- a/modules/gallery/helpers/gallery_theme.php
+++ b/modules/gallery/helpers/gallery_theme.php
@@ -22,12 +22,12 @@ class gallery_theme_Core {
$session = Session::instance();
$buf = "";
if ($session->get("debug")) {
- $theme->css("modules/gallery/css/debug.css");
+ $theme->css("debug.css");
}
if (($theme->page_type == "album" || $theme->page_type == "photo")
&& access::can("edit", $theme->item())) {
- $theme->css("modules/gallery/css/quick.css");
- $theme->script("modules/gallery/js/quick.js");
+ $theme->css("quick.css");
+ $theme->script("quick.js");
}
if (module::is_active("rss")) {
@@ -43,9 +43,9 @@ class gallery_theme_Core {
}
if ($session->get("l10n_mode", false)) {
- $theme->css("modules/gallery/css/l10n_client.css");
- $theme->script("lib/jquery.cookie.js");
- $theme->script("modules/gallery/js/l10n_client.js");
+ $theme->css("l10n_client.css");
+ $theme->script("jquery.cookie.js");
+ $theme->script("l10n_client.js");
}
return $buf;
@@ -80,13 +80,13 @@ class gallery_theme_Core {
static function admin_head($theme) {
$session = Session::instance();
if ($session->get("debug")) {
- $theme->css("modules/gallery/css/debug.css");
+ $theme->css("debug.css");
}
if ($session->get("l10n_mode", false)) {
- $theme->css("modules/gallery/css/l10n_client.css");
- $theme->script("lib/jquery.cookie.js");
- $theme->script("modules/gallery/js/l10n_client.js");
+ $theme->css("l10n_client.css");
+ $theme->script("jquery.cookie.js");
+ $theme->script("l10n_client.js");
}
}
diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php
index 31231ca6..219cc883 100644
--- a/modules/gallery/libraries/Gallery_View.php
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -27,24 +27,20 @@ class Gallery_View_Core extends View {
* @param $file the relative path to a script from the gallery3 directory
*/
public function script($file) {
- $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;
+ $base_file = str_replace(".js", "", $file);
+ if (($path = Kohana::find_file("js", $base_file, false, "js")) ||
+ file_exists($path = DOCROOT . "lib/$file")) {
+ $this->scripts[$path] = 1;
+ } else {
+ Kohana::log("error", "Can't find script file: $file");
+ }
}
/**
* 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 theme_url($path, $absolute_url=false) {
+ public function url($path, $absolute_url=false) {
$arg = "themes/{$this->theme_name}/$path";
return $absolute_url ? url::abs_file($arg) : url::file($arg);
}
@@ -53,27 +49,23 @@ class Gallery_View_Core extends View {
* Add a css file to the combined css list.
* @param $file the relative path to a script from the gallery3 directory
*/
- public function css($file, $theme_relative=false) {
- $this->css[$file] = 1;
- }
-
- /**
- * Add a css file to the combined css list.
- * @param $file the relative path to a script from the base of the active theme
- * @param
- */
- public function theme_css($file) {
- $file = "themes/{$this->theme_name}/$file";
- $this->css[$file] = 1;
+ public function css($file) {
+ $base_file = str_replace(".css", "", $file);
+ if (($path = Kohana::find_file("css", $base_file, false, "css")) ||
+ file_exists($path = DOCROOT . "lib/$file")) {
+ $this->css[$path] = 1;
+ } else {
+ Kohana::log("error", "Can't find css file: $file");
+ }
}
/**
* Combine a series of files into a single one and cache it in the database.
*/
- protected function combine_files($files, $type) {
+ protected function combine_files($paths, $type) {
$links = array();
- if (empty($files)) {
+ if (empty($paths)) {
return;
}
@@ -81,16 +73,10 @@ class Gallery_View_Core extends View {
// entries.
$key = array(url::abs_file(""));
- foreach (array_keys($files) as $file) {
- $path = DOCROOT . $file;
- if (file_exists($path)) {
- $stats = stat($path);
- $links[$file] = $path;
- // 7 == size, 9 == mtime, see http://php.net/stat
- $key[] = "$file $stats[7] $stats[9]";
- } else {
- Kohana::log("error", "missing file ($type): $file");
- }
+ foreach (array_keys($paths) as $path) {
+ $stats = stat($path);
+ // 7 == size, 9 == mtime, see http://php.net/stat
+ $key[] = "$path $stats[7] $stats[9]";
}
$key = md5(join(" ", $key));
@@ -99,11 +85,13 @@ class Gallery_View_Core extends View {
if (empty($contents)) {
$contents = "";
- foreach ($links as $file => $link) {
+ $docroot_len = strlen(DOCROOT);
+ foreach (array_keys($paths) as $path) {
+ $relative = substr($path, $docroot_len);
if ($type == "css") {
- $contents .= "/* $file */\n" . $this->process_css($link) . "\n";
+ $contents .= "/* $relative */\n" . $this->process_css($path) . "\n";
} else {
- $contents .= "/* $file */\n" . file_get_contents($link) . "\n";
+ $contents .= "/* $relative */\n" . file_get_contents($path) . "\n";
}
}
diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php
index 1352b493..59cec453 100644
--- a/modules/gallery/tests/Access_Helper_Test.php
+++ b/modules/gallery/tests/Access_Helper_Test.php
@@ -64,6 +64,43 @@ class Access_Helper_Test extends Unit_Test_Case {
$this->assert_false(array_key_exists("access_test_{$group->id}", $fields));
}
+ public function user_can_access_test() {
+ $access_test = group::create("access_test");
+
+ $root = ORM::factory("item", 1);
+ access::allow($access_test, "view", $root);
+
+ $item = album::create($root, rand(), "test album");
+
+ access::deny(group::everybody(), "view", $item);
+ access::deny(group::registered_users(), "view", $item);
+
+ $user = user::create("access_test", "Access Test", "");
+ foreach ($user->groups as $group) {
+ $user->remove($group);
+ }
+ $user->add($access_test);
+ $user->save();
+
+ $this->assert_true(access::user_can($user, "view", $item), "Should be able to view");
+ }
+
+ public function user_can_no_access_test() {
+ $root = ORM::factory("item", 1);
+ $item = album::create($root, rand(), "test album");
+
+ access::deny(group::everybody(), "view", $item);
+ access::deny(group::registered_users(), "view", $item);
+
+ $user = user::create("access_test", "Access Test", "");
+ foreach ($user->groups as $group) {
+ $user->remove($group);
+ }
+ $user->save();
+
+ $this->assert_false(access::user_can($user, "view", $item), "Should be unable to view");
+ }
+
public function adding_and_removing_items_adds_ands_removes_rows_test() {
$root = ORM::factory("item", 1);
$item = album::create($root, rand(), "test album");