diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-09-07 20:59:42 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-09-07 20:59:42 -0700 |
commit | a73b5e822684ae0138f3baa733b0013122b0368c (patch) | |
tree | 1fdff9c957e6a49acb497e91b99254bca6d50f9c | |
parent | 83ebc2e2b053a0d9fb100b1663471127ca281bda (diff) |
Switch to using Item_Model::relative_url() for the url path.
-rw-r--r-- | modules/gallery/helpers/MY_url.php | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index c4967c52..6e3657fd 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -28,7 +28,7 @@ class url extends url_Core { $parts = explode("/", $uri, 3); if ($parts[0] == "albums" || $parts[0] == "photos") { - $uri = model_cache::get("item", $parts[1])->relative_path(); + $uri = model_cache::get("item", $parts[1])->relative_url(); } return parent::site($uri . $query, $protocol); } @@ -55,17 +55,20 @@ class url extends url_Core { } /** - * Return the item that the uri is referencing + * Locate an item using the URI. We assume that the uri is in the form /a/b/c where each + * component matches up with an item slug. + * @param string $uri the uri fragment + * @return Item_Model */ static function get_item_from_uri($uri) { $current_uri = html_entity_decode($uri, ENT_QUOTES); - $item = ORM::factory("item")->where("relative_path_cache", $current_uri)->find(); + // In most cases, we'll have an exact match in the relative_url_cache item field. + // but failing that, walk down the tree until we find it. + $item = ORM::factory("item")->where("relative_url_cache", $current_uri)->find(); if (!$item->loaded) { - // It's possible that the relative path cache for the item we're looking for is out of date, - // so find it the hard way. $count = count(Router::$segments); foreach (ORM::factory("item") - ->where("name", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) + ->where("slug", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) ->where("level", $count + 1) ->find_all() as $match) { if ($match->relative_path() == $current_uri) { |