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