You are here

feeds_ex.module in Feeds extensible parsers 7

Same filename and directory in other branches
  1. 8 feeds_ex.module
  2. 7.2 feeds_ex.module

A Feeds framework used to create extensible parsers.

File

feeds_ex.module
View source
<?php

/**
 * @file
 * A Feeds framework used to create extensible parsers.
 */

/**
 * Defines which commit to checkout from flow/jsonpath.
 */
define('FEEDS_EX_JSONPATH_LIBRARY_VERSION', '0.5.0');

/**
 * Implements hook_menu().
 */
function feeds_ex_menu() {
  $items = array();
  $items['_feeds_ex/encoding_autocomplete'] = array(
    'title' => 'Encoding autocomplete',
    'page callback' => 'feeds_ex_encoding_autocomplete',
    'access arguments' => array(
      'administer feeds',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'feeds_ex.pages.inc',
  );
  return $items;
}

/**
 * Implements hook_theme().
 */
function feeds_ex_theme() {
  return array(
    'feeds_ex_configuration_table' => array(
      'file' => 'feeds_ex.theme.inc',
      'render element' => 'element',
    ),
  );
}

/**
 * Implements hook_modules_enabled().
 */
function feeds_ex_modules_enabled(array $modules) {
  if (in_array('querypath', $modules)) {
    cache_clear_all('plugins:feeds:plugins', 'cache');
  }
}

/**
 * Implements hook_registry_files_alter().
 *
 * Add JMESPath tests if they are supported.
 */
function feeds_ex_registry_files_alter(array &$files, array $modules) {
  if (version_compare(PHP_VERSION, '5.4.0', '<') || !module_exists('simpletest')) {
    return;
  }
  if (!feeds_ex_library_path('jmespath.php', 'vendor/autoload.php')) {
    return;
  }
  $path = drupal_get_path('module', 'feeds_ex');
  $files[$path . '/src/Tests/FeedsExJmesPath.test'] = array(
    'module' => 'feeds_ex',
    'weight' => 1,
  );
  $files[$path . '/src/Tests/FeedsExJmesPathLines.test'] = array(
    'module' => 'feeds_ex',
    'weight' => 1,
  );
}

/**
 * Implements hook_libraries_info().
 */
function feeds_ex_libraries_info() {
  $libraries = array();
  $libraries['jsonpath'] = array(
    'name' => 'JSONPath',
    'vendor url' => 'https://github.com/FlowCommunications/JSONPath',
    'download url' => 'https://github.com/FlowCommunications/JSONPath/archive/' . FEEDS_EX_JSONPATH_LIBRARY_VERSION . '.tar.gz',
    'version' => FEEDS_EX_JSONPATH_LIBRARY_VERSION,
    'xautoload' => '_feeds_ex_xautoload_callback',
  );
  return $libraries;
}

/**
 * Callback for xautoload.
 *
 * @see feeds_ex_libraries_info()
 */
function _feeds_ex_xautoload_callback($adapter) {
  try {
    $adapter
      ->composerJson('composer.json');
  } catch (Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error', FALSE);
  }
}

/**
 * Returns the path of a library.
 *
 * @param string $library
 *   The name of the library. If libraries module is installed, look for
 *   libraries with this name managed by libraries module.
 * @param string $file
 *   The filename to search for.
 *
 * @return string|bool
 *   Returns the relative path of the library, or false if it does not exist.
 */
function feeds_ex_library_path($library, $file) {
  $libraries_path = module_exists('libraries') ? libraries_get_path($library) : FALSE;
  if ($libraries_path && is_file($libraries_path . '/' . $file)) {
    return $libraries_path . '/' . $file;
  }
  elseif (is_file(DRUPAL_ROOT . '/sites/all/libraries/' . $library . '/' . $file)) {
    return 'sites/all/libraries/' . $library . '/' . $file;
  }
  return FALSE;
}

/**
 * Machine name exists callback.
 */
function feeds_ex_source_exists($source_id, array $element) {
  $sources = feeds_importer($element['#feeds_importer'])->parser
    ->getMappingSources();
  return isset($sources[$source_id]);
}

Functions

Namesort descending Description
feeds_ex_libraries_info Implements hook_libraries_info().
feeds_ex_library_path Returns the path of a library.
feeds_ex_menu Implements hook_menu().
feeds_ex_modules_enabled Implements hook_modules_enabled().
feeds_ex_registry_files_alter Implements hook_registry_files_alter().
feeds_ex_source_exists Machine name exists callback.
feeds_ex_theme Implements hook_theme().
_feeds_ex_xautoload_callback Callback for xautoload.

Constants

Namesort descending Description
FEEDS_EX_JSONPATH_LIBRARY_VERSION Defines which commit to checkout from flow/jsonpath.