You are here

function service_links_block in Service links 6.2

Same name and namespace in other branches
  1. 5 service_links.module \service_links_block()
  2. 6 service_links.module \service_links_block()

Implementation of hook_block().

File

./service_links.module, line 191
Adds social network links to the content.

Code

function service_links_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks['service_links'] = array(
      'info' => t('Service links'),
      'cache' => BLOCK_NO_CACHE,
    );
    $blocks['service_links_fisheye'] = array(
      'info' => t('Service links with FishEye effect'),
      'cache' => BLOCK_NO_CACHE,
    );
    $blocks['service_links_not_node'] = array(
      'info' => t('Service links block for not-node pages'),
      'cache' => BLOCK_NO_CACHE,
    );
    return $blocks;
  }
  elseif ($op == 'view') {
    $node = menu_get_object('node');
    $block = array();
    if (user_access('access service links') && isset($node)) {
      if (service_links_show($node)) {
        switch ($delta) {
          case 'service_links':
            $block['subject'] = t('Bookmark/Search this post');
            $style = variable_get('service_links_block_style', SERVICE_LINKS_STYLE_IMAGE_AND_TEXT);
            $block['content'] = theme('service_links_block_format', service_links_render($node, FALSE, $style), $style);
            break;
          case 'service_links_fisheye':
            $block['subject'] = t('Bookmark/Search this post');
            $block['content'] = theme('service_links_fisheye_format', service_links_render($node, FALSE, SERVICE_LINKS_STYLE_FISHEYE));
            break;
        }
      }
      return $block;
    }
    elseif (user_access('access service links') && !isset($node)) {
      switch ($delta) {
        case 'service_links_not_node':
          $block['subject'] = t('Bookmark/Search this post');
          $options = array(
            'style' => variable_get('service_links_block_not_node_style', SERVICE_LINKS_STYLE_IMAGE_AND_TEXT),
            'link_to_front' => variable_get('service_links_block_not_node_front', FALSE),
          );
          $block['content'] = theme('service_links_block_format', service_links_render(NULL, FALSE, $options), $options['style']);
          break;
      }
      return $block;
    }
  }
  elseif ($op == 'configure') {
    $form = array();
    switch ($delta) {
      case 'service_links':
        $form['service_links_block_style'] = array(
          '#type' => 'select',
          '#title' => t('Style'),
          '#description' => t('How the service links will appear in the block.'),
          '#default_value' => variable_get('service_links_block_style', SERVICE_LINKS_STYLE_IMAGE_AND_TEXT),
          '#options' => array(
            SERVICE_LINKS_STYLE_TEXT => t('Text'),
            SERVICE_LINKS_STYLE_IMAGE => t('Image'),
            SERVICE_LINKS_STYLE_IMAGE_AND_TEXT => t('Image and Text'),
          ),
        );
        break;
      case 'service_links_fisheye':
        $form['service_links_path_fisheye'] = array(
          '#type' => 'textfield',
          '#title' => t('Alternative icon folder'),
          '#size' => 60,
          '#description' => t('If you have alternative icons write here the path without trailing slash'),
          '#default_value' => service_links_expand_path(NULL, 'fisheye'),
        );
        break;
      case 'service_links_not_node':
        $form['service_links_block_not_node_style'] = array(
          '#type' => 'select',
          '#title' => t('Style'),
          '#description' => t('How the service links will appear in the block.'),
          '#default_value' => variable_get('service_links_block_not_node_style', SERVICE_LINKS_STYLE_IMAGE_AND_TEXT),
          '#options' => array(
            SERVICE_LINKS_STYLE_TEXT => t('Text'),
            SERVICE_LINKS_STYLE_IMAGE => t('Image'),
            SERVICE_LINKS_STYLE_IMAGE_AND_TEXT => t('Image and Text'),
          ),
        );
        $form['service_links_block_not_node_front'] = array(
          '#type' => 'checkbox',
          '#title' => t('Link always to the front page'),
          '#description' => t('If selected the services will link always to the front page %front.', array(
            '%front' => url('<front>', array(
              'absolute' => TRUE,
            )),
          )),
          '#default_value' => variable_get('service_links_block_not_node_front', FALSE),
        );
        break;
    }
    return $form;
  }
  elseif ($op == 'save') {
    switch ($delta) {
      case 'service_links':
        variable_set('service_links_block_style', $edit['service_links_block_style']);
        break;
      case 'service_links_fisheye':
        variable_set('service_links_path_fisheye', $edit['service_links_path_fisheye']);
        break;
      case 'service_links_not_node':
        variable_set('service_links_block_not_node_style', $edit['service_links_block_not_node_style']);
        variable_set('service_links_block_not_node_front', $edit['service_links_block_not_node_front']);
        break;
    }
  }
}