function visual_select_file_preprocess_views_view in Visual select file 7
Implements template_preprocess_views_view().
File
- ./
visual_select_file.module, line 122
Code
function visual_select_file_preprocess_views_view(&$vars) {
$view = $vars['view'];
if (_visual_select_file_view_has_tag($view)) {
$remove_absolute = variable_get('visual_select_file_remove_absolute', TRUE);
$field = isset($_GET['vsf_field']) ? $_GET['vsf_field'] : '';
global $base_url;
$base_url_length = strlen($base_url);
$fids = array_map(function ($record) {
return $record->fid;
}, $view->result);
$files = file_load_multiple($fids);
$meta = array();
foreach ($files as $fid => $file) {
$path = image_style_url('IMAGESTYLE', $file->uri);
$path = preg_replace('#\\?itok=[^&]+$#', '', $path);
// We know for a fact this itok won't work, so remove it for prettiness' sake.
$original = file_create_url($file->uri);
if ($remove_absolute) {
if (substr($path, 0, $base_url_length) == $base_url) {
$path = substr($path, $base_url_length);
}
if (substr($original, 0, $base_url_length) == $base_url) {
$original = substr($original, $base_url_length);
}
}
$meta[$fid] = array(
$fid,
$path,
$file->filename,
$original,
);
}
$results = array(
'results' => $meta,
'selected_file' => (int) @$_GET['vsf_fid'],
);
$context = compact('view', 'files', 'field');
drupal_alter('visual_select_file_results', $results, $context);
drupal_add_js(array(
'visual_select_file' => $results,
), 'setting');
}
}