Configure feeds to consume static pages markdown

Add static_page_import feed to feeds configuration. This module
introduce the groups_feeds_markdown_directory variable that
holds the markdown source directory. The default value is
public://feeds.

Change-Id: I70dc2d855a4d66a2d19b25bf6dae116c586ad1bb
This commit is contained in:
Marton Kiss 2014-05-07 20:08:20 +02:00
parent ff684f74dd
commit 9faaea5e06
2 changed files with 103 additions and 0 deletions

View File

@ -6,4 +6,31 @@
function groups_feeds_enable() {
//clear the cache to display in Feeds as available plugin.
cache_clear_all('plugins:feeds:plugins', 'cache');
}
/**
* Implement hook_install()
*
*/
function groups_feeds_install() {
// Create markdown fetcher source
$feed = 'static_page_import';
$feedSource = feeds_source($feed);
$config = $feedSource->getConfig();
$config['feeds_fetcher_directory_fetcher']['source'] =
variable_get('groups_feeds_markdown_directory', 'public://feeds');
$config['feeds_fetcher_directory_fetcher']['reset'] = 0;
$config['feeds_fetcher_directory_fetcher']['feed_files_fetched'] = "";
$feedSource->setConfig($config);
$feedSource->save();
}
/**
* Implement hook_uninstall()
*
*/
function groups_feeds_uninstall() {
// TODO: remove static_page_import feeds source
}

View File

@ -29,4 +29,80 @@ function groups_feeds_ctools_plugin_api($owner, $api) {
if ($owner == 'feeds' && $api == 'plugins') {
return array('version' => 1);
}
if ($owner == 'feeds' && $api == 'feeds_importer_default') {
return array('version' => 1);
}
}
/**
* Implement hook_feeds_importer_default()
*
* Add static page importer
*/
function groups_feeds_feeds_importer_default() {
$export = array();
$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'static_page_import';
$feeds_importer->config = array(
'name' => 'Static page import',
'description' => 'Import page nodes from markdown file.',
'fetcher' => array(
'plugin_key' => 'feeds_fetcher_directory_fetcher',
'config' => array(
'recursive' => 1,
'directory' => 'public://feeds',
'filemask' => '/\\.md$/',
'updated_files' => 1,
),
),
'parser' => array(
'plugin_key' => 'MarkdownParser',
'config' => array(),
),
'processor' => array(
'plugin_key' => 'FeedsNodeProcessor',
'config' => array(
'expire' => '-1',
'author' => '1',
'authorize' => 1,
'mappings' => array(
0 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => 1,
),
1 => array(
'source' => 'title',
'target' => 'title_field',
'unique' => FALSE,
),
2 => array(
'source' => 'body',
'target' => 'body',
'unique' => FALSE,
),
3 => array(
'source' => 'path',
'target' => 'path_alias',
'unique' => FALSE,
),
),
'update_existing' => '2',
'input_format' => 'plain_text',
'skip_hash_check' => 0,
'bundle' => 'page',
),
),
'content_type' => '',
'update' => 0,
'import_period' => '-1',
'expire_period' => 3600,
'import_on_create' => 1,
'process_in_background' => 1,
);
$export['staticpages'] = $feeds_importer;
return $export;
}