summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/helpers/album.php7
-rw-r--r--core/helpers/core_installer.php4
-rw-r--r--core/helpers/photo.php2
-rw-r--r--core/models/item.php67
-rw-r--r--core/tests/Album_Test.php22
-rw-r--r--core/tests/Core_Installer_Test.php7
-rw-r--r--core/tests/Photo_Test.php20
-rw-r--r--themes/default/views/album.html.php62
8 files changed, 114 insertions, 77 deletions
diff --git a/core/helpers/album.php b/core/helpers/album.php
index 415e654c..021c09f3 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -47,8 +47,11 @@ class Album_Core {
}
$album = $album->add_to_parent($parent_id);
- mkdir($album->path());
- mkdir($album->thumbnail_path());
+ mkdir($album->file_path());
+ $thumbnail_dir = dirname($album->thumbnail_path());
+ if (!file_exists($thumbnail_dir)) {
+ mkdir($thumbnail_dir);
+ }
return $album;
}
}
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index 8511b840..7d83236a 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -54,7 +54,7 @@ class core_installer {
KEY `type` (`type`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- foreach (array("albums", "thumbnails") as $dir) {
+ foreach (array("albums", "resizes") as $dir) {
@mkdir(VARPATH . $dir);
}
@@ -80,6 +80,6 @@ class core_installer {
$db->query("DROP TABLE IF EXISTS `items`;");
$db->query("DROP TABLE IF EXISTS `modules`;");
system("/bin/rm -rf " . VARPATH . "albums");
- system("/bin/rm -rf " . VARPATH . "thumbnails");
+ system("/bin/rm -rf " . VARPATH . "resizes");
}
}
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index e796ef03..dfa67e2b 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -54,7 +54,7 @@ class Photo_Core {
$photo->add_to_parent($parent_id);
- copy($filename, $photo->path());
+ copy($filename, $photo->file_path());
/** @todo: parameterize these values */
$image = Image::factory($filename);
diff --git a/core/models/item.php b/core/models/item.php
index 3d5f08a2..265a9219 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -28,8 +28,8 @@ class Item_Model extends ORM_MPTT {
return $this->type == 'photo';
}
- private function _get_path() {
- $paths = array();
+ private function _relative_path($prefix, $tag, $suffix) {
+ $paths = array($prefix);
foreach ($this->parents() as $parent) {
if ($parent->id > 1) {
$paths[] = $parent->name;
@@ -39,28 +39,75 @@ class Item_Model extends ORM_MPTT {
if (!$this->saved) {
$path .= $this->name;
}
+
+ if ($tag) {
+ $pi = pathinfo($path);
+ $path = "{$pi['dirname']}/{$pi['filename']}{$tag}.{$pi['extension']}";
+ }
+
+ if ($suffix) {
+ $path .= $suffix;
+ }
return $path;
}
- public function path() {
- return VARPATH . "albums/{$this->_get_path()}";
+ /**
+ * album: /var/albums/album1/album2
+ * photo: /var/albums/album1/album2/photo.jpg
+ */
+ public function file_path() {
+ if ($this->is_album()) {
+ return $this->_relative_path(VARPATH . "albums", "", "");
+ } else {
+ return $this->_relative_path(VARPATH . "albums", "", "");
+ }
}
+ /**
+ * album: /var/resizes/album1/.thumb.jpg
+ * photo: /var/albums/album1/photo.thumb.jpg
+ */
public function thumbnail_path() {
if ($this->is_album()) {
- return VARPATH . "thumbnails/{$this->_get_path()}";
+ return $this->_relative_path(VARPATH . "resizes", "", "/.thumb.jpg");
} else {
- $pi = pathinfo(VARPATH . "thumbnails/{$this->_get_path()}");
- return "{$pi['dirname']}/{$pi['filename']}_thumb.{$pi['extension']}";
+ return $this->_relative_path(VARPATH . "resizes", ".thumb", "");
}
}
+ /**
+ * album: http://example.com/gallery3/var/resizes/album1/.thumb.jpg
+ * photo: http://example.com/gallery3/var/albums/album1/photo.thumb.jpg
+ */
+ public function thumbnail_url() {
+ if ($this->is_album()) {
+ return $this->_relative_path(url::base() . "var/resizes", "", "/.thumb.jpg");
+ } else {
+ return $this->_relative_path(url::base() . "var/resizes", ".thumb", "");
+ }
+ }
+
+ /**
+ * album: /var/resizes/album1/.resize.jpg
+ * photo: /var/albums/album1/photo.resize.jpg
+ */
public function resize_path() {
if ($this->is_album()) {
- return VARPATH . "thumbnails/{$this->_get_path()}";
+ return $this->_relative_path(VARPATH . "resizes", "", "/.resize.jpg");
+ } else {
+ return $this->_relative_path(VARPATH . "resizes", ".resize", "");
+ }
+ }
+
+ /**
+ * album: http://example.com/gallery3/var/resizes/album1/.resize.jpg
+ * photo: http://example.com/gallery3/var/albums/album1/photo.resize.jpg
+ */
+ public function resize_url() {
+ if ($this->is_album()) {
+ return $this->_relative_path(url::base() . "var/resizes", "", "/.resize.jpg");
} else {
- $pi = pathinfo(VARPATH . "thumbnails/{$this->_get_path()}");
- return "{$pi['dirname']}/{$pi['filename']}_resize.{$pi['extension']}";
+ return $this->_relative_path(url::base() . "var/resizes", ".resize", "");
}
}
}
diff --git a/core/tests/Album_Test.php b/core/tests/Album_Test.php
index 5a41a08a..a2ab1c48 100644
--- a/core/tests/Album_Test.php
+++ b/core/tests/Album_Test.php
@@ -22,12 +22,12 @@ class Album_Test extends Unit_Test_Case {
$rand = rand();
$album = album::create(1, $rand, $rand, $rand);
- $this->assert_equal(VARPATH . "albums/$rand", $album->path());
- $this->assert_equal(VARPATH . "thumbnails/$rand", $album->thumbnail_path());
- $this->assert_equal(VARPATH . "thumbnails/$rand", $album->resize_path());
+ $this->assert_equal(VARPATH . "albums/$rand", $album->file_path());
+ $this->assert_equal(VARPATH . "resizes/$rand/.thumb.jpg", $album->thumbnail_path());
+ $this->assert_true(is_dir(VARPATH . "resizes/$rand"), "missing thumbnail dir");
- $this->assert_true(is_dir($album->path()), "missing path: {$album->path()}");
- $this->assert_true(is_dir($album->resize_path()), "missing path: {$album->resize_path()}");
+ // It's unclear that a resize makes sense for an album. But we have one.
+ $this->assert_equal(VARPATH . "resizes/$rand/.resize.jpg", $album->resize_path());
$this->assert_equal(1, $album->parent_id); // MPTT tests will cover other hierarchy checks
$this->assert_equal($rand, $album->name);
@@ -41,4 +41,16 @@ class Album_Test extends Unit_Test_Case {
$album2 = album::create(1, $rand, $rand, $rand);
$this->assert_true($album1->name != $album2->name);
}
+
+ public function thumbnail_url_test() {
+ $rand = rand();
+ $album = album::create(1, $rand, $rand, $rand);
+ $this->assert_equal("http://./var/resizes/$rand/.thumb.jpg", $album->thumbnail_url());
+ }
+
+ public function resize_url_test() {
+ $rand = rand();
+ $album = album::create(1, $rand, $rand, $rand);
+ $this->assert_equal("http://./var/resizes/$rand/.resize.jpg", $album->resize_url());
+ }
}
diff --git a/core/tests/Core_Installer_Test.php b/core/tests/Core_Installer_Test.php
index 4903805b..1cfd09cb 100644
--- a/core/tests/Core_Installer_Test.php
+++ b/core/tests/Core_Installer_Test.php
@@ -23,12 +23,9 @@
* test controller before it starts.
*/
class Core_Installer_Test extends Unit_Test_Case {
- public function install_creates_albums_dir_test() {
+ public function install_creates_dirs_test() {
$this->assert_true(file_exists(VARPATH . "albums"));
- }
-
- public function install_creates_thumbnails_dir_test() {
- $this->assert_true(file_exists(VARPATH . "thumbnails"));
+ $this->assert_true(file_exists(VARPATH . "resizes"));
}
public function install_registers_core_module_test() {
diff --git a/core/tests/Photo_Test.php b/core/tests/Photo_Test.php
index 8b0a48cc..0980a187 100644
--- a/core/tests/Photo_Test.php
+++ b/core/tests/Photo_Test.php
@@ -22,11 +22,11 @@ class Photo_Test extends Unit_Test_Case {
$rand = rand();
$photo = photo::create(1, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
- $this->assert_equal(VARPATH . "albums/$rand.jpg", $photo->path());
- $this->assert_equal(VARPATH . "thumbnails/{$rand}_thumb.jpg", $photo->thumbnail_path());
- $this->assert_equal(VARPATH . "thumbnails/{$rand}_resize.jpg", $photo->resize_path());
+ $this->assert_equal(VARPATH . "albums/$rand.jpg", $photo->file_path());
+ $this->assert_equal(VARPATH . "resizes/{$rand}.thumb.jpg", $photo->thumbnail_path());
+ $this->assert_equal(VARPATH . "resizes/{$rand}.resize.jpg", $photo->resize_path());
- $this->assert_true(is_file($photo->path()), "missing: {$photo->path()}");
+ $this->assert_true(is_file($photo->file_path()), "missing: {$photo->file_path()}");
$this->assert_true(is_file($photo->resize_path()), "missing: {$photo->resize_path()}");
$this->assert_true(is_file($photo->thumbnail_path()), "missing: {$photo->thumbnail_path()}");
@@ -54,4 +54,16 @@ class Photo_Test extends Unit_Test_Case {
// pass
}
}
+
+ public function thumbnail_url_test() {
+ $rand = rand();
+ $photo = photo::create(1, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+ $this->assert_equal("http://./var/resizes/{$rand}.thumb.jpg", $photo->thumbnail_url());
+ }
+
+ public function resize_url_test() {
+ $rand = rand();
+ $photo = photo::create(1, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+ $this->assert_equal("http://./var/resizes/{$rand}.resize.jpg", $photo->resize_url());
+ }
}
diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php
index dd0ad44b..390a22b8 100644
--- a/themes/default/views/album.html.php
+++ b/themes/default/views/album.html.php
@@ -4,13 +4,6 @@
<div id="bd">
<div id="yui-main">
<div id="gContent" class="yui-b">
- <script type="text/javascript">
- myTooltip = new YAHOO.widget.Tooltip("myTooltip", {
- context:"photo-id-1",
- text:"<strong>Photo title</strong><br />taken December 24, 2007<br />Viewed 27 times<br /><br/>Tags: christmas, familiy, home, xmas",
- showDelay:500 } );
- </script>
-
<div id="gAlbumGrid">
<div id="gAlbumGridHeader">
<h1><?= $item->title ?></h1>
@@ -18,54 +11,27 @@
<a href="#" id="gSlideshowLink" class="buttonlink">Slideshow</a>
</div>
- <div class="gAlbumContainer first gAlbum">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
+ <? foreach ($children as $i => $child): ?>
+ <? if ($child->is_album()): ?>
+ <div class="gAlbumContainer gAlbum <?= text::alternate("first", "", "") ?>">
+ <a href="<?= url::site("album/{$child->id}") ?>">
+ <img id="photo-id-<?= $child->id ?>" class="photo" alt="photo" src="<?= $child->thumbnail_url() ?>" />
+ </a>
<h2>Album title</h2>
<ul class="gMetadata">
<li>Views: 321</li>
<li>By: <a href="#">username</a></li>
</ul>
</div>
-
- <div class="gItemContainer">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer first">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer first">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
- </div>
-
- <div class="gItemContainer">
- <a href="photo.html"><img id="photo-id-1" class="photo" alt="photo" src="<?= $theme->url("images/thumbnail.jpg") ?>" /></a>
- <h2>Photo title</h2>
+ <? else: ?>
+ <div class="gItemContainer <?= text::alternate("first", "", "") ?>">
+ <a href="<?= url::site("photo/{$child->id}") ?>">
+ <img id="photo-id-<?= $child->id ?>" class="photo" alt="photo" src="<?= $child->thumbnail_url() ?>" />
+ </a>
+ <h2><?= $child->title ?></h2>
</div>
+ <? endif ?>
+ <? endforeach ?>
<div id="gPagination">
Items 1-10 of 34