diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-11-26 21:50:45 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-11-26 21:50:45 +0000 |
commit | 974f9f778891bbefeb083b2d97b3dae206c96452 (patch) | |
tree | 721c3c78bddb09c26ec306ae13e4093667961a97 | |
parent | 4e8937ccefc95272442a9cd5ccb71aab01f113a1 (diff) |
Add a new "tag" page type.
Create the concept of "page types" which let us specify the kind of
page that we're rendering in high level terms. Currently there are
three page types: album, photo and tag.
The tag page type uses slightly different variables. It has a $tag
but no $item. Adjust all sidebar_block() functions to avoid printing
stuff that's dependent on the item if there is no item.
Simplify the tag code to stop trying to fake an item.
Update the theme slightly to use $item and $tag where appropriate
(notably, for making the <title> element).
-rw-r--r-- | core/controllers/albums.php | 1 | ||||
-rw-r--r-- | core/controllers/photos.php | 1 | ||||
-rw-r--r-- | core/libraries/Theme.php | 4 | ||||
-rw-r--r-- | modules/carousel/helpers/carousel_block.php | 16 | ||||
-rw-r--r-- | modules/gmaps/helpers/gmaps_block.php | 12 | ||||
-rw-r--r-- | modules/info/helpers/info_block.php | 12 | ||||
-rw-r--r-- | modules/media_rss/helpers/media_rss_block.php | 6 | ||||
-rw-r--r-- | modules/tag/controllers/tags.php | 35 | ||||
-rw-r--r-- | modules/tag/models/tag.php | 61 | ||||
-rw-r--r-- | themes/default/views/header.html.php | 2 | ||||
-rw-r--r-- | themes/default/views/page.html.php | 12 | ||||
-rw-r--r-- | themes/default/views/tag.html.php | 31 |
12 files changed, 104 insertions, 89 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index f9e0be2c..4c117ac4 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -32,6 +32,7 @@ class Albums_Controller extends Items_Controller { $page = $this->input->get("page", "1"); $theme = new Theme($theme_name, $template); + $template->set_global("page_type", "album"); $template->set_global('page_size', $page_size); $template->set_global('item', $item); $template->set_global('children', $item->children($page_size, ($page-1) * $page_size)); diff --git a/core/controllers/photos.php b/core/controllers/photos.php index 1d995de8..2020aad3 100644 --- a/core/controllers/photos.php +++ b/core/controllers/photos.php @@ -28,6 +28,7 @@ class Photos_Controller extends Items_Controller { // @todo: this needs to be data-driven $theme = new Theme("default", $template); + $template->set_global("page_type", "photo"); $template->set_global('item', $item); $template->set_global('children', $item->children()); $template->set_global('parents', $item->parents()); diff --git a/core/libraries/Theme.php b/core/libraries/Theme.php index 315261a5..6ae08a4b 100644 --- a/core/libraries/Theme.php +++ b/core/libraries/Theme.php @@ -42,7 +42,7 @@ class Theme_Core { $this->pagination = new Pagination(); $this->pagination->initialize( array('query_string' => 'page', - 'total_items' => $this->template->item->children_count(), + 'total_items' => $this->template->children_count, 'items_per_page' => $this->template->page_size, 'style' => 'classic')); return $this->pagination->render(); @@ -64,6 +64,8 @@ class Theme_Core { case "album_top": case "album_blocks": case "album_bottom": + case "tag_top": + case "tag_bottom": case "thumbnail_top": case "thumbnail_bottom": case "thumbnail_info": diff --git a/modules/carousel/helpers/carousel_block.php b/modules/carousel/helpers/carousel_block.php index de131625..1732fa39 100644 --- a/modules/carousel/helpers/carousel_block.php +++ b/modules/carousel/helpers/carousel_block.php @@ -20,12 +20,14 @@ class carousel_block_Core { public static function sidebar_blocks($theme) { - $block = new Block(); - $block->id = "gCarousel"; - $block->title = "Album: <a href=\"#\">{$theme->item()->title_edit}</a>"; - $block->content = '<img src="' . - url::base() . "modules/carousel/images/carousel.png" . - '" width="214"/>'; - return $block->__toString(); + if ($theme->item()) { + $block = new Block(); + $block->id = "gCarousel"; + $block->title = "Album: <a href=\"#\">{$theme->item()->title_edit}</a>"; + $block->content = '<img src="' . + url::base() . "modules/carousel/images/carousel.png" . + '" width="214"/>'; + return $block; + } } }
\ No newline at end of file diff --git a/modules/gmaps/helpers/gmaps_block.php b/modules/gmaps/helpers/gmaps_block.php index 0d3155d1..dc58a4cd 100644 --- a/modules/gmaps/helpers/gmaps_block.php +++ b/modules/gmaps/helpers/gmaps_block.php @@ -20,10 +20,12 @@ class gmaps_block_Core { public static function sidebar_blocks($theme) { - $block = new Block(); - $block->id = "gMaps"; - $block->title = _("Location"); - $block->content = new View("gmaps_block.html"); - return $block; + if ($theme->item()) { + $block = new Block(); + $block->id = "gMaps"; + $block->title = _("Location"); + $block->content = new View("gmaps_block.html"); + return $block; + } } }
\ No newline at end of file diff --git a/modules/info/helpers/info_block.php b/modules/info/helpers/info_block.php index 40e5bb97..61115b2a 100644 --- a/modules/info/helpers/info_block.php +++ b/modules/info/helpers/info_block.php @@ -20,11 +20,13 @@ class info_block_Core { public static function sidebar_blocks($theme) { - $block = new Block(); - $block->id = "gMetadata"; - $block->title = _("Item Info"); - $block->content = new View("info_block.html"); - return $block; + if ($theme->item()) { + $block = new Block(); + $block->id = "gMetadata"; + $block->title = _("Item Info"); + $block->content = new View("info_block.html"); + return $block; + } } public static function thumbnail_info($theme, $item) { diff --git a/modules/media_rss/helpers/media_rss_block.php b/modules/media_rss/helpers/media_rss_block.php index b1db0bb2..2e9cd866 100644 --- a/modules/media_rss/helpers/media_rss_block.php +++ b/modules/media_rss/helpers/media_rss_block.php @@ -19,8 +19,10 @@ */ class media_rss_block_Core { public static function head($theme) { - $url = url::site("media_rss/feed/{$theme->item()->id}"); + if ($theme->item()) { + $url = url::site("media_rss/feed/{$theme->item()->id}"); - return "<link rel=\"alternate\" type=\"" . rest::RSS . "\" href=\"$url\" />"; + return "<link rel=\"alternate\" type=\"" . rest::RSS . "\" href=\"$url\" />"; + } } } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 6011179a..db5f93bd 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -20,31 +20,40 @@ class Tags_Controller extends REST_Controller { protected $resource_type = "tag"; - /** - * @see Rest_Controller::_index() - */ + public function _show($tag) { + // @todo: these need to be pulled from the database + $theme_name = "default"; + $page_size = 9; + + $template = new View("page.html"); + + $page = $this->input->get("page", "1"); + $theme = new Theme($theme_name, $template); + + $template->set_global("page_type", "tag"); + $template->set_global('page_size', $page_size); + $template->set_global('tag', $tag); + $template->set_global('children', $tag->items($page_size, ($page-1) * $page_size)); + $template->set_global('children_count', $tag->count); + $template->set_global('theme', $theme); + $template->set_global('user', Session::instance()->get('user', null)); + $template->content = new View("tag.html"); + + print $template; + } + public function _index() { throw new Exception("@todo Tag_Controller::_index NOT IMPLEMENTED"); } - /** - * @see Rest_Controller::_form_add($parameters) - */ public function _form_add($parameters) { throw new Exception("@todo Tag_Controller::_form NOT IMPLEMENTED"); } - /** - * @see Rest_Controller::_form_edit($resource) - */ public function _form_edit($tag) { throw new Exception("@todo Tag_Controller::_form NOT IMPLEMENTED"); } - public function _show($tag) { - Albums_Controller::_show($tag); - } - public function _create($tag) { throw new Exception("@todo Tag_Controller::_create NOT IMPLEMENTED"); } diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index c0e94f29..59dd8d54 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -20,64 +20,19 @@ class Tag_Model extends ORM { protected $has_and_belongs_to_many = array("items"); - protected $_children = array(); - var $rules = array( "name" => "required|length[4,32]"); /** - * Emulate the album method charactistics so that the tag looks like an album to the framework. - */ - public function __call($function, $args) { - if ($function == "children") { - return $this->_get_tag_children($args[0], $args[1]); - } else if ($function == "children_count") { - return $this->count; - } else if ($function == "parents") { - // Need to return as an ORM_Iterator as opposed to just the model. - return ORM::factory("item") - ->where("id", 1) - ->find_all(); - } else { - return parent::__call($function, $args); - } - } - - /** - * Emulate the album property charactistics so that the tag looks like an album to the framework. - */ - public function __get($property) { - if ($property == "title" || $property == "title_edit" || $property == "name_edit") { - return $this->name; - } else if ($property == "description_edit") { - return "There are {$this->count} items tagged."; - } else if ($property == "owner") { - return null; - } else { - return parent::__get($property); - } - } - - /** - * Get the item children. This code was borrowed from the ORM::__get($column) method and modified - * to allow for the specification of the limit and offset. - * @param int $limit - * @param int $offset + * Return all items associated with this tag. + * @param integer $limit number of rows to limit result to + * @param integer $offset offset in result to start returning rows from * @return ORM_Iterator */ - private function _get_tag_children($limit, $offset) { - // Load the child model - $model = ORM::factory(inflector::singular("items")); - - // Load JOIN info - $join_table = $model->join_table($this->table_name); - $join_col1 = $model->foreign_key(NULL, $join_table); - $join_col2 = $model->foreign_key(TRUE); - - // one<>alias:many relationship - return $model - ->join($join_table, $join_col1, $join_col2) - ->where($this->foreign_key(NULL, $join_table), $this->object[$this->primary_key]) + public function items($limit=null, $offset=0) { + return ORM::factory("item") + ->join("items_tags", "items.id", "items_tags.item_id") + ->where("items_tags.tag_id", $this->id) ->find_all($limit, $offset); - } + } }
\ No newline at end of file diff --git a/themes/default/views/header.html.php b/themes/default/views/header.html.php index 1ca2a952..c34486be 100644 --- a/themes/default/views/header.html.php +++ b/themes/default/views/header.html.php @@ -14,9 +14,11 @@ <?= $theme->header_bottom() ?> +<? if ($page_type != "tag"): ?> <ul id="gBreadcrumbs" class="gClearFix"> <? foreach ($parents as $parent): ?> <li><a href="<?= url::site("albums/{$parent->id}") ?>"><?= $parent->title_edit ?></a></li> <? endforeach ?> <li class="active"><?= $item->title_edit ?></li> </ul> +<? endif ?> diff --git a/themes/default/views/page.html.php b/themes/default/views/page.html.php index de0eff93..702595a6 100644 --- a/themes/default/views/page.html.php +++ b/themes/default/views/page.html.php @@ -4,7 +4,13 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> - <title><?= _("Browse Photos") ?> :: <?= $item->title ?></title> + <title> + <? if ($page_type == "tag"): ?> + <?= _("Browse Tags") ?> :: <?= $tag->name ?> + <? else: ?> + <?= _("Browse Photos") ?> :: <?= $item->title ?> + <? endif ?> + </title> <link rel="stylesheet" type="text/css" href="<?= url::file("lib/yui/reset-fonts-grids.css") ?>" media="screen,print,projection" /> <link rel="stylesheet" type="text/css" href="<?= $theme->url("css/screen.css") ?>" @@ -24,8 +30,8 @@ </head> <body> - <?= $theme->page_top() ?> - <div id="doc4" class="yui-t5 gView"> + <?= $theme->page_top() ?> + <div id="doc4" class="yui-t5 gView"> <div id="hd"> <div id="gHeader"> <?= $theme->display("header.html") ?> diff --git a/themes/default/views/tag.html.php b/themes/default/views/tag.html.php new file mode 100644 index 00000000..a4254e06 --- /dev/null +++ b/themes/default/views/tag.html.php @@ -0,0 +1,31 @@ +<? defined("SYSPATH") or die("No direct script access."); ?> +<div id="gAlbumHeader"> + <h1><?= $tag->name ?></h1> + <?= $theme->tag_top() ?> +</div> + +<ul id="gAlbumGrid"> + <? foreach ($children as $i => $child): ?> + <? $album_class = ""; ?> + <? if ($child->is_album()): ?> + <? $album_class = "gAlbum "; ?> + <? endif ?> + <li class="gItem <?= $album_class ?>"> + <?= $theme->thumbnail_top($child) ?> + <a href="<?= url::site("{$child->type}s/{$child->id}") ?>"> + <img id="gPhotoID-<?= $child->id ?>" class="gThumbnail" + alt="photo" src="<?= $child->thumbnail_url() ?>" + width="<?= $child->thumbnail_width ?>" + height="<?= $child->thumbnail_height ?>" /> + </a> + <h2><?= $child->title_edit ?></h2> + <?= $theme->thumbnail_bottom($child) ?> + <ul class="gMetadata"> + <?= $theme->thumbnail_info($child) ?> + </ul> + </li> + <? endforeach ?> +</ul> +<?= $theme->tag_bottom() ?> + +<?= $theme->pager() ?> |