You are here

function subscriptions_ui_link in Subscriptions 5.2

Same name and namespace in other branches
  1. 6 subscriptions_ui.module \subscriptions_ui_link()

Implementation of hook_link().

Add a Subscribe link to node pages (depending on the Display Settings).

File

./subscriptions_ui.module, line 72
Provides a user interface for Subscriptions.

Code

function subscriptions_ui_link($type, $node = NULL, $teaser = NULL) {
  global $user;
  if ($type == 'node' && subscriptions_ui_can_subscribe() && empty($teaser)) {
    if (variable_get('subscriptions_form_link_only', 0) && arg(2) != 'subscribe' && (!variable_get('subscriptions_avoid_empty_subscribe_links', 0) || module_invoke_all('subscriptions', 'node_options', $user, $node))) {
      $blocked_types = variable_get('subscriptions_blocked_content_types', array());
      if (!in_array($node->type, $blocked_types) || user_access('subscribe to all content types')) {
        return array(
          'subscriptions-subscribe' => array(
            'href' => $_GET['q'] . '/subscribe',
            'title' => t('Subscribe') . (in_array($node->type, $blocked_types) ? SUBSCRIPTIONS_UNAVAILABLE : ''),
            'html' => TRUE,
            'fragment' => 'subscribe',
            'attributes' => array(
              'title' => t('Receive notifications about changes and/or comments to this page (and possibly similar pages).'),
            ),
          ),
        );
      }
    }
    elseif (variable_get('subscriptions_form_in_block', 0) && arg(2) == 'subscribe') {

      // Make sure the block is visible
      global $theme;
      if (!isset($theme)) {
        init_theme();
      }
      $regions = system_region_list($theme);
      foreach (array_keys($regions) as $region) {
        $blocks = block_list($region);
        foreach (array_keys($blocks) as $block) {
          if ($block == 'subscriptions_ui_0') {
            $subscriptions_ui_block_visible = TRUE;
          }
        }
      }
      if (empty($subscriptions_ui_block_visible)) {
        drupal_set_message(t('Enable the !module block <!link_tag_begin>here<!link_tag_end>!', array(
          '!module' => 'Subscriptions',
          '!link_tag_begin' => 'a href="' . url('admin/build/block') . '"',
          '!link_tag_end' => '/a',
        )), 'error');
      }
    }
  }
}