| 2 |
|
|
| 3 |
function api_file_redirect() { |
function api_file_redirect() { |
| 4 |
$args = func_get_args(); |
$args = func_get_args(); |
|
$branches = api_get_branches(); |
|
| 5 |
$suffix = ''; |
$suffix = ''; |
| 6 |
$file = new StdClass(); |
$file = new StdClass(); |
| 7 |
$file->object_type = 'file'; |
$file->object_type = 'file'; |
| 8 |
$file->branch_name = variable_get('api_default_branch', NULL); |
$file->branch_name = db_result(db_query("SELECT branch_name FROM {api_branch} WHERE branch_id = %d", variable_get('api_default_branch', NULL))); |
| 9 |
|
|
| 10 |
$end = count($args) - 1; |
$end = count($args) - 1; |
| 11 |
if (in_array($args[$end], array('source', 'documentation'))) { |
if (in_array($args[$end], array('source', 'documentation'))) { |
| 12 |
$suffix = '/' . $args[$end]; |
$suffix = '/' . $args[$end]; |
| 13 |
$end -= 1; |
$end -= 1; |
| 14 |
} |
} |
| 15 |
if (isset($branches[$args[$end]])) { |
if (db_result(db_query("SELECT 1 FROM {api_branch} WHERE branch_name = '%s'", $args[$end]))) { |
| 16 |
$file->branch_name = $branches[$args[$end]]->branch_name; |
$file->branch_name = $args[$end]; |
| 17 |
$end -= 1; |
$end -= 1; |
| 18 |
} |
} |
| 19 |
$file->object_name = implode('/', array_slice($args, 0, $end - 0 + 1)); |
$file->object_name = implode('/', array_slice($args, 0, $end + 1)); |
| 20 |
|
|
| 21 |
drupal_goto(api_url($file) . $suffix); |
drupal_goto(api_url($file) . $suffix); |
| 22 |
} |
} |