class FeedsOAIParser in Feeds OAI-PMH Fetcher and Parser 6
Same name and namespace in other branches
- 7 FeedsOAIParser.inc \FeedsOAIParser
Class definition for OAI-PMH Dublin Core metadata parser.
Hierarchy
- class \FeedsConfigurable
- class \FeedsPlugin implements FeedsSourceInterface
- class \FeedsParser
- class \FeedsOAIParser
- class \FeedsParser
- class \FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsOAIParser
1 string reference to 'FeedsOAIParser'
- feeds_oai_pmh_feeds_plugins in ./
feeds_oai_pmh.module - Implementation of hook_feed_plugins().
File
- ./
FeedsOAIParser.inc, line 12 - Implementation of FeedsParser::parse().
View source
class FeedsOAIParser extends FeedsParser {
/**
* Implementation of FeedsParser::parse().
*/
public function parse(FeedsImportBatch $batch, FeedsSource $source) {
require_once drupal_get_path('module', 'feeds_oai_pmh') . '/feeds_oai_pmh.inc';
$feed = feeds_oai_pmh_parse($batch
->getRaw());
if (!$feed) {
// No items, return
return;
}
// Check for items.
if (is_array($feed['items'])) {
// Add set name element to each of the items.
$oai_endpoint_url = $source->config['FeedsOAIHTTPFetcher']['source'];
$identify_response = feeds_oai_pmh_identify($oai_endpoint_url);
if ($identify_response['repository']['sets']) {
foreach ($feed['items'] as $index => $item) {
foreach ($item['setspec_raw'] as $setspec) {
$set_name = $identify_response['repository']['sets'][$setspec]['name'];
$feed['items'][$index]['setspec_name'][] = $set_name;
}
}
}
// Return the items found in feed.
$batch
->setItems($feed['items']);
}
}
/**
* Implementation of FeedsParser::clear().
*
* Delete variables containing resumptionToken and from used in last fetch.
*/
public function clear(FeedsSource $source) {
// Only if FeedsOAIHTTPFetcher was used as the fetcher.
if ($source->config['FeedsOAIHTTPFetcher']) {
$oai_endpoint_url = $source->config['FeedsOAIHTTPFetcher']['source'];
$set = $source->config['FeedsOAIHTTPFetcher']['set'];
variable_del('feeds_oai:resumptionToken:' . $set . ':' . $oai_endpoint_url);
variable_del('feeds_oai:from:' . $set . ':' . $oai_endpoint_url);
}
parent::clear($source);
}
/**
* Return mapping sources.
*/
public function getMappingSources() {
self::loadMappers();
$sources = array();
drupal_alter('feeds_parser_sources', $sources, feeds_importer($this->id)->config['content_type']);
$sources += array(
'guid' => array(
'name' => t('Repository Record identifier'),
'description' => t('A unique string per each metadata record, defined by the repository.'),
),
'timestamp' => array(
'name' => t('Record publication date'),
'description' => t("Date this metadata record was published on the repository. Different from the described item's publication date."),
),
'metadata_record_url' => array(
'name' => t('Raw metadata record URL'),
'description' => t("The URL to a GetRecord OAI request for the source metadata record. Note: This URL will return raw XML data."),
),
'url' => array(
'name' => t('URL to resource'),
'description' => t('All valid URLs detected in dc:identifier elements.'),
),
'setspec_raw' => array(
'name' => t('Set: setSpec (raw value)'),
'description' => t("The set/setSpec from the record's header."),
),
'setspec_name' => array(
'name' => t('Set: name'),
'description' => t("The set name for this record, taken from the repository's identify response."),
),
);
// Add dublin core field to mapping sources
$elements = array(
'title',
'type',
'subject',
'contributor',
'creator',
'description',
'publisher',
'date',
'format',
'identifier',
'source',
'language',
'relation',
'coverage',
'rights',
);
foreach ($elements as $element) {
$sources[$element] = array(
'name' => t('Metadata: dc:@element', array(
'@element' => $element,
)),
'description' => t('From the metadata record.'),
);
}
return $sources;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | 1 |
FeedsConfigurable:: |
public | function | Return default configuration. | 6 |
FeedsConfigurable:: |
public | function | Return configuration form for this object. The keys of the configuration form must match the keys of the array returned by configDefaults(). | 10 |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent and enabled. I. e. it is defined either in code or in the database and it is enabled. | 1 |
FeedsConfigurable:: |
public | function | Implementation of getConfig(). | 1 |
FeedsConfigurable:: |
public static | function | Instantiate a FeedsConfigurable object. | 1 |
FeedsConfigurable:: |
public | function | Set configuration. | 1 |
FeedsConfigurable:: |
public | function | Override magic method __get(). Make sure that $this->config goes through getConfig() | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsOAIParser:: |
public | function |
Implementation of FeedsParser::clear(). Overrides FeedsParser:: |
|
FeedsOAIParser:: |
public | function |
Return mapping sources. Overrides FeedsParser:: |
|
FeedsOAIParser:: |
public | function |
Implementation of FeedsParser::parse(). Overrides FeedsParser:: |
|
FeedsParser:: |
public | function | Get an element identified by $element_key of the given item. The element key corresponds to the values in the array returned by FeedsParser::getMappingSources(). | 1 |
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
protected static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public | function |
Implementation of FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
A source is being deleted. Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
Callback methods, exposes source form. Overrides FeedsSourceInterface:: |
3 |
FeedsPlugin:: |
public | function |
Validation handler for sourceForm. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
A source is being saved. Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
protected | function |
Constructor. Overrides FeedsConfigurable:: |