Newer
Older
Alex Barth
committed
Alex Barth
committed
* Feeds - basic API functions and hook implementations.
*/
// Common request time, use as point of reference and to avoid calls to time().
Alex Barth
committed
define('FEEDS_REQUEST_TIME', time());
// Do not schedule a feed for refresh.
define('FEEDS_SCHEDULE_NEVER', -1);
// Never expire feed items.
define('FEEDS_EXPIRE_NEVER', -1);
// An object that is not persistent. Compare EXPORT_IN_DATABASE, EXPORT_IN_CODE.
Alex Barth
committed
define('FEEDS_EXPORT_NONE', 0x0);
// Status of batched operations.
define('FEEDS_BATCH_COMPLETE', 1);
define('FEEDS_BATCH_ACTIVE', 0);
Alex Barth
committed
/**
Alex Barth
committed
* @{
*/
function feeds_cron() {
Alex Barth
committed
if ($importers = feeds_reschedule()) {
foreach ($importers as $id) {
feeds_importer($id)->schedule();
$rows = db_query("SELECT feed_nid FROM {feeds_source} WHERE id = :id", array(':id' => $id));
Alex Barth
committed
foreach ($rows as $row) {
Alex Barth
committed
feeds_source($id, $row->feed_nid)->schedule();
}
}
feeds_reschedule(FALSE);
return;
}
Alex Barth
committed
}
/**
* Implements hook_cron_queue_info().
Alex Barth
committed
* Invoked by drupal_queue module if present.
*/
function feeds_cron_queue_info() {
$queues = array();
Alex Barth
committed
$queues['feeds_source_import'] = array(
'worker callback' => 'feeds_source_import',
'time' => variable_get('feeds_worker_time', 15),
);
$queues['feeds_importer_expire'] = array(
'worker callback' => 'feeds_importer_expire',
'time' => variable_get('feeds_worker_time', 15),
Alex Barth
committed
);
return $queues;
Alex Barth
committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Scheduler callback for importing from a source.
*/
function feeds_source_import($job) {
$source = feeds_source($job['type'], $job['id']);
try {
$source->existing()->import();
}
catch (Exception $e) {
watchdog('feeds_source_import()', $e->getMessage(), array(), WATCHDOG_ERROR);
}
$source->schedule();
}
/**
* Scheduler callback for expiring content.
*/
function feeds_importer_expire($job) {
$importer = feeds_importer($job['type']);
try {
$importer->existing()->expire();
}
catch (Exception $e) {
watchdog('feeds_importer_expire()', $e->getMessage(), array(), WATCHDOG_ERROR);
}
$importer->schedule();
}
/**
* Reschedule one or all importers.
*
* Note: feeds_reschedule() is used in update hook feeds_update_6012() and as
* such must be maintained as part of the upgrade path from pre 6.x 1.0 beta 6
* versions of Feeds.
*
* @param $importer_id
* If TRUE, all importers will be rescheduled, if FALSE, no importers will
* be rescheduled, if an importer id, only importer of that id will be
* rescheduled.
*
* @return
* TRUE if all importers need rescheduling. FALSE if no rescheduling is
* required. An array of importers that need rescheduling.
*/
function feeds_reschedule($importer_id = NULL) {
$reschedule = variable_get('feeds_reschedule', FALSE);
if ($importer_id === TRUE || $importer_id === FALSE) {
$reschedule = $importer_id;
}
elseif (is_string($importer_id) && $reschedule !== TRUE) {
$reschedule = is_array($reschedule) ? $reschedule : array();
$reschedule[$importer_id] = $importer_id;
}
variable_set('feeds_reschedule', $reschedule);
if ($reschedule === TRUE) {
return feeds_enabled_importers();
}
return $reschedule;
}
* Implements feeds_permission().
function feeds_permission() {
$perms = array(
'administer feeds' => array(
'title' => t('Administer Feeds'),
'description' => t('Create, update, delete importers, execute import and delete tasks on any importer.')
Alex Barth
committed
foreach (feeds_importer_load_all() as $importer) {
"import $importer->id feeds" => array(
'title' => t('Import @name feeds', array('@name' => $importer->config['name'])),
),
"clear $importer->id feeds" => array(
'title' => t('Delete items from @name feeds', array('@name' => $importer->config['name'])),
),
Alex Barth
committed
}
return $perms;
}
/**
*
* Declare form callbacks for all known classes derived from FeedsConfigurable.
Alex Barth
committed
*/
function feeds_forms() {
$forms = array();
$forms['FeedsImporter_feeds_form']['callback'] = 'feeds_form';
Alex Barth
committed
$plugins = feeds_get_plugins();
foreach ($plugins as $plugin) {
$forms[$plugin['handler']['class'] .'_feeds_form']['callback'] = 'feeds_form';
Alex Barth
committed
}
return $forms;
}
/**
Alex Barth
committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
*/
function feeds_menu() {
// Register a callback for all feed configurations that are not attached to a content type.
$items = array();
foreach (feeds_importer_load_all() as $importer) {
if (empty($importer->config['content_type'])) {
$items['import/'. $importer->id] = array(
'title' => $importer->config['name'],
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_import_form', 1),
'access callback' => 'feeds_access',
'access arguments' => array('import', $importer->id),
'file' => 'feeds.pages.inc',
);
$items['import/'. $importer->id .'/import'] = array(
'title' => 'Import',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['import/'. $importer->id .'/delete-items'] = array(
'title' => 'Delete items',
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_delete_tab_form', 1),
'access callback' => 'feeds_access',
'access arguments' => array('clear', $importer->id),
'file' => 'feeds.pages.inc',
'type' => MENU_LOCAL_TASK,
);
}
else {
$items['node/%node/import'] = array(
'title' => 'Import',
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_import_tab_form', 1),
'access callback' => 'feeds_access',
'access arguments' => array('import', 1),
'file' => 'feeds.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
$items['node/%node/delete-items'] = array(
'title' => 'Delete items',
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_delete_tab_form', NULL, 1),
'access callback' => 'feeds_access',
'access arguments' => array('clear', 1),
'file' => 'feeds.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 11,
);
}
Alex Barth
committed
}
if (count($items)) {
$items['import'] = array(
'title' => 'Import',
'page callback' => 'feeds_page',
'access callback' => 'feeds_page_access',
'file' => 'feeds.pages.inc',
);
}
return $items;
}
/**
* Menu loader callback.
*/
function feeds_importer_load($id) {
return feeds_importer($id);
}
/**
Alex Barth
committed
*/
function feeds_theme() {
return array(
'feeds_upload' => array(
'file' => 'feeds.pages.inc',
Alex Barth
committed
),
);
}
/**
* Menu access callback.
*
* @param $action
* One of 'import' or 'clear'.
* @param $param
* Node object or FeedsImporter id.
*/
function feeds_access($action, $param) {
if (is_string($param)) {
$importer_id = $param;
}
elseif ($param->type) {
$importer_id = feeds_get_importer_id($param->type);
Alex Barth
committed
}
// Check for permissions if feed id is present, otherwise return FALSE.
if ($importer_id) {
Alex Barth
committed
if (user_access('administer feeds') || user_access($action .' '. $importer_id .' feeds')) {
return TRUE;
}
}
return FALSE;
}
/**
* Menu access callback.
*/
function feeds_page_access() {
if (user_access('administer feeds')) {
return TRUE;
}
foreach (feeds_enabled_importers() as $id) {
Alex Barth
committed
return TRUE;
}
}
return FALSE;
}
/**
* Implements hook_views_api().
Alex Barth
committed
*/
function feeds_views_api() {
return array(
'api' => '2.0',
'path' => drupal_get_path('module', 'feeds') .'/views',
);
}
/**
* Implements hook_ctools_plugin_api().
Alex Barth
committed
*/
function feeds_ctools_plugin_api($owner, $api) {
if ($owner == 'feeds' && $api == 'plugins') {
return array('version' => 1);
}
}
Alex Barth
committed
/**
* Implements hook_ctools_plugin_type().
Alex Barth
committed
*/
function feeds_ctools_plugin_type() {
Alex Barth
committed
return array(
'plugins' => array(
'cache' => TRUE,
'use hooks' => TRUE,
'classes' => array('handler'),
),
Alex Barth
committed
);
}
Alex Barth
committed
/**
* Implements hook_feeds_plugins().
Alex Barth
committed
*/
function feeds_feeds_plugins() {
module_load_include('inc', 'feeds', 'feeds.plugins');
return _feeds_feeds_plugins();
}
/**
Alex Barth
committed
*/
function feeds_node_load($nodes) {
_feeds_node_processor_node_load($nodes);
/**
* Implements hook_node_validate().
*/
function feeds_node_validate($node, $form, &$form_state) {
if (!$importer_id = feeds_get_importer_id($node->type)) {
return;
}
// Keep a copy of the title for subsequent node creation stages.
// @todo: revisit whether $node still looses all of its properties
// between validate and insert stage.
$last_title = &drupal_static('feeds_node_last_title');
$last_feeds = &drupal_static('feeds_node_last_feeds');
Alex Barth
committed
// On validation stage we are working with a FeedsSource object that is
// not tied to a nid - when creating a new node there is no
// $node->nid at this stage.
$source = feeds_source($importer_id);
Alex Barth
committed
// Node module magically moved $form['feeds'] to $node->feeds :P
$last_feeds = $node->feeds;
$source->configFormValidate($last_feeds);
// If node title is empty, try to retrieve title from feed.
if (trim($node->title) == '') {
try {
$source->addConfig($last_feeds);
if (!$last_title = $source->preview()->getTitle()) {
throw new Exception();
}
}
catch (Exception $e) {
drupal_set_message($e->getMessage(), 'error');
form_set_error('title', t('Could not retrieve title from feed.'), 'error');
Alex Barth
committed
}
}
}
/**
Alex Barth
committed
*/
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
function feeds_node_insert($node) {
_feeds_node_processor_node_insert($node);
feeds_node_update($node);
}
/**
* Implements hook_node_update().
*/
function feeds_node_update($node) {
_feeds_node_processor_node_update($node);
if (!$importer_id = feeds_get_importer_id($node->type)) {
return;
}
$last_title = &drupal_static('feeds_node_last_title');
$last_feeds = &drupal_static('feeds_node_last_feeds');
// Populate title from result of validation phase.
if (!empty($last_title)) {
$node->title = $last_title;
}
$last_title = NULL;
// A node may not have been validated, make sure $last_feeds is present.
if (empty($last_feeds)) {
$last_feeds = $node->feeds;
}
// Add configuration to feed source and save.
$source = feeds_source($importer_id, $node->nid);
$source->addConfig($last_feeds);
$source->save();
// Refresh feed if import on create is selected and suppress_import is
// not set.
if ($op == 'insert' && feeds_importer($importer_id)->config['import_on_create'] && !isset($last_feeds['suppress_import'])) {
feeds_batch_set(t('Importing'), 'import', $importer_id, $node->nid);
}
// Add source to schedule, make sure importer is scheduled, too.
if ($op == 'insert') {
$source->schedule();
$source->importer->schedule();
}
$last_feeds = NULL;
}
/**
* Implements hook_node_delete().
*/
function feeds_node_delete($node) {
_feeds_node_processor_node_delete($node);
if ($importer_id = feeds_get_importer_id($node->type)) {
feeds_source($importer_id, $node->nid)->delete();
}
}
/**
* FeedsNodeProcessor's hook_node_load().
*/
function _feeds_node_processor_node_load($nodes) {
if ($items = db_query("SELECT nid, imported, guid, url, feed_nid FROM {feeds_node_item} WHERE nid IN nids(:nids)", array(':nids' => array_keys($nodes)))) {
foreach ($items as $item) {
$node->{$item->nid} = $item;
}
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
}
}
/**
* FeedsNodeProcessor's hook_node_insert().
*/
function _feeds_node_processor_node_insert($node) {
if (isset($node->feeds_node_item)) {
$node->feeds_node_item->nid = $node->nid;
drupal_write_record('feeds_node_item', $node->feeds_node_item);
}
}
/**
* FeedsNodeProcessor's hook_node_update().
*/
function _feeds_node_processor_node_update($node) {
if (isset($node->feeds_node_item)) {
$node->feeds_node_item->nid = $node->nid;
drupal_write_record('feeds_node_item', $node->feeds_node_item, 'nid');
}
}
/**
* FeedsNodeProcessor's hook_node_delete().
*/
function _feeds_node_processor_node_delete($node) {
if (isset($node->feeds_node_item)) {
db_delete('feeds_node_item')
->condition('nid', $node->nid)
->execute();
Alex Barth
committed
}
/**
* Implements hook_taxonomy_term_update().
*/
function feeds_taxonomy_term_update($term) {
if (isset($term->feeds_importer_id)) {
db_delete('feeds_term_item')
->condition('tid', $term->tid)
->execute();
}
}
/**
* Implements hook_taxonomy_term_insert().
*/
function feeds_taxonomy_term_insert($term) {
if (isset($term->feeds_importer_id)) {
$record = array(
'id' => $term->feeds_importer_id,
'tid' => $term->tid,
);
drupal_write_record('feeds_term_item', $record);
}
}
/**
* Implements hook_taxonomy_delete().
*/
function feeds_taxonomy_term_delete($term) {
db_delete('feeds_term_item')
->condition('tid', $term->tid)
->execute();
}
* Implements hook_form_alter().
*/
function feeds_form_alter(&$form, $form_state, $form_id) {
if ($form['#id'] == 'node-form') {
if ($importer_id = feeds_get_importer_id($form['type']['#value'])) {
Alex Barth
committed
// Set title to not required, try to retrieve it from feed.
$form['title']['#required'] = FALSE;
// Enable uploads.
$form['#attributes']['enctype'] = 'multipart/form-data';
Alex Barth
committed
// Build form.
$source = feeds_source($importer_id, empty($form['nid']['#value']) ? 0 : $form['nid']['#value']);
Alex Barth
committed
$form['feeds'] = array(
'#type' => 'fieldset',
'#title' => t('Feed'),
'#tree' => TRUE,
);
$form['feeds'] += $source->configForm($form_state);
$form['#feed_id'] = $importer_id;
Alex Barth
committed
}
}
}
/**
Alex Barth
committed
*/
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
*/
/**
* Batch helper.
*
* @param $title
* Title to show to user when executing batch.
* @param $method
* Method to execute on importer; one of 'import', 'clear' or 'expire'.
* @param $importer_id
* Identifier of a FeedsImporter object.
* @param $feed_nid
* If importer is attached to content type, feed node id identifying the
* source to be imported.
*/
function feeds_batch_set($title, $method, $importer_id, $feed_nid = 0) {
$batch = array(
'title' => $title,
'operations' => array(
array('feeds_batch', array($method, $importer_id, $feed_nid)),
),
'progress_message' => '',
);
batch_set($batch);
}
/**
* Batch callback.
*
* @param $method
* Method to execute on importer; one of 'import' or 'clear'.
* @param $importer_id
* Identifier of a FeedsImporter object.
* @param $feed_nid
* If importer is attached to content type, feed node id identifying the
* source to be imported.
* @param $context
* Batch context.
*/
function feeds_batch($method, $importer_id, $feed_nid = 0, &$context) {
$context['finished'] = 1;
try {
$context['finished'] = feeds_source($importer_id, $feed_nid)->$method();
}
catch (Exception $e) {
drupal_set_message($e->getMessage(), 'error');
}
}
/**
Alex Barth
committed
/**
* @defgroup utility Utility functions
* @{
*/
/**
* Loads all importers.
Alex Barth
committed
*
* @param $load_disabled
* Pass TRUE to load all importers, enabled or disabled, pass FALSE to only
* retrieve enabled importers.
Alex Barth
committed
* @return
* An array of all feed configurations available.
*/
function feeds_importer_load_all($load_disabled = FALSE) {
Alex Barth
committed
$feeds = array();
// This function can get called very early in install process through
// menu_router_rebuild(). Do not try to include CTools if not available.
if (function_exists('ctools_include')) {
ctools_include('export');
$configs = ctools_export_load_object('feeds_importer', 'all');
foreach ($configs as $config) {
if (!empty($config->id) && ($load_disabled || empty($config->disabled))) {
Alex Barth
committed
$feeds[$config->id] = feeds_importer($config->id);
Alex Barth
committed
return $feeds;
Alex Barth
committed
/**
* Gets an array of enabled importer ids.
Alex Barth
committed
*
* @return
* An array where the values contain ids of enabled importers.
Alex Barth
committed
*/
function feeds_enabled_importers() {
return array_keys(_feeds_importer_digest());
Alex Barth
committed
}
* Gets an enabled importer configuration by content type.
Alex Barth
committed
*
* @param $content_type
* A node type string.
*
* @return
* A FeedsImporter id if there is an importer for the given content type,
* FALSE otherwise.
function feeds_get_importer_id($content_type) {
$importers = array_flip(_feeds_importer_digest());
return isset($importers[$content_type]) ? $importers[$content_type] : FALSE;
}
/**
* Helper function for feeds_get_importer_id() and feeds_enabled_importers().
*/
function _feeds_importer_digest() {
$importers = &drupal_static(__FUNCTION__);
if ($importers === NULL) {
if ($cache = cache_get(__FUNCTION__)) {
$importers = $cache->data;
}
else {
$importers = array();
foreach (feeds_importer_load_all() as $importer) {
$importers[$importer->id] = isset($importer->config['content_type']) ? $importer->config['content_type'] : '';
Alex Barth
committed
}
cache_set(__FUNCTION__, $importers);
Alex Barth
committed
}
return $importers;
}
/**
* Resets importer caches. Call when enabling/disabling importers.
*/
function feeds_cache_clear($rebuild_menu = TRUE) {
cache_clear_all('_feeds_importer_digest', 'cache');
drupal_static_reset('_feeds_importer_digest');
ctools_include('export');
ctools_export_load_object_reset('feeds_importer');
if ($rebuild_menu) {
menu_rebuild();
}
}
* Exports a FeedsImporter configuration to code.
Alex Barth
committed
function feeds_export($importer_id, $indent = '') {
ctools_include('export');
$result = ctools_export_load_object('feeds_importer', 'names', array('id' => $importer_id));
if (isset($result[$importer_id])) {
return ctools_export_object('feeds_importer', $result[$importer_id], $indent);
}
}
* Logs to a file like /mytmp/feeds_my_domain_org.log in temporary directory.
*/
function feeds_dbg($msg) {
if (variable_get('feeds_debug', false)) {
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
$filename = trim(str_replace('/', '_', $_SERVER['HTTP_HOST'] . base_path()), '_');
$handle = fopen(file_directory_temp() ."/feeds_$filename.log", 'a');
fwrite($handle, date('c') ."\t$msg\n");
fclose($handle);
}
}
Alex Barth
committed
/**
Alex Barth
committed
*/
/**
* @defgroup instantiators Instantiators
* @{
*/
/**
* Gets an importer instance.
Alex Barth
committed
*
* @param $id
* The unique id of the importer object.
*
* @return
* A FeedsImporter object or an object of a class defined by the Drupal
* variable 'feeds_importer_class'. There is only one importer object
* per $id system-wide.
*/
function feeds_importer($id) {
return FeedsConfigurable::instance(variable_get('feeds_importer_class', 'FeedsImporter'), $id);
}
/**
* Gets an instance of a source object.
Alex Barth
committed
*
* @param $importer_id
* A FeedsImporter id.
Alex Barth
committed
* @param $feed_nid
* The node id of a feed node if the source is attached to a feed node.
*
* @return
* A FeedsSource object or an object of a class defiend by the Drupal
* variable 'source_class'.
*/
function feeds_source($importer_id, $feed_nid = 0) {
return FeedsSource::instance($importer_id, $feed_nid);
Alex Barth
committed
}
Alex Barth
committed
*/
/**
* @defgroup plugins Plugin functions
* @{
*
* @todo Encapsulate this in a FeedsPluginHandler class, move it to includes/
Alex Barth
committed
* and only load it if we're manipulating plugins.
*/
/**
* Gets all available plugins. Does not list hidden plugins.
Alex Barth
committed
*
* @return
* An array where the keys are the plugin keys and the values
* are the plugin info arrays as defined in hook_feeds_plugins().
*/
function feeds_get_plugins() {
Alex Barth
committed
ctools_include('plugins');
$plugins = ctools_get_plugins('feeds', 'plugins');
Alex Barth
committed
foreach ($plugins as $key => $info) {
if (!empty($info['hidden'])) {
continue;
Alex Barth
committed
$result[$key] = $info;
Alex Barth
committed
// Sort plugins by name and return.
uasort($result, 'feeds_plugin_compare');
return $result;
}
/**
Alex Barth
committed
* Sort callback for feeds_get_plugins().
Alex Barth
committed
function feeds_plugin_compare($a, $b) {
return strcasecmp($a['name'], $b['name']);
* Gets all available plugins of a particular type.
Alex Barth
committed
*
* @param $type
* 'fetcher', 'parser' or 'processor'
Alex Barth
committed
function feeds_get_plugins_by_type($type) {
$plugins = feeds_get_plugins();
$result = array();
foreach ($plugins as $key => $info) {
if ($type == feeds_plugin_type($key)) {
$result[$key] = $info;
}
}
return $result;
* Gets an instance of a class for a given plugin and id.
Alex Barth
committed
*
* @param $plugin
* A string that is the key of the plugin to load.
* @param $id
* A string that is the id of the object.
*
* @return
* A FeedsPlugin object.
*
* @throws Exception
* If plugin can't be instantiated.
Alex Barth
committed
function feeds_plugin_instance($plugin, $id) {
ctools_include('plugins');
if ($class = ctools_plugin_load_class('feeds', 'plugins', $plugin, 'handler')) {
return FeedsConfigurable::instance($class, $id);
$args = array( '%plugin' => $plugin);
if (user_access('administer feeds')) {
$args['!link'] = l($id, 'admin/build/feeds/edit/' . $id);
drupal_set_message(t('Missing Feeds plugin %plugin. See !link. Check whether all required libraries and modules are installed properly.', $args), 'warning');
}
else {
drupal_set_message(t('Missing Feeds plugin %plugin. Please contact your site administrator.', $args), 'warning');
}
$class = ctools_plugin_load_class('feeds', 'plugins', 'FeedsMissingPlugin', 'handler');
return FeedsConfigurable::instance($class, $id);
Alex Barth
committed
* Determines whether given plugin is derived from given base plugin.
*
Alex Barth
committed
* String that identifies a Feeds plugin key.
* @param $parent_plugin
* String that identifies a Feeds plugin key to be tested against.
*
* @return
* TRUE if $parent_plugin is directly *or indirectly* a parent of $plugin,
* FALSE otherwise.
function feeds_plugin_child($plugin_key, $parent_plugin) {
Alex Barth
committed
ctools_include('plugins');
$plugins = ctools_get_plugins('feeds', 'plugins');
$info = $plugins[$plugin_key];
Alex Barth
committed
if (empty($info['handler']['parent'])) {
return FALSE;
}
elseif ($info['handler']['parent'] == $parent_plugin) {
return TRUE;
}
else {
return feeds_plugin_child($info['handler']['parent'], $parent_plugin);
* Determines the type of a plugin.
Alex Barth
committed
*
* @param $plugin_key
* String that identifies a Feeds plugin key.
Alex Barth
committed
*
* @return
* One of the following values:
* 'fetcher' if the plugin is a fetcher
* 'parser' if the plugin is a parser
* 'processor' if the plugin is a processor
* FALSE otherwise.
Alex Barth
committed
function feeds_plugin_type($plugin_key) {
if (feeds_plugin_child($plugin_key, 'FeedsFetcher')) {
return 'fetcher';
}
elseif (feeds_plugin_child($plugin_key, 'FeedsParser')) {
return 'parser';
}
elseif (feeds_plugin_child($plugin_key, 'FeedsProcessor')) {
return 'processor';
}
return FALSE;
Alex Barth
committed
/**
Alex Barth
committed
*/
/**
* @defgroup include Funtions for loading libraries
* @{
*/
/**
* Includes a library file.
Alex Barth
committed
*
* @param $file
* The filename to load from.
* @param $library
* The name of the library. If libraries module is installed,
* feeds_include_library() will look for libraries with this name managed by
* libraries module.
*/
function feeds_include_library($file, $library) {
static $included = array();
if (!isset($included[$file])) {
// Try first whether libraries module is present and load the file from
// there. If this fails, require the library from the local path.
if (module_exists('libraries') && file_exists(libraries_get_path($library) . "/$file")) {
Alex Barth
committed
require libraries_get_path($library) ."/$file";
}
else {
require DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file";
Alex Barth
committed
}
}
$included[$file] = TRUE;
}
Alex Barth
committed
/**
* Checks whether a library is present.
*
* @param $file
* The filename to load from.
* @param $library
* The name of the library. If libraries module is installed,
* feeds_library_exists() will look for libraries with this name managed by
* libraries module.
*/
function feeds_library_exists($file, $library) {
if (module_exists('libraries') && file_exists(libraries_get_path($library) . "/$file")) {
Alex Barth
committed
return TRUE;
}
elseif (file_exists(DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file")) {
Alex Barth
committed
return TRUE;
}
return FALSE;
}
/**