You are here

public function SearchApiAttachmentsAlterSettings::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.

7 calls to SearchApiAttachmentsAlterSettings::isFileIndexable()
SearchApiAttachmentsAlterSettings::alterItems in includes/callback_attachments_settings.inc
Alter items before indexing.
SearchApiAttachmentsCommerceProductReferenceAlterSettings::alterItems in contrib/search_api_attachments_commerce_product_reference/includes/callback_attachments_commerce_product_reference_settings.inc
Alter items before indexing.
SearchApiAttachmentsFieldCollectionsAlterSettings::alterItems in contrib/search_api_attachments_field_collections/includes/callback_attachments_field_collections_settings.inc
Alter items before indexing.
SearchApiAttachmentsMultifieldAlterSettings::alterItems in contrib/search_api_attachments_multifield/includes/callback_attachments_multifield_settings.inc
Alter items before indexing.
SearchApiAttachmentsParagraphsAlterSettings::alterItems in contrib/search_api_attachments_paragraphs/includes/callback_attachments_paragraphs_settings.inc
Alter items before indexing.

... See full list

1 method overrides SearchApiAttachmentsAlterSettings::isFileIndexable()
SearchApiAttachmentsLinksAlterSettings::isFileIndexable in contrib/search_api_attachments_links/includes/callback_attachments_links_settings.inc
Checks if file is allowed to be indexed.

File

includes/callback_attachments_settings.inc, line 77
Search API data alteration callback.

Class

SearchApiAttachmentsAlterSettings
Indexes files content.

Code

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

  // File entity bundle restriction.
  if (isset($this->options['excluded_file_entity_bundles'])) {
    if (!empty($this->options['excluded_file_entity_bundles'])) {
      if (in_array($file->type, $this->options['excluded_file_entity_bundles'])) {
        return FALSE;
      }
    }
  }

  // Extension restriction.
  $exclude = array();
  foreach (explode(' ', $this->options['excluded_extensions']) as $ext) {
    $exclude[$ext] = file_get_mimetype('dummy.' . $ext);
  }

  // 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';
  }

  // Checking for missing content.
  if (empty($file)) {
    watchdog('search_api_attachments', 'file is empty for item %item_title (%item_nid)', array(
      '%item_title' => empty($item->title) ? t('empty') : $item->title,
      '%item_nid' => empty($item->nid) ? empty($item->id) ? t('empty') : $item->id : $item->nid,
    ), WATCHDOG_ERROR);
  }
  else {
    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)) {

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