diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/welcome.php | 4 | ||||
-rw-r--r-- | core/helpers/album.php | 13 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 4 | ||||
-rw-r--r-- | core/helpers/photo.php | 15 | ||||
-rw-r--r-- | core/libraries/ORM_MPTT.php | 8 | ||||
-rw-r--r-- | core/models/item.php | 42 | ||||
-rw-r--r-- | core/tests/Photo_Test.php | 6 | ||||
-rw-r--r-- | core/views/welcome.html.php | 3 |
8 files changed, 84 insertions, 11 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> |