summaryrefslogtreecommitdiff
path: root/modules/g2_import/controllers/g2.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/g2_import/controllers/g2.php')
-rw-r--r--modules/g2_import/controllers/g2.php22
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php
index 5fd4400c..1d97653a 100644
--- a/modules/g2_import/controllers/g2.php
+++ b/modules/g2_import/controllers/g2.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class G2_Controller extends Admin_Controller {
+class G2_Controller extends Controller {
/**
* Redirect Gallery 2 urls to their appropriate matching Gallery 3 url.
*
@@ -35,15 +35,25 @@ class G2_Controller extends Admin_Controller {
$id = $input->get("g2_itemId");
if ($id) {
- $where = array("g2_id", "=", $id);
+ // Requests by id are either core.DownloadItem or
+ // core.ShowItem requests.
+ // Later versions of Gallery 2 don't specify g2_view if
+ // it's the default (core.ShowItem).
+ // And in some cases (bbcode, embedding) people are using
+ // the id style URLs although URL rewriting is enabled.
+ $where = array(array("g2_id", "=", $id));
+ $view = $input->get("g2_view");
+ if ($view) {
+ $where[] = array("g2_url", "like", "%g2_view=$view%");
+ } // else: Assuming that the first search hit is sufficiently good.
} else if ($path) {
- $where = array("g2_url", "=", $path);
+ $where = array(array("g2_url", "=", $path));
} else {
throw new Kohana_404_Exception();
}
$g2_map = ORM::factory("g2_map")
- ->merge_where(array($where))
+ ->merge_where($where)
->find();
if (!$g2_map->loaded()) {
@@ -51,9 +61,10 @@ class G2_Controller extends Admin_Controller {
}
$item = ORM::factory("item", $g2_map->g3_id);
- if (!$item->loaded() || !access::can("view", $item)) {
+ if (!$item->loaded()) {
throw new Kohana_404_Exception();
}
+ access::required("view", $item);
// Redirect the user to the new url
@@ -64,6 +75,7 @@ class G2_Controller extends Admin_Controller {
case "resize":
url::redirect($item->resize_url(true));
+ case "file":
case "full":
url::redirect($item->file_url(true));