summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/welcome.php4
-rw-r--r--core/helpers/album.php13
-rw-r--r--core/helpers/core_installer.php4
-rw-r--r--core/helpers/photo.php15
-rw-r--r--core/libraries/ORM_MPTT.php8
-rw-r--r--core/models/item.php42
-rw-r--r--core/tests/Photo_Test.php6
-rw-r--r--core/views/welcome.html.php3
-rw-r--r--themes/default/css/styles.css6
-rw-r--r--themes/default/views/album.html.php10
-rw-r--r--themes/default/views/photo.html.php4
11 files changed, 96 insertions, 19 deletions
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index 1c90842c..f421ffc5 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -52,8 +52,8 @@ class Welcome_Controller extends Template_Controller {
$parent = $parents[array_rand($parents)];
switch(rand(0, 1)) {
case 0:
- $album = album::create($parent->id, "rnd_" . rand(), "Rnd $i", "rnd $i");
- $parents[] = $album;
+ $parents[] = album::create($parent->id, "rnd_" . rand(), "Rnd $i", "rnd $i")
+ ->set_thumbnail(DOCROOT . "core/tests/test.jpg", 200, 150);
break;
case 1:
diff --git a/core/helpers/album.php b/core/helpers/album.php
index 021c09f3..6934932e 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -54,4 +54,17 @@ class Album_Core {
}
return $album;
}
+
+ static function set_thumbnail($id, $filename) {
+ $album = ORM::factory("item", $id);
+
+ /** @todo: parameterize these dimensions */
+ $image = Image::factory($filename);
+ $image->resize(200, 140, Image::WIDTH)->save($album->thumbnail_path());
+
+ $dims = getimagesize($album->thumbnail_path());
+ $album->thumbnail_width = $dims[0];
+ $album->thumbnail_height = $dims[1];
+ return $album->save();
+ }
}
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index 7d83236a..bbcf9bd1 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -49,6 +49,10 @@ class core_installer {
`right` int(9) NOT NULL,
`parent_id` int(9) NOT NULL,
`level` int(9) NOT NULL,
+ `thumbnail_width` int(9) default NULL,
+ `thumbnail_height` int(9) default NULL,
+ `resize_width` int(9) default NULL,
+ `resize_height` int(9) default NULL,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `type` (`type`))
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index dfa67e2b..ef94f52b 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -52,14 +52,15 @@ class Photo_Core {
$photo->name = rand() . "." . $pi["extension"];
}
- $photo->add_to_parent($parent_id);
-
copy($filename, $photo->file_path());
- /** @todo: parameterize these values */
- $image = Image::factory($filename);
- $image->resize(200, 140, Image::WIDTH)->save($photo->thumbnail_path());
- $image->resize(800, 600, Image::WIDTH)->save($photo->resize_path());
- return $photo;
+ // This saves the photo
+ $photo->add_to_parent($parent_id);
+
+ /** @todo: parameterize these dimensions */
+ // This saves the photo a second time, which is unfortunate but difficult to avoid.
+ return $photo->set_thumbnail($filename, 200, 140)
+ ->set_resize($filename, 800, 600)
+ ->save();
}
}
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php
index 3ce5e3e4..83190d4a 100644
--- a/core/libraries/ORM_MPTT.php
+++ b/core/libraries/ORM_MPTT.php
@@ -45,6 +45,7 @@ class ORM_MPTT_Core extends ORM {
/**
* Add this node as a child of the parent provided.
*
+ * @chainable
* @param integer $parent_id the id of the parent node
* @return ORM
*/
@@ -113,6 +114,13 @@ class ORM_MPTT_Core extends ORM {
return $this->children;
}
+ function reload() {
+ $this->parent = null;
+ $this->parents = null;
+ $this->children = null;
+ return parent::reload();
+ }
+
/**
* Grow this node's space enough to make room for 1 or more new nodes.
*
diff --git a/core/models/item.php b/core/models/item.php
index 5a9e9b2c..3a9faea0 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -97,6 +97,48 @@ class Item_Model extends ORM_MPTT {
}
/**
+ * Build a thumbnail for this item from the image provided with the
+ * given width and height
+ *
+ * @chainable
+ * @param string $filename the path to an image
+ * @param integer $width the desired width of the thumbnail
+ * @param integer $height the desired height of the thumbnail
+ * @return ORM
+ */
+ public function set_thumbnail($filename, $width, $height) {
+ Image::factory($filename)
+ ->resize($width, $height, Image::WIDTH)
+ ->save($this->thumbnail_path());
+
+ $dims = getimagesize($this->thumbnail_path());
+ $this->thumbnail_width = $dims[0];
+ $this->thumbnail_height = $dims[1];
+ return $this;
+ }
+
+ /**
+ * Build a resize for this item from the image provided with the
+ * given width and height
+ *
+ * @chainable
+ * @param string $filename the path to an image
+ * @param integer $width the desired width of the resize
+ * @param integer $height the desired height of the resize
+ * @return ORM
+ */
+ public function set_resize($filename, $width, $height) {
+ Image::factory($filename)
+ ->resize($width, $height, Image::WIDTH)
+ ->save($this->resize_path());
+
+ $dims = getimagesize($this->resize_path());
+ $this->resize_width = $dims[0];
+ $this->resize_height = $dims[1];
+ return $this;
+ }
+
+ /**
* Return the relative path to this item's file.
* @param string $prefix prefix to the path (eg "/var" or "http://foo.com/var")
* @param string $tag a tag to specify before the extension (eg ".thumb", ".resize")
diff --git a/core/tests/Photo_Test.php b/core/tests/Photo_Test.php
index 0980a187..cc4921c0 100644
--- a/core/tests/Photo_Test.php
+++ b/core/tests/Photo_Test.php
@@ -63,7 +63,9 @@ class Photo_Test extends Unit_Test_Case {
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());
+ $album = album::create(1, $rand, $rand, $rand);
+ $photo = photo::create($album->id, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+
+ $this->assert_equal("http://./var/resizes/{$rand}/{$rand}.resize.jpg", $photo->resize_url());
}
}
diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php
index 28e18023..4bd0ef90 100644
--- a/core/views/welcome.html.php
+++ b/core/views/welcome.html.php
@@ -181,6 +181,9 @@
<li>
<a href="http://codex.gallery2.org/Gallery3:Coding_Standards">Gallery3: Coding Standards</a>
</li>
+ <li>
+ <a href="http://docs.kohanaphp.com/">Kohana Documentation</a>
+ </li>
</ul>
</div>
</div>
diff --git a/themes/default/css/styles.css b/themes/default/css/styles.css
index f50362a6..341927ef 100644
--- a/themes/default/css/styles.css
+++ b/themes/default/css/styles.css
@@ -339,10 +339,8 @@ table.gBlockContent td {
float: right;
}
#gItem img {
- clear: both;
+ clear: both;
display: block;
- width: 500px;
- height: 400px;
border: 1px solid silver;
background-color: #e7e7e7;
}
@@ -425,8 +423,6 @@ table.gMetadata td.toggle {
#gAlbumGrid .gItemContainer,
#gAlbumGrid .gAlbumContainer {
- width: 32%;
- height: 220px;
float: left;
text-align: center;
border: 1px lightgray solid;
diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php
index 390a22b8..232e749b 100644
--- a/themes/default/views/album.html.php
+++ b/themes/default/views/album.html.php
@@ -15,7 +15,10 @@
<? 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() ?>" />
+ <img id="photo-id-<?= $child->id ?>" class="photo"
+ alt="photo" src="<?= $child->thumbnail_url() ?>"
+ width="<?= $child->thumbnail_width ?>"
+ height="<?= $child->thumbnail_height ?>" />
</a>
<h2>Album title</h2>
<ul class="gMetadata">
@@ -26,7 +29,10 @@
<? 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() ?>" />
+ <img id="photo-id-<?= $child->id ?>" class="photo"
+ alt="photo" src="<?= $child->thumbnail_url() ?>"
+ width="<?= $child->thumbnail_width ?>"
+ height="<?= $child->thumbnail_height ?>" />
</a>
<h2><?= $child->title ?></h2>
</div>
diff --git a/themes/default/views/photo.html.php b/themes/default/views/photo.html.php
index 31458094..8f7fa791 100644
--- a/themes/default/views/photo.html.php
+++ b/themes/default/views/photo.html.php
@@ -8,7 +8,9 @@
<a href="" class="buttonlink">Full size (1024x768)</a>
<a href="" class="buttonlink">Slideshow</a>
- <img id="photo-id-<?= $item->id ?>" alt="photo" src="<?= $item->resize_url() ?>" />
+ <img id="photo-id-<?= $item->id ?>" alt="photo" src="<?= $item->resize_url() ?>"
+ width="<?= $item->resize_width ?>"
+ height="<?= $item->resize_height ?>" />
<h1><?= $item->title ?></h1>
<p><?= $item->description ?></p>
</div>