diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-11-05 07:13:46 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-11-05 07:13:46 +0000 |
commit | 581e931c439a726fbd6a0b0068debd2cd76e349d (patch) | |
tree | 904e121e5ebe6c4b53587bdc91723747fe6e3561 /core/models | |
parent | 00513a71d2091eba3110164e506c2231972a1584 (diff) |
Change the default theme to actually render what's in the Gallery.
Currently only the album view works, albums have no thumbnails, and
there's only 1 image in use.
Improved Item_Model to have the following API methods
file_path() -- returns the path to the source image or album dir
thumbnail_path(), thumbnail_url() -- returns path/url to the thumbnail
resize_path(), resize_url() -- returns path/url to the resize
All tests updated.
Diffstat (limited to 'core/models')
-rw-r--r-- | core/models/item.php | 67 |
1 files changed, 57 insertions, 10 deletions
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", ""); } } } |