get('path'); $page = $input->get('page'); if(!is_numeric($page)) $page = ''; if($path=='view_album.php' || $path=='slideshow.php') $path = $input->get('set_albumName'); if($path=='view_photo.php') $path = $input->get('set_albumName').'/'.$input->get('id'); if($path=='main.php') { //we do only name based g2 mapping here $item = item::root(); access::required('view', $item); url::redirect($item->abs_url(), '301'); } // Item names come in as FolderX/ItemX $album = 0; $pos = strrpos($path, '/'); if($pos!==false) { // Get ItemX into g1_item $g1_item = substr($path,$pos+1,strlen($path)); // Get FolderX into g1_item $g1_album = substr($path,0,$pos); } else { $album = 1; $g1_item = ''; $g1_album = $path; } // Only binary files (the item itself, not the html) may have file extensions $binary = 0; $pos = strrpos($g1_item, '.'); if($pos!==false) { $binary = 1; $g1_item = substr($g1_item, 0, $pos); } 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(); } $item = ORM::factory('item', $mapping->id); if (!$item->loaded()) { throw new Kohana_404_Exception(); } access::required('view', $item); if($binary) { 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(); if($page!='') { $url .= (strpos($url,'?')!==false ? '&':'?').'page='.$page; } url::redirect($url, '301'); } } }