You are here

protected function SearchApiAttachmentsEntityreferenceAlterSettings::getFilesContent in Search API attachments 7

Extracts and returns contents of files.

Parameters

array $files: The array of file objects/arrays.

array $exclude: The array of file extensions to exclude.

int $max_file_size: The maximum file size.

Return value

string Extracted contents of files imploded by the space character.

1 call to SearchApiAttachmentsEntityreferenceAlterSettings::getFilesContent()
SearchApiAttachmentsEntityreferenceAlterSettings::alterItems in contrib/search_api_attachments_entityreference/includes/callback_attachments_entityreference_settings.inc
Alter items before indexing.

File

contrib/search_api_attachments_entityreference/includes/callback_attachments_entityreference_settings.inc, line 144
Search API data alteration callback.

Class

SearchApiAttachmentsEntityreferenceAlterSettings

Code

protected function getFilesContent($files, $exclude, $max_file_size) {
  $ret = '';

  // Limit to the max number of value per field.
  if (isset($this->options['number_indexed']) && $this->options['number_indexed'] != '0' && count($files) > $this->options['number_indexed']) {
    $files = array_slice($files, 0, $this->options['number_indexed']);
  }
  foreach ($files as $file) {
    $file = (array) $file;

    // Private file restriction.
    if (!$this
      ->isTemporary($file) && !($this->options['excluded_private'] && $this
      ->isPrivate($file))) {

      // Extension restriction.
      if (!in_array($file['filemime'], $exclude)) {

        // File size restriction.
        $file_size_errors = file_validate_size((object) $file, $max_file_size);
        if (empty($file_size_errors)) {
          $ret .= ' ' . $this
            ->getFileContent($file);
        }
      }
    }
  }
  return trim($ret);
}