From bd9a5e38bf21c2c57baad01f8d5f529ad5ca8783 Mon Sep 17 00:00:00 2001 From: "Thomas E. Horner" Date: Sat, 29 Dec 2012 10:34:51 +0100 Subject: [PATCH] added redirect for sized+thumbs and hotfix for buggy dat files --- 3.0/modules/g1_import/controllers/g1.php | 19 ++++++++++++++++--- .../g1_import/helpers/Gallery1DataParser.php | 8 ++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/3.0/modules/g1_import/controllers/g1.php b/3.0/modules/g1_import/controllers/g1.php index 53458baa..eb8160ba 100644 --- a/3.0/modules/g1_import/controllers/g1.php +++ b/3.0/modules/g1_import/controllers/g1.php @@ -51,7 +51,7 @@ class G1_Controller extends Controller { $pos = strrpos($path, '/'); if($pos!==false) { // Get ItemX into g1_item - $g1_item = substr($path,$pos+1); + $g1_item = substr($path,$pos+1,strlen($path)); // Get FolderX into g1_item $g1_album = substr($path,0,$pos); } @@ -69,7 +69,12 @@ class G1_Controller extends Controller { $g1_item = substr($g1_item, 0, $pos); } - $mapping = ORM::factory('g1_map')->where('album', '=', $g1_album)->where('item', '=', $g1_item)->where('resource_type', '=', $album ? 'album':'item')->find(); + if(($pos=strrpos($g1_item, '.sized'))!==false||($pos=strrpos($g1_item, '.thumb'))!==false) { + $mapping = ORM::factory('g1_map')->where('album', '=', $g1_album)->where('item', '=', substr($g1_item,0, $pos))->where('resource_type', '=', $album ? 'album':'item')->find(); + } + else { + $mapping = ORM::factory('g1_map')->where('album', '=', $g1_album)->where('item', '=', $g1_item)->where('resource_type', '=', $album ? 'album':'item')->find(); + } if(!$mapping->loaded()) { throw new Kohana_404_Exception(); } @@ -80,7 +85,15 @@ class G1_Controller extends Controller { access::required('view', $item); if($binary) { - url::redirect($item->file_url(true), '301'); + if(strrpos($g1_item, '.sized')!==false) { + url::redirect($item->resize_url(true), '301'); + } + else if(strrpos($g1_item, '.thumb')!==false) { + url::redirect($item->thumb_url(true), '301'); + } + else { + url::redirect($item->file_url(true), '301'); + } } else { $url = $item->abs_url(); diff --git a/3.0/modules/g1_import/helpers/Gallery1DataParser.php b/3.0/modules/g1_import/helpers/Gallery1DataParser.php index 74b1d826..c4ae5ae8 100644 --- a/3.0/modules/g1_import/helpers/Gallery1DataParser.php +++ b/3.0/modules/g1_import/helpers/Gallery1DataParser.php @@ -74,16 +74,16 @@ class Gallery1DataParser { * We renamed User.php to Gallery_User.php in v1.2, so port forward * any saved user objects. */ - if (!strcmp(substr($tmp, 0, 10), 'O:4:"user"')) { - $tmp = str_replace('O:4:"user"', 'O:12:"gallery_user"', $tmp); + if (stripos($tmp, 'O:4:"user"')!==false) { + $tmp = str_ireplace('O:4:"user"', 'O:12:"gallery_user"', $tmp); } /* * Gallery3 already contains a class named Image so * we need to rename the G1 Image class to G1Img here */ - if (strpos($tmp, 'O:5:"Image"')!==false) { - $tmp = str_replace('O:5:"Image"', 'O:5:"G1Img"', $tmp); + if (stripos($tmp, 'O:5:"image"')!==false) { + $tmp = str_ireplace('O:5:"image"', 'O:5:"G1Img"', $tmp); } $object = unserialize($tmp);