Skip to content
Snippets Groups Projects
feeds.module 29.6 KiB
Newer Older
 * Simplified drupal_alter().
 *
 * - None of that 'multiple parameters by ref' crazyness.
 * - Don't use module_implements() to allow hot including on behalf
 *   implementations (see mappers/).
 *
 * @todo This needs to be removed and drupal_alter() used. This is crazy dumb.
 */
function feeds_alter($type, &$data) {
  $args = array(&$data);
  $additional_args = func_get_args();
  array_shift($additional_args);
  array_shift($additional_args);
  $args = array_merge($args, $additional_args);

    if (module_hook($module, $hook)) {
      call_user_func_array($module . '_' . $hook, $args);

/**
 * Copy of valid_url() that supports the webcal scheme.
 *
 * @see valid_url().
 *
 * @todo Replace with valid_url() when http://drupal.org/node/1191252 is fixed.
 */
function feeds_valid_url($url, $absolute = FALSE) {
  if ($absolute) {
    return (bool) preg_match("
      /^                                                      # Start at the beginning of the text
      (?:ftp|https?|feed|webcal):\/\/                         # Look for ftp, http, https, feed or webcal schemes
      (?:                                                     # Userinfo (optional) which is typically
        (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*      # a username or a username and password
        (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@          # combination
      )?
      (?:
        (?:[a-z0-9\-\.]|%[0-9a-f]{2})+                        # A domain name or a IPv4 address
        |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\])         # or a well formed IPv6 address
      )
      (?::[0-9]+)?                                            # Server port number (optional)
      (?:[\/|\?]
        (?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})   # The path and query (optional)
      *)?
    $/xi", $url);
  }
  else {
    return (bool) preg_match("/^(?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url);
  }
}

/**
 * Registers a feed subscription job for execution on feeds_exit().
 *
 * @param array $job
 *   Information about a new job to queue; or if set to NULL (default), leaves
 *   the current queued jobs unchanged.
 *
 * @return
 *   An array of subscribe jobs to process.
 *
 * @see feeds_exit()
 * @see feeds_get_subscription_jobs()
 */
function feeds_set_subscription_job(array $job = NULL) {
  $jobs = &drupal_static(__FUNCTION__, array());
  if (isset($job)) {
    $jobs[] = $job;
  }
  return $jobs;
}

/**
 * Returns the list of queued jobs to be run.
 *
 * @return
 *   An array of subscribe jobs to process.
 *
 * @see feeds_set_subscription_job()
 */
function feeds_get_subscription_jobs() {
  return feeds_set_subscription_job();
}