You are here

function taxonomy_xml_services in Taxonomy import/export via XML 7

Return descriptions of all the various services we can use to load schemas from.

Scans the /services directory and loads each inc file there.

Calls hook_taxonomy_service_info() on each of the files in turn to find out what it does.

Parameters

string $mode: How to return the results. Default 'full' is all info array. May also be 'options' which returns just the service name and ID as can be used in a selectbox.

Return value

array List of services.

5 calls to taxonomy_xml_services()
taxonomy_xml_about_services in ./taxonomy_xml.module
Admin help page listing details of available services A menu page callback
taxonomy_xml_add_all_children_to_queue in ./taxonomy_xml.process.inc
Queue up an import action.
taxonomy_xml_import_form in ./taxonomy_xml.admin.inc
Builds the import form.
taxonomy_xml_source_features_export in ./taxonomy_xml.features.inc
Implements hook_features_export().
taxonomy_xml_source_features_export_options in ./taxonomy_xml.features.inc
Implements hook_features_export_options().

File

./taxonomy_xml.module, line 906
Make it possible to import and export taxonomies as XML documents.

Code

function taxonomy_xml_services($mode = 'full') {
  static $services;
  if (!isset($services)) {
    $module_dir = drupal_get_path('module', 'taxonomy_xml');
    $incs = file_scan_directory($module_dir, '|.*\\.taxonomy_service\\.inc|');
    $services = array();
    foreach ($incs as $filepath => $file) {
      include_once DRUPAL_ROOT . '/' . $filepath;
      $format_name = preg_replace('|\\.taxonomy_service$|', '', $file->name);
      $funcname = "{$format_name}_taxonomy_service_info";
      if (!function_exists($funcname)) {
        watchdog('taxonomy_xml', "No {$funcname} function found in the file {$filepath}", array(), WATCHDOG_WARNING);
      }
      else {
        $service_infos = $funcname();
        foreach ($service_infos as $service_info) {
          $service_info['filepath'] = $filepath;
        }
        if (is_array($service_infos)) {
          $services += $service_infos;
        }
        else {
          watchdog('taxonomy_xml', "Incorrect return from {$funcname} in {$filepath}. Should have been an array describing its services", array(), WATCHDOG_WARNING);
        }
      }
    }
  }

  // This will have returned an index list of all services we can use.
  if ($mode == 'options') {

    // Return an array suitable for use in a form select element.
    $options = array();
    foreach ($services as $id => $service) {
      $options[$id] = $service['provider'] . " - " . $service['name'];
    }
    return $options;
  }
  return $services;
}