From 161366e51d17a3a31fcce79505948c5945603ff3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 1 Jan 2010 21:02:52 -0800 Subject: New controller for remapping Gallery 2 urls to Gallery 3 urls. --- modules/g2_import/controllers/g2.php | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 modules/g2_import/controllers/g2.php (limited to 'modules/g2_import/controllers/g2.php') diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php new file mode 100644 index 00000000..f303d604 --- /dev/null +++ b/modules/g2_import/controllers/g2.php @@ -0,0 +1,73 @@ +get("id")) { + $where = array("g2_id", "=", $g2_id); + } else if ($g2_url = $input->get("url")) { + $where = array("g2_url", "=", $g2_url); + } else { + throw new Kohana_404_Exception(); + } + + $g2_map = ORM::factory("g2_map") + ->merge_where(array($where)) + ->find(); + + if (!$g2_map->loaded()) { + throw new Kohana_404_Exception(); + } + + $item = ORM::factory("item")->where("id", "=", $g2_map->g3_id)->find(); + if (!$item->loaded() || !access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + + + // Redirect the user to the new url + switch ($g2_map->resource_type) { + case "thumbnail": + url::redirect($item->thumb_url(true)); + + case "resize": + url::redirect($item->resize_url(true)); + + case "full": + url::redirect($item->file_url(true)); + + case "item": + case "album": + url::redirect($item->abs_url()); + + case "group": + case "user": + default: + throw new Kohana_404_Exception(); + } + } +} \ No newline at end of file -- cgit v1.2.3 From 80e35affcb20e9ec1ded7ae2e750444718f8bffe Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 1 Jan 2010 21:56:29 -0800 Subject: Improve the PHPdoc for map() We now expect to either get query parameters from the Gallery2 url so we can pick off g2_itemId, or we'll get the rewrite url in the path query param. --- modules/g2_import/controllers/g2.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'modules/g2_import/controllers/g2.php') diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php index f303d604..3e002758 100644 --- a/modules/g2_import/controllers/g2.php +++ b/modules/g2_import/controllers/g2.php @@ -21,16 +21,23 @@ class G2_Controller extends Admin_Controller { /** * Redirect Gallery 2 urls to their appropriate matching Gallery 3 url. * - * Inputs look like this: - * /g2/map?url=v/Family/Wedding/IMG_3.jpg.html - * /g2/map?id=1931 + * We use mod_rewrite to create this path, so Gallery2 urls like this: + * /gallery2/v/Family/Wedding.jpg.html + * /gallery2/main.php?g2_view=core.ShowItem&g2_itemId=1234 + * + * Show up here like this: + * /g2/map?path=v/Family/Wedding.jpg.html + * /g2/map?g2_view=core.ShowItem&g2_itemId=1931 */ public function map() { $input = Input::instance(); - if ($g2_id = $input->get("id")) { - $where = array("g2_id", "=", $g2_id); - } else if ($g2_url = $input->get("url")) { - $where = array("g2_url", "=", $g2_url); + $path = $input->get("path"); + $id = $input->get("g2_itemId"); + + if ($id) { + $where = array("g2_id", "=", $id); + } else if ($path) { + $where = array("g2_url", "=", $path); } else { throw new Kohana_404_Exception(); } -- cgit v1.2.3