'. t('This module was developed by Dave Reid with assistance from FeedBurner.
If you like this module please consider donating to the developer\'s replacement laptop fund.', array('@link1' => 'http://davereid.net/', '@link2' => 'http://www.feedburner.com/', '@link3' => 'http://davereid.net/laptop-fund')) .'
'. t('These are the settings for the FeedBurner module. Once you have everything set, check out your site\'s FeedBurner feeds.', array('@link' => url('admin/build/feedburner'))) .'
'; return $output; case 'admin/build/feedburner': $errors = feedburner_requirements('runtime'); foreach ($errors as $error) { drupal_set_message($error['description'], 'error'); } $output = ''. t('This is the FeedBurner site feed redirection building page. Make sure to check out the FeedBurner settings.', array('@link' => url('admin/settings/feedburner'))) .'
'; return $output; } } /** * Implementation of hook_perm(). */ function feedburner_perm() { return array('administer FeedBurner', 'view FeedFlare'); } function feedburner_menu($may_cache) { $items = array(); $feedburner_admin = user_access('administer FeedBurner'); if ($may_cache) { $items[] = array( 'path' => 'admin/settings/feedburner', 'title' => t('FeedBurner'), 'description' => t('Administer FeedBurner integration.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('_feedburner_settings_form'), 'access' => $feedburner_admin, ); $items[] = array( 'path' => 'admin/build/feedburner', 'title' => t('FeedBurner'), 'description' => t('Change site feed redirections to FeedBurner.'), 'callback' => '_feedburner_build_overview', 'access' => $feedburner_admin, ); $items[] = array( 'path' => 'admin/build/feedburner/list', 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/build/feedburner/add', 'title' => t('Add'), 'callback' => 'drupal_get_form', 'callback arguments' => array('_feedburner_build_edit'), 'access' => $feedburner_admin, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/build/feedburner/edit', 'title' => t('Edit'), 'callback' => 'drupal_get_form', 'callback arguments' => array('_feedburner_build_edit'), 'access' => $feedburner_admin, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/feedburner/remove', 'title' => t('Remove'), 'callback' => '_feedburner_build_remove', 'access' => $feedburner_admin, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/feedburner/verify', 'callback' => '_feedburner_verify', 'access' => $feedburner_admin, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/feedburner/autocomplete', 'title' => t('Feeds autocomplete'), 'callback' => '_feedburner_autocomplete', 'access' => $feedburner_admin, 'type' => MENU_CALLBACK, ); } else { $items[] = array( 'path' => 'feedburner/test', 'callback' => '_feedburner_test', 'access' => true, 'type' => MENU_CALLBACK, ); } return $items; } /** * Implementation of hook_init(). */ function feedburner_init() { _feedburner_redirect(); // Emulate Drupal 6's menu-file-include system and include the admin functions on the FeedBurner admin paths if (isset($_GET['q']) && preg_match('/admin\/.*feedburner.*/i', $_GET['q'])) { _feedburner_include('admin'); } } /** * Implementation of hook_exit(). */ function feedburner_exit() { global $FEEDBURNER_NO_CACHE; if ($FEEDBURNER_NO_CACHE == true && variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { global $base_root; cache_clear_all($base_root . request_uri(), 'cache_page'); } } /** * Implementation of hook_user(). */ function feedburner_user($op, &$edit, &$account, $category = null) { if (!module_exists('blog') || !user_access('edit own blog') || !variable_get('feedburner_blogs', false)) { return; } _feedburner_include('admin'); $user_blog = 'blog/'. $account->uid .'/feed'; switch ($op) { case 'form': if ($category == 'account') { $feed = _feedburner_load($user_blog); $form['feedburner'] = array( '#type' => 'fieldset', '#title' => t('Blog FeedBurner Redirection'), '#weight' => 1, '#collapsible' => true, '#description' => t('Requests for your blog\'s feed (%url) will be redirected to this FeedBurner feed. Leave this blank to disable redirection.', array('%url' => url($user_blog, null, null, true))), ); $form['feedburner']['fb_uri'] = array( '#type' => 'textfield', '#maxlength' => 100, '#size' => 30, '#default_value' => $feed->fb_uri, '#field_prefix' => _feedburner_construct_url(), '#description' => t('This URI is case-sensitive and alphanumeric.'), '#validate' => array('_feedburner_build_edit_validate' => array()), ); return $form; } break; case 'update': if (_feedburner_save($user_blog, ($edit['status'] == 0 ? null : $edit['fb_uri'])) == true) { _feedburner_verify_feed($edit['fb_uri']); } unset($edit['fb_uri']); break; case 'delete': _feedburner_save($user_blog); break; } // switch } /** * Implementation of hook_block(). */ function feedburner_block($op = 'list', $delta = 0, $edit = array()) { _feedburner_include('block'); return _feedburner_block($op, $delta, $edit); } /** * Implementation of hook_cron(). * * Peforms verification of the 5 least-verified feeds. */ function feedburner_cron() { _feedburner_include('admin'); $result = db_query_range('SELECT DISTINCT fb_uri FROM {feedburner_feeds} WHERE verified < %d ORDER BY verified ASC', time(), 0, 5); while ($feed = db_fetch_object($result)) { _feedburner_verify_feed($feed->fb_uri); } } /** * Implementation of hook_requirements(). */ function feedburner_requirements($phase) { $requirements = array(); if ($phase == 'runtime') { if (!_feedburner_can_api(false, false)) { $requirements['feedburner_simplexml'] = array( 'title' => t('FeedBurner module'), 'value' => t('SimpleXML not enabled'), 'severity' => REQUIREMENT_WARNING, 'description' => t('The SimpleXML PHP extension (not available for PHP4) is required for some features to work.'), ); } else { $username = variable_get('feedburner_username', ''); $auth = variable_get('feedburner_auth', null); if (!empty($username) && empty($auth)) { $requirements['feedburner_auth'] = array( 'title' => t('FeedBurner account'), 'value' => t('FeedBurner account not verified'), 'severity' => REQUIREMENT_WARNING, 'description' => t('Your FeedBurner account is not verified.'), ); } } } return $requirements; } /** * Implementation of nodeapi(). */ function feedburner_nodeapi(&$node, $op, $teaser, $page) { if ($op == 'view') { $display = variable_get('feedburner_feedflare', FEEDBURNER_FEEDFLARE_NONE); if ($display == 3 || ($display == 1 && $teaser) || ($display == 2 && $page)) { $feedflare = _feedburner_get_feedflare($node->nid, $node->type); if ($feedflare != false) { $node->content['feedflare'] = array( '#value' => $feedflare, '#weight' => 10, ); } } } } /** * Get the JavaScript code for FeedFlare */ function _feedburner_get_feedflare($nid, $type) { $feedflare = false; if (user_access('view FeedFlare') && user_access('access content')) { $node_types = variable_get('feedburner_feedflare_node_types', array()); $feed = _feedburner_load('rss.xml'); if (isset($feed->fb_uri) && in_array($type, $node_types)) { $feedflare = ''; } } return $feedflare; } /** * Redirects the user to the appropriate FeedBurner feed if the current system * url is associated with a feed. */ function _feedburner_redirect() { // Ensure we have path functions loaded to use $_GET['q']. drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // Drupal paths with plus signs get turned into spaces in $_GET['q']. In // order to match them to the urls in the database, translate the spaces // back into plus signs. $path = preg_replace('/ /', '+', $_GET['q']); // Skip redirecting on a whitelist of paths (admin paths, etc). if (preg_match('/^admin\//i', $path)) { return; } // If the current user's useragent matches any of the useragent strings allowed raw feed access, stop redirecting. $useragents = '/'. _feedburner_var('useragents') .'/i'; if (!preg_match($useragents, $_SERVER['HTTP_USER_AGENT'])) { // If there is a FeedBurner feed matched to the current system url and if // the disabled redirection override query string ('feedburner_redirect=false') // isn't present, perform the redirect to the FeedBurner feed. $feed = _feedburner_load($path); $skip_redirect = (isset($_GET['feedburner_redirect']) && $_GET['feedburner_redirect'] == 'false'); if (isset($feed->fb_uri) && !$skip_redirect) { $url = _feedburner_construct_url($feed->fb_uri); $status = _feedburner_var('redirect_status'); // Copied the code from drupal_goto() so that I don't need to include // common.inc or do a full bootstrap. Messy errors ensue. module_invoke_all('exit', $url); session_write_close(); header('Location: '. $url, TRUE, $status); exit(); } } else { global $FEEDBURNER_NO_CACHE; $FEEDBURNER_NO_CACHE = true; } } function _feedburner_var($var, $default = null) { $default_name = 'FEEDBURNER_DEFAULT_'. strtoupper($var); if ($default === null && defined($default_name)) { $default = constant($default_name); } return variable_get('feedburner_'. $var, $default); } /** * Loads database details about a FeedBurner feed based on the system uri. * * @param $local_uri * A string containing the local system path. * @param $fields * A comma delimited string of the fields to load from the FeedBurner * database table (default 'fb_uri'). * @return * An associated array with the specified fields or FALSE if not found. */ function _feedburner_load($local_uri, $fields = 'fb_uri') { if (empty($local_uri) || empty($fields)) { return false; } $result = db_fetch_object(db_query("SELECT %s FROM {feedburner_feeds} WHERE local_uri = LOWER('%s')", $fields, $local_uri)); return (empty($result) ? false : $result); } /** * Constructs an absolute url based on a FeedBurner feed uri. */ function _feedburner_construct_url($uri = '') { return 'http://'. _feedburner_var('domain') .'/'. $uri; } /** * Include a FeedBurner module file. * * @param $file * Filename to include */ function _feedburner_include($file) { include_once './'. drupal_get_path('module', 'feedburner') .'/feedburner.'. $file .'.inc'; } /** * Determines if we can use the FeedBurner api. * * @param $auth * If the FeedBurner account details are included in the requirements. * @param $include * Boolean to include the api file, default false. */ function _feedburner_can_api($auth = false, $include = false) { $can_api = extension_loaded('SimpleXML') && function_exists('simplexml_load_string'); if ($auth == true && $can_api == true) { $can_api = (bool) variable_get('feedburner_auth', null); } if ($can_api == true) { _feedburner_include('api'); } return $can_api; }