diff options
Diffstat (limited to 'modules')
20 files changed, 75 insertions, 71 deletions
diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index da001c55..24f91aba 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -38,7 +38,7 @@ class Admin_Themes_Controller extends Admin_Controller { $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $theme_info->description = t($theme_info->description); $theme_info->name = t($theme_info->name); - + $themes[$theme_name] = $theme_info; } return $themes; @@ -54,7 +54,7 @@ class Admin_Themes_Controller extends Admin_Controller { if ($type == "admin") { $view->url = url::site("admin?theme=$theme_name"); } else { - $view->url = url::site("albums/1?theme=$theme_name"); + $view->url = item::root()->url("theme=$theme_name"); } print $view; } diff --git a/modules/gallery/controllers/after_install.php b/modules/gallery/controllers/after_install.php index f066afe4..b640092f 100644 --- a/modules/gallery/controllers/after_install.php +++ b/modules/gallery/controllers/after_install.php @@ -20,7 +20,7 @@ class After_Install_Controller extends Controller { public function index() { if (!user::active()->admin) { - url::redirect("albums/1"); + url::redirect(item::root()->url()); } $v = new View("after_install.html"); diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index b7a9f339..abcabfa6 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -42,9 +42,9 @@ class Albums_Controller extends Items_Controller { $index = $album->get_position($show); $page = ceil($index / $page_size); if ($page == 1) { - url::redirect("albums/$album->id"); + url::redirect($album->url()); } else { - url::redirect("albums/$album->id?page=$page"); + url::redirect($album->url("page=$page")); } } @@ -55,9 +55,9 @@ class Albums_Controller extends Items_Controller { // Make sure that the page references a valid offset if ($page < 1) { - url::redirect("albums/$album->id"); + url::redirect($album->url()); } else if ($page > $max_pages) { - url::redirect("albums/$album->id?page=$max_pages"); + url::redirect($album->url("page=$max_pages")); } $template = new Theme_View("page.html", "album"); @@ -116,8 +116,8 @@ class Albums_Controller extends Items_Controller { print json_encode( array("result" => "success", - "location" => url::site("albums/$new_album->id"), - "resource" => url::site("albums/$new_album->id"))); + "location" => $new_album->url(), + "resource" => $new_album->url())); } else { print json_encode( array( @@ -149,8 +149,8 @@ class Albums_Controller extends Items_Controller { print json_encode( array("result" => "success", - "resource" => url::site("photos/$photo->id"), - "location" => url::site("photos/$photo->id"))); + "resource" => $photo->url(), + "location" => $photo->url())); } else { print json_encode( array("result" => "error", diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index 93ef05a6..87b73436 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -43,7 +43,7 @@ class Move_Controller extends Controller { print json_encode( array("result" => "success", - "location" => url::site("albums/{$target->id}"))); + "location" => $target->url())); } public function show_sub_tree($source_id, $target_id) { diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index c549dbf8..1c266cc8 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -105,7 +105,7 @@ class Movies_Controller extends Items_Controller { $photo->save(); module::event("item_edit_form_completed", $photo, $form); - log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>"); + log::success("content", "Updated photo", "<a href=\"{$photo->url()}\">view</a>"); message::success( t("Saved photo %photo_title", array("photo_title" => $photo->title))); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 959097b2..79ad674a 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -97,7 +97,7 @@ class Photos_Controller extends Items_Controller { $photo->save(); module::event("item_edit_form_completed", $photo, $form); - log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>"); + log::success("content", "Updated photo", "<a href=\"{$photo->url()}\">view</a>"); message::success( t("Saved photo %photo_title", array("photo_title" => html::purify($photo->title)))); diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 20731f9c..2ac54754 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -121,7 +121,7 @@ class Quick_Controller extends Controller { print json_encode(array("result" => "success", "reload" => 1)); } else { print json_encode(array("result" => "success", - "location" => url::site("albums/$parent->id"))); + "location" => $parent->url())); } } diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index 1ca9a58f..368c947e 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -18,25 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class url extends url_Core { - static function site($uri, $protocol=false) { - if (($pos = strpos($uri, "?")) !== false) { - list ($uri, $query) = explode("?", $uri, 2); - $query = "?$query"; - } else { - $query = ""; - } - - // @todo if we're only doing this for Item_Model, why not just put this - // all into Item_Model::url()? It'd make url::site() faster. Downside is that - // anywhere we refer to an item by id, eg url::site("albums/123") would have - // to load the item and do $item->url(); - $parts = explode("/", $uri, 3); - if ($parts[0] == "albums" || $parts[0] == "photos" || $parts[0] == "movies") { - $uri = model_cache::get("item", $parts[1])->relative_url(); - } - return parent::site($uri . $query, $protocol); - } - static function parse_url() { if (Router::$controller) { return; diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index f72ef982..813134eb 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -82,9 +82,9 @@ class gallery_Core { static function site_menu($menu, $theme) { if ($theme->page_type != "login") { $menu->append(Menu::factory("link") - ->id("home") - ->label(t("Home")) - ->url(url::site("albums/1"))); + ->id("home") + ->label(t("Home")) + ->url(item::root()->url())); $item = $theme->item(); @@ -92,39 +92,39 @@ class gallery_Core { $can_add = $item && access::can("add", $item); if ($can_add) { - $menu->append($add_menu = Menu::factory("submenu") - ->id("add_menu") - ->label(t("Add"))); + $menu->append($add_menu = Menu::factory("submenu") + ->id("add_menu") + ->label(t("Add"))); $add_menu->append(Menu::factory("dialog") - ->id("add_photos_item") - ->label(t("Add photos")) - ->url(url::site("simple_uploader/app/$item->id"))); + ->id("add_photos_item") + ->label(t("Add photos")) + ->url(url::site("simple_uploader/app/$item->id"))); if ($item->is_album()) { - $add_menu->append(Menu::factory("dialog") - ->id("add_album_item") - ->label(t("Add an album")) - ->url(url::site("form/add/albums/$item->id?type=album"))); - } + $add_menu->append(Menu::factory("dialog") + ->id("add_album_item") + ->label(t("Add an album")) + ->url(url::site("form/add/albums/$item->id?type=album"))); + } } $menu->append($options_menu = Menu::factory("submenu") - ->id("options_menu") - ->label(t("Photo options"))); + ->id("options_menu") + ->label(t("Photo options"))); if ($item && ($can_edit || $can_add)) { if ($can_edit) { $options_menu->append(Menu::factory("dialog") - ->id("edit_item") - ->label($item->is_album() ? t("Edit album") : t("Edit photo")) - ->url(url::site("form/edit/{$item->type}s/$item->id"))); + ->id("edit_item") + ->label($item->is_album() ? t("Edit album") : t("Edit photo")) + ->url(url::site("form/edit/{$item->type}s/$item->id"))); } if ($item->is_album()) { $options_menu->label(t("Album options")); if ($can_edit) { $options_menu->append(Menu::factory("dialog") - ->id("edit_permissions") - ->label(t("Edit permissions")) - ->url(url::site("permissions/browse/$item->id"))); + ->id("edit_permissions") + ->label(t("Edit permissions")) + ->url(url::site("permissions/browse/$item->id"))); } } } diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index dee6ae40..f30df092 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -40,7 +40,7 @@ class gallery_rss_Core { $feed->max_pages = ceil($all_children->find_all()->count() / $limit); $feed->title = t("Recent Updates"); - $feed->link = url::abs_site("albums/1"); + $feed->link = item::root()->abs_url(); $feed->description = t("Recent Updates"); return $feed; @@ -54,7 +54,7 @@ class gallery_rss_Core { $feed->max_pages = ceil( $item->viewable()->descendants_count(array("type" => "photo")) / $limit); $feed->title = html::purify($item->title); - $feed->link = url::abs_site("albums/{$item->id}"); + $feed->link = $item->abs_url(); $feed->description = nl2br(html::purify($item->description)); return $feed; diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 8da88b6e..d907a177 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -184,4 +184,12 @@ class item_Core { return $model; } + + /** + * Return the root Item_Model + * @return Item_Model + */ + static function root() { + return model_cache::get("item", 1); + } }
\ No newline at end of file diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 0ec5d048..6e9debea 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -168,9 +168,24 @@ class Item_Model extends ORM_MPTT { * * @param string $query the query string (eg "show=3") */ - public function url($query=array(), $full_uri=false) { - $url = ($full_uri ? url::abs_site("{$this->type}s/$this->id") - : url::site("{$this->type}s/$this->id")); + public function url($query=null) { + $relative_url = $this->relative_url(); + $url = url::site($relative_url); + if ($query) { + $url .= "?$query"; + } + return $url; + } + + /** + * album: url::abs_site("albums/2") + * photo: url::abs_site("photos/3") + * + * @param string $query the query string (eg "show=3") + */ + public function abs_url($query=null) { + $relative_url = $this->relative_url(); + $url = url::abs_site($relative_url); if ($query) { $url .= "?$query"; } diff --git a/modules/gallery/views/admin_block_photo_stream.html.php b/modules/gallery/views/admin_block_photo_stream.html.php index 1b9d8ff5..4968c39b 100644 --- a/modules/gallery/views/admin_block_photo_stream.html.php +++ b/modules/gallery/views/admin_block_photo_stream.html.php @@ -2,7 +2,7 @@ <ul> <? foreach ($photos as $photo): ?> <li class="gItem gPhoto"> - <a href="<?= url::site("photos/$photo->id") ?>" title="<?= html::purify($photo->title)->for_html_attr() ?>"> + <a href="<?= $photo->url() ?>" title="<?= html::purify($photo->title)->for_html_attr() ?>"> <img <?= photo::img_dimensions($photo->width, $photo->height, 72) ?> src="<?= $photo->thumb_url() ?>" alt="<?= html::purify($photo->title)->for_html_attr() ?>" /> </a> diff --git a/modules/gallery/views/upgrader.html.php b/modules/gallery/views/upgrader.html.php index 04200920..5f93c2d5 100644 --- a/modules/gallery/views/upgrader.html.php +++ b/modules/gallery/views/upgrader.html.php @@ -18,7 +18,7 @@ <h1> <?= t("That's it!") ?> </h1> <p> <?= t("Your <a href=\"%url\">Gallery</a> is up to date.", - array("url" => html::mark_clean(url::site("albums/1")))) ?> + array("url" => html::mark_clean(item::root()->url()))) ?> </p> </div> </div> diff --git a/modules/notification/views/comment_published.html.php b/modules/notification/views/comment_published.html.php index e39e39c6..a8ca1899 100644 --- a/modules/notification/views/comment_published.html.php +++ b/modules/notification/views/comment_published.html.php @@ -25,8 +25,8 @@ <tr> <td><?= t("Url:") ?></td> <td> - <a href="<?= $comment->item()->url(array(), true) ?>#comments"> - <?= $comment->item()->url(array(), true) ?>#comments + <a href="<?= $comment->item()->abs_url() ?>#comments"> + <?= $comment->item()->abs_url() ?>#comments </a> </td> </tr> diff --git a/modules/notification/views/item_deleted.html.php b/modules/notification/views/item_deleted.html.php index a51782ff..a95cdd89 100644 --- a/modules/notification/views/item_deleted.html.php +++ b/modules/notification/views/item_deleted.html.php @@ -15,8 +15,8 @@ <tr> <td><?= t("Url:") ?></td> <td> - <a href="<?= $item->parent()->url(array(), true) ?>"> - <?= $item->parent()->url(array(), true) ?> + <a href="<?= $item->parent()->abs_url() ?>"> + <?= $item->parent()->abs_url() ?> </a> </td> </tr> diff --git a/modules/search/views/search.html.php b/modules/search/views/search.html.php index 7963948d..91d9eec8 100644 --- a/modules/search/views/search.html.php +++ b/modules/search/views/search.html.php @@ -28,7 +28,7 @@ <? $item_class = "gAlbum"; ?> <? endif ?> <li class="gItem <?= $item_class ?>"> - <a href="<?= url::site("items/$item->id") ?>"> + <a href="<?= $item->url() ?>"> <?= $item->thumb_img() ?> <p> <?= html::purify($item->title) ?> diff --git a/modules/user/controllers/login.php b/modules/user/controllers/login.php index b81b17b2..dcac0723 100644 --- a/modules/user/controllers/login.php +++ b/modules/user/controllers/login.php @@ -48,7 +48,7 @@ class Login_Controller extends Controller { list ($valid, $form) = $this->_auth("login/auth_html"); if ($valid) { - url::redirect("albums/1"); + url::redirect(item::root()->url()); } else { print $form; } diff --git a/modules/user/controllers/logout.php b/modules/user/controllers/logout.php index fc3ced56..3bf274a6 100644 --- a/modules/user/controllers/logout.php +++ b/modules/user/controllers/logout.php @@ -31,7 +31,7 @@ class Logout_Controller extends Controller { // Don't use url::redirect() because it'll call url::site() and munge the continue url. header("Location: $continue_url"); } else { - url::redirect("albums/1"); + url::redirect(item::root()->url()); } } } diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index a6522369..8c18916e 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -130,7 +130,7 @@ class Password_Controller extends Controller { $user->hash = null; $user->save(); message::success(t("Password reset successfully")); - url::redirect("albums/1"); + url::redirect(item::root()->url()); } else { print $view; } |