You are here

function linkit_file_linkit_load_plugins in Linkit 7

Same name and namespace in other branches
  1. 6 plugins/linkit_file/linkit_file.module \linkit_file_linkit_load_plugins()

Implements hook_linkit_load_plugins().

File

plugins/linkit_file/linkit_file.module, line 12
Extend Linkit with files.

Code

function linkit_file_linkit_load_plugins($string) {
  $matches = array();

  // Get files.
  $result = db_select('file_managed', 'f')
    ->fields('f', array(
    'filename',
    'uri',
    'filemime',
  ))
    ->condition('f.filename', '%' . db_like($string) . '%', 'LIKE')
    ->condition('f.status', '1')
    ->condition('f.uri', 'public://%', 'LIKE')
    ->execute();
  $public_path = variable_get('file_public_path', conf_path() . '/files');
  foreach ($result as $file) {
    $matches['file'][] = array(
      'title' => $file->filename,
      'path' => $public_path . '/' . file_uri_target($file->uri),
      'information' => array(
        'type' => 'File',
        'mimetype' => $file->filemime,
      ),
    );
  }
  return $matches;
}