You are here

public function SearchApiAttachmentsLinksAlterSettings::isFileIndexable in Search API attachments 7

Checks if file is allowed to be indexed.

Parameters

object $file: The file object.

object $item: The search api item.

string $field_name: The file name.

Return value

bool TRUE is the file is allowed to be indexed, FALSE otherwise.

Overrides SearchApiAttachmentsAlterSettings::isFileIndexable

1 call to SearchApiAttachmentsLinksAlterSettings::isFileIndexable()
SearchApiAttachmentsLinksAlterSettings::alterItems in contrib/search_api_attachments_links/includes/callback_attachments_links_settings.inc
Alter items before indexing.

File

contrib/search_api_attachments_links/includes/callback_attachments_links_settings.inc, line 68
Search API data alteration callback.

Class

SearchApiAttachmentsLinksAlterSettings
@file Search API data alteration callback.

Code

public function isFileIndexable($link, $item, $field_name = NULL) {

  // Extension restriction.
  $exclude = explode(' ', $this->options['excluded_extensions']);

  // File size restriction.
  if (isset($this->options['max_file_size'])) {
    $max_file_size = parse_size($this->options['max_file_size']);
  }
  else {
    $max_file_size = '0';
  }

  // Extension restriction.
  if (!in_array(pathinfo($link['url'], PATHINFO_EXTENSION), $exclude)) {

    // File size restriction.
    if ($max_file_size > $this
      ->getUrlSize($link['url'])) {

      // Allow customization of indexability rules.
      foreach (module_implements('search_api_attachments_indexable') as $module) {
        if (module_invoke($module, 'search_api_attachments_indexable', $link, $item, $field_name) === FALSE) {
          return FALSE;
        }
      }
      return TRUE;
    }
  }
  return FALSE;
}