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); // 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); } $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) { url::redirect($item->file_url(true), '301'); } else { $url = $item->abs_url(); if($page!='') { $url .= (strpos($url,'?')!==false ? '&':'?').'page='.$page; } url::redirect($url, '301'); } } }