You are here

function feedapi_get_settings in FeedAPI 6

Same name and namespace in other branches
  1. 5 feedapi.module \feedapi_get_settings()

Retrieve settings per content type or per node.

@todo: Use node type settings for pulling on/off and weight of parsers/processors, use per node settings to override their configuration, this allows us a more predictable presets/settings behaviour. See d. o. #191692 Watch out: cache permutations of node_type or node_type+nid or nid. Watch out: changes within page load likely.

Parameters

$node_type: Content type name or NULL if per node

$vid: Node vid or NULL if per content type

$reset: If TRUE, the data is returned from the database.

Return value

The associative array of feedapi settings

17 calls to feedapi_get_settings()
FeedAPIErrorTestsCase::testFeedAPI_Invalid_URL in tests/feedapi_error.test
FeedAPINodeTestsCase::testFeedAPI_Node in feedapi_node/tests/feedapi_node.test
Add a content-type, create a feed and refresh it. Check if everything seems ok Delete the feed Check if the rubbish is purged as well. Use simplified form to create a feed
FeedAPINodeTestsCase::testKeepNodeSettingsAtUpdate in feedapi_node/tests/feedapi_node.test
Checks if the node updates by feedapi_node do not alter basic node options
FeedAPIRevisionTestsCase::testFeedAPI_Node_Revisions in tests/feedapi_revision.test
Checks if the revision support works correctly
feedapi_create_node in ./feedapi.module
Create a feedapi node programatically.

... See full list

File

./feedapi.module, line 1399
Handle the submodules (for feed and item processing) Provide a basic management of feeds

Code

function feedapi_get_settings($node_type, $vid = FALSE, $reset = FALSE) {
  static $node_settings;
  if (is_numeric($vid)) {
    if (!isset($node_settings[$vid]) || $reset) {
      if ($settings = db_fetch_object(db_query('SELECT settings FROM {feedapi} WHERE vid = %d', $vid))) {
        $settings = unserialize($settings->settings);

        // If parsers don't have any settings, create an empty array
        if (!isset($settings['parsers'])) {
          $settings['parsers'] = array();
        }

        // If processors don't have any settings, create an empty array
        if (!isset($settings['processors'])) {
          $settings['processors'] = array();
        }
      }
      if (is_array($settings) && count($settings['processors']) == 0 && count($settings['parsers']) == 0) {
        $settings = NULL;
      }
      $node_settings[$vid] = !empty($settings) && is_array($settings) ? $settings : FALSE;
    }
    if (!is_array($node_settings[$vid])) {
      if (empty($node_type)) {

        // In normal case, this shouldn't happen. This is an emergency branch
        $node_type = db_result(db_query("SELECT type FROM {node} WHERE vid = %d", $vid));
      }
    }
    else {
      return $node_settings[$vid];
    }
  }

  // Fallback: node_type.
  if (isset($node_type) && is_string($node_type)) {
    if (($settings = variable_get('feedapi_settings_' . $node_type, FALSE)) && $settings['enabled'] == 1) {

      // Sanitize data right now, tricky users may turned off the module
      foreach (array(
        'parsers',
        'processors',
      ) as $type) {
        if (isset($settings[$type]) && is_array($settings[$type])) {
          $modules = array_keys($settings[$type]);
          foreach ($modules as $module) {
            if (!module_exists($module)) {
              unset($settings['parsers'][$module]);
            }
          }
        }
        else {

          // Missing parser or processor, set error message.
          if (user_access('administer content types')) {
            drupal_set_message(t('There are no !type defined for this content type. Go to !edit_page and enable at least one.', array(
              '!type' => $type,
              '!edit_page' => l('admin/content/node-type/' . $node_type, 'admin/content/node-type/' . $node_type),
            )), 'warning', FALSE);
          }
          else {
            drupal_set_message(t('There are no !type defined for this content type. Contact your site administrator.', array(
              '!type' => $type,
            )), 'warning', FALSE);
          }
        }
      }
      return $settings;
    }
  }
  return FALSE;
}