get_file_link()

Получает URL адрес страницы файла, по переданному ID или массива файла.

Фильтры из функции
ds_get_file_link_mask

Использование

$link = get_file_link(34); 
// Вернет ссылку на файл с ID 34
// https://site.ru/files/view/34/?t=2

Код функции

function get_file_link($file = NULL) 
{
	if (is_numeric($file)) {
		$file = get_file($file);
	}

	$author = get_user($file['user_id']); 
	$types = get_media_type($file['file_type']); 
	$terms = ds_get_file_terms($file); 

	foreach($terms AS $term) {
		$term_id = $term['term_id']; 
		break; 
	}

	$mask = use_filters('ds_get_file_link_mask', array(
	    '%user_nick%' => $author['nick'], 
	    '%user_id%' => $author['id'], 
	    '%term_id%' => isset($term['term_id']) ? $term['term_id'] : 0, 
	    '%file_id%' => $file['id'], 
	), $file, $terms, $author, $types);

	return str_replace(array_keys($mask), array_values($mask), $types['permalinks']['file_view']); 
}